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");
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 void update_rej_adj_count(struct isis_circuit
*circuit
)
554 circuit
->rej_adjacencies
++;
555 if (circuit
->is_type
== IS_LEVEL_1
)
556 circuit
->area
->rej_adjacencies
[0]++;
557 else if (circuit
->is_type
== IS_LEVEL_2
)
558 circuit
->area
->rej_adjacencies
[1]++;
560 circuit
->area
->rej_adjacencies
[0]++;
561 circuit
->area
->rej_adjacencies
[1]++;
565 static int process_hello(uint8_t pdu_type
, struct isis_circuit
*circuit
,
568 /* keep a copy of the raw pdu for NB notifications */
569 size_t pdu_start
= stream_get_getp(circuit
->rcv_stream
);
570 size_t pdu_end
= stream_get_endp(circuit
->rcv_stream
);
571 char raw_pdu
[pdu_end
- pdu_start
];
572 bool p2p_hello
= (pdu_type
== P2P_HELLO
);
573 int level
= p2p_hello
? 0
574 : (pdu_type
== L1_LAN_HELLO
) ? ISIS_LEVEL1
576 const char *pdu_name
=
579 : (level
== ISIS_LEVEL1
) ? "L1 LAN IIH" : "L2 LAN IIH";
581 stream_get_from(raw_pdu
, circuit
->rcv_stream
, pdu_start
,
582 pdu_end
- pdu_start
);
583 if (IS_DEBUG_ADJ_PACKETS
) {
584 zlog_debug("ISIS-Adj (%s): Rcvd %s on %s, cirType %s, cirID %u",
585 circuit
->area
->area_tag
, pdu_name
,
586 circuit
->interface
->name
,
587 circuit_t2string(circuit
->is_type
),
588 circuit
->circuit_id
);
589 if (IS_DEBUG_PACKET_DUMP
)
590 zlog_dump_data(STREAM_DATA(circuit
->rcv_stream
),
591 stream_get_endp(circuit
->rcv_stream
));
595 if (circuit
->circ_type
!= CIRCUIT_T_P2P
) {
596 zlog_warn("p2p hello on non p2p circuit");
597 update_rej_adj_count(circuit
);
599 isis_notif_reject_adjacency(
600 circuit
, "p2p hello on non p2p circuit",
601 raw_pdu
, sizeof(raw_pdu
));
602 #endif /* ifndef FABRICD */
606 if (circuit
->circ_type
!= CIRCUIT_T_BROADCAST
) {
607 zlog_warn("lan hello on non broadcast circuit");
608 update_rej_adj_count(circuit
);
610 isis_notif_reject_adjacency(
611 circuit
, "lan hello on non broadcast circuit",
612 raw_pdu
, sizeof(raw_pdu
));
613 #endif /* ifndef FABRICD */
617 if (circuit
->ext_domain
) {
619 "level %d LAN Hello received over circuit with externalDomain = true",
621 update_rej_adj_count(circuit
);
623 isis_notif_reject_adjacency(
625 "LAN Hello received over circuit with externalDomain = true",
626 raw_pdu
, sizeof(raw_pdu
));
627 #endif /* ifndef FABRICD */
631 if (!(circuit
->is_type
& level
)) {
632 if (IS_DEBUG_ADJ_PACKETS
) {
634 "ISIS-Adj (%s): Interface level mismatch, %s",
635 circuit
->area
->area_tag
,
636 circuit
->interface
->name
);
638 update_rej_adj_count(circuit
);
640 isis_notif_reject_adjacency(circuit
,
641 "Interface level mismatch",
642 raw_pdu
, sizeof(raw_pdu
));
643 #endif /* ifndef FABRICD */
648 struct iih_info iih
= {
649 .circuit
= circuit
, .ssnpa
= ssnpa
, .level
= level
};
651 /* Generic IIH Header */
652 iih
.circ_type
= stream_getc(circuit
->rcv_stream
) & 0x03;
653 stream_get(iih
.sys_id
, circuit
->rcv_stream
, ISIS_SYS_ID_LEN
);
654 iih
.holdtime
= stream_getw(circuit
->rcv_stream
);
655 iih
.pdu_len
= stream_getw(circuit
->rcv_stream
);
658 iih
.circuit_id
= stream_getc(circuit
->rcv_stream
);
660 iih
.priority
= stream_getc(circuit
->rcv_stream
);
661 stream_get(iih
.dis
, circuit
->rcv_stream
, ISIS_SYS_ID_LEN
+ 1);
664 if (pdu_len_validate(iih
.pdu_len
, circuit
)) {
666 "ISIS-Adj (%s): Rcvd %s from (%s) with invalid pdu length %hu",
667 circuit
->area
->area_tag
, pdu_name
,
668 circuit
->interface
->name
, iih
.pdu_len
);
669 update_rej_adj_count(circuit
);
671 isis_notif_reject_adjacency(circuit
, "Invalid PDU length",
672 raw_pdu
, sizeof(raw_pdu
));
673 #endif /* ifndef FABRICD */
677 if (!p2p_hello
&& !(level
& iih
.circ_type
)) {
678 flog_err(EC_ISIS_PACKET
,
679 "Level %d LAN Hello with Circuit Type %d", level
,
681 update_rej_adj_count(circuit
);
683 isis_notif_reject_adjacency(circuit
,
684 "LAN Hello with wrong IS-level",
685 raw_pdu
, sizeof(raw_pdu
));
686 #endif /* ifndef FABRICD */
690 const char *error_log
;
691 int retval
= ISIS_WARNING
;
693 if (isis_unpack_tlvs(STREAM_READABLE(circuit
->rcv_stream
),
694 circuit
->rcv_stream
, &iih
.tlvs
, &error_log
)) {
695 zlog_warn("isis_unpack_tlvs() failed: %s", error_log
);
696 update_rej_adj_count(circuit
);
698 isis_notif_reject_adjacency(circuit
, "Failed to unpack TLVs",
699 raw_pdu
, sizeof(raw_pdu
));
700 #endif /* ifndef FABRICD */
704 if (!iih
.tlvs
->area_addresses
.count
) {
705 zlog_warn("No Area addresses TLV in %s", pdu_name
);
707 /* send northbound notification */
708 isis_notif_area_mismatch(circuit
, raw_pdu
, sizeof(raw_pdu
));
709 #endif /* ifndef FABRICD */
713 if (!iih
.tlvs
->protocols_supported
.count
) {
714 zlog_warn("No supported protocols TLV in %s", pdu_name
);
715 update_rej_adj_count(circuit
);
717 isis_notif_reject_adjacency(circuit
,
718 "No supported protocols TLV",
719 raw_pdu
, sizeof(raw_pdu
));
720 #endif /* ifndef FABRICD */
724 int auth_code
= isis_tlvs_auth_is_valid(iih
.tlvs
, &circuit
->passwd
,
725 circuit
->rcv_stream
, false);
726 if (auth_code
!= ISIS_AUTH_OK
) {
727 isis_event_auth_failure(circuit
->area
->area_tag
,
728 "IIH authentication failure",
731 /* send northbound notification */
732 stream_get_from(raw_pdu
, circuit
->rcv_stream
, pdu_start
,
733 pdu_end
- pdu_start
);
734 if (auth_code
== ISIS_AUTH_FAILURE
) {
735 update_rej_adj_count(circuit
);
736 isis_notif_authentication_failure(circuit
, raw_pdu
,
738 } else { /* AUTH_TYPE_FAILURE or NO_VALIDATOR */
739 update_rej_adj_count(circuit
);
740 isis_notif_authentication_type_failure(circuit
, raw_pdu
,
743 #endif /* ifndef FABRICD */
747 if (!memcmp(iih
.sys_id
, circuit
->isis
->sysid
, ISIS_SYS_ID_LEN
)) {
749 "ISIS-Adj (%s): Received IIH with own sysid on %s - discard",
750 circuit
->area
->area_tag
, circuit
->interface
->name
);
751 update_rej_adj_count(circuit
);
753 isis_notif_reject_adjacency(circuit
,
754 "Received IIH with our own sysid",
755 raw_pdu
, sizeof(raw_pdu
));
756 #endif /* ifndef FABRICD */
761 && (listcount(circuit
->area
->area_addrs
) == 0
762 || (level
== ISIS_LEVEL1
763 && !isis_tlvs_area_addresses_match(
764 iih
.tlvs
, circuit
->area
->area_addrs
)))) {
765 if (IS_DEBUG_ADJ_PACKETS
) {
767 "ISIS-Adj (%s): Area mismatch, level %d IIH on %s",
768 circuit
->area
->area_tag
, level
,
769 circuit
->interface
->name
);
772 /* send northbound notification */
773 isis_notif_area_mismatch(circuit
, raw_pdu
, sizeof(raw_pdu
));
774 #endif /* ifndef FABRICD */
778 iih
.v4_usable
= (fabricd_ip_addrs(circuit
)
779 && iih
.tlvs
->ipv4_address
.count
);
781 iih
.v6_usable
= (circuit
->ipv6_link
&& listcount(circuit
->ipv6_link
)
782 && iih
.tlvs
->ipv6_address
.count
);
784 if (!iih
.v4_usable
&& !iih
.v6_usable
) {
785 if (IS_DEBUG_ADJ_PACKETS
) {
787 "ISIS-Adj (%s): Neither IPv4 nor IPv6 considered usable. Ignoring IIH",
788 circuit
->area
->area_tag
);
790 update_rej_adj_count(circuit
);
792 isis_notif_reject_adjacency(
793 circuit
, "Neither IPv4 not IPv6 considered usable",
794 raw_pdu
, sizeof(raw_pdu
));
795 #endif /* ifndef FABRICD */
799 retval
= p2p_hello
? process_p2p_hello(&iih
) : process_lan_hello(&iih
);
801 isis_free_tlvs(iih
.tlvs
);
806 static void lsp_flood_or_update(struct isis_lsp
*lsp
,
807 struct isis_circuit
*circuit
,
811 lsp_flood(lsp
, circuit
);
813 fabricd_update_lsp_no_flood(lsp
, circuit
);
817 * Process Level 1/2 Link State
819 * Section 7.3.15.1 - Action on receipt of a link state PDU
821 static int process_lsp(uint8_t pdu_type
, struct isis_circuit
*circuit
,
822 const uint8_t *ssnpa
, uint8_t max_area_addrs
)
826 size_t pdu_start
= stream_get_getp(circuit
->rcv_stream
);
827 size_t pdu_end
= stream_get_endp(circuit
->rcv_stream
);
828 char raw_pdu
[pdu_end
- pdu_start
];
830 stream_get_from(raw_pdu
, circuit
->rcv_stream
, pdu_start
,
831 pdu_end
- pdu_start
);
833 if (pdu_type
== FS_LINK_STATE
) {
836 if (max_area_addrs
!= L2_CIRCUIT_FLOODING_SCOPE
)
839 circuit_scoped
= true;
841 /* The stream is used verbatim for sending out new LSPDUs.
842 * So make sure we store it as an L2 LSPDU internally.
843 * (compare for the reverse in `send_lsp`) */
844 stream_putc_at(circuit
->rcv_stream
, 4, L2_LINK_STATE
);
845 stream_putc_at(circuit
->rcv_stream
, 7, 0);
847 if (pdu_type
== L1_LINK_STATE
)
851 circuit_scoped
= false;
854 if (IS_DEBUG_UPDATE_PACKETS
) {
856 "ISIS-Upd (%s): Rcvd %sL%d LSP on %s, cirType %s, cirID %u",
857 circuit
->area
->area_tag
,
858 circuit_scoped
? "Circuit scoped " : "", level
,
859 circuit
->interface
->name
,
860 circuit_t2string(circuit
->is_type
),
861 circuit
->circuit_id
);
862 if (IS_DEBUG_PACKET_DUMP
)
863 zlog_dump_data(STREAM_DATA(circuit
->rcv_stream
),
864 stream_get_endp(circuit
->rcv_stream
));
867 struct isis_lsp_hdr hdr
= {};
869 hdr
.pdu_len
= stream_getw(circuit
->rcv_stream
);
870 hdr
.rem_lifetime
= stream_getw(circuit
->rcv_stream
);
871 stream_get(hdr
.lsp_id
, circuit
->rcv_stream
, sizeof(hdr
.lsp_id
));
872 hdr
.seqno
= stream_getl(circuit
->rcv_stream
);
873 hdr
.checksum
= stream_getw(circuit
->rcv_stream
);
874 hdr
.lsp_bits
= stream_getc(circuit
->rcv_stream
);
877 /* send northbound notification */
878 isis_notif_lsp_received(circuit
, hdr
.lsp_id
, hdr
.seqno
, time(NULL
),
879 sysid_print(hdr
.lsp_id
));
880 #endif /* ifndef FABRICD */
882 if (pdu_len_validate(hdr
.pdu_len
, circuit
)) {
883 zlog_debug("ISIS-Upd (%s): LSP %s invalid LSP length %hu",
884 circuit
->area
->area_tag
, rawlspid_print(hdr
.lsp_id
),
889 if (IS_DEBUG_UPDATE_PACKETS
) {
890 zlog_debug("ISIS-Upd (%s): Rcvd L%d LSP %s, seq 0x%08x, cksum 0x%04hx, lifetime %hus, len %hu, on %s",
891 circuit
->area
->area_tag
, level
,
892 rawlspid_print(hdr
.lsp_id
), hdr
.seqno
, hdr
.checksum
,
893 hdr
.rem_lifetime
, hdr
.pdu_len
,
894 circuit
->interface
->name
);
897 /* lsp is_type check */
898 if ((hdr
.lsp_bits
& IS_LEVEL_1
) != IS_LEVEL_1
) {
900 "ISIS-Upd (%s): LSP %s invalid LSP is type 0x%x",
901 circuit
->area
->area_tag
, rawlspid_print(hdr
.lsp_id
),
902 hdr
.lsp_bits
& IS_LEVEL_1_AND_2
);
903 /* continue as per RFC1122 Be liberal in what you accept, and
904 * conservative in what you send */
907 /* Checksum sanity check - FIXME: move to correct place */
908 /* 12 = sysid+pdu+remtime */
909 if (iso_csum_verify(STREAM_DATA(circuit
->rcv_stream
) + 12,
910 hdr
.pdu_len
- 12, hdr
.checksum
, 12)) {
912 "ISIS-Upd (%s): LSP %s invalid LSP checksum 0x%04hx",
913 circuit
->area
->area_tag
, rawlspid_print(hdr
.lsp_id
),
918 /* 7.3.15.1 a) 1 - external domain circuit will discard lsps */
919 if (circuit
->ext_domain
) {
921 "ISIS-Upd (%s): LSP %s received at level %d over circuit with externalDomain = true",
922 circuit
->area
->area_tag
, rawlspid_print(hdr
.lsp_id
),
927 /* 7.3.15.1 a) 2,3 - manualL2OnlyMode not implemented */
928 if (!(circuit
->is_type
& level
)) {
930 "ISIS-Upd (%s): LSP %s received at level %d over circuit of type %s",
931 circuit
->area
->area_tag
, rawlspid_print(hdr
.lsp_id
),
932 level
, circuit_t2string(circuit
->is_type
));
936 struct isis_tlvs
*tlvs
= NULL
;
937 int retval
= ISIS_WARNING
;
938 const char *error_log
;
940 if (isis_unpack_tlvs(STREAM_READABLE(circuit
->rcv_stream
),
941 circuit
->rcv_stream
, &tlvs
, &error_log
)) {
942 zlog_warn("Something went wrong unpacking the LSP: %s",
945 /* send northbound notification. Note that the tlv-type and
946 * offset cannot correctly be set here as they are not returned
947 * by isis_unpack_tlvs, but in there I cannot fire a
948 * notification because I have no circuit information. So until
949 * we change the code above to return those extra fields, we
950 * will send dummy values which are ignored in the callback
952 circuit
->lsp_error_counter
++;
953 if (circuit
->is_type
== IS_LEVEL_1
) {
954 circuit
->area
->lsp_error_counter
[0]++;
955 } else if (circuit
->is_type
== IS_LEVEL_2
) {
956 circuit
->area
->lsp_error_counter
[1]++;
958 circuit
->area
->lsp_error_counter
[0]++;
959 circuit
->area
->lsp_error_counter
[1]++;
962 isis_notif_lsp_error(circuit
, hdr
.lsp_id
, raw_pdu
,
963 sizeof(raw_pdu
), 0, 0);
964 #endif /* ifndef FABRICD */
968 /* 7.3.15.1 a) 4 - need to make sure IDLength matches */
970 /* 7.3.15.1 a) 5 - maximum area match, can be ommited since we only use
973 /* 7.3.15.1 a) 7 - password check */
974 struct isis_passwd
*passwd
= (level
== ISIS_LEVEL1
)
975 ? &circuit
->area
->area_passwd
976 : &circuit
->area
->domain_passwd
;
977 int auth_code
= isis_tlvs_auth_is_valid(tlvs
, passwd
,
978 circuit
->rcv_stream
, true);
979 if (auth_code
!= ISIS_AUTH_OK
) {
980 isis_event_auth_failure(circuit
->area
->area_tag
,
981 "LSP authentication failure",
984 /* send northbound notification */
985 if (auth_code
== ISIS_AUTH_FAILURE
) {
986 circuit
->auth_failures
++;
987 if (circuit
->is_type
== IS_LEVEL_1
) {
988 circuit
->area
->auth_failures
[0]++;
989 } else if (circuit
->is_type
== IS_LEVEL_2
) {
990 circuit
->area
->auth_failures
[1]++;
992 circuit
->area
->auth_failures
[0]++;
993 circuit
->area
->auth_failures
[1]++;
995 isis_notif_authentication_failure(circuit
, raw_pdu
,
997 } else { /* AUTH_TYPE_FAILURE or NO_VALIDATOR */
998 circuit
->auth_type_failures
++;
999 if (circuit
->is_type
== IS_LEVEL_1
) {
1000 circuit
->area
->auth_type_failures
[0]++;
1001 } else if (circuit
->is_type
== IS_LEVEL_2
) {
1002 circuit
->area
->auth_type_failures
[1]++;
1004 circuit
->area
->auth_type_failures
[0]++;
1005 circuit
->area
->auth_type_failures
[1]++;
1007 isis_notif_authentication_type_failure(circuit
, raw_pdu
,
1010 #endif /* ifndef FABRICD */
1014 /* Find the LSP in our database and compare it to this Link State header
1016 struct isis_lsp
*lsp
=
1017 lsp_search(&circuit
->area
->lspdb
[level
- 1], hdr
.lsp_id
);
1020 comp
= lsp_compare(circuit
->area
->area_tag
, lsp
, hdr
.seqno
,
1021 hdr
.checksum
, hdr
.rem_lifetime
);
1022 if (lsp
&& (lsp
->own_lsp
))
1025 /* 7.3.15.1 a) 6 - Must check that we have an adjacency of the same
1027 /* for broadcast circuits, snpa should be compared */
1029 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
) {
1030 if (!isis_adj_lookup_snpa(ssnpa
,
1031 circuit
->u
.bc
.adjdb
[level
- 1])) {
1032 zlog_debug("(%s): DS ======= LSP %s, seq 0x%08x, cksum 0x%04hx, lifetime %hus on %s",
1033 circuit
->area
->area_tag
,
1034 rawlspid_print(hdr
.lsp_id
), hdr
.seqno
,
1035 hdr
.checksum
, hdr
.rem_lifetime
,
1036 circuit
->interface
->name
);
1037 goto out
; /* Silently discard */
1040 /* for non broadcast, we just need to find same level adj */
1042 /* If no adj, or no sharing of level */
1043 if (!circuit
->u
.p2p
.neighbor
) {
1047 if (((level
== IS_LEVEL_1
)
1048 && (circuit
->u
.p2p
.neighbor
->adj_usage
1049 == ISIS_ADJ_LEVEL2
))
1050 || ((level
== IS_LEVEL_2
)
1051 && (circuit
->u
.p2p
.neighbor
->adj_usage
1052 == ISIS_ADJ_LEVEL1
)))
1060 /* 7.3.15.1 a) 7 - Passwords for level 1 - not implemented */
1062 /* 7.3.15.1 a) 8 - Passwords for level 2 - not implemented */
1064 /* 7.3.15.1 a) 9 - OriginatingLSPBufferSize - not implemented FIXME: do
1067 /* 7.3.16.2 - If this is an LSP from another IS with identical seq_num
1069 * wrong checksum, initiate a purge. */
1070 if (lsp
&& (lsp
->hdr
.seqno
== hdr
.seqno
)
1071 && (lsp
->hdr
.checksum
!= hdr
.checksum
)
1072 && hdr
.rem_lifetime
) {
1073 zlog_warn("ISIS-Upd (%s): LSP %s seq 0x%08x with confused checksum received.",
1074 circuit
->area
->area_tag
, rawlspid_print(hdr
.lsp_id
),
1076 hdr
.rem_lifetime
= 0;
1077 lsp_confusion
= true;
1079 lsp_confusion
= false;
1081 /* 7.3.15.1 b) - If the remaining life time is 0, we perform 7.3.16.4 */
1082 if (hdr
.rem_lifetime
== 0) {
1084 /* 7.3.16.4 a) 1) No LSP in db -> send an ack, but don't
1086 /* only needed on explicit update, eg - p2p */
1087 if (circuit
->circ_type
== CIRCUIT_T_P2P
)
1088 ack_lsp(&hdr
, circuit
, level
);
1089 goto out
; /* FIXME: do we need a purge? */
1091 if (memcmp(hdr
.lsp_id
, circuit
->isis
->sysid
,
1093 /* LSP by some other system -> do 7.3.16.4 b) */
1094 /* 7.3.16.4 b) 1) */
1095 if (comp
== LSP_NEWER
) {
1096 lsp_update(lsp
, &hdr
, tlvs
,
1097 circuit
->rcv_stream
,
1098 circuit
->area
, level
,
1101 isis_free_tlvs(tlvs
);
1104 lsp_flood_or_update(lsp
, NULL
,
1107 ISIS_FLAGS_CLEAR_ALL(
1108 lsp
->SSNflags
); /* FIXME:
1113 /* For the case of lsp confusion, flood
1114 * the purge back to its
1115 * originator so that it can react.
1116 * Otherwise, don't reflood
1117 * through incoming circuit as usual */
1118 if (!lsp_confusion
) {
1124 if (circuit
->circ_type
1125 != CIRCUIT_T_BROADCAST
)
1130 } /* 7.3.16.4 b) 2) */
1131 else if (comp
== LSP_EQUAL
) {
1133 isis_tx_queue_del(circuit
->tx_queue
,
1136 if (circuit
->circ_type
1137 != CIRCUIT_T_BROADCAST
)
1138 ISIS_SET_FLAG(lsp
->SSNflags
,
1140 } /* 7.3.16.4 b) 3) */
1142 isis_tx_queue_add(circuit
->tx_queue
,
1143 lsp
, TX_LSP_NORMAL
);
1144 ISIS_CLEAR_FLAG(lsp
->SSNflags
, circuit
);
1146 } else if (lsp
->hdr
.rem_lifetime
!= 0) {
1147 /* our own LSP -> 7.3.16.4 c) */
1148 if (comp
== LSP_NEWER
) {
1150 if (lsp
->hdr
.seqno
< hdr
.seqno
) {
1154 ->lsp_seqno_skipped_counter
++;
1155 isis_notif_seqno_skipped(
1156 circuit
, hdr
.lsp_id
);
1158 #endif /* ifndef FABRICD */
1159 lsp_inc_seqno(lsp
, hdr
.seqno
);
1160 lsp_flood_or_update(lsp
, NULL
,
1163 isis_tx_queue_add(circuit
->tx_queue
,
1164 lsp
, TX_LSP_NORMAL
);
1165 ISIS_CLEAR_FLAG(lsp
->SSNflags
, circuit
);
1167 if (IS_DEBUG_UPDATE_PACKETS
)
1169 "ISIS-Upd (%s): (1) re-originating LSP %s new seq 0x%08x",
1170 circuit
->area
->area_tag
,
1171 rawlspid_print(hdr
.lsp_id
),
1174 /* our own LSP with 0 remaining life time */
1176 /* send northbound notification */
1177 isis_notif_own_lsp_purge(circuit
, hdr
.lsp_id
);
1178 #endif /* ifndef FABRICD */
1183 /* 7.3.15.1 c) - If this is our own lsp and we don't have it initiate a
1185 if (memcmp(hdr
.lsp_id
, circuit
->isis
->sysid
, ISIS_SYS_ID_LEN
) == 0) {
1187 /* 7.3.16.4: initiate a purge */
1188 lsp_purge_non_exist(level
, &hdr
, circuit
->area
);
1192 /* 7.3.15.1 d) - If this is our own lsp and we have it */
1194 /* In 7.3.16.1, If an Intermediate system R somewhere in the
1196 * has information that the current sequence number for source S
1198 * "greater" than that held by S, ... */
1200 if (comp
== LSP_NEWER
) {
1202 lsp_inc_seqno(lsp
, hdr
.seqno
);
1204 /* send northbound notification */
1205 circuit
->area
->lsp_seqno_skipped_counter
++;
1206 isis_notif_seqno_skipped(circuit
, hdr
.lsp_id
);
1207 #endif /* ifndef FABRICD */
1208 if (IS_DEBUG_UPDATE_PACKETS
) {
1210 "ISIS-Upd (%s): (2) re-originating LSP %s new seq 0x%08x",
1211 circuit
->area
->area_tag
,
1212 rawlspid_print(hdr
.lsp_id
),
1215 lsp_flood(lsp
, NULL
);
1216 } else if (comp
== LSP_EQUAL
) {
1217 isis_tx_queue_del(circuit
->tx_queue
, lsp
);
1218 if (circuit
->circ_type
!= CIRCUIT_T_BROADCAST
)
1219 ISIS_SET_FLAG(lsp
->SSNflags
, circuit
);
1221 isis_tx_queue_add(circuit
->tx_queue
, lsp
,
1223 ISIS_CLEAR_FLAG(lsp
->SSNflags
, circuit
);
1226 /* 7.3.15.1 e) - This lsp originated on another system */
1228 /* 7.3.15.1 e) 1) LSP newer than the one in db or no LSP in db
1230 if ((!lsp
|| comp
== LSP_NEWER
)) {
1232 * If this lsp is a frag, need to see if we have zero
1235 struct isis_lsp
*lsp0
= NULL
;
1236 if (LSP_FRAGMENT(hdr
.lsp_id
) != 0) {
1237 uint8_t lspid
[ISIS_SYS_ID_LEN
+ 2];
1238 memcpy(lspid
, hdr
.lsp_id
, ISIS_SYS_ID_LEN
+ 1);
1239 LSP_FRAGMENT(lspid
) = 0;
1241 &circuit
->area
->lspdb
[level
- 1], lspid
);
1244 "Got lsp frag, while zero lsp not in database");
1250 lsp
= lsp_new_from_recv(
1251 &hdr
, tlvs
, circuit
->rcv_stream
, lsp0
,
1252 circuit
->area
, level
);
1254 lsp_insert(&circuit
->area
->lspdb
[level
- 1],
1256 } else /* exists, so we overwrite */
1258 lsp_update(lsp
, &hdr
, tlvs
, circuit
->rcv_stream
,
1259 circuit
->area
, level
, false);
1262 lsp_flood_or_update(lsp
, circuit
, circuit_scoped
);
1265 if (circuit
->circ_type
!= CIRCUIT_T_BROADCAST
)
1266 ISIS_SET_FLAG(lsp
->SSNflags
, circuit
);
1269 /* 7.3.15.1 e) 2) LSP equal to the one in db */
1270 else if (comp
== LSP_EQUAL
) {
1271 isis_tx_queue_del(circuit
->tx_queue
, lsp
);
1272 lsp_update(lsp
, &hdr
, tlvs
, circuit
->rcv_stream
,
1273 circuit
->area
, level
, false);
1275 if (circuit
->circ_type
!= CIRCUIT_T_BROADCAST
)
1276 ISIS_SET_FLAG(lsp
->SSNflags
, circuit
);
1278 /* 7.3.15.1 e) 3) LSP older than the one in db */
1280 isis_tx_queue_add(circuit
->tx_queue
, lsp
,
1282 ISIS_CLEAR_FLAG(lsp
->SSNflags
, circuit
);
1289 fabricd_trigger_csnp(circuit
->area
, circuit_scoped
);
1291 isis_free_tlvs(tlvs
);
1296 * Process Sequence Numbers
1298 * Section 7.3.15.2 - Action on receipt of a sequence numbers PDU
1301 static int process_snp(uint8_t pdu_type
, struct isis_circuit
*circuit
,
1302 const uint8_t *ssnpa
)
1305 size_t pdu_start
= stream_get_getp(circuit
->rcv_stream
);
1306 size_t pdu_end
= stream_get_endp(circuit
->rcv_stream
);
1307 char raw_pdu
[pdu_end
- pdu_start
];
1308 #endif /* ifndef FABRICD */
1310 bool is_csnp
= (pdu_type
== L1_COMPLETE_SEQ_NUM
1311 || pdu_type
== L2_COMPLETE_SEQ_NUM
);
1312 char typechar
= is_csnp
? 'C' : 'P';
1313 int level
= (pdu_type
== L1_COMPLETE_SEQ_NUM
1314 || pdu_type
== L1_PARTIAL_SEQ_NUM
)
1318 uint16_t pdu_len
= stream_getw(circuit
->rcv_stream
);
1319 uint8_t rem_sys_id
[ISIS_SYS_ID_LEN
];
1321 stream_get(rem_sys_id
, circuit
->rcv_stream
, ISIS_SYS_ID_LEN
);
1322 stream_forward_getp(circuit
->rcv_stream
, 1); /* Circuit ID - unused */
1324 uint8_t start_lsp_id
[ISIS_SYS_ID_LEN
+ 2] = {};
1325 uint8_t stop_lsp_id
[ISIS_SYS_ID_LEN
+ 2] = {};
1328 stream_get(start_lsp_id
, circuit
->rcv_stream
,
1329 ISIS_SYS_ID_LEN
+ 2);
1330 stream_get(stop_lsp_id
, circuit
->rcv_stream
,
1331 ISIS_SYS_ID_LEN
+ 2);
1334 if (pdu_len_validate(pdu_len
, circuit
)) {
1335 zlog_warn("Received a CSNP with bogus length %d", pdu_len
);
1336 return ISIS_WARNING
;
1339 if (IS_DEBUG_SNP_PACKETS
) {
1341 "ISIS-Snp (%s): Rcvd L%d %cSNP on %s, cirType %s, cirID %u",
1342 circuit
->area
->area_tag
, level
, typechar
,
1343 circuit
->interface
->name
,
1344 circuit_t2string(circuit
->is_type
),
1345 circuit
->circuit_id
);
1346 if (IS_DEBUG_PACKET_DUMP
)
1347 zlog_dump_data(STREAM_DATA(circuit
->rcv_stream
),
1348 stream_get_endp(circuit
->rcv_stream
));
1351 /* 7.3.15.2 a) 1 - external domain circuit will discard snp pdu */
1352 if (circuit
->ext_domain
) {
1355 "ISIS-Snp (%s): Rcvd L%d %cSNP on %s, skipping: circuit externalDomain = true",
1356 circuit
->area
->area_tag
, level
, typechar
,
1357 circuit
->interface
->name
);
1362 /* 7.3.15.2 a) 2,3 - manualL2OnlyMode not implemented */
1363 if (!(circuit
->is_type
& level
)) {
1365 "ISIS-Snp (%s): Rcvd L%d %cSNP on %s, skipping: circuit type %s does not match level %d",
1366 circuit
->area
->area_tag
, level
, typechar
,
1367 circuit
->interface
->name
,
1368 circuit_t2string(circuit
->is_type
), level
);
1373 /* 7.3.15.2 a) 4 - not applicable for CSNP only PSNPs on broadcast */
1374 if (!is_csnp
&& (circuit
->circ_type
== CIRCUIT_T_BROADCAST
)
1375 && !circuit
->u
.bc
.is_dr
[level
- 1]) {
1377 "ISIS-Snp (%s): Rcvd L%d %cSNP from %s on %s, skipping: we are not the DIS",
1378 circuit
->area
->area_tag
, level
, typechar
,
1379 snpa_print(ssnpa
), circuit
->interface
->name
);
1384 /* 7.3.15.2 a) 5 - need to make sure IDLength matches - already checked
1387 /* 7.3.15.2 a) 6 - maximum area match, can be ommited since we only use
1389 * - already checked */
1391 /* 7.3.15.2 a) 7 - Must check that we have an adjacency of the same
1393 /* for broadcast circuits, snpa should be compared */
1394 /* FIXME : Do we need to check SNPA? */
1395 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
) {
1396 if (!isis_adj_lookup(rem_sys_id
,
1397 circuit
->u
.bc
.adjdb
[level
- 1]))
1398 return ISIS_OK
; /* Silently discard */
1400 if (!fabricd
&& !circuit
->u
.p2p
.neighbor
) {
1401 zlog_warn("no p2p neighbor on circuit %s",
1402 circuit
->interface
->name
);
1403 return ISIS_OK
; /* Silently discard */
1407 struct isis_tlvs
*tlvs
;
1408 int retval
= ISIS_WARNING
;
1409 const char *error_log
;
1411 if (isis_unpack_tlvs(STREAM_READABLE(circuit
->rcv_stream
),
1412 circuit
->rcv_stream
, &tlvs
, &error_log
)) {
1413 zlog_warn("Something went wrong unpacking the SNP: %s",
1418 struct isis_passwd
*passwd
= (level
== IS_LEVEL_1
)
1419 ? &circuit
->area
->area_passwd
1420 : &circuit
->area
->domain_passwd
;
1422 if (CHECK_FLAG(passwd
->snp_auth
, SNP_AUTH_RECV
)) {
1423 int auth_code
= isis_tlvs_auth_is_valid(
1424 tlvs
, passwd
, circuit
->rcv_stream
, false);
1425 if (auth_code
!= ISIS_AUTH_OK
) {
1426 isis_event_auth_failure(circuit
->area
->area_tag
,
1427 "SNP authentication failure",
1430 /* send northbound notification */
1431 stream_get_from(raw_pdu
, circuit
->rcv_stream
, pdu_start
,
1432 pdu_end
- pdu_start
);
1433 if (auth_code
== ISIS_AUTH_FAILURE
) {
1434 circuit
->auth_failures
++;
1435 if (circuit
->is_type
== IS_LEVEL_1
) {
1436 circuit
->area
->auth_failures
[0]++;
1437 } else if (circuit
->is_type
== IS_LEVEL_2
) {
1438 circuit
->area
->auth_failures
[1]++;
1440 circuit
->area
->auth_failures
[0]++;
1441 circuit
->area
->auth_failures
[1]++;
1443 isis_notif_authentication_failure(
1444 circuit
, raw_pdu
, sizeof(raw_pdu
));
1445 } else { /* AUTH_TYPE_FAILURE or NO_VALIDATOR */
1446 circuit
->auth_type_failures
++;
1447 if (circuit
->is_type
== IS_LEVEL_1
) {
1448 circuit
->area
->auth_type_failures
[0]++;
1449 } else if (circuit
->is_type
== IS_LEVEL_2
) {
1450 circuit
->area
->auth_type_failures
[1]++;
1452 circuit
->area
->auth_type_failures
[0]++;
1453 circuit
->area
->auth_type_failures
[1]++;
1455 isis_notif_authentication_type_failure(
1456 circuit
, raw_pdu
, sizeof(raw_pdu
));
1458 #endif /* ifndef FABRICD */
1463 struct isis_lsp_entry
*entry_head
=
1464 (struct isis_lsp_entry
*)tlvs
->lsp_entries
.head
;
1466 /* debug isis snp-packets */
1467 if (IS_DEBUG_SNP_PACKETS
) {
1468 zlog_debug("ISIS-Snp (%s): Rcvd L%d %cSNP from %s on %s",
1469 circuit
->area
->area_tag
, level
, typechar
,
1470 snpa_print(ssnpa
), circuit
->interface
->name
);
1471 for (struct isis_lsp_entry
*entry
= entry_head
; entry
;
1472 entry
= entry
->next
) {
1474 "ISIS-Snp (%s): %cSNP entry %s, seq 0x%08x, cksum 0x%04hx, lifetime %hus",
1475 circuit
->area
->area_tag
, typechar
,
1476 rawlspid_print(entry
->id
), entry
->seqno
,
1477 entry
->checksum
, entry
->rem_lifetime
);
1481 bool resync_needed
= false;
1483 /* 7.3.15.2 b) Actions on LSP_ENTRIES reported */
1484 for (struct isis_lsp_entry
*entry
= entry_head
; entry
;
1485 entry
= entry
->next
) {
1486 struct isis_lsp
*lsp
=
1487 lsp_search(&circuit
->area
->lspdb
[level
- 1], entry
->id
);
1488 bool own_lsp
= !memcmp(entry
->id
, circuit
->isis
->sysid
,
1491 /* 7.3.15.2 b) 1) is this LSP newer */
1492 int cmp
= lsp_compare(circuit
->area
->area_tag
, lsp
,
1493 entry
->seqno
, entry
->checksum
,
1494 entry
->rem_lifetime
);
1495 /* 7.3.15.2 b) 2) if it equals, clear SRM on p2p */
1496 if (cmp
== LSP_EQUAL
) {
1497 /* if (circuit->circ_type !=
1498 * CIRCUIT_T_BROADCAST) */
1499 isis_tx_queue_del(circuit
->tx_queue
, lsp
);
1501 /* 7.3.15.2 b) 3) if it is older, clear SSN and set SRM
1503 else if (cmp
== LSP_OLDER
) {
1504 ISIS_CLEAR_FLAG(lsp
->SSNflags
, circuit
);
1505 isis_tx_queue_add(circuit
->tx_queue
, lsp
,
1508 /* 7.3.15.2 b) 4) if it is newer, set SSN and clear SRM
1512 lsp_inc_seqno(lsp
, entry
->seqno
);
1513 isis_tx_queue_add(circuit
->tx_queue
, lsp
,
1516 ISIS_SET_FLAG(lsp
->SSNflags
, circuit
);
1517 /* if (circuit->circ_type !=
1518 * CIRCUIT_T_BROADCAST) */
1519 isis_tx_queue_del(circuit
->tx_queue
, lsp
);
1520 resync_needed
= true;
1524 /* 7.3.15.2 b) 5) if it was not found, and all of those
1526 * insert it and set SSN on it */
1527 if (entry
->rem_lifetime
&& entry
->checksum
1529 && memcmp(entry
->id
, circuit
->isis
->sysid
,
1531 struct isis_lsp
*lsp0
= NULL
;
1533 if (LSP_FRAGMENT(entry
->id
)) {
1534 uint8_t lspid
[ISIS_SYS_ID_LEN
+ 2];
1536 memcpy(lspid
, entry
->id
,
1537 ISIS_SYS_ID_LEN
+ 1);
1538 LSP_FRAGMENT(lspid
) = 0;
1540 &circuit
->area
->lspdb
[level
- 1],
1543 zlog_debug("Got lsp frag in snp, while zero not in database");
1547 lsp
= lsp_new(circuit
->area
, entry
->id
,
1548 entry
->rem_lifetime
, 0, 0,
1549 entry
->checksum
, lsp0
, level
);
1550 lsp_insert(&circuit
->area
->lspdb
[level
- 1],
1553 lsp_set_all_srmflags(lsp
, false);
1554 ISIS_SET_FLAG(lsp
->SSNflags
, circuit
);
1555 resync_needed
= true;
1560 /* 7.3.15.2 c) on CSNP set SRM for all in range which were not reported
1564 * Build a list from our own LSP db bounded with
1565 * start_lsp_id and stop_lsp_id
1567 struct list
*lsp_list
= list_new();
1568 lsp_build_list_nonzero_ht(&circuit
->area
->lspdb
[level
- 1],
1569 start_lsp_id
, stop_lsp_id
, lsp_list
);
1571 /* Fixme: Find a better solution */
1572 struct listnode
*node
, *nnode
;
1573 struct isis_lsp
*lsp
;
1574 for (struct isis_lsp_entry
*entry
= entry_head
; entry
;
1575 entry
= entry
->next
) {
1576 for (ALL_LIST_ELEMENTS(lsp_list
, node
, nnode
, lsp
)) {
1577 if (lsp_id_cmp(lsp
->hdr
.lsp_id
, entry
->id
)
1579 list_delete_node(lsp_list
, node
);
1585 /* on remaining LSPs we set SRM (neighbor knew not of) */
1586 for (ALL_LIST_ELEMENTS_RO(lsp_list
, node
, lsp
)) {
1587 isis_tx_queue_add(circuit
->tx_queue
, lsp
, TX_LSP_NORMAL
);
1588 resync_needed
= true;
1592 list_delete(&lsp_list
);
1595 if (fabricd_initial_sync_is_complete(circuit
->area
) && resync_needed
)
1596 zlog_warn("OpenFabric: Needed to resync LSPDB using CSNP!");
1600 isis_free_tlvs(tlvs
);
1604 static int pdu_size(uint8_t pdu_type
, uint8_t *size
)
1609 *size
= ISIS_LANHELLO_HDRLEN
;
1612 *size
= ISIS_P2PHELLO_HDRLEN
;
1617 *size
= ISIS_LSP_HDR_LEN
;
1619 case L1_COMPLETE_SEQ_NUM
:
1620 case L2_COMPLETE_SEQ_NUM
:
1621 *size
= ISIS_CSNP_HDRLEN
;
1623 case L1_PARTIAL_SEQ_NUM
:
1624 case L2_PARTIAL_SEQ_NUM
:
1625 *size
= ISIS_PSNP_HDRLEN
;
1630 *size
+= ISIS_FIXED_HDR_LEN
;
1638 int isis_handle_pdu(struct isis_circuit
*circuit
, uint8_t *ssnpa
)
1640 int retval
= ISIS_OK
;
1641 size_t pdu_start
= stream_get_getp(circuit
->rcv_stream
);
1642 size_t pdu_end
= stream_get_endp(circuit
->rcv_stream
);
1643 char raw_pdu
[pdu_end
- pdu_start
];
1645 stream_get_from(raw_pdu
, circuit
->rcv_stream
, pdu_start
,
1646 pdu_end
- pdu_start
);
1648 /* Verify that at least the 8 bytes fixed header have been received */
1649 if (stream_get_endp(circuit
->rcv_stream
) < ISIS_FIXED_HDR_LEN
) {
1650 flog_err(EC_ISIS_PACKET
, "PDU is too short to be IS-IS.");
1654 uint8_t idrp
= stream_getc(circuit
->rcv_stream
);
1655 uint8_t length
= stream_getc(circuit
->rcv_stream
);
1656 uint8_t version1
= stream_getc(circuit
->rcv_stream
);
1657 uint8_t id_len
= stream_getc(circuit
->rcv_stream
);
1658 uint8_t pdu_type
= stream_getc(circuit
->rcv_stream
)
1659 & 0x1f; /* bits 6-8 are reserved */
1660 uint8_t version2
= stream_getc(circuit
->rcv_stream
);
1662 stream_forward_getp(circuit
->rcv_stream
, 1); /* reserved */
1663 uint8_t max_area_addrs
= stream_getc(circuit
->rcv_stream
);
1665 pdu_counter_count(circuit
->area
->pdu_rx_counters
, pdu_type
);
1667 if (idrp
== ISO9542_ESIS
) {
1668 flog_err(EC_LIB_DEVELOPMENT
,
1669 "No support for ES-IS packet IDRP=%hhx", idrp
);
1673 if (idrp
!= ISO10589_ISIS
) {
1674 flog_err(EC_ISIS_PACKET
, "Not an IS-IS packet IDRP=%hhx",
1679 if (version1
!= 1) {
1680 zlog_warn("Unsupported ISIS version %hhu", version1
);
1682 /* send northbound notification */
1683 isis_notif_version_skew(circuit
, version1
, raw_pdu
,
1685 #endif /* ifndef FABRICD */
1686 return ISIS_WARNING
;
1689 if (id_len
!= 0 && id_len
!= ISIS_SYS_ID_LEN
) {
1692 "IDFieldLengthMismatch: ID Length field in a received PDU %hhu, while the parameter for this IS is %u",
1693 id_len
, ISIS_SYS_ID_LEN
);
1694 circuit
->id_len_mismatches
++;
1695 if (circuit
->is_type
== IS_LEVEL_1
) {
1696 circuit
->area
->id_len_mismatches
[0]++;
1697 } else if (circuit
->is_type
== IS_LEVEL_2
) {
1698 circuit
->area
->id_len_mismatches
[1]++;
1700 circuit
->area
->id_len_mismatches
[0]++;
1701 circuit
->area
->id_len_mismatches
[1]++;
1705 /* send northbound notification */
1706 isis_notif_id_len_mismatch(circuit
, id_len
, raw_pdu
,
1708 #endif /* ifndef FABRICD */
1712 uint8_t expected_length
;
1713 if (pdu_size(pdu_type
, &expected_length
)) {
1714 zlog_warn("Unsupported ISIS PDU %hhu", pdu_type
);
1715 return ISIS_WARNING
;
1718 if (length
!= expected_length
) {
1719 flog_err(EC_ISIS_PACKET
,
1720 "Expected fixed header length = %hhu but got %hhu",
1721 expected_length
, length
);
1725 if (stream_get_endp(circuit
->rcv_stream
) < length
) {
1728 "PDU is too short to contain fixed header of given PDU type.");
1732 if (version2
!= 1) {
1733 zlog_warn("Unsupported ISIS PDU version %hhu", version2
);
1735 /* send northbound notification */
1736 isis_notif_version_skew(circuit
, version2
, raw_pdu
,
1738 #endif /* ifndef FABRICD */
1739 return ISIS_WARNING
;
1742 if (circuit
->is_passive
) {
1743 zlog_warn("Received ISIS PDU on passive circuit %s",
1744 circuit
->interface
->name
);
1745 return ISIS_WARNING
;
1749 if (pdu_type
!= FS_LINK_STATE
/* FS PDU doesn't contain max area addr
1751 && max_area_addrs
!= 0
1752 && max_area_addrs
!= circuit
->isis
->max_area_addrs
) {
1755 "maximumAreaAddressesMismatch: maximumAreaAdresses in a received PDU %hhu while the parameter for this IS is %u",
1756 max_area_addrs
, circuit
->isis
->max_area_addrs
);
1757 circuit
->max_area_addr_mismatches
++;
1759 /* send northbound notification */
1760 isis_notif_max_area_addr_mismatch(circuit
, max_area_addrs
,
1761 raw_pdu
, sizeof(raw_pdu
));
1762 #endif /* ifndef FABRICD */
1770 if (fabricd
&& pdu_type
!= P2P_HELLO
)
1772 retval
= process_hello(pdu_type
, circuit
, ssnpa
);
1778 && pdu_type
!= L2_LINK_STATE
1779 && pdu_type
!= FS_LINK_STATE
)
1781 retval
= process_lsp(pdu_type
, circuit
, ssnpa
, max_area_addrs
);
1783 case L1_COMPLETE_SEQ_NUM
:
1784 case L2_COMPLETE_SEQ_NUM
:
1785 case L1_PARTIAL_SEQ_NUM
:
1786 case L2_PARTIAL_SEQ_NUM
:
1787 retval
= process_snp(pdu_type
, circuit
, ssnpa
);
1796 int isis_receive(struct thread
*thread
)
1798 struct isis_circuit
*circuit
;
1799 uint8_t ssnpa
[ETH_ALEN
];
1805 circuit
= THREAD_ARG(thread
);
1808 circuit
->t_read
= NULL
;
1810 isis_circuit_stream(circuit
, &circuit
->rcv_stream
);
1812 retval
= circuit
->rx(circuit
, ssnpa
);
1814 #if ISIS_METHOD != ISIS_METHOD_BPF
1815 if (retval
== ISIS_OK
)
1816 retval
= isis_handle_pdu(circuit
, ssnpa
);
1817 #endif //ISIS_METHOD != ISIS_METHOD_BPF
1820 * prepare for next packet.
1822 if (!circuit
->is_passive
)
1823 isis_circuit_prepare(circuit
);
1831 void fill_fixed_hdr(uint8_t pdu_type
, struct stream
*stream
)
1835 if (pdu_size(pdu_type
, &length
))
1836 assert(!"Unknown PDU Type");
1838 stream_putc(stream
, ISO10589_ISIS
); /* IDRP */
1839 stream_putc(stream
, length
); /* Length of fixed header */
1840 stream_putc(stream
, 1); /* Version/Protocol ID Extension 1 */
1841 stream_putc(stream
, 0); /* ID Length, 0 => 6 */
1842 stream_putc(stream
, pdu_type
);
1843 stream_putc(stream
, 1); /* Subversion */
1844 stream_putc(stream
, 0); /* Reserved */
1845 stream_putc(stream
, 0); /* Max Area Addresses 0 => 3 */
1848 static uint8_t hello_pdu_type(struct isis_circuit
*circuit
, int level
)
1850 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
)
1851 return (level
== IS_LEVEL_1
) ? L1_LAN_HELLO
: L2_LAN_HELLO
;
1856 static void put_hello_hdr(struct isis_circuit
*circuit
, int level
,
1857 size_t *len_pointer
)
1859 uint8_t pdu_type
= hello_pdu_type(circuit
, level
);
1861 isis_circuit_stream(circuit
, &circuit
->snd_stream
);
1862 fill_fixed_hdr(pdu_type
, circuit
->snd_stream
);
1864 stream_putc(circuit
->snd_stream
, circuit
->is_type
);
1865 stream_put(circuit
->snd_stream
, circuit
->isis
->sysid
, ISIS_SYS_ID_LEN
);
1867 uint32_t holdtime
= circuit
->hello_multiplier
[level
- 1]
1868 * circuit
->hello_interval
[level
- 1];
1870 if (holdtime
> 0xffff)
1873 stream_putw(circuit
->snd_stream
, holdtime
);
1874 *len_pointer
= stream_get_endp(circuit
->snd_stream
);
1875 stream_putw(circuit
->snd_stream
, 0); /* length is filled in later */
1877 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
) {
1878 uint8_t *desig_is
= (level
== IS_LEVEL_1
)
1879 ? circuit
->u
.bc
.l1_desig_is
1880 : circuit
->u
.bc
.l2_desig_is
;
1881 stream_putc(circuit
->snd_stream
, circuit
->priority
[level
- 1]);
1882 stream_put(circuit
->snd_stream
, desig_is
, ISIS_SYS_ID_LEN
+ 1);
1884 stream_putc(circuit
->snd_stream
, circuit
->circuit_id
);
1888 int send_hello(struct isis_circuit
*circuit
, int level
)
1893 if (circuit
->is_passive
)
1896 if (circuit
->interface
->mtu
== 0) {
1897 zlog_warn("circuit has zero MTU");
1898 return ISIS_WARNING
;
1901 put_hello_hdr(circuit
, level
, &len_pointer
);
1903 struct isis_tlvs
*tlvs
= isis_alloc_tlvs();
1905 isis_tlvs_add_auth(tlvs
, &circuit
->passwd
);
1907 if (!listcount(circuit
->area
->area_addrs
)) {
1908 isis_free_tlvs(tlvs
);
1909 return ISIS_WARNING
;
1912 isis_tlvs_add_area_addresses(tlvs
, circuit
->area
->area_addrs
);
1914 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
) {
1915 isis_tlvs_add_lan_neighbors(
1916 tlvs
, circuit
->u
.bc
.lan_neighs
[level
- 1]);
1917 } else if (circuit
->circ_type
== CIRCUIT_T_P2P
1918 && !circuit
->disable_threeway_adj
) {
1919 uint32_t ext_circuit_id
= circuit
->idx
;
1920 if (circuit
->u
.p2p
.neighbor
) {
1921 uint8_t threeway_state
;
1923 if (fabricd_initial_sync_is_in_progress(circuit
->area
)
1924 && fabricd_initial_sync_circuit(circuit
->area
) != circuit
)
1925 threeway_state
= ISIS_THREEWAY_DOWN
;
1927 threeway_state
= circuit
->u
.p2p
.neighbor
->threeway_state
;
1928 isis_tlvs_add_threeway_adj(tlvs
,
1931 circuit
->u
.p2p
.neighbor
->sysid
,
1932 circuit
->u
.p2p
.neighbor
->ext_circuit_id
);
1934 isis_tlvs_add_threeway_adj(tlvs
,
1941 isis_tlvs_set_protocols_supported(tlvs
, &circuit
->nlpids
);
1946 * TLV gets included if no topology is enabled on the interface,
1947 * if one topology other than #0 is enabled, or if multiple topologies
1950 struct isis_circuit_mt_setting
**mt_settings
;
1951 unsigned int mt_count
;
1953 mt_settings
= circuit_mt_settings(circuit
, &mt_count
);
1954 if (mt_count
== 0 && area_is_mt(circuit
->area
)) {
1955 tlvs
->mt_router_info_empty
= true;
1956 } else if ((mt_count
== 1
1957 && mt_settings
[0]->mtid
!= ISIS_MT_IPV4_UNICAST
)
1958 || (mt_count
> 1)) {
1959 for (unsigned int i
= 0; i
< mt_count
; i
++)
1960 isis_tlvs_add_mt_router_info(tlvs
, mt_settings
[i
]->mtid
,
1964 if (circuit
->ip_router
) {
1965 struct list
*circuit_ip_addrs
= fabricd_ip_addrs(circuit
);
1967 if (circuit_ip_addrs
)
1968 isis_tlvs_add_ipv4_addresses(tlvs
, circuit_ip_addrs
);
1971 if (circuit
->ipv6_router
&& circuit
->ipv6_link
)
1972 isis_tlvs_add_ipv6_addresses(tlvs
, circuit
->ipv6_link
);
1974 if (isis_pack_tlvs(tlvs
, circuit
->snd_stream
, len_pointer
,
1975 circuit
->pad_hellos
, false)) {
1976 isis_free_tlvs(tlvs
);
1977 return ISIS_WARNING
; /* XXX: Maybe Log TLV structure? */
1980 if (IS_DEBUG_ADJ_PACKETS
) {
1981 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
) {
1983 "ISIS-Adj (%s): Sending L%d LAN IIH on %s, length %zd",
1984 circuit
->area
->area_tag
, level
,
1985 circuit
->interface
->name
,
1986 stream_get_endp(circuit
->snd_stream
));
1989 "ISIS-Adj (%s): Sending P2P IIH on %s, length %zd",
1990 circuit
->area
->area_tag
,
1991 circuit
->interface
->name
,
1992 stream_get_endp(circuit
->snd_stream
));
1994 if (IS_DEBUG_PACKET_DUMP
)
1995 zlog_dump_data(STREAM_DATA(circuit
->snd_stream
),
1996 stream_get_endp(circuit
->snd_stream
));
1999 isis_free_tlvs(tlvs
);
2001 pdu_counter_count(circuit
->area
->pdu_tx_counters
,
2002 hello_pdu_type(circuit
, level
));
2003 retval
= circuit
->tx(circuit
, level
);
2004 if (retval
!= ISIS_OK
)
2005 flog_err(EC_ISIS_PACKET
,
2006 "ISIS-Adj (%s): Send L%d IIH on %s failed",
2007 circuit
->area
->area_tag
, level
,
2008 circuit
->interface
->name
);
2013 static int send_hello_cb(struct thread
*thread
)
2015 struct isis_circuit_arg
*arg
= THREAD_ARG(thread
);
2018 struct isis_circuit
*circuit
= arg
->circuit
;
2019 int level
= arg
->level
;
2023 if (circuit
->circ_type
== CIRCUIT_T_P2P
) {
2024 circuit
->u
.p2p
.t_send_p2p_hello
= NULL
;
2025 send_hello(circuit
, 1);
2026 send_hello_sched(circuit
, ISIS_LEVEL1
,
2027 1000 * circuit
->hello_interval
[1]);
2031 if (circuit
->circ_type
!= CIRCUIT_T_BROADCAST
) {
2032 zlog_warn("ISIS-Hello (%s): Trying to send hello on unknown circuit type %d",
2033 circuit
->area
->area_tag
, circuit
->circ_type
);
2034 return ISIS_WARNING
;
2037 circuit
->u
.bc
.t_send_lan_hello
[level
- 1] = NULL
;
2038 if (!(circuit
->is_type
& level
)) {
2039 zlog_warn("ISIS-Hello (%s): Trying to send L%d IIH in L%d-only circuit",
2040 circuit
->area
->area_tag
, level
, 3 - level
);
2041 return ISIS_WARNING
;
2044 if (circuit
->u
.bc
.run_dr_elect
[level
- 1])
2045 isis_dr_elect(circuit
, level
);
2047 int rv
= send_hello(circuit
, level
);
2049 /* set next timer thread */
2050 send_hello_sched(circuit
, level
, 1000 * circuit
->hello_interval
[level
- 1]);
2054 static void _send_hello_sched(struct isis_circuit
*circuit
,
2055 struct thread
**threadp
,
2056 int level
, long delay
)
2059 if (thread_timer_remain_msec(*threadp
) < (unsigned long)delay
)
2062 thread_cancel(threadp
);
2065 thread_add_timer_msec(master
, send_hello_cb
,
2066 &circuit
->level_arg
[level
- 1],
2067 isis_jitter(delay
, IIH_JITTER
),
2071 void send_hello_sched(struct isis_circuit
*circuit
, int level
, long delay
)
2073 if (circuit
->circ_type
== CIRCUIT_T_P2P
) {
2074 _send_hello_sched(circuit
, &circuit
->u
.p2p
.t_send_p2p_hello
,
2075 ISIS_LEVEL1
, delay
);
2079 if (circuit
->circ_type
!= CIRCUIT_T_BROADCAST
) {
2080 zlog_warn("%s: encountered unknown circuit type %d on %s",
2081 __func__
, circuit
->circ_type
,
2082 circuit
->interface
->name
);
2086 for (int loop_level
= ISIS_LEVEL1
; loop_level
<= ISIS_LEVEL2
; loop_level
++) {
2087 if (!(loop_level
& level
))
2092 &circuit
->u
.bc
.t_send_lan_hello
[loop_level
- 1],
2101 * Count the maximum number of lsps that can be accomodated by a given size.
2103 #define LSP_ENTRIES_LEN (10 + ISIS_SYS_ID_LEN)
2104 static uint16_t get_max_lsp_count(uint16_t size
)
2108 uint16_t remaining_size
;
2110 /* First count the full size TLVs */
2111 tlv_count
= size
/ MAX_LSP_ENTRIES_TLV_SIZE
;
2112 lsp_count
= tlv_count
* (MAX_LSP_ENTRIES_TLV_SIZE
/ LSP_ENTRIES_LEN
);
2114 /* The last TLV, if any */
2115 remaining_size
= size
% MAX_LSP_ENTRIES_TLV_SIZE
;
2116 if (remaining_size
- 2 >= LSP_ENTRIES_LEN
)
2117 lsp_count
+= (remaining_size
- 2) / LSP_ENTRIES_LEN
;
2122 int send_csnp(struct isis_circuit
*circuit
, int level
)
2124 if (lspdb_count(&circuit
->area
->lspdb
[level
- 1]) == 0)
2127 uint8_t pdu_type
= (level
== ISIS_LEVEL1
) ? L1_COMPLETE_SEQ_NUM
2128 : L2_COMPLETE_SEQ_NUM
;
2130 isis_circuit_stream(circuit
, &circuit
->snd_stream
);
2131 fill_fixed_hdr(pdu_type
, circuit
->snd_stream
);
2133 size_t len_pointer
= stream_get_endp(circuit
->snd_stream
);
2135 stream_putw(circuit
->snd_stream
, 0);
2136 stream_put(circuit
->snd_stream
, circuit
->isis
->sysid
, ISIS_SYS_ID_LEN
);
2137 /* with zero circuit id - ref 9.10, 9.11 */
2138 stream_putc(circuit
->snd_stream
, 0);
2140 size_t start_pointer
= stream_get_endp(circuit
->snd_stream
);
2141 stream_put(circuit
->snd_stream
, 0, ISIS_SYS_ID_LEN
+ 2);
2142 size_t end_pointer
= stream_get_endp(circuit
->snd_stream
);
2143 stream_put(circuit
->snd_stream
, 0, ISIS_SYS_ID_LEN
+ 2);
2145 struct isis_passwd
*passwd
= (level
== ISIS_LEVEL1
)
2146 ? &circuit
->area
->area_passwd
2147 : &circuit
->area
->domain_passwd
;
2149 struct isis_tlvs
*tlvs
= isis_alloc_tlvs();
2151 if (CHECK_FLAG(passwd
->snp_auth
, SNP_AUTH_SEND
))
2152 isis_tlvs_add_auth(tlvs
, passwd
);
2154 size_t tlv_start
= stream_get_endp(circuit
->snd_stream
);
2155 if (isis_pack_tlvs(tlvs
, circuit
->snd_stream
, len_pointer
, false,
2157 isis_free_tlvs(tlvs
);
2158 return ISIS_WARNING
;
2160 isis_free_tlvs(tlvs
);
2163 get_max_lsp_count(STREAM_WRITEABLE(circuit
->snd_stream
));
2165 uint8_t start
[ISIS_SYS_ID_LEN
+ 2];
2166 memset(start
, 0x00, ISIS_SYS_ID_LEN
+ 2);
2167 uint8_t stop
[ISIS_SYS_ID_LEN
+ 2];
2168 memset(stop
, 0xff, ISIS_SYS_ID_LEN
+ 2);
2172 tlvs
= isis_alloc_tlvs();
2173 if (CHECK_FLAG(passwd
->snp_auth
, SNP_AUTH_SEND
))
2174 isis_tlvs_add_auth(tlvs
, passwd
);
2176 struct isis_lsp
*last_lsp
;
2177 isis_tlvs_add_csnp_entries(tlvs
, start
, stop
, num_lsps
,
2178 &circuit
->area
->lspdb
[level
- 1],
2181 * Update the stop lsp_id before encoding this CSNP.
2183 if (tlvs
->lsp_entries
.count
< num_lsps
) {
2184 memset(stop
, 0xff, ISIS_SYS_ID_LEN
+ 2);
2186 memcpy(stop
, last_lsp
->hdr
.lsp_id
, sizeof(stop
));
2189 memcpy(STREAM_DATA(circuit
->snd_stream
) + start_pointer
, start
,
2190 ISIS_SYS_ID_LEN
+ 2);
2191 memcpy(STREAM_DATA(circuit
->snd_stream
) + end_pointer
, stop
,
2192 ISIS_SYS_ID_LEN
+ 2);
2193 stream_set_endp(circuit
->snd_stream
, tlv_start
);
2194 if (isis_pack_tlvs(tlvs
, circuit
->snd_stream
, len_pointer
,
2196 isis_free_tlvs(tlvs
);
2197 return ISIS_WARNING
;
2200 if (IS_DEBUG_SNP_PACKETS
) {
2202 "ISIS-Snp (%s): Sending L%d CSNP on %s, length %zd",
2203 circuit
->area
->area_tag
, level
,
2204 circuit
->interface
->name
,
2205 stream_get_endp(circuit
->snd_stream
));
2206 log_multiline(LOG_DEBUG
, " ", "%s",
2207 isis_format_tlvs(tlvs
));
2208 if (IS_DEBUG_PACKET_DUMP
)
2210 STREAM_DATA(circuit
->snd_stream
),
2211 stream_get_endp(circuit
->snd_stream
));
2214 pdu_counter_count(circuit
->area
->pdu_tx_counters
, pdu_type
);
2215 int retval
= circuit
->tx(circuit
, level
);
2216 if (retval
!= ISIS_OK
) {
2217 flog_err(EC_ISIS_PACKET
,
2218 "ISIS-Snp (%s): Send L%d CSNP on %s failed",
2219 circuit
->area
->area_tag
, level
,
2220 circuit
->interface
->name
);
2221 isis_free_tlvs(tlvs
);
2226 * Start lsp_id of the next CSNP should be one plus the
2227 * stop lsp_id in this current CSNP.
2229 memcpy(start
, stop
, ISIS_SYS_ID_LEN
+ 2);
2231 for (int i
= ISIS_SYS_ID_LEN
+ 1; i
>= 0; --i
) {
2232 if (start
[i
] < (uint8_t)0xff) {
2238 memset(stop
, 0xff, ISIS_SYS_ID_LEN
+ 2);
2239 isis_free_tlvs(tlvs
);
2245 int send_l1_csnp(struct thread
*thread
)
2247 struct isis_circuit
*circuit
;
2249 circuit
= THREAD_ARG(thread
);
2252 circuit
->t_send_csnp
[0] = NULL
;
2254 if ((circuit
->circ_type
== CIRCUIT_T_BROADCAST
2255 && circuit
->u
.bc
.is_dr
[0])
2256 || circuit
->circ_type
== CIRCUIT_T_P2P
) {
2257 send_csnp(circuit
, 1);
2259 /* set next timer thread */
2260 thread_add_timer(master
, send_l1_csnp
, circuit
,
2261 isis_jitter(circuit
->csnp_interval
[0], CSNP_JITTER
),
2262 &circuit
->t_send_csnp
[0]);
2267 int send_l2_csnp(struct thread
*thread
)
2269 struct isis_circuit
*circuit
;
2271 circuit
= THREAD_ARG(thread
);
2274 circuit
->t_send_csnp
[1] = NULL
;
2276 if ((circuit
->circ_type
== CIRCUIT_T_BROADCAST
2277 && circuit
->u
.bc
.is_dr
[1])
2278 || circuit
->circ_type
== CIRCUIT_T_P2P
) {
2279 send_csnp(circuit
, 2);
2281 /* set next timer thread */
2282 thread_add_timer(master
, send_l2_csnp
, circuit
,
2283 isis_jitter(circuit
->csnp_interval
[1], CSNP_JITTER
),
2284 &circuit
->t_send_csnp
[1]);
2290 * 7.3.15.4 action on expiration of partial SNP interval
2293 static int send_psnp(int level
, struct isis_circuit
*circuit
)
2295 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
2296 && circuit
->u
.bc
.is_dr
[level
- 1])
2299 if (lspdb_count(&circuit
->area
->lspdb
[level
- 1]) == 0)
2302 if (!circuit
->snd_stream
)
2305 uint8_t pdu_type
= (level
== ISIS_LEVEL1
) ? L1_PARTIAL_SEQ_NUM
2306 : L2_PARTIAL_SEQ_NUM
;
2308 isis_circuit_stream(circuit
, &circuit
->snd_stream
);
2309 fill_fixed_hdr(pdu_type
, circuit
->snd_stream
);
2311 size_t len_pointer
= stream_get_endp(circuit
->snd_stream
);
2312 stream_putw(circuit
->snd_stream
, 0); /* length is filled in later */
2313 stream_put(circuit
->snd_stream
, circuit
->isis
->sysid
, ISIS_SYS_ID_LEN
);
2314 stream_putc(circuit
->snd_stream
, circuit
->idx
);
2316 struct isis_passwd
*passwd
= (level
== ISIS_LEVEL1
)
2317 ? &circuit
->area
->area_passwd
2318 : &circuit
->area
->domain_passwd
;
2320 struct isis_tlvs
*tlvs
= isis_alloc_tlvs();
2322 if (CHECK_FLAG(passwd
->snp_auth
, SNP_AUTH_SEND
))
2323 isis_tlvs_add_auth(tlvs
, passwd
);
2325 size_t tlv_start
= stream_get_endp(circuit
->snd_stream
);
2326 if (isis_pack_tlvs(tlvs
, circuit
->snd_stream
, len_pointer
, false,
2328 isis_free_tlvs(tlvs
);
2329 return ISIS_WARNING
;
2331 isis_free_tlvs(tlvs
);
2334 get_max_lsp_count(STREAM_WRITEABLE(circuit
->snd_stream
));
2337 struct isis_lsp
*lsp
;
2339 tlvs
= isis_alloc_tlvs();
2340 if (CHECK_FLAG(passwd
->snp_auth
, SNP_AUTH_SEND
))
2341 isis_tlvs_add_auth(tlvs
, passwd
);
2343 frr_each (lspdb
, &circuit
->area
->lspdb
[level
- 1], lsp
) {
2344 if (ISIS_CHECK_FLAG(lsp
->SSNflags
, circuit
))
2345 isis_tlvs_add_lsp_entry(tlvs
, lsp
);
2347 if (tlvs
->lsp_entries
.count
== num_lsps
)
2351 if (!tlvs
->lsp_entries
.count
) {
2352 isis_free_tlvs(tlvs
);
2356 stream_set_endp(circuit
->snd_stream
, tlv_start
);
2357 if (isis_pack_tlvs(tlvs
, circuit
->snd_stream
, len_pointer
,
2359 isis_free_tlvs(tlvs
);
2360 return ISIS_WARNING
;
2363 if (IS_DEBUG_SNP_PACKETS
) {
2365 "ISIS-Snp (%s): Sending L%d PSNP on %s, length %zd",
2366 circuit
->area
->area_tag
, level
,
2367 circuit
->interface
->name
,
2368 stream_get_endp(circuit
->snd_stream
));
2369 log_multiline(LOG_DEBUG
, " ", "%s",
2370 isis_format_tlvs(tlvs
));
2371 if (IS_DEBUG_PACKET_DUMP
)
2373 STREAM_DATA(circuit
->snd_stream
),
2374 stream_get_endp(circuit
->snd_stream
));
2377 pdu_counter_count(circuit
->area
->pdu_tx_counters
, pdu_type
);
2378 int retval
= circuit
->tx(circuit
, level
);
2379 if (retval
!= ISIS_OK
) {
2380 flog_err(EC_ISIS_PACKET
,
2381 "ISIS-Snp (%s): Send L%d PSNP on %s failed",
2382 circuit
->area
->area_tag
, level
,
2383 circuit
->interface
->name
);
2384 isis_free_tlvs(tlvs
);
2389 * sending succeeded, we can clear SSN flags of this circuit
2390 * for the LSPs in list
2392 struct isis_lsp_entry
*entry_head
;
2393 entry_head
= (struct isis_lsp_entry
*)tlvs
->lsp_entries
.head
;
2394 for (struct isis_lsp_entry
*entry
= entry_head
; entry
;
2395 entry
= entry
->next
)
2396 ISIS_CLEAR_FLAG(entry
->lsp
->SSNflags
, circuit
);
2397 isis_free_tlvs(tlvs
);
2403 int send_l1_psnp(struct thread
*thread
)
2406 struct isis_circuit
*circuit
;
2408 circuit
= THREAD_ARG(thread
);
2411 circuit
->t_send_psnp
[0] = NULL
;
2413 send_psnp(1, circuit
);
2414 /* set next timer thread */
2415 thread_add_timer(master
, send_l1_psnp
, circuit
,
2416 isis_jitter(circuit
->psnp_interval
[0], PSNP_JITTER
),
2417 &circuit
->t_send_psnp
[0]);
2423 * 7.3.15.4 action on expiration of partial SNP interval
2426 int send_l2_psnp(struct thread
*thread
)
2428 struct isis_circuit
*circuit
;
2430 circuit
= THREAD_ARG(thread
);
2433 circuit
->t_send_psnp
[1] = NULL
;
2435 send_psnp(2, circuit
);
2437 /* set next timer thread */
2438 thread_add_timer(master
, send_l2_psnp
, circuit
,
2439 isis_jitter(circuit
->psnp_interval
[1], PSNP_JITTER
),
2440 &circuit
->t_send_psnp
[1]);
2446 * ISO 10589 - 7.3.14.3
2448 void send_lsp(struct isis_circuit
*circuit
, struct isis_lsp
*lsp
,
2449 enum isis_tx_type tx_type
)
2452 int retval
= ISIS_OK
;
2454 if (circuit
->state
!= C_STATE_UP
|| circuit
->is_passive
== 1)
2458 * Do not send if levels do not match
2460 if (!(lsp
->level
& circuit
->is_type
))
2464 * Do not send if we do not have adjacencies in state up on the circuit
2466 if (circuit
->upadjcount
[lsp
->level
- 1] == 0)
2469 /* stream_copy will assert and stop program execution if LSP is larger
2471 * the circuit's MTU. So handle and log this case here. */
2472 if (stream_get_endp(lsp
->pdu
) > stream_get_size(circuit
->snd_stream
)) {
2475 "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.",
2476 circuit
->area
->area_tag
, lsp
->level
,
2477 rawlspid_print(lsp
->hdr
.lsp_id
), lsp
->hdr
.seqno
,
2478 lsp
->hdr
.checksum
, lsp
->hdr
.rem_lifetime
,
2479 circuit
->interface
->name
, stream_get_endp(lsp
->pdu
),
2480 stream_get_size(circuit
->snd_stream
));
2482 /* send a northbound notification */
2483 isis_notif_lsp_too_large(circuit
, stream_get_endp(lsp
->pdu
),
2485 #endif /* ifndef FABRICD */
2486 if (IS_DEBUG_PACKET_DUMP
)
2487 zlog_dump_data(STREAM_DATA(lsp
->pdu
),
2488 stream_get_endp(lsp
->pdu
));
2489 retval
= ISIS_ERROR
;
2493 /* copy our lsp to the send buffer */
2494 stream_copy(circuit
->snd_stream
, lsp
->pdu
);
2496 if (tx_type
== TX_LSP_CIRCUIT_SCOPED
) {
2497 stream_putc_at(circuit
->snd_stream
, 4, FS_LINK_STATE
);
2498 stream_putc_at(circuit
->snd_stream
, 7,
2499 L2_CIRCUIT_FLOODING_SCOPE
);
2502 if (IS_DEBUG_UPDATE_PACKETS
) {
2503 zlog_debug("ISIS-Upd (%s): Sending %sL%d LSP %s, seq 0x%08x, cksum 0x%04hx, lifetime %hus on %s",
2504 circuit
->area
->area_tag
,
2505 (tx_type
== TX_LSP_CIRCUIT_SCOPED
)
2506 ? "Circuit scoped " : "",
2508 rawlspid_print(lsp
->hdr
.lsp_id
), lsp
->hdr
.seqno
,
2509 lsp
->hdr
.checksum
, lsp
->hdr
.rem_lifetime
,
2510 circuit
->interface
->name
);
2511 if (IS_DEBUG_PACKET_DUMP
)
2512 zlog_dump_data(STREAM_DATA(circuit
->snd_stream
),
2513 stream_get_endp(circuit
->snd_stream
));
2516 uint8_t pdu_type
= (tx_type
== TX_LSP_CIRCUIT_SCOPED
) ? FS_LINK_STATE
2517 : (lsp
->level
== ISIS_LEVEL1
) ? L1_LINK_STATE
2521 pdu_counter_count(circuit
->area
->pdu_tx_counters
, pdu_type
);
2522 retval
= circuit
->tx(circuit
, lsp
->level
);
2523 if (retval
!= ISIS_OK
) {
2524 flog_err(EC_ISIS_PACKET
,
2525 "ISIS-Upd (%s): Send L%d LSP on %s failed %s",
2526 circuit
->area
->area_tag
, lsp
->level
,
2527 circuit
->interface
->name
,
2528 (retval
== ISIS_WARNING
) ? "temporarily"
2534 || (retval
== ISIS_OK
&& circuit
->circ_type
== CIRCUIT_T_BROADCAST
)
2535 || (retval
!= ISIS_OK
&& retval
!= ISIS_WARNING
)) {
2536 /* SRM flag will trigger retransmission. We will not retransmit
2538 * encountered a fatal error.
2539 * On success, they should only be cleared if it's a broadcast
2541 * On a P2P circuit, we will wait for the ack from the neighbor
2545 isis_tx_queue_del(circuit
->tx_queue
, lsp
);