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
);
77 stream_putw(circuit
->snd_stream
, 0); /* PDU length */
78 stream_put(circuit
->snd_stream
, isis
->sysid
, ISIS_SYS_ID_LEN
);
79 stream_putc(circuit
->snd_stream
, circuit
->idx
);
80 stream_putc(circuit
->snd_stream
, 9); /* code */
81 stream_putc(circuit
->snd_stream
, 16); /* len */
83 stream_putw(circuit
->snd_stream
, hdr
->rem_lifetime
);
84 stream_put(circuit
->snd_stream
, hdr
->lsp_id
, ISIS_SYS_ID_LEN
+ 2);
85 stream_putl(circuit
->snd_stream
, hdr
->seqno
);
86 stream_putw(circuit
->snd_stream
, hdr
->checksum
);
88 length
= (uint16_t)stream_get_endp(circuit
->snd_stream
);
89 /* Update PDU length */
90 stream_putw_at(circuit
->snd_stream
, lenp
, length
);
92 pdu_counter_count(circuit
->area
->pdu_tx_counters
, pdu_type
);
93 retval
= circuit
->tx(circuit
, level
);
94 if (retval
!= ISIS_OK
)
95 flog_err(EC_ISIS_PACKET
,
96 "ISIS-Upd (%s): Send L%d LSP PSNP on %s failed",
97 circuit
->area
->area_tag
, level
,
98 circuit
->interface
->name
);
108 struct isis_circuit
*circuit
;
113 uint8_t sys_id
[ISIS_SYS_ID_LEN
];
120 uint8_t dis
[ISIS_SYS_ID_LEN
+ 1];
125 struct isis_tlvs
*tlvs
;
128 static int process_p2p_hello(struct iih_info
*iih
)
130 struct isis_threeway_adj
*tw_adj
= iih
->tlvs
->threeway_adj
;
132 if (tw_adj
->state
> ISIS_THREEWAY_DOWN
) {
133 if (IS_DEBUG_ADJ_PACKETS
) {
134 zlog_debug("ISIS-Adj (%s): Rcvd P2P IIH from (%s) with invalid three-way state: %d",
135 iih
->circuit
->area
->area_tag
,
136 iih
->circuit
->interface
->name
,
142 if (tw_adj
->neighbor_set
143 && (memcmp(tw_adj
->neighbor_id
, isis
->sysid
, ISIS_SYS_ID_LEN
)
144 || tw_adj
->neighbor_circuit_id
!= (uint32_t) iih
->circuit
->idx
)) {
146 if (IS_DEBUG_ADJ_PACKETS
) {
147 zlog_debug("ISIS-Adj (%s): Rcvd P2P IIH from (%s) which lists IS/Circuit different from us as neighbor.",
148 iih
->circuit
->area
->area_tag
,
149 iih
->circuit
->interface
->name
);
157 * My interpertation of the ISO, if no adj exists we will create one for
160 struct isis_adjacency
*adj
= iih
->circuit
->u
.p2p
.neighbor
;
161 /* If an adjacency exists, check it is with the source of the hello
164 if (memcmp(iih
->sys_id
, adj
->sysid
, ISIS_SYS_ID_LEN
)) {
166 "hello source and adjacency do not match, set adj down\n");
167 isis_adj_state_change(&adj
, ISIS_ADJ_DOWN
,
172 if (!adj
|| adj
->level
!= iih
->circ_type
) {
174 adj
= isis_new_adj(iih
->sys_id
, NULL
, iih
->circ_type
,
177 adj
->level
= iih
->circ_type
;
179 iih
->circuit
->u
.p2p
.neighbor
= adj
;
180 /* Build lsp with the new neighbor entry when a new
181 * adjacency is formed. Set adjacency circuit type to
182 * IIH PDU header circuit type before lsp is regenerated
183 * when an adjacency is up. This will result in the new
184 * adjacency entry getting added to the lsp tlv neighbor list.
186 adj
->circuit_t
= iih
->circ_type
;
187 isis_adj_state_change(&adj
, ISIS_ADJ_INITIALIZING
, NULL
);
188 adj
->sys_type
= ISIS_SYSTYPE_UNKNOWN
;
192 adj
->ext_circuit_id
= tw_adj
->local_circuit_id
;
194 /* 8.2.6 Monitoring point-to-point adjacencies */
195 adj
->hold_time
= iih
->holdtime
;
196 adj
->last_upd
= time(NULL
);
199 isis_tlvs_to_adj(iih
->tlvs
, adj
, &changed
);
200 changed
|= tlvs_to_adj_mt_set(iih
->tlvs
, iih
->v4_usable
, iih
->v6_usable
,
203 /* lets take care of the expiry */
204 THREAD_TIMER_OFF(adj
->t_expire
);
205 thread_add_timer(master
, isis_adj_expire
, adj
, (long)adj
->hold_time
,
208 /* While fabricds initial sync is in progress, ignore hellos from other
209 * interfaces than the one we are performing the initial sync on. */
210 if (fabricd_initial_sync_is_in_progress(iih
->circuit
->area
)
211 && fabricd_initial_sync_circuit(iih
->circuit
->area
) != iih
->circuit
)
214 /* 8.2.5.2 a) a match was detected */
215 if (isis_tlvs_area_addresses_match(iih
->tlvs
,
216 iih
->circuit
->area
->area_addrs
)) {
217 /* 8.2.5.2 a) 2) If the system is L1 - table 5 */
218 if (iih
->circuit
->area
->is_type
== IS_LEVEL_1
) {
219 switch (iih
->circ_type
) {
221 case IS_LEVEL_1_AND_2
:
222 if (adj
->adj_state
!= ISIS_ADJ_UP
223 || adj
->adj_usage
== ISIS_ADJ_LEVEL1
) {
224 isis_adj_process_threeway(adj
, tw_adj
,
229 if (adj
->adj_state
!= ISIS_ADJ_UP
) {
230 /* (7) reject - wrong system type event
232 zlog_warn("wrongSystemType");
234 } else if (adj
->adj_usage
== ISIS_ADJ_LEVEL1
) {
235 /* (6) down - wrong system */
236 isis_adj_state_change(&adj
,
244 /* 8.2.5.2 a) 3) If the system is L1L2 - table 6 */
245 if (iih
->circuit
->area
->is_type
== IS_LEVEL_1_AND_2
) {
246 switch (iih
->circ_type
) {
248 if (adj
->adj_state
!= ISIS_ADJ_UP
249 || adj
->adj_usage
== ISIS_ADJ_LEVEL1
) {
250 isis_adj_process_threeway(adj
, tw_adj
,
252 } else if ((adj
->adj_usage
253 == ISIS_ADJ_LEVEL1AND2
)
255 == ISIS_ADJ_LEVEL2
)) {
256 /* (8) down - wrong system */
257 isis_adj_state_change(&adj
,
263 if (adj
->adj_state
!= ISIS_ADJ_UP
264 || adj
->adj_usage
== ISIS_ADJ_LEVEL2
) {
265 isis_adj_process_threeway(adj
, tw_adj
,
267 } else if ((adj
->adj_usage
== ISIS_ADJ_LEVEL1
)
269 == ISIS_ADJ_LEVEL1AND2
)) {
270 /* (8) down - wrong system */
271 isis_adj_state_change(&adj
,
276 case IS_LEVEL_1_AND_2
:
277 if (adj
->adj_state
!= ISIS_ADJ_UP
278 || adj
->adj_usage
== ISIS_ADJ_LEVEL1AND2
) {
279 isis_adj_process_threeway(adj
, tw_adj
,
280 ISIS_ADJ_LEVEL1AND2
);
281 } else if ((adj
->adj_usage
== ISIS_ADJ_LEVEL1
)
283 == ISIS_ADJ_LEVEL2
)) {
284 /* (8) down - wrong system */
285 isis_adj_state_change(&adj
,
293 /* 8.2.5.2 a) 4) If the system is L2 - table 7 */
294 if (iih
->circuit
->area
->is_type
== IS_LEVEL_2
) {
295 switch (iih
->circ_type
) {
297 if (adj
->adj_state
!= ISIS_ADJ_UP
) {
298 /* (5) reject - wrong system type event
300 zlog_warn("wrongSystemType");
302 } else if ((adj
->adj_usage
303 == ISIS_ADJ_LEVEL1AND2
)
305 == ISIS_ADJ_LEVEL2
)) {
306 /* (6) down - wrong system */
307 isis_adj_state_change(&adj
,
312 case IS_LEVEL_1_AND_2
:
314 if (adj
->adj_state
!= ISIS_ADJ_UP
315 || adj
->adj_usage
== ISIS_ADJ_LEVEL2
) {
316 isis_adj_process_threeway(adj
, tw_adj
,
318 } else if (adj
->adj_usage
319 == ISIS_ADJ_LEVEL1AND2
) {
320 /* (6) down - wrong system */
321 isis_adj_state_change(&adj
,
329 /* 8.2.5.2 b) if no match was detected */
330 else if (listcount(iih
->circuit
->area
->area_addrs
) > 0) {
331 if (iih
->circuit
->area
->is_type
== IS_LEVEL_1
) {
332 /* 8.2.5.2 b) 1) is_type L1 and adj is not up */
333 if (adj
->adj_state
!= ISIS_ADJ_UP
) {
334 isis_adj_state_change(&adj
, ISIS_ADJ_DOWN
,
336 /* 8.2.5.2 b) 2)is_type L1 and adj is up */
338 isis_adj_state_change(&adj
, ISIS_ADJ_DOWN
,
339 "Down - Area Mismatch");
342 /* 8.2.5.2 b 3 If the system is L2 or L1L2 - table 8 */
344 switch (iih
->circ_type
) {
346 if (adj
->adj_state
!= ISIS_ADJ_UP
) {
347 /* (6) reject - Area Mismatch event */
348 zlog_warn("AreaMismatch");
350 } else if (adj
->adj_usage
== ISIS_ADJ_LEVEL1
) {
351 /* (7) down - area mismatch */
352 isis_adj_state_change(&adj
,
356 } else if ((adj
->adj_usage
357 == ISIS_ADJ_LEVEL1AND2
)
359 == ISIS_ADJ_LEVEL2
)) {
360 /* (7) down - wrong system */
361 isis_adj_state_change(&adj
,
366 case IS_LEVEL_1_AND_2
:
368 if (adj
->adj_state
!= ISIS_ADJ_UP
369 || adj
->adj_usage
== ISIS_ADJ_LEVEL2
) {
370 isis_adj_process_threeway(adj
, tw_adj
,
372 } else if (adj
->adj_usage
== ISIS_ADJ_LEVEL1
) {
373 /* (7) down - wrong system */
374 isis_adj_state_change(&adj
,
377 } else if (adj
->adj_usage
378 == ISIS_ADJ_LEVEL1AND2
) {
379 if (iih
->circ_type
== IS_LEVEL_2
) {
380 /* (7) down - wrong system */
381 isis_adj_state_change(
385 /* (7) down - area mismatch */
386 isis_adj_state_change(
395 /* down - area mismatch */
396 isis_adj_state_change(&adj
, ISIS_ADJ_DOWN
, "Area Mismatch");
400 if (adj
->adj_state
== ISIS_ADJ_UP
&& changed
) {
401 lsp_regenerate_schedule(
403 isis_adj_usage2levels(adj
->adj_usage
), 0);
406 /* 8.2.5.2 c) if the action was up - comparing circuit IDs */
407 /* FIXME - Missing parts */
409 /* some of my own understanding of the ISO, why the heck does
410 * it not say what should I change the system_type to...
412 switch (adj
->adj_usage
) {
413 case ISIS_ADJ_LEVEL1
:
414 adj
->sys_type
= ISIS_SYSTYPE_L1_IS
;
416 case ISIS_ADJ_LEVEL2
:
417 adj
->sys_type
= ISIS_SYSTYPE_L2_IS
;
419 case ISIS_ADJ_LEVEL1AND2
:
420 adj
->sys_type
= ISIS_SYSTYPE_L2_IS
;
423 adj
->sys_type
= ISIS_SYSTYPE_UNKNOWN
;
428 if (IS_DEBUG_ADJ_PACKETS
) {
430 "ISIS-Adj (%s): Rcvd P2P IIH from (%s), cir type %s, cir id %hhu, length %hu",
431 iih
->circuit
->area
->area_tag
,
432 iih
->circuit
->interface
->name
,
433 circuit_t2string(iih
->circuit
->is_type
),
434 iih
->circuit
->circuit_id
, iih
->pdu_len
);
440 static int process_lan_hello(struct iih_info
*iih
)
442 struct isis_adjacency
*adj
;
443 adj
= isis_adj_lookup(iih
->sys_id
,
444 iih
->circuit
->u
.bc
.adjdb
[iih
->level
- 1]);
445 if ((adj
== NULL
) || (memcmp(adj
->snpa
, iih
->ssnpa
, ETH_ALEN
))
446 || (adj
->level
!= iih
->level
)) {
448 /* Do as in 8.4.2.5 */
449 adj
= isis_new_adj(iih
->sys_id
, iih
->ssnpa
, iih
->level
,
453 memcpy(adj
->snpa
, iih
->ssnpa
, 6);
455 memset(adj
->snpa
, ' ', 6);
457 adj
->level
= iih
->level
;
459 isis_adj_state_change(&adj
, ISIS_ADJ_INITIALIZING
, NULL
);
461 if (iih
->level
== IS_LEVEL_1
)
462 adj
->sys_type
= ISIS_SYSTYPE_L1_IS
;
464 adj
->sys_type
= ISIS_SYSTYPE_L2_IS
;
465 list_delete_all_node(
466 iih
->circuit
->u
.bc
.lan_neighs
[iih
->level
- 1]);
467 isis_adj_build_neigh_list(
468 iih
->circuit
->u
.bc
.adjdb
[iih
->level
- 1],
469 iih
->circuit
->u
.bc
.lan_neighs
[iih
->level
- 1]);
472 if (adj
->dis_record
[iih
->level
- 1].dis
== ISIS_IS_DIS
) {
473 uint8_t *dis
= (iih
->level
== 1)
474 ? iih
->circuit
->u
.bc
.l1_desig_is
475 : iih
->circuit
->u
.bc
.l2_desig_is
;
477 if (memcmp(dis
, iih
->dis
, ISIS_SYS_ID_LEN
+ 1)) {
478 thread_add_event(master
, isis_event_dis_status_change
,
479 iih
->circuit
, 0, NULL
);
480 memcpy(dis
, iih
->dis
, ISIS_SYS_ID_LEN
+ 1);
484 adj
->circuit_t
= iih
->circ_type
;
485 adj
->hold_time
= iih
->holdtime
;
486 adj
->last_upd
= time(NULL
);
487 adj
->prio
[iih
->level
- 1] = iih
->priority
;
488 memcpy(adj
->lanid
, iih
->dis
, ISIS_SYS_ID_LEN
+ 1);
491 isis_tlvs_to_adj(iih
->tlvs
, adj
, &changed
);
492 changed
|= tlvs_to_adj_mt_set(iih
->tlvs
, iih
->v4_usable
, iih
->v6_usable
,
495 /* lets take care of the expiry */
496 THREAD_TIMER_OFF(adj
->t_expire
);
497 thread_add_timer(master
, isis_adj_expire
, adj
, (long)adj
->hold_time
,
501 * If the snpa for this circuit is found from LAN Neighbours TLV
502 * we have two-way communication -> adjacency can be put to state "up"
504 bool own_snpa_found
=
505 isis_tlvs_own_snpa_found(iih
->tlvs
, iih
->circuit
->u
.bc
.snpa
);
507 if (adj
->adj_state
!= ISIS_ADJ_UP
) {
508 if (own_snpa_found
) {
509 isis_adj_state_change(
511 "own SNPA found in LAN Neighbours TLV");
514 if (!own_snpa_found
) {
515 isis_adj_state_change(
516 &adj
, ISIS_ADJ_INITIALIZING
,
517 "own SNPA not found in LAN Neighbours TLV");
521 if (adj
->adj_state
== ISIS_ADJ_UP
&& changed
)
522 lsp_regenerate_schedule(adj
->circuit
->area
, iih
->level
, 0);
524 if (IS_DEBUG_ADJ_PACKETS
) {
526 "ISIS-Adj (%s): Rcvd L%d LAN IIH from %s on %s, cirType %s, cirID %u, length %zd",
527 iih
->circuit
->area
->area_tag
, iih
->level
,
528 snpa_print(iih
->ssnpa
), iih
->circuit
->interface
->name
,
529 circuit_t2string(iih
->circuit
->is_type
),
530 iih
->circuit
->circuit_id
,
531 stream_get_endp(iih
->circuit
->rcv_stream
));
536 static int pdu_len_validate(uint16_t pdu_len
, struct isis_circuit
*circuit
)
538 if (pdu_len
< stream_get_getp(circuit
->rcv_stream
)
539 || pdu_len
> ISO_MTU(circuit
)
540 || pdu_len
> stream_get_endp(circuit
->rcv_stream
))
543 if (pdu_len
< stream_get_endp(circuit
->rcv_stream
))
544 stream_set_endp(circuit
->rcv_stream
, pdu_len
);
548 static int process_hello(uint8_t pdu_type
, struct isis_circuit
*circuit
,
551 /* keep a copy of the raw pdu for NB notifications */
552 size_t pdu_start
= stream_get_getp(circuit
->rcv_stream
);
553 size_t pdu_end
= stream_get_endp(circuit
->rcv_stream
);
554 char raw_pdu
[pdu_end
- pdu_start
];
555 bool p2p_hello
= (pdu_type
== P2P_HELLO
);
556 int level
= p2p_hello
? 0
557 : (pdu_type
== L1_LAN_HELLO
) ? ISIS_LEVEL1
559 const char *pdu_name
=
562 : (level
== ISIS_LEVEL1
) ? "L1 LAN IIH" : "L2 LAN IIH";
565 stream_get_from(raw_pdu
, circuit
->rcv_stream
, pdu_start
,
566 pdu_end
- pdu_start
);
567 if (IS_DEBUG_ADJ_PACKETS
) {
568 zlog_debug("ISIS-Adj (%s): Rcvd %s on %s, cirType %s, cirID %u",
569 circuit
->area
->area_tag
, pdu_name
,
570 circuit
->interface
->name
,
571 circuit_t2string(circuit
->is_type
),
572 circuit
->circuit_id
);
573 if (IS_DEBUG_PACKET_DUMP
)
574 zlog_dump_data(STREAM_DATA(circuit
->rcv_stream
),
575 stream_get_endp(circuit
->rcv_stream
));
579 if (circuit
->circ_type
!= CIRCUIT_T_P2P
) {
580 zlog_warn("p2p hello on non p2p circuit");
581 circuit
->rej_adjacencies
++;
583 isis_notif_reject_adjacency(
584 circuit
, "p2p hello on non p2p circuit",
586 #endif /* ifndef FABRICD */
590 if (circuit
->circ_type
!= CIRCUIT_T_BROADCAST
) {
591 zlog_warn("lan hello on non broadcast circuit");
592 circuit
->rej_adjacencies
++;
594 isis_notif_reject_adjacency(
595 circuit
, "lan hello on non broadcast circuit",
597 #endif /* ifndef FABRICD */
601 if (circuit
->ext_domain
) {
603 "level %d LAN Hello received over circuit with externalDomain = true",
605 circuit
->rej_adjacencies
++;
607 isis_notif_reject_adjacency(
609 "LAN Hello received over circuit with externalDomain = true",
611 #endif /* ifndef FABRICD */
615 if (!(circuit
->is_type
& level
)) {
616 if (IS_DEBUG_ADJ_PACKETS
) {
618 "ISIS-Adj (%s): Interface level mismatch, %s",
619 circuit
->area
->area_tag
,
620 circuit
->interface
->name
);
622 circuit
->rej_adjacencies
++;
624 isis_notif_reject_adjacency(
625 circuit
, "Interface level mismatch", raw_pdu
);
626 #endif /* ifndef FABRICD */
631 struct iih_info iih
= {
632 .circuit
= circuit
, .ssnpa
= ssnpa
, .level
= level
};
634 /* Generic IIH Header */
635 iih
.circ_type
= stream_getc(circuit
->rcv_stream
) & 0x03;
636 stream_get(iih
.sys_id
, circuit
->rcv_stream
, ISIS_SYS_ID_LEN
);
637 iih
.holdtime
= stream_getw(circuit
->rcv_stream
);
638 iih
.pdu_len
= stream_getw(circuit
->rcv_stream
);
641 iih
.circuit_id
= stream_getc(circuit
->rcv_stream
);
643 iih
.priority
= stream_getc(circuit
->rcv_stream
);
644 stream_get(iih
.dis
, circuit
->rcv_stream
, ISIS_SYS_ID_LEN
+ 1);
647 if (pdu_len_validate(iih
.pdu_len
, circuit
)) {
649 "ISIS-Adj (%s): Rcvd %s from (%s) with invalid pdu length %hu",
650 circuit
->area
->area_tag
, pdu_name
,
651 circuit
->interface
->name
, iih
.pdu_len
);
652 circuit
->rej_adjacencies
++;
654 isis_notif_reject_adjacency(circuit
, "Invalid PDU length",
656 #endif /* ifndef FABRICD */
660 if (!p2p_hello
&& !(level
& iih
.circ_type
)) {
661 flog_err(EC_ISIS_PACKET
,
662 "Level %d LAN Hello with Circuit Type %d", level
,
664 circuit
->rej_adjacencies
++;
666 isis_notif_reject_adjacency(
667 circuit
, "LAN Hello with wrong IS-level", raw_pdu
);
668 #endif /* ifndef FABRICD */
672 const char *error_log
;
673 int retval
= ISIS_WARNING
;
675 if (isis_unpack_tlvs(STREAM_READABLE(circuit
->rcv_stream
),
676 circuit
->rcv_stream
, &iih
.tlvs
, &error_log
)) {
677 zlog_warn("isis_unpack_tlvs() failed: %s", error_log
);
678 circuit
->rej_adjacencies
++;
680 isis_notif_reject_adjacency(circuit
, "Failed to unpack TLVs",
682 #endif /* ifndef FABRICD */
686 if (!iih
.tlvs
->area_addresses
.count
) {
687 zlog_warn("No Area addresses TLV in %s", pdu_name
);
689 /* send northbound notification */
690 isis_notif_area_mismatch(circuit
, raw_pdu
);
691 #endif /* ifndef FABRICD */
695 if (!iih
.tlvs
->protocols_supported
.count
) {
696 zlog_warn("No supported protocols TLV in %s", pdu_name
);
697 circuit
->rej_adjacencies
++;
699 isis_notif_reject_adjacency(
700 circuit
, "No supported protocols TLV", raw_pdu
);
701 #endif /* ifndef FABRICD */
705 int auth_code
= isis_tlvs_auth_is_valid(iih
.tlvs
, &circuit
->passwd
,
706 circuit
->rcv_stream
, false);
707 if (auth_code
!= ISIS_AUTH_OK
) {
708 isis_event_auth_failure(circuit
->area
->area_tag
,
709 "IIH authentication failure",
712 /* send northbound notification */
713 stream_get_from(raw_pdu
, circuit
->rcv_stream
, pdu_start
,
714 pdu_end
- pdu_start
);
715 if (auth_code
== ISIS_AUTH_FAILURE
) {
716 circuit
->auth_failures
++;
717 isis_notif_authentication_failure(circuit
, raw_pdu
);
718 } else { /* AUTH_TYPE_FAILURE or NO_VALIDATOR */
719 circuit
->auth_type_failures
++;
720 isis_notif_authentication_type_failure(circuit
,
723 #endif /* ifndef FABRICD */
727 if (!memcmp(iih
.sys_id
, isis
->sysid
, ISIS_SYS_ID_LEN
)) {
729 "ISIS-Adj (%s): Received IIH with own sysid - discard",
730 circuit
->area
->area_tag
);
731 circuit
->rej_adjacencies
++;
733 isis_notif_reject_adjacency(
734 circuit
, "Received IIH with our own sysid", raw_pdu
);
735 #endif /* ifndef FABRICD */
740 && (listcount(circuit
->area
->area_addrs
) == 0
741 || (level
== ISIS_LEVEL1
742 && !isis_tlvs_area_addresses_match(
743 iih
.tlvs
, circuit
->area
->area_addrs
)))) {
744 if (IS_DEBUG_ADJ_PACKETS
) {
746 "ISIS-Adj (%s): Area mismatch, level %d IIH on %s",
747 circuit
->area
->area_tag
, level
,
748 circuit
->interface
->name
);
751 /* send northbound notification */
752 isis_notif_area_mismatch(circuit
, raw_pdu
);
753 #endif /* ifndef FABRICD */
757 iih
.v4_usable
= (fabricd_ip_addrs(circuit
)
758 && iih
.tlvs
->ipv4_address
.count
);
760 iih
.v6_usable
= (circuit
->ipv6_link
&& listcount(circuit
->ipv6_link
)
761 && iih
.tlvs
->ipv6_address
.count
);
763 if (!iih
.v4_usable
&& !iih
.v6_usable
) {
764 if (IS_DEBUG_ADJ_PACKETS
) {
766 "ISIS-Adj (%s): Neither IPv4 nor IPv6 considered usable. Ignoring IIH",
767 circuit
->area
->area_tag
);
769 circuit
->rej_adjacencies
++;
771 isis_notif_reject_adjacency(
772 circuit
, "Neither IPv4 not IPv6 considered usable",
774 #endif /* ifndef FABRICD */
778 retval
= p2p_hello
? process_p2p_hello(&iih
) : process_lan_hello(&iih
);
780 isis_free_tlvs(iih
.tlvs
);
785 static void lsp_flood_or_update(struct isis_lsp
*lsp
,
786 struct isis_circuit
*circuit
,
790 lsp_flood(lsp
, circuit
);
792 fabricd_update_lsp_no_flood(lsp
, circuit
);
796 * Process Level 1/2 Link State
798 * Section 7.3.15.1 - Action on receipt of a link state PDU
800 static int process_lsp(uint8_t pdu_type
, struct isis_circuit
*circuit
,
801 const uint8_t *ssnpa
, uint8_t max_area_addrs
)
805 size_t pdu_start
= stream_get_getp(circuit
->rcv_stream
);
806 size_t pdu_end
= stream_get_endp(circuit
->rcv_stream
);
807 char raw_pdu
[pdu_end
- pdu_start
];
809 stream_get_from(raw_pdu
, circuit
->rcv_stream
, pdu_start
,
810 pdu_end
- pdu_start
);
812 if (pdu_type
== FS_LINK_STATE
) {
815 if (max_area_addrs
!= L2_CIRCUIT_FLOODING_SCOPE
)
818 circuit_scoped
= true;
820 /* The stream is used verbatim for sending out new LSPDUs.
821 * So make sure we store it as an L2 LSPDU internally.
822 * (compare for the reverse in `send_lsp`) */
823 stream_putc_at(circuit
->rcv_stream
, 4, L2_LINK_STATE
);
824 stream_putc_at(circuit
->rcv_stream
, 7, 0);
826 if (pdu_type
== L1_LINK_STATE
)
830 circuit_scoped
= false;
833 if (IS_DEBUG_UPDATE_PACKETS
) {
835 "ISIS-Upd (%s): Rcvd %sL%d LSP on %s, cirType %s, cirID %u",
836 circuit
->area
->area_tag
,
837 circuit_scoped
? "Circuit scoped " : "", level
,
838 circuit
->interface
->name
,
839 circuit_t2string(circuit
->is_type
),
840 circuit
->circuit_id
);
841 if (IS_DEBUG_PACKET_DUMP
)
842 zlog_dump_data(STREAM_DATA(circuit
->rcv_stream
),
843 stream_get_endp(circuit
->rcv_stream
));
846 struct isis_lsp_hdr hdr
= {};
848 hdr
.pdu_len
= stream_getw(circuit
->rcv_stream
);
849 hdr
.rem_lifetime
= stream_getw(circuit
->rcv_stream
);
850 stream_get(hdr
.lsp_id
, circuit
->rcv_stream
, sizeof(hdr
.lsp_id
));
851 hdr
.seqno
= stream_getl(circuit
->rcv_stream
);
852 hdr
.checksum
= stream_getw(circuit
->rcv_stream
);
853 hdr
.lsp_bits
= stream_getc(circuit
->rcv_stream
);
856 /* send northbound notification */
857 isis_notif_lsp_received(circuit
, rawlspid_print(hdr
.lsp_id
), hdr
.seqno
,
858 time(NULL
), sysid_print(hdr
.lsp_id
));
859 #endif /* ifndef FABRICD */
861 if (pdu_len_validate(hdr
.pdu_len
, circuit
)) {
862 zlog_debug("ISIS-Upd (%s): LSP %s invalid LSP length %hu",
863 circuit
->area
->area_tag
, rawlspid_print(hdr
.lsp_id
),
868 if (IS_DEBUG_UPDATE_PACKETS
) {
869 zlog_debug("ISIS-Upd (%s): Rcvd L%d LSP %s, seq 0x%08x, cksum 0x%04hx, lifetime %hus, len %hu, on %s",
870 circuit
->area
->area_tag
, level
,
871 rawlspid_print(hdr
.lsp_id
), hdr
.seqno
, hdr
.checksum
,
872 hdr
.rem_lifetime
, hdr
.pdu_len
,
873 circuit
->interface
->name
);
876 /* lsp is_type check */
877 if ((hdr
.lsp_bits
& IS_LEVEL_1
) != IS_LEVEL_1
) {
879 "ISIS-Upd (%s): LSP %s invalid LSP is type 0x%x",
880 circuit
->area
->area_tag
, rawlspid_print(hdr
.lsp_id
),
881 hdr
.lsp_bits
& IS_LEVEL_1_AND_2
);
882 /* continue as per RFC1122 Be liberal in what you accept, and
883 * conservative in what you send */
886 /* Checksum sanity check - FIXME: move to correct place */
887 /* 12 = sysid+pdu+remtime */
888 if (iso_csum_verify(STREAM_DATA(circuit
->rcv_stream
) + 12,
889 hdr
.pdu_len
- 12, hdr
.checksum
, 12)) {
891 "ISIS-Upd (%s): LSP %s invalid LSP checksum 0x%04hx",
892 circuit
->area
->area_tag
, rawlspid_print(hdr
.lsp_id
),
897 /* 7.3.15.1 a) 1 - external domain circuit will discard lsps */
898 if (circuit
->ext_domain
) {
900 "ISIS-Upd (%s): LSP %s received at level %d over circuit with externalDomain = true",
901 circuit
->area
->area_tag
, rawlspid_print(hdr
.lsp_id
),
906 /* 7.3.15.1 a) 2,3 - manualL2OnlyMode not implemented */
907 if (!(circuit
->is_type
& level
)) {
909 "ISIS-Upd (%s): LSP %s received at level %d over circuit of type %s",
910 circuit
->area
->area_tag
, rawlspid_print(hdr
.lsp_id
),
911 level
, circuit_t2string(circuit
->is_type
));
915 struct isis_tlvs
*tlvs
= NULL
;
916 int retval
= ISIS_WARNING
;
917 const char *error_log
;
919 if (isis_unpack_tlvs(STREAM_READABLE(circuit
->rcv_stream
),
920 circuit
->rcv_stream
, &tlvs
, &error_log
)) {
921 zlog_warn("Something went wrong unpacking the LSP: %s",
924 /* send northbound notification. Note that the tlv-type and
925 * offset cannot correctly be set here as they are not returned
926 * by isis_unpack_tlvs, but in there I cannot fire a
927 * notification because I have no circuit information. So until
928 * we change the code above to return those extra fields, we
929 * will send dummy values which are ignored in the callback
931 isis_notif_lsp_error(circuit
, rawlspid_print(hdr
.lsp_id
),
933 #endif /* ifndef FABRICD */
937 /* 7.3.15.1 a) 4 - need to make sure IDLength matches */
939 /* 7.3.15.1 a) 5 - maximum area match, can be ommited since we only use
942 /* 7.3.15.1 a) 7 - password check */
943 struct isis_passwd
*passwd
= (level
== ISIS_LEVEL1
)
944 ? &circuit
->area
->area_passwd
945 : &circuit
->area
->domain_passwd
;
946 int auth_code
= isis_tlvs_auth_is_valid(tlvs
, passwd
,
947 circuit
->rcv_stream
, true);
948 if (auth_code
!= ISIS_AUTH_OK
) {
949 isis_event_auth_failure(circuit
->area
->area_tag
,
950 "LSP authentication failure",
953 /* send northbound notification */
954 if (auth_code
== ISIS_AUTH_FAILURE
) {
955 circuit
->auth_failures
++;
956 isis_notif_authentication_failure(circuit
, raw_pdu
);
957 } else { /* AUTH_TYPE_FAILURE or NO_VALIDATOR */
958 circuit
->auth_type_failures
++;
959 isis_notif_authentication_type_failure(circuit
,
962 #endif /* ifndef FABRICD */
966 /* Find the LSP in our database and compare it to this Link State header
968 struct isis_lsp
*lsp
=
969 lsp_search(&circuit
->area
->lspdb
[level
- 1], hdr
.lsp_id
);
972 comp
= lsp_compare(circuit
->area
->area_tag
, lsp
, hdr
.seqno
,
973 hdr
.checksum
, hdr
.rem_lifetime
);
974 if (lsp
&& (lsp
->own_lsp
))
977 /* 7.3.15.1 a) 6 - Must check that we have an adjacency of the same
979 /* for broadcast circuits, snpa should be compared */
981 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
) {
982 if (!isis_adj_lookup_snpa(ssnpa
,
983 circuit
->u
.bc
.adjdb
[level
- 1])) {
984 zlog_debug("(%s): DS ======= LSP %s, seq 0x%08x, cksum 0x%04hx, lifetime %hus on %s",
985 circuit
->area
->area_tag
,
986 rawlspid_print(hdr
.lsp_id
), hdr
.seqno
,
987 hdr
.checksum
, hdr
.rem_lifetime
,
988 circuit
->interface
->name
);
989 goto out
; /* Silently discard */
992 /* for non broadcast, we just need to find same level adj */
994 /* If no adj, or no sharing of level */
995 if (!circuit
->u
.p2p
.neighbor
) {
999 if (((level
== IS_LEVEL_1
)
1000 && (circuit
->u
.p2p
.neighbor
->adj_usage
1001 == ISIS_ADJ_LEVEL2
))
1002 || ((level
== IS_LEVEL_2
)
1003 && (circuit
->u
.p2p
.neighbor
->adj_usage
1004 == ISIS_ADJ_LEVEL1
)))
1012 /* 7.3.15.1 a) 7 - Passwords for level 1 - not implemented */
1014 /* 7.3.15.1 a) 8 - Passwords for level 2 - not implemented */
1016 /* 7.3.15.1 a) 9 - OriginatingLSPBufferSize - not implemented FIXME: do
1019 /* 7.3.16.2 - If this is an LSP from another IS with identical seq_num
1021 * wrong checksum, initiate a purge. */
1022 if (lsp
&& (lsp
->hdr
.seqno
== hdr
.seqno
)
1023 && (lsp
->hdr
.checksum
!= hdr
.checksum
)
1024 && hdr
.rem_lifetime
) {
1025 zlog_warn("ISIS-Upd (%s): LSP %s seq 0x%08x with confused checksum received.",
1026 circuit
->area
->area_tag
, rawlspid_print(hdr
.lsp_id
),
1028 hdr
.rem_lifetime
= 0;
1029 lsp_confusion
= true;
1031 lsp_confusion
= false;
1033 /* 7.3.15.1 b) - If the remaining life time is 0, we perform 7.3.16.4 */
1034 if (hdr
.rem_lifetime
== 0) {
1036 /* 7.3.16.4 a) 1) No LSP in db -> send an ack, but don't
1038 /* only needed on explicit update, eg - p2p */
1039 if (circuit
->circ_type
== CIRCUIT_T_P2P
)
1040 ack_lsp(&hdr
, circuit
, level
);
1041 goto out
; /* FIXME: do we need a purge? */
1043 if (memcmp(hdr
.lsp_id
, isis
->sysid
, ISIS_SYS_ID_LEN
)) {
1044 /* LSP by some other system -> do 7.3.16.4 b) */
1045 /* 7.3.16.4 b) 1) */
1046 if (comp
== LSP_NEWER
) {
1047 lsp_update(lsp
, &hdr
, tlvs
,
1048 circuit
->rcv_stream
,
1049 circuit
->area
, level
,
1052 isis_free_tlvs(tlvs
);
1055 lsp_flood_or_update(lsp
, NULL
,
1058 ISIS_FLAGS_CLEAR_ALL(
1059 lsp
->SSNflags
); /* FIXME:
1064 /* For the case of lsp confusion, flood
1065 * the purge back to its
1066 * originator so that it can react.
1067 * Otherwise, don't reflood
1068 * through incoming circuit as usual */
1069 if (!lsp_confusion
) {
1075 if (circuit
->circ_type
1076 != CIRCUIT_T_BROADCAST
)
1081 } /* 7.3.16.4 b) 2) */
1082 else if (comp
== LSP_EQUAL
) {
1084 isis_tx_queue_del(circuit
->tx_queue
,
1087 if (circuit
->circ_type
1088 != CIRCUIT_T_BROADCAST
)
1089 ISIS_SET_FLAG(lsp
->SSNflags
,
1091 } /* 7.3.16.4 b) 3) */
1093 isis_tx_queue_add(circuit
->tx_queue
,
1094 lsp
, TX_LSP_NORMAL
);
1095 ISIS_CLEAR_FLAG(lsp
->SSNflags
, circuit
);
1097 } else if (lsp
->hdr
.rem_lifetime
!= 0) {
1098 /* our own LSP -> 7.3.16.4 c) */
1099 if (comp
== LSP_NEWER
) {
1101 if (lsp
->hdr
.seqno
< hdr
.seqno
) {
1104 isis_notif_seqno_skipped(
1109 #endif /* ifndef FABRICD */
1110 lsp_inc_seqno(lsp
, hdr
.seqno
);
1111 lsp_flood_or_update(lsp
, NULL
,
1114 isis_tx_queue_add(circuit
->tx_queue
,
1115 lsp
, TX_LSP_NORMAL
);
1116 ISIS_CLEAR_FLAG(lsp
->SSNflags
, circuit
);
1118 if (IS_DEBUG_UPDATE_PACKETS
)
1120 "ISIS-Upd (%s): (1) re-originating LSP %s new seq 0x%08x",
1121 circuit
->area
->area_tag
,
1122 rawlspid_print(hdr
.lsp_id
),
1125 /* our own LSP with 0 remaining life time */
1127 /* send northbound notification */
1128 isis_notif_own_lsp_purge(
1129 circuit
, rawlspid_print(hdr
.lsp_id
));
1130 #endif /* ifndef FABRICD */
1135 /* 7.3.15.1 c) - If this is our own lsp and we don't have it initiate a
1137 if (memcmp(hdr
.lsp_id
, isis
->sysid
, ISIS_SYS_ID_LEN
) == 0) {
1139 /* 7.3.16.4: initiate a purge */
1140 lsp_purge_non_exist(level
, &hdr
, circuit
->area
);
1144 /* 7.3.15.1 d) - If this is our own lsp and we have it */
1146 /* In 7.3.16.1, If an Intermediate system R somewhere in the
1148 * has information that the current sequence number for source S
1150 * "greater" than that held by S, ... */
1152 if (comp
== LSP_NEWER
) {
1154 lsp_inc_seqno(lsp
, hdr
.seqno
);
1156 /* send northbound notification */
1157 isis_notif_seqno_skipped(circuit
,
1158 rawlspid_print(hdr
.lsp_id
));
1159 #endif /* ifndef FABRICD */
1160 if (IS_DEBUG_UPDATE_PACKETS
) {
1162 "ISIS-Upd (%s): (2) re-originating LSP %s new seq 0x%08x",
1163 circuit
->area
->area_tag
,
1164 rawlspid_print(hdr
.lsp_id
),
1167 lsp_flood(lsp
, NULL
);
1168 } else if (comp
== LSP_EQUAL
) {
1169 isis_tx_queue_del(circuit
->tx_queue
, lsp
);
1170 if (circuit
->circ_type
!= CIRCUIT_T_BROADCAST
)
1171 ISIS_SET_FLAG(lsp
->SSNflags
, circuit
);
1173 isis_tx_queue_add(circuit
->tx_queue
, lsp
,
1175 ISIS_CLEAR_FLAG(lsp
->SSNflags
, circuit
);
1178 /* 7.3.15.1 e) - This lsp originated on another system */
1180 /* 7.3.15.1 e) 1) LSP newer than the one in db or no LSP in db
1182 if ((!lsp
|| comp
== LSP_NEWER
)) {
1184 * If this lsp is a frag, need to see if we have zero
1187 struct isis_lsp
*lsp0
= NULL
;
1188 if (LSP_FRAGMENT(hdr
.lsp_id
) != 0) {
1189 uint8_t lspid
[ISIS_SYS_ID_LEN
+ 2];
1190 memcpy(lspid
, hdr
.lsp_id
, ISIS_SYS_ID_LEN
+ 1);
1191 LSP_FRAGMENT(lspid
) = 0;
1193 &circuit
->area
->lspdb
[level
- 1], lspid
);
1196 "Got lsp frag, while zero lsp not in database");
1202 lsp
= lsp_new_from_recv(
1203 &hdr
, tlvs
, circuit
->rcv_stream
, lsp0
,
1204 circuit
->area
, level
);
1206 lsp_insert(&circuit
->area
->lspdb
[level
- 1],
1208 } else /* exists, so we overwrite */
1210 lsp_update(lsp
, &hdr
, tlvs
, circuit
->rcv_stream
,
1211 circuit
->area
, level
, false);
1214 lsp_flood_or_update(lsp
, circuit
, circuit_scoped
);
1217 if (circuit
->circ_type
!= CIRCUIT_T_BROADCAST
)
1218 ISIS_SET_FLAG(lsp
->SSNflags
, circuit
);
1221 /* 7.3.15.1 e) 2) LSP equal to the one in db */
1222 else if (comp
== LSP_EQUAL
) {
1223 isis_tx_queue_del(circuit
->tx_queue
, lsp
);
1224 lsp_update(lsp
, &hdr
, tlvs
, circuit
->rcv_stream
,
1225 circuit
->area
, level
, false);
1227 if (circuit
->circ_type
!= CIRCUIT_T_BROADCAST
)
1228 ISIS_SET_FLAG(lsp
->SSNflags
, circuit
);
1230 /* 7.3.15.1 e) 3) LSP older than the one in db */
1232 isis_tx_queue_add(circuit
->tx_queue
, lsp
,
1234 ISIS_CLEAR_FLAG(lsp
->SSNflags
, circuit
);
1241 fabricd_trigger_csnp(circuit
->area
, circuit_scoped
);
1243 isis_free_tlvs(tlvs
);
1248 * Process Sequence Numbers
1250 * Section 7.3.15.2 - Action on receipt of a sequence numbers PDU
1253 static int process_snp(uint8_t pdu_type
, struct isis_circuit
*circuit
,
1254 const uint8_t *ssnpa
)
1257 size_t pdu_start
= stream_get_getp(circuit
->rcv_stream
);
1258 size_t pdu_end
= stream_get_endp(circuit
->rcv_stream
);
1259 char raw_pdu
[pdu_end
- pdu_start
];
1260 #endif /* ifndef FABRICD */
1262 bool is_csnp
= (pdu_type
== L1_COMPLETE_SEQ_NUM
1263 || pdu_type
== L2_COMPLETE_SEQ_NUM
);
1264 char typechar
= is_csnp
? 'C' : 'P';
1265 int level
= (pdu_type
== L1_COMPLETE_SEQ_NUM
1266 || pdu_type
== L1_PARTIAL_SEQ_NUM
)
1270 uint16_t pdu_len
= stream_getw(circuit
->rcv_stream
);
1271 uint8_t rem_sys_id
[ISIS_SYS_ID_LEN
];
1273 stream_get(rem_sys_id
, circuit
->rcv_stream
, ISIS_SYS_ID_LEN
);
1274 stream_forward_getp(circuit
->rcv_stream
, 1); /* Circuit ID - unused */
1276 uint8_t start_lsp_id
[ISIS_SYS_ID_LEN
+ 2] = {};
1277 uint8_t stop_lsp_id
[ISIS_SYS_ID_LEN
+ 2] = {};
1280 stream_get(start_lsp_id
, circuit
->rcv_stream
,
1281 ISIS_SYS_ID_LEN
+ 2);
1282 stream_get(stop_lsp_id
, circuit
->rcv_stream
,
1283 ISIS_SYS_ID_LEN
+ 2);
1286 if (pdu_len_validate(pdu_len
, circuit
)) {
1287 zlog_warn("Received a CSNP with bogus length %d", pdu_len
);
1288 return ISIS_WARNING
;
1291 if (IS_DEBUG_SNP_PACKETS
) {
1293 "ISIS-Snp (%s): Rcvd L%d %cSNP on %s, cirType %s, cirID %u",
1294 circuit
->area
->area_tag
, level
, typechar
,
1295 circuit
->interface
->name
,
1296 circuit_t2string(circuit
->is_type
),
1297 circuit
->circuit_id
);
1298 if (IS_DEBUG_PACKET_DUMP
)
1299 zlog_dump_data(STREAM_DATA(circuit
->rcv_stream
),
1300 stream_get_endp(circuit
->rcv_stream
));
1303 /* 7.3.15.2 a) 1 - external domain circuit will discard snp pdu */
1304 if (circuit
->ext_domain
) {
1307 "ISIS-Snp (%s): Rcvd L%d %cSNP on %s, skipping: circuit externalDomain = true",
1308 circuit
->area
->area_tag
, level
, typechar
,
1309 circuit
->interface
->name
);
1314 /* 7.3.15.2 a) 2,3 - manualL2OnlyMode not implemented */
1315 if (!(circuit
->is_type
& level
)) {
1317 "ISIS-Snp (%s): Rcvd L%d %cSNP on %s, skipping: circuit type %s does not match level %d",
1318 circuit
->area
->area_tag
, level
, typechar
,
1319 circuit
->interface
->name
,
1320 circuit_t2string(circuit
->is_type
), level
);
1325 /* 7.3.15.2 a) 4 - not applicable for CSNP only PSNPs on broadcast */
1326 if (!is_csnp
&& (circuit
->circ_type
== CIRCUIT_T_BROADCAST
)
1327 && !circuit
->u
.bc
.is_dr
[level
- 1]) {
1329 "ISIS-Snp (%s): Rcvd L%d %cSNP from %s on %s, skipping: we are not the DIS",
1330 circuit
->area
->area_tag
, level
, typechar
,
1331 snpa_print(ssnpa
), circuit
->interface
->name
);
1336 /* 7.3.15.2 a) 5 - need to make sure IDLength matches - already checked
1339 /* 7.3.15.2 a) 6 - maximum area match, can be ommited since we only use
1341 * - already checked */
1343 /* 7.3.15.2 a) 7 - Must check that we have an adjacency of the same
1345 /* for broadcast circuits, snpa should be compared */
1346 /* FIXME : Do we need to check SNPA? */
1347 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
) {
1348 if (!isis_adj_lookup(rem_sys_id
,
1349 circuit
->u
.bc
.adjdb
[level
- 1]))
1350 return ISIS_OK
; /* Silently discard */
1352 if (!fabricd
&& !circuit
->u
.p2p
.neighbor
) {
1353 zlog_warn("no p2p neighbor on circuit %s",
1354 circuit
->interface
->name
);
1355 return ISIS_OK
; /* Silently discard */
1359 struct isis_tlvs
*tlvs
;
1360 int retval
= ISIS_WARNING
;
1361 const char *error_log
;
1363 if (isis_unpack_tlvs(STREAM_READABLE(circuit
->rcv_stream
),
1364 circuit
->rcv_stream
, &tlvs
, &error_log
)) {
1365 zlog_warn("Something went wrong unpacking the SNP: %s",
1370 struct isis_passwd
*passwd
= (level
== IS_LEVEL_1
)
1371 ? &circuit
->area
->area_passwd
1372 : &circuit
->area
->domain_passwd
;
1373 if (CHECK_FLAG(passwd
->snp_auth
, SNP_AUTH_RECV
)) {
1374 int auth_code
= isis_tlvs_auth_is_valid(
1375 tlvs
, passwd
, circuit
->rcv_stream
, false);
1376 if (auth_code
!= ISIS_AUTH_OK
) {
1377 isis_event_auth_failure(circuit
->area
->area_tag
,
1378 "SNP authentication failure",
1381 /* send northbound notification */
1382 stream_get_from(raw_pdu
, circuit
->rcv_stream
, pdu_start
,
1383 pdu_end
- pdu_start
);
1384 if (auth_code
== ISIS_AUTH_FAILURE
) {
1385 circuit
->auth_failures
++;
1386 isis_notif_authentication_failure(circuit
,
1388 } else { /* AUTH_TYPE_FAILURE or NO_VALIDATOR */
1389 circuit
->auth_type_failures
++;
1390 isis_notif_authentication_type_failure(circuit
,
1393 #endif /* ifndef FABRICD */
1398 struct isis_lsp_entry
*entry_head
=
1399 (struct isis_lsp_entry
*)tlvs
->lsp_entries
.head
;
1401 /* debug isis snp-packets */
1402 if (IS_DEBUG_SNP_PACKETS
) {
1403 zlog_debug("ISIS-Snp (%s): Rcvd L%d %cSNP from %s on %s",
1404 circuit
->area
->area_tag
, level
, typechar
,
1405 snpa_print(ssnpa
), circuit
->interface
->name
);
1406 for (struct isis_lsp_entry
*entry
= entry_head
; entry
;
1407 entry
= entry
->next
) {
1409 "ISIS-Snp (%s): %cSNP entry %s, seq 0x%08x, cksum 0x%04hx, lifetime %hus",
1410 circuit
->area
->area_tag
, typechar
,
1411 rawlspid_print(entry
->id
), entry
->seqno
,
1412 entry
->checksum
, entry
->rem_lifetime
);
1416 bool resync_needed
= false;
1418 /* 7.3.15.2 b) Actions on LSP_ENTRIES reported */
1419 for (struct isis_lsp_entry
*entry
= entry_head
; entry
;
1420 entry
= entry
->next
) {
1421 struct isis_lsp
*lsp
=
1422 lsp_search(&circuit
->area
->lspdb
[level
- 1], entry
->id
);
1423 bool own_lsp
= !memcmp(entry
->id
, isis
->sysid
, ISIS_SYS_ID_LEN
);
1425 /* 7.3.15.2 b) 1) is this LSP newer */
1426 int cmp
= lsp_compare(circuit
->area
->area_tag
, lsp
,
1427 entry
->seqno
, entry
->checksum
,
1428 entry
->rem_lifetime
);
1429 /* 7.3.15.2 b) 2) if it equals, clear SRM on p2p */
1430 if (cmp
== LSP_EQUAL
) {
1431 /* if (circuit->circ_type !=
1432 * CIRCUIT_T_BROADCAST) */
1433 isis_tx_queue_del(circuit
->tx_queue
, lsp
);
1435 /* 7.3.15.2 b) 3) if it is older, clear SSN and set SRM
1437 else if (cmp
== LSP_OLDER
) {
1438 ISIS_CLEAR_FLAG(lsp
->SSNflags
, circuit
);
1439 isis_tx_queue_add(circuit
->tx_queue
, lsp
,
1442 /* 7.3.15.2 b) 4) if it is newer, set SSN and clear SRM
1446 lsp_inc_seqno(lsp
, entry
->seqno
);
1447 isis_tx_queue_add(circuit
->tx_queue
, lsp
,
1450 ISIS_SET_FLAG(lsp
->SSNflags
, circuit
);
1451 /* if (circuit->circ_type !=
1452 * CIRCUIT_T_BROADCAST) */
1453 isis_tx_queue_del(circuit
->tx_queue
, lsp
);
1454 resync_needed
= true;
1458 /* 7.3.15.2 b) 5) if it was not found, and all of those
1460 * insert it and set SSN on it */
1461 if (entry
->rem_lifetime
&& entry
->checksum
1462 && entry
->seqno
&& memcmp(entry
->id
, isis
->sysid
,
1464 struct isis_lsp
*lsp0
= NULL
;
1466 if (LSP_FRAGMENT(entry
->id
)) {
1467 uint8_t lspid
[ISIS_SYS_ID_LEN
+ 2];
1469 memcpy(lspid
, entry
->id
,
1470 ISIS_SYS_ID_LEN
+ 1);
1471 LSP_FRAGMENT(lspid
) = 0;
1473 &circuit
->area
->lspdb
[level
- 1],
1476 zlog_debug("Got lsp frag in snp, while zero not in database");
1480 lsp
= lsp_new(circuit
->area
, entry
->id
,
1481 entry
->rem_lifetime
, 0, 0,
1482 entry
->checksum
, lsp0
, level
);
1483 lsp_insert(&circuit
->area
->lspdb
[level
- 1],
1486 lsp_set_all_srmflags(lsp
, false);
1487 ISIS_SET_FLAG(lsp
->SSNflags
, circuit
);
1488 resync_needed
= true;
1493 /* 7.3.15.2 c) on CSNP set SRM for all in range which were not reported
1497 * Build a list from our own LSP db bounded with
1498 * start_lsp_id and stop_lsp_id
1500 struct list
*lsp_list
= list_new();
1501 lsp_build_list_nonzero_ht(&circuit
->area
->lspdb
[level
- 1],
1502 start_lsp_id
, stop_lsp_id
, lsp_list
);
1504 /* Fixme: Find a better solution */
1505 struct listnode
*node
, *nnode
;
1506 struct isis_lsp
*lsp
;
1507 for (struct isis_lsp_entry
*entry
= entry_head
; entry
;
1508 entry
= entry
->next
) {
1509 for (ALL_LIST_ELEMENTS(lsp_list
, node
, nnode
, lsp
)) {
1510 if (lsp_id_cmp(lsp
->hdr
.lsp_id
, entry
->id
)
1512 list_delete_node(lsp_list
, node
);
1518 /* on remaining LSPs we set SRM (neighbor knew not of) */
1519 for (ALL_LIST_ELEMENTS_RO(lsp_list
, node
, lsp
)) {
1520 isis_tx_queue_add(circuit
->tx_queue
, lsp
, TX_LSP_NORMAL
);
1521 resync_needed
= true;
1525 list_delete(&lsp_list
);
1528 if (fabricd_initial_sync_is_complete(circuit
->area
) && resync_needed
)
1529 zlog_warn("OpenFabric: Needed to resync LSPDB using CSNP!");
1533 isis_free_tlvs(tlvs
);
1537 static int pdu_size(uint8_t pdu_type
, uint8_t *size
)
1542 *size
= ISIS_LANHELLO_HDRLEN
;
1545 *size
= ISIS_P2PHELLO_HDRLEN
;
1550 *size
= ISIS_LSP_HDR_LEN
;
1552 case L1_COMPLETE_SEQ_NUM
:
1553 case L2_COMPLETE_SEQ_NUM
:
1554 *size
= ISIS_CSNP_HDRLEN
;
1556 case L1_PARTIAL_SEQ_NUM
:
1557 case L2_PARTIAL_SEQ_NUM
:
1558 *size
= ISIS_PSNP_HDRLEN
;
1563 *size
+= ISIS_FIXED_HDR_LEN
;
1571 int isis_handle_pdu(struct isis_circuit
*circuit
, uint8_t *ssnpa
)
1573 int retval
= ISIS_OK
;
1574 size_t pdu_start
= stream_get_getp(circuit
->rcv_stream
);
1575 size_t pdu_end
= stream_get_endp(circuit
->rcv_stream
);
1576 char raw_pdu
[pdu_end
- pdu_start
];
1578 stream_get_from(raw_pdu
, circuit
->rcv_stream
, pdu_start
,
1579 pdu_end
- pdu_start
);
1581 /* Verify that at least the 8 bytes fixed header have been received */
1582 if (stream_get_endp(circuit
->rcv_stream
) < ISIS_FIXED_HDR_LEN
) {
1583 flog_err(EC_ISIS_PACKET
, "PDU is too short to be IS-IS.");
1587 uint8_t idrp
= stream_getc(circuit
->rcv_stream
);
1588 uint8_t length
= stream_getc(circuit
->rcv_stream
);
1589 uint8_t version1
= stream_getc(circuit
->rcv_stream
);
1590 uint8_t id_len
= stream_getc(circuit
->rcv_stream
);
1591 uint8_t pdu_type
= stream_getc(circuit
->rcv_stream
)
1592 & 0x1f; /* bits 6-8 are reserved */
1593 uint8_t version2
= stream_getc(circuit
->rcv_stream
);
1595 stream_forward_getp(circuit
->rcv_stream
, 1); /* reserved */
1596 uint8_t max_area_addrs
= stream_getc(circuit
->rcv_stream
);
1598 pdu_counter_count(circuit
->area
->pdu_rx_counters
, pdu_type
);
1600 if (idrp
== ISO9542_ESIS
) {
1601 flog_err(EC_LIB_DEVELOPMENT
,
1602 "No support for ES-IS packet IDRP=%hhx", idrp
);
1606 if (idrp
!= ISO10589_ISIS
) {
1607 flog_err(EC_ISIS_PACKET
, "Not an IS-IS packet IDRP=%hhx",
1612 if (version1
!= 1) {
1613 zlog_warn("Unsupported ISIS version %hhu", version1
);
1615 /* send northbound notification */
1616 isis_notif_version_skew(circuit
, version1
, raw_pdu
);
1617 #endif /* ifndef FABRICD */
1618 return ISIS_WARNING
;
1621 if (id_len
!= 0 && id_len
!= ISIS_SYS_ID_LEN
) {
1624 "IDFieldLengthMismatch: ID Length field in a received PDU %hhu, while the parameter for this IS is %u",
1625 id_len
, ISIS_SYS_ID_LEN
);
1626 circuit
->id_len_mismatches
++;
1628 /* send northbound notification */
1629 isis_notif_id_len_mismatch(circuit
, id_len
, raw_pdu
);
1630 #endif /* ifndef FABRICD */
1634 uint8_t expected_length
;
1635 if (pdu_size(pdu_type
, &expected_length
)) {
1636 zlog_warn("Unsupported ISIS PDU %hhu", pdu_type
);
1637 return ISIS_WARNING
;
1640 if (length
!= expected_length
) {
1641 flog_err(EC_ISIS_PACKET
,
1642 "Expected fixed header length = %hhu but got %hhu",
1643 expected_length
, length
);
1647 if (stream_get_endp(circuit
->rcv_stream
) < length
) {
1650 "PDU is too short to contain fixed header of given PDU type.");
1654 if (version2
!= 1) {
1655 zlog_warn("Unsupported ISIS PDU version %hhu", version2
);
1657 /* send northbound notification */
1658 isis_notif_version_skew(circuit
, version2
, raw_pdu
);
1659 #endif /* ifndef FABRICD */
1660 return ISIS_WARNING
;
1663 if (circuit
->is_passive
) {
1664 zlog_warn("Received ISIS PDU on passive circuit %s",
1665 circuit
->interface
->name
);
1666 return ISIS_WARNING
;
1670 if (pdu_type
!= FS_LINK_STATE
/* FS PDU doesn't contain max area addr field */
1671 && max_area_addrs
!= 0
1672 && max_area_addrs
!= isis
->max_area_addrs
) {
1675 "maximumAreaAddressesMismatch: maximumAreaAdresses in a received PDU %hhu while the parameter for this IS is %u",
1676 max_area_addrs
, isis
->max_area_addrs
);
1677 circuit
->max_area_addr_mismatches
++;
1679 /* send northbound notification */
1680 isis_notif_max_area_addr_mismatch(circuit
, max_area_addrs
,
1682 #endif /* ifndef FABRICD */
1690 if (fabricd
&& pdu_type
!= P2P_HELLO
)
1692 retval
= process_hello(pdu_type
, circuit
, ssnpa
);
1698 && pdu_type
!= L2_LINK_STATE
1699 && pdu_type
!= FS_LINK_STATE
)
1701 retval
= process_lsp(pdu_type
, circuit
, ssnpa
, max_area_addrs
);
1703 case L1_COMPLETE_SEQ_NUM
:
1704 case L2_COMPLETE_SEQ_NUM
:
1705 case L1_PARTIAL_SEQ_NUM
:
1706 case L2_PARTIAL_SEQ_NUM
:
1707 retval
= process_snp(pdu_type
, circuit
, ssnpa
);
1716 int isis_receive(struct thread
*thread
)
1718 struct isis_circuit
*circuit
;
1719 uint8_t ssnpa
[ETH_ALEN
];
1725 circuit
= THREAD_ARG(thread
);
1728 circuit
->t_read
= NULL
;
1730 isis_circuit_stream(circuit
, &circuit
->rcv_stream
);
1732 retval
= circuit
->rx(circuit
, ssnpa
);
1734 #if ISIS_METHOD != ISIS_METHOD_BPF
1735 if (retval
== ISIS_OK
)
1736 retval
= isis_handle_pdu(circuit
, ssnpa
);
1737 #endif //ISIS_METHOD != ISIS_METHOD_BPF
1740 * prepare for next packet.
1742 if (!circuit
->is_passive
)
1743 isis_circuit_prepare(circuit
);
1751 void fill_fixed_hdr(uint8_t pdu_type
, struct stream
*stream
)
1755 if (pdu_size(pdu_type
, &length
))
1756 assert(!"Unknown PDU Type");
1758 stream_putc(stream
, ISO10589_ISIS
); /* IDRP */
1759 stream_putc(stream
, length
); /* Length of fixed header */
1760 stream_putc(stream
, 1); /* Version/Protocol ID Extension 1 */
1761 stream_putc(stream
, 0); /* ID Length, 0 => 6 */
1762 stream_putc(stream
, pdu_type
);
1763 stream_putc(stream
, 1); /* Subversion */
1764 stream_putc(stream
, 0); /* Reserved */
1765 stream_putc(stream
, 0); /* Max Area Addresses 0 => 3 */
1768 static uint8_t hello_pdu_type(struct isis_circuit
*circuit
, int level
)
1770 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
)
1771 return (level
== IS_LEVEL_1
) ? L1_LAN_HELLO
: L2_LAN_HELLO
;
1776 static void put_hello_hdr(struct isis_circuit
*circuit
, int level
,
1777 size_t *len_pointer
)
1779 uint8_t pdu_type
= hello_pdu_type(circuit
, level
);
1781 isis_circuit_stream(circuit
, &circuit
->snd_stream
);
1782 fill_fixed_hdr(pdu_type
, circuit
->snd_stream
);
1784 stream_putc(circuit
->snd_stream
, circuit
->is_type
);
1785 stream_put(circuit
->snd_stream
, circuit
->area
->isis
->sysid
,
1788 uint32_t holdtime
= circuit
->hello_multiplier
[level
- 1]
1789 * circuit
->hello_interval
[level
- 1];
1791 if (holdtime
> 0xffff)
1794 stream_putw(circuit
->snd_stream
, holdtime
);
1795 *len_pointer
= stream_get_endp(circuit
->snd_stream
);
1796 stream_putw(circuit
->snd_stream
, 0); /* length is filled in later */
1798 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
) {
1799 uint8_t *desig_is
= (level
== IS_LEVEL_1
)
1800 ? circuit
->u
.bc
.l1_desig_is
1801 : circuit
->u
.bc
.l2_desig_is
;
1802 stream_putc(circuit
->snd_stream
, circuit
->priority
[level
- 1]);
1803 stream_put(circuit
->snd_stream
, desig_is
, ISIS_SYS_ID_LEN
+ 1);
1805 stream_putc(circuit
->snd_stream
, circuit
->circuit_id
);
1809 int send_hello(struct isis_circuit
*circuit
, int level
)
1814 if (circuit
->is_passive
)
1817 if (circuit
->interface
->mtu
== 0) {
1818 zlog_warn("circuit has zero MTU");
1819 return ISIS_WARNING
;
1822 put_hello_hdr(circuit
, level
, &len_pointer
);
1824 struct isis_tlvs
*tlvs
= isis_alloc_tlvs();
1826 isis_tlvs_add_auth(tlvs
, &circuit
->passwd
);
1828 if (!listcount(circuit
->area
->area_addrs
)) {
1829 isis_free_tlvs(tlvs
);
1830 return ISIS_WARNING
;
1833 isis_tlvs_add_area_addresses(tlvs
, circuit
->area
->area_addrs
);
1835 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
) {
1836 isis_tlvs_add_lan_neighbors(
1837 tlvs
, circuit
->u
.bc
.lan_neighs
[level
- 1]);
1838 } else if (circuit
->circ_type
== CIRCUIT_T_P2P
1839 && !circuit
->disable_threeway_adj
) {
1840 uint32_t ext_circuit_id
= circuit
->idx
;
1841 if (circuit
->u
.p2p
.neighbor
) {
1842 uint8_t threeway_state
;
1844 if (fabricd_initial_sync_is_in_progress(circuit
->area
)
1845 && fabricd_initial_sync_circuit(circuit
->area
) != circuit
)
1846 threeway_state
= ISIS_THREEWAY_DOWN
;
1848 threeway_state
= circuit
->u
.p2p
.neighbor
->threeway_state
;
1849 isis_tlvs_add_threeway_adj(tlvs
,
1852 circuit
->u
.p2p
.neighbor
->sysid
,
1853 circuit
->u
.p2p
.neighbor
->ext_circuit_id
);
1855 isis_tlvs_add_threeway_adj(tlvs
,
1862 isis_tlvs_set_protocols_supported(tlvs
, &circuit
->nlpids
);
1867 * TLV gets included if no topology is enabled on the interface,
1868 * if one topology other than #0 is enabled, or if multiple topologies
1871 struct isis_circuit_mt_setting
**mt_settings
;
1872 unsigned int mt_count
;
1874 mt_settings
= circuit_mt_settings(circuit
, &mt_count
);
1875 if (mt_count
== 0 && area_is_mt(circuit
->area
)) {
1876 tlvs
->mt_router_info_empty
= true;
1877 } else if ((mt_count
== 1
1878 && mt_settings
[0]->mtid
!= ISIS_MT_IPV4_UNICAST
)
1879 || (mt_count
> 1)) {
1880 for (unsigned int i
= 0; i
< mt_count
; i
++)
1881 isis_tlvs_add_mt_router_info(tlvs
, mt_settings
[i
]->mtid
,
1885 if (circuit
->ip_router
) {
1886 struct list
*circuit_ip_addrs
= fabricd_ip_addrs(circuit
);
1888 if (circuit_ip_addrs
)
1889 isis_tlvs_add_ipv4_addresses(tlvs
, circuit_ip_addrs
);
1892 if (circuit
->ipv6_router
&& circuit
->ipv6_link
)
1893 isis_tlvs_add_ipv6_addresses(tlvs
, circuit
->ipv6_link
);
1895 if (isis_pack_tlvs(tlvs
, circuit
->snd_stream
, len_pointer
,
1896 circuit
->pad_hellos
, false)) {
1897 isis_free_tlvs(tlvs
);
1898 return ISIS_WARNING
; /* XXX: Maybe Log TLV structure? */
1901 if (IS_DEBUG_ADJ_PACKETS
) {
1902 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
) {
1904 "ISIS-Adj (%s): Sending L%d LAN IIH on %s, length %zd",
1905 circuit
->area
->area_tag
, level
,
1906 circuit
->interface
->name
,
1907 stream_get_endp(circuit
->snd_stream
));
1910 "ISIS-Adj (%s): Sending P2P IIH on %s, length %zd",
1911 circuit
->area
->area_tag
,
1912 circuit
->interface
->name
,
1913 stream_get_endp(circuit
->snd_stream
));
1915 if (IS_DEBUG_PACKET_DUMP
)
1916 zlog_dump_data(STREAM_DATA(circuit
->snd_stream
),
1917 stream_get_endp(circuit
->snd_stream
));
1920 isis_free_tlvs(tlvs
);
1922 pdu_counter_count(circuit
->area
->pdu_tx_counters
,
1923 hello_pdu_type(circuit
, level
));
1924 retval
= circuit
->tx(circuit
, level
);
1925 if (retval
!= ISIS_OK
)
1926 flog_err(EC_ISIS_PACKET
,
1927 "ISIS-Adj (%s): Send L%d IIH on %s failed",
1928 circuit
->area
->area_tag
, level
,
1929 circuit
->interface
->name
);
1934 static int send_hello_cb(struct thread
*thread
)
1936 struct isis_circuit_arg
*arg
= THREAD_ARG(thread
);
1939 struct isis_circuit
*circuit
= arg
->circuit
;
1940 int level
= arg
->level
;
1944 if (circuit
->circ_type
== CIRCUIT_T_P2P
) {
1945 circuit
->u
.p2p
.t_send_p2p_hello
= NULL
;
1946 send_hello(circuit
, 1);
1947 send_hello_sched(circuit
, ISIS_LEVEL1
,
1948 1000 * circuit
->hello_interval
[1]);
1952 if (circuit
->circ_type
!= CIRCUIT_T_BROADCAST
) {
1953 zlog_warn("ISIS-Hello (%s): Trying to send hello on unknown circuit type %d",
1954 circuit
->area
->area_tag
, circuit
->circ_type
);
1955 return ISIS_WARNING
;
1958 circuit
->u
.bc
.t_send_lan_hello
[level
- 1] = NULL
;
1959 if (!(circuit
->is_type
& level
)) {
1960 zlog_warn("ISIS-Hello (%s): Trying to send L%d IIH in L%d-only circuit",
1961 circuit
->area
->area_tag
, level
, 3 - level
);
1962 return ISIS_WARNING
;
1965 if (circuit
->u
.bc
.run_dr_elect
[level
- 1])
1966 isis_dr_elect(circuit
, level
);
1968 int rv
= send_hello(circuit
, level
);
1970 /* set next timer thread */
1971 send_hello_sched(circuit
, level
, 1000 * circuit
->hello_interval
[level
- 1]);
1975 static void _send_hello_sched(struct isis_circuit
*circuit
,
1976 struct thread
**threadp
,
1977 int level
, long delay
)
1980 if (thread_timer_remain_msec(*threadp
) < (unsigned long)delay
)
1983 thread_cancel(*threadp
);
1986 thread_add_timer_msec(master
, send_hello_cb
,
1987 &circuit
->level_arg
[level
- 1],
1988 isis_jitter(delay
, IIH_JITTER
),
1992 void send_hello_sched(struct isis_circuit
*circuit
, int level
, long delay
)
1994 if (circuit
->circ_type
== CIRCUIT_T_P2P
) {
1995 _send_hello_sched(circuit
, &circuit
->u
.p2p
.t_send_p2p_hello
,
1996 ISIS_LEVEL1
, delay
);
2000 if (circuit
->circ_type
!= CIRCUIT_T_BROADCAST
) {
2001 zlog_warn("%s: encountered unknown circuit type %d on %s",
2002 __func__
, circuit
->circ_type
,
2003 circuit
->interface
->name
);
2007 for (int loop_level
= ISIS_LEVEL1
; loop_level
<= ISIS_LEVEL2
; loop_level
++) {
2008 if (!(loop_level
& level
))
2013 &circuit
->u
.bc
.t_send_lan_hello
[loop_level
- 1],
2022 * Count the maximum number of lsps that can be accomodated by a given size.
2024 #define LSP_ENTRIES_LEN (10 + ISIS_SYS_ID_LEN)
2025 static uint16_t get_max_lsp_count(uint16_t size
)
2029 uint16_t remaining_size
;
2031 /* First count the full size TLVs */
2032 tlv_count
= size
/ MAX_LSP_ENTRIES_TLV_SIZE
;
2033 lsp_count
= tlv_count
* (MAX_LSP_ENTRIES_TLV_SIZE
/ LSP_ENTRIES_LEN
);
2035 /* The last TLV, if any */
2036 remaining_size
= size
% MAX_LSP_ENTRIES_TLV_SIZE
;
2037 if (remaining_size
- 2 >= LSP_ENTRIES_LEN
)
2038 lsp_count
+= (remaining_size
- 2) / LSP_ENTRIES_LEN
;
2043 int send_csnp(struct isis_circuit
*circuit
, int level
)
2045 if (lspdb_count(&circuit
->area
->lspdb
[level
- 1]) == 0)
2048 uint8_t pdu_type
= (level
== ISIS_LEVEL1
) ? L1_COMPLETE_SEQ_NUM
2049 : L2_COMPLETE_SEQ_NUM
;
2051 isis_circuit_stream(circuit
, &circuit
->snd_stream
);
2052 fill_fixed_hdr(pdu_type
, circuit
->snd_stream
);
2054 size_t len_pointer
= stream_get_endp(circuit
->snd_stream
);
2055 stream_putw(circuit
->snd_stream
, 0);
2056 stream_put(circuit
->snd_stream
, isis
->sysid
, ISIS_SYS_ID_LEN
);
2057 /* with zero circuit id - ref 9.10, 9.11 */
2058 stream_putc(circuit
->snd_stream
, 0);
2060 size_t start_pointer
= stream_get_endp(circuit
->snd_stream
);
2061 stream_put(circuit
->snd_stream
, 0, ISIS_SYS_ID_LEN
+ 2);
2062 size_t end_pointer
= stream_get_endp(circuit
->snd_stream
);
2063 stream_put(circuit
->snd_stream
, 0, ISIS_SYS_ID_LEN
+ 2);
2065 struct isis_passwd
*passwd
= (level
== ISIS_LEVEL1
)
2066 ? &circuit
->area
->area_passwd
2067 : &circuit
->area
->domain_passwd
;
2069 struct isis_tlvs
*tlvs
= isis_alloc_tlvs();
2071 if (CHECK_FLAG(passwd
->snp_auth
, SNP_AUTH_SEND
))
2072 isis_tlvs_add_auth(tlvs
, passwd
);
2074 size_t tlv_start
= stream_get_endp(circuit
->snd_stream
);
2075 if (isis_pack_tlvs(tlvs
, circuit
->snd_stream
, len_pointer
, false,
2077 isis_free_tlvs(tlvs
);
2078 return ISIS_WARNING
;
2080 isis_free_tlvs(tlvs
);
2083 get_max_lsp_count(STREAM_WRITEABLE(circuit
->snd_stream
));
2085 uint8_t start
[ISIS_SYS_ID_LEN
+ 2];
2086 memset(start
, 0x00, ISIS_SYS_ID_LEN
+ 2);
2087 uint8_t stop
[ISIS_SYS_ID_LEN
+ 2];
2088 memset(stop
, 0xff, ISIS_SYS_ID_LEN
+ 2);
2092 tlvs
= isis_alloc_tlvs();
2093 if (CHECK_FLAG(passwd
->snp_auth
, SNP_AUTH_SEND
))
2094 isis_tlvs_add_auth(tlvs
, passwd
);
2096 struct isis_lsp
*last_lsp
;
2097 isis_tlvs_add_csnp_entries(tlvs
, start
, stop
, num_lsps
,
2098 &circuit
->area
->lspdb
[level
- 1],
2101 * Update the stop lsp_id before encoding this CSNP.
2103 if (tlvs
->lsp_entries
.count
< num_lsps
) {
2104 memset(stop
, 0xff, ISIS_SYS_ID_LEN
+ 2);
2106 memcpy(stop
, last_lsp
->hdr
.lsp_id
, sizeof(stop
));
2109 memcpy(STREAM_DATA(circuit
->snd_stream
) + start_pointer
, start
,
2110 ISIS_SYS_ID_LEN
+ 2);
2111 memcpy(STREAM_DATA(circuit
->snd_stream
) + end_pointer
, stop
,
2112 ISIS_SYS_ID_LEN
+ 2);
2113 stream_set_endp(circuit
->snd_stream
, tlv_start
);
2114 if (isis_pack_tlvs(tlvs
, circuit
->snd_stream
, len_pointer
,
2116 isis_free_tlvs(tlvs
);
2117 return ISIS_WARNING
;
2120 if (IS_DEBUG_SNP_PACKETS
) {
2122 "ISIS-Snp (%s): Sending L%d CSNP on %s, length %zd",
2123 circuit
->area
->area_tag
, level
,
2124 circuit
->interface
->name
,
2125 stream_get_endp(circuit
->snd_stream
));
2126 log_multiline(LOG_DEBUG
, " ", "%s",
2127 isis_format_tlvs(tlvs
));
2128 if (IS_DEBUG_PACKET_DUMP
)
2130 STREAM_DATA(circuit
->snd_stream
),
2131 stream_get_endp(circuit
->snd_stream
));
2134 pdu_counter_count(circuit
->area
->pdu_tx_counters
, pdu_type
);
2135 int retval
= circuit
->tx(circuit
, level
);
2136 if (retval
!= ISIS_OK
) {
2137 flog_err(EC_ISIS_PACKET
,
2138 "ISIS-Snp (%s): Send L%d CSNP on %s failed",
2139 circuit
->area
->area_tag
, level
,
2140 circuit
->interface
->name
);
2141 isis_free_tlvs(tlvs
);
2146 * Start lsp_id of the next CSNP should be one plus the
2147 * stop lsp_id in this current CSNP.
2149 memcpy(start
, stop
, ISIS_SYS_ID_LEN
+ 2);
2151 for (int i
= ISIS_SYS_ID_LEN
+ 1; i
>= 0; --i
) {
2152 if (start
[i
] < (uint8_t)0xff) {
2158 memset(stop
, 0xff, ISIS_SYS_ID_LEN
+ 2);
2159 isis_free_tlvs(tlvs
);
2165 int send_l1_csnp(struct thread
*thread
)
2167 struct isis_circuit
*circuit
;
2169 circuit
= THREAD_ARG(thread
);
2172 circuit
->t_send_csnp
[0] = NULL
;
2174 if ((circuit
->circ_type
== CIRCUIT_T_BROADCAST
2175 && circuit
->u
.bc
.is_dr
[0])
2176 || circuit
->circ_type
== CIRCUIT_T_P2P
) {
2177 send_csnp(circuit
, 1);
2179 /* set next timer thread */
2180 thread_add_timer(master
, send_l1_csnp
, circuit
,
2181 isis_jitter(circuit
->csnp_interval
[0], CSNP_JITTER
),
2182 &circuit
->t_send_csnp
[0]);
2187 int send_l2_csnp(struct thread
*thread
)
2189 struct isis_circuit
*circuit
;
2191 circuit
= THREAD_ARG(thread
);
2194 circuit
->t_send_csnp
[1] = NULL
;
2196 if ((circuit
->circ_type
== CIRCUIT_T_BROADCAST
2197 && circuit
->u
.bc
.is_dr
[1])
2198 || circuit
->circ_type
== CIRCUIT_T_P2P
) {
2199 send_csnp(circuit
, 2);
2201 /* set next timer thread */
2202 thread_add_timer(master
, send_l2_csnp
, circuit
,
2203 isis_jitter(circuit
->csnp_interval
[1], CSNP_JITTER
),
2204 &circuit
->t_send_csnp
[1]);
2210 * 7.3.15.4 action on expiration of partial SNP interval
2213 static int send_psnp(int level
, struct isis_circuit
*circuit
)
2215 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
2216 && circuit
->u
.bc
.is_dr
[level
- 1])
2219 if (lspdb_count(&circuit
->area
->lspdb
[level
- 1]) == 0)
2222 if (!circuit
->snd_stream
)
2225 uint8_t pdu_type
= (level
== ISIS_LEVEL1
) ? L1_PARTIAL_SEQ_NUM
2226 : L2_PARTIAL_SEQ_NUM
;
2228 isis_circuit_stream(circuit
, &circuit
->snd_stream
);
2229 fill_fixed_hdr(pdu_type
, circuit
->snd_stream
);
2231 size_t len_pointer
= stream_get_endp(circuit
->snd_stream
);
2232 stream_putw(circuit
->snd_stream
, 0); /* length is filled in later */
2233 stream_put(circuit
->snd_stream
, isis
->sysid
, ISIS_SYS_ID_LEN
);
2234 stream_putc(circuit
->snd_stream
, circuit
->idx
);
2236 struct isis_passwd
*passwd
= (level
== ISIS_LEVEL1
)
2237 ? &circuit
->area
->area_passwd
2238 : &circuit
->area
->domain_passwd
;
2240 struct isis_tlvs
*tlvs
= isis_alloc_tlvs();
2242 if (CHECK_FLAG(passwd
->snp_auth
, SNP_AUTH_SEND
))
2243 isis_tlvs_add_auth(tlvs
, passwd
);
2245 size_t tlv_start
= stream_get_endp(circuit
->snd_stream
);
2246 if (isis_pack_tlvs(tlvs
, circuit
->snd_stream
, len_pointer
, false,
2248 isis_free_tlvs(tlvs
);
2249 return ISIS_WARNING
;
2251 isis_free_tlvs(tlvs
);
2254 get_max_lsp_count(STREAM_WRITEABLE(circuit
->snd_stream
));
2257 struct isis_lsp
*lsp
;
2259 tlvs
= isis_alloc_tlvs();
2260 if (CHECK_FLAG(passwd
->snp_auth
, SNP_AUTH_SEND
))
2261 isis_tlvs_add_auth(tlvs
, passwd
);
2263 frr_each (lspdb
, &circuit
->area
->lspdb
[level
- 1], lsp
) {
2264 if (ISIS_CHECK_FLAG(lsp
->SSNflags
, circuit
))
2265 isis_tlvs_add_lsp_entry(tlvs
, lsp
);
2267 if (tlvs
->lsp_entries
.count
== num_lsps
)
2271 if (!tlvs
->lsp_entries
.count
) {
2272 isis_free_tlvs(tlvs
);
2276 stream_set_endp(circuit
->snd_stream
, tlv_start
);
2277 if (isis_pack_tlvs(tlvs
, circuit
->snd_stream
, len_pointer
,
2279 isis_free_tlvs(tlvs
);
2280 return ISIS_WARNING
;
2283 if (IS_DEBUG_SNP_PACKETS
) {
2285 "ISIS-Snp (%s): Sending L%d PSNP on %s, length %zd",
2286 circuit
->area
->area_tag
, level
,
2287 circuit
->interface
->name
,
2288 stream_get_endp(circuit
->snd_stream
));
2289 log_multiline(LOG_DEBUG
, " ", "%s",
2290 isis_format_tlvs(tlvs
));
2291 if (IS_DEBUG_PACKET_DUMP
)
2293 STREAM_DATA(circuit
->snd_stream
),
2294 stream_get_endp(circuit
->snd_stream
));
2297 pdu_counter_count(circuit
->area
->pdu_tx_counters
, pdu_type
);
2298 int retval
= circuit
->tx(circuit
, level
);
2299 if (retval
!= ISIS_OK
) {
2300 flog_err(EC_ISIS_PACKET
,
2301 "ISIS-Snp (%s): Send L%d PSNP on %s failed",
2302 circuit
->area
->area_tag
, level
,
2303 circuit
->interface
->name
);
2304 isis_free_tlvs(tlvs
);
2309 * sending succeeded, we can clear SSN flags of this circuit
2310 * for the LSPs in list
2312 struct isis_lsp_entry
*entry_head
;
2313 entry_head
= (struct isis_lsp_entry
*)tlvs
->lsp_entries
.head
;
2314 for (struct isis_lsp_entry
*entry
= entry_head
; entry
;
2315 entry
= entry
->next
)
2316 ISIS_CLEAR_FLAG(entry
->lsp
->SSNflags
, circuit
);
2317 isis_free_tlvs(tlvs
);
2323 int send_l1_psnp(struct thread
*thread
)
2326 struct isis_circuit
*circuit
;
2328 circuit
= THREAD_ARG(thread
);
2331 circuit
->t_send_psnp
[0] = NULL
;
2333 send_psnp(1, circuit
);
2334 /* set next timer thread */
2335 thread_add_timer(master
, send_l1_psnp
, circuit
,
2336 isis_jitter(circuit
->psnp_interval
[0], PSNP_JITTER
),
2337 &circuit
->t_send_psnp
[0]);
2343 * 7.3.15.4 action on expiration of partial SNP interval
2346 int send_l2_psnp(struct thread
*thread
)
2348 struct isis_circuit
*circuit
;
2350 circuit
= THREAD_ARG(thread
);
2353 circuit
->t_send_psnp
[1] = NULL
;
2355 send_psnp(2, circuit
);
2357 /* set next timer thread */
2358 thread_add_timer(master
, send_l2_psnp
, circuit
,
2359 isis_jitter(circuit
->psnp_interval
[1], PSNP_JITTER
),
2360 &circuit
->t_send_psnp
[1]);
2366 * ISO 10589 - 7.3.14.3
2368 void send_lsp(struct isis_circuit
*circuit
, struct isis_lsp
*lsp
,
2369 enum isis_tx_type tx_type
)
2372 int retval
= ISIS_OK
;
2374 if (circuit
->state
!= C_STATE_UP
|| circuit
->is_passive
== 1)
2378 * Do not send if levels do not match
2380 if (!(lsp
->level
& circuit
->is_type
))
2384 * Do not send if we do not have adjacencies in state up on the circuit
2386 if (circuit
->upadjcount
[lsp
->level
- 1] == 0)
2389 /* stream_copy will assert and stop program execution if LSP is larger
2391 * the circuit's MTU. So handle and log this case here. */
2392 if (stream_get_endp(lsp
->pdu
) > stream_get_size(circuit
->snd_stream
)) {
2395 "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.",
2396 circuit
->area
->area_tag
, lsp
->level
,
2397 rawlspid_print(lsp
->hdr
.lsp_id
), lsp
->hdr
.seqno
,
2398 lsp
->hdr
.checksum
, lsp
->hdr
.rem_lifetime
,
2399 circuit
->interface
->name
, stream_get_endp(lsp
->pdu
),
2400 stream_get_size(circuit
->snd_stream
));
2402 /* send a northbound notification */
2403 isis_notif_lsp_too_large(circuit
, stream_get_endp(lsp
->pdu
),
2404 rawlspid_print(lsp
->hdr
.lsp_id
));
2405 #endif /* ifndef FABRICD */
2406 if (IS_DEBUG_PACKET_DUMP
)
2407 zlog_dump_data(STREAM_DATA(lsp
->pdu
),
2408 stream_get_endp(lsp
->pdu
));
2409 retval
= ISIS_ERROR
;
2413 /* copy our lsp to the send buffer */
2414 stream_copy(circuit
->snd_stream
, lsp
->pdu
);
2416 if (tx_type
== TX_LSP_CIRCUIT_SCOPED
) {
2417 stream_putc_at(circuit
->snd_stream
, 4, FS_LINK_STATE
);
2418 stream_putc_at(circuit
->snd_stream
, 7,
2419 L2_CIRCUIT_FLOODING_SCOPE
);
2422 if (IS_DEBUG_UPDATE_PACKETS
) {
2423 zlog_debug("ISIS-Upd (%s): Sending %sL%d LSP %s, seq 0x%08x, cksum 0x%04hx, lifetime %hus on %s",
2424 circuit
->area
->area_tag
,
2425 (tx_type
== TX_LSP_CIRCUIT_SCOPED
)
2426 ? "Circuit scoped " : "",
2428 rawlspid_print(lsp
->hdr
.lsp_id
), lsp
->hdr
.seqno
,
2429 lsp
->hdr
.checksum
, lsp
->hdr
.rem_lifetime
,
2430 circuit
->interface
->name
);
2431 if (IS_DEBUG_PACKET_DUMP
)
2432 zlog_dump_data(STREAM_DATA(circuit
->snd_stream
),
2433 stream_get_endp(circuit
->snd_stream
));
2436 uint8_t pdu_type
= (tx_type
== TX_LSP_CIRCUIT_SCOPED
) ? FS_LINK_STATE
2437 : (lsp
->level
== ISIS_LEVEL1
) ? L1_LINK_STATE
2441 pdu_counter_count(circuit
->area
->pdu_tx_counters
, pdu_type
);
2442 retval
= circuit
->tx(circuit
, lsp
->level
);
2443 if (retval
!= ISIS_OK
) {
2444 flog_err(EC_ISIS_PACKET
,
2445 "ISIS-Upd (%s): Send L%d LSP on %s failed %s",
2446 circuit
->area
->area_tag
, lsp
->level
,
2447 circuit
->interface
->name
,
2448 (retval
== ISIS_WARNING
) ? "temporarily"
2454 || (retval
== ISIS_OK
&& circuit
->circ_type
== CIRCUIT_T_BROADCAST
)
2455 || (retval
!= ISIS_OK
&& retval
!= ISIS_WARNING
)) {
2456 /* SRM flag will trigger retransmission. We will not retransmit
2458 * encountered a fatal error.
2459 * On success, they should only be cleared if it's a broadcast
2461 * On a P2P circuit, we will wait for the ack from the neighbor
2465 isis_tx_queue_del(circuit
->tx_queue
, lsp
);