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