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/dict.h"
40 #include "isisd/isis_constants.h"
41 #include "isisd/isis_common.h"
42 #include "isisd/isis_flags.h"
43 #include "isisd/isis_adjacency.h"
44 #include "isisd/isis_circuit.h"
45 #include "isisd/isis_network.h"
46 #include "isisd/isis_misc.h"
47 #include "isisd/isis_dr.h"
48 #include "isisd/isisd.h"
49 #include "isisd/isis_dynhn.h"
50 #include "isisd/isis_lsp.h"
51 #include "isisd/isis_pdu.h"
52 #include "isisd/iso_checksum.h"
53 #include "isisd/isis_csm.h"
54 #include "isisd/isis_events.h"
55 #include "isisd/isis_te.h"
56 #include "isisd/isis_mt.h"
57 #include "isisd/isis_tlvs.h"
58 #include "isisd/isis_errors.h"
59 #include "isisd/fabricd.h"
60 #include "isisd/isis_tx_queue.h"
61 #include "isisd/isis_pdu_counter.h"
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 (isis
->debugs
& 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 (isis
->debugs
& DEBUG_ADJ_PACKETS
) {
147 zlog_debug("ISIS-Adj (%s): Rcvd P2P IIH from (%s) which lists IS/Circuit different from us as neighbor.",
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
;
191 if (tw_adj
&& adj
->threeway_state
== ISIS_THREEWAY_DOWN
)
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 /* Update MPLS TE Remote IP address parameter if possible */
204 if (IS_MPLS_TE(iih
->circuit
->area
->mta
)
205 && IS_MPLS_TE(iih
->circuit
->mtc
)
206 && adj
->ipv4_address_count
)
207 set_circuitparams_rmt_ipaddr(iih
->circuit
->mtc
,
208 adj
->ipv4_addresses
[0]);
210 /* lets take care of the expiry */
211 THREAD_TIMER_OFF(adj
->t_expire
);
212 thread_add_timer(master
, isis_adj_expire
, adj
, (long)adj
->hold_time
,
215 /* While fabricds initial sync is in progress, ignore hellos from other
216 * interfaces than the one we are performing the initial sync on. */
217 if (fabricd_initial_sync_is_in_progress(iih
->circuit
->area
)
218 && fabricd_initial_sync_circuit(iih
->circuit
->area
) != iih
->circuit
)
221 /* 8.2.5.2 a) a match was detected */
222 if (isis_tlvs_area_addresses_match(iih
->tlvs
,
223 iih
->circuit
->area
->area_addrs
)) {
224 /* 8.2.5.2 a) 2) If the system is L1 - table 5 */
225 if (iih
->circuit
->area
->is_type
== IS_LEVEL_1
) {
226 switch (iih
->circ_type
) {
228 case IS_LEVEL_1_AND_2
:
229 if (adj
->adj_state
!= ISIS_ADJ_UP
230 || adj
->adj_usage
== ISIS_ADJ_LEVEL1
) {
231 isis_adj_process_threeway(adj
, tw_adj
,
236 if (adj
->adj_state
!= ISIS_ADJ_UP
) {
237 /* (7) reject - wrong system type event
239 zlog_warn("wrongSystemType");
241 } else if (adj
->adj_usage
== ISIS_ADJ_LEVEL1
) {
242 /* (6) down - wrong system */
243 isis_adj_state_change(adj
,
251 /* 8.2.5.2 a) 3) If the system is L1L2 - table 6 */
252 if (iih
->circuit
->area
->is_type
== IS_LEVEL_1_AND_2
) {
253 switch (iih
->circ_type
) {
255 if (adj
->adj_state
!= ISIS_ADJ_UP
256 || adj
->adj_usage
== ISIS_ADJ_LEVEL1
) {
257 isis_adj_process_threeway(adj
, tw_adj
,
259 } else if ((adj
->adj_usage
260 == ISIS_ADJ_LEVEL1AND2
)
262 == ISIS_ADJ_LEVEL2
)) {
263 /* (8) down - wrong system */
264 isis_adj_state_change(adj
,
270 if (adj
->adj_state
!= ISIS_ADJ_UP
271 || adj
->adj_usage
== ISIS_ADJ_LEVEL2
) {
272 isis_adj_process_threeway(adj
, tw_adj
,
274 } else if ((adj
->adj_usage
== ISIS_ADJ_LEVEL1
)
276 == ISIS_ADJ_LEVEL1AND2
)) {
277 /* (8) down - wrong system */
278 isis_adj_state_change(adj
,
283 case IS_LEVEL_1_AND_2
:
284 if (adj
->adj_state
!= ISIS_ADJ_UP
285 || adj
->adj_usage
== ISIS_ADJ_LEVEL1AND2
) {
286 isis_adj_process_threeway(adj
, tw_adj
,
287 ISIS_ADJ_LEVEL1AND2
);
288 } else if ((adj
->adj_usage
== ISIS_ADJ_LEVEL1
)
290 == ISIS_ADJ_LEVEL2
)) {
291 /* (8) down - wrong system */
292 isis_adj_state_change(adj
,
300 /* 8.2.5.2 a) 4) If the system is L2 - table 7 */
301 if (iih
->circuit
->area
->is_type
== IS_LEVEL_2
) {
302 switch (iih
->circ_type
) {
304 if (adj
->adj_state
!= ISIS_ADJ_UP
) {
305 /* (5) reject - wrong system type event
307 zlog_warn("wrongSystemType");
309 } else if ((adj
->adj_usage
310 == ISIS_ADJ_LEVEL1AND2
)
312 == ISIS_ADJ_LEVEL2
)) {
313 /* (6) down - wrong system */
314 isis_adj_state_change(adj
,
319 case IS_LEVEL_1_AND_2
:
321 if (adj
->adj_state
!= ISIS_ADJ_UP
322 || adj
->adj_usage
== ISIS_ADJ_LEVEL2
) {
323 isis_adj_process_threeway(adj
, tw_adj
,
325 } else if (adj
->adj_usage
326 == ISIS_ADJ_LEVEL1AND2
) {
327 /* (6) down - wrong system */
328 isis_adj_state_change(adj
,
336 /* 8.2.5.2 b) if no match was detected */
337 else if (listcount(iih
->circuit
->area
->area_addrs
) > 0) {
338 if (iih
->circuit
->area
->is_type
== IS_LEVEL_1
) {
339 /* 8.2.5.2 b) 1) is_type L1 and adj is not up */
340 if (adj
->adj_state
!= ISIS_ADJ_UP
) {
341 isis_adj_state_change(adj
, ISIS_ADJ_DOWN
,
343 /* 8.2.5.2 b) 2)is_type L1 and adj is up */
345 isis_adj_state_change(adj
, ISIS_ADJ_DOWN
,
346 "Down - Area Mismatch");
349 /* 8.2.5.2 b 3 If the system is L2 or L1L2 - table 8 */
351 switch (iih
->circ_type
) {
353 if (adj
->adj_state
!= ISIS_ADJ_UP
) {
354 /* (6) reject - Area Mismatch event */
355 zlog_warn("AreaMismatch");
357 } else if (adj
->adj_usage
== ISIS_ADJ_LEVEL1
) {
358 /* (7) down - area mismatch */
359 isis_adj_state_change(adj
,
363 } else if ((adj
->adj_usage
364 == ISIS_ADJ_LEVEL1AND2
)
366 == ISIS_ADJ_LEVEL2
)) {
367 /* (7) down - wrong system */
368 isis_adj_state_change(adj
,
373 case IS_LEVEL_1_AND_2
:
375 if (adj
->adj_state
!= ISIS_ADJ_UP
376 || adj
->adj_usage
== ISIS_ADJ_LEVEL2
) {
377 isis_adj_process_threeway(adj
, tw_adj
,
379 } else if (adj
->adj_usage
== ISIS_ADJ_LEVEL1
) {
380 /* (7) down - wrong system */
381 isis_adj_state_change(adj
,
384 } else if (adj
->adj_usage
385 == ISIS_ADJ_LEVEL1AND2
) {
386 if (iih
->circ_type
== IS_LEVEL_2
) {
387 /* (7) down - wrong system */
388 isis_adj_state_change(
392 /* (7) down - area mismatch */
393 isis_adj_state_change(
402 /* down - area mismatch */
403 isis_adj_state_change(adj
, ISIS_ADJ_DOWN
, "Area Mismatch");
406 if (adj
->adj_state
== ISIS_ADJ_UP
&& changed
) {
407 lsp_regenerate_schedule(adj
->circuit
->area
,
408 isis_adj_usage2levels(adj
->adj_usage
),
412 /* 8.2.5.2 c) if the action was up - comparing circuit IDs */
413 /* FIXME - Missing parts */
415 /* some of my own understanding of the ISO, why the heck does
416 * it not say what should I change the system_type to...
418 switch (adj
->adj_usage
) {
419 case ISIS_ADJ_LEVEL1
:
420 adj
->sys_type
= ISIS_SYSTYPE_L1_IS
;
422 case ISIS_ADJ_LEVEL2
:
423 adj
->sys_type
= ISIS_SYSTYPE_L2_IS
;
425 case ISIS_ADJ_LEVEL1AND2
:
426 adj
->sys_type
= ISIS_SYSTYPE_L2_IS
;
429 adj
->sys_type
= ISIS_SYSTYPE_UNKNOWN
;
433 if (isis
->debugs
& DEBUG_ADJ_PACKETS
) {
435 "ISIS-Adj (%s): Rcvd P2P IIH from (%s), cir type %s,"
436 " cir id %hhu, length %" PRIu16
,
437 iih
->circuit
->area
->area_tag
,
438 iih
->circuit
->interface
->name
,
439 circuit_t2string(iih
->circuit
->is_type
),
440 iih
->circuit
->circuit_id
, iih
->pdu_len
);
446 static int process_lan_hello(struct iih_info
*iih
)
448 struct isis_adjacency
*adj
;
449 adj
= isis_adj_lookup(iih
->sys_id
,
450 iih
->circuit
->u
.bc
.adjdb
[iih
->level
- 1]);
451 if ((adj
== NULL
) || (memcmp(adj
->snpa
, iih
->ssnpa
, ETH_ALEN
))
452 || (adj
->level
!= iih
->level
)) {
454 /* Do as in 8.4.2.5 */
455 adj
= isis_new_adj(iih
->sys_id
, iih
->ssnpa
, iih
->level
,
459 memcpy(adj
->snpa
, iih
->ssnpa
, 6);
461 memset(adj
->snpa
, ' ', 6);
463 adj
->level
= iih
->level
;
465 isis_adj_state_change(adj
, ISIS_ADJ_INITIALIZING
, NULL
);
467 if (iih
->level
== IS_LEVEL_1
)
468 adj
->sys_type
= ISIS_SYSTYPE_L1_IS
;
470 adj
->sys_type
= ISIS_SYSTYPE_L2_IS
;
471 list_delete_all_node(
472 iih
->circuit
->u
.bc
.lan_neighs
[iih
->level
- 1]);
473 isis_adj_build_neigh_list(
474 iih
->circuit
->u
.bc
.adjdb
[iih
->level
- 1],
475 iih
->circuit
->u
.bc
.lan_neighs
[iih
->level
- 1]);
478 if (adj
->dis_record
[iih
->level
- 1].dis
== ISIS_IS_DIS
) {
479 uint8_t *dis
= (iih
->level
== 1)
480 ? iih
->circuit
->u
.bc
.l1_desig_is
481 : iih
->circuit
->u
.bc
.l2_desig_is
;
483 if (memcmp(dis
, iih
->dis
, ISIS_SYS_ID_LEN
+ 1)) {
484 thread_add_event(master
, isis_event_dis_status_change
,
485 iih
->circuit
, 0, NULL
);
486 memcpy(dis
, iih
->dis
, ISIS_SYS_ID_LEN
+ 1);
490 adj
->circuit_t
= iih
->circ_type
;
491 adj
->hold_time
= iih
->holdtime
;
492 adj
->last_upd
= time(NULL
);
493 adj
->prio
[iih
->level
- 1] = iih
->priority
;
494 memcpy(adj
->lanid
, iih
->dis
, ISIS_SYS_ID_LEN
+ 1);
497 isis_tlvs_to_adj(iih
->tlvs
, adj
, &changed
);
498 changed
|= tlvs_to_adj_mt_set(iih
->tlvs
, iih
->v4_usable
, iih
->v6_usable
,
501 /* lets take care of the expiry */
502 THREAD_TIMER_OFF(adj
->t_expire
);
503 thread_add_timer(master
, isis_adj_expire
, adj
, (long)adj
->hold_time
,
507 * If the snpa for this circuit is found from LAN Neighbours TLV
508 * we have two-way communication -> adjacency can be put to state "up"
510 bool own_snpa_found
=
511 isis_tlvs_own_snpa_found(iih
->tlvs
, iih
->circuit
->u
.bc
.snpa
);
513 if (adj
->adj_state
!= ISIS_ADJ_UP
) {
514 if (own_snpa_found
) {
515 isis_adj_state_change(
517 "own SNPA found in LAN Neighbours TLV");
520 if (!own_snpa_found
) {
521 isis_adj_state_change(
522 adj
, ISIS_ADJ_INITIALIZING
,
523 "own SNPA not found in LAN Neighbours TLV");
527 if (adj
->adj_state
== ISIS_ADJ_UP
&& changed
)
528 lsp_regenerate_schedule(adj
->circuit
->area
, iih
->level
, 0);
530 if (isis
->debugs
& DEBUG_ADJ_PACKETS
) {
532 "ISIS-Adj (%s): Rcvd L%d LAN IIH from %s on %s, cirType %s, cirID %u, length %zd",
533 iih
->circuit
->area
->area_tag
, iih
->level
,
534 snpa_print(iih
->ssnpa
), iih
->circuit
->interface
->name
,
535 circuit_t2string(iih
->circuit
->is_type
),
536 iih
->circuit
->circuit_id
,
537 stream_get_endp(iih
->circuit
->rcv_stream
));
542 static int pdu_len_validate(uint16_t pdu_len
, struct isis_circuit
*circuit
)
544 if (pdu_len
< stream_get_getp(circuit
->rcv_stream
)
545 || pdu_len
> ISO_MTU(circuit
)
546 || pdu_len
> stream_get_endp(circuit
->rcv_stream
))
549 if (pdu_len
< stream_get_endp(circuit
->rcv_stream
))
550 stream_set_endp(circuit
->rcv_stream
, pdu_len
);
554 static int process_hello(uint8_t pdu_type
, struct isis_circuit
*circuit
,
557 /* keep a copy of the raw pdu for NB notifications */
558 size_t pdu_start
= stream_get_getp(circuit
->rcv_stream
);
559 size_t pdu_end
= stream_get_endp(circuit
->rcv_stream
);
560 char raw_pdu
[pdu_end
- pdu_start
];
561 bool p2p_hello
= (pdu_type
== P2P_HELLO
);
562 int level
= p2p_hello
? 0
563 : (pdu_type
== L1_LAN_HELLO
) ? ISIS_LEVEL1
565 const char *pdu_name
=
568 : (level
== ISIS_LEVEL1
) ? "L1 LAN IIH" : "L2 LAN IIH";
571 stream_get_from(raw_pdu
, circuit
->rcv_stream
, pdu_start
,
572 pdu_end
- pdu_start
);
573 if (isis
->debugs
& DEBUG_ADJ_PACKETS
) {
574 zlog_debug("ISIS-Adj (%s): Rcvd %s on %s, cirType %s, cirID %u",
575 circuit
->area
->area_tag
, pdu_name
,
576 circuit
->interface
->name
,
577 circuit_t2string(circuit
->is_type
),
578 circuit
->circuit_id
);
579 if (isis
->debugs
& DEBUG_PACKET_DUMP
)
580 zlog_dump_data(STREAM_DATA(circuit
->rcv_stream
),
581 stream_get_endp(circuit
->rcv_stream
));
585 if (circuit
->circ_type
!= CIRCUIT_T_P2P
) {
586 zlog_warn("p2p hello on non p2p circuit");
588 isis_notif_reject_adjacency(
589 circuit
, "p2p hello on non p2p circuit",
591 #endif /* ifndef FABRICD */
595 if (circuit
->circ_type
!= CIRCUIT_T_BROADCAST
) {
596 zlog_warn("lan hello on non broadcast circuit");
598 isis_notif_reject_adjacency(
599 circuit
, "lan hello on non broadcast circuit",
601 #endif /* ifndef FABRICD */
605 if (circuit
->ext_domain
) {
607 "level %d LAN Hello received over circuit with externalDomain = true",
610 isis_notif_reject_adjacency(
612 "LAN Hello received over circuit with externalDomain = true",
614 #endif /* ifndef FABRICD */
618 if (!(circuit
->is_type
& level
)) {
619 if (isis
->debugs
& DEBUG_ADJ_PACKETS
) {
621 "ISIS-Adj (%s): Interface level mismatch, %s",
622 circuit
->area
->area_tag
,
623 circuit
->interface
->name
);
626 isis_notif_reject_adjacency(
627 circuit
, "Interface level mismatch", raw_pdu
);
628 #endif /* ifndef FABRICD */
633 struct iih_info iih
= {
634 .circuit
= circuit
, .ssnpa
= ssnpa
, .level
= level
};
636 /* Generic IIH Header */
637 iih
.circ_type
= stream_getc(circuit
->rcv_stream
) & 0x03;
638 stream_get(iih
.sys_id
, circuit
->rcv_stream
, ISIS_SYS_ID_LEN
);
639 iih
.holdtime
= stream_getw(circuit
->rcv_stream
);
640 iih
.pdu_len
= stream_getw(circuit
->rcv_stream
);
643 iih
.circuit_id
= stream_getc(circuit
->rcv_stream
);
645 iih
.priority
= stream_getc(circuit
->rcv_stream
);
646 stream_get(iih
.dis
, circuit
->rcv_stream
, ISIS_SYS_ID_LEN
+ 1);
649 if (pdu_len_validate(iih
.pdu_len
, circuit
)) {
651 "ISIS-Adj (%s): Rcvd %s from (%s) with invalid pdu length %" PRIu16
,
652 circuit
->area
->area_tag
, pdu_name
,
653 circuit
->interface
->name
, iih
.pdu_len
);
655 isis_notif_reject_adjacency(circuit
, "Invalid PDU length",
657 #endif /* ifndef FABRICD */
661 if (!p2p_hello
&& !(level
& iih
.circ_type
)) {
662 flog_err(EC_ISIS_PACKET
,
663 "Level %d LAN Hello with Circuit Type %d", level
,
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
);
679 isis_notif_reject_adjacency(circuit
, "Failed to unpack TLVs",
681 #endif /* ifndef FABRICD */
685 if (!iih
.tlvs
->area_addresses
.count
) {
686 zlog_warn("No Area addresses TLV in %s", pdu_name
);
688 /* send northbound notification */
689 isis_notif_area_mismatch(circuit
, raw_pdu
);
690 #endif /* ifndef FABRICD */
694 if (!iih
.tlvs
->protocols_supported
.count
) {
695 zlog_warn("No supported protocols TLV in %s", pdu_name
);
697 isis_notif_reject_adjacency(
698 circuit
, "No supported protocols TLV", raw_pdu
);
699 #endif /* ifndef FABRICD */
703 int auth_code
= isis_tlvs_auth_is_valid(iih
.tlvs
, &circuit
->passwd
,
704 circuit
->rcv_stream
, false);
705 if (auth_code
!= ISIS_AUTH_OK
) {
706 isis_event_auth_failure(circuit
->area
->area_tag
,
707 "IIH authentication failure",
710 /* send northbound notification */
711 stream_get_from(raw_pdu
, circuit
->rcv_stream
, pdu_start
,
712 pdu_end
- pdu_start
);
713 if (auth_code
== ISIS_AUTH_FAILURE
)
714 isis_notif_authentication_failure(circuit
, raw_pdu
);
715 else /* AUTH_TYPE_FAILURE or NO_VALIDATOR */
716 isis_notif_authentication_type_failure(circuit
,
718 #endif /* ifndef FABRICD */
722 if (!memcmp(iih
.sys_id
, isis
->sysid
, ISIS_SYS_ID_LEN
)) {
724 "ISIS-Adj (%s): Received IIH with own sysid - discard",
725 circuit
->area
->area_tag
);
727 isis_notif_reject_adjacency(
728 circuit
, "Received IIH with our own sysid", raw_pdu
);
729 #endif /* ifndef FABRICD */
734 && (listcount(circuit
->area
->area_addrs
) == 0
735 || (level
== ISIS_LEVEL1
736 && !isis_tlvs_area_addresses_match(
737 iih
.tlvs
, circuit
->area
->area_addrs
)))) {
738 if (isis
->debugs
& DEBUG_ADJ_PACKETS
) {
740 "ISIS-Adj (%s): Area mismatch, level %d IIH on %s",
741 circuit
->area
->area_tag
, level
,
742 circuit
->interface
->name
);
745 /* send northbound notification */
746 isis_notif_area_mismatch(circuit
, raw_pdu
);
747 #endif /* ifndef FABRICD */
751 iih
.v4_usable
= (fabricd_ip_addrs(circuit
)
752 && iih
.tlvs
->ipv4_address
.count
);
754 iih
.v6_usable
= (circuit
->ipv6_link
&& listcount(circuit
->ipv6_link
)
755 && iih
.tlvs
->ipv6_address
.count
);
757 if (!iih
.v4_usable
&& !iih
.v6_usable
) {
758 if (isis
->debugs
& DEBUG_ADJ_PACKETS
) {
760 "ISIS-Adj (%s): Neither IPv4 nor IPv6 considered usable. Ignoring IIH",
761 circuit
->area
->area_tag
);
764 isis_notif_reject_adjacency(
765 circuit
, "Neither IPv4 not IPv6 considered usable",
767 #endif /* ifndef FABRICD */
771 retval
= p2p_hello
? process_p2p_hello(&iih
) : process_lan_hello(&iih
);
773 isis_free_tlvs(iih
.tlvs
);
778 static void lsp_flood_or_update(struct isis_lsp
*lsp
,
779 struct isis_circuit
*circuit
,
783 lsp_flood(lsp
, circuit
);
785 fabricd_update_lsp_no_flood(lsp
, circuit
);
789 * Process Level 1/2 Link State
791 * Section 7.3.15.1 - Action on receipt of a link state PDU
793 static int process_lsp(uint8_t pdu_type
, struct isis_circuit
*circuit
,
794 const uint8_t *ssnpa
, uint8_t max_area_addrs
)
798 size_t pdu_start
= stream_get_getp(circuit
->rcv_stream
);
799 size_t pdu_end
= stream_get_endp(circuit
->rcv_stream
);
800 char raw_pdu
[pdu_end
- pdu_start
];
802 stream_get_from(raw_pdu
, circuit
->rcv_stream
, pdu_start
,
803 pdu_end
- pdu_start
);
805 if (pdu_type
== FS_LINK_STATE
) {
808 if (max_area_addrs
!= L2_CIRCUIT_FLOODING_SCOPE
)
811 circuit_scoped
= true;
813 /* The stream is used verbatim for sending out new LSPDUs.
814 * So make sure we store it as an L2 LSPDU internally.
815 * (compare for the reverse in `send_lsp`) */
816 stream_putc_at(circuit
->rcv_stream
, 4, L2_LINK_STATE
);
817 stream_putc_at(circuit
->rcv_stream
, 7, 0);
819 if (pdu_type
== L1_LINK_STATE
)
823 circuit_scoped
= false;
826 if (isis
->debugs
& DEBUG_UPDATE_PACKETS
) {
828 "ISIS-Upd (%s): Rcvd %sL%d LSP on %s, cirType %s, cirID %u",
829 circuit
->area
->area_tag
,
830 circuit_scoped
? "Circuit scoped " : "", level
,
831 circuit
->interface
->name
,
832 circuit_t2string(circuit
->is_type
),
833 circuit
->circuit_id
);
834 if (isis
->debugs
& DEBUG_PACKET_DUMP
)
835 zlog_dump_data(STREAM_DATA(circuit
->rcv_stream
),
836 stream_get_endp(circuit
->rcv_stream
));
839 struct isis_lsp_hdr hdr
= {};
841 hdr
.pdu_len
= stream_getw(circuit
->rcv_stream
);
842 hdr
.rem_lifetime
= stream_getw(circuit
->rcv_stream
);
843 stream_get(hdr
.lsp_id
, circuit
->rcv_stream
, sizeof(hdr
.lsp_id
));
844 hdr
.seqno
= stream_getl(circuit
->rcv_stream
);
845 hdr
.checksum
= stream_getw(circuit
->rcv_stream
);
846 hdr
.lsp_bits
= stream_getc(circuit
->rcv_stream
);
849 /* send northbound notification */
850 isis_notif_lsp_received(circuit
, rawlspid_print(hdr
.lsp_id
), hdr
.seqno
,
851 time(NULL
), sysid_print(hdr
.lsp_id
));
852 #endif /* ifndef FABRICD */
854 if (pdu_len_validate(hdr
.pdu_len
, circuit
)) {
855 zlog_debug("ISIS-Upd (%s): LSP %s invalid LSP length %" PRIu16
,
856 circuit
->area
->area_tag
, rawlspid_print(hdr
.lsp_id
),
861 if (isis
->debugs
& DEBUG_UPDATE_PACKETS
) {
862 zlog_debug("ISIS-Upd (%s): Rcvd L%d LSP %s, seq 0x%08" PRIx32
863 ", cksum 0x%04" PRIx16
", lifetime %" PRIu16
864 "s, len %" PRIu16
", on %s",
865 circuit
->area
->area_tag
, level
,
866 rawlspid_print(hdr
.lsp_id
), hdr
.seqno
, hdr
.checksum
,
867 hdr
.rem_lifetime
, hdr
.pdu_len
,
868 circuit
->interface
->name
);
871 /* lsp is_type check */
872 if ((hdr
.lsp_bits
& IS_LEVEL_1
) != IS_LEVEL_1
) {
874 "ISIS-Upd (%s): LSP %s invalid LSP is type 0x%" PRIx8
,
875 circuit
->area
->area_tag
, rawlspid_print(hdr
.lsp_id
),
876 hdr
.lsp_bits
& IS_LEVEL_1_AND_2
);
877 /* continue as per RFC1122 Be liberal in what you accept, and
878 * conservative in what you send */
881 /* Checksum sanity check - FIXME: move to correct place */
882 /* 12 = sysid+pdu+remtime */
883 if (iso_csum_verify(STREAM_DATA(circuit
->rcv_stream
) + 12,
884 hdr
.pdu_len
- 12, hdr
.checksum
, 12)) {
886 "ISIS-Upd (%s): LSP %s invalid LSP checksum 0x%04" PRIx16
,
887 circuit
->area
->area_tag
, rawlspid_print(hdr
.lsp_id
),
892 /* 7.3.15.1 a) 1 - external domain circuit will discard lsps */
893 if (circuit
->ext_domain
) {
895 "ISIS-Upd (%s): LSP %s received at level %d over circuit with "
896 "externalDomain = true",
897 circuit
->area
->area_tag
, rawlspid_print(hdr
.lsp_id
),
902 /* 7.3.15.1 a) 2,3 - manualL2OnlyMode not implemented */
903 if (!(circuit
->is_type
& level
)) {
905 "ISIS-Upd (%s): LSP %s received at level %d over circuit of"
907 circuit
->area
->area_tag
, rawlspid_print(hdr
.lsp_id
),
908 level
, circuit_t2string(circuit
->is_type
));
912 struct isis_tlvs
*tlvs
= NULL
;
913 int retval
= ISIS_WARNING
;
914 const char *error_log
;
916 if (isis_unpack_tlvs(STREAM_READABLE(circuit
->rcv_stream
),
917 circuit
->rcv_stream
, &tlvs
, &error_log
)) {
918 zlog_warn("Something went wrong unpacking the LSP: %s",
921 /* send northbound notification. Note that the tlv-type and
922 * offset cannot correctly be set here as they are not returned
923 * by isis_unpack_tlvs, but in there I cannot fire a
924 * notification because I have no circuit information. So until
925 * we change the code above to return those extra fields, we
926 * will send dummy values which are ignored in the callback
928 isis_notif_lsp_error(circuit
, rawlspid_print(hdr
.lsp_id
),
930 #endif /* ifndef FABRICD */
934 /* 7.3.15.1 a) 4 - need to make sure IDLength matches */
936 /* 7.3.15.1 a) 5 - maximum area match, can be ommited since we only use
939 /* 7.3.15.1 a) 7 - password check */
940 struct isis_passwd
*passwd
= (level
== ISIS_LEVEL1
)
941 ? &circuit
->area
->area_passwd
942 : &circuit
->area
->domain_passwd
;
943 int auth_code
= isis_tlvs_auth_is_valid(tlvs
, passwd
,
944 circuit
->rcv_stream
, true);
945 if (auth_code
!= ISIS_AUTH_OK
) {
946 isis_event_auth_failure(circuit
->area
->area_tag
,
947 "LSP authentication failure",
950 /* send northbound notification */
951 if (auth_code
== ISIS_AUTH_FAILURE
)
952 isis_notif_authentication_failure(circuit
, raw_pdu
);
953 else /* AUTH_TYPE_FAILURE or NO_VALIDATOR */
954 isis_notif_authentication_type_failure(circuit
,
956 #endif /* ifndef FABRICD */
960 /* Find the LSP in our database and compare it to this Link State header
962 struct isis_lsp
*lsp
=
963 lsp_search(hdr
.lsp_id
, circuit
->area
->lspdb
[level
- 1]);
966 comp
= lsp_compare(circuit
->area
->area_tag
, lsp
, hdr
.seqno
,
967 hdr
.checksum
, hdr
.rem_lifetime
);
968 if (lsp
&& (lsp
->own_lsp
))
971 /* 7.3.15.1 a) 6 - Must check that we have an adjacency of the same
973 /* for broadcast circuits, snpa should be compared */
975 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
) {
976 if (!isis_adj_lookup_snpa(ssnpa
,
977 circuit
->u
.bc
.adjdb
[level
- 1])) {
978 zlog_debug("(%s): DS ======= LSP %s, seq 0x%08" PRIx32
979 ", cksum 0x%04" PRIx16
", lifetime %" PRIu16
981 circuit
->area
->area_tag
,
982 rawlspid_print(hdr
.lsp_id
), hdr
.seqno
,
983 hdr
.checksum
, hdr
.rem_lifetime
,
984 circuit
->interface
->name
);
985 goto out
; /* Silently discard */
988 /* for non broadcast, we just need to find same level adj */
990 /* If no adj, or no sharing of level */
991 if (!circuit
->u
.p2p
.neighbor
) {
995 if (((level
== IS_LEVEL_1
)
996 && (circuit
->u
.p2p
.neighbor
->adj_usage
998 || ((level
== IS_LEVEL_2
)
999 && (circuit
->u
.p2p
.neighbor
->adj_usage
1000 == ISIS_ADJ_LEVEL1
)))
1008 /* 7.3.15.1 a) 7 - Passwords for level 1 - not implemented */
1010 /* 7.3.15.1 a) 8 - Passwords for level 2 - not implemented */
1012 /* 7.3.15.1 a) 9 - OriginatingLSPBufferSize - not implemented FIXME: do
1015 /* 7.3.16.2 - If this is an LSP from another IS with identical seq_num
1017 * wrong checksum, initiate a purge. */
1018 if (lsp
&& (lsp
->hdr
.seqno
== hdr
.seqno
)
1019 && (lsp
->hdr
.checksum
!= hdr
.checksum
)
1020 && hdr
.rem_lifetime
) {
1021 zlog_warn("ISIS-Upd (%s): LSP %s seq 0x%08" PRIx32
1022 " with confused checksum received.",
1023 circuit
->area
->area_tag
, rawlspid_print(hdr
.lsp_id
),
1025 hdr
.rem_lifetime
= 0;
1026 lsp_confusion
= true;
1028 lsp_confusion
= false;
1030 /* 7.3.15.1 b) - If the remaining life time is 0, we perform 7.3.16.4 */
1031 if (hdr
.rem_lifetime
== 0) {
1033 /* 7.3.16.4 a) 1) No LSP in db -> send an ack, but don't
1035 /* only needed on explicit update, eg - p2p */
1036 if (circuit
->circ_type
== CIRCUIT_T_P2P
)
1037 ack_lsp(&hdr
, circuit
, level
);
1038 goto out
; /* FIXME: do we need a purge? */
1040 if (memcmp(hdr
.lsp_id
, isis
->sysid
, ISIS_SYS_ID_LEN
)) {
1041 /* LSP by some other system -> do 7.3.16.4 b) */
1042 /* 7.3.16.4 b) 1) */
1043 if (comp
== LSP_NEWER
) {
1044 lsp_update(lsp
, &hdr
, tlvs
,
1045 circuit
->rcv_stream
,
1046 circuit
->area
, level
,
1050 lsp_flood_or_update(lsp
, NULL
,
1053 ISIS_FLAGS_CLEAR_ALL(
1054 lsp
->SSNflags
); /* FIXME:
1059 /* For the case of lsp confusion, flood
1060 * the purge back to its
1061 * originator so that it can react.
1062 * Otherwise, don't reflood
1063 * through incoming circuit as usual */
1064 if (!lsp_confusion
) {
1070 if (circuit
->circ_type
1071 != CIRCUIT_T_BROADCAST
)
1076 } /* 7.3.16.4 b) 2) */
1077 else if (comp
== LSP_EQUAL
) {
1079 isis_tx_queue_del(circuit
->tx_queue
,
1082 if (circuit
->circ_type
1083 != CIRCUIT_T_BROADCAST
)
1084 ISIS_SET_FLAG(lsp
->SSNflags
,
1086 } /* 7.3.16.4 b) 3) */
1088 isis_tx_queue_add(circuit
->tx_queue
,
1089 lsp
, TX_LSP_NORMAL
);
1090 ISIS_CLEAR_FLAG(lsp
->SSNflags
, circuit
);
1092 } else if (lsp
->hdr
.rem_lifetime
!= 0) {
1093 /* our own LSP -> 7.3.16.4 c) */
1094 if (comp
== LSP_NEWER
) {
1096 if (lsp
->hdr
.seqno
< hdr
.seqno
) {
1099 isis_notif_seqno_skipped(
1104 #endif /* ifndef FABRICD */
1105 lsp_inc_seqno(lsp
, hdr
.seqno
);
1106 lsp_flood_or_update(lsp
, NULL
,
1109 isis_tx_queue_add(circuit
->tx_queue
,
1110 lsp
, TX_LSP_NORMAL
);
1111 ISIS_CLEAR_FLAG(lsp
->SSNflags
, circuit
);
1113 if (isis
->debugs
& DEBUG_UPDATE_PACKETS
)
1115 "ISIS-Upd (%s): (1) "
1116 "re-originating LSP %s new seq "
1118 circuit
->area
->area_tag
,
1119 rawlspid_print(hdr
.lsp_id
),
1122 /* our own LSP with 0 remaining life time */
1124 /* send northbound notification */
1125 isis_notif_own_lsp_purge(
1126 circuit
, rawlspid_print(hdr
.lsp_id
));
1127 #endif /* ifndef FABRICD */
1132 /* 7.3.15.1 c) - If this is our own lsp and we don't have it initiate a
1134 if (memcmp(hdr
.lsp_id
, isis
->sysid
, ISIS_SYS_ID_LEN
) == 0) {
1136 /* 7.3.16.4: initiate a purge */
1137 lsp_purge_non_exist(level
, &hdr
, circuit
->area
);
1141 /* 7.3.15.1 d) - If this is our own lsp and we have it */
1143 /* In 7.3.16.1, If an Intermediate system R somewhere in the
1145 * has information that the current sequence number for source S
1147 * "greater" than that held by S, ... */
1149 if (comp
== LSP_NEWER
) {
1151 lsp_inc_seqno(lsp
, hdr
.seqno
);
1153 /* send northbound notification */
1154 isis_notif_seqno_skipped(circuit
,
1155 rawlspid_print(hdr
.lsp_id
));
1156 #endif /* ifndef FABRICD */
1157 if (isis
->debugs
& DEBUG_UPDATE_PACKETS
) {
1159 "ISIS-Upd (%s): (2) re-originating LSP %s new seq 0x%08" PRIx32
,
1160 circuit
->area
->area_tag
,
1161 rawlspid_print(hdr
.lsp_id
),
1164 lsp_flood(lsp
, NULL
);
1165 } else if (comp
== LSP_EQUAL
) {
1166 isis_tx_queue_del(circuit
->tx_queue
, lsp
);
1167 if (circuit
->circ_type
!= CIRCUIT_T_BROADCAST
)
1168 ISIS_SET_FLAG(lsp
->SSNflags
, circuit
);
1170 isis_tx_queue_add(circuit
->tx_queue
, lsp
,
1172 ISIS_CLEAR_FLAG(lsp
->SSNflags
, circuit
);
1175 /* 7.3.15.1 e) - This lsp originated on another system */
1177 /* 7.3.15.1 e) 1) LSP newer than the one in db or no LSP in db
1179 if ((!lsp
|| comp
== LSP_NEWER
)) {
1181 * If this lsp is a frag, need to see if we have zero
1184 struct isis_lsp
*lsp0
= NULL
;
1185 if (LSP_FRAGMENT(hdr
.lsp_id
) != 0) {
1186 uint8_t lspid
[ISIS_SYS_ID_LEN
+ 2];
1187 memcpy(lspid
, hdr
.lsp_id
, ISIS_SYS_ID_LEN
+ 1);
1188 LSP_FRAGMENT(lspid
) = 0;
1190 lspid
, circuit
->area
->lspdb
[level
- 1]);
1193 "Got lsp frag, while zero lsp not in database");
1199 lsp
= lsp_new_from_recv(
1200 &hdr
, tlvs
, circuit
->rcv_stream
, lsp0
,
1201 circuit
->area
, level
);
1204 circuit
->area
->lspdb
[level
- 1]);
1205 } else /* exists, so we overwrite */
1207 lsp_update(lsp
, &hdr
, tlvs
, circuit
->rcv_stream
,
1208 circuit
->area
, level
, false);
1211 lsp_flood_or_update(lsp
, circuit
, circuit_scoped
);
1214 if (circuit
->circ_type
!= CIRCUIT_T_BROADCAST
)
1215 ISIS_SET_FLAG(lsp
->SSNflags
, circuit
);
1218 /* 7.3.15.1 e) 2) LSP equal to the one in db */
1219 else if (comp
== LSP_EQUAL
) {
1220 isis_tx_queue_del(circuit
->tx_queue
, lsp
);
1221 lsp_update(lsp
, &hdr
, tlvs
, circuit
->rcv_stream
,
1222 circuit
->area
, level
, false);
1224 if (circuit
->circ_type
!= CIRCUIT_T_BROADCAST
)
1225 ISIS_SET_FLAG(lsp
->SSNflags
, circuit
);
1227 /* 7.3.15.1 e) 3) LSP older than the one in db */
1229 isis_tx_queue_add(circuit
->tx_queue
, lsp
,
1231 ISIS_CLEAR_FLAG(lsp
->SSNflags
, circuit
);
1238 fabricd_trigger_csnp(circuit
->area
, circuit_scoped
);
1240 isis_free_tlvs(tlvs
);
1245 * Process Sequence Numbers
1247 * Section 7.3.15.2 - Action on receipt of a sequence numbers PDU
1250 static int process_snp(uint8_t pdu_type
, struct isis_circuit
*circuit
,
1251 const uint8_t *ssnpa
)
1254 size_t pdu_start
= stream_get_getp(circuit
->rcv_stream
);
1255 size_t pdu_end
= stream_get_endp(circuit
->rcv_stream
);
1256 char raw_pdu
[pdu_end
- pdu_start
];
1257 #endif /* ifndef FABRICD */
1259 bool is_csnp
= (pdu_type
== L1_COMPLETE_SEQ_NUM
1260 || pdu_type
== L2_COMPLETE_SEQ_NUM
);
1261 char typechar
= is_csnp
? 'C' : 'P';
1262 int level
= (pdu_type
== L1_COMPLETE_SEQ_NUM
1263 || pdu_type
== L1_PARTIAL_SEQ_NUM
)
1267 uint16_t pdu_len
= stream_getw(circuit
->rcv_stream
);
1268 uint8_t rem_sys_id
[ISIS_SYS_ID_LEN
];
1270 stream_get(rem_sys_id
, circuit
->rcv_stream
, ISIS_SYS_ID_LEN
);
1271 stream_forward_getp(circuit
->rcv_stream
, 1); /* Circuit ID - unused */
1273 uint8_t start_lsp_id
[ISIS_SYS_ID_LEN
+ 2] = {};
1274 uint8_t stop_lsp_id
[ISIS_SYS_ID_LEN
+ 2] = {};
1277 stream_get(start_lsp_id
, circuit
->rcv_stream
,
1278 ISIS_SYS_ID_LEN
+ 2);
1279 stream_get(stop_lsp_id
, circuit
->rcv_stream
,
1280 ISIS_SYS_ID_LEN
+ 2);
1283 if (pdu_len_validate(pdu_len
, circuit
)) {
1284 zlog_warn("Received a CSNP with bogus length %d", pdu_len
);
1285 return ISIS_WARNING
;
1288 if (isis
->debugs
& DEBUG_SNP_PACKETS
) {
1290 "ISIS-Snp (%s): Rcvd L%d %cSNP on %s, cirType %s, cirID %u",
1291 circuit
->area
->area_tag
, level
, typechar
,
1292 circuit
->interface
->name
,
1293 circuit_t2string(circuit
->is_type
),
1294 circuit
->circuit_id
);
1295 if (isis
->debugs
& DEBUG_PACKET_DUMP
)
1296 zlog_dump_data(STREAM_DATA(circuit
->rcv_stream
),
1297 stream_get_endp(circuit
->rcv_stream
));
1300 /* 7.3.15.2 a) 1 - external domain circuit will discard snp pdu */
1301 if (circuit
->ext_domain
) {
1304 "ISIS-Snp (%s): Rcvd L%d %cSNP on %s, "
1305 "skipping: circuit externalDomain = true",
1306 circuit
->area
->area_tag
, level
, typechar
,
1307 circuit
->interface
->name
);
1312 /* 7.3.15.2 a) 2,3 - manualL2OnlyMode not implemented */
1313 if (!(circuit
->is_type
& level
)) {
1315 "ISIS-Snp (%s): Rcvd L%d %cSNP on %s, "
1316 "skipping: circuit type %s does not match level %d",
1317 circuit
->area
->area_tag
, level
, typechar
,
1318 circuit
->interface
->name
,
1319 circuit_t2string(circuit
->is_type
), level
);
1324 /* 7.3.15.2 a) 4 - not applicable for CSNP only PSNPs on broadcast */
1325 if (!is_csnp
&& (circuit
->circ_type
== CIRCUIT_T_BROADCAST
)
1326 && !circuit
->u
.bc
.is_dr
[level
- 1]) {
1328 "ISIS-Snp (%s): Rcvd L%d %cSNP from %s on %s, "
1329 "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 isis_notif_authentication_failure(circuit
,
1387 else /* AUTH_TYPE_FAILURE or NO_VALIDATOR */
1388 isis_notif_authentication_type_failure(circuit
,
1390 #endif /* ifndef FABRICD */
1395 struct isis_lsp_entry
*entry_head
=
1396 (struct isis_lsp_entry
*)tlvs
->lsp_entries
.head
;
1398 /* debug isis snp-packets */
1399 if (isis
->debugs
& DEBUG_SNP_PACKETS
) {
1400 zlog_debug("ISIS-Snp (%s): Rcvd L%d %cSNP from %s on %s",
1401 circuit
->area
->area_tag
, level
, typechar
,
1402 snpa_print(ssnpa
), circuit
->interface
->name
);
1403 for (struct isis_lsp_entry
*entry
= entry_head
; entry
;
1404 entry
= entry
->next
) {
1406 "ISIS-Snp (%s): %cSNP entry %s, seq 0x%08" PRIx32
1407 ", cksum 0x%04" PRIx16
", lifetime %" PRIu16
"s",
1408 circuit
->area
->area_tag
, typechar
,
1409 rawlspid_print(entry
->id
), entry
->seqno
,
1410 entry
->checksum
, entry
->rem_lifetime
);
1414 bool resync_needed
= false;
1416 /* 7.3.15.2 b) Actions on LSP_ENTRIES reported */
1417 for (struct isis_lsp_entry
*entry
= entry_head
; entry
;
1418 entry
= entry
->next
) {
1419 struct isis_lsp
*lsp
=
1420 lsp_search(entry
->id
, circuit
->area
->lspdb
[level
- 1]);
1421 bool own_lsp
= !memcmp(entry
->id
, isis
->sysid
, ISIS_SYS_ID_LEN
);
1423 /* 7.3.15.2 b) 1) is this LSP newer */
1424 int cmp
= lsp_compare(circuit
->area
->area_tag
, lsp
,
1425 entry
->seqno
, entry
->checksum
,
1426 entry
->rem_lifetime
);
1427 /* 7.3.15.2 b) 2) if it equals, clear SRM on p2p */
1428 if (cmp
== LSP_EQUAL
) {
1429 /* if (circuit->circ_type !=
1430 * CIRCUIT_T_BROADCAST) */
1431 isis_tx_queue_del(circuit
->tx_queue
, lsp
);
1433 /* 7.3.15.2 b) 3) if it is older, clear SSN and set SRM
1435 else if (cmp
== LSP_OLDER
) {
1436 ISIS_CLEAR_FLAG(lsp
->SSNflags
, circuit
);
1437 isis_tx_queue_add(circuit
->tx_queue
, lsp
,
1440 /* 7.3.15.2 b) 4) if it is newer, set SSN and clear SRM
1444 lsp_inc_seqno(lsp
, entry
->seqno
);
1445 isis_tx_queue_add(circuit
->tx_queue
, lsp
,
1448 ISIS_SET_FLAG(lsp
->SSNflags
, circuit
);
1449 /* if (circuit->circ_type !=
1450 * CIRCUIT_T_BROADCAST) */
1451 isis_tx_queue_del(circuit
->tx_queue
, lsp
);
1452 resync_needed
= true;
1456 /* 7.3.15.2 b) 5) if it was not found, and all of those
1458 * insert it and set SSN on it */
1459 if (entry
->rem_lifetime
&& entry
->checksum
1460 && entry
->seqno
&& memcmp(entry
->id
, isis
->sysid
,
1462 struct isis_lsp
*lsp0
= NULL
;
1464 if (LSP_FRAGMENT(entry
->id
)) {
1465 uint8_t lspid
[ISIS_SYS_ID_LEN
+ 2];
1467 memcpy(lspid
, entry
->id
,
1468 ISIS_SYS_ID_LEN
+ 1);
1469 LSP_FRAGMENT(lspid
) = 0;
1472 circuit
->area
->lspdb
[level
- 1]);
1474 zlog_debug("Got lsp frag in snp, while zero not in database");
1478 lsp
= lsp_new(circuit
->area
, entry
->id
,
1479 entry
->rem_lifetime
, 0, 0,
1480 entry
->checksum
, lsp0
, level
);
1482 circuit
->area
->lspdb
[level
- 1]);
1484 lsp_set_all_srmflags(lsp
, false);
1485 ISIS_SET_FLAG(lsp
->SSNflags
, circuit
);
1486 resync_needed
= true;
1491 /* 7.3.15.2 c) on CSNP set SRM for all in range which were not reported
1495 * Build a list from our own LSP db bounded with
1496 * start_lsp_id and stop_lsp_id
1498 struct list
*lsp_list
= list_new();
1499 lsp_build_list_nonzero_ht(start_lsp_id
, stop_lsp_id
, lsp_list
,
1500 circuit
->area
->lspdb
[level
- 1]);
1502 /* Fixme: Find a better solution */
1503 struct listnode
*node
, *nnode
;
1504 struct isis_lsp
*lsp
;
1505 for (struct isis_lsp_entry
*entry
= entry_head
; entry
;
1506 entry
= entry
->next
) {
1507 for (ALL_LIST_ELEMENTS(lsp_list
, node
, nnode
, lsp
)) {
1508 if (lsp_id_cmp(lsp
->hdr
.lsp_id
, entry
->id
)
1510 list_delete_node(lsp_list
, node
);
1516 /* on remaining LSPs we set SRM (neighbor knew not of) */
1517 for (ALL_LIST_ELEMENTS_RO(lsp_list
, node
, lsp
)) {
1518 isis_tx_queue_add(circuit
->tx_queue
, lsp
, TX_LSP_NORMAL
);
1519 resync_needed
= true;
1523 list_delete(&lsp_list
);
1526 if (fabricd_initial_sync_is_complete(circuit
->area
) && resync_needed
)
1527 zlog_warn("OpenFabric: Needed to resync LSPDB using CSNP!");
1531 isis_free_tlvs(tlvs
);
1535 static int pdu_size(uint8_t pdu_type
, uint8_t *size
)
1540 *size
= ISIS_LANHELLO_HDRLEN
;
1543 *size
= ISIS_P2PHELLO_HDRLEN
;
1548 *size
= ISIS_LSP_HDR_LEN
;
1550 case L1_COMPLETE_SEQ_NUM
:
1551 case L2_COMPLETE_SEQ_NUM
:
1552 *size
= ISIS_CSNP_HDRLEN
;
1554 case L1_PARTIAL_SEQ_NUM
:
1555 case L2_PARTIAL_SEQ_NUM
:
1556 *size
= ISIS_PSNP_HDRLEN
;
1561 *size
+= ISIS_FIXED_HDR_LEN
;
1569 int isis_handle_pdu(struct isis_circuit
*circuit
, uint8_t *ssnpa
)
1571 int retval
= ISIS_OK
;
1572 size_t pdu_start
= stream_get_getp(circuit
->rcv_stream
);
1573 size_t pdu_end
= stream_get_endp(circuit
->rcv_stream
);
1574 char raw_pdu
[pdu_end
- pdu_start
];
1576 stream_get_from(raw_pdu
, circuit
->rcv_stream
, pdu_start
,
1577 pdu_end
- pdu_start
);
1579 /* Verify that at least the 8 bytes fixed header have been received */
1580 if (stream_get_endp(circuit
->rcv_stream
) < ISIS_FIXED_HDR_LEN
) {
1581 flog_err(EC_ISIS_PACKET
, "PDU is too short to be IS-IS.");
1585 uint8_t idrp
= stream_getc(circuit
->rcv_stream
);
1586 uint8_t length
= stream_getc(circuit
->rcv_stream
);
1587 uint8_t version1
= stream_getc(circuit
->rcv_stream
);
1588 uint8_t id_len
= stream_getc(circuit
->rcv_stream
);
1589 uint8_t pdu_type
= stream_getc(circuit
->rcv_stream
)
1590 & 0x1f; /* bits 6-8 are reserved */
1591 uint8_t version2
= stream_getc(circuit
->rcv_stream
);
1593 stream_forward_getp(circuit
->rcv_stream
, 1); /* reserved */
1594 uint8_t max_area_addrs
= stream_getc(circuit
->rcv_stream
);
1596 pdu_counter_count(circuit
->area
->pdu_rx_counters
, pdu_type
);
1598 if (idrp
== ISO9542_ESIS
) {
1599 flog_err(EC_LIB_DEVELOPMENT
,
1600 "No support for ES-IS packet IDRP=%" PRIx8
, idrp
);
1604 if (idrp
!= ISO10589_ISIS
) {
1605 flog_err(EC_ISIS_PACKET
, "Not an IS-IS packet IDRP=%" PRIx8
,
1610 if (version1
!= 1) {
1611 zlog_warn("Unsupported ISIS version %" PRIu8
, version1
);
1613 /* send northbound notification */
1614 isis_notif_version_skew(circuit
, version1
, raw_pdu
);
1615 #endif /* ifndef FABRICD */
1616 return ISIS_WARNING
;
1619 if (id_len
!= 0 && id_len
!= ISIS_SYS_ID_LEN
) {
1622 "IDFieldLengthMismatch: ID Length field in a received PDU %" PRIu8
1623 ", while the parameter for this IS is %u",
1624 id_len
, ISIS_SYS_ID_LEN
);
1626 /* send northbound notification */
1627 isis_notif_id_len_mismatch(circuit
, id_len
, raw_pdu
);
1628 #endif /* ifndef FABRICD */
1632 uint8_t expected_length
;
1633 if (pdu_size(pdu_type
, &expected_length
)) {
1634 zlog_warn("Unsupported ISIS PDU %" PRIu8
, pdu_type
);
1635 return ISIS_WARNING
;
1638 if (length
!= expected_length
) {
1639 flog_err(EC_ISIS_PACKET
,
1640 "Exepected fixed header length = %" PRIu8
1642 expected_length
, length
);
1646 if (stream_get_endp(circuit
->rcv_stream
) < length
) {
1649 "PDU is too short to contain fixed header of given PDU type.");
1653 if (version2
!= 1) {
1654 zlog_warn("Unsupported ISIS PDU version %" PRIu8
, version2
);
1656 /* send northbound notification */
1657 isis_notif_version_skew(circuit
, version2
, raw_pdu
);
1658 #endif /* ifndef FABRICD */
1659 return ISIS_WARNING
;
1662 if (circuit
->is_passive
) {
1663 zlog_warn("Received ISIS PDU on passive circuit %s",
1664 circuit
->interface
->name
);
1665 return ISIS_WARNING
;
1669 if (pdu_type
!= FS_LINK_STATE
/* FS PDU doesn't contain max area addr field */
1670 && max_area_addrs
!= 0
1671 && max_area_addrs
!= isis
->max_area_addrs
) {
1674 "maximumAreaAddressesMismatch: maximumAreaAdresses in a received PDU %" PRIu8
1675 " while the parameter for this IS is %u",
1676 max_area_addrs
, isis
->max_area_addrs
);
1678 /* send northbound notification */
1679 isis_notif_max_area_addr_mismatch(circuit
, max_area_addrs
,
1681 #endif /* ifndef FABRICD */
1689 if (fabricd
&& pdu_type
!= P2P_HELLO
)
1691 retval
= process_hello(pdu_type
, circuit
, ssnpa
);
1697 && pdu_type
!= L2_LINK_STATE
1698 && pdu_type
!= FS_LINK_STATE
)
1700 retval
= process_lsp(pdu_type
, circuit
, ssnpa
, max_area_addrs
);
1702 case L1_COMPLETE_SEQ_NUM
:
1703 case L2_COMPLETE_SEQ_NUM
:
1704 case L1_PARTIAL_SEQ_NUM
:
1705 case L2_PARTIAL_SEQ_NUM
:
1706 retval
= process_snp(pdu_type
, circuit
, ssnpa
);
1715 int isis_receive(struct thread
*thread
)
1717 struct isis_circuit
*circuit
;
1718 uint8_t ssnpa
[ETH_ALEN
];
1724 circuit
= THREAD_ARG(thread
);
1727 circuit
->t_read
= NULL
;
1729 isis_circuit_stream(circuit
, &circuit
->rcv_stream
);
1731 retval
= circuit
->rx(circuit
, ssnpa
);
1733 #if ISIS_METHOD != ISIS_METHOD_BPF
1734 if (retval
== ISIS_OK
)
1735 retval
= isis_handle_pdu(circuit
, ssnpa
);
1736 #endif //ISIS_METHOD != ISIS_METHOD_BPF
1739 * prepare for next packet.
1741 if (!circuit
->is_passive
)
1742 isis_circuit_prepare(circuit
);
1750 void fill_fixed_hdr(uint8_t pdu_type
, struct stream
*stream
)
1754 if (pdu_size(pdu_type
, &length
))
1755 assert(!"Unknown PDU Type");
1757 stream_putc(stream
, ISO10589_ISIS
); /* IDRP */
1758 stream_putc(stream
, length
); /* Length of fixed header */
1759 stream_putc(stream
, 1); /* Version/Protocol ID Extension 1 */
1760 stream_putc(stream
, 0); /* ID Length, 0 => 6 */
1761 stream_putc(stream
, pdu_type
);
1762 stream_putc(stream
, 1); /* Subversion */
1763 stream_putc(stream
, 0); /* Reserved */
1764 stream_putc(stream
, 0); /* Max Area Addresses 0 => 3 */
1767 static uint8_t hello_pdu_type(struct isis_circuit
*circuit
, int level
)
1769 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
)
1770 return (level
== IS_LEVEL_1
) ? L1_LAN_HELLO
: L2_LAN_HELLO
;
1775 static void put_hello_hdr(struct isis_circuit
*circuit
, int level
,
1776 size_t *len_pointer
)
1778 uint8_t pdu_type
= hello_pdu_type(circuit
, level
);
1780 isis_circuit_stream(circuit
, &circuit
->snd_stream
);
1781 fill_fixed_hdr(pdu_type
, circuit
->snd_stream
);
1783 stream_putc(circuit
->snd_stream
, circuit
->is_type
);
1784 stream_put(circuit
->snd_stream
, circuit
->area
->isis
->sysid
,
1787 uint32_t holdtime
= circuit
->hello_multiplier
[level
- 1]
1788 * circuit
->hello_interval
[level
- 1];
1790 if (holdtime
> 0xffff)
1793 stream_putw(circuit
->snd_stream
, holdtime
);
1794 *len_pointer
= stream_get_endp(circuit
->snd_stream
);
1795 stream_putw(circuit
->snd_stream
, 0); /* length is filled in later */
1797 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
) {
1798 uint8_t *desig_is
= (level
== IS_LEVEL_1
)
1799 ? circuit
->u
.bc
.l1_desig_is
1800 : circuit
->u
.bc
.l2_desig_is
;
1801 stream_putc(circuit
->snd_stream
, circuit
->priority
[level
- 1]);
1802 stream_put(circuit
->snd_stream
, desig_is
, ISIS_SYS_ID_LEN
+ 1);
1804 stream_putc(circuit
->snd_stream
, circuit
->circuit_id
);
1808 int send_hello(struct isis_circuit
*circuit
, int level
)
1813 if (circuit
->is_passive
)
1816 if (circuit
->interface
->mtu
== 0) {
1817 zlog_warn("circuit has zero MTU");
1818 return ISIS_WARNING
;
1821 put_hello_hdr(circuit
, level
, &len_pointer
);
1823 struct isis_tlvs
*tlvs
= isis_alloc_tlvs();
1825 isis_tlvs_add_auth(tlvs
, &circuit
->passwd
);
1827 if (!listcount(circuit
->area
->area_addrs
)) {
1828 isis_free_tlvs(tlvs
);
1829 return ISIS_WARNING
;
1832 isis_tlvs_add_area_addresses(tlvs
, circuit
->area
->area_addrs
);
1834 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
) {
1835 isis_tlvs_add_lan_neighbors(
1836 tlvs
, circuit
->u
.bc
.lan_neighs
[level
- 1]);
1837 } else if (circuit
->circ_type
== CIRCUIT_T_P2P
1838 && !circuit
->disable_threeway_adj
) {
1839 uint32_t ext_circuit_id
= circuit
->idx
;
1840 if (circuit
->u
.p2p
.neighbor
) {
1841 uint8_t threeway_state
;
1843 if (fabricd_initial_sync_is_in_progress(circuit
->area
)
1844 && fabricd_initial_sync_circuit(circuit
->area
) != circuit
)
1845 threeway_state
= ISIS_THREEWAY_DOWN
;
1847 threeway_state
= circuit
->u
.p2p
.neighbor
->threeway_state
;
1848 isis_tlvs_add_threeway_adj(tlvs
,
1851 circuit
->u
.p2p
.neighbor
->sysid
,
1852 circuit
->u
.p2p
.neighbor
->ext_circuit_id
);
1854 isis_tlvs_add_threeway_adj(tlvs
,
1861 isis_tlvs_set_protocols_supported(tlvs
, &circuit
->nlpids
);
1866 * TLV gets included if no topology is enabled on the interface,
1867 * if one topology other than #0 is enabled, or if multiple topologies
1870 struct isis_circuit_mt_setting
**mt_settings
;
1871 unsigned int mt_count
;
1873 mt_settings
= circuit_mt_settings(circuit
, &mt_count
);
1874 if (mt_count
== 0 && area_is_mt(circuit
->area
)) {
1875 tlvs
->mt_router_info_empty
= true;
1876 } else if ((mt_count
== 1
1877 && mt_settings
[0]->mtid
!= ISIS_MT_IPV4_UNICAST
)
1878 || (mt_count
> 1)) {
1879 for (unsigned int i
= 0; i
< mt_count
; i
++)
1880 isis_tlvs_add_mt_router_info(tlvs
, mt_settings
[i
]->mtid
,
1884 if (circuit
->ip_router
) {
1885 struct list
*circuit_ip_addrs
= fabricd_ip_addrs(circuit
);
1887 if (circuit_ip_addrs
)
1888 isis_tlvs_add_ipv4_addresses(tlvs
, circuit_ip_addrs
);
1891 if (circuit
->ipv6_router
&& circuit
->ipv6_link
)
1892 isis_tlvs_add_ipv6_addresses(tlvs
, circuit
->ipv6_link
);
1894 if (isis_pack_tlvs(tlvs
, circuit
->snd_stream
, len_pointer
,
1895 circuit
->pad_hellos
, false)) {
1896 isis_free_tlvs(tlvs
);
1897 return ISIS_WARNING
; /* XXX: Maybe Log TLV structure? */
1900 if (isis
->debugs
& DEBUG_ADJ_PACKETS
) {
1901 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
) {
1903 "ISIS-Adj (%s): Sending L%d LAN IIH on %s, length %zd",
1904 circuit
->area
->area_tag
, level
,
1905 circuit
->interface
->name
,
1906 stream_get_endp(circuit
->snd_stream
));
1909 "ISIS-Adj (%s): Sending P2P IIH on %s, length %zd",
1910 circuit
->area
->area_tag
,
1911 circuit
->interface
->name
,
1912 stream_get_endp(circuit
->snd_stream
));
1914 if (isis
->debugs
& DEBUG_PACKET_DUMP
)
1915 zlog_dump_data(STREAM_DATA(circuit
->snd_stream
),
1916 stream_get_endp(circuit
->snd_stream
));
1919 isis_free_tlvs(tlvs
);
1921 pdu_counter_count(circuit
->area
->pdu_tx_counters
,
1922 hello_pdu_type(circuit
, level
));
1923 retval
= circuit
->tx(circuit
, level
);
1924 if (retval
!= ISIS_OK
)
1925 flog_err(EC_ISIS_PACKET
,
1926 "ISIS-Adj (%s): Send L%d IIH on %s failed",
1927 circuit
->area
->area_tag
, level
,
1928 circuit
->interface
->name
);
1933 static int send_hello_cb(struct thread
*thread
)
1935 struct isis_circuit_arg
*arg
= THREAD_ARG(thread
);
1938 struct isis_circuit
*circuit
= arg
->circuit
;
1939 int level
= arg
->level
;
1943 if (circuit
->circ_type
== CIRCUIT_T_P2P
) {
1944 circuit
->u
.p2p
.t_send_p2p_hello
= NULL
;
1945 send_hello(circuit
, 1);
1946 send_hello_sched(circuit
, ISIS_LEVEL1
,
1947 1000 * circuit
->hello_interval
[1]);
1951 if (circuit
->circ_type
!= CIRCUIT_T_BROADCAST
) {
1952 zlog_warn("ISIS-Hello (%s): Trying to send hello on unknown circuit type %d",
1953 circuit
->area
->area_tag
, circuit
->circ_type
);
1954 return ISIS_WARNING
;
1957 circuit
->u
.bc
.t_send_lan_hello
[level
- 1] = NULL
;
1958 if (!(circuit
->is_type
& level
)) {
1959 zlog_warn("ISIS-Hello (%s): Trying to send L%d IIH in L%d-only circuit",
1960 circuit
->area
->area_tag
, level
, 3 - level
);
1961 return ISIS_WARNING
;
1964 if (circuit
->u
.bc
.run_dr_elect
[level
- 1])
1965 isis_dr_elect(circuit
, level
);
1967 int rv
= send_hello(circuit
, level
);
1969 /* set next timer thread */
1970 send_hello_sched(circuit
, level
, 1000 * circuit
->hello_interval
[level
- 1]);
1974 static void _send_hello_sched(struct isis_circuit
*circuit
,
1975 struct thread
**threadp
,
1976 int level
, long delay
)
1979 if (thread_timer_remain_msec(*threadp
) < (unsigned long)delay
)
1982 thread_cancel(*threadp
);
1985 thread_add_timer_msec(master
, send_hello_cb
,
1986 &circuit
->level_arg
[level
- 1],
1987 isis_jitter(delay
, IIH_JITTER
),
1991 void send_hello_sched(struct isis_circuit
*circuit
, int level
, long delay
)
1993 if (circuit
->circ_type
== CIRCUIT_T_P2P
) {
1994 _send_hello_sched(circuit
, &circuit
->u
.p2p
.t_send_p2p_hello
,
1995 ISIS_LEVEL1
, delay
);
1999 if (circuit
->circ_type
!= CIRCUIT_T_BROADCAST
) {
2000 zlog_warn("%s: encountered unknown circuit type %d on %s",
2001 __func__
, circuit
->circ_type
,
2002 circuit
->interface
->name
);
2006 for (int loop_level
= ISIS_LEVEL1
; loop_level
<= ISIS_LEVEL2
; loop_level
++) {
2007 if (!(loop_level
& level
))
2012 &circuit
->u
.bc
.t_send_lan_hello
[loop_level
- 1],
2021 * Count the maximum number of lsps that can be accomodated by a given size.
2023 #define LSP_ENTRIES_LEN (10 + ISIS_SYS_ID_LEN)
2024 static uint16_t get_max_lsp_count(uint16_t size
)
2028 uint16_t remaining_size
;
2030 /* First count the full size TLVs */
2031 tlv_count
= size
/ MAX_LSP_ENTRIES_TLV_SIZE
;
2032 lsp_count
= tlv_count
* (MAX_LSP_ENTRIES_TLV_SIZE
/ LSP_ENTRIES_LEN
);
2034 /* The last TLV, if any */
2035 remaining_size
= size
% MAX_LSP_ENTRIES_TLV_SIZE
;
2036 if (remaining_size
- 2 >= LSP_ENTRIES_LEN
)
2037 lsp_count
+= (remaining_size
- 2) / LSP_ENTRIES_LEN
;
2042 int send_csnp(struct isis_circuit
*circuit
, int level
)
2044 if (circuit
->area
->lspdb
[level
- 1] == NULL
2045 || dict_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 (isis
->debugs
& 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 (isis
->debugs
& 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 (circuit
->area
->lspdb
[level
- 1] == NULL
2220 || dict_count(circuit
->area
->lspdb
[level
- 1]) == 0)
2223 if (!circuit
->snd_stream
)
2226 uint8_t pdu_type
= (level
== ISIS_LEVEL1
) ? L1_PARTIAL_SEQ_NUM
2227 : L2_PARTIAL_SEQ_NUM
;
2229 isis_circuit_stream(circuit
, &circuit
->snd_stream
);
2230 fill_fixed_hdr(pdu_type
, circuit
->snd_stream
);
2232 size_t len_pointer
= stream_get_endp(circuit
->snd_stream
);
2233 stream_putw(circuit
->snd_stream
, 0); /* length is filled in later */
2234 stream_put(circuit
->snd_stream
, isis
->sysid
, ISIS_SYS_ID_LEN
);
2235 stream_putc(circuit
->snd_stream
, circuit
->idx
);
2237 struct isis_passwd
*passwd
= (level
== ISIS_LEVEL1
)
2238 ? &circuit
->area
->area_passwd
2239 : &circuit
->area
->domain_passwd
;
2241 struct isis_tlvs
*tlvs
= isis_alloc_tlvs();
2243 if (CHECK_FLAG(passwd
->snp_auth
, SNP_AUTH_SEND
))
2244 isis_tlvs_add_auth(tlvs
, passwd
);
2246 size_t tlv_start
= stream_get_endp(circuit
->snd_stream
);
2247 if (isis_pack_tlvs(tlvs
, circuit
->snd_stream
, len_pointer
, false,
2249 isis_free_tlvs(tlvs
);
2250 return ISIS_WARNING
;
2252 isis_free_tlvs(tlvs
);
2255 get_max_lsp_count(STREAM_WRITEABLE(circuit
->snd_stream
));
2258 tlvs
= isis_alloc_tlvs();
2259 if (CHECK_FLAG(passwd
->snp_auth
, SNP_AUTH_SEND
))
2260 isis_tlvs_add_auth(tlvs
, passwd
);
2262 for (dnode_t
*dnode
=
2263 dict_first(circuit
->area
->lspdb
[level
- 1]);
2264 dnode
; dnode
= dict_next(circuit
->area
->lspdb
[level
- 1],
2266 struct isis_lsp
*lsp
= dnode_get(dnode
);
2268 if (ISIS_CHECK_FLAG(lsp
->SSNflags
, circuit
))
2269 isis_tlvs_add_lsp_entry(tlvs
, lsp
);
2271 if (tlvs
->lsp_entries
.count
== num_lsps
)
2275 if (!tlvs
->lsp_entries
.count
) {
2276 isis_free_tlvs(tlvs
);
2280 stream_set_endp(circuit
->snd_stream
, tlv_start
);
2281 if (isis_pack_tlvs(tlvs
, circuit
->snd_stream
, len_pointer
,
2283 isis_free_tlvs(tlvs
);
2284 return ISIS_WARNING
;
2287 if (isis
->debugs
& DEBUG_SNP_PACKETS
) {
2289 "ISIS-Snp (%s): Sending L%d PSNP on %s, length %zd",
2290 circuit
->area
->area_tag
, level
,
2291 circuit
->interface
->name
,
2292 stream_get_endp(circuit
->snd_stream
));
2293 log_multiline(LOG_DEBUG
, " ", "%s",
2294 isis_format_tlvs(tlvs
));
2295 if (isis
->debugs
& DEBUG_PACKET_DUMP
)
2297 STREAM_DATA(circuit
->snd_stream
),
2298 stream_get_endp(circuit
->snd_stream
));
2301 pdu_counter_count(circuit
->area
->pdu_tx_counters
, pdu_type
);
2302 int retval
= circuit
->tx(circuit
, level
);
2303 if (retval
!= ISIS_OK
) {
2304 flog_err(EC_ISIS_PACKET
,
2305 "ISIS-Snp (%s): Send L%d PSNP on %s failed",
2306 circuit
->area
->area_tag
, level
,
2307 circuit
->interface
->name
);
2308 isis_free_tlvs(tlvs
);
2313 * sending succeeded, we can clear SSN flags of this circuit
2314 * for the LSPs in list
2316 struct isis_lsp_entry
*entry_head
;
2317 entry_head
= (struct isis_lsp_entry
*)tlvs
->lsp_entries
.head
;
2318 for (struct isis_lsp_entry
*entry
= entry_head
; entry
;
2319 entry
= entry
->next
)
2320 ISIS_CLEAR_FLAG(entry
->lsp
->SSNflags
, circuit
);
2321 isis_free_tlvs(tlvs
);
2327 int send_l1_psnp(struct thread
*thread
)
2330 struct isis_circuit
*circuit
;
2332 circuit
= THREAD_ARG(thread
);
2335 circuit
->t_send_psnp
[0] = NULL
;
2337 send_psnp(1, circuit
);
2338 /* set next timer thread */
2339 thread_add_timer(master
, send_l1_psnp
, circuit
,
2340 isis_jitter(circuit
->psnp_interval
[0], PSNP_JITTER
),
2341 &circuit
->t_send_psnp
[0]);
2347 * 7.3.15.4 action on expiration of partial SNP interval
2350 int send_l2_psnp(struct thread
*thread
)
2352 struct isis_circuit
*circuit
;
2354 circuit
= THREAD_ARG(thread
);
2357 circuit
->t_send_psnp
[1] = NULL
;
2359 send_psnp(2, circuit
);
2361 /* set next timer thread */
2362 thread_add_timer(master
, send_l2_psnp
, circuit
,
2363 isis_jitter(circuit
->psnp_interval
[1], PSNP_JITTER
),
2364 &circuit
->t_send_psnp
[1]);
2370 * ISO 10589 - 7.3.14.3
2372 void send_lsp(struct isis_circuit
*circuit
, struct isis_lsp
*lsp
,
2373 enum isis_tx_type tx_type
)
2376 int retval
= ISIS_OK
;
2378 if (circuit
->state
!= C_STATE_UP
|| circuit
->is_passive
== 1)
2382 * Do not send if levels do not match
2384 if (!(lsp
->level
& circuit
->is_type
))
2388 * Do not send if we do not have adjacencies in state up on the circuit
2390 if (circuit
->upadjcount
[lsp
->level
- 1] == 0)
2393 /* stream_copy will assert and stop program execution if LSP is larger
2395 * the circuit's MTU. So handle and log this case here. */
2396 if (stream_get_endp(lsp
->pdu
) > stream_get_size(circuit
->snd_stream
)) {
2399 "ISIS-Upd (%s): Can't send L%d LSP %s, seq 0x%08" PRIx32
2400 ", cksum 0x%04" PRIx16
", lifetime %" PRIu16
2401 "s on %s. LSP Size is %zu while interface stream size is %zu.",
2402 circuit
->area
->area_tag
, lsp
->level
,
2403 rawlspid_print(lsp
->hdr
.lsp_id
), lsp
->hdr
.seqno
,
2404 lsp
->hdr
.checksum
, lsp
->hdr
.rem_lifetime
,
2405 circuit
->interface
->name
, stream_get_endp(lsp
->pdu
),
2406 stream_get_size(circuit
->snd_stream
));
2408 /* send a northbound notification */
2409 isis_notif_lsp_too_large(circuit
, stream_get_endp(lsp
->pdu
),
2410 rawlspid_print(lsp
->hdr
.lsp_id
));
2411 #endif /* ifndef FABRICD */
2412 if (isis
->debugs
& DEBUG_PACKET_DUMP
)
2413 zlog_dump_data(STREAM_DATA(lsp
->pdu
),
2414 stream_get_endp(lsp
->pdu
));
2415 retval
= ISIS_ERROR
;
2419 /* copy our lsp to the send buffer */
2420 stream_copy(circuit
->snd_stream
, lsp
->pdu
);
2422 if (tx_type
== TX_LSP_CIRCUIT_SCOPED
) {
2423 stream_putc_at(circuit
->snd_stream
, 4, FS_LINK_STATE
);
2424 stream_putc_at(circuit
->snd_stream
, 7,
2425 L2_CIRCUIT_FLOODING_SCOPE
);
2428 if (isis
->debugs
& DEBUG_UPDATE_PACKETS
) {
2429 zlog_debug("ISIS-Upd (%s): Sending %sL%d LSP %s, seq 0x%08" PRIx32
2430 ", cksum 0x%04" PRIx16
", lifetime %" PRIu16
2432 circuit
->area
->area_tag
,
2433 (tx_type
== TX_LSP_CIRCUIT_SCOPED
)
2434 ? "Circuit scoped " : "",
2436 rawlspid_print(lsp
->hdr
.lsp_id
), lsp
->hdr
.seqno
,
2437 lsp
->hdr
.checksum
, lsp
->hdr
.rem_lifetime
,
2438 circuit
->interface
->name
);
2439 if (isis
->debugs
& DEBUG_PACKET_DUMP
)
2440 zlog_dump_data(STREAM_DATA(circuit
->snd_stream
),
2441 stream_get_endp(circuit
->snd_stream
));
2444 uint8_t pdu_type
= (tx_type
== TX_LSP_CIRCUIT_SCOPED
) ? FS_LINK_STATE
2445 : (lsp
->level
== ISIS_LEVEL1
) ? L1_LINK_STATE
2449 pdu_counter_count(circuit
->area
->pdu_tx_counters
, pdu_type
);
2450 retval
= circuit
->tx(circuit
, lsp
->level
);
2451 if (retval
!= ISIS_OK
) {
2452 flog_err(EC_ISIS_PACKET
,
2453 "ISIS-Upd (%s): Send L%d LSP on %s failed %s",
2454 circuit
->area
->area_tag
, lsp
->level
,
2455 circuit
->interface
->name
,
2456 (retval
== ISIS_WARNING
) ? "temporarily"
2462 || (retval
== ISIS_OK
&& circuit
->circ_type
== CIRCUIT_T_BROADCAST
)
2463 || (retval
!= ISIS_OK
&& retval
!= ISIS_WARNING
)) {
2464 /* SRM flag will trigger retransmission. We will not retransmit
2466 * encountered a fatal error.
2467 * On success, they should only be cleared if it's a broadcast
2469 * On a P2P circuit, we will wait for the ack from the neighbor
2473 isis_tx_queue_del(circuit
->tx_queue
, lsp
);