]> git.proxmox.com Git - mirror_frr.git/blob - isisd/isis_pdu.c
*: remove THREAD_ON macros, add nullity check
[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/isis_constants.h"
40 #include "isisd/isis_common.h"
41 #include "isisd/isis_flags.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_tlv.h"
48 #include "isisd/isisd.h"
49 #include "isisd/isis_dynhn.h"
50 #include "isisd/isis_lsp.h"
51 #include "isisd/isis_pdu.h"
52 #include "isisd/iso_checksum.h"
53 #include "isisd/isis_csm.h"
54 #include "isisd/isis_events.h"
55 #include "isisd/isis_te.h"
56 #include "isisd/isis_mt.h"
57
58 #define ISIS_MINIMUM_FIXED_HDR_LEN 15
59 #define ISIS_MIN_PDU_LEN 13 /* partial seqnum pdu with id_len=2 */
60
61 #ifndef PNBBY
62 #define PNBBY 8
63 #endif /* PNBBY */
64
65 /*
66 * HELPER FUNCS
67 */
68
69 /*
70 * Compares two sets of area addresses
71 */
72 static int
73 area_match (struct list *left, struct list *right)
74 {
75 struct area_addr *addr1, *addr2;
76 struct listnode *node1, *node2;
77
78 for (ALL_LIST_ELEMENTS_RO (left, node1, addr1))
79 {
80 for (ALL_LIST_ELEMENTS_RO (right, node2, addr2))
81 {
82 if (addr1->addr_len == addr2->addr_len &&
83 !memcmp (addr1->area_addr, addr2->area_addr, (int) addr1->addr_len))
84 return 1; /* match */
85 }
86 }
87
88 return 0; /* mismatch */
89 }
90
91 /*
92 * Checks whether we should accept a PDU of given level
93 */
94 static int
95 accept_level (int level, int circuit_t)
96 {
97 int retval = ((circuit_t & level) == level); /* simple approach */
98
99 return retval;
100 }
101
102 /*
103 * Verify authentication information
104 * Support cleartext and HMAC MD5 authentication
105 */
106 static int
107 authentication_check (struct isis_passwd *remote, struct isis_passwd *local,
108 struct stream *stream, uint32_t auth_tlv_offset)
109 {
110 unsigned char digest[ISIS_AUTH_MD5_SIZE];
111
112 /* Auth fail () - passwd type mismatch */
113 if (local->type != remote->type)
114 return ISIS_ERROR;
115
116 switch (local->type)
117 {
118 /* No authentication required */
119 case ISIS_PASSWD_TYPE_UNUSED:
120 break;
121
122 /* Cleartext (ISO 10589) */
123 case ISIS_PASSWD_TYPE_CLEARTXT:
124 /* Auth fail () - passwd len mismatch */
125 if (remote->len != local->len)
126 return ISIS_ERROR;
127 return memcmp (local->passwd, remote->passwd, local->len);
128
129 /* HMAC MD5 (RFC 3567) */
130 case ISIS_PASSWD_TYPE_HMAC_MD5:
131 /* Auth fail () - passwd len mismatch */
132 if (remote->len != ISIS_AUTH_MD5_SIZE)
133 return ISIS_ERROR;
134 /* Set the authentication value to 0 before the check */
135 memset (STREAM_DATA (stream) + auth_tlv_offset + 3, 0,
136 ISIS_AUTH_MD5_SIZE);
137 /* Compute the digest */
138 hmac_md5 (STREAM_DATA (stream), stream_get_endp (stream),
139 (unsigned char *) &(local->passwd), local->len,
140 (unsigned char *) &digest);
141 /* Copy back the authentication value after the check */
142 memcpy (STREAM_DATA (stream) + auth_tlv_offset + 3,
143 remote->passwd, ISIS_AUTH_MD5_SIZE);
144 return memcmp (digest, remote->passwd, ISIS_AUTH_MD5_SIZE);
145
146 default:
147 zlog_err ("Unsupported authentication type");
148 return ISIS_ERROR;
149 }
150
151 /* Authentication pass when no authentication is configured */
152 return ISIS_OK;
153 }
154
155 static int
156 lsp_authentication_check (struct stream *stream, struct isis_area *area,
157 int level, struct isis_passwd *passwd)
158 {
159 struct isis_link_state_hdr *hdr;
160 uint32_t expected = 0, found = 0, auth_tlv_offset = 0;
161 uint16_t checksum, rem_lifetime, pdu_len;
162 struct tlvs tlvs;
163 int retval = ISIS_OK;
164
165 hdr = (struct isis_link_state_hdr *) (STREAM_PNT (stream));
166 pdu_len = ntohs (hdr->pdu_len);
167 expected |= TLVFLAG_AUTH_INFO;
168 auth_tlv_offset = stream_get_getp (stream) + ISIS_LSP_HDR_LEN;
169 retval = parse_tlvs (area->area_tag, STREAM_PNT (stream) + ISIS_LSP_HDR_LEN,
170 pdu_len - ISIS_FIXED_HDR_LEN - ISIS_LSP_HDR_LEN,
171 &expected, &found, &tlvs, &auth_tlv_offset);
172
173 if (retval != ISIS_OK)
174 {
175 zlog_err ("ISIS-Upd (%s): Parse failed L%d LSP %s, seq 0x%08x, "
176 "cksum 0x%04x, lifetime %us, len %u",
177 area->area_tag, level, rawlspid_print (hdr->lsp_id),
178 ntohl (hdr->seq_num), ntohs (hdr->checksum),
179 ntohs (hdr->rem_lifetime), pdu_len);
180 if ((isis->debugs & DEBUG_UPDATE_PACKETS) &&
181 (isis->debugs & DEBUG_PACKET_DUMP))
182 zlog_dump_data (STREAM_DATA (stream), stream_get_endp (stream));
183 return retval;
184 }
185
186 if (!(found & TLVFLAG_AUTH_INFO))
187 {
188 zlog_err ("No authentication tlv in LSP");
189 return ISIS_ERROR;
190 }
191
192 if (tlvs.auth_info.type != ISIS_PASSWD_TYPE_CLEARTXT &&
193 tlvs.auth_info.type != ISIS_PASSWD_TYPE_HMAC_MD5)
194 {
195 zlog_err ("Unknown authentication type in LSP");
196 return ISIS_ERROR;
197 }
198
199 /*
200 * RFC 5304 set checksum and remaining lifetime to zero before
201 * verification and reset to old values after verification.
202 */
203 checksum = hdr->checksum;
204 rem_lifetime = hdr->rem_lifetime;
205 hdr->checksum = 0;
206 hdr->rem_lifetime = 0;
207 retval = authentication_check (&tlvs.auth_info, passwd, stream,
208 auth_tlv_offset);
209 hdr->checksum = checksum;
210 hdr->rem_lifetime = rem_lifetime;
211
212 return retval;
213 }
214
215 /*
216 * Processing helper functions
217 */
218 static void
219 del_addr (void *val)
220 {
221 XFREE (MTYPE_ISIS_TMP, val);
222 }
223
224 static void
225 tlvs_to_adj_area_addrs (struct tlvs *tlvs, struct isis_adjacency *adj)
226 {
227 struct listnode *node;
228 struct area_addr *area_addr, *malloced;
229
230 if (adj->area_addrs)
231 {
232 adj->area_addrs->del = del_addr;
233 list_delete (adj->area_addrs);
234 }
235 adj->area_addrs = list_new ();
236 if (tlvs->area_addrs)
237 {
238 for (ALL_LIST_ELEMENTS_RO (tlvs->area_addrs, node, area_addr))
239 {
240 malloced = XMALLOC (MTYPE_ISIS_TMP, sizeof (struct area_addr));
241 memcpy (malloced, area_addr, sizeof (struct area_addr));
242 listnode_add (adj->area_addrs, malloced);
243 }
244 }
245 }
246
247 static int
248 tlvs_to_adj_nlpids (struct tlvs *tlvs, struct isis_adjacency *adj)
249 {
250 int i;
251 struct nlpids *tlv_nlpids;
252
253 if (tlvs->nlpids)
254 {
255
256 tlv_nlpids = tlvs->nlpids;
257 if (tlv_nlpids->count > array_size (adj->nlpids.nlpids))
258 return 1;
259
260 adj->nlpids.count = tlv_nlpids->count;
261
262 for (i = 0; i < tlv_nlpids->count; i++)
263 {
264 adj->nlpids.nlpids[i] = tlv_nlpids->nlpids[i];
265 }
266 }
267 return 0;
268 }
269
270 static void
271 tlvs_to_adj_ipv4_addrs (struct tlvs *tlvs, struct isis_adjacency *adj)
272 {
273 struct listnode *node;
274 struct in_addr *ipv4_addr, *malloced;
275
276 if (adj->ipv4_addrs)
277 {
278 adj->ipv4_addrs->del = del_addr;
279 list_delete (adj->ipv4_addrs);
280 }
281 adj->ipv4_addrs = list_new ();
282 if (tlvs->ipv4_addrs)
283 {
284 for (ALL_LIST_ELEMENTS_RO (tlvs->ipv4_addrs, node, ipv4_addr))
285 {
286 malloced = XMALLOC (MTYPE_ISIS_TMP, sizeof (struct in_addr));
287 memcpy (malloced, ipv4_addr, sizeof (struct in_addr));
288 listnode_add (adj->ipv4_addrs, malloced);
289 }
290 }
291 }
292
293 static void
294 tlvs_to_adj_ipv6_addrs (struct tlvs *tlvs, struct isis_adjacency *adj)
295 {
296 struct listnode *node;
297 struct in6_addr *ipv6_addr, *malloced;
298
299 if (adj->ipv6_addrs)
300 {
301 adj->ipv6_addrs->del = del_addr;
302 list_delete (adj->ipv6_addrs);
303 }
304 adj->ipv6_addrs = list_new ();
305 if (tlvs->ipv6_addrs)
306 {
307 for (ALL_LIST_ELEMENTS_RO (tlvs->ipv6_addrs, node, ipv6_addr))
308 {
309 malloced = XMALLOC (MTYPE_ISIS_TMP, sizeof (struct in6_addr));
310 memcpy (malloced, ipv6_addr, sizeof (struct in6_addr));
311 listnode_add (adj->ipv6_addrs, malloced);
312 }
313 }
314
315 }
316
317 /*
318 * RECEIVE SIDE
319 */
320
321 /*
322 * Process P2P IIH
323 * ISO - 10589
324 * Section 8.2.5 - Receiving point-to-point IIH PDUs
325 *
326 */
327 static int
328 process_p2p_hello (struct isis_circuit *circuit)
329 {
330 int retval = ISIS_OK;
331 struct isis_p2p_hello_hdr *hdr;
332 struct isis_adjacency *adj;
333 u_int32_t expected = 0, found = 0, auth_tlv_offset = 0;
334 uint16_t pdu_len;
335 struct tlvs tlvs;
336 int v4_usable = 0, v6_usable = 0;
337
338 if (isis->debugs & DEBUG_ADJ_PACKETS)
339 {
340 zlog_debug ("ISIS-Adj (%s): Rcvd P2P IIH on %s, cirType %s, cirID %u",
341 circuit->area->area_tag, circuit->interface->name,
342 circuit_t2string (circuit->is_type), circuit->circuit_id);
343 if (isis->debugs & DEBUG_PACKET_DUMP)
344 zlog_dump_data (STREAM_DATA (circuit->rcv_stream),
345 stream_get_endp (circuit->rcv_stream));
346 }
347
348 if (circuit->circ_type != CIRCUIT_T_P2P)
349 {
350 zlog_warn ("p2p hello on non p2p circuit");
351 return ISIS_WARNING;
352 }
353
354 if ((stream_get_endp (circuit->rcv_stream) -
355 stream_get_getp (circuit->rcv_stream)) < ISIS_P2PHELLO_HDRLEN)
356 {
357 zlog_warn ("Packet too short");
358 return ISIS_WARNING;
359 }
360
361 /* 8.2.5.1 PDU acceptance tests */
362
363 /* 8.2.5.1 a) external domain untrue */
364 /* FIXME: not useful at all? */
365
366 /* 8.2.5.1 b) ID Length mismatch */
367 /* checked at the handle_pdu */
368
369 /* 8.2.5.2 IIH PDU Processing */
370
371 /* 8.2.5.2 a) 1) Maximum Area Addresses */
372 /* Already checked, and can also be ommited */
373
374 /*
375 * Get the header
376 */
377 hdr = (struct isis_p2p_hello_hdr *) STREAM_PNT (circuit->rcv_stream);
378 pdu_len = ntohs (hdr->pdu_len);
379
380 if (pdu_len < (ISIS_FIXED_HDR_LEN + ISIS_P2PHELLO_HDRLEN) ||
381 pdu_len > ISO_MTU(circuit) ||
382 pdu_len > stream_get_endp (circuit->rcv_stream))
383 {
384 zlog_warn ("ISIS-Adj (%s): Rcvd P2P IIH from (%s) with "
385 "invalid pdu length %d",
386 circuit->area->area_tag, circuit->interface->name, pdu_len);
387 return ISIS_WARNING;
388 }
389
390 /*
391 * Set the stream endp to PDU length, ignoring additional padding
392 * introduced by transport chips.
393 */
394 if (pdu_len < stream_get_endp (circuit->rcv_stream))
395 stream_set_endp (circuit->rcv_stream, pdu_len);
396
397 stream_forward_getp (circuit->rcv_stream, ISIS_P2PHELLO_HDRLEN);
398
399 /*
400 * Lets get the TLVS now
401 */
402 expected |= TLVFLAG_AREA_ADDRS;
403 expected |= TLVFLAG_AUTH_INFO;
404 expected |= TLVFLAG_NLPID;
405 expected |= TLVFLAG_IPV4_ADDR;
406 expected |= TLVFLAG_IPV6_ADDR;
407 expected |= TLVFLAG_MT_ROUTER_INFORMATION;
408
409 auth_tlv_offset = stream_get_getp (circuit->rcv_stream);
410 retval = parse_tlvs (circuit->area->area_tag,
411 STREAM_PNT (circuit->rcv_stream),
412 pdu_len - ISIS_P2PHELLO_HDRLEN - ISIS_FIXED_HDR_LEN,
413 &expected, &found, &tlvs, &auth_tlv_offset);
414
415 if (retval > ISIS_WARNING)
416 {
417 zlog_warn ("parse_tlvs() failed");
418 free_tlvs (&tlvs);
419 return retval;
420 };
421
422 if (!(found & TLVFLAG_AREA_ADDRS))
423 {
424 zlog_warn ("No Area addresses TLV in P2P IS to IS hello");
425 free_tlvs (&tlvs);
426 return ISIS_WARNING;
427 }
428
429 if (!(found & TLVFLAG_NLPID))
430 {
431 zlog_warn ("No supported protocols TLV in P2P IS to IS hello");
432 free_tlvs (&tlvs);
433 return ISIS_WARNING;
434 }
435
436 /* 8.2.5.1 c) Authentication */
437 if (circuit->passwd.type)
438 {
439 if (!(found & TLVFLAG_AUTH_INFO) ||
440 authentication_check (&tlvs.auth_info, &circuit->passwd,
441 circuit->rcv_stream, auth_tlv_offset))
442 {
443 isis_event_auth_failure (circuit->area->area_tag,
444 "P2P hello authentication failure",
445 hdr->source_id);
446 free_tlvs (&tlvs);
447 return ISIS_OK;
448 }
449 }
450
451 /*
452 * check if both ends have an IPv4 address
453 */
454 if (circuit->ip_addrs && listcount(circuit->ip_addrs)
455 && tlvs.ipv4_addrs && listcount(tlvs.ipv4_addrs))
456 {
457 v4_usable = 1;
458 }
459
460 if (found & TLVFLAG_IPV6_ADDR)
461 {
462 /* TBA: check that we have a linklocal ourselves? */
463 struct listnode *node;
464 struct in6_addr *ip;
465 for (ALL_LIST_ELEMENTS_RO (tlvs.ipv6_addrs, node, ip))
466 if (IN6_IS_ADDR_LINKLOCAL (ip))
467 {
468 v6_usable = 1;
469 break;
470 }
471
472 if (!v6_usable)
473 zlog_warn ("ISIS-Adj: IPv6 addresses present but no link-local "
474 "in P2P IIH from %s\n", circuit->interface->name);
475 }
476
477 if (!(found & (TLVFLAG_IPV4_ADDR | TLVFLAG_IPV6_ADDR)))
478 zlog_warn ("ISIS-Adj: neither IPv4 nor IPv6 addr in P2P IIH from %s\n",
479 circuit->interface->name);
480
481 if (!v6_usable && !v4_usable)
482 {
483 free_tlvs (&tlvs);
484 return ISIS_WARNING;
485 }
486
487 /*
488 * it's own p2p IIH PDU - discard
489 */
490 if (!memcmp (hdr->source_id, isis->sysid, ISIS_SYS_ID_LEN))
491 {
492 zlog_warn ("ISIS-Adj (%s): it's own IIH PDU - discarded",
493 circuit->area->area_tag);
494 free_tlvs (&tlvs);
495 return ISIS_WARNING;
496 }
497
498 /*
499 * My interpertation of the ISO, if no adj exists we will create one for
500 * the circuit
501 */
502 adj = circuit->u.p2p.neighbor;
503 /* If an adjacency exists, check it is with the source of the hello
504 * packets */
505 if (adj)
506 {
507 if (memcmp(hdr->source_id, adj->sysid, ISIS_SYS_ID_LEN))
508 {
509 zlog_debug("hello source and adjacency do not match, set adj down\n");
510 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "adj do not exist");
511 return 0;
512 }
513 }
514 if (!adj || adj->level != hdr->circuit_t)
515 {
516 if (!adj)
517 {
518 adj = isis_new_adj (hdr->source_id, NULL, hdr->circuit_t, circuit);
519 if (adj == NULL)
520 return ISIS_ERROR;
521 }
522 else
523 {
524 adj->level = hdr->circuit_t;
525 }
526 circuit->u.p2p.neighbor = adj;
527 /* Build lsp with the new neighbor entry when a new
528 * adjacency is formed. Set adjacency circuit type to
529 * IIH PDU header circuit type before lsp is regenerated
530 * when an adjacency is up. This will result in the new
531 * adjacency entry getting added to the lsp tlv neighbor list.
532 */
533 adj->circuit_t = hdr->circuit_t;
534 isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING, NULL);
535 adj->sys_type = ISIS_SYSTYPE_UNKNOWN;
536 }
537
538 /* 8.2.6 Monitoring point-to-point adjacencies */
539 adj->hold_time = ntohs (hdr->hold_time);
540 adj->last_upd = time (NULL);
541
542 /* we do this now because the adj may not survive till the end... */
543 tlvs_to_adj_area_addrs (&tlvs, adj);
544
545 /* which protocol are spoken ??? */
546 if (tlvs_to_adj_nlpids (&tlvs, adj))
547 {
548 free_tlvs (&tlvs);
549 return ISIS_WARNING;
550 }
551
552 /* we need to copy addresses to the adj */
553 if (found & TLVFLAG_IPV4_ADDR)
554 tlvs_to_adj_ipv4_addrs (&tlvs, adj);
555
556 /* Update MPLS TE Remote IP address parameter if possible */
557 if (IS_MPLS_TE(isisMplsTE) && circuit->mtc && IS_CIRCUIT_TE(circuit->mtc))
558 if (adj->ipv4_addrs != NULL && listcount(adj->ipv4_addrs) != 0)
559 {
560 struct in_addr *ip_addr;
561 ip_addr = (struct in_addr *)listgetdata ((struct listnode *)listhead (adj->ipv4_addrs));
562 set_circuitparams_rmt_ipaddr (circuit->mtc, *ip_addr);
563 }
564
565 if (found & TLVFLAG_IPV6_ADDR)
566 tlvs_to_adj_ipv6_addrs (&tlvs, adj);
567
568 bool mt_set_changed = tlvs_to_adj_mt_set(&tlvs, v4_usable, v6_usable, adj);
569
570 /* lets take care of the expiry */
571 THREAD_TIMER_OFF (adj->t_expire);
572 thread_add_timer(master, isis_adj_expire, adj, (long)adj->hold_time,
573 &adj->t_expire);
574
575 /* 8.2.5.2 a) a match was detected */
576 if (area_match (circuit->area->area_addrs, tlvs.area_addrs))
577 {
578 /* 8.2.5.2 a) 2) If the system is L1 - table 5 */
579 if (circuit->area->is_type == IS_LEVEL_1)
580 {
581 switch (hdr->circuit_t)
582 {
583 case IS_LEVEL_1:
584 case IS_LEVEL_1_AND_2:
585 if (adj->adj_state != ISIS_ADJ_UP)
586 {
587 /* (4) adj state up */
588 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
589 /* (5) adj usage level 1 */
590 adj->adj_usage = ISIS_ADJ_LEVEL1;
591 }
592 else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
593 {
594 ; /* accept */
595 }
596 break;
597 case IS_LEVEL_2:
598 if (adj->adj_state != ISIS_ADJ_UP)
599 {
600 /* (7) reject - wrong system type event */
601 zlog_warn ("wrongSystemType");
602 free_tlvs (&tlvs);
603 return ISIS_WARNING; /* Reject */
604 }
605 else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
606 {
607 /* (6) down - wrong system */
608 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
609 }
610 break;
611 }
612 }
613
614 /* 8.2.5.2 a) 3) If the system is L1L2 - table 6 */
615 if (circuit->area->is_type == IS_LEVEL_1_AND_2)
616 {
617 switch (hdr->circuit_t)
618 {
619 case IS_LEVEL_1:
620 if (adj->adj_state != ISIS_ADJ_UP)
621 {
622 /* (6) adj state up */
623 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
624 /* (7) adj usage level 1 */
625 adj->adj_usage = ISIS_ADJ_LEVEL1;
626 }
627 else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
628 {
629 ; /* accept */
630 }
631 else if ((adj->adj_usage == ISIS_ADJ_LEVEL1AND2) ||
632 (adj->adj_usage == ISIS_ADJ_LEVEL2))
633 {
634 /* (8) down - wrong system */
635 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
636 }
637 break;
638 case IS_LEVEL_2:
639 if (adj->adj_state != ISIS_ADJ_UP)
640 {
641 /* (6) adj state up */
642 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
643 /* (9) adj usage level 2 */
644 adj->adj_usage = ISIS_ADJ_LEVEL2;
645 }
646 else if ((adj->adj_usage == ISIS_ADJ_LEVEL1) ||
647 (adj->adj_usage == ISIS_ADJ_LEVEL1AND2))
648 {
649 /* (8) down - wrong system */
650 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
651 }
652 else if (adj->adj_usage == ISIS_ADJ_LEVEL2)
653 {
654 ; /* Accept */
655 }
656 break;
657 case IS_LEVEL_1_AND_2:
658 if (adj->adj_state != ISIS_ADJ_UP)
659 {
660 /* (6) adj state up */
661 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
662 /* (10) adj usage level 1 */
663 adj->adj_usage = ISIS_ADJ_LEVEL1AND2;
664 }
665 else if ((adj->adj_usage == ISIS_ADJ_LEVEL1) ||
666 (adj->adj_usage == ISIS_ADJ_LEVEL2))
667 {
668 /* (8) down - wrong system */
669 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
670 }
671 else if (adj->adj_usage == ISIS_ADJ_LEVEL1AND2)
672 {
673 ; /* Accept */
674 }
675 break;
676 }
677 }
678
679 /* 8.2.5.2 a) 4) If the system is L2 - table 7 */
680 if (circuit->area->is_type == IS_LEVEL_2)
681 {
682 switch (hdr->circuit_t)
683 {
684 case IS_LEVEL_1:
685 if (adj->adj_state != ISIS_ADJ_UP)
686 {
687 /* (5) reject - wrong system type event */
688 zlog_warn ("wrongSystemType");
689 free_tlvs (&tlvs);
690 return ISIS_WARNING; /* Reject */
691 }
692 else if ((adj->adj_usage == ISIS_ADJ_LEVEL1AND2) ||
693 (adj->adj_usage == ISIS_ADJ_LEVEL2))
694 {
695 /* (6) down - wrong system */
696 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
697 }
698 break;
699 case IS_LEVEL_1_AND_2:
700 case IS_LEVEL_2:
701 if (adj->adj_state != ISIS_ADJ_UP)
702 {
703 /* (7) adj state up */
704 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
705 /* (8) adj usage level 2 */
706 adj->adj_usage = ISIS_ADJ_LEVEL2;
707 }
708 else if (adj->adj_usage == ISIS_ADJ_LEVEL1AND2)
709 {
710 /* (6) down - wrong system */
711 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
712 }
713 else if (adj->adj_usage == ISIS_ADJ_LEVEL2)
714 {
715 ; /* Accept */
716 }
717 break;
718 }
719 }
720 }
721 /* 8.2.5.2 b) if no match was detected */
722 else if (listcount (circuit->area->area_addrs) > 0)
723 {
724 if (circuit->area->is_type == IS_LEVEL_1)
725 {
726 /* 8.2.5.2 b) 1) is_type L1 and adj is not up */
727 if (adj->adj_state != ISIS_ADJ_UP)
728 {
729 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Area Mismatch");
730 /* 8.2.5.2 b) 2)is_type L1 and adj is up */
731 }
732 else
733 {
734 isis_adj_state_change (adj, ISIS_ADJ_DOWN,
735 "Down - Area Mismatch");
736 }
737 }
738 /* 8.2.5.2 b 3 If the system is L2 or L1L2 - table 8 */
739 else
740 {
741 switch (hdr->circuit_t)
742 {
743 case IS_LEVEL_1:
744 if (adj->adj_state != ISIS_ADJ_UP)
745 {
746 /* (6) reject - Area Mismatch event */
747 zlog_warn ("AreaMismatch");
748 free_tlvs (&tlvs);
749 return ISIS_WARNING; /* Reject */
750 }
751 else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
752 {
753 /* (7) down - area mismatch */
754 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Area Mismatch");
755
756 }
757 else if ((adj->adj_usage == ISIS_ADJ_LEVEL1AND2) ||
758 (adj->adj_usage == ISIS_ADJ_LEVEL2))
759 {
760 /* (7) down - wrong system */
761 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
762 }
763 break;
764 case IS_LEVEL_1_AND_2:
765 case IS_LEVEL_2:
766 if (adj->adj_state != ISIS_ADJ_UP)
767 {
768 /* (8) adj state up */
769 isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
770 /* (9) adj usage level 2 */
771 adj->adj_usage = ISIS_ADJ_LEVEL2;
772 }
773 else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
774 {
775 /* (7) down - wrong system */
776 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
777 }
778 else if (adj->adj_usage == ISIS_ADJ_LEVEL1AND2)
779 {
780 if (hdr->circuit_t == IS_LEVEL_2)
781 {
782 /* (7) down - wrong system */
783 isis_adj_state_change (adj, ISIS_ADJ_DOWN,
784 "Wrong System");
785 }
786 else
787 {
788 /* (7) down - area mismatch */
789 isis_adj_state_change (adj, ISIS_ADJ_DOWN,
790 "Area Mismatch");
791 }
792 }
793 else if (adj->adj_usage == ISIS_ADJ_LEVEL2)
794 {
795 ; /* Accept */
796 }
797 break;
798 }
799 }
800 }
801 else
802 {
803 /* down - area mismatch */
804 isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Area Mismatch");
805 }
806
807 if (adj->adj_state == ISIS_ADJ_UP && mt_set_changed)
808 {
809 lsp_regenerate_schedule(adj->circuit->area,
810 isis_adj_usage2levels(adj->adj_usage), 0);
811 }
812
813 /* 8.2.5.2 c) if the action was up - comparing circuit IDs */
814 /* FIXME - Missing parts */
815
816 /* some of my own understanding of the ISO, why the heck does
817 * it not say what should I change the system_type to...
818 */
819 switch (adj->adj_usage)
820 {
821 case ISIS_ADJ_LEVEL1:
822 adj->sys_type = ISIS_SYSTYPE_L1_IS;
823 break;
824 case ISIS_ADJ_LEVEL2:
825 adj->sys_type = ISIS_SYSTYPE_L2_IS;
826 break;
827 case ISIS_ADJ_LEVEL1AND2:
828 adj->sys_type = ISIS_SYSTYPE_L2_IS;
829 break;
830 case ISIS_ADJ_NONE:
831 adj->sys_type = ISIS_SYSTYPE_UNKNOWN;
832 break;
833 }
834
835
836 if (isis->debugs & DEBUG_ADJ_PACKETS)
837 {
838 zlog_debug ("ISIS-Adj (%s): Rcvd P2P IIH from (%s), cir type %s,"
839 " cir id %02d, length %d",
840 circuit->area->area_tag, circuit->interface->name,
841 circuit_t2string (circuit->is_type),
842 circuit->circuit_id, pdu_len);
843 }
844
845 free_tlvs (&tlvs);
846
847 return retval;
848 }
849
850 /*
851 * Process IS-IS LAN Level 1/2 Hello PDU
852 */
853 static int
854 process_lan_hello (int level, struct isis_circuit *circuit, const u_char *ssnpa)
855 {
856 int retval = ISIS_OK;
857 struct isis_lan_hello_hdr hdr;
858 struct isis_adjacency *adj;
859 u_int32_t expected = 0, found = 0, auth_tlv_offset = 0;
860 struct tlvs tlvs;
861 u_char *snpa;
862 struct listnode *node;
863 int v4_usable = 0, v6_usable = 0;
864
865 if (isis->debugs & DEBUG_ADJ_PACKETS)
866 {
867 zlog_debug ("ISIS-Adj (%s): Rcvd L%d LAN IIH on %s, cirType %s, "
868 "cirID %u",
869 circuit->area->area_tag, level, circuit->interface->name,
870 circuit_t2string (circuit->is_type), circuit->circuit_id);
871 if (isis->debugs & DEBUG_PACKET_DUMP)
872 zlog_dump_data (STREAM_DATA (circuit->rcv_stream),
873 stream_get_endp (circuit->rcv_stream));
874 }
875
876 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
877 {
878 zlog_warn ("lan hello on non broadcast circuit");
879 return ISIS_WARNING;
880 }
881
882 if ((stream_get_endp (circuit->rcv_stream) -
883 stream_get_getp (circuit->rcv_stream)) < ISIS_LANHELLO_HDRLEN)
884 {
885 zlog_warn ("Packet too short");
886 return ISIS_WARNING;
887 }
888
889 if (circuit->ext_domain)
890 {
891 zlog_debug ("level %d LAN Hello received over circuit with "
892 "externalDomain = true", level);
893 return ISIS_WARNING;
894 }
895
896 if (!accept_level (level, circuit->is_type))
897 {
898 if (isis->debugs & DEBUG_ADJ_PACKETS)
899 {
900 zlog_debug ("ISIS-Adj (%s): Interface level mismatch, %s",
901 circuit->area->area_tag, circuit->interface->name);
902 }
903 return ISIS_WARNING;
904 }
905
906 #if 0
907 /* Cisco's debug message compatability */
908 if (!accept_level (level, circuit->area->is_type))
909 {
910 if (isis->debugs & DEBUG_ADJ_PACKETS)
911 {
912 zlog_debug ("ISIS-Adj (%s): is type mismatch",
913 circuit->area->area_tag);
914 }
915 return ISIS_WARNING;
916 }
917 #endif
918 /*
919 * Fill the header
920 */
921 hdr.circuit_t = stream_getc (circuit->rcv_stream);
922 stream_get (hdr.source_id, circuit->rcv_stream, ISIS_SYS_ID_LEN);
923 hdr.hold_time = stream_getw (circuit->rcv_stream);
924 hdr.pdu_len = stream_getw (circuit->rcv_stream);
925 hdr.prio = stream_getc (circuit->rcv_stream);
926 stream_get (hdr.lan_id, circuit->rcv_stream, ISIS_SYS_ID_LEN + 1);
927
928 if (hdr.pdu_len < (ISIS_FIXED_HDR_LEN + ISIS_LANHELLO_HDRLEN) ||
929 hdr.pdu_len > ISO_MTU(circuit) ||
930 hdr.pdu_len > stream_get_endp (circuit->rcv_stream))
931 {
932 zlog_warn ("ISIS-Adj (%s): Rcvd LAN IIH from (%s) with "
933 "invalid pdu length %d",
934 circuit->area->area_tag, circuit->interface->name,
935 hdr.pdu_len);
936 return ISIS_WARNING;
937 }
938
939 /*
940 * Set the stream endp to PDU length, ignoring additional padding
941 * introduced by transport chips.
942 */
943 if (hdr.pdu_len < stream_get_endp (circuit->rcv_stream))
944 stream_set_endp (circuit->rcv_stream, hdr.pdu_len);
945
946 if (hdr.circuit_t != IS_LEVEL_1 &&
947 hdr.circuit_t != IS_LEVEL_2 &&
948 hdr.circuit_t != IS_LEVEL_1_AND_2 &&
949 (level & hdr.circuit_t) == 0)
950 {
951 zlog_err ("Level %d LAN Hello with Circuit Type %d", level,
952 hdr.circuit_t);
953 return ISIS_ERROR;
954 }
955
956 /*
957 * Then get the tlvs
958 */
959 expected |= TLVFLAG_AUTH_INFO;
960 expected |= TLVFLAG_AREA_ADDRS;
961 expected |= TLVFLAG_LAN_NEIGHS;
962 expected |= TLVFLAG_NLPID;
963 expected |= TLVFLAG_IPV4_ADDR;
964 expected |= TLVFLAG_IPV6_ADDR;
965 expected |= TLVFLAG_MT_ROUTER_INFORMATION;
966
967 auth_tlv_offset = stream_get_getp (circuit->rcv_stream);
968 retval = parse_tlvs (circuit->area->area_tag,
969 STREAM_PNT (circuit->rcv_stream),
970 hdr.pdu_len - ISIS_LANHELLO_HDRLEN - ISIS_FIXED_HDR_LEN,
971 &expected, &found, &tlvs,
972 &auth_tlv_offset);
973
974 if (retval > ISIS_WARNING)
975 {
976 zlog_warn ("parse_tlvs() failed");
977 goto out;
978 }
979
980 if (!(found & TLVFLAG_AREA_ADDRS))
981 {
982 zlog_warn ("No Area addresses TLV in Level %d LAN IS to IS hello",
983 level);
984 retval = ISIS_WARNING;
985 goto out;
986 }
987
988 if (!(found & TLVFLAG_NLPID))
989 {
990 zlog_warn ("No supported protocols TLV in Level %d LAN IS to IS hello",
991 level);
992 retval = ISIS_WARNING;
993 goto out;
994 }
995
996 /* Verify authentication, either cleartext of HMAC MD5 */
997 if (circuit->passwd.type)
998 {
999 if (!(found & TLVFLAG_AUTH_INFO) ||
1000 authentication_check (&tlvs.auth_info, &circuit->passwd,
1001 circuit->rcv_stream, auth_tlv_offset))
1002 {
1003 isis_event_auth_failure (circuit->area->area_tag,
1004 "LAN hello authentication failure",
1005 hdr.source_id);
1006 retval = ISIS_WARNING;
1007 goto out;
1008 }
1009 }
1010
1011 if (!memcmp (hdr.source_id, isis->sysid, ISIS_SYS_ID_LEN))
1012 {
1013 zlog_warn ("ISIS-Adj (%s): duplicate system ID on interface %s",
1014 circuit->area->area_tag, circuit->interface->name);
1015 return ISIS_WARNING;
1016 }
1017
1018 /*
1019 * Accept the level 1 adjacency only if a match between local and
1020 * remote area addresses is found
1021 */
1022 if (listcount (circuit->area->area_addrs) == 0 ||
1023 (level == IS_LEVEL_1 &&
1024 area_match (circuit->area->area_addrs, tlvs.area_addrs) == 0))
1025 {
1026 if (isis->debugs & DEBUG_ADJ_PACKETS)
1027 {
1028 zlog_debug ("ISIS-Adj (%s): Area mismatch, level %d IIH on %s",
1029 circuit->area->area_tag, level,
1030 circuit->interface->name);
1031 }
1032 retval = ISIS_OK;
1033 goto out;
1034 }
1035
1036 /*
1037 * it's own IIH PDU - discard silently
1038 */
1039 if (!memcmp (circuit->u.bc.snpa, ssnpa, ETH_ALEN))
1040 {
1041 zlog_debug ("ISIS-Adj (%s): it's own IIH PDU - discarded",
1042 circuit->area->area_tag);
1043
1044 retval = ISIS_OK;
1045 goto out;
1046 }
1047
1048 /*
1049 * check if both ends have an IPv4 address
1050 */
1051 if (circuit->ip_addrs && listcount(circuit->ip_addrs)
1052 && tlvs.ipv4_addrs && listcount(tlvs.ipv4_addrs))
1053 {
1054 v4_usable = 1;
1055 }
1056
1057 if (found & TLVFLAG_IPV6_ADDR)
1058 {
1059 /* TBA: check that we have a linklocal ourselves? */
1060 struct listnode *node;
1061 struct in6_addr *ip;
1062 for (ALL_LIST_ELEMENTS_RO (tlvs.ipv6_addrs, node, ip))
1063 if (IN6_IS_ADDR_LINKLOCAL (ip))
1064 {
1065 v6_usable = 1;
1066 break;
1067 }
1068
1069 if (!v6_usable)
1070 zlog_warn ("ISIS-Adj: IPv6 addresses present but no link-local "
1071 "in LAN IIH from %s\n", circuit->interface->name);
1072 }
1073
1074 if (!(found & (TLVFLAG_IPV4_ADDR | TLVFLAG_IPV6_ADDR)))
1075 zlog_warn ("ISIS-Adj: neither IPv4 nor IPv6 addr in LAN IIH from %s\n",
1076 circuit->interface->name);
1077
1078 if (!v6_usable && !v4_usable)
1079 {
1080 free_tlvs (&tlvs);
1081 return ISIS_WARNING;
1082 }
1083
1084
1085 adj = isis_adj_lookup (hdr.source_id, circuit->u.bc.adjdb[level - 1]);
1086 if ((adj == NULL) || (memcmp(adj->snpa, ssnpa, ETH_ALEN)) ||
1087 (adj->level != level))
1088 {
1089 if (!adj)
1090 {
1091 /*
1092 * Do as in 8.4.2.5
1093 */
1094 adj = isis_new_adj (hdr.source_id, ssnpa, level, circuit);
1095 if (adj == NULL)
1096 {
1097 retval = ISIS_ERROR;
1098 goto out;
1099 }
1100 }
1101 else
1102 {
1103 if (ssnpa) {
1104 memcpy (adj->snpa, ssnpa, 6);
1105 } else {
1106 memset (adj->snpa, ' ', 6);
1107 }
1108 adj->level = level;
1109 }
1110 isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING, NULL);
1111
1112 if (level == IS_LEVEL_1)
1113 adj->sys_type = ISIS_SYSTYPE_L1_IS;
1114 else
1115 adj->sys_type = ISIS_SYSTYPE_L2_IS;
1116 list_delete_all_node (circuit->u.bc.lan_neighs[level - 1]);
1117 isis_adj_build_neigh_list (circuit->u.bc.adjdb[level - 1],
1118 circuit->u.bc.lan_neighs[level - 1]);
1119 }
1120
1121 if(adj->dis_record[level-1].dis==ISIS_IS_DIS)
1122 switch (level)
1123 {
1124 case 1:
1125 if (memcmp (circuit->u.bc.l1_desig_is, hdr.lan_id, ISIS_SYS_ID_LEN + 1))
1126 {
1127 thread_add_event(master, isis_event_dis_status_change, circuit, 0,
1128 NULL);
1129 memcpy (&circuit->u.bc.l1_desig_is, hdr.lan_id,
1130 ISIS_SYS_ID_LEN + 1);
1131 }
1132 break;
1133 case 2:
1134 if (memcmp (circuit->u.bc.l2_desig_is, hdr.lan_id, ISIS_SYS_ID_LEN + 1))
1135 {
1136 thread_add_event(master, isis_event_dis_status_change, circuit, 0,
1137 NULL);
1138 memcpy (&circuit->u.bc.l2_desig_is, hdr.lan_id,
1139 ISIS_SYS_ID_LEN + 1);
1140 }
1141 break;
1142 }
1143
1144 adj->hold_time = hdr.hold_time;
1145 adj->last_upd = time (NULL);
1146 adj->prio[level - 1] = hdr.prio;
1147
1148 memcpy (adj->lanid, hdr.lan_id, ISIS_SYS_ID_LEN + 1);
1149
1150 tlvs_to_adj_area_addrs (&tlvs, adj);
1151
1152 /* which protocol are spoken ??? */
1153 if (tlvs_to_adj_nlpids (&tlvs, adj))
1154 {
1155 retval = ISIS_WARNING;
1156 goto out;
1157 }
1158
1159 /* we need to copy addresses to the adj */
1160 if (found & TLVFLAG_IPV4_ADDR)
1161 tlvs_to_adj_ipv4_addrs (&tlvs, adj);
1162
1163 if (found & TLVFLAG_IPV6_ADDR)
1164 tlvs_to_adj_ipv6_addrs (&tlvs, adj);
1165
1166 adj->circuit_t = hdr.circuit_t;
1167
1168 bool mt_set_changed = tlvs_to_adj_mt_set(&tlvs, v4_usable, v6_usable, adj);
1169
1170 /* lets take care of the expiry */
1171 THREAD_TIMER_OFF (adj->t_expire);
1172 thread_add_timer(master, isis_adj_expire, adj, (long)adj->hold_time,
1173 &adj->t_expire);
1174
1175 /*
1176 * If the snpa for this circuit is found from LAN Neighbours TLV
1177 * we have two-way communication -> adjacency can be put to state "up"
1178 */
1179
1180 if (found & TLVFLAG_LAN_NEIGHS)
1181 {
1182 if (adj->adj_state != ISIS_ADJ_UP)
1183 {
1184 for (ALL_LIST_ELEMENTS_RO (tlvs.lan_neighs, node, snpa))
1185 {
1186 if (!memcmp (snpa, circuit->u.bc.snpa, ETH_ALEN))
1187 {
1188 isis_adj_state_change (adj, ISIS_ADJ_UP,
1189 "own SNPA found in LAN Neighbours TLV");
1190 }
1191 }
1192 }
1193 else
1194 {
1195 int found = 0;
1196 for (ALL_LIST_ELEMENTS_RO (tlvs.lan_neighs, node, snpa))
1197 if (!memcmp (snpa, circuit->u.bc.snpa, ETH_ALEN))
1198 {
1199 found = 1;
1200 break;
1201 }
1202 if (found == 0)
1203 isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING,
1204 "own SNPA not found in LAN Neighbours TLV");
1205 }
1206 }
1207 else if (adj->adj_state == ISIS_ADJ_UP)
1208 {
1209 isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING,
1210 "no LAN Neighbours TLV found");
1211 }
1212
1213 if (adj->adj_state == ISIS_ADJ_UP && mt_set_changed)
1214 lsp_regenerate_schedule(adj->circuit->area, level, 0);
1215
1216 out:
1217 if (isis->debugs & DEBUG_ADJ_PACKETS)
1218 {
1219 zlog_debug ("ISIS-Adj (%s): Rcvd L%d LAN IIH from %s on %s, cirType %s, "
1220 "cirID %u, length %zd",
1221 circuit->area->area_tag,
1222 level, snpa_print (ssnpa), circuit->interface->name,
1223 circuit_t2string (circuit->is_type),
1224 circuit->circuit_id,
1225 stream_get_endp (circuit->rcv_stream));
1226 }
1227
1228 free_tlvs (&tlvs);
1229
1230 return retval;
1231 }
1232
1233 /*
1234 * Process Level 1/2 Link State
1235 * ISO - 10589
1236 * Section 7.3.15.1 - Action on receipt of a link state PDU
1237 */
1238 static int
1239 process_lsp (int level, struct isis_circuit *circuit, const u_char *ssnpa)
1240 {
1241 struct isis_link_state_hdr *hdr;
1242 struct isis_adjacency *adj = NULL;
1243 struct isis_lsp *lsp, *lsp0 = NULL;
1244 int retval = ISIS_OK, comp = 0;
1245 u_char lspid[ISIS_SYS_ID_LEN + 2];
1246 struct isis_passwd *passwd;
1247 uint16_t pdu_len;
1248 int lsp_confusion;
1249
1250 if (isis->debugs & DEBUG_UPDATE_PACKETS)
1251 {
1252 zlog_debug ("ISIS-Upd (%s): Rcvd L%d LSP on %s, cirType %s, cirID %u",
1253 circuit->area->area_tag, level, circuit->interface->name,
1254 circuit_t2string (circuit->is_type), circuit->circuit_id);
1255 if (isis->debugs & DEBUG_PACKET_DUMP)
1256 zlog_dump_data (STREAM_DATA (circuit->rcv_stream),
1257 stream_get_endp (circuit->rcv_stream));
1258 }
1259
1260 if ((stream_get_endp (circuit->rcv_stream) -
1261 stream_get_getp (circuit->rcv_stream)) < ISIS_LSP_HDR_LEN)
1262 {
1263 zlog_warn ("Packet too short");
1264 return ISIS_WARNING;
1265 }
1266
1267 /* Reference the header */
1268 hdr = (struct isis_link_state_hdr *) STREAM_PNT (circuit->rcv_stream);
1269 pdu_len = ntohs (hdr->pdu_len);
1270
1271 /* lsp length check */
1272 if (pdu_len < (ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN) ||
1273 pdu_len > ISO_MTU(circuit) ||
1274 pdu_len > stream_get_endp (circuit->rcv_stream))
1275 {
1276 zlog_debug ("ISIS-Upd (%s): LSP %s invalid LSP length %d",
1277 circuit->area->area_tag,
1278 rawlspid_print (hdr->lsp_id), pdu_len);
1279
1280 return ISIS_WARNING;
1281 }
1282
1283 /*
1284 * Set the stream endp to PDU length, ignoring additional padding
1285 * introduced by transport chips.
1286 */
1287 if (pdu_len < stream_get_endp (circuit->rcv_stream))
1288 stream_set_endp (circuit->rcv_stream, pdu_len);
1289
1290 if (isis->debugs & DEBUG_UPDATE_PACKETS)
1291 {
1292 zlog_debug ("ISIS-Upd (%s): Rcvd L%d LSP %s, seq 0x%08x, cksum 0x%04x, "
1293 "lifetime %us, len %u, on %s",
1294 circuit->area->area_tag,
1295 level,
1296 rawlspid_print (hdr->lsp_id),
1297 ntohl (hdr->seq_num),
1298 ntohs (hdr->checksum),
1299 ntohs (hdr->rem_lifetime),
1300 pdu_len,
1301 circuit->interface->name);
1302 }
1303
1304 /* lsp is_type check */
1305 if ((hdr->lsp_bits & IS_LEVEL_1_AND_2) != IS_LEVEL_1 &&
1306 (hdr->lsp_bits & IS_LEVEL_1_AND_2) != IS_LEVEL_1_AND_2)
1307 {
1308 zlog_debug ("ISIS-Upd (%s): LSP %s invalid LSP is type %x",
1309 circuit->area->area_tag,
1310 rawlspid_print (hdr->lsp_id), hdr->lsp_bits);
1311 /* continue as per RFC1122 Be liberal in what you accept, and
1312 * conservative in what you send */
1313 }
1314
1315 /* Checksum sanity check - FIXME: move to correct place */
1316 /* 12 = sysid+pdu+remtime */
1317 if (iso_csum_verify (STREAM_PNT (circuit->rcv_stream) + 4,
1318 pdu_len - 12, &hdr->checksum))
1319 {
1320 zlog_debug ("ISIS-Upd (%s): LSP %s invalid LSP checksum 0x%04x",
1321 circuit->area->area_tag,
1322 rawlspid_print (hdr->lsp_id), ntohs (hdr->checksum));
1323
1324 return ISIS_WARNING;
1325 }
1326
1327 /* 7.3.15.1 a) 1 - external domain circuit will discard lsps */
1328 if (circuit->ext_domain)
1329 {
1330 zlog_debug
1331 ("ISIS-Upd (%s): LSP %s received at level %d over circuit with "
1332 "externalDomain = true", circuit->area->area_tag,
1333 rawlspid_print (hdr->lsp_id), level);
1334
1335 return ISIS_WARNING;
1336 }
1337
1338 /* 7.3.15.1 a) 2,3 - manualL2OnlyMode not implemented */
1339 if (!accept_level (level, circuit->is_type))
1340 {
1341 zlog_debug ("ISIS-Upd (%s): LSP %s received at level %d over circuit of"
1342 " type %s",
1343 circuit->area->area_tag,
1344 rawlspid_print (hdr->lsp_id),
1345 level, circuit_t2string (circuit->is_type));
1346
1347 return ISIS_WARNING;
1348 }
1349
1350 /* 7.3.15.1 a) 4 - need to make sure IDLength matches */
1351
1352 /* 7.3.15.1 a) 5 - maximum area match, can be ommited since we only use 3 */
1353
1354 /* 7.3.15.1 a) 7 - password check */
1355 (level == IS_LEVEL_1) ? (passwd = &circuit->area->area_passwd) :
1356 (passwd = &circuit->area->domain_passwd);
1357 if (passwd->type)
1358 {
1359 if (lsp_authentication_check (circuit->rcv_stream, circuit->area,
1360 level, passwd))
1361 {
1362 isis_event_auth_failure (circuit->area->area_tag,
1363 "LSP authentication failure", hdr->lsp_id);
1364 return ISIS_WARNING;
1365 }
1366 }
1367 /* Find the LSP in our database and compare it to this Link State header */
1368 lsp = lsp_search (hdr->lsp_id, circuit->area->lspdb[level - 1]);
1369 if (lsp)
1370 comp = lsp_compare (circuit->area->area_tag, lsp, hdr->seq_num,
1371 hdr->checksum, hdr->rem_lifetime);
1372 if (lsp && (lsp->own_lsp))
1373 goto dontcheckadj;
1374
1375 /* 7.3.15.1 a) 6 - Must check that we have an adjacency of the same level */
1376 /* for broadcast circuits, snpa should be compared */
1377
1378 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
1379 {
1380 adj = isis_adj_lookup_snpa (ssnpa, circuit->u.bc.adjdb[level - 1]);
1381 if (!adj)
1382 {
1383 zlog_debug ("(%s): DS ======= LSP %s, seq 0x%08x, cksum 0x%04x, "
1384 "lifetime %us on %s",
1385 circuit->area->area_tag,
1386 rawlspid_print (hdr->lsp_id),
1387 ntohl (hdr->seq_num),
1388 ntohs (hdr->checksum),
1389 ntohs (hdr->rem_lifetime), circuit->interface->name);
1390 return ISIS_WARNING; /* Silently discard */
1391 }
1392 }
1393 /* for non broadcast, we just need to find same level adj */
1394 else
1395 {
1396 /* If no adj, or no sharing of level */
1397 if (!circuit->u.p2p.neighbor)
1398 {
1399 return ISIS_OK; /* Silently discard */
1400 }
1401 else
1402 {
1403 if (((level == IS_LEVEL_1) &&
1404 (circuit->u.p2p.neighbor->adj_usage == ISIS_ADJ_LEVEL2)) ||
1405 ((level == IS_LEVEL_2) &&
1406 (circuit->u.p2p.neighbor->adj_usage == ISIS_ADJ_LEVEL1)))
1407 return ISIS_WARNING; /* Silently discard */
1408 adj = circuit->u.p2p.neighbor;
1409 }
1410 }
1411
1412 dontcheckadj:
1413 /* 7.3.15.1 a) 7 - Passwords for level 1 - not implemented */
1414
1415 /* 7.3.15.1 a) 8 - Passwords for level 2 - not implemented */
1416
1417 /* 7.3.15.1 a) 9 - OriginatingLSPBufferSize - not implemented FIXME: do it */
1418
1419 /* 7.3.16.2 - If this is an LSP from another IS with identical seq_num but
1420 * wrong checksum, initiate a purge. */
1421 if (lsp
1422 && (lsp->lsp_header->seq_num == hdr->seq_num)
1423 && (lsp->lsp_header->checksum != hdr->checksum))
1424 {
1425 zlog_warn("ISIS-Upd (%s): LSP %s seq 0x%08x with confused checksum received.",
1426 circuit->area->area_tag, rawlspid_print(hdr->lsp_id),
1427 ntohl(hdr->seq_num));
1428 hdr->rem_lifetime = 0;
1429 lsp_confusion = 1;
1430 }
1431 else
1432 lsp_confusion = 0;
1433
1434 /* 7.3.15.1 b) - If the remaining life time is 0, we perform 7.3.16.4 */
1435 if (hdr->rem_lifetime == 0)
1436 {
1437 if (!lsp)
1438 {
1439 /* 7.3.16.4 a) 1) No LSP in db -> send an ack, but don't save */
1440 /* only needed on explicit update, eg - p2p */
1441 if (circuit->circ_type == CIRCUIT_T_P2P)
1442 ack_lsp (hdr, circuit, level);
1443 return retval; /* FIXME: do we need a purge? */
1444 }
1445 else
1446 {
1447 if (memcmp (hdr->lsp_id, isis->sysid, ISIS_SYS_ID_LEN))
1448 {
1449 /* LSP by some other system -> do 7.3.16.4 b) */
1450 /* 7.3.16.4 b) 1) */
1451 if (comp == LSP_NEWER)
1452 {
1453 lsp_update (lsp, circuit->rcv_stream, circuit->area, level);
1454 /* ii */
1455 lsp_set_all_srmflags (lsp);
1456 /* v */
1457 ISIS_FLAGS_CLEAR_ALL (lsp->SSNflags); /* FIXME: OTHER than c */
1458
1459 /* For the case of lsp confusion, flood the purge back to its
1460 * originator so that it can react. Otherwise, don't reflood
1461 * through incoming circuit as usual */
1462 if (!lsp_confusion)
1463 {
1464 /* iii */
1465 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
1466 /* iv */
1467 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
1468 ISIS_SET_FLAG (lsp->SSNflags, circuit);
1469 }
1470 } /* 7.3.16.4 b) 2) */
1471 else if (comp == LSP_EQUAL)
1472 {
1473 /* i */
1474 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
1475 /* ii */
1476 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
1477 ISIS_SET_FLAG (lsp->SSNflags, circuit);
1478 } /* 7.3.16.4 b) 3) */
1479 else
1480 {
1481 ISIS_SET_FLAG (lsp->SRMflags, circuit);
1482 ISIS_CLEAR_FLAG (lsp->SSNflags, circuit);
1483 }
1484 }
1485 else if (lsp->lsp_header->rem_lifetime != 0)
1486 {
1487 /* our own LSP -> 7.3.16.4 c) */
1488 if (comp == LSP_NEWER)
1489 {
1490 lsp_inc_seqnum (lsp, ntohl (hdr->seq_num));
1491 lsp_set_all_srmflags (lsp);
1492 }
1493 else
1494 {
1495 ISIS_SET_FLAG (lsp->SRMflags, circuit);
1496 ISIS_CLEAR_FLAG (lsp->SSNflags, circuit);
1497 }
1498 if (isis->debugs & DEBUG_UPDATE_PACKETS)
1499 zlog_debug ("ISIS-Upd (%s): (1) re-originating LSP %s new "
1500 "seq 0x%08x", circuit->area->area_tag,
1501 rawlspid_print (hdr->lsp_id),
1502 ntohl (lsp->lsp_header->seq_num));
1503 }
1504 }
1505 return retval;
1506 }
1507 /* 7.3.15.1 c) - If this is our own lsp and we don't have it initiate a
1508 * purge */
1509 if (memcmp (hdr->lsp_id, isis->sysid, ISIS_SYS_ID_LEN) == 0)
1510 {
1511 if (!lsp)
1512 {
1513 /* 7.3.16.4: initiate a purge */
1514 lsp_purge_non_exist(level, hdr, circuit->area);
1515 return ISIS_OK;
1516 }
1517 /* 7.3.15.1 d) - If this is our own lsp and we have it */
1518
1519 /* In 7.3.16.1, If an Intermediate system R somewhere in the domain
1520 * has information that the current sequence number for source S is
1521 * "greater" than that held by S, ... */
1522
1523 if (ntohl (hdr->seq_num) > ntohl (lsp->lsp_header->seq_num))
1524 {
1525 /* 7.3.16.1 */
1526 lsp_inc_seqnum (lsp, ntohl (hdr->seq_num));
1527 if (isis->debugs & DEBUG_UPDATE_PACKETS)
1528 zlog_debug ("ISIS-Upd (%s): (2) re-originating LSP %s new seq "
1529 "0x%08x", circuit->area->area_tag,
1530 rawlspid_print (hdr->lsp_id),
1531 ntohl (lsp->lsp_header->seq_num));
1532 }
1533 /* If the received LSP is older or equal,
1534 * resend the LSP which will act as ACK */
1535 lsp_set_all_srmflags (lsp);
1536 }
1537 else
1538 {
1539 /* 7.3.15.1 e) - This lsp originated on another system */
1540
1541 /* 7.3.15.1 e) 1) LSP newer than the one in db or no LSP in db */
1542 if ((!lsp || comp == LSP_NEWER))
1543 {
1544 /*
1545 * If this lsp is a frag, need to see if we have zero lsp present
1546 */
1547 if (LSP_FRAGMENT (hdr->lsp_id) != 0)
1548 {
1549 memcpy (lspid, hdr->lsp_id, ISIS_SYS_ID_LEN + 1);
1550 LSP_FRAGMENT (lspid) = 0;
1551 lsp0 = lsp_search (lspid, circuit->area->lspdb[level - 1]);
1552 if (!lsp0)
1553 {
1554 zlog_debug ("Got lsp frag, while zero lsp not in database");
1555 return ISIS_OK;
1556 }
1557 }
1558 /* i */
1559 if (!lsp)
1560 {
1561 lsp = lsp_new_from_stream_ptr (circuit->rcv_stream,
1562 pdu_len, lsp0,
1563 circuit->area, level);
1564 lsp_insert (lsp, circuit->area->lspdb[level - 1]);
1565 }
1566 else /* exists, so we overwrite */
1567 {
1568 lsp_update (lsp, circuit->rcv_stream, circuit->area, level);
1569 }
1570 /* ii */
1571 lsp_set_all_srmflags (lsp);
1572 /* iii */
1573 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
1574
1575 /* iv */
1576 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
1577 ISIS_SET_FLAG (lsp->SSNflags, circuit);
1578 /* FIXME: v) */
1579 }
1580 /* 7.3.15.1 e) 2) LSP equal to the one in db */
1581 else if (comp == LSP_EQUAL)
1582 {
1583 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
1584 lsp_update (lsp, circuit->rcv_stream, circuit->area, level);
1585 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
1586 ISIS_SET_FLAG (lsp->SSNflags, circuit);
1587 }
1588 /* 7.3.15.1 e) 3) LSP older than the one in db */
1589 else
1590 {
1591 ISIS_SET_FLAG (lsp->SRMflags, circuit);
1592 ISIS_CLEAR_FLAG (lsp->SSNflags, circuit);
1593 }
1594 }
1595 return retval;
1596 }
1597
1598 /*
1599 * Process Sequence Numbers
1600 * ISO - 10589
1601 * Section 7.3.15.2 - Action on receipt of a sequence numbers PDU
1602 */
1603
1604 static int
1605 process_snp (int snp_type, int level, struct isis_circuit *circuit,
1606 const u_char *ssnpa)
1607 {
1608 int retval = ISIS_OK;
1609 int cmp, own_lsp;
1610 char typechar = ' ';
1611 uint16_t pdu_len;
1612 struct isis_adjacency *adj;
1613 struct isis_complete_seqnum_hdr *chdr = NULL;
1614 struct isis_partial_seqnum_hdr *phdr = NULL;
1615 uint32_t found = 0, expected = 0, auth_tlv_offset = 0;
1616 struct isis_lsp *lsp;
1617 struct lsp_entry *entry;
1618 struct listnode *node, *nnode;
1619 struct listnode *node2, *nnode2;
1620 struct tlvs tlvs;
1621 struct list *lsp_list = NULL;
1622 struct isis_passwd *passwd;
1623
1624 if (snp_type == ISIS_SNP_CSNP_FLAG)
1625 {
1626 /* getting the header info */
1627 typechar = 'C';
1628 chdr =
1629 (struct isis_complete_seqnum_hdr *) STREAM_PNT (circuit->rcv_stream);
1630 stream_forward_getp (circuit->rcv_stream, ISIS_CSNP_HDRLEN);
1631 pdu_len = ntohs (chdr->pdu_len);
1632 if (pdu_len < (ISIS_FIXED_HDR_LEN + ISIS_CSNP_HDRLEN) ||
1633 pdu_len > ISO_MTU(circuit) ||
1634 pdu_len > stream_get_endp (circuit->rcv_stream))
1635 {
1636 zlog_warn ("Received a CSNP with bogus length %d", pdu_len);
1637 return ISIS_WARNING;
1638 }
1639 }
1640 else
1641 {
1642 typechar = 'P';
1643 phdr =
1644 (struct isis_partial_seqnum_hdr *) STREAM_PNT (circuit->rcv_stream);
1645 stream_forward_getp (circuit->rcv_stream, ISIS_PSNP_HDRLEN);
1646 pdu_len = ntohs (phdr->pdu_len);
1647 if (pdu_len < (ISIS_FIXED_HDR_LEN + ISIS_PSNP_HDRLEN) ||
1648 pdu_len > ISO_MTU(circuit) ||
1649 pdu_len > stream_get_endp (circuit->rcv_stream))
1650 {
1651 zlog_warn ("Received a PSNP with bogus length %d", pdu_len);
1652 return ISIS_WARNING;
1653 }
1654 }
1655
1656 /*
1657 * Set the stream endp to PDU length, ignoring additional padding
1658 * introduced by transport chips.
1659 */
1660 if (pdu_len < stream_get_endp (circuit->rcv_stream))
1661 stream_set_endp (circuit->rcv_stream, pdu_len);
1662
1663 /* 7.3.15.2 a) 1 - external domain circuit will discard snp pdu */
1664 if (circuit->ext_domain)
1665 {
1666
1667 zlog_debug ("ISIS-Snp (%s): Rcvd L%d %cSNP on %s, "
1668 "skipping: circuit externalDomain = true",
1669 circuit->area->area_tag,
1670 level, typechar, circuit->interface->name);
1671
1672 return ISIS_OK;
1673 }
1674
1675 /* 7.3.15.2 a) 2,3 - manualL2OnlyMode not implemented */
1676 if (!accept_level (level, circuit->is_type))
1677 {
1678
1679 zlog_debug ("ISIS-Snp (%s): Rcvd L%d %cSNP on %s, "
1680 "skipping: circuit type %s does not match level %d",
1681 circuit->area->area_tag,
1682 level,
1683 typechar,
1684 circuit->interface->name,
1685 circuit_t2string (circuit->is_type), level);
1686
1687 return ISIS_OK;
1688 }
1689
1690 /* 7.3.15.2 a) 4 - not applicable for CSNP only PSNPs on broadcast */
1691 if ((snp_type == ISIS_SNP_PSNP_FLAG) &&
1692 (circuit->circ_type == CIRCUIT_T_BROADCAST) &&
1693 (!circuit->u.bc.is_dr[level - 1]))
1694 {
1695 zlog_debug ("ISIS-Snp (%s): Rcvd L%d %cSNP from %s on %s, "
1696 "skipping: we are not the DIS",
1697 circuit->area->area_tag,
1698 level,
1699 typechar, snpa_print (ssnpa), circuit->interface->name);
1700
1701 return ISIS_OK;
1702 }
1703
1704 /* 7.3.15.2 a) 5 - need to make sure IDLength matches - already checked */
1705
1706 /* 7.3.15.2 a) 6 - maximum area match, can be ommited since we only use 3
1707 * - already checked */
1708
1709 /* 7.3.15.2 a) 7 - Must check that we have an adjacency of the same level */
1710 /* for broadcast circuits, snpa should be compared */
1711 /* FIXME : Do we need to check SNPA? */
1712 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
1713 {
1714 if (snp_type == ISIS_SNP_CSNP_FLAG)
1715 {
1716 adj =
1717 isis_adj_lookup (chdr->source_id, circuit->u.bc.adjdb[level - 1]);
1718 }
1719 else
1720 {
1721 /* a psnp on a broadcast, how lovely of Juniper :) */
1722 adj =
1723 isis_adj_lookup (phdr->source_id, circuit->u.bc.adjdb[level - 1]);
1724 }
1725 if (!adj)
1726 return ISIS_OK; /* Silently discard */
1727 }
1728 else
1729 {
1730 if (!circuit->u.p2p.neighbor)
1731 {
1732 zlog_warn ("no p2p neighbor on circuit %s", circuit->interface->name);
1733 return ISIS_OK; /* Silently discard */
1734 }
1735 }
1736
1737 /* 7.3.15.2 a) 8 - Passwords for level 1 - not implemented */
1738
1739 /* 7.3.15.2 a) 9 - Passwords for level 2 - not implemented */
1740
1741 memset (&tlvs, 0, sizeof (struct tlvs));
1742
1743 /* parse the SNP */
1744 expected |= TLVFLAG_LSP_ENTRIES;
1745 expected |= TLVFLAG_AUTH_INFO;
1746
1747 auth_tlv_offset = stream_get_getp (circuit->rcv_stream);
1748 retval = parse_tlvs (circuit->area->area_tag,
1749 STREAM_PNT (circuit->rcv_stream),
1750 pdu_len - stream_get_getp (circuit->rcv_stream),
1751 &expected, &found, &tlvs, &auth_tlv_offset);
1752
1753 if (retval > ISIS_WARNING)
1754 {
1755 zlog_warn ("something went very wrong processing SNP");
1756 free_tlvs (&tlvs);
1757 return retval;
1758 }
1759
1760 if (level == IS_LEVEL_1)
1761 passwd = &circuit->area->area_passwd;
1762 else
1763 passwd = &circuit->area->domain_passwd;
1764
1765 if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_RECV))
1766 {
1767 if (passwd->type)
1768 {
1769 if (!(found & TLVFLAG_AUTH_INFO) ||
1770 authentication_check (&tlvs.auth_info, passwd,
1771 circuit->rcv_stream, auth_tlv_offset))
1772 {
1773 isis_event_auth_failure (circuit->area->area_tag,
1774 "SNP authentication" " failure",
1775 phdr ? phdr->source_id :
1776 chdr->source_id);
1777 free_tlvs (&tlvs);
1778 return ISIS_OK;
1779 }
1780 }
1781 }
1782
1783 /* debug isis snp-packets */
1784 if (isis->debugs & DEBUG_SNP_PACKETS)
1785 {
1786 zlog_debug ("ISIS-Snp (%s): Rcvd L%d %cSNP from %s on %s",
1787 circuit->area->area_tag,
1788 level,
1789 typechar, snpa_print (ssnpa), circuit->interface->name);
1790 if (tlvs.lsp_entries)
1791 {
1792 for (ALL_LIST_ELEMENTS_RO (tlvs.lsp_entries, node, entry))
1793 {
1794 zlog_debug ("ISIS-Snp (%s): %cSNP entry %s, seq 0x%08x,"
1795 " cksum 0x%04x, lifetime %us",
1796 circuit->area->area_tag,
1797 typechar,
1798 rawlspid_print (entry->lsp_id),
1799 ntohl (entry->seq_num),
1800 ntohs (entry->checksum), ntohs (entry->rem_lifetime));
1801 }
1802 }
1803 }
1804
1805 /* 7.3.15.2 b) Actions on LSP_ENTRIES reported */
1806 if (tlvs.lsp_entries)
1807 {
1808 for (ALL_LIST_ELEMENTS_RO (tlvs.lsp_entries, node, entry))
1809 {
1810 lsp = lsp_search (entry->lsp_id, circuit->area->lspdb[level - 1]);
1811 own_lsp = !memcmp (entry->lsp_id, isis->sysid, ISIS_SYS_ID_LEN);
1812 if (lsp)
1813 {
1814 /* 7.3.15.2 b) 1) is this LSP newer */
1815 cmp = lsp_compare (circuit->area->area_tag, lsp, entry->seq_num,
1816 entry->checksum, entry->rem_lifetime);
1817 /* 7.3.15.2 b) 2) if it equals, clear SRM on p2p */
1818 if (cmp == LSP_EQUAL)
1819 {
1820 /* if (circuit->circ_type != CIRCUIT_T_BROADCAST) */
1821 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
1822 }
1823 /* 7.3.15.2 b) 3) if it is older, clear SSN and set SRM */
1824 else if (cmp == LSP_OLDER)
1825 {
1826 ISIS_CLEAR_FLAG (lsp->SSNflags, circuit);
1827 ISIS_SET_FLAG (lsp->SRMflags, circuit);
1828 }
1829 /* 7.3.15.2 b) 4) if it is newer, set SSN and clear SRM on p2p */
1830 else
1831 {
1832 if (own_lsp)
1833 {
1834 lsp_inc_seqnum (lsp, ntohl (entry->seq_num));
1835 ISIS_SET_FLAG (lsp->SRMflags, circuit);
1836 }
1837 else
1838 {
1839 ISIS_SET_FLAG (lsp->SSNflags, circuit);
1840 /* if (circuit->circ_type != CIRCUIT_T_BROADCAST) */
1841 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
1842 }
1843 }
1844 }
1845 else
1846 {
1847 /* 7.3.15.2 b) 5) if it was not found, and all of those are not 0,
1848 * insert it and set SSN on it */
1849 if (entry->rem_lifetime && entry->checksum && entry->seq_num &&
1850 memcmp (entry->lsp_id, isis->sysid, ISIS_SYS_ID_LEN))
1851 {
1852 lsp = lsp_new(circuit->area, entry->lsp_id,
1853 ntohs(entry->rem_lifetime),
1854 0, 0, entry->checksum, level);
1855 lsp_insert (lsp, circuit->area->lspdb[level - 1]);
1856 ISIS_FLAGS_CLEAR_ALL (lsp->SRMflags);
1857 ISIS_SET_FLAG (lsp->SSNflags, circuit);
1858 }
1859 }
1860 }
1861 }
1862
1863 /* 7.3.15.2 c) on CSNP set SRM for all in range which were not reported */
1864 if (snp_type == ISIS_SNP_CSNP_FLAG)
1865 {
1866 /*
1867 * Build a list from our own LSP db bounded with
1868 * start_lsp_id and stop_lsp_id
1869 */
1870 lsp_list = list_new ();
1871 lsp_build_list_nonzero_ht (chdr->start_lsp_id, chdr->stop_lsp_id,
1872 lsp_list, circuit->area->lspdb[level - 1]);
1873
1874 /* Fixme: Find a better solution */
1875 if (tlvs.lsp_entries)
1876 {
1877 for (ALL_LIST_ELEMENTS (tlvs.lsp_entries, node, nnode, entry))
1878 {
1879 for (ALL_LIST_ELEMENTS (lsp_list, node2, nnode2, lsp))
1880 {
1881 if (lsp_id_cmp (lsp->lsp_header->lsp_id, entry->lsp_id) == 0)
1882 {
1883 list_delete_node (lsp_list, node2);
1884 break;
1885 }
1886 }
1887 }
1888 }
1889 /* on remaining LSPs we set SRM (neighbor knew not of) */
1890 for (ALL_LIST_ELEMENTS_RO (lsp_list, node, lsp))
1891 ISIS_SET_FLAG (lsp->SRMflags, circuit);
1892 /* lets free it */
1893 list_delete (lsp_list);
1894
1895 }
1896
1897 free_tlvs (&tlvs);
1898 return retval;
1899 }
1900
1901 static int
1902 process_csnp (int level, struct isis_circuit *circuit, const u_char *ssnpa)
1903 {
1904 if (isis->debugs & DEBUG_SNP_PACKETS)
1905 {
1906 zlog_debug ("ISIS-Snp (%s): Rcvd L%d CSNP on %s, cirType %s, cirID %u",
1907 circuit->area->area_tag, level, circuit->interface->name,
1908 circuit_t2string (circuit->is_type), circuit->circuit_id);
1909 if (isis->debugs & DEBUG_PACKET_DUMP)
1910 zlog_dump_data (STREAM_DATA (circuit->rcv_stream),
1911 stream_get_endp (circuit->rcv_stream));
1912 }
1913
1914 /* Sanity check - FIXME: move to correct place */
1915 if ((stream_get_endp (circuit->rcv_stream) -
1916 stream_get_getp (circuit->rcv_stream)) < ISIS_CSNP_HDRLEN)
1917 {
1918 zlog_warn ("Packet too short ( < %d)", ISIS_CSNP_HDRLEN);
1919 return ISIS_WARNING;
1920 }
1921
1922 return process_snp (ISIS_SNP_CSNP_FLAG, level, circuit, ssnpa);
1923 }
1924
1925 static int
1926 process_psnp (int level, struct isis_circuit *circuit, const u_char *ssnpa)
1927 {
1928 if (isis->debugs & DEBUG_SNP_PACKETS)
1929 {
1930 zlog_debug ("ISIS-Snp (%s): Rcvd L%d PSNP on %s, cirType %s, cirID %u",
1931 circuit->area->area_tag, level, circuit->interface->name,
1932 circuit_t2string (circuit->is_type), circuit->circuit_id);
1933 if (isis->debugs & DEBUG_PACKET_DUMP)
1934 zlog_dump_data (STREAM_DATA (circuit->rcv_stream),
1935 stream_get_endp (circuit->rcv_stream));
1936 }
1937
1938 if ((stream_get_endp (circuit->rcv_stream) -
1939 stream_get_getp (circuit->rcv_stream)) < ISIS_PSNP_HDRLEN)
1940 {
1941 zlog_warn ("Packet too short ( < %d)", ISIS_PSNP_HDRLEN);
1942 return ISIS_WARNING;
1943 }
1944
1945 return process_snp (ISIS_SNP_PSNP_FLAG, level, circuit, ssnpa);
1946 }
1947
1948 /*
1949 * PDU Dispatcher
1950 */
1951
1952 static int
1953 isis_handle_pdu (struct isis_circuit *circuit, u_char * ssnpa)
1954 {
1955 struct isis_fixed_hdr *hdr;
1956
1957 int retval = ISIS_OK;
1958
1959 /*
1960 * Let's first read data from stream to the header
1961 */
1962 hdr = (struct isis_fixed_hdr *) STREAM_DATA (circuit->rcv_stream);
1963
1964 if ((hdr->idrp != ISO10589_ISIS) && (hdr->idrp != ISO9542_ESIS))
1965 {
1966 zlog_err ("Not an IS-IS or ES-IS packet IDRP=%02x", hdr->idrp);
1967 return ISIS_ERROR;
1968 }
1969
1970 /* now we need to know if this is an ISO 9542 packet and
1971 * take real good care of it, waaa!
1972 */
1973 if (hdr->idrp == ISO9542_ESIS)
1974 {
1975 zlog_err ("No support for ES-IS packet IDRP=%02x", hdr->idrp);
1976 return ISIS_ERROR;
1977 }
1978 stream_set_getp (circuit->rcv_stream, ISIS_FIXED_HDR_LEN);
1979
1980 /*
1981 * and then process it
1982 */
1983
1984 if (hdr->length < ISIS_MINIMUM_FIXED_HDR_LEN)
1985 {
1986 zlog_err ("Fixed header length = %d", hdr->length);
1987 return ISIS_ERROR;
1988 }
1989
1990 if (hdr->version1 != 1)
1991 {
1992 zlog_warn ("Unsupported ISIS version %u", hdr->version1);
1993 return ISIS_WARNING;
1994 }
1995 /* either 6 or 0 */
1996 if ((hdr->id_len != 0) && (hdr->id_len != ISIS_SYS_ID_LEN))
1997 {
1998 zlog_err
1999 ("IDFieldLengthMismatch: ID Length field in a received PDU %u, "
2000 "while the parameter for this IS is %u", hdr->id_len,
2001 ISIS_SYS_ID_LEN);
2002 return ISIS_ERROR;
2003 }
2004
2005 if (hdr->version2 != 1)
2006 {
2007 zlog_warn ("Unsupported ISIS version %u", hdr->version2);
2008 return ISIS_WARNING;
2009 }
2010
2011 if (circuit->is_passive)
2012 {
2013 zlog_warn ("Received ISIS PDU on passive circuit %s",
2014 circuit->interface->name);
2015 return ISIS_WARNING;
2016 }
2017
2018 /* either 3 or 0 */
2019 if ((hdr->max_area_addrs != 0)
2020 && (hdr->max_area_addrs != isis->max_area_addrs))
2021 {
2022 zlog_err ("maximumAreaAddressesMismatch: maximumAreaAdresses in a "
2023 "received PDU %u while the parameter for this IS is %u",
2024 hdr->max_area_addrs, isis->max_area_addrs);
2025 return ISIS_ERROR;
2026 }
2027
2028 switch (hdr->pdu_type)
2029 {
2030 case L1_LAN_HELLO:
2031 retval = process_lan_hello (ISIS_LEVEL1, circuit, ssnpa);
2032 break;
2033 case L2_LAN_HELLO:
2034 retval = process_lan_hello (ISIS_LEVEL2, circuit, ssnpa);
2035 break;
2036 case P2P_HELLO:
2037 retval = process_p2p_hello (circuit);
2038 break;
2039 case L1_LINK_STATE:
2040 retval = process_lsp (ISIS_LEVEL1, circuit, ssnpa);
2041 break;
2042 case L2_LINK_STATE:
2043 retval = process_lsp (ISIS_LEVEL2, circuit, ssnpa);
2044 break;
2045 case L1_COMPLETE_SEQ_NUM:
2046 retval = process_csnp (ISIS_LEVEL1, circuit, ssnpa);
2047 break;
2048 case L2_COMPLETE_SEQ_NUM:
2049 retval = process_csnp (ISIS_LEVEL2, circuit, ssnpa);
2050 break;
2051 case L1_PARTIAL_SEQ_NUM:
2052 retval = process_psnp (ISIS_LEVEL1, circuit, ssnpa);
2053 break;
2054 case L2_PARTIAL_SEQ_NUM:
2055 retval = process_psnp (ISIS_LEVEL2, circuit, ssnpa);
2056 break;
2057 default:
2058 return ISIS_ERROR;
2059 }
2060
2061 return retval;
2062 }
2063
2064 int
2065 isis_receive (struct thread *thread)
2066 {
2067 struct isis_circuit *circuit;
2068 u_char ssnpa[ETH_ALEN];
2069 int retval;
2070
2071 /*
2072 * Get the circuit
2073 */
2074 circuit = THREAD_ARG (thread);
2075 assert (circuit);
2076
2077 circuit->t_read = NULL;
2078
2079 isis_circuit_stream(circuit, &circuit->rcv_stream);
2080
2081 retval = circuit->rx (circuit, ssnpa);
2082
2083 if (retval == ISIS_OK)
2084 retval = isis_handle_pdu (circuit, ssnpa);
2085
2086 /*
2087 * prepare for next packet.
2088 */
2089 if (!circuit->is_passive)
2090 isis_circuit_prepare (circuit);
2091
2092 return retval;
2093 }
2094
2095 /* filling of the fixed isis header */
2096 void
2097 fill_fixed_hdr (struct isis_fixed_hdr *hdr, u_char pdu_type)
2098 {
2099 memset (hdr, 0, sizeof (struct isis_fixed_hdr));
2100
2101 hdr->idrp = ISO10589_ISIS;
2102
2103 switch (pdu_type)
2104 {
2105 case L1_LAN_HELLO:
2106 case L2_LAN_HELLO:
2107 hdr->length = ISIS_LANHELLO_HDRLEN;
2108 break;
2109 case P2P_HELLO:
2110 hdr->length = ISIS_P2PHELLO_HDRLEN;
2111 break;
2112 case L1_LINK_STATE:
2113 case L2_LINK_STATE:
2114 hdr->length = ISIS_LSP_HDR_LEN;
2115 break;
2116 case L1_COMPLETE_SEQ_NUM:
2117 case L2_COMPLETE_SEQ_NUM:
2118 hdr->length = ISIS_CSNP_HDRLEN;
2119 break;
2120 case L1_PARTIAL_SEQ_NUM:
2121 case L2_PARTIAL_SEQ_NUM:
2122 hdr->length = ISIS_PSNP_HDRLEN;
2123 break;
2124 default:
2125 zlog_warn ("fill_fixed_hdr(): unknown pdu type %d", pdu_type);
2126 return;
2127 }
2128 hdr->length += ISIS_FIXED_HDR_LEN;
2129 hdr->pdu_type = pdu_type;
2130 hdr->version1 = 1;
2131 hdr->id_len = 0; /* ISIS_SYS_ID_LEN - 0==6 */
2132 hdr->version2 = 1;
2133 hdr->max_area_addrs = 0; /* isis->max_area_addrs - 0==3 */
2134 }
2135
2136 /*
2137 * SEND SIDE
2138 */
2139 static void
2140 fill_fixed_hdr_andstream (struct isis_fixed_hdr *hdr, u_char pdu_type,
2141 struct stream *stream)
2142 {
2143 fill_fixed_hdr (hdr, pdu_type);
2144
2145 stream_putc (stream, hdr->idrp);
2146 stream_putc (stream, hdr->length);
2147 stream_putc (stream, hdr->version1);
2148 stream_putc (stream, hdr->id_len);
2149 stream_putc (stream, hdr->pdu_type);
2150 stream_putc (stream, hdr->version2);
2151 stream_putc (stream, hdr->reserved);
2152 stream_putc (stream, hdr->max_area_addrs);
2153
2154 return;
2155 }
2156
2157 int
2158 send_hello (struct isis_circuit *circuit, int level)
2159 {
2160 struct isis_fixed_hdr fixed_hdr;
2161 struct isis_lan_hello_hdr hello_hdr;
2162 struct isis_p2p_hello_hdr p2p_hello_hdr;
2163 unsigned char hmac_md5_hash[ISIS_AUTH_MD5_SIZE];
2164 size_t len_pointer, length, auth_tlv_offset = 0;
2165 u_int32_t interval;
2166 int retval;
2167
2168 if (circuit->is_passive)
2169 return ISIS_OK;
2170
2171 if (circuit->interface->mtu == 0)
2172 {
2173 zlog_warn ("circuit has zero MTU");
2174 return ISIS_WARNING;
2175 }
2176
2177 isis_circuit_stream(circuit, &circuit->snd_stream);
2178
2179 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
2180 if (level == IS_LEVEL_1)
2181 fill_fixed_hdr_andstream (&fixed_hdr, L1_LAN_HELLO,
2182 circuit->snd_stream);
2183 else
2184 fill_fixed_hdr_andstream (&fixed_hdr, L2_LAN_HELLO,
2185 circuit->snd_stream);
2186 else
2187 fill_fixed_hdr_andstream (&fixed_hdr, P2P_HELLO, circuit->snd_stream);
2188
2189 /*
2190 * Fill LAN Level 1 or 2 Hello PDU header
2191 */
2192 memset (&hello_hdr, 0, sizeof (struct isis_lan_hello_hdr));
2193 interval = circuit->hello_multiplier[level - 1] *
2194 circuit->hello_interval[level - 1];
2195 if (interval > USHRT_MAX)
2196 interval = USHRT_MAX;
2197 hello_hdr.circuit_t = circuit->is_type;
2198 memcpy (hello_hdr.source_id, isis->sysid, ISIS_SYS_ID_LEN);
2199 hello_hdr.hold_time = htons ((u_int16_t) interval);
2200
2201 hello_hdr.pdu_len = 0; /* Update the PDU Length later */
2202 len_pointer = stream_get_endp (circuit->snd_stream) + 3 + ISIS_SYS_ID_LEN;
2203
2204 /* copy the shared part of the hello to the p2p hello if needed */
2205 if (circuit->circ_type == CIRCUIT_T_P2P)
2206 {
2207 memcpy (&p2p_hello_hdr, &hello_hdr, 5 + ISIS_SYS_ID_LEN);
2208 p2p_hello_hdr.local_id = circuit->circuit_id;
2209 /* FIXME: need better understanding */
2210 stream_put (circuit->snd_stream, &p2p_hello_hdr, ISIS_P2PHELLO_HDRLEN);
2211 }
2212 else
2213 {
2214 hello_hdr.prio = circuit->priority[level - 1];
2215 if (level == IS_LEVEL_1)
2216 {
2217 memcpy (hello_hdr.lan_id, circuit->u.bc.l1_desig_is,
2218 ISIS_SYS_ID_LEN + 1);
2219 }
2220 else if (level == IS_LEVEL_2)
2221 {
2222 memcpy (hello_hdr.lan_id, circuit->u.bc.l2_desig_is,
2223 ISIS_SYS_ID_LEN + 1);
2224 }
2225 stream_put (circuit->snd_stream, &hello_hdr, ISIS_LANHELLO_HDRLEN);
2226 }
2227
2228 /*
2229 * Then the variable length part.
2230 */
2231
2232 /* add circuit password */
2233 switch (circuit->passwd.type)
2234 {
2235 /* Cleartext */
2236 case ISIS_PASSWD_TYPE_CLEARTXT:
2237 if (tlv_add_authinfo (circuit->passwd.type, circuit->passwd.len,
2238 circuit->passwd.passwd, circuit->snd_stream))
2239 return ISIS_WARNING;
2240 break;
2241
2242 /* HMAC MD5 */
2243 case ISIS_PASSWD_TYPE_HMAC_MD5:
2244 /* Remember where TLV is written so we can later overwrite the MD5 hash */
2245 auth_tlv_offset = stream_get_endp (circuit->snd_stream);
2246 memset(&hmac_md5_hash, 0, ISIS_AUTH_MD5_SIZE);
2247 if (tlv_add_authinfo (circuit->passwd.type, ISIS_AUTH_MD5_SIZE,
2248 hmac_md5_hash, circuit->snd_stream))
2249 return ISIS_WARNING;
2250 break;
2251
2252 default:
2253 break;
2254 }
2255
2256 /* Area Addresses TLV */
2257 if (listcount (circuit->area->area_addrs) == 0)
2258 return ISIS_WARNING;
2259 if (tlv_add_area_addrs (circuit->area->area_addrs, circuit->snd_stream))
2260 return ISIS_WARNING;
2261
2262 /* LAN Neighbors TLV */
2263 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
2264 {
2265 if (level == IS_LEVEL_1 && circuit->u.bc.lan_neighs[0] &&
2266 listcount (circuit->u.bc.lan_neighs[0]) > 0)
2267 if (tlv_add_lan_neighs (circuit->u.bc.lan_neighs[0],
2268 circuit->snd_stream))
2269 return ISIS_WARNING;
2270 if (level == IS_LEVEL_2 && circuit->u.bc.lan_neighs[1] &&
2271 listcount (circuit->u.bc.lan_neighs[1]) > 0)
2272 if (tlv_add_lan_neighs (circuit->u.bc.lan_neighs[1],
2273 circuit->snd_stream))
2274 return ISIS_WARNING;
2275 }
2276
2277 /* Protocols Supported TLV */
2278 if (circuit->nlpids.count > 0)
2279 if (tlv_add_nlpid (&circuit->nlpids, circuit->snd_stream))
2280 return ISIS_WARNING;
2281 /* IP interface Address TLV */
2282 if (circuit->ip_router && circuit->ip_addrs &&
2283 listcount (circuit->ip_addrs) > 0)
2284 if (tlv_add_ip_addrs (circuit->ip_addrs, circuit->snd_stream))
2285 return ISIS_WARNING;
2286
2287 /*
2288 * MT Supported TLV
2289 *
2290 * TLV gets included if no topology is enabled on the interface,
2291 * if one topology other than #0 is enabled, or if multiple topologies
2292 * are enabled.
2293 */
2294 struct isis_circuit_mt_setting **mt_settings;
2295 unsigned int mt_count;
2296
2297 mt_settings = circuit_mt_settings(circuit, &mt_count);
2298 if ((mt_count == 0 && area_is_mt(circuit->area))
2299 || (mt_count == 1 && mt_settings[0]->mtid != ISIS_MT_IPV4_UNICAST)
2300 || (mt_count > 1))
2301 {
2302 struct list *mt_info = list_new();
2303 mt_info->del = free_tlv;
2304
2305 for (unsigned int i = 0; i < mt_count; i++)
2306 {
2307 struct mt_router_info *info;
2308
2309 info = XCALLOC(MTYPE_ISIS_TLV, sizeof(*info));
2310 info->mtid = mt_settings[i]->mtid;
2311 /* overload info is not valid in IIH, so it's not included here */
2312 listnode_add(mt_info, info);
2313 }
2314 tlv_add_mt_router_info (mt_info, circuit->snd_stream);
2315 list_free(mt_info);
2316 }
2317
2318 /* IPv6 Interface Address TLV */
2319 if (circuit->ipv6_router && circuit->ipv6_link &&
2320 listcount (circuit->ipv6_link) > 0)
2321 if (tlv_add_ipv6_addrs (circuit->ipv6_link, circuit->snd_stream))
2322 return ISIS_WARNING;
2323
2324 if (circuit->pad_hellos)
2325 if (tlv_add_padding (circuit->snd_stream))
2326 return ISIS_WARNING;
2327
2328 length = stream_get_endp (circuit->snd_stream);
2329 /* Update PDU length */
2330 stream_putw_at (circuit->snd_stream, len_pointer, (u_int16_t) length);
2331
2332 /* For HMAC MD5 we need to compute the md5 hash and store it */
2333 if (circuit->passwd.type == ISIS_PASSWD_TYPE_HMAC_MD5)
2334 {
2335 hmac_md5 (STREAM_DATA (circuit->snd_stream),
2336 stream_get_endp (circuit->snd_stream),
2337 (unsigned char *) &circuit->passwd.passwd, circuit->passwd.len,
2338 (unsigned char *) &hmac_md5_hash);
2339 /* Copy the hash into the stream */
2340 memcpy (STREAM_DATA (circuit->snd_stream) + auth_tlv_offset + 3,
2341 hmac_md5_hash, ISIS_AUTH_MD5_SIZE);
2342 }
2343
2344 if (isis->debugs & DEBUG_ADJ_PACKETS)
2345 {
2346 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
2347 {
2348 zlog_debug ("ISIS-Adj (%s): Sending L%d LAN IIH on %s, length %zd",
2349 circuit->area->area_tag, level, circuit->interface->name,
2350 length);
2351 }
2352 else
2353 {
2354 zlog_debug ("ISIS-Adj (%s): Sending P2P IIH on %s, length %zd",
2355 circuit->area->area_tag, circuit->interface->name,
2356 length);
2357 }
2358 if (isis->debugs & DEBUG_PACKET_DUMP)
2359 zlog_dump_data (STREAM_DATA (circuit->snd_stream),
2360 stream_get_endp (circuit->snd_stream));
2361 }
2362
2363 retval = circuit->tx (circuit, level);
2364 if (retval != ISIS_OK)
2365 zlog_err ("ISIS-Adj (%s): Send L%d IIH on %s failed",
2366 circuit->area->area_tag, level, circuit->interface->name);
2367
2368 return retval;
2369 }
2370
2371 int
2372 send_lan_l1_hello (struct thread *thread)
2373 {
2374 struct isis_circuit *circuit;
2375 int retval;
2376
2377 circuit = THREAD_ARG (thread);
2378 assert (circuit);
2379 circuit->u.bc.t_send_lan_hello[0] = NULL;
2380
2381 if (!(circuit->area->is_type & IS_LEVEL_1))
2382 {
2383 zlog_warn ("ISIS-Hello (%s): Trying to send L1 IIH in L2-only area",
2384 circuit->area->area_tag);
2385 return 1;
2386 }
2387
2388 if (circuit->u.bc.run_dr_elect[0])
2389 isis_dr_elect (circuit, 1);
2390
2391 retval = send_hello (circuit, 1);
2392
2393 /* set next timer thread */
2394 thread_add_timer(master, send_lan_l1_hello, circuit,
2395 isis_jitter(circuit->hello_interval[0], IIH_JITTER),
2396 &circuit->u.bc.t_send_lan_hello[0]);
2397
2398 return retval;
2399 }
2400
2401 int
2402 send_lan_l2_hello (struct thread *thread)
2403 {
2404 struct isis_circuit *circuit;
2405 int retval;
2406
2407 circuit = THREAD_ARG (thread);
2408 assert (circuit);
2409 circuit->u.bc.t_send_lan_hello[1] = NULL;
2410
2411 if (!(circuit->area->is_type & IS_LEVEL_2))
2412 {
2413 zlog_warn ("ISIS-Hello (%s): Trying to send L2 IIH in L1 area",
2414 circuit->area->area_tag);
2415 return 1;
2416 }
2417
2418 if (circuit->u.bc.run_dr_elect[1])
2419 isis_dr_elect (circuit, 2);
2420
2421 retval = send_hello (circuit, 2);
2422
2423 /* set next timer thread */
2424 thread_add_timer(master, send_lan_l2_hello, circuit,
2425 isis_jitter(circuit->hello_interval[1], IIH_JITTER),
2426 &circuit->u.bc.t_send_lan_hello[1]);
2427
2428 return retval;
2429 }
2430
2431 int
2432 send_p2p_hello (struct thread *thread)
2433 {
2434 struct isis_circuit *circuit;
2435
2436 circuit = THREAD_ARG (thread);
2437 assert (circuit);
2438 circuit->u.p2p.t_send_p2p_hello = NULL;
2439
2440 send_hello (circuit, 1);
2441
2442 /* set next timer thread */
2443 thread_add_timer(master, send_p2p_hello, circuit,
2444 isis_jitter(circuit->hello_interval[1], IIH_JITTER),
2445 &circuit->u.p2p.t_send_p2p_hello);
2446
2447 return ISIS_OK;
2448 }
2449
2450 static int
2451 build_csnp (int level, u_char * start, u_char * stop, struct list *lsps,
2452 struct isis_circuit *circuit)
2453 {
2454 struct isis_fixed_hdr fixed_hdr;
2455 struct isis_passwd *passwd;
2456 unsigned long lenp;
2457 u_int16_t length;
2458 unsigned char hmac_md5_hash[ISIS_AUTH_MD5_SIZE];
2459 unsigned long auth_tlv_offset = 0;
2460 int retval = ISIS_OK;
2461
2462 isis_circuit_stream(circuit, &circuit->snd_stream);
2463
2464 if (level == IS_LEVEL_1)
2465 fill_fixed_hdr_andstream (&fixed_hdr, L1_COMPLETE_SEQ_NUM,
2466 circuit->snd_stream);
2467 else
2468 fill_fixed_hdr_andstream (&fixed_hdr, L2_COMPLETE_SEQ_NUM,
2469 circuit->snd_stream);
2470
2471 /*
2472 * Fill Level 1 or 2 Complete Sequence Numbers header
2473 */
2474
2475 lenp = stream_get_endp (circuit->snd_stream);
2476 stream_putw (circuit->snd_stream, 0); /* PDU length - when we know it */
2477 /* no need to send the source here, it is always us if we csnp */
2478 stream_put (circuit->snd_stream, isis->sysid, ISIS_SYS_ID_LEN);
2479 /* with zero circuit id - ref 9.10, 9.11 */
2480 stream_putc (circuit->snd_stream, 0x00);
2481
2482 stream_put (circuit->snd_stream, start, ISIS_SYS_ID_LEN + 2);
2483 stream_put (circuit->snd_stream, stop, ISIS_SYS_ID_LEN + 2);
2484
2485 /*
2486 * And TLVs
2487 */
2488 if (level == IS_LEVEL_1)
2489 passwd = &circuit->area->area_passwd;
2490 else
2491 passwd = &circuit->area->domain_passwd;
2492
2493 if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_SEND))
2494 {
2495 switch (passwd->type)
2496 {
2497 /* Cleartext */
2498 case ISIS_PASSWD_TYPE_CLEARTXT:
2499 if (tlv_add_authinfo (ISIS_PASSWD_TYPE_CLEARTXT, passwd->len,
2500 passwd->passwd, circuit->snd_stream))
2501 return ISIS_WARNING;
2502 break;
2503
2504 /* HMAC MD5 */
2505 case ISIS_PASSWD_TYPE_HMAC_MD5:
2506 /* Remember where TLV is written so we can later overwrite the MD5 hash */
2507 auth_tlv_offset = stream_get_endp (circuit->snd_stream);
2508 memset(&hmac_md5_hash, 0, ISIS_AUTH_MD5_SIZE);
2509 if (tlv_add_authinfo (ISIS_PASSWD_TYPE_HMAC_MD5, ISIS_AUTH_MD5_SIZE,
2510 hmac_md5_hash, circuit->snd_stream))
2511 return ISIS_WARNING;
2512 break;
2513
2514 default:
2515 break;
2516 }
2517 }
2518
2519 retval = tlv_add_lsp_entries (lsps, circuit->snd_stream);
2520 if (retval != ISIS_OK)
2521 return retval;
2522
2523 length = (u_int16_t) stream_get_endp (circuit->snd_stream);
2524 /* Update PU length */
2525 stream_putw_at (circuit->snd_stream, lenp, length);
2526
2527 /* For HMAC MD5 we need to compute the md5 hash and store it */
2528 if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_SEND) &&
2529 passwd->type == ISIS_PASSWD_TYPE_HMAC_MD5)
2530 {
2531 hmac_md5 (STREAM_DATA (circuit->snd_stream),
2532 stream_get_endp(circuit->snd_stream),
2533 (unsigned char *) &passwd->passwd, passwd->len,
2534 (unsigned char *) &hmac_md5_hash);
2535 /* Copy the hash into the stream */
2536 memcpy (STREAM_DATA (circuit->snd_stream) + auth_tlv_offset + 3,
2537 hmac_md5_hash, ISIS_AUTH_MD5_SIZE);
2538 }
2539
2540 return retval;
2541 }
2542
2543 /*
2544 * Count the maximum number of lsps that can be accomodated by a given size.
2545 */
2546 static uint16_t
2547 get_max_lsp_count (uint16_t size)
2548 {
2549 uint16_t tlv_count;
2550 uint16_t lsp_count;
2551 uint16_t remaining_size;
2552
2553 /* First count the full size TLVs */
2554 tlv_count = size / MAX_LSP_ENTRIES_TLV_SIZE;
2555 lsp_count = tlv_count * (MAX_LSP_ENTRIES_TLV_SIZE / LSP_ENTRIES_LEN);
2556
2557 /* The last TLV, if any */
2558 remaining_size = size % MAX_LSP_ENTRIES_TLV_SIZE;
2559 if (remaining_size - 2 >= LSP_ENTRIES_LEN)
2560 lsp_count += (remaining_size - 2) / LSP_ENTRIES_LEN;
2561
2562 return lsp_count;
2563 }
2564
2565 /*
2566 * Calculate the length of Authentication Info. TLV.
2567 */
2568 static uint16_t
2569 auth_tlv_length (int level, struct isis_circuit *circuit)
2570 {
2571 struct isis_passwd *passwd;
2572 uint16_t length;
2573
2574 if (level == IS_LEVEL_1)
2575 passwd = &circuit->area->area_passwd;
2576 else
2577 passwd = &circuit->area->domain_passwd;
2578
2579 /* Also include the length of TLV header */
2580 length = AUTH_INFO_HDRLEN;
2581 if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_SEND))
2582 {
2583 switch (passwd->type)
2584 {
2585 /* Cleartext */
2586 case ISIS_PASSWD_TYPE_CLEARTXT:
2587 length += passwd->len;
2588 break;
2589
2590 /* HMAC MD5 */
2591 case ISIS_PASSWD_TYPE_HMAC_MD5:
2592 length += ISIS_AUTH_MD5_SIZE;
2593 break;
2594
2595 default:
2596 break;
2597 }
2598 }
2599
2600 return length;
2601 }
2602
2603 /*
2604 * Calculate the maximum number of lsps that can be accomodated in a CSNP/PSNP.
2605 */
2606 static uint16_t
2607 max_lsps_per_snp (int snp_type, int level, struct isis_circuit *circuit)
2608 {
2609 int snp_hdr_len;
2610 int auth_tlv_len;
2611 uint16_t lsp_count;
2612
2613 snp_hdr_len = ISIS_FIXED_HDR_LEN;
2614 if (snp_type == ISIS_SNP_CSNP_FLAG)
2615 snp_hdr_len += ISIS_CSNP_HDRLEN;
2616 else
2617 snp_hdr_len += ISIS_PSNP_HDRLEN;
2618
2619 auth_tlv_len = auth_tlv_length (level, circuit);
2620 lsp_count = get_max_lsp_count (
2621 stream_get_size (circuit->snd_stream) - snp_hdr_len - auth_tlv_len);
2622 return lsp_count;
2623 }
2624
2625 /*
2626 * FIXME: support multiple CSNPs
2627 */
2628
2629 int
2630 send_csnp (struct isis_circuit *circuit, int level)
2631 {
2632 u_char start[ISIS_SYS_ID_LEN + 2];
2633 u_char stop[ISIS_SYS_ID_LEN + 2];
2634 struct list *list = NULL;
2635 struct listnode *node;
2636 struct isis_lsp *lsp;
2637 u_char num_lsps, loop = 1;
2638 int i, retval = ISIS_OK;
2639
2640 if (circuit->area->lspdb[level - 1] == NULL ||
2641 dict_count (circuit->area->lspdb[level - 1]) == 0)
2642 return retval;
2643
2644 memset (start, 0x00, ISIS_SYS_ID_LEN + 2);
2645 memset (stop, 0xff, ISIS_SYS_ID_LEN + 2);
2646
2647 num_lsps = max_lsps_per_snp (ISIS_SNP_CSNP_FLAG, level, circuit);
2648
2649 while (loop)
2650 {
2651 list = list_new ();
2652 lsp_build_list (start, stop, num_lsps, list,
2653 circuit->area->lspdb[level - 1]);
2654 /*
2655 * Update the stop lsp_id before encoding this CSNP.
2656 */
2657 if (listcount (list) < num_lsps)
2658 {
2659 memset (stop, 0xff, ISIS_SYS_ID_LEN + 2);
2660 }
2661 else
2662 {
2663 node = listtail (list);
2664 lsp = listgetdata (node);
2665 memcpy (stop, lsp->lsp_header->lsp_id, ISIS_SYS_ID_LEN + 2);
2666 }
2667
2668 retval = build_csnp (level, start, stop, list, circuit);
2669 if (retval != ISIS_OK)
2670 {
2671 zlog_err ("ISIS-Snp (%s): Build L%d CSNP on %s failed",
2672 circuit->area->area_tag, level, circuit->interface->name);
2673 list_delete (list);
2674 return retval;
2675 }
2676
2677 if (isis->debugs & DEBUG_SNP_PACKETS)
2678 {
2679 zlog_debug ("ISIS-Snp (%s): Sending L%d CSNP on %s, length %zd",
2680 circuit->area->area_tag, level, circuit->interface->name,
2681 stream_get_endp (circuit->snd_stream));
2682 for (ALL_LIST_ELEMENTS_RO (list, node, lsp))
2683 {
2684 zlog_debug ("ISIS-Snp (%s): CSNP entry %s, seq 0x%08x,"
2685 " cksum 0x%04x, lifetime %us",
2686 circuit->area->area_tag,
2687 rawlspid_print (lsp->lsp_header->lsp_id),
2688 ntohl (lsp->lsp_header->seq_num),
2689 ntohs (lsp->lsp_header->checksum),
2690 ntohs (lsp->lsp_header->rem_lifetime));
2691 }
2692 if (isis->debugs & DEBUG_PACKET_DUMP)
2693 zlog_dump_data (STREAM_DATA (circuit->snd_stream),
2694 stream_get_endp (circuit->snd_stream));
2695 }
2696
2697 retval = circuit->tx (circuit, level);
2698 if (retval != ISIS_OK)
2699 {
2700 zlog_err ("ISIS-Snp (%s): Send L%d CSNP on %s failed",
2701 circuit->area->area_tag, level,
2702 circuit->interface->name);
2703 list_delete (list);
2704 return retval;
2705 }
2706
2707 /*
2708 * Start lsp_id of the next CSNP should be one plus the
2709 * stop lsp_id in this current CSNP.
2710 */
2711 memcpy (start, stop, ISIS_SYS_ID_LEN + 2);
2712 loop = 0;
2713 for (i = ISIS_SYS_ID_LEN + 1; i >= 0; --i)
2714 {
2715 if (start[i] < (u_char)0xff)
2716 {
2717 start[i] += 1;
2718 loop = 1;
2719 break;
2720 }
2721 }
2722 memset (stop, 0xff, ISIS_SYS_ID_LEN + 2);
2723 list_delete (list);
2724 }
2725
2726 return retval;
2727 }
2728
2729 int
2730 send_l1_csnp (struct thread *thread)
2731 {
2732 struct isis_circuit *circuit;
2733 int retval = ISIS_OK;
2734
2735 circuit = THREAD_ARG (thread);
2736 assert (circuit);
2737
2738 circuit->t_send_csnp[0] = NULL;
2739
2740 if (circuit->circ_type == CIRCUIT_T_BROADCAST && circuit->u.bc.is_dr[0])
2741 {
2742 send_csnp (circuit, 1);
2743 }
2744 /* set next timer thread */
2745 thread_add_timer(master, send_l1_csnp, circuit,
2746 isis_jitter(circuit->csnp_interval[0], CSNP_JITTER),
2747 &circuit->t_send_csnp[0]);
2748
2749 return retval;
2750 }
2751
2752 int
2753 send_l2_csnp (struct thread *thread)
2754 {
2755 struct isis_circuit *circuit;
2756 int retval = ISIS_OK;
2757
2758 circuit = THREAD_ARG (thread);
2759 assert (circuit);
2760
2761 circuit->t_send_csnp[1] = NULL;
2762
2763 if (circuit->circ_type == CIRCUIT_T_BROADCAST && circuit->u.bc.is_dr[1])
2764 {
2765 send_csnp (circuit, 2);
2766 }
2767 /* set next timer thread */
2768 thread_add_timer(master, send_l2_csnp, circuit,
2769 isis_jitter(circuit->csnp_interval[1], CSNP_JITTER),
2770 &circuit->t_send_csnp[1]);
2771
2772 return retval;
2773 }
2774
2775 static int
2776 build_psnp (int level, struct isis_circuit *circuit, struct list *lsps)
2777 {
2778 struct isis_fixed_hdr fixed_hdr;
2779 unsigned long lenp;
2780 u_int16_t length;
2781 struct isis_lsp *lsp;
2782 struct isis_passwd *passwd;
2783 struct listnode *node;
2784 unsigned char hmac_md5_hash[ISIS_AUTH_MD5_SIZE];
2785 unsigned long auth_tlv_offset = 0;
2786 int retval = ISIS_OK;
2787
2788 isis_circuit_stream(circuit, &circuit->snd_stream);
2789
2790 if (level == IS_LEVEL_1)
2791 fill_fixed_hdr_andstream (&fixed_hdr, L1_PARTIAL_SEQ_NUM,
2792 circuit->snd_stream);
2793 else
2794 fill_fixed_hdr_andstream (&fixed_hdr, L2_PARTIAL_SEQ_NUM,
2795 circuit->snd_stream);
2796
2797 /*
2798 * Fill Level 1 or 2 Partial Sequence Numbers header
2799 */
2800 lenp = stream_get_endp (circuit->snd_stream);
2801 stream_putw (circuit->snd_stream, 0); /* PDU length - when we know it */
2802 stream_put (circuit->snd_stream, isis->sysid, ISIS_SYS_ID_LEN);
2803 stream_putc (circuit->snd_stream, circuit->idx);
2804
2805 /*
2806 * And TLVs
2807 */
2808
2809 if (level == IS_LEVEL_1)
2810 passwd = &circuit->area->area_passwd;
2811 else
2812 passwd = &circuit->area->domain_passwd;
2813
2814 if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_SEND))
2815 {
2816 switch (passwd->type)
2817 {
2818 /* Cleartext */
2819 case ISIS_PASSWD_TYPE_CLEARTXT:
2820 if (tlv_add_authinfo (ISIS_PASSWD_TYPE_CLEARTXT, passwd->len,
2821 passwd->passwd, circuit->snd_stream))
2822 return ISIS_WARNING;
2823 break;
2824
2825 /* HMAC MD5 */
2826 case ISIS_PASSWD_TYPE_HMAC_MD5:
2827 /* Remember where TLV is written so we can later overwrite the MD5 hash */
2828 auth_tlv_offset = stream_get_endp (circuit->snd_stream);
2829 memset(&hmac_md5_hash, 0, ISIS_AUTH_MD5_SIZE);
2830 if (tlv_add_authinfo (ISIS_PASSWD_TYPE_HMAC_MD5, ISIS_AUTH_MD5_SIZE,
2831 hmac_md5_hash, circuit->snd_stream))
2832 return ISIS_WARNING;
2833 break;
2834
2835 default:
2836 break;
2837 }
2838 }
2839
2840 retval = tlv_add_lsp_entries (lsps, circuit->snd_stream);
2841 if (retval != ISIS_OK)
2842 return retval;
2843
2844 if (isis->debugs & DEBUG_SNP_PACKETS)
2845 {
2846 for (ALL_LIST_ELEMENTS_RO (lsps, node, lsp))
2847 {
2848 zlog_debug ("ISIS-Snp (%s): PSNP entry %s, seq 0x%08x,"
2849 " cksum 0x%04x, lifetime %us",
2850 circuit->area->area_tag,
2851 rawlspid_print (lsp->lsp_header->lsp_id),
2852 ntohl (lsp->lsp_header->seq_num),
2853 ntohs (lsp->lsp_header->checksum),
2854 ntohs (lsp->lsp_header->rem_lifetime));
2855 }
2856 }
2857
2858 length = (u_int16_t) stream_get_endp (circuit->snd_stream);
2859 /* Update PDU length */
2860 stream_putw_at (circuit->snd_stream, lenp, length);
2861
2862 /* For HMAC MD5 we need to compute the md5 hash and store it */
2863 if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_SEND) &&
2864 passwd->type == ISIS_PASSWD_TYPE_HMAC_MD5)
2865 {
2866 hmac_md5 (STREAM_DATA (circuit->snd_stream),
2867 stream_get_endp(circuit->snd_stream),
2868 (unsigned char *) &passwd->passwd, passwd->len,
2869 (unsigned char *) &hmac_md5_hash);
2870 /* Copy the hash into the stream */
2871 memcpy (STREAM_DATA (circuit->snd_stream) + auth_tlv_offset + 3,
2872 hmac_md5_hash, ISIS_AUTH_MD5_SIZE);
2873 }
2874
2875 return ISIS_OK;
2876 }
2877
2878 /*
2879 * 7.3.15.4 action on expiration of partial SNP interval
2880 * level 1
2881 */
2882 static int
2883 send_psnp (int level, struct isis_circuit *circuit)
2884 {
2885 struct isis_lsp *lsp;
2886 struct list *list = NULL;
2887 struct listnode *node;
2888 u_char num_lsps;
2889 int retval = ISIS_OK;
2890
2891 if (circuit->circ_type == CIRCUIT_T_BROADCAST &&
2892 circuit->u.bc.is_dr[level - 1])
2893 return ISIS_OK;
2894
2895 if (circuit->area->lspdb[level - 1] == NULL ||
2896 dict_count (circuit->area->lspdb[level - 1]) == 0)
2897 return ISIS_OK;
2898
2899 if (! circuit->snd_stream)
2900 return ISIS_ERROR;
2901
2902 num_lsps = max_lsps_per_snp (ISIS_SNP_PSNP_FLAG, level, circuit);
2903
2904 while (1)
2905 {
2906 list = list_new ();
2907 lsp_build_list_ssn (circuit, num_lsps, list,
2908 circuit->area->lspdb[level - 1]);
2909
2910 if (listcount (list) == 0)
2911 {
2912 list_delete (list);
2913 return ISIS_OK;
2914 }
2915
2916 retval = build_psnp (level, circuit, list);
2917 if (retval != ISIS_OK)
2918 {
2919 zlog_err ("ISIS-Snp (%s): Build L%d PSNP on %s failed",
2920 circuit->area->area_tag, level, circuit->interface->name);
2921 list_delete (list);
2922 return retval;
2923 }
2924
2925 if (isis->debugs & DEBUG_SNP_PACKETS)
2926 {
2927 zlog_debug ("ISIS-Snp (%s): Sending L%d PSNP on %s, length %zd",
2928 circuit->area->area_tag, level,
2929 circuit->interface->name,
2930 stream_get_endp (circuit->snd_stream));
2931 if (isis->debugs & DEBUG_PACKET_DUMP)
2932 zlog_dump_data (STREAM_DATA (circuit->snd_stream),
2933 stream_get_endp (circuit->snd_stream));
2934 }
2935
2936 retval = circuit->tx (circuit, level);
2937 if (retval != ISIS_OK)
2938 {
2939 zlog_err ("ISIS-Snp (%s): Send L%d PSNP on %s failed",
2940 circuit->area->area_tag, level,
2941 circuit->interface->name);
2942 list_delete (list);
2943 return retval;
2944 }
2945
2946 /*
2947 * sending succeeded, we can clear SSN flags of this circuit
2948 * for the LSPs in list
2949 */
2950 for (ALL_LIST_ELEMENTS_RO (list, node, lsp))
2951 ISIS_CLEAR_FLAG (lsp->SSNflags, circuit);
2952 list_delete (list);
2953 }
2954
2955 return retval;
2956 }
2957
2958 int
2959 send_l1_psnp (struct thread *thread)
2960 {
2961
2962 struct isis_circuit *circuit;
2963 int retval = ISIS_OK;
2964
2965 circuit = THREAD_ARG (thread);
2966 assert (circuit);
2967
2968 circuit->t_send_psnp[0] = NULL;
2969
2970 send_psnp (1, circuit);
2971 /* set next timer thread */
2972 thread_add_timer(master, send_l1_psnp, circuit,
2973 isis_jitter(circuit->psnp_interval[0], PSNP_JITTER),
2974 &circuit->t_send_psnp[0]);
2975
2976 return retval;
2977 }
2978
2979 /*
2980 * 7.3.15.4 action on expiration of partial SNP interval
2981 * level 2
2982 */
2983 int
2984 send_l2_psnp (struct thread *thread)
2985 {
2986 struct isis_circuit *circuit;
2987 int retval = ISIS_OK;
2988
2989 circuit = THREAD_ARG (thread);
2990 assert (circuit);
2991
2992 circuit->t_send_psnp[1] = NULL;
2993
2994 send_psnp (2, circuit);
2995
2996 /* set next timer thread */
2997 thread_add_timer(master, send_l2_psnp, circuit,
2998 isis_jitter(circuit->psnp_interval[1], PSNP_JITTER),
2999 &circuit->t_send_psnp[1]);
3000
3001 return retval;
3002 }
3003
3004 /*
3005 * ISO 10589 - 7.3.14.3
3006 */
3007 int
3008 send_lsp (struct thread *thread)
3009 {
3010 struct isis_circuit *circuit;
3011 struct isis_lsp *lsp;
3012 struct listnode *node;
3013 int clear_srm = 1;
3014 int retval = ISIS_OK;
3015
3016 circuit = THREAD_ARG (thread);
3017 assert (circuit);
3018
3019 if (!circuit->lsp_queue)
3020 return ISIS_OK;
3021
3022 node = listhead (circuit->lsp_queue);
3023
3024 /*
3025 * Handle case where there are no LSPs on the queue. This can
3026 * happen, for instance, if an adjacency goes down before this
3027 * thread gets a chance to run.
3028 */
3029 if (!node)
3030 return ISIS_OK;
3031
3032 /*
3033 * Delete LSP from lsp_queue. If it's still in queue, it is assumed
3034 * as 'transmit pending', but send_lsp may never be called again.
3035 * Retry will happen because SRM flag will not be cleared.
3036 */
3037 lsp = listgetdata(node);
3038 list_delete_node (circuit->lsp_queue, node);
3039
3040 /* Set the last-cleared time if the queue is empty. */
3041 /* TODO: Is is possible that new lsps keep being added to the queue
3042 * that the queue is never empty? */
3043 if (list_isempty (circuit->lsp_queue))
3044 circuit->lsp_queue_last_cleared = time (NULL);
3045
3046 if (circuit->state != C_STATE_UP || circuit->is_passive == 1)
3047 goto out;
3048
3049 /*
3050 * Do not send if levels do not match
3051 */
3052 if (!(lsp->level & circuit->is_type))
3053 goto out;
3054
3055 /*
3056 * Do not send if we do not have adjacencies in state up on the circuit
3057 */
3058 if (circuit->upadjcount[lsp->level - 1] == 0)
3059 goto out;
3060
3061 /* stream_copy will assert and stop program execution if LSP is larger than
3062 * the circuit's MTU. So handle and log this case here. */
3063 if (stream_get_endp(lsp->pdu) > stream_get_size(circuit->snd_stream))
3064 {
3065 zlog_err("ISIS-Upd (%s): Can't send L%d LSP %s, seq 0x%08x,"
3066 " cksum 0x%04x, lifetime %us on %s. LSP Size is %zu"
3067 " while interface stream size is %zu.",
3068 circuit->area->area_tag, lsp->level,
3069 rawlspid_print(lsp->lsp_header->lsp_id),
3070 ntohl(lsp->lsp_header->seq_num),
3071 ntohs(lsp->lsp_header->checksum),
3072 ntohs(lsp->lsp_header->rem_lifetime),
3073 circuit->interface->name,
3074 stream_get_endp(lsp->pdu),
3075 stream_get_size(circuit->snd_stream));
3076 if (isis->debugs & DEBUG_PACKET_DUMP)
3077 zlog_dump_data(STREAM_DATA(lsp->pdu), stream_get_endp(lsp->pdu));
3078 retval = ISIS_ERROR;
3079 goto out;
3080 }
3081
3082 /* copy our lsp to the send buffer */
3083 stream_copy (circuit->snd_stream, lsp->pdu);
3084
3085 if (isis->debugs & DEBUG_UPDATE_PACKETS)
3086 {
3087 zlog_debug
3088 ("ISIS-Upd (%s): Sending L%d LSP %s, seq 0x%08x, cksum 0x%04x,"
3089 " lifetime %us on %s", circuit->area->area_tag, lsp->level,
3090 rawlspid_print (lsp->lsp_header->lsp_id),
3091 ntohl (lsp->lsp_header->seq_num),
3092 ntohs (lsp->lsp_header->checksum),
3093 ntohs (lsp->lsp_header->rem_lifetime),
3094 circuit->interface->name);
3095 if (isis->debugs & DEBUG_PACKET_DUMP)
3096 zlog_dump_data (STREAM_DATA (circuit->snd_stream),
3097 stream_get_endp (circuit->snd_stream));
3098 }
3099
3100 clear_srm = 0;
3101 retval = circuit->tx (circuit, lsp->level);
3102 if (retval != ISIS_OK)
3103 {
3104 zlog_err ("ISIS-Upd (%s): Send L%d LSP on %s failed %s",
3105 circuit->area->area_tag, lsp->level,
3106 circuit->interface->name,
3107 (retval == ISIS_WARNING) ? "temporarily" : "permanently");
3108 }
3109
3110 out:
3111 if (clear_srm
3112 || (retval == ISIS_OK && circuit->circ_type == CIRCUIT_T_BROADCAST)
3113 || (retval != ISIS_OK && retval != ISIS_WARNING))
3114 {
3115 /* SRM flag will trigger retransmission. We will not retransmit if we
3116 * encountered a fatal error.
3117 * On success, they should only be cleared if it's a broadcast circuit.
3118 * On a P2P circuit, we will wait for the ack from the neighbor to clear
3119 * the fag.
3120 */
3121 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
3122 }
3123
3124 return retval;
3125 }
3126
3127 int
3128 ack_lsp (struct isis_link_state_hdr *hdr, struct isis_circuit *circuit,
3129 int level)
3130 {
3131 unsigned long lenp;
3132 int retval;
3133 u_int16_t length;
3134 struct isis_fixed_hdr fixed_hdr;
3135
3136 isis_circuit_stream(circuit, &circuit->snd_stream);
3137
3138 // fill_llc_hdr (stream);
3139 if (level == IS_LEVEL_1)
3140 fill_fixed_hdr_andstream (&fixed_hdr, L1_PARTIAL_SEQ_NUM,
3141 circuit->snd_stream);
3142 else
3143 fill_fixed_hdr_andstream (&fixed_hdr, L2_PARTIAL_SEQ_NUM,
3144 circuit->snd_stream);
3145
3146
3147 lenp = stream_get_endp (circuit->snd_stream);
3148 stream_putw (circuit->snd_stream, 0); /* PDU length */
3149 stream_put (circuit->snd_stream, isis->sysid, ISIS_SYS_ID_LEN);
3150 stream_putc (circuit->snd_stream, circuit->idx);
3151 stream_putc (circuit->snd_stream, 9); /* code */
3152 stream_putc (circuit->snd_stream, 16); /* len */
3153
3154 stream_putw (circuit->snd_stream, ntohs (hdr->rem_lifetime));
3155 stream_put (circuit->snd_stream, hdr->lsp_id, ISIS_SYS_ID_LEN + 2);
3156 stream_putl (circuit->snd_stream, ntohl (hdr->seq_num));
3157 stream_putw (circuit->snd_stream, ntohs (hdr->checksum));
3158
3159 length = (u_int16_t) stream_get_endp (circuit->snd_stream);
3160 /* Update PDU length */
3161 stream_putw_at (circuit->snd_stream, lenp, length);
3162
3163 retval = circuit->tx (circuit, level);
3164 if (retval != ISIS_OK)
3165 zlog_err ("ISIS-Upd (%s): Send L%d LSP PSNP on %s failed",
3166 circuit->area->area_tag, level,
3167 circuit->interface->name);
3168
3169 return retval;
3170 }