2 * IS-IS Rout(e)ing protocol - isis_lsp.c
5 * Copyright (C) 2001,2002 Sampo Saaristo
6 * Tampere University of Technology
7 * Institute of Communications Engineering
8 * Copyright (C) 2013-2015 Christian Franke <chris@opensourcerouting.org>
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the Free
12 * Software Foundation; either version 2 of the License, or (at your option)
15 * This program is distributed in the hope that it will be useful,but WITHOUT
16 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
20 * You should have received a copy of the GNU General Public License along
21 * with this program; see the file COPYING; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
40 #include "srcdest_table.h"
41 #include "lib_errors.h"
43 #include "isisd/dict.h"
44 #include "isisd/isis_constants.h"
45 #include "isisd/isis_common.h"
46 #include "isisd/isis_flags.h"
47 #include "isisd/isis_circuit.h"
48 #include "isisd/isisd.h"
49 #include "isisd/isis_lsp.h"
50 #include "isisd/isis_pdu.h"
51 #include "isisd/isis_dynhn.h"
52 #include "isisd/isis_misc.h"
53 #include "isisd/isis_csm.h"
54 #include "isisd/isis_adjacency.h"
55 #include "isisd/isis_spf.h"
56 #include "isisd/isis_te.h"
57 #include "isisd/isis_mt.h"
58 #include "isisd/isis_tlvs.h"
59 #include "isisd/fabricd.h"
60 #include "isisd/isis_tx_queue.h"
62 static int lsp_refresh(struct thread
*thread
);
63 static int lsp_l1_refresh_pseudo(struct thread
*thread
);
64 static int lsp_l2_refresh_pseudo(struct thread
*thread
);
66 int lsp_id_cmp(uint8_t *id1
, uint8_t *id2
)
68 return memcmp(id1
, id2
, ISIS_SYS_ID_LEN
+ 2);
71 dict_t
*lsp_db_init(void)
75 dict
= dict_create(DICTCOUNT_T_MAX
, (dict_comp_t
)lsp_id_cmp
);
80 struct isis_lsp
*lsp_search(uint8_t *id
, dict_t
*lspdb
)
87 zlog_debug("searching db");
88 for (dn
= dict_first(lspdb
); dn
; dn
= dict_next(lspdb
, dn
)) {
90 rawlspid_print((uint8_t *)dnode_getkey(dn
)),
93 #endif /* EXTREME DEBUG */
95 node
= dict_lookup(lspdb
, id
);
98 return (struct isis_lsp
*)dnode_get(node
);
103 static void lsp_clear_data(struct isis_lsp
*lsp
)
108 isis_free_tlvs(lsp
->tlvs
);
112 static void lsp_remove_frags(struct list
*frags
, dict_t
*lspdb
);
114 static void lsp_destroy(struct isis_lsp
*lsp
)
116 struct listnode
*cnode
;
117 struct isis_circuit
*circuit
;
122 for (ALL_LIST_ELEMENTS_RO(lsp
->area
->circuit_list
, cnode
, circuit
))
123 isis_tx_queue_del(circuit
->tx_queue
, lsp
);
125 ISIS_FLAGS_CLEAR_ALL(lsp
->SSNflags
);
129 if (!LSP_FRAGMENT(lsp
->hdr
.lsp_id
)) {
130 if (lsp
->lspu
.frags
) {
131 lsp_remove_frags(lsp
->lspu
.frags
,
132 lsp
->area
->lspdb
[lsp
->level
- 1]);
133 list_delete(&lsp
->lspu
.frags
);
136 if (lsp
->lspu
.zero_lsp
137 && lsp
->lspu
.zero_lsp
->lspu
.frags
) {
138 listnode_delete(lsp
->lspu
.zero_lsp
->lspu
.frags
, lsp
);
142 isis_spf_schedule(lsp
->area
, lsp
->level
);
145 stream_free(lsp
->pdu
);
146 XFREE(MTYPE_ISIS_LSP
, lsp
);
149 void lsp_db_destroy(dict_t
*lspdb
)
151 dnode_t
*dnode
, *next
;
152 struct isis_lsp
*lsp
;
154 dnode
= dict_first(lspdb
);
156 next
= dict_next(lspdb
, dnode
);
157 lsp
= dnode_get(dnode
);
159 dict_delete_free(lspdb
, dnode
);
169 * Remove all the frags belonging to the given lsp
171 static void lsp_remove_frags(struct list
*frags
, dict_t
*lspdb
)
174 struct listnode
*lnode
, *lnnode
;
175 struct isis_lsp
*lsp
;
177 for (ALL_LIST_ELEMENTS(frags
, lnode
, lnnode
, lsp
)) {
178 dnode
= dict_lookup(lspdb
, lsp
->hdr
.lsp_id
);
180 dnode_destroy(dict_delete(lspdb
, dnode
));
184 void lsp_search_and_destroy(uint8_t *id
, dict_t
*lspdb
)
187 struct isis_lsp
*lsp
;
189 node
= dict_lookup(lspdb
, id
);
191 node
= dict_delete(lspdb
, node
);
192 lsp
= dnode_get(node
);
194 * If this is a zero lsp, remove all the frags now
196 if (LSP_FRAGMENT(lsp
->hdr
.lsp_id
) == 0) {
198 lsp_remove_frags(lsp
->lspu
.frags
, lspdb
);
201 * else just remove this frag, from the zero lsps' frag
204 if (lsp
->lspu
.zero_lsp
205 && lsp
->lspu
.zero_lsp
->lspu
.frags
)
206 listnode_delete(lsp
->lspu
.zero_lsp
->lspu
.frags
,
215 * Compares a LSP to given values
216 * Params are given in net order
218 int lsp_compare(char *areatag
, struct isis_lsp
*lsp
, uint32_t seqno
,
219 uint16_t checksum
, uint16_t rem_lifetime
)
221 if (lsp
->hdr
.seqno
== seqno
&& lsp
->hdr
.checksum
== checksum
222 && ((lsp
->hdr
.rem_lifetime
== 0 && rem_lifetime
== 0)
223 || (lsp
->hdr
.rem_lifetime
!= 0 && rem_lifetime
!= 0))) {
224 if (isis
->debugs
& DEBUG_SNP_PACKETS
) {
226 "ISIS-Snp (%s): Compare LSP %s seq 0x%08" PRIx32
227 ", cksum 0x%04" PRIx16
", lifetime %" PRIu16
229 areatag
, rawlspid_print(lsp
->hdr
.lsp_id
),
230 lsp
->hdr
.seqno
, lsp
->hdr
.checksum
,
231 lsp
->hdr
.rem_lifetime
);
233 "ISIS-Snp (%s): is equal to ours seq 0x%08" PRIx32
234 ", cksum 0x%04" PRIx16
", lifetime %" PRIu16
236 areatag
, seqno
, checksum
, rem_lifetime
);
242 * LSPs with identical checksums should only be treated as newer if:
243 * a) The current LSP has a remaining lifetime != 0 and the other LSP
245 * remaining lifetime == 0. In this case, we should participate in
247 * and should not treat the current LSP with remaining lifetime == 0
249 * b) The LSP has an incorrect checksum. In this case, we need to react
253 if (seqno
> lsp
->hdr
.seqno
254 || (seqno
== lsp
->hdr
.seqno
255 && ((lsp
->hdr
.rem_lifetime
!= 0 && rem_lifetime
== 0)
256 || lsp
->hdr
.checksum
!= checksum
))) {
257 if (isis
->debugs
& DEBUG_SNP_PACKETS
) {
259 "ISIS-Snp (%s): Compare LSP %s seq 0x%08" PRIx32
260 ", cksum 0x%04" PRIx16
", lifetime %" PRIu16
262 areatag
, rawlspid_print(lsp
->hdr
.lsp_id
), seqno
,
263 checksum
, rem_lifetime
);
265 "ISIS-Snp (%s): is newer than ours seq 0x%08" PRIx32
266 ", cksum 0x%04" PRIx16
", lifetime %" PRIu16
268 areatag
, lsp
->hdr
.seqno
, lsp
->hdr
.checksum
,
269 lsp
->hdr
.rem_lifetime
);
273 if (isis
->debugs
& DEBUG_SNP_PACKETS
) {
274 zlog_debug("ISIS-Snp (%s): Compare LSP %s seq 0x%08" PRIx32
275 ", cksum 0x%04" PRIx16
", lifetime %" PRIu16
"s",
276 areatag
, rawlspid_print(lsp
->hdr
.lsp_id
), seqno
,
277 checksum
, rem_lifetime
);
279 "ISIS-Snp (%s): is older than ours seq 0x%08" PRIx32
280 ", cksum 0x%04" PRIx16
", lifetime %" PRIu16
"s",
281 areatag
, lsp
->hdr
.seqno
, lsp
->hdr
.checksum
,
282 lsp
->hdr
.rem_lifetime
);
288 static void put_lsp_hdr(struct isis_lsp
*lsp
, size_t *len_pointer
, bool keep
)
291 (lsp
->level
== IS_LEVEL_1
) ? L1_LINK_STATE
: L2_LINK_STATE
;
292 struct isis_lsp_hdr
*hdr
= &lsp
->hdr
;
293 struct stream
*stream
= lsp
->pdu
;
294 size_t orig_getp
= 0, orig_endp
= 0;
297 orig_getp
= stream_get_getp(lsp
->pdu
);
298 orig_endp
= stream_get_endp(lsp
->pdu
);
301 stream_set_getp(lsp
->pdu
, 0);
302 stream_set_endp(lsp
->pdu
, 0);
304 fill_fixed_hdr(pdu_type
, stream
);
307 *len_pointer
= stream_get_endp(stream
);
308 stream_putw(stream
, hdr
->pdu_len
);
309 stream_putw(stream
, hdr
->rem_lifetime
);
310 stream_put(stream
, hdr
->lsp_id
, sizeof(hdr
->lsp_id
));
311 stream_putl(stream
, hdr
->seqno
);
312 stream_putw(stream
, hdr
->checksum
);
313 stream_putc(stream
, hdr
->lsp_bits
);
316 stream_set_endp(lsp
->pdu
, orig_endp
);
317 stream_set_getp(lsp
->pdu
, orig_getp
);
321 static void lsp_add_auth(struct isis_lsp
*lsp
)
323 struct isis_passwd
*passwd
;
324 passwd
= (lsp
->level
== IS_LEVEL_1
) ? &lsp
->area
->area_passwd
325 : &lsp
->area
->domain_passwd
;
326 isis_tlvs_add_auth(lsp
->tlvs
, passwd
);
329 static void lsp_pack_pdu(struct isis_lsp
*lsp
)
332 lsp
->tlvs
= isis_alloc_tlvs();
337 put_lsp_hdr(lsp
, &len_pointer
, false);
338 isis_pack_tlvs(lsp
->tlvs
, lsp
->pdu
, len_pointer
, false, true);
340 lsp
->hdr
.pdu_len
= stream_get_endp(lsp
->pdu
);
342 ntohs(fletcher_checksum(STREAM_DATA(lsp
->pdu
) + 12,
343 stream_get_endp(lsp
->pdu
) - 12, 12));
346 void lsp_inc_seqno(struct isis_lsp
*lsp
, uint32_t seqno
)
350 if (seqno
== 0 || lsp
->hdr
.seqno
> seqno
)
351 newseq
= lsp
->hdr
.seqno
+ 1;
355 lsp
->hdr
.seqno
= newseq
;
358 isis_spf_schedule(lsp
->area
, lsp
->level
);
361 static void lsp_purge_add_poi(struct isis_lsp
*lsp
,
362 const uint8_t *sender
)
364 if (!lsp
->area
->purge_originator
)
367 /* add purge originator identification */
369 lsp
->tlvs
= isis_alloc_tlvs();
370 isis_tlvs_set_purge_originator(lsp
->tlvs
, isis
->sysid
, sender
);
371 isis_tlvs_set_dynamic_hostname(lsp
->tlvs
, cmd_hostname_get());
374 static void lsp_purge(struct isis_lsp
*lsp
, int level
,
375 const uint8_t *sender
)
379 stream_reset(lsp
->pdu
);
382 lsp
->hdr
.checksum
= 0;
383 lsp
->hdr
.rem_lifetime
= 0;
385 lsp
->age_out
= lsp
->area
->max_lsp_lifetime
[level
- 1];
387 lsp_purge_add_poi(lsp
, sender
);
390 lsp_flood(lsp
, NULL
);
394 * Generates checksum for LSP and its frags
396 static void lsp_seqno_update(struct isis_lsp
*lsp0
)
398 struct isis_lsp
*lsp
;
399 struct listnode
*node
;
401 lsp_inc_seqno(lsp0
, 0);
403 if (!lsp0
->lspu
.frags
)
406 for (ALL_LIST_ELEMENTS_RO(lsp0
->lspu
.frags
, node
, lsp
)) {
408 lsp_inc_seqno(lsp
, 0);
410 lsp_purge(lsp
, lsp0
->level
, NULL
);
416 static uint8_t lsp_bits_generate(int level
, int overload_bit
, int attached_bit
)
418 uint8_t lsp_bits
= 0;
419 if (level
== IS_LEVEL_1
)
420 lsp_bits
= IS_LEVEL_1
;
422 lsp_bits
= IS_LEVEL_1_AND_2
;
424 lsp_bits
|= overload_bit
;
426 lsp_bits
|= attached_bit
;
430 static void lsp_update_data(struct isis_lsp
*lsp
, struct isis_lsp_hdr
*hdr
,
431 struct isis_tlvs
*tlvs
, struct stream
*stream
,
432 struct isis_area
*area
, int level
)
434 /* free the old lsp data */
437 /* copying only the relevant part of our stream */
438 if (lsp
->pdu
!= NULL
)
439 stream_free(lsp
->pdu
);
440 lsp
->pdu
= stream_dup(stream
);
442 memcpy(&lsp
->hdr
, hdr
, sizeof(lsp
->hdr
));
445 lsp
->age_out
= ZERO_AGE_LIFETIME
;
446 lsp
->installed
= time(NULL
);
450 if (area
->dynhostname
&& lsp
->tlvs
->hostname
451 && lsp
->hdr
.rem_lifetime
) {
452 isis_dynhn_insert(lsp
->hdr
.lsp_id
, lsp
->tlvs
->hostname
,
453 (lsp
->hdr
.lsp_bits
& LSPBIT_IST
)
462 static void lsp_link_fragment(struct isis_lsp
*lsp
, struct isis_lsp
*lsp0
)
464 if (!LSP_FRAGMENT(lsp
->hdr
.lsp_id
)) {
465 /* zero lsp -> create list to store fragments */
466 lsp
->lspu
.frags
= list_new();
468 /* fragment -> set backpointer and add to zero lsps list */
470 lsp
->lspu
.zero_lsp
= lsp0
;
471 listnode_add(lsp0
->lspu
.frags
, lsp
);
475 void lsp_update(struct isis_lsp
*lsp
, struct isis_lsp_hdr
*hdr
,
476 struct isis_tlvs
*tlvs
, struct stream
*stream
,
477 struct isis_area
*area
, int level
, bool confusion
)
482 "ISIS-Upd (%s): BUG updating LSP %s still marked as own LSP",
483 area
->area_tag
, rawlspid_print(lsp
->hdr
.lsp_id
));
489 lsp_purge(lsp
, level
, NULL
);
491 lsp_update_data(lsp
, hdr
, tlvs
, stream
, area
, level
);
494 if (LSP_FRAGMENT(lsp
->hdr
.lsp_id
) && !lsp
->lspu
.zero_lsp
) {
495 uint8_t lspid
[ISIS_SYS_ID_LEN
+ 2];
496 struct isis_lsp
*lsp0
;
498 memcpy(lspid
, lsp
->hdr
.lsp_id
, ISIS_SYS_ID_LEN
+ 1);
499 LSP_FRAGMENT(lspid
) = 0;
500 lsp0
= lsp_search(lspid
, area
->lspdb
[level
- 1]);
502 lsp_link_fragment(lsp
, lsp0
);
506 isis_spf_schedule(lsp
->area
, lsp
->level
);
509 /* creation of LSP directly from what we received */
510 struct isis_lsp
*lsp_new_from_recv(struct isis_lsp_hdr
*hdr
,
511 struct isis_tlvs
*tlvs
,
512 struct stream
*stream
, struct isis_lsp
*lsp0
,
513 struct isis_area
*area
, int level
)
515 struct isis_lsp
*lsp
;
517 lsp
= XCALLOC(MTYPE_ISIS_LSP
, sizeof(struct isis_lsp
));
518 lsp_update_data(lsp
, hdr
, tlvs
, stream
, area
, level
);
519 lsp_link_fragment(lsp
, lsp0
);
524 static void lsp_adjust_stream(struct isis_lsp
*lsp
)
527 if (STREAM_SIZE(lsp
->pdu
) == LLC_LEN
+ lsp
->area
->lsp_mtu
)
529 stream_free(lsp
->pdu
);
532 lsp
->pdu
= stream_new(LLC_LEN
+ lsp
->area
->lsp_mtu
);
535 struct isis_lsp
*lsp_new(struct isis_area
*area
, uint8_t *lsp_id
,
536 uint16_t rem_lifetime
, uint32_t seqno
,
537 uint8_t lsp_bits
, uint16_t checksum
,
538 struct isis_lsp
*lsp0
, int level
)
540 struct isis_lsp
*lsp
;
542 lsp
= XCALLOC(MTYPE_ISIS_LSP
, sizeof(struct isis_lsp
));
545 lsp_adjust_stream(lsp
);
547 /* Minimal LSP PDU size */
548 lsp
->hdr
.pdu_len
= ISIS_FIXED_HDR_LEN
+ ISIS_LSP_HDR_LEN
;
549 memcpy(lsp
->hdr
.lsp_id
, lsp_id
, sizeof(lsp
->hdr
.lsp_id
));
550 lsp
->hdr
.checksum
= checksum
;
551 lsp
->hdr
.seqno
= seqno
;
552 lsp
->hdr
.rem_lifetime
= rem_lifetime
;
553 lsp
->hdr
.lsp_bits
= lsp_bits
;
555 lsp
->age_out
= ZERO_AGE_LIFETIME
;
556 lsp_link_fragment(lsp
, lsp0
);
557 put_lsp_hdr(lsp
, NULL
, false);
559 if (isis
->debugs
& DEBUG_EVENTS
)
560 zlog_debug("New LSP with ID %s-%02x-%02x len %d seqnum %08x",
561 sysid_print(lsp_id
), LSP_PSEUDO_ID(lsp
->hdr
.lsp_id
),
562 LSP_FRAGMENT(lsp
->hdr
.lsp_id
), lsp
->hdr
.pdu_len
,
568 void lsp_insert(struct isis_lsp
*lsp
, dict_t
*lspdb
)
570 dict_alloc_insert(lspdb
, lsp
->hdr
.lsp_id
, lsp
);
572 isis_spf_schedule(lsp
->area
, lsp
->level
);
576 * Build a list of LSPs with non-zero ht bounded by start and stop ids
578 void lsp_build_list_nonzero_ht(uint8_t *start_id
, uint8_t *stop_id
,
579 struct list
*list
, dict_t
*lspdb
)
581 dnode_t
*first
, *last
, *curr
;
583 first
= dict_lower_bound(lspdb
, start_id
);
587 last
= dict_upper_bound(lspdb
, stop_id
);
591 if (((struct isis_lsp
*)(curr
->dict_data
))->hdr
.rem_lifetime
)
592 listnode_add(list
, first
->dict_data
);
595 curr
= dict_next(lspdb
, curr
);
597 && ((struct isis_lsp
*)(curr
->dict_data
))->hdr
.rem_lifetime
)
598 listnode_add(list
, curr
->dict_data
);
606 static void lsp_set_time(struct isis_lsp
*lsp
)
610 if (lsp
->hdr
.rem_lifetime
== 0) {
611 if (lsp
->age_out
> 0)
616 lsp
->hdr
.rem_lifetime
--;
617 if (lsp
->pdu
&& stream_get_endp(lsp
->pdu
) >= 12)
618 stream_putw_at(lsp
->pdu
, 10, lsp
->hdr
.rem_lifetime
);
621 static void lspid_print(uint8_t *lsp_id
, uint8_t *trg
, char dynhost
, char frag
)
623 struct isis_dynhn
*dyn
= NULL
;
624 uint8_t id
[SYSID_STRLEN
];
627 dyn
= dynhn_find_by_id(lsp_id
);
632 sprintf((char *)id
, "%.14s", dyn
->hostname
);
633 else if (!memcmp(isis
->sysid
, lsp_id
, ISIS_SYS_ID_LEN
) && dynhost
)
634 sprintf((char *)id
, "%.14s", cmd_hostname_get());
636 memcpy(id
, sysid_print(lsp_id
), 15);
638 sprintf((char *)trg
, "%s.%02x-%02x", id
, LSP_PSEUDO_ID(lsp_id
),
639 LSP_FRAGMENT(lsp_id
));
641 sprintf((char *)trg
, "%s.%02x", id
, LSP_PSEUDO_ID(lsp_id
));
644 /* Convert the lsp attribute bits to attribute string */
645 static const char *lsp_bits2string(uint8_t lsp_bits
, char *buf
, size_t buf_size
)
652 if (buf_size
< 2 * 3)
655 /* we only focus on the default metric */
656 pos
+= sprintf(pos
, "%d/",
657 ISIS_MASK_LSP_ATT_DEFAULT_BIT(lsp_bits
) ? 1 : 0);
659 pos
+= sprintf(pos
, "%d/",
660 ISIS_MASK_LSP_PARTITION_BIT(lsp_bits
) ? 1 : 0);
662 sprintf(pos
, "%d", ISIS_MASK_LSP_OL_BIT(lsp_bits
) ? 1 : 0);
667 /* this function prints the lsp on show isis database */
668 void lsp_print(struct isis_lsp
*lsp
, struct vty
*vty
, char dynhost
)
674 lspid_print(lsp
->hdr
.lsp_id
, LSPid
, dynhost
, 1);
675 vty_out(vty
, "%-21s%c ", LSPid
, lsp
->own_lsp
? '*' : ' ');
676 vty_out(vty
, "%5" PRIu16
" ", lsp
->hdr
.pdu_len
);
677 vty_out(vty
, "0x%08" PRIx32
" ", lsp
->hdr
.seqno
);
678 vty_out(vty
, "0x%04" PRIx16
" ", lsp
->hdr
.checksum
);
679 if (lsp
->hdr
.rem_lifetime
== 0) {
680 snprintf(age_out
, 8, "(%d)", lsp
->age_out
);
682 vty_out(vty
, "%7s ", age_out
);
684 vty_out(vty
, " %5" PRIu16
" ", lsp
->hdr
.rem_lifetime
);
685 vty_out(vty
, "%s\n", lsp_bits2string(lsp
->hdr
.lsp_bits
, b
, sizeof(b
)));
688 void lsp_print_detail(struct isis_lsp
*lsp
, struct vty
*vty
, char dynhost
)
690 lsp_print(lsp
, vty
, dynhost
);
692 vty_multiline(vty
, " ", "%s", isis_format_tlvs(lsp
->tlvs
));
696 /* print all the lsps info in the local lspdb */
697 int lsp_print_all(struct vty
*vty
, dict_t
*lspdb
, char detail
, char dynhost
)
700 dnode_t
*node
= dict_first(lspdb
), *next
;
703 if (detail
== ISIS_UI_LEVEL_BRIEF
) {
704 while (node
!= NULL
) {
705 /* I think it is unnecessary, so I comment it out */
706 /* dict_contains (lspdb, node); */
707 next
= dict_next(lspdb
, node
);
708 lsp_print(dnode_get(node
), vty
, dynhost
);
712 } else if (detail
== ISIS_UI_LEVEL_DETAIL
) {
713 while (node
!= NULL
) {
714 next
= dict_next(lspdb
, node
);
715 lsp_print_detail(dnode_get(node
), vty
, dynhost
);
724 static uint16_t lsp_rem_lifetime(struct isis_area
*area
, int level
)
726 uint16_t rem_lifetime
;
728 /* Add jitter to configured LSP lifetime */
730 isis_jitter(area
->max_lsp_lifetime
[level
- 1], MAX_AGE_JITTER
);
732 /* No jitter if the max refresh will be less than configure gen interval
734 /* N.B. this calucation is acceptable since rem_lifetime is in
737 if (area
->lsp_gen_interval
[level
- 1] > (rem_lifetime
- 300))
738 rem_lifetime
= area
->max_lsp_lifetime
[level
- 1];
743 static uint16_t lsp_refresh_time(struct isis_lsp
*lsp
, uint16_t rem_lifetime
)
745 struct isis_area
*area
= lsp
->area
;
746 int level
= lsp
->level
;
747 uint16_t refresh_time
;
749 /* Add jitter to LSP refresh time */
751 isis_jitter(area
->lsp_refresh
[level
- 1], MAX_LSP_GEN_JITTER
);
753 /* RFC 4444 : make sure the refresh time is at least less than 300
754 * of the remaining lifetime and more than gen interval */
755 if (refresh_time
<= area
->lsp_gen_interval
[level
- 1]
756 || refresh_time
> (rem_lifetime
- 300))
757 refresh_time
= rem_lifetime
- 300;
759 /* In cornercases, refresh_time might be <= lsp_gen_interval, however
760 * we accept this violation to satisfy refresh_time <= rem_lifetime -
766 static void lsp_build_ext_reach_ipv4(struct isis_lsp
*lsp
,
767 struct isis_area
*area
)
769 struct route_table
*er_table
= get_ext_reach(area
, AF_INET
, lsp
->level
);
773 for (struct route_node
*rn
= route_top(er_table
); rn
;
774 rn
= route_next(rn
)) {
778 struct prefix_ipv4
*ipv4
= (struct prefix_ipv4
*)&rn
->p
;
779 struct isis_ext_info
*info
= rn
->info
;
781 uint32_t metric
= info
->metric
;
782 if (metric
> MAX_WIDE_PATH_METRIC
)
783 metric
= MAX_WIDE_PATH_METRIC
;
784 if (area
->oldmetric
&& metric
> 0x3f)
788 isis_tlvs_add_oldstyle_ip_reach(lsp
->tlvs
, ipv4
,
791 isis_tlvs_add_extended_ip_reach(lsp
->tlvs
, ipv4
,
796 static void lsp_build_ext_reach_ipv6(struct isis_lsp
*lsp
,
797 struct isis_area
*area
)
799 struct route_table
*er_table
=
800 get_ext_reach(area
, AF_INET6
, lsp
->level
);
804 for (struct route_node
*rn
= route_top(er_table
); rn
;
805 rn
= srcdest_route_next(rn
)) {
808 struct isis_ext_info
*info
= rn
->info
;
810 struct prefix_ipv6
*p
, *src_p
;
811 srcdest_rnode_prefixes(rn
, (const struct prefix
**)&p
,
812 (const struct prefix
**)&src_p
);
814 uint32_t metric
= info
->metric
;
815 if (info
->metric
> MAX_WIDE_PATH_METRIC
)
816 metric
= MAX_WIDE_PATH_METRIC
;
818 if (!src_p
|| !src_p
->prefixlen
) {
819 isis_tlvs_add_ipv6_reach(lsp
->tlvs
,
820 isis_area_ipv6_topology(area
),
822 } else if (isis_area_ipv6_dstsrc_enabled(area
)) {
823 isis_tlvs_add_ipv6_dstsrc_reach(lsp
->tlvs
,
830 static void lsp_build_ext_reach(struct isis_lsp
*lsp
, struct isis_area
*area
)
832 lsp_build_ext_reach_ipv4(lsp
, area
);
833 lsp_build_ext_reach_ipv6(lsp
, area
);
836 static struct isis_lsp
*lsp_next_frag(uint8_t frag_num
, struct isis_lsp
*lsp0
,
837 struct isis_area
*area
, int level
)
839 struct isis_lsp
*lsp
;
840 uint8_t frag_id
[ISIS_SYS_ID_LEN
+ 2];
842 memcpy(frag_id
, lsp0
->hdr
.lsp_id
, ISIS_SYS_ID_LEN
+ 1);
843 LSP_FRAGMENT(frag_id
) = frag_num
;
845 lsp
= lsp_search(frag_id
, area
->lspdb
[level
- 1]);
848 if (!lsp
->lspu
.zero_lsp
)
849 lsp_link_fragment(lsp
, lsp0
);
853 lsp
= lsp_new(area
, frag_id
, lsp0
->hdr
.rem_lifetime
, 0,
854 lsp_bits_generate(level
, area
->overload_bit
,
858 lsp_insert(lsp
, area
->lspdb
[level
- 1]);
863 * Builds the LSP data part. This func creates a new frag whenever
864 * area->lsp_frag_threshold is exceeded.
866 static void lsp_build(struct isis_lsp
*lsp
, struct isis_area
*area
)
868 int level
= lsp
->level
;
869 char buf
[PREFIX2STR_BUFFER
];
870 struct listnode
*node
;
871 struct isis_lsp
*frag
;
874 for (ALL_LIST_ELEMENTS_RO(lsp
->lspu
.frags
, node
, frag
))
875 lsp_clear_data(frag
);
877 lsp
->tlvs
= isis_alloc_tlvs();
878 lsp_debug("ISIS (%s): Constructing local system LSP for level %d",
879 area
->area_tag
, level
);
881 lsp
->hdr
.lsp_bits
= lsp_bits_generate(level
, area
->overload_bit
,
886 isis_tlvs_add_area_addresses(lsp
->tlvs
, area
->area_addrs
);
888 /* Protocols Supported */
889 if (area
->ip_circuits
> 0 || area
->ipv6_circuits
> 0) {
890 struct nlpids nlpids
= {.count
= 0};
891 if (area
->ip_circuits
> 0) {
893 "ISIS (%s): Found IPv4 circuit, adding IPv4 to NLPIDs",
895 nlpids
.nlpids
[nlpids
.count
] = NLPID_IP
;
898 if (area
->ipv6_circuits
> 0) {
900 "ISIS (%s): Found IPv6 circuit, adding IPv6 to NLPIDs",
902 nlpids
.nlpids
[nlpids
.count
] = NLPID_IPV6
;
905 isis_tlvs_set_protocols_supported(lsp
->tlvs
, &nlpids
);
908 if (area_is_mt(area
)) {
909 lsp_debug("ISIS (%s): Adding MT router tlv...", area
->area_tag
);
911 struct isis_area_mt_setting
**mt_settings
;
912 unsigned int mt_count
;
914 mt_settings
= area_mt_settings(area
, &mt_count
);
915 for (unsigned int i
= 0; i
< mt_count
; i
++) {
916 isis_tlvs_add_mt_router_info(
917 lsp
->tlvs
, mt_settings
[i
]->mtid
,
918 mt_settings
[i
]->overload
, false);
919 lsp_debug("ISIS (%s): MT %s", area
->area_tag
,
920 isis_mtid2str(mt_settings
[i
]->mtid
));
923 lsp_debug("ISIS (%s): Not adding MT router tlv (disabled)",
926 /* Dynamic Hostname */
927 if (area
->dynhostname
) {
928 isis_tlvs_set_dynamic_hostname(lsp
->tlvs
, cmd_hostname_get());
929 lsp_debug("ISIS (%s): Adding dynamic hostname '%s'",
930 area
->area_tag
, cmd_hostname_get());
932 lsp_debug("ISIS (%s): Not adding dynamic hostname (disabled)",
936 /* IPv4 address and TE router ID TLVs. In case of the first one we don't
937 * follow "C" vendor, but "J" vendor behavior - one IPv4 address is put
939 * LSP and this address is same as router id. */
940 if (isis
->router_id
!= 0) {
941 struct in_addr id
= {.s_addr
= isis
->router_id
};
942 inet_ntop(AF_INET
, &id
, buf
, sizeof(buf
));
943 lsp_debug("ISIS (%s): Adding router ID %s as IPv4 tlv.",
944 area
->area_tag
, buf
);
945 isis_tlvs_add_ipv4_address(lsp
->tlvs
, &id
);
947 /* Exactly same data is put into TE router ID TLV, but only if
949 * TLV's are in use. */
950 if (area
->newmetric
) {
953 "ISIS (%s): Adding router ID also as TE router ID tlv.",
955 isis_tlvs_set_te_router_id(lsp
->tlvs
, &id
);
958 lsp_debug("ISIS (%s): Router ID is unset. Not adding tlv.",
962 lsp_debug("ISIS (%s): Adding circuit specific information.",
967 "ISIS (%s): Adding tier %" PRIu8
" spine-leaf-extension tlv.",
968 area
->area_tag
, fabricd_tier(area
));
969 isis_tlvs_add_spine_leaf(lsp
->tlvs
, fabricd_tier(area
), true,
970 false, false, false);
973 struct isis_circuit
*circuit
;
974 for (ALL_LIST_ELEMENTS_RO(area
->circuit_list
, node
, circuit
)) {
975 if (!circuit
->interface
)
977 "ISIS (%s): Processing %s circuit %p with unknown interface",
979 circuit_type2string(circuit
->circ_type
),
982 lsp_debug("ISIS (%s): Processing %s circuit %s",
984 circuit_type2string(circuit
->circ_type
),
985 circuit
->interface
->name
);
987 if (circuit
->state
!= C_STATE_UP
) {
988 lsp_debug("ISIS (%s): Circuit is not up, ignoring.",
993 uint32_t metric
= area
->oldmetric
994 ? circuit
->metric
[level
- 1]
995 : circuit
->te_metric
[level
- 1];
997 if (circuit
->ip_router
&& circuit
->ip_addrs
998 && circuit
->ip_addrs
->count
> 0) {
1000 "ISIS (%s): Circuit has IPv4 active, adding respective TLVs.",
1002 struct listnode
*ipnode
;
1003 struct prefix_ipv4
*ipv4
;
1004 for (ALL_LIST_ELEMENTS_RO(circuit
->ip_addrs
, ipnode
,
1006 if (area
->oldmetric
) {
1008 "ISIS (%s): Adding old-style IP reachability for %s",
1010 prefix2str(ipv4
, buf
,
1012 isis_tlvs_add_oldstyle_ip_reach(
1013 lsp
->tlvs
, ipv4
, metric
);
1016 if (area
->newmetric
) {
1018 "ISIS (%s): Adding te-style IP reachability for %s",
1020 prefix2str(ipv4
, buf
,
1022 isis_tlvs_add_extended_ip_reach(
1023 lsp
->tlvs
, ipv4
, metric
);
1028 if (circuit
->ipv6_router
&& circuit
->ipv6_non_link
1029 && circuit
->ipv6_non_link
->count
> 0) {
1030 struct listnode
*ipnode
;
1031 struct prefix_ipv6
*ipv6
;
1032 for (ALL_LIST_ELEMENTS_RO(circuit
->ipv6_non_link
,
1035 "ISIS (%s): Adding IPv6 reachability for %s",
1037 prefix2str(ipv6
, buf
, sizeof(buf
)));
1038 isis_tlvs_add_ipv6_reach(
1040 isis_area_ipv6_topology(area
), ipv6
,
1045 switch (circuit
->circ_type
) {
1046 case CIRCUIT_T_BROADCAST
:
1047 if (level
& circuit
->is_type
) {
1049 (level
== IS_LEVEL_1
)
1050 ? circuit
->u
.bc
.l1_desig_is
1051 : circuit
->u
.bc
.l2_desig_is
;
1053 if (LSP_PSEUDO_ID(ne_id
)) {
1054 if (area
->oldmetric
) {
1056 "ISIS (%s): Adding DIS %s.%02x as old-style neighbor",
1059 LSP_PSEUDO_ID(ne_id
));
1060 isis_tlvs_add_oldstyle_reach(
1064 if (area
->newmetric
) {
1065 uint8_t subtlvs
[256];
1068 if (IS_MPLS_TE(isisMplsTE
)
1069 && circuit
->interface
1071 circuit
->interface
))
1072 subtlv_len
= add_te_subtlvs(
1080 level
, ne_id
, metric
,
1081 subtlvs
, subtlv_len
);
1086 "ISIS (%s): Circuit is not active for current level. Not adding IS neighbors",
1090 case CIRCUIT_T_P2P
: {
1091 struct isis_adjacency
*nei
= circuit
->u
.p2p
.neighbor
;
1092 if (nei
&& nei
->adj_state
== ISIS_ADJ_UP
1093 && (level
& nei
->circuit_t
)) {
1095 memcpy(ne_id
, nei
->sysid
, ISIS_SYS_ID_LEN
);
1096 LSP_PSEUDO_ID(ne_id
) = 0;
1098 if (area
->oldmetric
) {
1100 "ISIS (%s): Adding old-style is reach for %s",
1102 sysid_print(ne_id
));
1103 isis_tlvs_add_oldstyle_reach(
1104 lsp
->tlvs
, ne_id
, metric
);
1106 if (area
->newmetric
) {
1107 uint8_t subtlvs
[256];
1110 if (IS_MPLS_TE(isisMplsTE
)
1111 && circuit
->interface
!= NULL
1113 circuit
->interface
))
1114 /* Update Local and Remote IP
1115 * address for MPLS TE circuit
1117 /* NOTE sure that it is the
1118 * pertinent place for that
1120 /* Local IP address could be
1121 * updated in isis_circuit.c -
1122 * isis_circuit_add_addr() */
1123 /* But, where update remote IP
1124 * address ? in isis_pdu.c -
1125 * process_p2p_hello() ? */
1127 /* Add SubTLVs & Adjust real
1128 * size of SubTLVs */
1129 subtlv_len
= add_te_subtlvs(
1130 subtlvs
, circuit
->mtc
);
1132 /* Or keep only TE metric with
1133 * no SubTLVs if MPLS_TE is off
1137 uint32_t neighbor_metric
;
1138 if (fabricd_tier(area
) == 0) {
1139 neighbor_metric
= 0xffe;
1141 neighbor_metric
= metric
;
1144 tlvs_add_mt_p2p(lsp
->tlvs
, circuit
,
1145 ne_id
, neighbor_metric
,
1146 subtlvs
, subtlv_len
);
1150 "ISIS (%s): No adjacency for given level on this circuit. Not adding IS neighbors",
1154 case CIRCUIT_T_LOOPBACK
:
1157 zlog_warn("lsp_area_create: unknown circuit type");
1161 lsp_build_ext_reach(lsp
, area
);
1163 struct isis_tlvs
*tlvs
= lsp
->tlvs
;
1166 lsp_adjust_stream(lsp
);
1168 size_t tlv_space
= STREAM_WRITEABLE(lsp
->pdu
) - LLC_LEN
;
1169 lsp_clear_data(lsp
);
1171 struct list
*fragments
= isis_fragment_tlvs(tlvs
, tlv_space
);
1173 zlog_warn("BUG: could not fragment own LSP:");
1174 log_multiline(LOG_WARNING
, " ", "%s",
1175 isis_format_tlvs(tlvs
));
1176 isis_free_tlvs(tlvs
);
1179 isis_free_tlvs(tlvs
);
1181 bool fragment_overflow
= false;
1183 for (ALL_LIST_ELEMENTS_RO(fragments
, node
, tlvs
)) {
1184 if (node
!= listhead(fragments
)) {
1185 if (LSP_FRAGMENT(frag
->hdr
.lsp_id
) == 255) {
1186 if (!fragment_overflow
) {
1187 fragment_overflow
= true;
1189 "ISIS (%s): Too much information for 256 fragments",
1192 isis_free_tlvs(tlvs
);
1196 frag
= lsp_next_frag(LSP_FRAGMENT(frag
->hdr
.lsp_id
) + 1,
1198 lsp_adjust_stream(frag
);
1203 list_delete(&fragments
);
1204 lsp_debug("ISIS (%s): LSP construction is complete. Serializing...",
1210 * 7.3.7 and 7.3.9 Generation on non-pseudonode LSPs
1212 int lsp_generate(struct isis_area
*area
, int level
)
1214 struct isis_lsp
*oldlsp
, *newlsp
;
1215 uint32_t seq_num
= 0;
1216 uint8_t lspid
[ISIS_SYS_ID_LEN
+ 2];
1217 uint16_t rem_lifetime
, refresh_time
;
1219 if ((area
== NULL
) || (area
->is_type
& level
) != level
)
1222 memset(&lspid
, 0, ISIS_SYS_ID_LEN
+ 2);
1223 memcpy(&lspid
, isis
->sysid
, ISIS_SYS_ID_LEN
);
1225 /* only builds the lsp if the area shares the level */
1226 oldlsp
= lsp_search(lspid
, area
->lspdb
[level
- 1]);
1228 /* FIXME: we should actually initiate a purge */
1229 seq_num
= oldlsp
->hdr
.seqno
;
1230 lsp_search_and_destroy(oldlsp
->hdr
.lsp_id
,
1231 area
->lspdb
[level
- 1]);
1233 rem_lifetime
= lsp_rem_lifetime(area
, level
);
1235 lsp_new(area
, lspid
, rem_lifetime
, seq_num
,
1236 area
->is_type
| area
->overload_bit
| area
->attached_bit
,
1238 newlsp
->area
= area
;
1239 newlsp
->own_lsp
= 1;
1241 lsp_insert(newlsp
, area
->lspdb
[level
- 1]);
1242 /* build_lsp_data (newlsp, area); */
1243 lsp_build(newlsp
, area
);
1244 /* time to calculate our checksum */
1245 lsp_seqno_update(newlsp
);
1246 newlsp
->last_generated
= time(NULL
);
1247 lsp_flood(newlsp
, NULL
);
1249 refresh_time
= lsp_refresh_time(newlsp
, rem_lifetime
);
1251 THREAD_TIMER_OFF(area
->t_lsp_refresh
[level
- 1]);
1252 area
->lsp_regenerate_pending
[level
- 1] = 0;
1253 thread_add_timer(master
, lsp_refresh
,
1254 &area
->lsp_refresh_arg
[level
- 1], refresh_time
,
1255 &area
->t_lsp_refresh
[level
- 1]);
1257 if (isis
->debugs
& DEBUG_UPDATE_PACKETS
) {
1258 zlog_debug("ISIS-Upd (%s): Building L%d LSP %s, len %" PRIu16
1259 ", seq 0x%08" PRIx32
", cksum 0x%04" PRIx16
1260 ", lifetime %" PRIu16
"s refresh %" PRIu16
"s",
1261 area
->area_tag
, level
,
1262 rawlspid_print(newlsp
->hdr
.lsp_id
),
1263 newlsp
->hdr
.pdu_len
, newlsp
->hdr
.seqno
,
1264 newlsp
->hdr
.checksum
, newlsp
->hdr
.rem_lifetime
,
1268 "ISIS (%s): Built L%d LSP. Set triggered regenerate to non-pending.",
1269 area
->area_tag
, level
);
1275 * Search own LSPs, update holding time and flood
1277 static int lsp_regenerate(struct isis_area
*area
, int level
)
1280 struct isis_lsp
*lsp
, *frag
;
1281 struct listnode
*node
;
1282 uint8_t lspid
[ISIS_SYS_ID_LEN
+ 2];
1283 uint16_t rem_lifetime
, refresh_time
;
1285 if ((area
== NULL
) || (area
->is_type
& level
) != level
)
1288 lspdb
= area
->lspdb
[level
- 1];
1290 memset(lspid
, 0, ISIS_SYS_ID_LEN
+ 2);
1291 memcpy(lspid
, isis
->sysid
, ISIS_SYS_ID_LEN
);
1293 lsp
= lsp_search(lspid
, lspdb
);
1296 flog_err(EC_LIB_DEVELOPMENT
,
1297 "ISIS-Upd (%s): lsp_regenerate: no L%d LSP found!",
1298 area
->area_tag
, level
);
1302 lsp_clear_data(lsp
);
1303 lsp_build(lsp
, area
);
1304 rem_lifetime
= lsp_rem_lifetime(area
, level
);
1305 lsp
->hdr
.rem_lifetime
= rem_lifetime
;
1306 lsp
->last_generated
= time(NULL
);
1307 lsp_flood(lsp
, NULL
);
1308 for (ALL_LIST_ELEMENTS_RO(lsp
->lspu
.frags
, node
, frag
)) {
1309 frag
->hdr
.lsp_bits
= lsp_bits_generate(
1310 level
, area
->overload_bit
, area
->attached_bit
);
1311 /* Set the lifetime values of all the fragments to the same
1313 * so that no fragment expires before the lsp is refreshed.
1315 frag
->hdr
.rem_lifetime
= rem_lifetime
;
1316 frag
->age_out
= ZERO_AGE_LIFETIME
;
1317 lsp_flood(frag
, NULL
);
1319 lsp_seqno_update(lsp
);
1321 refresh_time
= lsp_refresh_time(lsp
, rem_lifetime
);
1322 thread_add_timer(master
, lsp_refresh
,
1323 &area
->lsp_refresh_arg
[level
- 1], refresh_time
,
1324 &area
->t_lsp_refresh
[level
- 1]);
1325 area
->lsp_regenerate_pending
[level
- 1] = 0;
1327 if (isis
->debugs
& DEBUG_UPDATE_PACKETS
) {
1329 "ISIS-Upd (%s): Refreshed our L%d LSP %s, len %" PRIu16
1330 ", seq 0x%08" PRIx32
", cksum 0x%04" PRIx16
1331 ", lifetime %" PRIu16
"s refresh %" PRIu16
"s",
1332 area
->area_tag
, level
, rawlspid_print(lsp
->hdr
.lsp_id
),
1333 lsp
->hdr
.pdu_len
, lsp
->hdr
.seqno
, lsp
->hdr
.checksum
,
1334 lsp
->hdr
.rem_lifetime
, refresh_time
);
1337 "ISIS (%s): Rebuilt L%d LSP. Set triggered regenerate to non-pending.",
1338 area
->area_tag
, level
);
1344 * Something has changed or periodic refresh -> regenerate LSP
1346 static int lsp_refresh(struct thread
*thread
)
1348 struct lsp_refresh_arg
*arg
= THREAD_ARG(thread
);
1352 struct isis_area
*area
= arg
->area
;
1356 int level
= arg
->level
;
1358 area
->t_lsp_refresh
[level
- 1] = NULL
;
1359 area
->lsp_regenerate_pending
[level
- 1] = 0;
1361 if ((area
->is_type
& level
) == 0)
1364 if (monotime_since(&area
->last_lsp_refresh_event
[level
- 1], NULL
) < 50000L) {
1365 sched_debug("ISIS (%s): Still unstable, postpone LSP L%d refresh",
1366 area
->area_tag
, level
);
1367 _lsp_regenerate_schedule(area
, level
, 0, false,
1368 __func__
, __FILE__
, __LINE__
);
1373 "ISIS (%s): LSP L%d refresh timer expired. Refreshing LSP...",
1374 area
->area_tag
, level
);
1375 return lsp_regenerate(area
, level
);
1378 int _lsp_regenerate_schedule(struct isis_area
*area
, int level
,
1379 int all_pseudo
, bool postpone
,
1380 const char *func
, const char *file
,
1383 struct isis_lsp
*lsp
;
1384 uint8_t id
[ISIS_SYS_ID_LEN
+ 2];
1387 struct listnode
*cnode
;
1388 struct isis_circuit
*circuit
;
1395 "ISIS (%s): Scheduling regeneration of %s LSPs, %sincluding PSNs"
1396 " Caller: %s %s:%d",
1397 area
->area_tag
, circuit_t2string(level
),
1398 all_pseudo
? "" : "not ",
1401 memcpy(id
, isis
->sysid
, ISIS_SYS_ID_LEN
);
1402 LSP_PSEUDO_ID(id
) = LSP_FRAGMENT(id
) = 0;
1405 for (lvl
= IS_LEVEL_1
; lvl
<= IS_LEVEL_2
; lvl
++) {
1406 if (!((level
& lvl
) && (area
->is_type
& lvl
)))
1410 monotime(&area
->last_lsp_refresh_event
[lvl
- 1]);
1414 "ISIS (%s): Checking whether L%d needs to be scheduled",
1415 area
->area_tag
, lvl
);
1417 if (area
->lsp_regenerate_pending
[lvl
- 1]) {
1418 struct timeval remain
= thread_timer_remain(
1419 area
->t_lsp_refresh
[lvl
- 1]);
1421 "ISIS (%s): Regeneration is already pending, nothing todo."
1422 " (Due in %lld.%03lld seconds)",
1423 area
->area_tag
, (long long)remain
.tv_sec
,
1424 (long long)remain
.tv_usec
/ 1000);
1428 lsp
= lsp_search(id
, area
->lspdb
[lvl
- 1]);
1431 "ISIS (%s): We do not have any LSPs to regenerate, nothing todo.",
1437 * Throttle avoidance
1440 "ISIS (%s): Will schedule regen timer. Last run was: %lld, Now is: %lld",
1441 area
->area_tag
, (long long)lsp
->last_generated
,
1443 THREAD_TIMER_OFF(area
->t_lsp_refresh
[lvl
- 1]);
1444 diff
= now
- lsp
->last_generated
;
1445 if (diff
< area
->lsp_gen_interval
[lvl
- 1]) {
1447 1000 * (area
->lsp_gen_interval
[lvl
- 1] - diff
);
1449 "ISIS (%s): Scheduling in %ld ms to match configured lsp_gen_interval",
1450 area
->area_tag
, timeout
);
1453 * lsps are not regenerated if lsp_regenerate function
1455 * directly. However if the lsp_regenerate call is
1457 * later execution it works.
1461 "ISIS (%s): Last generation was more than lsp_gen_interval ago."
1462 " Scheduling for execution in %ld ms.",
1463 area
->area_tag
, timeout
);
1466 area
->lsp_regenerate_pending
[lvl
- 1] = 1;
1467 thread_add_timer_msec(master
, lsp_refresh
,
1468 &area
->lsp_refresh_arg
[lvl
- 1],
1470 &area
->t_lsp_refresh
[lvl
- 1]);
1474 for (ALL_LIST_ELEMENTS_RO(area
->circuit_list
, cnode
, circuit
))
1475 lsp_regenerate_schedule_pseudo(circuit
, level
);
1482 * Funcs for pseudonode LSPs
1486 * 7.3.8 and 7.3.10 Generation of level 1 and 2 pseudonode LSPs
1488 static void lsp_build_pseudo(struct isis_lsp
*lsp
, struct isis_circuit
*circuit
,
1491 struct isis_adjacency
*adj
;
1492 struct list
*adj_list
;
1493 struct listnode
*node
;
1494 struct isis_area
*area
= circuit
->area
;
1496 lsp_clear_data(lsp
);
1497 lsp
->tlvs
= isis_alloc_tlvs();
1499 "ISIS (%s): Constructing pseudo LSP %s for interface %s level %d",
1500 area
->area_tag
, rawlspid_print(lsp
->hdr
.lsp_id
),
1501 circuit
->interface
->name
, level
);
1504 /* RFC3787 section 4 SHOULD not set overload bit in pseudo LSPs */
1506 lsp_bits_generate(level
, 0, circuit
->area
->attached_bit
);
1509 * add self to IS neighbours
1511 uint8_t ne_id
[ISIS_SYS_ID_LEN
+ 1];
1513 memcpy(ne_id
, isis
->sysid
, ISIS_SYS_ID_LEN
);
1514 LSP_PSEUDO_ID(ne_id
) = 0;
1516 if (circuit
->area
->oldmetric
) {
1517 isis_tlvs_add_oldstyle_reach(lsp
->tlvs
, ne_id
, 0);
1519 "ISIS (%s): Adding %s.%02x as old-style neighbor (self)",
1520 area
->area_tag
, sysid_print(ne_id
),
1521 LSP_PSEUDO_ID(ne_id
));
1523 if (circuit
->area
->newmetric
) {
1524 isis_tlvs_add_extended_reach(lsp
->tlvs
, ISIS_MT_IPV4_UNICAST
,
1527 "ISIS (%s): Adding %s.%02x as te-style neighbor (self)",
1528 area
->area_tag
, sysid_print(ne_id
),
1529 LSP_PSEUDO_ID(ne_id
));
1532 adj_list
= list_new();
1533 isis_adj_build_up_list(circuit
->u
.bc
.adjdb
[level
- 1], adj_list
);
1535 for (ALL_LIST_ELEMENTS_RO(adj_list
, node
, adj
)) {
1536 if (!(adj
->level
& level
)) {
1538 "ISIS (%s): Ignoring neighbor %s, level does not intersect",
1539 area
->area_tag
, sysid_print(adj
->sysid
));
1543 if (!(level
== IS_LEVEL_1
1544 && adj
->sys_type
== ISIS_SYSTYPE_L1_IS
)
1545 && !(level
== IS_LEVEL_1
1546 && adj
->sys_type
== ISIS_SYSTYPE_L2_IS
1547 && adj
->adj_usage
== ISIS_ADJ_LEVEL1AND2
)
1548 && !(level
== IS_LEVEL_2
1549 && adj
->sys_type
== ISIS_SYSTYPE_L2_IS
)) {
1551 "ISIS (%s): Ignoring neighbor %s, level does not match",
1552 area
->area_tag
, sysid_print(adj
->sysid
));
1556 memcpy(ne_id
, adj
->sysid
, ISIS_SYS_ID_LEN
);
1557 if (circuit
->area
->oldmetric
) {
1558 isis_tlvs_add_oldstyle_reach(lsp
->tlvs
, ne_id
, 0);
1560 "ISIS (%s): Adding %s.%02x as old-style neighbor (peer)",
1561 area
->area_tag
, sysid_print(ne_id
),
1562 LSP_PSEUDO_ID(ne_id
));
1564 if (circuit
->area
->newmetric
) {
1565 isis_tlvs_add_extended_reach(lsp
->tlvs
,
1566 ISIS_MT_IPV4_UNICAST
,
1569 "ISIS (%s): Adding %s.%02x as te-style neighbor (peer)",
1570 area
->area_tag
, sysid_print(ne_id
),
1571 LSP_PSEUDO_ID(ne_id
));
1574 list_delete(&adj_list
);
1578 int lsp_generate_pseudo(struct isis_circuit
*circuit
, int level
)
1580 dict_t
*lspdb
= circuit
->area
->lspdb
[level
- 1];
1581 struct isis_lsp
*lsp
;
1582 uint8_t lsp_id
[ISIS_SYS_ID_LEN
+ 2];
1583 uint16_t rem_lifetime
, refresh_time
;
1585 if ((circuit
->is_type
& level
) != level
1586 || (circuit
->state
!= C_STATE_UP
)
1587 || (circuit
->circ_type
!= CIRCUIT_T_BROADCAST
)
1588 || (circuit
->u
.bc
.is_dr
[level
- 1] == 0))
1591 memcpy(lsp_id
, isis
->sysid
, ISIS_SYS_ID_LEN
);
1592 LSP_FRAGMENT(lsp_id
) = 0;
1593 LSP_PSEUDO_ID(lsp_id
) = circuit
->circuit_id
;
1596 * If for some reason have a pseudo LSP in the db already -> regenerate
1598 if (lsp_search(lsp_id
, lspdb
))
1599 return lsp_regenerate_schedule_pseudo(circuit
, level
);
1601 rem_lifetime
= lsp_rem_lifetime(circuit
->area
, level
);
1602 /* RFC3787 section 4 SHOULD not set overload bit in pseudo LSPs */
1603 lsp
= lsp_new(circuit
->area
, lsp_id
, rem_lifetime
, 1,
1604 circuit
->area
->is_type
| circuit
->area
->attached_bit
, 0,
1606 lsp
->area
= circuit
->area
;
1608 lsp_build_pseudo(lsp
, circuit
, level
);
1611 lsp_insert(lsp
, lspdb
);
1612 lsp_flood(lsp
, NULL
);
1614 refresh_time
= lsp_refresh_time(lsp
, rem_lifetime
);
1615 THREAD_TIMER_OFF(circuit
->u
.bc
.t_refresh_pseudo_lsp
[level
- 1]);
1616 circuit
->lsp_regenerate_pending
[level
- 1] = 0;
1617 if (level
== IS_LEVEL_1
)
1619 master
, lsp_l1_refresh_pseudo
, circuit
, refresh_time
,
1620 &circuit
->u
.bc
.t_refresh_pseudo_lsp
[level
- 1]);
1621 else if (level
== IS_LEVEL_2
)
1623 master
, lsp_l2_refresh_pseudo
, circuit
, refresh_time
,
1624 &circuit
->u
.bc
.t_refresh_pseudo_lsp
[level
- 1]);
1626 if (isis
->debugs
& DEBUG_UPDATE_PACKETS
) {
1628 "ISIS-Upd (%s): Built L%d Pseudo LSP %s, len %" PRIu16
1629 ", seq 0x%08" PRIx32
", cksum 0x%04" PRIx16
1630 ", lifetime %" PRIu16
"s, refresh %" PRIu16
"s",
1631 circuit
->area
->area_tag
, level
,
1632 rawlspid_print(lsp
->hdr
.lsp_id
), lsp
->hdr
.pdu_len
,
1633 lsp
->hdr
.seqno
, lsp
->hdr
.checksum
,
1634 lsp
->hdr
.rem_lifetime
, refresh_time
);
1640 static int lsp_regenerate_pseudo(struct isis_circuit
*circuit
, int level
)
1642 dict_t
*lspdb
= circuit
->area
->lspdb
[level
- 1];
1643 struct isis_lsp
*lsp
;
1644 uint8_t lsp_id
[ISIS_SYS_ID_LEN
+ 2];
1645 uint16_t rem_lifetime
, refresh_time
;
1647 if ((circuit
->is_type
& level
) != level
1648 || (circuit
->state
!= C_STATE_UP
)
1649 || (circuit
->circ_type
!= CIRCUIT_T_BROADCAST
)
1650 || (circuit
->u
.bc
.is_dr
[level
- 1] == 0))
1653 memcpy(lsp_id
, isis
->sysid
, ISIS_SYS_ID_LEN
);
1654 LSP_PSEUDO_ID(lsp_id
) = circuit
->circuit_id
;
1655 LSP_FRAGMENT(lsp_id
) = 0;
1657 lsp
= lsp_search(lsp_id
, lspdb
);
1660 flog_err(EC_LIB_DEVELOPMENT
,
1661 "lsp_regenerate_pseudo: no l%d LSP %s found!", level
,
1662 rawlspid_print(lsp_id
));
1666 rem_lifetime
= lsp_rem_lifetime(circuit
->area
, level
);
1667 lsp
->hdr
.rem_lifetime
= rem_lifetime
;
1668 lsp_build_pseudo(lsp
, circuit
, level
);
1669 lsp_inc_seqno(lsp
, 0);
1670 lsp
->last_generated
= time(NULL
);
1671 lsp_flood(lsp
, NULL
);
1673 refresh_time
= lsp_refresh_time(lsp
, rem_lifetime
);
1674 if (level
== IS_LEVEL_1
)
1676 master
, lsp_l1_refresh_pseudo
, circuit
, refresh_time
,
1677 &circuit
->u
.bc
.t_refresh_pseudo_lsp
[level
- 1]);
1678 else if (level
== IS_LEVEL_2
)
1680 master
, lsp_l2_refresh_pseudo
, circuit
, refresh_time
,
1681 &circuit
->u
.bc
.t_refresh_pseudo_lsp
[level
- 1]);
1683 if (isis
->debugs
& DEBUG_UPDATE_PACKETS
) {
1685 "ISIS-Upd (%s): Refreshed L%d Pseudo LSP %s, len %" PRIu16
1686 ", seq 0x%08" PRIx32
", cksum 0x%04" PRIx16
1687 ", lifetime %" PRIu16
"s, refresh %" PRIu16
"s",
1688 circuit
->area
->area_tag
, level
,
1689 rawlspid_print(lsp
->hdr
.lsp_id
), lsp
->hdr
.pdu_len
,
1690 lsp
->hdr
.seqno
, lsp
->hdr
.checksum
,
1691 lsp
->hdr
.rem_lifetime
, refresh_time
);
1698 * Something has changed or periodic refresh -> regenerate pseudo LSP
1700 static int lsp_l1_refresh_pseudo(struct thread
*thread
)
1702 struct isis_circuit
*circuit
;
1703 uint8_t id
[ISIS_SYS_ID_LEN
+ 2];
1705 circuit
= THREAD_ARG(thread
);
1707 circuit
->u
.bc
.t_refresh_pseudo_lsp
[0] = NULL
;
1708 circuit
->lsp_regenerate_pending
[0] = 0;
1710 if ((circuit
->u
.bc
.is_dr
[0] == 0)
1711 || (circuit
->is_type
& IS_LEVEL_1
) == 0) {
1712 memcpy(id
, isis
->sysid
, ISIS_SYS_ID_LEN
);
1713 LSP_PSEUDO_ID(id
) = circuit
->circuit_id
;
1714 LSP_FRAGMENT(id
) = 0;
1715 lsp_purge_pseudo(id
, circuit
, IS_LEVEL_1
);
1719 return lsp_regenerate_pseudo(circuit
, IS_LEVEL_1
);
1722 static int lsp_l2_refresh_pseudo(struct thread
*thread
)
1724 struct isis_circuit
*circuit
;
1725 uint8_t id
[ISIS_SYS_ID_LEN
+ 2];
1727 circuit
= THREAD_ARG(thread
);
1729 circuit
->u
.bc
.t_refresh_pseudo_lsp
[1] = NULL
;
1730 circuit
->lsp_regenerate_pending
[1] = 0;
1732 if ((circuit
->u
.bc
.is_dr
[1] == 0)
1733 || (circuit
->is_type
& IS_LEVEL_2
) == 0) {
1734 memcpy(id
, isis
->sysid
, ISIS_SYS_ID_LEN
);
1735 LSP_PSEUDO_ID(id
) = circuit
->circuit_id
;
1736 LSP_FRAGMENT(id
) = 0;
1737 lsp_purge_pseudo(id
, circuit
, IS_LEVEL_2
);
1741 return lsp_regenerate_pseudo(circuit
, IS_LEVEL_2
);
1744 int lsp_regenerate_schedule_pseudo(struct isis_circuit
*circuit
, int level
)
1746 struct isis_lsp
*lsp
;
1747 uint8_t lsp_id
[ISIS_SYS_ID_LEN
+ 2];
1751 struct isis_area
*area
= circuit
->area
;
1753 if (circuit
->circ_type
!= CIRCUIT_T_BROADCAST
1754 || circuit
->state
!= C_STATE_UP
)
1758 "ISIS (%s): Scheduling regeneration of %s pseudo LSP for interface %s",
1759 area
->area_tag
, circuit_t2string(level
),
1760 circuit
->interface
->name
);
1762 memcpy(lsp_id
, isis
->sysid
, ISIS_SYS_ID_LEN
);
1763 LSP_PSEUDO_ID(lsp_id
) = circuit
->circuit_id
;
1764 LSP_FRAGMENT(lsp_id
) = 0;
1767 for (lvl
= IS_LEVEL_1
; lvl
<= IS_LEVEL_2
; lvl
++) {
1769 "ISIS (%s): Checking whether L%d pseudo LSP needs to be scheduled",
1770 area
->area_tag
, lvl
);
1772 if (!((level
& lvl
) && (circuit
->is_type
& lvl
))) {
1773 sched_debug("ISIS (%s): Level is not active on circuit",
1778 if (circuit
->u
.bc
.is_dr
[lvl
- 1] == 0) {
1780 "ISIS (%s): This IS is not DR, nothing to do.",
1785 if (circuit
->lsp_regenerate_pending
[lvl
- 1]) {
1786 struct timeval remain
= thread_timer_remain(
1787 circuit
->u
.bc
.t_refresh_pseudo_lsp
[lvl
- 1]);
1789 "ISIS (%s): Regenerate is already pending, nothing todo."
1790 " (Due in %lld.%03lld seconds)",
1791 area
->area_tag
, (long long)remain
.tv_sec
,
1792 (long long)remain
.tv_usec
/ 1000);
1796 lsp
= lsp_search(lsp_id
, circuit
->area
->lspdb
[lvl
- 1]);
1799 "ISIS (%s): Pseudonode LSP does not exist yet, nothing to regenerate.",
1805 * Throttle avoidance
1808 "ISIS (%s): Will schedule PSN regen timer. Last run was: %lld, Now is: %lld",
1809 area
->area_tag
, (long long)lsp
->last_generated
,
1811 THREAD_TIMER_OFF(circuit
->u
.bc
.t_refresh_pseudo_lsp
[lvl
- 1]);
1812 diff
= now
- lsp
->last_generated
;
1813 if (diff
< circuit
->area
->lsp_gen_interval
[lvl
- 1]) {
1815 1000 * (circuit
->area
->lsp_gen_interval
[lvl
- 1]
1818 "ISIS (%s): Sechduling in %ld ms to match configured lsp_gen_interval",
1819 area
->area_tag
, timeout
);
1823 "ISIS (%s): Last generation was more than lsp_gen_interval ago."
1824 " Scheduling for execution in %ld ms.",
1825 area
->area_tag
, timeout
);
1828 circuit
->lsp_regenerate_pending
[lvl
- 1] = 1;
1830 if (lvl
== IS_LEVEL_1
) {
1831 thread_add_timer_msec(
1832 master
, lsp_l1_refresh_pseudo
, circuit
, timeout
,
1833 &circuit
->u
.bc
.t_refresh_pseudo_lsp
[lvl
- 1]);
1834 } else if (lvl
== IS_LEVEL_2
) {
1835 thread_add_timer_msec(
1836 master
, lsp_l2_refresh_pseudo
, circuit
, timeout
,
1837 &circuit
->u
.bc
.t_refresh_pseudo_lsp
[lvl
- 1]);
1845 * Walk through LSPs for an area
1846 * - set remaining lifetime
1848 int lsp_tick(struct thread
*thread
)
1850 struct isis_area
*area
;
1851 struct isis_lsp
*lsp
;
1852 dnode_t
*dnode
, *dnode_next
;
1854 uint16_t rem_lifetime
;
1855 bool fabricd_sync_incomplete
= false;
1857 area
= THREAD_ARG(thread
);
1859 area
->t_tick
= NULL
;
1860 thread_add_timer(master
, lsp_tick
, area
, 1, &area
->t_tick
);
1862 struct isis_circuit
*fabricd_init_c
= fabricd_initial_sync_circuit(area
);
1865 * Remove LSPs which have aged out
1867 for (level
= 0; level
< ISIS_LEVELS
; level
++) {
1868 if (area
->lspdb
[level
] && dict_count(area
->lspdb
[level
]) > 0) {
1869 for (dnode
= dict_first(area
->lspdb
[level
]);
1870 dnode
!= NULL
; dnode
= dnode_next
) {
1872 dict_next(area
->lspdb
[level
], dnode
);
1873 lsp
= dnode_get(dnode
);
1876 * The lsp rem_lifetime is kept at 0 for MaxAge
1878 * ZeroAgeLifetime depending on explicit purge
1880 * natural age out. So schedule spf only once
1882 * the first time rem_lifetime becomes 0.
1884 rem_lifetime
= lsp
->hdr
.rem_lifetime
;
1888 * Schedule may run spf which should be done
1890 * the lsp rem_lifetime becomes 0 for the first
1892 * ISO 10589 - 7.3.16.4 first paragraph.
1894 if (rem_lifetime
== 1 && lsp
->hdr
.seqno
!= 0) {
1895 /* 7.3.16.4 a) set SRM flags on all */
1896 /* 7.3.16.4 b) retain only the header */
1897 if (lsp
->area
->purge_originator
)
1898 lsp_purge(lsp
, lsp
->level
, NULL
);
1900 lsp_flood(lsp
, NULL
);
1901 /* 7.3.16.4 c) record the time to purge
1903 isis_spf_schedule(lsp
->area
, lsp
->level
);
1906 if (lsp
->age_out
== 0) {
1908 "ISIS-Upd (%s): L%u LSP %s seq "
1909 "0x%08" PRIx32
" aged out",
1910 area
->area_tag
, lsp
->level
,
1911 rawlspid_print(lsp
->hdr
.lsp_id
),
1915 dict_delete_free(area
->lspdb
[level
],
1919 if (fabricd_init_c
&& lsp
) {
1920 fabricd_sync_incomplete
|=
1921 ISIS_CHECK_FLAG(lsp
->SSNflags
,
1929 && !fabricd_sync_incomplete
1930 && !isis_tx_queue_len(fabricd_init_c
->tx_queue
)) {
1931 fabricd_initial_sync_finish(area
);
1937 void lsp_purge_pseudo(uint8_t *id
, struct isis_circuit
*circuit
, int level
)
1939 struct isis_lsp
*lsp
;
1941 lsp
= lsp_search(id
, circuit
->area
->lspdb
[level
- 1]);
1945 lsp_purge(lsp
, level
, NULL
);
1949 * Purge own LSP that is received and we don't have.
1950 * -> Do as in 7.3.16.4
1952 void lsp_purge_non_exist(int level
, struct isis_lsp_hdr
*hdr
,
1953 struct isis_area
*area
)
1955 struct isis_lsp
*lsp
;
1958 * We need to create the LSP to be purged
1960 lsp
= XCALLOC(MTYPE_ISIS_LSP
, sizeof(struct isis_lsp
));
1963 lsp_adjust_stream(lsp
);
1964 lsp
->age_out
= ZERO_AGE_LIFETIME
;
1966 memcpy(&lsp
->hdr
, hdr
, sizeof(lsp
->hdr
));
1967 lsp
->hdr
.rem_lifetime
= 0;
1969 lsp_purge_add_poi(lsp
, NULL
);
1973 lsp_insert(lsp
, area
->lspdb
[lsp
->level
- 1]);
1974 lsp_flood(lsp
, NULL
);
1979 void lsp_set_all_srmflags(struct isis_lsp
*lsp
, bool set
)
1981 struct listnode
*node
;
1982 struct isis_circuit
*circuit
;
1989 struct list
*circuit_list
= lsp
->area
->circuit_list
;
1990 for (ALL_LIST_ELEMENTS_RO(circuit_list
, node
, circuit
)) {
1992 isis_tx_queue_add(circuit
->tx_queue
, lsp
,
1995 isis_tx_queue_del(circuit
->tx_queue
, lsp
);
2000 void lsp_flood(struct isis_lsp
*lsp
, struct isis_circuit
*circuit
)
2003 lsp_set_all_srmflags(lsp
, true);
2005 fabricd_lsp_flood(lsp
);
2008 isis_tx_queue_del(circuit
->tx_queue
, lsp
);
2011 static int lsp_handle_adj_state_change(struct isis_adjacency
*adj
)
2013 lsp_regenerate_schedule(adj
->circuit
->area
, IS_LEVEL_1
| IS_LEVEL_2
, 0);
2019 hook_register(isis_adj_state_change_hook
,
2020 lsp_handle_adj_state_change
);