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\n",
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.\n",
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(isisMplsTE
) && iih
->circuit
->mtc
205 && IS_CIRCUIT_TE(iih
->circuit
->mtc
) && adj
->ipv4_address_count
)
206 set_circuitparams_rmt_ipaddr(iih
->circuit
->mtc
,
207 adj
->ipv4_addresses
[0]);
209 /* lets take care of the expiry */
210 THREAD_TIMER_OFF(adj
->t_expire
);
211 thread_add_timer(master
, isis_adj_expire
, adj
, (long)adj
->hold_time
,
214 /* While fabricds initial sync is in progress, ignore hellos from other
215 * interfaces than the one we are performing the initial sync on. */
216 if (fabricd_initial_sync_is_in_progress(iih
->circuit
->area
)
217 && fabricd_initial_sync_circuit(iih
->circuit
->area
) != iih
->circuit
)
220 /* 8.2.5.2 a) a match was detected */
221 if (isis_tlvs_area_addresses_match(iih
->tlvs
,
222 iih
->circuit
->area
->area_addrs
)) {
223 /* 8.2.5.2 a) 2) If the system is L1 - table 5 */
224 if (iih
->circuit
->area
->is_type
== IS_LEVEL_1
) {
225 switch (iih
->circ_type
) {
227 case IS_LEVEL_1_AND_2
:
228 if (adj
->adj_state
!= ISIS_ADJ_UP
229 || adj
->adj_usage
== ISIS_ADJ_LEVEL1
) {
230 isis_adj_process_threeway(adj
, tw_adj
,
235 if (adj
->adj_state
!= ISIS_ADJ_UP
) {
236 /* (7) reject - wrong system type event
238 zlog_warn("wrongSystemType");
240 } else if (adj
->adj_usage
== ISIS_ADJ_LEVEL1
) {
241 /* (6) down - wrong system */
242 isis_adj_state_change(adj
,
250 /* 8.2.5.2 a) 3) If the system is L1L2 - table 6 */
251 if (iih
->circuit
->area
->is_type
== IS_LEVEL_1_AND_2
) {
252 switch (iih
->circ_type
) {
254 if (adj
->adj_state
!= ISIS_ADJ_UP
255 || adj
->adj_usage
== ISIS_ADJ_LEVEL1
) {
256 isis_adj_process_threeway(adj
, tw_adj
,
258 } else if ((adj
->adj_usage
259 == ISIS_ADJ_LEVEL1AND2
)
261 == ISIS_ADJ_LEVEL2
)) {
262 /* (8) down - wrong system */
263 isis_adj_state_change(adj
,
269 if (adj
->adj_state
!= ISIS_ADJ_UP
270 || adj
->adj_usage
== ISIS_ADJ_LEVEL2
) {
271 isis_adj_process_threeway(adj
, tw_adj
,
273 } else if ((adj
->adj_usage
== ISIS_ADJ_LEVEL1
)
275 == ISIS_ADJ_LEVEL1AND2
)) {
276 /* (8) down - wrong system */
277 isis_adj_state_change(adj
,
282 case IS_LEVEL_1_AND_2
:
283 if (adj
->adj_state
!= ISIS_ADJ_UP
284 || adj
->adj_usage
== ISIS_ADJ_LEVEL1AND2
) {
285 isis_adj_process_threeway(adj
, tw_adj
,
286 ISIS_ADJ_LEVEL1AND2
);
287 } else if ((adj
->adj_usage
== ISIS_ADJ_LEVEL1
)
289 == ISIS_ADJ_LEVEL2
)) {
290 /* (8) down - wrong system */
291 isis_adj_state_change(adj
,
299 /* 8.2.5.2 a) 4) If the system is L2 - table 7 */
300 if (iih
->circuit
->area
->is_type
== IS_LEVEL_2
) {
301 switch (iih
->circ_type
) {
303 if (adj
->adj_state
!= ISIS_ADJ_UP
) {
304 /* (5) reject - wrong system type event
306 zlog_warn("wrongSystemType");
308 } else if ((adj
->adj_usage
309 == ISIS_ADJ_LEVEL1AND2
)
311 == ISIS_ADJ_LEVEL2
)) {
312 /* (6) down - wrong system */
313 isis_adj_state_change(adj
,
318 case IS_LEVEL_1_AND_2
:
320 if (adj
->adj_state
!= ISIS_ADJ_UP
321 || adj
->adj_usage
== ISIS_ADJ_LEVEL2
) {
322 isis_adj_process_threeway(adj
, tw_adj
,
324 } else if (adj
->adj_usage
325 == ISIS_ADJ_LEVEL1AND2
) {
326 /* (6) down - wrong system */
327 isis_adj_state_change(adj
,
335 /* 8.2.5.2 b) if no match was detected */
336 else if (listcount(iih
->circuit
->area
->area_addrs
) > 0) {
337 if (iih
->circuit
->area
->is_type
== IS_LEVEL_1
) {
338 /* 8.2.5.2 b) 1) is_type L1 and adj is not up */
339 if (adj
->adj_state
!= ISIS_ADJ_UP
) {
340 isis_adj_state_change(adj
, ISIS_ADJ_DOWN
,
342 /* 8.2.5.2 b) 2)is_type L1 and adj is up */
344 isis_adj_state_change(adj
, ISIS_ADJ_DOWN
,
345 "Down - Area Mismatch");
348 /* 8.2.5.2 b 3 If the system is L2 or L1L2 - table 8 */
350 switch (iih
->circ_type
) {
352 if (adj
->adj_state
!= ISIS_ADJ_UP
) {
353 /* (6) reject - Area Mismatch event */
354 zlog_warn("AreaMismatch");
356 } else if (adj
->adj_usage
== ISIS_ADJ_LEVEL1
) {
357 /* (7) down - area mismatch */
358 isis_adj_state_change(adj
,
362 } else if ((adj
->adj_usage
363 == ISIS_ADJ_LEVEL1AND2
)
365 == ISIS_ADJ_LEVEL2
)) {
366 /* (7) down - wrong system */
367 isis_adj_state_change(adj
,
372 case IS_LEVEL_1_AND_2
:
374 if (adj
->adj_state
!= ISIS_ADJ_UP
375 || adj
->adj_usage
== ISIS_ADJ_LEVEL2
) {
376 isis_adj_process_threeway(adj
, tw_adj
,
378 } else if (adj
->adj_usage
== ISIS_ADJ_LEVEL1
) {
379 /* (7) down - wrong system */
380 isis_adj_state_change(adj
,
383 } else if (adj
->adj_usage
384 == ISIS_ADJ_LEVEL1AND2
) {
385 if (iih
->circ_type
== IS_LEVEL_2
) {
386 /* (7) down - wrong system */
387 isis_adj_state_change(
391 /* (7) down - area mismatch */
392 isis_adj_state_change(
401 /* down - area mismatch */
402 isis_adj_state_change(adj
, ISIS_ADJ_DOWN
, "Area Mismatch");
405 if (adj
->adj_state
== ISIS_ADJ_UP
&& changed
) {
406 lsp_regenerate_schedule(adj
->circuit
->area
,
407 isis_adj_usage2levels(adj
->adj_usage
),
411 /* 8.2.5.2 c) if the action was up - comparing circuit IDs */
412 /* FIXME - Missing parts */
414 /* some of my own understanding of the ISO, why the heck does
415 * it not say what should I change the system_type to...
417 switch (adj
->adj_usage
) {
418 case ISIS_ADJ_LEVEL1
:
419 adj
->sys_type
= ISIS_SYSTYPE_L1_IS
;
421 case ISIS_ADJ_LEVEL2
:
422 adj
->sys_type
= ISIS_SYSTYPE_L2_IS
;
424 case ISIS_ADJ_LEVEL1AND2
:
425 adj
->sys_type
= ISIS_SYSTYPE_L2_IS
;
428 adj
->sys_type
= ISIS_SYSTYPE_UNKNOWN
;
432 if (isis
->debugs
& DEBUG_ADJ_PACKETS
) {
434 "ISIS-Adj (%s): Rcvd P2P IIH from (%s), cir type %s,"
435 " cir id %hhu, length %" PRIu16
,
436 iih
->circuit
->area
->area_tag
,
437 iih
->circuit
->interface
->name
,
438 circuit_t2string(iih
->circuit
->is_type
),
439 iih
->circuit
->circuit_id
, iih
->pdu_len
);
445 static int process_lan_hello(struct iih_info
*iih
)
447 struct isis_adjacency
*adj
;
448 adj
= isis_adj_lookup(iih
->sys_id
,
449 iih
->circuit
->u
.bc
.adjdb
[iih
->level
- 1]);
450 if ((adj
== NULL
) || (memcmp(adj
->snpa
, iih
->ssnpa
, ETH_ALEN
))
451 || (adj
->level
!= iih
->level
)) {
453 /* Do as in 8.4.2.5 */
454 adj
= isis_new_adj(iih
->sys_id
, iih
->ssnpa
, iih
->level
,
458 memcpy(adj
->snpa
, iih
->ssnpa
, 6);
460 memset(adj
->snpa
, ' ', 6);
462 adj
->level
= iih
->level
;
464 isis_adj_state_change(adj
, ISIS_ADJ_INITIALIZING
, NULL
);
466 if (iih
->level
== IS_LEVEL_1
)
467 adj
->sys_type
= ISIS_SYSTYPE_L1_IS
;
469 adj
->sys_type
= ISIS_SYSTYPE_L2_IS
;
470 list_delete_all_node(
471 iih
->circuit
->u
.bc
.lan_neighs
[iih
->level
- 1]);
472 isis_adj_build_neigh_list(
473 iih
->circuit
->u
.bc
.adjdb
[iih
->level
- 1],
474 iih
->circuit
->u
.bc
.lan_neighs
[iih
->level
- 1]);
477 if (adj
->dis_record
[iih
->level
- 1].dis
== ISIS_IS_DIS
) {
478 uint8_t *dis
= (iih
->level
== 1)
479 ? iih
->circuit
->u
.bc
.l1_desig_is
480 : iih
->circuit
->u
.bc
.l2_desig_is
;
482 if (memcmp(dis
, iih
->dis
, ISIS_SYS_ID_LEN
+ 1)) {
483 thread_add_event(master
, isis_event_dis_status_change
,
484 iih
->circuit
, 0, NULL
);
485 memcpy(dis
, iih
->dis
, ISIS_SYS_ID_LEN
+ 1);
489 adj
->circuit_t
= iih
->circ_type
;
490 adj
->hold_time
= iih
->holdtime
;
491 adj
->last_upd
= time(NULL
);
492 adj
->prio
[iih
->level
- 1] = iih
->priority
;
493 memcpy(adj
->lanid
, iih
->dis
, ISIS_SYS_ID_LEN
+ 1);
496 isis_tlvs_to_adj(iih
->tlvs
, adj
, &changed
);
497 changed
|= tlvs_to_adj_mt_set(iih
->tlvs
, iih
->v4_usable
, iih
->v6_usable
,
500 /* lets take care of the expiry */
501 THREAD_TIMER_OFF(adj
->t_expire
);
502 thread_add_timer(master
, isis_adj_expire
, adj
, (long)adj
->hold_time
,
506 * If the snpa for this circuit is found from LAN Neighbours TLV
507 * we have two-way communication -> adjacency can be put to state "up"
509 bool own_snpa_found
=
510 isis_tlvs_own_snpa_found(iih
->tlvs
, iih
->circuit
->u
.bc
.snpa
);
512 if (adj
->adj_state
!= ISIS_ADJ_UP
) {
513 if (own_snpa_found
) {
514 isis_adj_state_change(
516 "own SNPA found in LAN Neighbours TLV");
519 if (!own_snpa_found
) {
520 isis_adj_state_change(
521 adj
, ISIS_ADJ_INITIALIZING
,
522 "own SNPA not found in LAN Neighbours TLV");
526 if (adj
->adj_state
== ISIS_ADJ_UP
&& changed
)
527 lsp_regenerate_schedule(adj
->circuit
->area
, iih
->level
, 0);
529 if (isis
->debugs
& DEBUG_ADJ_PACKETS
) {
531 "ISIS-Adj (%s): Rcvd L%d LAN IIH from %s on %s, cirType %s, cirID %u, length %zd",
532 iih
->circuit
->area
->area_tag
, iih
->level
,
533 snpa_print(iih
->ssnpa
), iih
->circuit
->interface
->name
,
534 circuit_t2string(iih
->circuit
->is_type
),
535 iih
->circuit
->circuit_id
,
536 stream_get_endp(iih
->circuit
->rcv_stream
));
541 static int pdu_len_validate(uint16_t pdu_len
, struct isis_circuit
*circuit
)
543 if (pdu_len
< stream_get_getp(circuit
->rcv_stream
)
544 || pdu_len
> ISO_MTU(circuit
)
545 || pdu_len
> stream_get_endp(circuit
->rcv_stream
))
548 if (pdu_len
< stream_get_endp(circuit
->rcv_stream
))
549 stream_set_endp(circuit
->rcv_stream
, pdu_len
);
553 static int process_hello(uint8_t pdu_type
, struct isis_circuit
*circuit
,
556 bool p2p_hello
= (pdu_type
== P2P_HELLO
);
557 int level
= p2p_hello
? 0
558 : (pdu_type
== L1_LAN_HELLO
) ? ISIS_LEVEL1
560 const char *pdu_name
=
563 : (level
== ISIS_LEVEL1
) ? "L1 LAN IIH" : "L2 LAN IIH";
565 if (isis
->debugs
& DEBUG_ADJ_PACKETS
) {
566 zlog_debug("ISIS-Adj (%s): Rcvd %s on %s, cirType %s, cirID %u",
567 circuit
->area
->area_tag
, pdu_name
,
568 circuit
->interface
->name
,
569 circuit_t2string(circuit
->is_type
),
570 circuit
->circuit_id
);
571 if (isis
->debugs
& DEBUG_PACKET_DUMP
)
572 zlog_dump_data(STREAM_DATA(circuit
->rcv_stream
),
573 stream_get_endp(circuit
->rcv_stream
));
577 if (circuit
->circ_type
!= CIRCUIT_T_P2P
) {
578 zlog_warn("p2p hello on non p2p circuit");
582 if (circuit
->circ_type
!= CIRCUIT_T_BROADCAST
) {
583 zlog_warn("lan hello on non broadcast circuit");
587 if (circuit
->ext_domain
) {
589 "level %d LAN Hello received over circuit with externalDomain = true",
594 if (!(circuit
->is_type
& level
)) {
595 if (isis
->debugs
& DEBUG_ADJ_PACKETS
) {
597 "ISIS-Adj (%s): Interface level mismatch, %s",
598 circuit
->area
->area_tag
,
599 circuit
->interface
->name
);
605 struct iih_info iih
= {
606 .circuit
= circuit
, .ssnpa
= ssnpa
, .level
= level
};
608 /* Generic IIH Header */
609 iih
.circ_type
= stream_getc(circuit
->rcv_stream
) & 0x03;
610 stream_get(iih
.sys_id
, circuit
->rcv_stream
, ISIS_SYS_ID_LEN
);
611 iih
.holdtime
= stream_getw(circuit
->rcv_stream
);
612 iih
.pdu_len
= stream_getw(circuit
->rcv_stream
);
615 iih
.circuit_id
= stream_getc(circuit
->rcv_stream
);
617 iih
.priority
= stream_getc(circuit
->rcv_stream
);
618 stream_get(iih
.dis
, circuit
->rcv_stream
, ISIS_SYS_ID_LEN
+ 1);
621 if (pdu_len_validate(iih
.pdu_len
, circuit
)) {
623 "ISIS-Adj (%s): Rcvd %s from (%s) with invalid pdu length %" PRIu16
,
624 circuit
->area
->area_tag
, pdu_name
,
625 circuit
->interface
->name
, iih
.pdu_len
);
629 if (!p2p_hello
&& !(level
& iih
.circ_type
)) {
630 flog_err(EC_ISIS_PACKET
,
631 "Level %d LAN Hello with Circuit Type %d", level
,
636 const char *error_log
;
637 int retval
= ISIS_WARNING
;
639 if (isis_unpack_tlvs(STREAM_READABLE(circuit
->rcv_stream
),
640 circuit
->rcv_stream
, &iih
.tlvs
, &error_log
)) {
641 zlog_warn("isis_unpack_tlvs() failed: %s", error_log
);
645 if (!iih
.tlvs
->area_addresses
.count
) {
646 zlog_warn("No Area addresses TLV in %s", pdu_name
);
650 if (!iih
.tlvs
->protocols_supported
.count
) {
651 zlog_warn("No supported protocols TLV in %s", pdu_name
);
655 if (!isis_tlvs_auth_is_valid(iih
.tlvs
, &circuit
->passwd
,
656 circuit
->rcv_stream
, false)) {
657 isis_event_auth_failure(circuit
->area
->area_tag
,
658 "IIH authentication failure",
663 if (!memcmp(iih
.sys_id
, isis
->sysid
, ISIS_SYS_ID_LEN
)) {
665 "ISIS-Adj (%s): Received IIH with own sysid - discard",
666 circuit
->area
->area_tag
);
671 && (listcount(circuit
->area
->area_addrs
) == 0
672 || (level
== ISIS_LEVEL1
673 && !isis_tlvs_area_addresses_match(
674 iih
.tlvs
, circuit
->area
->area_addrs
)))) {
675 if (isis
->debugs
& DEBUG_ADJ_PACKETS
) {
677 "ISIS-Adj (%s): Area mismatch, level %d IIH on %s",
678 circuit
->area
->area_tag
, level
,
679 circuit
->interface
->name
);
684 iih
.v4_usable
= (fabricd_ip_addrs(circuit
)
685 && iih
.tlvs
->ipv4_address
.count
);
687 iih
.v6_usable
= (circuit
->ipv6_link
&& listcount(circuit
->ipv6_link
)
688 && iih
.tlvs
->ipv6_address
.count
);
690 if (!iih
.v4_usable
&& !iih
.v6_usable
) {
691 if (isis
->debugs
& DEBUG_ADJ_PACKETS
) {
693 "ISIS-Adj (%s): Neither IPv4 nor IPv6 considered usable. Ignoring IIH",
694 circuit
->area
->area_tag
);
700 retval
= p2p_hello
? process_p2p_hello(&iih
) : process_lan_hello(&iih
);
702 isis_free_tlvs(iih
.tlvs
);
707 static void lsp_flood_or_update(struct isis_lsp
*lsp
,
708 struct isis_circuit
*circuit
,
711 if (!circuit_scoped
) {
712 lsp_flood(lsp
, circuit
);
714 fabricd_update_lsp_no_flood(lsp
, circuit
);
719 * Process Level 1/2 Link State
721 * Section 7.3.15.1 - Action on receipt of a link state PDU
723 static int process_lsp(uint8_t pdu_type
, struct isis_circuit
*circuit
,
724 const uint8_t *ssnpa
, uint8_t max_area_addrs
)
729 if (pdu_type
== FS_LINK_STATE
) {
732 if (max_area_addrs
!= L2_CIRCUIT_FLOODING_SCOPE
)
735 circuit_scoped
= true;
737 /* The stream is used verbatim for sending out new LSPDUs.
738 * So make sure we store it as an L2 LSPDU internally.
739 * (compare for the reverse in `send_lsp`) */
740 stream_putc_at(circuit
->rcv_stream
, 4, L2_LINK_STATE
);
741 stream_putc_at(circuit
->rcv_stream
, 7, 0);
743 if (pdu_type
== L1_LINK_STATE
)
747 circuit_scoped
= false;
750 if (isis
->debugs
& DEBUG_UPDATE_PACKETS
) {
752 "ISIS-Upd (%s): Rcvd %sL%d LSP on %s, cirType %s, cirID %u",
753 circuit
->area
->area_tag
,
754 circuit_scoped
? "Circuit scoped " : "", level
,
755 circuit
->interface
->name
,
756 circuit_t2string(circuit
->is_type
),
757 circuit
->circuit_id
);
758 if (isis
->debugs
& DEBUG_PACKET_DUMP
)
759 zlog_dump_data(STREAM_DATA(circuit
->rcv_stream
),
760 stream_get_endp(circuit
->rcv_stream
));
763 struct isis_lsp_hdr hdr
= {};
765 hdr
.pdu_len
= stream_getw(circuit
->rcv_stream
);
766 hdr
.rem_lifetime
= stream_getw(circuit
->rcv_stream
);
767 stream_get(hdr
.lsp_id
, circuit
->rcv_stream
, sizeof(hdr
.lsp_id
));
768 hdr
.seqno
= stream_getl(circuit
->rcv_stream
);
769 hdr
.checksum
= stream_getw(circuit
->rcv_stream
);
770 hdr
.lsp_bits
= stream_getc(circuit
->rcv_stream
);
772 if (pdu_len_validate(hdr
.pdu_len
, circuit
)) {
773 zlog_debug("ISIS-Upd (%s): LSP %s invalid LSP length %" PRIu16
,
774 circuit
->area
->area_tag
, rawlspid_print(hdr
.lsp_id
),
779 if (isis
->debugs
& DEBUG_UPDATE_PACKETS
) {
780 zlog_debug("ISIS-Upd (%s): Rcvd L%d LSP %s, seq 0x%08" PRIx32
781 ", cksum 0x%04" PRIx16
", lifetime %" PRIu16
782 "s, len %" PRIu16
", on %s",
783 circuit
->area
->area_tag
, level
,
784 rawlspid_print(hdr
.lsp_id
), hdr
.seqno
, hdr
.checksum
,
785 hdr
.rem_lifetime
, hdr
.pdu_len
,
786 circuit
->interface
->name
);
789 /* lsp is_type check */
790 if ((hdr
.lsp_bits
& IS_LEVEL_1
) != IS_LEVEL_1
) {
792 "ISIS-Upd (%s): LSP %s invalid LSP is type 0x%" PRIx8
,
793 circuit
->area
->area_tag
, rawlspid_print(hdr
.lsp_id
),
794 hdr
.lsp_bits
& IS_LEVEL_1_AND_2
);
795 /* continue as per RFC1122 Be liberal in what you accept, and
796 * conservative in what you send */
799 /* Checksum sanity check - FIXME: move to correct place */
800 /* 12 = sysid+pdu+remtime */
801 if (iso_csum_verify(STREAM_DATA(circuit
->rcv_stream
) + 12,
802 hdr
.pdu_len
- 12, hdr
.checksum
, 12)) {
804 "ISIS-Upd (%s): LSP %s invalid LSP checksum 0x%04" PRIx16
,
805 circuit
->area
->area_tag
, rawlspid_print(hdr
.lsp_id
),
810 /* 7.3.15.1 a) 1 - external domain circuit will discard lsps */
811 if (circuit
->ext_domain
) {
813 "ISIS-Upd (%s): LSP %s received at level %d over circuit with "
814 "externalDomain = true",
815 circuit
->area
->area_tag
, rawlspid_print(hdr
.lsp_id
),
820 /* 7.3.15.1 a) 2,3 - manualL2OnlyMode not implemented */
821 if (!(circuit
->is_type
& level
)) {
823 "ISIS-Upd (%s): LSP %s received at level %d over circuit of"
825 circuit
->area
->area_tag
, rawlspid_print(hdr
.lsp_id
),
826 level
, circuit_t2string(circuit
->is_type
));
830 struct isis_tlvs
*tlvs
= NULL
;
831 int retval
= ISIS_WARNING
;
832 const char *error_log
;
834 if (isis_unpack_tlvs(STREAM_READABLE(circuit
->rcv_stream
),
835 circuit
->rcv_stream
, &tlvs
, &error_log
)) {
836 zlog_warn("Something went wrong unpacking the LSP: %s",
841 /* 7.3.15.1 a) 4 - need to make sure IDLength matches */
843 /* 7.3.15.1 a) 5 - maximum area match, can be ommited since we only use
846 /* 7.3.15.1 a) 7 - password check */
847 struct isis_passwd
*passwd
= (level
== ISIS_LEVEL1
)
848 ? &circuit
->area
->area_passwd
849 : &circuit
->area
->domain_passwd
;
850 if (!isis_tlvs_auth_is_valid(tlvs
, passwd
, circuit
->rcv_stream
, true)) {
851 isis_event_auth_failure(circuit
->area
->area_tag
,
852 "LSP authentication failure",
857 /* Find the LSP in our database and compare it to this Link State header
859 struct isis_lsp
*lsp
=
860 lsp_search(hdr
.lsp_id
, circuit
->area
->lspdb
[level
- 1]);
863 comp
= lsp_compare(circuit
->area
->area_tag
, lsp
, hdr
.seqno
,
864 hdr
.checksum
, hdr
.rem_lifetime
);
865 if (lsp
&& (lsp
->own_lsp
))
868 /* 7.3.15.1 a) 6 - Must check that we have an adjacency of the same
870 /* for broadcast circuits, snpa should be compared */
872 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
) {
873 if (!isis_adj_lookup_snpa(ssnpa
,
874 circuit
->u
.bc
.adjdb
[level
- 1])) {
875 zlog_debug("(%s): DS ======= LSP %s, seq 0x%08" PRIx32
876 ", cksum 0x%04" PRIx16
", lifetime %" PRIu16
878 circuit
->area
->area_tag
,
879 rawlspid_print(hdr
.lsp_id
), hdr
.seqno
,
880 hdr
.checksum
, hdr
.rem_lifetime
,
881 circuit
->interface
->name
);
882 goto out
; /* Silently discard */
885 /* for non broadcast, we just need to find same level adj */
887 /* If no adj, or no sharing of level */
888 if (!circuit
->u
.p2p
.neighbor
) {
892 if (((level
== IS_LEVEL_1
)
893 && (circuit
->u
.p2p
.neighbor
->adj_usage
895 || ((level
== IS_LEVEL_2
)
896 && (circuit
->u
.p2p
.neighbor
->adj_usage
897 == ISIS_ADJ_LEVEL1
)))
905 /* 7.3.15.1 a) 7 - Passwords for level 1 - not implemented */
907 /* 7.3.15.1 a) 8 - Passwords for level 2 - not implemented */
909 /* 7.3.15.1 a) 9 - OriginatingLSPBufferSize - not implemented FIXME: do
912 /* 7.3.16.2 - If this is an LSP from another IS with identical seq_num
914 * wrong checksum, initiate a purge. */
915 if (lsp
&& (lsp
->hdr
.seqno
== hdr
.seqno
)
916 && (lsp
->hdr
.checksum
!= hdr
.checksum
)
917 && hdr
.rem_lifetime
) {
918 zlog_warn("ISIS-Upd (%s): LSP %s seq 0x%08" PRIx32
919 " with confused checksum received.",
920 circuit
->area
->area_tag
, rawlspid_print(hdr
.lsp_id
),
922 hdr
.rem_lifetime
= 0;
923 lsp_confusion
= true;
925 lsp_confusion
= false;
927 /* 7.3.15.1 b) - If the remaining life time is 0, we perform 7.3.16.4 */
928 if (hdr
.rem_lifetime
== 0) {
930 /* 7.3.16.4 a) 1) No LSP in db -> send an ack, but don't
932 /* only needed on explicit update, eg - p2p */
933 if (circuit
->circ_type
== CIRCUIT_T_P2P
)
934 ack_lsp(&hdr
, circuit
, level
);
935 goto out
; /* FIXME: do we need a purge? */
937 if (memcmp(hdr
.lsp_id
, isis
->sysid
, ISIS_SYS_ID_LEN
)) {
938 /* LSP by some other system -> do 7.3.16.4 b) */
940 if (comp
== LSP_NEWER
) {
941 lsp_update(lsp
, &hdr
, tlvs
,
943 circuit
->area
, level
,
947 lsp_flood_or_update(lsp
, NULL
,
950 ISIS_FLAGS_CLEAR_ALL(
951 lsp
->SSNflags
); /* FIXME:
956 /* For the case of lsp confusion, flood
957 * the purge back to its
958 * originator so that it can react.
959 * Otherwise, don't reflood
960 * through incoming circuit as usual */
961 if (!lsp_confusion
) {
967 if (circuit
->circ_type
968 != CIRCUIT_T_BROADCAST
)
973 } /* 7.3.16.4 b) 2) */
974 else if (comp
== LSP_EQUAL
) {
976 isis_tx_queue_del(circuit
->tx_queue
,
979 if (circuit
->circ_type
980 != CIRCUIT_T_BROADCAST
)
981 ISIS_SET_FLAG(lsp
->SSNflags
,
983 } /* 7.3.16.4 b) 3) */
985 isis_tx_queue_add(circuit
->tx_queue
,
987 ISIS_CLEAR_FLAG(lsp
->SSNflags
, circuit
);
989 } else if (lsp
->hdr
.rem_lifetime
!= 0) {
990 /* our own LSP -> 7.3.16.4 c) */
991 if (comp
== LSP_NEWER
) {
992 lsp_inc_seqno(lsp
, hdr
.seqno
);
993 lsp_flood_or_update(lsp
, NULL
, circuit_scoped
);
995 isis_tx_queue_add(circuit
->tx_queue
,
997 ISIS_CLEAR_FLAG(lsp
->SSNflags
, circuit
);
999 if (isis
->debugs
& DEBUG_UPDATE_PACKETS
)
1001 "ISIS-Upd (%s): (1) re-originating LSP %s new seq 0x%08" PRIx32
,
1002 circuit
->area
->area_tag
,
1003 rawlspid_print(hdr
.lsp_id
),
1009 /* 7.3.15.1 c) - If this is our own lsp and we don't have it initiate a
1011 if (memcmp(hdr
.lsp_id
, isis
->sysid
, ISIS_SYS_ID_LEN
) == 0) {
1013 /* 7.3.16.4: initiate a purge */
1014 lsp_purge_non_exist(level
, &hdr
, circuit
->area
);
1018 /* 7.3.15.1 d) - If this is our own lsp and we have it */
1020 /* In 7.3.16.1, If an Intermediate system R somewhere in the
1022 * has information that the current sequence number for source S
1024 * "greater" than that held by S, ... */
1026 if (comp
== LSP_NEWER
) {
1028 lsp_inc_seqno(lsp
, hdr
.seqno
);
1029 if (isis
->debugs
& DEBUG_UPDATE_PACKETS
) {
1031 "ISIS-Upd (%s): (2) re-originating LSP %s new seq 0x%08" PRIx32
,
1032 circuit
->area
->area_tag
,
1033 rawlspid_print(hdr
.lsp_id
),
1036 lsp_flood(lsp
, NULL
);
1037 } else if (comp
== LSP_EQUAL
) {
1038 isis_tx_queue_del(circuit
->tx_queue
, lsp
);
1039 if (circuit
->circ_type
!= CIRCUIT_T_BROADCAST
)
1040 ISIS_SET_FLAG(lsp
->SSNflags
, circuit
);
1042 isis_tx_queue_add(circuit
->tx_queue
, lsp
,
1044 ISIS_CLEAR_FLAG(lsp
->SSNflags
, circuit
);
1047 /* 7.3.15.1 e) - This lsp originated on another system */
1049 /* 7.3.15.1 e) 1) LSP newer than the one in db or no LSP in db
1051 if ((!lsp
|| comp
== LSP_NEWER
)) {
1053 * If this lsp is a frag, need to see if we have zero
1056 struct isis_lsp
*lsp0
= NULL
;
1057 if (LSP_FRAGMENT(hdr
.lsp_id
) != 0) {
1058 uint8_t lspid
[ISIS_SYS_ID_LEN
+ 2];
1059 memcpy(lspid
, hdr
.lsp_id
, ISIS_SYS_ID_LEN
+ 1);
1060 LSP_FRAGMENT(lspid
) = 0;
1062 lspid
, circuit
->area
->lspdb
[level
- 1]);
1065 "Got lsp frag, while zero lsp not in database");
1071 lsp
= lsp_new_from_recv(
1072 &hdr
, tlvs
, circuit
->rcv_stream
, lsp0
,
1073 circuit
->area
, level
);
1076 circuit
->area
->lspdb
[level
- 1]);
1077 } else /* exists, so we overwrite */
1079 lsp_update(lsp
, &hdr
, tlvs
, circuit
->rcv_stream
,
1080 circuit
->area
, level
, false);
1083 lsp_flood_or_update(lsp
, circuit
, circuit_scoped
);
1086 if (circuit
->circ_type
!= CIRCUIT_T_BROADCAST
)
1087 ISIS_SET_FLAG(lsp
->SSNflags
, circuit
);
1090 /* 7.3.15.1 e) 2) LSP equal to the one in db */
1091 else if (comp
== LSP_EQUAL
) {
1092 isis_tx_queue_del(circuit
->tx_queue
, lsp
);
1093 lsp_update(lsp
, &hdr
, tlvs
, circuit
->rcv_stream
,
1094 circuit
->area
, level
, false);
1096 if (circuit
->circ_type
!= CIRCUIT_T_BROADCAST
)
1097 ISIS_SET_FLAG(lsp
->SSNflags
, circuit
);
1099 /* 7.3.15.1 e) 3) LSP older than the one in db */
1101 isis_tx_queue_add(circuit
->tx_queue
, lsp
,
1103 ISIS_CLEAR_FLAG(lsp
->SSNflags
, circuit
);
1110 fabricd_trigger_csnp(circuit
->area
, circuit_scoped
);
1112 isis_free_tlvs(tlvs
);
1117 * Process Sequence Numbers
1119 * Section 7.3.15.2 - Action on receipt of a sequence numbers PDU
1122 static int process_snp(uint8_t pdu_type
, struct isis_circuit
*circuit
,
1123 const uint8_t *ssnpa
)
1125 bool is_csnp
= (pdu_type
== L1_COMPLETE_SEQ_NUM
1126 || pdu_type
== L2_COMPLETE_SEQ_NUM
);
1127 char typechar
= is_csnp
? 'C' : 'P';
1128 int level
= (pdu_type
== L1_COMPLETE_SEQ_NUM
1129 || pdu_type
== L1_PARTIAL_SEQ_NUM
)
1133 uint16_t pdu_len
= stream_getw(circuit
->rcv_stream
);
1134 uint8_t rem_sys_id
[ISIS_SYS_ID_LEN
];
1135 stream_get(rem_sys_id
, circuit
->rcv_stream
, ISIS_SYS_ID_LEN
);
1136 stream_forward_getp(circuit
->rcv_stream
, 1); /* Circuit ID - unused */
1138 uint8_t start_lsp_id
[ISIS_SYS_ID_LEN
+ 2] = {};
1139 uint8_t stop_lsp_id
[ISIS_SYS_ID_LEN
+ 2] = {};
1142 stream_get(start_lsp_id
, circuit
->rcv_stream
,
1143 ISIS_SYS_ID_LEN
+ 2);
1144 stream_get(stop_lsp_id
, circuit
->rcv_stream
,
1145 ISIS_SYS_ID_LEN
+ 2);
1148 if (pdu_len_validate(pdu_len
, circuit
)) {
1149 zlog_warn("Received a CSNP with bogus length %d", pdu_len
);
1150 return ISIS_WARNING
;
1153 if (isis
->debugs
& DEBUG_SNP_PACKETS
) {
1155 "ISIS-Snp (%s): Rcvd L%d %cSNP on %s, cirType %s, cirID %u",
1156 circuit
->area
->area_tag
, level
, typechar
,
1157 circuit
->interface
->name
,
1158 circuit_t2string(circuit
->is_type
),
1159 circuit
->circuit_id
);
1160 if (isis
->debugs
& DEBUG_PACKET_DUMP
)
1161 zlog_dump_data(STREAM_DATA(circuit
->rcv_stream
),
1162 stream_get_endp(circuit
->rcv_stream
));
1165 /* 7.3.15.2 a) 1 - external domain circuit will discard snp pdu */
1166 if (circuit
->ext_domain
) {
1169 "ISIS-Snp (%s): Rcvd L%d %cSNP on %s, "
1170 "skipping: circuit externalDomain = true",
1171 circuit
->area
->area_tag
, level
, typechar
,
1172 circuit
->interface
->name
);
1177 /* 7.3.15.2 a) 2,3 - manualL2OnlyMode not implemented */
1178 if (!(circuit
->is_type
& level
)) {
1180 "ISIS-Snp (%s): Rcvd L%d %cSNP on %s, "
1181 "skipping: circuit type %s does not match level %d",
1182 circuit
->area
->area_tag
, level
, typechar
,
1183 circuit
->interface
->name
,
1184 circuit_t2string(circuit
->is_type
), level
);
1189 /* 7.3.15.2 a) 4 - not applicable for CSNP only PSNPs on broadcast */
1190 if (!is_csnp
&& (circuit
->circ_type
== CIRCUIT_T_BROADCAST
)
1191 && !circuit
->u
.bc
.is_dr
[level
- 1]) {
1193 "ISIS-Snp (%s): Rcvd L%d %cSNP from %s on %s, "
1194 "skipping: we are not the DIS",
1195 circuit
->area
->area_tag
, level
, typechar
,
1196 snpa_print(ssnpa
), circuit
->interface
->name
);
1201 /* 7.3.15.2 a) 5 - need to make sure IDLength matches - already checked
1204 /* 7.3.15.2 a) 6 - maximum area match, can be ommited since we only use
1206 * - already checked */
1208 /* 7.3.15.2 a) 7 - Must check that we have an adjacency of the same
1210 /* for broadcast circuits, snpa should be compared */
1211 /* FIXME : Do we need to check SNPA? */
1212 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
) {
1213 if (!isis_adj_lookup(rem_sys_id
,
1214 circuit
->u
.bc
.adjdb
[level
- 1]))
1215 return ISIS_OK
; /* Silently discard */
1217 if (!fabricd
&& !circuit
->u
.p2p
.neighbor
) {
1218 zlog_warn("no p2p neighbor on circuit %s",
1219 circuit
->interface
->name
);
1220 return ISIS_OK
; /* Silently discard */
1224 struct isis_tlvs
*tlvs
;
1225 int retval
= ISIS_WARNING
;
1226 const char *error_log
;
1228 if (isis_unpack_tlvs(STREAM_READABLE(circuit
->rcv_stream
),
1229 circuit
->rcv_stream
, &tlvs
, &error_log
)) {
1230 zlog_warn("Something went wrong unpacking the SNP: %s",
1235 struct isis_passwd
*passwd
= (level
== IS_LEVEL_1
)
1236 ? &circuit
->area
->area_passwd
1237 : &circuit
->area
->domain_passwd
;
1238 if (CHECK_FLAG(passwd
->snp_auth
, SNP_AUTH_RECV
)
1239 && !isis_tlvs_auth_is_valid(tlvs
, passwd
, circuit
->rcv_stream
,
1241 isis_event_auth_failure(circuit
->area
->area_tag
,
1242 "SNP authentication failure",
1247 struct isis_lsp_entry
*entry_head
=
1248 (struct isis_lsp_entry
*)tlvs
->lsp_entries
.head
;
1250 /* debug isis snp-packets */
1251 if (isis
->debugs
& DEBUG_SNP_PACKETS
) {
1252 zlog_debug("ISIS-Snp (%s): Rcvd L%d %cSNP from %s on %s",
1253 circuit
->area
->area_tag
, level
, typechar
,
1254 snpa_print(ssnpa
), circuit
->interface
->name
);
1255 for (struct isis_lsp_entry
*entry
= entry_head
; entry
;
1256 entry
= entry
->next
) {
1258 "ISIS-Snp (%s): %cSNP entry %s, seq 0x%08" PRIx32
1259 ", cksum 0x%04" PRIx16
", lifetime %" PRIu16
"s",
1260 circuit
->area
->area_tag
, typechar
,
1261 rawlspid_print(entry
->id
), entry
->seqno
,
1262 entry
->checksum
, entry
->rem_lifetime
);
1266 bool resync_needed
= false;
1268 /* 7.3.15.2 b) Actions on LSP_ENTRIES reported */
1269 for (struct isis_lsp_entry
*entry
= entry_head
; entry
;
1270 entry
= entry
->next
) {
1271 struct isis_lsp
*lsp
=
1272 lsp_search(entry
->id
, circuit
->area
->lspdb
[level
- 1]);
1273 bool own_lsp
= !memcmp(entry
->id
, isis
->sysid
, ISIS_SYS_ID_LEN
);
1275 /* 7.3.15.2 b) 1) is this LSP newer */
1276 int cmp
= lsp_compare(circuit
->area
->area_tag
, lsp
,
1277 entry
->seqno
, entry
->checksum
,
1278 entry
->rem_lifetime
);
1279 /* 7.3.15.2 b) 2) if it equals, clear SRM on p2p */
1280 if (cmp
== LSP_EQUAL
) {
1281 /* if (circuit->circ_type !=
1282 * CIRCUIT_T_BROADCAST) */
1283 isis_tx_queue_del(circuit
->tx_queue
, lsp
);
1285 /* 7.3.15.2 b) 3) if it is older, clear SSN and set SRM
1287 else if (cmp
== LSP_OLDER
) {
1288 ISIS_CLEAR_FLAG(lsp
->SSNflags
, circuit
);
1289 isis_tx_queue_add(circuit
->tx_queue
, lsp
,
1292 /* 7.3.15.2 b) 4) if it is newer, set SSN and clear SRM
1296 lsp_inc_seqno(lsp
, entry
->seqno
);
1297 isis_tx_queue_add(circuit
->tx_queue
, lsp
,
1300 ISIS_SET_FLAG(lsp
->SSNflags
, circuit
);
1301 /* if (circuit->circ_type !=
1302 * CIRCUIT_T_BROADCAST) */
1303 isis_tx_queue_del(circuit
->tx_queue
, lsp
);
1304 resync_needed
= true;
1308 /* 7.3.15.2 b) 5) if it was not found, and all of those
1310 * insert it and set SSN on it */
1311 if (entry
->rem_lifetime
&& entry
->checksum
1312 && entry
->seqno
&& memcmp(entry
->id
, isis
->sysid
,
1314 struct isis_lsp
*lsp0
= NULL
;
1316 if (LSP_FRAGMENT(entry
->id
)) {
1317 uint8_t lspid
[ISIS_SYS_ID_LEN
+ 2];
1319 memcpy(lspid
, entry
->id
,
1320 ISIS_SYS_ID_LEN
+ 1);
1321 LSP_FRAGMENT(lspid
) = 0;
1324 circuit
->area
->lspdb
[level
- 1]);
1326 zlog_debug("Got lsp frag in snp, while zero not in database");
1330 lsp
= lsp_new(circuit
->area
, entry
->id
,
1331 entry
->rem_lifetime
, 0, 0,
1332 entry
->checksum
, lsp0
, level
);
1334 circuit
->area
->lspdb
[level
- 1]);
1336 lsp_set_all_srmflags(lsp
, false);
1337 ISIS_SET_FLAG(lsp
->SSNflags
, circuit
);
1338 resync_needed
= true;
1343 /* 7.3.15.2 c) on CSNP set SRM for all in range which were not reported
1347 * Build a list from our own LSP db bounded with
1348 * start_lsp_id and stop_lsp_id
1350 struct list
*lsp_list
= list_new();
1351 lsp_build_list_nonzero_ht(start_lsp_id
, stop_lsp_id
, lsp_list
,
1352 circuit
->area
->lspdb
[level
- 1]);
1354 /* Fixme: Find a better solution */
1355 struct listnode
*node
, *nnode
;
1356 struct isis_lsp
*lsp
;
1357 for (struct isis_lsp_entry
*entry
= entry_head
; entry
;
1358 entry
= entry
->next
) {
1359 for (ALL_LIST_ELEMENTS(lsp_list
, node
, nnode
, lsp
)) {
1360 if (lsp_id_cmp(lsp
->hdr
.lsp_id
, entry
->id
)
1362 list_delete_node(lsp_list
, node
);
1368 /* on remaining LSPs we set SRM (neighbor knew not of) */
1369 for (ALL_LIST_ELEMENTS_RO(lsp_list
, node
, lsp
)) {
1370 isis_tx_queue_add(circuit
->tx_queue
, lsp
, TX_LSP_NORMAL
);
1371 resync_needed
= true;
1375 list_delete(&lsp_list
);
1378 if (fabricd_initial_sync_is_complete(circuit
->area
) && resync_needed
)
1379 zlog_warn("OpenFabric: Needed to resync LSPDB using CSNP!\n");
1383 isis_free_tlvs(tlvs
);
1387 static int pdu_size(uint8_t pdu_type
, uint8_t *size
)
1392 *size
= ISIS_LANHELLO_HDRLEN
;
1395 *size
= ISIS_P2PHELLO_HDRLEN
;
1400 *size
= ISIS_LSP_HDR_LEN
;
1402 case L1_COMPLETE_SEQ_NUM
:
1403 case L2_COMPLETE_SEQ_NUM
:
1404 *size
= ISIS_CSNP_HDRLEN
;
1406 case L1_PARTIAL_SEQ_NUM
:
1407 case L2_PARTIAL_SEQ_NUM
:
1408 *size
= ISIS_PSNP_HDRLEN
;
1413 *size
+= ISIS_FIXED_HDR_LEN
;
1421 int isis_handle_pdu(struct isis_circuit
*circuit
, uint8_t *ssnpa
)
1423 int retval
= ISIS_OK
;
1425 /* Verify that at least the 8 bytes fixed header have been received */
1426 if (stream_get_endp(circuit
->rcv_stream
) < ISIS_FIXED_HDR_LEN
) {
1427 flog_err(EC_ISIS_PACKET
, "PDU is too short to be IS-IS.");
1431 uint8_t idrp
= stream_getc(circuit
->rcv_stream
);
1432 uint8_t length
= stream_getc(circuit
->rcv_stream
);
1433 uint8_t version1
= stream_getc(circuit
->rcv_stream
);
1434 uint8_t id_len
= stream_getc(circuit
->rcv_stream
);
1435 uint8_t pdu_type
= stream_getc(circuit
->rcv_stream
)
1436 & 0x1f; /* bits 6-8 are reserved */
1437 uint8_t version2
= stream_getc(circuit
->rcv_stream
);
1438 stream_forward_getp(circuit
->rcv_stream
, 1); /* reserved */
1439 uint8_t max_area_addrs
= stream_getc(circuit
->rcv_stream
);
1441 pdu_counter_count(circuit
->area
->pdu_rx_counters
, pdu_type
);
1443 if (idrp
== ISO9542_ESIS
) {
1444 flog_err(EC_LIB_DEVELOPMENT
,
1445 "No support for ES-IS packet IDRP=%" PRIx8
, idrp
);
1449 if (idrp
!= ISO10589_ISIS
) {
1450 flog_err(EC_ISIS_PACKET
, "Not an IS-IS packet IDRP=%" PRIx8
,
1455 if (version1
!= 1) {
1456 zlog_warn("Unsupported ISIS version %" PRIu8
, version1
);
1457 return ISIS_WARNING
;
1460 if (id_len
!= 0 && id_len
!= ISIS_SYS_ID_LEN
) {
1463 "IDFieldLengthMismatch: ID Length field in a received PDU %" PRIu8
1464 ", while the parameter for this IS is %u",
1465 id_len
, ISIS_SYS_ID_LEN
);
1469 uint8_t expected_length
;
1470 if (pdu_size(pdu_type
, &expected_length
)) {
1471 zlog_warn("Unsupported ISIS PDU %" PRIu8
, pdu_type
);
1472 return ISIS_WARNING
;
1475 if (length
!= expected_length
) {
1476 flog_err(EC_ISIS_PACKET
,
1477 "Exepected fixed header length = %" PRIu8
1479 expected_length
, length
);
1483 if (stream_get_endp(circuit
->rcv_stream
) < length
) {
1486 "PDU is too short to contain fixed header of given PDU type.");
1490 if (version2
!= 1) {
1491 zlog_warn("Unsupported ISIS PDU version %" PRIu8
, version2
);
1492 return ISIS_WARNING
;
1495 if (circuit
->is_passive
) {
1496 zlog_warn("Received ISIS PDU on passive circuit %s",
1497 circuit
->interface
->name
);
1498 return ISIS_WARNING
;
1502 if (pdu_type
!= FS_LINK_STATE
/* FS PDU doesn't contain max area addr field */
1503 && max_area_addrs
!= 0
1504 && max_area_addrs
!= isis
->max_area_addrs
) {
1507 "maximumAreaAddressesMismatch: maximumAreaAdresses in a received PDU %" PRIu8
1508 " while the parameter for this IS is %u",
1509 max_area_addrs
, isis
->max_area_addrs
);
1517 if (fabricd
&& pdu_type
!= P2P_HELLO
)
1519 retval
= process_hello(pdu_type
, circuit
, ssnpa
);
1525 && pdu_type
!= L2_LINK_STATE
1526 && pdu_type
!= FS_LINK_STATE
)
1528 retval
= process_lsp(pdu_type
, circuit
, ssnpa
, max_area_addrs
);
1530 case L1_COMPLETE_SEQ_NUM
:
1531 case L2_COMPLETE_SEQ_NUM
:
1532 case L1_PARTIAL_SEQ_NUM
:
1533 case L2_PARTIAL_SEQ_NUM
:
1534 retval
= process_snp(pdu_type
, circuit
, ssnpa
);
1543 int isis_receive(struct thread
*thread
)
1545 struct isis_circuit
*circuit
;
1546 uint8_t ssnpa
[ETH_ALEN
];
1552 circuit
= THREAD_ARG(thread
);
1555 circuit
->t_read
= NULL
;
1557 isis_circuit_stream(circuit
, &circuit
->rcv_stream
);
1559 retval
= circuit
->rx(circuit
, ssnpa
);
1561 #if ISIS_METHOD != ISIS_METHOD_BPF
1562 if (retval
== ISIS_OK
)
1563 retval
= isis_handle_pdu(circuit
, ssnpa
);
1564 #endif //ISIS_METHOD != ISIS_METHOD_BPF
1567 * prepare for next packet.
1569 if (!circuit
->is_passive
)
1570 isis_circuit_prepare(circuit
);
1578 void fill_fixed_hdr(uint8_t pdu_type
, struct stream
*stream
)
1582 if (pdu_size(pdu_type
, &length
))
1583 assert(!"Unknown PDU Type");
1585 stream_putc(stream
, ISO10589_ISIS
); /* IDRP */
1586 stream_putc(stream
, length
); /* Length of fixed header */
1587 stream_putc(stream
, 1); /* Version/Protocol ID Extension 1 */
1588 stream_putc(stream
, 0); /* ID Length, 0 => 6 */
1589 stream_putc(stream
, pdu_type
);
1590 stream_putc(stream
, 1); /* Subversion */
1591 stream_putc(stream
, 0); /* Reserved */
1592 stream_putc(stream
, 0); /* Max Area Addresses 0 => 3 */
1595 static uint8_t hello_pdu_type(struct isis_circuit
*circuit
, int level
)
1597 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
)
1598 return (level
== IS_LEVEL_1
) ? L1_LAN_HELLO
: L2_LAN_HELLO
;
1603 static void put_hello_hdr(struct isis_circuit
*circuit
, int level
,
1604 size_t *len_pointer
)
1606 uint8_t pdu_type
= hello_pdu_type(circuit
, level
);
1608 isis_circuit_stream(circuit
, &circuit
->snd_stream
);
1609 fill_fixed_hdr(pdu_type
, circuit
->snd_stream
);
1611 stream_putc(circuit
->snd_stream
, circuit
->is_type
);
1612 stream_put(circuit
->snd_stream
, circuit
->area
->isis
->sysid
,
1615 uint32_t holdtime
= circuit
->hello_multiplier
[level
- 1]
1616 * circuit
->hello_interval
[level
- 1];
1618 if (holdtime
> 0xffff)
1621 stream_putw(circuit
->snd_stream
, holdtime
);
1622 *len_pointer
= stream_get_endp(circuit
->snd_stream
);
1623 stream_putw(circuit
->snd_stream
, 0); /* length is filled in later */
1625 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
) {
1626 uint8_t *desig_is
= (level
== IS_LEVEL_1
)
1627 ? circuit
->u
.bc
.l1_desig_is
1628 : circuit
->u
.bc
.l2_desig_is
;
1629 stream_putc(circuit
->snd_stream
, circuit
->priority
[level
- 1]);
1630 stream_put(circuit
->snd_stream
, desig_is
, ISIS_SYS_ID_LEN
+ 1);
1632 stream_putc(circuit
->snd_stream
, circuit
->circuit_id
);
1636 int send_hello(struct isis_circuit
*circuit
, int level
)
1641 if (circuit
->is_passive
)
1644 if (circuit
->interface
->mtu
== 0) {
1645 zlog_warn("circuit has zero MTU");
1646 return ISIS_WARNING
;
1649 put_hello_hdr(circuit
, level
, &len_pointer
);
1651 struct isis_tlvs
*tlvs
= isis_alloc_tlvs();
1653 isis_tlvs_add_auth(tlvs
, &circuit
->passwd
);
1655 if (!listcount(circuit
->area
->area_addrs
)) {
1656 isis_free_tlvs(tlvs
);
1657 return ISIS_WARNING
;
1660 isis_tlvs_add_area_addresses(tlvs
, circuit
->area
->area_addrs
);
1662 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
) {
1663 isis_tlvs_add_lan_neighbors(
1664 tlvs
, circuit
->u
.bc
.lan_neighs
[level
- 1]);
1665 } else if (circuit
->circ_type
== CIRCUIT_T_P2P
1666 && !circuit
->disable_threeway_adj
) {
1667 uint32_t ext_circuit_id
= circuit
->idx
;
1668 if (circuit
->u
.p2p
.neighbor
) {
1669 uint8_t threeway_state
;
1671 if (fabricd_initial_sync_is_in_progress(circuit
->area
)
1672 && fabricd_initial_sync_circuit(circuit
->area
) != circuit
)
1673 threeway_state
= ISIS_THREEWAY_DOWN
;
1675 threeway_state
= circuit
->u
.p2p
.neighbor
->threeway_state
;
1676 isis_tlvs_add_threeway_adj(tlvs
,
1679 circuit
->u
.p2p
.neighbor
->sysid
,
1680 circuit
->u
.p2p
.neighbor
->ext_circuit_id
);
1682 isis_tlvs_add_threeway_adj(tlvs
,
1689 isis_tlvs_set_protocols_supported(tlvs
, &circuit
->nlpids
);
1694 * TLV gets included if no topology is enabled on the interface,
1695 * if one topology other than #0 is enabled, or if multiple topologies
1698 struct isis_circuit_mt_setting
**mt_settings
;
1699 unsigned int mt_count
;
1701 mt_settings
= circuit_mt_settings(circuit
, &mt_count
);
1702 if (mt_count
== 0 && area_is_mt(circuit
->area
)) {
1703 tlvs
->mt_router_info_empty
= true;
1704 } else if ((mt_count
== 1
1705 && mt_settings
[0]->mtid
!= ISIS_MT_IPV4_UNICAST
)
1706 || (mt_count
> 1)) {
1707 for (unsigned int i
= 0; i
< mt_count
; i
++)
1708 isis_tlvs_add_mt_router_info(tlvs
, mt_settings
[i
]->mtid
,
1712 if (circuit
->ip_router
) {
1713 struct list
*circuit_ip_addrs
= fabricd_ip_addrs(circuit
);
1715 if (circuit_ip_addrs
)
1716 isis_tlvs_add_ipv4_addresses(tlvs
, circuit_ip_addrs
);
1719 if (circuit
->ipv6_router
&& circuit
->ipv6_link
)
1720 isis_tlvs_add_ipv6_addresses(tlvs
, circuit
->ipv6_link
);
1722 if (isis_pack_tlvs(tlvs
, circuit
->snd_stream
, len_pointer
,
1723 circuit
->pad_hellos
, false)) {
1724 isis_free_tlvs(tlvs
);
1725 return ISIS_WARNING
; /* XXX: Maybe Log TLV structure? */
1728 if (isis
->debugs
& DEBUG_ADJ_PACKETS
) {
1729 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
) {
1731 "ISIS-Adj (%s): Sending L%d LAN IIH on %s, length %zd",
1732 circuit
->area
->area_tag
, level
,
1733 circuit
->interface
->name
,
1734 stream_get_endp(circuit
->snd_stream
));
1737 "ISIS-Adj (%s): Sending P2P IIH on %s, length %zd",
1738 circuit
->area
->area_tag
,
1739 circuit
->interface
->name
,
1740 stream_get_endp(circuit
->snd_stream
));
1742 if (isis
->debugs
& DEBUG_PACKET_DUMP
)
1743 zlog_dump_data(STREAM_DATA(circuit
->snd_stream
),
1744 stream_get_endp(circuit
->snd_stream
));
1747 isis_free_tlvs(tlvs
);
1749 pdu_counter_count(circuit
->area
->pdu_tx_counters
, hello_pdu_type(circuit
, level
));
1750 retval
= circuit
->tx(circuit
, level
);
1751 if (retval
!= ISIS_OK
)
1752 flog_err(EC_ISIS_PACKET
,
1753 "ISIS-Adj (%s): Send L%d IIH on %s failed",
1754 circuit
->area
->area_tag
, level
,
1755 circuit
->interface
->name
);
1760 static int send_hello_cb(struct thread
*thread
)
1762 struct isis_circuit_arg
*arg
= THREAD_ARG(thread
);
1766 struct isis_circuit
*circuit
= arg
->circuit
;
1767 int level
= arg
->level
;
1771 if (circuit
->circ_type
== CIRCUIT_T_P2P
) {
1772 circuit
->u
.p2p
.t_send_p2p_hello
= NULL
;
1773 send_hello(circuit
, 1);
1774 send_hello_sched(circuit
, ISIS_LEVEL1
,
1775 1000 * circuit
->hello_interval
[1]);
1779 if (circuit
->circ_type
!= CIRCUIT_T_BROADCAST
) {
1780 zlog_warn("ISIS-Hello (%s): Trying to send hello on unknown circuit type %d",
1781 circuit
->area
->area_tag
, circuit
->circ_type
);
1782 return ISIS_WARNING
;
1785 circuit
->u
.bc
.t_send_lan_hello
[level
- 1] = NULL
;
1786 if (!(circuit
->is_type
& level
)) {
1787 zlog_warn("ISIS-Hello (%s): Trying to send L%d IIH in L%d-only circuit",
1788 circuit
->area
->area_tag
, level
, 3 - level
);
1789 return ISIS_WARNING
;
1792 if (circuit
->u
.bc
.run_dr_elect
[level
- 1])
1793 isis_dr_elect(circuit
, level
);
1795 int rv
= send_hello(circuit
, level
);
1797 /* set next timer thread */
1798 send_hello_sched(circuit
, level
, 1000 * circuit
->hello_interval
[level
- 1]);
1802 static void _send_hello_sched(struct isis_circuit
*circuit
,
1803 struct thread
**threadp
,
1804 int level
, long delay
)
1807 if (thread_timer_remain_msec(*threadp
) < (unsigned long)delay
)
1810 thread_cancel(*threadp
);
1813 thread_add_timer_msec(master
, send_hello_cb
,
1814 &circuit
->level_arg
[level
- 1],
1815 isis_jitter(delay
, IIH_JITTER
),
1819 void send_hello_sched(struct isis_circuit
*circuit
, int level
, long delay
)
1821 if (circuit
->circ_type
== CIRCUIT_T_P2P
) {
1822 _send_hello_sched(circuit
, &circuit
->u
.p2p
.t_send_p2p_hello
,
1823 ISIS_LEVEL1
, delay
);
1827 if (circuit
->circ_type
!= CIRCUIT_T_BROADCAST
) {
1828 zlog_warn("%s: encountered unknown circuit type %d on %s",
1829 __func__
, circuit
->circ_type
,
1830 circuit
->interface
->name
);
1834 for (int loop_level
= ISIS_LEVEL1
; loop_level
<= ISIS_LEVEL2
; loop_level
++) {
1835 if (!(loop_level
& level
))
1840 &circuit
->u
.bc
.t_send_lan_hello
[loop_level
- 1],
1849 * Count the maximum number of lsps that can be accomodated by a given size.
1851 #define LSP_ENTRIES_LEN (10 + ISIS_SYS_ID_LEN)
1852 static uint16_t get_max_lsp_count(uint16_t size
)
1856 uint16_t remaining_size
;
1858 /* First count the full size TLVs */
1859 tlv_count
= size
/ MAX_LSP_ENTRIES_TLV_SIZE
;
1860 lsp_count
= tlv_count
* (MAX_LSP_ENTRIES_TLV_SIZE
/ LSP_ENTRIES_LEN
);
1862 /* The last TLV, if any */
1863 remaining_size
= size
% MAX_LSP_ENTRIES_TLV_SIZE
;
1864 if (remaining_size
- 2 >= LSP_ENTRIES_LEN
)
1865 lsp_count
+= (remaining_size
- 2) / LSP_ENTRIES_LEN
;
1870 int send_csnp(struct isis_circuit
*circuit
, int level
)
1872 if (circuit
->area
->lspdb
[level
- 1] == NULL
1873 || dict_count(circuit
->area
->lspdb
[level
- 1]) == 0)
1876 uint8_t pdu_type
= (level
== ISIS_LEVEL1
) ? L1_COMPLETE_SEQ_NUM
1877 : L2_COMPLETE_SEQ_NUM
;
1879 isis_circuit_stream(circuit
, &circuit
->snd_stream
);
1880 fill_fixed_hdr(pdu_type
, circuit
->snd_stream
);
1882 size_t len_pointer
= stream_get_endp(circuit
->snd_stream
);
1883 stream_putw(circuit
->snd_stream
, 0);
1884 stream_put(circuit
->snd_stream
, isis
->sysid
, ISIS_SYS_ID_LEN
);
1885 /* with zero circuit id - ref 9.10, 9.11 */
1886 stream_putc(circuit
->snd_stream
, 0);
1888 size_t start_pointer
= stream_get_endp(circuit
->snd_stream
);
1889 stream_put(circuit
->snd_stream
, 0, ISIS_SYS_ID_LEN
+ 2);
1890 size_t end_pointer
= stream_get_endp(circuit
->snd_stream
);
1891 stream_put(circuit
->snd_stream
, 0, ISIS_SYS_ID_LEN
+ 2);
1893 struct isis_passwd
*passwd
= (level
== ISIS_LEVEL1
)
1894 ? &circuit
->area
->area_passwd
1895 : &circuit
->area
->domain_passwd
;
1897 struct isis_tlvs
*tlvs
= isis_alloc_tlvs();
1899 if (CHECK_FLAG(passwd
->snp_auth
, SNP_AUTH_SEND
))
1900 isis_tlvs_add_auth(tlvs
, passwd
);
1902 size_t tlv_start
= stream_get_endp(circuit
->snd_stream
);
1903 if (isis_pack_tlvs(tlvs
, circuit
->snd_stream
, len_pointer
, false,
1905 isis_free_tlvs(tlvs
);
1906 return ISIS_WARNING
;
1908 isis_free_tlvs(tlvs
);
1911 get_max_lsp_count(STREAM_WRITEABLE(circuit
->snd_stream
));
1913 uint8_t start
[ISIS_SYS_ID_LEN
+ 2];
1914 memset(start
, 0x00, ISIS_SYS_ID_LEN
+ 2);
1915 uint8_t stop
[ISIS_SYS_ID_LEN
+ 2];
1916 memset(stop
, 0xff, ISIS_SYS_ID_LEN
+ 2);
1920 tlvs
= isis_alloc_tlvs();
1921 if (CHECK_FLAG(passwd
->snp_auth
, SNP_AUTH_SEND
))
1922 isis_tlvs_add_auth(tlvs
, passwd
);
1924 struct isis_lsp
*last_lsp
;
1925 isis_tlvs_add_csnp_entries(tlvs
, start
, stop
, num_lsps
,
1926 circuit
->area
->lspdb
[level
- 1],
1929 * Update the stop lsp_id before encoding this CSNP.
1931 if (tlvs
->lsp_entries
.count
< num_lsps
) {
1932 memset(stop
, 0xff, ISIS_SYS_ID_LEN
+ 2);
1934 memcpy(stop
, last_lsp
->hdr
.lsp_id
, sizeof(stop
));
1937 memcpy(STREAM_DATA(circuit
->snd_stream
) + start_pointer
, start
,
1938 ISIS_SYS_ID_LEN
+ 2);
1939 memcpy(STREAM_DATA(circuit
->snd_stream
) + end_pointer
, stop
,
1940 ISIS_SYS_ID_LEN
+ 2);
1941 stream_set_endp(circuit
->snd_stream
, tlv_start
);
1942 if (isis_pack_tlvs(tlvs
, circuit
->snd_stream
, len_pointer
,
1944 isis_free_tlvs(tlvs
);
1945 return ISIS_WARNING
;
1948 if (isis
->debugs
& DEBUG_SNP_PACKETS
) {
1950 "ISIS-Snp (%s): Sending L%d CSNP on %s, length %zd",
1951 circuit
->area
->area_tag
, level
,
1952 circuit
->interface
->name
,
1953 stream_get_endp(circuit
->snd_stream
));
1954 log_multiline(LOG_DEBUG
, " ", "%s",
1955 isis_format_tlvs(tlvs
));
1956 if (isis
->debugs
& DEBUG_PACKET_DUMP
)
1958 STREAM_DATA(circuit
->snd_stream
),
1959 stream_get_endp(circuit
->snd_stream
));
1962 pdu_counter_count(circuit
->area
->pdu_tx_counters
, pdu_type
);
1963 int retval
= circuit
->tx(circuit
, level
);
1964 if (retval
!= ISIS_OK
) {
1965 flog_err(EC_ISIS_PACKET
,
1966 "ISIS-Snp (%s): Send L%d CSNP on %s failed",
1967 circuit
->area
->area_tag
, level
,
1968 circuit
->interface
->name
);
1969 isis_free_tlvs(tlvs
);
1974 * Start lsp_id of the next CSNP should be one plus the
1975 * stop lsp_id in this current CSNP.
1977 memcpy(start
, stop
, ISIS_SYS_ID_LEN
+ 2);
1979 for (int i
= ISIS_SYS_ID_LEN
+ 1; i
>= 0; --i
) {
1980 if (start
[i
] < (uint8_t)0xff) {
1986 memset(stop
, 0xff, ISIS_SYS_ID_LEN
+ 2);
1987 isis_free_tlvs(tlvs
);
1993 int send_l1_csnp(struct thread
*thread
)
1995 struct isis_circuit
*circuit
;
1996 int retval
= ISIS_OK
;
1998 circuit
= THREAD_ARG(thread
);
2001 circuit
->t_send_csnp
[0] = NULL
;
2003 if ((circuit
->circ_type
== CIRCUIT_T_BROADCAST
2004 && circuit
->u
.bc
.is_dr
[0])
2005 || circuit
->circ_type
== CIRCUIT_T_P2P
) {
2006 send_csnp(circuit
, 1);
2008 /* set next timer thread */
2009 thread_add_timer(master
, send_l1_csnp
, circuit
,
2010 isis_jitter(circuit
->csnp_interval
[0], CSNP_JITTER
),
2011 &circuit
->t_send_csnp
[0]);
2016 int send_l2_csnp(struct thread
*thread
)
2018 struct isis_circuit
*circuit
;
2019 int retval
= ISIS_OK
;
2021 circuit
= THREAD_ARG(thread
);
2024 circuit
->t_send_csnp
[1] = NULL
;
2026 if ((circuit
->circ_type
== CIRCUIT_T_BROADCAST
2027 && circuit
->u
.bc
.is_dr
[1])
2028 || circuit
->circ_type
== CIRCUIT_T_P2P
) {
2029 send_csnp(circuit
, 2);
2031 /* set next timer thread */
2032 thread_add_timer(master
, send_l2_csnp
, circuit
,
2033 isis_jitter(circuit
->csnp_interval
[1], CSNP_JITTER
),
2034 &circuit
->t_send_csnp
[1]);
2040 * 7.3.15.4 action on expiration of partial SNP interval
2043 static int send_psnp(int level
, struct isis_circuit
*circuit
)
2045 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
2046 && circuit
->u
.bc
.is_dr
[level
- 1])
2049 if (circuit
->area
->lspdb
[level
- 1] == NULL
2050 || dict_count(circuit
->area
->lspdb
[level
- 1]) == 0)
2053 if (!circuit
->snd_stream
)
2056 uint8_t pdu_type
= (level
== ISIS_LEVEL1
) ? L1_PARTIAL_SEQ_NUM
2057 : L2_PARTIAL_SEQ_NUM
;
2059 isis_circuit_stream(circuit
, &circuit
->snd_stream
);
2060 fill_fixed_hdr(pdu_type
, circuit
->snd_stream
);
2062 size_t len_pointer
= stream_get_endp(circuit
->snd_stream
);
2063 stream_putw(circuit
->snd_stream
, 0); /* length is filled in later */
2064 stream_put(circuit
->snd_stream
, isis
->sysid
, ISIS_SYS_ID_LEN
);
2065 stream_putc(circuit
->snd_stream
, circuit
->idx
);
2067 struct isis_passwd
*passwd
= (level
== ISIS_LEVEL1
)
2068 ? &circuit
->area
->area_passwd
2069 : &circuit
->area
->domain_passwd
;
2071 struct isis_tlvs
*tlvs
= isis_alloc_tlvs();
2073 if (CHECK_FLAG(passwd
->snp_auth
, SNP_AUTH_SEND
))
2074 isis_tlvs_add_auth(tlvs
, passwd
);
2076 size_t tlv_start
= stream_get_endp(circuit
->snd_stream
);
2077 if (isis_pack_tlvs(tlvs
, circuit
->snd_stream
, len_pointer
, false,
2079 isis_free_tlvs(tlvs
);
2080 return ISIS_WARNING
;
2082 isis_free_tlvs(tlvs
);
2085 get_max_lsp_count(STREAM_WRITEABLE(circuit
->snd_stream
));
2088 tlvs
= isis_alloc_tlvs();
2089 if (CHECK_FLAG(passwd
->snp_auth
, SNP_AUTH_SEND
))
2090 isis_tlvs_add_auth(tlvs
, passwd
);
2092 for (dnode_t
*dnode
=
2093 dict_first(circuit
->area
->lspdb
[level
- 1]);
2094 dnode
; dnode
= dict_next(circuit
->area
->lspdb
[level
- 1],
2096 struct isis_lsp
*lsp
= dnode_get(dnode
);
2098 if (ISIS_CHECK_FLAG(lsp
->SSNflags
, circuit
))
2099 isis_tlvs_add_lsp_entry(tlvs
, lsp
);
2101 if (tlvs
->lsp_entries
.count
== num_lsps
)
2105 if (!tlvs
->lsp_entries
.count
) {
2106 isis_free_tlvs(tlvs
);
2110 stream_set_endp(circuit
->snd_stream
, tlv_start
);
2111 if (isis_pack_tlvs(tlvs
, circuit
->snd_stream
, len_pointer
,
2113 isis_free_tlvs(tlvs
);
2114 return ISIS_WARNING
;
2117 if (isis
->debugs
& DEBUG_SNP_PACKETS
) {
2119 "ISIS-Snp (%s): Sending L%d PSNP on %s, length %zd",
2120 circuit
->area
->area_tag
, level
,
2121 circuit
->interface
->name
,
2122 stream_get_endp(circuit
->snd_stream
));
2123 log_multiline(LOG_DEBUG
, " ", "%s",
2124 isis_format_tlvs(tlvs
));
2125 if (isis
->debugs
& DEBUG_PACKET_DUMP
)
2127 STREAM_DATA(circuit
->snd_stream
),
2128 stream_get_endp(circuit
->snd_stream
));
2131 pdu_counter_count(circuit
->area
->pdu_tx_counters
, pdu_type
);
2132 int retval
= circuit
->tx(circuit
, level
);
2133 if (retval
!= ISIS_OK
) {
2134 flog_err(EC_ISIS_PACKET
,
2135 "ISIS-Snp (%s): Send L%d PSNP on %s failed",
2136 circuit
->area
->area_tag
, level
,
2137 circuit
->interface
->name
);
2138 isis_free_tlvs(tlvs
);
2143 * sending succeeded, we can clear SSN flags of this circuit
2144 * for the LSPs in list
2146 struct isis_lsp_entry
*entry_head
;
2147 entry_head
= (struct isis_lsp_entry
*)tlvs
->lsp_entries
.head
;
2148 for (struct isis_lsp_entry
*entry
= entry_head
; entry
;
2149 entry
= entry
->next
)
2150 ISIS_CLEAR_FLAG(entry
->lsp
->SSNflags
, circuit
);
2151 isis_free_tlvs(tlvs
);
2157 int send_l1_psnp(struct thread
*thread
)
2160 struct isis_circuit
*circuit
;
2161 int retval
= ISIS_OK
;
2163 circuit
= THREAD_ARG(thread
);
2166 circuit
->t_send_psnp
[0] = NULL
;
2168 send_psnp(1, circuit
);
2169 /* set next timer thread */
2170 thread_add_timer(master
, send_l1_psnp
, circuit
,
2171 isis_jitter(circuit
->psnp_interval
[0], PSNP_JITTER
),
2172 &circuit
->t_send_psnp
[0]);
2178 * 7.3.15.4 action on expiration of partial SNP interval
2181 int send_l2_psnp(struct thread
*thread
)
2183 struct isis_circuit
*circuit
;
2184 int retval
= ISIS_OK
;
2186 circuit
= THREAD_ARG(thread
);
2189 circuit
->t_send_psnp
[1] = NULL
;
2191 send_psnp(2, circuit
);
2193 /* set next timer thread */
2194 thread_add_timer(master
, send_l2_psnp
, circuit
,
2195 isis_jitter(circuit
->psnp_interval
[1], PSNP_JITTER
),
2196 &circuit
->t_send_psnp
[1]);
2202 * ISO 10589 - 7.3.14.3
2204 void send_lsp(struct isis_circuit
*circuit
, struct isis_lsp
*lsp
,
2205 enum isis_tx_type tx_type
)
2208 int retval
= ISIS_OK
;
2210 if (circuit
->state
!= C_STATE_UP
|| circuit
->is_passive
== 1)
2214 * Do not send if levels do not match
2216 if (!(lsp
->level
& circuit
->is_type
))
2220 * Do not send if we do not have adjacencies in state up on the circuit
2222 if (circuit
->upadjcount
[lsp
->level
- 1] == 0)
2225 /* stream_copy will assert and stop program execution if LSP is larger
2227 * the circuit's MTU. So handle and log this case here. */
2228 if (stream_get_endp(lsp
->pdu
) > stream_get_size(circuit
->snd_stream
)) {
2231 "ISIS-Upd (%s): Can't send L%d LSP %s, seq 0x%08" PRIx32
2232 ", cksum 0x%04" PRIx16
", lifetime %" PRIu16
2233 "s on %s. LSP Size is %zu while interface stream size is %zu.",
2234 circuit
->area
->area_tag
, lsp
->level
,
2235 rawlspid_print(lsp
->hdr
.lsp_id
), lsp
->hdr
.seqno
,
2236 lsp
->hdr
.checksum
, lsp
->hdr
.rem_lifetime
,
2237 circuit
->interface
->name
, stream_get_endp(lsp
->pdu
),
2238 stream_get_size(circuit
->snd_stream
));
2239 if (isis
->debugs
& DEBUG_PACKET_DUMP
)
2240 zlog_dump_data(STREAM_DATA(lsp
->pdu
),
2241 stream_get_endp(lsp
->pdu
));
2242 retval
= ISIS_ERROR
;
2246 /* copy our lsp to the send buffer */
2247 stream_copy(circuit
->snd_stream
, lsp
->pdu
);
2249 if (tx_type
== TX_LSP_CIRCUIT_SCOPED
) {
2250 stream_putc_at(circuit
->snd_stream
, 4, FS_LINK_STATE
);
2251 stream_putc_at(circuit
->snd_stream
, 7, L2_CIRCUIT_FLOODING_SCOPE
);
2254 if (isis
->debugs
& DEBUG_UPDATE_PACKETS
) {
2255 zlog_debug("ISIS-Upd (%s): Sending %sL%d LSP %s, seq 0x%08" PRIx32
2256 ", cksum 0x%04" PRIx16
", lifetime %" PRIu16
2258 circuit
->area
->area_tag
,
2259 (tx_type
== TX_LSP_CIRCUIT_SCOPED
)
2260 ? "Circuit scoped " : "",
2262 rawlspid_print(lsp
->hdr
.lsp_id
), lsp
->hdr
.seqno
,
2263 lsp
->hdr
.checksum
, lsp
->hdr
.rem_lifetime
,
2264 circuit
->interface
->name
);
2265 if (isis
->debugs
& DEBUG_PACKET_DUMP
)
2266 zlog_dump_data(STREAM_DATA(circuit
->snd_stream
),
2267 stream_get_endp(circuit
->snd_stream
));
2270 uint8_t pdu_type
= (tx_type
== TX_LSP_CIRCUIT_SCOPED
) ? FS_LINK_STATE
2271 : (lsp
->level
== ISIS_LEVEL1
) ? L1_LINK_STATE
2275 pdu_counter_count(circuit
->area
->pdu_tx_counters
, pdu_type
);
2276 retval
= circuit
->tx(circuit
, lsp
->level
);
2277 if (retval
!= ISIS_OK
) {
2278 flog_err(EC_ISIS_PACKET
,
2279 "ISIS-Upd (%s): Send L%d LSP on %s failed %s",
2280 circuit
->area
->area_tag
, lsp
->level
,
2281 circuit
->interface
->name
,
2282 (retval
== ISIS_WARNING
) ? "temporarily"
2288 || (retval
== ISIS_OK
&& circuit
->circ_type
== CIRCUIT_T_BROADCAST
)
2289 || (retval
!= ISIS_OK
&& retval
!= ISIS_WARNING
)) {
2290 /* SRM flag will trigger retransmission. We will not retransmit
2292 * encountered a fatal error.
2293 * On success, they should only be cleared if it's a broadcast
2295 * On a P2P circuit, we will wait for the ack from the neighbor
2299 isis_tx_queue_del(circuit
->tx_queue
, lsp
);