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 (isis
->debugs
& 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 (isis
->debugs
& DEBUG_ADJ_PACKETS
) {
147 zlog_debug("ISIS-Adj (%s): Rcvd P2P IIH from (%s) which lists IS/Circuit different from us as neighbor.",
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");
399 if (adj
->adj_state
== ISIS_ADJ_UP
&& changed
) {
400 lsp_regenerate_schedule(adj
->circuit
->area
,
401 isis_adj_usage2levels(adj
->adj_usage
),
405 /* 8.2.5.2 c) if the action was up - comparing circuit IDs */
406 /* FIXME - Missing parts */
408 /* some of my own understanding of the ISO, why the heck does
409 * it not say what should I change the system_type to...
411 switch (adj
->adj_usage
) {
412 case ISIS_ADJ_LEVEL1
:
413 adj
->sys_type
= ISIS_SYSTYPE_L1_IS
;
415 case ISIS_ADJ_LEVEL2
:
416 adj
->sys_type
= ISIS_SYSTYPE_L2_IS
;
418 case ISIS_ADJ_LEVEL1AND2
:
419 adj
->sys_type
= ISIS_SYSTYPE_L2_IS
;
422 adj
->sys_type
= ISIS_SYSTYPE_UNKNOWN
;
426 if (isis
->debugs
& DEBUG_ADJ_PACKETS
) {
428 "ISIS-Adj (%s): Rcvd P2P IIH from (%s), cir type %s,"
429 " cir id %hhu, length %" PRIu16
,
430 iih
->circuit
->area
->area_tag
,
431 iih
->circuit
->interface
->name
,
432 circuit_t2string(iih
->circuit
->is_type
),
433 iih
->circuit
->circuit_id
, iih
->pdu_len
);
439 static int process_lan_hello(struct iih_info
*iih
)
441 struct isis_adjacency
*adj
;
442 adj
= isis_adj_lookup(iih
->sys_id
,
443 iih
->circuit
->u
.bc
.adjdb
[iih
->level
- 1]);
444 if ((adj
== NULL
) || (memcmp(adj
->snpa
, iih
->ssnpa
, ETH_ALEN
))
445 || (adj
->level
!= iih
->level
)) {
447 /* Do as in 8.4.2.5 */
448 adj
= isis_new_adj(iih
->sys_id
, iih
->ssnpa
, iih
->level
,
452 memcpy(adj
->snpa
, iih
->ssnpa
, 6);
454 memset(adj
->snpa
, ' ', 6);
456 adj
->level
= iih
->level
;
458 isis_adj_state_change(adj
, ISIS_ADJ_INITIALIZING
, NULL
);
460 if (iih
->level
== IS_LEVEL_1
)
461 adj
->sys_type
= ISIS_SYSTYPE_L1_IS
;
463 adj
->sys_type
= ISIS_SYSTYPE_L2_IS
;
464 list_delete_all_node(
465 iih
->circuit
->u
.bc
.lan_neighs
[iih
->level
- 1]);
466 isis_adj_build_neigh_list(
467 iih
->circuit
->u
.bc
.adjdb
[iih
->level
- 1],
468 iih
->circuit
->u
.bc
.lan_neighs
[iih
->level
- 1]);
471 if (adj
->dis_record
[iih
->level
- 1].dis
== ISIS_IS_DIS
) {
472 uint8_t *dis
= (iih
->level
== 1)
473 ? iih
->circuit
->u
.bc
.l1_desig_is
474 : iih
->circuit
->u
.bc
.l2_desig_is
;
476 if (memcmp(dis
, iih
->dis
, ISIS_SYS_ID_LEN
+ 1)) {
477 thread_add_event(master
, isis_event_dis_status_change
,
478 iih
->circuit
, 0, NULL
);
479 memcpy(dis
, iih
->dis
, ISIS_SYS_ID_LEN
+ 1);
483 adj
->circuit_t
= iih
->circ_type
;
484 adj
->hold_time
= iih
->holdtime
;
485 adj
->last_upd
= time(NULL
);
486 adj
->prio
[iih
->level
- 1] = iih
->priority
;
487 memcpy(adj
->lanid
, iih
->dis
, ISIS_SYS_ID_LEN
+ 1);
490 isis_tlvs_to_adj(iih
->tlvs
, adj
, &changed
);
491 changed
|= tlvs_to_adj_mt_set(iih
->tlvs
, iih
->v4_usable
, iih
->v6_usable
,
494 /* lets take care of the expiry */
495 THREAD_TIMER_OFF(adj
->t_expire
);
496 thread_add_timer(master
, isis_adj_expire
, adj
, (long)adj
->hold_time
,
500 * If the snpa for this circuit is found from LAN Neighbours TLV
501 * we have two-way communication -> adjacency can be put to state "up"
503 bool own_snpa_found
=
504 isis_tlvs_own_snpa_found(iih
->tlvs
, iih
->circuit
->u
.bc
.snpa
);
506 if (adj
->adj_state
!= ISIS_ADJ_UP
) {
507 if (own_snpa_found
) {
508 isis_adj_state_change(
510 "own SNPA found in LAN Neighbours TLV");
513 if (!own_snpa_found
) {
514 isis_adj_state_change(
515 adj
, ISIS_ADJ_INITIALIZING
,
516 "own SNPA not found in LAN Neighbours TLV");
520 if (adj
->adj_state
== ISIS_ADJ_UP
&& changed
)
521 lsp_regenerate_schedule(adj
->circuit
->area
, iih
->level
, 0);
523 if (isis
->debugs
& DEBUG_ADJ_PACKETS
) {
525 "ISIS-Adj (%s): Rcvd L%d LAN IIH from %s on %s, cirType %s, cirID %u, length %zd",
526 iih
->circuit
->area
->area_tag
, iih
->level
,
527 snpa_print(iih
->ssnpa
), iih
->circuit
->interface
->name
,
528 circuit_t2string(iih
->circuit
->is_type
),
529 iih
->circuit
->circuit_id
,
530 stream_get_endp(iih
->circuit
->rcv_stream
));
535 static int pdu_len_validate(uint16_t pdu_len
, struct isis_circuit
*circuit
)
537 if (pdu_len
< stream_get_getp(circuit
->rcv_stream
)
538 || pdu_len
> ISO_MTU(circuit
)
539 || pdu_len
> stream_get_endp(circuit
->rcv_stream
))
542 if (pdu_len
< stream_get_endp(circuit
->rcv_stream
))
543 stream_set_endp(circuit
->rcv_stream
, pdu_len
);
547 static int process_hello(uint8_t pdu_type
, struct isis_circuit
*circuit
,
550 /* keep a copy of the raw pdu for NB notifications */
551 size_t pdu_start
= stream_get_getp(circuit
->rcv_stream
);
552 size_t pdu_end
= stream_get_endp(circuit
->rcv_stream
);
553 char raw_pdu
[pdu_end
- pdu_start
];
554 bool p2p_hello
= (pdu_type
== P2P_HELLO
);
555 int level
= p2p_hello
? 0
556 : (pdu_type
== L1_LAN_HELLO
) ? ISIS_LEVEL1
558 const char *pdu_name
=
561 : (level
== ISIS_LEVEL1
) ? "L1 LAN IIH" : "L2 LAN IIH";
564 stream_get_from(raw_pdu
, circuit
->rcv_stream
, pdu_start
,
565 pdu_end
- pdu_start
);
566 if (isis
->debugs
& DEBUG_ADJ_PACKETS
) {
567 zlog_debug("ISIS-Adj (%s): Rcvd %s on %s, cirType %s, cirID %u",
568 circuit
->area
->area_tag
, pdu_name
,
569 circuit
->interface
->name
,
570 circuit_t2string(circuit
->is_type
),
571 circuit
->circuit_id
);
572 if (isis
->debugs
& DEBUG_PACKET_DUMP
)
573 zlog_dump_data(STREAM_DATA(circuit
->rcv_stream
),
574 stream_get_endp(circuit
->rcv_stream
));
578 if (circuit
->circ_type
!= CIRCUIT_T_P2P
) {
579 zlog_warn("p2p hello on non p2p circuit");
580 circuit
->rej_adjacencies
++;
582 isis_notif_reject_adjacency(
583 circuit
, "p2p hello on non p2p circuit",
585 #endif /* ifndef FABRICD */
589 if (circuit
->circ_type
!= CIRCUIT_T_BROADCAST
) {
590 zlog_warn("lan hello on non broadcast circuit");
591 circuit
->rej_adjacencies
++;
593 isis_notif_reject_adjacency(
594 circuit
, "lan hello on non broadcast circuit",
596 #endif /* ifndef FABRICD */
600 if (circuit
->ext_domain
) {
602 "level %d LAN Hello received over circuit with externalDomain = true",
604 circuit
->rej_adjacencies
++;
606 isis_notif_reject_adjacency(
608 "LAN Hello received over circuit with externalDomain = true",
610 #endif /* ifndef FABRICD */
614 if (!(circuit
->is_type
& level
)) {
615 if (isis
->debugs
& DEBUG_ADJ_PACKETS
) {
617 "ISIS-Adj (%s): Interface level mismatch, %s",
618 circuit
->area
->area_tag
,
619 circuit
->interface
->name
);
621 circuit
->rej_adjacencies
++;
623 isis_notif_reject_adjacency(
624 circuit
, "Interface level mismatch", raw_pdu
);
625 #endif /* ifndef FABRICD */
630 struct iih_info iih
= {
631 .circuit
= circuit
, .ssnpa
= ssnpa
, .level
= level
};
633 /* Generic IIH Header */
634 iih
.circ_type
= stream_getc(circuit
->rcv_stream
) & 0x03;
635 stream_get(iih
.sys_id
, circuit
->rcv_stream
, ISIS_SYS_ID_LEN
);
636 iih
.holdtime
= stream_getw(circuit
->rcv_stream
);
637 iih
.pdu_len
= stream_getw(circuit
->rcv_stream
);
640 iih
.circuit_id
= stream_getc(circuit
->rcv_stream
);
642 iih
.priority
= stream_getc(circuit
->rcv_stream
);
643 stream_get(iih
.dis
, circuit
->rcv_stream
, ISIS_SYS_ID_LEN
+ 1);
646 if (pdu_len_validate(iih
.pdu_len
, circuit
)) {
648 "ISIS-Adj (%s): Rcvd %s from (%s) with invalid pdu length %" PRIu16
,
649 circuit
->area
->area_tag
, pdu_name
,
650 circuit
->interface
->name
, iih
.pdu_len
);
651 circuit
->rej_adjacencies
++;
653 isis_notif_reject_adjacency(circuit
, "Invalid PDU length",
655 #endif /* ifndef FABRICD */
659 if (!p2p_hello
&& !(level
& iih
.circ_type
)) {
660 flog_err(EC_ISIS_PACKET
,
661 "Level %d LAN Hello with Circuit Type %d", level
,
663 circuit
->rej_adjacencies
++;
665 isis_notif_reject_adjacency(
666 circuit
, "LAN Hello with wrong IS-level", raw_pdu
);
667 #endif /* ifndef FABRICD */
671 const char *error_log
;
672 int retval
= ISIS_WARNING
;
674 if (isis_unpack_tlvs(STREAM_READABLE(circuit
->rcv_stream
),
675 circuit
->rcv_stream
, &iih
.tlvs
, &error_log
)) {
676 zlog_warn("isis_unpack_tlvs() failed: %s", error_log
);
677 circuit
->rej_adjacencies
++;
679 isis_notif_reject_adjacency(circuit
, "Failed to unpack TLVs",
681 #endif /* ifndef FABRICD */
685 if (!iih
.tlvs
->area_addresses
.count
) {
686 zlog_warn("No Area addresses TLV in %s", pdu_name
);
688 /* send northbound notification */
689 isis_notif_area_mismatch(circuit
, raw_pdu
);
690 #endif /* ifndef FABRICD */
694 if (!iih
.tlvs
->protocols_supported
.count
) {
695 zlog_warn("No supported protocols TLV in %s", pdu_name
);
696 circuit
->rej_adjacencies
++;
698 isis_notif_reject_adjacency(
699 circuit
, "No supported protocols TLV", raw_pdu
);
700 #endif /* ifndef FABRICD */
704 int auth_code
= isis_tlvs_auth_is_valid(iih
.tlvs
, &circuit
->passwd
,
705 circuit
->rcv_stream
, false);
706 if (auth_code
!= ISIS_AUTH_OK
) {
707 isis_event_auth_failure(circuit
->area
->area_tag
,
708 "IIH authentication failure",
711 /* send northbound notification */
712 stream_get_from(raw_pdu
, circuit
->rcv_stream
, pdu_start
,
713 pdu_end
- pdu_start
);
714 if (auth_code
== ISIS_AUTH_FAILURE
) {
715 circuit
->auth_failures
++;
716 isis_notif_authentication_failure(circuit
, raw_pdu
);
717 } else { /* AUTH_TYPE_FAILURE or NO_VALIDATOR */
718 circuit
->auth_type_failures
++;
719 isis_notif_authentication_type_failure(circuit
,
722 #endif /* ifndef FABRICD */
726 if (!memcmp(iih
.sys_id
, isis
->sysid
, ISIS_SYS_ID_LEN
)) {
728 "ISIS-Adj (%s): Received IIH with own sysid - discard",
729 circuit
->area
->area_tag
);
730 circuit
->rej_adjacencies
++;
732 isis_notif_reject_adjacency(
733 circuit
, "Received IIH with our own sysid", raw_pdu
);
734 #endif /* ifndef FABRICD */
739 && (listcount(circuit
->area
->area_addrs
) == 0
740 || (level
== ISIS_LEVEL1
741 && !isis_tlvs_area_addresses_match(
742 iih
.tlvs
, circuit
->area
->area_addrs
)))) {
743 if (isis
->debugs
& DEBUG_ADJ_PACKETS
) {
745 "ISIS-Adj (%s): Area mismatch, level %d IIH on %s",
746 circuit
->area
->area_tag
, level
,
747 circuit
->interface
->name
);
750 /* send northbound notification */
751 isis_notif_area_mismatch(circuit
, raw_pdu
);
752 #endif /* ifndef FABRICD */
756 iih
.v4_usable
= (fabricd_ip_addrs(circuit
)
757 && iih
.tlvs
->ipv4_address
.count
);
759 iih
.v6_usable
= (circuit
->ipv6_link
&& listcount(circuit
->ipv6_link
)
760 && iih
.tlvs
->ipv6_address
.count
);
762 if (!iih
.v4_usable
&& !iih
.v6_usable
) {
763 if (isis
->debugs
& DEBUG_ADJ_PACKETS
) {
765 "ISIS-Adj (%s): Neither IPv4 nor IPv6 considered usable. Ignoring IIH",
766 circuit
->area
->area_tag
);
768 circuit
->rej_adjacencies
++;
770 isis_notif_reject_adjacency(
771 circuit
, "Neither IPv4 not IPv6 considered usable",
773 #endif /* ifndef FABRICD */
777 retval
= p2p_hello
? process_p2p_hello(&iih
) : process_lan_hello(&iih
);
779 isis_free_tlvs(iih
.tlvs
);
784 static void lsp_flood_or_update(struct isis_lsp
*lsp
,
785 struct isis_circuit
*circuit
,
789 lsp_flood(lsp
, circuit
);
791 fabricd_update_lsp_no_flood(lsp
, circuit
);
795 * Process Level 1/2 Link State
797 * Section 7.3.15.1 - Action on receipt of a link state PDU
799 static int process_lsp(uint8_t pdu_type
, struct isis_circuit
*circuit
,
800 const uint8_t *ssnpa
, uint8_t max_area_addrs
)
804 size_t pdu_start
= stream_get_getp(circuit
->rcv_stream
);
805 size_t pdu_end
= stream_get_endp(circuit
->rcv_stream
);
806 char raw_pdu
[pdu_end
- pdu_start
];
808 stream_get_from(raw_pdu
, circuit
->rcv_stream
, pdu_start
,
809 pdu_end
- pdu_start
);
811 if (pdu_type
== FS_LINK_STATE
) {
814 if (max_area_addrs
!= L2_CIRCUIT_FLOODING_SCOPE
)
817 circuit_scoped
= true;
819 /* The stream is used verbatim for sending out new LSPDUs.
820 * So make sure we store it as an L2 LSPDU internally.
821 * (compare for the reverse in `send_lsp`) */
822 stream_putc_at(circuit
->rcv_stream
, 4, L2_LINK_STATE
);
823 stream_putc_at(circuit
->rcv_stream
, 7, 0);
825 if (pdu_type
== L1_LINK_STATE
)
829 circuit_scoped
= false;
832 if (isis
->debugs
& DEBUG_UPDATE_PACKETS
) {
834 "ISIS-Upd (%s): Rcvd %sL%d LSP on %s, cirType %s, cirID %u",
835 circuit
->area
->area_tag
,
836 circuit_scoped
? "Circuit scoped " : "", level
,
837 circuit
->interface
->name
,
838 circuit_t2string(circuit
->is_type
),
839 circuit
->circuit_id
);
840 if (isis
->debugs
& DEBUG_PACKET_DUMP
)
841 zlog_dump_data(STREAM_DATA(circuit
->rcv_stream
),
842 stream_get_endp(circuit
->rcv_stream
));
845 struct isis_lsp_hdr hdr
= {};
847 hdr
.pdu_len
= stream_getw(circuit
->rcv_stream
);
848 hdr
.rem_lifetime
= stream_getw(circuit
->rcv_stream
);
849 stream_get(hdr
.lsp_id
, circuit
->rcv_stream
, sizeof(hdr
.lsp_id
));
850 hdr
.seqno
= stream_getl(circuit
->rcv_stream
);
851 hdr
.checksum
= stream_getw(circuit
->rcv_stream
);
852 hdr
.lsp_bits
= stream_getc(circuit
->rcv_stream
);
855 /* send northbound notification */
856 isis_notif_lsp_received(circuit
, rawlspid_print(hdr
.lsp_id
), hdr
.seqno
,
857 time(NULL
), sysid_print(hdr
.lsp_id
));
858 #endif /* ifndef FABRICD */
860 if (pdu_len_validate(hdr
.pdu_len
, circuit
)) {
861 zlog_debug("ISIS-Upd (%s): LSP %s invalid LSP length %" PRIu16
,
862 circuit
->area
->area_tag
, rawlspid_print(hdr
.lsp_id
),
867 if (isis
->debugs
& DEBUG_UPDATE_PACKETS
) {
868 zlog_debug("ISIS-Upd (%s): Rcvd L%d LSP %s, seq 0x%08" PRIx32
869 ", cksum 0x%04" PRIx16
", lifetime %" PRIu16
870 "s, len %" PRIu16
", on %s",
871 circuit
->area
->area_tag
, level
,
872 rawlspid_print(hdr
.lsp_id
), hdr
.seqno
, hdr
.checksum
,
873 hdr
.rem_lifetime
, hdr
.pdu_len
,
874 circuit
->interface
->name
);
877 /* lsp is_type check */
878 if ((hdr
.lsp_bits
& IS_LEVEL_1
) != IS_LEVEL_1
) {
880 "ISIS-Upd (%s): LSP %s invalid LSP is type 0x%" PRIx8
,
881 circuit
->area
->area_tag
, rawlspid_print(hdr
.lsp_id
),
882 hdr
.lsp_bits
& IS_LEVEL_1_AND_2
);
883 /* continue as per RFC1122 Be liberal in what you accept, and
884 * conservative in what you send */
887 /* Checksum sanity check - FIXME: move to correct place */
888 /* 12 = sysid+pdu+remtime */
889 if (iso_csum_verify(STREAM_DATA(circuit
->rcv_stream
) + 12,
890 hdr
.pdu_len
- 12, hdr
.checksum
, 12)) {
892 "ISIS-Upd (%s): LSP %s invalid LSP checksum 0x%04" PRIx16
,
893 circuit
->area
->area_tag
, rawlspid_print(hdr
.lsp_id
),
898 /* 7.3.15.1 a) 1 - external domain circuit will discard lsps */
899 if (circuit
->ext_domain
) {
901 "ISIS-Upd (%s): LSP %s received at level %d over circuit with "
902 "externalDomain = true",
903 circuit
->area
->area_tag
, rawlspid_print(hdr
.lsp_id
),
908 /* 7.3.15.1 a) 2,3 - manualL2OnlyMode not implemented */
909 if (!(circuit
->is_type
& level
)) {
911 "ISIS-Upd (%s): LSP %s received at level %d over circuit of"
913 circuit
->area
->area_tag
, rawlspid_print(hdr
.lsp_id
),
914 level
, circuit_t2string(circuit
->is_type
));
918 struct isis_tlvs
*tlvs
= NULL
;
919 int retval
= ISIS_WARNING
;
920 const char *error_log
;
922 if (isis_unpack_tlvs(STREAM_READABLE(circuit
->rcv_stream
),
923 circuit
->rcv_stream
, &tlvs
, &error_log
)) {
924 zlog_warn("Something went wrong unpacking the LSP: %s",
927 /* send northbound notification. Note that the tlv-type and
928 * offset cannot correctly be set here as they are not returned
929 * by isis_unpack_tlvs, but in there I cannot fire a
930 * notification because I have no circuit information. So until
931 * we change the code above to return those extra fields, we
932 * will send dummy values which are ignored in the callback
934 isis_notif_lsp_error(circuit
, rawlspid_print(hdr
.lsp_id
),
936 #endif /* ifndef FABRICD */
940 /* 7.3.15.1 a) 4 - need to make sure IDLength matches */
942 /* 7.3.15.1 a) 5 - maximum area match, can be ommited since we only use
945 /* 7.3.15.1 a) 7 - password check */
946 struct isis_passwd
*passwd
= (level
== ISIS_LEVEL1
)
947 ? &circuit
->area
->area_passwd
948 : &circuit
->area
->domain_passwd
;
949 int auth_code
= isis_tlvs_auth_is_valid(tlvs
, passwd
,
950 circuit
->rcv_stream
, true);
951 if (auth_code
!= ISIS_AUTH_OK
) {
952 isis_event_auth_failure(circuit
->area
->area_tag
,
953 "LSP authentication failure",
956 /* send northbound notification */
957 if (auth_code
== ISIS_AUTH_FAILURE
) {
958 circuit
->auth_failures
++;
959 isis_notif_authentication_failure(circuit
, raw_pdu
);
960 } else { /* AUTH_TYPE_FAILURE or NO_VALIDATOR */
961 circuit
->auth_type_failures
++;
962 isis_notif_authentication_type_failure(circuit
,
965 #endif /* ifndef FABRICD */
969 /* Find the LSP in our database and compare it to this Link State header
971 struct isis_lsp
*lsp
=
972 lsp_search(&circuit
->area
->lspdb
[level
- 1], hdr
.lsp_id
);
975 comp
= lsp_compare(circuit
->area
->area_tag
, lsp
, hdr
.seqno
,
976 hdr
.checksum
, hdr
.rem_lifetime
);
977 if (lsp
&& (lsp
->own_lsp
))
980 /* 7.3.15.1 a) 6 - Must check that we have an adjacency of the same
982 /* for broadcast circuits, snpa should be compared */
984 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
) {
985 if (!isis_adj_lookup_snpa(ssnpa
,
986 circuit
->u
.bc
.adjdb
[level
- 1])) {
987 zlog_debug("(%s): DS ======= LSP %s, seq 0x%08" PRIx32
988 ", cksum 0x%04" PRIx16
", lifetime %" PRIu16
990 circuit
->area
->area_tag
,
991 rawlspid_print(hdr
.lsp_id
), hdr
.seqno
,
992 hdr
.checksum
, hdr
.rem_lifetime
,
993 circuit
->interface
->name
);
994 goto out
; /* Silently discard */
997 /* for non broadcast, we just need to find same level adj */
999 /* If no adj, or no sharing of level */
1000 if (!circuit
->u
.p2p
.neighbor
) {
1004 if (((level
== IS_LEVEL_1
)
1005 && (circuit
->u
.p2p
.neighbor
->adj_usage
1006 == ISIS_ADJ_LEVEL2
))
1007 || ((level
== IS_LEVEL_2
)
1008 && (circuit
->u
.p2p
.neighbor
->adj_usage
1009 == ISIS_ADJ_LEVEL1
)))
1017 /* 7.3.15.1 a) 7 - Passwords for level 1 - not implemented */
1019 /* 7.3.15.1 a) 8 - Passwords for level 2 - not implemented */
1021 /* 7.3.15.1 a) 9 - OriginatingLSPBufferSize - not implemented FIXME: do
1024 /* 7.3.16.2 - If this is an LSP from another IS with identical seq_num
1026 * wrong checksum, initiate a purge. */
1027 if (lsp
&& (lsp
->hdr
.seqno
== hdr
.seqno
)
1028 && (lsp
->hdr
.checksum
!= hdr
.checksum
)
1029 && hdr
.rem_lifetime
) {
1030 zlog_warn("ISIS-Upd (%s): LSP %s seq 0x%08" PRIx32
1031 " with confused checksum received.",
1032 circuit
->area
->area_tag
, rawlspid_print(hdr
.lsp_id
),
1034 hdr
.rem_lifetime
= 0;
1035 lsp_confusion
= true;
1037 lsp_confusion
= false;
1039 /* 7.3.15.1 b) - If the remaining life time is 0, we perform 7.3.16.4 */
1040 if (hdr
.rem_lifetime
== 0) {
1042 /* 7.3.16.4 a) 1) No LSP in db -> send an ack, but don't
1044 /* only needed on explicit update, eg - p2p */
1045 if (circuit
->circ_type
== CIRCUIT_T_P2P
)
1046 ack_lsp(&hdr
, circuit
, level
);
1047 goto out
; /* FIXME: do we need a purge? */
1049 if (memcmp(hdr
.lsp_id
, isis
->sysid
, ISIS_SYS_ID_LEN
)) {
1050 /* LSP by some other system -> do 7.3.16.4 b) */
1051 /* 7.3.16.4 b) 1) */
1052 if (comp
== LSP_NEWER
) {
1053 lsp_update(lsp
, &hdr
, tlvs
,
1054 circuit
->rcv_stream
,
1055 circuit
->area
, level
,
1058 isis_free_tlvs(tlvs
);
1061 lsp_flood_or_update(lsp
, NULL
,
1064 ISIS_FLAGS_CLEAR_ALL(
1065 lsp
->SSNflags
); /* FIXME:
1070 /* For the case of lsp confusion, flood
1071 * the purge back to its
1072 * originator so that it can react.
1073 * Otherwise, don't reflood
1074 * through incoming circuit as usual */
1075 if (!lsp_confusion
) {
1081 if (circuit
->circ_type
1082 != CIRCUIT_T_BROADCAST
)
1087 } /* 7.3.16.4 b) 2) */
1088 else if (comp
== LSP_EQUAL
) {
1090 isis_tx_queue_del(circuit
->tx_queue
,
1093 if (circuit
->circ_type
1094 != CIRCUIT_T_BROADCAST
)
1095 ISIS_SET_FLAG(lsp
->SSNflags
,
1097 } /* 7.3.16.4 b) 3) */
1099 isis_tx_queue_add(circuit
->tx_queue
,
1100 lsp
, TX_LSP_NORMAL
);
1101 ISIS_CLEAR_FLAG(lsp
->SSNflags
, circuit
);
1103 } else if (lsp
->hdr
.rem_lifetime
!= 0) {
1104 /* our own LSP -> 7.3.16.4 c) */
1105 if (comp
== LSP_NEWER
) {
1107 if (lsp
->hdr
.seqno
< hdr
.seqno
) {
1110 isis_notif_seqno_skipped(
1115 #endif /* ifndef FABRICD */
1116 lsp_inc_seqno(lsp
, hdr
.seqno
);
1117 lsp_flood_or_update(lsp
, NULL
,
1120 isis_tx_queue_add(circuit
->tx_queue
,
1121 lsp
, TX_LSP_NORMAL
);
1122 ISIS_CLEAR_FLAG(lsp
->SSNflags
, circuit
);
1124 if (isis
->debugs
& DEBUG_UPDATE_PACKETS
)
1126 "ISIS-Upd (%s): (1) "
1127 "re-originating LSP %s new seq "
1129 circuit
->area
->area_tag
,
1130 rawlspid_print(hdr
.lsp_id
),
1133 /* our own LSP with 0 remaining life time */
1135 /* send northbound notification */
1136 isis_notif_own_lsp_purge(
1137 circuit
, rawlspid_print(hdr
.lsp_id
));
1138 #endif /* ifndef FABRICD */
1143 /* 7.3.15.1 c) - If this is our own lsp and we don't have it initiate a
1145 if (memcmp(hdr
.lsp_id
, isis
->sysid
, ISIS_SYS_ID_LEN
) == 0) {
1147 /* 7.3.16.4: initiate a purge */
1148 lsp_purge_non_exist(level
, &hdr
, circuit
->area
);
1152 /* 7.3.15.1 d) - If this is our own lsp and we have it */
1154 /* In 7.3.16.1, If an Intermediate system R somewhere in the
1156 * has information that the current sequence number for source S
1158 * "greater" than that held by S, ... */
1160 if (comp
== LSP_NEWER
) {
1162 lsp_inc_seqno(lsp
, hdr
.seqno
);
1164 /* send northbound notification */
1165 isis_notif_seqno_skipped(circuit
,
1166 rawlspid_print(hdr
.lsp_id
));
1167 #endif /* ifndef FABRICD */
1168 if (isis
->debugs
& DEBUG_UPDATE_PACKETS
) {
1170 "ISIS-Upd (%s): (2) re-originating LSP %s new seq 0x%08" PRIx32
,
1171 circuit
->area
->area_tag
,
1172 rawlspid_print(hdr
.lsp_id
),
1175 lsp_flood(lsp
, NULL
);
1176 } else if (comp
== LSP_EQUAL
) {
1177 isis_tx_queue_del(circuit
->tx_queue
, lsp
);
1178 if (circuit
->circ_type
!= CIRCUIT_T_BROADCAST
)
1179 ISIS_SET_FLAG(lsp
->SSNflags
, circuit
);
1181 isis_tx_queue_add(circuit
->tx_queue
, lsp
,
1183 ISIS_CLEAR_FLAG(lsp
->SSNflags
, circuit
);
1186 /* 7.3.15.1 e) - This lsp originated on another system */
1188 /* 7.3.15.1 e) 1) LSP newer than the one in db or no LSP in db
1190 if ((!lsp
|| comp
== LSP_NEWER
)) {
1192 * If this lsp is a frag, need to see if we have zero
1195 struct isis_lsp
*lsp0
= NULL
;
1196 if (LSP_FRAGMENT(hdr
.lsp_id
) != 0) {
1197 uint8_t lspid
[ISIS_SYS_ID_LEN
+ 2];
1198 memcpy(lspid
, hdr
.lsp_id
, ISIS_SYS_ID_LEN
+ 1);
1199 LSP_FRAGMENT(lspid
) = 0;
1201 &circuit
->area
->lspdb
[level
- 1], lspid
);
1204 "Got lsp frag, while zero lsp not in database");
1210 lsp
= lsp_new_from_recv(
1211 &hdr
, tlvs
, circuit
->rcv_stream
, lsp0
,
1212 circuit
->area
, level
);
1214 lsp_insert(&circuit
->area
->lspdb
[level
- 1],
1216 } else /* exists, so we overwrite */
1218 lsp_update(lsp
, &hdr
, tlvs
, circuit
->rcv_stream
,
1219 circuit
->area
, level
, false);
1222 lsp_flood_or_update(lsp
, circuit
, circuit_scoped
);
1225 if (circuit
->circ_type
!= CIRCUIT_T_BROADCAST
)
1226 ISIS_SET_FLAG(lsp
->SSNflags
, circuit
);
1229 /* 7.3.15.1 e) 2) LSP equal to the one in db */
1230 else if (comp
== LSP_EQUAL
) {
1231 isis_tx_queue_del(circuit
->tx_queue
, lsp
);
1232 lsp_update(lsp
, &hdr
, tlvs
, circuit
->rcv_stream
,
1233 circuit
->area
, level
, false);
1235 if (circuit
->circ_type
!= CIRCUIT_T_BROADCAST
)
1236 ISIS_SET_FLAG(lsp
->SSNflags
, circuit
);
1238 /* 7.3.15.1 e) 3) LSP older than the one in db */
1240 isis_tx_queue_add(circuit
->tx_queue
, lsp
,
1242 ISIS_CLEAR_FLAG(lsp
->SSNflags
, circuit
);
1249 fabricd_trigger_csnp(circuit
->area
, circuit_scoped
);
1251 isis_free_tlvs(tlvs
);
1256 * Process Sequence Numbers
1258 * Section 7.3.15.2 - Action on receipt of a sequence numbers PDU
1261 static int process_snp(uint8_t pdu_type
, struct isis_circuit
*circuit
,
1262 const uint8_t *ssnpa
)
1265 size_t pdu_start
= stream_get_getp(circuit
->rcv_stream
);
1266 size_t pdu_end
= stream_get_endp(circuit
->rcv_stream
);
1267 char raw_pdu
[pdu_end
- pdu_start
];
1268 #endif /* ifndef FABRICD */
1270 bool is_csnp
= (pdu_type
== L1_COMPLETE_SEQ_NUM
1271 || pdu_type
== L2_COMPLETE_SEQ_NUM
);
1272 char typechar
= is_csnp
? 'C' : 'P';
1273 int level
= (pdu_type
== L1_COMPLETE_SEQ_NUM
1274 || pdu_type
== L1_PARTIAL_SEQ_NUM
)
1278 uint16_t pdu_len
= stream_getw(circuit
->rcv_stream
);
1279 uint8_t rem_sys_id
[ISIS_SYS_ID_LEN
];
1281 stream_get(rem_sys_id
, circuit
->rcv_stream
, ISIS_SYS_ID_LEN
);
1282 stream_forward_getp(circuit
->rcv_stream
, 1); /* Circuit ID - unused */
1284 uint8_t start_lsp_id
[ISIS_SYS_ID_LEN
+ 2] = {};
1285 uint8_t stop_lsp_id
[ISIS_SYS_ID_LEN
+ 2] = {};
1288 stream_get(start_lsp_id
, circuit
->rcv_stream
,
1289 ISIS_SYS_ID_LEN
+ 2);
1290 stream_get(stop_lsp_id
, circuit
->rcv_stream
,
1291 ISIS_SYS_ID_LEN
+ 2);
1294 if (pdu_len_validate(pdu_len
, circuit
)) {
1295 zlog_warn("Received a CSNP with bogus length %d", pdu_len
);
1296 return ISIS_WARNING
;
1299 if (isis
->debugs
& DEBUG_SNP_PACKETS
) {
1301 "ISIS-Snp (%s): Rcvd L%d %cSNP on %s, cirType %s, cirID %u",
1302 circuit
->area
->area_tag
, level
, typechar
,
1303 circuit
->interface
->name
,
1304 circuit_t2string(circuit
->is_type
),
1305 circuit
->circuit_id
);
1306 if (isis
->debugs
& DEBUG_PACKET_DUMP
)
1307 zlog_dump_data(STREAM_DATA(circuit
->rcv_stream
),
1308 stream_get_endp(circuit
->rcv_stream
));
1311 /* 7.3.15.2 a) 1 - external domain circuit will discard snp pdu */
1312 if (circuit
->ext_domain
) {
1315 "ISIS-Snp (%s): Rcvd L%d %cSNP on %s, "
1316 "skipping: circuit externalDomain = true",
1317 circuit
->area
->area_tag
, level
, typechar
,
1318 circuit
->interface
->name
);
1323 /* 7.3.15.2 a) 2,3 - manualL2OnlyMode not implemented */
1324 if (!(circuit
->is_type
& level
)) {
1326 "ISIS-Snp (%s): Rcvd L%d %cSNP on %s, "
1327 "skipping: circuit type %s does not match level %d",
1328 circuit
->area
->area_tag
, level
, typechar
,
1329 circuit
->interface
->name
,
1330 circuit_t2string(circuit
->is_type
), level
);
1335 /* 7.3.15.2 a) 4 - not applicable for CSNP only PSNPs on broadcast */
1336 if (!is_csnp
&& (circuit
->circ_type
== CIRCUIT_T_BROADCAST
)
1337 && !circuit
->u
.bc
.is_dr
[level
- 1]) {
1339 "ISIS-Snp (%s): Rcvd L%d %cSNP from %s on %s, "
1340 "skipping: we are not the DIS",
1341 circuit
->area
->area_tag
, level
, typechar
,
1342 snpa_print(ssnpa
), circuit
->interface
->name
);
1347 /* 7.3.15.2 a) 5 - need to make sure IDLength matches - already checked
1350 /* 7.3.15.2 a) 6 - maximum area match, can be ommited since we only use
1352 * - already checked */
1354 /* 7.3.15.2 a) 7 - Must check that we have an adjacency of the same
1356 /* for broadcast circuits, snpa should be compared */
1357 /* FIXME : Do we need to check SNPA? */
1358 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
) {
1359 if (!isis_adj_lookup(rem_sys_id
,
1360 circuit
->u
.bc
.adjdb
[level
- 1]))
1361 return ISIS_OK
; /* Silently discard */
1363 if (!fabricd
&& !circuit
->u
.p2p
.neighbor
) {
1364 zlog_warn("no p2p neighbor on circuit %s",
1365 circuit
->interface
->name
);
1366 return ISIS_OK
; /* Silently discard */
1370 struct isis_tlvs
*tlvs
;
1371 int retval
= ISIS_WARNING
;
1372 const char *error_log
;
1374 if (isis_unpack_tlvs(STREAM_READABLE(circuit
->rcv_stream
),
1375 circuit
->rcv_stream
, &tlvs
, &error_log
)) {
1376 zlog_warn("Something went wrong unpacking the SNP: %s",
1381 struct isis_passwd
*passwd
= (level
== IS_LEVEL_1
)
1382 ? &circuit
->area
->area_passwd
1383 : &circuit
->area
->domain_passwd
;
1384 if (CHECK_FLAG(passwd
->snp_auth
, SNP_AUTH_RECV
)) {
1385 int auth_code
= isis_tlvs_auth_is_valid(
1386 tlvs
, passwd
, circuit
->rcv_stream
, false);
1387 if (auth_code
!= ISIS_AUTH_OK
) {
1388 isis_event_auth_failure(circuit
->area
->area_tag
,
1389 "SNP authentication failure",
1392 /* send northbound notification */
1393 stream_get_from(raw_pdu
, circuit
->rcv_stream
, pdu_start
,
1394 pdu_end
- pdu_start
);
1395 if (auth_code
== ISIS_AUTH_FAILURE
) {
1396 circuit
->auth_failures
++;
1397 isis_notif_authentication_failure(circuit
,
1399 } else { /* AUTH_TYPE_FAILURE or NO_VALIDATOR */
1400 circuit
->auth_type_failures
++;
1401 isis_notif_authentication_type_failure(circuit
,
1404 #endif /* ifndef FABRICD */
1409 struct isis_lsp_entry
*entry_head
=
1410 (struct isis_lsp_entry
*)tlvs
->lsp_entries
.head
;
1412 /* debug isis snp-packets */
1413 if (isis
->debugs
& DEBUG_SNP_PACKETS
) {
1414 zlog_debug("ISIS-Snp (%s): Rcvd L%d %cSNP from %s on %s",
1415 circuit
->area
->area_tag
, level
, typechar
,
1416 snpa_print(ssnpa
), circuit
->interface
->name
);
1417 for (struct isis_lsp_entry
*entry
= entry_head
; entry
;
1418 entry
= entry
->next
) {
1420 "ISIS-Snp (%s): %cSNP entry %s, seq 0x%08" PRIx32
1421 ", cksum 0x%04" PRIx16
", lifetime %" PRIu16
"s",
1422 circuit
->area
->area_tag
, typechar
,
1423 rawlspid_print(entry
->id
), entry
->seqno
,
1424 entry
->checksum
, entry
->rem_lifetime
);
1428 bool resync_needed
= false;
1430 /* 7.3.15.2 b) Actions on LSP_ENTRIES reported */
1431 for (struct isis_lsp_entry
*entry
= entry_head
; entry
;
1432 entry
= entry
->next
) {
1433 struct isis_lsp
*lsp
=
1434 lsp_search(&circuit
->area
->lspdb
[level
- 1], entry
->id
);
1435 bool own_lsp
= !memcmp(entry
->id
, isis
->sysid
, ISIS_SYS_ID_LEN
);
1437 /* 7.3.15.2 b) 1) is this LSP newer */
1438 int cmp
= lsp_compare(circuit
->area
->area_tag
, lsp
,
1439 entry
->seqno
, entry
->checksum
,
1440 entry
->rem_lifetime
);
1441 /* 7.3.15.2 b) 2) if it equals, clear SRM on p2p */
1442 if (cmp
== LSP_EQUAL
) {
1443 /* if (circuit->circ_type !=
1444 * CIRCUIT_T_BROADCAST) */
1445 isis_tx_queue_del(circuit
->tx_queue
, lsp
);
1447 /* 7.3.15.2 b) 3) if it is older, clear SSN and set SRM
1449 else if (cmp
== LSP_OLDER
) {
1450 ISIS_CLEAR_FLAG(lsp
->SSNflags
, circuit
);
1451 isis_tx_queue_add(circuit
->tx_queue
, lsp
,
1454 /* 7.3.15.2 b) 4) if it is newer, set SSN and clear SRM
1458 lsp_inc_seqno(lsp
, entry
->seqno
);
1459 isis_tx_queue_add(circuit
->tx_queue
, lsp
,
1462 ISIS_SET_FLAG(lsp
->SSNflags
, circuit
);
1463 /* if (circuit->circ_type !=
1464 * CIRCUIT_T_BROADCAST) */
1465 isis_tx_queue_del(circuit
->tx_queue
, lsp
);
1466 resync_needed
= true;
1470 /* 7.3.15.2 b) 5) if it was not found, and all of those
1472 * insert it and set SSN on it */
1473 if (entry
->rem_lifetime
&& entry
->checksum
1474 && entry
->seqno
&& memcmp(entry
->id
, isis
->sysid
,
1476 struct isis_lsp
*lsp0
= NULL
;
1478 if (LSP_FRAGMENT(entry
->id
)) {
1479 uint8_t lspid
[ISIS_SYS_ID_LEN
+ 2];
1481 memcpy(lspid
, entry
->id
,
1482 ISIS_SYS_ID_LEN
+ 1);
1483 LSP_FRAGMENT(lspid
) = 0;
1485 &circuit
->area
->lspdb
[level
- 1],
1488 zlog_debug("Got lsp frag in snp, while zero not in database");
1492 lsp
= lsp_new(circuit
->area
, entry
->id
,
1493 entry
->rem_lifetime
, 0, 0,
1494 entry
->checksum
, lsp0
, level
);
1495 lsp_insert(&circuit
->area
->lspdb
[level
- 1],
1498 lsp_set_all_srmflags(lsp
, false);
1499 ISIS_SET_FLAG(lsp
->SSNflags
, circuit
);
1500 resync_needed
= true;
1505 /* 7.3.15.2 c) on CSNP set SRM for all in range which were not reported
1509 * Build a list from our own LSP db bounded with
1510 * start_lsp_id and stop_lsp_id
1512 struct list
*lsp_list
= list_new();
1513 lsp_build_list_nonzero_ht(&circuit
->area
->lspdb
[level
- 1],
1514 start_lsp_id
, stop_lsp_id
, lsp_list
);
1516 /* Fixme: Find a better solution */
1517 struct listnode
*node
, *nnode
;
1518 struct isis_lsp
*lsp
;
1519 for (struct isis_lsp_entry
*entry
= entry_head
; entry
;
1520 entry
= entry
->next
) {
1521 for (ALL_LIST_ELEMENTS(lsp_list
, node
, nnode
, lsp
)) {
1522 if (lsp_id_cmp(lsp
->hdr
.lsp_id
, entry
->id
)
1524 list_delete_node(lsp_list
, node
);
1530 /* on remaining LSPs we set SRM (neighbor knew not of) */
1531 for (ALL_LIST_ELEMENTS_RO(lsp_list
, node
, lsp
)) {
1532 isis_tx_queue_add(circuit
->tx_queue
, lsp
, TX_LSP_NORMAL
);
1533 resync_needed
= true;
1537 list_delete(&lsp_list
);
1540 if (fabricd_initial_sync_is_complete(circuit
->area
) && resync_needed
)
1541 zlog_warn("OpenFabric: Needed to resync LSPDB using CSNP!");
1545 isis_free_tlvs(tlvs
);
1549 static int pdu_size(uint8_t pdu_type
, uint8_t *size
)
1554 *size
= ISIS_LANHELLO_HDRLEN
;
1557 *size
= ISIS_P2PHELLO_HDRLEN
;
1562 *size
= ISIS_LSP_HDR_LEN
;
1564 case L1_COMPLETE_SEQ_NUM
:
1565 case L2_COMPLETE_SEQ_NUM
:
1566 *size
= ISIS_CSNP_HDRLEN
;
1568 case L1_PARTIAL_SEQ_NUM
:
1569 case L2_PARTIAL_SEQ_NUM
:
1570 *size
= ISIS_PSNP_HDRLEN
;
1575 *size
+= ISIS_FIXED_HDR_LEN
;
1583 int isis_handle_pdu(struct isis_circuit
*circuit
, uint8_t *ssnpa
)
1585 int retval
= ISIS_OK
;
1586 size_t pdu_start
= stream_get_getp(circuit
->rcv_stream
);
1587 size_t pdu_end
= stream_get_endp(circuit
->rcv_stream
);
1588 char raw_pdu
[pdu_end
- pdu_start
];
1590 stream_get_from(raw_pdu
, circuit
->rcv_stream
, pdu_start
,
1591 pdu_end
- pdu_start
);
1593 /* Verify that at least the 8 bytes fixed header have been received */
1594 if (stream_get_endp(circuit
->rcv_stream
) < ISIS_FIXED_HDR_LEN
) {
1595 flog_err(EC_ISIS_PACKET
, "PDU is too short to be IS-IS.");
1599 uint8_t idrp
= stream_getc(circuit
->rcv_stream
);
1600 uint8_t length
= stream_getc(circuit
->rcv_stream
);
1601 uint8_t version1
= stream_getc(circuit
->rcv_stream
);
1602 uint8_t id_len
= stream_getc(circuit
->rcv_stream
);
1603 uint8_t pdu_type
= stream_getc(circuit
->rcv_stream
)
1604 & 0x1f; /* bits 6-8 are reserved */
1605 uint8_t version2
= stream_getc(circuit
->rcv_stream
);
1607 stream_forward_getp(circuit
->rcv_stream
, 1); /* reserved */
1608 uint8_t max_area_addrs
= stream_getc(circuit
->rcv_stream
);
1610 pdu_counter_count(circuit
->area
->pdu_rx_counters
, pdu_type
);
1612 if (idrp
== ISO9542_ESIS
) {
1613 flog_err(EC_LIB_DEVELOPMENT
,
1614 "No support for ES-IS packet IDRP=%" PRIx8
, idrp
);
1618 if (idrp
!= ISO10589_ISIS
) {
1619 flog_err(EC_ISIS_PACKET
, "Not an IS-IS packet IDRP=%" PRIx8
,
1624 if (version1
!= 1) {
1625 zlog_warn("Unsupported ISIS version %" PRIu8
, version1
);
1627 /* send northbound notification */
1628 isis_notif_version_skew(circuit
, version1
, raw_pdu
);
1629 #endif /* ifndef FABRICD */
1630 return ISIS_WARNING
;
1633 if (id_len
!= 0 && id_len
!= ISIS_SYS_ID_LEN
) {
1636 "IDFieldLengthMismatch: ID Length field in a received PDU %" PRIu8
1637 ", while the parameter for this IS is %u",
1638 id_len
, ISIS_SYS_ID_LEN
);
1639 circuit
->id_len_mismatches
++;
1641 /* send northbound notification */
1642 isis_notif_id_len_mismatch(circuit
, id_len
, raw_pdu
);
1643 #endif /* ifndef FABRICD */
1647 uint8_t expected_length
;
1648 if (pdu_size(pdu_type
, &expected_length
)) {
1649 zlog_warn("Unsupported ISIS PDU %" PRIu8
, pdu_type
);
1650 return ISIS_WARNING
;
1653 if (length
!= expected_length
) {
1654 flog_err(EC_ISIS_PACKET
,
1655 "Exepected fixed header length = %" PRIu8
1657 expected_length
, length
);
1661 if (stream_get_endp(circuit
->rcv_stream
) < length
) {
1664 "PDU is too short to contain fixed header of given PDU type.");
1668 if (version2
!= 1) {
1669 zlog_warn("Unsupported ISIS PDU version %" PRIu8
, version2
);
1671 /* send northbound notification */
1672 isis_notif_version_skew(circuit
, version2
, raw_pdu
);
1673 #endif /* ifndef FABRICD */
1674 return ISIS_WARNING
;
1677 if (circuit
->is_passive
) {
1678 zlog_warn("Received ISIS PDU on passive circuit %s",
1679 circuit
->interface
->name
);
1680 return ISIS_WARNING
;
1684 if (pdu_type
!= FS_LINK_STATE
/* FS PDU doesn't contain max area addr field */
1685 && max_area_addrs
!= 0
1686 && max_area_addrs
!= isis
->max_area_addrs
) {
1689 "maximumAreaAddressesMismatch: maximumAreaAdresses in a received PDU %" PRIu8
1690 " while the parameter for this IS is %u",
1691 max_area_addrs
, isis
->max_area_addrs
);
1692 circuit
->max_area_addr_mismatches
++;
1694 /* send northbound notification */
1695 isis_notif_max_area_addr_mismatch(circuit
, max_area_addrs
,
1697 #endif /* ifndef FABRICD */
1705 if (fabricd
&& pdu_type
!= P2P_HELLO
)
1707 retval
= process_hello(pdu_type
, circuit
, ssnpa
);
1713 && pdu_type
!= L2_LINK_STATE
1714 && pdu_type
!= FS_LINK_STATE
)
1716 retval
= process_lsp(pdu_type
, circuit
, ssnpa
, max_area_addrs
);
1718 case L1_COMPLETE_SEQ_NUM
:
1719 case L2_COMPLETE_SEQ_NUM
:
1720 case L1_PARTIAL_SEQ_NUM
:
1721 case L2_PARTIAL_SEQ_NUM
:
1722 retval
= process_snp(pdu_type
, circuit
, ssnpa
);
1731 int isis_receive(struct thread
*thread
)
1733 struct isis_circuit
*circuit
;
1734 uint8_t ssnpa
[ETH_ALEN
];
1740 circuit
= THREAD_ARG(thread
);
1743 circuit
->t_read
= NULL
;
1745 isis_circuit_stream(circuit
, &circuit
->rcv_stream
);
1747 retval
= circuit
->rx(circuit
, ssnpa
);
1749 #if ISIS_METHOD != ISIS_METHOD_BPF
1750 if (retval
== ISIS_OK
)
1751 retval
= isis_handle_pdu(circuit
, ssnpa
);
1752 #endif //ISIS_METHOD != ISIS_METHOD_BPF
1755 * prepare for next packet.
1757 if (!circuit
->is_passive
)
1758 isis_circuit_prepare(circuit
);
1766 void fill_fixed_hdr(uint8_t pdu_type
, struct stream
*stream
)
1770 if (pdu_size(pdu_type
, &length
))
1771 assert(!"Unknown PDU Type");
1773 stream_putc(stream
, ISO10589_ISIS
); /* IDRP */
1774 stream_putc(stream
, length
); /* Length of fixed header */
1775 stream_putc(stream
, 1); /* Version/Protocol ID Extension 1 */
1776 stream_putc(stream
, 0); /* ID Length, 0 => 6 */
1777 stream_putc(stream
, pdu_type
);
1778 stream_putc(stream
, 1); /* Subversion */
1779 stream_putc(stream
, 0); /* Reserved */
1780 stream_putc(stream
, 0); /* Max Area Addresses 0 => 3 */
1783 static uint8_t hello_pdu_type(struct isis_circuit
*circuit
, int level
)
1785 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
)
1786 return (level
== IS_LEVEL_1
) ? L1_LAN_HELLO
: L2_LAN_HELLO
;
1791 static void put_hello_hdr(struct isis_circuit
*circuit
, int level
,
1792 size_t *len_pointer
)
1794 uint8_t pdu_type
= hello_pdu_type(circuit
, level
);
1796 isis_circuit_stream(circuit
, &circuit
->snd_stream
);
1797 fill_fixed_hdr(pdu_type
, circuit
->snd_stream
);
1799 stream_putc(circuit
->snd_stream
, circuit
->is_type
);
1800 stream_put(circuit
->snd_stream
, circuit
->area
->isis
->sysid
,
1803 uint32_t holdtime
= circuit
->hello_multiplier
[level
- 1]
1804 * circuit
->hello_interval
[level
- 1];
1806 if (holdtime
> 0xffff)
1809 stream_putw(circuit
->snd_stream
, holdtime
);
1810 *len_pointer
= stream_get_endp(circuit
->snd_stream
);
1811 stream_putw(circuit
->snd_stream
, 0); /* length is filled in later */
1813 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
) {
1814 uint8_t *desig_is
= (level
== IS_LEVEL_1
)
1815 ? circuit
->u
.bc
.l1_desig_is
1816 : circuit
->u
.bc
.l2_desig_is
;
1817 stream_putc(circuit
->snd_stream
, circuit
->priority
[level
- 1]);
1818 stream_put(circuit
->snd_stream
, desig_is
, ISIS_SYS_ID_LEN
+ 1);
1820 stream_putc(circuit
->snd_stream
, circuit
->circuit_id
);
1824 int send_hello(struct isis_circuit
*circuit
, int level
)
1829 if (circuit
->is_passive
)
1832 if (circuit
->interface
->mtu
== 0) {
1833 zlog_warn("circuit has zero MTU");
1834 return ISIS_WARNING
;
1837 put_hello_hdr(circuit
, level
, &len_pointer
);
1839 struct isis_tlvs
*tlvs
= isis_alloc_tlvs();
1841 isis_tlvs_add_auth(tlvs
, &circuit
->passwd
);
1843 if (!listcount(circuit
->area
->area_addrs
)) {
1844 isis_free_tlvs(tlvs
);
1845 return ISIS_WARNING
;
1848 isis_tlvs_add_area_addresses(tlvs
, circuit
->area
->area_addrs
);
1850 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
) {
1851 isis_tlvs_add_lan_neighbors(
1852 tlvs
, circuit
->u
.bc
.lan_neighs
[level
- 1]);
1853 } else if (circuit
->circ_type
== CIRCUIT_T_P2P
1854 && !circuit
->disable_threeway_adj
) {
1855 uint32_t ext_circuit_id
= circuit
->idx
;
1856 if (circuit
->u
.p2p
.neighbor
) {
1857 uint8_t threeway_state
;
1859 if (fabricd_initial_sync_is_in_progress(circuit
->area
)
1860 && fabricd_initial_sync_circuit(circuit
->area
) != circuit
)
1861 threeway_state
= ISIS_THREEWAY_DOWN
;
1863 threeway_state
= circuit
->u
.p2p
.neighbor
->threeway_state
;
1864 isis_tlvs_add_threeway_adj(tlvs
,
1867 circuit
->u
.p2p
.neighbor
->sysid
,
1868 circuit
->u
.p2p
.neighbor
->ext_circuit_id
);
1870 isis_tlvs_add_threeway_adj(tlvs
,
1877 isis_tlvs_set_protocols_supported(tlvs
, &circuit
->nlpids
);
1882 * TLV gets included if no topology is enabled on the interface,
1883 * if one topology other than #0 is enabled, or if multiple topologies
1886 struct isis_circuit_mt_setting
**mt_settings
;
1887 unsigned int mt_count
;
1889 mt_settings
= circuit_mt_settings(circuit
, &mt_count
);
1890 if (mt_count
== 0 && area_is_mt(circuit
->area
)) {
1891 tlvs
->mt_router_info_empty
= true;
1892 } else if ((mt_count
== 1
1893 && mt_settings
[0]->mtid
!= ISIS_MT_IPV4_UNICAST
)
1894 || (mt_count
> 1)) {
1895 for (unsigned int i
= 0; i
< mt_count
; i
++)
1896 isis_tlvs_add_mt_router_info(tlvs
, mt_settings
[i
]->mtid
,
1900 if (circuit
->ip_router
) {
1901 struct list
*circuit_ip_addrs
= fabricd_ip_addrs(circuit
);
1903 if (circuit_ip_addrs
)
1904 isis_tlvs_add_ipv4_addresses(tlvs
, circuit_ip_addrs
);
1907 if (circuit
->ipv6_router
&& circuit
->ipv6_link
)
1908 isis_tlvs_add_ipv6_addresses(tlvs
, circuit
->ipv6_link
);
1910 if (isis_pack_tlvs(tlvs
, circuit
->snd_stream
, len_pointer
,
1911 circuit
->pad_hellos
, false)) {
1912 isis_free_tlvs(tlvs
);
1913 return ISIS_WARNING
; /* XXX: Maybe Log TLV structure? */
1916 if (isis
->debugs
& DEBUG_ADJ_PACKETS
) {
1917 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
) {
1919 "ISIS-Adj (%s): Sending L%d LAN IIH on %s, length %zd",
1920 circuit
->area
->area_tag
, level
,
1921 circuit
->interface
->name
,
1922 stream_get_endp(circuit
->snd_stream
));
1925 "ISIS-Adj (%s): Sending P2P IIH on %s, length %zd",
1926 circuit
->area
->area_tag
,
1927 circuit
->interface
->name
,
1928 stream_get_endp(circuit
->snd_stream
));
1930 if (isis
->debugs
& DEBUG_PACKET_DUMP
)
1931 zlog_dump_data(STREAM_DATA(circuit
->snd_stream
),
1932 stream_get_endp(circuit
->snd_stream
));
1935 isis_free_tlvs(tlvs
);
1937 pdu_counter_count(circuit
->area
->pdu_tx_counters
,
1938 hello_pdu_type(circuit
, level
));
1939 retval
= circuit
->tx(circuit
, level
);
1940 if (retval
!= ISIS_OK
)
1941 flog_err(EC_ISIS_PACKET
,
1942 "ISIS-Adj (%s): Send L%d IIH on %s failed",
1943 circuit
->area
->area_tag
, level
,
1944 circuit
->interface
->name
);
1949 static int send_hello_cb(struct thread
*thread
)
1951 struct isis_circuit_arg
*arg
= THREAD_ARG(thread
);
1954 struct isis_circuit
*circuit
= arg
->circuit
;
1955 int level
= arg
->level
;
1959 if (circuit
->circ_type
== CIRCUIT_T_P2P
) {
1960 circuit
->u
.p2p
.t_send_p2p_hello
= NULL
;
1961 send_hello(circuit
, 1);
1962 send_hello_sched(circuit
, ISIS_LEVEL1
,
1963 1000 * circuit
->hello_interval
[1]);
1967 if (circuit
->circ_type
!= CIRCUIT_T_BROADCAST
) {
1968 zlog_warn("ISIS-Hello (%s): Trying to send hello on unknown circuit type %d",
1969 circuit
->area
->area_tag
, circuit
->circ_type
);
1970 return ISIS_WARNING
;
1973 circuit
->u
.bc
.t_send_lan_hello
[level
- 1] = NULL
;
1974 if (!(circuit
->is_type
& level
)) {
1975 zlog_warn("ISIS-Hello (%s): Trying to send L%d IIH in L%d-only circuit",
1976 circuit
->area
->area_tag
, level
, 3 - level
);
1977 return ISIS_WARNING
;
1980 if (circuit
->u
.bc
.run_dr_elect
[level
- 1])
1981 isis_dr_elect(circuit
, level
);
1983 int rv
= send_hello(circuit
, level
);
1985 /* set next timer thread */
1986 send_hello_sched(circuit
, level
, 1000 * circuit
->hello_interval
[level
- 1]);
1990 static void _send_hello_sched(struct isis_circuit
*circuit
,
1991 struct thread
**threadp
,
1992 int level
, long delay
)
1995 if (thread_timer_remain_msec(*threadp
) < (unsigned long)delay
)
1998 thread_cancel(*threadp
);
2001 thread_add_timer_msec(master
, send_hello_cb
,
2002 &circuit
->level_arg
[level
- 1],
2003 isis_jitter(delay
, IIH_JITTER
),
2007 void send_hello_sched(struct isis_circuit
*circuit
, int level
, long delay
)
2009 if (circuit
->circ_type
== CIRCUIT_T_P2P
) {
2010 _send_hello_sched(circuit
, &circuit
->u
.p2p
.t_send_p2p_hello
,
2011 ISIS_LEVEL1
, delay
);
2015 if (circuit
->circ_type
!= CIRCUIT_T_BROADCAST
) {
2016 zlog_warn("%s: encountered unknown circuit type %d on %s",
2017 __func__
, circuit
->circ_type
,
2018 circuit
->interface
->name
);
2022 for (int loop_level
= ISIS_LEVEL1
; loop_level
<= ISIS_LEVEL2
; loop_level
++) {
2023 if (!(loop_level
& level
))
2028 &circuit
->u
.bc
.t_send_lan_hello
[loop_level
- 1],
2037 * Count the maximum number of lsps that can be accomodated by a given size.
2039 #define LSP_ENTRIES_LEN (10 + ISIS_SYS_ID_LEN)
2040 static uint16_t get_max_lsp_count(uint16_t size
)
2044 uint16_t remaining_size
;
2046 /* First count the full size TLVs */
2047 tlv_count
= size
/ MAX_LSP_ENTRIES_TLV_SIZE
;
2048 lsp_count
= tlv_count
* (MAX_LSP_ENTRIES_TLV_SIZE
/ LSP_ENTRIES_LEN
);
2050 /* The last TLV, if any */
2051 remaining_size
= size
% MAX_LSP_ENTRIES_TLV_SIZE
;
2052 if (remaining_size
- 2 >= LSP_ENTRIES_LEN
)
2053 lsp_count
+= (remaining_size
- 2) / LSP_ENTRIES_LEN
;
2058 int send_csnp(struct isis_circuit
*circuit
, int level
)
2060 if (lspdb_count(&circuit
->area
->lspdb
[level
- 1]) == 0)
2063 uint8_t pdu_type
= (level
== ISIS_LEVEL1
) ? L1_COMPLETE_SEQ_NUM
2064 : L2_COMPLETE_SEQ_NUM
;
2066 isis_circuit_stream(circuit
, &circuit
->snd_stream
);
2067 fill_fixed_hdr(pdu_type
, circuit
->snd_stream
);
2069 size_t len_pointer
= stream_get_endp(circuit
->snd_stream
);
2070 stream_putw(circuit
->snd_stream
, 0);
2071 stream_put(circuit
->snd_stream
, isis
->sysid
, ISIS_SYS_ID_LEN
);
2072 /* with zero circuit id - ref 9.10, 9.11 */
2073 stream_putc(circuit
->snd_stream
, 0);
2075 size_t start_pointer
= stream_get_endp(circuit
->snd_stream
);
2076 stream_put(circuit
->snd_stream
, 0, ISIS_SYS_ID_LEN
+ 2);
2077 size_t end_pointer
= stream_get_endp(circuit
->snd_stream
);
2078 stream_put(circuit
->snd_stream
, 0, ISIS_SYS_ID_LEN
+ 2);
2080 struct isis_passwd
*passwd
= (level
== ISIS_LEVEL1
)
2081 ? &circuit
->area
->area_passwd
2082 : &circuit
->area
->domain_passwd
;
2084 struct isis_tlvs
*tlvs
= isis_alloc_tlvs();
2086 if (CHECK_FLAG(passwd
->snp_auth
, SNP_AUTH_SEND
))
2087 isis_tlvs_add_auth(tlvs
, passwd
);
2089 size_t tlv_start
= stream_get_endp(circuit
->snd_stream
);
2090 if (isis_pack_tlvs(tlvs
, circuit
->snd_stream
, len_pointer
, false,
2092 isis_free_tlvs(tlvs
);
2093 return ISIS_WARNING
;
2095 isis_free_tlvs(tlvs
);
2098 get_max_lsp_count(STREAM_WRITEABLE(circuit
->snd_stream
));
2100 uint8_t start
[ISIS_SYS_ID_LEN
+ 2];
2101 memset(start
, 0x00, ISIS_SYS_ID_LEN
+ 2);
2102 uint8_t stop
[ISIS_SYS_ID_LEN
+ 2];
2103 memset(stop
, 0xff, ISIS_SYS_ID_LEN
+ 2);
2107 tlvs
= isis_alloc_tlvs();
2108 if (CHECK_FLAG(passwd
->snp_auth
, SNP_AUTH_SEND
))
2109 isis_tlvs_add_auth(tlvs
, passwd
);
2111 struct isis_lsp
*last_lsp
;
2112 isis_tlvs_add_csnp_entries(tlvs
, start
, stop
, num_lsps
,
2113 &circuit
->area
->lspdb
[level
- 1],
2116 * Update the stop lsp_id before encoding this CSNP.
2118 if (tlvs
->lsp_entries
.count
< num_lsps
) {
2119 memset(stop
, 0xff, ISIS_SYS_ID_LEN
+ 2);
2121 memcpy(stop
, last_lsp
->hdr
.lsp_id
, sizeof(stop
));
2124 memcpy(STREAM_DATA(circuit
->snd_stream
) + start_pointer
, start
,
2125 ISIS_SYS_ID_LEN
+ 2);
2126 memcpy(STREAM_DATA(circuit
->snd_stream
) + end_pointer
, stop
,
2127 ISIS_SYS_ID_LEN
+ 2);
2128 stream_set_endp(circuit
->snd_stream
, tlv_start
);
2129 if (isis_pack_tlvs(tlvs
, circuit
->snd_stream
, len_pointer
,
2131 isis_free_tlvs(tlvs
);
2132 return ISIS_WARNING
;
2135 if (isis
->debugs
& DEBUG_SNP_PACKETS
) {
2137 "ISIS-Snp (%s): Sending L%d CSNP on %s, length %zd",
2138 circuit
->area
->area_tag
, level
,
2139 circuit
->interface
->name
,
2140 stream_get_endp(circuit
->snd_stream
));
2141 log_multiline(LOG_DEBUG
, " ", "%s",
2142 isis_format_tlvs(tlvs
));
2143 if (isis
->debugs
& DEBUG_PACKET_DUMP
)
2145 STREAM_DATA(circuit
->snd_stream
),
2146 stream_get_endp(circuit
->snd_stream
));
2149 pdu_counter_count(circuit
->area
->pdu_tx_counters
, pdu_type
);
2150 int retval
= circuit
->tx(circuit
, level
);
2151 if (retval
!= ISIS_OK
) {
2152 flog_err(EC_ISIS_PACKET
,
2153 "ISIS-Snp (%s): Send L%d CSNP on %s failed",
2154 circuit
->area
->area_tag
, level
,
2155 circuit
->interface
->name
);
2156 isis_free_tlvs(tlvs
);
2161 * Start lsp_id of the next CSNP should be one plus the
2162 * stop lsp_id in this current CSNP.
2164 memcpy(start
, stop
, ISIS_SYS_ID_LEN
+ 2);
2166 for (int i
= ISIS_SYS_ID_LEN
+ 1; i
>= 0; --i
) {
2167 if (start
[i
] < (uint8_t)0xff) {
2173 memset(stop
, 0xff, ISIS_SYS_ID_LEN
+ 2);
2174 isis_free_tlvs(tlvs
);
2180 int send_l1_csnp(struct thread
*thread
)
2182 struct isis_circuit
*circuit
;
2184 circuit
= THREAD_ARG(thread
);
2187 circuit
->t_send_csnp
[0] = NULL
;
2189 if ((circuit
->circ_type
== CIRCUIT_T_BROADCAST
2190 && circuit
->u
.bc
.is_dr
[0])
2191 || circuit
->circ_type
== CIRCUIT_T_P2P
) {
2192 send_csnp(circuit
, 1);
2194 /* set next timer thread */
2195 thread_add_timer(master
, send_l1_csnp
, circuit
,
2196 isis_jitter(circuit
->csnp_interval
[0], CSNP_JITTER
),
2197 &circuit
->t_send_csnp
[0]);
2202 int send_l2_csnp(struct thread
*thread
)
2204 struct isis_circuit
*circuit
;
2206 circuit
= THREAD_ARG(thread
);
2209 circuit
->t_send_csnp
[1] = NULL
;
2211 if ((circuit
->circ_type
== CIRCUIT_T_BROADCAST
2212 && circuit
->u
.bc
.is_dr
[1])
2213 || circuit
->circ_type
== CIRCUIT_T_P2P
) {
2214 send_csnp(circuit
, 2);
2216 /* set next timer thread */
2217 thread_add_timer(master
, send_l2_csnp
, circuit
,
2218 isis_jitter(circuit
->csnp_interval
[1], CSNP_JITTER
),
2219 &circuit
->t_send_csnp
[1]);
2225 * 7.3.15.4 action on expiration of partial SNP interval
2228 static int send_psnp(int level
, struct isis_circuit
*circuit
)
2230 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
2231 && circuit
->u
.bc
.is_dr
[level
- 1])
2234 if (lspdb_count(&circuit
->area
->lspdb
[level
- 1]) == 0)
2237 if (!circuit
->snd_stream
)
2240 uint8_t pdu_type
= (level
== ISIS_LEVEL1
) ? L1_PARTIAL_SEQ_NUM
2241 : L2_PARTIAL_SEQ_NUM
;
2243 isis_circuit_stream(circuit
, &circuit
->snd_stream
);
2244 fill_fixed_hdr(pdu_type
, circuit
->snd_stream
);
2246 size_t len_pointer
= stream_get_endp(circuit
->snd_stream
);
2247 stream_putw(circuit
->snd_stream
, 0); /* length is filled in later */
2248 stream_put(circuit
->snd_stream
, isis
->sysid
, ISIS_SYS_ID_LEN
);
2249 stream_putc(circuit
->snd_stream
, circuit
->idx
);
2251 struct isis_passwd
*passwd
= (level
== ISIS_LEVEL1
)
2252 ? &circuit
->area
->area_passwd
2253 : &circuit
->area
->domain_passwd
;
2255 struct isis_tlvs
*tlvs
= isis_alloc_tlvs();
2257 if (CHECK_FLAG(passwd
->snp_auth
, SNP_AUTH_SEND
))
2258 isis_tlvs_add_auth(tlvs
, passwd
);
2260 size_t tlv_start
= stream_get_endp(circuit
->snd_stream
);
2261 if (isis_pack_tlvs(tlvs
, circuit
->snd_stream
, len_pointer
, false,
2263 isis_free_tlvs(tlvs
);
2264 return ISIS_WARNING
;
2266 isis_free_tlvs(tlvs
);
2269 get_max_lsp_count(STREAM_WRITEABLE(circuit
->snd_stream
));
2272 struct isis_lsp
*lsp
;
2274 tlvs
= isis_alloc_tlvs();
2275 if (CHECK_FLAG(passwd
->snp_auth
, SNP_AUTH_SEND
))
2276 isis_tlvs_add_auth(tlvs
, passwd
);
2278 frr_each (lspdb
, &circuit
->area
->lspdb
[level
- 1], lsp
) {
2279 if (ISIS_CHECK_FLAG(lsp
->SSNflags
, circuit
))
2280 isis_tlvs_add_lsp_entry(tlvs
, lsp
);
2282 if (tlvs
->lsp_entries
.count
== num_lsps
)
2286 if (!tlvs
->lsp_entries
.count
) {
2287 isis_free_tlvs(tlvs
);
2291 stream_set_endp(circuit
->snd_stream
, tlv_start
);
2292 if (isis_pack_tlvs(tlvs
, circuit
->snd_stream
, len_pointer
,
2294 isis_free_tlvs(tlvs
);
2295 return ISIS_WARNING
;
2298 if (isis
->debugs
& DEBUG_SNP_PACKETS
) {
2300 "ISIS-Snp (%s): Sending L%d PSNP on %s, length %zd",
2301 circuit
->area
->area_tag
, level
,
2302 circuit
->interface
->name
,
2303 stream_get_endp(circuit
->snd_stream
));
2304 log_multiline(LOG_DEBUG
, " ", "%s",
2305 isis_format_tlvs(tlvs
));
2306 if (isis
->debugs
& DEBUG_PACKET_DUMP
)
2308 STREAM_DATA(circuit
->snd_stream
),
2309 stream_get_endp(circuit
->snd_stream
));
2312 pdu_counter_count(circuit
->area
->pdu_tx_counters
, pdu_type
);
2313 int retval
= circuit
->tx(circuit
, level
);
2314 if (retval
!= ISIS_OK
) {
2315 flog_err(EC_ISIS_PACKET
,
2316 "ISIS-Snp (%s): Send L%d PSNP on %s failed",
2317 circuit
->area
->area_tag
, level
,
2318 circuit
->interface
->name
);
2319 isis_free_tlvs(tlvs
);
2324 * sending succeeded, we can clear SSN flags of this circuit
2325 * for the LSPs in list
2327 struct isis_lsp_entry
*entry_head
;
2328 entry_head
= (struct isis_lsp_entry
*)tlvs
->lsp_entries
.head
;
2329 for (struct isis_lsp_entry
*entry
= entry_head
; entry
;
2330 entry
= entry
->next
)
2331 ISIS_CLEAR_FLAG(entry
->lsp
->SSNflags
, circuit
);
2332 isis_free_tlvs(tlvs
);
2338 int send_l1_psnp(struct thread
*thread
)
2341 struct isis_circuit
*circuit
;
2343 circuit
= THREAD_ARG(thread
);
2346 circuit
->t_send_psnp
[0] = NULL
;
2348 send_psnp(1, circuit
);
2349 /* set next timer thread */
2350 thread_add_timer(master
, send_l1_psnp
, circuit
,
2351 isis_jitter(circuit
->psnp_interval
[0], PSNP_JITTER
),
2352 &circuit
->t_send_psnp
[0]);
2358 * 7.3.15.4 action on expiration of partial SNP interval
2361 int send_l2_psnp(struct thread
*thread
)
2363 struct isis_circuit
*circuit
;
2365 circuit
= THREAD_ARG(thread
);
2368 circuit
->t_send_psnp
[1] = NULL
;
2370 send_psnp(2, circuit
);
2372 /* set next timer thread */
2373 thread_add_timer(master
, send_l2_psnp
, circuit
,
2374 isis_jitter(circuit
->psnp_interval
[1], PSNP_JITTER
),
2375 &circuit
->t_send_psnp
[1]);
2381 * ISO 10589 - 7.3.14.3
2383 void send_lsp(struct isis_circuit
*circuit
, struct isis_lsp
*lsp
,
2384 enum isis_tx_type tx_type
)
2387 int retval
= ISIS_OK
;
2389 if (circuit
->state
!= C_STATE_UP
|| circuit
->is_passive
== 1)
2393 * Do not send if levels do not match
2395 if (!(lsp
->level
& circuit
->is_type
))
2399 * Do not send if we do not have adjacencies in state up on the circuit
2401 if (circuit
->upadjcount
[lsp
->level
- 1] == 0)
2404 /* stream_copy will assert and stop program execution if LSP is larger
2406 * the circuit's MTU. So handle and log this case here. */
2407 if (stream_get_endp(lsp
->pdu
) > stream_get_size(circuit
->snd_stream
)) {
2410 "ISIS-Upd (%s): Can't send L%d LSP %s, seq 0x%08" PRIx32
2411 ", cksum 0x%04" PRIx16
", lifetime %" PRIu16
2412 "s on %s. LSP Size is %zu while interface stream size is %zu.",
2413 circuit
->area
->area_tag
, lsp
->level
,
2414 rawlspid_print(lsp
->hdr
.lsp_id
), lsp
->hdr
.seqno
,
2415 lsp
->hdr
.checksum
, lsp
->hdr
.rem_lifetime
,
2416 circuit
->interface
->name
, stream_get_endp(lsp
->pdu
),
2417 stream_get_size(circuit
->snd_stream
));
2419 /* send a northbound notification */
2420 isis_notif_lsp_too_large(circuit
, stream_get_endp(lsp
->pdu
),
2421 rawlspid_print(lsp
->hdr
.lsp_id
));
2422 #endif /* ifndef FABRICD */
2423 if (isis
->debugs
& DEBUG_PACKET_DUMP
)
2424 zlog_dump_data(STREAM_DATA(lsp
->pdu
),
2425 stream_get_endp(lsp
->pdu
));
2426 retval
= ISIS_ERROR
;
2430 /* copy our lsp to the send buffer */
2431 stream_copy(circuit
->snd_stream
, lsp
->pdu
);
2433 if (tx_type
== TX_LSP_CIRCUIT_SCOPED
) {
2434 stream_putc_at(circuit
->snd_stream
, 4, FS_LINK_STATE
);
2435 stream_putc_at(circuit
->snd_stream
, 7,
2436 L2_CIRCUIT_FLOODING_SCOPE
);
2439 if (isis
->debugs
& DEBUG_UPDATE_PACKETS
) {
2440 zlog_debug("ISIS-Upd (%s): Sending %sL%d LSP %s, seq 0x%08" PRIx32
2441 ", cksum 0x%04" PRIx16
", lifetime %" PRIu16
2443 circuit
->area
->area_tag
,
2444 (tx_type
== TX_LSP_CIRCUIT_SCOPED
)
2445 ? "Circuit scoped " : "",
2447 rawlspid_print(lsp
->hdr
.lsp_id
), lsp
->hdr
.seqno
,
2448 lsp
->hdr
.checksum
, lsp
->hdr
.rem_lifetime
,
2449 circuit
->interface
->name
);
2450 if (isis
->debugs
& DEBUG_PACKET_DUMP
)
2451 zlog_dump_data(STREAM_DATA(circuit
->snd_stream
),
2452 stream_get_endp(circuit
->snd_stream
));
2455 uint8_t pdu_type
= (tx_type
== TX_LSP_CIRCUIT_SCOPED
) ? FS_LINK_STATE
2456 : (lsp
->level
== ISIS_LEVEL1
) ? L1_LINK_STATE
2460 pdu_counter_count(circuit
->area
->pdu_tx_counters
, pdu_type
);
2461 retval
= circuit
->tx(circuit
, lsp
->level
);
2462 if (retval
!= ISIS_OK
) {
2463 flog_err(EC_ISIS_PACKET
,
2464 "ISIS-Upd (%s): Send L%d LSP on %s failed %s",
2465 circuit
->area
->area_tag
, lsp
->level
,
2466 circuit
->interface
->name
,
2467 (retval
== ISIS_WARNING
) ? "temporarily"
2473 || (retval
== ISIS_OK
&& circuit
->circ_type
== CIRCUIT_T_BROADCAST
)
2474 || (retval
!= ISIS_OK
&& retval
!= ISIS_WARNING
)) {
2475 /* SRM flag will trigger retransmission. We will not retransmit
2477 * encountered a fatal error.
2478 * On success, they should only be cleared if it's a broadcast
2480 * On a P2P circuit, we will wait for the ack from the neighbor
2484 isis_tx_queue_del(circuit
->tx_queue
, lsp
);