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