2 * IS-IS Rout(e)ing protocol - isis_pdu.c
5 * Copyright (C) 2001,2002 Sampo Saaristo
6 * Tampere University of Technology
7 * Institute of Communications Engineering
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)
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
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
37 #include "lib_errors.h"
39 #include "isisd/isis_constants.h"
40 #include "isisd/isis_common.h"
41 #include "isisd/isis_flags.h"
42 #include "isisd/isis_adjacency.h"
43 #include "isisd/isis_circuit.h"
44 #include "isisd/isis_network.h"
45 #include "isisd/isis_misc.h"
46 #include "isisd/isis_dr.h"
47 #include "isisd/isisd.h"
48 #include "isisd/isis_dynhn.h"
49 #include "isisd/isis_lsp.h"
50 #include "isisd/isis_pdu.h"
51 #include "isisd/iso_checksum.h"
52 #include "isisd/isis_csm.h"
53 #include "isisd/isis_events.h"
54 #include "isisd/isis_te.h"
55 #include "isisd/isis_mt.h"
56 #include "isisd/isis_tlvs.h"
57 #include "isisd/isis_errors.h"
58 #include "isisd/fabricd.h"
59 #include "isisd/isis_tx_queue.h"
60 #include "isisd/isis_pdu_counter.h"
61 #include "isisd/isis_nb.h"
63 static int ack_lsp(struct isis_lsp_hdr
*hdr
, struct isis_circuit
*circuit
,
70 (level
== IS_LEVEL_1
) ? L1_PARTIAL_SEQ_NUM
: L2_PARTIAL_SEQ_NUM
;
72 isis_circuit_stream(circuit
, &circuit
->snd_stream
);
74 fill_fixed_hdr(pdu_type
, circuit
->snd_stream
);
76 lenp
= stream_get_endp(circuit
->snd_stream
);
78 stream_putw(circuit
->snd_stream
, 0); /* PDU length */
79 stream_put(circuit
->snd_stream
, circuit
->isis
->sysid
, ISIS_SYS_ID_LEN
);
80 stream_putc(circuit
->snd_stream
, circuit
->idx
);
81 stream_putc(circuit
->snd_stream
, 9); /* code */
82 stream_putc(circuit
->snd_stream
, 16); /* len */
84 stream_putw(circuit
->snd_stream
, hdr
->rem_lifetime
);
85 stream_put(circuit
->snd_stream
, hdr
->lsp_id
, ISIS_SYS_ID_LEN
+ 2);
86 stream_putl(circuit
->snd_stream
, hdr
->seqno
);
87 stream_putw(circuit
->snd_stream
, hdr
->checksum
);
89 length
= (uint16_t)stream_get_endp(circuit
->snd_stream
);
90 /* Update PDU length */
91 stream_putw_at(circuit
->snd_stream
, lenp
, length
);
93 pdu_counter_count(circuit
->area
->pdu_tx_counters
, pdu_type
);
94 retval
= circuit
->tx(circuit
, level
);
95 if (retval
!= ISIS_OK
)
96 flog_err(EC_ISIS_PACKET
,
97 "ISIS-Upd (%s): Send L%d LSP PSNP on %s failed",
98 circuit
->area
->area_tag
, level
,
99 circuit
->interface
->name
);
109 struct isis_circuit
*circuit
;
114 uint8_t sys_id
[ISIS_SYS_ID_LEN
];
121 uint8_t dis
[ISIS_SYS_ID_LEN
+ 1];
126 struct isis_tlvs
*tlvs
;
129 static int process_p2p_hello(struct iih_info
*iih
)
131 struct isis_threeway_adj
*tw_adj
= iih
->tlvs
->threeway_adj
;
134 if (tw_adj
->state
> ISIS_THREEWAY_DOWN
) {
135 if (IS_DEBUG_ADJ_PACKETS
) {
136 zlog_debug("ISIS-Adj (%s): Rcvd P2P IIH from (%s) with invalid three-way state: %d",
137 iih
->circuit
->area
->area_tag
,
138 iih
->circuit
->interface
->name
,
144 if (tw_adj
->neighbor_set
145 && (memcmp(tw_adj
->neighbor_id
, iih
->circuit
->isis
->sysid
,
147 || tw_adj
->neighbor_circuit_id
148 != (uint32_t)iih
->circuit
->idx
)) {
150 if (IS_DEBUG_ADJ_PACKETS
) {
151 zlog_debug("ISIS-Adj (%s): Rcvd P2P IIH from (%s) which lists IS/Circuit different from us as neighbor.",
152 iih
->circuit
->area
->area_tag
,
153 iih
->circuit
->interface
->name
);
161 * My interpertation of the ISO, if no adj exists we will create one for
164 struct isis_adjacency
*adj
= iih
->circuit
->u
.p2p
.neighbor
;
165 /* If an adjacency exists, check it is with the source of the hello
168 if (memcmp(iih
->sys_id
, adj
->sysid
, ISIS_SYS_ID_LEN
)) {
170 "hello source and adjacency do not match, set adj down\n");
171 isis_adj_state_change(&adj
, ISIS_ADJ_DOWN
,
176 if (!adj
|| adj
->level
!= iih
->circ_type
) {
178 adj
= isis_new_adj(iih
->sys_id
, NULL
, iih
->circ_type
,
181 adj
->level
= iih
->circ_type
;
183 iih
->circuit
->u
.p2p
.neighbor
= adj
;
184 /* Build lsp with the new neighbor entry when a new
185 * adjacency is formed. Set adjacency circuit type to
186 * IIH PDU header circuit type before lsp is regenerated
187 * when an adjacency is up. This will result in the new
188 * adjacency entry getting added to the lsp tlv neighbor list.
190 adj
->circuit_t
= iih
->circ_type
;
191 isis_adj_state_change(&adj
, ISIS_ADJ_INITIALIZING
, NULL
);
192 adj
->sys_type
= ISIS_SYSTYPE_UNKNOWN
;
196 adj
->ext_circuit_id
= tw_adj
->local_circuit_id
;
198 /* 8.2.6 Monitoring point-to-point adjacencies */
199 adj
->hold_time
= iih
->holdtime
;
200 adj
->last_upd
= time(NULL
);
203 isis_tlvs_to_adj(iih
->tlvs
, adj
, &changed
);
204 changed
|= tlvs_to_adj_mt_set(iih
->tlvs
, iih
->v4_usable
, iih
->v6_usable
,
207 /* lets take care of the expiry */
208 thread_cancel(&adj
->t_expire
);
209 thread_add_timer(master
, isis_adj_expire
, adj
, (long)adj
->hold_time
,
212 /* While fabricds initial sync is in progress, ignore hellos from other
213 * interfaces than the one we are performing the initial sync on. */
214 if (fabricd_initial_sync_is_in_progress(iih
->circuit
->area
)
215 && fabricd_initial_sync_circuit(iih
->circuit
->area
) != iih
->circuit
)
218 /* 8.2.5.2 a) a match was detected */
219 if (isis_tlvs_area_addresses_match(iih
->tlvs
,
220 iih
->circuit
->area
->area_addrs
)) {
221 /* 8.2.5.2 a) 2) If the system is L1 - table 5 */
222 if (iih
->circuit
->area
->is_type
== IS_LEVEL_1
) {
223 switch (iih
->circ_type
) {
225 case IS_LEVEL_1_AND_2
:
226 if (adj
->adj_state
!= ISIS_ADJ_UP
227 || adj
->adj_usage
== ISIS_ADJ_LEVEL1
) {
228 isis_adj_process_threeway(adj
, tw_adj
,
233 if (adj
->adj_state
!= ISIS_ADJ_UP
) {
234 /* (7) reject - wrong system type event
236 zlog_warn("wrongSystemType");
238 } else if (adj
->adj_usage
== ISIS_ADJ_LEVEL1
) {
239 /* (6) down - wrong system */
240 isis_adj_state_change(&adj
,
248 /* 8.2.5.2 a) 3) If the system is L1L2 - table 6 */
249 if (iih
->circuit
->area
->is_type
== IS_LEVEL_1_AND_2
) {
250 switch (iih
->circ_type
) {
252 if (adj
->adj_state
!= ISIS_ADJ_UP
253 || adj
->adj_usage
== ISIS_ADJ_LEVEL1
) {
254 isis_adj_process_threeway(adj
, tw_adj
,
256 } else if ((adj
->adj_usage
257 == ISIS_ADJ_LEVEL1AND2
)
259 == ISIS_ADJ_LEVEL2
)) {
260 /* (8) down - wrong system */
261 isis_adj_state_change(&adj
,
267 if (adj
->adj_state
!= ISIS_ADJ_UP
268 || adj
->adj_usage
== ISIS_ADJ_LEVEL2
) {
269 isis_adj_process_threeway(adj
, tw_adj
,
271 } else if ((adj
->adj_usage
== ISIS_ADJ_LEVEL1
)
273 == ISIS_ADJ_LEVEL1AND2
)) {
274 /* (8) down - wrong system */
275 isis_adj_state_change(&adj
,
280 case IS_LEVEL_1_AND_2
:
281 if (adj
->adj_state
!= ISIS_ADJ_UP
282 || adj
->adj_usage
== ISIS_ADJ_LEVEL1AND2
) {
283 isis_adj_process_threeway(adj
, tw_adj
,
284 ISIS_ADJ_LEVEL1AND2
);
285 } else if ((adj
->adj_usage
== ISIS_ADJ_LEVEL1
)
287 == ISIS_ADJ_LEVEL2
)) {
288 /* (8) down - wrong system */
289 isis_adj_state_change(&adj
,
297 /* 8.2.5.2 a) 4) If the system is L2 - table 7 */
298 if (iih
->circuit
->area
->is_type
== IS_LEVEL_2
) {
299 switch (iih
->circ_type
) {
301 if (adj
->adj_state
!= ISIS_ADJ_UP
) {
302 /* (5) reject - wrong system type event
304 zlog_warn("wrongSystemType");
306 } else if ((adj
->adj_usage
307 == ISIS_ADJ_LEVEL1AND2
)
309 == ISIS_ADJ_LEVEL2
)) {
310 /* (6) down - wrong system */
311 isis_adj_state_change(&adj
,
316 case IS_LEVEL_1_AND_2
:
318 if (adj
->adj_state
!= ISIS_ADJ_UP
319 || adj
->adj_usage
== ISIS_ADJ_LEVEL2
) {
320 isis_adj_process_threeway(adj
, tw_adj
,
322 } else if (adj
->adj_usage
323 == ISIS_ADJ_LEVEL1AND2
) {
324 /* (6) down - wrong system */
325 isis_adj_state_change(&adj
,
333 /* 8.2.5.2 b) if no match was detected */
334 else if (listcount(iih
->circuit
->area
->area_addrs
) > 0) {
335 if (iih
->circuit
->area
->is_type
== IS_LEVEL_1
) {
336 /* 8.2.5.2 b) 1) is_type L1 and adj is not up */
337 if (adj
->adj_state
!= ISIS_ADJ_UP
) {
338 isis_adj_state_change(&adj
, ISIS_ADJ_DOWN
,
340 /* 8.2.5.2 b) 2)is_type L1 and adj is up */
342 isis_adj_state_change(&adj
, ISIS_ADJ_DOWN
,
343 "Down - Area Mismatch");
346 /* 8.2.5.2 b 3 If the system is L2 or L1L2 - table 8 */
348 switch (iih
->circ_type
) {
350 if (adj
->adj_state
!= ISIS_ADJ_UP
) {
351 /* (6) reject - Area Mismatch event */
352 zlog_warn("AreaMismatch");
354 } else if (adj
->adj_usage
== ISIS_ADJ_LEVEL1
) {
355 /* (7) down - area mismatch */
356 isis_adj_state_change(&adj
,
360 } else if ((adj
->adj_usage
361 == ISIS_ADJ_LEVEL1AND2
)
363 == ISIS_ADJ_LEVEL2
)) {
364 /* (7) down - wrong system */
365 isis_adj_state_change(&adj
,
370 case IS_LEVEL_1_AND_2
:
372 if (adj
->adj_state
!= ISIS_ADJ_UP
373 || adj
->adj_usage
== ISIS_ADJ_LEVEL2
) {
374 isis_adj_process_threeway(adj
, tw_adj
,
376 } else if (adj
->adj_usage
== ISIS_ADJ_LEVEL1
) {
377 /* (7) down - wrong system */
378 isis_adj_state_change(&adj
,
381 } else if (adj
->adj_usage
382 == ISIS_ADJ_LEVEL1AND2
) {
383 if (iih
->circ_type
== IS_LEVEL_2
) {
384 /* (7) down - wrong system */
385 isis_adj_state_change(
389 /* (7) down - area mismatch */
390 isis_adj_state_change(
399 /* down - area mismatch */
400 isis_adj_state_change(&adj
, ISIS_ADJ_DOWN
, "Area Mismatch");
404 if (adj
->adj_state
== ISIS_ADJ_UP
&& changed
) {
405 lsp_regenerate_schedule(
407 isis_adj_usage2levels(adj
->adj_usage
), 0);
410 /* 8.2.5.2 c) if the action was up - comparing circuit IDs */
411 /* FIXME - Missing parts */
413 /* some of my own understanding of the ISO, why the heck does
414 * it not say what should I change the system_type to...
416 switch (adj
->adj_usage
) {
417 case ISIS_ADJ_LEVEL1
:
418 adj
->sys_type
= ISIS_SYSTYPE_L1_IS
;
420 case ISIS_ADJ_LEVEL2
:
421 adj
->sys_type
= ISIS_SYSTYPE_L2_IS
;
423 case ISIS_ADJ_LEVEL1AND2
:
424 adj
->sys_type
= ISIS_SYSTYPE_L2_IS
;
427 adj
->sys_type
= ISIS_SYSTYPE_UNKNOWN
;
432 if (IS_DEBUG_ADJ_PACKETS
) {
434 "ISIS-Adj (%s): Rcvd P2P IIH from (%s), cir type %s, cir id %hhu, length %hu",
435 iih
->circuit
->area
->area_tag
,
436 iih
->circuit
->interface
->name
,
437 circuit_t2string(iih
->circuit
->is_type
),
438 iih
->circuit
->circuit_id
, iih
->pdu_len
);
444 static int process_lan_hello(struct iih_info
*iih
)
446 struct isis_adjacency
*adj
;
447 adj
= isis_adj_lookup(iih
->sys_id
,
448 iih
->circuit
->u
.bc
.adjdb
[iih
->level
- 1]);
449 if ((adj
== NULL
) || (memcmp(adj
->snpa
, iih
->ssnpa
, ETH_ALEN
))
450 || (adj
->level
!= iih
->level
)) {
452 /* Do as in 8.4.2.5 */
453 adj
= isis_new_adj(iih
->sys_id
, iih
->ssnpa
, iih
->level
,
457 memcpy(adj
->snpa
, iih
->ssnpa
, 6);
459 memset(adj
->snpa
, ' ', 6);
461 adj
->level
= iih
->level
;
463 isis_adj_state_change(&adj
, ISIS_ADJ_INITIALIZING
, NULL
);
465 if (iih
->level
== IS_LEVEL_1
)
466 adj
->sys_type
= ISIS_SYSTYPE_L1_IS
;
468 adj
->sys_type
= ISIS_SYSTYPE_L2_IS
;
469 list_delete_all_node(
470 iih
->circuit
->u
.bc
.lan_neighs
[iih
->level
- 1]);
471 isis_adj_build_neigh_list(
472 iih
->circuit
->u
.bc
.adjdb
[iih
->level
- 1],
473 iih
->circuit
->u
.bc
.lan_neighs
[iih
->level
- 1]);
476 if (adj
->dis_record
[iih
->level
- 1].dis
== ISIS_IS_DIS
) {
477 uint8_t *dis
= (iih
->level
== 1)
478 ? iih
->circuit
->u
.bc
.l1_desig_is
479 : iih
->circuit
->u
.bc
.l2_desig_is
;
481 if (memcmp(dis
, iih
->dis
, ISIS_SYS_ID_LEN
+ 1)) {
482 thread_add_event(master
, isis_event_dis_status_change
,
483 iih
->circuit
, 0, NULL
);
484 memcpy(dis
, iih
->dis
, ISIS_SYS_ID_LEN
+ 1);
488 adj
->circuit_t
= iih
->circ_type
;
489 adj
->hold_time
= iih
->holdtime
;
490 adj
->last_upd
= time(NULL
);
491 adj
->prio
[iih
->level
- 1] = iih
->priority
;
492 memcpy(adj
->lanid
, iih
->dis
, ISIS_SYS_ID_LEN
+ 1);
495 isis_tlvs_to_adj(iih
->tlvs
, adj
, &changed
);
496 changed
|= tlvs_to_adj_mt_set(iih
->tlvs
, iih
->v4_usable
, iih
->v6_usable
,
499 /* lets take care of the expiry */
500 thread_cancel(&adj
->t_expire
);
501 thread_add_timer(master
, isis_adj_expire
, adj
, (long)adj
->hold_time
,
505 * If the snpa for this circuit is found from LAN Neighbours TLV
506 * we have two-way communication -> adjacency can be put to state "up"
508 bool own_snpa_found
=
509 isis_tlvs_own_snpa_found(iih
->tlvs
, iih
->circuit
->u
.bc
.snpa
);
511 if (adj
->adj_state
!= ISIS_ADJ_UP
) {
512 if (own_snpa_found
) {
513 isis_adj_state_change(
515 "own SNPA found in LAN Neighbours TLV");
518 if (!own_snpa_found
) {
519 isis_adj_state_change(
520 &adj
, ISIS_ADJ_INITIALIZING
,
521 "own SNPA not found in LAN Neighbours TLV");
525 if (adj
->adj_state
== ISIS_ADJ_UP
&& changed
)
526 lsp_regenerate_schedule(adj
->circuit
->area
, iih
->level
, 0);
528 if (IS_DEBUG_ADJ_PACKETS
) {
530 "ISIS-Adj (%s): Rcvd L%d LAN IIH from %s on %s, cirType %s, cirID %u, length %zd",
531 iih
->circuit
->area
->area_tag
, iih
->level
,
532 snpa_print(iih
->ssnpa
), iih
->circuit
->interface
->name
,
533 circuit_t2string(iih
->circuit
->is_type
),
534 iih
->circuit
->circuit_id
,
535 stream_get_endp(iih
->circuit
->rcv_stream
));
540 static int pdu_len_validate(uint16_t pdu_len
, struct isis_circuit
*circuit
)
542 if (pdu_len
< stream_get_getp(circuit
->rcv_stream
)
543 || pdu_len
> ISO_MTU(circuit
)
544 || pdu_len
> stream_get_endp(circuit
->rcv_stream
))
547 if (pdu_len
< stream_get_endp(circuit
->rcv_stream
))
548 stream_set_endp(circuit
->rcv_stream
, pdu_len
);
552 static int process_hello(uint8_t pdu_type
, struct isis_circuit
*circuit
,
555 /* keep a copy of the raw pdu for NB notifications */
556 size_t pdu_start
= stream_get_getp(circuit
->rcv_stream
);
557 size_t pdu_end
= stream_get_endp(circuit
->rcv_stream
);
558 char raw_pdu
[pdu_end
- pdu_start
];
559 bool p2p_hello
= (pdu_type
== P2P_HELLO
);
560 int level
= p2p_hello
? 0
561 : (pdu_type
== L1_LAN_HELLO
) ? ISIS_LEVEL1
563 const char *pdu_name
=
566 : (level
== ISIS_LEVEL1
) ? "L1 LAN IIH" : "L2 LAN IIH";
568 stream_get_from(raw_pdu
, circuit
->rcv_stream
, pdu_start
,
569 pdu_end
- pdu_start
);
570 if (IS_DEBUG_ADJ_PACKETS
) {
571 zlog_debug("ISIS-Adj (%s): Rcvd %s on %s, cirType %s, cirID %u",
572 circuit
->area
->area_tag
, pdu_name
,
573 circuit
->interface
->name
,
574 circuit_t2string(circuit
->is_type
),
575 circuit
->circuit_id
);
576 if (IS_DEBUG_PACKET_DUMP
)
577 zlog_dump_data(STREAM_DATA(circuit
->rcv_stream
),
578 stream_get_endp(circuit
->rcv_stream
));
582 if (circuit
->circ_type
!= CIRCUIT_T_P2P
) {
583 zlog_warn("p2p hello on non p2p circuit");
584 circuit
->rej_adjacencies
++;
586 isis_notif_reject_adjacency(
587 circuit
, "p2p hello on non p2p circuit",
589 #endif /* ifndef FABRICD */
593 if (circuit
->circ_type
!= CIRCUIT_T_BROADCAST
) {
594 zlog_warn("lan hello on non broadcast circuit");
595 circuit
->rej_adjacencies
++;
597 isis_notif_reject_adjacency(
598 circuit
, "lan hello on non broadcast circuit",
600 #endif /* ifndef FABRICD */
604 if (circuit
->ext_domain
) {
606 "level %d LAN Hello received over circuit with externalDomain = true",
608 circuit
->rej_adjacencies
++;
610 isis_notif_reject_adjacency(
612 "LAN Hello received over circuit with externalDomain = true",
614 #endif /* ifndef FABRICD */
618 if (!(circuit
->is_type
& level
)) {
619 if (IS_DEBUG_ADJ_PACKETS
) {
621 "ISIS-Adj (%s): Interface level mismatch, %s",
622 circuit
->area
->area_tag
,
623 circuit
->interface
->name
);
625 circuit
->rej_adjacencies
++;
627 isis_notif_reject_adjacency(
628 circuit
, "Interface level mismatch", raw_pdu
);
629 #endif /* ifndef FABRICD */
634 struct iih_info iih
= {
635 .circuit
= circuit
, .ssnpa
= ssnpa
, .level
= level
};
637 /* Generic IIH Header */
638 iih
.circ_type
= stream_getc(circuit
->rcv_stream
) & 0x03;
639 stream_get(iih
.sys_id
, circuit
->rcv_stream
, ISIS_SYS_ID_LEN
);
640 iih
.holdtime
= stream_getw(circuit
->rcv_stream
);
641 iih
.pdu_len
= stream_getw(circuit
->rcv_stream
);
644 iih
.circuit_id
= stream_getc(circuit
->rcv_stream
);
646 iih
.priority
= stream_getc(circuit
->rcv_stream
);
647 stream_get(iih
.dis
, circuit
->rcv_stream
, ISIS_SYS_ID_LEN
+ 1);
650 if (pdu_len_validate(iih
.pdu_len
, circuit
)) {
652 "ISIS-Adj (%s): Rcvd %s from (%s) with invalid pdu length %hu",
653 circuit
->area
->area_tag
, pdu_name
,
654 circuit
->interface
->name
, iih
.pdu_len
);
655 circuit
->rej_adjacencies
++;
657 isis_notif_reject_adjacency(circuit
, "Invalid PDU length",
659 #endif /* ifndef FABRICD */
663 if (!p2p_hello
&& !(level
& iih
.circ_type
)) {
664 flog_err(EC_ISIS_PACKET
,
665 "Level %d LAN Hello with Circuit Type %d", level
,
667 circuit
->rej_adjacencies
++;
669 isis_notif_reject_adjacency(
670 circuit
, "LAN Hello with wrong IS-level", raw_pdu
);
671 #endif /* ifndef FABRICD */
675 const char *error_log
;
676 int retval
= ISIS_WARNING
;
678 if (isis_unpack_tlvs(STREAM_READABLE(circuit
->rcv_stream
),
679 circuit
->rcv_stream
, &iih
.tlvs
, &error_log
)) {
680 zlog_warn("isis_unpack_tlvs() failed: %s", error_log
);
681 circuit
->rej_adjacencies
++;
683 isis_notif_reject_adjacency(circuit
, "Failed to unpack TLVs",
685 #endif /* ifndef FABRICD */
689 if (!iih
.tlvs
->area_addresses
.count
) {
690 zlog_warn("No Area addresses TLV in %s", pdu_name
);
692 /* send northbound notification */
693 isis_notif_area_mismatch(circuit
, raw_pdu
);
694 #endif /* ifndef FABRICD */
698 if (!iih
.tlvs
->protocols_supported
.count
) {
699 zlog_warn("No supported protocols TLV in %s", pdu_name
);
700 circuit
->rej_adjacencies
++;
702 isis_notif_reject_adjacency(
703 circuit
, "No supported protocols TLV", raw_pdu
);
704 #endif /* ifndef FABRICD */
708 int auth_code
= isis_tlvs_auth_is_valid(iih
.tlvs
, &circuit
->passwd
,
709 circuit
->rcv_stream
, false);
710 if (auth_code
!= ISIS_AUTH_OK
) {
711 isis_event_auth_failure(circuit
->area
->area_tag
,
712 "IIH authentication failure",
715 /* send northbound notification */
716 stream_get_from(raw_pdu
, circuit
->rcv_stream
, pdu_start
,
717 pdu_end
- pdu_start
);
718 if (auth_code
== ISIS_AUTH_FAILURE
) {
719 circuit
->auth_failures
++;
720 isis_notif_authentication_failure(circuit
, raw_pdu
);
721 } else { /* AUTH_TYPE_FAILURE or NO_VALIDATOR */
722 circuit
->auth_type_failures
++;
723 isis_notif_authentication_type_failure(circuit
,
726 #endif /* ifndef FABRICD */
730 if (!memcmp(iih
.sys_id
, circuit
->isis
->sysid
, ISIS_SYS_ID_LEN
)) {
732 "ISIS-Adj (%s): Received IIH with own sysid on %s - discard",
733 circuit
->area
->area_tag
, circuit
->interface
->name
);
734 circuit
->rej_adjacencies
++;
736 isis_notif_reject_adjacency(
737 circuit
, "Received IIH with our own sysid", raw_pdu
);
738 #endif /* ifndef FABRICD */
743 && (listcount(circuit
->area
->area_addrs
) == 0
744 || (level
== ISIS_LEVEL1
745 && !isis_tlvs_area_addresses_match(
746 iih
.tlvs
, circuit
->area
->area_addrs
)))) {
747 if (IS_DEBUG_ADJ_PACKETS
) {
749 "ISIS-Adj (%s): Area mismatch, level %d IIH on %s",
750 circuit
->area
->area_tag
, level
,
751 circuit
->interface
->name
);
754 /* send northbound notification */
755 isis_notif_area_mismatch(circuit
, raw_pdu
);
756 #endif /* ifndef FABRICD */
760 iih
.v4_usable
= (fabricd_ip_addrs(circuit
)
761 && iih
.tlvs
->ipv4_address
.count
);
763 iih
.v6_usable
= (circuit
->ipv6_link
&& listcount(circuit
->ipv6_link
)
764 && iih
.tlvs
->ipv6_address
.count
);
766 if (!iih
.v4_usable
&& !iih
.v6_usable
) {
767 if (IS_DEBUG_ADJ_PACKETS
) {
769 "ISIS-Adj (%s): Neither IPv4 nor IPv6 considered usable. Ignoring IIH",
770 circuit
->area
->area_tag
);
772 circuit
->rej_adjacencies
++;
774 isis_notif_reject_adjacency(
775 circuit
, "Neither IPv4 not IPv6 considered usable",
777 #endif /* ifndef FABRICD */
781 retval
= p2p_hello
? process_p2p_hello(&iih
) : process_lan_hello(&iih
);
783 isis_free_tlvs(iih
.tlvs
);
788 static void lsp_flood_or_update(struct isis_lsp
*lsp
,
789 struct isis_circuit
*circuit
,
793 lsp_flood(lsp
, circuit
);
795 fabricd_update_lsp_no_flood(lsp
, circuit
);
799 * Process Level 1/2 Link State
801 * Section 7.3.15.1 - Action on receipt of a link state PDU
803 static int process_lsp(uint8_t pdu_type
, struct isis_circuit
*circuit
,
804 const uint8_t *ssnpa
, uint8_t max_area_addrs
)
808 size_t pdu_start
= stream_get_getp(circuit
->rcv_stream
);
809 size_t pdu_end
= stream_get_endp(circuit
->rcv_stream
);
810 char raw_pdu
[pdu_end
- pdu_start
];
812 stream_get_from(raw_pdu
, circuit
->rcv_stream
, pdu_start
,
813 pdu_end
- pdu_start
);
815 if (pdu_type
== FS_LINK_STATE
) {
818 if (max_area_addrs
!= L2_CIRCUIT_FLOODING_SCOPE
)
821 circuit_scoped
= true;
823 /* The stream is used verbatim for sending out new LSPDUs.
824 * So make sure we store it as an L2 LSPDU internally.
825 * (compare for the reverse in `send_lsp`) */
826 stream_putc_at(circuit
->rcv_stream
, 4, L2_LINK_STATE
);
827 stream_putc_at(circuit
->rcv_stream
, 7, 0);
829 if (pdu_type
== L1_LINK_STATE
)
833 circuit_scoped
= false;
836 if (IS_DEBUG_UPDATE_PACKETS
) {
838 "ISIS-Upd (%s): Rcvd %sL%d LSP on %s, cirType %s, cirID %u",
839 circuit
->area
->area_tag
,
840 circuit_scoped
? "Circuit scoped " : "", level
,
841 circuit
->interface
->name
,
842 circuit_t2string(circuit
->is_type
),
843 circuit
->circuit_id
);
844 if (IS_DEBUG_PACKET_DUMP
)
845 zlog_dump_data(STREAM_DATA(circuit
->rcv_stream
),
846 stream_get_endp(circuit
->rcv_stream
));
849 struct isis_lsp_hdr hdr
= {};
851 hdr
.pdu_len
= stream_getw(circuit
->rcv_stream
);
852 hdr
.rem_lifetime
= stream_getw(circuit
->rcv_stream
);
853 stream_get(hdr
.lsp_id
, circuit
->rcv_stream
, sizeof(hdr
.lsp_id
));
854 hdr
.seqno
= stream_getl(circuit
->rcv_stream
);
855 hdr
.checksum
= stream_getw(circuit
->rcv_stream
);
856 hdr
.lsp_bits
= stream_getc(circuit
->rcv_stream
);
859 /* send northbound notification */
860 isis_notif_lsp_received(circuit
, rawlspid_print(hdr
.lsp_id
), hdr
.seqno
,
861 time(NULL
), sysid_print(hdr
.lsp_id
));
862 #endif /* ifndef FABRICD */
864 if (pdu_len_validate(hdr
.pdu_len
, circuit
)) {
865 zlog_debug("ISIS-Upd (%s): LSP %s invalid LSP length %hu",
866 circuit
->area
->area_tag
, rawlspid_print(hdr
.lsp_id
),
871 if (IS_DEBUG_UPDATE_PACKETS
) {
872 zlog_debug("ISIS-Upd (%s): Rcvd L%d LSP %s, seq 0x%08x, cksum 0x%04hx, lifetime %hus, len %hu, on %s",
873 circuit
->area
->area_tag
, level
,
874 rawlspid_print(hdr
.lsp_id
), hdr
.seqno
, hdr
.checksum
,
875 hdr
.rem_lifetime
, hdr
.pdu_len
,
876 circuit
->interface
->name
);
879 /* lsp is_type check */
880 if ((hdr
.lsp_bits
& IS_LEVEL_1
) != IS_LEVEL_1
) {
882 "ISIS-Upd (%s): LSP %s invalid LSP is type 0x%x",
883 circuit
->area
->area_tag
, rawlspid_print(hdr
.lsp_id
),
884 hdr
.lsp_bits
& IS_LEVEL_1_AND_2
);
885 /* continue as per RFC1122 Be liberal in what you accept, and
886 * conservative in what you send */
889 /* Checksum sanity check - FIXME: move to correct place */
890 /* 12 = sysid+pdu+remtime */
891 if (iso_csum_verify(STREAM_DATA(circuit
->rcv_stream
) + 12,
892 hdr
.pdu_len
- 12, hdr
.checksum
, 12)) {
894 "ISIS-Upd (%s): LSP %s invalid LSP checksum 0x%04hx",
895 circuit
->area
->area_tag
, rawlspid_print(hdr
.lsp_id
),
900 /* 7.3.15.1 a) 1 - external domain circuit will discard lsps */
901 if (circuit
->ext_domain
) {
903 "ISIS-Upd (%s): LSP %s received at level %d over circuit with externalDomain = true",
904 circuit
->area
->area_tag
, rawlspid_print(hdr
.lsp_id
),
909 /* 7.3.15.1 a) 2,3 - manualL2OnlyMode not implemented */
910 if (!(circuit
->is_type
& level
)) {
912 "ISIS-Upd (%s): LSP %s received at level %d over circuit of type %s",
913 circuit
->area
->area_tag
, rawlspid_print(hdr
.lsp_id
),
914 level
, circuit_t2string(circuit
->is_type
));
918 struct isis_tlvs
*tlvs
= NULL
;
919 int retval
= ISIS_WARNING
;
920 const char *error_log
;
922 if (isis_unpack_tlvs(STREAM_READABLE(circuit
->rcv_stream
),
923 circuit
->rcv_stream
, &tlvs
, &error_log
)) {
924 zlog_warn("Something went wrong unpacking the LSP: %s",
927 /* send northbound notification. Note that the tlv-type and
928 * offset cannot correctly be set here as they are not returned
929 * by isis_unpack_tlvs, but in there I cannot fire a
930 * notification because I have no circuit information. So until
931 * we change the code above to return those extra fields, we
932 * will send dummy values which are ignored in the callback
934 isis_notif_lsp_error(circuit
, rawlspid_print(hdr
.lsp_id
),
936 #endif /* ifndef FABRICD */
940 /* 7.3.15.1 a) 4 - need to make sure IDLength matches */
942 /* 7.3.15.1 a) 5 - maximum area match, can be ommited since we only use
945 /* 7.3.15.1 a) 7 - password check */
946 struct isis_passwd
*passwd
= (level
== ISIS_LEVEL1
)
947 ? &circuit
->area
->area_passwd
948 : &circuit
->area
->domain_passwd
;
949 int auth_code
= isis_tlvs_auth_is_valid(tlvs
, passwd
,
950 circuit
->rcv_stream
, true);
951 if (auth_code
!= ISIS_AUTH_OK
) {
952 isis_event_auth_failure(circuit
->area
->area_tag
,
953 "LSP authentication failure",
956 /* send northbound notification */
957 if (auth_code
== ISIS_AUTH_FAILURE
) {
958 circuit
->auth_failures
++;
959 isis_notif_authentication_failure(circuit
, raw_pdu
);
960 } else { /* AUTH_TYPE_FAILURE or NO_VALIDATOR */
961 circuit
->auth_type_failures
++;
962 isis_notif_authentication_type_failure(circuit
,
965 #endif /* ifndef FABRICD */
969 /* Find the LSP in our database and compare it to this Link State header
971 struct isis_lsp
*lsp
=
972 lsp_search(&circuit
->area
->lspdb
[level
- 1], hdr
.lsp_id
);
975 comp
= lsp_compare(circuit
->area
->area_tag
, lsp
, hdr
.seqno
,
976 hdr
.checksum
, hdr
.rem_lifetime
);
977 if (lsp
&& (lsp
->own_lsp
))
980 /* 7.3.15.1 a) 6 - Must check that we have an adjacency of the same
982 /* for broadcast circuits, snpa should be compared */
984 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
) {
985 if (!isis_adj_lookup_snpa(ssnpa
,
986 circuit
->u
.bc
.adjdb
[level
- 1])) {
987 zlog_debug("(%s): DS ======= LSP %s, seq 0x%08x, cksum 0x%04hx, lifetime %hus on %s",
988 circuit
->area
->area_tag
,
989 rawlspid_print(hdr
.lsp_id
), hdr
.seqno
,
990 hdr
.checksum
, hdr
.rem_lifetime
,
991 circuit
->interface
->name
);
992 goto out
; /* Silently discard */
995 /* for non broadcast, we just need to find same level adj */
997 /* If no adj, or no sharing of level */
998 if (!circuit
->u
.p2p
.neighbor
) {
1002 if (((level
== IS_LEVEL_1
)
1003 && (circuit
->u
.p2p
.neighbor
->adj_usage
1004 == ISIS_ADJ_LEVEL2
))
1005 || ((level
== IS_LEVEL_2
)
1006 && (circuit
->u
.p2p
.neighbor
->adj_usage
1007 == ISIS_ADJ_LEVEL1
)))
1015 /* 7.3.15.1 a) 7 - Passwords for level 1 - not implemented */
1017 /* 7.3.15.1 a) 8 - Passwords for level 2 - not implemented */
1019 /* 7.3.15.1 a) 9 - OriginatingLSPBufferSize - not implemented FIXME: do
1022 /* 7.3.16.2 - If this is an LSP from another IS with identical seq_num
1024 * wrong checksum, initiate a purge. */
1025 if (lsp
&& (lsp
->hdr
.seqno
== hdr
.seqno
)
1026 && (lsp
->hdr
.checksum
!= hdr
.checksum
)
1027 && hdr
.rem_lifetime
) {
1028 zlog_warn("ISIS-Upd (%s): LSP %s seq 0x%08x with confused checksum received.",
1029 circuit
->area
->area_tag
, rawlspid_print(hdr
.lsp_id
),
1031 hdr
.rem_lifetime
= 0;
1032 lsp_confusion
= true;
1034 lsp_confusion
= false;
1036 /* 7.3.15.1 b) - If the remaining life time is 0, we perform 7.3.16.4 */
1037 if (hdr
.rem_lifetime
== 0) {
1039 /* 7.3.16.4 a) 1) No LSP in db -> send an ack, but don't
1041 /* only needed on explicit update, eg - p2p */
1042 if (circuit
->circ_type
== CIRCUIT_T_P2P
)
1043 ack_lsp(&hdr
, circuit
, level
);
1044 goto out
; /* FIXME: do we need a purge? */
1046 if (memcmp(hdr
.lsp_id
, circuit
->isis
->sysid
,
1048 /* LSP by some other system -> do 7.3.16.4 b) */
1049 /* 7.3.16.4 b) 1) */
1050 if (comp
== LSP_NEWER
) {
1051 lsp_update(lsp
, &hdr
, tlvs
,
1052 circuit
->rcv_stream
,
1053 circuit
->area
, level
,
1056 isis_free_tlvs(tlvs
);
1059 lsp_flood_or_update(lsp
, NULL
,
1062 ISIS_FLAGS_CLEAR_ALL(
1063 lsp
->SSNflags
); /* FIXME:
1068 /* For the case of lsp confusion, flood
1069 * the purge back to its
1070 * originator so that it can react.
1071 * Otherwise, don't reflood
1072 * through incoming circuit as usual */
1073 if (!lsp_confusion
) {
1079 if (circuit
->circ_type
1080 != CIRCUIT_T_BROADCAST
)
1085 } /* 7.3.16.4 b) 2) */
1086 else if (comp
== LSP_EQUAL
) {
1088 isis_tx_queue_del(circuit
->tx_queue
,
1091 if (circuit
->circ_type
1092 != CIRCUIT_T_BROADCAST
)
1093 ISIS_SET_FLAG(lsp
->SSNflags
,
1095 } /* 7.3.16.4 b) 3) */
1097 isis_tx_queue_add(circuit
->tx_queue
,
1098 lsp
, TX_LSP_NORMAL
);
1099 ISIS_CLEAR_FLAG(lsp
->SSNflags
, circuit
);
1101 } else if (lsp
->hdr
.rem_lifetime
!= 0) {
1102 /* our own LSP -> 7.3.16.4 c) */
1103 if (comp
== LSP_NEWER
) {
1105 if (lsp
->hdr
.seqno
< hdr
.seqno
) {
1108 isis_notif_seqno_skipped(
1113 #endif /* ifndef FABRICD */
1114 lsp_inc_seqno(lsp
, hdr
.seqno
);
1115 lsp_flood_or_update(lsp
, NULL
,
1118 isis_tx_queue_add(circuit
->tx_queue
,
1119 lsp
, TX_LSP_NORMAL
);
1120 ISIS_CLEAR_FLAG(lsp
->SSNflags
, circuit
);
1122 if (IS_DEBUG_UPDATE_PACKETS
)
1124 "ISIS-Upd (%s): (1) re-originating LSP %s new seq 0x%08x",
1125 circuit
->area
->area_tag
,
1126 rawlspid_print(hdr
.lsp_id
),
1129 /* our own LSP with 0 remaining life time */
1131 /* send northbound notification */
1132 isis_notif_own_lsp_purge(
1133 circuit
, rawlspid_print(hdr
.lsp_id
));
1134 #endif /* ifndef FABRICD */
1139 /* 7.3.15.1 c) - If this is our own lsp and we don't have it initiate a
1141 if (memcmp(hdr
.lsp_id
, circuit
->isis
->sysid
, ISIS_SYS_ID_LEN
) == 0) {
1143 /* 7.3.16.4: initiate a purge */
1144 lsp_purge_non_exist(level
, &hdr
, circuit
->area
);
1148 /* 7.3.15.1 d) - If this is our own lsp and we have it */
1150 /* In 7.3.16.1, If an Intermediate system R somewhere in the
1152 * has information that the current sequence number for source S
1154 * "greater" than that held by S, ... */
1156 if (comp
== LSP_NEWER
) {
1158 lsp_inc_seqno(lsp
, hdr
.seqno
);
1160 /* send northbound notification */
1161 isis_notif_seqno_skipped(circuit
,
1162 rawlspid_print(hdr
.lsp_id
));
1163 #endif /* ifndef FABRICD */
1164 if (IS_DEBUG_UPDATE_PACKETS
) {
1166 "ISIS-Upd (%s): (2) re-originating LSP %s new seq 0x%08x",
1167 circuit
->area
->area_tag
,
1168 rawlspid_print(hdr
.lsp_id
),
1171 lsp_flood(lsp
, NULL
);
1172 } else if (comp
== LSP_EQUAL
) {
1173 isis_tx_queue_del(circuit
->tx_queue
, lsp
);
1174 if (circuit
->circ_type
!= CIRCUIT_T_BROADCAST
)
1175 ISIS_SET_FLAG(lsp
->SSNflags
, circuit
);
1177 isis_tx_queue_add(circuit
->tx_queue
, lsp
,
1179 ISIS_CLEAR_FLAG(lsp
->SSNflags
, circuit
);
1182 /* 7.3.15.1 e) - This lsp originated on another system */
1184 /* 7.3.15.1 e) 1) LSP newer than the one in db or no LSP in db
1186 if ((!lsp
|| comp
== LSP_NEWER
)) {
1188 * If this lsp is a frag, need to see if we have zero
1191 struct isis_lsp
*lsp0
= NULL
;
1192 if (LSP_FRAGMENT(hdr
.lsp_id
) != 0) {
1193 uint8_t lspid
[ISIS_SYS_ID_LEN
+ 2];
1194 memcpy(lspid
, hdr
.lsp_id
, ISIS_SYS_ID_LEN
+ 1);
1195 LSP_FRAGMENT(lspid
) = 0;
1197 &circuit
->area
->lspdb
[level
- 1], lspid
);
1200 "Got lsp frag, while zero lsp not in database");
1206 lsp
= lsp_new_from_recv(
1207 &hdr
, tlvs
, circuit
->rcv_stream
, lsp0
,
1208 circuit
->area
, level
);
1210 lsp_insert(&circuit
->area
->lspdb
[level
- 1],
1212 } else /* exists, so we overwrite */
1214 lsp_update(lsp
, &hdr
, tlvs
, circuit
->rcv_stream
,
1215 circuit
->area
, level
, false);
1218 lsp_flood_or_update(lsp
, circuit
, circuit_scoped
);
1221 if (circuit
->circ_type
!= CIRCUIT_T_BROADCAST
)
1222 ISIS_SET_FLAG(lsp
->SSNflags
, circuit
);
1225 /* 7.3.15.1 e) 2) LSP equal to the one in db */
1226 else if (comp
== LSP_EQUAL
) {
1227 isis_tx_queue_del(circuit
->tx_queue
, lsp
);
1228 lsp_update(lsp
, &hdr
, tlvs
, circuit
->rcv_stream
,
1229 circuit
->area
, level
, false);
1231 if (circuit
->circ_type
!= CIRCUIT_T_BROADCAST
)
1232 ISIS_SET_FLAG(lsp
->SSNflags
, circuit
);
1234 /* 7.3.15.1 e) 3) LSP older than the one in db */
1236 isis_tx_queue_add(circuit
->tx_queue
, lsp
,
1238 ISIS_CLEAR_FLAG(lsp
->SSNflags
, circuit
);
1245 fabricd_trigger_csnp(circuit
->area
, circuit_scoped
);
1247 isis_free_tlvs(tlvs
);
1252 * Process Sequence Numbers
1254 * Section 7.3.15.2 - Action on receipt of a sequence numbers PDU
1257 static int process_snp(uint8_t pdu_type
, struct isis_circuit
*circuit
,
1258 const uint8_t *ssnpa
)
1261 size_t pdu_start
= stream_get_getp(circuit
->rcv_stream
);
1262 size_t pdu_end
= stream_get_endp(circuit
->rcv_stream
);
1263 char raw_pdu
[pdu_end
- pdu_start
];
1264 #endif /* ifndef FABRICD */
1266 bool is_csnp
= (pdu_type
== L1_COMPLETE_SEQ_NUM
1267 || pdu_type
== L2_COMPLETE_SEQ_NUM
);
1268 char typechar
= is_csnp
? 'C' : 'P';
1269 int level
= (pdu_type
== L1_COMPLETE_SEQ_NUM
1270 || pdu_type
== L1_PARTIAL_SEQ_NUM
)
1274 uint16_t pdu_len
= stream_getw(circuit
->rcv_stream
);
1275 uint8_t rem_sys_id
[ISIS_SYS_ID_LEN
];
1277 stream_get(rem_sys_id
, circuit
->rcv_stream
, ISIS_SYS_ID_LEN
);
1278 stream_forward_getp(circuit
->rcv_stream
, 1); /* Circuit ID - unused */
1280 uint8_t start_lsp_id
[ISIS_SYS_ID_LEN
+ 2] = {};
1281 uint8_t stop_lsp_id
[ISIS_SYS_ID_LEN
+ 2] = {};
1284 stream_get(start_lsp_id
, circuit
->rcv_stream
,
1285 ISIS_SYS_ID_LEN
+ 2);
1286 stream_get(stop_lsp_id
, circuit
->rcv_stream
,
1287 ISIS_SYS_ID_LEN
+ 2);
1290 if (pdu_len_validate(pdu_len
, circuit
)) {
1291 zlog_warn("Received a CSNP with bogus length %d", pdu_len
);
1292 return ISIS_WARNING
;
1295 if (IS_DEBUG_SNP_PACKETS
) {
1297 "ISIS-Snp (%s): Rcvd L%d %cSNP on %s, cirType %s, cirID %u",
1298 circuit
->area
->area_tag
, level
, typechar
,
1299 circuit
->interface
->name
,
1300 circuit_t2string(circuit
->is_type
),
1301 circuit
->circuit_id
);
1302 if (IS_DEBUG_PACKET_DUMP
)
1303 zlog_dump_data(STREAM_DATA(circuit
->rcv_stream
),
1304 stream_get_endp(circuit
->rcv_stream
));
1307 /* 7.3.15.2 a) 1 - external domain circuit will discard snp pdu */
1308 if (circuit
->ext_domain
) {
1311 "ISIS-Snp (%s): Rcvd L%d %cSNP on %s, skipping: circuit externalDomain = true",
1312 circuit
->area
->area_tag
, level
, typechar
,
1313 circuit
->interface
->name
);
1318 /* 7.3.15.2 a) 2,3 - manualL2OnlyMode not implemented */
1319 if (!(circuit
->is_type
& level
)) {
1321 "ISIS-Snp (%s): Rcvd L%d %cSNP on %s, skipping: circuit type %s does not match level %d",
1322 circuit
->area
->area_tag
, level
, typechar
,
1323 circuit
->interface
->name
,
1324 circuit_t2string(circuit
->is_type
), level
);
1329 /* 7.3.15.2 a) 4 - not applicable for CSNP only PSNPs on broadcast */
1330 if (!is_csnp
&& (circuit
->circ_type
== CIRCUIT_T_BROADCAST
)
1331 && !circuit
->u
.bc
.is_dr
[level
- 1]) {
1333 "ISIS-Snp (%s): Rcvd L%d %cSNP from %s on %s, skipping: we are not the DIS",
1334 circuit
->area
->area_tag
, level
, typechar
,
1335 snpa_print(ssnpa
), circuit
->interface
->name
);
1340 /* 7.3.15.2 a) 5 - need to make sure IDLength matches - already checked
1343 /* 7.3.15.2 a) 6 - maximum area match, can be ommited since we only use
1345 * - already checked */
1347 /* 7.3.15.2 a) 7 - Must check that we have an adjacency of the same
1349 /* for broadcast circuits, snpa should be compared */
1350 /* FIXME : Do we need to check SNPA? */
1351 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
) {
1352 if (!isis_adj_lookup(rem_sys_id
,
1353 circuit
->u
.bc
.adjdb
[level
- 1]))
1354 return ISIS_OK
; /* Silently discard */
1356 if (!fabricd
&& !circuit
->u
.p2p
.neighbor
) {
1357 zlog_warn("no p2p neighbor on circuit %s",
1358 circuit
->interface
->name
);
1359 return ISIS_OK
; /* Silently discard */
1363 struct isis_tlvs
*tlvs
;
1364 int retval
= ISIS_WARNING
;
1365 const char *error_log
;
1367 if (isis_unpack_tlvs(STREAM_READABLE(circuit
->rcv_stream
),
1368 circuit
->rcv_stream
, &tlvs
, &error_log
)) {
1369 zlog_warn("Something went wrong unpacking the SNP: %s",
1374 struct isis_passwd
*passwd
= (level
== IS_LEVEL_1
)
1375 ? &circuit
->area
->area_passwd
1376 : &circuit
->area
->domain_passwd
;
1378 if (CHECK_FLAG(passwd
->snp_auth
, SNP_AUTH_RECV
)) {
1379 int auth_code
= isis_tlvs_auth_is_valid(
1380 tlvs
, passwd
, circuit
->rcv_stream
, false);
1381 if (auth_code
!= ISIS_AUTH_OK
) {
1382 isis_event_auth_failure(circuit
->area
->area_tag
,
1383 "SNP authentication failure",
1386 /* send northbound notification */
1387 stream_get_from(raw_pdu
, circuit
->rcv_stream
, pdu_start
,
1388 pdu_end
- pdu_start
);
1389 if (auth_code
== ISIS_AUTH_FAILURE
) {
1390 circuit
->auth_failures
++;
1391 isis_notif_authentication_failure(circuit
,
1393 } else { /* AUTH_TYPE_FAILURE or NO_VALIDATOR */
1394 circuit
->auth_type_failures
++;
1395 isis_notif_authentication_type_failure(circuit
,
1398 #endif /* ifndef FABRICD */
1403 struct isis_lsp_entry
*entry_head
=
1404 (struct isis_lsp_entry
*)tlvs
->lsp_entries
.head
;
1406 /* debug isis snp-packets */
1407 if (IS_DEBUG_SNP_PACKETS
) {
1408 zlog_debug("ISIS-Snp (%s): Rcvd L%d %cSNP from %s on %s",
1409 circuit
->area
->area_tag
, level
, typechar
,
1410 snpa_print(ssnpa
), circuit
->interface
->name
);
1411 for (struct isis_lsp_entry
*entry
= entry_head
; entry
;
1412 entry
= entry
->next
) {
1414 "ISIS-Snp (%s): %cSNP entry %s, seq 0x%08x, cksum 0x%04hx, lifetime %hus",
1415 circuit
->area
->area_tag
, typechar
,
1416 rawlspid_print(entry
->id
), entry
->seqno
,
1417 entry
->checksum
, entry
->rem_lifetime
);
1421 bool resync_needed
= false;
1423 /* 7.3.15.2 b) Actions on LSP_ENTRIES reported */
1424 for (struct isis_lsp_entry
*entry
= entry_head
; entry
;
1425 entry
= entry
->next
) {
1426 struct isis_lsp
*lsp
=
1427 lsp_search(&circuit
->area
->lspdb
[level
- 1], entry
->id
);
1428 bool own_lsp
= !memcmp(entry
->id
, circuit
->isis
->sysid
,
1431 /* 7.3.15.2 b) 1) is this LSP newer */
1432 int cmp
= lsp_compare(circuit
->area
->area_tag
, lsp
,
1433 entry
->seqno
, entry
->checksum
,
1434 entry
->rem_lifetime
);
1435 /* 7.3.15.2 b) 2) if it equals, clear SRM on p2p */
1436 if (cmp
== LSP_EQUAL
) {
1437 /* if (circuit->circ_type !=
1438 * CIRCUIT_T_BROADCAST) */
1439 isis_tx_queue_del(circuit
->tx_queue
, lsp
);
1441 /* 7.3.15.2 b) 3) if it is older, clear SSN and set SRM
1443 else if (cmp
== LSP_OLDER
) {
1444 ISIS_CLEAR_FLAG(lsp
->SSNflags
, circuit
);
1445 isis_tx_queue_add(circuit
->tx_queue
, lsp
,
1448 /* 7.3.15.2 b) 4) if it is newer, set SSN and clear SRM
1452 lsp_inc_seqno(lsp
, entry
->seqno
);
1453 isis_tx_queue_add(circuit
->tx_queue
, lsp
,
1456 ISIS_SET_FLAG(lsp
->SSNflags
, circuit
);
1457 /* if (circuit->circ_type !=
1458 * CIRCUIT_T_BROADCAST) */
1459 isis_tx_queue_del(circuit
->tx_queue
, lsp
);
1460 resync_needed
= true;
1464 /* 7.3.15.2 b) 5) if it was not found, and all of those
1466 * insert it and set SSN on it */
1467 if (entry
->rem_lifetime
&& entry
->checksum
1469 && memcmp(entry
->id
, circuit
->isis
->sysid
,
1471 struct isis_lsp
*lsp0
= NULL
;
1473 if (LSP_FRAGMENT(entry
->id
)) {
1474 uint8_t lspid
[ISIS_SYS_ID_LEN
+ 2];
1476 memcpy(lspid
, entry
->id
,
1477 ISIS_SYS_ID_LEN
+ 1);
1478 LSP_FRAGMENT(lspid
) = 0;
1480 &circuit
->area
->lspdb
[level
- 1],
1483 zlog_debug("Got lsp frag in snp, while zero not in database");
1487 lsp
= lsp_new(circuit
->area
, entry
->id
,
1488 entry
->rem_lifetime
, 0, 0,
1489 entry
->checksum
, lsp0
, level
);
1490 lsp_insert(&circuit
->area
->lspdb
[level
- 1],
1493 lsp_set_all_srmflags(lsp
, false);
1494 ISIS_SET_FLAG(lsp
->SSNflags
, circuit
);
1495 resync_needed
= true;
1500 /* 7.3.15.2 c) on CSNP set SRM for all in range which were not reported
1504 * Build a list from our own LSP db bounded with
1505 * start_lsp_id and stop_lsp_id
1507 struct list
*lsp_list
= list_new();
1508 lsp_build_list_nonzero_ht(&circuit
->area
->lspdb
[level
- 1],
1509 start_lsp_id
, stop_lsp_id
, lsp_list
);
1511 /* Fixme: Find a better solution */
1512 struct listnode
*node
, *nnode
;
1513 struct isis_lsp
*lsp
;
1514 for (struct isis_lsp_entry
*entry
= entry_head
; entry
;
1515 entry
= entry
->next
) {
1516 for (ALL_LIST_ELEMENTS(lsp_list
, node
, nnode
, lsp
)) {
1517 if (lsp_id_cmp(lsp
->hdr
.lsp_id
, entry
->id
)
1519 list_delete_node(lsp_list
, node
);
1525 /* on remaining LSPs we set SRM (neighbor knew not of) */
1526 for (ALL_LIST_ELEMENTS_RO(lsp_list
, node
, lsp
)) {
1527 isis_tx_queue_add(circuit
->tx_queue
, lsp
, TX_LSP_NORMAL
);
1528 resync_needed
= true;
1532 list_delete(&lsp_list
);
1535 if (fabricd_initial_sync_is_complete(circuit
->area
) && resync_needed
)
1536 zlog_warn("OpenFabric: Needed to resync LSPDB using CSNP!");
1540 isis_free_tlvs(tlvs
);
1544 static int pdu_size(uint8_t pdu_type
, uint8_t *size
)
1549 *size
= ISIS_LANHELLO_HDRLEN
;
1552 *size
= ISIS_P2PHELLO_HDRLEN
;
1557 *size
= ISIS_LSP_HDR_LEN
;
1559 case L1_COMPLETE_SEQ_NUM
:
1560 case L2_COMPLETE_SEQ_NUM
:
1561 *size
= ISIS_CSNP_HDRLEN
;
1563 case L1_PARTIAL_SEQ_NUM
:
1564 case L2_PARTIAL_SEQ_NUM
:
1565 *size
= ISIS_PSNP_HDRLEN
;
1570 *size
+= ISIS_FIXED_HDR_LEN
;
1578 int isis_handle_pdu(struct isis_circuit
*circuit
, uint8_t *ssnpa
)
1580 int retval
= ISIS_OK
;
1581 size_t pdu_start
= stream_get_getp(circuit
->rcv_stream
);
1582 size_t pdu_end
= stream_get_endp(circuit
->rcv_stream
);
1583 char raw_pdu
[pdu_end
- pdu_start
];
1585 stream_get_from(raw_pdu
, circuit
->rcv_stream
, pdu_start
,
1586 pdu_end
- pdu_start
);
1588 /* Verify that at least the 8 bytes fixed header have been received */
1589 if (stream_get_endp(circuit
->rcv_stream
) < ISIS_FIXED_HDR_LEN
) {
1590 flog_err(EC_ISIS_PACKET
, "PDU is too short to be IS-IS.");
1594 uint8_t idrp
= stream_getc(circuit
->rcv_stream
);
1595 uint8_t length
= stream_getc(circuit
->rcv_stream
);
1596 uint8_t version1
= stream_getc(circuit
->rcv_stream
);
1597 uint8_t id_len
= stream_getc(circuit
->rcv_stream
);
1598 uint8_t pdu_type
= stream_getc(circuit
->rcv_stream
)
1599 & 0x1f; /* bits 6-8 are reserved */
1600 uint8_t version2
= stream_getc(circuit
->rcv_stream
);
1602 stream_forward_getp(circuit
->rcv_stream
, 1); /* reserved */
1603 uint8_t max_area_addrs
= stream_getc(circuit
->rcv_stream
);
1605 pdu_counter_count(circuit
->area
->pdu_rx_counters
, pdu_type
);
1607 if (idrp
== ISO9542_ESIS
) {
1608 flog_err(EC_LIB_DEVELOPMENT
,
1609 "No support for ES-IS packet IDRP=%hhx", idrp
);
1613 if (idrp
!= ISO10589_ISIS
) {
1614 flog_err(EC_ISIS_PACKET
, "Not an IS-IS packet IDRP=%hhx",
1619 if (version1
!= 1) {
1620 zlog_warn("Unsupported ISIS version %hhu", version1
);
1622 /* send northbound notification */
1623 isis_notif_version_skew(circuit
, version1
, raw_pdu
);
1624 #endif /* ifndef FABRICD */
1625 return ISIS_WARNING
;
1628 if (id_len
!= 0 && id_len
!= ISIS_SYS_ID_LEN
) {
1631 "IDFieldLengthMismatch: ID Length field in a received PDU %hhu, while the parameter for this IS is %u",
1632 id_len
, ISIS_SYS_ID_LEN
);
1633 circuit
->id_len_mismatches
++;
1635 /* send northbound notification */
1636 isis_notif_id_len_mismatch(circuit
, id_len
, raw_pdu
);
1637 #endif /* ifndef FABRICD */
1641 uint8_t expected_length
;
1642 if (pdu_size(pdu_type
, &expected_length
)) {
1643 zlog_warn("Unsupported ISIS PDU %hhu", pdu_type
);
1644 return ISIS_WARNING
;
1647 if (length
!= expected_length
) {
1648 flog_err(EC_ISIS_PACKET
,
1649 "Expected fixed header length = %hhu but got %hhu",
1650 expected_length
, length
);
1654 if (stream_get_endp(circuit
->rcv_stream
) < length
) {
1657 "PDU is too short to contain fixed header of given PDU type.");
1661 if (version2
!= 1) {
1662 zlog_warn("Unsupported ISIS PDU version %hhu", version2
);
1664 /* send northbound notification */
1665 isis_notif_version_skew(circuit
, version2
, raw_pdu
);
1666 #endif /* ifndef FABRICD */
1667 return ISIS_WARNING
;
1670 if (circuit
->is_passive
) {
1671 zlog_warn("Received ISIS PDU on passive circuit %s",
1672 circuit
->interface
->name
);
1673 return ISIS_WARNING
;
1677 if (pdu_type
!= FS_LINK_STATE
/* FS PDU doesn't contain max area addr
1679 && max_area_addrs
!= 0
1680 && max_area_addrs
!= circuit
->isis
->max_area_addrs
) {
1683 "maximumAreaAddressesMismatch: maximumAreaAdresses in a received PDU %hhu while the parameter for this IS is %u",
1684 max_area_addrs
, circuit
->isis
->max_area_addrs
);
1685 circuit
->max_area_addr_mismatches
++;
1687 /* send northbound notification */
1688 isis_notif_max_area_addr_mismatch(circuit
, max_area_addrs
,
1690 #endif /* ifndef FABRICD */
1698 if (fabricd
&& pdu_type
!= P2P_HELLO
)
1700 retval
= process_hello(pdu_type
, circuit
, ssnpa
);
1706 && pdu_type
!= L2_LINK_STATE
1707 && pdu_type
!= FS_LINK_STATE
)
1709 retval
= process_lsp(pdu_type
, circuit
, ssnpa
, max_area_addrs
);
1711 case L1_COMPLETE_SEQ_NUM
:
1712 case L2_COMPLETE_SEQ_NUM
:
1713 case L1_PARTIAL_SEQ_NUM
:
1714 case L2_PARTIAL_SEQ_NUM
:
1715 retval
= process_snp(pdu_type
, circuit
, ssnpa
);
1724 int isis_receive(struct thread
*thread
)
1726 struct isis_circuit
*circuit
;
1727 uint8_t ssnpa
[ETH_ALEN
];
1733 circuit
= THREAD_ARG(thread
);
1736 circuit
->t_read
= NULL
;
1738 isis_circuit_stream(circuit
, &circuit
->rcv_stream
);
1740 retval
= circuit
->rx(circuit
, ssnpa
);
1742 #if ISIS_METHOD != ISIS_METHOD_BPF
1743 if (retval
== ISIS_OK
)
1744 retval
= isis_handle_pdu(circuit
, ssnpa
);
1745 #endif //ISIS_METHOD != ISIS_METHOD_BPF
1748 * prepare for next packet.
1750 if (!circuit
->is_passive
)
1751 isis_circuit_prepare(circuit
);
1759 void fill_fixed_hdr(uint8_t pdu_type
, struct stream
*stream
)
1763 if (pdu_size(pdu_type
, &length
))
1764 assert(!"Unknown PDU Type");
1766 stream_putc(stream
, ISO10589_ISIS
); /* IDRP */
1767 stream_putc(stream
, length
); /* Length of fixed header */
1768 stream_putc(stream
, 1); /* Version/Protocol ID Extension 1 */
1769 stream_putc(stream
, 0); /* ID Length, 0 => 6 */
1770 stream_putc(stream
, pdu_type
);
1771 stream_putc(stream
, 1); /* Subversion */
1772 stream_putc(stream
, 0); /* Reserved */
1773 stream_putc(stream
, 0); /* Max Area Addresses 0 => 3 */
1776 static uint8_t hello_pdu_type(struct isis_circuit
*circuit
, int level
)
1778 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
)
1779 return (level
== IS_LEVEL_1
) ? L1_LAN_HELLO
: L2_LAN_HELLO
;
1784 static void put_hello_hdr(struct isis_circuit
*circuit
, int level
,
1785 size_t *len_pointer
)
1787 uint8_t pdu_type
= hello_pdu_type(circuit
, level
);
1789 isis_circuit_stream(circuit
, &circuit
->snd_stream
);
1790 fill_fixed_hdr(pdu_type
, circuit
->snd_stream
);
1792 stream_putc(circuit
->snd_stream
, circuit
->is_type
);
1793 stream_put(circuit
->snd_stream
, circuit
->isis
->sysid
, ISIS_SYS_ID_LEN
);
1795 uint32_t holdtime
= circuit
->hello_multiplier
[level
- 1]
1796 * circuit
->hello_interval
[level
- 1];
1798 if (holdtime
> 0xffff)
1801 stream_putw(circuit
->snd_stream
, holdtime
);
1802 *len_pointer
= stream_get_endp(circuit
->snd_stream
);
1803 stream_putw(circuit
->snd_stream
, 0); /* length is filled in later */
1805 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
) {
1806 uint8_t *desig_is
= (level
== IS_LEVEL_1
)
1807 ? circuit
->u
.bc
.l1_desig_is
1808 : circuit
->u
.bc
.l2_desig_is
;
1809 stream_putc(circuit
->snd_stream
, circuit
->priority
[level
- 1]);
1810 stream_put(circuit
->snd_stream
, desig_is
, ISIS_SYS_ID_LEN
+ 1);
1812 stream_putc(circuit
->snd_stream
, circuit
->circuit_id
);
1816 int send_hello(struct isis_circuit
*circuit
, int level
)
1821 if (circuit
->is_passive
)
1824 if (circuit
->interface
->mtu
== 0) {
1825 zlog_warn("circuit has zero MTU");
1826 return ISIS_WARNING
;
1829 put_hello_hdr(circuit
, level
, &len_pointer
);
1831 struct isis_tlvs
*tlvs
= isis_alloc_tlvs();
1833 isis_tlvs_add_auth(tlvs
, &circuit
->passwd
);
1835 if (!listcount(circuit
->area
->area_addrs
)) {
1836 isis_free_tlvs(tlvs
);
1837 return ISIS_WARNING
;
1840 isis_tlvs_add_area_addresses(tlvs
, circuit
->area
->area_addrs
);
1842 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
) {
1843 isis_tlvs_add_lan_neighbors(
1844 tlvs
, circuit
->u
.bc
.lan_neighs
[level
- 1]);
1845 } else if (circuit
->circ_type
== CIRCUIT_T_P2P
1846 && !circuit
->disable_threeway_adj
) {
1847 uint32_t ext_circuit_id
= circuit
->idx
;
1848 if (circuit
->u
.p2p
.neighbor
) {
1849 uint8_t threeway_state
;
1851 if (fabricd_initial_sync_is_in_progress(circuit
->area
)
1852 && fabricd_initial_sync_circuit(circuit
->area
) != circuit
)
1853 threeway_state
= ISIS_THREEWAY_DOWN
;
1855 threeway_state
= circuit
->u
.p2p
.neighbor
->threeway_state
;
1856 isis_tlvs_add_threeway_adj(tlvs
,
1859 circuit
->u
.p2p
.neighbor
->sysid
,
1860 circuit
->u
.p2p
.neighbor
->ext_circuit_id
);
1862 isis_tlvs_add_threeway_adj(tlvs
,
1869 isis_tlvs_set_protocols_supported(tlvs
, &circuit
->nlpids
);
1874 * TLV gets included if no topology is enabled on the interface,
1875 * if one topology other than #0 is enabled, or if multiple topologies
1878 struct isis_circuit_mt_setting
**mt_settings
;
1879 unsigned int mt_count
;
1881 mt_settings
= circuit_mt_settings(circuit
, &mt_count
);
1882 if (mt_count
== 0 && area_is_mt(circuit
->area
)) {
1883 tlvs
->mt_router_info_empty
= true;
1884 } else if ((mt_count
== 1
1885 && mt_settings
[0]->mtid
!= ISIS_MT_IPV4_UNICAST
)
1886 || (mt_count
> 1)) {
1887 for (unsigned int i
= 0; i
< mt_count
; i
++)
1888 isis_tlvs_add_mt_router_info(tlvs
, mt_settings
[i
]->mtid
,
1892 if (circuit
->ip_router
) {
1893 struct list
*circuit_ip_addrs
= fabricd_ip_addrs(circuit
);
1895 if (circuit_ip_addrs
)
1896 isis_tlvs_add_ipv4_addresses(tlvs
, circuit_ip_addrs
);
1899 if (circuit
->ipv6_router
&& circuit
->ipv6_link
)
1900 isis_tlvs_add_ipv6_addresses(tlvs
, circuit
->ipv6_link
);
1902 if (isis_pack_tlvs(tlvs
, circuit
->snd_stream
, len_pointer
,
1903 circuit
->pad_hellos
, false)) {
1904 isis_free_tlvs(tlvs
);
1905 return ISIS_WARNING
; /* XXX: Maybe Log TLV structure? */
1908 if (IS_DEBUG_ADJ_PACKETS
) {
1909 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
) {
1911 "ISIS-Adj (%s): Sending L%d LAN IIH on %s, length %zd",
1912 circuit
->area
->area_tag
, level
,
1913 circuit
->interface
->name
,
1914 stream_get_endp(circuit
->snd_stream
));
1917 "ISIS-Adj (%s): Sending P2P IIH on %s, length %zd",
1918 circuit
->area
->area_tag
,
1919 circuit
->interface
->name
,
1920 stream_get_endp(circuit
->snd_stream
));
1922 if (IS_DEBUG_PACKET_DUMP
)
1923 zlog_dump_data(STREAM_DATA(circuit
->snd_stream
),
1924 stream_get_endp(circuit
->snd_stream
));
1927 isis_free_tlvs(tlvs
);
1929 pdu_counter_count(circuit
->area
->pdu_tx_counters
,
1930 hello_pdu_type(circuit
, level
));
1931 retval
= circuit
->tx(circuit
, level
);
1932 if (retval
!= ISIS_OK
)
1933 flog_err(EC_ISIS_PACKET
,
1934 "ISIS-Adj (%s): Send L%d IIH on %s failed",
1935 circuit
->area
->area_tag
, level
,
1936 circuit
->interface
->name
);
1941 static int send_hello_cb(struct thread
*thread
)
1943 struct isis_circuit_arg
*arg
= THREAD_ARG(thread
);
1946 struct isis_circuit
*circuit
= arg
->circuit
;
1947 int level
= arg
->level
;
1951 if (circuit
->circ_type
== CIRCUIT_T_P2P
) {
1952 circuit
->u
.p2p
.t_send_p2p_hello
= NULL
;
1953 send_hello(circuit
, 1);
1954 send_hello_sched(circuit
, ISIS_LEVEL1
,
1955 1000 * circuit
->hello_interval
[1]);
1959 if (circuit
->circ_type
!= CIRCUIT_T_BROADCAST
) {
1960 zlog_warn("ISIS-Hello (%s): Trying to send hello on unknown circuit type %d",
1961 circuit
->area
->area_tag
, circuit
->circ_type
);
1962 return ISIS_WARNING
;
1965 circuit
->u
.bc
.t_send_lan_hello
[level
- 1] = NULL
;
1966 if (!(circuit
->is_type
& level
)) {
1967 zlog_warn("ISIS-Hello (%s): Trying to send L%d IIH in L%d-only circuit",
1968 circuit
->area
->area_tag
, level
, 3 - level
);
1969 return ISIS_WARNING
;
1972 if (circuit
->u
.bc
.run_dr_elect
[level
- 1])
1973 isis_dr_elect(circuit
, level
);
1975 int rv
= send_hello(circuit
, level
);
1977 /* set next timer thread */
1978 send_hello_sched(circuit
, level
, 1000 * circuit
->hello_interval
[level
- 1]);
1982 static void _send_hello_sched(struct isis_circuit
*circuit
,
1983 struct thread
**threadp
,
1984 int level
, long delay
)
1987 if (thread_timer_remain_msec(*threadp
) < (unsigned long)delay
)
1990 thread_cancel(threadp
);
1993 thread_add_timer_msec(master
, send_hello_cb
,
1994 &circuit
->level_arg
[level
- 1],
1995 isis_jitter(delay
, IIH_JITTER
),
1999 void send_hello_sched(struct isis_circuit
*circuit
, int level
, long delay
)
2001 if (circuit
->circ_type
== CIRCUIT_T_P2P
) {
2002 _send_hello_sched(circuit
, &circuit
->u
.p2p
.t_send_p2p_hello
,
2003 ISIS_LEVEL1
, delay
);
2007 if (circuit
->circ_type
!= CIRCUIT_T_BROADCAST
) {
2008 zlog_warn("%s: encountered unknown circuit type %d on %s",
2009 __func__
, circuit
->circ_type
,
2010 circuit
->interface
->name
);
2014 for (int loop_level
= ISIS_LEVEL1
; loop_level
<= ISIS_LEVEL2
; loop_level
++) {
2015 if (!(loop_level
& level
))
2020 &circuit
->u
.bc
.t_send_lan_hello
[loop_level
- 1],
2029 * Count the maximum number of lsps that can be accomodated by a given size.
2031 #define LSP_ENTRIES_LEN (10 + ISIS_SYS_ID_LEN)
2032 static uint16_t get_max_lsp_count(uint16_t size
)
2036 uint16_t remaining_size
;
2038 /* First count the full size TLVs */
2039 tlv_count
= size
/ MAX_LSP_ENTRIES_TLV_SIZE
;
2040 lsp_count
= tlv_count
* (MAX_LSP_ENTRIES_TLV_SIZE
/ LSP_ENTRIES_LEN
);
2042 /* The last TLV, if any */
2043 remaining_size
= size
% MAX_LSP_ENTRIES_TLV_SIZE
;
2044 if (remaining_size
- 2 >= LSP_ENTRIES_LEN
)
2045 lsp_count
+= (remaining_size
- 2) / LSP_ENTRIES_LEN
;
2050 int send_csnp(struct isis_circuit
*circuit
, int level
)
2052 if (lspdb_count(&circuit
->area
->lspdb
[level
- 1]) == 0)
2055 uint8_t pdu_type
= (level
== ISIS_LEVEL1
) ? L1_COMPLETE_SEQ_NUM
2056 : L2_COMPLETE_SEQ_NUM
;
2058 isis_circuit_stream(circuit
, &circuit
->snd_stream
);
2059 fill_fixed_hdr(pdu_type
, circuit
->snd_stream
);
2061 size_t len_pointer
= stream_get_endp(circuit
->snd_stream
);
2063 stream_putw(circuit
->snd_stream
, 0);
2064 stream_put(circuit
->snd_stream
, circuit
->isis
->sysid
, ISIS_SYS_ID_LEN
);
2065 /* with zero circuit id - ref 9.10, 9.11 */
2066 stream_putc(circuit
->snd_stream
, 0);
2068 size_t start_pointer
= stream_get_endp(circuit
->snd_stream
);
2069 stream_put(circuit
->snd_stream
, 0, ISIS_SYS_ID_LEN
+ 2);
2070 size_t end_pointer
= stream_get_endp(circuit
->snd_stream
);
2071 stream_put(circuit
->snd_stream
, 0, ISIS_SYS_ID_LEN
+ 2);
2073 struct isis_passwd
*passwd
= (level
== ISIS_LEVEL1
)
2074 ? &circuit
->area
->area_passwd
2075 : &circuit
->area
->domain_passwd
;
2077 struct isis_tlvs
*tlvs
= isis_alloc_tlvs();
2079 if (CHECK_FLAG(passwd
->snp_auth
, SNP_AUTH_SEND
))
2080 isis_tlvs_add_auth(tlvs
, passwd
);
2082 size_t tlv_start
= stream_get_endp(circuit
->snd_stream
);
2083 if (isis_pack_tlvs(tlvs
, circuit
->snd_stream
, len_pointer
, false,
2085 isis_free_tlvs(tlvs
);
2086 return ISIS_WARNING
;
2088 isis_free_tlvs(tlvs
);
2091 get_max_lsp_count(STREAM_WRITEABLE(circuit
->snd_stream
));
2093 uint8_t start
[ISIS_SYS_ID_LEN
+ 2];
2094 memset(start
, 0x00, ISIS_SYS_ID_LEN
+ 2);
2095 uint8_t stop
[ISIS_SYS_ID_LEN
+ 2];
2096 memset(stop
, 0xff, ISIS_SYS_ID_LEN
+ 2);
2100 tlvs
= isis_alloc_tlvs();
2101 if (CHECK_FLAG(passwd
->snp_auth
, SNP_AUTH_SEND
))
2102 isis_tlvs_add_auth(tlvs
, passwd
);
2104 struct isis_lsp
*last_lsp
;
2105 isis_tlvs_add_csnp_entries(tlvs
, start
, stop
, num_lsps
,
2106 &circuit
->area
->lspdb
[level
- 1],
2109 * Update the stop lsp_id before encoding this CSNP.
2111 if (tlvs
->lsp_entries
.count
< num_lsps
) {
2112 memset(stop
, 0xff, ISIS_SYS_ID_LEN
+ 2);
2114 memcpy(stop
, last_lsp
->hdr
.lsp_id
, sizeof(stop
));
2117 memcpy(STREAM_DATA(circuit
->snd_stream
) + start_pointer
, start
,
2118 ISIS_SYS_ID_LEN
+ 2);
2119 memcpy(STREAM_DATA(circuit
->snd_stream
) + end_pointer
, stop
,
2120 ISIS_SYS_ID_LEN
+ 2);
2121 stream_set_endp(circuit
->snd_stream
, tlv_start
);
2122 if (isis_pack_tlvs(tlvs
, circuit
->snd_stream
, len_pointer
,
2124 isis_free_tlvs(tlvs
);
2125 return ISIS_WARNING
;
2128 if (IS_DEBUG_SNP_PACKETS
) {
2130 "ISIS-Snp (%s): Sending L%d CSNP on %s, length %zd",
2131 circuit
->area
->area_tag
, level
,
2132 circuit
->interface
->name
,
2133 stream_get_endp(circuit
->snd_stream
));
2134 log_multiline(LOG_DEBUG
, " ", "%s",
2135 isis_format_tlvs(tlvs
));
2136 if (IS_DEBUG_PACKET_DUMP
)
2138 STREAM_DATA(circuit
->snd_stream
),
2139 stream_get_endp(circuit
->snd_stream
));
2142 pdu_counter_count(circuit
->area
->pdu_tx_counters
, pdu_type
);
2143 int retval
= circuit
->tx(circuit
, level
);
2144 if (retval
!= ISIS_OK
) {
2145 flog_err(EC_ISIS_PACKET
,
2146 "ISIS-Snp (%s): Send L%d CSNP on %s failed",
2147 circuit
->area
->area_tag
, level
,
2148 circuit
->interface
->name
);
2149 isis_free_tlvs(tlvs
);
2154 * Start lsp_id of the next CSNP should be one plus the
2155 * stop lsp_id in this current CSNP.
2157 memcpy(start
, stop
, ISIS_SYS_ID_LEN
+ 2);
2159 for (int i
= ISIS_SYS_ID_LEN
+ 1; i
>= 0; --i
) {
2160 if (start
[i
] < (uint8_t)0xff) {
2166 memset(stop
, 0xff, ISIS_SYS_ID_LEN
+ 2);
2167 isis_free_tlvs(tlvs
);
2173 int send_l1_csnp(struct thread
*thread
)
2175 struct isis_circuit
*circuit
;
2177 circuit
= THREAD_ARG(thread
);
2180 circuit
->t_send_csnp
[0] = NULL
;
2182 if ((circuit
->circ_type
== CIRCUIT_T_BROADCAST
2183 && circuit
->u
.bc
.is_dr
[0])
2184 || circuit
->circ_type
== CIRCUIT_T_P2P
) {
2185 send_csnp(circuit
, 1);
2187 /* set next timer thread */
2188 thread_add_timer(master
, send_l1_csnp
, circuit
,
2189 isis_jitter(circuit
->csnp_interval
[0], CSNP_JITTER
),
2190 &circuit
->t_send_csnp
[0]);
2195 int send_l2_csnp(struct thread
*thread
)
2197 struct isis_circuit
*circuit
;
2199 circuit
= THREAD_ARG(thread
);
2202 circuit
->t_send_csnp
[1] = NULL
;
2204 if ((circuit
->circ_type
== CIRCUIT_T_BROADCAST
2205 && circuit
->u
.bc
.is_dr
[1])
2206 || circuit
->circ_type
== CIRCUIT_T_P2P
) {
2207 send_csnp(circuit
, 2);
2209 /* set next timer thread */
2210 thread_add_timer(master
, send_l2_csnp
, circuit
,
2211 isis_jitter(circuit
->csnp_interval
[1], CSNP_JITTER
),
2212 &circuit
->t_send_csnp
[1]);
2218 * 7.3.15.4 action on expiration of partial SNP interval
2221 static int send_psnp(int level
, struct isis_circuit
*circuit
)
2223 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
2224 && circuit
->u
.bc
.is_dr
[level
- 1])
2227 if (lspdb_count(&circuit
->area
->lspdb
[level
- 1]) == 0)
2230 if (!circuit
->snd_stream
)
2233 uint8_t pdu_type
= (level
== ISIS_LEVEL1
) ? L1_PARTIAL_SEQ_NUM
2234 : L2_PARTIAL_SEQ_NUM
;
2236 isis_circuit_stream(circuit
, &circuit
->snd_stream
);
2237 fill_fixed_hdr(pdu_type
, circuit
->snd_stream
);
2239 size_t len_pointer
= stream_get_endp(circuit
->snd_stream
);
2240 stream_putw(circuit
->snd_stream
, 0); /* length is filled in later */
2241 stream_put(circuit
->snd_stream
, circuit
->isis
->sysid
, ISIS_SYS_ID_LEN
);
2242 stream_putc(circuit
->snd_stream
, circuit
->idx
);
2244 struct isis_passwd
*passwd
= (level
== ISIS_LEVEL1
)
2245 ? &circuit
->area
->area_passwd
2246 : &circuit
->area
->domain_passwd
;
2248 struct isis_tlvs
*tlvs
= isis_alloc_tlvs();
2250 if (CHECK_FLAG(passwd
->snp_auth
, SNP_AUTH_SEND
))
2251 isis_tlvs_add_auth(tlvs
, passwd
);
2253 size_t tlv_start
= stream_get_endp(circuit
->snd_stream
);
2254 if (isis_pack_tlvs(tlvs
, circuit
->snd_stream
, len_pointer
, false,
2256 isis_free_tlvs(tlvs
);
2257 return ISIS_WARNING
;
2259 isis_free_tlvs(tlvs
);
2262 get_max_lsp_count(STREAM_WRITEABLE(circuit
->snd_stream
));
2265 struct isis_lsp
*lsp
;
2267 tlvs
= isis_alloc_tlvs();
2268 if (CHECK_FLAG(passwd
->snp_auth
, SNP_AUTH_SEND
))
2269 isis_tlvs_add_auth(tlvs
, passwd
);
2271 frr_each (lspdb
, &circuit
->area
->lspdb
[level
- 1], lsp
) {
2272 if (ISIS_CHECK_FLAG(lsp
->SSNflags
, circuit
))
2273 isis_tlvs_add_lsp_entry(tlvs
, lsp
);
2275 if (tlvs
->lsp_entries
.count
== num_lsps
)
2279 if (!tlvs
->lsp_entries
.count
) {
2280 isis_free_tlvs(tlvs
);
2284 stream_set_endp(circuit
->snd_stream
, tlv_start
);
2285 if (isis_pack_tlvs(tlvs
, circuit
->snd_stream
, len_pointer
,
2287 isis_free_tlvs(tlvs
);
2288 return ISIS_WARNING
;
2291 if (IS_DEBUG_SNP_PACKETS
) {
2293 "ISIS-Snp (%s): Sending L%d PSNP on %s, length %zd",
2294 circuit
->area
->area_tag
, level
,
2295 circuit
->interface
->name
,
2296 stream_get_endp(circuit
->snd_stream
));
2297 log_multiline(LOG_DEBUG
, " ", "%s",
2298 isis_format_tlvs(tlvs
));
2299 if (IS_DEBUG_PACKET_DUMP
)
2301 STREAM_DATA(circuit
->snd_stream
),
2302 stream_get_endp(circuit
->snd_stream
));
2305 pdu_counter_count(circuit
->area
->pdu_tx_counters
, pdu_type
);
2306 int retval
= circuit
->tx(circuit
, level
);
2307 if (retval
!= ISIS_OK
) {
2308 flog_err(EC_ISIS_PACKET
,
2309 "ISIS-Snp (%s): Send L%d PSNP on %s failed",
2310 circuit
->area
->area_tag
, level
,
2311 circuit
->interface
->name
);
2312 isis_free_tlvs(tlvs
);
2317 * sending succeeded, we can clear SSN flags of this circuit
2318 * for the LSPs in list
2320 struct isis_lsp_entry
*entry_head
;
2321 entry_head
= (struct isis_lsp_entry
*)tlvs
->lsp_entries
.head
;
2322 for (struct isis_lsp_entry
*entry
= entry_head
; entry
;
2323 entry
= entry
->next
)
2324 ISIS_CLEAR_FLAG(entry
->lsp
->SSNflags
, circuit
);
2325 isis_free_tlvs(tlvs
);
2331 int send_l1_psnp(struct thread
*thread
)
2334 struct isis_circuit
*circuit
;
2336 circuit
= THREAD_ARG(thread
);
2339 circuit
->t_send_psnp
[0] = NULL
;
2341 send_psnp(1, circuit
);
2342 /* set next timer thread */
2343 thread_add_timer(master
, send_l1_psnp
, circuit
,
2344 isis_jitter(circuit
->psnp_interval
[0], PSNP_JITTER
),
2345 &circuit
->t_send_psnp
[0]);
2351 * 7.3.15.4 action on expiration of partial SNP interval
2354 int send_l2_psnp(struct thread
*thread
)
2356 struct isis_circuit
*circuit
;
2358 circuit
= THREAD_ARG(thread
);
2361 circuit
->t_send_psnp
[1] = NULL
;
2363 send_psnp(2, circuit
);
2365 /* set next timer thread */
2366 thread_add_timer(master
, send_l2_psnp
, circuit
,
2367 isis_jitter(circuit
->psnp_interval
[1], PSNP_JITTER
),
2368 &circuit
->t_send_psnp
[1]);
2374 * ISO 10589 - 7.3.14.3
2376 void send_lsp(struct isis_circuit
*circuit
, struct isis_lsp
*lsp
,
2377 enum isis_tx_type tx_type
)
2380 int retval
= ISIS_OK
;
2382 if (circuit
->state
!= C_STATE_UP
|| circuit
->is_passive
== 1)
2386 * Do not send if levels do not match
2388 if (!(lsp
->level
& circuit
->is_type
))
2392 * Do not send if we do not have adjacencies in state up on the circuit
2394 if (circuit
->upadjcount
[lsp
->level
- 1] == 0)
2397 /* stream_copy will assert and stop program execution if LSP is larger
2399 * the circuit's MTU. So handle and log this case here. */
2400 if (stream_get_endp(lsp
->pdu
) > stream_get_size(circuit
->snd_stream
)) {
2403 "ISIS-Upd (%s): Can't send L%d LSP %s, seq 0x%08x, cksum 0x%04hx, lifetime %hus on %s. LSP Size is %zu while interface stream size is %zu.",
2404 circuit
->area
->area_tag
, lsp
->level
,
2405 rawlspid_print(lsp
->hdr
.lsp_id
), lsp
->hdr
.seqno
,
2406 lsp
->hdr
.checksum
, lsp
->hdr
.rem_lifetime
,
2407 circuit
->interface
->name
, stream_get_endp(lsp
->pdu
),
2408 stream_get_size(circuit
->snd_stream
));
2410 /* send a northbound notification */
2411 isis_notif_lsp_too_large(circuit
, stream_get_endp(lsp
->pdu
),
2412 rawlspid_print(lsp
->hdr
.lsp_id
));
2413 #endif /* ifndef FABRICD */
2414 if (IS_DEBUG_PACKET_DUMP
)
2415 zlog_dump_data(STREAM_DATA(lsp
->pdu
),
2416 stream_get_endp(lsp
->pdu
));
2417 retval
= ISIS_ERROR
;
2421 /* copy our lsp to the send buffer */
2422 stream_copy(circuit
->snd_stream
, lsp
->pdu
);
2424 if (tx_type
== TX_LSP_CIRCUIT_SCOPED
) {
2425 stream_putc_at(circuit
->snd_stream
, 4, FS_LINK_STATE
);
2426 stream_putc_at(circuit
->snd_stream
, 7,
2427 L2_CIRCUIT_FLOODING_SCOPE
);
2430 if (IS_DEBUG_UPDATE_PACKETS
) {
2431 zlog_debug("ISIS-Upd (%s): Sending %sL%d LSP %s, seq 0x%08x, cksum 0x%04hx, lifetime %hus on %s",
2432 circuit
->area
->area_tag
,
2433 (tx_type
== TX_LSP_CIRCUIT_SCOPED
)
2434 ? "Circuit scoped " : "",
2436 rawlspid_print(lsp
->hdr
.lsp_id
), lsp
->hdr
.seqno
,
2437 lsp
->hdr
.checksum
, lsp
->hdr
.rem_lifetime
,
2438 circuit
->interface
->name
);
2439 if (IS_DEBUG_PACKET_DUMP
)
2440 zlog_dump_data(STREAM_DATA(circuit
->snd_stream
),
2441 stream_get_endp(circuit
->snd_stream
));
2444 uint8_t pdu_type
= (tx_type
== TX_LSP_CIRCUIT_SCOPED
) ? FS_LINK_STATE
2445 : (lsp
->level
== ISIS_LEVEL1
) ? L1_LINK_STATE
2449 pdu_counter_count(circuit
->area
->pdu_tx_counters
, pdu_type
);
2450 retval
= circuit
->tx(circuit
, lsp
->level
);
2451 if (retval
!= ISIS_OK
) {
2452 flog_err(EC_ISIS_PACKET
,
2453 "ISIS-Upd (%s): Send L%d LSP on %s failed %s",
2454 circuit
->area
->area_tag
, lsp
->level
,
2455 circuit
->interface
->name
,
2456 (retval
== ISIS_WARNING
) ? "temporarily"
2462 || (retval
== ISIS_OK
&& circuit
->circ_type
== CIRCUIT_T_BROADCAST
)
2463 || (retval
!= ISIS_OK
&& retval
!= ISIS_WARNING
)) {
2464 /* SRM flag will trigger retransmission. We will not retransmit
2466 * encountered a fatal error.
2467 * On success, they should only be cleared if it's a broadcast
2469 * On a P2P circuit, we will wait for the ack from the neighbor
2473 isis_tx_queue_del(circuit
->tx_queue
, lsp
);