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