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
,
1059 lsp_flood_or_update(lsp
, NULL
,
1062 ISIS_FLAGS_CLEAR_ALL(
1063 lsp
->SSNflags
); /* FIXME:
1068 /* For the case of lsp confusion, flood
1069 * the purge back to its
1070 * originator so that it can react.
1071 * Otherwise, don't reflood
1072 * through incoming circuit as usual */
1073 if (!lsp_confusion
) {
1079 if (circuit
->circ_type
1080 != CIRCUIT_T_BROADCAST
)
1085 } /* 7.3.16.4 b) 2) */
1086 else if (comp
== LSP_EQUAL
) {
1088 isis_tx_queue_del(circuit
->tx_queue
,
1091 if (circuit
->circ_type
1092 != CIRCUIT_T_BROADCAST
)
1093 ISIS_SET_FLAG(lsp
->SSNflags
,
1095 } /* 7.3.16.4 b) 3) */
1097 isis_tx_queue_add(circuit
->tx_queue
,
1098 lsp
, TX_LSP_NORMAL
);
1099 ISIS_CLEAR_FLAG(lsp
->SSNflags
, circuit
);
1101 } else if (lsp
->hdr
.rem_lifetime
!= 0) {
1102 /* our own LSP -> 7.3.16.4 c) */
1103 if (comp
== LSP_NEWER
) {
1105 if (lsp
->hdr
.seqno
< hdr
.seqno
) {
1108 isis_notif_seqno_skipped(
1113 #endif /* ifndef FABRICD */
1114 lsp_inc_seqno(lsp
, hdr
.seqno
);
1115 lsp_flood_or_update(lsp
, NULL
,
1118 isis_tx_queue_add(circuit
->tx_queue
,
1119 lsp
, TX_LSP_NORMAL
);
1120 ISIS_CLEAR_FLAG(lsp
->SSNflags
, circuit
);
1122 if (isis
->debugs
& DEBUG_UPDATE_PACKETS
)
1124 "ISIS-Upd (%s): (1) "
1125 "re-originating LSP %s new seq "
1127 circuit
->area
->area_tag
,
1128 rawlspid_print(hdr
.lsp_id
),
1131 /* our own LSP with 0 remaining life time */
1133 /* send northbound notification */
1134 isis_notif_own_lsp_purge(
1135 circuit
, rawlspid_print(hdr
.lsp_id
));
1136 #endif /* ifndef FABRICD */
1141 /* 7.3.15.1 c) - If this is our own lsp and we don't have it initiate a
1143 if (memcmp(hdr
.lsp_id
, isis
->sysid
, ISIS_SYS_ID_LEN
) == 0) {
1145 /* 7.3.16.4: initiate a purge */
1146 lsp_purge_non_exist(level
, &hdr
, circuit
->area
);
1150 /* 7.3.15.1 d) - If this is our own lsp and we have it */
1152 /* In 7.3.16.1, If an Intermediate system R somewhere in the
1154 * has information that the current sequence number for source S
1156 * "greater" than that held by S, ... */
1158 if (comp
== LSP_NEWER
) {
1160 lsp_inc_seqno(lsp
, hdr
.seqno
);
1162 /* send northbound notification */
1163 isis_notif_seqno_skipped(circuit
,
1164 rawlspid_print(hdr
.lsp_id
));
1165 #endif /* ifndef FABRICD */
1166 if (isis
->debugs
& DEBUG_UPDATE_PACKETS
) {
1168 "ISIS-Upd (%s): (2) re-originating LSP %s new seq 0x%08" PRIx32
,
1169 circuit
->area
->area_tag
,
1170 rawlspid_print(hdr
.lsp_id
),
1173 lsp_flood(lsp
, NULL
);
1174 } else if (comp
== LSP_EQUAL
) {
1175 isis_tx_queue_del(circuit
->tx_queue
, lsp
);
1176 if (circuit
->circ_type
!= CIRCUIT_T_BROADCAST
)
1177 ISIS_SET_FLAG(lsp
->SSNflags
, circuit
);
1179 isis_tx_queue_add(circuit
->tx_queue
, lsp
,
1181 ISIS_CLEAR_FLAG(lsp
->SSNflags
, circuit
);
1184 /* 7.3.15.1 e) - This lsp originated on another system */
1186 /* 7.3.15.1 e) 1) LSP newer than the one in db or no LSP in db
1188 if ((!lsp
|| comp
== LSP_NEWER
)) {
1190 * If this lsp is a frag, need to see if we have zero
1193 struct isis_lsp
*lsp0
= NULL
;
1194 if (LSP_FRAGMENT(hdr
.lsp_id
) != 0) {
1195 uint8_t lspid
[ISIS_SYS_ID_LEN
+ 2];
1196 memcpy(lspid
, hdr
.lsp_id
, ISIS_SYS_ID_LEN
+ 1);
1197 LSP_FRAGMENT(lspid
) = 0;
1199 &circuit
->area
->lspdb
[level
- 1], lspid
);
1202 "Got lsp frag, while zero lsp not in database");
1208 lsp
= lsp_new_from_recv(
1209 &hdr
, tlvs
, circuit
->rcv_stream
, lsp0
,
1210 circuit
->area
, level
);
1212 lsp_insert(&circuit
->area
->lspdb
[level
- 1],
1214 } else /* exists, so we overwrite */
1216 lsp_update(lsp
, &hdr
, tlvs
, circuit
->rcv_stream
,
1217 circuit
->area
, level
, false);
1220 lsp_flood_or_update(lsp
, circuit
, circuit_scoped
);
1223 if (circuit
->circ_type
!= CIRCUIT_T_BROADCAST
)
1224 ISIS_SET_FLAG(lsp
->SSNflags
, circuit
);
1227 /* 7.3.15.1 e) 2) LSP equal to the one in db */
1228 else if (comp
== LSP_EQUAL
) {
1229 isis_tx_queue_del(circuit
->tx_queue
, lsp
);
1230 lsp_update(lsp
, &hdr
, tlvs
, circuit
->rcv_stream
,
1231 circuit
->area
, level
, false);
1233 if (circuit
->circ_type
!= CIRCUIT_T_BROADCAST
)
1234 ISIS_SET_FLAG(lsp
->SSNflags
, circuit
);
1236 /* 7.3.15.1 e) 3) LSP older than the one in db */
1238 isis_tx_queue_add(circuit
->tx_queue
, lsp
,
1240 ISIS_CLEAR_FLAG(lsp
->SSNflags
, circuit
);
1247 fabricd_trigger_csnp(circuit
->area
, circuit_scoped
);
1249 isis_free_tlvs(tlvs
);
1254 * Process Sequence Numbers
1256 * Section 7.3.15.2 - Action on receipt of a sequence numbers PDU
1259 static int process_snp(uint8_t pdu_type
, struct isis_circuit
*circuit
,
1260 const uint8_t *ssnpa
)
1263 size_t pdu_start
= stream_get_getp(circuit
->rcv_stream
);
1264 size_t pdu_end
= stream_get_endp(circuit
->rcv_stream
);
1265 char raw_pdu
[pdu_end
- pdu_start
];
1266 #endif /* ifndef FABRICD */
1268 bool is_csnp
= (pdu_type
== L1_COMPLETE_SEQ_NUM
1269 || pdu_type
== L2_COMPLETE_SEQ_NUM
);
1270 char typechar
= is_csnp
? 'C' : 'P';
1271 int level
= (pdu_type
== L1_COMPLETE_SEQ_NUM
1272 || pdu_type
== L1_PARTIAL_SEQ_NUM
)
1276 uint16_t pdu_len
= stream_getw(circuit
->rcv_stream
);
1277 uint8_t rem_sys_id
[ISIS_SYS_ID_LEN
];
1279 stream_get(rem_sys_id
, circuit
->rcv_stream
, ISIS_SYS_ID_LEN
);
1280 stream_forward_getp(circuit
->rcv_stream
, 1); /* Circuit ID - unused */
1282 uint8_t start_lsp_id
[ISIS_SYS_ID_LEN
+ 2] = {};
1283 uint8_t stop_lsp_id
[ISIS_SYS_ID_LEN
+ 2] = {};
1286 stream_get(start_lsp_id
, circuit
->rcv_stream
,
1287 ISIS_SYS_ID_LEN
+ 2);
1288 stream_get(stop_lsp_id
, circuit
->rcv_stream
,
1289 ISIS_SYS_ID_LEN
+ 2);
1292 if (pdu_len_validate(pdu_len
, circuit
)) {
1293 zlog_warn("Received a CSNP with bogus length %d", pdu_len
);
1294 return ISIS_WARNING
;
1297 if (isis
->debugs
& DEBUG_SNP_PACKETS
) {
1299 "ISIS-Snp (%s): Rcvd L%d %cSNP on %s, cirType %s, cirID %u",
1300 circuit
->area
->area_tag
, level
, typechar
,
1301 circuit
->interface
->name
,
1302 circuit_t2string(circuit
->is_type
),
1303 circuit
->circuit_id
);
1304 if (isis
->debugs
& DEBUG_PACKET_DUMP
)
1305 zlog_dump_data(STREAM_DATA(circuit
->rcv_stream
),
1306 stream_get_endp(circuit
->rcv_stream
));
1309 /* 7.3.15.2 a) 1 - external domain circuit will discard snp pdu */
1310 if (circuit
->ext_domain
) {
1313 "ISIS-Snp (%s): Rcvd L%d %cSNP on %s, "
1314 "skipping: circuit externalDomain = true",
1315 circuit
->area
->area_tag
, level
, typechar
,
1316 circuit
->interface
->name
);
1321 /* 7.3.15.2 a) 2,3 - manualL2OnlyMode not implemented */
1322 if (!(circuit
->is_type
& level
)) {
1324 "ISIS-Snp (%s): Rcvd L%d %cSNP on %s, "
1325 "skipping: circuit type %s does not match level %d",
1326 circuit
->area
->area_tag
, level
, typechar
,
1327 circuit
->interface
->name
,
1328 circuit_t2string(circuit
->is_type
), level
);
1333 /* 7.3.15.2 a) 4 - not applicable for CSNP only PSNPs on broadcast */
1334 if (!is_csnp
&& (circuit
->circ_type
== CIRCUIT_T_BROADCAST
)
1335 && !circuit
->u
.bc
.is_dr
[level
- 1]) {
1337 "ISIS-Snp (%s): Rcvd L%d %cSNP from %s on %s, "
1338 "skipping: we are not the DIS",
1339 circuit
->area
->area_tag
, level
, typechar
,
1340 snpa_print(ssnpa
), circuit
->interface
->name
);
1345 /* 7.3.15.2 a) 5 - need to make sure IDLength matches - already checked
1348 /* 7.3.15.2 a) 6 - maximum area match, can be ommited since we only use
1350 * - already checked */
1352 /* 7.3.15.2 a) 7 - Must check that we have an adjacency of the same
1354 /* for broadcast circuits, snpa should be compared */
1355 /* FIXME : Do we need to check SNPA? */
1356 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
) {
1357 if (!isis_adj_lookup(rem_sys_id
,
1358 circuit
->u
.bc
.adjdb
[level
- 1]))
1359 return ISIS_OK
; /* Silently discard */
1361 if (!fabricd
&& !circuit
->u
.p2p
.neighbor
) {
1362 zlog_warn("no p2p neighbor on circuit %s",
1363 circuit
->interface
->name
);
1364 return ISIS_OK
; /* Silently discard */
1368 struct isis_tlvs
*tlvs
;
1369 int retval
= ISIS_WARNING
;
1370 const char *error_log
;
1372 if (isis_unpack_tlvs(STREAM_READABLE(circuit
->rcv_stream
),
1373 circuit
->rcv_stream
, &tlvs
, &error_log
)) {
1374 zlog_warn("Something went wrong unpacking the SNP: %s",
1379 struct isis_passwd
*passwd
= (level
== IS_LEVEL_1
)
1380 ? &circuit
->area
->area_passwd
1381 : &circuit
->area
->domain_passwd
;
1382 if (CHECK_FLAG(passwd
->snp_auth
, SNP_AUTH_RECV
)) {
1383 int auth_code
= isis_tlvs_auth_is_valid(
1384 tlvs
, passwd
, circuit
->rcv_stream
, false);
1385 if (auth_code
!= ISIS_AUTH_OK
) {
1386 isis_event_auth_failure(circuit
->area
->area_tag
,
1387 "SNP authentication failure",
1390 /* send northbound notification */
1391 stream_get_from(raw_pdu
, circuit
->rcv_stream
, pdu_start
,
1392 pdu_end
- pdu_start
);
1393 if (auth_code
== ISIS_AUTH_FAILURE
) {
1394 circuit
->auth_failures
++;
1395 isis_notif_authentication_failure(circuit
,
1397 } else { /* AUTH_TYPE_FAILURE or NO_VALIDATOR */
1398 circuit
->auth_type_failures
++;
1399 isis_notif_authentication_type_failure(circuit
,
1402 #endif /* ifndef FABRICD */
1407 struct isis_lsp_entry
*entry_head
=
1408 (struct isis_lsp_entry
*)tlvs
->lsp_entries
.head
;
1410 /* debug isis snp-packets */
1411 if (isis
->debugs
& DEBUG_SNP_PACKETS
) {
1412 zlog_debug("ISIS-Snp (%s): Rcvd L%d %cSNP from %s on %s",
1413 circuit
->area
->area_tag
, level
, typechar
,
1414 snpa_print(ssnpa
), circuit
->interface
->name
);
1415 for (struct isis_lsp_entry
*entry
= entry_head
; entry
;
1416 entry
= entry
->next
) {
1418 "ISIS-Snp (%s): %cSNP entry %s, seq 0x%08" PRIx32
1419 ", cksum 0x%04" PRIx16
", lifetime %" PRIu16
"s",
1420 circuit
->area
->area_tag
, typechar
,
1421 rawlspid_print(entry
->id
), entry
->seqno
,
1422 entry
->checksum
, entry
->rem_lifetime
);
1426 bool resync_needed
= false;
1428 /* 7.3.15.2 b) Actions on LSP_ENTRIES reported */
1429 for (struct isis_lsp_entry
*entry
= entry_head
; entry
;
1430 entry
= entry
->next
) {
1431 struct isis_lsp
*lsp
=
1432 lsp_search(&circuit
->area
->lspdb
[level
- 1], entry
->id
);
1433 bool own_lsp
= !memcmp(entry
->id
, isis
->sysid
, ISIS_SYS_ID_LEN
);
1435 /* 7.3.15.2 b) 1) is this LSP newer */
1436 int cmp
= lsp_compare(circuit
->area
->area_tag
, lsp
,
1437 entry
->seqno
, entry
->checksum
,
1438 entry
->rem_lifetime
);
1439 /* 7.3.15.2 b) 2) if it equals, clear SRM on p2p */
1440 if (cmp
== LSP_EQUAL
) {
1441 /* if (circuit->circ_type !=
1442 * CIRCUIT_T_BROADCAST) */
1443 isis_tx_queue_del(circuit
->tx_queue
, lsp
);
1445 /* 7.3.15.2 b) 3) if it is older, clear SSN and set SRM
1447 else if (cmp
== LSP_OLDER
) {
1448 ISIS_CLEAR_FLAG(lsp
->SSNflags
, circuit
);
1449 isis_tx_queue_add(circuit
->tx_queue
, lsp
,
1452 /* 7.3.15.2 b) 4) if it is newer, set SSN and clear SRM
1456 lsp_inc_seqno(lsp
, entry
->seqno
);
1457 isis_tx_queue_add(circuit
->tx_queue
, lsp
,
1460 ISIS_SET_FLAG(lsp
->SSNflags
, circuit
);
1461 /* if (circuit->circ_type !=
1462 * CIRCUIT_T_BROADCAST) */
1463 isis_tx_queue_del(circuit
->tx_queue
, lsp
);
1464 resync_needed
= true;
1468 /* 7.3.15.2 b) 5) if it was not found, and all of those
1470 * insert it and set SSN on it */
1471 if (entry
->rem_lifetime
&& entry
->checksum
1472 && entry
->seqno
&& memcmp(entry
->id
, isis
->sysid
,
1474 struct isis_lsp
*lsp0
= NULL
;
1476 if (LSP_FRAGMENT(entry
->id
)) {
1477 uint8_t lspid
[ISIS_SYS_ID_LEN
+ 2];
1479 memcpy(lspid
, entry
->id
,
1480 ISIS_SYS_ID_LEN
+ 1);
1481 LSP_FRAGMENT(lspid
) = 0;
1483 &circuit
->area
->lspdb
[level
- 1],
1486 zlog_debug("Got lsp frag in snp, while zero not in database");
1490 lsp
= lsp_new(circuit
->area
, entry
->id
,
1491 entry
->rem_lifetime
, 0, 0,
1492 entry
->checksum
, lsp0
, level
);
1493 lsp_insert(&circuit
->area
->lspdb
[level
- 1],
1496 lsp_set_all_srmflags(lsp
, false);
1497 ISIS_SET_FLAG(lsp
->SSNflags
, circuit
);
1498 resync_needed
= true;
1503 /* 7.3.15.2 c) on CSNP set SRM for all in range which were not reported
1507 * Build a list from our own LSP db bounded with
1508 * start_lsp_id and stop_lsp_id
1510 struct list
*lsp_list
= list_new();
1511 lsp_build_list_nonzero_ht(&circuit
->area
->lspdb
[level
- 1],
1512 start_lsp_id
, stop_lsp_id
, lsp_list
);
1514 /* Fixme: Find a better solution */
1515 struct listnode
*node
, *nnode
;
1516 struct isis_lsp
*lsp
;
1517 for (struct isis_lsp_entry
*entry
= entry_head
; entry
;
1518 entry
= entry
->next
) {
1519 for (ALL_LIST_ELEMENTS(lsp_list
, node
, nnode
, lsp
)) {
1520 if (lsp_id_cmp(lsp
->hdr
.lsp_id
, entry
->id
)
1522 list_delete_node(lsp_list
, node
);
1528 /* on remaining LSPs we set SRM (neighbor knew not of) */
1529 for (ALL_LIST_ELEMENTS_RO(lsp_list
, node
, lsp
)) {
1530 isis_tx_queue_add(circuit
->tx_queue
, lsp
, TX_LSP_NORMAL
);
1531 resync_needed
= true;
1535 list_delete(&lsp_list
);
1538 if (fabricd_initial_sync_is_complete(circuit
->area
) && resync_needed
)
1539 zlog_warn("OpenFabric: Needed to resync LSPDB using CSNP!");
1543 isis_free_tlvs(tlvs
);
1547 static int pdu_size(uint8_t pdu_type
, uint8_t *size
)
1552 *size
= ISIS_LANHELLO_HDRLEN
;
1555 *size
= ISIS_P2PHELLO_HDRLEN
;
1560 *size
= ISIS_LSP_HDR_LEN
;
1562 case L1_COMPLETE_SEQ_NUM
:
1563 case L2_COMPLETE_SEQ_NUM
:
1564 *size
= ISIS_CSNP_HDRLEN
;
1566 case L1_PARTIAL_SEQ_NUM
:
1567 case L2_PARTIAL_SEQ_NUM
:
1568 *size
= ISIS_PSNP_HDRLEN
;
1573 *size
+= ISIS_FIXED_HDR_LEN
;
1581 int isis_handle_pdu(struct isis_circuit
*circuit
, uint8_t *ssnpa
)
1583 int retval
= ISIS_OK
;
1584 size_t pdu_start
= stream_get_getp(circuit
->rcv_stream
);
1585 size_t pdu_end
= stream_get_endp(circuit
->rcv_stream
);
1586 char raw_pdu
[pdu_end
- pdu_start
];
1588 stream_get_from(raw_pdu
, circuit
->rcv_stream
, pdu_start
,
1589 pdu_end
- pdu_start
);
1591 /* Verify that at least the 8 bytes fixed header have been received */
1592 if (stream_get_endp(circuit
->rcv_stream
) < ISIS_FIXED_HDR_LEN
) {
1593 flog_err(EC_ISIS_PACKET
, "PDU is too short to be IS-IS.");
1597 uint8_t idrp
= stream_getc(circuit
->rcv_stream
);
1598 uint8_t length
= stream_getc(circuit
->rcv_stream
);
1599 uint8_t version1
= stream_getc(circuit
->rcv_stream
);
1600 uint8_t id_len
= stream_getc(circuit
->rcv_stream
);
1601 uint8_t pdu_type
= stream_getc(circuit
->rcv_stream
)
1602 & 0x1f; /* bits 6-8 are reserved */
1603 uint8_t version2
= stream_getc(circuit
->rcv_stream
);
1605 stream_forward_getp(circuit
->rcv_stream
, 1); /* reserved */
1606 uint8_t max_area_addrs
= stream_getc(circuit
->rcv_stream
);
1608 pdu_counter_count(circuit
->area
->pdu_rx_counters
, pdu_type
);
1610 if (idrp
== ISO9542_ESIS
) {
1611 flog_err(EC_LIB_DEVELOPMENT
,
1612 "No support for ES-IS packet IDRP=%" PRIx8
, idrp
);
1616 if (idrp
!= ISO10589_ISIS
) {
1617 flog_err(EC_ISIS_PACKET
, "Not an IS-IS packet IDRP=%" PRIx8
,
1622 if (version1
!= 1) {
1623 zlog_warn("Unsupported ISIS version %" PRIu8
, version1
);
1625 /* send northbound notification */
1626 isis_notif_version_skew(circuit
, version1
, raw_pdu
);
1627 #endif /* ifndef FABRICD */
1628 return ISIS_WARNING
;
1631 if (id_len
!= 0 && id_len
!= ISIS_SYS_ID_LEN
) {
1634 "IDFieldLengthMismatch: ID Length field in a received PDU %" PRIu8
1635 ", while the parameter for this IS is %u",
1636 id_len
, ISIS_SYS_ID_LEN
);
1637 circuit
->id_len_mismatches
++;
1639 /* send northbound notification */
1640 isis_notif_id_len_mismatch(circuit
, id_len
, raw_pdu
);
1641 #endif /* ifndef FABRICD */
1645 uint8_t expected_length
;
1646 if (pdu_size(pdu_type
, &expected_length
)) {
1647 zlog_warn("Unsupported ISIS PDU %" PRIu8
, pdu_type
);
1648 return ISIS_WARNING
;
1651 if (length
!= expected_length
) {
1652 flog_err(EC_ISIS_PACKET
,
1653 "Exepected fixed header length = %" PRIu8
1655 expected_length
, length
);
1659 if (stream_get_endp(circuit
->rcv_stream
) < length
) {
1662 "PDU is too short to contain fixed header of given PDU type.");
1666 if (version2
!= 1) {
1667 zlog_warn("Unsupported ISIS PDU version %" PRIu8
, version2
);
1669 /* send northbound notification */
1670 isis_notif_version_skew(circuit
, version2
, raw_pdu
);
1671 #endif /* ifndef FABRICD */
1672 return ISIS_WARNING
;
1675 if (circuit
->is_passive
) {
1676 zlog_warn("Received ISIS PDU on passive circuit %s",
1677 circuit
->interface
->name
);
1678 return ISIS_WARNING
;
1682 if (pdu_type
!= FS_LINK_STATE
/* FS PDU doesn't contain max area addr field */
1683 && max_area_addrs
!= 0
1684 && max_area_addrs
!= isis
->max_area_addrs
) {
1687 "maximumAreaAddressesMismatch: maximumAreaAdresses in a received PDU %" PRIu8
1688 " while the parameter for this IS is %u",
1689 max_area_addrs
, isis
->max_area_addrs
);
1690 circuit
->max_area_addr_mismatches
++;
1692 /* send northbound notification */
1693 isis_notif_max_area_addr_mismatch(circuit
, max_area_addrs
,
1695 #endif /* ifndef FABRICD */
1703 if (fabricd
&& pdu_type
!= P2P_HELLO
)
1705 retval
= process_hello(pdu_type
, circuit
, ssnpa
);
1711 && pdu_type
!= L2_LINK_STATE
1712 && pdu_type
!= FS_LINK_STATE
)
1714 retval
= process_lsp(pdu_type
, circuit
, ssnpa
, max_area_addrs
);
1716 case L1_COMPLETE_SEQ_NUM
:
1717 case L2_COMPLETE_SEQ_NUM
:
1718 case L1_PARTIAL_SEQ_NUM
:
1719 case L2_PARTIAL_SEQ_NUM
:
1720 retval
= process_snp(pdu_type
, circuit
, ssnpa
);
1729 int isis_receive(struct thread
*thread
)
1731 struct isis_circuit
*circuit
;
1732 uint8_t ssnpa
[ETH_ALEN
];
1738 circuit
= THREAD_ARG(thread
);
1741 circuit
->t_read
= NULL
;
1743 isis_circuit_stream(circuit
, &circuit
->rcv_stream
);
1745 retval
= circuit
->rx(circuit
, ssnpa
);
1747 #if ISIS_METHOD != ISIS_METHOD_BPF
1748 if (retval
== ISIS_OK
)
1749 retval
= isis_handle_pdu(circuit
, ssnpa
);
1750 #endif //ISIS_METHOD != ISIS_METHOD_BPF
1753 * prepare for next packet.
1755 if (!circuit
->is_passive
)
1756 isis_circuit_prepare(circuit
);
1764 void fill_fixed_hdr(uint8_t pdu_type
, struct stream
*stream
)
1768 if (pdu_size(pdu_type
, &length
))
1769 assert(!"Unknown PDU Type");
1771 stream_putc(stream
, ISO10589_ISIS
); /* IDRP */
1772 stream_putc(stream
, length
); /* Length of fixed header */
1773 stream_putc(stream
, 1); /* Version/Protocol ID Extension 1 */
1774 stream_putc(stream
, 0); /* ID Length, 0 => 6 */
1775 stream_putc(stream
, pdu_type
);
1776 stream_putc(stream
, 1); /* Subversion */
1777 stream_putc(stream
, 0); /* Reserved */
1778 stream_putc(stream
, 0); /* Max Area Addresses 0 => 3 */
1781 static uint8_t hello_pdu_type(struct isis_circuit
*circuit
, int level
)
1783 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
)
1784 return (level
== IS_LEVEL_1
) ? L1_LAN_HELLO
: L2_LAN_HELLO
;
1789 static void put_hello_hdr(struct isis_circuit
*circuit
, int level
,
1790 size_t *len_pointer
)
1792 uint8_t pdu_type
= hello_pdu_type(circuit
, level
);
1794 isis_circuit_stream(circuit
, &circuit
->snd_stream
);
1795 fill_fixed_hdr(pdu_type
, circuit
->snd_stream
);
1797 stream_putc(circuit
->snd_stream
, circuit
->is_type
);
1798 stream_put(circuit
->snd_stream
, circuit
->area
->isis
->sysid
,
1801 uint32_t holdtime
= circuit
->hello_multiplier
[level
- 1]
1802 * circuit
->hello_interval
[level
- 1];
1804 if (holdtime
> 0xffff)
1807 stream_putw(circuit
->snd_stream
, holdtime
);
1808 *len_pointer
= stream_get_endp(circuit
->snd_stream
);
1809 stream_putw(circuit
->snd_stream
, 0); /* length is filled in later */
1811 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
) {
1812 uint8_t *desig_is
= (level
== IS_LEVEL_1
)
1813 ? circuit
->u
.bc
.l1_desig_is
1814 : circuit
->u
.bc
.l2_desig_is
;
1815 stream_putc(circuit
->snd_stream
, circuit
->priority
[level
- 1]);
1816 stream_put(circuit
->snd_stream
, desig_is
, ISIS_SYS_ID_LEN
+ 1);
1818 stream_putc(circuit
->snd_stream
, circuit
->circuit_id
);
1822 int send_hello(struct isis_circuit
*circuit
, int level
)
1827 if (circuit
->is_passive
)
1830 if (circuit
->interface
->mtu
== 0) {
1831 zlog_warn("circuit has zero MTU");
1832 return ISIS_WARNING
;
1835 put_hello_hdr(circuit
, level
, &len_pointer
);
1837 struct isis_tlvs
*tlvs
= isis_alloc_tlvs();
1839 isis_tlvs_add_auth(tlvs
, &circuit
->passwd
);
1841 if (!listcount(circuit
->area
->area_addrs
)) {
1842 isis_free_tlvs(tlvs
);
1843 return ISIS_WARNING
;
1846 isis_tlvs_add_area_addresses(tlvs
, circuit
->area
->area_addrs
);
1848 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
) {
1849 isis_tlvs_add_lan_neighbors(
1850 tlvs
, circuit
->u
.bc
.lan_neighs
[level
- 1]);
1851 } else if (circuit
->circ_type
== CIRCUIT_T_P2P
1852 && !circuit
->disable_threeway_adj
) {
1853 uint32_t ext_circuit_id
= circuit
->idx
;
1854 if (circuit
->u
.p2p
.neighbor
) {
1855 uint8_t threeway_state
;
1857 if (fabricd_initial_sync_is_in_progress(circuit
->area
)
1858 && fabricd_initial_sync_circuit(circuit
->area
) != circuit
)
1859 threeway_state
= ISIS_THREEWAY_DOWN
;
1861 threeway_state
= circuit
->u
.p2p
.neighbor
->threeway_state
;
1862 isis_tlvs_add_threeway_adj(tlvs
,
1865 circuit
->u
.p2p
.neighbor
->sysid
,
1866 circuit
->u
.p2p
.neighbor
->ext_circuit_id
);
1868 isis_tlvs_add_threeway_adj(tlvs
,
1875 isis_tlvs_set_protocols_supported(tlvs
, &circuit
->nlpids
);
1880 * TLV gets included if no topology is enabled on the interface,
1881 * if one topology other than #0 is enabled, or if multiple topologies
1884 struct isis_circuit_mt_setting
**mt_settings
;
1885 unsigned int mt_count
;
1887 mt_settings
= circuit_mt_settings(circuit
, &mt_count
);
1888 if (mt_count
== 0 && area_is_mt(circuit
->area
)) {
1889 tlvs
->mt_router_info_empty
= true;
1890 } else if ((mt_count
== 1
1891 && mt_settings
[0]->mtid
!= ISIS_MT_IPV4_UNICAST
)
1892 || (mt_count
> 1)) {
1893 for (unsigned int i
= 0; i
< mt_count
; i
++)
1894 isis_tlvs_add_mt_router_info(tlvs
, mt_settings
[i
]->mtid
,
1898 if (circuit
->ip_router
) {
1899 struct list
*circuit_ip_addrs
= fabricd_ip_addrs(circuit
);
1901 if (circuit_ip_addrs
)
1902 isis_tlvs_add_ipv4_addresses(tlvs
, circuit_ip_addrs
);
1905 if (circuit
->ipv6_router
&& circuit
->ipv6_link
)
1906 isis_tlvs_add_ipv6_addresses(tlvs
, circuit
->ipv6_link
);
1908 if (isis_pack_tlvs(tlvs
, circuit
->snd_stream
, len_pointer
,
1909 circuit
->pad_hellos
, false)) {
1910 isis_free_tlvs(tlvs
);
1911 return ISIS_WARNING
; /* XXX: Maybe Log TLV structure? */
1914 if (isis
->debugs
& DEBUG_ADJ_PACKETS
) {
1915 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
) {
1917 "ISIS-Adj (%s): Sending L%d LAN IIH on %s, length %zd",
1918 circuit
->area
->area_tag
, level
,
1919 circuit
->interface
->name
,
1920 stream_get_endp(circuit
->snd_stream
));
1923 "ISIS-Adj (%s): Sending P2P IIH on %s, length %zd",
1924 circuit
->area
->area_tag
,
1925 circuit
->interface
->name
,
1926 stream_get_endp(circuit
->snd_stream
));
1928 if (isis
->debugs
& DEBUG_PACKET_DUMP
)
1929 zlog_dump_data(STREAM_DATA(circuit
->snd_stream
),
1930 stream_get_endp(circuit
->snd_stream
));
1933 isis_free_tlvs(tlvs
);
1935 pdu_counter_count(circuit
->area
->pdu_tx_counters
,
1936 hello_pdu_type(circuit
, level
));
1937 retval
= circuit
->tx(circuit
, level
);
1938 if (retval
!= ISIS_OK
)
1939 flog_err(EC_ISIS_PACKET
,
1940 "ISIS-Adj (%s): Send L%d IIH on %s failed",
1941 circuit
->area
->area_tag
, level
,
1942 circuit
->interface
->name
);
1947 static int send_hello_cb(struct thread
*thread
)
1949 struct isis_circuit_arg
*arg
= THREAD_ARG(thread
);
1952 struct isis_circuit
*circuit
= arg
->circuit
;
1953 int level
= arg
->level
;
1957 if (circuit
->circ_type
== CIRCUIT_T_P2P
) {
1958 circuit
->u
.p2p
.t_send_p2p_hello
= NULL
;
1959 send_hello(circuit
, 1);
1960 send_hello_sched(circuit
, ISIS_LEVEL1
,
1961 1000 * circuit
->hello_interval
[1]);
1965 if (circuit
->circ_type
!= CIRCUIT_T_BROADCAST
) {
1966 zlog_warn("ISIS-Hello (%s): Trying to send hello on unknown circuit type %d",
1967 circuit
->area
->area_tag
, circuit
->circ_type
);
1968 return ISIS_WARNING
;
1971 circuit
->u
.bc
.t_send_lan_hello
[level
- 1] = NULL
;
1972 if (!(circuit
->is_type
& level
)) {
1973 zlog_warn("ISIS-Hello (%s): Trying to send L%d IIH in L%d-only circuit",
1974 circuit
->area
->area_tag
, level
, 3 - level
);
1975 return ISIS_WARNING
;
1978 if (circuit
->u
.bc
.run_dr_elect
[level
- 1])
1979 isis_dr_elect(circuit
, level
);
1981 int rv
= send_hello(circuit
, level
);
1983 /* set next timer thread */
1984 send_hello_sched(circuit
, level
, 1000 * circuit
->hello_interval
[level
- 1]);
1988 static void _send_hello_sched(struct isis_circuit
*circuit
,
1989 struct thread
**threadp
,
1990 int level
, long delay
)
1993 if (thread_timer_remain_msec(*threadp
) < (unsigned long)delay
)
1996 thread_cancel(*threadp
);
1999 thread_add_timer_msec(master
, send_hello_cb
,
2000 &circuit
->level_arg
[level
- 1],
2001 isis_jitter(delay
, IIH_JITTER
),
2005 void send_hello_sched(struct isis_circuit
*circuit
, int level
, long delay
)
2007 if (circuit
->circ_type
== CIRCUIT_T_P2P
) {
2008 _send_hello_sched(circuit
, &circuit
->u
.p2p
.t_send_p2p_hello
,
2009 ISIS_LEVEL1
, delay
);
2013 if (circuit
->circ_type
!= CIRCUIT_T_BROADCAST
) {
2014 zlog_warn("%s: encountered unknown circuit type %d on %s",
2015 __func__
, circuit
->circ_type
,
2016 circuit
->interface
->name
);
2020 for (int loop_level
= ISIS_LEVEL1
; loop_level
<= ISIS_LEVEL2
; loop_level
++) {
2021 if (!(loop_level
& level
))
2026 &circuit
->u
.bc
.t_send_lan_hello
[loop_level
- 1],
2035 * Count the maximum number of lsps that can be accomodated by a given size.
2037 #define LSP_ENTRIES_LEN (10 + ISIS_SYS_ID_LEN)
2038 static uint16_t get_max_lsp_count(uint16_t size
)
2042 uint16_t remaining_size
;
2044 /* First count the full size TLVs */
2045 tlv_count
= size
/ MAX_LSP_ENTRIES_TLV_SIZE
;
2046 lsp_count
= tlv_count
* (MAX_LSP_ENTRIES_TLV_SIZE
/ LSP_ENTRIES_LEN
);
2048 /* The last TLV, if any */
2049 remaining_size
= size
% MAX_LSP_ENTRIES_TLV_SIZE
;
2050 if (remaining_size
- 2 >= LSP_ENTRIES_LEN
)
2051 lsp_count
+= (remaining_size
- 2) / LSP_ENTRIES_LEN
;
2056 int send_csnp(struct isis_circuit
*circuit
, int level
)
2058 if (lspdb_count(&circuit
->area
->lspdb
[level
- 1]) == 0)
2061 uint8_t pdu_type
= (level
== ISIS_LEVEL1
) ? L1_COMPLETE_SEQ_NUM
2062 : L2_COMPLETE_SEQ_NUM
;
2064 isis_circuit_stream(circuit
, &circuit
->snd_stream
);
2065 fill_fixed_hdr(pdu_type
, circuit
->snd_stream
);
2067 size_t len_pointer
= stream_get_endp(circuit
->snd_stream
);
2068 stream_putw(circuit
->snd_stream
, 0);
2069 stream_put(circuit
->snd_stream
, isis
->sysid
, ISIS_SYS_ID_LEN
);
2070 /* with zero circuit id - ref 9.10, 9.11 */
2071 stream_putc(circuit
->snd_stream
, 0);
2073 size_t start_pointer
= stream_get_endp(circuit
->snd_stream
);
2074 stream_put(circuit
->snd_stream
, 0, ISIS_SYS_ID_LEN
+ 2);
2075 size_t end_pointer
= stream_get_endp(circuit
->snd_stream
);
2076 stream_put(circuit
->snd_stream
, 0, ISIS_SYS_ID_LEN
+ 2);
2078 struct isis_passwd
*passwd
= (level
== ISIS_LEVEL1
)
2079 ? &circuit
->area
->area_passwd
2080 : &circuit
->area
->domain_passwd
;
2082 struct isis_tlvs
*tlvs
= isis_alloc_tlvs();
2084 if (CHECK_FLAG(passwd
->snp_auth
, SNP_AUTH_SEND
))
2085 isis_tlvs_add_auth(tlvs
, passwd
);
2087 size_t tlv_start
= stream_get_endp(circuit
->snd_stream
);
2088 if (isis_pack_tlvs(tlvs
, circuit
->snd_stream
, len_pointer
, false,
2090 isis_free_tlvs(tlvs
);
2091 return ISIS_WARNING
;
2093 isis_free_tlvs(tlvs
);
2096 get_max_lsp_count(STREAM_WRITEABLE(circuit
->snd_stream
));
2098 uint8_t start
[ISIS_SYS_ID_LEN
+ 2];
2099 memset(start
, 0x00, ISIS_SYS_ID_LEN
+ 2);
2100 uint8_t stop
[ISIS_SYS_ID_LEN
+ 2];
2101 memset(stop
, 0xff, ISIS_SYS_ID_LEN
+ 2);
2105 tlvs
= isis_alloc_tlvs();
2106 if (CHECK_FLAG(passwd
->snp_auth
, SNP_AUTH_SEND
))
2107 isis_tlvs_add_auth(tlvs
, passwd
);
2109 struct isis_lsp
*last_lsp
;
2110 isis_tlvs_add_csnp_entries(tlvs
, start
, stop
, num_lsps
,
2111 &circuit
->area
->lspdb
[level
- 1],
2114 * Update the stop lsp_id before encoding this CSNP.
2116 if (tlvs
->lsp_entries
.count
< num_lsps
) {
2117 memset(stop
, 0xff, ISIS_SYS_ID_LEN
+ 2);
2119 memcpy(stop
, last_lsp
->hdr
.lsp_id
, sizeof(stop
));
2122 memcpy(STREAM_DATA(circuit
->snd_stream
) + start_pointer
, start
,
2123 ISIS_SYS_ID_LEN
+ 2);
2124 memcpy(STREAM_DATA(circuit
->snd_stream
) + end_pointer
, stop
,
2125 ISIS_SYS_ID_LEN
+ 2);
2126 stream_set_endp(circuit
->snd_stream
, tlv_start
);
2127 if (isis_pack_tlvs(tlvs
, circuit
->snd_stream
, len_pointer
,
2129 isis_free_tlvs(tlvs
);
2130 return ISIS_WARNING
;
2133 if (isis
->debugs
& DEBUG_SNP_PACKETS
) {
2135 "ISIS-Snp (%s): Sending L%d CSNP on %s, length %zd",
2136 circuit
->area
->area_tag
, level
,
2137 circuit
->interface
->name
,
2138 stream_get_endp(circuit
->snd_stream
));
2139 log_multiline(LOG_DEBUG
, " ", "%s",
2140 isis_format_tlvs(tlvs
));
2141 if (isis
->debugs
& DEBUG_PACKET_DUMP
)
2143 STREAM_DATA(circuit
->snd_stream
),
2144 stream_get_endp(circuit
->snd_stream
));
2147 pdu_counter_count(circuit
->area
->pdu_tx_counters
, pdu_type
);
2148 int retval
= circuit
->tx(circuit
, level
);
2149 if (retval
!= ISIS_OK
) {
2150 flog_err(EC_ISIS_PACKET
,
2151 "ISIS-Snp (%s): Send L%d CSNP on %s failed",
2152 circuit
->area
->area_tag
, level
,
2153 circuit
->interface
->name
);
2154 isis_free_tlvs(tlvs
);
2159 * Start lsp_id of the next CSNP should be one plus the
2160 * stop lsp_id in this current CSNP.
2162 memcpy(start
, stop
, ISIS_SYS_ID_LEN
+ 2);
2164 for (int i
= ISIS_SYS_ID_LEN
+ 1; i
>= 0; --i
) {
2165 if (start
[i
] < (uint8_t)0xff) {
2171 memset(stop
, 0xff, ISIS_SYS_ID_LEN
+ 2);
2172 isis_free_tlvs(tlvs
);
2178 int send_l1_csnp(struct thread
*thread
)
2180 struct isis_circuit
*circuit
;
2182 circuit
= THREAD_ARG(thread
);
2185 circuit
->t_send_csnp
[0] = NULL
;
2187 if ((circuit
->circ_type
== CIRCUIT_T_BROADCAST
2188 && circuit
->u
.bc
.is_dr
[0])
2189 || circuit
->circ_type
== CIRCUIT_T_P2P
) {
2190 send_csnp(circuit
, 1);
2192 /* set next timer thread */
2193 thread_add_timer(master
, send_l1_csnp
, circuit
,
2194 isis_jitter(circuit
->csnp_interval
[0], CSNP_JITTER
),
2195 &circuit
->t_send_csnp
[0]);
2200 int send_l2_csnp(struct thread
*thread
)
2202 struct isis_circuit
*circuit
;
2204 circuit
= THREAD_ARG(thread
);
2207 circuit
->t_send_csnp
[1] = NULL
;
2209 if ((circuit
->circ_type
== CIRCUIT_T_BROADCAST
2210 && circuit
->u
.bc
.is_dr
[1])
2211 || circuit
->circ_type
== CIRCUIT_T_P2P
) {
2212 send_csnp(circuit
, 2);
2214 /* set next timer thread */
2215 thread_add_timer(master
, send_l2_csnp
, circuit
,
2216 isis_jitter(circuit
->csnp_interval
[1], CSNP_JITTER
),
2217 &circuit
->t_send_csnp
[1]);
2223 * 7.3.15.4 action on expiration of partial SNP interval
2226 static int send_psnp(int level
, struct isis_circuit
*circuit
)
2228 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
2229 && circuit
->u
.bc
.is_dr
[level
- 1])
2232 if (lspdb_count(&circuit
->area
->lspdb
[level
- 1]) == 0)
2235 if (!circuit
->snd_stream
)
2238 uint8_t pdu_type
= (level
== ISIS_LEVEL1
) ? L1_PARTIAL_SEQ_NUM
2239 : L2_PARTIAL_SEQ_NUM
;
2241 isis_circuit_stream(circuit
, &circuit
->snd_stream
);
2242 fill_fixed_hdr(pdu_type
, circuit
->snd_stream
);
2244 size_t len_pointer
= stream_get_endp(circuit
->snd_stream
);
2245 stream_putw(circuit
->snd_stream
, 0); /* length is filled in later */
2246 stream_put(circuit
->snd_stream
, isis
->sysid
, ISIS_SYS_ID_LEN
);
2247 stream_putc(circuit
->snd_stream
, circuit
->idx
);
2249 struct isis_passwd
*passwd
= (level
== ISIS_LEVEL1
)
2250 ? &circuit
->area
->area_passwd
2251 : &circuit
->area
->domain_passwd
;
2253 struct isis_tlvs
*tlvs
= isis_alloc_tlvs();
2255 if (CHECK_FLAG(passwd
->snp_auth
, SNP_AUTH_SEND
))
2256 isis_tlvs_add_auth(tlvs
, passwd
);
2258 size_t tlv_start
= stream_get_endp(circuit
->snd_stream
);
2259 if (isis_pack_tlvs(tlvs
, circuit
->snd_stream
, len_pointer
, false,
2261 isis_free_tlvs(tlvs
);
2262 return ISIS_WARNING
;
2264 isis_free_tlvs(tlvs
);
2267 get_max_lsp_count(STREAM_WRITEABLE(circuit
->snd_stream
));
2270 struct isis_lsp
*lsp
;
2272 tlvs
= isis_alloc_tlvs();
2273 if (CHECK_FLAG(passwd
->snp_auth
, SNP_AUTH_SEND
))
2274 isis_tlvs_add_auth(tlvs
, passwd
);
2276 frr_each (lspdb
, &circuit
->area
->lspdb
[level
- 1], lsp
) {
2277 if (ISIS_CHECK_FLAG(lsp
->SSNflags
, circuit
))
2278 isis_tlvs_add_lsp_entry(tlvs
, lsp
);
2280 if (tlvs
->lsp_entries
.count
== num_lsps
)
2284 if (!tlvs
->lsp_entries
.count
) {
2285 isis_free_tlvs(tlvs
);
2289 stream_set_endp(circuit
->snd_stream
, tlv_start
);
2290 if (isis_pack_tlvs(tlvs
, circuit
->snd_stream
, len_pointer
,
2292 isis_free_tlvs(tlvs
);
2293 return ISIS_WARNING
;
2296 if (isis
->debugs
& DEBUG_SNP_PACKETS
) {
2298 "ISIS-Snp (%s): Sending L%d PSNP on %s, length %zd",
2299 circuit
->area
->area_tag
, level
,
2300 circuit
->interface
->name
,
2301 stream_get_endp(circuit
->snd_stream
));
2302 log_multiline(LOG_DEBUG
, " ", "%s",
2303 isis_format_tlvs(tlvs
));
2304 if (isis
->debugs
& DEBUG_PACKET_DUMP
)
2306 STREAM_DATA(circuit
->snd_stream
),
2307 stream_get_endp(circuit
->snd_stream
));
2310 pdu_counter_count(circuit
->area
->pdu_tx_counters
, pdu_type
);
2311 int retval
= circuit
->tx(circuit
, level
);
2312 if (retval
!= ISIS_OK
) {
2313 flog_err(EC_ISIS_PACKET
,
2314 "ISIS-Snp (%s): Send L%d PSNP on %s failed",
2315 circuit
->area
->area_tag
, level
,
2316 circuit
->interface
->name
);
2317 isis_free_tlvs(tlvs
);
2322 * sending succeeded, we can clear SSN flags of this circuit
2323 * for the LSPs in list
2325 struct isis_lsp_entry
*entry_head
;
2326 entry_head
= (struct isis_lsp_entry
*)tlvs
->lsp_entries
.head
;
2327 for (struct isis_lsp_entry
*entry
= entry_head
; entry
;
2328 entry
= entry
->next
)
2329 ISIS_CLEAR_FLAG(entry
->lsp
->SSNflags
, circuit
);
2330 isis_free_tlvs(tlvs
);
2336 int send_l1_psnp(struct thread
*thread
)
2339 struct isis_circuit
*circuit
;
2341 circuit
= THREAD_ARG(thread
);
2344 circuit
->t_send_psnp
[0] = NULL
;
2346 send_psnp(1, circuit
);
2347 /* set next timer thread */
2348 thread_add_timer(master
, send_l1_psnp
, circuit
,
2349 isis_jitter(circuit
->psnp_interval
[0], PSNP_JITTER
),
2350 &circuit
->t_send_psnp
[0]);
2356 * 7.3.15.4 action on expiration of partial SNP interval
2359 int send_l2_psnp(struct thread
*thread
)
2361 struct isis_circuit
*circuit
;
2363 circuit
= THREAD_ARG(thread
);
2366 circuit
->t_send_psnp
[1] = NULL
;
2368 send_psnp(2, circuit
);
2370 /* set next timer thread */
2371 thread_add_timer(master
, send_l2_psnp
, circuit
,
2372 isis_jitter(circuit
->psnp_interval
[1], PSNP_JITTER
),
2373 &circuit
->t_send_psnp
[1]);
2379 * ISO 10589 - 7.3.14.3
2381 void send_lsp(struct isis_circuit
*circuit
, struct isis_lsp
*lsp
,
2382 enum isis_tx_type tx_type
)
2385 int retval
= ISIS_OK
;
2387 if (circuit
->state
!= C_STATE_UP
|| circuit
->is_passive
== 1)
2391 * Do not send if levels do not match
2393 if (!(lsp
->level
& circuit
->is_type
))
2397 * Do not send if we do not have adjacencies in state up on the circuit
2399 if (circuit
->upadjcount
[lsp
->level
- 1] == 0)
2402 /* stream_copy will assert and stop program execution if LSP is larger
2404 * the circuit's MTU. So handle and log this case here. */
2405 if (stream_get_endp(lsp
->pdu
) > stream_get_size(circuit
->snd_stream
)) {
2408 "ISIS-Upd (%s): Can't send L%d LSP %s, seq 0x%08" PRIx32
2409 ", cksum 0x%04" PRIx16
", lifetime %" PRIu16
2410 "s on %s. LSP Size is %zu while interface stream size is %zu.",
2411 circuit
->area
->area_tag
, lsp
->level
,
2412 rawlspid_print(lsp
->hdr
.lsp_id
), lsp
->hdr
.seqno
,
2413 lsp
->hdr
.checksum
, lsp
->hdr
.rem_lifetime
,
2414 circuit
->interface
->name
, stream_get_endp(lsp
->pdu
),
2415 stream_get_size(circuit
->snd_stream
));
2417 /* send a northbound notification */
2418 isis_notif_lsp_too_large(circuit
, stream_get_endp(lsp
->pdu
),
2419 rawlspid_print(lsp
->hdr
.lsp_id
));
2420 #endif /* ifndef FABRICD */
2421 if (isis
->debugs
& DEBUG_PACKET_DUMP
)
2422 zlog_dump_data(STREAM_DATA(lsp
->pdu
),
2423 stream_get_endp(lsp
->pdu
));
2424 retval
= ISIS_ERROR
;
2428 /* copy our lsp to the send buffer */
2429 stream_copy(circuit
->snd_stream
, lsp
->pdu
);
2431 if (tx_type
== TX_LSP_CIRCUIT_SCOPED
) {
2432 stream_putc_at(circuit
->snd_stream
, 4, FS_LINK_STATE
);
2433 stream_putc_at(circuit
->snd_stream
, 7,
2434 L2_CIRCUIT_FLOODING_SCOPE
);
2437 if (isis
->debugs
& DEBUG_UPDATE_PACKETS
) {
2438 zlog_debug("ISIS-Upd (%s): Sending %sL%d LSP %s, seq 0x%08" PRIx32
2439 ", cksum 0x%04" PRIx16
", lifetime %" PRIu16
2441 circuit
->area
->area_tag
,
2442 (tx_type
== TX_LSP_CIRCUIT_SCOPED
)
2443 ? "Circuit scoped " : "",
2445 rawlspid_print(lsp
->hdr
.lsp_id
), lsp
->hdr
.seqno
,
2446 lsp
->hdr
.checksum
, lsp
->hdr
.rem_lifetime
,
2447 circuit
->interface
->name
);
2448 if (isis
->debugs
& DEBUG_PACKET_DUMP
)
2449 zlog_dump_data(STREAM_DATA(circuit
->snd_stream
),
2450 stream_get_endp(circuit
->snd_stream
));
2453 uint8_t pdu_type
= (tx_type
== TX_LSP_CIRCUIT_SCOPED
) ? FS_LINK_STATE
2454 : (lsp
->level
== ISIS_LEVEL1
) ? L1_LINK_STATE
2458 pdu_counter_count(circuit
->area
->pdu_tx_counters
, pdu_type
);
2459 retval
= circuit
->tx(circuit
, lsp
->level
);
2460 if (retval
!= ISIS_OK
) {
2461 flog_err(EC_ISIS_PACKET
,
2462 "ISIS-Upd (%s): Send L%d LSP on %s failed %s",
2463 circuit
->area
->area_tag
, lsp
->level
,
2464 circuit
->interface
->name
,
2465 (retval
== ISIS_WARNING
) ? "temporarily"
2471 || (retval
== ISIS_OK
&& circuit
->circ_type
== CIRCUIT_T_BROADCAST
)
2472 || (retval
!= ISIS_OK
&& retval
!= ISIS_WARNING
)) {
2473 /* SRM flag will trigger retransmission. We will not retransmit
2475 * encountered a fatal error.
2476 * On success, they should only be cleared if it's a broadcast
2478 * On a P2P circuit, we will wait for the ack from the neighbor
2482 isis_tx_queue_del(circuit
->tx_queue
, lsp
);