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