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