2 * IS-IS Rout(e)ing protocol - isis_pdu.c
5 * Copyright (C) 2001,2002 Sampo Saaristo
6 * Tampere University of Technology
7 * Institute of Communications Engineering
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public Licenseas published by the Free
11 * Software Foundation; either version 2 of the License, or (at your option)
14 * This program is distributed in the hope that it will be useful,but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
19 * You should have received a copy of the GNU General Public License along
20 * with this program; see the file COPYING; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
37 #include "lib_errors.h"
39 #include "isisd/isis_constants.h"
40 #include "isisd/isis_common.h"
41 #include "isisd/isis_flags.h"
42 #include "isisd/isis_adjacency.h"
43 #include "isisd/isis_circuit.h"
44 #include "isisd/isis_network.h"
45 #include "isisd/isis_misc.h"
46 #include "isisd/isis_dr.h"
47 #include "isisd/isisd.h"
48 #include "isisd/isis_dynhn.h"
49 #include "isisd/isis_lsp.h"
50 #include "isisd/isis_pdu.h"
51 #include "isisd/iso_checksum.h"
52 #include "isisd/isis_csm.h"
53 #include "isisd/isis_events.h"
54 #include "isisd/isis_te.h"
55 #include "isisd/isis_mt.h"
56 #include "isisd/isis_tlvs.h"
57 #include "isisd/isis_errors.h"
58 #include "isisd/fabricd.h"
59 #include "isisd/isis_tx_queue.h"
60 #include "isisd/isis_pdu_counter.h"
61 #include "isisd/isis_nb.h"
63 static int ack_lsp(struct isis_lsp_hdr
*hdr
, struct isis_circuit
*circuit
,
70 (level
== IS_LEVEL_1
) ? L1_PARTIAL_SEQ_NUM
: L2_PARTIAL_SEQ_NUM
;
72 isis_circuit_stream(circuit
, &circuit
->snd_stream
);
74 fill_fixed_hdr(pdu_type
, circuit
->snd_stream
);
76 lenp
= stream_get_endp(circuit
->snd_stream
);
77 stream_putw(circuit
->snd_stream
, 0); /* PDU length */
78 stream_put(circuit
->snd_stream
, isis
->sysid
, ISIS_SYS_ID_LEN
);
79 stream_putc(circuit
->snd_stream
, circuit
->idx
);
80 stream_putc(circuit
->snd_stream
, 9); /* code */
81 stream_putc(circuit
->snd_stream
, 16); /* len */
83 stream_putw(circuit
->snd_stream
, hdr
->rem_lifetime
);
84 stream_put(circuit
->snd_stream
, hdr
->lsp_id
, ISIS_SYS_ID_LEN
+ 2);
85 stream_putl(circuit
->snd_stream
, hdr
->seqno
);
86 stream_putw(circuit
->snd_stream
, hdr
->checksum
);
88 length
= (uint16_t)stream_get_endp(circuit
->snd_stream
);
89 /* Update PDU length */
90 stream_putw_at(circuit
->snd_stream
, lenp
, length
);
92 pdu_counter_count(circuit
->area
->pdu_tx_counters
, pdu_type
);
93 retval
= circuit
->tx(circuit
, level
);
94 if (retval
!= ISIS_OK
)
95 flog_err(EC_ISIS_PACKET
,
96 "ISIS-Upd (%s): Send L%d LSP PSNP on %s failed",
97 circuit
->area
->area_tag
, level
,
98 circuit
->interface
->name
);
108 struct isis_circuit
*circuit
;
113 uint8_t sys_id
[ISIS_SYS_ID_LEN
];
120 uint8_t dis
[ISIS_SYS_ID_LEN
+ 1];
125 struct isis_tlvs
*tlvs
;
128 static int process_p2p_hello(struct iih_info
*iih
)
130 struct isis_threeway_adj
*tw_adj
= iih
->tlvs
->threeway_adj
;
132 if (tw_adj
->state
> ISIS_THREEWAY_DOWN
) {
133 if (IS_DEBUG_ADJ_PACKETS
) {
134 zlog_debug("ISIS-Adj (%s): Rcvd P2P IIH from (%s) with invalid three-way state: %d",
135 iih
->circuit
->area
->area_tag
,
136 iih
->circuit
->interface
->name
,
142 if (tw_adj
->neighbor_set
143 && (memcmp(tw_adj
->neighbor_id
, isis
->sysid
, ISIS_SYS_ID_LEN
)
144 || tw_adj
->neighbor_circuit_id
!= (uint32_t) iih
->circuit
->idx
)) {
146 if (IS_DEBUG_ADJ_PACKETS
) {
147 zlog_debug("ISIS-Adj (%s): Rcvd P2P IIH from (%s) which lists IS/Circuit different from us as neighbor.",
148 iih
->circuit
->area
->area_tag
,
149 iih
->circuit
->interface
->name
);
157 * My interpertation of the ISO, if no adj exists we will create one for
160 struct isis_adjacency
*adj
= iih
->circuit
->u
.p2p
.neighbor
;
161 /* If an adjacency exists, check it is with the source of the hello
164 if (memcmp(iih
->sys_id
, adj
->sysid
, ISIS_SYS_ID_LEN
)) {
166 "hello source and adjacency do not match, set adj down\n");
167 isis_adj_state_change(&adj
, ISIS_ADJ_DOWN
,
172 if (!adj
|| adj
->level
!= iih
->circ_type
) {
174 adj
= isis_new_adj(iih
->sys_id
, NULL
, iih
->circ_type
,
177 adj
->level
= iih
->circ_type
;
179 iih
->circuit
->u
.p2p
.neighbor
= adj
;
180 /* Build lsp with the new neighbor entry when a new
181 * adjacency is formed. Set adjacency circuit type to
182 * IIH PDU header circuit type before lsp is regenerated
183 * when an adjacency is up. This will result in the new
184 * adjacency entry getting added to the lsp tlv neighbor list.
186 adj
->circuit_t
= iih
->circ_type
;
187 isis_adj_state_change(&adj
, ISIS_ADJ_INITIALIZING
, NULL
);
188 adj
->sys_type
= ISIS_SYSTYPE_UNKNOWN
;
192 adj
->ext_circuit_id
= tw_adj
->local_circuit_id
;
194 /* 8.2.6 Monitoring point-to-point adjacencies */
195 adj
->hold_time
= iih
->holdtime
;
196 adj
->last_upd
= time(NULL
);
199 isis_tlvs_to_adj(iih
->tlvs
, adj
, &changed
);
200 changed
|= tlvs_to_adj_mt_set(iih
->tlvs
, iih
->v4_usable
, iih
->v6_usable
,
203 /* lets take care of the expiry */
204 THREAD_TIMER_OFF(adj
->t_expire
);
205 thread_add_timer(master
, isis_adj_expire
, adj
, (long)adj
->hold_time
,
208 /* While fabricds initial sync is in progress, ignore hellos from other
209 * interfaces than the one we are performing the initial sync on. */
210 if (fabricd_initial_sync_is_in_progress(iih
->circuit
->area
)
211 && fabricd_initial_sync_circuit(iih
->circuit
->area
) != iih
->circuit
)
214 /* 8.2.5.2 a) a match was detected */
215 if (isis_tlvs_area_addresses_match(iih
->tlvs
,
216 iih
->circuit
->area
->area_addrs
)) {
217 /* 8.2.5.2 a) 2) If the system is L1 - table 5 */
218 if (iih
->circuit
->area
->is_type
== IS_LEVEL_1
) {
219 switch (iih
->circ_type
) {
221 case IS_LEVEL_1_AND_2
:
222 if (adj
->adj_state
!= ISIS_ADJ_UP
223 || adj
->adj_usage
== ISIS_ADJ_LEVEL1
) {
224 isis_adj_process_threeway(adj
, tw_adj
,
229 if (adj
->adj_state
!= ISIS_ADJ_UP
) {
230 /* (7) reject - wrong system type event
232 zlog_warn("wrongSystemType");
234 } else if (adj
->adj_usage
== ISIS_ADJ_LEVEL1
) {
235 /* (6) down - wrong system */
236 isis_adj_state_change(&adj
,
244 /* 8.2.5.2 a) 3) If the system is L1L2 - table 6 */
245 if (iih
->circuit
->area
->is_type
== IS_LEVEL_1_AND_2
) {
246 switch (iih
->circ_type
) {
248 if (adj
->adj_state
!= ISIS_ADJ_UP
249 || adj
->adj_usage
== ISIS_ADJ_LEVEL1
) {
250 isis_adj_process_threeway(adj
, tw_adj
,
252 } else if ((adj
->adj_usage
253 == ISIS_ADJ_LEVEL1AND2
)
255 == ISIS_ADJ_LEVEL2
)) {
256 /* (8) down - wrong system */
257 isis_adj_state_change(&adj
,
263 if (adj
->adj_state
!= ISIS_ADJ_UP
264 || adj
->adj_usage
== ISIS_ADJ_LEVEL2
) {
265 isis_adj_process_threeway(adj
, tw_adj
,
267 } else if ((adj
->adj_usage
== ISIS_ADJ_LEVEL1
)
269 == ISIS_ADJ_LEVEL1AND2
)) {
270 /* (8) down - wrong system */
271 isis_adj_state_change(&adj
,
276 case IS_LEVEL_1_AND_2
:
277 if (adj
->adj_state
!= ISIS_ADJ_UP
278 || adj
->adj_usage
== ISIS_ADJ_LEVEL1AND2
) {
279 isis_adj_process_threeway(adj
, tw_adj
,
280 ISIS_ADJ_LEVEL1AND2
);
281 } else if ((adj
->adj_usage
== ISIS_ADJ_LEVEL1
)
283 == ISIS_ADJ_LEVEL2
)) {
284 /* (8) down - wrong system */
285 isis_adj_state_change(&adj
,
293 /* 8.2.5.2 a) 4) If the system is L2 - table 7 */
294 if (iih
->circuit
->area
->is_type
== IS_LEVEL_2
) {
295 switch (iih
->circ_type
) {
297 if (adj
->adj_state
!= ISIS_ADJ_UP
) {
298 /* (5) reject - wrong system type event
300 zlog_warn("wrongSystemType");
302 } else if ((adj
->adj_usage
303 == ISIS_ADJ_LEVEL1AND2
)
305 == ISIS_ADJ_LEVEL2
)) {
306 /* (6) down - wrong system */
307 isis_adj_state_change(&adj
,
312 case IS_LEVEL_1_AND_2
:
314 if (adj
->adj_state
!= ISIS_ADJ_UP
315 || adj
->adj_usage
== ISIS_ADJ_LEVEL2
) {
316 isis_adj_process_threeway(adj
, tw_adj
,
318 } else if (adj
->adj_usage
319 == ISIS_ADJ_LEVEL1AND2
) {
320 /* (6) down - wrong system */
321 isis_adj_state_change(&adj
,
329 /* 8.2.5.2 b) if no match was detected */
330 else if (listcount(iih
->circuit
->area
->area_addrs
) > 0) {
331 if (iih
->circuit
->area
->is_type
== IS_LEVEL_1
) {
332 /* 8.2.5.2 b) 1) is_type L1 and adj is not up */
333 if (adj
->adj_state
!= ISIS_ADJ_UP
) {
334 isis_adj_state_change(&adj
, ISIS_ADJ_DOWN
,
336 /* 8.2.5.2 b) 2)is_type L1 and adj is up */
338 isis_adj_state_change(&adj
, ISIS_ADJ_DOWN
,
339 "Down - Area Mismatch");
342 /* 8.2.5.2 b 3 If the system is L2 or L1L2 - table 8 */
344 switch (iih
->circ_type
) {
346 if (adj
->adj_state
!= ISIS_ADJ_UP
) {
347 /* (6) reject - Area Mismatch event */
348 zlog_warn("AreaMismatch");
350 } else if (adj
->adj_usage
== ISIS_ADJ_LEVEL1
) {
351 /* (7) down - area mismatch */
352 isis_adj_state_change(&adj
,
356 } else if ((adj
->adj_usage
357 == ISIS_ADJ_LEVEL1AND2
)
359 == ISIS_ADJ_LEVEL2
)) {
360 /* (7) down - wrong system */
361 isis_adj_state_change(&adj
,
366 case IS_LEVEL_1_AND_2
:
368 if (adj
->adj_state
!= ISIS_ADJ_UP
369 || adj
->adj_usage
== ISIS_ADJ_LEVEL2
) {
370 isis_adj_process_threeway(adj
, tw_adj
,
372 } else if (adj
->adj_usage
== ISIS_ADJ_LEVEL1
) {
373 /* (7) down - wrong system */
374 isis_adj_state_change(&adj
,
377 } else if (adj
->adj_usage
378 == ISIS_ADJ_LEVEL1AND2
) {
379 if (iih
->circ_type
== IS_LEVEL_2
) {
380 /* (7) down - wrong system */
381 isis_adj_state_change(
385 /* (7) down - area mismatch */
386 isis_adj_state_change(
395 /* down - area mismatch */
396 isis_adj_state_change(&adj
, ISIS_ADJ_DOWN
, "Area Mismatch");
400 if (adj
->adj_state
== ISIS_ADJ_UP
&& changed
) {
401 lsp_regenerate_schedule(
403 isis_adj_usage2levels(adj
->adj_usage
), 0);
406 /* 8.2.5.2 c) if the action was up - comparing circuit IDs */
407 /* FIXME - Missing parts */
409 /* some of my own understanding of the ISO, why the heck does
410 * it not say what should I change the system_type to...
412 switch (adj
->adj_usage
) {
413 case ISIS_ADJ_LEVEL1
:
414 adj
->sys_type
= ISIS_SYSTYPE_L1_IS
;
416 case ISIS_ADJ_LEVEL2
:
417 adj
->sys_type
= ISIS_SYSTYPE_L2_IS
;
419 case ISIS_ADJ_LEVEL1AND2
:
420 adj
->sys_type
= ISIS_SYSTYPE_L2_IS
;
423 adj
->sys_type
= ISIS_SYSTYPE_UNKNOWN
;
428 if (IS_DEBUG_ADJ_PACKETS
) {
430 "ISIS-Adj (%s): Rcvd P2P IIH from (%s), cir type %s,"
431 " cir id %hhu, length %" PRIu16
,
432 iih
->circuit
->area
->area_tag
,
433 iih
->circuit
->interface
->name
,
434 circuit_t2string(iih
->circuit
->is_type
),
435 iih
->circuit
->circuit_id
, iih
->pdu_len
);
441 static int process_lan_hello(struct iih_info
*iih
)
443 struct isis_adjacency
*adj
;
444 adj
= isis_adj_lookup(iih
->sys_id
,
445 iih
->circuit
->u
.bc
.adjdb
[iih
->level
- 1]);
446 if ((adj
== NULL
) || (memcmp(adj
->snpa
, iih
->ssnpa
, ETH_ALEN
))
447 || (adj
->level
!= iih
->level
)) {
449 /* Do as in 8.4.2.5 */
450 adj
= isis_new_adj(iih
->sys_id
, iih
->ssnpa
, iih
->level
,
454 memcpy(adj
->snpa
, iih
->ssnpa
, 6);
456 memset(adj
->snpa
, ' ', 6);
458 adj
->level
= iih
->level
;
460 isis_adj_state_change(&adj
, ISIS_ADJ_INITIALIZING
, NULL
);
462 if (iih
->level
== IS_LEVEL_1
)
463 adj
->sys_type
= ISIS_SYSTYPE_L1_IS
;
465 adj
->sys_type
= ISIS_SYSTYPE_L2_IS
;
466 list_delete_all_node(
467 iih
->circuit
->u
.bc
.lan_neighs
[iih
->level
- 1]);
468 isis_adj_build_neigh_list(
469 iih
->circuit
->u
.bc
.adjdb
[iih
->level
- 1],
470 iih
->circuit
->u
.bc
.lan_neighs
[iih
->level
- 1]);
473 if (adj
->dis_record
[iih
->level
- 1].dis
== ISIS_IS_DIS
) {
474 uint8_t *dis
= (iih
->level
== 1)
475 ? iih
->circuit
->u
.bc
.l1_desig_is
476 : iih
->circuit
->u
.bc
.l2_desig_is
;
478 if (memcmp(dis
, iih
->dis
, ISIS_SYS_ID_LEN
+ 1)) {
479 thread_add_event(master
, isis_event_dis_status_change
,
480 iih
->circuit
, 0, NULL
);
481 memcpy(dis
, iih
->dis
, ISIS_SYS_ID_LEN
+ 1);
485 adj
->circuit_t
= iih
->circ_type
;
486 adj
->hold_time
= iih
->holdtime
;
487 adj
->last_upd
= time(NULL
);
488 adj
->prio
[iih
->level
- 1] = iih
->priority
;
489 memcpy(adj
->lanid
, iih
->dis
, ISIS_SYS_ID_LEN
+ 1);
492 isis_tlvs_to_adj(iih
->tlvs
, adj
, &changed
);
493 changed
|= tlvs_to_adj_mt_set(iih
->tlvs
, iih
->v4_usable
, iih
->v6_usable
,
496 /* lets take care of the expiry */
497 THREAD_TIMER_OFF(adj
->t_expire
);
498 thread_add_timer(master
, isis_adj_expire
, adj
, (long)adj
->hold_time
,
502 * If the snpa for this circuit is found from LAN Neighbours TLV
503 * we have two-way communication -> adjacency can be put to state "up"
505 bool own_snpa_found
=
506 isis_tlvs_own_snpa_found(iih
->tlvs
, iih
->circuit
->u
.bc
.snpa
);
508 if (adj
->adj_state
!= ISIS_ADJ_UP
) {
509 if (own_snpa_found
) {
510 isis_adj_state_change(
512 "own SNPA found in LAN Neighbours TLV");
515 if (!own_snpa_found
) {
516 isis_adj_state_change(
517 &adj
, ISIS_ADJ_INITIALIZING
,
518 "own SNPA not found in LAN Neighbours TLV");
522 if (adj
->adj_state
== ISIS_ADJ_UP
&& changed
)
523 lsp_regenerate_schedule(adj
->circuit
->area
, iih
->level
, 0);
525 if (IS_DEBUG_ADJ_PACKETS
) {
527 "ISIS-Adj (%s): Rcvd L%d LAN IIH from %s on %s, cirType %s, cirID %u, length %zd",
528 iih
->circuit
->area
->area_tag
, iih
->level
,
529 snpa_print(iih
->ssnpa
), iih
->circuit
->interface
->name
,
530 circuit_t2string(iih
->circuit
->is_type
),
531 iih
->circuit
->circuit_id
,
532 stream_get_endp(iih
->circuit
->rcv_stream
));
537 static int pdu_len_validate(uint16_t pdu_len
, struct isis_circuit
*circuit
)
539 if (pdu_len
< stream_get_getp(circuit
->rcv_stream
)
540 || pdu_len
> ISO_MTU(circuit
)
541 || pdu_len
> stream_get_endp(circuit
->rcv_stream
))
544 if (pdu_len
< stream_get_endp(circuit
->rcv_stream
))
545 stream_set_endp(circuit
->rcv_stream
, pdu_len
);
549 static int process_hello(uint8_t pdu_type
, struct isis_circuit
*circuit
,
552 /* keep a copy of the raw pdu for NB notifications */
553 size_t pdu_start
= stream_get_getp(circuit
->rcv_stream
);
554 size_t pdu_end
= stream_get_endp(circuit
->rcv_stream
);
555 char raw_pdu
[pdu_end
- pdu_start
];
556 bool p2p_hello
= (pdu_type
== P2P_HELLO
);
557 int level
= p2p_hello
? 0
558 : (pdu_type
== L1_LAN_HELLO
) ? ISIS_LEVEL1
560 const char *pdu_name
=
563 : (level
== ISIS_LEVEL1
) ? "L1 LAN IIH" : "L2 LAN IIH";
566 stream_get_from(raw_pdu
, circuit
->rcv_stream
, pdu_start
,
567 pdu_end
- pdu_start
);
568 if (IS_DEBUG_ADJ_PACKETS
) {
569 zlog_debug("ISIS-Adj (%s): Rcvd %s on %s, cirType %s, cirID %u",
570 circuit
->area
->area_tag
, pdu_name
,
571 circuit
->interface
->name
,
572 circuit_t2string(circuit
->is_type
),
573 circuit
->circuit_id
);
574 if (IS_DEBUG_PACKET_DUMP
)
575 zlog_dump_data(STREAM_DATA(circuit
->rcv_stream
),
576 stream_get_endp(circuit
->rcv_stream
));
580 if (circuit
->circ_type
!= CIRCUIT_T_P2P
) {
581 zlog_warn("p2p hello on non p2p circuit");
582 circuit
->rej_adjacencies
++;
584 isis_notif_reject_adjacency(
585 circuit
, "p2p hello on non p2p circuit",
587 #endif /* ifndef FABRICD */
591 if (circuit
->circ_type
!= CIRCUIT_T_BROADCAST
) {
592 zlog_warn("lan hello on non broadcast circuit");
593 circuit
->rej_adjacencies
++;
595 isis_notif_reject_adjacency(
596 circuit
, "lan hello on non broadcast circuit",
598 #endif /* ifndef FABRICD */
602 if (circuit
->ext_domain
) {
604 "level %d LAN Hello received over circuit with externalDomain = true",
606 circuit
->rej_adjacencies
++;
608 isis_notif_reject_adjacency(
610 "LAN Hello received over circuit with externalDomain = true",
612 #endif /* ifndef FABRICD */
616 if (!(circuit
->is_type
& level
)) {
617 if (IS_DEBUG_ADJ_PACKETS
) {
619 "ISIS-Adj (%s): Interface level mismatch, %s",
620 circuit
->area
->area_tag
,
621 circuit
->interface
->name
);
623 circuit
->rej_adjacencies
++;
625 isis_notif_reject_adjacency(
626 circuit
, "Interface level mismatch", raw_pdu
);
627 #endif /* ifndef FABRICD */
632 struct iih_info iih
= {
633 .circuit
= circuit
, .ssnpa
= ssnpa
, .level
= level
};
635 /* Generic IIH Header */
636 iih
.circ_type
= stream_getc(circuit
->rcv_stream
) & 0x03;
637 stream_get(iih
.sys_id
, circuit
->rcv_stream
, ISIS_SYS_ID_LEN
);
638 iih
.holdtime
= stream_getw(circuit
->rcv_stream
);
639 iih
.pdu_len
= stream_getw(circuit
->rcv_stream
);
642 iih
.circuit_id
= stream_getc(circuit
->rcv_stream
);
644 iih
.priority
= stream_getc(circuit
->rcv_stream
);
645 stream_get(iih
.dis
, circuit
->rcv_stream
, ISIS_SYS_ID_LEN
+ 1);
648 if (pdu_len_validate(iih
.pdu_len
, circuit
)) {
650 "ISIS-Adj (%s): Rcvd %s from (%s) with invalid pdu length %" PRIu16
,
651 circuit
->area
->area_tag
, pdu_name
,
652 circuit
->interface
->name
, iih
.pdu_len
);
653 circuit
->rej_adjacencies
++;
655 isis_notif_reject_adjacency(circuit
, "Invalid PDU length",
657 #endif /* ifndef FABRICD */
661 if (!p2p_hello
&& !(level
& iih
.circ_type
)) {
662 flog_err(EC_ISIS_PACKET
,
663 "Level %d LAN Hello with Circuit Type %d", level
,
665 circuit
->rej_adjacencies
++;
667 isis_notif_reject_adjacency(
668 circuit
, "LAN Hello with wrong IS-level", raw_pdu
);
669 #endif /* ifndef FABRICD */
673 const char *error_log
;
674 int retval
= ISIS_WARNING
;
676 if (isis_unpack_tlvs(STREAM_READABLE(circuit
->rcv_stream
),
677 circuit
->rcv_stream
, &iih
.tlvs
, &error_log
)) {
678 zlog_warn("isis_unpack_tlvs() failed: %s", error_log
);
679 circuit
->rej_adjacencies
++;
681 isis_notif_reject_adjacency(circuit
, "Failed to unpack TLVs",
683 #endif /* ifndef FABRICD */
687 if (!iih
.tlvs
->area_addresses
.count
) {
688 zlog_warn("No Area addresses TLV in %s", pdu_name
);
690 /* send northbound notification */
691 isis_notif_area_mismatch(circuit
, raw_pdu
);
692 #endif /* ifndef FABRICD */
696 if (!iih
.tlvs
->protocols_supported
.count
) {
697 zlog_warn("No supported protocols TLV in %s", pdu_name
);
698 circuit
->rej_adjacencies
++;
700 isis_notif_reject_adjacency(
701 circuit
, "No supported protocols TLV", raw_pdu
);
702 #endif /* ifndef FABRICD */
706 int auth_code
= isis_tlvs_auth_is_valid(iih
.tlvs
, &circuit
->passwd
,
707 circuit
->rcv_stream
, false);
708 if (auth_code
!= ISIS_AUTH_OK
) {
709 isis_event_auth_failure(circuit
->area
->area_tag
,
710 "IIH authentication failure",
713 /* send northbound notification */
714 stream_get_from(raw_pdu
, circuit
->rcv_stream
, pdu_start
,
715 pdu_end
- pdu_start
);
716 if (auth_code
== ISIS_AUTH_FAILURE
) {
717 circuit
->auth_failures
++;
718 isis_notif_authentication_failure(circuit
, raw_pdu
);
719 } else { /* AUTH_TYPE_FAILURE or NO_VALIDATOR */
720 circuit
->auth_type_failures
++;
721 isis_notif_authentication_type_failure(circuit
,
724 #endif /* ifndef FABRICD */
728 if (!memcmp(iih
.sys_id
, isis
->sysid
, ISIS_SYS_ID_LEN
)) {
730 "ISIS-Adj (%s): Received IIH with own sysid - discard",
731 circuit
->area
->area_tag
);
732 circuit
->rej_adjacencies
++;
734 isis_notif_reject_adjacency(
735 circuit
, "Received IIH with our own sysid", raw_pdu
);
736 #endif /* ifndef FABRICD */
741 && (listcount(circuit
->area
->area_addrs
) == 0
742 || (level
== ISIS_LEVEL1
743 && !isis_tlvs_area_addresses_match(
744 iih
.tlvs
, circuit
->area
->area_addrs
)))) {
745 if (IS_DEBUG_ADJ_PACKETS
) {
747 "ISIS-Adj (%s): Area mismatch, level %d IIH on %s",
748 circuit
->area
->area_tag
, level
,
749 circuit
->interface
->name
);
752 /* send northbound notification */
753 isis_notif_area_mismatch(circuit
, raw_pdu
);
754 #endif /* ifndef FABRICD */
758 iih
.v4_usable
= (fabricd_ip_addrs(circuit
)
759 && iih
.tlvs
->ipv4_address
.count
);
761 iih
.v6_usable
= (circuit
->ipv6_link
&& listcount(circuit
->ipv6_link
)
762 && iih
.tlvs
->ipv6_address
.count
);
764 if (!iih
.v4_usable
&& !iih
.v6_usable
) {
765 if (IS_DEBUG_ADJ_PACKETS
) {
767 "ISIS-Adj (%s): Neither IPv4 nor IPv6 considered usable. Ignoring IIH",
768 circuit
->area
->area_tag
);
770 circuit
->rej_adjacencies
++;
772 isis_notif_reject_adjacency(
773 circuit
, "Neither IPv4 not IPv6 considered usable",
775 #endif /* ifndef FABRICD */
779 retval
= p2p_hello
? process_p2p_hello(&iih
) : process_lan_hello(&iih
);
781 isis_free_tlvs(iih
.tlvs
);
786 static void lsp_flood_or_update(struct isis_lsp
*lsp
,
787 struct isis_circuit
*circuit
,
791 lsp_flood(lsp
, circuit
);
793 fabricd_update_lsp_no_flood(lsp
, circuit
);
797 * Process Level 1/2 Link State
799 * Section 7.3.15.1 - Action on receipt of a link state PDU
801 static int process_lsp(uint8_t pdu_type
, struct isis_circuit
*circuit
,
802 const uint8_t *ssnpa
, uint8_t max_area_addrs
)
806 size_t pdu_start
= stream_get_getp(circuit
->rcv_stream
);
807 size_t pdu_end
= stream_get_endp(circuit
->rcv_stream
);
808 char raw_pdu
[pdu_end
- pdu_start
];
810 stream_get_from(raw_pdu
, circuit
->rcv_stream
, pdu_start
,
811 pdu_end
- pdu_start
);
813 if (pdu_type
== FS_LINK_STATE
) {
816 if (max_area_addrs
!= L2_CIRCUIT_FLOODING_SCOPE
)
819 circuit_scoped
= true;
821 /* The stream is used verbatim for sending out new LSPDUs.
822 * So make sure we store it as an L2 LSPDU internally.
823 * (compare for the reverse in `send_lsp`) */
824 stream_putc_at(circuit
->rcv_stream
, 4, L2_LINK_STATE
);
825 stream_putc_at(circuit
->rcv_stream
, 7, 0);
827 if (pdu_type
== L1_LINK_STATE
)
831 circuit_scoped
= false;
834 if (IS_DEBUG_UPDATE_PACKETS
) {
836 "ISIS-Upd (%s): Rcvd %sL%d LSP on %s, cirType %s, cirID %u",
837 circuit
->area
->area_tag
,
838 circuit_scoped
? "Circuit scoped " : "", level
,
839 circuit
->interface
->name
,
840 circuit_t2string(circuit
->is_type
),
841 circuit
->circuit_id
);
842 if (IS_DEBUG_PACKET_DUMP
)
843 zlog_dump_data(STREAM_DATA(circuit
->rcv_stream
),
844 stream_get_endp(circuit
->rcv_stream
));
847 struct isis_lsp_hdr hdr
= {};
849 hdr
.pdu_len
= stream_getw(circuit
->rcv_stream
);
850 hdr
.rem_lifetime
= stream_getw(circuit
->rcv_stream
);
851 stream_get(hdr
.lsp_id
, circuit
->rcv_stream
, sizeof(hdr
.lsp_id
));
852 hdr
.seqno
= stream_getl(circuit
->rcv_stream
);
853 hdr
.checksum
= stream_getw(circuit
->rcv_stream
);
854 hdr
.lsp_bits
= stream_getc(circuit
->rcv_stream
);
857 /* send northbound notification */
858 isis_notif_lsp_received(circuit
, rawlspid_print(hdr
.lsp_id
), hdr
.seqno
,
859 time(NULL
), sysid_print(hdr
.lsp_id
));
860 #endif /* ifndef FABRICD */
862 if (pdu_len_validate(hdr
.pdu_len
, circuit
)) {
863 zlog_debug("ISIS-Upd (%s): LSP %s invalid LSP length %" PRIu16
,
864 circuit
->area
->area_tag
, rawlspid_print(hdr
.lsp_id
),
869 if (IS_DEBUG_UPDATE_PACKETS
) {
870 zlog_debug("ISIS-Upd (%s): Rcvd L%d LSP %s, seq 0x%08" PRIx32
871 ", cksum 0x%04" PRIx16
", lifetime %" PRIu16
872 "s, len %" PRIu16
", on %s",
873 circuit
->area
->area_tag
, level
,
874 rawlspid_print(hdr
.lsp_id
), hdr
.seqno
, hdr
.checksum
,
875 hdr
.rem_lifetime
, hdr
.pdu_len
,
876 circuit
->interface
->name
);
879 /* lsp is_type check */
880 if ((hdr
.lsp_bits
& IS_LEVEL_1
) != IS_LEVEL_1
) {
882 "ISIS-Upd (%s): LSP %s invalid LSP is type 0x%" PRIx8
,
883 circuit
->area
->area_tag
, rawlspid_print(hdr
.lsp_id
),
884 hdr
.lsp_bits
& IS_LEVEL_1_AND_2
);
885 /* continue as per RFC1122 Be liberal in what you accept, and
886 * conservative in what you send */
889 /* Checksum sanity check - FIXME: move to correct place */
890 /* 12 = sysid+pdu+remtime */
891 if (iso_csum_verify(STREAM_DATA(circuit
->rcv_stream
) + 12,
892 hdr
.pdu_len
- 12, hdr
.checksum
, 12)) {
894 "ISIS-Upd (%s): LSP %s invalid LSP checksum 0x%04" PRIx16
,
895 circuit
->area
->area_tag
, rawlspid_print(hdr
.lsp_id
),
900 /* 7.3.15.1 a) 1 - external domain circuit will discard lsps */
901 if (circuit
->ext_domain
) {
903 "ISIS-Upd (%s): LSP %s received at level %d over circuit with "
904 "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"
915 circuit
->area
->area_tag
, rawlspid_print(hdr
.lsp_id
),
916 level
, circuit_t2string(circuit
->is_type
));
920 struct isis_tlvs
*tlvs
= NULL
;
921 int retval
= ISIS_WARNING
;
922 const char *error_log
;
924 if (isis_unpack_tlvs(STREAM_READABLE(circuit
->rcv_stream
),
925 circuit
->rcv_stream
, &tlvs
, &error_log
)) {
926 zlog_warn("Something went wrong unpacking the LSP: %s",
929 /* send northbound notification. Note that the tlv-type and
930 * offset cannot correctly be set here as they are not returned
931 * by isis_unpack_tlvs, but in there I cannot fire a
932 * notification because I have no circuit information. So until
933 * we change the code above to return those extra fields, we
934 * will send dummy values which are ignored in the callback
936 isis_notif_lsp_error(circuit
, rawlspid_print(hdr
.lsp_id
),
938 #endif /* ifndef FABRICD */
942 /* 7.3.15.1 a) 4 - need to make sure IDLength matches */
944 /* 7.3.15.1 a) 5 - maximum area match, can be ommited since we only use
947 /* 7.3.15.1 a) 7 - password check */
948 struct isis_passwd
*passwd
= (level
== ISIS_LEVEL1
)
949 ? &circuit
->area
->area_passwd
950 : &circuit
->area
->domain_passwd
;
951 int auth_code
= isis_tlvs_auth_is_valid(tlvs
, passwd
,
952 circuit
->rcv_stream
, true);
953 if (auth_code
!= ISIS_AUTH_OK
) {
954 isis_event_auth_failure(circuit
->area
->area_tag
,
955 "LSP authentication failure",
958 /* send northbound notification */
959 if (auth_code
== ISIS_AUTH_FAILURE
) {
960 circuit
->auth_failures
++;
961 isis_notif_authentication_failure(circuit
, raw_pdu
);
962 } else { /* AUTH_TYPE_FAILURE or NO_VALIDATOR */
963 circuit
->auth_type_failures
++;
964 isis_notif_authentication_type_failure(circuit
,
967 #endif /* ifndef FABRICD */
971 /* Find the LSP in our database and compare it to this Link State header
973 struct isis_lsp
*lsp
=
974 lsp_search(&circuit
->area
->lspdb
[level
- 1], hdr
.lsp_id
);
977 comp
= lsp_compare(circuit
->area
->area_tag
, lsp
, hdr
.seqno
,
978 hdr
.checksum
, hdr
.rem_lifetime
);
979 if (lsp
&& (lsp
->own_lsp
))
982 /* 7.3.15.1 a) 6 - Must check that we have an adjacency of the same
984 /* for broadcast circuits, snpa should be compared */
986 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
) {
987 if (!isis_adj_lookup_snpa(ssnpa
,
988 circuit
->u
.bc
.adjdb
[level
- 1])) {
989 zlog_debug("(%s): DS ======= LSP %s, seq 0x%08" PRIx32
990 ", cksum 0x%04" PRIx16
", lifetime %" PRIu16
992 circuit
->area
->area_tag
,
993 rawlspid_print(hdr
.lsp_id
), hdr
.seqno
,
994 hdr
.checksum
, hdr
.rem_lifetime
,
995 circuit
->interface
->name
);
996 goto out
; /* Silently discard */
999 /* for non broadcast, we just need to find same level adj */
1001 /* If no adj, or no sharing of level */
1002 if (!circuit
->u
.p2p
.neighbor
) {
1006 if (((level
== IS_LEVEL_1
)
1007 && (circuit
->u
.p2p
.neighbor
->adj_usage
1008 == ISIS_ADJ_LEVEL2
))
1009 || ((level
== IS_LEVEL_2
)
1010 && (circuit
->u
.p2p
.neighbor
->adj_usage
1011 == ISIS_ADJ_LEVEL1
)))
1019 /* 7.3.15.1 a) 7 - Passwords for level 1 - not implemented */
1021 /* 7.3.15.1 a) 8 - Passwords for level 2 - not implemented */
1023 /* 7.3.15.1 a) 9 - OriginatingLSPBufferSize - not implemented FIXME: do
1026 /* 7.3.16.2 - If this is an LSP from another IS with identical seq_num
1028 * wrong checksum, initiate a purge. */
1029 if (lsp
&& (lsp
->hdr
.seqno
== hdr
.seqno
)
1030 && (lsp
->hdr
.checksum
!= hdr
.checksum
)
1031 && hdr
.rem_lifetime
) {
1032 zlog_warn("ISIS-Upd (%s): LSP %s seq 0x%08" PRIx32
1033 " with confused checksum received.",
1034 circuit
->area
->area_tag
, rawlspid_print(hdr
.lsp_id
),
1036 hdr
.rem_lifetime
= 0;
1037 lsp_confusion
= true;
1039 lsp_confusion
= false;
1041 /* 7.3.15.1 b) - If the remaining life time is 0, we perform 7.3.16.4 */
1042 if (hdr
.rem_lifetime
== 0) {
1044 /* 7.3.16.4 a) 1) No LSP in db -> send an ack, but don't
1046 /* only needed on explicit update, eg - p2p */
1047 if (circuit
->circ_type
== CIRCUIT_T_P2P
)
1048 ack_lsp(&hdr
, circuit
, level
);
1049 goto out
; /* FIXME: do we need a purge? */
1051 if (memcmp(hdr
.lsp_id
, isis
->sysid
, ISIS_SYS_ID_LEN
)) {
1052 /* LSP by some other system -> do 7.3.16.4 b) */
1053 /* 7.3.16.4 b) 1) */
1054 if (comp
== LSP_NEWER
) {
1055 lsp_update(lsp
, &hdr
, tlvs
,
1056 circuit
->rcv_stream
,
1057 circuit
->area
, level
,
1060 isis_free_tlvs(tlvs
);
1063 lsp_flood_or_update(lsp
, NULL
,
1066 ISIS_FLAGS_CLEAR_ALL(
1067 lsp
->SSNflags
); /* FIXME:
1072 /* For the case of lsp confusion, flood
1073 * the purge back to its
1074 * originator so that it can react.
1075 * Otherwise, don't reflood
1076 * through incoming circuit as usual */
1077 if (!lsp_confusion
) {
1083 if (circuit
->circ_type
1084 != CIRCUIT_T_BROADCAST
)
1089 } /* 7.3.16.4 b) 2) */
1090 else if (comp
== LSP_EQUAL
) {
1092 isis_tx_queue_del(circuit
->tx_queue
,
1095 if (circuit
->circ_type
1096 != CIRCUIT_T_BROADCAST
)
1097 ISIS_SET_FLAG(lsp
->SSNflags
,
1099 } /* 7.3.16.4 b) 3) */
1101 isis_tx_queue_add(circuit
->tx_queue
,
1102 lsp
, TX_LSP_NORMAL
);
1103 ISIS_CLEAR_FLAG(lsp
->SSNflags
, circuit
);
1105 } else if (lsp
->hdr
.rem_lifetime
!= 0) {
1106 /* our own LSP -> 7.3.16.4 c) */
1107 if (comp
== LSP_NEWER
) {
1109 if (lsp
->hdr
.seqno
< hdr
.seqno
) {
1112 isis_notif_seqno_skipped(
1117 #endif /* ifndef FABRICD */
1118 lsp_inc_seqno(lsp
, hdr
.seqno
);
1119 lsp_flood_or_update(lsp
, NULL
,
1122 isis_tx_queue_add(circuit
->tx_queue
,
1123 lsp
, TX_LSP_NORMAL
);
1124 ISIS_CLEAR_FLAG(lsp
->SSNflags
, circuit
);
1126 if (IS_DEBUG_UPDATE_PACKETS
)
1128 "ISIS-Upd (%s): (1) "
1129 "re-originating LSP %s new seq "
1131 circuit
->area
->area_tag
,
1132 rawlspid_print(hdr
.lsp_id
),
1135 /* our own LSP with 0 remaining life time */
1137 /* send northbound notification */
1138 isis_notif_own_lsp_purge(
1139 circuit
, rawlspid_print(hdr
.lsp_id
));
1140 #endif /* ifndef FABRICD */
1145 /* 7.3.15.1 c) - If this is our own lsp and we don't have it initiate a
1147 if (memcmp(hdr
.lsp_id
, isis
->sysid
, ISIS_SYS_ID_LEN
) == 0) {
1149 /* 7.3.16.4: initiate a purge */
1150 lsp_purge_non_exist(level
, &hdr
, circuit
->area
);
1154 /* 7.3.15.1 d) - If this is our own lsp and we have it */
1156 /* In 7.3.16.1, If an Intermediate system R somewhere in the
1158 * has information that the current sequence number for source S
1160 * "greater" than that held by S, ... */
1162 if (comp
== LSP_NEWER
) {
1164 lsp_inc_seqno(lsp
, hdr
.seqno
);
1166 /* send northbound notification */
1167 isis_notif_seqno_skipped(circuit
,
1168 rawlspid_print(hdr
.lsp_id
));
1169 #endif /* ifndef FABRICD */
1170 if (IS_DEBUG_UPDATE_PACKETS
) {
1172 "ISIS-Upd (%s): (2) re-originating LSP %s new seq 0x%08" PRIx32
,
1173 circuit
->area
->area_tag
,
1174 rawlspid_print(hdr
.lsp_id
),
1177 lsp_flood(lsp
, NULL
);
1178 } else if (comp
== LSP_EQUAL
) {
1179 isis_tx_queue_del(circuit
->tx_queue
, lsp
);
1180 if (circuit
->circ_type
!= CIRCUIT_T_BROADCAST
)
1181 ISIS_SET_FLAG(lsp
->SSNflags
, circuit
);
1183 isis_tx_queue_add(circuit
->tx_queue
, lsp
,
1185 ISIS_CLEAR_FLAG(lsp
->SSNflags
, circuit
);
1188 /* 7.3.15.1 e) - This lsp originated on another system */
1190 /* 7.3.15.1 e) 1) LSP newer than the one in db or no LSP in db
1192 if ((!lsp
|| comp
== LSP_NEWER
)) {
1194 * If this lsp is a frag, need to see if we have zero
1197 struct isis_lsp
*lsp0
= NULL
;
1198 if (LSP_FRAGMENT(hdr
.lsp_id
) != 0) {
1199 uint8_t lspid
[ISIS_SYS_ID_LEN
+ 2];
1200 memcpy(lspid
, hdr
.lsp_id
, ISIS_SYS_ID_LEN
+ 1);
1201 LSP_FRAGMENT(lspid
) = 0;
1203 &circuit
->area
->lspdb
[level
- 1], lspid
);
1206 "Got lsp frag, while zero lsp not in database");
1212 lsp
= lsp_new_from_recv(
1213 &hdr
, tlvs
, circuit
->rcv_stream
, lsp0
,
1214 circuit
->area
, level
);
1216 lsp_insert(&circuit
->area
->lspdb
[level
- 1],
1218 } else /* exists, so we overwrite */
1220 lsp_update(lsp
, &hdr
, tlvs
, circuit
->rcv_stream
,
1221 circuit
->area
, level
, false);
1224 lsp_flood_or_update(lsp
, circuit
, circuit_scoped
);
1227 if (circuit
->circ_type
!= CIRCUIT_T_BROADCAST
)
1228 ISIS_SET_FLAG(lsp
->SSNflags
, circuit
);
1231 /* 7.3.15.1 e) 2) LSP equal to the one in db */
1232 else if (comp
== LSP_EQUAL
) {
1233 isis_tx_queue_del(circuit
->tx_queue
, lsp
);
1234 lsp_update(lsp
, &hdr
, tlvs
, circuit
->rcv_stream
,
1235 circuit
->area
, level
, false);
1237 if (circuit
->circ_type
!= CIRCUIT_T_BROADCAST
)
1238 ISIS_SET_FLAG(lsp
->SSNflags
, circuit
);
1240 /* 7.3.15.1 e) 3) LSP older than the one in db */
1242 isis_tx_queue_add(circuit
->tx_queue
, lsp
,
1244 ISIS_CLEAR_FLAG(lsp
->SSNflags
, circuit
);
1251 fabricd_trigger_csnp(circuit
->area
, circuit_scoped
);
1253 isis_free_tlvs(tlvs
);
1258 * Process Sequence Numbers
1260 * Section 7.3.15.2 - Action on receipt of a sequence numbers PDU
1263 static int process_snp(uint8_t pdu_type
, struct isis_circuit
*circuit
,
1264 const uint8_t *ssnpa
)
1267 size_t pdu_start
= stream_get_getp(circuit
->rcv_stream
);
1268 size_t pdu_end
= stream_get_endp(circuit
->rcv_stream
);
1269 char raw_pdu
[pdu_end
- pdu_start
];
1270 #endif /* ifndef FABRICD */
1272 bool is_csnp
= (pdu_type
== L1_COMPLETE_SEQ_NUM
1273 || pdu_type
== L2_COMPLETE_SEQ_NUM
);
1274 char typechar
= is_csnp
? 'C' : 'P';
1275 int level
= (pdu_type
== L1_COMPLETE_SEQ_NUM
1276 || pdu_type
== L1_PARTIAL_SEQ_NUM
)
1280 uint16_t pdu_len
= stream_getw(circuit
->rcv_stream
);
1281 uint8_t rem_sys_id
[ISIS_SYS_ID_LEN
];
1283 stream_get(rem_sys_id
, circuit
->rcv_stream
, ISIS_SYS_ID_LEN
);
1284 stream_forward_getp(circuit
->rcv_stream
, 1); /* Circuit ID - unused */
1286 uint8_t start_lsp_id
[ISIS_SYS_ID_LEN
+ 2] = {};
1287 uint8_t stop_lsp_id
[ISIS_SYS_ID_LEN
+ 2] = {};
1290 stream_get(start_lsp_id
, circuit
->rcv_stream
,
1291 ISIS_SYS_ID_LEN
+ 2);
1292 stream_get(stop_lsp_id
, circuit
->rcv_stream
,
1293 ISIS_SYS_ID_LEN
+ 2);
1296 if (pdu_len_validate(pdu_len
, circuit
)) {
1297 zlog_warn("Received a CSNP with bogus length %d", pdu_len
);
1298 return ISIS_WARNING
;
1301 if (IS_DEBUG_SNP_PACKETS
) {
1303 "ISIS-Snp (%s): Rcvd L%d %cSNP on %s, cirType %s, cirID %u",
1304 circuit
->area
->area_tag
, level
, typechar
,
1305 circuit
->interface
->name
,
1306 circuit_t2string(circuit
->is_type
),
1307 circuit
->circuit_id
);
1308 if (IS_DEBUG_PACKET_DUMP
)
1309 zlog_dump_data(STREAM_DATA(circuit
->rcv_stream
),
1310 stream_get_endp(circuit
->rcv_stream
));
1313 /* 7.3.15.2 a) 1 - external domain circuit will discard snp pdu */
1314 if (circuit
->ext_domain
) {
1317 "ISIS-Snp (%s): Rcvd L%d %cSNP on %s, "
1318 "skipping: circuit externalDomain = true",
1319 circuit
->area
->area_tag
, level
, typechar
,
1320 circuit
->interface
->name
);
1325 /* 7.3.15.2 a) 2,3 - manualL2OnlyMode not implemented */
1326 if (!(circuit
->is_type
& level
)) {
1328 "ISIS-Snp (%s): Rcvd L%d %cSNP on %s, "
1329 "skipping: circuit type %s does not match level %d",
1330 circuit
->area
->area_tag
, level
, typechar
,
1331 circuit
->interface
->name
,
1332 circuit_t2string(circuit
->is_type
), level
);
1337 /* 7.3.15.2 a) 4 - not applicable for CSNP only PSNPs on broadcast */
1338 if (!is_csnp
&& (circuit
->circ_type
== CIRCUIT_T_BROADCAST
)
1339 && !circuit
->u
.bc
.is_dr
[level
- 1]) {
1341 "ISIS-Snp (%s): Rcvd L%d %cSNP from %s on %s, "
1342 "skipping: we are not the DIS",
1343 circuit
->area
->area_tag
, level
, typechar
,
1344 snpa_print(ssnpa
), circuit
->interface
->name
);
1349 /* 7.3.15.2 a) 5 - need to make sure IDLength matches - already checked
1352 /* 7.3.15.2 a) 6 - maximum area match, can be ommited since we only use
1354 * - already checked */
1356 /* 7.3.15.2 a) 7 - Must check that we have an adjacency of the same
1358 /* for broadcast circuits, snpa should be compared */
1359 /* FIXME : Do we need to check SNPA? */
1360 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
) {
1361 if (!isis_adj_lookup(rem_sys_id
,
1362 circuit
->u
.bc
.adjdb
[level
- 1]))
1363 return ISIS_OK
; /* Silently discard */
1365 if (!fabricd
&& !circuit
->u
.p2p
.neighbor
) {
1366 zlog_warn("no p2p neighbor on circuit %s",
1367 circuit
->interface
->name
);
1368 return ISIS_OK
; /* Silently discard */
1372 struct isis_tlvs
*tlvs
;
1373 int retval
= ISIS_WARNING
;
1374 const char *error_log
;
1376 if (isis_unpack_tlvs(STREAM_READABLE(circuit
->rcv_stream
),
1377 circuit
->rcv_stream
, &tlvs
, &error_log
)) {
1378 zlog_warn("Something went wrong unpacking the SNP: %s",
1383 struct isis_passwd
*passwd
= (level
== IS_LEVEL_1
)
1384 ? &circuit
->area
->area_passwd
1385 : &circuit
->area
->domain_passwd
;
1386 if (CHECK_FLAG(passwd
->snp_auth
, SNP_AUTH_RECV
)) {
1387 int auth_code
= isis_tlvs_auth_is_valid(
1388 tlvs
, passwd
, circuit
->rcv_stream
, false);
1389 if (auth_code
!= ISIS_AUTH_OK
) {
1390 isis_event_auth_failure(circuit
->area
->area_tag
,
1391 "SNP authentication failure",
1394 /* send northbound notification */
1395 stream_get_from(raw_pdu
, circuit
->rcv_stream
, pdu_start
,
1396 pdu_end
- pdu_start
);
1397 if (auth_code
== ISIS_AUTH_FAILURE
) {
1398 circuit
->auth_failures
++;
1399 isis_notif_authentication_failure(circuit
,
1401 } else { /* AUTH_TYPE_FAILURE or NO_VALIDATOR */
1402 circuit
->auth_type_failures
++;
1403 isis_notif_authentication_type_failure(circuit
,
1406 #endif /* ifndef FABRICD */
1411 struct isis_lsp_entry
*entry_head
=
1412 (struct isis_lsp_entry
*)tlvs
->lsp_entries
.head
;
1414 /* debug isis snp-packets */
1415 if (IS_DEBUG_SNP_PACKETS
) {
1416 zlog_debug("ISIS-Snp (%s): Rcvd L%d %cSNP from %s on %s",
1417 circuit
->area
->area_tag
, level
, typechar
,
1418 snpa_print(ssnpa
), circuit
->interface
->name
);
1419 for (struct isis_lsp_entry
*entry
= entry_head
; entry
;
1420 entry
= entry
->next
) {
1422 "ISIS-Snp (%s): %cSNP entry %s, seq 0x%08" PRIx32
1423 ", cksum 0x%04" PRIx16
", lifetime %" PRIu16
"s",
1424 circuit
->area
->area_tag
, typechar
,
1425 rawlspid_print(entry
->id
), entry
->seqno
,
1426 entry
->checksum
, entry
->rem_lifetime
);
1430 bool resync_needed
= false;
1432 /* 7.3.15.2 b) Actions on LSP_ENTRIES reported */
1433 for (struct isis_lsp_entry
*entry
= entry_head
; entry
;
1434 entry
= entry
->next
) {
1435 struct isis_lsp
*lsp
=
1436 lsp_search(&circuit
->area
->lspdb
[level
- 1], entry
->id
);
1437 bool own_lsp
= !memcmp(entry
->id
, isis
->sysid
, ISIS_SYS_ID_LEN
);
1439 /* 7.3.15.2 b) 1) is this LSP newer */
1440 int cmp
= lsp_compare(circuit
->area
->area_tag
, lsp
,
1441 entry
->seqno
, entry
->checksum
,
1442 entry
->rem_lifetime
);
1443 /* 7.3.15.2 b) 2) if it equals, clear SRM on p2p */
1444 if (cmp
== LSP_EQUAL
) {
1445 /* if (circuit->circ_type !=
1446 * CIRCUIT_T_BROADCAST) */
1447 isis_tx_queue_del(circuit
->tx_queue
, lsp
);
1449 /* 7.3.15.2 b) 3) if it is older, clear SSN and set SRM
1451 else if (cmp
== LSP_OLDER
) {
1452 ISIS_CLEAR_FLAG(lsp
->SSNflags
, circuit
);
1453 isis_tx_queue_add(circuit
->tx_queue
, lsp
,
1456 /* 7.3.15.2 b) 4) if it is newer, set SSN and clear SRM
1460 lsp_inc_seqno(lsp
, entry
->seqno
);
1461 isis_tx_queue_add(circuit
->tx_queue
, lsp
,
1464 ISIS_SET_FLAG(lsp
->SSNflags
, circuit
);
1465 /* if (circuit->circ_type !=
1466 * CIRCUIT_T_BROADCAST) */
1467 isis_tx_queue_del(circuit
->tx_queue
, lsp
);
1468 resync_needed
= true;
1472 /* 7.3.15.2 b) 5) if it was not found, and all of those
1474 * insert it and set SSN on it */
1475 if (entry
->rem_lifetime
&& entry
->checksum
1476 && entry
->seqno
&& memcmp(entry
->id
, isis
->sysid
,
1478 struct isis_lsp
*lsp0
= NULL
;
1480 if (LSP_FRAGMENT(entry
->id
)) {
1481 uint8_t lspid
[ISIS_SYS_ID_LEN
+ 2];
1483 memcpy(lspid
, entry
->id
,
1484 ISIS_SYS_ID_LEN
+ 1);
1485 LSP_FRAGMENT(lspid
) = 0;
1487 &circuit
->area
->lspdb
[level
- 1],
1490 zlog_debug("Got lsp frag in snp, while zero not in database");
1494 lsp
= lsp_new(circuit
->area
, entry
->id
,
1495 entry
->rem_lifetime
, 0, 0,
1496 entry
->checksum
, lsp0
, level
);
1497 lsp_insert(&circuit
->area
->lspdb
[level
- 1],
1500 lsp_set_all_srmflags(lsp
, false);
1501 ISIS_SET_FLAG(lsp
->SSNflags
, circuit
);
1502 resync_needed
= true;
1507 /* 7.3.15.2 c) on CSNP set SRM for all in range which were not reported
1511 * Build a list from our own LSP db bounded with
1512 * start_lsp_id and stop_lsp_id
1514 struct list
*lsp_list
= list_new();
1515 lsp_build_list_nonzero_ht(&circuit
->area
->lspdb
[level
- 1],
1516 start_lsp_id
, stop_lsp_id
, lsp_list
);
1518 /* Fixme: Find a better solution */
1519 struct listnode
*node
, *nnode
;
1520 struct isis_lsp
*lsp
;
1521 for (struct isis_lsp_entry
*entry
= entry_head
; entry
;
1522 entry
= entry
->next
) {
1523 for (ALL_LIST_ELEMENTS(lsp_list
, node
, nnode
, lsp
)) {
1524 if (lsp_id_cmp(lsp
->hdr
.lsp_id
, entry
->id
)
1526 list_delete_node(lsp_list
, node
);
1532 /* on remaining LSPs we set SRM (neighbor knew not of) */
1533 for (ALL_LIST_ELEMENTS_RO(lsp_list
, node
, lsp
)) {
1534 isis_tx_queue_add(circuit
->tx_queue
, lsp
, TX_LSP_NORMAL
);
1535 resync_needed
= true;
1539 list_delete(&lsp_list
);
1542 if (fabricd_initial_sync_is_complete(circuit
->area
) && resync_needed
)
1543 zlog_warn("OpenFabric: Needed to resync LSPDB using CSNP!");
1547 isis_free_tlvs(tlvs
);
1551 static int pdu_size(uint8_t pdu_type
, uint8_t *size
)
1556 *size
= ISIS_LANHELLO_HDRLEN
;
1559 *size
= ISIS_P2PHELLO_HDRLEN
;
1564 *size
= ISIS_LSP_HDR_LEN
;
1566 case L1_COMPLETE_SEQ_NUM
:
1567 case L2_COMPLETE_SEQ_NUM
:
1568 *size
= ISIS_CSNP_HDRLEN
;
1570 case L1_PARTIAL_SEQ_NUM
:
1571 case L2_PARTIAL_SEQ_NUM
:
1572 *size
= ISIS_PSNP_HDRLEN
;
1577 *size
+= ISIS_FIXED_HDR_LEN
;
1585 int isis_handle_pdu(struct isis_circuit
*circuit
, uint8_t *ssnpa
)
1587 int retval
= ISIS_OK
;
1588 size_t pdu_start
= stream_get_getp(circuit
->rcv_stream
);
1589 size_t pdu_end
= stream_get_endp(circuit
->rcv_stream
);
1590 char raw_pdu
[pdu_end
- pdu_start
];
1592 stream_get_from(raw_pdu
, circuit
->rcv_stream
, pdu_start
,
1593 pdu_end
- pdu_start
);
1595 /* Verify that at least the 8 bytes fixed header have been received */
1596 if (stream_get_endp(circuit
->rcv_stream
) < ISIS_FIXED_HDR_LEN
) {
1597 flog_err(EC_ISIS_PACKET
, "PDU is too short to be IS-IS.");
1601 uint8_t idrp
= stream_getc(circuit
->rcv_stream
);
1602 uint8_t length
= stream_getc(circuit
->rcv_stream
);
1603 uint8_t version1
= stream_getc(circuit
->rcv_stream
);
1604 uint8_t id_len
= stream_getc(circuit
->rcv_stream
);
1605 uint8_t pdu_type
= stream_getc(circuit
->rcv_stream
)
1606 & 0x1f; /* bits 6-8 are reserved */
1607 uint8_t version2
= stream_getc(circuit
->rcv_stream
);
1609 stream_forward_getp(circuit
->rcv_stream
, 1); /* reserved */
1610 uint8_t max_area_addrs
= stream_getc(circuit
->rcv_stream
);
1612 pdu_counter_count(circuit
->area
->pdu_rx_counters
, pdu_type
);
1614 if (idrp
== ISO9542_ESIS
) {
1615 flog_err(EC_LIB_DEVELOPMENT
,
1616 "No support for ES-IS packet IDRP=%" PRIx8
, idrp
);
1620 if (idrp
!= ISO10589_ISIS
) {
1621 flog_err(EC_ISIS_PACKET
, "Not an IS-IS packet IDRP=%" PRIx8
,
1626 if (version1
!= 1) {
1627 zlog_warn("Unsupported ISIS version %" PRIu8
, version1
);
1629 /* send northbound notification */
1630 isis_notif_version_skew(circuit
, version1
, raw_pdu
);
1631 #endif /* ifndef FABRICD */
1632 return ISIS_WARNING
;
1635 if (id_len
!= 0 && id_len
!= ISIS_SYS_ID_LEN
) {
1638 "IDFieldLengthMismatch: ID Length field in a received PDU %" PRIu8
1639 ", while the parameter for this IS is %u",
1640 id_len
, ISIS_SYS_ID_LEN
);
1641 circuit
->id_len_mismatches
++;
1643 /* send northbound notification */
1644 isis_notif_id_len_mismatch(circuit
, id_len
, raw_pdu
);
1645 #endif /* ifndef FABRICD */
1649 uint8_t expected_length
;
1650 if (pdu_size(pdu_type
, &expected_length
)) {
1651 zlog_warn("Unsupported ISIS PDU %" PRIu8
, pdu_type
);
1652 return ISIS_WARNING
;
1655 if (length
!= expected_length
) {
1656 flog_err(EC_ISIS_PACKET
,
1657 "Expected fixed header length = %" PRIu8
1659 expected_length
, length
);
1663 if (stream_get_endp(circuit
->rcv_stream
) < length
) {
1666 "PDU is too short to contain fixed header of given PDU type.");
1670 if (version2
!= 1) {
1671 zlog_warn("Unsupported ISIS PDU version %" PRIu8
, version2
);
1673 /* send northbound notification */
1674 isis_notif_version_skew(circuit
, version2
, raw_pdu
);
1675 #endif /* ifndef FABRICD */
1676 return ISIS_WARNING
;
1679 if (circuit
->is_passive
) {
1680 zlog_warn("Received ISIS PDU on passive circuit %s",
1681 circuit
->interface
->name
);
1682 return ISIS_WARNING
;
1686 if (pdu_type
!= FS_LINK_STATE
/* FS PDU doesn't contain max area addr field */
1687 && max_area_addrs
!= 0
1688 && max_area_addrs
!= isis
->max_area_addrs
) {
1691 "maximumAreaAddressesMismatch: maximumAreaAdresses in a received PDU %" PRIu8
1692 " while the parameter for this IS is %u",
1693 max_area_addrs
, isis
->max_area_addrs
);
1694 circuit
->max_area_addr_mismatches
++;
1696 /* send northbound notification */
1697 isis_notif_max_area_addr_mismatch(circuit
, max_area_addrs
,
1699 #endif /* ifndef FABRICD */
1707 if (fabricd
&& pdu_type
!= P2P_HELLO
)
1709 retval
= process_hello(pdu_type
, circuit
, ssnpa
);
1715 && pdu_type
!= L2_LINK_STATE
1716 && pdu_type
!= FS_LINK_STATE
)
1718 retval
= process_lsp(pdu_type
, circuit
, ssnpa
, max_area_addrs
);
1720 case L1_COMPLETE_SEQ_NUM
:
1721 case L2_COMPLETE_SEQ_NUM
:
1722 case L1_PARTIAL_SEQ_NUM
:
1723 case L2_PARTIAL_SEQ_NUM
:
1724 retval
= process_snp(pdu_type
, circuit
, ssnpa
);
1733 int isis_receive(struct thread
*thread
)
1735 struct isis_circuit
*circuit
;
1736 uint8_t ssnpa
[ETH_ALEN
];
1742 circuit
= THREAD_ARG(thread
);
1745 circuit
->t_read
= NULL
;
1747 isis_circuit_stream(circuit
, &circuit
->rcv_stream
);
1749 retval
= circuit
->rx(circuit
, ssnpa
);
1751 #if ISIS_METHOD != ISIS_METHOD_BPF
1752 if (retval
== ISIS_OK
)
1753 retval
= isis_handle_pdu(circuit
, ssnpa
);
1754 #endif //ISIS_METHOD != ISIS_METHOD_BPF
1757 * prepare for next packet.
1759 if (!circuit
->is_passive
)
1760 isis_circuit_prepare(circuit
);
1768 void fill_fixed_hdr(uint8_t pdu_type
, struct stream
*stream
)
1772 if (pdu_size(pdu_type
, &length
))
1773 assert(!"Unknown PDU Type");
1775 stream_putc(stream
, ISO10589_ISIS
); /* IDRP */
1776 stream_putc(stream
, length
); /* Length of fixed header */
1777 stream_putc(stream
, 1); /* Version/Protocol ID Extension 1 */
1778 stream_putc(stream
, 0); /* ID Length, 0 => 6 */
1779 stream_putc(stream
, pdu_type
);
1780 stream_putc(stream
, 1); /* Subversion */
1781 stream_putc(stream
, 0); /* Reserved */
1782 stream_putc(stream
, 0); /* Max Area Addresses 0 => 3 */
1785 static uint8_t hello_pdu_type(struct isis_circuit
*circuit
, int level
)
1787 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
)
1788 return (level
== IS_LEVEL_1
) ? L1_LAN_HELLO
: L2_LAN_HELLO
;
1793 static void put_hello_hdr(struct isis_circuit
*circuit
, int level
,
1794 size_t *len_pointer
)
1796 uint8_t pdu_type
= hello_pdu_type(circuit
, level
);
1798 isis_circuit_stream(circuit
, &circuit
->snd_stream
);
1799 fill_fixed_hdr(pdu_type
, circuit
->snd_stream
);
1801 stream_putc(circuit
->snd_stream
, circuit
->is_type
);
1802 stream_put(circuit
->snd_stream
, circuit
->area
->isis
->sysid
,
1805 uint32_t holdtime
= circuit
->hello_multiplier
[level
- 1]
1806 * circuit
->hello_interval
[level
- 1];
1808 if (holdtime
> 0xffff)
1811 stream_putw(circuit
->snd_stream
, holdtime
);
1812 *len_pointer
= stream_get_endp(circuit
->snd_stream
);
1813 stream_putw(circuit
->snd_stream
, 0); /* length is filled in later */
1815 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
) {
1816 uint8_t *desig_is
= (level
== IS_LEVEL_1
)
1817 ? circuit
->u
.bc
.l1_desig_is
1818 : circuit
->u
.bc
.l2_desig_is
;
1819 stream_putc(circuit
->snd_stream
, circuit
->priority
[level
- 1]);
1820 stream_put(circuit
->snd_stream
, desig_is
, ISIS_SYS_ID_LEN
+ 1);
1822 stream_putc(circuit
->snd_stream
, circuit
->circuit_id
);
1826 int send_hello(struct isis_circuit
*circuit
, int level
)
1831 if (circuit
->is_passive
)
1834 if (circuit
->interface
->mtu
== 0) {
1835 zlog_warn("circuit has zero MTU");
1836 return ISIS_WARNING
;
1839 put_hello_hdr(circuit
, level
, &len_pointer
);
1841 struct isis_tlvs
*tlvs
= isis_alloc_tlvs();
1843 isis_tlvs_add_auth(tlvs
, &circuit
->passwd
);
1845 if (!listcount(circuit
->area
->area_addrs
)) {
1846 isis_free_tlvs(tlvs
);
1847 return ISIS_WARNING
;
1850 isis_tlvs_add_area_addresses(tlvs
, circuit
->area
->area_addrs
);
1852 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
) {
1853 isis_tlvs_add_lan_neighbors(
1854 tlvs
, circuit
->u
.bc
.lan_neighs
[level
- 1]);
1855 } else if (circuit
->circ_type
== CIRCUIT_T_P2P
1856 && !circuit
->disable_threeway_adj
) {
1857 uint32_t ext_circuit_id
= circuit
->idx
;
1858 if (circuit
->u
.p2p
.neighbor
) {
1859 uint8_t threeway_state
;
1861 if (fabricd_initial_sync_is_in_progress(circuit
->area
)
1862 && fabricd_initial_sync_circuit(circuit
->area
) != circuit
)
1863 threeway_state
= ISIS_THREEWAY_DOWN
;
1865 threeway_state
= circuit
->u
.p2p
.neighbor
->threeway_state
;
1866 isis_tlvs_add_threeway_adj(tlvs
,
1869 circuit
->u
.p2p
.neighbor
->sysid
,
1870 circuit
->u
.p2p
.neighbor
->ext_circuit_id
);
1872 isis_tlvs_add_threeway_adj(tlvs
,
1879 isis_tlvs_set_protocols_supported(tlvs
, &circuit
->nlpids
);
1884 * TLV gets included if no topology is enabled on the interface,
1885 * if one topology other than #0 is enabled, or if multiple topologies
1888 struct isis_circuit_mt_setting
**mt_settings
;
1889 unsigned int mt_count
;
1891 mt_settings
= circuit_mt_settings(circuit
, &mt_count
);
1892 if (mt_count
== 0 && area_is_mt(circuit
->area
)) {
1893 tlvs
->mt_router_info_empty
= true;
1894 } else if ((mt_count
== 1
1895 && mt_settings
[0]->mtid
!= ISIS_MT_IPV4_UNICAST
)
1896 || (mt_count
> 1)) {
1897 for (unsigned int i
= 0; i
< mt_count
; i
++)
1898 isis_tlvs_add_mt_router_info(tlvs
, mt_settings
[i
]->mtid
,
1902 if (circuit
->ip_router
) {
1903 struct list
*circuit_ip_addrs
= fabricd_ip_addrs(circuit
);
1905 if (circuit_ip_addrs
)
1906 isis_tlvs_add_ipv4_addresses(tlvs
, circuit_ip_addrs
);
1909 if (circuit
->ipv6_router
&& circuit
->ipv6_link
)
1910 isis_tlvs_add_ipv6_addresses(tlvs
, circuit
->ipv6_link
);
1912 if (isis_pack_tlvs(tlvs
, circuit
->snd_stream
, len_pointer
,
1913 circuit
->pad_hellos
, false)) {
1914 isis_free_tlvs(tlvs
);
1915 return ISIS_WARNING
; /* XXX: Maybe Log TLV structure? */
1918 if (IS_DEBUG_ADJ_PACKETS
) {
1919 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
) {
1921 "ISIS-Adj (%s): Sending L%d LAN IIH on %s, length %zd",
1922 circuit
->area
->area_tag
, level
,
1923 circuit
->interface
->name
,
1924 stream_get_endp(circuit
->snd_stream
));
1927 "ISIS-Adj (%s): Sending P2P IIH on %s, length %zd",
1928 circuit
->area
->area_tag
,
1929 circuit
->interface
->name
,
1930 stream_get_endp(circuit
->snd_stream
));
1932 if (IS_DEBUG_PACKET_DUMP
)
1933 zlog_dump_data(STREAM_DATA(circuit
->snd_stream
),
1934 stream_get_endp(circuit
->snd_stream
));
1937 isis_free_tlvs(tlvs
);
1939 pdu_counter_count(circuit
->area
->pdu_tx_counters
,
1940 hello_pdu_type(circuit
, level
));
1941 retval
= circuit
->tx(circuit
, level
);
1942 if (retval
!= ISIS_OK
)
1943 flog_err(EC_ISIS_PACKET
,
1944 "ISIS-Adj (%s): Send L%d IIH on %s failed",
1945 circuit
->area
->area_tag
, level
,
1946 circuit
->interface
->name
);
1951 static int send_hello_cb(struct thread
*thread
)
1953 struct isis_circuit_arg
*arg
= THREAD_ARG(thread
);
1956 struct isis_circuit
*circuit
= arg
->circuit
;
1957 int level
= arg
->level
;
1961 if (circuit
->circ_type
== CIRCUIT_T_P2P
) {
1962 circuit
->u
.p2p
.t_send_p2p_hello
= NULL
;
1963 send_hello(circuit
, 1);
1964 send_hello_sched(circuit
, ISIS_LEVEL1
,
1965 1000 * circuit
->hello_interval
[1]);
1969 if (circuit
->circ_type
!= CIRCUIT_T_BROADCAST
) {
1970 zlog_warn("ISIS-Hello (%s): Trying to send hello on unknown circuit type %d",
1971 circuit
->area
->area_tag
, circuit
->circ_type
);
1972 return ISIS_WARNING
;
1975 circuit
->u
.bc
.t_send_lan_hello
[level
- 1] = NULL
;
1976 if (!(circuit
->is_type
& level
)) {
1977 zlog_warn("ISIS-Hello (%s): Trying to send L%d IIH in L%d-only circuit",
1978 circuit
->area
->area_tag
, level
, 3 - level
);
1979 return ISIS_WARNING
;
1982 if (circuit
->u
.bc
.run_dr_elect
[level
- 1])
1983 isis_dr_elect(circuit
, level
);
1985 int rv
= send_hello(circuit
, level
);
1987 /* set next timer thread */
1988 send_hello_sched(circuit
, level
, 1000 * circuit
->hello_interval
[level
- 1]);
1992 static void _send_hello_sched(struct isis_circuit
*circuit
,
1993 struct thread
**threadp
,
1994 int level
, long delay
)
1997 if (thread_timer_remain_msec(*threadp
) < (unsigned long)delay
)
2000 thread_cancel(*threadp
);
2003 thread_add_timer_msec(master
, send_hello_cb
,
2004 &circuit
->level_arg
[level
- 1],
2005 isis_jitter(delay
, IIH_JITTER
),
2009 void send_hello_sched(struct isis_circuit
*circuit
, int level
, long delay
)
2011 if (circuit
->circ_type
== CIRCUIT_T_P2P
) {
2012 _send_hello_sched(circuit
, &circuit
->u
.p2p
.t_send_p2p_hello
,
2013 ISIS_LEVEL1
, delay
);
2017 if (circuit
->circ_type
!= CIRCUIT_T_BROADCAST
) {
2018 zlog_warn("%s: encountered unknown circuit type %d on %s",
2019 __func__
, circuit
->circ_type
,
2020 circuit
->interface
->name
);
2024 for (int loop_level
= ISIS_LEVEL1
; loop_level
<= ISIS_LEVEL2
; loop_level
++) {
2025 if (!(loop_level
& level
))
2030 &circuit
->u
.bc
.t_send_lan_hello
[loop_level
- 1],
2039 * Count the maximum number of lsps that can be accomodated by a given size.
2041 #define LSP_ENTRIES_LEN (10 + ISIS_SYS_ID_LEN)
2042 static uint16_t get_max_lsp_count(uint16_t size
)
2046 uint16_t remaining_size
;
2048 /* First count the full size TLVs */
2049 tlv_count
= size
/ MAX_LSP_ENTRIES_TLV_SIZE
;
2050 lsp_count
= tlv_count
* (MAX_LSP_ENTRIES_TLV_SIZE
/ LSP_ENTRIES_LEN
);
2052 /* The last TLV, if any */
2053 remaining_size
= size
% MAX_LSP_ENTRIES_TLV_SIZE
;
2054 if (remaining_size
- 2 >= LSP_ENTRIES_LEN
)
2055 lsp_count
+= (remaining_size
- 2) / LSP_ENTRIES_LEN
;
2060 int send_csnp(struct isis_circuit
*circuit
, int level
)
2062 if (lspdb_count(&circuit
->area
->lspdb
[level
- 1]) == 0)
2065 uint8_t pdu_type
= (level
== ISIS_LEVEL1
) ? L1_COMPLETE_SEQ_NUM
2066 : L2_COMPLETE_SEQ_NUM
;
2068 isis_circuit_stream(circuit
, &circuit
->snd_stream
);
2069 fill_fixed_hdr(pdu_type
, circuit
->snd_stream
);
2071 size_t len_pointer
= stream_get_endp(circuit
->snd_stream
);
2072 stream_putw(circuit
->snd_stream
, 0);
2073 stream_put(circuit
->snd_stream
, isis
->sysid
, ISIS_SYS_ID_LEN
);
2074 /* with zero circuit id - ref 9.10, 9.11 */
2075 stream_putc(circuit
->snd_stream
, 0);
2077 size_t start_pointer
= stream_get_endp(circuit
->snd_stream
);
2078 stream_put(circuit
->snd_stream
, 0, ISIS_SYS_ID_LEN
+ 2);
2079 size_t end_pointer
= stream_get_endp(circuit
->snd_stream
);
2080 stream_put(circuit
->snd_stream
, 0, ISIS_SYS_ID_LEN
+ 2);
2082 struct isis_passwd
*passwd
= (level
== ISIS_LEVEL1
)
2083 ? &circuit
->area
->area_passwd
2084 : &circuit
->area
->domain_passwd
;
2086 struct isis_tlvs
*tlvs
= isis_alloc_tlvs();
2088 if (CHECK_FLAG(passwd
->snp_auth
, SNP_AUTH_SEND
))
2089 isis_tlvs_add_auth(tlvs
, passwd
);
2091 size_t tlv_start
= stream_get_endp(circuit
->snd_stream
);
2092 if (isis_pack_tlvs(tlvs
, circuit
->snd_stream
, len_pointer
, false,
2094 isis_free_tlvs(tlvs
);
2095 return ISIS_WARNING
;
2097 isis_free_tlvs(tlvs
);
2100 get_max_lsp_count(STREAM_WRITEABLE(circuit
->snd_stream
));
2102 uint8_t start
[ISIS_SYS_ID_LEN
+ 2];
2103 memset(start
, 0x00, ISIS_SYS_ID_LEN
+ 2);
2104 uint8_t stop
[ISIS_SYS_ID_LEN
+ 2];
2105 memset(stop
, 0xff, ISIS_SYS_ID_LEN
+ 2);
2109 tlvs
= isis_alloc_tlvs();
2110 if (CHECK_FLAG(passwd
->snp_auth
, SNP_AUTH_SEND
))
2111 isis_tlvs_add_auth(tlvs
, passwd
);
2113 struct isis_lsp
*last_lsp
;
2114 isis_tlvs_add_csnp_entries(tlvs
, start
, stop
, num_lsps
,
2115 &circuit
->area
->lspdb
[level
- 1],
2118 * Update the stop lsp_id before encoding this CSNP.
2120 if (tlvs
->lsp_entries
.count
< num_lsps
) {
2121 memset(stop
, 0xff, ISIS_SYS_ID_LEN
+ 2);
2123 memcpy(stop
, last_lsp
->hdr
.lsp_id
, sizeof(stop
));
2126 memcpy(STREAM_DATA(circuit
->snd_stream
) + start_pointer
, start
,
2127 ISIS_SYS_ID_LEN
+ 2);
2128 memcpy(STREAM_DATA(circuit
->snd_stream
) + end_pointer
, stop
,
2129 ISIS_SYS_ID_LEN
+ 2);
2130 stream_set_endp(circuit
->snd_stream
, tlv_start
);
2131 if (isis_pack_tlvs(tlvs
, circuit
->snd_stream
, len_pointer
,
2133 isis_free_tlvs(tlvs
);
2134 return ISIS_WARNING
;
2137 if (IS_DEBUG_SNP_PACKETS
) {
2139 "ISIS-Snp (%s): Sending L%d CSNP on %s, length %zd",
2140 circuit
->area
->area_tag
, level
,
2141 circuit
->interface
->name
,
2142 stream_get_endp(circuit
->snd_stream
));
2143 log_multiline(LOG_DEBUG
, " ", "%s",
2144 isis_format_tlvs(tlvs
));
2145 if (IS_DEBUG_PACKET_DUMP
)
2147 STREAM_DATA(circuit
->snd_stream
),
2148 stream_get_endp(circuit
->snd_stream
));
2151 pdu_counter_count(circuit
->area
->pdu_tx_counters
, pdu_type
);
2152 int retval
= circuit
->tx(circuit
, level
);
2153 if (retval
!= ISIS_OK
) {
2154 flog_err(EC_ISIS_PACKET
,
2155 "ISIS-Snp (%s): Send L%d CSNP on %s failed",
2156 circuit
->area
->area_tag
, level
,
2157 circuit
->interface
->name
);
2158 isis_free_tlvs(tlvs
);
2163 * Start lsp_id of the next CSNP should be one plus the
2164 * stop lsp_id in this current CSNP.
2166 memcpy(start
, stop
, ISIS_SYS_ID_LEN
+ 2);
2168 for (int i
= ISIS_SYS_ID_LEN
+ 1; i
>= 0; --i
) {
2169 if (start
[i
] < (uint8_t)0xff) {
2175 memset(stop
, 0xff, ISIS_SYS_ID_LEN
+ 2);
2176 isis_free_tlvs(tlvs
);
2182 int send_l1_csnp(struct thread
*thread
)
2184 struct isis_circuit
*circuit
;
2186 circuit
= THREAD_ARG(thread
);
2189 circuit
->t_send_csnp
[0] = NULL
;
2191 if ((circuit
->circ_type
== CIRCUIT_T_BROADCAST
2192 && circuit
->u
.bc
.is_dr
[0])
2193 || circuit
->circ_type
== CIRCUIT_T_P2P
) {
2194 send_csnp(circuit
, 1);
2196 /* set next timer thread */
2197 thread_add_timer(master
, send_l1_csnp
, circuit
,
2198 isis_jitter(circuit
->csnp_interval
[0], CSNP_JITTER
),
2199 &circuit
->t_send_csnp
[0]);
2204 int send_l2_csnp(struct thread
*thread
)
2206 struct isis_circuit
*circuit
;
2208 circuit
= THREAD_ARG(thread
);
2211 circuit
->t_send_csnp
[1] = NULL
;
2213 if ((circuit
->circ_type
== CIRCUIT_T_BROADCAST
2214 && circuit
->u
.bc
.is_dr
[1])
2215 || circuit
->circ_type
== CIRCUIT_T_P2P
) {
2216 send_csnp(circuit
, 2);
2218 /* set next timer thread */
2219 thread_add_timer(master
, send_l2_csnp
, circuit
,
2220 isis_jitter(circuit
->csnp_interval
[1], CSNP_JITTER
),
2221 &circuit
->t_send_csnp
[1]);
2227 * 7.3.15.4 action on expiration of partial SNP interval
2230 static int send_psnp(int level
, struct isis_circuit
*circuit
)
2232 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
2233 && circuit
->u
.bc
.is_dr
[level
- 1])
2236 if (lspdb_count(&circuit
->area
->lspdb
[level
- 1]) == 0)
2239 if (!circuit
->snd_stream
)
2242 uint8_t pdu_type
= (level
== ISIS_LEVEL1
) ? L1_PARTIAL_SEQ_NUM
2243 : L2_PARTIAL_SEQ_NUM
;
2245 isis_circuit_stream(circuit
, &circuit
->snd_stream
);
2246 fill_fixed_hdr(pdu_type
, circuit
->snd_stream
);
2248 size_t len_pointer
= stream_get_endp(circuit
->snd_stream
);
2249 stream_putw(circuit
->snd_stream
, 0); /* length is filled in later */
2250 stream_put(circuit
->snd_stream
, isis
->sysid
, ISIS_SYS_ID_LEN
);
2251 stream_putc(circuit
->snd_stream
, circuit
->idx
);
2253 struct isis_passwd
*passwd
= (level
== ISIS_LEVEL1
)
2254 ? &circuit
->area
->area_passwd
2255 : &circuit
->area
->domain_passwd
;
2257 struct isis_tlvs
*tlvs
= isis_alloc_tlvs();
2259 if (CHECK_FLAG(passwd
->snp_auth
, SNP_AUTH_SEND
))
2260 isis_tlvs_add_auth(tlvs
, passwd
);
2262 size_t tlv_start
= stream_get_endp(circuit
->snd_stream
);
2263 if (isis_pack_tlvs(tlvs
, circuit
->snd_stream
, len_pointer
, false,
2265 isis_free_tlvs(tlvs
);
2266 return ISIS_WARNING
;
2268 isis_free_tlvs(tlvs
);
2271 get_max_lsp_count(STREAM_WRITEABLE(circuit
->snd_stream
));
2274 struct isis_lsp
*lsp
;
2276 tlvs
= isis_alloc_tlvs();
2277 if (CHECK_FLAG(passwd
->snp_auth
, SNP_AUTH_SEND
))
2278 isis_tlvs_add_auth(tlvs
, passwd
);
2280 frr_each (lspdb
, &circuit
->area
->lspdb
[level
- 1], lsp
) {
2281 if (ISIS_CHECK_FLAG(lsp
->SSNflags
, circuit
))
2282 isis_tlvs_add_lsp_entry(tlvs
, lsp
);
2284 if (tlvs
->lsp_entries
.count
== num_lsps
)
2288 if (!tlvs
->lsp_entries
.count
) {
2289 isis_free_tlvs(tlvs
);
2293 stream_set_endp(circuit
->snd_stream
, tlv_start
);
2294 if (isis_pack_tlvs(tlvs
, circuit
->snd_stream
, len_pointer
,
2296 isis_free_tlvs(tlvs
);
2297 return ISIS_WARNING
;
2300 if (IS_DEBUG_SNP_PACKETS
) {
2302 "ISIS-Snp (%s): Sending L%d PSNP on %s, length %zd",
2303 circuit
->area
->area_tag
, level
,
2304 circuit
->interface
->name
,
2305 stream_get_endp(circuit
->snd_stream
));
2306 log_multiline(LOG_DEBUG
, " ", "%s",
2307 isis_format_tlvs(tlvs
));
2308 if (IS_DEBUG_PACKET_DUMP
)
2310 STREAM_DATA(circuit
->snd_stream
),
2311 stream_get_endp(circuit
->snd_stream
));
2314 pdu_counter_count(circuit
->area
->pdu_tx_counters
, pdu_type
);
2315 int retval
= circuit
->tx(circuit
, level
);
2316 if (retval
!= ISIS_OK
) {
2317 flog_err(EC_ISIS_PACKET
,
2318 "ISIS-Snp (%s): Send L%d PSNP on %s failed",
2319 circuit
->area
->area_tag
, level
,
2320 circuit
->interface
->name
);
2321 isis_free_tlvs(tlvs
);
2326 * sending succeeded, we can clear SSN flags of this circuit
2327 * for the LSPs in list
2329 struct isis_lsp_entry
*entry_head
;
2330 entry_head
= (struct isis_lsp_entry
*)tlvs
->lsp_entries
.head
;
2331 for (struct isis_lsp_entry
*entry
= entry_head
; entry
;
2332 entry
= entry
->next
)
2333 ISIS_CLEAR_FLAG(entry
->lsp
->SSNflags
, circuit
);
2334 isis_free_tlvs(tlvs
);
2340 int send_l1_psnp(struct thread
*thread
)
2343 struct isis_circuit
*circuit
;
2345 circuit
= THREAD_ARG(thread
);
2348 circuit
->t_send_psnp
[0] = NULL
;
2350 send_psnp(1, circuit
);
2351 /* set next timer thread */
2352 thread_add_timer(master
, send_l1_psnp
, circuit
,
2353 isis_jitter(circuit
->psnp_interval
[0], PSNP_JITTER
),
2354 &circuit
->t_send_psnp
[0]);
2360 * 7.3.15.4 action on expiration of partial SNP interval
2363 int send_l2_psnp(struct thread
*thread
)
2365 struct isis_circuit
*circuit
;
2367 circuit
= THREAD_ARG(thread
);
2370 circuit
->t_send_psnp
[1] = NULL
;
2372 send_psnp(2, circuit
);
2374 /* set next timer thread */
2375 thread_add_timer(master
, send_l2_psnp
, circuit
,
2376 isis_jitter(circuit
->psnp_interval
[1], PSNP_JITTER
),
2377 &circuit
->t_send_psnp
[1]);
2383 * ISO 10589 - 7.3.14.3
2385 void send_lsp(struct isis_circuit
*circuit
, struct isis_lsp
*lsp
,
2386 enum isis_tx_type tx_type
)
2389 int retval
= ISIS_OK
;
2391 if (circuit
->state
!= C_STATE_UP
|| circuit
->is_passive
== 1)
2395 * Do not send if levels do not match
2397 if (!(lsp
->level
& circuit
->is_type
))
2401 * Do not send if we do not have adjacencies in state up on the circuit
2403 if (circuit
->upadjcount
[lsp
->level
- 1] == 0)
2406 /* stream_copy will assert and stop program execution if LSP is larger
2408 * the circuit's MTU. So handle and log this case here. */
2409 if (stream_get_endp(lsp
->pdu
) > stream_get_size(circuit
->snd_stream
)) {
2412 "ISIS-Upd (%s): Can't send L%d LSP %s, seq 0x%08" PRIx32
2413 ", cksum 0x%04" PRIx16
", lifetime %" PRIu16
2414 "s on %s. LSP Size is %zu while interface stream size is %zu.",
2415 circuit
->area
->area_tag
, lsp
->level
,
2416 rawlspid_print(lsp
->hdr
.lsp_id
), lsp
->hdr
.seqno
,
2417 lsp
->hdr
.checksum
, lsp
->hdr
.rem_lifetime
,
2418 circuit
->interface
->name
, stream_get_endp(lsp
->pdu
),
2419 stream_get_size(circuit
->snd_stream
));
2421 /* send a northbound notification */
2422 isis_notif_lsp_too_large(circuit
, stream_get_endp(lsp
->pdu
),
2423 rawlspid_print(lsp
->hdr
.lsp_id
));
2424 #endif /* ifndef FABRICD */
2425 if (IS_DEBUG_PACKET_DUMP
)
2426 zlog_dump_data(STREAM_DATA(lsp
->pdu
),
2427 stream_get_endp(lsp
->pdu
));
2428 retval
= ISIS_ERROR
;
2432 /* copy our lsp to the send buffer */
2433 stream_copy(circuit
->snd_stream
, lsp
->pdu
);
2435 if (tx_type
== TX_LSP_CIRCUIT_SCOPED
) {
2436 stream_putc_at(circuit
->snd_stream
, 4, FS_LINK_STATE
);
2437 stream_putc_at(circuit
->snd_stream
, 7,
2438 L2_CIRCUIT_FLOODING_SCOPE
);
2441 if (IS_DEBUG_UPDATE_PACKETS
) {
2442 zlog_debug("ISIS-Upd (%s): Sending %sL%d LSP %s, seq 0x%08" PRIx32
2443 ", cksum 0x%04" PRIx16
", lifetime %" PRIu16
2445 circuit
->area
->area_tag
,
2446 (tx_type
== TX_LSP_CIRCUIT_SCOPED
)
2447 ? "Circuit scoped " : "",
2449 rawlspid_print(lsp
->hdr
.lsp_id
), lsp
->hdr
.seqno
,
2450 lsp
->hdr
.checksum
, lsp
->hdr
.rem_lifetime
,
2451 circuit
->interface
->name
);
2452 if (IS_DEBUG_PACKET_DUMP
)
2453 zlog_dump_data(STREAM_DATA(circuit
->snd_stream
),
2454 stream_get_endp(circuit
->snd_stream
));
2457 uint8_t pdu_type
= (tx_type
== TX_LSP_CIRCUIT_SCOPED
) ? FS_LINK_STATE
2458 : (lsp
->level
== ISIS_LEVEL1
) ? L1_LINK_STATE
2462 pdu_counter_count(circuit
->area
->pdu_tx_counters
, pdu_type
);
2463 retval
= circuit
->tx(circuit
, lsp
->level
);
2464 if (retval
!= ISIS_OK
) {
2465 flog_err(EC_ISIS_PACKET
,
2466 "ISIS-Upd (%s): Send L%d LSP on %s failed %s",
2467 circuit
->area
->area_tag
, lsp
->level
,
2468 circuit
->interface
->name
,
2469 (retval
== ISIS_WARNING
) ? "temporarily"
2475 || (retval
== ISIS_OK
&& circuit
->circ_type
== CIRCUIT_T_BROADCAST
)
2476 || (retval
!= ISIS_OK
&& retval
!= ISIS_WARNING
)) {
2477 /* SRM flag will trigger retransmission. We will not retransmit
2479 * encountered a fatal error.
2480 * On success, they should only be cleared if it's a broadcast
2482 * On a P2P circuit, we will wait for the ack from the neighbor
2486 isis_tx_queue_del(circuit
->tx_queue
, lsp
);