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"
62 static int ack_lsp(struct isis_lsp_hdr
*hdr
, struct isis_circuit
*circuit
,
69 (level
== IS_LEVEL_1
) ? L1_PARTIAL_SEQ_NUM
: L2_PARTIAL_SEQ_NUM
;
71 isis_circuit_stream(circuit
, &circuit
->snd_stream
);
73 fill_fixed_hdr(pdu_type
, circuit
->snd_stream
);
75 lenp
= stream_get_endp(circuit
->snd_stream
);
76 stream_putw(circuit
->snd_stream
, 0); /* PDU length */
77 stream_put(circuit
->snd_stream
, isis
->sysid
, ISIS_SYS_ID_LEN
);
78 stream_putc(circuit
->snd_stream
, circuit
->idx
);
79 stream_putc(circuit
->snd_stream
, 9); /* code */
80 stream_putc(circuit
->snd_stream
, 16); /* len */
82 stream_putw(circuit
->snd_stream
, hdr
->rem_lifetime
);
83 stream_put(circuit
->snd_stream
, hdr
->lsp_id
, ISIS_SYS_ID_LEN
+ 2);
84 stream_putl(circuit
->snd_stream
, hdr
->seqno
);
85 stream_putw(circuit
->snd_stream
, hdr
->checksum
);
87 length
= (uint16_t)stream_get_endp(circuit
->snd_stream
);
88 /* Update PDU length */
89 stream_putw_at(circuit
->snd_stream
, lenp
, length
);
91 pdu_counter_count(circuit
->area
->pdu_tx_counters
, pdu_type
);
92 retval
= circuit
->tx(circuit
, level
);
93 if (retval
!= ISIS_OK
)
94 flog_err(EC_ISIS_PACKET
,
95 "ISIS-Upd (%s): Send L%d LSP PSNP on %s failed",
96 circuit
->area
->area_tag
, level
,
97 circuit
->interface
->name
);
107 struct isis_circuit
*circuit
;
112 uint8_t sys_id
[ISIS_SYS_ID_LEN
];
119 uint8_t dis
[ISIS_SYS_ID_LEN
+ 1];
124 struct isis_tlvs
*tlvs
;
127 static int process_p2p_hello(struct iih_info
*iih
)
129 struct isis_threeway_adj
*tw_adj
= iih
->tlvs
->threeway_adj
;
131 if (tw_adj
->state
> ISIS_THREEWAY_DOWN
) {
132 if (isis
->debugs
& DEBUG_ADJ_PACKETS
) {
133 zlog_debug("ISIS-Adj (%s): Rcvd P2P IIH from (%s) with invalid three-way state: %d",
134 iih
->circuit
->area
->area_tag
,
135 iih
->circuit
->interface
->name
,
141 if (tw_adj
->neighbor_set
142 && (memcmp(tw_adj
->neighbor_id
, isis
->sysid
, ISIS_SYS_ID_LEN
)
143 || tw_adj
->neighbor_circuit_id
!= (uint32_t) iih
->circuit
->idx
)) {
145 if (isis
->debugs
& DEBUG_ADJ_PACKETS
) {
146 zlog_debug("ISIS-Adj (%s): Rcvd P2P IIH from (%s) which lists IS/Circuit different from us as neighbor.",
147 iih
->circuit
->area
->area_tag
,
148 iih
->circuit
->interface
->name
);
156 * My interpertation of the ISO, if no adj exists we will create one for
159 struct isis_adjacency
*adj
= iih
->circuit
->u
.p2p
.neighbor
;
160 /* If an adjacency exists, check it is with the source of the hello
163 if (memcmp(iih
->sys_id
, adj
->sysid
, ISIS_SYS_ID_LEN
)) {
165 "hello source and adjacency do not match, set adj down\n");
166 isis_adj_state_change(adj
, ISIS_ADJ_DOWN
,
171 if (!adj
|| adj
->level
!= iih
->circ_type
) {
173 adj
= isis_new_adj(iih
->sys_id
, NULL
, iih
->circ_type
,
176 adj
->level
= iih
->circ_type
;
178 iih
->circuit
->u
.p2p
.neighbor
= adj
;
179 /* Build lsp with the new neighbor entry when a new
180 * adjacency is formed. Set adjacency circuit type to
181 * IIH PDU header circuit type before lsp is regenerated
182 * when an adjacency is up. This will result in the new
183 * adjacency entry getting added to the lsp tlv neighbor list.
185 adj
->circuit_t
= iih
->circ_type
;
186 isis_adj_state_change(adj
, ISIS_ADJ_INITIALIZING
, NULL
);
187 adj
->sys_type
= ISIS_SYSTYPE_UNKNOWN
;
191 adj
->ext_circuit_id
= tw_adj
->local_circuit_id
;
193 /* 8.2.6 Monitoring point-to-point adjacencies */
194 adj
->hold_time
= iih
->holdtime
;
195 adj
->last_upd
= time(NULL
);
198 isis_tlvs_to_adj(iih
->tlvs
, adj
, &changed
);
199 changed
|= tlvs_to_adj_mt_set(iih
->tlvs
, iih
->v4_usable
, iih
->v6_usable
,
202 /* lets take care of the expiry */
203 THREAD_TIMER_OFF(adj
->t_expire
);
204 thread_add_timer(master
, isis_adj_expire
, adj
, (long)adj
->hold_time
,
207 /* While fabricds initial sync is in progress, ignore hellos from other
208 * interfaces than the one we are performing the initial sync on. */
209 if (fabricd_initial_sync_is_in_progress(iih
->circuit
->area
)
210 && fabricd_initial_sync_circuit(iih
->circuit
->area
) != iih
->circuit
)
213 /* 8.2.5.2 a) a match was detected */
214 if (isis_tlvs_area_addresses_match(iih
->tlvs
,
215 iih
->circuit
->area
->area_addrs
)) {
216 /* 8.2.5.2 a) 2) If the system is L1 - table 5 */
217 if (iih
->circuit
->area
->is_type
== IS_LEVEL_1
) {
218 switch (iih
->circ_type
) {
220 case IS_LEVEL_1_AND_2
:
221 if (adj
->adj_state
!= ISIS_ADJ_UP
222 || adj
->adj_usage
== ISIS_ADJ_LEVEL1
) {
223 isis_adj_process_threeway(adj
, tw_adj
,
228 if (adj
->adj_state
!= ISIS_ADJ_UP
) {
229 /* (7) reject - wrong system type event
231 zlog_warn("wrongSystemType");
233 } else if (adj
->adj_usage
== ISIS_ADJ_LEVEL1
) {
234 /* (6) down - wrong system */
235 isis_adj_state_change(adj
,
243 /* 8.2.5.2 a) 3) If the system is L1L2 - table 6 */
244 if (iih
->circuit
->area
->is_type
== IS_LEVEL_1_AND_2
) {
245 switch (iih
->circ_type
) {
247 if (adj
->adj_state
!= ISIS_ADJ_UP
248 || adj
->adj_usage
== ISIS_ADJ_LEVEL1
) {
249 isis_adj_process_threeway(adj
, tw_adj
,
251 } else if ((adj
->adj_usage
252 == ISIS_ADJ_LEVEL1AND2
)
254 == ISIS_ADJ_LEVEL2
)) {
255 /* (8) down - wrong system */
256 isis_adj_state_change(adj
,
262 if (adj
->adj_state
!= ISIS_ADJ_UP
263 || adj
->adj_usage
== ISIS_ADJ_LEVEL2
) {
264 isis_adj_process_threeway(adj
, tw_adj
,
266 } else if ((adj
->adj_usage
== ISIS_ADJ_LEVEL1
)
268 == ISIS_ADJ_LEVEL1AND2
)) {
269 /* (8) down - wrong system */
270 isis_adj_state_change(adj
,
275 case IS_LEVEL_1_AND_2
:
276 if (adj
->adj_state
!= ISIS_ADJ_UP
277 || adj
->adj_usage
== ISIS_ADJ_LEVEL1AND2
) {
278 isis_adj_process_threeway(adj
, tw_adj
,
279 ISIS_ADJ_LEVEL1AND2
);
280 } else if ((adj
->adj_usage
== ISIS_ADJ_LEVEL1
)
282 == ISIS_ADJ_LEVEL2
)) {
283 /* (8) down - wrong system */
284 isis_adj_state_change(adj
,
292 /* 8.2.5.2 a) 4) If the system is L2 - table 7 */
293 if (iih
->circuit
->area
->is_type
== IS_LEVEL_2
) {
294 switch (iih
->circ_type
) {
296 if (adj
->adj_state
!= ISIS_ADJ_UP
) {
297 /* (5) reject - wrong system type event
299 zlog_warn("wrongSystemType");
301 } else if ((adj
->adj_usage
302 == ISIS_ADJ_LEVEL1AND2
)
304 == ISIS_ADJ_LEVEL2
)) {
305 /* (6) down - wrong system */
306 isis_adj_state_change(adj
,
311 case IS_LEVEL_1_AND_2
:
313 if (adj
->adj_state
!= ISIS_ADJ_UP
314 || adj
->adj_usage
== ISIS_ADJ_LEVEL2
) {
315 isis_adj_process_threeway(adj
, tw_adj
,
317 } else if (adj
->adj_usage
318 == ISIS_ADJ_LEVEL1AND2
) {
319 /* (6) down - wrong system */
320 isis_adj_state_change(adj
,
328 /* 8.2.5.2 b) if no match was detected */
329 else if (listcount(iih
->circuit
->area
->area_addrs
) > 0) {
330 if (iih
->circuit
->area
->is_type
== IS_LEVEL_1
) {
331 /* 8.2.5.2 b) 1) is_type L1 and adj is not up */
332 if (adj
->adj_state
!= ISIS_ADJ_UP
) {
333 isis_adj_state_change(adj
, ISIS_ADJ_DOWN
,
335 /* 8.2.5.2 b) 2)is_type L1 and adj is up */
337 isis_adj_state_change(adj
, ISIS_ADJ_DOWN
,
338 "Down - Area Mismatch");
341 /* 8.2.5.2 b 3 If the system is L2 or L1L2 - table 8 */
343 switch (iih
->circ_type
) {
345 if (adj
->adj_state
!= ISIS_ADJ_UP
) {
346 /* (6) reject - Area Mismatch event */
347 zlog_warn("AreaMismatch");
349 } else if (adj
->adj_usage
== ISIS_ADJ_LEVEL1
) {
350 /* (7) down - area mismatch */
351 isis_adj_state_change(adj
,
355 } else if ((adj
->adj_usage
356 == ISIS_ADJ_LEVEL1AND2
)
358 == ISIS_ADJ_LEVEL2
)) {
359 /* (7) down - wrong system */
360 isis_adj_state_change(adj
,
365 case IS_LEVEL_1_AND_2
:
367 if (adj
->adj_state
!= ISIS_ADJ_UP
368 || adj
->adj_usage
== ISIS_ADJ_LEVEL2
) {
369 isis_adj_process_threeway(adj
, tw_adj
,
371 } else if (adj
->adj_usage
== ISIS_ADJ_LEVEL1
) {
372 /* (7) down - wrong system */
373 isis_adj_state_change(adj
,
376 } else if (adj
->adj_usage
377 == ISIS_ADJ_LEVEL1AND2
) {
378 if (iih
->circ_type
== IS_LEVEL_2
) {
379 /* (7) down - wrong system */
380 isis_adj_state_change(
384 /* (7) down - area mismatch */
385 isis_adj_state_change(
394 /* down - area mismatch */
395 isis_adj_state_change(adj
, ISIS_ADJ_DOWN
, "Area Mismatch");
398 if (adj
->adj_state
== ISIS_ADJ_UP
&& changed
) {
399 lsp_regenerate_schedule(adj
->circuit
->area
,
400 isis_adj_usage2levels(adj
->adj_usage
),
404 /* 8.2.5.2 c) if the action was up - comparing circuit IDs */
405 /* FIXME - Missing parts */
407 /* some of my own understanding of the ISO, why the heck does
408 * it not say what should I change the system_type to...
410 switch (adj
->adj_usage
) {
411 case ISIS_ADJ_LEVEL1
:
412 adj
->sys_type
= ISIS_SYSTYPE_L1_IS
;
414 case ISIS_ADJ_LEVEL2
:
415 adj
->sys_type
= ISIS_SYSTYPE_L2_IS
;
417 case ISIS_ADJ_LEVEL1AND2
:
418 adj
->sys_type
= ISIS_SYSTYPE_L2_IS
;
421 adj
->sys_type
= ISIS_SYSTYPE_UNKNOWN
;
425 if (isis
->debugs
& DEBUG_ADJ_PACKETS
) {
427 "ISIS-Adj (%s): Rcvd P2P IIH from (%s), cir type %s,"
428 " cir id %hhu, length %" PRIu16
,
429 iih
->circuit
->area
->area_tag
,
430 iih
->circuit
->interface
->name
,
431 circuit_t2string(iih
->circuit
->is_type
),
432 iih
->circuit
->circuit_id
, iih
->pdu_len
);
438 static int process_lan_hello(struct iih_info
*iih
)
440 struct isis_adjacency
*adj
;
441 adj
= isis_adj_lookup(iih
->sys_id
,
442 iih
->circuit
->u
.bc
.adjdb
[iih
->level
- 1]);
443 if ((adj
== NULL
) || (memcmp(adj
->snpa
, iih
->ssnpa
, ETH_ALEN
))
444 || (adj
->level
!= iih
->level
)) {
446 /* Do as in 8.4.2.5 */
447 adj
= isis_new_adj(iih
->sys_id
, iih
->ssnpa
, iih
->level
,
451 memcpy(adj
->snpa
, iih
->ssnpa
, 6);
453 memset(adj
->snpa
, ' ', 6);
455 adj
->level
= iih
->level
;
457 isis_adj_state_change(adj
, ISIS_ADJ_INITIALIZING
, NULL
);
459 if (iih
->level
== IS_LEVEL_1
)
460 adj
->sys_type
= ISIS_SYSTYPE_L1_IS
;
462 adj
->sys_type
= ISIS_SYSTYPE_L2_IS
;
463 list_delete_all_node(
464 iih
->circuit
->u
.bc
.lan_neighs
[iih
->level
- 1]);
465 isis_adj_build_neigh_list(
466 iih
->circuit
->u
.bc
.adjdb
[iih
->level
- 1],
467 iih
->circuit
->u
.bc
.lan_neighs
[iih
->level
- 1]);
470 if (adj
->dis_record
[iih
->level
- 1].dis
== ISIS_IS_DIS
) {
471 uint8_t *dis
= (iih
->level
== 1)
472 ? iih
->circuit
->u
.bc
.l1_desig_is
473 : iih
->circuit
->u
.bc
.l2_desig_is
;
475 if (memcmp(dis
, iih
->dis
, ISIS_SYS_ID_LEN
+ 1)) {
476 thread_add_event(master
, isis_event_dis_status_change
,
477 iih
->circuit
, 0, NULL
);
478 memcpy(dis
, iih
->dis
, ISIS_SYS_ID_LEN
+ 1);
482 adj
->circuit_t
= iih
->circ_type
;
483 adj
->hold_time
= iih
->holdtime
;
484 adj
->last_upd
= time(NULL
);
485 adj
->prio
[iih
->level
- 1] = iih
->priority
;
486 memcpy(adj
->lanid
, iih
->dis
, ISIS_SYS_ID_LEN
+ 1);
489 isis_tlvs_to_adj(iih
->tlvs
, adj
, &changed
);
490 changed
|= tlvs_to_adj_mt_set(iih
->tlvs
, iih
->v4_usable
, iih
->v6_usable
,
493 /* lets take care of the expiry */
494 THREAD_TIMER_OFF(adj
->t_expire
);
495 thread_add_timer(master
, isis_adj_expire
, adj
, (long)adj
->hold_time
,
499 * If the snpa for this circuit is found from LAN Neighbours TLV
500 * we have two-way communication -> adjacency can be put to state "up"
502 bool own_snpa_found
=
503 isis_tlvs_own_snpa_found(iih
->tlvs
, iih
->circuit
->u
.bc
.snpa
);
505 if (adj
->adj_state
!= ISIS_ADJ_UP
) {
506 if (own_snpa_found
) {
507 isis_adj_state_change(
509 "own SNPA found in LAN Neighbours TLV");
512 if (!own_snpa_found
) {
513 isis_adj_state_change(
514 adj
, ISIS_ADJ_INITIALIZING
,
515 "own SNPA not found in LAN Neighbours TLV");
519 if (adj
->adj_state
== ISIS_ADJ_UP
&& changed
)
520 lsp_regenerate_schedule(adj
->circuit
->area
, iih
->level
, 0);
522 if (isis
->debugs
& DEBUG_ADJ_PACKETS
) {
524 "ISIS-Adj (%s): Rcvd L%d LAN IIH from %s on %s, cirType %s, cirID %u, length %zd",
525 iih
->circuit
->area
->area_tag
, iih
->level
,
526 snpa_print(iih
->ssnpa
), iih
->circuit
->interface
->name
,
527 circuit_t2string(iih
->circuit
->is_type
),
528 iih
->circuit
->circuit_id
,
529 stream_get_endp(iih
->circuit
->rcv_stream
));
534 static int pdu_len_validate(uint16_t pdu_len
, struct isis_circuit
*circuit
)
536 if (pdu_len
< stream_get_getp(circuit
->rcv_stream
)
537 || pdu_len
> ISO_MTU(circuit
)
538 || pdu_len
> stream_get_endp(circuit
->rcv_stream
))
541 if (pdu_len
< stream_get_endp(circuit
->rcv_stream
))
542 stream_set_endp(circuit
->rcv_stream
, pdu_len
);
546 static int process_hello(uint8_t pdu_type
, struct isis_circuit
*circuit
,
549 /* keep a copy of the raw pdu for NB notifications */
550 size_t pdu_start
= stream_get_getp(circuit
->rcv_stream
);
551 size_t pdu_end
= stream_get_endp(circuit
->rcv_stream
);
552 char raw_pdu
[pdu_end
- pdu_start
];
553 bool p2p_hello
= (pdu_type
== P2P_HELLO
);
554 int level
= p2p_hello
? 0
555 : (pdu_type
== L1_LAN_HELLO
) ? ISIS_LEVEL1
557 const char *pdu_name
=
560 : (level
== ISIS_LEVEL1
) ? "L1 LAN IIH" : "L2 LAN IIH";
563 stream_get_from(raw_pdu
, circuit
->rcv_stream
, pdu_start
,
564 pdu_end
- pdu_start
);
565 if (isis
->debugs
& DEBUG_ADJ_PACKETS
) {
566 zlog_debug("ISIS-Adj (%s): Rcvd %s on %s, cirType %s, cirID %u",
567 circuit
->area
->area_tag
, pdu_name
,
568 circuit
->interface
->name
,
569 circuit_t2string(circuit
->is_type
),
570 circuit
->circuit_id
);
571 if (isis
->debugs
& DEBUG_PACKET_DUMP
)
572 zlog_dump_data(STREAM_DATA(circuit
->rcv_stream
),
573 stream_get_endp(circuit
->rcv_stream
));
577 if (circuit
->circ_type
!= CIRCUIT_T_P2P
) {
578 zlog_warn("p2p hello on non p2p circuit");
579 circuit
->rej_adjacencies
++;
581 isis_notif_reject_adjacency(
582 circuit
, "p2p hello on non p2p circuit",
584 #endif /* ifndef FABRICD */
588 if (circuit
->circ_type
!= CIRCUIT_T_BROADCAST
) {
589 zlog_warn("lan hello on non broadcast circuit");
590 circuit
->rej_adjacencies
++;
592 isis_notif_reject_adjacency(
593 circuit
, "lan hello on non broadcast circuit",
595 #endif /* ifndef FABRICD */
599 if (circuit
->ext_domain
) {
601 "level %d LAN Hello received over circuit with externalDomain = true",
603 circuit
->rej_adjacencies
++;
605 isis_notif_reject_adjacency(
607 "LAN Hello received over circuit with externalDomain = true",
609 #endif /* ifndef FABRICD */
613 if (!(circuit
->is_type
& level
)) {
614 if (isis
->debugs
& DEBUG_ADJ_PACKETS
) {
616 "ISIS-Adj (%s): Interface level mismatch, %s",
617 circuit
->area
->area_tag
,
618 circuit
->interface
->name
);
620 circuit
->rej_adjacencies
++;
622 isis_notif_reject_adjacency(
623 circuit
, "Interface level mismatch", raw_pdu
);
624 #endif /* ifndef FABRICD */
629 struct iih_info iih
= {
630 .circuit
= circuit
, .ssnpa
= ssnpa
, .level
= level
};
632 /* Generic IIH Header */
633 iih
.circ_type
= stream_getc(circuit
->rcv_stream
) & 0x03;
634 stream_get(iih
.sys_id
, circuit
->rcv_stream
, ISIS_SYS_ID_LEN
);
635 iih
.holdtime
= stream_getw(circuit
->rcv_stream
);
636 iih
.pdu_len
= stream_getw(circuit
->rcv_stream
);
639 iih
.circuit_id
= stream_getc(circuit
->rcv_stream
);
641 iih
.priority
= stream_getc(circuit
->rcv_stream
);
642 stream_get(iih
.dis
, circuit
->rcv_stream
, ISIS_SYS_ID_LEN
+ 1);
645 if (pdu_len_validate(iih
.pdu_len
, circuit
)) {
647 "ISIS-Adj (%s): Rcvd %s from (%s) with invalid pdu length %" PRIu16
,
648 circuit
->area
->area_tag
, pdu_name
,
649 circuit
->interface
->name
, iih
.pdu_len
);
650 circuit
->rej_adjacencies
++;
652 isis_notif_reject_adjacency(circuit
, "Invalid PDU length",
654 #endif /* ifndef FABRICD */
658 if (!p2p_hello
&& !(level
& iih
.circ_type
)) {
659 flog_err(EC_ISIS_PACKET
,
660 "Level %d LAN Hello with Circuit Type %d", level
,
662 circuit
->rej_adjacencies
++;
664 isis_notif_reject_adjacency(
665 circuit
, "LAN Hello with wrong IS-level", raw_pdu
);
666 #endif /* ifndef FABRICD */
670 const char *error_log
;
671 int retval
= ISIS_WARNING
;
673 if (isis_unpack_tlvs(STREAM_READABLE(circuit
->rcv_stream
),
674 circuit
->rcv_stream
, &iih
.tlvs
, &error_log
)) {
675 zlog_warn("isis_unpack_tlvs() failed: %s", error_log
);
676 circuit
->rej_adjacencies
++;
678 isis_notif_reject_adjacency(circuit
, "Failed to unpack TLVs",
680 #endif /* ifndef FABRICD */
684 if (!iih
.tlvs
->area_addresses
.count
) {
685 zlog_warn("No Area addresses TLV in %s", pdu_name
);
687 /* send northbound notification */
688 isis_notif_area_mismatch(circuit
, raw_pdu
);
689 #endif /* ifndef FABRICD */
693 if (!iih
.tlvs
->protocols_supported
.count
) {
694 zlog_warn("No supported protocols TLV in %s", pdu_name
);
695 circuit
->rej_adjacencies
++;
697 isis_notif_reject_adjacency(
698 circuit
, "No supported protocols TLV", raw_pdu
);
699 #endif /* ifndef FABRICD */
703 int auth_code
= isis_tlvs_auth_is_valid(iih
.tlvs
, &circuit
->passwd
,
704 circuit
->rcv_stream
, false);
705 if (auth_code
!= ISIS_AUTH_OK
) {
706 isis_event_auth_failure(circuit
->area
->area_tag
,
707 "IIH authentication failure",
710 /* send northbound notification */
711 stream_get_from(raw_pdu
, circuit
->rcv_stream
, pdu_start
,
712 pdu_end
- pdu_start
);
713 if (auth_code
== ISIS_AUTH_FAILURE
) {
714 circuit
->auth_failures
++;
715 isis_notif_authentication_failure(circuit
, raw_pdu
);
716 } else { /* AUTH_TYPE_FAILURE or NO_VALIDATOR */
717 circuit
->auth_type_failures
++;
718 isis_notif_authentication_type_failure(circuit
,
721 #endif /* ifndef FABRICD */
725 if (!memcmp(iih
.sys_id
, isis
->sysid
, ISIS_SYS_ID_LEN
)) {
727 "ISIS-Adj (%s): Received IIH with own sysid - discard",
728 circuit
->area
->area_tag
);
729 circuit
->rej_adjacencies
++;
731 isis_notif_reject_adjacency(
732 circuit
, "Received IIH with our own sysid", raw_pdu
);
733 #endif /* ifndef FABRICD */
738 && (listcount(circuit
->area
->area_addrs
) == 0
739 || (level
== ISIS_LEVEL1
740 && !isis_tlvs_area_addresses_match(
741 iih
.tlvs
, circuit
->area
->area_addrs
)))) {
742 if (isis
->debugs
& DEBUG_ADJ_PACKETS
) {
744 "ISIS-Adj (%s): Area mismatch, level %d IIH on %s",
745 circuit
->area
->area_tag
, level
,
746 circuit
->interface
->name
);
749 /* send northbound notification */
750 isis_notif_area_mismatch(circuit
, raw_pdu
);
751 #endif /* ifndef FABRICD */
755 iih
.v4_usable
= (fabricd_ip_addrs(circuit
)
756 && iih
.tlvs
->ipv4_address
.count
);
758 iih
.v6_usable
= (circuit
->ipv6_link
&& listcount(circuit
->ipv6_link
)
759 && iih
.tlvs
->ipv6_address
.count
);
761 if (!iih
.v4_usable
&& !iih
.v6_usable
) {
762 if (isis
->debugs
& DEBUG_ADJ_PACKETS
) {
764 "ISIS-Adj (%s): Neither IPv4 nor IPv6 considered usable. Ignoring IIH",
765 circuit
->area
->area_tag
);
767 circuit
->rej_adjacencies
++;
769 isis_notif_reject_adjacency(
770 circuit
, "Neither IPv4 not IPv6 considered usable",
772 #endif /* ifndef FABRICD */
776 retval
= p2p_hello
? process_p2p_hello(&iih
) : process_lan_hello(&iih
);
778 isis_free_tlvs(iih
.tlvs
);
783 static void lsp_flood_or_update(struct isis_lsp
*lsp
,
784 struct isis_circuit
*circuit
,
788 lsp_flood(lsp
, circuit
);
790 fabricd_update_lsp_no_flood(lsp
, circuit
);
794 * Process Level 1/2 Link State
796 * Section 7.3.15.1 - Action on receipt of a link state PDU
798 static int process_lsp(uint8_t pdu_type
, struct isis_circuit
*circuit
,
799 const uint8_t *ssnpa
, uint8_t max_area_addrs
)
803 size_t pdu_start
= stream_get_getp(circuit
->rcv_stream
);
804 size_t pdu_end
= stream_get_endp(circuit
->rcv_stream
);
805 char raw_pdu
[pdu_end
- pdu_start
];
807 stream_get_from(raw_pdu
, circuit
->rcv_stream
, pdu_start
,
808 pdu_end
- pdu_start
);
810 if (pdu_type
== FS_LINK_STATE
) {
813 if (max_area_addrs
!= L2_CIRCUIT_FLOODING_SCOPE
)
816 circuit_scoped
= true;
818 /* The stream is used verbatim for sending out new LSPDUs.
819 * So make sure we store it as an L2 LSPDU internally.
820 * (compare for the reverse in `send_lsp`) */
821 stream_putc_at(circuit
->rcv_stream
, 4, L2_LINK_STATE
);
822 stream_putc_at(circuit
->rcv_stream
, 7, 0);
824 if (pdu_type
== L1_LINK_STATE
)
828 circuit_scoped
= false;
831 if (isis
->debugs
& DEBUG_UPDATE_PACKETS
) {
833 "ISIS-Upd (%s): Rcvd %sL%d LSP on %s, cirType %s, cirID %u",
834 circuit
->area
->area_tag
,
835 circuit_scoped
? "Circuit scoped " : "", level
,
836 circuit
->interface
->name
,
837 circuit_t2string(circuit
->is_type
),
838 circuit
->circuit_id
);
839 if (isis
->debugs
& DEBUG_PACKET_DUMP
)
840 zlog_dump_data(STREAM_DATA(circuit
->rcv_stream
),
841 stream_get_endp(circuit
->rcv_stream
));
844 struct isis_lsp_hdr hdr
= {};
846 hdr
.pdu_len
= stream_getw(circuit
->rcv_stream
);
847 hdr
.rem_lifetime
= stream_getw(circuit
->rcv_stream
);
848 stream_get(hdr
.lsp_id
, circuit
->rcv_stream
, sizeof(hdr
.lsp_id
));
849 hdr
.seqno
= stream_getl(circuit
->rcv_stream
);
850 hdr
.checksum
= stream_getw(circuit
->rcv_stream
);
851 hdr
.lsp_bits
= stream_getc(circuit
->rcv_stream
);
854 /* send northbound notification */
855 isis_notif_lsp_received(circuit
, rawlspid_print(hdr
.lsp_id
), hdr
.seqno
,
856 time(NULL
), sysid_print(hdr
.lsp_id
));
857 #endif /* ifndef FABRICD */
859 if (pdu_len_validate(hdr
.pdu_len
, circuit
)) {
860 zlog_debug("ISIS-Upd (%s): LSP %s invalid LSP length %" PRIu16
,
861 circuit
->area
->area_tag
, rawlspid_print(hdr
.lsp_id
),
866 if (isis
->debugs
& DEBUG_UPDATE_PACKETS
) {
867 zlog_debug("ISIS-Upd (%s): Rcvd L%d LSP %s, seq 0x%08" PRIx32
868 ", cksum 0x%04" PRIx16
", lifetime %" PRIu16
869 "s, len %" PRIu16
", on %s",
870 circuit
->area
->area_tag
, level
,
871 rawlspid_print(hdr
.lsp_id
), hdr
.seqno
, hdr
.checksum
,
872 hdr
.rem_lifetime
, hdr
.pdu_len
,
873 circuit
->interface
->name
);
876 /* lsp is_type check */
877 if ((hdr
.lsp_bits
& IS_LEVEL_1
) != IS_LEVEL_1
) {
879 "ISIS-Upd (%s): LSP %s invalid LSP is type 0x%" PRIx8
,
880 circuit
->area
->area_tag
, rawlspid_print(hdr
.lsp_id
),
881 hdr
.lsp_bits
& IS_LEVEL_1_AND_2
);
882 /* continue as per RFC1122 Be liberal in what you accept, and
883 * conservative in what you send */
886 /* Checksum sanity check - FIXME: move to correct place */
887 /* 12 = sysid+pdu+remtime */
888 if (iso_csum_verify(STREAM_DATA(circuit
->rcv_stream
) + 12,
889 hdr
.pdu_len
- 12, hdr
.checksum
, 12)) {
891 "ISIS-Upd (%s): LSP %s invalid LSP checksum 0x%04" PRIx16
,
892 circuit
->area
->area_tag
, rawlspid_print(hdr
.lsp_id
),
897 /* 7.3.15.1 a) 1 - external domain circuit will discard lsps */
898 if (circuit
->ext_domain
) {
900 "ISIS-Upd (%s): LSP %s received at level %d over circuit with "
901 "externalDomain = true",
902 circuit
->area
->area_tag
, rawlspid_print(hdr
.lsp_id
),
907 /* 7.3.15.1 a) 2,3 - manualL2OnlyMode not implemented */
908 if (!(circuit
->is_type
& level
)) {
910 "ISIS-Upd (%s): LSP %s received at level %d over circuit of"
912 circuit
->area
->area_tag
, rawlspid_print(hdr
.lsp_id
),
913 level
, circuit_t2string(circuit
->is_type
));
917 struct isis_tlvs
*tlvs
= NULL
;
918 int retval
= ISIS_WARNING
;
919 const char *error_log
;
921 if (isis_unpack_tlvs(STREAM_READABLE(circuit
->rcv_stream
),
922 circuit
->rcv_stream
, &tlvs
, &error_log
)) {
923 zlog_warn("Something went wrong unpacking the LSP: %s",
926 /* send northbound notification. Note that the tlv-type and
927 * offset cannot correctly be set here as they are not returned
928 * by isis_unpack_tlvs, but in there I cannot fire a
929 * notification because I have no circuit information. So until
930 * we change the code above to return those extra fields, we
931 * will send dummy values which are ignored in the callback
933 isis_notif_lsp_error(circuit
, rawlspid_print(hdr
.lsp_id
),
935 #endif /* ifndef FABRICD */
939 /* 7.3.15.1 a) 4 - need to make sure IDLength matches */
941 /* 7.3.15.1 a) 5 - maximum area match, can be ommited since we only use
944 /* 7.3.15.1 a) 7 - password check */
945 struct isis_passwd
*passwd
= (level
== ISIS_LEVEL1
)
946 ? &circuit
->area
->area_passwd
947 : &circuit
->area
->domain_passwd
;
948 int auth_code
= isis_tlvs_auth_is_valid(tlvs
, passwd
,
949 circuit
->rcv_stream
, true);
950 if (auth_code
!= ISIS_AUTH_OK
) {
951 isis_event_auth_failure(circuit
->area
->area_tag
,
952 "LSP authentication failure",
955 /* send northbound notification */
956 if (auth_code
== ISIS_AUTH_FAILURE
) {
957 circuit
->auth_failures
++;
958 isis_notif_authentication_failure(circuit
, raw_pdu
);
959 } else { /* AUTH_TYPE_FAILURE or NO_VALIDATOR */
960 circuit
->auth_type_failures
++;
961 isis_notif_authentication_type_failure(circuit
,
964 #endif /* ifndef FABRICD */
968 /* Find the LSP in our database and compare it to this Link State header
970 struct isis_lsp
*lsp
=
971 lsp_search(&circuit
->area
->lspdb
[level
- 1], hdr
.lsp_id
);
974 comp
= lsp_compare(circuit
->area
->area_tag
, lsp
, hdr
.seqno
,
975 hdr
.checksum
, hdr
.rem_lifetime
);
976 if (lsp
&& (lsp
->own_lsp
))
979 /* 7.3.15.1 a) 6 - Must check that we have an adjacency of the same
981 /* for broadcast circuits, snpa should be compared */
983 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
) {
984 if (!isis_adj_lookup_snpa(ssnpa
,
985 circuit
->u
.bc
.adjdb
[level
- 1])) {
986 zlog_debug("(%s): DS ======= LSP %s, seq 0x%08" PRIx32
987 ", cksum 0x%04" PRIx16
", lifetime %" PRIu16
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%08" PRIx32
1030 " with confused checksum received.",
1031 circuit
->area
->area_tag
, rawlspid_print(hdr
.lsp_id
),
1033 hdr
.rem_lifetime
= 0;
1034 lsp_confusion
= true;
1036 lsp_confusion
= false;
1038 /* 7.3.15.1 b) - If the remaining life time is 0, we perform 7.3.16.4 */
1039 if (hdr
.rem_lifetime
== 0) {
1041 /* 7.3.16.4 a) 1) No LSP in db -> send an ack, but don't
1043 /* only needed on explicit update, eg - p2p */
1044 if (circuit
->circ_type
== CIRCUIT_T_P2P
)
1045 ack_lsp(&hdr
, circuit
, level
);
1046 goto out
; /* FIXME: do we need a purge? */
1048 if (memcmp(hdr
.lsp_id
, isis
->sysid
, ISIS_SYS_ID_LEN
)) {
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
,
1058 lsp_flood_or_update(lsp
, NULL
,
1061 ISIS_FLAGS_CLEAR_ALL(
1062 lsp
->SSNflags
); /* FIXME:
1067 /* For the case of lsp confusion, flood
1068 * the purge back to its
1069 * originator so that it can react.
1070 * Otherwise, don't reflood
1071 * through incoming circuit as usual */
1072 if (!lsp_confusion
) {
1078 if (circuit
->circ_type
1079 != CIRCUIT_T_BROADCAST
)
1084 } /* 7.3.16.4 b) 2) */
1085 else if (comp
== LSP_EQUAL
) {
1087 isis_tx_queue_del(circuit
->tx_queue
,
1090 if (circuit
->circ_type
1091 != CIRCUIT_T_BROADCAST
)
1092 ISIS_SET_FLAG(lsp
->SSNflags
,
1094 } /* 7.3.16.4 b) 3) */
1096 isis_tx_queue_add(circuit
->tx_queue
,
1097 lsp
, TX_LSP_NORMAL
);
1098 ISIS_CLEAR_FLAG(lsp
->SSNflags
, circuit
);
1100 } else if (lsp
->hdr
.rem_lifetime
!= 0) {
1101 /* our own LSP -> 7.3.16.4 c) */
1102 if (comp
== LSP_NEWER
) {
1104 if (lsp
->hdr
.seqno
< hdr
.seqno
) {
1107 isis_notif_seqno_skipped(
1112 #endif /* ifndef FABRICD */
1113 lsp_inc_seqno(lsp
, hdr
.seqno
);
1114 lsp_flood_or_update(lsp
, NULL
,
1117 isis_tx_queue_add(circuit
->tx_queue
,
1118 lsp
, TX_LSP_NORMAL
);
1119 ISIS_CLEAR_FLAG(lsp
->SSNflags
, circuit
);
1121 if (isis
->debugs
& DEBUG_UPDATE_PACKETS
)
1123 "ISIS-Upd (%s): (1) "
1124 "re-originating LSP %s new seq "
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
, isis
->sysid
, ISIS_SYS_ID_LEN
) == 0) {
1144 /* 7.3.16.4: initiate a purge */
1145 lsp_purge_non_exist(level
, &hdr
, circuit
->area
);
1149 /* 7.3.15.1 d) - If this is our own lsp and we have it */
1151 /* In 7.3.16.1, If an Intermediate system R somewhere in the
1153 * has information that the current sequence number for source S
1155 * "greater" than that held by S, ... */
1157 if (comp
== LSP_NEWER
) {
1159 lsp_inc_seqno(lsp
, hdr
.seqno
);
1161 /* send northbound notification */
1162 isis_notif_seqno_skipped(circuit
,
1163 rawlspid_print(hdr
.lsp_id
));
1164 #endif /* ifndef FABRICD */
1165 if (isis
->debugs
& DEBUG_UPDATE_PACKETS
) {
1167 "ISIS-Upd (%s): (2) re-originating LSP %s new seq 0x%08" PRIx32
,
1168 circuit
->area
->area_tag
,
1169 rawlspid_print(hdr
.lsp_id
),
1172 lsp_flood(lsp
, NULL
);
1173 } else if (comp
== LSP_EQUAL
) {
1174 isis_tx_queue_del(circuit
->tx_queue
, lsp
);
1175 if (circuit
->circ_type
!= CIRCUIT_T_BROADCAST
)
1176 ISIS_SET_FLAG(lsp
->SSNflags
, circuit
);
1178 isis_tx_queue_add(circuit
->tx_queue
, lsp
,
1180 ISIS_CLEAR_FLAG(lsp
->SSNflags
, circuit
);
1183 /* 7.3.15.1 e) - This lsp originated on another system */
1185 /* 7.3.15.1 e) 1) LSP newer than the one in db or no LSP in db
1187 if ((!lsp
|| comp
== LSP_NEWER
)) {
1189 * If this lsp is a frag, need to see if we have zero
1192 struct isis_lsp
*lsp0
= NULL
;
1193 if (LSP_FRAGMENT(hdr
.lsp_id
) != 0) {
1194 uint8_t lspid
[ISIS_SYS_ID_LEN
+ 2];
1195 memcpy(lspid
, hdr
.lsp_id
, ISIS_SYS_ID_LEN
+ 1);
1196 LSP_FRAGMENT(lspid
) = 0;
1198 &circuit
->area
->lspdb
[level
- 1], lspid
);
1201 "Got lsp frag, while zero lsp not in database");
1207 lsp
= lsp_new_from_recv(
1208 &hdr
, tlvs
, circuit
->rcv_stream
, lsp0
,
1209 circuit
->area
, level
);
1211 lsp_insert(&circuit
->area
->lspdb
[level
- 1],
1213 } else /* exists, so we overwrite */
1215 lsp_update(lsp
, &hdr
, tlvs
, circuit
->rcv_stream
,
1216 circuit
->area
, level
, false);
1219 lsp_flood_or_update(lsp
, circuit
, circuit_scoped
);
1222 if (circuit
->circ_type
!= CIRCUIT_T_BROADCAST
)
1223 ISIS_SET_FLAG(lsp
->SSNflags
, circuit
);
1226 /* 7.3.15.1 e) 2) LSP equal to the one in db */
1227 else if (comp
== LSP_EQUAL
) {
1228 isis_tx_queue_del(circuit
->tx_queue
, lsp
);
1229 lsp_update(lsp
, &hdr
, tlvs
, circuit
->rcv_stream
,
1230 circuit
->area
, level
, false);
1232 if (circuit
->circ_type
!= CIRCUIT_T_BROADCAST
)
1233 ISIS_SET_FLAG(lsp
->SSNflags
, circuit
);
1235 /* 7.3.15.1 e) 3) LSP older than the one in db */
1237 isis_tx_queue_add(circuit
->tx_queue
, lsp
,
1239 ISIS_CLEAR_FLAG(lsp
->SSNflags
, circuit
);
1246 fabricd_trigger_csnp(circuit
->area
, circuit_scoped
);
1248 isis_free_tlvs(tlvs
);
1253 * Process Sequence Numbers
1255 * Section 7.3.15.2 - Action on receipt of a sequence numbers PDU
1258 static int process_snp(uint8_t pdu_type
, struct isis_circuit
*circuit
,
1259 const uint8_t *ssnpa
)
1262 size_t pdu_start
= stream_get_getp(circuit
->rcv_stream
);
1263 size_t pdu_end
= stream_get_endp(circuit
->rcv_stream
);
1264 char raw_pdu
[pdu_end
- pdu_start
];
1265 #endif /* ifndef FABRICD */
1267 bool is_csnp
= (pdu_type
== L1_COMPLETE_SEQ_NUM
1268 || pdu_type
== L2_COMPLETE_SEQ_NUM
);
1269 char typechar
= is_csnp
? 'C' : 'P';
1270 int level
= (pdu_type
== L1_COMPLETE_SEQ_NUM
1271 || pdu_type
== L1_PARTIAL_SEQ_NUM
)
1275 uint16_t pdu_len
= stream_getw(circuit
->rcv_stream
);
1276 uint8_t rem_sys_id
[ISIS_SYS_ID_LEN
];
1278 stream_get(rem_sys_id
, circuit
->rcv_stream
, ISIS_SYS_ID_LEN
);
1279 stream_forward_getp(circuit
->rcv_stream
, 1); /* Circuit ID - unused */
1281 uint8_t start_lsp_id
[ISIS_SYS_ID_LEN
+ 2] = {};
1282 uint8_t stop_lsp_id
[ISIS_SYS_ID_LEN
+ 2] = {};
1285 stream_get(start_lsp_id
, circuit
->rcv_stream
,
1286 ISIS_SYS_ID_LEN
+ 2);
1287 stream_get(stop_lsp_id
, circuit
->rcv_stream
,
1288 ISIS_SYS_ID_LEN
+ 2);
1291 if (pdu_len_validate(pdu_len
, circuit
)) {
1292 zlog_warn("Received a CSNP with bogus length %d", pdu_len
);
1293 return ISIS_WARNING
;
1296 if (isis
->debugs
& DEBUG_SNP_PACKETS
) {
1298 "ISIS-Snp (%s): Rcvd L%d %cSNP on %s, cirType %s, cirID %u",
1299 circuit
->area
->area_tag
, level
, typechar
,
1300 circuit
->interface
->name
,
1301 circuit_t2string(circuit
->is_type
),
1302 circuit
->circuit_id
);
1303 if (isis
->debugs
& DEBUG_PACKET_DUMP
)
1304 zlog_dump_data(STREAM_DATA(circuit
->rcv_stream
),
1305 stream_get_endp(circuit
->rcv_stream
));
1308 /* 7.3.15.2 a) 1 - external domain circuit will discard snp pdu */
1309 if (circuit
->ext_domain
) {
1312 "ISIS-Snp (%s): Rcvd L%d %cSNP on %s, "
1313 "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, "
1324 "skipping: circuit type %s does not match level %d",
1325 circuit
->area
->area_tag
, level
, typechar
,
1326 circuit
->interface
->name
,
1327 circuit_t2string(circuit
->is_type
), level
);
1332 /* 7.3.15.2 a) 4 - not applicable for CSNP only PSNPs on broadcast */
1333 if (!is_csnp
&& (circuit
->circ_type
== CIRCUIT_T_BROADCAST
)
1334 && !circuit
->u
.bc
.is_dr
[level
- 1]) {
1336 "ISIS-Snp (%s): Rcvd L%d %cSNP from %s on %s, "
1337 "skipping: we are not the DIS",
1338 circuit
->area
->area_tag
, level
, typechar
,
1339 snpa_print(ssnpa
), circuit
->interface
->name
);
1344 /* 7.3.15.2 a) 5 - need to make sure IDLength matches - already checked
1347 /* 7.3.15.2 a) 6 - maximum area match, can be ommited since we only use
1349 * - already checked */
1351 /* 7.3.15.2 a) 7 - Must check that we have an adjacency of the same
1353 /* for broadcast circuits, snpa should be compared */
1354 /* FIXME : Do we need to check SNPA? */
1355 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
) {
1356 if (!isis_adj_lookup(rem_sys_id
,
1357 circuit
->u
.bc
.adjdb
[level
- 1]))
1358 return ISIS_OK
; /* Silently discard */
1360 if (!fabricd
&& !circuit
->u
.p2p
.neighbor
) {
1361 zlog_warn("no p2p neighbor on circuit %s",
1362 circuit
->interface
->name
);
1363 return ISIS_OK
; /* Silently discard */
1367 struct isis_tlvs
*tlvs
;
1368 int retval
= ISIS_WARNING
;
1369 const char *error_log
;
1371 if (isis_unpack_tlvs(STREAM_READABLE(circuit
->rcv_stream
),
1372 circuit
->rcv_stream
, &tlvs
, &error_log
)) {
1373 zlog_warn("Something went wrong unpacking the SNP: %s",
1378 struct isis_passwd
*passwd
= (level
== IS_LEVEL_1
)
1379 ? &circuit
->area
->area_passwd
1380 : &circuit
->area
->domain_passwd
;
1381 if (CHECK_FLAG(passwd
->snp_auth
, SNP_AUTH_RECV
)) {
1382 int auth_code
= isis_tlvs_auth_is_valid(
1383 tlvs
, passwd
, circuit
->rcv_stream
, false);
1384 if (auth_code
!= ISIS_AUTH_OK
) {
1385 isis_event_auth_failure(circuit
->area
->area_tag
,
1386 "SNP authentication failure",
1389 /* send northbound notification */
1390 stream_get_from(raw_pdu
, circuit
->rcv_stream
, pdu_start
,
1391 pdu_end
- pdu_start
);
1392 if (auth_code
== ISIS_AUTH_FAILURE
) {
1393 circuit
->auth_failures
++;
1394 isis_notif_authentication_failure(circuit
,
1396 } else { /* AUTH_TYPE_FAILURE or NO_VALIDATOR */
1397 circuit
->auth_type_failures
++;
1398 isis_notif_authentication_type_failure(circuit
,
1401 #endif /* ifndef FABRICD */
1406 struct isis_lsp_entry
*entry_head
=
1407 (struct isis_lsp_entry
*)tlvs
->lsp_entries
.head
;
1409 /* debug isis snp-packets */
1410 if (isis
->debugs
& DEBUG_SNP_PACKETS
) {
1411 zlog_debug("ISIS-Snp (%s): Rcvd L%d %cSNP from %s on %s",
1412 circuit
->area
->area_tag
, level
, typechar
,
1413 snpa_print(ssnpa
), circuit
->interface
->name
);
1414 for (struct isis_lsp_entry
*entry
= entry_head
; entry
;
1415 entry
= entry
->next
) {
1417 "ISIS-Snp (%s): %cSNP entry %s, seq 0x%08" PRIx32
1418 ", cksum 0x%04" PRIx16
", lifetime %" PRIu16
"s",
1419 circuit
->area
->area_tag
, typechar
,
1420 rawlspid_print(entry
->id
), entry
->seqno
,
1421 entry
->checksum
, entry
->rem_lifetime
);
1425 bool resync_needed
= false;
1427 /* 7.3.15.2 b) Actions on LSP_ENTRIES reported */
1428 for (struct isis_lsp_entry
*entry
= entry_head
; entry
;
1429 entry
= entry
->next
) {
1430 struct isis_lsp
*lsp
=
1431 lsp_search(&circuit
->area
->lspdb
[level
- 1], entry
->id
);
1432 bool own_lsp
= !memcmp(entry
->id
, isis
->sysid
, ISIS_SYS_ID_LEN
);
1434 /* 7.3.15.2 b) 1) is this LSP newer */
1435 int cmp
= lsp_compare(circuit
->area
->area_tag
, lsp
,
1436 entry
->seqno
, entry
->checksum
,
1437 entry
->rem_lifetime
);
1438 /* 7.3.15.2 b) 2) if it equals, clear SRM on p2p */
1439 if (cmp
== LSP_EQUAL
) {
1440 /* if (circuit->circ_type !=
1441 * CIRCUIT_T_BROADCAST) */
1442 isis_tx_queue_del(circuit
->tx_queue
, lsp
);
1444 /* 7.3.15.2 b) 3) if it is older, clear SSN and set SRM
1446 else if (cmp
== LSP_OLDER
) {
1447 ISIS_CLEAR_FLAG(lsp
->SSNflags
, circuit
);
1448 isis_tx_queue_add(circuit
->tx_queue
, lsp
,
1451 /* 7.3.15.2 b) 4) if it is newer, set SSN and clear SRM
1455 lsp_inc_seqno(lsp
, entry
->seqno
);
1456 isis_tx_queue_add(circuit
->tx_queue
, lsp
,
1459 ISIS_SET_FLAG(lsp
->SSNflags
, circuit
);
1460 /* if (circuit->circ_type !=
1461 * CIRCUIT_T_BROADCAST) */
1462 isis_tx_queue_del(circuit
->tx_queue
, lsp
);
1463 resync_needed
= true;
1467 /* 7.3.15.2 b) 5) if it was not found, and all of those
1469 * insert it and set SSN on it */
1470 if (entry
->rem_lifetime
&& entry
->checksum
1471 && entry
->seqno
&& memcmp(entry
->id
, 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=%" PRIx8
, idrp
);
1615 if (idrp
!= ISO10589_ISIS
) {
1616 flog_err(EC_ISIS_PACKET
, "Not an IS-IS packet IDRP=%" PRIx8
,
1621 if (version1
!= 1) {
1622 zlog_warn("Unsupported ISIS version %" PRIu8
, 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 %" PRIu8
1634 ", while the parameter for this IS is %u",
1635 id_len
, ISIS_SYS_ID_LEN
);
1636 circuit
->id_len_mismatches
++;
1638 /* send northbound notification */
1639 isis_notif_id_len_mismatch(circuit
, id_len
, raw_pdu
);
1640 #endif /* ifndef FABRICD */
1644 uint8_t expected_length
;
1645 if (pdu_size(pdu_type
, &expected_length
)) {
1646 zlog_warn("Unsupported ISIS PDU %" PRIu8
, pdu_type
);
1647 return ISIS_WARNING
;
1650 if (length
!= expected_length
) {
1651 flog_err(EC_ISIS_PACKET
,
1652 "Exepected fixed header length = %" PRIu8
1654 expected_length
, length
);
1658 if (stream_get_endp(circuit
->rcv_stream
) < length
) {
1661 "PDU is too short to contain fixed header of given PDU type.");
1665 if (version2
!= 1) {
1666 zlog_warn("Unsupported ISIS PDU version %" PRIu8
, version2
);
1668 /* send northbound notification */
1669 isis_notif_version_skew(circuit
, version2
, raw_pdu
);
1670 #endif /* ifndef FABRICD */
1671 return ISIS_WARNING
;
1674 if (circuit
->is_passive
) {
1675 zlog_warn("Received ISIS PDU on passive circuit %s",
1676 circuit
->interface
->name
);
1677 return ISIS_WARNING
;
1681 if (pdu_type
!= FS_LINK_STATE
/* FS PDU doesn't contain max area addr field */
1682 && max_area_addrs
!= 0
1683 && max_area_addrs
!= isis
->max_area_addrs
) {
1686 "maximumAreaAddressesMismatch: maximumAreaAdresses in a received PDU %" PRIu8
1687 " while the parameter for this IS is %u",
1688 max_area_addrs
, isis
->max_area_addrs
);
1689 circuit
->max_area_addr_mismatches
++;
1691 /* send northbound notification */
1692 isis_notif_max_area_addr_mismatch(circuit
, max_area_addrs
,
1694 #endif /* ifndef FABRICD */
1702 if (fabricd
&& pdu_type
!= P2P_HELLO
)
1704 retval
= process_hello(pdu_type
, circuit
, ssnpa
);
1710 && pdu_type
!= L2_LINK_STATE
1711 && pdu_type
!= FS_LINK_STATE
)
1713 retval
= process_lsp(pdu_type
, circuit
, ssnpa
, max_area_addrs
);
1715 case L1_COMPLETE_SEQ_NUM
:
1716 case L2_COMPLETE_SEQ_NUM
:
1717 case L1_PARTIAL_SEQ_NUM
:
1718 case L2_PARTIAL_SEQ_NUM
:
1719 retval
= process_snp(pdu_type
, circuit
, ssnpa
);
1728 int isis_receive(struct thread
*thread
)
1730 struct isis_circuit
*circuit
;
1731 uint8_t ssnpa
[ETH_ALEN
];
1737 circuit
= THREAD_ARG(thread
);
1740 circuit
->t_read
= NULL
;
1742 isis_circuit_stream(circuit
, &circuit
->rcv_stream
);
1744 retval
= circuit
->rx(circuit
, ssnpa
);
1746 #if ISIS_METHOD != ISIS_METHOD_BPF
1747 if (retval
== ISIS_OK
)
1748 retval
= isis_handle_pdu(circuit
, ssnpa
);
1749 #endif //ISIS_METHOD != ISIS_METHOD_BPF
1752 * prepare for next packet.
1754 if (!circuit
->is_passive
)
1755 isis_circuit_prepare(circuit
);
1763 void fill_fixed_hdr(uint8_t pdu_type
, struct stream
*stream
)
1767 if (pdu_size(pdu_type
, &length
))
1768 assert(!"Unknown PDU Type");
1770 stream_putc(stream
, ISO10589_ISIS
); /* IDRP */
1771 stream_putc(stream
, length
); /* Length of fixed header */
1772 stream_putc(stream
, 1); /* Version/Protocol ID Extension 1 */
1773 stream_putc(stream
, 0); /* ID Length, 0 => 6 */
1774 stream_putc(stream
, pdu_type
);
1775 stream_putc(stream
, 1); /* Subversion */
1776 stream_putc(stream
, 0); /* Reserved */
1777 stream_putc(stream
, 0); /* Max Area Addresses 0 => 3 */
1780 static uint8_t hello_pdu_type(struct isis_circuit
*circuit
, int level
)
1782 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
)
1783 return (level
== IS_LEVEL_1
) ? L1_LAN_HELLO
: L2_LAN_HELLO
;
1788 static void put_hello_hdr(struct isis_circuit
*circuit
, int level
,
1789 size_t *len_pointer
)
1791 uint8_t pdu_type
= hello_pdu_type(circuit
, level
);
1793 isis_circuit_stream(circuit
, &circuit
->snd_stream
);
1794 fill_fixed_hdr(pdu_type
, circuit
->snd_stream
);
1796 stream_putc(circuit
->snd_stream
, circuit
->is_type
);
1797 stream_put(circuit
->snd_stream
, circuit
->area
->isis
->sysid
,
1800 uint32_t holdtime
= circuit
->hello_multiplier
[level
- 1]
1801 * circuit
->hello_interval
[level
- 1];
1803 if (holdtime
> 0xffff)
1806 stream_putw(circuit
->snd_stream
, holdtime
);
1807 *len_pointer
= stream_get_endp(circuit
->snd_stream
);
1808 stream_putw(circuit
->snd_stream
, 0); /* length is filled in later */
1810 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
) {
1811 uint8_t *desig_is
= (level
== IS_LEVEL_1
)
1812 ? circuit
->u
.bc
.l1_desig_is
1813 : circuit
->u
.bc
.l2_desig_is
;
1814 stream_putc(circuit
->snd_stream
, circuit
->priority
[level
- 1]);
1815 stream_put(circuit
->snd_stream
, desig_is
, ISIS_SYS_ID_LEN
+ 1);
1817 stream_putc(circuit
->snd_stream
, circuit
->circuit_id
);
1821 int send_hello(struct isis_circuit
*circuit
, int level
)
1826 if (circuit
->is_passive
)
1829 if (circuit
->interface
->mtu
== 0) {
1830 zlog_warn("circuit has zero MTU");
1831 return ISIS_WARNING
;
1834 put_hello_hdr(circuit
, level
, &len_pointer
);
1836 struct isis_tlvs
*tlvs
= isis_alloc_tlvs();
1838 isis_tlvs_add_auth(tlvs
, &circuit
->passwd
);
1840 if (!listcount(circuit
->area
->area_addrs
)) {
1841 isis_free_tlvs(tlvs
);
1842 return ISIS_WARNING
;
1845 isis_tlvs_add_area_addresses(tlvs
, circuit
->area
->area_addrs
);
1847 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
) {
1848 isis_tlvs_add_lan_neighbors(
1849 tlvs
, circuit
->u
.bc
.lan_neighs
[level
- 1]);
1850 } else if (circuit
->circ_type
== CIRCUIT_T_P2P
1851 && !circuit
->disable_threeway_adj
) {
1852 uint32_t ext_circuit_id
= circuit
->idx
;
1853 if (circuit
->u
.p2p
.neighbor
) {
1854 uint8_t threeway_state
;
1856 if (fabricd_initial_sync_is_in_progress(circuit
->area
)
1857 && fabricd_initial_sync_circuit(circuit
->area
) != circuit
)
1858 threeway_state
= ISIS_THREEWAY_DOWN
;
1860 threeway_state
= circuit
->u
.p2p
.neighbor
->threeway_state
;
1861 isis_tlvs_add_threeway_adj(tlvs
,
1864 circuit
->u
.p2p
.neighbor
->sysid
,
1865 circuit
->u
.p2p
.neighbor
->ext_circuit_id
);
1867 isis_tlvs_add_threeway_adj(tlvs
,
1874 isis_tlvs_set_protocols_supported(tlvs
, &circuit
->nlpids
);
1879 * TLV gets included if no topology is enabled on the interface,
1880 * if one topology other than #0 is enabled, or if multiple topologies
1883 struct isis_circuit_mt_setting
**mt_settings
;
1884 unsigned int mt_count
;
1886 mt_settings
= circuit_mt_settings(circuit
, &mt_count
);
1887 if (mt_count
== 0 && area_is_mt(circuit
->area
)) {
1888 tlvs
->mt_router_info_empty
= true;
1889 } else if ((mt_count
== 1
1890 && mt_settings
[0]->mtid
!= ISIS_MT_IPV4_UNICAST
)
1891 || (mt_count
> 1)) {
1892 for (unsigned int i
= 0; i
< mt_count
; i
++)
1893 isis_tlvs_add_mt_router_info(tlvs
, mt_settings
[i
]->mtid
,
1897 if (circuit
->ip_router
) {
1898 struct list
*circuit_ip_addrs
= fabricd_ip_addrs(circuit
);
1900 if (circuit_ip_addrs
)
1901 isis_tlvs_add_ipv4_addresses(tlvs
, circuit_ip_addrs
);
1904 if (circuit
->ipv6_router
&& circuit
->ipv6_link
)
1905 isis_tlvs_add_ipv6_addresses(tlvs
, circuit
->ipv6_link
);
1907 if (isis_pack_tlvs(tlvs
, circuit
->snd_stream
, len_pointer
,
1908 circuit
->pad_hellos
, false)) {
1909 isis_free_tlvs(tlvs
);
1910 return ISIS_WARNING
; /* XXX: Maybe Log TLV structure? */
1913 if (isis
->debugs
& DEBUG_ADJ_PACKETS
) {
1914 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
) {
1916 "ISIS-Adj (%s): Sending L%d LAN IIH on %s, length %zd",
1917 circuit
->area
->area_tag
, level
,
1918 circuit
->interface
->name
,
1919 stream_get_endp(circuit
->snd_stream
));
1922 "ISIS-Adj (%s): Sending P2P IIH on %s, length %zd",
1923 circuit
->area
->area_tag
,
1924 circuit
->interface
->name
,
1925 stream_get_endp(circuit
->snd_stream
));
1927 if (isis
->debugs
& DEBUG_PACKET_DUMP
)
1928 zlog_dump_data(STREAM_DATA(circuit
->snd_stream
),
1929 stream_get_endp(circuit
->snd_stream
));
1932 isis_free_tlvs(tlvs
);
1934 pdu_counter_count(circuit
->area
->pdu_tx_counters
,
1935 hello_pdu_type(circuit
, level
));
1936 retval
= circuit
->tx(circuit
, level
);
1937 if (retval
!= ISIS_OK
)
1938 flog_err(EC_ISIS_PACKET
,
1939 "ISIS-Adj (%s): Send L%d IIH on %s failed",
1940 circuit
->area
->area_tag
, level
,
1941 circuit
->interface
->name
);
1946 static int send_hello_cb(struct thread
*thread
)
1948 struct isis_circuit_arg
*arg
= THREAD_ARG(thread
);
1951 struct isis_circuit
*circuit
= arg
->circuit
;
1952 int level
= arg
->level
;
1956 if (circuit
->circ_type
== CIRCUIT_T_P2P
) {
1957 circuit
->u
.p2p
.t_send_p2p_hello
= NULL
;
1958 send_hello(circuit
, 1);
1959 send_hello_sched(circuit
, ISIS_LEVEL1
,
1960 1000 * circuit
->hello_interval
[1]);
1964 if (circuit
->circ_type
!= CIRCUIT_T_BROADCAST
) {
1965 zlog_warn("ISIS-Hello (%s): Trying to send hello on unknown circuit type %d",
1966 circuit
->area
->area_tag
, circuit
->circ_type
);
1967 return ISIS_WARNING
;
1970 circuit
->u
.bc
.t_send_lan_hello
[level
- 1] = NULL
;
1971 if (!(circuit
->is_type
& level
)) {
1972 zlog_warn("ISIS-Hello (%s): Trying to send L%d IIH in L%d-only circuit",
1973 circuit
->area
->area_tag
, level
, 3 - level
);
1974 return ISIS_WARNING
;
1977 if (circuit
->u
.bc
.run_dr_elect
[level
- 1])
1978 isis_dr_elect(circuit
, level
);
1980 int rv
= send_hello(circuit
, level
);
1982 /* set next timer thread */
1983 send_hello_sched(circuit
, level
, 1000 * circuit
->hello_interval
[level
- 1]);
1987 static void _send_hello_sched(struct isis_circuit
*circuit
,
1988 struct thread
**threadp
,
1989 int level
, long delay
)
1992 if (thread_timer_remain_msec(*threadp
) < (unsigned long)delay
)
1995 thread_cancel(*threadp
);
1998 thread_add_timer_msec(master
, send_hello_cb
,
1999 &circuit
->level_arg
[level
- 1],
2000 isis_jitter(delay
, IIH_JITTER
),
2004 void send_hello_sched(struct isis_circuit
*circuit
, int level
, long delay
)
2006 if (circuit
->circ_type
== CIRCUIT_T_P2P
) {
2007 _send_hello_sched(circuit
, &circuit
->u
.p2p
.t_send_p2p_hello
,
2008 ISIS_LEVEL1
, delay
);
2012 if (circuit
->circ_type
!= CIRCUIT_T_BROADCAST
) {
2013 zlog_warn("%s: encountered unknown circuit type %d on %s",
2014 __func__
, circuit
->circ_type
,
2015 circuit
->interface
->name
);
2019 for (int loop_level
= ISIS_LEVEL1
; loop_level
<= ISIS_LEVEL2
; loop_level
++) {
2020 if (!(loop_level
& level
))
2025 &circuit
->u
.bc
.t_send_lan_hello
[loop_level
- 1],
2034 * Count the maximum number of lsps that can be accomodated by a given size.
2036 #define LSP_ENTRIES_LEN (10 + ISIS_SYS_ID_LEN)
2037 static uint16_t get_max_lsp_count(uint16_t size
)
2041 uint16_t remaining_size
;
2043 /* First count the full size TLVs */
2044 tlv_count
= size
/ MAX_LSP_ENTRIES_TLV_SIZE
;
2045 lsp_count
= tlv_count
* (MAX_LSP_ENTRIES_TLV_SIZE
/ LSP_ENTRIES_LEN
);
2047 /* The last TLV, if any */
2048 remaining_size
= size
% MAX_LSP_ENTRIES_TLV_SIZE
;
2049 if (remaining_size
- 2 >= LSP_ENTRIES_LEN
)
2050 lsp_count
+= (remaining_size
- 2) / LSP_ENTRIES_LEN
;
2055 int send_csnp(struct isis_circuit
*circuit
, int level
)
2057 if (lspdb_count(&circuit
->area
->lspdb
[level
- 1]) == 0)
2060 uint8_t pdu_type
= (level
== ISIS_LEVEL1
) ? L1_COMPLETE_SEQ_NUM
2061 : L2_COMPLETE_SEQ_NUM
;
2063 isis_circuit_stream(circuit
, &circuit
->snd_stream
);
2064 fill_fixed_hdr(pdu_type
, circuit
->snd_stream
);
2066 size_t len_pointer
= stream_get_endp(circuit
->snd_stream
);
2067 stream_putw(circuit
->snd_stream
, 0);
2068 stream_put(circuit
->snd_stream
, isis
->sysid
, ISIS_SYS_ID_LEN
);
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 (isis
->debugs
& 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 (isis
->debugs
& 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
, isis
->sysid
, ISIS_SYS_ID_LEN
);
2246 stream_putc(circuit
->snd_stream
, circuit
->idx
);
2248 struct isis_passwd
*passwd
= (level
== ISIS_LEVEL1
)
2249 ? &circuit
->area
->area_passwd
2250 : &circuit
->area
->domain_passwd
;
2252 struct isis_tlvs
*tlvs
= isis_alloc_tlvs();
2254 if (CHECK_FLAG(passwd
->snp_auth
, SNP_AUTH_SEND
))
2255 isis_tlvs_add_auth(tlvs
, passwd
);
2257 size_t tlv_start
= stream_get_endp(circuit
->snd_stream
);
2258 if (isis_pack_tlvs(tlvs
, circuit
->snd_stream
, len_pointer
, false,
2260 isis_free_tlvs(tlvs
);
2261 return ISIS_WARNING
;
2263 isis_free_tlvs(tlvs
);
2266 get_max_lsp_count(STREAM_WRITEABLE(circuit
->snd_stream
));
2269 struct isis_lsp
*lsp
;
2271 tlvs
= isis_alloc_tlvs();
2272 if (CHECK_FLAG(passwd
->snp_auth
, SNP_AUTH_SEND
))
2273 isis_tlvs_add_auth(tlvs
, passwd
);
2275 frr_each (lspdb
, &circuit
->area
->lspdb
[level
- 1], lsp
) {
2276 if (ISIS_CHECK_FLAG(lsp
->SSNflags
, circuit
))
2277 isis_tlvs_add_lsp_entry(tlvs
, lsp
);
2279 if (tlvs
->lsp_entries
.count
== num_lsps
)
2283 if (!tlvs
->lsp_entries
.count
) {
2284 isis_free_tlvs(tlvs
);
2288 stream_set_endp(circuit
->snd_stream
, tlv_start
);
2289 if (isis_pack_tlvs(tlvs
, circuit
->snd_stream
, len_pointer
,
2291 isis_free_tlvs(tlvs
);
2292 return ISIS_WARNING
;
2295 if (isis
->debugs
& DEBUG_SNP_PACKETS
) {
2297 "ISIS-Snp (%s): Sending L%d PSNP on %s, length %zd",
2298 circuit
->area
->area_tag
, level
,
2299 circuit
->interface
->name
,
2300 stream_get_endp(circuit
->snd_stream
));
2301 log_multiline(LOG_DEBUG
, " ", "%s",
2302 isis_format_tlvs(tlvs
));
2303 if (isis
->debugs
& DEBUG_PACKET_DUMP
)
2305 STREAM_DATA(circuit
->snd_stream
),
2306 stream_get_endp(circuit
->snd_stream
));
2309 pdu_counter_count(circuit
->area
->pdu_tx_counters
, pdu_type
);
2310 int retval
= circuit
->tx(circuit
, level
);
2311 if (retval
!= ISIS_OK
) {
2312 flog_err(EC_ISIS_PACKET
,
2313 "ISIS-Snp (%s): Send L%d PSNP on %s failed",
2314 circuit
->area
->area_tag
, level
,
2315 circuit
->interface
->name
);
2316 isis_free_tlvs(tlvs
);
2321 * sending succeeded, we can clear SSN flags of this circuit
2322 * for the LSPs in list
2324 struct isis_lsp_entry
*entry_head
;
2325 entry_head
= (struct isis_lsp_entry
*)tlvs
->lsp_entries
.head
;
2326 for (struct isis_lsp_entry
*entry
= entry_head
; entry
;
2327 entry
= entry
->next
)
2328 ISIS_CLEAR_FLAG(entry
->lsp
->SSNflags
, circuit
);
2329 isis_free_tlvs(tlvs
);
2335 int send_l1_psnp(struct thread
*thread
)
2338 struct isis_circuit
*circuit
;
2340 circuit
= THREAD_ARG(thread
);
2343 circuit
->t_send_psnp
[0] = NULL
;
2345 send_psnp(1, circuit
);
2346 /* set next timer thread */
2347 thread_add_timer(master
, send_l1_psnp
, circuit
,
2348 isis_jitter(circuit
->psnp_interval
[0], PSNP_JITTER
),
2349 &circuit
->t_send_psnp
[0]);
2355 * 7.3.15.4 action on expiration of partial SNP interval
2358 int send_l2_psnp(struct thread
*thread
)
2360 struct isis_circuit
*circuit
;
2362 circuit
= THREAD_ARG(thread
);
2365 circuit
->t_send_psnp
[1] = NULL
;
2367 send_psnp(2, circuit
);
2369 /* set next timer thread */
2370 thread_add_timer(master
, send_l2_psnp
, circuit
,
2371 isis_jitter(circuit
->psnp_interval
[1], PSNP_JITTER
),
2372 &circuit
->t_send_psnp
[1]);
2378 * ISO 10589 - 7.3.14.3
2380 void send_lsp(struct isis_circuit
*circuit
, struct isis_lsp
*lsp
,
2381 enum isis_tx_type tx_type
)
2384 int retval
= ISIS_OK
;
2386 if (circuit
->state
!= C_STATE_UP
|| circuit
->is_passive
== 1)
2390 * Do not send if levels do not match
2392 if (!(lsp
->level
& circuit
->is_type
))
2396 * Do not send if we do not have adjacencies in state up on the circuit
2398 if (circuit
->upadjcount
[lsp
->level
- 1] == 0)
2401 /* stream_copy will assert and stop program execution if LSP is larger
2403 * the circuit's MTU. So handle and log this case here. */
2404 if (stream_get_endp(lsp
->pdu
) > stream_get_size(circuit
->snd_stream
)) {
2407 "ISIS-Upd (%s): Can't send L%d LSP %s, seq 0x%08" PRIx32
2408 ", cksum 0x%04" PRIx16
", lifetime %" PRIu16
2409 "s on %s. LSP Size is %zu while interface stream size is %zu.",
2410 circuit
->area
->area_tag
, lsp
->level
,
2411 rawlspid_print(lsp
->hdr
.lsp_id
), lsp
->hdr
.seqno
,
2412 lsp
->hdr
.checksum
, lsp
->hdr
.rem_lifetime
,
2413 circuit
->interface
->name
, stream_get_endp(lsp
->pdu
),
2414 stream_get_size(circuit
->snd_stream
));
2416 /* send a northbound notification */
2417 isis_notif_lsp_too_large(circuit
, stream_get_endp(lsp
->pdu
),
2418 rawlspid_print(lsp
->hdr
.lsp_id
));
2419 #endif /* ifndef FABRICD */
2420 if (isis
->debugs
& DEBUG_PACKET_DUMP
)
2421 zlog_dump_data(STREAM_DATA(lsp
->pdu
),
2422 stream_get_endp(lsp
->pdu
));
2423 retval
= ISIS_ERROR
;
2427 /* copy our lsp to the send buffer */
2428 stream_copy(circuit
->snd_stream
, lsp
->pdu
);
2430 if (tx_type
== TX_LSP_CIRCUIT_SCOPED
) {
2431 stream_putc_at(circuit
->snd_stream
, 4, FS_LINK_STATE
);
2432 stream_putc_at(circuit
->snd_stream
, 7,
2433 L2_CIRCUIT_FLOODING_SCOPE
);
2436 if (isis
->debugs
& DEBUG_UPDATE_PACKETS
) {
2437 zlog_debug("ISIS-Upd (%s): Sending %sL%d LSP %s, seq 0x%08" PRIx32
2438 ", cksum 0x%04" PRIx16
", lifetime %" PRIu16
2440 circuit
->area
->area_tag
,
2441 (tx_type
== TX_LSP_CIRCUIT_SCOPED
)
2442 ? "Circuit scoped " : "",
2444 rawlspid_print(lsp
->hdr
.lsp_id
), lsp
->hdr
.seqno
,
2445 lsp
->hdr
.checksum
, lsp
->hdr
.rem_lifetime
,
2446 circuit
->interface
->name
);
2447 if (isis
->debugs
& DEBUG_PACKET_DUMP
)
2448 zlog_dump_data(STREAM_DATA(circuit
->snd_stream
),
2449 stream_get_endp(circuit
->snd_stream
));
2452 uint8_t pdu_type
= (tx_type
== TX_LSP_CIRCUIT_SCOPED
) ? FS_LINK_STATE
2453 : (lsp
->level
== ISIS_LEVEL1
) ? L1_LINK_STATE
2457 pdu_counter_count(circuit
->area
->pdu_tx_counters
, pdu_type
);
2458 retval
= circuit
->tx(circuit
, lsp
->level
);
2459 if (retval
!= ISIS_OK
) {
2460 flog_err(EC_ISIS_PACKET
,
2461 "ISIS-Upd (%s): Send L%d LSP on %s failed %s",
2462 circuit
->area
->area_tag
, lsp
->level
,
2463 circuit
->interface
->name
,
2464 (retval
== ISIS_WARNING
) ? "temporarily"
2470 || (retval
== ISIS_OK
&& circuit
->circ_type
== CIRCUIT_T_BROADCAST
)
2471 || (retval
!= ISIS_OK
&& retval
!= ISIS_WARNING
)) {
2472 /* SRM flag will trigger retransmission. We will not retransmit
2474 * encountered a fatal error.
2475 * On success, they should only be cleared if it's a broadcast
2477 * On a P2P circuit, we will wait for the ack from the neighbor
2481 isis_tx_queue_del(circuit
->tx_queue
, lsp
);