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