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