]> git.proxmox.com Git - mirror_frr.git/blob - isisd/isis_pdu.c
Merge pull request #4966 from Orange-OpenSource/isis-TE
[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; see the file COPYING; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 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 #include "lib_errors.h"
38
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/isisd.h"
48 #include "isisd/isis_dynhn.h"
49 #include "isisd/isis_lsp.h"
50 #include "isisd/isis_pdu.h"
51 #include "isisd/iso_checksum.h"
52 #include "isisd/isis_csm.h"
53 #include "isisd/isis_events.h"
54 #include "isisd/isis_te.h"
55 #include "isisd/isis_mt.h"
56 #include "isisd/isis_tlvs.h"
57 #include "isisd/isis_errors.h"
58 #include "isisd/fabricd.h"
59 #include "isisd/isis_tx_queue.h"
60 #include "isisd/isis_pdu_counter.h"
61
62 static int ack_lsp(struct isis_lsp_hdr *hdr, struct isis_circuit *circuit,
63 int level)
64 {
65 unsigned long lenp;
66 int retval;
67 uint16_t length;
68 uint8_t pdu_type =
69 (level == IS_LEVEL_1) ? L1_PARTIAL_SEQ_NUM : L2_PARTIAL_SEQ_NUM;
70
71 isis_circuit_stream(circuit, &circuit->snd_stream);
72
73 fill_fixed_hdr(pdu_type, circuit->snd_stream);
74
75 lenp = stream_get_endp(circuit->snd_stream);
76 stream_putw(circuit->snd_stream, 0); /* PDU length */
77 stream_put(circuit->snd_stream, isis->sysid, ISIS_SYS_ID_LEN);
78 stream_putc(circuit->snd_stream, circuit->idx);
79 stream_putc(circuit->snd_stream, 9); /* code */
80 stream_putc(circuit->snd_stream, 16); /* len */
81
82 stream_putw(circuit->snd_stream, hdr->rem_lifetime);
83 stream_put(circuit->snd_stream, hdr->lsp_id, ISIS_SYS_ID_LEN + 2);
84 stream_putl(circuit->snd_stream, hdr->seqno);
85 stream_putw(circuit->snd_stream, hdr->checksum);
86
87 length = (uint16_t)stream_get_endp(circuit->snd_stream);
88 /* Update PDU length */
89 stream_putw_at(circuit->snd_stream, lenp, length);
90
91 pdu_counter_count(circuit->area->pdu_tx_counters, pdu_type);
92 retval = circuit->tx(circuit, level);
93 if (retval != ISIS_OK)
94 flog_err(EC_ISIS_PACKET,
95 "ISIS-Upd (%s): Send L%d LSP PSNP on %s failed",
96 circuit->area->area_tag, level,
97 circuit->interface->name);
98
99 return retval;
100 }
101
102 /*
103 * RECEIVE SIDE
104 */
105
106 struct iih_info {
107 struct isis_circuit *circuit;
108 uint8_t *ssnpa;
109 int level;
110
111 uint8_t circ_type;
112 uint8_t sys_id[ISIS_SYS_ID_LEN];
113 uint16_t holdtime;
114 uint16_t pdu_len;
115
116 uint8_t circuit_id;
117
118 uint8_t priority;
119 uint8_t dis[ISIS_SYS_ID_LEN + 1];
120
121 bool v4_usable;
122 bool v6_usable;
123
124 struct isis_tlvs *tlvs;
125 };
126
127 static int process_p2p_hello(struct iih_info *iih)
128 {
129 struct isis_threeway_adj *tw_adj = iih->tlvs->threeway_adj;
130 if (tw_adj) {
131 if (tw_adj->state > ISIS_THREEWAY_DOWN) {
132 if (isis->debugs & DEBUG_ADJ_PACKETS) {
133 zlog_debug("ISIS-Adj (%s): Rcvd P2P IIH from (%s) with invalid three-way state: %d",
134 iih->circuit->area->area_tag,
135 iih->circuit->interface->name,
136 tw_adj->state);
137 }
138 return ISIS_WARNING;
139 }
140
141 if (tw_adj->neighbor_set
142 && (memcmp(tw_adj->neighbor_id, isis->sysid, ISIS_SYS_ID_LEN)
143 || tw_adj->neighbor_circuit_id != (uint32_t) iih->circuit->idx)) {
144
145 if (isis->debugs & DEBUG_ADJ_PACKETS) {
146 zlog_debug("ISIS-Adj (%s): Rcvd P2P IIH from (%s) which lists IS/Circuit different from us as neighbor.",
147 iih->circuit->area->area_tag,
148 iih->circuit->interface->name);
149 }
150
151 return ISIS_WARNING;
152 }
153 }
154
155 /*
156 * My interpertation of the ISO, if no adj exists we will create one for
157 * the circuit
158 */
159 struct isis_adjacency *adj = iih->circuit->u.p2p.neighbor;
160 /* If an adjacency exists, check it is with the source of the hello
161 * packets */
162 if (adj) {
163 if (memcmp(iih->sys_id, adj->sysid, ISIS_SYS_ID_LEN)) {
164 zlog_debug(
165 "hello source and adjacency do not match, set adj down\n");
166 isis_adj_state_change(adj, ISIS_ADJ_DOWN,
167 "adj do not exist");
168 return ISIS_OK;
169 }
170 }
171 if (!adj || adj->level != iih->circ_type) {
172 if (!adj) {
173 adj = isis_new_adj(iih->sys_id, NULL, iih->circ_type,
174 iih->circuit);
175 } else {
176 adj->level = iih->circ_type;
177 }
178 iih->circuit->u.p2p.neighbor = adj;
179 /* Build lsp with the new neighbor entry when a new
180 * adjacency is formed. Set adjacency circuit type to
181 * IIH PDU header circuit type before lsp is regenerated
182 * when an adjacency is up. This will result in the new
183 * adjacency entry getting added to the lsp tlv neighbor list.
184 */
185 adj->circuit_t = iih->circ_type;
186 isis_adj_state_change(adj, ISIS_ADJ_INITIALIZING, NULL);
187 adj->sys_type = ISIS_SYSTYPE_UNKNOWN;
188 }
189
190 if (tw_adj && adj->threeway_state == ISIS_THREEWAY_DOWN)
191 adj->ext_circuit_id = tw_adj->local_circuit_id;
192
193 /* 8.2.6 Monitoring point-to-point adjacencies */
194 adj->hold_time = iih->holdtime;
195 adj->last_upd = time(NULL);
196
197 bool changed;
198 isis_tlvs_to_adj(iih->tlvs, adj, &changed);
199 changed |= tlvs_to_adj_mt_set(iih->tlvs, iih->v4_usable, iih->v6_usable,
200 adj);
201
202 /* lets take care of the expiry */
203 THREAD_TIMER_OFF(adj->t_expire);
204 thread_add_timer(master, isis_adj_expire, adj, (long)adj->hold_time,
205 &adj->t_expire);
206
207 /* While fabricds initial sync is in progress, ignore hellos from other
208 * interfaces than the one we are performing the initial sync on. */
209 if (fabricd_initial_sync_is_in_progress(iih->circuit->area)
210 && fabricd_initial_sync_circuit(iih->circuit->area) != iih->circuit)
211 return ISIS_OK;
212
213 /* 8.2.5.2 a) a match was detected */
214 if (isis_tlvs_area_addresses_match(iih->tlvs,
215 iih->circuit->area->area_addrs)) {
216 /* 8.2.5.2 a) 2) If the system is L1 - table 5 */
217 if (iih->circuit->area->is_type == IS_LEVEL_1) {
218 switch (iih->circ_type) {
219 case IS_LEVEL_1:
220 case IS_LEVEL_1_AND_2:
221 if (adj->adj_state != ISIS_ADJ_UP
222 || adj->adj_usage == ISIS_ADJ_LEVEL1) {
223 isis_adj_process_threeway(adj, tw_adj,
224 ISIS_ADJ_LEVEL1);
225 }
226 break;
227 case IS_LEVEL_2:
228 if (adj->adj_state != ISIS_ADJ_UP) {
229 /* (7) reject - wrong system type event
230 */
231 zlog_warn("wrongSystemType");
232 return ISIS_WARNING;
233 } else if (adj->adj_usage == ISIS_ADJ_LEVEL1) {
234 /* (6) down - wrong system */
235 isis_adj_state_change(adj,
236 ISIS_ADJ_DOWN,
237 "Wrong System");
238 }
239 break;
240 }
241 }
242
243 /* 8.2.5.2 a) 3) If the system is L1L2 - table 6 */
244 if (iih->circuit->area->is_type == IS_LEVEL_1_AND_2) {
245 switch (iih->circ_type) {
246 case IS_LEVEL_1:
247 if (adj->adj_state != ISIS_ADJ_UP
248 || adj->adj_usage == ISIS_ADJ_LEVEL1) {
249 isis_adj_process_threeway(adj, tw_adj,
250 ISIS_ADJ_LEVEL1);
251 } else if ((adj->adj_usage
252 == ISIS_ADJ_LEVEL1AND2)
253 || (adj->adj_usage
254 == ISIS_ADJ_LEVEL2)) {
255 /* (8) down - wrong system */
256 isis_adj_state_change(adj,
257 ISIS_ADJ_DOWN,
258 "Wrong System");
259 }
260 break;
261 case IS_LEVEL_2:
262 if (adj->adj_state != ISIS_ADJ_UP
263 || adj->adj_usage == ISIS_ADJ_LEVEL2) {
264 isis_adj_process_threeway(adj, tw_adj,
265 ISIS_ADJ_LEVEL2);
266 } else if ((adj->adj_usage == ISIS_ADJ_LEVEL1)
267 || (adj->adj_usage
268 == ISIS_ADJ_LEVEL1AND2)) {
269 /* (8) down - wrong system */
270 isis_adj_state_change(adj,
271 ISIS_ADJ_DOWN,
272 "Wrong System");
273 }
274 break;
275 case IS_LEVEL_1_AND_2:
276 if (adj->adj_state != ISIS_ADJ_UP
277 || adj->adj_usage == ISIS_ADJ_LEVEL1AND2) {
278 isis_adj_process_threeway(adj, tw_adj,
279 ISIS_ADJ_LEVEL1AND2);
280 } else if ((adj->adj_usage == ISIS_ADJ_LEVEL1)
281 || (adj->adj_usage
282 == ISIS_ADJ_LEVEL2)) {
283 /* (8) down - wrong system */
284 isis_adj_state_change(adj,
285 ISIS_ADJ_DOWN,
286 "Wrong System");
287 }
288 break;
289 }
290 }
291
292 /* 8.2.5.2 a) 4) If the system is L2 - table 7 */
293 if (iih->circuit->area->is_type == IS_LEVEL_2) {
294 switch (iih->circ_type) {
295 case IS_LEVEL_1:
296 if (adj->adj_state != ISIS_ADJ_UP) {
297 /* (5) reject - wrong system type event
298 */
299 zlog_warn("wrongSystemType");
300 return ISIS_WARNING;
301 } else if ((adj->adj_usage
302 == ISIS_ADJ_LEVEL1AND2)
303 || (adj->adj_usage
304 == ISIS_ADJ_LEVEL2)) {
305 /* (6) down - wrong system */
306 isis_adj_state_change(adj,
307 ISIS_ADJ_DOWN,
308 "Wrong System");
309 }
310 break;
311 case IS_LEVEL_1_AND_2:
312 case IS_LEVEL_2:
313 if (adj->adj_state != ISIS_ADJ_UP
314 || adj->adj_usage == ISIS_ADJ_LEVEL2) {
315 isis_adj_process_threeway(adj, tw_adj,
316 ISIS_ADJ_LEVEL2);
317 } else if (adj->adj_usage
318 == ISIS_ADJ_LEVEL1AND2) {
319 /* (6) down - wrong system */
320 isis_adj_state_change(adj,
321 ISIS_ADJ_DOWN,
322 "Wrong System");
323 }
324 break;
325 }
326 }
327 }
328 /* 8.2.5.2 b) if no match was detected */
329 else if (listcount(iih->circuit->area->area_addrs) > 0) {
330 if (iih->circuit->area->is_type == IS_LEVEL_1) {
331 /* 8.2.5.2 b) 1) is_type L1 and adj is not up */
332 if (adj->adj_state != ISIS_ADJ_UP) {
333 isis_adj_state_change(adj, ISIS_ADJ_DOWN,
334 "Area Mismatch");
335 /* 8.2.5.2 b) 2)is_type L1 and adj is up */
336 } else {
337 isis_adj_state_change(adj, ISIS_ADJ_DOWN,
338 "Down - Area Mismatch");
339 }
340 }
341 /* 8.2.5.2 b 3 If the system is L2 or L1L2 - table 8 */
342 else {
343 switch (iih->circ_type) {
344 case IS_LEVEL_1:
345 if (adj->adj_state != ISIS_ADJ_UP) {
346 /* (6) reject - Area Mismatch event */
347 zlog_warn("AreaMismatch");
348 return ISIS_WARNING;
349 } else if (adj->adj_usage == ISIS_ADJ_LEVEL1) {
350 /* (7) down - area mismatch */
351 isis_adj_state_change(adj,
352 ISIS_ADJ_DOWN,
353 "Area Mismatch");
354
355 } else if ((adj->adj_usage
356 == ISIS_ADJ_LEVEL1AND2)
357 || (adj->adj_usage
358 == ISIS_ADJ_LEVEL2)) {
359 /* (7) down - wrong system */
360 isis_adj_state_change(adj,
361 ISIS_ADJ_DOWN,
362 "Wrong System");
363 }
364 break;
365 case IS_LEVEL_1_AND_2:
366 case IS_LEVEL_2:
367 if (adj->adj_state != ISIS_ADJ_UP
368 || adj->adj_usage == ISIS_ADJ_LEVEL2) {
369 isis_adj_process_threeway(adj, tw_adj,
370 ISIS_ADJ_LEVEL2);
371 } else if (adj->adj_usage == ISIS_ADJ_LEVEL1) {
372 /* (7) down - wrong system */
373 isis_adj_state_change(adj,
374 ISIS_ADJ_DOWN,
375 "Wrong System");
376 } else if (adj->adj_usage
377 == ISIS_ADJ_LEVEL1AND2) {
378 if (iih->circ_type == IS_LEVEL_2) {
379 /* (7) down - wrong system */
380 isis_adj_state_change(
381 adj, ISIS_ADJ_DOWN,
382 "Wrong System");
383 } else {
384 /* (7) down - area mismatch */
385 isis_adj_state_change(
386 adj, ISIS_ADJ_DOWN,
387 "Area Mismatch");
388 }
389 }
390 break;
391 }
392 }
393 } else {
394 /* down - area mismatch */
395 isis_adj_state_change(adj, ISIS_ADJ_DOWN, "Area Mismatch");
396 }
397
398 if (adj->adj_state == ISIS_ADJ_UP && changed) {
399 lsp_regenerate_schedule(adj->circuit->area,
400 isis_adj_usage2levels(adj->adj_usage),
401 0);
402 }
403
404 /* 8.2.5.2 c) if the action was up - comparing circuit IDs */
405 /* FIXME - Missing parts */
406
407 /* some of my own understanding of the ISO, why the heck does
408 * it not say what should I change the system_type to...
409 */
410 switch (adj->adj_usage) {
411 case ISIS_ADJ_LEVEL1:
412 adj->sys_type = ISIS_SYSTYPE_L1_IS;
413 break;
414 case ISIS_ADJ_LEVEL2:
415 adj->sys_type = ISIS_SYSTYPE_L2_IS;
416 break;
417 case ISIS_ADJ_LEVEL1AND2:
418 adj->sys_type = ISIS_SYSTYPE_L2_IS;
419 break;
420 case ISIS_ADJ_NONE:
421 adj->sys_type = ISIS_SYSTYPE_UNKNOWN;
422 break;
423 }
424
425 if (isis->debugs & DEBUG_ADJ_PACKETS) {
426 zlog_debug(
427 "ISIS-Adj (%s): Rcvd P2P IIH from (%s), cir type %s,"
428 " cir id %hhu, length %" PRIu16,
429 iih->circuit->area->area_tag,
430 iih->circuit->interface->name,
431 circuit_t2string(iih->circuit->is_type),
432 iih->circuit->circuit_id, iih->pdu_len);
433 }
434
435 return ISIS_OK;
436 }
437
438 static int process_lan_hello(struct iih_info *iih)
439 {
440 struct isis_adjacency *adj;
441 adj = isis_adj_lookup(iih->sys_id,
442 iih->circuit->u.bc.adjdb[iih->level - 1]);
443 if ((adj == NULL) || (memcmp(adj->snpa, iih->ssnpa, ETH_ALEN))
444 || (adj->level != iih->level)) {
445 if (!adj) {
446 /* Do as in 8.4.2.5 */
447 adj = isis_new_adj(iih->sys_id, iih->ssnpa, iih->level,
448 iih->circuit);
449 } else {
450 if (iih->ssnpa) {
451 memcpy(adj->snpa, iih->ssnpa, 6);
452 } else {
453 memset(adj->snpa, ' ', 6);
454 }
455 adj->level = iih->level;
456 }
457 isis_adj_state_change(adj, ISIS_ADJ_INITIALIZING, NULL);
458
459 if (iih->level == IS_LEVEL_1)
460 adj->sys_type = ISIS_SYSTYPE_L1_IS;
461 else
462 adj->sys_type = ISIS_SYSTYPE_L2_IS;
463 list_delete_all_node(
464 iih->circuit->u.bc.lan_neighs[iih->level - 1]);
465 isis_adj_build_neigh_list(
466 iih->circuit->u.bc.adjdb[iih->level - 1],
467 iih->circuit->u.bc.lan_neighs[iih->level - 1]);
468 }
469
470 if (adj->dis_record[iih->level - 1].dis == ISIS_IS_DIS) {
471 uint8_t *dis = (iih->level == 1)
472 ? iih->circuit->u.bc.l1_desig_is
473 : iih->circuit->u.bc.l2_desig_is;
474
475 if (memcmp(dis, iih->dis, ISIS_SYS_ID_LEN + 1)) {
476 thread_add_event(master, isis_event_dis_status_change,
477 iih->circuit, 0, NULL);
478 memcpy(dis, iih->dis, ISIS_SYS_ID_LEN + 1);
479 }
480 }
481
482 adj->circuit_t = iih->circ_type;
483 adj->hold_time = iih->holdtime;
484 adj->last_upd = time(NULL);
485 adj->prio[iih->level - 1] = iih->priority;
486 memcpy(adj->lanid, iih->dis, ISIS_SYS_ID_LEN + 1);
487
488 bool changed;
489 isis_tlvs_to_adj(iih->tlvs, adj, &changed);
490 changed |= tlvs_to_adj_mt_set(iih->tlvs, iih->v4_usable, iih->v6_usable,
491 adj);
492
493 /* lets take care of the expiry */
494 THREAD_TIMER_OFF(adj->t_expire);
495 thread_add_timer(master, isis_adj_expire, adj, (long)adj->hold_time,
496 &adj->t_expire);
497
498 /*
499 * If the snpa for this circuit is found from LAN Neighbours TLV
500 * we have two-way communication -> adjacency can be put to state "up"
501 */
502 bool own_snpa_found =
503 isis_tlvs_own_snpa_found(iih->tlvs, iih->circuit->u.bc.snpa);
504
505 if (adj->adj_state != ISIS_ADJ_UP) {
506 if (own_snpa_found) {
507 isis_adj_state_change(
508 adj, ISIS_ADJ_UP,
509 "own SNPA found in LAN Neighbours TLV");
510 }
511 } else {
512 if (!own_snpa_found) {
513 isis_adj_state_change(
514 adj, ISIS_ADJ_INITIALIZING,
515 "own SNPA not found in LAN Neighbours TLV");
516 }
517 }
518
519 if (adj->adj_state == ISIS_ADJ_UP && changed)
520 lsp_regenerate_schedule(adj->circuit->area, iih->level, 0);
521
522 if (isis->debugs & DEBUG_ADJ_PACKETS) {
523 zlog_debug(
524 "ISIS-Adj (%s): Rcvd L%d LAN IIH from %s on %s, cirType %s, cirID %u, length %zd",
525 iih->circuit->area->area_tag, iih->level,
526 snpa_print(iih->ssnpa), iih->circuit->interface->name,
527 circuit_t2string(iih->circuit->is_type),
528 iih->circuit->circuit_id,
529 stream_get_endp(iih->circuit->rcv_stream));
530 }
531 return ISIS_OK;
532 }
533
534 static int pdu_len_validate(uint16_t pdu_len, struct isis_circuit *circuit)
535 {
536 if (pdu_len < stream_get_getp(circuit->rcv_stream)
537 || pdu_len > ISO_MTU(circuit)
538 || pdu_len > stream_get_endp(circuit->rcv_stream))
539 return 1;
540
541 if (pdu_len < stream_get_endp(circuit->rcv_stream))
542 stream_set_endp(circuit->rcv_stream, pdu_len);
543 return 0;
544 }
545
546 static int process_hello(uint8_t pdu_type, struct isis_circuit *circuit,
547 uint8_t *ssnpa)
548 {
549 /* keep a copy of the raw pdu for NB notifications */
550 size_t pdu_start = stream_get_getp(circuit->rcv_stream);
551 size_t pdu_end = stream_get_endp(circuit->rcv_stream);
552 char raw_pdu[pdu_end - pdu_start];
553 bool p2p_hello = (pdu_type == P2P_HELLO);
554 int level = p2p_hello ? 0
555 : (pdu_type == L1_LAN_HELLO) ? ISIS_LEVEL1
556 : ISIS_LEVEL2;
557 const char *pdu_name =
558 p2p_hello
559 ? "P2P IIH"
560 : (level == ISIS_LEVEL1) ? "L1 LAN IIH" : "L2 LAN IIH";
561
562
563 stream_get_from(raw_pdu, circuit->rcv_stream, pdu_start,
564 pdu_end - pdu_start);
565 if (isis->debugs & DEBUG_ADJ_PACKETS) {
566 zlog_debug("ISIS-Adj (%s): Rcvd %s on %s, cirType %s, cirID %u",
567 circuit->area->area_tag, pdu_name,
568 circuit->interface->name,
569 circuit_t2string(circuit->is_type),
570 circuit->circuit_id);
571 if (isis->debugs & DEBUG_PACKET_DUMP)
572 zlog_dump_data(STREAM_DATA(circuit->rcv_stream),
573 stream_get_endp(circuit->rcv_stream));
574 }
575
576 if (p2p_hello) {
577 if (circuit->circ_type != CIRCUIT_T_P2P) {
578 zlog_warn("p2p hello on non p2p circuit");
579 #ifndef FABRICD
580 isis_notif_reject_adjacency(
581 circuit, "p2p hello on non p2p circuit",
582 raw_pdu);
583 #endif /* ifndef FABRICD */
584 return ISIS_WARNING;
585 }
586 } else {
587 if (circuit->circ_type != CIRCUIT_T_BROADCAST) {
588 zlog_warn("lan hello on non broadcast circuit");
589 #ifndef FABRICD
590 isis_notif_reject_adjacency(
591 circuit, "lan hello on non broadcast circuit",
592 raw_pdu);
593 #endif /* ifndef FABRICD */
594 return ISIS_WARNING;
595 }
596
597 if (circuit->ext_domain) {
598 zlog_debug(
599 "level %d LAN Hello received over circuit with externalDomain = true",
600 level);
601 #ifndef FABRICD
602 isis_notif_reject_adjacency(
603 circuit,
604 "LAN Hello received over circuit with externalDomain = true",
605 raw_pdu);
606 #endif /* ifndef FABRICD */
607 return ISIS_WARNING;
608 }
609
610 if (!(circuit->is_type & level)) {
611 if (isis->debugs & DEBUG_ADJ_PACKETS) {
612 zlog_debug(
613 "ISIS-Adj (%s): Interface level mismatch, %s",
614 circuit->area->area_tag,
615 circuit->interface->name);
616 }
617 #ifndef FABRICD
618 isis_notif_reject_adjacency(
619 circuit, "Interface level mismatch", raw_pdu);
620 #endif /* ifndef FABRICD */
621 return ISIS_WARNING;
622 }
623 }
624
625 struct iih_info iih = {
626 .circuit = circuit, .ssnpa = ssnpa, .level = level};
627
628 /* Generic IIH Header */
629 iih.circ_type = stream_getc(circuit->rcv_stream) & 0x03;
630 stream_get(iih.sys_id, circuit->rcv_stream, ISIS_SYS_ID_LEN);
631 iih.holdtime = stream_getw(circuit->rcv_stream);
632 iih.pdu_len = stream_getw(circuit->rcv_stream);
633
634 if (p2p_hello) {
635 iih.circuit_id = stream_getc(circuit->rcv_stream);
636 } else {
637 iih.priority = stream_getc(circuit->rcv_stream);
638 stream_get(iih.dis, circuit->rcv_stream, ISIS_SYS_ID_LEN + 1);
639 }
640
641 if (pdu_len_validate(iih.pdu_len, circuit)) {
642 zlog_warn(
643 "ISIS-Adj (%s): Rcvd %s from (%s) with invalid pdu length %" PRIu16,
644 circuit->area->area_tag, pdu_name,
645 circuit->interface->name, iih.pdu_len);
646 #ifndef FABRICD
647 isis_notif_reject_adjacency(circuit, "Invalid PDU length",
648 raw_pdu);
649 #endif /* ifndef FABRICD */
650 return ISIS_WARNING;
651 }
652
653 if (!p2p_hello && !(level & iih.circ_type)) {
654 flog_err(EC_ISIS_PACKET,
655 "Level %d LAN Hello with Circuit Type %d", level,
656 iih.circ_type);
657 #ifndef FABRICD
658 isis_notif_reject_adjacency(
659 circuit, "LAN Hello with wrong IS-level", raw_pdu);
660 #endif /* ifndef FABRICD */
661 return ISIS_ERROR;
662 }
663
664 const char *error_log;
665 int retval = ISIS_WARNING;
666
667 if (isis_unpack_tlvs(STREAM_READABLE(circuit->rcv_stream),
668 circuit->rcv_stream, &iih.tlvs, &error_log)) {
669 zlog_warn("isis_unpack_tlvs() failed: %s", error_log);
670 #ifndef FABRICD
671 isis_notif_reject_adjacency(circuit, "Failed to unpack TLVs",
672 raw_pdu);
673 #endif /* ifndef FABRICD */
674 goto out;
675 }
676
677 if (!iih.tlvs->area_addresses.count) {
678 zlog_warn("No Area addresses TLV in %s", pdu_name);
679 #ifndef FABRICD
680 /* send northbound notification */
681 isis_notif_area_mismatch(circuit, raw_pdu);
682 #endif /* ifndef FABRICD */
683 goto out;
684 }
685
686 if (!iih.tlvs->protocols_supported.count) {
687 zlog_warn("No supported protocols TLV in %s", pdu_name);
688 #ifndef FABRICD
689 isis_notif_reject_adjacency(
690 circuit, "No supported protocols TLV", raw_pdu);
691 #endif /* ifndef FABRICD */
692 goto out;
693 }
694
695 int auth_code = isis_tlvs_auth_is_valid(iih.tlvs, &circuit->passwd,
696 circuit->rcv_stream, false);
697 if (auth_code != ISIS_AUTH_OK) {
698 isis_event_auth_failure(circuit->area->area_tag,
699 "IIH authentication failure",
700 iih.sys_id);
701 #ifndef FABRICD
702 /* send northbound notification */
703 stream_get_from(raw_pdu, circuit->rcv_stream, pdu_start,
704 pdu_end - pdu_start);
705 if (auth_code == ISIS_AUTH_FAILURE)
706 isis_notif_authentication_failure(circuit, raw_pdu);
707 else /* AUTH_TYPE_FAILURE or NO_VALIDATOR */
708 isis_notif_authentication_type_failure(circuit,
709 raw_pdu);
710 #endif /* ifndef FABRICD */
711 goto out;
712 }
713
714 if (!memcmp(iih.sys_id, isis->sysid, ISIS_SYS_ID_LEN)) {
715 zlog_warn(
716 "ISIS-Adj (%s): Received IIH with own sysid - discard",
717 circuit->area->area_tag);
718 #ifndef FABRICD
719 isis_notif_reject_adjacency(
720 circuit, "Received IIH with our own sysid", raw_pdu);
721 #endif /* ifndef FABRICD */
722 goto out;
723 }
724
725 if (!p2p_hello
726 && (listcount(circuit->area->area_addrs) == 0
727 || (level == ISIS_LEVEL1
728 && !isis_tlvs_area_addresses_match(
729 iih.tlvs, circuit->area->area_addrs)))) {
730 if (isis->debugs & DEBUG_ADJ_PACKETS) {
731 zlog_debug(
732 "ISIS-Adj (%s): Area mismatch, level %d IIH on %s",
733 circuit->area->area_tag, level,
734 circuit->interface->name);
735 }
736 #ifndef FABRICD
737 /* send northbound notification */
738 isis_notif_area_mismatch(circuit, raw_pdu);
739 #endif /* ifndef FABRICD */
740 goto out;
741 }
742
743 iih.v4_usable = (fabricd_ip_addrs(circuit)
744 && iih.tlvs->ipv4_address.count);
745
746 iih.v6_usable = (circuit->ipv6_link && listcount(circuit->ipv6_link)
747 && iih.tlvs->ipv6_address.count);
748
749 if (!iih.v4_usable && !iih.v6_usable) {
750 if (isis->debugs & DEBUG_ADJ_PACKETS) {
751 zlog_warn(
752 "ISIS-Adj (%s): Neither IPv4 nor IPv6 considered usable. Ignoring IIH",
753 circuit->area->area_tag);
754 }
755 #ifndef FABRICD
756 isis_notif_reject_adjacency(
757 circuit, "Neither IPv4 not IPv6 considered usable",
758 raw_pdu);
759 #endif /* ifndef FABRICD */
760 goto out;
761 }
762
763 retval = p2p_hello ? process_p2p_hello(&iih) : process_lan_hello(&iih);
764 out:
765 isis_free_tlvs(iih.tlvs);
766
767 return retval;
768 }
769
770 static void lsp_flood_or_update(struct isis_lsp *lsp,
771 struct isis_circuit *circuit,
772 bool circuit_scoped)
773 {
774 if (!circuit_scoped)
775 lsp_flood(lsp, circuit);
776 else
777 fabricd_update_lsp_no_flood(lsp, circuit);
778 }
779
780 /*
781 * Process Level 1/2 Link State
782 * ISO - 10589
783 * Section 7.3.15.1 - Action on receipt of a link state PDU
784 */
785 static int process_lsp(uint8_t pdu_type, struct isis_circuit *circuit,
786 const uint8_t *ssnpa, uint8_t max_area_addrs)
787 {
788 int level;
789 bool circuit_scoped;
790 size_t pdu_start = stream_get_getp(circuit->rcv_stream);
791 size_t pdu_end = stream_get_endp(circuit->rcv_stream);
792 char raw_pdu[pdu_end - pdu_start];
793
794 stream_get_from(raw_pdu, circuit->rcv_stream, pdu_start,
795 pdu_end - pdu_start);
796
797 if (pdu_type == FS_LINK_STATE) {
798 if (!fabricd)
799 return ISIS_ERROR;
800 if (max_area_addrs != L2_CIRCUIT_FLOODING_SCOPE)
801 return ISIS_ERROR;
802 level = ISIS_LEVEL2;
803 circuit_scoped = true;
804
805 /* The stream is used verbatim for sending out new LSPDUs.
806 * So make sure we store it as an L2 LSPDU internally.
807 * (compare for the reverse in `send_lsp`) */
808 stream_putc_at(circuit->rcv_stream, 4, L2_LINK_STATE);
809 stream_putc_at(circuit->rcv_stream, 7, 0);
810 } else {
811 if (pdu_type == L1_LINK_STATE)
812 level = ISIS_LEVEL1;
813 else
814 level = ISIS_LEVEL2;
815 circuit_scoped = false;
816 }
817
818 if (isis->debugs & DEBUG_UPDATE_PACKETS) {
819 zlog_debug(
820 "ISIS-Upd (%s): Rcvd %sL%d LSP on %s, cirType %s, cirID %u",
821 circuit->area->area_tag,
822 circuit_scoped ? "Circuit scoped " : "", level,
823 circuit->interface->name,
824 circuit_t2string(circuit->is_type),
825 circuit->circuit_id);
826 if (isis->debugs & DEBUG_PACKET_DUMP)
827 zlog_dump_data(STREAM_DATA(circuit->rcv_stream),
828 stream_get_endp(circuit->rcv_stream));
829 }
830
831 struct isis_lsp_hdr hdr = {};
832
833 hdr.pdu_len = stream_getw(circuit->rcv_stream);
834 hdr.rem_lifetime = stream_getw(circuit->rcv_stream);
835 stream_get(hdr.lsp_id, circuit->rcv_stream, sizeof(hdr.lsp_id));
836 hdr.seqno = stream_getl(circuit->rcv_stream);
837 hdr.checksum = stream_getw(circuit->rcv_stream);
838 hdr.lsp_bits = stream_getc(circuit->rcv_stream);
839
840 #ifndef FABRICD
841 /* send northbound notification */
842 isis_notif_lsp_received(circuit, rawlspid_print(hdr.lsp_id), hdr.seqno,
843 time(NULL), sysid_print(hdr.lsp_id));
844 #endif /* ifndef FABRICD */
845
846 if (pdu_len_validate(hdr.pdu_len, circuit)) {
847 zlog_debug("ISIS-Upd (%s): LSP %s invalid LSP length %" PRIu16,
848 circuit->area->area_tag, rawlspid_print(hdr.lsp_id),
849 hdr.pdu_len);
850 return ISIS_WARNING;
851 }
852
853 if (isis->debugs & DEBUG_UPDATE_PACKETS) {
854 zlog_debug("ISIS-Upd (%s): Rcvd L%d LSP %s, seq 0x%08" PRIx32
855 ", cksum 0x%04" PRIx16 ", lifetime %" PRIu16
856 "s, len %" PRIu16 ", on %s",
857 circuit->area->area_tag, level,
858 rawlspid_print(hdr.lsp_id), hdr.seqno, hdr.checksum,
859 hdr.rem_lifetime, hdr.pdu_len,
860 circuit->interface->name);
861 }
862
863 /* lsp is_type check */
864 if ((hdr.lsp_bits & IS_LEVEL_1) != IS_LEVEL_1) {
865 zlog_debug(
866 "ISIS-Upd (%s): LSP %s invalid LSP is type 0x%" PRIx8,
867 circuit->area->area_tag, rawlspid_print(hdr.lsp_id),
868 hdr.lsp_bits & IS_LEVEL_1_AND_2);
869 /* continue as per RFC1122 Be liberal in what you accept, and
870 * conservative in what you send */
871 }
872
873 /* Checksum sanity check - FIXME: move to correct place */
874 /* 12 = sysid+pdu+remtime */
875 if (iso_csum_verify(STREAM_DATA(circuit->rcv_stream) + 12,
876 hdr.pdu_len - 12, hdr.checksum, 12)) {
877 zlog_debug(
878 "ISIS-Upd (%s): LSP %s invalid LSP checksum 0x%04" PRIx16,
879 circuit->area->area_tag, rawlspid_print(hdr.lsp_id),
880 hdr.checksum);
881 return ISIS_WARNING;
882 }
883
884 /* 7.3.15.1 a) 1 - external domain circuit will discard lsps */
885 if (circuit->ext_domain) {
886 zlog_debug(
887 "ISIS-Upd (%s): LSP %s received at level %d over circuit with "
888 "externalDomain = true",
889 circuit->area->area_tag, rawlspid_print(hdr.lsp_id),
890 level);
891 return ISIS_WARNING;
892 }
893
894 /* 7.3.15.1 a) 2,3 - manualL2OnlyMode not implemented */
895 if (!(circuit->is_type & level)) {
896 zlog_debug(
897 "ISIS-Upd (%s): LSP %s received at level %d over circuit of"
898 " type %s",
899 circuit->area->area_tag, rawlspid_print(hdr.lsp_id),
900 level, circuit_t2string(circuit->is_type));
901 return ISIS_WARNING;
902 }
903
904 struct isis_tlvs *tlvs = NULL;
905 int retval = ISIS_WARNING;
906 const char *error_log;
907
908 if (isis_unpack_tlvs(STREAM_READABLE(circuit->rcv_stream),
909 circuit->rcv_stream, &tlvs, &error_log)) {
910 zlog_warn("Something went wrong unpacking the LSP: %s",
911 error_log);
912 #ifndef FABRICD
913 /* send northbound notification. Note that the tlv-type and
914 * offset cannot correctly be set here as they are not returned
915 * by isis_unpack_tlvs, but in there I cannot fire a
916 * notification because I have no circuit information. So until
917 * we change the code above to return those extra fields, we
918 * will send dummy values which are ignored in the callback
919 */
920 isis_notif_lsp_error(circuit, rawlspid_print(hdr.lsp_id),
921 raw_pdu, 0, 0);
922 #endif /* ifndef FABRICD */
923 goto out;
924 }
925
926 /* 7.3.15.1 a) 4 - need to make sure IDLength matches */
927
928 /* 7.3.15.1 a) 5 - maximum area match, can be ommited since we only use
929 * 3 */
930
931 /* 7.3.15.1 a) 7 - password check */
932 struct isis_passwd *passwd = (level == ISIS_LEVEL1)
933 ? &circuit->area->area_passwd
934 : &circuit->area->domain_passwd;
935 int auth_code = isis_tlvs_auth_is_valid(tlvs, passwd,
936 circuit->rcv_stream, true);
937 if (auth_code != ISIS_AUTH_OK) {
938 isis_event_auth_failure(circuit->area->area_tag,
939 "LSP authentication failure",
940 hdr.lsp_id);
941 #ifndef FABRICD
942 /* send northbound notification */
943 if (auth_code == ISIS_AUTH_FAILURE)
944 isis_notif_authentication_failure(circuit, raw_pdu);
945 else /* AUTH_TYPE_FAILURE or NO_VALIDATOR */
946 isis_notif_authentication_type_failure(circuit,
947 raw_pdu);
948 #endif /* ifndef FABRICD */
949 goto out;
950 }
951
952 /* Find the LSP in our database and compare it to this Link State header
953 */
954 struct isis_lsp *lsp =
955 lsp_search(&circuit->area->lspdb[level - 1], hdr.lsp_id);
956 int comp = 0;
957 if (lsp)
958 comp = lsp_compare(circuit->area->area_tag, lsp, hdr.seqno,
959 hdr.checksum, hdr.rem_lifetime);
960 if (lsp && (lsp->own_lsp))
961 goto dontcheckadj;
962
963 /* 7.3.15.1 a) 6 - Must check that we have an adjacency of the same
964 * level */
965 /* for broadcast circuits, snpa should be compared */
966
967 if (circuit->circ_type == CIRCUIT_T_BROADCAST) {
968 if (!isis_adj_lookup_snpa(ssnpa,
969 circuit->u.bc.adjdb[level - 1])) {
970 zlog_debug("(%s): DS ======= LSP %s, seq 0x%08" PRIx32
971 ", cksum 0x%04" PRIx16 ", lifetime %" PRIu16
972 "s on %s",
973 circuit->area->area_tag,
974 rawlspid_print(hdr.lsp_id), hdr.seqno,
975 hdr.checksum, hdr.rem_lifetime,
976 circuit->interface->name);
977 goto out; /* Silently discard */
978 }
979 }
980 /* for non broadcast, we just need to find same level adj */
981 else {
982 /* If no adj, or no sharing of level */
983 if (!circuit->u.p2p.neighbor) {
984 retval = ISIS_OK;
985 goto out;
986 } else {
987 if (((level == IS_LEVEL_1)
988 && (circuit->u.p2p.neighbor->adj_usage
989 == ISIS_ADJ_LEVEL2))
990 || ((level == IS_LEVEL_2)
991 && (circuit->u.p2p.neighbor->adj_usage
992 == ISIS_ADJ_LEVEL1)))
993 goto out;
994 }
995 }
996
997 bool lsp_confusion;
998
999 dontcheckadj:
1000 /* 7.3.15.1 a) 7 - Passwords for level 1 - not implemented */
1001
1002 /* 7.3.15.1 a) 8 - Passwords for level 2 - not implemented */
1003
1004 /* 7.3.15.1 a) 9 - OriginatingLSPBufferSize - not implemented FIXME: do
1005 * it */
1006
1007 /* 7.3.16.2 - If this is an LSP from another IS with identical seq_num
1008 * but
1009 * wrong checksum, initiate a purge. */
1010 if (lsp && (lsp->hdr.seqno == hdr.seqno)
1011 && (lsp->hdr.checksum != hdr.checksum)
1012 && hdr.rem_lifetime) {
1013 zlog_warn("ISIS-Upd (%s): LSP %s seq 0x%08" PRIx32
1014 " with confused checksum received.",
1015 circuit->area->area_tag, rawlspid_print(hdr.lsp_id),
1016 hdr.seqno);
1017 hdr.rem_lifetime = 0;
1018 lsp_confusion = true;
1019 } else
1020 lsp_confusion = false;
1021
1022 /* 7.3.15.1 b) - If the remaining life time is 0, we perform 7.3.16.4 */
1023 if (hdr.rem_lifetime == 0) {
1024 if (!lsp) {
1025 /* 7.3.16.4 a) 1) No LSP in db -> send an ack, but don't
1026 * save */
1027 /* only needed on explicit update, eg - p2p */
1028 if (circuit->circ_type == CIRCUIT_T_P2P)
1029 ack_lsp(&hdr, circuit, level);
1030 goto out; /* FIXME: do we need a purge? */
1031 } else {
1032 if (memcmp(hdr.lsp_id, isis->sysid, ISIS_SYS_ID_LEN)) {
1033 /* LSP by some other system -> do 7.3.16.4 b) */
1034 /* 7.3.16.4 b) 1) */
1035 if (comp == LSP_NEWER) {
1036 lsp_update(lsp, &hdr, tlvs,
1037 circuit->rcv_stream,
1038 circuit->area, level,
1039 lsp_confusion);
1040 tlvs = NULL;
1041 /* ii */
1042 lsp_flood_or_update(lsp, NULL,
1043 circuit_scoped);
1044 /* v */
1045 ISIS_FLAGS_CLEAR_ALL(
1046 lsp->SSNflags); /* FIXME:
1047 OTHER
1048 than c
1049 */
1050
1051 /* For the case of lsp confusion, flood
1052 * the purge back to its
1053 * originator so that it can react.
1054 * Otherwise, don't reflood
1055 * through incoming circuit as usual */
1056 if (!lsp_confusion) {
1057 isis_tx_queue_del(
1058 circuit->tx_queue,
1059 lsp);
1060
1061 /* iv */
1062 if (circuit->circ_type
1063 != CIRCUIT_T_BROADCAST)
1064 ISIS_SET_FLAG(
1065 lsp->SSNflags,
1066 circuit);
1067 }
1068 } /* 7.3.16.4 b) 2) */
1069 else if (comp == LSP_EQUAL) {
1070 /* i */
1071 isis_tx_queue_del(circuit->tx_queue,
1072 lsp);
1073 /* ii */
1074 if (circuit->circ_type
1075 != CIRCUIT_T_BROADCAST)
1076 ISIS_SET_FLAG(lsp->SSNflags,
1077 circuit);
1078 } /* 7.3.16.4 b) 3) */
1079 else {
1080 isis_tx_queue_add(circuit->tx_queue,
1081 lsp, TX_LSP_NORMAL);
1082 ISIS_CLEAR_FLAG(lsp->SSNflags, circuit);
1083 }
1084 } else if (lsp->hdr.rem_lifetime != 0) {
1085 /* our own LSP -> 7.3.16.4 c) */
1086 if (comp == LSP_NEWER) {
1087 #ifndef FABRICD
1088 if (lsp->hdr.seqno < hdr.seqno) {
1089 /* send northbound
1090 * notification */
1091 isis_notif_seqno_skipped(
1092 circuit,
1093 rawlspid_print(
1094 hdr.lsp_id));
1095 }
1096 #endif /* ifndef FABRICD */
1097 lsp_inc_seqno(lsp, hdr.seqno);
1098 lsp_flood_or_update(lsp, NULL,
1099 circuit_scoped);
1100 } else {
1101 isis_tx_queue_add(circuit->tx_queue,
1102 lsp, TX_LSP_NORMAL);
1103 ISIS_CLEAR_FLAG(lsp->SSNflags, circuit);
1104 }
1105 if (isis->debugs & DEBUG_UPDATE_PACKETS)
1106 zlog_debug(
1107 "ISIS-Upd (%s): (1) "
1108 "re-originating LSP %s new seq "
1109 "0x%08" PRIx32,
1110 circuit->area->area_tag,
1111 rawlspid_print(hdr.lsp_id),
1112 lsp->hdr.seqno);
1113 } else {
1114 /* our own LSP with 0 remaining life time */
1115 #ifndef FABRICD
1116 /* send northbound notification */
1117 isis_notif_own_lsp_purge(
1118 circuit, rawlspid_print(hdr.lsp_id));
1119 #endif /* ifndef FABRICD */
1120 }
1121 }
1122 goto out;
1123 }
1124 /* 7.3.15.1 c) - If this is our own lsp and we don't have it initiate a
1125 * purge */
1126 if (memcmp(hdr.lsp_id, isis->sysid, ISIS_SYS_ID_LEN) == 0) {
1127 if (!lsp) {
1128 /* 7.3.16.4: initiate a purge */
1129 lsp_purge_non_exist(level, &hdr, circuit->area);
1130 retval = ISIS_OK;
1131 goto out;
1132 }
1133 /* 7.3.15.1 d) - If this is our own lsp and we have it */
1134
1135 /* In 7.3.16.1, If an Intermediate system R somewhere in the
1136 * domain
1137 * has information that the current sequence number for source S
1138 * is
1139 * "greater" than that held by S, ... */
1140
1141 if (comp == LSP_NEWER) {
1142 /* 7.3.16.1 */
1143 lsp_inc_seqno(lsp, hdr.seqno);
1144 #ifndef FABRICD
1145 /* send northbound notification */
1146 isis_notif_seqno_skipped(circuit,
1147 rawlspid_print(hdr.lsp_id));
1148 #endif /* ifndef FABRICD */
1149 if (isis->debugs & DEBUG_UPDATE_PACKETS) {
1150 zlog_debug(
1151 "ISIS-Upd (%s): (2) re-originating LSP %s new seq 0x%08" PRIx32,
1152 circuit->area->area_tag,
1153 rawlspid_print(hdr.lsp_id),
1154 lsp->hdr.seqno);
1155 }
1156 lsp_flood(lsp, NULL);
1157 } else if (comp == LSP_EQUAL) {
1158 isis_tx_queue_del(circuit->tx_queue, lsp);
1159 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
1160 ISIS_SET_FLAG(lsp->SSNflags, circuit);
1161 } else {
1162 isis_tx_queue_add(circuit->tx_queue, lsp,
1163 TX_LSP_NORMAL);
1164 ISIS_CLEAR_FLAG(lsp->SSNflags, circuit);
1165 }
1166 } else {
1167 /* 7.3.15.1 e) - This lsp originated on another system */
1168
1169 /* 7.3.15.1 e) 1) LSP newer than the one in db or no LSP in db
1170 */
1171 if ((!lsp || comp == LSP_NEWER)) {
1172 /*
1173 * If this lsp is a frag, need to see if we have zero
1174 * lsp present
1175 */
1176 struct isis_lsp *lsp0 = NULL;
1177 if (LSP_FRAGMENT(hdr.lsp_id) != 0) {
1178 uint8_t lspid[ISIS_SYS_ID_LEN + 2];
1179 memcpy(lspid, hdr.lsp_id, ISIS_SYS_ID_LEN + 1);
1180 LSP_FRAGMENT(lspid) = 0;
1181 lsp0 = lsp_search(
1182 &circuit->area->lspdb[level - 1], lspid);
1183 if (!lsp0) {
1184 zlog_debug(
1185 "Got lsp frag, while zero lsp not in database");
1186 goto out;
1187 }
1188 }
1189 /* i */
1190 if (!lsp) {
1191 lsp = lsp_new_from_recv(
1192 &hdr, tlvs, circuit->rcv_stream, lsp0,
1193 circuit->area, level);
1194 tlvs = NULL;
1195 lsp_insert(&circuit->area->lspdb[level - 1],
1196 lsp);
1197 } else /* exists, so we overwrite */
1198 {
1199 lsp_update(lsp, &hdr, tlvs, circuit->rcv_stream,
1200 circuit->area, level, false);
1201 tlvs = NULL;
1202 }
1203 lsp_flood_or_update(lsp, circuit, circuit_scoped);
1204
1205 /* iv */
1206 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
1207 ISIS_SET_FLAG(lsp->SSNflags, circuit);
1208 /* FIXME: v) */
1209 }
1210 /* 7.3.15.1 e) 2) LSP equal to the one in db */
1211 else if (comp == LSP_EQUAL) {
1212 isis_tx_queue_del(circuit->tx_queue, lsp);
1213 lsp_update(lsp, &hdr, tlvs, circuit->rcv_stream,
1214 circuit->area, level, false);
1215 tlvs = NULL;
1216 if (circuit->circ_type != CIRCUIT_T_BROADCAST)
1217 ISIS_SET_FLAG(lsp->SSNflags, circuit);
1218 }
1219 /* 7.3.15.1 e) 3) LSP older than the one in db */
1220 else {
1221 isis_tx_queue_add(circuit->tx_queue, lsp,
1222 TX_LSP_NORMAL);
1223 ISIS_CLEAR_FLAG(lsp->SSNflags, circuit);
1224 }
1225 }
1226
1227 retval = ISIS_OK;
1228
1229 out:
1230 fabricd_trigger_csnp(circuit->area, circuit_scoped);
1231
1232 isis_free_tlvs(tlvs);
1233 return retval;
1234 }
1235
1236 /*
1237 * Process Sequence Numbers
1238 * ISO - 10589
1239 * Section 7.3.15.2 - Action on receipt of a sequence numbers PDU
1240 */
1241
1242 static int process_snp(uint8_t pdu_type, struct isis_circuit *circuit,
1243 const uint8_t *ssnpa)
1244 {
1245 #ifndef FABRICD
1246 size_t pdu_start = stream_get_getp(circuit->rcv_stream);
1247 size_t pdu_end = stream_get_endp(circuit->rcv_stream);
1248 char raw_pdu[pdu_end - pdu_start];
1249 #endif /* ifndef FABRICD */
1250
1251 bool is_csnp = (pdu_type == L1_COMPLETE_SEQ_NUM
1252 || pdu_type == L2_COMPLETE_SEQ_NUM);
1253 char typechar = is_csnp ? 'C' : 'P';
1254 int level = (pdu_type == L1_COMPLETE_SEQ_NUM
1255 || pdu_type == L1_PARTIAL_SEQ_NUM)
1256 ? ISIS_LEVEL1
1257 : ISIS_LEVEL2;
1258
1259 uint16_t pdu_len = stream_getw(circuit->rcv_stream);
1260 uint8_t rem_sys_id[ISIS_SYS_ID_LEN];
1261
1262 stream_get(rem_sys_id, circuit->rcv_stream, ISIS_SYS_ID_LEN);
1263 stream_forward_getp(circuit->rcv_stream, 1); /* Circuit ID - unused */
1264
1265 uint8_t start_lsp_id[ISIS_SYS_ID_LEN + 2] = {};
1266 uint8_t stop_lsp_id[ISIS_SYS_ID_LEN + 2] = {};
1267
1268 if (is_csnp) {
1269 stream_get(start_lsp_id, circuit->rcv_stream,
1270 ISIS_SYS_ID_LEN + 2);
1271 stream_get(stop_lsp_id, circuit->rcv_stream,
1272 ISIS_SYS_ID_LEN + 2);
1273 }
1274
1275 if (pdu_len_validate(pdu_len, circuit)) {
1276 zlog_warn("Received a CSNP with bogus length %d", pdu_len);
1277 return ISIS_WARNING;
1278 }
1279
1280 if (isis->debugs & DEBUG_SNP_PACKETS) {
1281 zlog_debug(
1282 "ISIS-Snp (%s): Rcvd L%d %cSNP on %s, cirType %s, cirID %u",
1283 circuit->area->area_tag, level, typechar,
1284 circuit->interface->name,
1285 circuit_t2string(circuit->is_type),
1286 circuit->circuit_id);
1287 if (isis->debugs & DEBUG_PACKET_DUMP)
1288 zlog_dump_data(STREAM_DATA(circuit->rcv_stream),
1289 stream_get_endp(circuit->rcv_stream));
1290 }
1291
1292 /* 7.3.15.2 a) 1 - external domain circuit will discard snp pdu */
1293 if (circuit->ext_domain) {
1294
1295 zlog_debug(
1296 "ISIS-Snp (%s): Rcvd L%d %cSNP on %s, "
1297 "skipping: circuit externalDomain = true",
1298 circuit->area->area_tag, level, typechar,
1299 circuit->interface->name);
1300
1301 return ISIS_OK;
1302 }
1303
1304 /* 7.3.15.2 a) 2,3 - manualL2OnlyMode not implemented */
1305 if (!(circuit->is_type & level)) {
1306 zlog_debug(
1307 "ISIS-Snp (%s): Rcvd L%d %cSNP on %s, "
1308 "skipping: circuit type %s does not match level %d",
1309 circuit->area->area_tag, level, typechar,
1310 circuit->interface->name,
1311 circuit_t2string(circuit->is_type), level);
1312
1313 return ISIS_OK;
1314 }
1315
1316 /* 7.3.15.2 a) 4 - not applicable for CSNP only PSNPs on broadcast */
1317 if (!is_csnp && (circuit->circ_type == CIRCUIT_T_BROADCAST)
1318 && !circuit->u.bc.is_dr[level - 1]) {
1319 zlog_debug(
1320 "ISIS-Snp (%s): Rcvd L%d %cSNP from %s on %s, "
1321 "skipping: we are not the DIS",
1322 circuit->area->area_tag, level, typechar,
1323 snpa_print(ssnpa), circuit->interface->name);
1324
1325 return ISIS_OK;
1326 }
1327
1328 /* 7.3.15.2 a) 5 - need to make sure IDLength matches - already checked
1329 */
1330
1331 /* 7.3.15.2 a) 6 - maximum area match, can be ommited since we only use
1332 * 3
1333 * - already checked */
1334
1335 /* 7.3.15.2 a) 7 - Must check that we have an adjacency of the same
1336 * level */
1337 /* for broadcast circuits, snpa should be compared */
1338 /* FIXME : Do we need to check SNPA? */
1339 if (circuit->circ_type == CIRCUIT_T_BROADCAST) {
1340 if (!isis_adj_lookup(rem_sys_id,
1341 circuit->u.bc.adjdb[level - 1]))
1342 return ISIS_OK; /* Silently discard */
1343 } else {
1344 if (!fabricd && !circuit->u.p2p.neighbor) {
1345 zlog_warn("no p2p neighbor on circuit %s",
1346 circuit->interface->name);
1347 return ISIS_OK; /* Silently discard */
1348 }
1349 }
1350
1351 struct isis_tlvs *tlvs;
1352 int retval = ISIS_WARNING;
1353 const char *error_log;
1354
1355 if (isis_unpack_tlvs(STREAM_READABLE(circuit->rcv_stream),
1356 circuit->rcv_stream, &tlvs, &error_log)) {
1357 zlog_warn("Something went wrong unpacking the SNP: %s",
1358 error_log);
1359 goto out;
1360 }
1361
1362 struct isis_passwd *passwd = (level == IS_LEVEL_1)
1363 ? &circuit->area->area_passwd
1364 : &circuit->area->domain_passwd;
1365 if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_RECV)) {
1366 int auth_code = isis_tlvs_auth_is_valid(
1367 tlvs, passwd, circuit->rcv_stream, false);
1368 if (auth_code != ISIS_AUTH_OK) {
1369 isis_event_auth_failure(circuit->area->area_tag,
1370 "SNP authentication failure",
1371 rem_sys_id);
1372 #ifndef FABRICD
1373 /* send northbound notification */
1374 stream_get_from(raw_pdu, circuit->rcv_stream, pdu_start,
1375 pdu_end - pdu_start);
1376 if (auth_code == ISIS_AUTH_FAILURE)
1377 isis_notif_authentication_failure(circuit,
1378 raw_pdu);
1379 else /* AUTH_TYPE_FAILURE or NO_VALIDATOR */
1380 isis_notif_authentication_type_failure(circuit,
1381 raw_pdu);
1382 #endif /* ifndef FABRICD */
1383 goto out;
1384 }
1385 }
1386
1387 struct isis_lsp_entry *entry_head =
1388 (struct isis_lsp_entry *)tlvs->lsp_entries.head;
1389
1390 /* debug isis snp-packets */
1391 if (isis->debugs & DEBUG_SNP_PACKETS) {
1392 zlog_debug("ISIS-Snp (%s): Rcvd L%d %cSNP from %s on %s",
1393 circuit->area->area_tag, level, typechar,
1394 snpa_print(ssnpa), circuit->interface->name);
1395 for (struct isis_lsp_entry *entry = entry_head; entry;
1396 entry = entry->next) {
1397 zlog_debug(
1398 "ISIS-Snp (%s): %cSNP entry %s, seq 0x%08" PRIx32
1399 ", cksum 0x%04" PRIx16 ", lifetime %" PRIu16 "s",
1400 circuit->area->area_tag, typechar,
1401 rawlspid_print(entry->id), entry->seqno,
1402 entry->checksum, entry->rem_lifetime);
1403 }
1404 }
1405
1406 bool resync_needed = false;
1407
1408 /* 7.3.15.2 b) Actions on LSP_ENTRIES reported */
1409 for (struct isis_lsp_entry *entry = entry_head; entry;
1410 entry = entry->next) {
1411 struct isis_lsp *lsp =
1412 lsp_search(&circuit->area->lspdb[level - 1], entry->id);
1413 bool own_lsp = !memcmp(entry->id, isis->sysid, ISIS_SYS_ID_LEN);
1414 if (lsp) {
1415 /* 7.3.15.2 b) 1) is this LSP newer */
1416 int cmp = lsp_compare(circuit->area->area_tag, lsp,
1417 entry->seqno, entry->checksum,
1418 entry->rem_lifetime);
1419 /* 7.3.15.2 b) 2) if it equals, clear SRM on p2p */
1420 if (cmp == LSP_EQUAL) {
1421 /* if (circuit->circ_type !=
1422 * CIRCUIT_T_BROADCAST) */
1423 isis_tx_queue_del(circuit->tx_queue, lsp);
1424 }
1425 /* 7.3.15.2 b) 3) if it is older, clear SSN and set SRM
1426 */
1427 else if (cmp == LSP_OLDER) {
1428 ISIS_CLEAR_FLAG(lsp->SSNflags, circuit);
1429 isis_tx_queue_add(circuit->tx_queue, lsp,
1430 TX_LSP_NORMAL);
1431 }
1432 /* 7.3.15.2 b) 4) if it is newer, set SSN and clear SRM
1433 on p2p */
1434 else {
1435 if (own_lsp) {
1436 lsp_inc_seqno(lsp, entry->seqno);
1437 isis_tx_queue_add(circuit->tx_queue, lsp,
1438 TX_LSP_NORMAL);
1439 } else {
1440 ISIS_SET_FLAG(lsp->SSNflags, circuit);
1441 /* if (circuit->circ_type !=
1442 * CIRCUIT_T_BROADCAST) */
1443 isis_tx_queue_del(circuit->tx_queue, lsp);
1444 resync_needed = true;
1445 }
1446 }
1447 } else {
1448 /* 7.3.15.2 b) 5) if it was not found, and all of those
1449 * are not 0,
1450 * insert it and set SSN on it */
1451 if (entry->rem_lifetime && entry->checksum
1452 && entry->seqno && memcmp(entry->id, isis->sysid,
1453 ISIS_SYS_ID_LEN)) {
1454 struct isis_lsp *lsp0 = NULL;
1455
1456 if (LSP_FRAGMENT(entry->id)) {
1457 uint8_t lspid[ISIS_SYS_ID_LEN + 2];
1458
1459 memcpy(lspid, entry->id,
1460 ISIS_SYS_ID_LEN + 1);
1461 LSP_FRAGMENT(lspid) = 0;
1462 lsp0 = lsp_search(
1463 &circuit->area->lspdb[level - 1],
1464 lspid);
1465 if (!lsp0) {
1466 zlog_debug("Got lsp frag in snp, while zero not in database");
1467 continue;
1468 }
1469 }
1470 lsp = lsp_new(circuit->area, entry->id,
1471 entry->rem_lifetime, 0, 0,
1472 entry->checksum, lsp0, level);
1473 lsp_insert(&circuit->area->lspdb[level - 1],
1474 lsp);
1475
1476 lsp_set_all_srmflags(lsp, false);
1477 ISIS_SET_FLAG(lsp->SSNflags, circuit);
1478 resync_needed = true;
1479 }
1480 }
1481 }
1482
1483 /* 7.3.15.2 c) on CSNP set SRM for all in range which were not reported
1484 */
1485 if (is_csnp) {
1486 /*
1487 * Build a list from our own LSP db bounded with
1488 * start_lsp_id and stop_lsp_id
1489 */
1490 struct list *lsp_list = list_new();
1491 lsp_build_list_nonzero_ht(&circuit->area->lspdb[level - 1],
1492 start_lsp_id, stop_lsp_id, lsp_list);
1493
1494 /* Fixme: Find a better solution */
1495 struct listnode *node, *nnode;
1496 struct isis_lsp *lsp;
1497 for (struct isis_lsp_entry *entry = entry_head; entry;
1498 entry = entry->next) {
1499 for (ALL_LIST_ELEMENTS(lsp_list, node, nnode, lsp)) {
1500 if (lsp_id_cmp(lsp->hdr.lsp_id, entry->id)
1501 == 0) {
1502 list_delete_node(lsp_list, node);
1503 break;
1504 }
1505 }
1506 }
1507
1508 /* on remaining LSPs we set SRM (neighbor knew not of) */
1509 for (ALL_LIST_ELEMENTS_RO(lsp_list, node, lsp)) {
1510 isis_tx_queue_add(circuit->tx_queue, lsp, TX_LSP_NORMAL);
1511 resync_needed = true;
1512 }
1513
1514 /* lets free it */
1515 list_delete(&lsp_list);
1516 }
1517
1518 if (fabricd_initial_sync_is_complete(circuit->area) && resync_needed)
1519 zlog_warn("OpenFabric: Needed to resync LSPDB using CSNP!");
1520
1521 retval = ISIS_OK;
1522 out:
1523 isis_free_tlvs(tlvs);
1524 return retval;
1525 }
1526
1527 static int pdu_size(uint8_t pdu_type, uint8_t *size)
1528 {
1529 switch (pdu_type) {
1530 case L1_LAN_HELLO:
1531 case L2_LAN_HELLO:
1532 *size = ISIS_LANHELLO_HDRLEN;
1533 break;
1534 case P2P_HELLO:
1535 *size = ISIS_P2PHELLO_HDRLEN;
1536 break;
1537 case L1_LINK_STATE:
1538 case L2_LINK_STATE:
1539 case FS_LINK_STATE:
1540 *size = ISIS_LSP_HDR_LEN;
1541 break;
1542 case L1_COMPLETE_SEQ_NUM:
1543 case L2_COMPLETE_SEQ_NUM:
1544 *size = ISIS_CSNP_HDRLEN;
1545 break;
1546 case L1_PARTIAL_SEQ_NUM:
1547 case L2_PARTIAL_SEQ_NUM:
1548 *size = ISIS_PSNP_HDRLEN;
1549 break;
1550 default:
1551 return 1;
1552 }
1553 *size += ISIS_FIXED_HDR_LEN;
1554 return 0;
1555 }
1556
1557 /*
1558 * PDU Dispatcher
1559 */
1560
1561 int isis_handle_pdu(struct isis_circuit *circuit, uint8_t *ssnpa)
1562 {
1563 int retval = ISIS_OK;
1564 size_t pdu_start = stream_get_getp(circuit->rcv_stream);
1565 size_t pdu_end = stream_get_endp(circuit->rcv_stream);
1566 char raw_pdu[pdu_end - pdu_start];
1567
1568 stream_get_from(raw_pdu, circuit->rcv_stream, pdu_start,
1569 pdu_end - pdu_start);
1570
1571 /* Verify that at least the 8 bytes fixed header have been received */
1572 if (stream_get_endp(circuit->rcv_stream) < ISIS_FIXED_HDR_LEN) {
1573 flog_err(EC_ISIS_PACKET, "PDU is too short to be IS-IS.");
1574 return ISIS_ERROR;
1575 }
1576
1577 uint8_t idrp = stream_getc(circuit->rcv_stream);
1578 uint8_t length = stream_getc(circuit->rcv_stream);
1579 uint8_t version1 = stream_getc(circuit->rcv_stream);
1580 uint8_t id_len = stream_getc(circuit->rcv_stream);
1581 uint8_t pdu_type = stream_getc(circuit->rcv_stream)
1582 & 0x1f; /* bits 6-8 are reserved */
1583 uint8_t version2 = stream_getc(circuit->rcv_stream);
1584
1585 stream_forward_getp(circuit->rcv_stream, 1); /* reserved */
1586 uint8_t max_area_addrs = stream_getc(circuit->rcv_stream);
1587
1588 pdu_counter_count(circuit->area->pdu_rx_counters, pdu_type);
1589
1590 if (idrp == ISO9542_ESIS) {
1591 flog_err(EC_LIB_DEVELOPMENT,
1592 "No support for ES-IS packet IDRP=%" PRIx8, idrp);
1593 return ISIS_ERROR;
1594 }
1595
1596 if (idrp != ISO10589_ISIS) {
1597 flog_err(EC_ISIS_PACKET, "Not an IS-IS packet IDRP=%" PRIx8,
1598 idrp);
1599 return ISIS_ERROR;
1600 }
1601
1602 if (version1 != 1) {
1603 zlog_warn("Unsupported ISIS version %" PRIu8, version1);
1604 #ifndef FABRICD
1605 /* send northbound notification */
1606 isis_notif_version_skew(circuit, version1, raw_pdu);
1607 #endif /* ifndef FABRICD */
1608 return ISIS_WARNING;
1609 }
1610
1611 if (id_len != 0 && id_len != ISIS_SYS_ID_LEN) {
1612 flog_err(
1613 EC_ISIS_PACKET,
1614 "IDFieldLengthMismatch: ID Length field in a received PDU %" PRIu8
1615 ", while the parameter for this IS is %u",
1616 id_len, ISIS_SYS_ID_LEN);
1617 #ifndef FABRICD
1618 /* send northbound notification */
1619 isis_notif_id_len_mismatch(circuit, id_len, raw_pdu);
1620 #endif /* ifndef FABRICD */
1621 return ISIS_ERROR;
1622 }
1623
1624 uint8_t expected_length;
1625 if (pdu_size(pdu_type, &expected_length)) {
1626 zlog_warn("Unsupported ISIS PDU %" PRIu8, pdu_type);
1627 return ISIS_WARNING;
1628 }
1629
1630 if (length != expected_length) {
1631 flog_err(EC_ISIS_PACKET,
1632 "Exepected fixed header length = %" PRIu8
1633 " but got %" PRIu8,
1634 expected_length, length);
1635 return ISIS_ERROR;
1636 }
1637
1638 if (stream_get_endp(circuit->rcv_stream) < length) {
1639 flog_err(
1640 EC_ISIS_PACKET,
1641 "PDU is too short to contain fixed header of given PDU type.");
1642 return ISIS_ERROR;
1643 }
1644
1645 if (version2 != 1) {
1646 zlog_warn("Unsupported ISIS PDU version %" PRIu8, version2);
1647 #ifndef FABRICD
1648 /* send northbound notification */
1649 isis_notif_version_skew(circuit, version2, raw_pdu);
1650 #endif /* ifndef FABRICD */
1651 return ISIS_WARNING;
1652 }
1653
1654 if (circuit->is_passive) {
1655 zlog_warn("Received ISIS PDU on passive circuit %s",
1656 circuit->interface->name);
1657 return ISIS_WARNING;
1658 }
1659
1660 /* either 3 or 0 */
1661 if (pdu_type != FS_LINK_STATE /* FS PDU doesn't contain max area addr field */
1662 && max_area_addrs != 0
1663 && max_area_addrs != isis->max_area_addrs) {
1664 flog_err(
1665 EC_ISIS_PACKET,
1666 "maximumAreaAddressesMismatch: maximumAreaAdresses in a received PDU %" PRIu8
1667 " while the parameter for this IS is %u",
1668 max_area_addrs, isis->max_area_addrs);
1669 #ifndef FABRICD
1670 /* send northbound notification */
1671 isis_notif_max_area_addr_mismatch(circuit, max_area_addrs,
1672 raw_pdu);
1673 #endif /* ifndef FABRICD */
1674 return ISIS_ERROR;
1675 }
1676
1677 switch (pdu_type) {
1678 case L1_LAN_HELLO:
1679 case L2_LAN_HELLO:
1680 case P2P_HELLO:
1681 if (fabricd && pdu_type != P2P_HELLO)
1682 return ISIS_ERROR;
1683 retval = process_hello(pdu_type, circuit, ssnpa);
1684 break;
1685 case L1_LINK_STATE:
1686 case L2_LINK_STATE:
1687 case FS_LINK_STATE:
1688 if (fabricd
1689 && pdu_type != L2_LINK_STATE
1690 && pdu_type != FS_LINK_STATE)
1691 return ISIS_ERROR;
1692 retval = process_lsp(pdu_type, circuit, ssnpa, max_area_addrs);
1693 break;
1694 case L1_COMPLETE_SEQ_NUM:
1695 case L2_COMPLETE_SEQ_NUM:
1696 case L1_PARTIAL_SEQ_NUM:
1697 case L2_PARTIAL_SEQ_NUM:
1698 retval = process_snp(pdu_type, circuit, ssnpa);
1699 break;
1700 default:
1701 return ISIS_ERROR;
1702 }
1703
1704 return retval;
1705 }
1706
1707 int isis_receive(struct thread *thread)
1708 {
1709 struct isis_circuit *circuit;
1710 uint8_t ssnpa[ETH_ALEN];
1711 int retval;
1712
1713 /*
1714 * Get the circuit
1715 */
1716 circuit = THREAD_ARG(thread);
1717 assert(circuit);
1718
1719 circuit->t_read = NULL;
1720
1721 isis_circuit_stream(circuit, &circuit->rcv_stream);
1722
1723 retval = circuit->rx(circuit, ssnpa);
1724
1725 #if ISIS_METHOD != ISIS_METHOD_BPF
1726 if (retval == ISIS_OK)
1727 retval = isis_handle_pdu(circuit, ssnpa);
1728 #endif //ISIS_METHOD != ISIS_METHOD_BPF
1729
1730 /*
1731 * prepare for next packet.
1732 */
1733 if (!circuit->is_passive)
1734 isis_circuit_prepare(circuit);
1735
1736 return retval;
1737 }
1738
1739 /*
1740 * SEND SIDE
1741 */
1742 void fill_fixed_hdr(uint8_t pdu_type, struct stream *stream)
1743 {
1744 uint8_t length;
1745
1746 if (pdu_size(pdu_type, &length))
1747 assert(!"Unknown PDU Type");
1748
1749 stream_putc(stream, ISO10589_ISIS); /* IDRP */
1750 stream_putc(stream, length); /* Length of fixed header */
1751 stream_putc(stream, 1); /* Version/Protocol ID Extension 1 */
1752 stream_putc(stream, 0); /* ID Length, 0 => 6 */
1753 stream_putc(stream, pdu_type);
1754 stream_putc(stream, 1); /* Subversion */
1755 stream_putc(stream, 0); /* Reserved */
1756 stream_putc(stream, 0); /* Max Area Addresses 0 => 3 */
1757 }
1758
1759 static uint8_t hello_pdu_type(struct isis_circuit *circuit, int level)
1760 {
1761 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
1762 return (level == IS_LEVEL_1) ? L1_LAN_HELLO : L2_LAN_HELLO;
1763 else
1764 return P2P_HELLO;
1765 }
1766
1767 static void put_hello_hdr(struct isis_circuit *circuit, int level,
1768 size_t *len_pointer)
1769 {
1770 uint8_t pdu_type = hello_pdu_type(circuit, level);
1771
1772 isis_circuit_stream(circuit, &circuit->snd_stream);
1773 fill_fixed_hdr(pdu_type, circuit->snd_stream);
1774
1775 stream_putc(circuit->snd_stream, circuit->is_type);
1776 stream_put(circuit->snd_stream, circuit->area->isis->sysid,
1777 ISIS_SYS_ID_LEN);
1778
1779 uint32_t holdtime = circuit->hello_multiplier[level - 1]
1780 * circuit->hello_interval[level - 1];
1781
1782 if (holdtime > 0xffff)
1783 holdtime = 0xffff;
1784
1785 stream_putw(circuit->snd_stream, holdtime);
1786 *len_pointer = stream_get_endp(circuit->snd_stream);
1787 stream_putw(circuit->snd_stream, 0); /* length is filled in later */
1788
1789 if (circuit->circ_type == CIRCUIT_T_BROADCAST) {
1790 uint8_t *desig_is = (level == IS_LEVEL_1)
1791 ? circuit->u.bc.l1_desig_is
1792 : circuit->u.bc.l2_desig_is;
1793 stream_putc(circuit->snd_stream, circuit->priority[level - 1]);
1794 stream_put(circuit->snd_stream, desig_is, ISIS_SYS_ID_LEN + 1);
1795 } else {
1796 stream_putc(circuit->snd_stream, circuit->circuit_id);
1797 }
1798 }
1799
1800 int send_hello(struct isis_circuit *circuit, int level)
1801 {
1802 size_t len_pointer;
1803 int retval;
1804
1805 if (circuit->is_passive)
1806 return ISIS_OK;
1807
1808 if (circuit->interface->mtu == 0) {
1809 zlog_warn("circuit has zero MTU");
1810 return ISIS_WARNING;
1811 }
1812
1813 put_hello_hdr(circuit, level, &len_pointer);
1814
1815 struct isis_tlvs *tlvs = isis_alloc_tlvs();
1816
1817 isis_tlvs_add_auth(tlvs, &circuit->passwd);
1818
1819 if (!listcount(circuit->area->area_addrs)) {
1820 isis_free_tlvs(tlvs);
1821 return ISIS_WARNING;
1822 }
1823
1824 isis_tlvs_add_area_addresses(tlvs, circuit->area->area_addrs);
1825
1826 if (circuit->circ_type == CIRCUIT_T_BROADCAST) {
1827 isis_tlvs_add_lan_neighbors(
1828 tlvs, circuit->u.bc.lan_neighs[level - 1]);
1829 } else if (circuit->circ_type == CIRCUIT_T_P2P
1830 && !circuit->disable_threeway_adj) {
1831 uint32_t ext_circuit_id = circuit->idx;
1832 if (circuit->u.p2p.neighbor) {
1833 uint8_t threeway_state;
1834
1835 if (fabricd_initial_sync_is_in_progress(circuit->area)
1836 && fabricd_initial_sync_circuit(circuit->area) != circuit)
1837 threeway_state = ISIS_THREEWAY_DOWN;
1838 else
1839 threeway_state = circuit->u.p2p.neighbor->threeway_state;
1840 isis_tlvs_add_threeway_adj(tlvs,
1841 threeway_state,
1842 ext_circuit_id,
1843 circuit->u.p2p.neighbor->sysid,
1844 circuit->u.p2p.neighbor->ext_circuit_id);
1845 } else {
1846 isis_tlvs_add_threeway_adj(tlvs,
1847 ISIS_THREEWAY_DOWN,
1848 ext_circuit_id,
1849 NULL, 0);
1850 }
1851 }
1852
1853 isis_tlvs_set_protocols_supported(tlvs, &circuit->nlpids);
1854
1855 /*
1856 * MT Supported TLV
1857 *
1858 * TLV gets included if no topology is enabled on the interface,
1859 * if one topology other than #0 is enabled, or if multiple topologies
1860 * are enabled.
1861 */
1862 struct isis_circuit_mt_setting **mt_settings;
1863 unsigned int mt_count;
1864
1865 mt_settings = circuit_mt_settings(circuit, &mt_count);
1866 if (mt_count == 0 && area_is_mt(circuit->area)) {
1867 tlvs->mt_router_info_empty = true;
1868 } else if ((mt_count == 1
1869 && mt_settings[0]->mtid != ISIS_MT_IPV4_UNICAST)
1870 || (mt_count > 1)) {
1871 for (unsigned int i = 0; i < mt_count; i++)
1872 isis_tlvs_add_mt_router_info(tlvs, mt_settings[i]->mtid,
1873 false, false);
1874 }
1875
1876 if (circuit->ip_router) {
1877 struct list *circuit_ip_addrs = fabricd_ip_addrs(circuit);
1878
1879 if (circuit_ip_addrs)
1880 isis_tlvs_add_ipv4_addresses(tlvs, circuit_ip_addrs);
1881 }
1882
1883 if (circuit->ipv6_router && circuit->ipv6_link)
1884 isis_tlvs_add_ipv6_addresses(tlvs, circuit->ipv6_link);
1885
1886 if (isis_pack_tlvs(tlvs, circuit->snd_stream, len_pointer,
1887 circuit->pad_hellos, false)) {
1888 isis_free_tlvs(tlvs);
1889 return ISIS_WARNING; /* XXX: Maybe Log TLV structure? */
1890 }
1891
1892 if (isis->debugs & DEBUG_ADJ_PACKETS) {
1893 if (circuit->circ_type == CIRCUIT_T_BROADCAST) {
1894 zlog_debug(
1895 "ISIS-Adj (%s): Sending L%d LAN IIH on %s, length %zd",
1896 circuit->area->area_tag, level,
1897 circuit->interface->name,
1898 stream_get_endp(circuit->snd_stream));
1899 } else {
1900 zlog_debug(
1901 "ISIS-Adj (%s): Sending P2P IIH on %s, length %zd",
1902 circuit->area->area_tag,
1903 circuit->interface->name,
1904 stream_get_endp(circuit->snd_stream));
1905 }
1906 if (isis->debugs & DEBUG_PACKET_DUMP)
1907 zlog_dump_data(STREAM_DATA(circuit->snd_stream),
1908 stream_get_endp(circuit->snd_stream));
1909 }
1910
1911 isis_free_tlvs(tlvs);
1912
1913 pdu_counter_count(circuit->area->pdu_tx_counters,
1914 hello_pdu_type(circuit, level));
1915 retval = circuit->tx(circuit, level);
1916 if (retval != ISIS_OK)
1917 flog_err(EC_ISIS_PACKET,
1918 "ISIS-Adj (%s): Send L%d IIH on %s failed",
1919 circuit->area->area_tag, level,
1920 circuit->interface->name);
1921
1922 return retval;
1923 }
1924
1925 static int send_hello_cb(struct thread *thread)
1926 {
1927 struct isis_circuit_arg *arg = THREAD_ARG(thread);
1928 assert(arg);
1929
1930 struct isis_circuit *circuit = arg->circuit;
1931 int level = arg->level;
1932
1933 assert(circuit);
1934
1935 if (circuit->circ_type == CIRCUIT_T_P2P) {
1936 circuit->u.p2p.t_send_p2p_hello = NULL;
1937 send_hello(circuit, 1);
1938 send_hello_sched(circuit, ISIS_LEVEL1,
1939 1000 * circuit->hello_interval[1]);
1940 return ISIS_OK;
1941 }
1942
1943 if (circuit->circ_type != CIRCUIT_T_BROADCAST) {
1944 zlog_warn("ISIS-Hello (%s): Trying to send hello on unknown circuit type %d",
1945 circuit->area->area_tag, circuit->circ_type);
1946 return ISIS_WARNING;
1947 }
1948
1949 circuit->u.bc.t_send_lan_hello[level - 1] = NULL;
1950 if (!(circuit->is_type & level)) {
1951 zlog_warn("ISIS-Hello (%s): Trying to send L%d IIH in L%d-only circuit",
1952 circuit->area->area_tag, level, 3 - level);
1953 return ISIS_WARNING;
1954 }
1955
1956 if (circuit->u.bc.run_dr_elect[level - 1])
1957 isis_dr_elect(circuit, level);
1958
1959 int rv = send_hello(circuit, level);
1960
1961 /* set next timer thread */
1962 send_hello_sched(circuit, level, 1000 * circuit->hello_interval[level - 1]);
1963 return rv;
1964 }
1965
1966 static void _send_hello_sched(struct isis_circuit *circuit,
1967 struct thread **threadp,
1968 int level, long delay)
1969 {
1970 if (*threadp) {
1971 if (thread_timer_remain_msec(*threadp) < (unsigned long)delay)
1972 return;
1973
1974 thread_cancel(*threadp);
1975 }
1976
1977 thread_add_timer_msec(master, send_hello_cb,
1978 &circuit->level_arg[level - 1],
1979 isis_jitter(delay, IIH_JITTER),
1980 threadp);
1981 }
1982
1983 void send_hello_sched(struct isis_circuit *circuit, int level, long delay)
1984 {
1985 if (circuit->circ_type == CIRCUIT_T_P2P) {
1986 _send_hello_sched(circuit, &circuit->u.p2p.t_send_p2p_hello,
1987 ISIS_LEVEL1, delay);
1988 return;
1989 }
1990
1991 if (circuit->circ_type != CIRCUIT_T_BROADCAST) {
1992 zlog_warn("%s: encountered unknown circuit type %d on %s",
1993 __func__, circuit->circ_type,
1994 circuit->interface->name);
1995 return;
1996 }
1997
1998 for (int loop_level = ISIS_LEVEL1; loop_level <= ISIS_LEVEL2; loop_level++) {
1999 if (!(loop_level & level))
2000 continue;
2001
2002 _send_hello_sched(
2003 circuit,
2004 &circuit->u.bc.t_send_lan_hello[loop_level - 1],
2005 loop_level,
2006 delay
2007 );
2008 }
2009 }
2010
2011
2012 /*
2013 * Count the maximum number of lsps that can be accomodated by a given size.
2014 */
2015 #define LSP_ENTRIES_LEN (10 + ISIS_SYS_ID_LEN)
2016 static uint16_t get_max_lsp_count(uint16_t size)
2017 {
2018 uint16_t tlv_count;
2019 uint16_t lsp_count;
2020 uint16_t remaining_size;
2021
2022 /* First count the full size TLVs */
2023 tlv_count = size / MAX_LSP_ENTRIES_TLV_SIZE;
2024 lsp_count = tlv_count * (MAX_LSP_ENTRIES_TLV_SIZE / LSP_ENTRIES_LEN);
2025
2026 /* The last TLV, if any */
2027 remaining_size = size % MAX_LSP_ENTRIES_TLV_SIZE;
2028 if (remaining_size - 2 >= LSP_ENTRIES_LEN)
2029 lsp_count += (remaining_size - 2) / LSP_ENTRIES_LEN;
2030
2031 return lsp_count;
2032 }
2033
2034 int send_csnp(struct isis_circuit *circuit, int level)
2035 {
2036 if (lspdb_count(&circuit->area->lspdb[level - 1]) == 0)
2037 return ISIS_OK;
2038
2039 uint8_t pdu_type = (level == ISIS_LEVEL1) ? L1_COMPLETE_SEQ_NUM
2040 : L2_COMPLETE_SEQ_NUM;
2041
2042 isis_circuit_stream(circuit, &circuit->snd_stream);
2043 fill_fixed_hdr(pdu_type, circuit->snd_stream);
2044
2045 size_t len_pointer = stream_get_endp(circuit->snd_stream);
2046 stream_putw(circuit->snd_stream, 0);
2047 stream_put(circuit->snd_stream, isis->sysid, ISIS_SYS_ID_LEN);
2048 /* with zero circuit id - ref 9.10, 9.11 */
2049 stream_putc(circuit->snd_stream, 0);
2050
2051 size_t start_pointer = stream_get_endp(circuit->snd_stream);
2052 stream_put(circuit->snd_stream, 0, ISIS_SYS_ID_LEN + 2);
2053 size_t end_pointer = stream_get_endp(circuit->snd_stream);
2054 stream_put(circuit->snd_stream, 0, ISIS_SYS_ID_LEN + 2);
2055
2056 struct isis_passwd *passwd = (level == ISIS_LEVEL1)
2057 ? &circuit->area->area_passwd
2058 : &circuit->area->domain_passwd;
2059
2060 struct isis_tlvs *tlvs = isis_alloc_tlvs();
2061
2062 if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_SEND))
2063 isis_tlvs_add_auth(tlvs, passwd);
2064
2065 size_t tlv_start = stream_get_endp(circuit->snd_stream);
2066 if (isis_pack_tlvs(tlvs, circuit->snd_stream, len_pointer, false,
2067 false)) {
2068 isis_free_tlvs(tlvs);
2069 return ISIS_WARNING;
2070 }
2071 isis_free_tlvs(tlvs);
2072
2073 uint16_t num_lsps =
2074 get_max_lsp_count(STREAM_WRITEABLE(circuit->snd_stream));
2075
2076 uint8_t start[ISIS_SYS_ID_LEN + 2];
2077 memset(start, 0x00, ISIS_SYS_ID_LEN + 2);
2078 uint8_t stop[ISIS_SYS_ID_LEN + 2];
2079 memset(stop, 0xff, ISIS_SYS_ID_LEN + 2);
2080
2081 bool loop = true;
2082 while (loop) {
2083 tlvs = isis_alloc_tlvs();
2084 if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_SEND))
2085 isis_tlvs_add_auth(tlvs, passwd);
2086
2087 struct isis_lsp *last_lsp;
2088 isis_tlvs_add_csnp_entries(tlvs, start, stop, num_lsps,
2089 &circuit->area->lspdb[level - 1],
2090 &last_lsp);
2091 /*
2092 * Update the stop lsp_id before encoding this CSNP.
2093 */
2094 if (tlvs->lsp_entries.count < num_lsps) {
2095 memset(stop, 0xff, ISIS_SYS_ID_LEN + 2);
2096 } else {
2097 memcpy(stop, last_lsp->hdr.lsp_id, sizeof(stop));
2098 }
2099
2100 memcpy(STREAM_DATA(circuit->snd_stream) + start_pointer, start,
2101 ISIS_SYS_ID_LEN + 2);
2102 memcpy(STREAM_DATA(circuit->snd_stream) + end_pointer, stop,
2103 ISIS_SYS_ID_LEN + 2);
2104 stream_set_endp(circuit->snd_stream, tlv_start);
2105 if (isis_pack_tlvs(tlvs, circuit->snd_stream, len_pointer,
2106 false, false)) {
2107 isis_free_tlvs(tlvs);
2108 return ISIS_WARNING;
2109 }
2110
2111 if (isis->debugs & DEBUG_SNP_PACKETS) {
2112 zlog_debug(
2113 "ISIS-Snp (%s): Sending L%d CSNP on %s, length %zd",
2114 circuit->area->area_tag, level,
2115 circuit->interface->name,
2116 stream_get_endp(circuit->snd_stream));
2117 log_multiline(LOG_DEBUG, " ", "%s",
2118 isis_format_tlvs(tlvs));
2119 if (isis->debugs & DEBUG_PACKET_DUMP)
2120 zlog_dump_data(
2121 STREAM_DATA(circuit->snd_stream),
2122 stream_get_endp(circuit->snd_stream));
2123 }
2124
2125 pdu_counter_count(circuit->area->pdu_tx_counters, pdu_type);
2126 int retval = circuit->tx(circuit, level);
2127 if (retval != ISIS_OK) {
2128 flog_err(EC_ISIS_PACKET,
2129 "ISIS-Snp (%s): Send L%d CSNP on %s failed",
2130 circuit->area->area_tag, level,
2131 circuit->interface->name);
2132 isis_free_tlvs(tlvs);
2133 return retval;
2134 }
2135
2136 /*
2137 * Start lsp_id of the next CSNP should be one plus the
2138 * stop lsp_id in this current CSNP.
2139 */
2140 memcpy(start, stop, ISIS_SYS_ID_LEN + 2);
2141 loop = false;
2142 for (int i = ISIS_SYS_ID_LEN + 1; i >= 0; --i) {
2143 if (start[i] < (uint8_t)0xff) {
2144 start[i] += 1;
2145 loop = true;
2146 break;
2147 }
2148 }
2149 memset(stop, 0xff, ISIS_SYS_ID_LEN + 2);
2150 isis_free_tlvs(tlvs);
2151 }
2152
2153 return ISIS_OK;
2154 }
2155
2156 int send_l1_csnp(struct thread *thread)
2157 {
2158 struct isis_circuit *circuit;
2159
2160 circuit = THREAD_ARG(thread);
2161 assert(circuit);
2162
2163 circuit->t_send_csnp[0] = NULL;
2164
2165 if ((circuit->circ_type == CIRCUIT_T_BROADCAST
2166 && circuit->u.bc.is_dr[0])
2167 || circuit->circ_type == CIRCUIT_T_P2P) {
2168 send_csnp(circuit, 1);
2169 }
2170 /* set next timer thread */
2171 thread_add_timer(master, send_l1_csnp, circuit,
2172 isis_jitter(circuit->csnp_interval[0], CSNP_JITTER),
2173 &circuit->t_send_csnp[0]);
2174
2175 return ISIS_OK;
2176 }
2177
2178 int send_l2_csnp(struct thread *thread)
2179 {
2180 struct isis_circuit *circuit;
2181
2182 circuit = THREAD_ARG(thread);
2183 assert(circuit);
2184
2185 circuit->t_send_csnp[1] = NULL;
2186
2187 if ((circuit->circ_type == CIRCUIT_T_BROADCAST
2188 && circuit->u.bc.is_dr[1])
2189 || circuit->circ_type == CIRCUIT_T_P2P) {
2190 send_csnp(circuit, 2);
2191 }
2192 /* set next timer thread */
2193 thread_add_timer(master, send_l2_csnp, circuit,
2194 isis_jitter(circuit->csnp_interval[1], CSNP_JITTER),
2195 &circuit->t_send_csnp[1]);
2196
2197 return ISIS_OK;
2198 }
2199
2200 /*
2201 * 7.3.15.4 action on expiration of partial SNP interval
2202 * level 1
2203 */
2204 static int send_psnp(int level, struct isis_circuit *circuit)
2205 {
2206 if (circuit->circ_type == CIRCUIT_T_BROADCAST
2207 && circuit->u.bc.is_dr[level - 1])
2208 return ISIS_OK;
2209
2210 if (lspdb_count(&circuit->area->lspdb[level - 1]) == 0)
2211 return ISIS_OK;
2212
2213 if (!circuit->snd_stream)
2214 return ISIS_ERROR;
2215
2216 uint8_t pdu_type = (level == ISIS_LEVEL1) ? L1_PARTIAL_SEQ_NUM
2217 : L2_PARTIAL_SEQ_NUM;
2218
2219 isis_circuit_stream(circuit, &circuit->snd_stream);
2220 fill_fixed_hdr(pdu_type, circuit->snd_stream);
2221
2222 size_t len_pointer = stream_get_endp(circuit->snd_stream);
2223 stream_putw(circuit->snd_stream, 0); /* length is filled in later */
2224 stream_put(circuit->snd_stream, isis->sysid, ISIS_SYS_ID_LEN);
2225 stream_putc(circuit->snd_stream, circuit->idx);
2226
2227 struct isis_passwd *passwd = (level == ISIS_LEVEL1)
2228 ? &circuit->area->area_passwd
2229 : &circuit->area->domain_passwd;
2230
2231 struct isis_tlvs *tlvs = isis_alloc_tlvs();
2232
2233 if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_SEND))
2234 isis_tlvs_add_auth(tlvs, passwd);
2235
2236 size_t tlv_start = stream_get_endp(circuit->snd_stream);
2237 if (isis_pack_tlvs(tlvs, circuit->snd_stream, len_pointer, false,
2238 false)) {
2239 isis_free_tlvs(tlvs);
2240 return ISIS_WARNING;
2241 }
2242 isis_free_tlvs(tlvs);
2243
2244 uint16_t num_lsps =
2245 get_max_lsp_count(STREAM_WRITEABLE(circuit->snd_stream));
2246
2247 while (1) {
2248 struct isis_lsp *lsp;
2249
2250 tlvs = isis_alloc_tlvs();
2251 if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_SEND))
2252 isis_tlvs_add_auth(tlvs, passwd);
2253
2254 frr_each (lspdb, &circuit->area->lspdb[level - 1], lsp) {
2255 if (ISIS_CHECK_FLAG(lsp->SSNflags, circuit))
2256 isis_tlvs_add_lsp_entry(tlvs, lsp);
2257
2258 if (tlvs->lsp_entries.count == num_lsps)
2259 break;
2260 }
2261
2262 if (!tlvs->lsp_entries.count) {
2263 isis_free_tlvs(tlvs);
2264 return ISIS_OK;
2265 }
2266
2267 stream_set_endp(circuit->snd_stream, tlv_start);
2268 if (isis_pack_tlvs(tlvs, circuit->snd_stream, len_pointer,
2269 false, false)) {
2270 isis_free_tlvs(tlvs);
2271 return ISIS_WARNING;
2272 }
2273
2274 if (isis->debugs & DEBUG_SNP_PACKETS) {
2275 zlog_debug(
2276 "ISIS-Snp (%s): Sending L%d PSNP on %s, length %zd",
2277 circuit->area->area_tag, level,
2278 circuit->interface->name,
2279 stream_get_endp(circuit->snd_stream));
2280 log_multiline(LOG_DEBUG, " ", "%s",
2281 isis_format_tlvs(tlvs));
2282 if (isis->debugs & DEBUG_PACKET_DUMP)
2283 zlog_dump_data(
2284 STREAM_DATA(circuit->snd_stream),
2285 stream_get_endp(circuit->snd_stream));
2286 }
2287
2288 pdu_counter_count(circuit->area->pdu_tx_counters, pdu_type);
2289 int retval = circuit->tx(circuit, level);
2290 if (retval != ISIS_OK) {
2291 flog_err(EC_ISIS_PACKET,
2292 "ISIS-Snp (%s): Send L%d PSNP on %s failed",
2293 circuit->area->area_tag, level,
2294 circuit->interface->name);
2295 isis_free_tlvs(tlvs);
2296 return retval;
2297 }
2298
2299 /*
2300 * sending succeeded, we can clear SSN flags of this circuit
2301 * for the LSPs in list
2302 */
2303 struct isis_lsp_entry *entry_head;
2304 entry_head = (struct isis_lsp_entry *)tlvs->lsp_entries.head;
2305 for (struct isis_lsp_entry *entry = entry_head; entry;
2306 entry = entry->next)
2307 ISIS_CLEAR_FLAG(entry->lsp->SSNflags, circuit);
2308 isis_free_tlvs(tlvs);
2309 }
2310
2311 return ISIS_OK;
2312 }
2313
2314 int send_l1_psnp(struct thread *thread)
2315 {
2316
2317 struct isis_circuit *circuit;
2318
2319 circuit = THREAD_ARG(thread);
2320 assert(circuit);
2321
2322 circuit->t_send_psnp[0] = NULL;
2323
2324 send_psnp(1, circuit);
2325 /* set next timer thread */
2326 thread_add_timer(master, send_l1_psnp, circuit,
2327 isis_jitter(circuit->psnp_interval[0], PSNP_JITTER),
2328 &circuit->t_send_psnp[0]);
2329
2330 return ISIS_OK;
2331 }
2332
2333 /*
2334 * 7.3.15.4 action on expiration of partial SNP interval
2335 * level 2
2336 */
2337 int send_l2_psnp(struct thread *thread)
2338 {
2339 struct isis_circuit *circuit;
2340
2341 circuit = THREAD_ARG(thread);
2342 assert(circuit);
2343
2344 circuit->t_send_psnp[1] = NULL;
2345
2346 send_psnp(2, circuit);
2347
2348 /* set next timer thread */
2349 thread_add_timer(master, send_l2_psnp, circuit,
2350 isis_jitter(circuit->psnp_interval[1], PSNP_JITTER),
2351 &circuit->t_send_psnp[1]);
2352
2353 return ISIS_OK;
2354 }
2355
2356 /*
2357 * ISO 10589 - 7.3.14.3
2358 */
2359 void send_lsp(struct isis_circuit *circuit, struct isis_lsp *lsp,
2360 enum isis_tx_type tx_type)
2361 {
2362 int clear_srm = 1;
2363 int retval = ISIS_OK;
2364
2365 if (circuit->state != C_STATE_UP || circuit->is_passive == 1)
2366 goto out;
2367
2368 /*
2369 * Do not send if levels do not match
2370 */
2371 if (!(lsp->level & circuit->is_type))
2372 goto out;
2373
2374 /*
2375 * Do not send if we do not have adjacencies in state up on the circuit
2376 */
2377 if (circuit->upadjcount[lsp->level - 1] == 0)
2378 goto out;
2379
2380 /* stream_copy will assert and stop program execution if LSP is larger
2381 * than
2382 * the circuit's MTU. So handle and log this case here. */
2383 if (stream_get_endp(lsp->pdu) > stream_get_size(circuit->snd_stream)) {
2384 flog_err(
2385 EC_ISIS_PACKET,
2386 "ISIS-Upd (%s): Can't send L%d LSP %s, seq 0x%08" PRIx32
2387 ", cksum 0x%04" PRIx16 ", lifetime %" PRIu16
2388 "s on %s. LSP Size is %zu while interface stream size is %zu.",
2389 circuit->area->area_tag, lsp->level,
2390 rawlspid_print(lsp->hdr.lsp_id), lsp->hdr.seqno,
2391 lsp->hdr.checksum, lsp->hdr.rem_lifetime,
2392 circuit->interface->name, stream_get_endp(lsp->pdu),
2393 stream_get_size(circuit->snd_stream));
2394 #ifndef FABRICD
2395 /* send a northbound notification */
2396 isis_notif_lsp_too_large(circuit, stream_get_endp(lsp->pdu),
2397 rawlspid_print(lsp->hdr.lsp_id));
2398 #endif /* ifndef FABRICD */
2399 if (isis->debugs & DEBUG_PACKET_DUMP)
2400 zlog_dump_data(STREAM_DATA(lsp->pdu),
2401 stream_get_endp(lsp->pdu));
2402 retval = ISIS_ERROR;
2403 goto out;
2404 }
2405
2406 /* copy our lsp to the send buffer */
2407 stream_copy(circuit->snd_stream, lsp->pdu);
2408
2409 if (tx_type == TX_LSP_CIRCUIT_SCOPED) {
2410 stream_putc_at(circuit->snd_stream, 4, FS_LINK_STATE);
2411 stream_putc_at(circuit->snd_stream, 7,
2412 L2_CIRCUIT_FLOODING_SCOPE);
2413 }
2414
2415 if (isis->debugs & DEBUG_UPDATE_PACKETS) {
2416 zlog_debug("ISIS-Upd (%s): Sending %sL%d LSP %s, seq 0x%08" PRIx32
2417 ", cksum 0x%04" PRIx16 ", lifetime %" PRIu16
2418 "s on %s",
2419 circuit->area->area_tag,
2420 (tx_type == TX_LSP_CIRCUIT_SCOPED)
2421 ? "Circuit scoped " : "",
2422 lsp->level,
2423 rawlspid_print(lsp->hdr.lsp_id), lsp->hdr.seqno,
2424 lsp->hdr.checksum, lsp->hdr.rem_lifetime,
2425 circuit->interface->name);
2426 if (isis->debugs & DEBUG_PACKET_DUMP)
2427 zlog_dump_data(STREAM_DATA(circuit->snd_stream),
2428 stream_get_endp(circuit->snd_stream));
2429 }
2430
2431 uint8_t pdu_type = (tx_type == TX_LSP_CIRCUIT_SCOPED) ? FS_LINK_STATE
2432 : (lsp->level == ISIS_LEVEL1) ? L1_LINK_STATE
2433 : L2_LINK_STATE;
2434
2435 clear_srm = 0;
2436 pdu_counter_count(circuit->area->pdu_tx_counters, pdu_type);
2437 retval = circuit->tx(circuit, lsp->level);
2438 if (retval != ISIS_OK) {
2439 flog_err(EC_ISIS_PACKET,
2440 "ISIS-Upd (%s): Send L%d LSP on %s failed %s",
2441 circuit->area->area_tag, lsp->level,
2442 circuit->interface->name,
2443 (retval == ISIS_WARNING) ? "temporarily"
2444 : "permanently");
2445 }
2446
2447 out:
2448 if (clear_srm
2449 || (retval == ISIS_OK && circuit->circ_type == CIRCUIT_T_BROADCAST)
2450 || (retval != ISIS_OK && retval != ISIS_WARNING)) {
2451 /* SRM flag will trigger retransmission. We will not retransmit
2452 * if we
2453 * encountered a fatal error.
2454 * On success, they should only be cleared if it's a broadcast
2455 * circuit.
2456 * On a P2P circuit, we will wait for the ack from the neighbor
2457 * to clear
2458 * the fag.
2459 */
2460 isis_tx_queue_del(circuit->tx_queue, lsp);
2461 }
2462 }