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