2 * IS-IS Rout(e)ing protocol - isis_pdu.c
5 * Copyright (C) 2001,2002 Sampo Saaristo
6 * Tampere University of Technology
7 * Institute of Communications Engineering
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public Licenseas published by the Free
11 * Software Foundation; either version 2 of the License, or (at your option)
14 * This program is distributed in the hope that it will be useful,but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
19 * You should have received a copy of the GNU General Public License along
20 * with this program; see the file COPYING; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
37 #include "lib_errors.h"
39 #include "isisd/isis_constants.h"
40 #include "isisd/isis_common.h"
41 #include "isisd/isis_flags.h"
42 #include "isisd/isis_adjacency.h"
43 #include "isisd/isis_circuit.h"
44 #include "isisd/isis_network.h"
45 #include "isisd/isis_misc.h"
46 #include "isisd/isis_dr.h"
47 #include "isisd/isisd.h"
48 #include "isisd/isis_dynhn.h"
49 #include "isisd/isis_lsp.h"
50 #include "isisd/isis_pdu.h"
51 #include "isisd/iso_checksum.h"
52 #include "isisd/isis_csm.h"
53 #include "isisd/isis_events.h"
54 #include "isisd/isis_te.h"
55 #include "isisd/isis_mt.h"
56 #include "isisd/isis_tlvs.h"
57 #include "isisd/isis_errors.h"
58 #include "isisd/fabricd.h"
59 #include "isisd/isis_tx_queue.h"
60 #include "isisd/isis_pdu_counter.h"
61 #include "isisd/isis_nb.h"
63 static int ack_lsp(struct isis_lsp_hdr
*hdr
, struct isis_circuit
*circuit
,
70 (level
== IS_LEVEL_1
) ? L1_PARTIAL_SEQ_NUM
: L2_PARTIAL_SEQ_NUM
;
72 isis_circuit_stream(circuit
, &circuit
->snd_stream
);
74 fill_fixed_hdr(pdu_type
, circuit
->snd_stream
);
76 lenp
= stream_get_endp(circuit
->snd_stream
);
78 stream_putw(circuit
->snd_stream
, 0); /* PDU length */
79 stream_put(circuit
->snd_stream
, circuit
->area
->isis
->sysid
,
81 stream_putc(circuit
->snd_stream
, circuit
->idx
);
82 stream_putc(circuit
->snd_stream
, 9); /* code */
83 stream_putc(circuit
->snd_stream
, 16); /* len */
85 stream_putw(circuit
->snd_stream
, hdr
->rem_lifetime
);
86 stream_put(circuit
->snd_stream
, hdr
->lsp_id
, ISIS_SYS_ID_LEN
+ 2);
87 stream_putl(circuit
->snd_stream
, hdr
->seqno
);
88 stream_putw(circuit
->snd_stream
, hdr
->checksum
);
90 length
= (uint16_t)stream_get_endp(circuit
->snd_stream
);
91 /* Update PDU length */
92 stream_putw_at(circuit
->snd_stream
, lenp
, length
);
94 pdu_counter_count(circuit
->area
->pdu_tx_counters
, pdu_type
);
95 retval
= circuit
->tx(circuit
, level
);
96 if (retval
!= ISIS_OK
)
97 flog_err(EC_ISIS_PACKET
,
98 "ISIS-Upd (%s): Send L%d LSP PSNP on %s failed",
99 circuit
->area
->area_tag
, level
,
100 circuit
->interface
->name
);
110 struct isis_circuit
*circuit
;
115 uint8_t sys_id
[ISIS_SYS_ID_LEN
];
122 uint8_t dis
[ISIS_SYS_ID_LEN
+ 1];
127 struct isis_tlvs
*tlvs
;
130 static int process_p2p_hello(struct iih_info
*iih
)
132 struct isis_threeway_adj
*tw_adj
= iih
->tlvs
->threeway_adj
;
135 if (tw_adj
->state
> ISIS_THREEWAY_DOWN
) {
136 if (IS_DEBUG_ADJ_PACKETS
) {
137 zlog_debug("ISIS-Adj (%s): Rcvd P2P IIH from (%s) with invalid three-way state: %d",
138 iih
->circuit
->area
->area_tag
,
139 iih
->circuit
->interface
->name
,
145 if (tw_adj
->neighbor_set
146 && (memcmp(tw_adj
->neighbor_id
,
147 iih
->circuit
->area
->isis
->sysid
, ISIS_SYS_ID_LEN
)
148 || tw_adj
->neighbor_circuit_id
149 != (uint32_t)iih
->circuit
->idx
)) {
151 if (IS_DEBUG_ADJ_PACKETS
) {
152 zlog_debug("ISIS-Adj (%s): Rcvd P2P IIH from (%s) which lists IS/Circuit different from us as neighbor.",
153 iih
->circuit
->area
->area_tag
,
154 iih
->circuit
->interface
->name
);
162 * My interpertation of the ISO, if no adj exists we will create one for
165 struct isis_adjacency
*adj
= iih
->circuit
->u
.p2p
.neighbor
;
166 /* If an adjacency exists, check it is with the source of the hello
169 if (memcmp(iih
->sys_id
, adj
->sysid
, ISIS_SYS_ID_LEN
)) {
171 "hello source and adjacency do not match, set adj down\n");
172 isis_adj_state_change(&adj
, ISIS_ADJ_DOWN
,
177 if (!adj
|| adj
->level
!= iih
->circ_type
) {
179 adj
= isis_new_adj(iih
->sys_id
, NULL
, iih
->circ_type
,
182 adj
->level
= iih
->circ_type
;
184 iih
->circuit
->u
.p2p
.neighbor
= adj
;
185 /* Build lsp with the new neighbor entry when a new
186 * adjacency is formed. Set adjacency circuit type to
187 * IIH PDU header circuit type before lsp is regenerated
188 * when an adjacency is up. This will result in the new
189 * adjacency entry getting added to the lsp tlv neighbor list.
191 adj
->circuit_t
= iih
->circ_type
;
192 isis_adj_state_change(&adj
, ISIS_ADJ_INITIALIZING
, NULL
);
193 adj
->sys_type
= ISIS_SYSTYPE_UNKNOWN
;
197 adj
->ext_circuit_id
= tw_adj
->local_circuit_id
;
199 /* 8.2.6 Monitoring point-to-point adjacencies */
200 adj
->hold_time
= iih
->holdtime
;
201 adj
->last_upd
= time(NULL
);
204 isis_tlvs_to_adj(iih
->tlvs
, adj
, &changed
);
205 changed
|= tlvs_to_adj_mt_set(iih
->tlvs
, iih
->v4_usable
, iih
->v6_usable
,
208 /* lets take care of the expiry */
209 THREAD_TIMER_OFF(adj
->t_expire
);
210 thread_add_timer(master
, isis_adj_expire
, adj
, (long)adj
->hold_time
,
213 /* While fabricds initial sync is in progress, ignore hellos from other
214 * interfaces than the one we are performing the initial sync on. */
215 if (fabricd_initial_sync_is_in_progress(iih
->circuit
->area
)
216 && fabricd_initial_sync_circuit(iih
->circuit
->area
) != iih
->circuit
)
219 /* 8.2.5.2 a) a match was detected */
220 if (isis_tlvs_area_addresses_match(iih
->tlvs
,
221 iih
->circuit
->area
->area_addrs
)) {
222 /* 8.2.5.2 a) 2) If the system is L1 - table 5 */
223 if (iih
->circuit
->area
->is_type
== IS_LEVEL_1
) {
224 switch (iih
->circ_type
) {
226 case IS_LEVEL_1_AND_2
:
227 if (adj
->adj_state
!= ISIS_ADJ_UP
228 || adj
->adj_usage
== ISIS_ADJ_LEVEL1
) {
229 isis_adj_process_threeway(adj
, tw_adj
,
234 if (adj
->adj_state
!= ISIS_ADJ_UP
) {
235 /* (7) reject - wrong system type event
237 zlog_warn("wrongSystemType");
239 } else if (adj
->adj_usage
== ISIS_ADJ_LEVEL1
) {
240 /* (6) down - wrong system */
241 isis_adj_state_change(&adj
,
249 /* 8.2.5.2 a) 3) If the system is L1L2 - table 6 */
250 if (iih
->circuit
->area
->is_type
== IS_LEVEL_1_AND_2
) {
251 switch (iih
->circ_type
) {
253 if (adj
->adj_state
!= ISIS_ADJ_UP
254 || adj
->adj_usage
== ISIS_ADJ_LEVEL1
) {
255 isis_adj_process_threeway(adj
, tw_adj
,
257 } else if ((adj
->adj_usage
258 == ISIS_ADJ_LEVEL1AND2
)
260 == ISIS_ADJ_LEVEL2
)) {
261 /* (8) down - wrong system */
262 isis_adj_state_change(&adj
,
268 if (adj
->adj_state
!= ISIS_ADJ_UP
269 || adj
->adj_usage
== ISIS_ADJ_LEVEL2
) {
270 isis_adj_process_threeway(adj
, tw_adj
,
272 } else if ((adj
->adj_usage
== ISIS_ADJ_LEVEL1
)
274 == ISIS_ADJ_LEVEL1AND2
)) {
275 /* (8) down - wrong system */
276 isis_adj_state_change(&adj
,
281 case IS_LEVEL_1_AND_2
:
282 if (adj
->adj_state
!= ISIS_ADJ_UP
283 || adj
->adj_usage
== ISIS_ADJ_LEVEL1AND2
) {
284 isis_adj_process_threeway(adj
, tw_adj
,
285 ISIS_ADJ_LEVEL1AND2
);
286 } else if ((adj
->adj_usage
== ISIS_ADJ_LEVEL1
)
288 == ISIS_ADJ_LEVEL2
)) {
289 /* (8) down - wrong system */
290 isis_adj_state_change(&adj
,
298 /* 8.2.5.2 a) 4) If the system is L2 - table 7 */
299 if (iih
->circuit
->area
->is_type
== IS_LEVEL_2
) {
300 switch (iih
->circ_type
) {
302 if (adj
->adj_state
!= ISIS_ADJ_UP
) {
303 /* (5) reject - wrong system type event
305 zlog_warn("wrongSystemType");
307 } else if ((adj
->adj_usage
308 == ISIS_ADJ_LEVEL1AND2
)
310 == ISIS_ADJ_LEVEL2
)) {
311 /* (6) down - wrong system */
312 isis_adj_state_change(&adj
,
317 case IS_LEVEL_1_AND_2
:
319 if (adj
->adj_state
!= ISIS_ADJ_UP
320 || adj
->adj_usage
== ISIS_ADJ_LEVEL2
) {
321 isis_adj_process_threeway(adj
, tw_adj
,
323 } else if (adj
->adj_usage
324 == ISIS_ADJ_LEVEL1AND2
) {
325 /* (6) down - wrong system */
326 isis_adj_state_change(&adj
,
334 /* 8.2.5.2 b) if no match was detected */
335 else if (listcount(iih
->circuit
->area
->area_addrs
) > 0) {
336 if (iih
->circuit
->area
->is_type
== IS_LEVEL_1
) {
337 /* 8.2.5.2 b) 1) is_type L1 and adj is not up */
338 if (adj
->adj_state
!= ISIS_ADJ_UP
) {
339 isis_adj_state_change(&adj
, ISIS_ADJ_DOWN
,
341 /* 8.2.5.2 b) 2)is_type L1 and adj is up */
343 isis_adj_state_change(&adj
, ISIS_ADJ_DOWN
,
344 "Down - Area Mismatch");
347 /* 8.2.5.2 b 3 If the system is L2 or L1L2 - table 8 */
349 switch (iih
->circ_type
) {
351 if (adj
->adj_state
!= ISIS_ADJ_UP
) {
352 /* (6) reject - Area Mismatch event */
353 zlog_warn("AreaMismatch");
355 } else if (adj
->adj_usage
== ISIS_ADJ_LEVEL1
) {
356 /* (7) down - area mismatch */
357 isis_adj_state_change(&adj
,
361 } else if ((adj
->adj_usage
362 == ISIS_ADJ_LEVEL1AND2
)
364 == ISIS_ADJ_LEVEL2
)) {
365 /* (7) down - wrong system */
366 isis_adj_state_change(&adj
,
371 case IS_LEVEL_1_AND_2
:
373 if (adj
->adj_state
!= ISIS_ADJ_UP
374 || adj
->adj_usage
== ISIS_ADJ_LEVEL2
) {
375 isis_adj_process_threeway(adj
, tw_adj
,
377 } else if (adj
->adj_usage
== ISIS_ADJ_LEVEL1
) {
378 /* (7) down - wrong system */
379 isis_adj_state_change(&adj
,
382 } else if (adj
->adj_usage
383 == ISIS_ADJ_LEVEL1AND2
) {
384 if (iih
->circ_type
== IS_LEVEL_2
) {
385 /* (7) down - wrong system */
386 isis_adj_state_change(
390 /* (7) down - area mismatch */
391 isis_adj_state_change(
400 /* down - area mismatch */
401 isis_adj_state_change(&adj
, ISIS_ADJ_DOWN
, "Area Mismatch");
405 if (adj
->adj_state
== ISIS_ADJ_UP
&& changed
) {
406 lsp_regenerate_schedule(
408 isis_adj_usage2levels(adj
->adj_usage
), 0);
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
;
433 if (IS_DEBUG_ADJ_PACKETS
) {
435 "ISIS-Adj (%s): Rcvd P2P IIH from (%s), cir type %s, cir id %hhu, length %hu",
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 (IS_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 /* keep a copy of the raw pdu for NB notifications */
557 size_t pdu_start
= stream_get_getp(circuit
->rcv_stream
);
558 size_t pdu_end
= stream_get_endp(circuit
->rcv_stream
);
559 char raw_pdu
[pdu_end
- pdu_start
];
560 bool p2p_hello
= (pdu_type
== P2P_HELLO
);
561 int level
= p2p_hello
? 0
562 : (pdu_type
== L1_LAN_HELLO
) ? ISIS_LEVEL1
564 const char *pdu_name
=
567 : (level
== ISIS_LEVEL1
) ? "L1 LAN IIH" : "L2 LAN IIH";
569 stream_get_from(raw_pdu
, circuit
->rcv_stream
, pdu_start
,
570 pdu_end
- pdu_start
);
571 if (IS_DEBUG_ADJ_PACKETS
) {
572 zlog_debug("ISIS-Adj (%s): Rcvd %s on %s, cirType %s, cirID %u",
573 circuit
->area
->area_tag
, pdu_name
,
574 circuit
->interface
->name
,
575 circuit_t2string(circuit
->is_type
),
576 circuit
->circuit_id
);
577 if (IS_DEBUG_PACKET_DUMP
)
578 zlog_dump_data(STREAM_DATA(circuit
->rcv_stream
),
579 stream_get_endp(circuit
->rcv_stream
));
583 if (circuit
->circ_type
!= CIRCUIT_T_P2P
) {
584 zlog_warn("p2p hello on non p2p circuit");
585 circuit
->rej_adjacencies
++;
587 isis_notif_reject_adjacency(
588 circuit
, "p2p hello on non p2p circuit",
590 #endif /* ifndef FABRICD */
594 if (circuit
->circ_type
!= CIRCUIT_T_BROADCAST
) {
595 zlog_warn("lan hello on non broadcast circuit");
596 circuit
->rej_adjacencies
++;
598 isis_notif_reject_adjacency(
599 circuit
, "lan hello on non broadcast circuit",
601 #endif /* ifndef FABRICD */
605 if (circuit
->ext_domain
) {
607 "level %d LAN Hello received over circuit with externalDomain = true",
609 circuit
->rej_adjacencies
++;
611 isis_notif_reject_adjacency(
613 "LAN Hello received over circuit with externalDomain = true",
615 #endif /* ifndef FABRICD */
619 if (!(circuit
->is_type
& level
)) {
620 if (IS_DEBUG_ADJ_PACKETS
) {
622 "ISIS-Adj (%s): Interface level mismatch, %s",
623 circuit
->area
->area_tag
,
624 circuit
->interface
->name
);
626 circuit
->rej_adjacencies
++;
628 isis_notif_reject_adjacency(
629 circuit
, "Interface level mismatch", raw_pdu
);
630 #endif /* ifndef FABRICD */
635 struct iih_info iih
= {
636 .circuit
= circuit
, .ssnpa
= ssnpa
, .level
= level
};
638 /* Generic IIH Header */
639 iih
.circ_type
= stream_getc(circuit
->rcv_stream
) & 0x03;
640 stream_get(iih
.sys_id
, circuit
->rcv_stream
, ISIS_SYS_ID_LEN
);
641 iih
.holdtime
= stream_getw(circuit
->rcv_stream
);
642 iih
.pdu_len
= stream_getw(circuit
->rcv_stream
);
645 iih
.circuit_id
= stream_getc(circuit
->rcv_stream
);
647 iih
.priority
= stream_getc(circuit
->rcv_stream
);
648 stream_get(iih
.dis
, circuit
->rcv_stream
, ISIS_SYS_ID_LEN
+ 1);
651 if (pdu_len_validate(iih
.pdu_len
, circuit
)) {
653 "ISIS-Adj (%s): Rcvd %s from (%s) with invalid pdu length %hu",
654 circuit
->area
->area_tag
, pdu_name
,
655 circuit
->interface
->name
, iih
.pdu_len
);
656 circuit
->rej_adjacencies
++;
658 isis_notif_reject_adjacency(circuit
, "Invalid PDU length",
660 #endif /* ifndef FABRICD */
664 if (!p2p_hello
&& !(level
& iih
.circ_type
)) {
665 flog_err(EC_ISIS_PACKET
,
666 "Level %d LAN Hello with Circuit Type %d", level
,
668 circuit
->rej_adjacencies
++;
670 isis_notif_reject_adjacency(
671 circuit
, "LAN Hello with wrong IS-level", raw_pdu
);
672 #endif /* ifndef FABRICD */
676 const char *error_log
;
677 int retval
= ISIS_WARNING
;
679 if (isis_unpack_tlvs(STREAM_READABLE(circuit
->rcv_stream
),
680 circuit
->rcv_stream
, &iih
.tlvs
, &error_log
)) {
681 zlog_warn("isis_unpack_tlvs() failed: %s", error_log
);
682 circuit
->rej_adjacencies
++;
684 isis_notif_reject_adjacency(circuit
, "Failed to unpack TLVs",
686 #endif /* ifndef FABRICD */
690 if (!iih
.tlvs
->area_addresses
.count
) {
691 zlog_warn("No Area addresses TLV in %s", pdu_name
);
693 /* send northbound notification */
694 isis_notif_area_mismatch(circuit
, raw_pdu
);
695 #endif /* ifndef FABRICD */
699 if (!iih
.tlvs
->protocols_supported
.count
) {
700 zlog_warn("No supported protocols TLV in %s", pdu_name
);
701 circuit
->rej_adjacencies
++;
703 isis_notif_reject_adjacency(
704 circuit
, "No supported protocols TLV", raw_pdu
);
705 #endif /* ifndef FABRICD */
709 int auth_code
= isis_tlvs_auth_is_valid(iih
.tlvs
, &circuit
->passwd
,
710 circuit
->rcv_stream
, false);
711 if (auth_code
!= ISIS_AUTH_OK
) {
712 isis_event_auth_failure(circuit
->area
->area_tag
,
713 "IIH authentication failure",
716 /* send northbound notification */
717 stream_get_from(raw_pdu
, circuit
->rcv_stream
, pdu_start
,
718 pdu_end
- pdu_start
);
719 if (auth_code
== ISIS_AUTH_FAILURE
) {
720 circuit
->auth_failures
++;
721 isis_notif_authentication_failure(circuit
, raw_pdu
);
722 } else { /* AUTH_TYPE_FAILURE or NO_VALIDATOR */
723 circuit
->auth_type_failures
++;
724 isis_notif_authentication_type_failure(circuit
,
727 #endif /* ifndef FABRICD */
731 if (!memcmp(iih
.sys_id
, circuit
->area
->isis
->sysid
, ISIS_SYS_ID_LEN
)) {
733 "ISIS-Adj (%s): Received IIH with own sysid - discard",
734 circuit
->area
->area_tag
);
735 circuit
->rej_adjacencies
++;
737 isis_notif_reject_adjacency(
738 circuit
, "Received IIH with our own sysid", raw_pdu
);
739 #endif /* ifndef FABRICD */
744 && (listcount(circuit
->area
->area_addrs
) == 0
745 || (level
== ISIS_LEVEL1
746 && !isis_tlvs_area_addresses_match(
747 iih
.tlvs
, circuit
->area
->area_addrs
)))) {
748 if (IS_DEBUG_ADJ_PACKETS
) {
750 "ISIS-Adj (%s): Area mismatch, level %d IIH on %s",
751 circuit
->area
->area_tag
, level
,
752 circuit
->interface
->name
);
755 /* send northbound notification */
756 isis_notif_area_mismatch(circuit
, raw_pdu
);
757 #endif /* ifndef FABRICD */
761 iih
.v4_usable
= (fabricd_ip_addrs(circuit
)
762 && iih
.tlvs
->ipv4_address
.count
);
764 iih
.v6_usable
= (circuit
->ipv6_link
&& listcount(circuit
->ipv6_link
)
765 && iih
.tlvs
->ipv6_address
.count
);
767 if (!iih
.v4_usable
&& !iih
.v6_usable
) {
768 if (IS_DEBUG_ADJ_PACKETS
) {
770 "ISIS-Adj (%s): Neither IPv4 nor IPv6 considered usable. Ignoring IIH",
771 circuit
->area
->area_tag
);
773 circuit
->rej_adjacencies
++;
775 isis_notif_reject_adjacency(
776 circuit
, "Neither IPv4 not IPv6 considered usable",
778 #endif /* ifndef FABRICD */
782 retval
= p2p_hello
? process_p2p_hello(&iih
) : process_lan_hello(&iih
);
784 isis_free_tlvs(iih
.tlvs
);
789 static void lsp_flood_or_update(struct isis_lsp
*lsp
,
790 struct isis_circuit
*circuit
,
794 lsp_flood(lsp
, circuit
);
796 fabricd_update_lsp_no_flood(lsp
, circuit
);
800 * Process Level 1/2 Link State
802 * Section 7.3.15.1 - Action on receipt of a link state PDU
804 static int process_lsp(uint8_t pdu_type
, struct isis_circuit
*circuit
,
805 const uint8_t *ssnpa
, uint8_t max_area_addrs
)
809 size_t pdu_start
= stream_get_getp(circuit
->rcv_stream
);
810 size_t pdu_end
= stream_get_endp(circuit
->rcv_stream
);
811 char raw_pdu
[pdu_end
- pdu_start
];
813 stream_get_from(raw_pdu
, circuit
->rcv_stream
, pdu_start
,
814 pdu_end
- pdu_start
);
816 if (pdu_type
== FS_LINK_STATE
) {
819 if (max_area_addrs
!= L2_CIRCUIT_FLOODING_SCOPE
)
822 circuit_scoped
= true;
824 /* The stream is used verbatim for sending out new LSPDUs.
825 * So make sure we store it as an L2 LSPDU internally.
826 * (compare for the reverse in `send_lsp`) */
827 stream_putc_at(circuit
->rcv_stream
, 4, L2_LINK_STATE
);
828 stream_putc_at(circuit
->rcv_stream
, 7, 0);
830 if (pdu_type
== L1_LINK_STATE
)
834 circuit_scoped
= false;
837 if (IS_DEBUG_UPDATE_PACKETS
) {
839 "ISIS-Upd (%s): Rcvd %sL%d LSP on %s, cirType %s, cirID %u",
840 circuit
->area
->area_tag
,
841 circuit_scoped
? "Circuit scoped " : "", level
,
842 circuit
->interface
->name
,
843 circuit_t2string(circuit
->is_type
),
844 circuit
->circuit_id
);
845 if (IS_DEBUG_PACKET_DUMP
)
846 zlog_dump_data(STREAM_DATA(circuit
->rcv_stream
),
847 stream_get_endp(circuit
->rcv_stream
));
850 struct isis_lsp_hdr hdr
= {};
852 hdr
.pdu_len
= stream_getw(circuit
->rcv_stream
);
853 hdr
.rem_lifetime
= stream_getw(circuit
->rcv_stream
);
854 stream_get(hdr
.lsp_id
, circuit
->rcv_stream
, sizeof(hdr
.lsp_id
));
855 hdr
.seqno
= stream_getl(circuit
->rcv_stream
);
856 hdr
.checksum
= stream_getw(circuit
->rcv_stream
);
857 hdr
.lsp_bits
= stream_getc(circuit
->rcv_stream
);
860 /* send northbound notification */
861 isis_notif_lsp_received(circuit
, rawlspid_print(hdr
.lsp_id
), hdr
.seqno
,
862 time(NULL
), sysid_print(hdr
.lsp_id
));
863 #endif /* ifndef FABRICD */
865 if (pdu_len_validate(hdr
.pdu_len
, circuit
)) {
866 zlog_debug("ISIS-Upd (%s): LSP %s invalid LSP length %hu",
867 circuit
->area
->area_tag
, rawlspid_print(hdr
.lsp_id
),
872 if (IS_DEBUG_UPDATE_PACKETS
) {
873 zlog_debug("ISIS-Upd (%s): Rcvd L%d LSP %s, seq 0x%08x, cksum 0x%04hx, lifetime %hus, len %hu, on %s",
874 circuit
->area
->area_tag
, level
,
875 rawlspid_print(hdr
.lsp_id
), hdr
.seqno
, hdr
.checksum
,
876 hdr
.rem_lifetime
, hdr
.pdu_len
,
877 circuit
->interface
->name
);
880 /* lsp is_type check */
881 if ((hdr
.lsp_bits
& IS_LEVEL_1
) != IS_LEVEL_1
) {
883 "ISIS-Upd (%s): LSP %s invalid LSP is type 0x%x",
884 circuit
->area
->area_tag
, rawlspid_print(hdr
.lsp_id
),
885 hdr
.lsp_bits
& IS_LEVEL_1_AND_2
);
886 /* continue as per RFC1122 Be liberal in what you accept, and
887 * conservative in what you send */
890 /* Checksum sanity check - FIXME: move to correct place */
891 /* 12 = sysid+pdu+remtime */
892 if (iso_csum_verify(STREAM_DATA(circuit
->rcv_stream
) + 12,
893 hdr
.pdu_len
- 12, hdr
.checksum
, 12)) {
895 "ISIS-Upd (%s): LSP %s invalid LSP checksum 0x%04hx",
896 circuit
->area
->area_tag
, rawlspid_print(hdr
.lsp_id
),
901 /* 7.3.15.1 a) 1 - external domain circuit will discard lsps */
902 if (circuit
->ext_domain
) {
904 "ISIS-Upd (%s): LSP %s received at level %d over circuit with externalDomain = true",
905 circuit
->area
->area_tag
, rawlspid_print(hdr
.lsp_id
),
910 /* 7.3.15.1 a) 2,3 - manualL2OnlyMode not implemented */
911 if (!(circuit
->is_type
& level
)) {
913 "ISIS-Upd (%s): LSP %s received at level %d over circuit of type %s",
914 circuit
->area
->area_tag
, rawlspid_print(hdr
.lsp_id
),
915 level
, circuit_t2string(circuit
->is_type
));
919 struct isis_tlvs
*tlvs
= NULL
;
920 int retval
= ISIS_WARNING
;
921 const char *error_log
;
923 if (isis_unpack_tlvs(STREAM_READABLE(circuit
->rcv_stream
),
924 circuit
->rcv_stream
, &tlvs
, &error_log
)) {
925 zlog_warn("Something went wrong unpacking the LSP: %s",
928 /* send northbound notification. Note that the tlv-type and
929 * offset cannot correctly be set here as they are not returned
930 * by isis_unpack_tlvs, but in there I cannot fire a
931 * notification because I have no circuit information. So until
932 * we change the code above to return those extra fields, we
933 * will send dummy values which are ignored in the callback
935 isis_notif_lsp_error(circuit
, rawlspid_print(hdr
.lsp_id
),
937 #endif /* ifndef FABRICD */
941 /* 7.3.15.1 a) 4 - need to make sure IDLength matches */
943 /* 7.3.15.1 a) 5 - maximum area match, can be ommited since we only use
946 /* 7.3.15.1 a) 7 - password check */
947 struct isis_passwd
*passwd
= (level
== ISIS_LEVEL1
)
948 ? &circuit
->area
->area_passwd
949 : &circuit
->area
->domain_passwd
;
950 int auth_code
= isis_tlvs_auth_is_valid(tlvs
, passwd
,
951 circuit
->rcv_stream
, true);
952 if (auth_code
!= ISIS_AUTH_OK
) {
953 isis_event_auth_failure(circuit
->area
->area_tag
,
954 "LSP authentication failure",
957 /* send northbound notification */
958 if (auth_code
== ISIS_AUTH_FAILURE
) {
959 circuit
->auth_failures
++;
960 isis_notif_authentication_failure(circuit
, raw_pdu
);
961 } else { /* AUTH_TYPE_FAILURE or NO_VALIDATOR */
962 circuit
->auth_type_failures
++;
963 isis_notif_authentication_type_failure(circuit
,
966 #endif /* ifndef FABRICD */
970 /* Find the LSP in our database and compare it to this Link State header
972 struct isis_lsp
*lsp
=
973 lsp_search(&circuit
->area
->lspdb
[level
- 1], hdr
.lsp_id
);
976 comp
= lsp_compare(circuit
->area
->area_tag
, lsp
, hdr
.seqno
,
977 hdr
.checksum
, hdr
.rem_lifetime
);
978 if (lsp
&& (lsp
->own_lsp
))
981 /* 7.3.15.1 a) 6 - Must check that we have an adjacency of the same
983 /* for broadcast circuits, snpa should be compared */
985 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
) {
986 if (!isis_adj_lookup_snpa(ssnpa
,
987 circuit
->u
.bc
.adjdb
[level
- 1])) {
988 zlog_debug("(%s): DS ======= LSP %s, seq 0x%08x, cksum 0x%04hx, lifetime %hus on %s",
989 circuit
->area
->area_tag
,
990 rawlspid_print(hdr
.lsp_id
), hdr
.seqno
,
991 hdr
.checksum
, hdr
.rem_lifetime
,
992 circuit
->interface
->name
);
993 goto out
; /* Silently discard */
996 /* for non broadcast, we just need to find same level adj */
998 /* If no adj, or no sharing of level */
999 if (!circuit
->u
.p2p
.neighbor
) {
1003 if (((level
== IS_LEVEL_1
)
1004 && (circuit
->u
.p2p
.neighbor
->adj_usage
1005 == ISIS_ADJ_LEVEL2
))
1006 || ((level
== IS_LEVEL_2
)
1007 && (circuit
->u
.p2p
.neighbor
->adj_usage
1008 == ISIS_ADJ_LEVEL1
)))
1016 /* 7.3.15.1 a) 7 - Passwords for level 1 - not implemented */
1018 /* 7.3.15.1 a) 8 - Passwords for level 2 - not implemented */
1020 /* 7.3.15.1 a) 9 - OriginatingLSPBufferSize - not implemented FIXME: do
1023 /* 7.3.16.2 - If this is an LSP from another IS with identical seq_num
1025 * wrong checksum, initiate a purge. */
1026 if (lsp
&& (lsp
->hdr
.seqno
== hdr
.seqno
)
1027 && (lsp
->hdr
.checksum
!= hdr
.checksum
)
1028 && hdr
.rem_lifetime
) {
1029 zlog_warn("ISIS-Upd (%s): LSP %s seq 0x%08x with confused checksum received.",
1030 circuit
->area
->area_tag
, rawlspid_print(hdr
.lsp_id
),
1032 hdr
.rem_lifetime
= 0;
1033 lsp_confusion
= true;
1035 lsp_confusion
= false;
1037 /* 7.3.15.1 b) - If the remaining life time is 0, we perform 7.3.16.4 */
1038 if (hdr
.rem_lifetime
== 0) {
1040 /* 7.3.16.4 a) 1) No LSP in db -> send an ack, but don't
1042 /* only needed on explicit update, eg - p2p */
1043 if (circuit
->circ_type
== CIRCUIT_T_P2P
)
1044 ack_lsp(&hdr
, circuit
, level
);
1045 goto out
; /* FIXME: do we need a purge? */
1047 if (memcmp(hdr
.lsp_id
, circuit
->area
->isis
->sysid
,
1049 /* LSP by some other system -> do 7.3.16.4 b) */
1050 /* 7.3.16.4 b) 1) */
1051 if (comp
== LSP_NEWER
) {
1052 lsp_update(lsp
, &hdr
, tlvs
,
1053 circuit
->rcv_stream
,
1054 circuit
->area
, level
,
1057 isis_free_tlvs(tlvs
);
1060 lsp_flood_or_update(lsp
, NULL
,
1063 ISIS_FLAGS_CLEAR_ALL(
1064 lsp
->SSNflags
); /* FIXME:
1069 /* For the case of lsp confusion, flood
1070 * the purge back to its
1071 * originator so that it can react.
1072 * Otherwise, don't reflood
1073 * through incoming circuit as usual */
1074 if (!lsp_confusion
) {
1080 if (circuit
->circ_type
1081 != CIRCUIT_T_BROADCAST
)
1086 } /* 7.3.16.4 b) 2) */
1087 else if (comp
== LSP_EQUAL
) {
1089 isis_tx_queue_del(circuit
->tx_queue
,
1092 if (circuit
->circ_type
1093 != CIRCUIT_T_BROADCAST
)
1094 ISIS_SET_FLAG(lsp
->SSNflags
,
1096 } /* 7.3.16.4 b) 3) */
1098 isis_tx_queue_add(circuit
->tx_queue
,
1099 lsp
, TX_LSP_NORMAL
);
1100 ISIS_CLEAR_FLAG(lsp
->SSNflags
, circuit
);
1102 } else if (lsp
->hdr
.rem_lifetime
!= 0) {
1103 /* our own LSP -> 7.3.16.4 c) */
1104 if (comp
== LSP_NEWER
) {
1106 if (lsp
->hdr
.seqno
< hdr
.seqno
) {
1109 isis_notif_seqno_skipped(
1114 #endif /* ifndef FABRICD */
1115 lsp_inc_seqno(lsp
, hdr
.seqno
);
1116 lsp_flood_or_update(lsp
, NULL
,
1119 isis_tx_queue_add(circuit
->tx_queue
,
1120 lsp
, TX_LSP_NORMAL
);
1121 ISIS_CLEAR_FLAG(lsp
->SSNflags
, circuit
);
1123 if (IS_DEBUG_UPDATE_PACKETS
)
1125 "ISIS-Upd (%s): (1) re-originating LSP %s new seq 0x%08x",
1126 circuit
->area
->area_tag
,
1127 rawlspid_print(hdr
.lsp_id
),
1130 /* our own LSP with 0 remaining life time */
1132 /* send northbound notification */
1133 isis_notif_own_lsp_purge(
1134 circuit
, rawlspid_print(hdr
.lsp_id
));
1135 #endif /* ifndef FABRICD */
1140 /* 7.3.15.1 c) - If this is our own lsp and we don't have it initiate a
1142 if (memcmp(hdr
.lsp_id
, circuit
->area
->isis
->sysid
, ISIS_SYS_ID_LEN
)
1145 /* 7.3.16.4: initiate a purge */
1146 lsp_purge_non_exist(level
, &hdr
, circuit
->area
);
1150 /* 7.3.15.1 d) - If this is our own lsp and we have it */
1152 /* In 7.3.16.1, If an Intermediate system R somewhere in the
1154 * has information that the current sequence number for source S
1156 * "greater" than that held by S, ... */
1158 if (comp
== LSP_NEWER
) {
1160 lsp_inc_seqno(lsp
, hdr
.seqno
);
1162 /* send northbound notification */
1163 isis_notif_seqno_skipped(circuit
,
1164 rawlspid_print(hdr
.lsp_id
));
1165 #endif /* ifndef FABRICD */
1166 if (IS_DEBUG_UPDATE_PACKETS
) {
1168 "ISIS-Upd (%s): (2) re-originating LSP %s new seq 0x%08x",
1169 circuit
->area
->area_tag
,
1170 rawlspid_print(hdr
.lsp_id
),
1173 lsp_flood(lsp
, NULL
);
1174 } else if (comp
== LSP_EQUAL
) {
1175 isis_tx_queue_del(circuit
->tx_queue
, lsp
);
1176 if (circuit
->circ_type
!= CIRCUIT_T_BROADCAST
)
1177 ISIS_SET_FLAG(lsp
->SSNflags
, circuit
);
1179 isis_tx_queue_add(circuit
->tx_queue
, lsp
,
1181 ISIS_CLEAR_FLAG(lsp
->SSNflags
, circuit
);
1184 /* 7.3.15.1 e) - This lsp originated on another system */
1186 /* 7.3.15.1 e) 1) LSP newer than the one in db or no LSP in db
1188 if ((!lsp
|| comp
== LSP_NEWER
)) {
1190 * If this lsp is a frag, need to see if we have zero
1193 struct isis_lsp
*lsp0
= NULL
;
1194 if (LSP_FRAGMENT(hdr
.lsp_id
) != 0) {
1195 uint8_t lspid
[ISIS_SYS_ID_LEN
+ 2];
1196 memcpy(lspid
, hdr
.lsp_id
, ISIS_SYS_ID_LEN
+ 1);
1197 LSP_FRAGMENT(lspid
) = 0;
1199 &circuit
->area
->lspdb
[level
- 1], lspid
);
1202 "Got lsp frag, while zero lsp not in database");
1208 lsp
= lsp_new_from_recv(
1209 &hdr
, tlvs
, circuit
->rcv_stream
, lsp0
,
1210 circuit
->area
, level
);
1212 lsp_insert(&circuit
->area
->lspdb
[level
- 1],
1214 } else /* exists, so we overwrite */
1216 lsp_update(lsp
, &hdr
, tlvs
, circuit
->rcv_stream
,
1217 circuit
->area
, level
, false);
1220 lsp_flood_or_update(lsp
, circuit
, circuit_scoped
);
1223 if (circuit
->circ_type
!= CIRCUIT_T_BROADCAST
)
1224 ISIS_SET_FLAG(lsp
->SSNflags
, circuit
);
1227 /* 7.3.15.1 e) 2) LSP equal to the one in db */
1228 else if (comp
== LSP_EQUAL
) {
1229 isis_tx_queue_del(circuit
->tx_queue
, lsp
);
1230 lsp_update(lsp
, &hdr
, tlvs
, circuit
->rcv_stream
,
1231 circuit
->area
, level
, false);
1233 if (circuit
->circ_type
!= CIRCUIT_T_BROADCAST
)
1234 ISIS_SET_FLAG(lsp
->SSNflags
, circuit
);
1236 /* 7.3.15.1 e) 3) LSP older than the one in db */
1238 isis_tx_queue_add(circuit
->tx_queue
, lsp
,
1240 ISIS_CLEAR_FLAG(lsp
->SSNflags
, circuit
);
1247 fabricd_trigger_csnp(circuit
->area
, circuit_scoped
);
1249 isis_free_tlvs(tlvs
);
1254 * Process Sequence Numbers
1256 * Section 7.3.15.2 - Action on receipt of a sequence numbers PDU
1259 static int process_snp(uint8_t pdu_type
, struct isis_circuit
*circuit
,
1260 const uint8_t *ssnpa
)
1263 size_t pdu_start
= stream_get_getp(circuit
->rcv_stream
);
1264 size_t pdu_end
= stream_get_endp(circuit
->rcv_stream
);
1265 char raw_pdu
[pdu_end
- pdu_start
];
1266 #endif /* ifndef FABRICD */
1268 bool is_csnp
= (pdu_type
== L1_COMPLETE_SEQ_NUM
1269 || pdu_type
== L2_COMPLETE_SEQ_NUM
);
1270 char typechar
= is_csnp
? 'C' : 'P';
1271 int level
= (pdu_type
== L1_COMPLETE_SEQ_NUM
1272 || pdu_type
== L1_PARTIAL_SEQ_NUM
)
1276 uint16_t pdu_len
= stream_getw(circuit
->rcv_stream
);
1277 uint8_t rem_sys_id
[ISIS_SYS_ID_LEN
];
1279 stream_get(rem_sys_id
, circuit
->rcv_stream
, ISIS_SYS_ID_LEN
);
1280 stream_forward_getp(circuit
->rcv_stream
, 1); /* Circuit ID - unused */
1282 uint8_t start_lsp_id
[ISIS_SYS_ID_LEN
+ 2] = {};
1283 uint8_t stop_lsp_id
[ISIS_SYS_ID_LEN
+ 2] = {};
1286 stream_get(start_lsp_id
, circuit
->rcv_stream
,
1287 ISIS_SYS_ID_LEN
+ 2);
1288 stream_get(stop_lsp_id
, circuit
->rcv_stream
,
1289 ISIS_SYS_ID_LEN
+ 2);
1292 if (pdu_len_validate(pdu_len
, circuit
)) {
1293 zlog_warn("Received a CSNP with bogus length %d", pdu_len
);
1294 return ISIS_WARNING
;
1297 if (IS_DEBUG_SNP_PACKETS
) {
1299 "ISIS-Snp (%s): Rcvd L%d %cSNP on %s, cirType %s, cirID %u",
1300 circuit
->area
->area_tag
, level
, typechar
,
1301 circuit
->interface
->name
,
1302 circuit_t2string(circuit
->is_type
),
1303 circuit
->circuit_id
);
1304 if (IS_DEBUG_PACKET_DUMP
)
1305 zlog_dump_data(STREAM_DATA(circuit
->rcv_stream
),
1306 stream_get_endp(circuit
->rcv_stream
));
1309 /* 7.3.15.2 a) 1 - external domain circuit will discard snp pdu */
1310 if (circuit
->ext_domain
) {
1313 "ISIS-Snp (%s): Rcvd L%d %cSNP on %s, skipping: circuit externalDomain = true",
1314 circuit
->area
->area_tag
, level
, typechar
,
1315 circuit
->interface
->name
);
1320 /* 7.3.15.2 a) 2,3 - manualL2OnlyMode not implemented */
1321 if (!(circuit
->is_type
& level
)) {
1323 "ISIS-Snp (%s): Rcvd L%d %cSNP on %s, skipping: circuit type %s does not match level %d",
1324 circuit
->area
->area_tag
, level
, typechar
,
1325 circuit
->interface
->name
,
1326 circuit_t2string(circuit
->is_type
), level
);
1331 /* 7.3.15.2 a) 4 - not applicable for CSNP only PSNPs on broadcast */
1332 if (!is_csnp
&& (circuit
->circ_type
== CIRCUIT_T_BROADCAST
)
1333 && !circuit
->u
.bc
.is_dr
[level
- 1]) {
1335 "ISIS-Snp (%s): Rcvd L%d %cSNP from %s on %s, skipping: we are not the DIS",
1336 circuit
->area
->area_tag
, level
, typechar
,
1337 snpa_print(ssnpa
), circuit
->interface
->name
);
1342 /* 7.3.15.2 a) 5 - need to make sure IDLength matches - already checked
1345 /* 7.3.15.2 a) 6 - maximum area match, can be ommited since we only use
1347 * - already checked */
1349 /* 7.3.15.2 a) 7 - Must check that we have an adjacency of the same
1351 /* for broadcast circuits, snpa should be compared */
1352 /* FIXME : Do we need to check SNPA? */
1353 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
) {
1354 if (!isis_adj_lookup(rem_sys_id
,
1355 circuit
->u
.bc
.adjdb
[level
- 1]))
1356 return ISIS_OK
; /* Silently discard */
1358 if (!fabricd
&& !circuit
->u
.p2p
.neighbor
) {
1359 zlog_warn("no p2p neighbor on circuit %s",
1360 circuit
->interface
->name
);
1361 return ISIS_OK
; /* Silently discard */
1365 struct isis_tlvs
*tlvs
;
1366 int retval
= ISIS_WARNING
;
1367 const char *error_log
;
1369 if (isis_unpack_tlvs(STREAM_READABLE(circuit
->rcv_stream
),
1370 circuit
->rcv_stream
, &tlvs
, &error_log
)) {
1371 zlog_warn("Something went wrong unpacking the SNP: %s",
1376 struct isis_passwd
*passwd
= (level
== IS_LEVEL_1
)
1377 ? &circuit
->area
->area_passwd
1378 : &circuit
->area
->domain_passwd
;
1380 if (CHECK_FLAG(passwd
->snp_auth
, SNP_AUTH_RECV
)) {
1381 int auth_code
= isis_tlvs_auth_is_valid(
1382 tlvs
, passwd
, circuit
->rcv_stream
, false);
1383 if (auth_code
!= ISIS_AUTH_OK
) {
1384 isis_event_auth_failure(circuit
->area
->area_tag
,
1385 "SNP authentication failure",
1388 /* send northbound notification */
1389 stream_get_from(raw_pdu
, circuit
->rcv_stream
, pdu_start
,
1390 pdu_end
- pdu_start
);
1391 if (auth_code
== ISIS_AUTH_FAILURE
) {
1392 circuit
->auth_failures
++;
1393 isis_notif_authentication_failure(circuit
,
1395 } else { /* AUTH_TYPE_FAILURE or NO_VALIDATOR */
1396 circuit
->auth_type_failures
++;
1397 isis_notif_authentication_type_failure(circuit
,
1400 #endif /* ifndef FABRICD */
1405 struct isis_lsp_entry
*entry_head
=
1406 (struct isis_lsp_entry
*)tlvs
->lsp_entries
.head
;
1408 /* debug isis snp-packets */
1409 if (IS_DEBUG_SNP_PACKETS
) {
1410 zlog_debug("ISIS-Snp (%s): Rcvd L%d %cSNP from %s on %s",
1411 circuit
->area
->area_tag
, level
, typechar
,
1412 snpa_print(ssnpa
), circuit
->interface
->name
);
1413 for (struct isis_lsp_entry
*entry
= entry_head
; entry
;
1414 entry
= entry
->next
) {
1416 "ISIS-Snp (%s): %cSNP entry %s, seq 0x%08x, cksum 0x%04hx, lifetime %hus",
1417 circuit
->area
->area_tag
, typechar
,
1418 rawlspid_print(entry
->id
), entry
->seqno
,
1419 entry
->checksum
, entry
->rem_lifetime
);
1423 bool resync_needed
= false;
1425 /* 7.3.15.2 b) Actions on LSP_ENTRIES reported */
1426 for (struct isis_lsp_entry
*entry
= entry_head
; entry
;
1427 entry
= entry
->next
) {
1428 struct isis_lsp
*lsp
=
1429 lsp_search(&circuit
->area
->lspdb
[level
- 1], entry
->id
);
1430 bool own_lsp
= !memcmp(entry
->id
, circuit
->area
->isis
->sysid
,
1433 /* 7.3.15.2 b) 1) is this LSP newer */
1434 int cmp
= lsp_compare(circuit
->area
->area_tag
, lsp
,
1435 entry
->seqno
, entry
->checksum
,
1436 entry
->rem_lifetime
);
1437 /* 7.3.15.2 b) 2) if it equals, clear SRM on p2p */
1438 if (cmp
== LSP_EQUAL
) {
1439 /* if (circuit->circ_type !=
1440 * CIRCUIT_T_BROADCAST) */
1441 isis_tx_queue_del(circuit
->tx_queue
, lsp
);
1443 /* 7.3.15.2 b) 3) if it is older, clear SSN and set SRM
1445 else if (cmp
== LSP_OLDER
) {
1446 ISIS_CLEAR_FLAG(lsp
->SSNflags
, circuit
);
1447 isis_tx_queue_add(circuit
->tx_queue
, lsp
,
1450 /* 7.3.15.2 b) 4) if it is newer, set SSN and clear SRM
1454 lsp_inc_seqno(lsp
, entry
->seqno
);
1455 isis_tx_queue_add(circuit
->tx_queue
, lsp
,
1458 ISIS_SET_FLAG(lsp
->SSNflags
, circuit
);
1459 /* if (circuit->circ_type !=
1460 * CIRCUIT_T_BROADCAST) */
1461 isis_tx_queue_del(circuit
->tx_queue
, lsp
);
1462 resync_needed
= true;
1466 /* 7.3.15.2 b) 5) if it was not found, and all of those
1468 * insert it and set SSN on it */
1469 if (entry
->rem_lifetime
&& entry
->checksum
1471 && memcmp(entry
->id
, circuit
->area
->isis
->sysid
,
1473 struct isis_lsp
*lsp0
= NULL
;
1475 if (LSP_FRAGMENT(entry
->id
)) {
1476 uint8_t lspid
[ISIS_SYS_ID_LEN
+ 2];
1478 memcpy(lspid
, entry
->id
,
1479 ISIS_SYS_ID_LEN
+ 1);
1480 LSP_FRAGMENT(lspid
) = 0;
1482 &circuit
->area
->lspdb
[level
- 1],
1485 zlog_debug("Got lsp frag in snp, while zero not in database");
1489 lsp
= lsp_new(circuit
->area
, entry
->id
,
1490 entry
->rem_lifetime
, 0, 0,
1491 entry
->checksum
, lsp0
, level
);
1492 lsp_insert(&circuit
->area
->lspdb
[level
- 1],
1495 lsp_set_all_srmflags(lsp
, false);
1496 ISIS_SET_FLAG(lsp
->SSNflags
, circuit
);
1497 resync_needed
= true;
1502 /* 7.3.15.2 c) on CSNP set SRM for all in range which were not reported
1506 * Build a list from our own LSP db bounded with
1507 * start_lsp_id and stop_lsp_id
1509 struct list
*lsp_list
= list_new();
1510 lsp_build_list_nonzero_ht(&circuit
->area
->lspdb
[level
- 1],
1511 start_lsp_id
, stop_lsp_id
, lsp_list
);
1513 /* Fixme: Find a better solution */
1514 struct listnode
*node
, *nnode
;
1515 struct isis_lsp
*lsp
;
1516 for (struct isis_lsp_entry
*entry
= entry_head
; entry
;
1517 entry
= entry
->next
) {
1518 for (ALL_LIST_ELEMENTS(lsp_list
, node
, nnode
, lsp
)) {
1519 if (lsp_id_cmp(lsp
->hdr
.lsp_id
, entry
->id
)
1521 list_delete_node(lsp_list
, node
);
1527 /* on remaining LSPs we set SRM (neighbor knew not of) */
1528 for (ALL_LIST_ELEMENTS_RO(lsp_list
, node
, lsp
)) {
1529 isis_tx_queue_add(circuit
->tx_queue
, lsp
, TX_LSP_NORMAL
);
1530 resync_needed
= true;
1534 list_delete(&lsp_list
);
1537 if (fabricd_initial_sync_is_complete(circuit
->area
) && resync_needed
)
1538 zlog_warn("OpenFabric: Needed to resync LSPDB using CSNP!");
1542 isis_free_tlvs(tlvs
);
1546 static int pdu_size(uint8_t pdu_type
, uint8_t *size
)
1551 *size
= ISIS_LANHELLO_HDRLEN
;
1554 *size
= ISIS_P2PHELLO_HDRLEN
;
1559 *size
= ISIS_LSP_HDR_LEN
;
1561 case L1_COMPLETE_SEQ_NUM
:
1562 case L2_COMPLETE_SEQ_NUM
:
1563 *size
= ISIS_CSNP_HDRLEN
;
1565 case L1_PARTIAL_SEQ_NUM
:
1566 case L2_PARTIAL_SEQ_NUM
:
1567 *size
= ISIS_PSNP_HDRLEN
;
1572 *size
+= ISIS_FIXED_HDR_LEN
;
1580 int isis_handle_pdu(struct isis_circuit
*circuit
, uint8_t *ssnpa
)
1582 int retval
= ISIS_OK
;
1583 size_t pdu_start
= stream_get_getp(circuit
->rcv_stream
);
1584 size_t pdu_end
= stream_get_endp(circuit
->rcv_stream
);
1585 char raw_pdu
[pdu_end
- pdu_start
];
1587 stream_get_from(raw_pdu
, circuit
->rcv_stream
, pdu_start
,
1588 pdu_end
- pdu_start
);
1590 /* Verify that at least the 8 bytes fixed header have been received */
1591 if (stream_get_endp(circuit
->rcv_stream
) < ISIS_FIXED_HDR_LEN
) {
1592 flog_err(EC_ISIS_PACKET
, "PDU is too short to be IS-IS.");
1596 uint8_t idrp
= stream_getc(circuit
->rcv_stream
);
1597 uint8_t length
= stream_getc(circuit
->rcv_stream
);
1598 uint8_t version1
= stream_getc(circuit
->rcv_stream
);
1599 uint8_t id_len
= stream_getc(circuit
->rcv_stream
);
1600 uint8_t pdu_type
= stream_getc(circuit
->rcv_stream
)
1601 & 0x1f; /* bits 6-8 are reserved */
1602 uint8_t version2
= stream_getc(circuit
->rcv_stream
);
1604 stream_forward_getp(circuit
->rcv_stream
, 1); /* reserved */
1605 uint8_t max_area_addrs
= stream_getc(circuit
->rcv_stream
);
1607 pdu_counter_count(circuit
->area
->pdu_rx_counters
, pdu_type
);
1609 if (idrp
== ISO9542_ESIS
) {
1610 flog_err(EC_LIB_DEVELOPMENT
,
1611 "No support for ES-IS packet IDRP=%hhx", idrp
);
1615 if (idrp
!= ISO10589_ISIS
) {
1616 flog_err(EC_ISIS_PACKET
, "Not an IS-IS packet IDRP=%hhx",
1621 if (version1
!= 1) {
1622 zlog_warn("Unsupported ISIS version %hhu", version1
);
1624 /* send northbound notification */
1625 isis_notif_version_skew(circuit
, version1
, raw_pdu
);
1626 #endif /* ifndef FABRICD */
1627 return ISIS_WARNING
;
1630 if (id_len
!= 0 && id_len
!= ISIS_SYS_ID_LEN
) {
1633 "IDFieldLengthMismatch: ID Length field in a received PDU %hhu, while the parameter for this IS is %u",
1634 id_len
, ISIS_SYS_ID_LEN
);
1635 circuit
->id_len_mismatches
++;
1637 /* send northbound notification */
1638 isis_notif_id_len_mismatch(circuit
, id_len
, raw_pdu
);
1639 #endif /* ifndef FABRICD */
1643 uint8_t expected_length
;
1644 if (pdu_size(pdu_type
, &expected_length
)) {
1645 zlog_warn("Unsupported ISIS PDU %hhu", pdu_type
);
1646 return ISIS_WARNING
;
1649 if (length
!= expected_length
) {
1650 flog_err(EC_ISIS_PACKET
,
1651 "Expected fixed header length = %hhu but got %hhu",
1652 expected_length
, length
);
1656 if (stream_get_endp(circuit
->rcv_stream
) < length
) {
1659 "PDU is too short to contain fixed header of given PDU type.");
1663 if (version2
!= 1) {
1664 zlog_warn("Unsupported ISIS PDU version %hhu", version2
);
1666 /* send northbound notification */
1667 isis_notif_version_skew(circuit
, version2
, raw_pdu
);
1668 #endif /* ifndef FABRICD */
1669 return ISIS_WARNING
;
1672 if (circuit
->is_passive
) {
1673 zlog_warn("Received ISIS PDU on passive circuit %s",
1674 circuit
->interface
->name
);
1675 return ISIS_WARNING
;
1679 if (pdu_type
!= FS_LINK_STATE
/* FS PDU doesn't contain max area addr
1681 && max_area_addrs
!= 0
1682 && max_area_addrs
!= circuit
->area
->isis
->max_area_addrs
) {
1685 "maximumAreaAddressesMismatch: maximumAreaAdresses in a received PDU %hhu while the parameter for this IS is %u",
1686 max_area_addrs
, circuit
->area
->isis
->max_area_addrs
);
1687 circuit
->max_area_addr_mismatches
++;
1689 /* send northbound notification */
1690 isis_notif_max_area_addr_mismatch(circuit
, max_area_addrs
,
1692 #endif /* ifndef FABRICD */
1700 if (fabricd
&& pdu_type
!= P2P_HELLO
)
1702 retval
= process_hello(pdu_type
, circuit
, ssnpa
);
1708 && pdu_type
!= L2_LINK_STATE
1709 && pdu_type
!= FS_LINK_STATE
)
1711 retval
= process_lsp(pdu_type
, circuit
, ssnpa
, max_area_addrs
);
1713 case L1_COMPLETE_SEQ_NUM
:
1714 case L2_COMPLETE_SEQ_NUM
:
1715 case L1_PARTIAL_SEQ_NUM
:
1716 case L2_PARTIAL_SEQ_NUM
:
1717 retval
= process_snp(pdu_type
, circuit
, ssnpa
);
1726 int isis_receive(struct thread
*thread
)
1728 struct isis_circuit
*circuit
;
1729 uint8_t ssnpa
[ETH_ALEN
];
1735 circuit
= THREAD_ARG(thread
);
1738 circuit
->t_read
= NULL
;
1740 isis_circuit_stream(circuit
, &circuit
->rcv_stream
);
1742 retval
= circuit
->rx(circuit
, ssnpa
);
1744 #if ISIS_METHOD != ISIS_METHOD_BPF
1745 if (retval
== ISIS_OK
)
1746 retval
= isis_handle_pdu(circuit
, ssnpa
);
1747 #endif //ISIS_METHOD != ISIS_METHOD_BPF
1750 * prepare for next packet.
1752 if (!circuit
->is_passive
)
1753 isis_circuit_prepare(circuit
);
1761 void fill_fixed_hdr(uint8_t pdu_type
, struct stream
*stream
)
1765 if (pdu_size(pdu_type
, &length
))
1766 assert(!"Unknown PDU Type");
1768 stream_putc(stream
, ISO10589_ISIS
); /* IDRP */
1769 stream_putc(stream
, length
); /* Length of fixed header */
1770 stream_putc(stream
, 1); /* Version/Protocol ID Extension 1 */
1771 stream_putc(stream
, 0); /* ID Length, 0 => 6 */
1772 stream_putc(stream
, pdu_type
);
1773 stream_putc(stream
, 1); /* Subversion */
1774 stream_putc(stream
, 0); /* Reserved */
1775 stream_putc(stream
, 0); /* Max Area Addresses 0 => 3 */
1778 static uint8_t hello_pdu_type(struct isis_circuit
*circuit
, int level
)
1780 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
)
1781 return (level
== IS_LEVEL_1
) ? L1_LAN_HELLO
: L2_LAN_HELLO
;
1786 static void put_hello_hdr(struct isis_circuit
*circuit
, int level
,
1787 size_t *len_pointer
)
1789 uint8_t pdu_type
= hello_pdu_type(circuit
, level
);
1791 isis_circuit_stream(circuit
, &circuit
->snd_stream
);
1792 fill_fixed_hdr(pdu_type
, circuit
->snd_stream
);
1794 stream_putc(circuit
->snd_stream
, circuit
->is_type
);
1795 stream_put(circuit
->snd_stream
, circuit
->area
->isis
->sysid
,
1798 uint32_t holdtime
= circuit
->hello_multiplier
[level
- 1]
1799 * circuit
->hello_interval
[level
- 1];
1801 if (holdtime
> 0xffff)
1804 stream_putw(circuit
->snd_stream
, holdtime
);
1805 *len_pointer
= stream_get_endp(circuit
->snd_stream
);
1806 stream_putw(circuit
->snd_stream
, 0); /* length is filled in later */
1808 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
) {
1809 uint8_t *desig_is
= (level
== IS_LEVEL_1
)
1810 ? circuit
->u
.bc
.l1_desig_is
1811 : circuit
->u
.bc
.l2_desig_is
;
1812 stream_putc(circuit
->snd_stream
, circuit
->priority
[level
- 1]);
1813 stream_put(circuit
->snd_stream
, desig_is
, ISIS_SYS_ID_LEN
+ 1);
1815 stream_putc(circuit
->snd_stream
, circuit
->circuit_id
);
1819 int send_hello(struct isis_circuit
*circuit
, int level
)
1824 if (circuit
->is_passive
)
1827 if (circuit
->interface
->mtu
== 0) {
1828 zlog_warn("circuit has zero MTU");
1829 return ISIS_WARNING
;
1832 put_hello_hdr(circuit
, level
, &len_pointer
);
1834 struct isis_tlvs
*tlvs
= isis_alloc_tlvs();
1836 isis_tlvs_add_auth(tlvs
, &circuit
->passwd
);
1838 if (!listcount(circuit
->area
->area_addrs
)) {
1839 isis_free_tlvs(tlvs
);
1840 return ISIS_WARNING
;
1843 isis_tlvs_add_area_addresses(tlvs
, circuit
->area
->area_addrs
);
1845 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
) {
1846 isis_tlvs_add_lan_neighbors(
1847 tlvs
, circuit
->u
.bc
.lan_neighs
[level
- 1]);
1848 } else if (circuit
->circ_type
== CIRCUIT_T_P2P
1849 && !circuit
->disable_threeway_adj
) {
1850 uint32_t ext_circuit_id
= circuit
->idx
;
1851 if (circuit
->u
.p2p
.neighbor
) {
1852 uint8_t threeway_state
;
1854 if (fabricd_initial_sync_is_in_progress(circuit
->area
)
1855 && fabricd_initial_sync_circuit(circuit
->area
) != circuit
)
1856 threeway_state
= ISIS_THREEWAY_DOWN
;
1858 threeway_state
= circuit
->u
.p2p
.neighbor
->threeway_state
;
1859 isis_tlvs_add_threeway_adj(tlvs
,
1862 circuit
->u
.p2p
.neighbor
->sysid
,
1863 circuit
->u
.p2p
.neighbor
->ext_circuit_id
);
1865 isis_tlvs_add_threeway_adj(tlvs
,
1872 isis_tlvs_set_protocols_supported(tlvs
, &circuit
->nlpids
);
1877 * TLV gets included if no topology is enabled on the interface,
1878 * if one topology other than #0 is enabled, or if multiple topologies
1881 struct isis_circuit_mt_setting
**mt_settings
;
1882 unsigned int mt_count
;
1884 mt_settings
= circuit_mt_settings(circuit
, &mt_count
);
1885 if (mt_count
== 0 && area_is_mt(circuit
->area
)) {
1886 tlvs
->mt_router_info_empty
= true;
1887 } else if ((mt_count
== 1
1888 && mt_settings
[0]->mtid
!= ISIS_MT_IPV4_UNICAST
)
1889 || (mt_count
> 1)) {
1890 for (unsigned int i
= 0; i
< mt_count
; i
++)
1891 isis_tlvs_add_mt_router_info(tlvs
, mt_settings
[i
]->mtid
,
1895 if (circuit
->ip_router
) {
1896 struct list
*circuit_ip_addrs
= fabricd_ip_addrs(circuit
);
1898 if (circuit_ip_addrs
)
1899 isis_tlvs_add_ipv4_addresses(tlvs
, circuit_ip_addrs
);
1902 if (circuit
->ipv6_router
&& circuit
->ipv6_link
)
1903 isis_tlvs_add_ipv6_addresses(tlvs
, circuit
->ipv6_link
);
1905 if (isis_pack_tlvs(tlvs
, circuit
->snd_stream
, len_pointer
,
1906 circuit
->pad_hellos
, false)) {
1907 isis_free_tlvs(tlvs
);
1908 return ISIS_WARNING
; /* XXX: Maybe Log TLV structure? */
1911 if (IS_DEBUG_ADJ_PACKETS
) {
1912 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
) {
1914 "ISIS-Adj (%s): Sending L%d LAN IIH on %s, length %zd",
1915 circuit
->area
->area_tag
, level
,
1916 circuit
->interface
->name
,
1917 stream_get_endp(circuit
->snd_stream
));
1920 "ISIS-Adj (%s): Sending P2P IIH on %s, length %zd",
1921 circuit
->area
->area_tag
,
1922 circuit
->interface
->name
,
1923 stream_get_endp(circuit
->snd_stream
));
1925 if (IS_DEBUG_PACKET_DUMP
)
1926 zlog_dump_data(STREAM_DATA(circuit
->snd_stream
),
1927 stream_get_endp(circuit
->snd_stream
));
1930 isis_free_tlvs(tlvs
);
1932 pdu_counter_count(circuit
->area
->pdu_tx_counters
,
1933 hello_pdu_type(circuit
, level
));
1934 retval
= circuit
->tx(circuit
, level
);
1935 if (retval
!= ISIS_OK
)
1936 flog_err(EC_ISIS_PACKET
,
1937 "ISIS-Adj (%s): Send L%d IIH on %s failed",
1938 circuit
->area
->area_tag
, level
,
1939 circuit
->interface
->name
);
1944 static int send_hello_cb(struct thread
*thread
)
1946 struct isis_circuit_arg
*arg
= THREAD_ARG(thread
);
1949 struct isis_circuit
*circuit
= arg
->circuit
;
1950 int level
= arg
->level
;
1954 if (circuit
->circ_type
== CIRCUIT_T_P2P
) {
1955 circuit
->u
.p2p
.t_send_p2p_hello
= NULL
;
1956 send_hello(circuit
, 1);
1957 send_hello_sched(circuit
, ISIS_LEVEL1
,
1958 1000 * circuit
->hello_interval
[1]);
1962 if (circuit
->circ_type
!= CIRCUIT_T_BROADCAST
) {
1963 zlog_warn("ISIS-Hello (%s): Trying to send hello on unknown circuit type %d",
1964 circuit
->area
->area_tag
, circuit
->circ_type
);
1965 return ISIS_WARNING
;
1968 circuit
->u
.bc
.t_send_lan_hello
[level
- 1] = NULL
;
1969 if (!(circuit
->is_type
& level
)) {
1970 zlog_warn("ISIS-Hello (%s): Trying to send L%d IIH in L%d-only circuit",
1971 circuit
->area
->area_tag
, level
, 3 - level
);
1972 return ISIS_WARNING
;
1975 if (circuit
->u
.bc
.run_dr_elect
[level
- 1])
1976 isis_dr_elect(circuit
, level
);
1978 int rv
= send_hello(circuit
, level
);
1980 /* set next timer thread */
1981 send_hello_sched(circuit
, level
, 1000 * circuit
->hello_interval
[level
- 1]);
1985 static void _send_hello_sched(struct isis_circuit
*circuit
,
1986 struct thread
**threadp
,
1987 int level
, long delay
)
1990 if (thread_timer_remain_msec(*threadp
) < (unsigned long)delay
)
1993 thread_cancel(*threadp
);
1996 thread_add_timer_msec(master
, send_hello_cb
,
1997 &circuit
->level_arg
[level
- 1],
1998 isis_jitter(delay
, IIH_JITTER
),
2002 void send_hello_sched(struct isis_circuit
*circuit
, int level
, long delay
)
2004 if (circuit
->circ_type
== CIRCUIT_T_P2P
) {
2005 _send_hello_sched(circuit
, &circuit
->u
.p2p
.t_send_p2p_hello
,
2006 ISIS_LEVEL1
, delay
);
2010 if (circuit
->circ_type
!= CIRCUIT_T_BROADCAST
) {
2011 zlog_warn("%s: encountered unknown circuit type %d on %s",
2012 __func__
, circuit
->circ_type
,
2013 circuit
->interface
->name
);
2017 for (int loop_level
= ISIS_LEVEL1
; loop_level
<= ISIS_LEVEL2
; loop_level
++) {
2018 if (!(loop_level
& level
))
2023 &circuit
->u
.bc
.t_send_lan_hello
[loop_level
- 1],
2032 * Count the maximum number of lsps that can be accomodated by a given size.
2034 #define LSP_ENTRIES_LEN (10 + ISIS_SYS_ID_LEN)
2035 static uint16_t get_max_lsp_count(uint16_t size
)
2039 uint16_t remaining_size
;
2041 /* First count the full size TLVs */
2042 tlv_count
= size
/ MAX_LSP_ENTRIES_TLV_SIZE
;
2043 lsp_count
= tlv_count
* (MAX_LSP_ENTRIES_TLV_SIZE
/ LSP_ENTRIES_LEN
);
2045 /* The last TLV, if any */
2046 remaining_size
= size
% MAX_LSP_ENTRIES_TLV_SIZE
;
2047 if (remaining_size
- 2 >= LSP_ENTRIES_LEN
)
2048 lsp_count
+= (remaining_size
- 2) / LSP_ENTRIES_LEN
;
2053 int send_csnp(struct isis_circuit
*circuit
, int level
)
2055 if (lspdb_count(&circuit
->area
->lspdb
[level
- 1]) == 0)
2058 uint8_t pdu_type
= (level
== ISIS_LEVEL1
) ? L1_COMPLETE_SEQ_NUM
2059 : L2_COMPLETE_SEQ_NUM
;
2061 isis_circuit_stream(circuit
, &circuit
->snd_stream
);
2062 fill_fixed_hdr(pdu_type
, circuit
->snd_stream
);
2064 size_t len_pointer
= stream_get_endp(circuit
->snd_stream
);
2066 stream_putw(circuit
->snd_stream
, 0);
2067 stream_put(circuit
->snd_stream
, circuit
->area
->isis
->sysid
,
2069 /* with zero circuit id - ref 9.10, 9.11 */
2070 stream_putc(circuit
->snd_stream
, 0);
2072 size_t start_pointer
= stream_get_endp(circuit
->snd_stream
);
2073 stream_put(circuit
->snd_stream
, 0, ISIS_SYS_ID_LEN
+ 2);
2074 size_t end_pointer
= stream_get_endp(circuit
->snd_stream
);
2075 stream_put(circuit
->snd_stream
, 0, ISIS_SYS_ID_LEN
+ 2);
2077 struct isis_passwd
*passwd
= (level
== ISIS_LEVEL1
)
2078 ? &circuit
->area
->area_passwd
2079 : &circuit
->area
->domain_passwd
;
2081 struct isis_tlvs
*tlvs
= isis_alloc_tlvs();
2083 if (CHECK_FLAG(passwd
->snp_auth
, SNP_AUTH_SEND
))
2084 isis_tlvs_add_auth(tlvs
, passwd
);
2086 size_t tlv_start
= stream_get_endp(circuit
->snd_stream
);
2087 if (isis_pack_tlvs(tlvs
, circuit
->snd_stream
, len_pointer
, false,
2089 isis_free_tlvs(tlvs
);
2090 return ISIS_WARNING
;
2092 isis_free_tlvs(tlvs
);
2095 get_max_lsp_count(STREAM_WRITEABLE(circuit
->snd_stream
));
2097 uint8_t start
[ISIS_SYS_ID_LEN
+ 2];
2098 memset(start
, 0x00, ISIS_SYS_ID_LEN
+ 2);
2099 uint8_t stop
[ISIS_SYS_ID_LEN
+ 2];
2100 memset(stop
, 0xff, ISIS_SYS_ID_LEN
+ 2);
2104 tlvs
= isis_alloc_tlvs();
2105 if (CHECK_FLAG(passwd
->snp_auth
, SNP_AUTH_SEND
))
2106 isis_tlvs_add_auth(tlvs
, passwd
);
2108 struct isis_lsp
*last_lsp
;
2109 isis_tlvs_add_csnp_entries(tlvs
, start
, stop
, num_lsps
,
2110 &circuit
->area
->lspdb
[level
- 1],
2113 * Update the stop lsp_id before encoding this CSNP.
2115 if (tlvs
->lsp_entries
.count
< num_lsps
) {
2116 memset(stop
, 0xff, ISIS_SYS_ID_LEN
+ 2);
2118 memcpy(stop
, last_lsp
->hdr
.lsp_id
, sizeof(stop
));
2121 memcpy(STREAM_DATA(circuit
->snd_stream
) + start_pointer
, start
,
2122 ISIS_SYS_ID_LEN
+ 2);
2123 memcpy(STREAM_DATA(circuit
->snd_stream
) + end_pointer
, stop
,
2124 ISIS_SYS_ID_LEN
+ 2);
2125 stream_set_endp(circuit
->snd_stream
, tlv_start
);
2126 if (isis_pack_tlvs(tlvs
, circuit
->snd_stream
, len_pointer
,
2128 isis_free_tlvs(tlvs
);
2129 return ISIS_WARNING
;
2132 if (IS_DEBUG_SNP_PACKETS
) {
2134 "ISIS-Snp (%s): Sending L%d CSNP on %s, length %zd",
2135 circuit
->area
->area_tag
, level
,
2136 circuit
->interface
->name
,
2137 stream_get_endp(circuit
->snd_stream
));
2138 log_multiline(LOG_DEBUG
, " ", "%s",
2139 isis_format_tlvs(tlvs
));
2140 if (IS_DEBUG_PACKET_DUMP
)
2142 STREAM_DATA(circuit
->snd_stream
),
2143 stream_get_endp(circuit
->snd_stream
));
2146 pdu_counter_count(circuit
->area
->pdu_tx_counters
, pdu_type
);
2147 int retval
= circuit
->tx(circuit
, level
);
2148 if (retval
!= ISIS_OK
) {
2149 flog_err(EC_ISIS_PACKET
,
2150 "ISIS-Snp (%s): Send L%d CSNP on %s failed",
2151 circuit
->area
->area_tag
, level
,
2152 circuit
->interface
->name
);
2153 isis_free_tlvs(tlvs
);
2158 * Start lsp_id of the next CSNP should be one plus the
2159 * stop lsp_id in this current CSNP.
2161 memcpy(start
, stop
, ISIS_SYS_ID_LEN
+ 2);
2163 for (int i
= ISIS_SYS_ID_LEN
+ 1; i
>= 0; --i
) {
2164 if (start
[i
] < (uint8_t)0xff) {
2170 memset(stop
, 0xff, ISIS_SYS_ID_LEN
+ 2);
2171 isis_free_tlvs(tlvs
);
2177 int send_l1_csnp(struct thread
*thread
)
2179 struct isis_circuit
*circuit
;
2181 circuit
= THREAD_ARG(thread
);
2184 circuit
->t_send_csnp
[0] = NULL
;
2186 if ((circuit
->circ_type
== CIRCUIT_T_BROADCAST
2187 && circuit
->u
.bc
.is_dr
[0])
2188 || circuit
->circ_type
== CIRCUIT_T_P2P
) {
2189 send_csnp(circuit
, 1);
2191 /* set next timer thread */
2192 thread_add_timer(master
, send_l1_csnp
, circuit
,
2193 isis_jitter(circuit
->csnp_interval
[0], CSNP_JITTER
),
2194 &circuit
->t_send_csnp
[0]);
2199 int send_l2_csnp(struct thread
*thread
)
2201 struct isis_circuit
*circuit
;
2203 circuit
= THREAD_ARG(thread
);
2206 circuit
->t_send_csnp
[1] = NULL
;
2208 if ((circuit
->circ_type
== CIRCUIT_T_BROADCAST
2209 && circuit
->u
.bc
.is_dr
[1])
2210 || circuit
->circ_type
== CIRCUIT_T_P2P
) {
2211 send_csnp(circuit
, 2);
2213 /* set next timer thread */
2214 thread_add_timer(master
, send_l2_csnp
, circuit
,
2215 isis_jitter(circuit
->csnp_interval
[1], CSNP_JITTER
),
2216 &circuit
->t_send_csnp
[1]);
2222 * 7.3.15.4 action on expiration of partial SNP interval
2225 static int send_psnp(int level
, struct isis_circuit
*circuit
)
2227 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
2228 && circuit
->u
.bc
.is_dr
[level
- 1])
2231 if (lspdb_count(&circuit
->area
->lspdb
[level
- 1]) == 0)
2234 if (!circuit
->snd_stream
)
2237 uint8_t pdu_type
= (level
== ISIS_LEVEL1
) ? L1_PARTIAL_SEQ_NUM
2238 : L2_PARTIAL_SEQ_NUM
;
2240 isis_circuit_stream(circuit
, &circuit
->snd_stream
);
2241 fill_fixed_hdr(pdu_type
, circuit
->snd_stream
);
2243 size_t len_pointer
= stream_get_endp(circuit
->snd_stream
);
2244 stream_putw(circuit
->snd_stream
, 0); /* length is filled in later */
2245 stream_put(circuit
->snd_stream
, circuit
->area
->isis
->sysid
,
2247 stream_putc(circuit
->snd_stream
, circuit
->idx
);
2249 struct isis_passwd
*passwd
= (level
== ISIS_LEVEL1
)
2250 ? &circuit
->area
->area_passwd
2251 : &circuit
->area
->domain_passwd
;
2253 struct isis_tlvs
*tlvs
= isis_alloc_tlvs();
2255 if (CHECK_FLAG(passwd
->snp_auth
, SNP_AUTH_SEND
))
2256 isis_tlvs_add_auth(tlvs
, passwd
);
2258 size_t tlv_start
= stream_get_endp(circuit
->snd_stream
);
2259 if (isis_pack_tlvs(tlvs
, circuit
->snd_stream
, len_pointer
, false,
2261 isis_free_tlvs(tlvs
);
2262 return ISIS_WARNING
;
2264 isis_free_tlvs(tlvs
);
2267 get_max_lsp_count(STREAM_WRITEABLE(circuit
->snd_stream
));
2270 struct isis_lsp
*lsp
;
2272 tlvs
= isis_alloc_tlvs();
2273 if (CHECK_FLAG(passwd
->snp_auth
, SNP_AUTH_SEND
))
2274 isis_tlvs_add_auth(tlvs
, passwd
);
2276 frr_each (lspdb
, &circuit
->area
->lspdb
[level
- 1], lsp
) {
2277 if (ISIS_CHECK_FLAG(lsp
->SSNflags
, circuit
))
2278 isis_tlvs_add_lsp_entry(tlvs
, lsp
);
2280 if (tlvs
->lsp_entries
.count
== num_lsps
)
2284 if (!tlvs
->lsp_entries
.count
) {
2285 isis_free_tlvs(tlvs
);
2289 stream_set_endp(circuit
->snd_stream
, tlv_start
);
2290 if (isis_pack_tlvs(tlvs
, circuit
->snd_stream
, len_pointer
,
2292 isis_free_tlvs(tlvs
);
2293 return ISIS_WARNING
;
2296 if (IS_DEBUG_SNP_PACKETS
) {
2298 "ISIS-Snp (%s): Sending L%d PSNP on %s, length %zd",
2299 circuit
->area
->area_tag
, level
,
2300 circuit
->interface
->name
,
2301 stream_get_endp(circuit
->snd_stream
));
2302 log_multiline(LOG_DEBUG
, " ", "%s",
2303 isis_format_tlvs(tlvs
));
2304 if (IS_DEBUG_PACKET_DUMP
)
2306 STREAM_DATA(circuit
->snd_stream
),
2307 stream_get_endp(circuit
->snd_stream
));
2310 pdu_counter_count(circuit
->area
->pdu_tx_counters
, pdu_type
);
2311 int retval
= circuit
->tx(circuit
, level
);
2312 if (retval
!= ISIS_OK
) {
2313 flog_err(EC_ISIS_PACKET
,
2314 "ISIS-Snp (%s): Send L%d PSNP on %s failed",
2315 circuit
->area
->area_tag
, level
,
2316 circuit
->interface
->name
);
2317 isis_free_tlvs(tlvs
);
2322 * sending succeeded, we can clear SSN flags of this circuit
2323 * for the LSPs in list
2325 struct isis_lsp_entry
*entry_head
;
2326 entry_head
= (struct isis_lsp_entry
*)tlvs
->lsp_entries
.head
;
2327 for (struct isis_lsp_entry
*entry
= entry_head
; entry
;
2328 entry
= entry
->next
)
2329 ISIS_CLEAR_FLAG(entry
->lsp
->SSNflags
, circuit
);
2330 isis_free_tlvs(tlvs
);
2336 int send_l1_psnp(struct thread
*thread
)
2339 struct isis_circuit
*circuit
;
2341 circuit
= THREAD_ARG(thread
);
2344 circuit
->t_send_psnp
[0] = NULL
;
2346 send_psnp(1, circuit
);
2347 /* set next timer thread */
2348 thread_add_timer(master
, send_l1_psnp
, circuit
,
2349 isis_jitter(circuit
->psnp_interval
[0], PSNP_JITTER
),
2350 &circuit
->t_send_psnp
[0]);
2356 * 7.3.15.4 action on expiration of partial SNP interval
2359 int send_l2_psnp(struct thread
*thread
)
2361 struct isis_circuit
*circuit
;
2363 circuit
= THREAD_ARG(thread
);
2366 circuit
->t_send_psnp
[1] = NULL
;
2368 send_psnp(2, circuit
);
2370 /* set next timer thread */
2371 thread_add_timer(master
, send_l2_psnp
, circuit
,
2372 isis_jitter(circuit
->psnp_interval
[1], PSNP_JITTER
),
2373 &circuit
->t_send_psnp
[1]);
2379 * ISO 10589 - 7.3.14.3
2381 void send_lsp(struct isis_circuit
*circuit
, struct isis_lsp
*lsp
,
2382 enum isis_tx_type tx_type
)
2385 int retval
= ISIS_OK
;
2387 if (circuit
->state
!= C_STATE_UP
|| circuit
->is_passive
== 1)
2391 * Do not send if levels do not match
2393 if (!(lsp
->level
& circuit
->is_type
))
2397 * Do not send if we do not have adjacencies in state up on the circuit
2399 if (circuit
->upadjcount
[lsp
->level
- 1] == 0)
2402 /* stream_copy will assert and stop program execution if LSP is larger
2404 * the circuit's MTU. So handle and log this case here. */
2405 if (stream_get_endp(lsp
->pdu
) > stream_get_size(circuit
->snd_stream
)) {
2408 "ISIS-Upd (%s): Can't send L%d LSP %s, seq 0x%08x, cksum 0x%04hx, lifetime %hus on %s. LSP Size is %zu while interface stream size is %zu.",
2409 circuit
->area
->area_tag
, lsp
->level
,
2410 rawlspid_print(lsp
->hdr
.lsp_id
), lsp
->hdr
.seqno
,
2411 lsp
->hdr
.checksum
, lsp
->hdr
.rem_lifetime
,
2412 circuit
->interface
->name
, stream_get_endp(lsp
->pdu
),
2413 stream_get_size(circuit
->snd_stream
));
2415 /* send a northbound notification */
2416 isis_notif_lsp_too_large(circuit
, stream_get_endp(lsp
->pdu
),
2417 rawlspid_print(lsp
->hdr
.lsp_id
));
2418 #endif /* ifndef FABRICD */
2419 if (IS_DEBUG_PACKET_DUMP
)
2420 zlog_dump_data(STREAM_DATA(lsp
->pdu
),
2421 stream_get_endp(lsp
->pdu
));
2422 retval
= ISIS_ERROR
;
2426 /* copy our lsp to the send buffer */
2427 stream_copy(circuit
->snd_stream
, lsp
->pdu
);
2429 if (tx_type
== TX_LSP_CIRCUIT_SCOPED
) {
2430 stream_putc_at(circuit
->snd_stream
, 4, FS_LINK_STATE
);
2431 stream_putc_at(circuit
->snd_stream
, 7,
2432 L2_CIRCUIT_FLOODING_SCOPE
);
2435 if (IS_DEBUG_UPDATE_PACKETS
) {
2436 zlog_debug("ISIS-Upd (%s): Sending %sL%d LSP %s, seq 0x%08x, cksum 0x%04hx, lifetime %hus on %s",
2437 circuit
->area
->area_tag
,
2438 (tx_type
== TX_LSP_CIRCUIT_SCOPED
)
2439 ? "Circuit scoped " : "",
2441 rawlspid_print(lsp
->hdr
.lsp_id
), lsp
->hdr
.seqno
,
2442 lsp
->hdr
.checksum
, lsp
->hdr
.rem_lifetime
,
2443 circuit
->interface
->name
);
2444 if (IS_DEBUG_PACKET_DUMP
)
2445 zlog_dump_data(STREAM_DATA(circuit
->snd_stream
),
2446 stream_get_endp(circuit
->snd_stream
));
2449 uint8_t pdu_type
= (tx_type
== TX_LSP_CIRCUIT_SCOPED
) ? FS_LINK_STATE
2450 : (lsp
->level
== ISIS_LEVEL1
) ? L1_LINK_STATE
2454 pdu_counter_count(circuit
->area
->pdu_tx_counters
, pdu_type
);
2455 retval
= circuit
->tx(circuit
, lsp
->level
);
2456 if (retval
!= ISIS_OK
) {
2457 flog_err(EC_ISIS_PACKET
,
2458 "ISIS-Upd (%s): Send L%d LSP on %s failed %s",
2459 circuit
->area
->area_tag
, lsp
->level
,
2460 circuit
->interface
->name
,
2461 (retval
== ISIS_WARNING
) ? "temporarily"
2467 || (retval
== ISIS_OK
&& circuit
->circ_type
== CIRCUIT_T_BROADCAST
)
2468 || (retval
!= ISIS_OK
&& retval
!= ISIS_WARNING
)) {
2469 /* SRM flag will trigger retransmission. We will not retransmit
2471 * encountered a fatal error.
2472 * On success, they should only be cleared if it's a broadcast
2474 * On a P2P circuit, we will wait for the ack from the neighbor
2478 isis_tx_queue_del(circuit
->tx_queue
, lsp
);