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