]>
Commit | Line | Data |
---|---|---|
eb5d44eb | 1 | /* |
2 | * IS-IS Rout(e)ing protocol - isis_pdu.c | |
3 | * PDU processing | |
4 | * | |
5 | * Copyright (C) 2001,2002 Sampo Saaristo | |
6 | * Tampere University of Technology | |
7 | * Institute of Communications Engineering | |
8 | * | |
9 | * This program is free software; you can redistribute it and/or modify it | |
10 | * under the terms of the GNU General Public Licenseas published by the Free | |
11 | * Software Foundation; either version 2 of the License, or (at your option) | |
12 | * any later version. | |
13 | * | |
14 | * This program is distributed in the hope that it will be useful,but WITHOUT | |
15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
16 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
17 | * more details. | |
18 | ||
19 | * You should have received a copy of the GNU General Public License along | |
20 | * with this program; if not, write to the Free Software Foundation, Inc., | |
21 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
22 | */ | |
23 | ||
24 | #include <stdio.h> | |
25 | #include <string.h> | |
26 | #include <zebra.h> | |
eb5d44eb | 27 | |
28 | #include "memory.h" | |
29 | #include "thread.h" | |
30 | #include "linklist.h" | |
31 | #include "log.h" | |
32 | #include "stream.h" | |
33 | #include "vty.h" | |
34 | #include "hash.c" | |
35 | #include "prefix.h" | |
36 | #include "if.h" | |
37 | ||
38 | #include "isisd/dict.h" | |
39 | #include "isisd/include-netbsd/iso.h" | |
40 | #include "isisd/isis_constants.h" | |
41 | #include "isisd/isis_common.h" | |
42 | #include "isisd/isis_adjacency.h" | |
43 | #include "isisd/isis_circuit.h" | |
44 | #include "isisd/isis_network.h" | |
45 | #include "isisd/isis_misc.h" | |
46 | #include "isisd/isis_dr.h" | |
47 | #include "isisd/isis_flags.h" | |
48 | #include "isisd/isis_tlv.h" | |
49 | #include "isisd/isisd.h" | |
50 | #include "isisd/isis_dynhn.h" | |
51 | #include "isisd/isis_lsp.h" | |
52 | #include "isisd/isis_pdu.h" | |
53 | #include "isisd/iso_checksum.h" | |
54 | #include "isisd/isis_csm.h" | |
55 | #include "isisd/isis_events.h" | |
56 | ||
57 | extern struct thread_master *master; | |
58 | extern struct isis *isis; | |
59 | ||
60 | #define ISIS_MINIMUM_FIXED_HDR_LEN 15 | |
61 | #define ISIS_MIN_PDU_LEN 13 /* partial seqnum pdu with id_len=2 */ | |
62 | ||
63 | #ifndef PNBBY | |
64 | #define PNBBY 8 | |
65 | #endif /* PNBBY */ | |
66 | ||
67 | /* Utility mask array. */ | |
68 | static u_char maskbit[] = | |
69 | { | |
70 | 0x00, 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe, 0xff | |
71 | }; | |
72 | ||
73 | /* | |
74 | * HELPER FUNCS | |
75 | */ | |
76 | ||
77 | /* | |
78 | * Compares two sets of area addresses | |
79 | */ | |
80 | static int | |
81 | area_match (struct list *left, struct list *right) | |
82 | { | |
83 | struct area_addr *addr1, *addr2; | |
84 | struct listnode *node1, *node2; | |
85 | ||
86 | LIST_LOOP (left, addr1, node1) { | |
87 | LIST_LOOP (right, addr2, node2) { | |
88 | if (addr1->addr_len == addr2->addr_len && | |
89 | !memcmp (addr1->area_addr, addr2->area_addr, (int)addr1->addr_len)) | |
90 | return 1; /* match */ | |
91 | } | |
92 | } | |
93 | ||
94 | return 0; /* mismatch */ | |
95 | } | |
96 | ||
97 | /* | |
98 | * Check if ip2 is in the ip1's network (function like Prefix.h:prefix_match() ) | |
99 | * param ip1 the IS interface ip address structure | |
100 | * param ip2 the IIH's ip address | |
101 | * return 0 the IIH's IP is not in the IS's subnetwork | |
102 | * 1 the IIH's IP is in the IS's subnetwork | |
103 | */ | |
104 | int | |
105 | ip_same_subnet (struct prefix_ipv4 *ip1, struct in_addr *ip2) | |
106 | { | |
107 | u_char *addr1, *addr2; | |
108 | int shift, offset; | |
109 | int len; | |
110 | ||
111 | addr1 = (u_char *) &ip1->prefix.s_addr; | |
112 | addr2 = (u_char *) &ip2->s_addr; | |
113 | len = ip1->prefixlen; | |
114 | ||
115 | shift = len % PNBBY; | |
116 | offset = len / PNBBY; | |
117 | ||
118 | while (offset--) { | |
119 | if (addr1[offset] != addr2[offset]) { | |
120 | return 0; | |
121 | } | |
122 | } | |
123 | ||
124 | if (shift) { | |
125 | if (maskbit[shift] & (addr1[offset] ^ addr2[offset])) { | |
126 | return 0; | |
127 | } | |
128 | } | |
129 | ||
130 | return 1; /* match */ | |
131 | } | |
132 | ||
133 | ||
134 | /* | |
135 | * Compares two set of ip addresses | |
136 | * param left the local interface's ip addresses | |
137 | * param right the iih interface's ip address | |
138 | * return 0 no match; | |
139 | * 1 match; | |
140 | */ | |
141 | static int | |
142 | ip_match (struct list *left, struct list *right) | |
143 | { | |
144 | struct prefix_ipv4 *ip1; | |
145 | struct in_addr *ip2; | |
146 | struct listnode *node1, *node2; | |
147 | ||
148 | LIST_LOOP (left, ip1, node1) { | |
149 | LIST_LOOP (right, ip2, node2) { | |
150 | if (ip_same_subnet(ip1, ip2)) { | |
151 | return 1; /* match */ | |
152 | } | |
153 | } | |
154 | ||
155 | } | |
156 | return 0; | |
157 | } | |
158 | ||
159 | /* | |
160 | * Checks whether we should accept a PDU of given level | |
161 | */ | |
162 | static int | |
163 | accept_level (int level, int circuit_t) | |
164 | { | |
165 | int retval = ((circuit_t & level) == level); /* simple approach */ | |
166 | ||
167 | return retval; | |
168 | } | |
169 | ||
170 | int | |
171 | authentication_check (struct isis_passwd *one, struct isis_passwd *theother) | |
172 | { | |
173 | if (one->type != theother->type) { | |
174 | zlog_warn ("Unsupported authentication type %d", theother->type ); | |
175 | return 1; /* Auth fail (different authentication types)*/ | |
176 | } | |
177 | switch (one->type) { | |
178 | case ISIS_PASSWD_TYPE_CLEARTXT: | |
179 | if (one->len != theother->len) | |
180 | return 1; /* Auth fail () - passwd len mismatch */ | |
181 | return memcmp (one->passwd, theother->passwd, one->len); | |
182 | break; | |
183 | default: | |
184 | zlog_warn ("Unsupported authentication type"); | |
185 | break; | |
186 | } | |
187 | return 0; /* Auth pass */ | |
188 | } | |
189 | ||
190 | /* | |
191 | * Processing helper functions | |
192 | */ | |
193 | void | |
194 | tlvs_to_adj_nlpids (struct tlvs *tlvs, struct isis_adjacency *adj) | |
195 | { | |
196 | int i; | |
197 | struct nlpids *tlv_nlpids; | |
198 | ||
199 | if (tlvs->nlpids) { | |
200 | ||
201 | tlv_nlpids = tlvs->nlpids; | |
202 | ||
203 | adj->nlpids.count = tlv_nlpids->count; | |
204 | ||
205 | for (i=0;i<tlv_nlpids->count;i++) { | |
206 | adj->nlpids.nlpids[i] = tlv_nlpids->nlpids[i]; | |
207 | } | |
208 | } | |
209 | } | |
210 | ||
211 | void | |
212 | del_ip_addr (void *val) | |
213 | { | |
214 | XFREE (MTYPE_ISIS_TMP, val); | |
215 | } | |
216 | ||
217 | void | |
218 | tlvs_to_adj_ipv4_addrs (struct tlvs *tlvs, struct isis_adjacency *adj) | |
219 | { | |
220 | struct listnode *node; | |
221 | struct in_addr *ipv4_addr, *malloced; | |
222 | ||
223 | if (adj->ipv4_addrs) { | |
224 | adj->ipv4_addrs->del = del_ip_addr; | |
225 | list_delete (adj->ipv4_addrs); | |
226 | } | |
227 | adj->ipv4_addrs = list_new (); | |
228 | if (tlvs->ipv4_addrs) { | |
229 | LIST_LOOP (tlvs->ipv4_addrs, ipv4_addr, node) { | |
230 | malloced = XMALLOC (MTYPE_ISIS_TMP, sizeof (struct in_addr)); | |
231 | memcpy (malloced, ipv4_addr, sizeof (struct in_addr)); | |
232 | listnode_add (adj->ipv4_addrs, malloced); | |
233 | } | |
234 | } | |
235 | } | |
236 | ||
237 | #ifdef HAVE_IPV6 | |
238 | void | |
239 | tlvs_to_adj_ipv6_addrs (struct tlvs *tlvs, struct isis_adjacency *adj) | |
240 | { | |
241 | struct listnode *node; | |
242 | struct in6_addr *ipv6_addr, *malloced; | |
243 | ||
244 | if (adj->ipv6_addrs) { | |
245 | adj->ipv6_addrs->del = del_ip_addr; | |
246 | list_delete (adj->ipv6_addrs); | |
247 | } | |
248 | adj->ipv6_addrs = list_new (); | |
249 | if (tlvs->ipv6_addrs) { | |
250 | LIST_LOOP (tlvs->ipv6_addrs, ipv6_addr, node) { | |
251 | malloced = XMALLOC (MTYPE_ISIS_TMP, sizeof (struct in6_addr)); | |
252 | memcpy (malloced, ipv6_addr, sizeof (struct in6_addr)); | |
253 | listnode_add (adj->ipv6_addrs, malloced); | |
254 | } | |
255 | } | |
256 | ||
257 | } | |
258 | #endif /* HAVE_IPV6 */ | |
259 | ||
260 | ||
261 | ||
262 | /* | |
263 | * RECEIVE SIDE | |
264 | */ | |
265 | ||
266 | /* | |
267 | * Process P2P IIH | |
268 | * ISO - 10589 | |
269 | * Section 8.2.5 - Receiving point-to-point IIH PDUs | |
270 | * | |
271 | */ | |
272 | static int | |
273 | process_p2p_hello (struct isis_circuit *circuit) | |
274 | { | |
275 | int retval = ISIS_OK; | |
276 | struct isis_p2p_hello_hdr *hdr; | |
277 | struct isis_adjacency *adj; | |
278 | u_int32_t expected = 0, found; | |
279 | struct tlvs tlvs; | |
280 | ||
281 | if ((stream_get_endp (circuit->rcv_stream) - | |
282 | stream_get_getp (circuit->rcv_stream)) < | |
283 | ISIS_P2PHELLO_HDRLEN) { | |
284 | zlog_warn ("Packet too short"); | |
285 | return ISIS_WARNING; | |
286 | } | |
287 | ||
288 | /* 8.2.5.1 PDU acceptance tests */ | |
289 | ||
290 | /* 8.2.5.1 a) external domain untrue */ | |
291 | /* FIXME: not useful at all? */ | |
292 | ||
293 | /* 8.2.5.1 b) ID Length mismatch */ | |
294 | /* checked at the handle_pdu */ | |
295 | ||
296 | /* 8.2.5.2 IIH PDU Processing */ | |
297 | ||
298 | /* 8.2.5.2 a) 1) Maximum Area Addresses */ | |
299 | /* Already checked, and can also be ommited */ | |
300 | ||
301 | /* | |
302 | * Get the header | |
303 | */ | |
304 | hdr = (struct isis_p2p_hello_hdr*) STREAM_PNT(circuit->rcv_stream); | |
305 | circuit->rcv_stream->getp += ISIS_P2PHELLO_HDRLEN; | |
306 | ||
307 | /* hdr.circuit_t = stream_getc (stream); | |
308 | stream_get (hdr.source_id, stream, ISIS_SYS_ID_LEN); | |
309 | hdr.hold_time = stream_getw (stream); | |
310 | hdr.pdu_len = stream_getw (stream); | |
311 | hdr.local_id = stream_getc (stream); */ | |
312 | ||
313 | /* | |
314 | * My interpertation of the ISO, if no adj exists we will create one for | |
315 | * the circuit | |
316 | */ | |
317 | ||
318 | if (isis->debugs & DEBUG_ADJ_PACKETS) { | |
319 | zlog_info("ISIS-Adj (%s): Rcvd P2P IIH from (%s), cir type %s," | |
320 | " cir id %02d, length %d", | |
321 | circuit->area->area_tag, circuit->interface->name, | |
322 | circuit_t2string(circuit->circuit_is_type), | |
323 | circuit->circuit_id,ntohs(hdr->pdu_len)); | |
324 | } | |
325 | ||
326 | adj = circuit->u.p2p.neighbor; | |
327 | if ( !adj ) { | |
328 | adj = isis_new_adj (hdr->source_id," ", 0, circuit); | |
329 | if (adj == NULL) | |
330 | return ISIS_ERROR; | |
331 | circuit->u.p2p.neighbor = adj; | |
332 | isis_adj_state_change(adj, ISIS_ADJ_INITIALIZING, NULL); | |
333 | adj->sys_type = ISIS_SYSTYPE_UNKNOWN; | |
334 | } | |
335 | ||
336 | /* 8.2.6 Monitoring point-to-point adjacencies */ | |
337 | adj->hold_time = ntohs (hdr->hold_time); | |
338 | adj->last_upd = time (NULL); | |
339 | ||
340 | /* | |
341 | * Lets get the TLVS now | |
342 | */ | |
343 | expected |= TLVFLAG_AREA_ADDRS; | |
344 | expected |= TLVFLAG_AUTH_INFO; | |
345 | expected |= TLVFLAG_NLPID; | |
346 | expected |= TLVFLAG_IPV4_ADDR; | |
347 | expected |= TLVFLAG_IPV6_ADDR; | |
348 | ||
349 | retval = parse_tlvs (circuit->area->area_tag, | |
350 | STREAM_PNT (circuit->rcv_stream), | |
351 | ntohs (hdr->pdu_len) - ISIS_P2PHELLO_HDRLEN | |
352 | - ISIS_FIXED_HDR_LEN, | |
353 | &expected, | |
354 | &found, | |
355 | &tlvs); | |
356 | ||
357 | if (retval > ISIS_WARNING) { | |
358 | free_tlvs (&tlvs); | |
359 | return retval; | |
360 | }; | |
361 | ||
362 | /* 8.2.5.1 c) Authentication */ | |
363 | if (circuit->passwd.type) { | |
364 | if (!(found & TLVFLAG_AUTH_INFO) || | |
365 | authentication_check (&circuit->passwd, &tlvs.auth_info)) { | |
366 | isis_event_auth_failure (circuit->area->area_tag, | |
367 | "P2P hello authentication failure", | |
368 | hdr->source_id); | |
369 | return ISIS_OK; | |
370 | } | |
371 | } | |
372 | ||
373 | /* we do this now because the adj may not survive till the end... */ | |
374 | ||
375 | /* we need to copy addresses to the adj */ | |
376 | tlvs_to_adj_ipv4_addrs (&tlvs,adj); | |
377 | ||
378 | #ifdef HAVE_IPV6 | |
379 | tlvs_to_adj_ipv6_addrs (&tlvs,adj); | |
380 | #endif /* HAVE_IPV6 */ | |
381 | ||
382 | /* lets take care of the expiry */ | |
d70f99e1 | 383 | THREAD_TIMER_OFF(adj->t_expire); |
384 | THREAD_TIMER_ON(master, adj->t_expire, isis_adj_expire, adj, | |
eb5d44eb | 385 | (long)adj->hold_time); |
386 | ||
387 | /* 8.2.5.2 a) a match was detected */ | |
388 | if (area_match (circuit->area->area_addrs, tlvs.area_addrs)) { | |
389 | /* 8.2.5.2 a) 2) If the system is L1 - table 5 */ | |
390 | if (circuit->area->is_type == IS_LEVEL_1) { | |
391 | switch (hdr->circuit_t) { | |
392 | case IS_LEVEL_1: | |
393 | case IS_LEVEL_1_AND_2: | |
394 | if (adj->adj_state != ISIS_ADJ_UP) { | |
395 | /* (4) adj state up */ | |
396 | isis_adj_state_change (adj, ISIS_ADJ_UP, NULL); | |
397 | /* (5) adj usage level 1 */ | |
398 | adj->adj_usage = ISIS_ADJ_LEVEL1; | |
399 | } else if (adj->adj_usage == ISIS_ADJ_LEVEL1) { | |
400 | ; /* accept */ | |
401 | } | |
402 | break; | |
403 | case IS_LEVEL_2: | |
404 | if (adj->adj_state != ISIS_ADJ_UP) { | |
405 | /* (7) reject - wrong system type event */ | |
406 | zlog_warn ("wrongSystemType"); | |
407 | return ISIS_WARNING; /* Reject */ | |
408 | } else if (adj->adj_usage == ISIS_ADJ_LEVEL1) { | |
409 | /* (6) down - wrong system */ | |
410 | isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System"); | |
411 | } | |
412 | break; | |
413 | } | |
414 | } | |
415 | ||
416 | /* 8.2.5.2 a) 3) If the system is L1L2 - table 6 */ | |
417 | if (circuit->area->is_type == IS_LEVEL_1_AND_2) { | |
418 | switch (hdr->circuit_t) { | |
419 | case IS_LEVEL_1: | |
420 | if (adj->adj_state != ISIS_ADJ_UP) { | |
421 | /* (6) adj state up */ | |
422 | isis_adj_state_change (adj, ISIS_ADJ_UP, NULL); | |
423 | /* (7) adj usage level 1 */ | |
424 | adj->adj_usage = ISIS_ADJ_LEVEL1; | |
425 | } else if (adj->adj_usage == ISIS_ADJ_LEVEL1) { | |
426 | ; /* accept */ | |
427 | } else if ((adj->adj_usage == ISIS_ADJ_LEVEL1AND2) || | |
428 | (adj->adj_usage == ISIS_ADJ_LEVEL2)) { | |
429 | /* (8) down - wrong system */ | |
430 | isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System"); | |
431 | } | |
432 | break; | |
433 | case IS_LEVEL_2: | |
434 | if (adj->adj_state != ISIS_ADJ_UP) { | |
435 | /* (6) adj state up */ | |
436 | isis_adj_state_change (adj, ISIS_ADJ_UP, NULL); | |
437 | /* (9) adj usage level 2 */ | |
438 | adj->adj_usage = ISIS_ADJ_LEVEL2; | |
439 | } else if ((adj->adj_usage == ISIS_ADJ_LEVEL1) || | |
440 | (adj->adj_usage == ISIS_ADJ_LEVEL1AND2)) { | |
441 | /* (8) down - wrong system */ | |
442 | isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System"); | |
443 | } else if (adj->adj_usage == ISIS_ADJ_LEVEL2) { | |
444 | ; /* Accept */ | |
445 | } | |
446 | break; | |
447 | case IS_LEVEL_1_AND_2: | |
448 | if (adj->adj_state != ISIS_ADJ_UP) { | |
449 | /* (6) adj state up */ | |
450 | isis_adj_state_change (adj, ISIS_ADJ_UP, NULL); | |
451 | /* (10) adj usage level 1 */ | |
452 | adj->adj_usage = ISIS_ADJ_LEVEL1AND2; | |
453 | } else if ((adj->adj_usage == ISIS_ADJ_LEVEL1) || | |
454 | (adj->adj_usage == ISIS_ADJ_LEVEL2)) { | |
455 | /* (8) down - wrong system */ | |
456 | isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System"); | |
457 | } else if (adj->adj_usage == ISIS_ADJ_LEVEL1AND2) { | |
458 | ; /* Accept */ | |
459 | } | |
460 | break; | |
461 | } | |
462 | } | |
463 | ||
464 | /* 8.2.5.2 a) 4) If the system is L2 - table 7 */ | |
465 | if (circuit->area->is_type == IS_LEVEL_2) { | |
466 | switch (hdr->circuit_t) { | |
467 | case IS_LEVEL_1: | |
468 | if (adj->adj_state != ISIS_ADJ_UP) { | |
469 | /* (5) reject - wrong system type event */ | |
470 | zlog_warn ("wrongSystemType"); | |
471 | return ISIS_WARNING; /* Reject */ | |
472 | } else if ((adj->adj_usage == ISIS_ADJ_LEVEL1AND2) || | |
473 | (adj->adj_usage == ISIS_ADJ_LEVEL2)) { | |
474 | /* (6) down - wrong system */ | |
475 | isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System"); | |
476 | } | |
477 | break; | |
478 | case IS_LEVEL_1_AND_2: | |
479 | case IS_LEVEL_2: | |
480 | if (adj->adj_state != ISIS_ADJ_UP) { | |
481 | /* (7) adj state up */ | |
482 | isis_adj_state_change (adj, ISIS_ADJ_UP, NULL); | |
483 | /* (8) adj usage level 2 */ | |
484 | adj->adj_usage = ISIS_ADJ_LEVEL2; | |
485 | } else if (adj->adj_usage == ISIS_ADJ_LEVEL1AND2) { | |
486 | /* (6) down - wrong system */ | |
487 | isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System"); | |
488 | } else if (adj->adj_usage == ISIS_ADJ_LEVEL2) { | |
489 | ; /* Accept */ | |
490 | } | |
491 | break; | |
492 | } | |
493 | } | |
494 | } | |
495 | /* 8.2.5.2 b) if no match was detected */ | |
496 | else | |
497 | { | |
498 | if (circuit->area->is_type == IS_LEVEL_1) { | |
499 | /* 8.2.5.2 b) 1) is_type L1 and adj is not up */ | |
500 | if (adj->adj_state != ISIS_ADJ_UP) { | |
501 | isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Area Mismatch"); | |
502 | /* 8.2.5.2 b) 2)is_type L1 and adj is up */ | |
503 | } else { | |
504 | isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Down - Area Mismatch"); | |
505 | } | |
506 | } | |
507 | /* 8.2.5.2 b 3 If the system is L2 or L1L2 - table 8 */ | |
508 | else | |
509 | { | |
510 | switch (hdr->circuit_t) { | |
511 | case IS_LEVEL_1: | |
512 | if (adj->adj_state != ISIS_ADJ_UP) { | |
513 | /* (6) reject - Area Mismatch event */ | |
514 | zlog_warn ("AreaMismatch"); | |
515 | return ISIS_WARNING; /* Reject */ | |
516 | } else if (adj->adj_usage == ISIS_ADJ_LEVEL1) { | |
517 | /* (7) down - area mismatch */ | |
518 | isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Area Mismatch"); | |
519 | ||
520 | } else if ((adj->adj_usage == ISIS_ADJ_LEVEL1AND2) || | |
521 | (adj->adj_usage == ISIS_ADJ_LEVEL2)) { | |
522 | /* (7) down - wrong system */ | |
523 | isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System"); | |
524 | } | |
525 | break; | |
526 | case IS_LEVEL_1_AND_2: | |
527 | case IS_LEVEL_2: | |
528 | if (adj->adj_state != ISIS_ADJ_UP) { | |
529 | /* (8) adj state up */ | |
530 | isis_adj_state_change (adj, ISIS_ADJ_UP, NULL); | |
531 | /* (9) adj usage level 2 */ | |
532 | adj->adj_usage = ISIS_ADJ_LEVEL2; | |
533 | } else if (adj->adj_usage == ISIS_ADJ_LEVEL1) { | |
534 | /* (7) down - wrong system */ | |
535 | isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System"); | |
536 | } else if (adj->adj_usage == ISIS_ADJ_LEVEL1AND2) { | |
537 | if (hdr->circuit_t == IS_LEVEL_2) { | |
538 | /* (7) down - wrong system */ | |
539 | isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System"); | |
540 | } else { | |
541 | /* (7) down - area mismatch */ | |
542 | isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Area Mismatch"); | |
543 | } | |
544 | } else if (adj->adj_usage == ISIS_ADJ_LEVEL2) { | |
545 | ; /* Accept */ | |
546 | } | |
547 | break; | |
548 | } | |
549 | } | |
550 | } | |
551 | /* 8.2.5.2 c) if the action was up - comparing circuit IDs */ | |
552 | /* FIXME - Missing parts */ | |
553 | ||
554 | ||
555 | /* some of my own understanding of the ISO, why the heck does | |
556 | * it not say what should I change the system_type to... | |
557 | */ | |
558 | switch (adj->adj_usage) { | |
559 | case ISIS_ADJ_LEVEL1: | |
560 | adj->sys_type = ISIS_SYSTYPE_L1_IS; | |
561 | break; | |
562 | case ISIS_ADJ_LEVEL2: | |
563 | adj->sys_type = ISIS_SYSTYPE_L2_IS; | |
564 | break; | |
565 | case ISIS_ADJ_LEVEL1AND2: | |
566 | adj->sys_type = ISIS_SYSTYPE_L2_IS; | |
567 | break; | |
568 | case ISIS_ADJ_NONE: | |
569 | adj->sys_type = ISIS_SYSTYPE_UNKNOWN; | |
570 | break; | |
571 | } | |
572 | ||
573 | adj->circuit_t = hdr->circuit_t; | |
574 | adj->level = hdr->circuit_t; | |
575 | ||
576 | free_tlvs (&tlvs); | |
577 | ||
578 | return retval; | |
579 | } | |
580 | ||
581 | ||
582 | /* | |
583 | * Process IS-IS LAN Level 1/2 Hello PDU | |
584 | */ | |
585 | static int | |
586 | process_lan_hello (int level, struct isis_circuit *circuit, u_char *ssnpa) | |
587 | { | |
588 | int retval = ISIS_OK; | |
589 | struct isis_lan_hello_hdr hdr; | |
590 | struct isis_adjacency *adj; | |
591 | u_int32_t expected = 0, found; | |
592 | struct tlvs tlvs; | |
593 | u_char *snpa; | |
594 | struct listnode *node; | |
595 | ||
596 | if ((stream_get_endp (circuit->rcv_stream) - | |
597 | stream_get_getp (circuit->rcv_stream)) < ISIS_LANHELLO_HDRLEN) { | |
598 | zlog_warn ("Packet too short"); | |
599 | return ISIS_WARNING; | |
600 | } | |
601 | ||
602 | if (circuit->ext_domain) { | |
603 | zlog_info ("level %d LAN Hello received over circuit with " | |
604 | "externalDomain = true", level); | |
605 | return ISIS_WARNING; | |
606 | } | |
607 | ||
608 | if (!accept_level (level, circuit->circuit_is_type)) { | |
609 | if (isis->debugs & DEBUG_ADJ_PACKETS) { | |
610 | zlog_info ("ISIS-Adj (%s): Interface level mismatch, %s", | |
611 | circuit->area->area_tag, circuit->interface->name); | |
612 | } | |
613 | return ISIS_WARNING; | |
614 | } | |
615 | ||
616 | #if 0 | |
617 | /* Cisco's debug message compatability */ | |
618 | if (!accept_level (level, circuit->area->is_type)) { | |
619 | if (isis->debugs & DEBUG_ADJ_PACKETS) { | |
620 | zlog_info ("ISIS-Adj (%s): is type mismatch", | |
621 | circuit->area->area_tag); | |
622 | } | |
623 | return ISIS_WARNING; | |
624 | } | |
625 | #endif | |
626 | /* | |
627 | * Fill the header | |
628 | */ | |
629 | hdr.circuit_t = stream_getc (circuit->rcv_stream); | |
630 | stream_get (hdr.source_id, circuit->rcv_stream, ISIS_SYS_ID_LEN); | |
631 | hdr.hold_time = stream_getw (circuit->rcv_stream); | |
632 | hdr.pdu_len = stream_getw (circuit->rcv_stream); | |
633 | hdr.prio = stream_getc (circuit->rcv_stream); | |
634 | stream_get (hdr.lan_id, circuit->rcv_stream, ISIS_SYS_ID_LEN + 1); | |
635 | ||
636 | if (hdr.circuit_t != IS_LEVEL_1 && hdr.circuit_t != IS_LEVEL_2 && | |
637 | hdr.circuit_t != IS_LEVEL_1_AND_2 ) { | |
638 | zlog_warn ("Level %d LAN Hello with Circuit Type %d", level, | |
639 | hdr.circuit_t); | |
640 | return ISIS_ERROR; | |
641 | } | |
642 | /* | |
643 | * Then get the tlvs | |
644 | */ | |
645 | expected |= TLVFLAG_AUTH_INFO; | |
646 | expected |= TLVFLAG_AREA_ADDRS; | |
647 | expected |= TLVFLAG_LAN_NEIGHS; | |
648 | expected |= TLVFLAG_NLPID; | |
649 | expected |= TLVFLAG_IPV4_ADDR; | |
650 | expected |= TLVFLAG_IPV6_ADDR; | |
651 | ||
652 | retval = parse_tlvs (circuit->area->area_tag, | |
653 | STREAM_PNT (circuit->rcv_stream), | |
654 | hdr.pdu_len - ISIS_LANHELLO_HDRLEN - ISIS_FIXED_HDR_LEN, | |
655 | &expected, | |
656 | &found, | |
657 | &tlvs); | |
658 | ||
659 | if (retval > ISIS_WARNING) { | |
660 | zlog_warn ("parse_tlvs() failed"); | |
661 | goto out; | |
662 | } | |
663 | ||
664 | if (!(found & TLVFLAG_AREA_ADDRS)) { | |
665 | zlog_warn ("No Area addresses TLV in Level %d LAN IS to IS hello", level); | |
666 | retval = ISIS_WARNING; | |
667 | goto out; | |
668 | } | |
669 | ||
670 | if (circuit->passwd.type) { | |
671 | if (!(found & TLVFLAG_AUTH_INFO) || | |
672 | authentication_check (&circuit->passwd, &tlvs.auth_info)) { | |
673 | isis_event_auth_failure (circuit->area->area_tag, | |
674 | "LAN hello authentication failure", | |
675 | hdr.source_id); | |
676 | retval = ISIS_WARNING; | |
677 | goto out; | |
678 | } | |
679 | } | |
680 | ||
681 | /* | |
682 | * Accept the level 1 adjacency only if a match between local and | |
683 | * remote area addresses is found | |
684 | */ | |
685 | if (level == 1 && !area_match (circuit->area->area_addrs, tlvs.area_addrs)) { | |
686 | if (isis->debugs & DEBUG_ADJ_PACKETS) { | |
687 | zlog_info ("ISIS-Adj (%s): Area mismatch, level %d IIH on %s", | |
688 | circuit->area->area_tag, level,circuit->interface->name); | |
689 | } | |
690 | retval = ISIS_OK; | |
691 | goto out; | |
692 | } | |
693 | ||
694 | /* | |
695 | * it's own IIH PDU - discard silently | |
696 | */ | |
697 | if (!memcmp (circuit->u.bc.snpa, ssnpa, ETH_ALEN)) { | |
698 | zlog_info ("ISIS-Adj (%s): it's own IIH PDU - discarded", | |
699 | circuit->area->area_tag); | |
700 | ||
701 | retval = ISIS_OK; | |
702 | goto out; | |
703 | } | |
704 | ||
705 | /* | |
706 | * check if it's own interface ip match iih ip addrs | |
707 | */ | |
708 | if (!(found & TLVFLAG_IPV4_ADDR) || !ip_match(circuit->ip_addrs, tlvs.ipv4_addrs)) { | |
709 | zlog_info("ISIS-Adj: No usable IP interface addresses in LAN IIH from %s\n", | |
710 | circuit->interface->name); | |
711 | retval = ISIS_WARNING; | |
712 | goto out; | |
713 | } | |
714 | ||
715 | ||
716 | adj = isis_adj_lookup (hdr.source_id, circuit->u.bc.adjdb[level - 1]); | |
717 | if (!adj) { | |
718 | /* | |
719 | * Do as in 8.4.2.5 | |
720 | */ | |
721 | adj = isis_new_adj (hdr.source_id, ssnpa, level, circuit); | |
722 | if (adj == NULL) | |
723 | retval = ISIS_ERROR; | |
724 | goto out; | |
725 | ||
726 | adj->level = level; | |
727 | isis_adj_state_change(adj, ISIS_ADJ_INITIALIZING, NULL); | |
728 | ||
729 | if (level == 1) { | |
730 | adj->sys_type = ISIS_SYSTYPE_L1_IS; | |
731 | } else { | |
732 | adj->sys_type = ISIS_SYSTYPE_L2_IS; | |
733 | } | |
734 | list_delete_all_node (circuit->u.bc.lan_neighs[level - 1]); | |
735 | isis_adj_build_neigh_list (circuit->u.bc.adjdb[level - 1], | |
736 | circuit->u.bc.lan_neighs[level - 1]); | |
737 | } | |
738 | ||
739 | switch (level) { | |
740 | case 1 : | |
741 | if (memcmp(circuit->u.bc.l1_desig_is, hdr.lan_id, ISIS_SYS_ID_LEN + 1)) { | |
742 | thread_add_event (master, isis_event_dis_status_change, circuit, 0); | |
743 | memcpy (&circuit->u.bc.l1_desig_is, hdr.lan_id, ISIS_SYS_ID_LEN + 1); | |
744 | } | |
745 | break; | |
746 | case 2 : | |
747 | if (memcmp (circuit->u.bc.l2_desig_is, hdr.lan_id, ISIS_SYS_ID_LEN + 1)) { | |
748 | thread_add_event (master, isis_event_dis_status_change, circuit, 0); | |
749 | memcpy (&circuit->u.bc.l2_desig_is, hdr.lan_id, ISIS_SYS_ID_LEN + 1); | |
750 | } | |
751 | break; | |
752 | } | |
753 | ||
754 | #if 0 | |
755 | /* Old solution: believe the lan-header always | |
756 | */ | |
757 | if (level == 1) { | |
758 | memcpy(circuit->u.bc.l1_desig_is, hdr.lan_id, ISIS_SYS_ID_LEN + 1); | |
759 | } else if (level == 2) { | |
760 | memcpy(circuit->u.bc.l2_desig_is, hdr.lan_id, ISIS_SYS_ID_LEN + 1); | |
761 | } | |
762 | #endif | |
763 | ||
764 | adj->hold_time = hdr.hold_time; | |
765 | adj->last_upd = time (NULL); | |
766 | adj->prio[level-1] = hdr.prio; | |
767 | ||
768 | memcpy (adj->lanid, hdr.lan_id, ISIS_SYS_ID_LEN + 1); | |
769 | ||
770 | /* which protocol are spoken ??? */ | |
771 | if (found & TLVFLAG_NLPID) | |
772 | tlvs_to_adj_nlpids (&tlvs, adj); | |
773 | ||
774 | /* we need to copy addresses to the adj */ | |
775 | if (found & TLVFLAG_IPV4_ADDR) | |
776 | tlvs_to_adj_ipv4_addrs (&tlvs, adj); | |
777 | ||
778 | #ifdef HAVE_IPV6 | |
779 | if (found & TLVFLAG_IPV6_ADDR) | |
780 | tlvs_to_adj_ipv6_addrs (&tlvs, adj); | |
781 | #endif /* HAVE_IPV6 */ | |
782 | ||
783 | adj->circuit_t = hdr.circuit_t; | |
784 | ||
785 | /* lets take care of the expiry */ | |
d70f99e1 | 786 | THREAD_TIMER_OFF(adj->t_expire); |
787 | THREAD_TIMER_ON(master, adj->t_expire, isis_adj_expire, adj, | |
eb5d44eb | 788 | (long)adj->hold_time); |
789 | ||
790 | /* | |
791 | * If the snpa for this circuit is found from LAN Neighbours TLV | |
792 | * we have two-way communication -> adjacency can be put to state "up" | |
793 | */ | |
794 | ||
795 | if (found & TLVFLAG_LAN_NEIGHS) { | |
796 | if (adj->adj_state != ISIS_ADJ_UP) { | |
797 | LIST_LOOP (tlvs.lan_neighs, snpa, node) | |
798 | if (!memcmp (snpa, circuit->u.bc.snpa, ETH_ALEN)) { | |
799 | isis_adj_state_change (adj, ISIS_ADJ_UP, | |
800 | "own SNPA found in LAN Neighbours TLV"); | |
801 | } | |
802 | } | |
803 | } | |
804 | ||
805 | out: | |
806 | /* DEBUG_ADJ_PACKETS */ | |
807 | if (isis->debugs & DEBUG_ADJ_PACKETS) { | |
808 | /* FIXME: is this place right? fix missing info */ | |
809 | zlog_info ("ISIS-Adj (%s): Rcvd L%d LAN IIH from %s on %s, cirType %s, " | |
810 | "cirID %u, length %ld", | |
811 | circuit->area->area_tag, | |
812 | level,snpa_print(ssnpa), circuit->interface->name, | |
813 | circuit_t2string(circuit->circuit_is_type), | |
814 | circuit->circuit_id, | |
815 | stream_get_endp (circuit->rcv_stream)); | |
816 | } | |
817 | ||
818 | ||
819 | free_tlvs (&tlvs); | |
820 | ||
821 | return retval; | |
822 | } | |
823 | ||
824 | /* | |
825 | * Process Level 1/2 Link State | |
826 | * ISO - 10589 | |
827 | * Section 7.3.15.1 - Action on receipt of a link state PDU | |
828 | */ | |
829 | static int | |
830 | process_lsp (int level, struct isis_circuit *circuit, u_char *ssnpa) | |
831 | { | |
832 | struct isis_link_state_hdr *hdr; | |
833 | struct isis_adjacency *adj = NULL; | |
834 | struct isis_lsp *lsp, *lsp0 = NULL; | |
835 | int retval = ISIS_OK, comp = 0; | |
836 | u_char lspid[ISIS_SYS_ID_LEN + 2]; | |
837 | struct isis_passwd *passwd; | |
838 | ||
839 | /* Sanity check - FIXME: move to correct place */ | |
840 | if ((stream_get_endp (circuit->rcv_stream) - | |
841 | stream_get_getp (circuit->rcv_stream)) < ISIS_LSP_HDR_LEN ) { | |
842 | zlog_warn ("Packet too short"); | |
843 | return ISIS_WARNING; | |
844 | } | |
845 | ||
846 | /* Reference the header */ | |
847 | hdr = (struct isis_link_state_hdr*)STREAM_PNT (circuit->rcv_stream); | |
848 | ||
849 | if (isis->debugs & DEBUG_UPDATE_PACKETS) { | |
850 | zlog_info ("ISIS-Upd (%s): Rcvd L%d LSP %s, seq 0x%08x, cksum 0x%04x, " | |
851 | "lifetime %us, len %lu, on %s", | |
852 | circuit->area->area_tag, | |
853 | level, | |
854 | rawlspid_print(hdr->lsp_id), | |
855 | ntohl(hdr->seq_num), | |
856 | ntohs(hdr->checksum), | |
857 | ntohs(hdr->rem_lifetime), | |
858 | circuit->rcv_stream->endp, | |
859 | circuit->interface->name); | |
860 | } | |
861 | ||
862 | assert (ntohs (hdr->pdu_len) > ISIS_LSP_HDR_LEN); | |
863 | ||
864 | /* Checksum sanity check - FIXME: move to correct place */ | |
865 | /* 12 = sysid+pdu+remtime */ | |
866 | if (iso_csum_verify (STREAM_PNT (circuit->rcv_stream) + 4, | |
867 | ntohs (hdr->pdu_len) - 12, &hdr->checksum)) { | |
868 | zlog_info ("ISIS-Upd (%s): LSP %s invalid LSP checksum 0x%04x", | |
869 | circuit->area->area_tag, | |
870 | rawlspid_print (hdr->lsp_id), | |
871 | ntohs(hdr->checksum)); | |
872 | ||
873 | return ISIS_WARNING; | |
874 | } | |
875 | ||
876 | /* 7.3.15.1 a) 1 - external domain circuit will discard lsps */ | |
877 | if (circuit->ext_domain) { | |
878 | zlog_info ("ISIS-Upd (%s): LSP %s received at level %d over circuit with " | |
879 | "externalDomain = true", | |
880 | circuit->area->area_tag, | |
881 | rawlspid_print (hdr->lsp_id), | |
882 | level); | |
883 | ||
884 | return ISIS_WARNING; | |
885 | } | |
886 | ||
887 | /* 7.3.15.1 a) 2,3 - manualL2OnlyMode not implemented */ | |
888 | if (!accept_level (level, circuit->circuit_is_type)) { | |
889 | zlog_info ("ISIS-Upd (%s): LSP %s received at level %d over circuit of" | |
890 | " type %s", | |
891 | circuit->area->area_tag, | |
892 | rawlspid_print(hdr->lsp_id), | |
893 | level, | |
894 | circuit_t2string (circuit->circuit_is_type)); | |
895 | ||
896 | return ISIS_WARNING; | |
897 | } | |
898 | ||
899 | /* 7.3.15.1 a) 4 - need to make sure IDLength matches */ | |
900 | ||
901 | /* 7.3.15.1 a) 5 - maximum area match, can be ommited since we only use 3 */ | |
902 | ||
903 | /* 7.3.15.1 a) 7 - password check */ | |
904 | (level == ISIS_LEVEL1) ? (passwd = &circuit->area->area_passwd) : | |
905 | (passwd = &circuit->area->domain_passwd); | |
906 | if (passwd->type) { | |
907 | if (isis_lsp_authinfo_check (circuit->rcv_stream, circuit->area, | |
908 | ntohs (hdr->pdu_len), passwd)) { | |
909 | isis_event_auth_failure (circuit->area->area_tag, | |
910 | "LSP authentication failure", | |
911 | hdr->lsp_id); | |
912 | return ISIS_WARNING; | |
913 | } | |
914 | } | |
915 | /* Find the LSP in our database and compare it to this Link State header */ | |
916 | lsp = lsp_search (hdr->lsp_id, circuit->area->lspdb[level - 1]); | |
917 | if (lsp) | |
918 | comp = lsp_compare (circuit->area->area_tag, lsp, hdr->seq_num, | |
919 | hdr->checksum, hdr->rem_lifetime); | |
920 | if (lsp && (lsp->own_lsp | |
921 | #ifdef TOPOLOGY_GENERATE | |
922 | || lsp->from_topology | |
923 | #endif /* TOPOLOGY_GENERATE */ | |
924 | )) | |
925 | goto dontcheckadj; | |
926 | ||
927 | /* 7.3.15.1 a) 6 - Must check that we have an adjacency of the same level */ | |
928 | /* for broadcast circuits, snpa should be compared */ | |
929 | /* FIXME : Point To Point */ | |
930 | ||
931 | if (circuit->circ_type == CIRCUIT_T_BROADCAST) { | |
932 | adj = isis_adj_lookup_snpa (ssnpa, circuit->u.bc.adjdb[level - 1]); | |
933 | if (!adj) { | |
934 | zlog_info ("(%s): DS ======= LSP %s, seq 0x%08x, cksum 0x%04x, " | |
935 | "lifetime %us on %s", | |
936 | circuit->area->area_tag, | |
937 | rawlspid_print (hdr->lsp_id), | |
938 | ntohl (hdr->seq_num), | |
939 | ntohs (hdr->checksum), | |
940 | ntohs (hdr->rem_lifetime), | |
941 | circuit->interface->name); | |
942 | return ISIS_WARNING; /* Silently discard */ | |
943 | } | |
944 | } | |
945 | ||
946 | /* for non broadcast, we just need to find same level adj */ | |
947 | else { | |
948 | /* If no adj, or no sharing of level */ | |
949 | if (!circuit->u.p2p.neighbor) { | |
950 | return ISIS_OK; /* Silently discard */ | |
951 | } else { | |
952 | if (((level == 1) && | |
953 | (circuit->u.p2p.neighbor->adj_usage == ISIS_ADJ_LEVEL2)) || | |
954 | ((level == 2) && | |
955 | (circuit->u.p2p.neighbor->adj_usage == ISIS_ADJ_LEVEL1))) | |
956 | return ISIS_WARNING; /* Silently discard */ | |
957 | } | |
958 | } | |
959 | dontcheckadj: | |
960 | /* 7.3.15.1 a) 7 - Passwords for level 1 - not implemented */ | |
961 | ||
962 | /* 7.3.15.1 a) 8 - Passwords for level 2 - not implemented */ | |
963 | ||
964 | /* 7.3.15.1 a) 9 - OriginatingLSPBufferSize - not implemented FIXME: do it*/ | |
965 | ||
966 | ||
967 | /* 7.3.15.1 b) - If the remaining life time is 0, we perform 7.3.16.4*/ | |
968 | if (hdr->rem_lifetime == 0) { | |
969 | if (!lsp) { | |
970 | /* 7.3.16.4 a) 1) No LSP in db -> send an ack, but don't save */ | |
971 | /* only needed on explicit update, eg - p2p */ | |
972 | if (circuit->circ_type == CIRCUIT_T_P2P) | |
973 | ack_lsp (hdr, circuit, level); | |
974 | return retval; /* FIXME: do we need a purge? */ | |
975 | } else { | |
976 | if (memcmp (hdr->lsp_id, isis->sysid, ISIS_SYS_ID_LEN )) { | |
977 | /* LSP by some other system -> do 7.3.16.4 b) */ | |
978 | /* 7.3.16.4 b) 1) */ | |
979 | if (comp == LSP_NEWER) { | |
980 | lsp_update (lsp, hdr, circuit->rcv_stream, circuit->area); | |
981 | /* ii */ | |
982 | ISIS_FLAGS_SET_ALL (lsp->SRMflags); | |
983 | /* iii */ | |
984 | ISIS_CLEAR_FLAG (lsp->SRMflags, circuit); | |
985 | /* v */ | |
986 | ISIS_FLAGS_CLEAR_ALL(lsp->SSNflags); /* FIXME: OTHER than c */ | |
987 | /* iv */ | |
988 | if (circuit->circ_type != CIRCUIT_T_BROADCAST) | |
989 | ISIS_SET_FLAG(lsp->SSNflags, circuit); | |
990 | ||
991 | } /* 7.3.16.4 b) 2) */ | |
992 | else if (comp == LSP_EQUAL) { | |
993 | /* i */ | |
994 | ISIS_CLEAR_FLAG(lsp->SRMflags, circuit); | |
995 | /* ii*/ | |
996 | if (circuit->circ_type != CIRCUIT_T_BROADCAST) | |
997 | ISIS_SET_FLAG(lsp->SSNflags, circuit); | |
998 | } /* 7.3.16.4 b) 3) */ | |
999 | else { | |
1000 | ISIS_SET_FLAG(lsp->SRMflags, circuit); | |
1001 | ISIS_CLEAR_FLAG(lsp->SSNflags, circuit); | |
1002 | } | |
1003 | } else { | |
1004 | /* our own LSP -> 7.3.16.4 c) */ | |
1005 | if (LSP_PSEUDO_ID(lsp->lsp_header->lsp_id) != circuit->circuit_id || | |
1006 | (LSP_PSEUDO_ID(lsp->lsp_header->lsp_id) == circuit->circuit_id && | |
1007 | circuit->u.bc.is_dr[level - 1] == 1) ) { | |
1008 | lsp->lsp_header->seq_num = htonl (ntohl (hdr->seq_num) + 1); | |
1009 | zlog_info ("LSP LEN: %d", ntohs (lsp->lsp_header->pdu_len)); | |
1010 | iso_csum_create (STREAM_DATA (lsp->pdu) + 12, | |
1011 | ntohs (lsp->lsp_header->pdu_len) - 12, 12); | |
1012 | ISIS_FLAGS_SET_ALL (lsp->SRMflags); | |
1013 | zlog_info ("ISIS-Upd (%s): (1) re-originating LSP %s new seq 0x%08x", | |
1014 | circuit->area->area_tag, | |
1015 | rawlspid_print (hdr->lsp_id), | |
1016 | ntohl (lsp->lsp_header->seq_num)); | |
1017 | lsp->lsp_header->rem_lifetime = htons (isis_jitter | |
1018 | (circuit->area-> | |
1019 | max_lsp_lifetime[level-1], | |
1020 | MAX_AGE_JITTER)); | |
1021 | ||
1022 | } else { | |
1023 | /* Got purge for own pseudo-lsp, and we are not DR */ | |
1024 | lsp_purge_dr (lsp->lsp_header->lsp_id, circuit, level); | |
1025 | } | |
1026 | } | |
1027 | } | |
1028 | return retval; | |
1029 | } | |
1030 | /* 7.3.15.1 c) - If this is our own lsp and we don't have it initiate a | |
1031 | * purge */ | |
1032 | if (memcmp (hdr->lsp_id, isis->sysid, ISIS_SYS_ID_LEN ) == 0) { | |
1033 | if (!lsp) { | |
1034 | /* 7.3.16.4: initiate a purge */ | |
1035 | lsp_purge_non_exist (hdr, circuit->area); | |
1036 | return ISIS_OK; | |
1037 | } | |
1038 | /* 7.3.15.1 d) - If this is our own lsp and we have it */ | |
1039 | ||
1040 | /* In 7.3.16.1, If an Intermediate system R somewhere in the domain | |
1041 | * has information that the current sequence number for source S is | |
1042 | * "greater" than that held by S, ... */ | |
1043 | ||
1044 | else if (ntohl (hdr->seq_num) > ntohl (lsp->lsp_header->seq_num)) { | |
1045 | /* 7.3.16.1 */ | |
1046 | lsp->lsp_header->seq_num = htonl (ntohl (hdr->seq_num) + 1); | |
1047 | ||
1048 | iso_csum_create (STREAM_DATA (lsp->pdu) + 12, | |
1049 | ntohs(lsp->lsp_header->pdu_len) - 12, 12); | |
1050 | ||
1051 | ISIS_FLAGS_SET_ALL (lsp->SRMflags); | |
1052 | zlog_info ("ISIS-Upd (%s): (2) re-originating LSP %s new seq 0x%08x", | |
1053 | circuit->area->area_tag, | |
1054 | rawlspid_print (hdr->lsp_id), | |
1055 | ntohl (lsp->lsp_header->seq_num)); | |
1056 | lsp->lsp_header->rem_lifetime = htons (isis_jitter | |
1057 | (circuit-> | |
1058 | area->max_lsp_lifetime[level-1], | |
1059 | MAX_AGE_JITTER)); | |
1060 | ||
1061 | } | |
1062 | } else { | |
1063 | /* 7.3.15.1 e) - This lsp originated on another system */ | |
1064 | ||
1065 | /* 7.3.15.1 e) 1) LSP newer than the one in db or no LSP in db */ | |
1066 | if ((!lsp || comp == LSP_NEWER)){ | |
1067 | /* i */ | |
1068 | if (lsp) { | |
1069 | #ifdef EXTREME_DEBUG | |
1070 | zlog_info ("level %d number is - %ld", level, | |
1071 | circuit->area->lspdb[level-1]->dict_nodecount); | |
1072 | #endif /* EXTREME DEBUG */ | |
1073 | lsp_search_and_destroy (hdr->lsp_id, circuit->area->lspdb[level-1]); | |
1074 | /* exists, so we overwrite */ | |
1075 | #ifdef EXTREME_DEBUG | |
1076 | zlog_info ("level %d number is - %ld",level, | |
1077 | circuit->area->lspdb[level-1]->dict_nodecount); | |
1078 | #endif /* EXTREME DEBUG */ | |
1079 | } | |
1080 | /* | |
1081 | * If this lsp is a frag, need to see if we have zero lsp present | |
1082 | */ | |
1083 | if (LSP_FRAGMENT (hdr->lsp_id) != 0) { | |
1084 | memcpy (lspid, hdr->lsp_id, ISIS_SYS_ID_LEN + 1); | |
1085 | LSP_FRAGMENT (lspid) = 0; | |
1086 | lsp0 = lsp_search (lspid, circuit->area->lspdb[level - 1]); | |
1087 | if (!lsp0) { | |
1088 | zlog_info ("Got lsp frag, while zero lsp not database"); | |
1089 | return ISIS_OK; | |
1090 | } | |
1091 | } | |
1092 | lsp = lsp_new_from_stream_ptr (circuit->rcv_stream, ntohs (hdr->pdu_len), | |
1093 | lsp0, circuit->area); | |
1094 | lsp->level = level; | |
1095 | lsp->adj = adj; | |
1096 | lsp_insert (lsp, circuit->area->lspdb[level-1]); | |
1097 | /* ii */ | |
1098 | ISIS_FLAGS_SET_ALL (lsp->SRMflags); | |
1099 | /* iii */ | |
1100 | ISIS_CLEAR_FLAG (lsp->SRMflags, circuit); | |
1101 | ||
1102 | /* iv */ | |
1103 | if (circuit->circ_type != CIRCUIT_T_BROADCAST) | |
1104 | ISIS_SET_FLAG (lsp->SSNflags, circuit); | |
1105 | /* FIXME: v) */ | |
1106 | } | |
1107 | /* 7.3.15.1 e) 2) LSP equal to the one in db */ | |
1108 | else if (comp == LSP_EQUAL) { | |
1109 | ISIS_CLEAR_FLAG (lsp->SRMflags, circuit); | |
1110 | lsp_update (lsp, hdr, circuit->rcv_stream, circuit->area); | |
1111 | if (circuit->circ_type != CIRCUIT_T_BROADCAST) { | |
1112 | ISIS_SET_FLAG (lsp->SSNflags, circuit); | |
1113 | } | |
1114 | } | |
1115 | /* 7.3.15.1 e) 3) LSP older than the one in db */ | |
1116 | else { | |
1117 | ISIS_SET_FLAG(lsp->SRMflags, circuit); | |
1118 | ISIS_CLEAR_FLAG(lsp->SSNflags, circuit); | |
1119 | } | |
1120 | } | |
1121 | if (lsp) | |
1122 | lsp->adj = adj; | |
1123 | return retval; | |
1124 | } | |
1125 | ||
1126 | /* | |
1127 | * Process Sequence Numbers | |
1128 | * ISO - 10589 | |
1129 | * Section 7.3.15.2 - Action on receipt of a sequence numbers PDU | |
1130 | */ | |
1131 | ||
1132 | int | |
1133 | process_snp (int snp_type, int level, struct isis_circuit *circuit, | |
1134 | u_char *ssnpa) | |
1135 | { | |
1136 | int retval = ISIS_OK; | |
1137 | int cmp, own_lsp; | |
1138 | char typechar = ' '; | |
1139 | int len; | |
1140 | struct isis_adjacency *adj; | |
1141 | struct isis_complete_seqnum_hdr *chdr = NULL; | |
1142 | struct isis_partial_seqnum_hdr *phdr = NULL; | |
1143 | uint32_t found = 0, expected = 0; | |
1144 | struct isis_lsp *lsp; | |
1145 | struct lsp_entry *entry; | |
1146 | struct listnode *node,*node2; | |
1147 | struct tlvs tlvs; | |
1148 | struct list *lsp_list = NULL; | |
1149 | struct isis_passwd *passwd; | |
1150 | ||
1151 | if (snp_type == ISIS_SNP_CSNP_FLAG) { | |
1152 | /* getting the header info */ | |
1153 | typechar = 'C'; | |
1154 | chdr = (struct isis_complete_seqnum_hdr*)STREAM_PNT(circuit->rcv_stream); | |
1155 | circuit->rcv_stream->getp += ISIS_CSNP_HDRLEN; | |
1156 | len = ntohs(chdr->pdu_len); | |
1157 | if (len < ISIS_CSNP_HDRLEN) { | |
1158 | zlog_warn ("Received a CSNP with bogus length!"); | |
1159 | return ISIS_OK; | |
1160 | } | |
1161 | } else { | |
1162 | typechar = 'P'; | |
1163 | phdr = (struct isis_partial_seqnum_hdr*)STREAM_PNT(circuit->rcv_stream); | |
1164 | circuit->rcv_stream->getp += ISIS_PSNP_HDRLEN; | |
1165 | len = ntohs(phdr->pdu_len); | |
1166 | if (len < ISIS_PSNP_HDRLEN) { | |
1167 | zlog_warn ("Received a CSNP with bogus length!"); | |
1168 | return ISIS_OK; | |
1169 | } | |
1170 | } | |
1171 | ||
1172 | /* 7.3.15.2 a) 1 - external domain circuit will discard snp pdu */ | |
1173 | if (circuit->ext_domain) { | |
1174 | ||
1175 | zlog_info ("ISIS-Snp (%s): Rcvd L%d %cSNP on %s, " | |
1176 | "skipping: circuit externalDomain = true", | |
1177 | circuit->area->area_tag, | |
1178 | level, | |
1179 | typechar, | |
1180 | circuit->interface->name); | |
1181 | ||
1182 | return ISIS_OK; | |
1183 | } | |
1184 | ||
1185 | /* 7.3.15.2 a) 2,3 - manualL2OnlyMode not implemented */ | |
1186 | if (!accept_level (level, circuit->circuit_is_type)) { | |
1187 | ||
1188 | zlog_info ("ISIS-Snp (%s): Rcvd L%d %cSNP on %s, " | |
1189 | "skipping: circuit type %s does not match level %d", | |
1190 | circuit->area->area_tag, | |
1191 | level, | |
1192 | typechar, | |
1193 | circuit->interface->name, | |
1194 | circuit_t2string (circuit->circuit_is_type), | |
1195 | level); | |
1196 | ||
1197 | return ISIS_OK; | |
1198 | } | |
1199 | ||
1200 | /* 7.3.15.2 a) 4 - not applicable for CSNP only PSNPs on broadcast */ | |
1201 | if ((snp_type == ISIS_SNP_PSNP_FLAG) && | |
1202 | (circuit->circ_type == CIRCUIT_T_BROADCAST)) { | |
1203 | if (!circuit->u.bc.is_dr[level-1]) { | |
1204 | ||
1205 | zlog_info ("ISIS-Snp (%s): Rcvd L%d %cSNP from %s on %s, " | |
1206 | "skipping: we are not the DIS", | |
1207 | circuit->area->area_tag, | |
1208 | level, | |
1209 | typechar, | |
1210 | snpa_print(ssnpa), | |
1211 | circuit->interface->name); | |
1212 | ||
1213 | return ISIS_OK; | |
1214 | } | |
1215 | } | |
1216 | ||
1217 | /* 7.3.15.2 a) 5 - need to make sure IDLength matches - already checked */ | |
1218 | ||
1219 | /* 7.3.15.2 a) 6 - maximum area match, can be ommited since we only use 3 | |
1220 | * - already checked */ | |
1221 | ||
1222 | /* 7.3.15.2 a) 7 - Must check that we have an adjacency of the same level */ | |
1223 | /* for broadcast circuits, snpa should be compared */ | |
1224 | /* FIXME : Do we need to check SNPA? */ | |
1225 | if (circuit->circ_type == CIRCUIT_T_BROADCAST) { | |
1226 | if (snp_type == ISIS_SNP_CSNP_FLAG) { | |
1227 | adj = isis_adj_lookup (chdr->source_id, circuit->u.bc.adjdb[level - 1]); | |
1228 | } else { | |
1229 | /* a psnp on a broadcast, how lovely of Juniper :) */ | |
1230 | adj = isis_adj_lookup (phdr->source_id, circuit->u.bc.adjdb[level - 1]); | |
1231 | } | |
1232 | if (!adj) | |
1233 | return ISIS_OK; /* Silently discard */ | |
1234 | } else { | |
1235 | if (!circuit->u.p2p.neighbor) | |
1236 | return ISIS_OK; /* Silently discard */ | |
1237 | } | |
1238 | ||
1239 | /* 7.3.15.2 a) 8 - Passwords for level 1 - not implemented */ | |
1240 | ||
1241 | /* 7.3.15.2 a) 9 - Passwords for level 2 - not implemented */ | |
1242 | ||
1243 | memset (&tlvs, 0, sizeof (struct tlvs)); | |
1244 | ||
1245 | /* parse the SNP */ | |
1246 | expected |= TLVFLAG_LSP_ENTRIES; | |
1247 | expected |= TLVFLAG_AUTH_INFO; | |
1248 | retval = parse_tlvs (circuit->area->area_tag, | |
1249 | STREAM_PNT(circuit->rcv_stream), | |
1250 | len - circuit->rcv_stream->getp, | |
1251 | &expected, | |
1252 | &found, | |
1253 | &tlvs); | |
1254 | ||
1255 | if (retval > ISIS_WARNING) { | |
1256 | zlog_warn ("something went very wrong processing SNP"); | |
1257 | free_tlvs (&tlvs); | |
1258 | return retval; | |
1259 | } | |
1260 | ||
1261 | (level == 1) ? (passwd = &circuit->area->area_passwd) : | |
1262 | (passwd = &circuit->area->domain_passwd); | |
1263 | if (passwd->type) { | |
1264 | if (!(found & TLVFLAG_AUTH_INFO) || | |
1265 | authentication_check (passwd, &tlvs.auth_info)) { | |
1266 | isis_event_auth_failure (circuit->area->area_tag, "SNP authentication" | |
1267 | " failure", phdr ? | |
1268 | phdr->source_id : chdr->source_id); | |
1269 | return ISIS_OK; | |
1270 | } | |
1271 | } | |
1272 | ||
1273 | /* debug isis snp-packets */ | |
1274 | if (isis->debugs & DEBUG_SNP_PACKETS) { | |
1275 | zlog_info ("ISIS-Snp (%s): Rcvd L%d %cSNP from %s on %s", | |
1276 | circuit->area->area_tag, | |
1277 | level, | |
1278 | typechar, | |
1279 | snpa_print(ssnpa), | |
1280 | circuit->interface->name); | |
1281 | if (tlvs.lsp_entries) { | |
1282 | LIST_LOOP (tlvs.lsp_entries,entry,node) { | |
1283 | zlog_info("ISIS-Snp (%s): %cSNP entry %s, seq 0x%08x," | |
1284 | " cksum 0x%04x, lifetime %us", | |
1285 | circuit->area->area_tag, | |
1286 | typechar, | |
1287 | rawlspid_print (entry->lsp_id), | |
1288 | ntohl (entry->seq_num), | |
1289 | ntohs (entry->checksum), | |
1290 | ntohs (entry->rem_lifetime)); | |
1291 | } | |
1292 | } | |
1293 | } | |
1294 | ||
1295 | /* 7.3.15.2 b) Actions on LSP_ENTRIES reported */ | |
1296 | if (tlvs.lsp_entries) { | |
1297 | LIST_LOOP (tlvs.lsp_entries, entry, node) { | |
1298 | lsp = lsp_search (entry->lsp_id, circuit->area->lspdb[level - 1]); | |
1299 | own_lsp = !memcmp (entry->lsp_id, isis->sysid, ISIS_SYS_ID_LEN); | |
1300 | if (lsp) { | |
1301 | /* 7.3.15.2 b) 1) is this LSP newer */ | |
1302 | cmp = lsp_compare (circuit->area->area_tag, lsp, entry->seq_num, | |
1303 | entry->checksum, entry->rem_lifetime); | |
1304 | /* 7.3.15.2 b) 2) if it equals, clear SRM on p2p */ | |
1305 | if (cmp == LSP_EQUAL) { | |
1306 | if (circuit->circ_type != CIRCUIT_T_BROADCAST) | |
1307 | ISIS_CLEAR_FLAG (lsp->SRMflags, circuit); | |
1308 | /* 7.3.15.2 b) 3) if it is older, clear SSN and set SRM */ | |
1309 | } else if (cmp == LSP_OLDER) { | |
1310 | ISIS_CLEAR_FLAG (lsp->SSNflags, circuit); | |
1311 | ISIS_SET_FLAG (lsp->SRMflags, circuit); | |
1312 | } else { | |
1313 | /* 7.3.15.2 b) 4) if it is newer, set SSN and clear SRM on p2p*/ | |
1314 | if (own_lsp) { | |
1315 | lsp_inc_seqnum (lsp, ntohl (entry->seq_num)); | |
1316 | ISIS_SET_FLAG (lsp->SRMflags, circuit); | |
1317 | } else { | |
1318 | ISIS_SET_FLAG (lsp->SSNflags, circuit); | |
1319 | if (circuit->circ_type != CIRCUIT_T_BROADCAST) | |
1320 | ISIS_CLEAR_FLAG (lsp->SRMflags, circuit); | |
1321 | } | |
1322 | } | |
1323 | } else { | |
1324 | /* 7.3.15.2 b) 5) if it was not found, and all of those are not 0, | |
1325 | * insert it and set SSN on it */ | |
1326 | if (entry->rem_lifetime && entry->checksum && entry->seq_num && | |
1327 | memcmp (entry->lsp_id, isis->sysid, ISIS_SYS_ID_LEN)) { | |
1328 | lsp = lsp_new (entry->lsp_id, ntohs (entry->rem_lifetime), | |
1329 | 0, 0, entry->checksum, level); | |
1330 | lsp_insert (lsp, circuit->area->lspdb[level - 1]); | |
1331 | ISIS_SET_FLAG (lsp->SSNflags, circuit); | |
1332 | } | |
1333 | } | |
1334 | } | |
1335 | } | |
1336 | ||
1337 | /* 7.3.15.2 c) on CSNP set SRM for all in range which were not reported */ | |
1338 | if (snp_type == ISIS_SNP_CSNP_FLAG) { | |
1339 | /* | |
1340 | * Build a list from our own LSP db bounded with start_ and stop_lsp_id | |
1341 | */ | |
1342 | lsp_list = list_new (); | |
1343 | lsp_build_list_nonzero_ht (chdr->start_lsp_id, chdr->stop_lsp_id, | |
1344 | lsp_list, circuit->area->lspdb[level - 1]); | |
1345 | ||
1346 | /* Fixme: Find a better solution */ | |
1347 | if (tlvs.lsp_entries) { | |
1348 | LIST_LOOP (tlvs.lsp_entries, entry, node) { | |
1349 | LIST_LOOP (lsp_list, lsp, node2) { | |
1350 | if (lsp_id_cmp (lsp->lsp_header->lsp_id, entry->lsp_id) == 0) { | |
1351 | list_delete_node (lsp_list, node2); | |
1352 | break; | |
1353 | } | |
1354 | } | |
1355 | } | |
1356 | } | |
1357 | /* on remaining LSPs we set SRM (neighbor knew not of) */ | |
1358 | LIST_LOOP (lsp_list, lsp, node2) { | |
1359 | ISIS_SET_FLAG (lsp->SRMflags, circuit); | |
1360 | } | |
1361 | /* lets free it */ | |
1362 | list_free (lsp_list); | |
1363 | } | |
1364 | ||
1365 | free_tlvs (&tlvs); | |
1366 | return retval; | |
1367 | } | |
1368 | ||
1369 | int | |
1370 | process_csnp (int level, struct isis_circuit *circuit, u_char *ssnpa) | |
1371 | { | |
1372 | ||
1373 | /* Sanity check - FIXME: move to correct place */ | |
1374 | if ((stream_get_endp (circuit->rcv_stream) - | |
1375 | stream_get_getp (circuit->rcv_stream)) < ISIS_CSNP_HDRLEN) { | |
1376 | zlog_warn ("Packet too short ( < %d)", ISIS_CSNP_HDRLEN); | |
1377 | return ISIS_WARNING; | |
1378 | } | |
1379 | ||
1380 | return process_snp (ISIS_SNP_CSNP_FLAG, level, circuit, ssnpa); | |
1381 | } | |
1382 | ||
1383 | int | |
1384 | process_psnp (int level, struct isis_circuit *circuit, u_char *ssnpa) | |
1385 | { | |
1386 | ||
1387 | if ((stream_get_endp (circuit->rcv_stream) - | |
1388 | stream_get_getp (circuit->rcv_stream)) < ISIS_PSNP_HDRLEN) { | |
1389 | zlog_warn ("Packet too short"); | |
1390 | return ISIS_WARNING; | |
1391 | } | |
1392 | ||
1393 | return process_snp (ISIS_SNP_PSNP_FLAG, level, circuit, ssnpa); | |
1394 | } | |
1395 | ||
1396 | ||
1397 | ||
1398 | /* | |
1399 | * Process ISH | |
1400 | * ISO - 10589 | |
1401 | * Section 8.2.2 - Receiving ISH PDUs by an intermediate system | |
1402 | * FIXME: sample packet dump, need to figure 0x81 - looks like NLPid | |
1403 | 0x82 0x15 0x01 0x00 0x04 0x01 0x2c 0x59 | |
1404 | 0x38 0x08 0x47 0x00 0x01 0x00 0x02 0x00 | |
1405 | 0x03 0x00 0x81 0x01 0xcc | |
1406 | */ | |
1407 | int | |
1408 | process_is_hello (struct isis_circuit *circuit) | |
1409 | { | |
1410 | struct isis_adjacency *adj; | |
1411 | int retval = ISIS_OK; | |
1412 | u_char neigh_len; | |
1413 | u_char *sysid; | |
1414 | ||
1415 | /* In this point in time we are not yet able to handle is_hellos | |
1416 | * on lan - Sorry juniper... | |
1417 | */ | |
1418 | if (circuit->circ_type == CIRCUIT_T_BROADCAST) | |
1419 | return retval; | |
1420 | ||
1421 | neigh_len = stream_getc (circuit->rcv_stream); | |
1422 | sysid = STREAM_PNT(circuit->rcv_stream) + neigh_len - 1 - ISIS_SYS_ID_LEN; | |
1423 | adj = circuit->u.p2p.neighbor; | |
1424 | if (!adj) { | |
1425 | /* 8.2.2 */ | |
1426 | adj = isis_new_adj (sysid, " ", 0, circuit); | |
1427 | if (adj == NULL) | |
1428 | return ISIS_ERROR; | |
1429 | ||
1430 | isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING, NULL); | |
1431 | adj->sys_type = ISIS_SYSTYPE_UNKNOWN; | |
1432 | circuit->u.p2p.neighbor = adj; | |
1433 | } | |
1434 | /* 8.2.2 a)*/ | |
1435 | if ((adj->adj_state == ISIS_ADJ_UP) && memcmp (adj->sysid,sysid, | |
1436 | ISIS_SYS_ID_LEN)) { | |
1437 | /* 8.2.2 a) 1) FIXME: adjStateChange(down) event */ | |
1438 | /* 8.2.2 a) 2) delete the adj */ | |
1439 | XFREE (MTYPE_ISIS_ADJACENCY, adj); | |
1440 | /* 8.2.2 a) 3) create a new adj */ | |
1441 | adj = isis_new_adj (sysid, " ", 0, circuit); | |
1442 | if (adj == NULL) | |
1443 | return ISIS_ERROR; | |
1444 | ||
1445 | /* 8.2.2 a) 3) i */ | |
1446 | isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING, NULL); | |
1447 | /* 8.2.2 a) 3) ii */ | |
1448 | adj->sys_type = ISIS_SYSTYPE_UNKNOWN; | |
1449 | /* 8.2.2 a) 4) quite meaningless */ | |
1450 | } | |
1451 | /* 8.2.2 b) ignore on condition */ | |
1452 | if ((adj->adj_state == ISIS_ADJ_INITIALIZING) && | |
1453 | (adj->sys_type == ISIS_SYSTYPE_IS)) { | |
1454 | /* do nothing */ | |
1455 | } else { | |
1456 | /* 8.2.2 c) respond with a p2p IIH */ | |
1457 | send_hello (circuit, 1); | |
1458 | } | |
1459 | /* 8.2.2 d) type is IS */ | |
1460 | adj->sys_type = ISIS_SYSTYPE_IS; | |
1461 | /* 8.2.2 e) FIXME: Circuit type of? */ | |
1462 | ||
1463 | ||
1464 | return retval; | |
1465 | } | |
1466 | ||
1467 | ||
1468 | /* | |
1469 | * PDU Dispatcher | |
1470 | */ | |
1471 | ||
1472 | int | |
1473 | isis_handle_pdu (struct isis_circuit *circuit, u_char *ssnpa) | |
1474 | { | |
1475 | ||
1476 | struct isis_fixed_hdr *hdr; | |
1477 | struct esis_fixed_hdr *esis_hdr; | |
1478 | ||
1479 | int retval=ISIS_OK; | |
1480 | ||
1481 | /* | |
1482 | * Let's first read data from stream to the header | |
1483 | */ | |
1484 | hdr = (struct isis_fixed_hdr*)STREAM_DATA(circuit->rcv_stream); | |
1485 | ||
1486 | if ((hdr->idrp != ISO10589_ISIS) && (hdr->idrp != ISO9542_ESIS)){ | |
1487 | zlog_warn ("Not an IS-IS or ES-IS packet IDRP=%02x", hdr->idrp); | |
1488 | return ISIS_ERROR; | |
1489 | } | |
1490 | ||
1491 | /* now we need to know if this is an ISO 9542 packet and | |
1492 | * take real good care of it, waaa! | |
1493 | */ | |
1494 | if (hdr->idrp == ISO9542_ESIS){ | |
1495 | esis_hdr = (struct esis_fixed_hdr*)STREAM_DATA(circuit->rcv_stream); | |
1496 | stream_set_getp (circuit->rcv_stream, ESIS_FIXED_HDR_LEN); | |
1497 | /* FIXME: Need to do some acceptence tests */ | |
1498 | /* example length... */ | |
1499 | switch (esis_hdr->pdu_type) { | |
1500 | case ESH_PDU: | |
1501 | /* FIXME */ | |
1502 | break; | |
1503 | case ISH_PDU: | |
1504 | zlog_info ("AN ISH PDU!!"); | |
1505 | retval = process_is_hello (circuit); | |
1506 | break; | |
1507 | default: | |
1508 | return ISIS_ERROR; | |
1509 | } | |
1510 | return retval; | |
1511 | } else { | |
1512 | stream_set_getp (circuit->rcv_stream, ISIS_FIXED_HDR_LEN); | |
1513 | } | |
1514 | /* | |
1515 | * and then process it | |
1516 | */ | |
1517 | ||
1518 | if (hdr->length < ISIS_MINIMUM_FIXED_HDR_LEN) { | |
1519 | zlog_err ("Fixed header length = %d", hdr->length); | |
1520 | return ISIS_ERROR; | |
1521 | } | |
1522 | ||
1523 | if (hdr->version1 != 1) { | |
1524 | zlog_warn ("Unsupported ISIS version %u", hdr->version1); | |
1525 | return ISIS_WARNING; | |
1526 | } | |
1527 | /* either 6 or 0 */ | |
1528 | if ((hdr->id_len != 0) && (hdr->id_len != ISIS_SYS_ID_LEN)) { | |
1529 | zlog_err ("IDFieldLengthMismatch: ID Length field in a received PDU %u, " | |
1530 | "while the parameter for this IS is %u", hdr->id_len, | |
1531 | ISIS_SYS_ID_LEN); | |
1532 | return ISIS_ERROR; | |
1533 | } | |
1534 | ||
1535 | if (hdr->version2 != 1) { | |
1536 | zlog_warn ("Unsupported ISIS version %u", hdr->version2); | |
1537 | return ISIS_WARNING; | |
1538 | } | |
1539 | /* either 3 or 0 */ | |
1540 | if ((hdr->max_area_addrs != 0) && (hdr->max_area_addrs != isis->max_area_addrs)) { | |
1541 | zlog_err ("maximumAreaAddressesMismatch: maximumAreaAdresses in a " | |
1542 | "received PDU %u while the parameter for this IS is %u", | |
1543 | hdr->max_area_addrs, isis->max_area_addrs); | |
1544 | return ISIS_ERROR; | |
1545 | } | |
1546 | ||
1547 | switch (hdr->pdu_type) { | |
1548 | case L1_LAN_HELLO: | |
1549 | retval = process_lan_hello (ISIS_LEVEL1, circuit, ssnpa); | |
1550 | break; | |
1551 | case L2_LAN_HELLO: | |
1552 | retval = process_lan_hello (ISIS_LEVEL2, circuit, ssnpa); | |
1553 | break; | |
1554 | case P2P_HELLO: | |
1555 | retval = process_p2p_hello (circuit); | |
1556 | break; | |
1557 | case L1_LINK_STATE: | |
1558 | retval = process_lsp (ISIS_LEVEL1, circuit, ssnpa); | |
1559 | break; | |
1560 | case L2_LINK_STATE: | |
1561 | retval = process_lsp (ISIS_LEVEL2, circuit, ssnpa); | |
1562 | break; | |
1563 | case L1_COMPLETE_SEQ_NUM: | |
1564 | retval = process_csnp (ISIS_LEVEL1, circuit, ssnpa); | |
1565 | break; | |
1566 | case L2_COMPLETE_SEQ_NUM: | |
1567 | retval = process_csnp (ISIS_LEVEL2, circuit, ssnpa); | |
1568 | break; | |
1569 | case L1_PARTIAL_SEQ_NUM: | |
1570 | retval = process_psnp (ISIS_LEVEL1, circuit, ssnpa); | |
1571 | break; | |
1572 | case L2_PARTIAL_SEQ_NUM: | |
1573 | retval = process_psnp (ISIS_LEVEL2, circuit, ssnpa); | |
1574 | break; | |
1575 | default: | |
1576 | return ISIS_ERROR; | |
1577 | } | |
1578 | ||
1579 | return retval; | |
1580 | } | |
1581 | ||
1582 | ||
1583 | #ifdef GNU_LINUX | |
1584 | int | |
1585 | isis_receive (struct thread *thread) | |
1586 | { | |
1587 | ||
1588 | struct isis_circuit *circuit; | |
1589 | u_char ssnpa[ETH_ALEN]; | |
1590 | int retval; | |
1591 | ||
1592 | /* | |
1593 | * Get the circuit | |
1594 | */ | |
1595 | circuit = THREAD_ARG (thread); | |
1596 | assert (circuit); | |
1597 | ||
1598 | if (circuit->rcv_stream == NULL) | |
1599 | circuit->rcv_stream = stream_new (ISO_MTU(circuit)); | |
1600 | else | |
1601 | stream_reset (circuit->rcv_stream); | |
1602 | ||
1603 | retval = circuit->rx (circuit, ssnpa); | |
1604 | circuit->t_read = NULL; | |
1605 | ||
1606 | if (retval == ISIS_OK) | |
1607 | retval = isis_handle_pdu (circuit, ssnpa); | |
1608 | ||
1609 | /* | |
1610 | * prepare for next packet. | |
1611 | */ | |
d70f99e1 | 1612 | THREAD_READ_ON(master, circuit->t_read, isis_receive, circuit, circuit->fd); |
eb5d44eb | 1613 | |
1614 | return retval; | |
1615 | } | |
1616 | ||
1617 | #else | |
1618 | int | |
1619 | isis_receive (struct thread *thread) | |
1620 | { | |
1621 | ||
1622 | struct isis_circuit *circuit; | |
1623 | u_char ssnpa[ETH_ALEN]; | |
1624 | int retval; | |
1625 | ||
1626 | /* | |
1627 | * Get the circuit | |
1628 | */ | |
1629 | circuit = THREAD_ARG (thread); | |
1630 | assert (circuit); | |
1631 | ||
1632 | circuit->t_read = NULL; | |
1633 | ||
1634 | if (circuit->rcv_stream == NULL) | |
1635 | circuit->rcv_stream = stream_new (ISO_MTU(circuit)); | |
1636 | else | |
1637 | stream_reset (circuit->rcv_stream); | |
1638 | ||
1639 | retval = circuit->rx (circuit, ssnpa); | |
1640 | ||
1641 | if (retval == ISIS_OK) | |
1642 | retval = isis_handle_pdu (circuit, ssnpa); | |
1643 | ||
1644 | /* | |
1645 | * prepare for next packet. | |
1646 | */ | |
1647 | circuit->t_read = thread_add_timer_msec (master, isis_receive, circuit, | |
1648 | listcount | |
1649 | (circuit->area->circuit_list)*100); | |
1650 | ||
1651 | ||
1652 | return retval; | |
1653 | } | |
1654 | ||
1655 | #endif | |
1656 | ||
1657 | /* filling of the fixed isis header */ | |
1658 | void | |
1659 | fill_fixed_hdr (struct isis_fixed_hdr *hdr, u_char pdu_type) | |
1660 | { | |
1661 | memset (hdr, 0, sizeof (struct isis_fixed_hdr)); | |
1662 | ||
1663 | hdr->idrp = ISO10589_ISIS; | |
1664 | ||
1665 | switch (pdu_type) { | |
1666 | case L1_LAN_HELLO: | |
1667 | case L2_LAN_HELLO: | |
1668 | hdr->length = ISIS_LANHELLO_HDRLEN; | |
1669 | break; | |
1670 | case P2P_HELLO: | |
1671 | hdr->length = ISIS_P2PHELLO_HDRLEN; | |
1672 | break; | |
1673 | case L1_LINK_STATE: | |
1674 | case L2_LINK_STATE: | |
1675 | hdr->length = ISIS_LSP_HDR_LEN; | |
1676 | break; | |
1677 | case L1_COMPLETE_SEQ_NUM: | |
1678 | case L2_COMPLETE_SEQ_NUM: | |
1679 | hdr->length = ISIS_CSNP_HDRLEN; | |
1680 | break; | |
1681 | case L1_PARTIAL_SEQ_NUM: | |
1682 | case L2_PARTIAL_SEQ_NUM: | |
1683 | hdr->length = ISIS_PSNP_HDRLEN; | |
1684 | break; | |
1685 | default: | |
1686 | zlog_warn ("fill_fixed_hdr(): unknown pdu type %d", pdu_type); | |
1687 | return; | |
1688 | } | |
1689 | hdr->length += ISIS_FIXED_HDR_LEN; | |
1690 | hdr->pdu_type = pdu_type; | |
1691 | hdr->version1 = 1; | |
1692 | hdr->id_len = 0; /* ISIS_SYS_ID_LEN - 0==6 */ | |
1693 | hdr->version2 = 1; | |
1694 | hdr->max_area_addrs = 0; /* isis->max_area_addrs - 0==3 */ | |
1695 | } | |
1696 | ||
1697 | ||
1698 | /* | |
1699 | * SEND SIDE | |
1700 | */ | |
1701 | void | |
1702 | fill_fixed_hdr_andstream (struct isis_fixed_hdr *hdr, u_char pdu_type, | |
1703 | struct stream *stream) | |
1704 | { | |
1705 | fill_fixed_hdr (hdr,pdu_type); | |
1706 | ||
1707 | stream_putc (stream, hdr->idrp); | |
1708 | stream_putc (stream, hdr->length); | |
1709 | stream_putc (stream, hdr->version1); | |
1710 | stream_putc (stream, hdr->id_len); | |
1711 | stream_putc (stream, hdr->pdu_type); | |
1712 | stream_putc (stream, hdr->version2); | |
1713 | stream_putc (stream, hdr->reserved); | |
1714 | stream_putc (stream, hdr->max_area_addrs); | |
1715 | ||
1716 | return; | |
1717 | } | |
1718 | ||
1719 | ||
1720 | int | |
1721 | send_hello (struct isis_circuit *circuit, int level) | |
1722 | { | |
1723 | struct isis_fixed_hdr fixed_hdr; | |
1724 | struct isis_lan_hello_hdr hello_hdr; | |
1725 | struct isis_p2p_hello_hdr p2p_hello_hdr; | |
1726 | ||
1727 | u_int32_t interval; | |
1728 | unsigned long len_pointer, length; | |
1729 | int retval; | |
1730 | ||
1731 | if (circuit->interface->mtu == 0) { | |
1732 | zlog_warn ("circuit has zero MTU"); | |
1733 | return ISIS_WARNING; | |
1734 | } | |
1735 | ||
1736 | if (!circuit->snd_stream) | |
1737 | circuit->snd_stream = stream_new (ISO_MTU(circuit)); | |
1738 | else | |
1739 | stream_reset (circuit->snd_stream); | |
1740 | ||
1741 | if (circuit->circ_type == CIRCUIT_T_BROADCAST) | |
1742 | if (level == 1) | |
1743 | fill_fixed_hdr_andstream(&fixed_hdr, L1_LAN_HELLO, circuit->snd_stream); | |
1744 | else | |
1745 | fill_fixed_hdr_andstream(&fixed_hdr, L2_LAN_HELLO, circuit->snd_stream); | |
1746 | else | |
1747 | fill_fixed_hdr_andstream(&fixed_hdr, P2P_HELLO, circuit->snd_stream); | |
1748 | ||
1749 | /* | |
1750 | * Fill LAN Level 1 or 2 Hello PDU header | |
1751 | */ | |
1752 | memset (&hello_hdr, 0, sizeof (struct isis_lan_hello_hdr)); | |
1753 | interval = circuit->hello_multiplier[level - 1] * | |
1754 | circuit->hello_interval[level - 1]; | |
1755 | if (interval > USHRT_MAX) | |
1756 | interval = USHRT_MAX; | |
1757 | hello_hdr.circuit_t = circuit->circuit_is_type; | |
1758 | memcpy (hello_hdr.source_id, isis->sysid, ISIS_SYS_ID_LEN); | |
1759 | hello_hdr.hold_time = htons((u_int16_t)interval); | |
1760 | ||
1761 | hello_hdr.pdu_len = 0; /* Update the PDU Length later */ | |
1762 | len_pointer = stream_get_putp (circuit->snd_stream) + 3 + ISIS_SYS_ID_LEN; | |
1763 | ||
1764 | ||
1765 | /* copy the shared part of the hello to the p2p hello if needed */ | |
1766 | if (circuit->circ_type == CIRCUIT_T_P2P) { | |
1767 | memcpy (&p2p_hello_hdr, &hello_hdr, 5 + ISIS_SYS_ID_LEN); | |
1768 | p2p_hello_hdr.local_id = circuit->circuit_id; | |
1769 | /* FIXME: need better understanding */ | |
1770 | stream_put (circuit->snd_stream, &p2p_hello_hdr, ISIS_P2PHELLO_HDRLEN); | |
1771 | } else { | |
1772 | hello_hdr.prio = circuit->u.bc.priority[level - 1]; | |
1773 | if(level == 1 && circuit->u.bc.l1_desig_is) { | |
1774 | memcpy(hello_hdr.lan_id, circuit->u.bc.l1_desig_is, ISIS_SYS_ID_LEN + 1); | |
1775 | } else if (level == 2 && circuit->u.bc.l2_desig_is){ | |
1776 | memcpy(hello_hdr.lan_id, circuit->u.bc.l2_desig_is, ISIS_SYS_ID_LEN + 1); | |
1777 | } | |
1778 | stream_put (circuit->snd_stream, &hello_hdr, ISIS_LANHELLO_HDRLEN); | |
1779 | } | |
1780 | ||
1781 | /* | |
1782 | * Then the variable length part | |
1783 | */ | |
1784 | /* add circuit password */ | |
1785 | if (circuit->passwd.type) | |
1786 | if (tlv_add_authinfo (circuit->passwd.type, circuit->passwd.len, | |
1787 | circuit->passwd.passwd, circuit->snd_stream)) | |
1788 | return ISIS_WARNING; | |
1789 | /* Area Addresses TLV */ | |
1790 | assert (circuit->area); | |
1791 | if (circuit->area->area_addrs && circuit->area->area_addrs->count > 0) | |
1792 | if (tlv_add_area_addrs (circuit->area->area_addrs, circuit->snd_stream)) | |
1793 | return ISIS_WARNING; | |
1794 | ||
1795 | /* LAN Neighbors TLV */ | |
1796 | if (circuit->circ_type == CIRCUIT_T_BROADCAST) { | |
1797 | if (level == 1 && circuit->u.bc.lan_neighs[0]->count > 0) | |
1798 | if (tlv_add_lan_neighs (circuit->u.bc.lan_neighs[0], | |
1799 | circuit->snd_stream)) | |
1800 | return ISIS_WARNING; | |
1801 | if (level == 2 && circuit->u.bc.lan_neighs[1]->count > 0) | |
1802 | if (tlv_add_lan_neighs (circuit->u.bc.lan_neighs[1], | |
1803 | circuit->snd_stream)) | |
1804 | return ISIS_WARNING; | |
1805 | } | |
1806 | ||
1807 | /* Protocols Supported TLV */ | |
1808 | if (circuit->nlpids.count > 0) | |
1809 | if (tlv_add_nlpid (&circuit->nlpids, circuit->snd_stream)) | |
1810 | return ISIS_WARNING; | |
1811 | /* IP interface Address TLV */ | |
1812 | if (circuit->ip_router && circuit->ip_addrs && circuit->ip_addrs->count > 0) | |
1813 | if (tlv_add_ip_addrs (circuit->ip_addrs, circuit->snd_stream)) | |
1814 | return ISIS_WARNING; | |
1815 | ||
1816 | #ifdef HAVE_IPV6 | |
1817 | /* IPv6 Interface Address TLV */ | |
1818 | if (circuit->ipv6_router && circuit->ipv6_link && | |
1819 | circuit->ipv6_link->count > 0) | |
1820 | if (tlv_add_ipv6_addrs (circuit->ipv6_link, circuit->snd_stream)) | |
1821 | return ISIS_WARNING; | |
1822 | #endif /* HAVE_IPV6 */ | |
1823 | ||
1824 | if (circuit->u.bc.pad_hellos) | |
1825 | if (tlv_add_padding (circuit->snd_stream)) | |
1826 | return ISIS_WARNING; | |
1827 | ||
1828 | length = stream_get_putp (circuit->snd_stream); | |
1829 | /* Update PDU length */ | |
1830 | stream_putw_at (circuit->snd_stream, len_pointer, (u_int16_t)length); | |
1831 | ||
1832 | retval = circuit->tx (circuit, level); | |
1833 | if (retval) | |
1834 | zlog_warn ("sending of LAN Level %d Hello failed", level); | |
1835 | ||
1836 | /* DEBUG_ADJ_PACKETS */ | |
1837 | if (isis->debugs & DEBUG_ADJ_PACKETS) { | |
1838 | if (circuit->circ_type == CIRCUIT_T_BROADCAST) { | |
1839 | zlog_info ("ISIS-Adj (%s): Sent L%d LAN IIH on %s, length %ld", | |
1840 | circuit->area->area_tag, level, circuit->interface->name, | |
1841 | STREAM_SIZE(circuit->snd_stream)); | |
1842 | } else { | |
1843 | zlog_info ("ISIS-Adj (%s): Sent P2P IIH on %s, length %ld", | |
1844 | circuit->area->area_tag, circuit->interface->name, | |
1845 | STREAM_SIZE(circuit->snd_stream)); | |
1846 | } | |
1847 | } | |
1848 | ||
1849 | ||
1850 | return retval; | |
1851 | } | |
1852 | ||
1853 | int | |
1854 | send_lan_hello (struct isis_circuit *circuit, int level) | |
1855 | { | |
1856 | return send_hello (circuit,level); | |
1857 | } | |
1858 | ||
1859 | int | |
1860 | send_lan_l1_hello (struct thread *thread) | |
1861 | { | |
1862 | ||
1863 | struct isis_circuit *circuit; | |
1864 | int retval; | |
1865 | ||
1866 | circuit = THREAD_ARG (thread); | |
1867 | assert (circuit); | |
1868 | circuit->u.bc.t_send_lan_hello[0] = NULL; | |
1869 | ||
1870 | if (circuit->u.bc.run_dr_elect[0]) | |
1871 | retval = isis_dr_elect (circuit, 1); | |
1872 | ||
1873 | retval = send_lan_hello (circuit, 1); | |
1874 | ||
1875 | /* set next timer thread */ | |
d70f99e1 | 1876 | THREAD_TIMER_ON(master, circuit->u.bc.t_send_lan_hello[0], send_lan_l1_hello, |
1877 | circuit, isis_jitter (circuit->hello_interval[0], IIH_JITTER)); | |
eb5d44eb | 1878 | |
1879 | return retval; | |
1880 | } | |
1881 | ||
1882 | int | |
1883 | send_lan_l2_hello (struct thread *thread) | |
1884 | { | |
1885 | struct isis_circuit *circuit; | |
1886 | int retval; | |
1887 | ||
1888 | circuit = THREAD_ARG (thread); | |
1889 | assert (circuit); | |
1890 | circuit->u.bc.t_send_lan_hello[1] = NULL; | |
1891 | ||
1892 | if (circuit->u.bc.run_dr_elect[1]) | |
1893 | retval = isis_dr_elect (circuit, 2); | |
1894 | ||
1895 | retval = send_lan_hello (circuit, 2); | |
1896 | ||
1897 | /* set next timer thread*/ | |
d70f99e1 | 1898 | THREAD_TIMER_ON(master, circuit->u.bc.t_send_lan_hello[1], send_lan_l2_hello, |
1899 | circuit, isis_jitter (circuit->hello_interval[1], IIH_JITTER)); | |
eb5d44eb | 1900 | |
1901 | return retval; | |
1902 | } | |
1903 | ||
1904 | int | |
1905 | send_p2p_hello (struct thread *thread) | |
1906 | { | |
1907 | struct isis_circuit *circuit; | |
1908 | ||
1909 | circuit = THREAD_ARG (thread); | |
1910 | assert (circuit); | |
1911 | circuit->u.p2p.t_send_p2p_hello = NULL; | |
1912 | ||
1913 | send_hello(circuit,1); | |
1914 | ||
1915 | /* set next timer thread*/ | |
d70f99e1 | 1916 | THREAD_TIMER_ON(master, circuit->u.p2p.t_send_p2p_hello, send_p2p_hello, |
1917 | circuit, isis_jitter (circuit->hello_interval[1], IIH_JITTER)); | |
eb5d44eb | 1918 | |
1919 | return ISIS_OK; | |
1920 | } | |
1921 | ||
1922 | int | |
1923 | build_csnp (int level, u_char *start, u_char *stop, struct list *lsps, | |
1924 | struct isis_circuit *circuit) | |
1925 | { | |
1926 | struct isis_fixed_hdr fixed_hdr; | |
1927 | struct isis_passwd *passwd; | |
1928 | int retval = ISIS_OK; | |
1929 | unsigned long lenp; | |
1930 | u_int16_t length; | |
1931 | ||
1932 | if (level ==1) | |
1933 | fill_fixed_hdr_andstream (&fixed_hdr, L1_COMPLETE_SEQ_NUM, | |
1934 | circuit->snd_stream); | |
1935 | else | |
1936 | fill_fixed_hdr_andstream (&fixed_hdr, L2_COMPLETE_SEQ_NUM, | |
1937 | circuit->snd_stream); | |
1938 | ||
1939 | /* | |
1940 | * Fill Level 1 or 2 Complete Sequence Numbers header | |
1941 | */ | |
1942 | ||
1943 | lenp = stream_get_putp (circuit->snd_stream); | |
1944 | stream_putw (circuit->snd_stream, 0); /* PDU length - when we know it */ | |
1945 | /* no need to send the source here, it is always us if we csnp */ | |
1946 | stream_put (circuit->snd_stream, isis->sysid, ISIS_SYS_ID_LEN); | |
1947 | /* with zero circuit id - ref 9.10, 9.11 */ | |
1948 | stream_putc (circuit->snd_stream, 0x00); | |
1949 | ||
1950 | stream_put (circuit->snd_stream, start, ISIS_SYS_ID_LEN + 2); | |
1951 | stream_put (circuit->snd_stream, stop, ISIS_SYS_ID_LEN + 2); | |
1952 | ||
1953 | /* | |
1954 | * And TLVs | |
1955 | */ | |
1956 | if (level == 1) | |
1957 | passwd = &circuit->area->area_passwd; | |
1958 | else | |
1959 | passwd = &circuit->area->domain_passwd; | |
1960 | ||
1961 | if (passwd->type) | |
1962 | retval = tlv_add_authinfo (passwd->type, passwd->len, | |
1963 | passwd->passwd, circuit->snd_stream); | |
1964 | ||
1965 | if (!retval && lsps) { | |
1966 | retval = tlv_add_lsp_entries (lsps, circuit->snd_stream); | |
1967 | } | |
1968 | length = (u_int16_t)stream_get_putp (circuit->snd_stream); | |
1969 | assert (length >= ISIS_CSNP_HDRLEN); | |
1970 | /* Update PU length */ | |
1971 | stream_putw_at (circuit->snd_stream, lenp, length); | |
1972 | ||
1973 | return retval; | |
1974 | } | |
1975 | ||
1976 | /* | |
1977 | * FIXME: support multiple CSNPs | |
1978 | */ | |
1979 | ||
1980 | int | |
1981 | send_csnp (struct isis_circuit *circuit, int level) | |
1982 | { | |
1983 | int retval = ISIS_OK; | |
1984 | u_char start[ISIS_SYS_ID_LEN + 2]; | |
1985 | u_char stop[ISIS_SYS_ID_LEN + 2]; | |
1986 | struct list *list = NULL; | |
1987 | struct listnode *node; | |
1988 | struct isis_lsp *lsp; | |
1989 | ||
1990 | memset (start,0x00, ISIS_SYS_ID_LEN + 2); | |
1991 | memset (stop, 0xff, ISIS_SYS_ID_LEN + 2); | |
1992 | ||
1993 | if (circuit->area->lspdb[level-1] && | |
1994 | dict_count (circuit->area->lspdb[level-1]) > 0) { | |
1995 | list = list_new (); | |
1996 | lsp_build_list (start, stop, list, circuit->area->lspdb[level-1]); | |
1997 | ||
1998 | if (circuit->snd_stream == NULL) | |
1999 | circuit->snd_stream = stream_new (ISO_MTU(circuit)); | |
2000 | else | |
2001 | stream_reset (circuit->snd_stream); | |
2002 | ||
2003 | retval = build_csnp (level, start, stop, list, circuit); | |
2004 | ||
2005 | if (isis->debugs & DEBUG_SNP_PACKETS) { | |
2006 | zlog_info ("ISIS-Snp (%s): Sent L%d CSNP on %s, length %ld", | |
2007 | circuit->area->area_tag, level, circuit->interface->name, | |
2008 | STREAM_SIZE(circuit->snd_stream)); | |
2009 | LIST_LOOP (list, lsp, node) { | |
2010 | zlog_info("ISIS-Snp (%s): CSNP entry %s, seq 0x%08x," | |
2011 | " cksum 0x%04x, lifetime %us", | |
2012 | circuit->area->area_tag, | |
2013 | rawlspid_print (lsp->lsp_header->lsp_id), | |
2014 | ntohl (lsp->lsp_header->seq_num), | |
2015 | ntohs (lsp->lsp_header->checksum), | |
2016 | ntohs (lsp->lsp_header->rem_lifetime)); | |
2017 | } | |
2018 | } | |
2019 | ||
2020 | list_delete (list); | |
2021 | ||
2022 | if (retval == ISIS_OK) | |
2023 | retval = circuit->tx (circuit, level); | |
2024 | } | |
2025 | return retval; | |
2026 | } | |
2027 | ||
2028 | int | |
2029 | send_l1_csnp (struct thread *thread) | |
2030 | { | |
2031 | struct isis_circuit *circuit; | |
2032 | int retval = ISIS_OK; | |
2033 | ||
2034 | circuit = THREAD_ARG (thread); | |
2035 | assert (circuit); | |
2036 | ||
2037 | circuit->t_send_csnp[0] = NULL; | |
2038 | ||
2039 | if (circuit->circ_type == CIRCUIT_T_BROADCAST && circuit->u.bc.is_dr[0]) { | |
2040 | send_csnp(circuit,1); | |
2041 | } | |
2042 | /* set next timer thread */ | |
d70f99e1 | 2043 | THREAD_TIMER_ON(master, circuit->t_send_csnp[0], send_l1_csnp, circuit, |
2044 | isis_jitter(circuit->csnp_interval[0], CSNP_JITTER)); | |
eb5d44eb | 2045 | |
2046 | return retval; | |
2047 | } | |
2048 | ||
2049 | int | |
2050 | send_l2_csnp (struct thread *thread) | |
2051 | { | |
2052 | struct isis_circuit *circuit; | |
2053 | int retval = ISIS_OK; | |
2054 | ||
2055 | circuit = THREAD_ARG (thread); | |
2056 | assert (circuit); | |
2057 | ||
2058 | circuit->t_send_csnp[1] = NULL; | |
2059 | ||
2060 | if (circuit->circ_type == CIRCUIT_T_BROADCAST && circuit->u.bc.is_dr[1]) { | |
2061 | send_csnp(circuit,2); | |
2062 | } | |
2063 | /* set next timer thread */ | |
d70f99e1 | 2064 | THREAD_TIMER_ON(master, circuit->t_send_csnp[1], send_l2_csnp, circuit, |
2065 | isis_jitter(circuit->csnp_interval[1], CSNP_JITTER)); | |
2066 | ||
eb5d44eb | 2067 | return retval; |
2068 | } | |
2069 | ||
2070 | int | |
2071 | build_psnp (int level, struct isis_circuit *circuit, struct list *lsps) | |
2072 | { | |
2073 | struct isis_fixed_hdr fixed_hdr; | |
2074 | unsigned long lenp; | |
2075 | u_int16_t length; | |
2076 | int retval = 0; | |
2077 | struct isis_lsp *lsp; | |
2078 | struct isis_passwd *passwd; | |
2079 | struct listnode *node; | |
2080 | ||
2081 | if (level == 1) | |
2082 | fill_fixed_hdr_andstream (&fixed_hdr, L1_PARTIAL_SEQ_NUM, | |
2083 | circuit->snd_stream); | |
2084 | else | |
2085 | fill_fixed_hdr_andstream (&fixed_hdr, L2_PARTIAL_SEQ_NUM, | |
2086 | circuit->snd_stream); | |
2087 | ||
2088 | /* | |
2089 | * Fill Level 1 or 2 Partial Sequence Numbers header | |
2090 | */ | |
2091 | lenp = stream_get_putp (circuit->snd_stream); | |
2092 | stream_putw (circuit->snd_stream, 0); /* PDU length - when we know it */ | |
2093 | stream_put (circuit->snd_stream, isis->sysid, ISIS_SYS_ID_LEN); | |
2094 | stream_putc (circuit->snd_stream, circuit->idx); | |
2095 | ||
2096 | /* | |
2097 | * And TLVs | |
2098 | */ | |
2099 | ||
2100 | if (level == 1) | |
2101 | passwd = &circuit->area->area_passwd; | |
2102 | else | |
2103 | passwd = &circuit->area->domain_passwd; | |
2104 | ||
2105 | if (passwd->type) | |
2106 | retval = tlv_add_authinfo (passwd->type, passwd->len, | |
2107 | passwd->passwd, circuit->snd_stream); | |
2108 | ||
2109 | if (!retval && lsps) { | |
2110 | retval = tlv_add_lsp_entries (lsps, circuit->snd_stream); | |
2111 | } | |
2112 | ||
2113 | if (isis->debugs & DEBUG_SNP_PACKETS) { | |
2114 | LIST_LOOP (lsps, lsp, node) { | |
2115 | zlog_info("ISIS-Snp (%s): PSNP entry %s, seq 0x%08x," | |
2116 | " cksum 0x%04x, lifetime %us", | |
2117 | circuit->area->area_tag, | |
2118 | rawlspid_print (lsp->lsp_header->lsp_id), | |
2119 | ntohl (lsp->lsp_header->seq_num), | |
2120 | ntohs (lsp->lsp_header->checksum), | |
2121 | ntohs (lsp->lsp_header->rem_lifetime)); | |
2122 | } | |
2123 | } | |
2124 | ||
2125 | length = (u_int16_t)stream_get_putp (circuit->snd_stream); | |
2126 | assert (length >= ISIS_PSNP_HDRLEN); | |
2127 | /* Update PDU length */ | |
2128 | stream_putw_at (circuit->snd_stream, lenp, length); | |
2129 | ||
2130 | return ISIS_OK; | |
2131 | } | |
2132 | ||
2133 | /* | |
2134 | * 7.3.15.4 action on expiration of partial SNP interval | |
2135 | * level 1 | |
2136 | */ | |
2137 | int | |
2138 | send_psnp (int level, struct isis_circuit *circuit) | |
2139 | { | |
2140 | int retval = ISIS_OK; | |
2141 | struct isis_lsp *lsp; | |
2142 | struct list *list = NULL; | |
2143 | struct listnode *node; | |
2144 | ||
2145 | if ((circuit->circ_type == CIRCUIT_T_BROADCAST && | |
2146 | !circuit->u.bc.is_dr[level - 1]) || | |
2147 | circuit->circ_type != CIRCUIT_T_BROADCAST) { | |
2148 | ||
2149 | if (circuit->area->lspdb[level-1] && | |
2150 | dict_count (circuit->area->lspdb[level-1]) > 0) { | |
2151 | list = list_new (); | |
2152 | lsp_build_list_ssn (circuit, list, circuit->area->lspdb[level-1]); | |
2153 | ||
2154 | if (listcount(list) > 0) { | |
2155 | if (circuit->snd_stream == NULL) | |
2156 | circuit->snd_stream = stream_new (ISO_MTU(circuit)); | |
2157 | else | |
2158 | stream_reset (circuit->snd_stream); | |
2159 | ||
2160 | ||
2161 | if (isis->debugs & DEBUG_SNP_PACKETS) | |
2162 | zlog_info ("ISIS-Snp (%s): Sent L%d PSNP on %s, length %ld", | |
2163 | circuit->area->area_tag, level, circuit->interface->name, | |
2164 | STREAM_SIZE(circuit->snd_stream)); | |
2165 | ||
2166 | retval = build_psnp (level, circuit, list); | |
2167 | if (retval == ISIS_OK) | |
2168 | retval = circuit->tx (circuit, level); | |
2169 | ||
2170 | if (retval == ISIS_OK) { | |
2171 | /* | |
2172 | * sending succeeded, we can clear SSN flags of this circuit | |
2173 | * for the LSPs in list | |
2174 | */ | |
2175 | for (node = listhead (list); node; nextnode(node)) { | |
2176 | lsp = getdata (node); | |
2177 | ISIS_CLEAR_FLAG (lsp->SSNflags, circuit); | |
2178 | } | |
2179 | } | |
2180 | } | |
2181 | list_delete (list); | |
2182 | } | |
2183 | } | |
2184 | ||
2185 | return retval; | |
2186 | } | |
2187 | ||
2188 | int | |
2189 | send_l1_psnp (struct thread *thread) | |
2190 | { | |
2191 | ||
2192 | struct isis_circuit *circuit; | |
2193 | int retval = ISIS_OK; | |
2194 | ||
2195 | circuit = THREAD_ARG (thread); | |
2196 | assert (circuit); | |
2197 | ||
2198 | circuit->t_send_psnp[0] = NULL; | |
2199 | ||
2200 | send_psnp (1, circuit); | |
2201 | /* set next timer thread */ | |
d70f99e1 | 2202 | THREAD_TIMER_ON(master, circuit->t_send_psnp[0], send_l1_psnp, circuit, |
2203 | isis_jitter(circuit->psnp_interval[0], PSNP_JITTER)); | |
eb5d44eb | 2204 | |
2205 | return retval; | |
2206 | } | |
2207 | ||
2208 | /* | |
2209 | * 7.3.15.4 action on expiration of partial SNP interval | |
2210 | * level 2 | |
2211 | */ | |
2212 | int | |
2213 | send_l2_psnp (struct thread *thread) | |
2214 | { | |
2215 | ||
2216 | struct isis_circuit *circuit; | |
2217 | int retval = ISIS_OK; | |
2218 | ||
2219 | circuit = THREAD_ARG (thread); | |
2220 | assert (circuit); | |
2221 | ||
2222 | circuit->t_send_psnp[1] = NULL; | |
2223 | ||
2224 | send_psnp (2, circuit); | |
2225 | ||
2226 | /* set next timer thread */ | |
d70f99e1 | 2227 | THREAD_TIMER_ON(master, circuit->t_send_psnp[1], send_l2_psnp, circuit, |
2228 | isis_jitter(circuit->psnp_interval[1], PSNP_JITTER)); | |
eb5d44eb | 2229 | |
2230 | return retval; | |
2231 | } | |
2232 | ||
2233 | ||
2234 | void | |
2235 | build_link_state (struct isis_lsp *lsp, struct isis_circuit *circuit, | |
2236 | struct stream *stream) | |
2237 | { | |
2238 | unsigned long length; | |
2239 | ||
2240 | stream_put (stream, lsp->pdu, ntohs(lsp->lsp_header->pdu_len)); | |
2241 | length = stream_get_putp (stream); | |
2242 | ||
2243 | return; | |
2244 | } | |
2245 | ||
2246 | ||
2247 | /* | |
2248 | * ISO 10589 - 7.3.14.3 | |
2249 | */ | |
2250 | int | |
2251 | send_lsp (struct thread *thread) | |
2252 | { | |
2253 | struct isis_circuit *circuit; | |
2254 | struct isis_lsp *lsp; | |
2255 | struct listnode *node; | |
2256 | int retval = 0; | |
2257 | ||
2258 | circuit = THREAD_ARG (thread); | |
2259 | assert (circuit); | |
2260 | ||
2261 | if (circuit->state == C_STATE_UP) { | |
2262 | node = listhead (circuit->lsp_queue); | |
2263 | assert (node); | |
2264 | ||
2265 | lsp = getdata (node); | |
2266 | ||
2267 | /* | |
2268 | * Do not send if levels do not match | |
2269 | */ | |
2270 | if (!(lsp->level & circuit->circuit_is_type)) | |
2271 | goto dontsend; | |
2272 | ||
2273 | /* | |
2274 | * Do not send if we do not have adjacencies in state up on the circuit | |
2275 | */ | |
2276 | if (circuit->upadjcount[lsp->level - 1] == 0) | |
2277 | goto dontsend; | |
2278 | /* only send if it needs sending */ | |
2279 | if ((time(NULL) - lsp->last_sent) >= | |
2280 | circuit->area->lsp_gen_interval[lsp->level-1]) { | |
2281 | ||
2282 | if (isis->debugs & DEBUG_UPDATE_PACKETS) { | |
2283 | zlog_info ("ISIS-Upd (%s): Sent L%d LSP %s, seq 0x%08x, cksum 0x%04x," | |
2284 | " lifetime %us on %s", | |
2285 | circuit->area->area_tag, | |
2286 | lsp->level, | |
2287 | rawlspid_print (lsp->lsp_header->lsp_id), | |
2288 | ntohl(lsp->lsp_header->seq_num), | |
2289 | ntohs(lsp->lsp_header->checksum), | |
2290 | ntohs(lsp->lsp_header->rem_lifetime), | |
2291 | circuit->interface->name); | |
2292 | } | |
2293 | /* copy our lsp to the send buffer */ | |
2294 | circuit->snd_stream->getp = lsp->pdu->getp; | |
2295 | circuit->snd_stream->putp = lsp->pdu->putp; | |
2296 | circuit->snd_stream->endp = lsp->pdu->endp; | |
2297 | memcpy (circuit->snd_stream->data, lsp->pdu->data, lsp->pdu->endp); | |
2298 | ||
2299 | retval = circuit->tx (circuit, lsp->level); | |
2300 | ||
2301 | /* | |
2302 | * If the sending succeeded, we can del the lsp from circuits lsp_queue | |
2303 | */ | |
2304 | if (retval == ISIS_OK) { | |
2305 | list_delete_node (circuit->lsp_queue, node); | |
2306 | ||
2307 | /* | |
2308 | * On broadcast circuits also the SRMflag can be cleared | |
2309 | */ | |
2310 | if (circuit->circ_type == CIRCUIT_T_BROADCAST) | |
2311 | ISIS_CLEAR_FLAG (lsp->SRMflags, circuit); | |
2312 | ||
2313 | if (flags_any_set (lsp->SRMflags) == 0) { | |
2314 | /* | |
2315 | * need to remember when we were last sent | |
2316 | */ | |
2317 | lsp->last_sent = time (NULL); | |
2318 | } | |
2319 | } else { | |
2320 | zlog_info ("sending of level %d link state failed", lsp->level); | |
2321 | } | |
2322 | } else { | |
2323 | /* my belief is that if it wasn't his time, the lsp can be removed | |
2324 | * from the queue | |
2325 | */ | |
2326 | dontsend: | |
2327 | list_delete_node (circuit->lsp_queue, node); | |
2328 | } | |
2329 | #if 0 | |
2330 | /* | |
2331 | * If there are still LSPs send next one after lsp-interval (33 msecs) | |
2332 | */ | |
2333 | if (listcount (circuit->lsp_queue) > 0) | |
2334 | thread_add_timer (master, send_lsp, circuit, | |
2335 | 1); | |
2336 | #endif | |
2337 | } | |
2338 | ||
2339 | return retval; | |
2340 | } | |
2341 | ||
2342 | int | |
2343 | ack_lsp (struct isis_link_state_hdr *hdr, struct isis_circuit *circuit, | |
2344 | int level) | |
2345 | { | |
2346 | unsigned long lenp; | |
2347 | int retval; | |
2348 | u_int16_t length; | |
2349 | struct isis_fixed_hdr fixed_hdr; | |
2350 | ||
2351 | if (!circuit->snd_stream) | |
2352 | circuit->snd_stream = stream_new (ISO_MTU(circuit)); | |
2353 | else | |
2354 | stream_reset (circuit->snd_stream); | |
2355 | ||
2356 | // fill_llc_hdr (stream); | |
2357 | if (level == 1) | |
2358 | fill_fixed_hdr_andstream (&fixed_hdr, L1_PARTIAL_SEQ_NUM, | |
2359 | circuit->snd_stream); | |
2360 | else | |
2361 | fill_fixed_hdr_andstream (&fixed_hdr, L2_PARTIAL_SEQ_NUM, | |
2362 | circuit->snd_stream); | |
2363 | ||
2364 | ||
2365 | lenp = stream_get_putp (circuit->snd_stream); | |
2366 | stream_putw (circuit->snd_stream, 0); /* PDU length */ | |
2367 | stream_put (circuit->snd_stream, isis->sysid, ISIS_SYS_ID_LEN); | |
2368 | stream_putc (circuit->snd_stream, circuit->idx); | |
2369 | stream_putc (circuit->snd_stream, 9); /* code */ | |
2370 | stream_putc (circuit->snd_stream, 16); /* len */ | |
2371 | ||
2372 | stream_putw (circuit->snd_stream, ntohs(hdr->rem_lifetime)); | |
2373 | stream_put (circuit->snd_stream, hdr->lsp_id, ISIS_SYS_ID_LEN + 2); | |
2374 | stream_putl (circuit->snd_stream, ntohl(hdr->seq_num)); | |
2375 | stream_putw (circuit->snd_stream, ntohs(hdr->checksum)); | |
2376 | ||
2377 | length = (u_int16_t)stream_get_putp (circuit->snd_stream); | |
2378 | /* Update PDU length */ | |
2379 | stream_putw_at (circuit->snd_stream, lenp, length); | |
2380 | ||
2381 | retval = circuit->tx (circuit, level); | |
2382 | ||
2383 | return retval; | |
2384 | } | |
2385 | ||
2386 | #if 0 | |
2387 | /* | |
2388 | * ISH PDU Processing | |
2389 | */ | |
2390 | ||
2391 | ||
2392 | /* | |
2393 | * Let's first check if the local and remote system have any common area | |
2394 | * addresses | |
2395 | */ | |
2396 | if (area_match(tlvs.area_addrs, isis->man_area_addrs) == 0) { | |
2397 | if (circuit->circuit_t == IS_LEVEL_2) { | |
2398 | /* do as in table 8 (p. 40) */ | |
2399 | switch (circuit_type) { | |
2400 | case IS_LEVEL_1: | |
2401 | if (adj->adj_state != ISIS_ADJ_UP) { | |
2402 | /* Reject */ | |
2403 | zlog_warn("areaMismatch"); | |
2404 | retval = ISIS_WARNING; | |
2405 | } else if (adj->adj_usage == ISIS_ADJ_LEVEL1) { | |
2406 | isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Area Mismatch", | |
2407 | circuit->adjdb); | |
2408 | } else if (adj->adj_usage == ISIS_ADJ_LEVEL1AND2 || | |
2409 | adj->adj_usage == ISIS_ADJ_LEVEL2) { | |
2410 | isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System", | |
2411 | circuit->adjdb); | |
2412 | } | |
2413 | break; | |
2414 | case IS_LEVEL_2: | |
2415 | if (adj->adj_state != ISIS_ADJ_UP) { | |
2416 | isis_adj_state_change (adj, ISIS_ADJ_UP, NULL, circuit->adjdb); | |
2417 | adj->adj_usage = ISIS_ADJ_LEVEL2; | |
2418 | } else if (adj->adj_usage == ISIS_ADJ_LEVEL1 || | |
2419 | adj->adj_usage == ISIS_ADJ_LEVEL1AND2) { | |
2420 | isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System", | |
2421 | circuit->adjdb); | |
2422 | } else if (adj->adj_usage == ISIS_ADJ_LEVEL2) { | |
2423 | ; /* Accept */ | |
2424 | } | |
2425 | break; | |
2426 | case IS_LEVEL_1_AND_2: | |
2427 | if (adj->adj_state != ISIS_ADJ_UP) { | |
2428 | isis_adj_state_change (adj, ISIS_ADJ_UP, NULL, circuit->adjdb); | |
2429 | adj->adj_usage = ISIS_ADJ_LEVEL2; | |
2430 | } else if (adj->adj_usage == ISIS_ADJ_LEVEL1) { | |
2431 | isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System", | |
2432 | circuit->adjdb); | |
2433 | } else if (adj->adj_usage == ISIS_ADJ_LEVEL1AND2) { | |
2434 | isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Area Mismatch", | |
2435 | circuit->adjdb); | |
2436 | } else if (adj->adj_usage == ISIS_ADJ_LEVEL2) { | |
2437 | ; /* Accept */ | |
2438 | } | |
2439 | break; | |
2440 | } | |
2441 | goto mismatch; | |
2442 | } else { | |
2443 | isis_delete_adj (adj, circuit->adjdb); | |
2444 | zlog_warn("areaMismatch"); | |
2445 | return ISIS_WARNING; | |
2446 | } | |
2447 | } | |
2448 | ||
2449 | mismatch: | |
2450 | #endif | |
2451 | ||
2452 | ||
2453 | ||
2454 |