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"
62 static int ack_lsp(struct isis_lsp_hdr
*hdr
, struct isis_circuit
*circuit
,
69 (level
== IS_LEVEL_1
) ? L1_PARTIAL_SEQ_NUM
: L2_PARTIAL_SEQ_NUM
;
71 isis_circuit_stream(circuit
, &circuit
->snd_stream
);
73 fill_fixed_hdr(pdu_type
, circuit
->snd_stream
);
75 lenp
= stream_get_endp(circuit
->snd_stream
);
76 stream_putw(circuit
->snd_stream
, 0); /* PDU length */
77 stream_put(circuit
->snd_stream
, isis
->sysid
, ISIS_SYS_ID_LEN
);
78 stream_putc(circuit
->snd_stream
, circuit
->idx
);
79 stream_putc(circuit
->snd_stream
, 9); /* code */
80 stream_putc(circuit
->snd_stream
, 16); /* len */
82 stream_putw(circuit
->snd_stream
, hdr
->rem_lifetime
);
83 stream_put(circuit
->snd_stream
, hdr
->lsp_id
, ISIS_SYS_ID_LEN
+ 2);
84 stream_putl(circuit
->snd_stream
, hdr
->seqno
);
85 stream_putw(circuit
->snd_stream
, hdr
->checksum
);
87 length
= (uint16_t)stream_get_endp(circuit
->snd_stream
);
88 /* Update PDU length */
89 stream_putw_at(circuit
->snd_stream
, lenp
, length
);
91 retval
= circuit
->tx(circuit
, level
);
92 if (retval
!= ISIS_OK
)
93 flog_err(EC_ISIS_PACKET
,
94 "ISIS-Upd (%s): Send L%d LSP PSNP on %s failed",
95 circuit
->area
->area_tag
, level
,
96 circuit
->interface
->name
);
106 struct isis_circuit
*circuit
;
111 uint8_t sys_id
[ISIS_SYS_ID_LEN
];
118 uint8_t dis
[ISIS_SYS_ID_LEN
+ 1];
123 struct isis_tlvs
*tlvs
;
126 static int process_p2p_hello(struct iih_info
*iih
)
128 struct isis_threeway_adj
*tw_adj
= iih
->tlvs
->threeway_adj
;
130 if (tw_adj
->state
> ISIS_THREEWAY_DOWN
) {
131 if (isis
->debugs
& DEBUG_ADJ_PACKETS
) {
132 zlog_debug("ISIS-Adj (%s): Rcvd P2P IIH from (%s) with invalid three-way state: %d\n",
133 iih
->circuit
->area
->area_tag
,
134 iih
->circuit
->interface
->name
,
140 if (tw_adj
->neighbor_set
141 && (memcmp(tw_adj
->neighbor_id
, isis
->sysid
, ISIS_SYS_ID_LEN
)
142 || tw_adj
->neighbor_circuit_id
!= (uint32_t) iih
->circuit
->idx
)) {
144 if (isis
->debugs
& DEBUG_ADJ_PACKETS
) {
145 zlog_debug("ISIS-Adj (%s): Rcvd P2P IIH from (%s) which lists IS/Circuit different from us as neighbor.\n",
146 iih
->circuit
->area
->area_tag
,
147 iih
->circuit
->interface
->name
);
155 * My interpertation of the ISO, if no adj exists we will create one for
158 struct isis_adjacency
*adj
= iih
->circuit
->u
.p2p
.neighbor
;
159 /* If an adjacency exists, check it is with the source of the hello
162 if (memcmp(iih
->sys_id
, adj
->sysid
, ISIS_SYS_ID_LEN
)) {
164 "hello source and adjacency do not match, set adj down\n");
165 isis_adj_state_change(adj
, ISIS_ADJ_DOWN
,
170 if (!adj
|| adj
->level
!= iih
->circ_type
) {
172 adj
= isis_new_adj(iih
->sys_id
, NULL
, iih
->circ_type
,
175 adj
->level
= iih
->circ_type
;
177 iih
->circuit
->u
.p2p
.neighbor
= adj
;
178 /* Build lsp with the new neighbor entry when a new
179 * adjacency is formed. Set adjacency circuit type to
180 * IIH PDU header circuit type before lsp is regenerated
181 * when an adjacency is up. This will result in the new
182 * adjacency entry getting added to the lsp tlv neighbor list.
184 adj
->circuit_t
= iih
->circ_type
;
185 isis_adj_state_change(adj
, ISIS_ADJ_INITIALIZING
, NULL
);
186 adj
->sys_type
= ISIS_SYSTYPE_UNKNOWN
;
189 if (tw_adj
&& adj
->threeway_state
== ISIS_THREEWAY_DOWN
)
190 adj
->ext_circuit_id
= tw_adj
->local_circuit_id
;
192 /* 8.2.6 Monitoring point-to-point adjacencies */
193 adj
->hold_time
= iih
->holdtime
;
194 adj
->last_upd
= time(NULL
);
197 isis_tlvs_to_adj(iih
->tlvs
, adj
, &changed
);
198 changed
|= tlvs_to_adj_mt_set(iih
->tlvs
, iih
->v4_usable
, iih
->v6_usable
,
201 /* Update MPLS TE Remote IP address parameter if possible */
202 if (IS_MPLS_TE(isisMplsTE
) && iih
->circuit
->mtc
203 && IS_CIRCUIT_TE(iih
->circuit
->mtc
) && adj
->ipv4_address_count
)
204 set_circuitparams_rmt_ipaddr(iih
->circuit
->mtc
,
205 adj
->ipv4_addresses
[0]);
207 /* lets take care of the expiry */
208 THREAD_TIMER_OFF(adj
->t_expire
);
209 thread_add_timer(master
, isis_adj_expire
, adj
, (long)adj
->hold_time
,
212 /* While fabricds initial sync is in progress, ignore hellos from other
213 * interfaces than the one we are performing the initial sync on. */
214 if (fabricd_initial_sync_is_in_progress(iih
->circuit
->area
)
215 && fabricd_initial_sync_circuit(iih
->circuit
->area
) != iih
->circuit
)
218 /* 8.2.5.2 a) a match was detected */
219 if (isis_tlvs_area_addresses_match(iih
->tlvs
,
220 iih
->circuit
->area
->area_addrs
)) {
221 /* 8.2.5.2 a) 2) If the system is L1 - table 5 */
222 if (iih
->circuit
->area
->is_type
== IS_LEVEL_1
) {
223 switch (iih
->circ_type
) {
225 case IS_LEVEL_1_AND_2
:
226 if (adj
->adj_state
!= ISIS_ADJ_UP
227 || adj
->adj_usage
== ISIS_ADJ_LEVEL1
) {
228 isis_adj_process_threeway(adj
, tw_adj
,
233 if (adj
->adj_state
!= ISIS_ADJ_UP
) {
234 /* (7) reject - wrong system type event
236 zlog_warn("wrongSystemType");
238 } else if (adj
->adj_usage
== ISIS_ADJ_LEVEL1
) {
239 /* (6) down - wrong system */
240 isis_adj_state_change(adj
,
248 /* 8.2.5.2 a) 3) If the system is L1L2 - table 6 */
249 if (iih
->circuit
->area
->is_type
== IS_LEVEL_1_AND_2
) {
250 switch (iih
->circ_type
) {
252 if (adj
->adj_state
!= ISIS_ADJ_UP
253 || adj
->adj_usage
== ISIS_ADJ_LEVEL1
) {
254 isis_adj_process_threeway(adj
, tw_adj
,
256 } else if ((adj
->adj_usage
257 == ISIS_ADJ_LEVEL1AND2
)
259 == ISIS_ADJ_LEVEL2
)) {
260 /* (8) down - wrong system */
261 isis_adj_state_change(adj
,
267 if (adj
->adj_state
!= ISIS_ADJ_UP
268 || adj
->adj_usage
== ISIS_ADJ_LEVEL2
) {
269 isis_adj_process_threeway(adj
, tw_adj
,
271 } else if ((adj
->adj_usage
== ISIS_ADJ_LEVEL1
)
273 == ISIS_ADJ_LEVEL1AND2
)) {
274 /* (8) down - wrong system */
275 isis_adj_state_change(adj
,
280 case IS_LEVEL_1_AND_2
:
281 if (adj
->adj_state
!= ISIS_ADJ_UP
282 || adj
->adj_usage
== ISIS_ADJ_LEVEL1AND2
) {
283 isis_adj_process_threeway(adj
, tw_adj
,
284 ISIS_ADJ_LEVEL1AND2
);
285 } else if ((adj
->adj_usage
== ISIS_ADJ_LEVEL1
)
287 == ISIS_ADJ_LEVEL2
)) {
288 /* (8) down - wrong system */
289 isis_adj_state_change(adj
,
297 /* 8.2.5.2 a) 4) If the system is L2 - table 7 */
298 if (iih
->circuit
->area
->is_type
== IS_LEVEL_2
) {
299 switch (iih
->circ_type
) {
301 if (adj
->adj_state
!= ISIS_ADJ_UP
) {
302 /* (5) reject - wrong system type event
304 zlog_warn("wrongSystemType");
306 } else if ((adj
->adj_usage
307 == ISIS_ADJ_LEVEL1AND2
)
309 == ISIS_ADJ_LEVEL2
)) {
310 /* (6) down - wrong system */
311 isis_adj_state_change(adj
,
316 case IS_LEVEL_1_AND_2
:
318 if (adj
->adj_state
!= ISIS_ADJ_UP
319 || adj
->adj_usage
== ISIS_ADJ_LEVEL2
) {
320 isis_adj_process_threeway(adj
, tw_adj
,
322 } else if (adj
->adj_usage
323 == ISIS_ADJ_LEVEL1AND2
) {
324 /* (6) down - wrong system */
325 isis_adj_state_change(adj
,
333 /* 8.2.5.2 b) if no match was detected */
334 else if (listcount(iih
->circuit
->area
->area_addrs
) > 0) {
335 if (iih
->circuit
->area
->is_type
== IS_LEVEL_1
) {
336 /* 8.2.5.2 b) 1) is_type L1 and adj is not up */
337 if (adj
->adj_state
!= ISIS_ADJ_UP
) {
338 isis_adj_state_change(adj
, ISIS_ADJ_DOWN
,
340 /* 8.2.5.2 b) 2)is_type L1 and adj is up */
342 isis_adj_state_change(adj
, ISIS_ADJ_DOWN
,
343 "Down - Area Mismatch");
346 /* 8.2.5.2 b 3 If the system is L2 or L1L2 - table 8 */
348 switch (iih
->circ_type
) {
350 if (adj
->adj_state
!= ISIS_ADJ_UP
) {
351 /* (6) reject - Area Mismatch event */
352 zlog_warn("AreaMismatch");
354 } else if (adj
->adj_usage
== ISIS_ADJ_LEVEL1
) {
355 /* (7) down - area mismatch */
356 isis_adj_state_change(adj
,
360 } else if ((adj
->adj_usage
361 == ISIS_ADJ_LEVEL1AND2
)
363 == ISIS_ADJ_LEVEL2
)) {
364 /* (7) down - wrong system */
365 isis_adj_state_change(adj
,
370 case IS_LEVEL_1_AND_2
:
372 if (adj
->adj_state
!= ISIS_ADJ_UP
373 || adj
->adj_usage
== ISIS_ADJ_LEVEL2
) {
374 isis_adj_process_threeway(adj
, tw_adj
,
376 } else if (adj
->adj_usage
== ISIS_ADJ_LEVEL1
) {
377 /* (7) down - wrong system */
378 isis_adj_state_change(adj
,
381 } else if (adj
->adj_usage
382 == ISIS_ADJ_LEVEL1AND2
) {
383 if (iih
->circ_type
== IS_LEVEL_2
) {
384 /* (7) down - wrong system */
385 isis_adj_state_change(
389 /* (7) down - area mismatch */
390 isis_adj_state_change(
399 /* down - area mismatch */
400 isis_adj_state_change(adj
, ISIS_ADJ_DOWN
, "Area Mismatch");
403 if (adj
->adj_state
== ISIS_ADJ_UP
&& changed
) {
404 lsp_regenerate_schedule(adj
->circuit
->area
,
405 isis_adj_usage2levels(adj
->adj_usage
),
409 /* 8.2.5.2 c) if the action was up - comparing circuit IDs */
410 /* FIXME - Missing parts */
412 /* some of my own understanding of the ISO, why the heck does
413 * it not say what should I change the system_type to...
415 switch (adj
->adj_usage
) {
416 case ISIS_ADJ_LEVEL1
:
417 adj
->sys_type
= ISIS_SYSTYPE_L1_IS
;
419 case ISIS_ADJ_LEVEL2
:
420 adj
->sys_type
= ISIS_SYSTYPE_L2_IS
;
422 case ISIS_ADJ_LEVEL1AND2
:
423 adj
->sys_type
= ISIS_SYSTYPE_L2_IS
;
426 adj
->sys_type
= ISIS_SYSTYPE_UNKNOWN
;
430 if (isis
->debugs
& DEBUG_ADJ_PACKETS
) {
432 "ISIS-Adj (%s): Rcvd P2P IIH from (%s), cir type %s,"
433 " cir id %hhu, length %" PRIu16
,
434 iih
->circuit
->area
->area_tag
,
435 iih
->circuit
->interface
->name
,
436 circuit_t2string(iih
->circuit
->is_type
),
437 iih
->circuit
->circuit_id
, iih
->pdu_len
);
443 static int process_lan_hello(struct iih_info
*iih
)
445 struct isis_adjacency
*adj
;
446 adj
= isis_adj_lookup(iih
->sys_id
,
447 iih
->circuit
->u
.bc
.adjdb
[iih
->level
- 1]);
448 if ((adj
== NULL
) || (memcmp(adj
->snpa
, iih
->ssnpa
, ETH_ALEN
))
449 || (adj
->level
!= iih
->level
)) {
451 /* Do as in 8.4.2.5 */
452 adj
= isis_new_adj(iih
->sys_id
, iih
->ssnpa
, iih
->level
,
456 memcpy(adj
->snpa
, iih
->ssnpa
, 6);
458 memset(adj
->snpa
, ' ', 6);
460 adj
->level
= iih
->level
;
462 isis_adj_state_change(adj
, ISIS_ADJ_INITIALIZING
, NULL
);
464 if (iih
->level
== IS_LEVEL_1
)
465 adj
->sys_type
= ISIS_SYSTYPE_L1_IS
;
467 adj
->sys_type
= ISIS_SYSTYPE_L2_IS
;
468 list_delete_all_node(
469 iih
->circuit
->u
.bc
.lan_neighs
[iih
->level
- 1]);
470 isis_adj_build_neigh_list(
471 iih
->circuit
->u
.bc
.adjdb
[iih
->level
- 1],
472 iih
->circuit
->u
.bc
.lan_neighs
[iih
->level
- 1]);
475 if (adj
->dis_record
[iih
->level
- 1].dis
== ISIS_IS_DIS
) {
476 uint8_t *dis
= (iih
->level
== 1)
477 ? iih
->circuit
->u
.bc
.l1_desig_is
478 : iih
->circuit
->u
.bc
.l2_desig_is
;
480 if (memcmp(dis
, iih
->dis
, ISIS_SYS_ID_LEN
+ 1)) {
481 thread_add_event(master
, isis_event_dis_status_change
,
482 iih
->circuit
, 0, NULL
);
483 memcpy(dis
, iih
->dis
, ISIS_SYS_ID_LEN
+ 1);
487 adj
->circuit_t
= iih
->circ_type
;
488 adj
->hold_time
= iih
->holdtime
;
489 adj
->last_upd
= time(NULL
);
490 adj
->prio
[iih
->level
- 1] = iih
->priority
;
491 memcpy(adj
->lanid
, iih
->dis
, ISIS_SYS_ID_LEN
+ 1);
494 isis_tlvs_to_adj(iih
->tlvs
, adj
, &changed
);
495 changed
|= tlvs_to_adj_mt_set(iih
->tlvs
, iih
->v4_usable
, iih
->v6_usable
,
498 /* lets take care of the expiry */
499 THREAD_TIMER_OFF(adj
->t_expire
);
500 thread_add_timer(master
, isis_adj_expire
, adj
, (long)adj
->hold_time
,
504 * If the snpa for this circuit is found from LAN Neighbours TLV
505 * we have two-way communication -> adjacency can be put to state "up"
507 bool own_snpa_found
=
508 isis_tlvs_own_snpa_found(iih
->tlvs
, iih
->circuit
->u
.bc
.snpa
);
510 if (adj
->adj_state
!= ISIS_ADJ_UP
) {
511 if (own_snpa_found
) {
512 isis_adj_state_change(
514 "own SNPA found in LAN Neighbours TLV");
517 if (!own_snpa_found
) {
518 isis_adj_state_change(
519 adj
, ISIS_ADJ_INITIALIZING
,
520 "own SNPA not found in LAN Neighbours TLV");
524 if (adj
->adj_state
== ISIS_ADJ_UP
&& changed
)
525 lsp_regenerate_schedule(adj
->circuit
->area
, iih
->level
, 0);
527 if (isis
->debugs
& DEBUG_ADJ_PACKETS
) {
529 "ISIS-Adj (%s): Rcvd L%d LAN IIH from %s on %s, cirType %s, cirID %u, length %zd",
530 iih
->circuit
->area
->area_tag
, iih
->level
,
531 snpa_print(iih
->ssnpa
), iih
->circuit
->interface
->name
,
532 circuit_t2string(iih
->circuit
->is_type
),
533 iih
->circuit
->circuit_id
,
534 stream_get_endp(iih
->circuit
->rcv_stream
));
539 static int pdu_len_validate(uint16_t pdu_len
, struct isis_circuit
*circuit
)
541 if (pdu_len
< stream_get_getp(circuit
->rcv_stream
)
542 || pdu_len
> ISO_MTU(circuit
)
543 || pdu_len
> stream_get_endp(circuit
->rcv_stream
))
546 if (pdu_len
< stream_get_endp(circuit
->rcv_stream
))
547 stream_set_endp(circuit
->rcv_stream
, pdu_len
);
551 static int process_hello(uint8_t pdu_type
, struct isis_circuit
*circuit
,
554 bool p2p_hello
= (pdu_type
== P2P_HELLO
);
555 int level
= p2p_hello
? 0
556 : (pdu_type
== L1_LAN_HELLO
) ? ISIS_LEVEL1
558 const char *pdu_name
=
561 : (level
== ISIS_LEVEL1
) ? "L1 LAN IIH" : "L2 LAN IIH";
563 if (isis
->debugs
& DEBUG_ADJ_PACKETS
) {
564 zlog_debug("ISIS-Adj (%s): Rcvd %s on %s, cirType %s, cirID %u",
565 circuit
->area
->area_tag
, pdu_name
,
566 circuit
->interface
->name
,
567 circuit_t2string(circuit
->is_type
),
568 circuit
->circuit_id
);
569 if (isis
->debugs
& DEBUG_PACKET_DUMP
)
570 zlog_dump_data(STREAM_DATA(circuit
->rcv_stream
),
571 stream_get_endp(circuit
->rcv_stream
));
575 if (circuit
->circ_type
!= CIRCUIT_T_P2P
) {
576 zlog_warn("p2p hello on non p2p circuit");
580 if (circuit
->circ_type
!= CIRCUIT_T_BROADCAST
) {
581 zlog_warn("lan hello on non broadcast circuit");
585 if (circuit
->ext_domain
) {
587 "level %d LAN Hello received over circuit with externalDomain = true",
592 if (!(circuit
->is_type
& level
)) {
593 if (isis
->debugs
& DEBUG_ADJ_PACKETS
) {
595 "ISIS-Adj (%s): Interface level mismatch, %s",
596 circuit
->area
->area_tag
,
597 circuit
->interface
->name
);
603 struct iih_info iih
= {
604 .circuit
= circuit
, .ssnpa
= ssnpa
, .level
= level
};
606 /* Generic IIH Header */
607 iih
.circ_type
= stream_getc(circuit
->rcv_stream
) & 0x03;
608 stream_get(iih
.sys_id
, circuit
->rcv_stream
, ISIS_SYS_ID_LEN
);
609 iih
.holdtime
= stream_getw(circuit
->rcv_stream
);
610 iih
.pdu_len
= stream_getw(circuit
->rcv_stream
);
613 iih
.circuit_id
= stream_getc(circuit
->rcv_stream
);
615 iih
.priority
= stream_getc(circuit
->rcv_stream
);
616 stream_get(iih
.dis
, circuit
->rcv_stream
, ISIS_SYS_ID_LEN
+ 1);
619 if (pdu_len_validate(iih
.pdu_len
, circuit
)) {
621 "ISIS-Adj (%s): Rcvd %s from (%s) with invalid pdu length %" PRIu16
,
622 circuit
->area
->area_tag
, pdu_name
,
623 circuit
->interface
->name
, iih
.pdu_len
);
627 if (!p2p_hello
&& !(level
& iih
.circ_type
)) {
628 flog_err(EC_ISIS_PACKET
,
629 "Level %d LAN Hello with Circuit Type %d", level
,
634 const char *error_log
;
635 int retval
= ISIS_WARNING
;
637 if (isis_unpack_tlvs(STREAM_READABLE(circuit
->rcv_stream
),
638 circuit
->rcv_stream
, &iih
.tlvs
, &error_log
)) {
639 zlog_warn("isis_unpack_tlvs() failed: %s", error_log
);
643 if (!iih
.tlvs
->area_addresses
.count
) {
644 zlog_warn("No Area addresses TLV in %s", pdu_name
);
648 if (!iih
.tlvs
->protocols_supported
.count
) {
649 zlog_warn("No supported protocols TLV in %s", pdu_name
);
653 if (!isis_tlvs_auth_is_valid(iih
.tlvs
, &circuit
->passwd
,
654 circuit
->rcv_stream
, false)) {
655 isis_event_auth_failure(circuit
->area
->area_tag
,
656 "IIH authentication failure",
661 if (!memcmp(iih
.sys_id
, isis
->sysid
, ISIS_SYS_ID_LEN
)) {
663 "ISIS-Adj (%s): Received IIH with own sysid - discard",
664 circuit
->area
->area_tag
);
669 && (listcount(circuit
->area
->area_addrs
) == 0
670 || (level
== ISIS_LEVEL1
671 && !isis_tlvs_area_addresses_match(
672 iih
.tlvs
, circuit
->area
->area_addrs
)))) {
673 if (isis
->debugs
& DEBUG_ADJ_PACKETS
) {
675 "ISIS-Adj (%s): Area mismatch, level %d IIH on %s",
676 circuit
->area
->area_tag
, level
,
677 circuit
->interface
->name
);
682 iih
.v4_usable
= (fabricd_ip_addrs(circuit
)
683 && iih
.tlvs
->ipv4_address
.count
);
685 iih
.v6_usable
= (circuit
->ipv6_link
&& listcount(circuit
->ipv6_link
)
686 && iih
.tlvs
->ipv6_address
.count
);
688 if (!iih
.v4_usable
&& !iih
.v6_usable
) {
689 if (isis
->debugs
& DEBUG_ADJ_PACKETS
) {
691 "ISIS-Adj (%s): Neither IPv4 nor IPv6 considered usable. Ignoring IIH",
692 circuit
->area
->area_tag
);
698 retval
= p2p_hello
? process_p2p_hello(&iih
) : process_lan_hello(&iih
);
700 isis_free_tlvs(iih
.tlvs
);
706 * Process Level 1/2 Link State
708 * Section 7.3.15.1 - Action on receipt of a link state PDU
710 static int process_lsp(uint8_t pdu_type
, struct isis_circuit
*circuit
,
711 const uint8_t *ssnpa
, uint8_t max_area_addrs
)
716 if (pdu_type
== FS_LINK_STATE
) {
719 if (max_area_addrs
!= L2_CIRCUIT_FLOODING_SCOPE
)
722 circuit_scoped
= true;
724 /* The stream is used verbatim for sending out new LSPDUs.
725 * So make sure we store it as an L2 LSPDU internally.
726 * (compare for the reverse in `send_lsp`) */
727 stream_putc_at(circuit
->rcv_stream
, 4, L2_LINK_STATE
);
728 stream_putc_at(circuit
->rcv_stream
, 7, 0);
730 if (pdu_type
== L1_LINK_STATE
)
734 circuit_scoped
= false;
737 if (isis
->debugs
& DEBUG_UPDATE_PACKETS
) {
739 "ISIS-Upd (%s): Rcvd %sL%d LSP on %s, cirType %s, cirID %u",
740 circuit
->area
->area_tag
,
741 circuit_scoped
? "Circuit scoped " : "", level
,
742 circuit
->interface
->name
,
743 circuit_t2string(circuit
->is_type
),
744 circuit
->circuit_id
);
745 if (isis
->debugs
& DEBUG_PACKET_DUMP
)
746 zlog_dump_data(STREAM_DATA(circuit
->rcv_stream
),
747 stream_get_endp(circuit
->rcv_stream
));
750 struct isis_lsp_hdr hdr
= {0};
752 hdr
.pdu_len
= stream_getw(circuit
->rcv_stream
);
753 hdr
.rem_lifetime
= stream_getw(circuit
->rcv_stream
);
754 stream_get(hdr
.lsp_id
, circuit
->rcv_stream
, sizeof(hdr
.lsp_id
));
755 hdr
.seqno
= stream_getl(circuit
->rcv_stream
);
756 hdr
.checksum
= stream_getw(circuit
->rcv_stream
);
757 hdr
.lsp_bits
= stream_getc(circuit
->rcv_stream
);
759 if (pdu_len_validate(hdr
.pdu_len
, circuit
)) {
760 zlog_debug("ISIS-Upd (%s): LSP %s invalid LSP length %" PRIu16
,
761 circuit
->area
->area_tag
, rawlspid_print(hdr
.lsp_id
),
766 if (isis
->debugs
& DEBUG_UPDATE_PACKETS
) {
767 zlog_debug("ISIS-Upd (%s): Rcvd L%d LSP %s, seq 0x%08" PRIx32
768 ", cksum 0x%04" PRIx16
", lifetime %" PRIu16
769 "s, len %" PRIu16
", on %s",
770 circuit
->area
->area_tag
, level
,
771 rawlspid_print(hdr
.lsp_id
), hdr
.seqno
, hdr
.checksum
,
772 hdr
.rem_lifetime
, hdr
.pdu_len
,
773 circuit
->interface
->name
);
776 /* lsp is_type check */
777 if ((hdr
.lsp_bits
& IS_LEVEL_1
) != IS_LEVEL_1
) {
779 "ISIS-Upd (%s): LSP %s invalid LSP is type 0x%" PRIx8
,
780 circuit
->area
->area_tag
, rawlspid_print(hdr
.lsp_id
),
781 hdr
.lsp_bits
& IS_LEVEL_1_AND_2
);
782 /* continue as per RFC1122 Be liberal in what you accept, and
783 * conservative in what you send */
786 /* Checksum sanity check - FIXME: move to correct place */
787 /* 12 = sysid+pdu+remtime */
788 if (iso_csum_verify(STREAM_DATA(circuit
->rcv_stream
) + 12,
789 hdr
.pdu_len
- 12, hdr
.checksum
, 12)) {
791 "ISIS-Upd (%s): LSP %s invalid LSP checksum 0x%04" PRIx16
,
792 circuit
->area
->area_tag
, rawlspid_print(hdr
.lsp_id
),
797 /* 7.3.15.1 a) 1 - external domain circuit will discard lsps */
798 if (circuit
->ext_domain
) {
800 "ISIS-Upd (%s): LSP %s received at level %d over circuit with "
801 "externalDomain = true",
802 circuit
->area
->area_tag
, rawlspid_print(hdr
.lsp_id
),
807 /* 7.3.15.1 a) 2,3 - manualL2OnlyMode not implemented */
808 if (!(circuit
->is_type
& level
)) {
810 "ISIS-Upd (%s): LSP %s received at level %d over circuit of"
812 circuit
->area
->area_tag
, rawlspid_print(hdr
.lsp_id
),
813 level
, circuit_t2string(circuit
->is_type
));
817 struct isis_tlvs
*tlvs
= NULL
;
818 int retval
= ISIS_WARNING
;
819 const char *error_log
;
821 if (isis_unpack_tlvs(STREAM_READABLE(circuit
->rcv_stream
),
822 circuit
->rcv_stream
, &tlvs
, &error_log
)) {
823 zlog_warn("Something went wrong unpacking the LSP: %s",
828 /* 7.3.15.1 a) 4 - need to make sure IDLength matches */
830 /* 7.3.15.1 a) 5 - maximum area match, can be ommited since we only use
833 /* 7.3.15.1 a) 7 - password check */
834 struct isis_passwd
*passwd
= (level
== ISIS_LEVEL1
)
835 ? &circuit
->area
->area_passwd
836 : &circuit
->area
->domain_passwd
;
837 if (!isis_tlvs_auth_is_valid(tlvs
, passwd
, circuit
->rcv_stream
, true)) {
838 isis_event_auth_failure(circuit
->area
->area_tag
,
839 "LSP authentication failure",
844 /* Find the LSP in our database and compare it to this Link State header
846 struct isis_lsp
*lsp
=
847 lsp_search(hdr
.lsp_id
, circuit
->area
->lspdb
[level
- 1]);
850 comp
= lsp_compare(circuit
->area
->area_tag
, lsp
, hdr
.seqno
,
851 hdr
.checksum
, hdr
.rem_lifetime
);
852 if (lsp
&& (lsp
->own_lsp
))
855 /* 7.3.15.1 a) 6 - Must check that we have an adjacency of the same
857 /* for broadcast circuits, snpa should be compared */
859 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
) {
860 if (!isis_adj_lookup_snpa(ssnpa
,
861 circuit
->u
.bc
.adjdb
[level
- 1])) {
862 zlog_debug("(%s): DS ======= LSP %s, seq 0x%08" PRIx32
863 ", cksum 0x%04" PRIx16
", lifetime %" PRIu16
865 circuit
->area
->area_tag
,
866 rawlspid_print(hdr
.lsp_id
), hdr
.seqno
,
867 hdr
.checksum
, hdr
.rem_lifetime
,
868 circuit
->interface
->name
);
869 goto out
; /* Silently discard */
872 /* for non broadcast, we just need to find same level adj */
874 /* If no adj, or no sharing of level */
875 if (!circuit
->u
.p2p
.neighbor
) {
879 if (((level
== IS_LEVEL_1
)
880 && (circuit
->u
.p2p
.neighbor
->adj_usage
882 || ((level
== IS_LEVEL_2
)
883 && (circuit
->u
.p2p
.neighbor
->adj_usage
884 == ISIS_ADJ_LEVEL1
)))
892 /* 7.3.15.1 a) 7 - Passwords for level 1 - not implemented */
894 /* 7.3.15.1 a) 8 - Passwords for level 2 - not implemented */
896 /* 7.3.15.1 a) 9 - OriginatingLSPBufferSize - not implemented FIXME: do
899 /* 7.3.16.2 - If this is an LSP from another IS with identical seq_num
901 * wrong checksum, initiate a purge. */
902 if (lsp
&& (lsp
->hdr
.seqno
== hdr
.seqno
)
903 && (lsp
->hdr
.checksum
!= hdr
.checksum
)
904 && hdr
.rem_lifetime
) {
905 zlog_warn("ISIS-Upd (%s): LSP %s seq 0x%08" PRIx32
906 " with confused checksum received.",
907 circuit
->area
->area_tag
, rawlspid_print(hdr
.lsp_id
),
909 hdr
.rem_lifetime
= 0;
910 lsp_confusion
= true;
912 lsp_confusion
= false;
914 /* 7.3.15.1 b) - If the remaining life time is 0, we perform 7.3.16.4 */
915 if (hdr
.rem_lifetime
== 0) {
917 /* 7.3.16.4 a) 1) No LSP in db -> send an ack, but don't
919 /* only needed on explicit update, eg - p2p */
920 if (circuit
->circ_type
== CIRCUIT_T_P2P
)
921 ack_lsp(&hdr
, circuit
, level
);
922 goto out
; /* FIXME: do we need a purge? */
924 if (memcmp(hdr
.lsp_id
, isis
->sysid
, ISIS_SYS_ID_LEN
)) {
925 /* LSP by some other system -> do 7.3.16.4 b) */
927 if (comp
== LSP_NEWER
) {
928 lsp_update(lsp
, &hdr
, tlvs
,
930 circuit
->area
, level
,
935 lsp_flood(lsp
, NULL
);
937 ISIS_FLAGS_CLEAR_ALL(
938 lsp
->SSNflags
); /* FIXME:
943 /* For the case of lsp confusion, flood
944 * the purge back to its
945 * originator so that it can react.
946 * Otherwise, don't reflood
947 * through incoming circuit as usual */
948 if (!lsp_confusion
) {
954 if (circuit
->circ_type
955 != CIRCUIT_T_BROADCAST
)
960 } /* 7.3.16.4 b) 2) */
961 else if (comp
== LSP_EQUAL
) {
963 isis_tx_queue_del(circuit
->tx_queue
,
966 if (circuit
->circ_type
967 != CIRCUIT_T_BROADCAST
)
968 ISIS_SET_FLAG(lsp
->SSNflags
,
970 } /* 7.3.16.4 b) 3) */
972 isis_tx_queue_add(circuit
->tx_queue
,
974 ISIS_CLEAR_FLAG(lsp
->SSNflags
, circuit
);
976 } else if (lsp
->hdr
.rem_lifetime
!= 0) {
977 /* our own LSP -> 7.3.16.4 c) */
978 if (comp
== LSP_NEWER
) {
979 lsp_inc_seqno(lsp
, hdr
.seqno
);
981 lsp_flood(lsp
, NULL
);
983 isis_tx_queue_add(circuit
->tx_queue
,
985 ISIS_CLEAR_FLAG(lsp
->SSNflags
, circuit
);
987 if (isis
->debugs
& DEBUG_UPDATE_PACKETS
)
989 "ISIS-Upd (%s): (1) re-originating LSP %s new seq 0x%08" PRIx32
,
990 circuit
->area
->area_tag
,
991 rawlspid_print(hdr
.lsp_id
),
997 /* 7.3.15.1 c) - If this is our own lsp and we don't have it initiate a
999 if (memcmp(hdr
.lsp_id
, isis
->sysid
, ISIS_SYS_ID_LEN
) == 0) {
1001 /* 7.3.16.4: initiate a purge */
1002 lsp_purge_non_exist(level
, &hdr
, circuit
->area
);
1006 /* 7.3.15.1 d) - If this is our own lsp and we have it */
1008 /* In 7.3.16.1, If an Intermediate system R somewhere in the
1010 * has information that the current sequence number for source S
1012 * "greater" than that held by S, ... */
1014 if (comp
== LSP_NEWER
) {
1016 lsp_inc_seqno(lsp
, hdr
.seqno
);
1017 if (isis
->debugs
& DEBUG_UPDATE_PACKETS
) {
1019 "ISIS-Upd (%s): (2) re-originating LSP %s new seq 0x%08" PRIx32
,
1020 circuit
->area
->area_tag
,
1021 rawlspid_print(hdr
.lsp_id
),
1024 lsp_flood(lsp
, NULL
);
1025 } else if (comp
== LSP_EQUAL
) {
1026 isis_tx_queue_del(circuit
->tx_queue
, lsp
);
1027 if (circuit
->circ_type
!= CIRCUIT_T_BROADCAST
)
1028 ISIS_SET_FLAG(lsp
->SSNflags
, circuit
);
1030 isis_tx_queue_add(circuit
->tx_queue
, lsp
,
1032 ISIS_CLEAR_FLAG(lsp
->SSNflags
, circuit
);
1035 /* 7.3.15.1 e) - This lsp originated on another system */
1037 /* 7.3.15.1 e) 1) LSP newer than the one in db or no LSP in db
1039 if ((!lsp
|| comp
== LSP_NEWER
)) {
1041 * If this lsp is a frag, need to see if we have zero
1044 struct isis_lsp
*lsp0
= NULL
;
1045 if (LSP_FRAGMENT(hdr
.lsp_id
) != 0) {
1046 uint8_t lspid
[ISIS_SYS_ID_LEN
+ 2];
1047 memcpy(lspid
, hdr
.lsp_id
, ISIS_SYS_ID_LEN
+ 1);
1048 LSP_FRAGMENT(lspid
) = 0;
1050 lspid
, circuit
->area
->lspdb
[level
- 1]);
1053 "Got lsp frag, while zero lsp not in database");
1059 lsp
= lsp_new_from_recv(
1060 &hdr
, tlvs
, circuit
->rcv_stream
, lsp0
,
1061 circuit
->area
, level
);
1064 circuit
->area
->lspdb
[level
- 1]);
1065 } else /* exists, so we overwrite */
1067 lsp_update(lsp
, &hdr
, tlvs
, circuit
->rcv_stream
,
1068 circuit
->area
, level
, false);
1071 if (!circuit_scoped
)
1072 lsp_flood(lsp
, circuit
);
1075 if (circuit
->circ_type
!= CIRCUIT_T_BROADCAST
)
1076 ISIS_SET_FLAG(lsp
->SSNflags
, circuit
);
1079 /* 7.3.15.1 e) 2) LSP equal to the one in db */
1080 else if (comp
== LSP_EQUAL
) {
1081 isis_tx_queue_del(circuit
->tx_queue
, lsp
);
1082 lsp_update(lsp
, &hdr
, tlvs
, circuit
->rcv_stream
,
1083 circuit
->area
, level
, false);
1085 if (circuit
->circ_type
!= CIRCUIT_T_BROADCAST
)
1086 ISIS_SET_FLAG(lsp
->SSNflags
, circuit
);
1088 /* 7.3.15.1 e) 3) LSP older than the one in db */
1090 isis_tx_queue_add(circuit
->tx_queue
, lsp
,
1092 ISIS_CLEAR_FLAG(lsp
->SSNflags
, circuit
);
1099 if (circuit_scoped
) {
1100 fabricd_trigger_csnp(circuit
->area
);
1103 isis_free_tlvs(tlvs
);
1108 * Process Sequence Numbers
1110 * Section 7.3.15.2 - Action on receipt of a sequence numbers PDU
1113 static int process_snp(uint8_t pdu_type
, struct isis_circuit
*circuit
,
1114 const uint8_t *ssnpa
)
1116 bool is_csnp
= (pdu_type
== L1_COMPLETE_SEQ_NUM
1117 || pdu_type
== L2_COMPLETE_SEQ_NUM
);
1118 char typechar
= is_csnp
? 'C' : 'P';
1119 int level
= (pdu_type
== L1_COMPLETE_SEQ_NUM
1120 || pdu_type
== L1_PARTIAL_SEQ_NUM
)
1124 uint16_t pdu_len
= stream_getw(circuit
->rcv_stream
);
1125 uint8_t rem_sys_id
[ISIS_SYS_ID_LEN
];
1126 stream_get(rem_sys_id
, circuit
->rcv_stream
, ISIS_SYS_ID_LEN
);
1127 stream_forward_getp(circuit
->rcv_stream
, 1); /* Circuit ID - unused */
1129 uint8_t start_lsp_id
[ISIS_SYS_ID_LEN
+ 2] = {0};
1130 uint8_t stop_lsp_id
[ISIS_SYS_ID_LEN
+ 2] = {0};
1133 stream_get(start_lsp_id
, circuit
->rcv_stream
,
1134 ISIS_SYS_ID_LEN
+ 2);
1135 stream_get(stop_lsp_id
, circuit
->rcv_stream
,
1136 ISIS_SYS_ID_LEN
+ 2);
1139 if (pdu_len_validate(pdu_len
, circuit
)) {
1140 zlog_warn("Received a CSNP with bogus length %d", pdu_len
);
1141 return ISIS_WARNING
;
1144 if (isis
->debugs
& DEBUG_SNP_PACKETS
) {
1146 "ISIS-Snp (%s): Rcvd L%d %cSNP on %s, cirType %s, cirID %u",
1147 circuit
->area
->area_tag
, level
, typechar
,
1148 circuit
->interface
->name
,
1149 circuit_t2string(circuit
->is_type
),
1150 circuit
->circuit_id
);
1151 if (isis
->debugs
& DEBUG_PACKET_DUMP
)
1152 zlog_dump_data(STREAM_DATA(circuit
->rcv_stream
),
1153 stream_get_endp(circuit
->rcv_stream
));
1156 /* 7.3.15.2 a) 1 - external domain circuit will discard snp pdu */
1157 if (circuit
->ext_domain
) {
1160 "ISIS-Snp (%s): Rcvd L%d %cSNP on %s, "
1161 "skipping: circuit externalDomain = true",
1162 circuit
->area
->area_tag
, level
, typechar
,
1163 circuit
->interface
->name
);
1168 /* 7.3.15.2 a) 2,3 - manualL2OnlyMode not implemented */
1169 if (!(circuit
->is_type
& level
)) {
1171 "ISIS-Snp (%s): Rcvd L%d %cSNP on %s, "
1172 "skipping: circuit type %s does not match level %d",
1173 circuit
->area
->area_tag
, level
, typechar
,
1174 circuit
->interface
->name
,
1175 circuit_t2string(circuit
->is_type
), level
);
1180 /* 7.3.15.2 a) 4 - not applicable for CSNP only PSNPs on broadcast */
1181 if (!is_csnp
&& (circuit
->circ_type
== CIRCUIT_T_BROADCAST
)
1182 && !circuit
->u
.bc
.is_dr
[level
- 1]) {
1184 "ISIS-Snp (%s): Rcvd L%d %cSNP from %s on %s, "
1185 "skipping: we are not the DIS",
1186 circuit
->area
->area_tag
, level
, typechar
,
1187 snpa_print(ssnpa
), circuit
->interface
->name
);
1192 /* 7.3.15.2 a) 5 - need to make sure IDLength matches - already checked
1195 /* 7.3.15.2 a) 6 - maximum area match, can be ommited since we only use
1197 * - already checked */
1199 /* 7.3.15.2 a) 7 - Must check that we have an adjacency of the same
1201 /* for broadcast circuits, snpa should be compared */
1202 /* FIXME : Do we need to check SNPA? */
1203 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
) {
1204 if (!isis_adj_lookup(rem_sys_id
,
1205 circuit
->u
.bc
.adjdb
[level
- 1]))
1206 return ISIS_OK
; /* Silently discard */
1208 if (!fabricd
&& !circuit
->u
.p2p
.neighbor
) {
1209 zlog_warn("no p2p neighbor on circuit %s",
1210 circuit
->interface
->name
);
1211 return ISIS_OK
; /* Silently discard */
1215 struct isis_tlvs
*tlvs
;
1216 int retval
= ISIS_WARNING
;
1217 const char *error_log
;
1219 if (isis_unpack_tlvs(STREAM_READABLE(circuit
->rcv_stream
),
1220 circuit
->rcv_stream
, &tlvs
, &error_log
)) {
1221 zlog_warn("Something went wrong unpacking the SNP: %s",
1226 struct isis_passwd
*passwd
= (level
== IS_LEVEL_1
)
1227 ? &circuit
->area
->area_passwd
1228 : &circuit
->area
->domain_passwd
;
1229 if (CHECK_FLAG(passwd
->snp_auth
, SNP_AUTH_RECV
)
1230 && !isis_tlvs_auth_is_valid(tlvs
, passwd
, circuit
->rcv_stream
,
1232 isis_event_auth_failure(circuit
->area
->area_tag
,
1233 "SNP authentication failure",
1238 struct isis_lsp_entry
*entry_head
=
1239 (struct isis_lsp_entry
*)tlvs
->lsp_entries
.head
;
1241 /* debug isis snp-packets */
1242 if (isis
->debugs
& DEBUG_SNP_PACKETS
) {
1243 zlog_debug("ISIS-Snp (%s): Rcvd L%d %cSNP from %s on %s",
1244 circuit
->area
->area_tag
, level
, typechar
,
1245 snpa_print(ssnpa
), circuit
->interface
->name
);
1246 for (struct isis_lsp_entry
*entry
= entry_head
; entry
;
1247 entry
= entry
->next
) {
1249 "ISIS-Snp (%s): %cSNP entry %s, seq 0x%08" PRIx32
1250 ", cksum 0x%04" PRIx16
", lifetime %" PRIu16
"s",
1251 circuit
->area
->area_tag
, typechar
,
1252 rawlspid_print(entry
->id
), entry
->seqno
,
1253 entry
->checksum
, entry
->rem_lifetime
);
1257 bool resync_needed
= false;
1259 /* 7.3.15.2 b) Actions on LSP_ENTRIES reported */
1260 for (struct isis_lsp_entry
*entry
= entry_head
; entry
;
1261 entry
= entry
->next
) {
1262 struct isis_lsp
*lsp
=
1263 lsp_search(entry
->id
, circuit
->area
->lspdb
[level
- 1]);
1264 bool own_lsp
= !memcmp(entry
->id
, isis
->sysid
, ISIS_SYS_ID_LEN
);
1266 /* 7.3.15.2 b) 1) is this LSP newer */
1267 int cmp
= lsp_compare(circuit
->area
->area_tag
, lsp
,
1268 entry
->seqno
, entry
->checksum
,
1269 entry
->rem_lifetime
);
1270 /* 7.3.15.2 b) 2) if it equals, clear SRM on p2p */
1271 if (cmp
== LSP_EQUAL
) {
1272 /* if (circuit->circ_type !=
1273 * CIRCUIT_T_BROADCAST) */
1274 isis_tx_queue_del(circuit
->tx_queue
, lsp
);
1276 /* 7.3.15.2 b) 3) if it is older, clear SSN and set SRM
1278 else if (cmp
== LSP_OLDER
) {
1279 ISIS_CLEAR_FLAG(lsp
->SSNflags
, circuit
);
1280 isis_tx_queue_add(circuit
->tx_queue
, lsp
,
1283 /* 7.3.15.2 b) 4) if it is newer, set SSN and clear SRM
1287 lsp_inc_seqno(lsp
, entry
->seqno
);
1288 isis_tx_queue_add(circuit
->tx_queue
, lsp
,
1291 ISIS_SET_FLAG(lsp
->SSNflags
, circuit
);
1292 /* if (circuit->circ_type !=
1293 * CIRCUIT_T_BROADCAST) */
1294 isis_tx_queue_del(circuit
->tx_queue
, lsp
);
1295 resync_needed
= true;
1299 /* 7.3.15.2 b) 5) if it was not found, and all of those
1301 * insert it and set SSN on it */
1302 if (entry
->rem_lifetime
&& entry
->checksum
1303 && entry
->seqno
&& memcmp(entry
->id
, isis
->sysid
,
1305 struct isis_lsp
*lsp0
= NULL
;
1307 if (LSP_FRAGMENT(entry
->id
)) {
1308 uint8_t lspid
[ISIS_SYS_ID_LEN
+ 2];
1310 memcpy(lspid
, entry
->id
,
1311 ISIS_SYS_ID_LEN
+ 1);
1312 LSP_FRAGMENT(lspid
) = 0;
1315 circuit
->area
->lspdb
[level
- 1]);
1317 zlog_debug("Got lsp frag in snp, while zero not in database");
1321 lsp
= lsp_new(circuit
->area
, entry
->id
,
1322 entry
->rem_lifetime
, 0, 0,
1323 entry
->checksum
, lsp0
, level
);
1325 circuit
->area
->lspdb
[level
- 1]);
1327 lsp_set_all_srmflags(lsp
, false);
1328 ISIS_SET_FLAG(lsp
->SSNflags
, circuit
);
1329 resync_needed
= true;
1334 /* 7.3.15.2 c) on CSNP set SRM for all in range which were not reported
1338 * Build a list from our own LSP db bounded with
1339 * start_lsp_id and stop_lsp_id
1341 struct list
*lsp_list
= list_new();
1342 lsp_build_list_nonzero_ht(start_lsp_id
, stop_lsp_id
, lsp_list
,
1343 circuit
->area
->lspdb
[level
- 1]);
1345 /* Fixme: Find a better solution */
1346 struct listnode
*node
, *nnode
;
1347 struct isis_lsp
*lsp
;
1348 for (struct isis_lsp_entry
*entry
= entry_head
; entry
;
1349 entry
= entry
->next
) {
1350 for (ALL_LIST_ELEMENTS(lsp_list
, node
, nnode
, lsp
)) {
1351 if (lsp_id_cmp(lsp
->hdr
.lsp_id
, entry
->id
)
1353 list_delete_node(lsp_list
, node
);
1359 /* on remaining LSPs we set SRM (neighbor knew not of) */
1360 for (ALL_LIST_ELEMENTS_RO(lsp_list
, node
, lsp
)) {
1361 isis_tx_queue_add(circuit
->tx_queue
, lsp
, TX_LSP_NORMAL
);
1362 resync_needed
= true;
1366 list_delete(&lsp_list
);
1369 if (fabricd_initial_sync_is_complete(circuit
->area
) && resync_needed
)
1370 zlog_warn("OpenFabric: Needed to resync LSPDB using CSNP!\n");
1374 isis_free_tlvs(tlvs
);
1378 static int pdu_size(uint8_t pdu_type
, uint8_t *size
)
1383 *size
= ISIS_LANHELLO_HDRLEN
;
1386 *size
= ISIS_P2PHELLO_HDRLEN
;
1391 *size
= ISIS_LSP_HDR_LEN
;
1393 case L1_COMPLETE_SEQ_NUM
:
1394 case L2_COMPLETE_SEQ_NUM
:
1395 *size
= ISIS_CSNP_HDRLEN
;
1397 case L1_PARTIAL_SEQ_NUM
:
1398 case L2_PARTIAL_SEQ_NUM
:
1399 *size
= ISIS_PSNP_HDRLEN
;
1404 *size
+= ISIS_FIXED_HDR_LEN
;
1412 int isis_handle_pdu(struct isis_circuit
*circuit
, uint8_t *ssnpa
)
1414 int retval
= ISIS_OK
;
1416 /* Verify that at least the 8 bytes fixed header have been received */
1417 if (stream_get_endp(circuit
->rcv_stream
) < ISIS_FIXED_HDR_LEN
) {
1418 flog_err(EC_ISIS_PACKET
, "PDU is too short to be IS-IS.");
1422 uint8_t idrp
= stream_getc(circuit
->rcv_stream
);
1423 uint8_t length
= stream_getc(circuit
->rcv_stream
);
1424 uint8_t version1
= stream_getc(circuit
->rcv_stream
);
1425 uint8_t id_len
= stream_getc(circuit
->rcv_stream
);
1426 uint8_t pdu_type
= stream_getc(circuit
->rcv_stream
)
1427 & 0x1f; /* bits 6-8 are reserved */
1428 uint8_t version2
= stream_getc(circuit
->rcv_stream
);
1429 stream_forward_getp(circuit
->rcv_stream
, 1); /* reserved */
1430 uint8_t max_area_addrs
= stream_getc(circuit
->rcv_stream
);
1432 if (idrp
== ISO9542_ESIS
) {
1433 flog_err(EC_LIB_DEVELOPMENT
,
1434 "No support for ES-IS packet IDRP=%" PRIx8
, idrp
);
1438 if (idrp
!= ISO10589_ISIS
) {
1439 flog_err(EC_ISIS_PACKET
, "Not an IS-IS packet IDRP=%" PRIx8
,
1444 if (version1
!= 1) {
1445 zlog_warn("Unsupported ISIS version %" PRIu8
, version1
);
1446 return ISIS_WARNING
;
1449 if (id_len
!= 0 && id_len
!= ISIS_SYS_ID_LEN
) {
1452 "IDFieldLengthMismatch: ID Length field in a received PDU %" PRIu8
1453 ", while the parameter for this IS is %u",
1454 id_len
, ISIS_SYS_ID_LEN
);
1458 uint8_t expected_length
;
1459 if (pdu_size(pdu_type
, &expected_length
)) {
1460 zlog_warn("Unsupported ISIS PDU %" PRIu8
, pdu_type
);
1461 return ISIS_WARNING
;
1464 if (length
!= expected_length
) {
1465 flog_err(EC_ISIS_PACKET
,
1466 "Exepected fixed header length = %" PRIu8
1468 expected_length
, length
);
1472 if (stream_get_endp(circuit
->rcv_stream
) < length
) {
1475 "PDU is too short to contain fixed header of given PDU type.");
1479 if (version2
!= 1) {
1480 zlog_warn("Unsupported ISIS PDU version %" PRIu8
, version2
);
1481 return ISIS_WARNING
;
1484 if (circuit
->is_passive
) {
1485 zlog_warn("Received ISIS PDU on passive circuit %s",
1486 circuit
->interface
->name
);
1487 return ISIS_WARNING
;
1491 if (pdu_type
!= FS_LINK_STATE
/* FS PDU doesn't contain max area addr field */
1492 && max_area_addrs
!= 0
1493 && max_area_addrs
!= isis
->max_area_addrs
) {
1496 "maximumAreaAddressesMismatch: maximumAreaAdresses in a received PDU %" PRIu8
1497 " while the parameter for this IS is %u",
1498 max_area_addrs
, isis
->max_area_addrs
);
1506 if (fabricd
&& pdu_type
!= P2P_HELLO
)
1508 retval
= process_hello(pdu_type
, circuit
, ssnpa
);
1514 && pdu_type
!= L2_LINK_STATE
1515 && pdu_type
!= FS_LINK_STATE
)
1517 retval
= process_lsp(pdu_type
, circuit
, ssnpa
, max_area_addrs
);
1519 case L1_COMPLETE_SEQ_NUM
:
1520 case L2_COMPLETE_SEQ_NUM
:
1521 case L1_PARTIAL_SEQ_NUM
:
1522 case L2_PARTIAL_SEQ_NUM
:
1523 retval
= process_snp(pdu_type
, circuit
, ssnpa
);
1532 int isis_receive(struct thread
*thread
)
1534 struct isis_circuit
*circuit
;
1535 uint8_t ssnpa
[ETH_ALEN
];
1541 circuit
= THREAD_ARG(thread
);
1544 circuit
->t_read
= NULL
;
1546 isis_circuit_stream(circuit
, &circuit
->rcv_stream
);
1548 retval
= circuit
->rx(circuit
, ssnpa
);
1550 #if ISIS_METHOD != ISIS_METHOD_BPF
1551 if (retval
== ISIS_OK
)
1552 retval
= isis_handle_pdu(circuit
, ssnpa
);
1553 #endif //ISIS_METHOD != ISIS_METHOD_BPF
1556 * prepare for next packet.
1558 if (!circuit
->is_passive
)
1559 isis_circuit_prepare(circuit
);
1567 void fill_fixed_hdr(uint8_t pdu_type
, struct stream
*stream
)
1571 if (pdu_size(pdu_type
, &length
))
1572 assert(!"Unknown PDU Type");
1574 stream_putc(stream
, ISO10589_ISIS
); /* IDRP */
1575 stream_putc(stream
, length
); /* Length of fixed header */
1576 stream_putc(stream
, 1); /* Version/Protocol ID Extension 1 */
1577 stream_putc(stream
, 0); /* ID Length, 0 => 6 */
1578 stream_putc(stream
, pdu_type
);
1579 stream_putc(stream
, 1); /* Subversion */
1580 stream_putc(stream
, 0); /* Reserved */
1581 stream_putc(stream
, 0); /* Max Area Addresses 0 => 3 */
1584 static void put_hello_hdr(struct isis_circuit
*circuit
, int level
,
1585 size_t *len_pointer
)
1589 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
)
1590 pdu_type
= (level
== IS_LEVEL_1
) ? L1_LAN_HELLO
: L2_LAN_HELLO
;
1592 pdu_type
= P2P_HELLO
;
1594 isis_circuit_stream(circuit
, &circuit
->snd_stream
);
1595 fill_fixed_hdr(pdu_type
, circuit
->snd_stream
);
1597 stream_putc(circuit
->snd_stream
, circuit
->is_type
);
1598 stream_put(circuit
->snd_stream
, circuit
->area
->isis
->sysid
,
1601 uint32_t holdtime
= circuit
->hello_multiplier
[level
- 1]
1602 * circuit
->hello_interval
[level
- 1];
1604 if (holdtime
> 0xffff)
1607 stream_putw(circuit
->snd_stream
, holdtime
);
1608 *len_pointer
= stream_get_endp(circuit
->snd_stream
);
1609 stream_putw(circuit
->snd_stream
, 0); /* length is filled in later */
1611 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
) {
1612 uint8_t *desig_is
= (level
== IS_LEVEL_1
)
1613 ? circuit
->u
.bc
.l1_desig_is
1614 : circuit
->u
.bc
.l2_desig_is
;
1615 stream_putc(circuit
->snd_stream
, circuit
->priority
[level
- 1]);
1616 stream_put(circuit
->snd_stream
, desig_is
, ISIS_SYS_ID_LEN
+ 1);
1618 stream_putc(circuit
->snd_stream
, circuit
->circuit_id
);
1622 int send_hello(struct isis_circuit
*circuit
, int level
)
1627 if (circuit
->is_passive
)
1630 if (circuit
->interface
->mtu
== 0) {
1631 zlog_warn("circuit has zero MTU");
1632 return ISIS_WARNING
;
1635 put_hello_hdr(circuit
, level
, &len_pointer
);
1637 struct isis_tlvs
*tlvs
= isis_alloc_tlvs();
1639 isis_tlvs_add_auth(tlvs
, &circuit
->passwd
);
1641 if (!listcount(circuit
->area
->area_addrs
)) {
1642 isis_free_tlvs(tlvs
);
1643 return ISIS_WARNING
;
1646 isis_tlvs_add_area_addresses(tlvs
, circuit
->area
->area_addrs
);
1648 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
) {
1649 isis_tlvs_add_lan_neighbors(
1650 tlvs
, circuit
->u
.bc
.lan_neighs
[level
- 1]);
1651 } else if (circuit
->circ_type
== CIRCUIT_T_P2P
1652 && !circuit
->disable_threeway_adj
) {
1653 uint32_t ext_circuit_id
= circuit
->idx
;
1654 if (circuit
->u
.p2p
.neighbor
) {
1655 uint8_t threeway_state
;
1657 if (fabricd_initial_sync_is_in_progress(circuit
->area
)
1658 && fabricd_initial_sync_circuit(circuit
->area
) != circuit
)
1659 threeway_state
= ISIS_THREEWAY_DOWN
;
1661 threeway_state
= circuit
->u
.p2p
.neighbor
->threeway_state
;
1662 isis_tlvs_add_threeway_adj(tlvs
,
1665 circuit
->u
.p2p
.neighbor
->sysid
,
1666 circuit
->u
.p2p
.neighbor
->ext_circuit_id
);
1668 isis_tlvs_add_threeway_adj(tlvs
,
1675 isis_tlvs_set_protocols_supported(tlvs
, &circuit
->nlpids
);
1680 * TLV gets included if no topology is enabled on the interface,
1681 * if one topology other than #0 is enabled, or if multiple topologies
1684 struct isis_circuit_mt_setting
**mt_settings
;
1685 unsigned int mt_count
;
1687 mt_settings
= circuit_mt_settings(circuit
, &mt_count
);
1688 if (mt_count
== 0 && area_is_mt(circuit
->area
)) {
1689 tlvs
->mt_router_info_empty
= true;
1690 } else if ((mt_count
== 1
1691 && mt_settings
[0]->mtid
!= ISIS_MT_IPV4_UNICAST
)
1692 || (mt_count
> 1)) {
1693 for (unsigned int i
= 0; i
< mt_count
; i
++)
1694 isis_tlvs_add_mt_router_info(tlvs
, mt_settings
[i
]->mtid
,
1698 if (circuit
->ip_router
) {
1699 struct list
*circuit_ip_addrs
= fabricd_ip_addrs(circuit
);
1701 if (circuit_ip_addrs
)
1702 isis_tlvs_add_ipv4_addresses(tlvs
, circuit_ip_addrs
);
1705 if (circuit
->ipv6_router
&& circuit
->ipv6_link
)
1706 isis_tlvs_add_ipv6_addresses(tlvs
, circuit
->ipv6_link
);
1708 if (isis_pack_tlvs(tlvs
, circuit
->snd_stream
, len_pointer
,
1709 circuit
->pad_hellos
, false)) {
1710 isis_free_tlvs(tlvs
);
1711 return ISIS_WARNING
; /* XXX: Maybe Log TLV structure? */
1714 if (isis
->debugs
& DEBUG_ADJ_PACKETS
) {
1715 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
) {
1717 "ISIS-Adj (%s): Sending L%d LAN IIH on %s, length %zd",
1718 circuit
->area
->area_tag
, level
,
1719 circuit
->interface
->name
,
1720 stream_get_endp(circuit
->snd_stream
));
1723 "ISIS-Adj (%s): Sending P2P IIH on %s, length %zd",
1724 circuit
->area
->area_tag
,
1725 circuit
->interface
->name
,
1726 stream_get_endp(circuit
->snd_stream
));
1728 if (isis
->debugs
& DEBUG_PACKET_DUMP
)
1729 zlog_dump_data(STREAM_DATA(circuit
->snd_stream
),
1730 stream_get_endp(circuit
->snd_stream
));
1733 isis_free_tlvs(tlvs
);
1735 retval
= circuit
->tx(circuit
, level
);
1736 if (retval
!= ISIS_OK
)
1737 flog_err(EC_ISIS_PACKET
,
1738 "ISIS-Adj (%s): Send L%d IIH on %s failed",
1739 circuit
->area
->area_tag
, level
,
1740 circuit
->interface
->name
);
1745 int send_lan_l1_hello(struct thread
*thread
)
1747 struct isis_circuit
*circuit
;
1750 circuit
= THREAD_ARG(thread
);
1752 circuit
->u
.bc
.t_send_lan_hello
[0] = NULL
;
1754 if (!(circuit
->area
->is_type
& IS_LEVEL_1
)) {
1756 "ISIS-Hello (%s): Trying to send L1 IIH in L2-only area",
1757 circuit
->area
->area_tag
);
1761 if (circuit
->u
.bc
.run_dr_elect
[0])
1762 isis_dr_elect(circuit
, 1);
1764 retval
= send_hello(circuit
, 1);
1766 /* set next timer thread */
1767 thread_add_timer(master
, send_lan_l1_hello
, circuit
,
1768 isis_jitter(circuit
->hello_interval
[0], IIH_JITTER
),
1769 &circuit
->u
.bc
.t_send_lan_hello
[0]);
1774 int send_lan_l2_hello(struct thread
*thread
)
1776 struct isis_circuit
*circuit
;
1779 circuit
= THREAD_ARG(thread
);
1781 circuit
->u
.bc
.t_send_lan_hello
[1] = NULL
;
1783 if (!(circuit
->area
->is_type
& IS_LEVEL_2
)) {
1784 zlog_warn("ISIS-Hello (%s): Trying to send L2 IIH in L1 area",
1785 circuit
->area
->area_tag
);
1789 if (circuit
->u
.bc
.run_dr_elect
[1])
1790 isis_dr_elect(circuit
, 2);
1792 retval
= send_hello(circuit
, 2);
1794 /* set next timer thread */
1795 thread_add_timer(master
, send_lan_l2_hello
, circuit
,
1796 isis_jitter(circuit
->hello_interval
[1], IIH_JITTER
),
1797 &circuit
->u
.bc
.t_send_lan_hello
[1]);
1802 int send_p2p_hello(struct thread
*thread
)
1804 struct isis_circuit
*circuit
;
1806 circuit
= THREAD_ARG(thread
);
1808 circuit
->u
.p2p
.t_send_p2p_hello
= NULL
;
1810 send_hello(circuit
, 1);
1812 /* set next timer thread */
1813 thread_add_timer(master
, send_p2p_hello
, circuit
,
1814 isis_jitter(circuit
->hello_interval
[1], IIH_JITTER
),
1815 &circuit
->u
.p2p
.t_send_p2p_hello
);
1821 * Count the maximum number of lsps that can be accomodated by a given size.
1823 #define LSP_ENTRIES_LEN (10 + ISIS_SYS_ID_LEN)
1824 static uint16_t get_max_lsp_count(uint16_t size
)
1828 uint16_t remaining_size
;
1830 /* First count the full size TLVs */
1831 tlv_count
= size
/ MAX_LSP_ENTRIES_TLV_SIZE
;
1832 lsp_count
= tlv_count
* (MAX_LSP_ENTRIES_TLV_SIZE
/ LSP_ENTRIES_LEN
);
1834 /* The last TLV, if any */
1835 remaining_size
= size
% MAX_LSP_ENTRIES_TLV_SIZE
;
1836 if (remaining_size
- 2 >= LSP_ENTRIES_LEN
)
1837 lsp_count
+= (remaining_size
- 2) / LSP_ENTRIES_LEN
;
1842 int send_csnp(struct isis_circuit
*circuit
, int level
)
1844 if (circuit
->area
->lspdb
[level
- 1] == NULL
1845 || dict_count(circuit
->area
->lspdb
[level
- 1]) == 0)
1848 isis_circuit_stream(circuit
, &circuit
->snd_stream
);
1849 fill_fixed_hdr((level
== ISIS_LEVEL1
) ? L1_COMPLETE_SEQ_NUM
1850 : L2_COMPLETE_SEQ_NUM
,
1851 circuit
->snd_stream
);
1853 size_t len_pointer
= stream_get_endp(circuit
->snd_stream
);
1854 stream_putw(circuit
->snd_stream
, 0);
1855 stream_put(circuit
->snd_stream
, isis
->sysid
, ISIS_SYS_ID_LEN
);
1856 /* with zero circuit id - ref 9.10, 9.11 */
1857 stream_putc(circuit
->snd_stream
, 0);
1859 size_t start_pointer
= stream_get_endp(circuit
->snd_stream
);
1860 stream_put(circuit
->snd_stream
, 0, ISIS_SYS_ID_LEN
+ 2);
1861 size_t end_pointer
= stream_get_endp(circuit
->snd_stream
);
1862 stream_put(circuit
->snd_stream
, 0, ISIS_SYS_ID_LEN
+ 2);
1864 struct isis_passwd
*passwd
= (level
== ISIS_LEVEL1
)
1865 ? &circuit
->area
->area_passwd
1866 : &circuit
->area
->domain_passwd
;
1868 struct isis_tlvs
*tlvs
= isis_alloc_tlvs();
1870 if (CHECK_FLAG(passwd
->snp_auth
, SNP_AUTH_SEND
))
1871 isis_tlvs_add_auth(tlvs
, passwd
);
1873 size_t tlv_start
= stream_get_endp(circuit
->snd_stream
);
1874 if (isis_pack_tlvs(tlvs
, circuit
->snd_stream
, len_pointer
, false,
1876 isis_free_tlvs(tlvs
);
1877 return ISIS_WARNING
;
1879 isis_free_tlvs(tlvs
);
1882 get_max_lsp_count(STREAM_WRITEABLE(circuit
->snd_stream
));
1884 uint8_t start
[ISIS_SYS_ID_LEN
+ 2];
1885 memset(start
, 0x00, ISIS_SYS_ID_LEN
+ 2);
1886 uint8_t stop
[ISIS_SYS_ID_LEN
+ 2];
1887 memset(stop
, 0xff, ISIS_SYS_ID_LEN
+ 2);
1891 tlvs
= isis_alloc_tlvs();
1892 if (CHECK_FLAG(passwd
->snp_auth
, SNP_AUTH_SEND
))
1893 isis_tlvs_add_auth(tlvs
, passwd
);
1895 struct isis_lsp
*last_lsp
;
1896 isis_tlvs_add_csnp_entries(tlvs
, start
, stop
, num_lsps
,
1897 circuit
->area
->lspdb
[level
- 1],
1900 * Update the stop lsp_id before encoding this CSNP.
1902 if (tlvs
->lsp_entries
.count
< num_lsps
) {
1903 memset(stop
, 0xff, ISIS_SYS_ID_LEN
+ 2);
1905 memcpy(stop
, last_lsp
->hdr
.lsp_id
, sizeof(stop
));
1908 memcpy(STREAM_DATA(circuit
->snd_stream
) + start_pointer
, start
,
1909 ISIS_SYS_ID_LEN
+ 2);
1910 memcpy(STREAM_DATA(circuit
->snd_stream
) + end_pointer
, stop
,
1911 ISIS_SYS_ID_LEN
+ 2);
1912 stream_set_endp(circuit
->snd_stream
, tlv_start
);
1913 if (isis_pack_tlvs(tlvs
, circuit
->snd_stream
, len_pointer
,
1915 isis_free_tlvs(tlvs
);
1916 return ISIS_WARNING
;
1919 if (isis
->debugs
& DEBUG_SNP_PACKETS
) {
1921 "ISIS-Snp (%s): Sending L%d CSNP on %s, length %zd",
1922 circuit
->area
->area_tag
, level
,
1923 circuit
->interface
->name
,
1924 stream_get_endp(circuit
->snd_stream
));
1925 log_multiline(LOG_DEBUG
, " ", "%s",
1926 isis_format_tlvs(tlvs
));
1927 if (isis
->debugs
& DEBUG_PACKET_DUMP
)
1929 STREAM_DATA(circuit
->snd_stream
),
1930 stream_get_endp(circuit
->snd_stream
));
1933 int retval
= circuit
->tx(circuit
, level
);
1934 if (retval
!= ISIS_OK
) {
1935 flog_err(EC_ISIS_PACKET
,
1936 "ISIS-Snp (%s): Send L%d CSNP on %s failed",
1937 circuit
->area
->area_tag
, level
,
1938 circuit
->interface
->name
);
1939 isis_free_tlvs(tlvs
);
1944 * Start lsp_id of the next CSNP should be one plus the
1945 * stop lsp_id in this current CSNP.
1947 memcpy(start
, stop
, ISIS_SYS_ID_LEN
+ 2);
1949 for (int i
= ISIS_SYS_ID_LEN
+ 1; i
>= 0; --i
) {
1950 if (start
[i
] < (uint8_t)0xff) {
1956 memset(stop
, 0xff, ISIS_SYS_ID_LEN
+ 2);
1957 isis_free_tlvs(tlvs
);
1963 int send_l1_csnp(struct thread
*thread
)
1965 struct isis_circuit
*circuit
;
1966 int retval
= ISIS_OK
;
1968 circuit
= THREAD_ARG(thread
);
1971 circuit
->t_send_csnp
[0] = NULL
;
1973 if ((circuit
->circ_type
== CIRCUIT_T_BROADCAST
1974 && circuit
->u
.bc
.is_dr
[0])
1975 || circuit
->circ_type
== CIRCUIT_T_P2P
) {
1976 send_csnp(circuit
, 1);
1978 /* set next timer thread */
1979 thread_add_timer(master
, send_l1_csnp
, circuit
,
1980 isis_jitter(circuit
->csnp_interval
[0], CSNP_JITTER
),
1981 &circuit
->t_send_csnp
[0]);
1986 int send_l2_csnp(struct thread
*thread
)
1988 struct isis_circuit
*circuit
;
1989 int retval
= ISIS_OK
;
1991 circuit
= THREAD_ARG(thread
);
1994 circuit
->t_send_csnp
[1] = NULL
;
1996 if ((circuit
->circ_type
== CIRCUIT_T_BROADCAST
1997 && circuit
->u
.bc
.is_dr
[1])
1998 || circuit
->circ_type
== CIRCUIT_T_P2P
) {
1999 send_csnp(circuit
, 2);
2001 /* set next timer thread */
2002 thread_add_timer(master
, send_l2_csnp
, circuit
,
2003 isis_jitter(circuit
->csnp_interval
[1], CSNP_JITTER
),
2004 &circuit
->t_send_csnp
[1]);
2010 * 7.3.15.4 action on expiration of partial SNP interval
2013 static int send_psnp(int level
, struct isis_circuit
*circuit
)
2015 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
2016 && circuit
->u
.bc
.is_dr
[level
- 1])
2019 if (circuit
->area
->lspdb
[level
- 1] == NULL
2020 || dict_count(circuit
->area
->lspdb
[level
- 1]) == 0)
2023 if (!circuit
->snd_stream
)
2026 isis_circuit_stream(circuit
, &circuit
->snd_stream
);
2027 fill_fixed_hdr((level
== ISIS_LEVEL1
) ? L1_PARTIAL_SEQ_NUM
2028 : L2_PARTIAL_SEQ_NUM
,
2029 circuit
->snd_stream
);
2031 size_t len_pointer
= stream_get_endp(circuit
->snd_stream
);
2032 stream_putw(circuit
->snd_stream
, 0); /* length is filled in later */
2033 stream_put(circuit
->snd_stream
, isis
->sysid
, ISIS_SYS_ID_LEN
);
2034 stream_putc(circuit
->snd_stream
, circuit
->idx
);
2036 struct isis_passwd
*passwd
= (level
== ISIS_LEVEL1
)
2037 ? &circuit
->area
->area_passwd
2038 : &circuit
->area
->domain_passwd
;
2040 struct isis_tlvs
*tlvs
= isis_alloc_tlvs();
2042 if (CHECK_FLAG(passwd
->snp_auth
, SNP_AUTH_SEND
))
2043 isis_tlvs_add_auth(tlvs
, passwd
);
2045 size_t tlv_start
= stream_get_endp(circuit
->snd_stream
);
2046 if (isis_pack_tlvs(tlvs
, circuit
->snd_stream
, len_pointer
, false,
2048 isis_free_tlvs(tlvs
);
2049 return ISIS_WARNING
;
2051 isis_free_tlvs(tlvs
);
2054 get_max_lsp_count(STREAM_WRITEABLE(circuit
->snd_stream
));
2057 tlvs
= isis_alloc_tlvs();
2058 if (CHECK_FLAG(passwd
->snp_auth
, SNP_AUTH_SEND
))
2059 isis_tlvs_add_auth(tlvs
, passwd
);
2061 for (dnode_t
*dnode
=
2062 dict_first(circuit
->area
->lspdb
[level
- 1]);
2063 dnode
; dnode
= dict_next(circuit
->area
->lspdb
[level
- 1],
2065 struct isis_lsp
*lsp
= dnode_get(dnode
);
2067 if (ISIS_CHECK_FLAG(lsp
->SSNflags
, circuit
))
2068 isis_tlvs_add_lsp_entry(tlvs
, lsp
);
2070 if (tlvs
->lsp_entries
.count
== num_lsps
)
2074 if (!tlvs
->lsp_entries
.count
) {
2075 isis_free_tlvs(tlvs
);
2079 stream_set_endp(circuit
->snd_stream
, tlv_start
);
2080 if (isis_pack_tlvs(tlvs
, circuit
->snd_stream
, len_pointer
,
2082 isis_free_tlvs(tlvs
);
2083 return ISIS_WARNING
;
2086 if (isis
->debugs
& DEBUG_SNP_PACKETS
) {
2088 "ISIS-Snp (%s): Sending L%d PSNP on %s, length %zd",
2089 circuit
->area
->area_tag
, level
,
2090 circuit
->interface
->name
,
2091 stream_get_endp(circuit
->snd_stream
));
2092 log_multiline(LOG_DEBUG
, " ", "%s",
2093 isis_format_tlvs(tlvs
));
2094 if (isis
->debugs
& DEBUG_PACKET_DUMP
)
2096 STREAM_DATA(circuit
->snd_stream
),
2097 stream_get_endp(circuit
->snd_stream
));
2100 int retval
= circuit
->tx(circuit
, level
);
2101 if (retval
!= ISIS_OK
) {
2102 flog_err(EC_ISIS_PACKET
,
2103 "ISIS-Snp (%s): Send L%d PSNP on %s failed",
2104 circuit
->area
->area_tag
, level
,
2105 circuit
->interface
->name
);
2106 isis_free_tlvs(tlvs
);
2111 * sending succeeded, we can clear SSN flags of this circuit
2112 * for the LSPs in list
2114 struct isis_lsp_entry
*entry_head
;
2115 entry_head
= (struct isis_lsp_entry
*)tlvs
->lsp_entries
.head
;
2116 for (struct isis_lsp_entry
*entry
= entry_head
; entry
;
2117 entry
= entry
->next
)
2118 ISIS_CLEAR_FLAG(entry
->lsp
->SSNflags
, circuit
);
2119 isis_free_tlvs(tlvs
);
2125 int send_l1_psnp(struct thread
*thread
)
2128 struct isis_circuit
*circuit
;
2129 int retval
= ISIS_OK
;
2131 circuit
= THREAD_ARG(thread
);
2134 circuit
->t_send_psnp
[0] = NULL
;
2136 send_psnp(1, circuit
);
2137 /* set next timer thread */
2138 thread_add_timer(master
, send_l1_psnp
, circuit
,
2139 isis_jitter(circuit
->psnp_interval
[0], PSNP_JITTER
),
2140 &circuit
->t_send_psnp
[0]);
2146 * 7.3.15.4 action on expiration of partial SNP interval
2149 int send_l2_psnp(struct thread
*thread
)
2151 struct isis_circuit
*circuit
;
2152 int retval
= ISIS_OK
;
2154 circuit
= THREAD_ARG(thread
);
2157 circuit
->t_send_psnp
[1] = NULL
;
2159 send_psnp(2, circuit
);
2161 /* set next timer thread */
2162 thread_add_timer(master
, send_l2_psnp
, circuit
,
2163 isis_jitter(circuit
->psnp_interval
[1], PSNP_JITTER
),
2164 &circuit
->t_send_psnp
[1]);
2170 * ISO 10589 - 7.3.14.3
2172 void send_lsp(void *arg
, struct isis_lsp
*lsp
, enum isis_tx_type tx_type
)
2174 struct isis_circuit
*circuit
= arg
;
2176 int retval
= ISIS_OK
;
2178 if (circuit
->state
!= C_STATE_UP
|| circuit
->is_passive
== 1)
2182 * Do not send if levels do not match
2184 if (!(lsp
->level
& circuit
->is_type
))
2188 * Do not send if we do not have adjacencies in state up on the circuit
2190 if (circuit
->upadjcount
[lsp
->level
- 1] == 0)
2193 /* stream_copy will assert and stop program execution if LSP is larger
2195 * the circuit's MTU. So handle and log this case here. */
2196 if (stream_get_endp(lsp
->pdu
) > stream_get_size(circuit
->snd_stream
)) {
2199 "ISIS-Upd (%s): Can't send L%d LSP %s, seq 0x%08" PRIx32
2200 ", cksum 0x%04" PRIx16
", lifetime %" PRIu16
2201 "s on %s. LSP Size is %zu while interface stream size is %zu.",
2202 circuit
->area
->area_tag
, lsp
->level
,
2203 rawlspid_print(lsp
->hdr
.lsp_id
), lsp
->hdr
.seqno
,
2204 lsp
->hdr
.checksum
, lsp
->hdr
.rem_lifetime
,
2205 circuit
->interface
->name
, stream_get_endp(lsp
->pdu
),
2206 stream_get_size(circuit
->snd_stream
));
2207 if (isis
->debugs
& DEBUG_PACKET_DUMP
)
2208 zlog_dump_data(STREAM_DATA(lsp
->pdu
),
2209 stream_get_endp(lsp
->pdu
));
2210 retval
= ISIS_ERROR
;
2214 /* copy our lsp to the send buffer */
2215 stream_copy(circuit
->snd_stream
, lsp
->pdu
);
2217 if (tx_type
== TX_LSP_CIRCUIT_SCOPED
) {
2218 stream_putc_at(circuit
->snd_stream
, 4, FS_LINK_STATE
);
2219 stream_putc_at(circuit
->snd_stream
, 7, L2_CIRCUIT_FLOODING_SCOPE
);
2222 if (isis
->debugs
& DEBUG_UPDATE_PACKETS
) {
2223 zlog_debug("ISIS-Upd (%s): Sending L%d LSP %s, seq 0x%08" PRIx32
2224 ", cksum 0x%04" PRIx16
", lifetime %" PRIu16
2226 circuit
->area
->area_tag
, lsp
->level
,
2227 rawlspid_print(lsp
->hdr
.lsp_id
), lsp
->hdr
.seqno
,
2228 lsp
->hdr
.checksum
, lsp
->hdr
.rem_lifetime
,
2229 circuit
->interface
->name
);
2230 if (isis
->debugs
& DEBUG_PACKET_DUMP
)
2231 zlog_dump_data(STREAM_DATA(circuit
->snd_stream
),
2232 stream_get_endp(circuit
->snd_stream
));
2236 retval
= circuit
->tx(circuit
, lsp
->level
);
2237 if (retval
!= ISIS_OK
) {
2238 flog_err(EC_ISIS_PACKET
,
2239 "ISIS-Upd (%s): Send L%d LSP on %s failed %s",
2240 circuit
->area
->area_tag
, lsp
->level
,
2241 circuit
->interface
->name
,
2242 (retval
== ISIS_WARNING
) ? "temporarily"
2248 || (retval
== ISIS_OK
&& circuit
->circ_type
== CIRCUIT_T_BROADCAST
)
2249 || (retval
!= ISIS_OK
&& retval
!= ISIS_WARNING
)) {
2250 /* SRM flag will trigger retransmission. We will not retransmit
2252 * encountered a fatal error.
2253 * On success, they should only be cleared if it's a broadcast
2255 * On a P2P circuit, we will wait for the ack from the neighbor
2259 isis_tx_queue_del(circuit
->tx_queue
, lsp
);