1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (C) 2020 NetDEF, Inc.
14 #include "srcdest_table.h"
18 #include "isis_common.h"
20 #include "isis_misc.h"
21 #include "isis_adjacency.h"
22 #include "isis_circuit.h"
25 #include "isis_route.h"
27 #include "isis_tlvs.h"
28 #include "isis_spf_private.h"
29 #include "isis_zebra.h"
30 #include "isis_errors.h"
32 DEFINE_MTYPE_STATIC(ISISD
, ISIS_SPF_NODE
, "ISIS SPF Node");
33 DEFINE_MTYPE_STATIC(ISISD
, ISIS_LFA_TIEBREAKER
, "ISIS LFA Tiebreaker");
34 DEFINE_MTYPE_STATIC(ISISD
, ISIS_LFA_EXCL_IFACE
, "ISIS LFA Excluded Interface");
35 DEFINE_MTYPE_STATIC(ISISD
, ISIS_RLFA
, "ISIS Remote LFA");
36 DEFINE_MTYPE(ISISD
, ISIS_NEXTHOP_LABELS
, "ISIS nexthop MPLS labels");
38 static inline int isis_spf_node_compare(const struct isis_spf_node
*a
,
39 const struct isis_spf_node
*b
)
41 return memcmp(a
->sysid
, b
->sysid
, sizeof(a
->sysid
));
43 RB_GENERATE(isis_spf_nodes
, isis_spf_node
, entry
, isis_spf_node_compare
)
46 * Initialize list of SPF nodes.
48 * @param nodes List of SPF nodes
50 void isis_spf_node_list_init(struct isis_spf_nodes
*nodes
)
52 RB_INIT(isis_spf_nodes
, nodes
);
56 * Clear list of SPF nodes, releasing all allocated memory.
58 * @param nodes List of SPF nodes
60 void isis_spf_node_list_clear(struct isis_spf_nodes
*nodes
)
62 while (!RB_EMPTY(isis_spf_nodes
, nodes
)) {
63 struct isis_spf_node
*node
= RB_ROOT(isis_spf_nodes
, nodes
);
65 if (node
->adjacencies
)
66 list_delete(&node
->adjacencies
);
67 if (node
->lfa
.spftree
)
68 isis_spftree_del(node
->lfa
.spftree
);
69 if (node
->lfa
.spftree_reverse
)
70 isis_spftree_del(node
->lfa
.spftree_reverse
);
71 isis_spf_node_list_clear(&node
->lfa
.p_space
);
72 RB_REMOVE(isis_spf_nodes
, nodes
, node
);
73 XFREE(MTYPE_ISIS_SPF_NODE
, node
);
78 * Add new node to list of SPF nodes.
80 * @param nodes List of SPF nodes
81 * @param sysid Node System ID
83 * @return Pointer to new IS-IS SPF node structure.
85 struct isis_spf_node
*isis_spf_node_new(struct isis_spf_nodes
*nodes
,
88 struct isis_spf_node
*node
;
90 node
= XCALLOC(MTYPE_ISIS_SPF_NODE
, sizeof(*node
));
91 memcpy(node
->sysid
, sysid
, sizeof(node
->sysid
));
92 node
->adjacencies
= list_new();
93 isis_spf_node_list_init(&node
->lfa
.p_space
);
94 RB_INSERT(isis_spf_nodes
, nodes
, node
);
100 * Lookup SPF node by its System ID on the given list.
102 * @param nodes List of SPF nodes
103 * @param sysid Node System ID
105 * @return Pointer to SPF node if found, NULL otherwise
107 struct isis_spf_node
*isis_spf_node_find(const struct isis_spf_nodes
*nodes
,
108 const uint8_t *sysid
)
110 struct isis_spf_node node
= {};
112 memcpy(node
.sysid
, sysid
, sizeof(node
.sysid
));
113 return RB_FIND(isis_spf_nodes
, nodes
, &node
);
117 * LFA tiebreaker RB-tree comparison function.
119 * @param a First LFA tiebreaker
120 * @param b Second LFA tiebreaker
122 * @return -1 (a < b), 0 (a == b) or +1 (a > b)
124 int lfa_tiebreaker_cmp(const struct lfa_tiebreaker
*a
,
125 const struct lfa_tiebreaker
*b
)
127 if (a
->index
< b
->index
)
129 if (a
->index
> b
->index
)
132 return a
->type
- b
->type
;
136 * Initialize list of LFA tie-breakers.
138 * @param area IS-IS area
139 * @param level IS-IS level
141 void isis_lfa_tiebreakers_init(struct isis_area
*area
, int level
)
143 lfa_tiebreaker_tree_init(&area
->lfa_tiebreakers
[level
- 1]);
147 * Clear list of LFA tie-breakers, releasing all allocated memory.
149 * @param area IS-IS area
150 * @param level IS-IS level
152 void isis_lfa_tiebreakers_clear(struct isis_area
*area
, int level
)
154 while (lfa_tiebreaker_tree_count(&area
->lfa_tiebreakers
[level
- 1])
156 struct lfa_tiebreaker
*tie_b
;
158 tie_b
= lfa_tiebreaker_tree_first(
159 &area
->lfa_tiebreakers
[level
- 1]);
160 isis_lfa_tiebreaker_delete(area
, level
, tie_b
);
165 * Add new LFA tie-breaker to list of LFA tie-breakers.
167 * @param area IS-IS area
168 * @param level IS-IS level
169 * @param index LFA tie-breaker index
170 * @param type LFA tie-breaker type
172 * @return Pointer to new LFA tie-breaker structure.
174 struct lfa_tiebreaker
*isis_lfa_tiebreaker_add(struct isis_area
*area
,
175 int level
, uint8_t index
,
176 enum lfa_tiebreaker_type type
)
178 struct lfa_tiebreaker
*tie_b
;
180 tie_b
= XCALLOC(MTYPE_ISIS_LFA_TIEBREAKER
, sizeof(*tie_b
));
181 tie_b
->index
= index
;
184 lfa_tiebreaker_tree_add(&area
->lfa_tiebreakers
[level
- 1], tie_b
);
190 * Remove LFA tie-breaker from list of LFA tie-breakers.
192 * @param area IS-IS area
193 * @param level IS-IS level
194 * @param tie_b Pointer to LFA tie-breaker structure
196 void isis_lfa_tiebreaker_delete(struct isis_area
*area
, int level
,
197 struct lfa_tiebreaker
*tie_b
)
199 lfa_tiebreaker_tree_del(&area
->lfa_tiebreakers
[level
- 1], tie_b
);
200 XFREE(MTYPE_ISIS_LFA_TIEBREAKER
, tie_b
);
203 static bool lfa_excl_interface_hash_cmp(const void *value1
, const void *value2
)
205 return strmatch(value1
, value2
);
208 static unsigned int lfa_excl_interface_hash_make(const void *value
)
210 return string_hash_make(value
);
213 static void *lfa_excl_interface_hash_alloc(void *p
)
215 return XSTRDUP(MTYPE_ISIS_LFA_EXCL_IFACE
, p
);
218 static void lfa_excl_interface_hash_free(void *arg
)
220 XFREE(MTYPE_ISIS_LFA_EXCL_IFACE
, arg
);
224 * Initialize hash table of LFA excluded interfaces.
226 * @param circuit IS-IS interface
227 * @param level IS-IS level
229 void isis_lfa_excluded_ifaces_init(struct isis_circuit
*circuit
, int level
)
231 circuit
->lfa_excluded_ifaces
[level
- 1] = hash_create(
232 lfa_excl_interface_hash_make
, lfa_excl_interface_hash_cmp
,
233 "LFA Excluded Interfaces");
237 * Clear hash table of LFA excluded interfaces, releasing all allocated memory.
239 * @param nodes List of SPF nodes
241 void isis_lfa_excluded_ifaces_clear(struct isis_circuit
*circuit
, int level
)
243 hash_clean(circuit
->lfa_excluded_ifaces
[level
- 1],
244 lfa_excl_interface_hash_free
);
248 * Add new interface to hash table of excluded interfaces.
250 * @param circuit IS-IS interface
251 * @param level IS-IS level
252 * @param ifname Excluded interface name
254 void isis_lfa_excluded_iface_add(struct isis_circuit
*circuit
, int level
,
257 (void)hash_get(circuit
->lfa_excluded_ifaces
[level
- 1], (char *)ifname
,
258 lfa_excl_interface_hash_alloc
);
262 * Remove interface from hash table of excluded interfaces.
264 * @param circuit IS-IS interface
265 * @param level IS-IS level
266 * @param ifname Excluded interface name
268 void isis_lfa_excluded_iface_delete(struct isis_circuit
*circuit
, int level
,
273 found
= hash_lookup(circuit
->lfa_excluded_ifaces
[level
- 1],
276 hash_release(circuit
->lfa_excluded_ifaces
[level
- 1], found
);
277 lfa_excl_interface_hash_free(found
);
282 * Lookup excluded interface.
284 * @param circuit IS-IS interface
285 * @param level IS-IS level
286 * @param ifname Excluded interface name
288 bool isis_lfa_excluded_iface_check(struct isis_circuit
*circuit
, int level
,
291 return hash_lookup(circuit
->lfa_excluded_ifaces
[level
- 1],
296 * Check if a given IS-IS adjacency needs to be excised when computing the SPF
297 * post-convergence tree.
299 * @param spftree IS-IS SPF tree
300 * @param id Adjacency System ID (or LAN ID of the designated router
301 * for broadcast interfaces)
303 * @return true if the adjacency needs to be excised, false
306 bool isis_lfa_excise_adj_check(const struct isis_spftree
*spftree
,
309 const struct lfa_protected_resource
*resource
;
311 if (spftree
->type
!= SPF_TYPE_RLFA
&& spftree
->type
!= SPF_TYPE_TI_LFA
)
315 * Adjacencies formed over the failed interface should be excised both
316 * when using link and node protection.
318 resource
= &spftree
->lfa
.protected_resource
;
319 if (!memcmp(resource
->adjacency
, id
, ISIS_SYS_ID_LEN
+ 1))
326 * Check if a given IS-IS node needs to be excised when computing the SPF
327 * post-convergence tree.
329 * @param spftree IS-IS SPF tree
330 * @param id Node System ID
332 * @return true if the node needs to be excised, false otherwise
334 bool isis_lfa_excise_node_check(const struct isis_spftree
*spftree
,
337 const struct lfa_protected_resource
*resource
;
339 if (spftree
->type
!= SPF_TYPE_TI_LFA
)
343 * When using node protection, nodes reachable over the failed interface
346 resource
= &spftree
->lfa
.protected_resource
;
347 if (resource
->type
== LFA_LINK_PROTECTION
)
350 if (isis_spf_node_find(&resource
->nodes
, id
))
356 struct tilfa_find_pnode_prefix_sid_args
{
360 static int tilfa_find_pnode_prefix_sid_cb(const struct prefix
*prefix
,
361 uint32_t metric
, bool external
,
362 struct isis_subtlvs
*subtlvs
,
365 struct tilfa_find_pnode_prefix_sid_args
*args
= arg
;
366 struct isis_prefix_sid
*psid
;
368 if (!subtlvs
|| subtlvs
->prefix_sids
.count
== 0)
369 return LSP_ITER_CONTINUE
;
371 psid
= (struct isis_prefix_sid
*)subtlvs
->prefix_sids
.head
;
373 /* Require the node flag to be set. */
374 if (!CHECK_FLAG(psid
->flags
, ISIS_PREFIX_SID_NODE
))
375 return LSP_ITER_CONTINUE
;
377 args
->sid_index
= psid
->value
;
379 return LSP_ITER_STOP
;
382 /* Find Prefix-SID associated to a System ID. */
383 static uint32_t tilfa_find_pnode_prefix_sid(struct isis_spftree
*spftree
,
384 const uint8_t *sysid
)
386 struct isis_lsp
*lsp
;
387 struct tilfa_find_pnode_prefix_sid_args args
;
389 lsp
= isis_root_system_lsp(spftree
->lspdb
, sysid
);
393 args
.sid_index
= UINT32_MAX
;
394 isis_lsp_iterate_ip_reach(lsp
, spftree
->family
, spftree
->mtid
,
395 tilfa_find_pnode_prefix_sid_cb
, &args
);
397 return args
.sid_index
;
400 struct tilfa_find_qnode_adj_sid_args
{
401 const uint8_t *qnode_sysid
;
405 static int tilfa_find_qnode_adj_sid_cb(const uint8_t *id
, uint32_t metric
,
407 struct isis_ext_subtlvs
*subtlvs
,
410 struct tilfa_find_qnode_adj_sid_args
*args
= arg
;
411 struct isis_adj_sid
*adj_sid
;
413 if (memcmp(id
, args
->qnode_sysid
, ISIS_SYS_ID_LEN
))
414 return LSP_ITER_CONTINUE
;
415 if (!subtlvs
|| subtlvs
->adj_sid
.count
== 0)
416 return LSP_ITER_CONTINUE
;
418 adj_sid
= (struct isis_adj_sid
*)subtlvs
->adj_sid
.head
;
419 args
->label
= adj_sid
->sid
;
421 return LSP_ITER_STOP
;
424 /* Find Adj-SID associated to a pair of System IDs. */
425 static mpls_label_t
tilfa_find_qnode_adj_sid(struct isis_spftree
*spftree
,
426 const uint8_t *source_sysid
,
427 const uint8_t *qnode_sysid
)
429 struct isis_lsp
*lsp
;
430 struct tilfa_find_qnode_adj_sid_args args
;
432 lsp
= isis_root_system_lsp(spftree
->lspdb
, source_sysid
);
434 return MPLS_INVALID_LABEL
;
436 args
.qnode_sysid
= qnode_sysid
;
437 args
.label
= MPLS_INVALID_LABEL
;
438 isis_lsp_iterate_is_reach(lsp
, spftree
->mtid
,
439 tilfa_find_qnode_adj_sid_cb
, &args
);
445 * Compute the MPLS label stack associated to a TI-LFA repair list. This
446 * needs to be computed separately for each adjacency since different
447 * neighbors can have different SRGBs.
449 static struct mpls_label_stack
*
450 tilfa_compute_label_stack(struct lspdb_head
*lspdb
,
451 const struct isis_spf_adj
*sadj
,
452 const struct list
*repair_list
)
454 struct mpls_label_stack
*label_stack
;
455 struct isis_tilfa_sid
*sid
;
456 struct listnode
*node
;
459 /* Allocate label stack. */
460 label_stack
= XCALLOC(MTYPE_ISIS_NEXTHOP_LABELS
,
461 sizeof(struct mpls_label_stack
)
462 + listcount(repair_list
)
463 * sizeof(mpls_label_t
));
464 label_stack
->num_labels
= listcount(repair_list
);
466 for (ALL_LIST_ELEMENTS_RO(repair_list
, node
, sid
)) {
467 const uint8_t *target_node
;
468 struct isis_sr_block
*srgb
;
472 case TILFA_SID_PREFIX
:
473 if (sid
->value
.index
.remote
)
474 target_node
= sid
->value
.index
.remote_sysid
;
476 target_node
= sadj
->id
;
477 srgb
= isis_sr_find_srgb(lspdb
, target_node
);
479 zlog_warn("%s: SRGB not found for node %s",
481 print_sys_hostname(target_node
));
485 /* Check if the SID index falls inside the SRGB. */
486 if (sid
->value
.index
.value
>= srgb
->range_size
) {
488 EC_ISIS_SID_OVERFLOW
,
489 "%s: SID index %u falls outside remote SRGB range",
490 __func__
, sid
->value
.index
.value
);
495 * Prefix-SID: map SID index to label value within the
498 label
= srgb
->lower_bound
+ sid
->value
.index
.value
;
501 /* Adj-SID: absolute label value can be used directly */
502 label
= sid
->value
.label
;
505 flog_err(EC_LIB_DEVELOPMENT
,
506 "%s: unknown TI-LFA SID type [%u]", __func__
,
510 label_stack
->label
[i
++] = label
;
516 XFREE(MTYPE_ISIS_NEXTHOP_LABELS
, label_stack
);
520 static int tilfa_repair_list_apply(struct isis_spftree
*spftree
,
521 struct isis_vertex
*vertex_dest
,
522 const struct isis_vertex
*vertex_pnode
,
523 const struct list
*repair_list
)
525 struct isis_vertex_adj
*vadj
;
526 struct listnode
*node
;
528 for (ALL_LIST_ELEMENTS_RO(vertex_dest
->Adj_N
, node
, vadj
)) {
529 struct isis_spf_adj
*sadj
= vadj
->sadj
;
530 struct mpls_label_stack
*label_stack
;
533 * Don't try to apply the repair list if one was already applied
534 * before (can't have ECMP past the P-node).
536 if (vadj
->label_stack
)
539 if (!isis_vertex_adj_exists(spftree
, vertex_pnode
, sadj
))
542 label_stack
= tilfa_compute_label_stack(spftree
->lspdb
, sadj
,
545 char buf
[VID2STR_BUFFER
];
547 vid2string(vertex_dest
, buf
, sizeof(buf
));
549 "%s: %s %s adjacency %s: failed to compute label stack",
550 __func__
, vtype2string(vertex_dest
->type
), buf
,
551 print_sys_hostname(sadj
->id
));
555 vadj
->label_stack
= label_stack
;
562 * Check if a node belongs to the extended P-space corresponding to a given
565 static bool lfa_ext_p_space_check(const struct isis_spftree
*spftree_pc
,
566 const struct isis_vertex
*vertex_dest
,
567 const struct isis_vertex
*vertex
)
569 struct isis_spftree
*spftree_old
= spftree_pc
->lfa
.old
.spftree
;
570 struct isis_vertex_adj
*vadj
;
571 struct listnode
*node
;
573 /* Check the local P-space first. */
574 if (isis_spf_node_find(&spftree_pc
->lfa
.p_space
, vertex
->N
.id
))
578 * Check the P-space of the adjacent routers used to reach the
581 for (ALL_LIST_ELEMENTS_RO(vertex_dest
->Adj_N
, node
, vadj
)) {
582 struct isis_spf_adj
*sadj
= vadj
->sadj
;
583 struct isis_spf_node
*adj_node
;
586 isis_spf_node_find(&spftree_old
->adj_nodes
, sadj
->id
);
590 if (isis_spf_node_find(&adj_node
->lfa
.p_space
, vertex
->N
.id
))
597 /* Check if a node belongs to the Q-space. */
598 static bool lfa_q_space_check(const struct isis_spftree
*spftree_pc
,
599 const struct isis_vertex
*vertex
)
601 return isis_spf_node_find(&spftree_pc
->lfa
.q_space
, vertex
->N
.id
);
604 /* This is a recursive function. */
605 static int tilfa_build_repair_list(struct isis_spftree
*spftree_pc
,
606 struct isis_vertex
*vertex_dest
,
607 const struct isis_vertex
*vertex
,
608 const struct isis_vertex
*vertex_child
,
609 struct isis_spf_nodes
*used_pnodes
,
610 struct list
*repair_list
)
612 struct isis_vertex
*pvertex
;
613 struct listnode
*node
;
614 bool is_pnode
, is_qnode
;
615 char buf
[VID2STR_BUFFER
];
616 struct isis_tilfa_sid sid_dest
= {}, sid_qnode
= {}, sid_pnode
= {};
618 mpls_label_t label_qnode
;
621 vid2string(vertex
, buf
, sizeof(buf
));
622 zlog_debug("ISIS-LFA: vertex %s %s", vtype2string(vertex
->type
),
626 /* Push original Prefix-SID label when necessary. */
627 if (VTYPE_IP(vertex
->type
) && vertex
->N
.ip
.sr
.present
) {
628 pvertex
= listnode_head(vertex
->parents
);
631 sid_index
= vertex
->N
.ip
.sr
.sid
.value
;
634 "ISIS-LFA: pushing Prefix-SID to %pFX (index %u)",
635 &vertex
->N
.ip
.p
.dest
, sid_index
);
636 sid_dest
.type
= TILFA_SID_PREFIX
;
637 sid_dest
.value
.index
.value
= sid_index
;
638 sid_dest
.value
.index
.remote
= true;
639 memcpy(sid_dest
.value
.index
.remote_sysid
, pvertex
->N
.id
,
640 sizeof(sid_dest
.value
.index
.remote_sysid
));
641 listnode_add_head(repair_list
, &sid_dest
);
646 if (vertex
->type
!= VTYPE_NONPSEUDO_IS
647 && vertex
->type
!= VTYPE_NONPSEUDO_TE_IS
)
649 if (!VTYPE_IS(vertex_child
->type
))
652 /* Check if node is part of the extended P-space and/or Q-space. */
653 is_pnode
= lfa_ext_p_space_check(spftree_pc
, vertex_dest
, vertex
);
654 is_qnode
= lfa_q_space_check(spftree_pc
, vertex
);
656 /* Push Adj-SID label when necessary. */
658 || spftree_pc
->lfa
.protected_resource
.type
== LFA_NODE_PROTECTION
)
661 * If vertex is the penultimate hop router, then pushing an
662 * Adj-SID towards the final hop means that the No-PHP flag of
663 * the original Prefix-SID must be honored. We do that by
664 * removing the previously added Prefix-SID from the repair list
665 * when those conditions are met.
667 if (vertex
->depth
== (vertex_dest
->depth
- 2)
668 && VTYPE_IP(vertex_dest
->type
)
669 && vertex_dest
->N
.ip
.sr
.present
670 && !CHECK_FLAG(vertex_dest
->N
.ip
.sr
.sid
.flags
,
671 ISIS_PREFIX_SID_NO_PHP
)) {
672 list_delete_all_node(repair_list
);
675 label_qnode
= tilfa_find_qnode_adj_sid(spftree_pc
, vertex
->N
.id
,
677 if (label_qnode
== MPLS_INVALID_LABEL
) {
678 zlog_warn("ISIS-LFA: failed to find %s->%s Adj-SID",
679 print_sys_hostname(vertex
->N
.id
),
680 print_sys_hostname(vertex_child
->N
.id
));
685 "ISIS-LFA: pushing %s->%s Adj-SID (label %u)",
686 print_sys_hostname(vertex
->N
.id
),
687 print_sys_hostname(vertex_child
->N
.id
),
689 sid_qnode
.type
= TILFA_SID_ADJ
;
690 sid_qnode
.value
.label
= label_qnode
;
691 listnode_add_head(repair_list
, &sid_qnode
);
694 /* Push Prefix-SID label when necessary. */
696 /* The same P-node can't be used more than once. */
697 if (isis_spf_node_find(used_pnodes
, vertex
->N
.id
)) {
700 "ISIS-LFA: skipping already used P-node");
703 isis_spf_node_new(used_pnodes
, vertex
->N
.id
);
708 "ISIS-LFA: destination is within Ext-P-Space");
713 tilfa_find_pnode_prefix_sid(spftree_pc
, vertex
->N
.id
);
714 if (sid_index
== UINT32_MAX
) {
716 "ISIS-LFA: failed to find Prefix-SID corresponding to PQ-node %s",
717 print_sys_hostname(vertex
->N
.id
));
723 "ISIS-LFA: pushing Node-SID to %s (index %u)",
724 print_sys_hostname(vertex
->N
.id
), sid_index
);
725 sid_pnode
.type
= TILFA_SID_PREFIX
;
726 sid_pnode
.value
.index
.value
= sid_index
;
727 listnode_add_head(repair_list
, &sid_pnode
);
729 /* Apply repair list. */
730 if (spftree_pc
->area
->srdb
.config
.msd
731 && listcount(repair_list
)
732 > spftree_pc
->area
->srdb
.config
.msd
) {
734 "ISIS-LFA: list of repair segments exceeds locally configured MSD (%u > %u)",
735 listcount(repair_list
),
736 spftree_pc
->area
->srdb
.config
.msd
);
739 if (tilfa_repair_list_apply(spftree_pc
, vertex_dest
, vertex
,
747 for (ALL_LIST_ELEMENTS_RO(vertex
->parents
, node
, pvertex
)) {
748 struct list
*repair_list_parent
;
752 ecmp
= (listcount(vertex
->parents
) > 1) ? true : false;
753 repair_list_parent
= ecmp
? list_dup(repair_list
) : repair_list
;
754 ret
= tilfa_build_repair_list(spftree_pc
, vertex_dest
, pvertex
,
758 list_delete(&repair_list_parent
);
766 static const char *lfa_protection_type2str(enum lfa_protection_type type
)
769 case LFA_LINK_PROTECTION
:
770 return "link protection";
771 case LFA_NODE_PROTECTION
:
772 return "node protection";
774 return "unknown protection type";
779 lfa_protected_resource2str(const struct lfa_protected_resource
*resource
)
781 const uint8_t *fail_id
;
782 static char buffer
[128];
784 fail_id
= resource
->adjacency
;
785 snprintf(buffer
, sizeof(buffer
), "%s.%u's failure (%s)",
786 print_sys_hostname(fail_id
), LSP_PSEUDO_ID(fail_id
),
787 lfa_protection_type2str(resource
->type
));
793 spf_adj_check_is_affected(const struct isis_spf_adj
*sadj
,
794 const struct lfa_protected_resource
*resource
,
795 const uint8_t *root_sysid
, bool reverse
)
797 if (!!CHECK_FLAG(sadj
->flags
, F_ISIS_SPF_ADJ_BROADCAST
)
798 != !!LSP_PSEUDO_ID(resource
->adjacency
))
801 if (CHECK_FLAG(sadj
->flags
, F_ISIS_SPF_ADJ_BROADCAST
)) {
802 if (!memcmp(sadj
->lan
.desig_is_id
, resource
->adjacency
,
803 ISIS_SYS_ID_LEN
+ 1))
807 && !memcmp(sadj
->id
, resource
->adjacency
, ISIS_SYS_ID_LEN
))
809 if (reverse
&& !memcmp(sadj
->id
, root_sysid
, ISIS_SYS_ID_LEN
))
816 /* Check if the given vertex is affected by a given local failure. */
818 spf_vertex_check_is_affected(const struct isis_vertex
*vertex
,
819 const uint8_t *root_sysid
,
820 const struct lfa_protected_resource
*resource
)
822 struct isis_vertex_adj
*vadj
;
823 struct listnode
*node
;
824 size_t affected_nhs
= 0;
826 /* Local routes don't need protection. */
827 if (VTYPE_IP(vertex
->type
) && vertex
->depth
== 1)
830 for (ALL_LIST_ELEMENTS_RO(vertex
->Adj_N
, node
, vadj
)) {
831 struct isis_spf_adj
*sadj
= vadj
->sadj
;
833 if (spf_adj_check_is_affected(sadj
, resource
, root_sysid
,
839 * No need to compute backup paths for ECMP routes, except if all
840 * primary nexthops share the same broadcast interface.
842 if (listcount(vertex
->Adj_N
) == affected_nhs
)
848 /* Check if a given RLFA/TI-LFA post-convergence SPF vertex needs protection. */
849 static bool lfa_check_needs_protection(const struct isis_spftree
*spftree_pc
,
850 const struct isis_vertex
*vertex
)
852 struct isis_vertex
*vertex_old
;
854 /* Only local adjacencies need TI-LFA Adj-SID protection. */
855 if (spftree_pc
->type
== SPF_TYPE_TI_LFA
&& VTYPE_IS(vertex
->type
)
856 && !isis_adj_find(spftree_pc
->area
, spftree_pc
->level
,
860 vertex_old
= isis_find_vertex(&spftree_pc
->lfa
.old
.spftree
->paths
,
861 &vertex
->N
, vertex
->type
);
865 /* Skip vertex if it's already protected by local LFA. */
866 if (CHECK_FLAG(vertex_old
->flags
, F_ISIS_VERTEX_LFA_PROTECTED
))
869 return spf_vertex_check_is_affected(
870 vertex_old
, spftree_pc
->sysid
,
871 &spftree_pc
->lfa
.protected_resource
);
875 * Check if the given SPF vertex needs protection and, if so, compute and
876 * install the corresponding repair paths.
878 * @param spftree_pc The post-convergence SPF tree
879 * @param vertex IS-IS SPF vertex to check
881 * @return 0 if the vertex needs to be protected, -1 otherwise
883 int isis_tilfa_check(struct isis_spftree
*spftree_pc
,
884 struct isis_vertex
*vertex
)
886 struct isis_spf_nodes used_pnodes
;
887 char buf
[VID2STR_BUFFER
];
888 struct list
*repair_list
;
891 if (!spftree_pc
->area
->srdb
.enabled
)
894 if (!lfa_check_needs_protection(spftree_pc
, vertex
)) {
897 "ISIS-LFA: %s %s unaffected by %s",
898 vtype2string(vertex
->type
),
899 vid2string(vertex
, buf
, sizeof(buf
)),
900 lfa_protected_resource2str(
901 &spftree_pc
->lfa
.protected_resource
));
907 * Check if the route/adjacency was already covered by node protection.
909 if (VTYPE_IS(vertex
->type
)) {
910 struct isis_adjacency
*adj
;
912 adj
= isis_adj_find(spftree_pc
->area
, spftree_pc
->level
,
915 && isis_sr_adj_sid_find(adj
, spftree_pc
->family
,
916 ISIS_SR_LAN_BACKUP
)) {
919 "ISIS-LFA: %s %s already covered by node protection",
920 vtype2string(vertex
->type
),
921 vid2string(vertex
, buf
, sizeof(buf
)));
926 if (VTYPE_IP(vertex
->type
)) {
927 struct route_table
*route_table
;
929 route_table
= spftree_pc
->lfa
.old
.spftree
->route_table_backup
;
930 if (route_node_lookup(route_table
, &vertex
->N
.ip
.p
.dest
)) {
933 "ISIS-LFA: %s %s already covered by node protection",
934 vtype2string(vertex
->type
),
935 vid2string(vertex
, buf
, sizeof(buf
)));
943 "ISIS-LFA: computing repair path(s) of %s %s w.r.t %s",
944 vtype2string(vertex
->type
),
945 vid2string(vertex
, buf
, sizeof(buf
)),
946 lfa_protected_resource2str(
947 &spftree_pc
->lfa
.protected_resource
));
949 /* Create base repair list. */
950 repair_list
= list_new();
952 isis_spf_node_list_init(&used_pnodes
);
953 ret
= tilfa_build_repair_list(spftree_pc
, vertex
, vertex
, NULL
,
954 &used_pnodes
, repair_list
);
955 isis_spf_node_list_clear(&used_pnodes
);
956 list_delete(&repair_list
);
959 "ISIS-LFA: failed to compute repair path(s) of %s %s w.r.t %s",
960 vtype2string(vertex
->type
),
961 vid2string(vertex
, buf
, sizeof(buf
)),
962 lfa_protected_resource2str(
963 &spftree_pc
->lfa
.protected_resource
));
969 spf_adj_node_is_affected(struct isis_spf_node
*adj_node
,
970 const struct lfa_protected_resource
*resource
,
971 const uint8_t *root_sysid
)
973 struct isis_spf_adj
*sadj
;
974 struct listnode
*node
;
976 for (ALL_LIST_ELEMENTS_RO(adj_node
->adjacencies
, node
, sadj
)) {
977 if (sadj
->metric
!= adj_node
->best_metric
)
979 if (spf_adj_check_is_affected(sadj
, resource
, root_sysid
,
987 static bool vertex_is_affected(struct isis_spftree
*spftree_root
,
988 const struct isis_spf_nodes
*adj_nodes
,
989 bool p_space
, const struct isis_vertex
*vertex
,
990 const struct lfa_protected_resource
*resource
)
992 struct isis_vertex
*pvertex
;
993 struct listnode
*node
, *vnode
;
995 for (ALL_LIST_ELEMENTS_RO(vertex
->parents
, node
, pvertex
)) {
996 struct isis_spftree
*spftree_parent
;
997 struct isis_vertex
*vertex_child
;
998 struct isis_vertex_adj
*vadj
;
999 bool reverse
= false;
1001 if (p_space
&& resource
->type
== LFA_NODE_PROTECTION
) {
1002 if (isis_spf_node_find(&resource
->nodes
, vertex
->N
.id
))
1007 /* Check if either the vertex or its parent is the root node. */
1008 if (memcmp(vertex
->N
.id
, spftree_root
->sysid
, ISIS_SYS_ID_LEN
)
1009 && memcmp(pvertex
->N
.id
, spftree_root
->sysid
,
1013 /* Get SPT of the parent vertex. */
1014 if (!memcmp(pvertex
->N
.id
, spftree_root
->sysid
,
1016 spftree_parent
= spftree_root
;
1018 struct isis_spf_node
*adj_node
;
1020 adj_node
= isis_spf_node_find(adj_nodes
, pvertex
->N
.id
);
1022 spftree_parent
= adj_node
->lfa
.spftree
;
1023 assert(spftree_parent
);
1027 /* Get paths pvertex uses to reach vertex. */
1028 vertex_child
= isis_find_vertex(&spftree_parent
->paths
,
1029 &vertex
->N
, vertex
->type
);
1033 /* Check if any of these paths use the protected resource. */
1034 for (ALL_LIST_ELEMENTS_RO(vertex_child
->Adj_N
, vnode
, vadj
))
1035 if (spf_adj_check_is_affected(vadj
->sadj
, resource
,
1036 spftree_root
->sysid
,
1041 if (vertex_is_affected(spftree_root
, adj_nodes
, p_space
,
1049 /* Calculate set of nodes reachable without using the protected interface. */
1050 static void lfa_calc_reach_nodes(struct isis_spftree
*spftree
,
1051 struct isis_spftree
*spftree_root
,
1052 const struct isis_spf_nodes
*adj_nodes
,
1054 const struct lfa_protected_resource
*resource
,
1055 struct isis_spf_nodes
*nodes
)
1057 struct isis_vertex
*vertex
;
1058 struct listnode
*node
;
1060 for (ALL_QUEUE_ELEMENTS_RO(&spftree
->paths
, node
, vertex
)) {
1061 char buf
[VID2STR_BUFFER
];
1063 if (!VTYPE_IS(vertex
->type
))
1066 /* Skip root node. */
1067 if (!memcmp(vertex
->N
.id
, spftree_root
->sysid
, ISIS_SYS_ID_LEN
))
1070 /* Don't add the same node twice. */
1071 if (isis_spf_node_find(nodes
, vertex
->N
.id
))
1074 if (!vertex_is_affected(spftree_root
, adj_nodes
, p_space
,
1075 vertex
, resource
)) {
1078 "ISIS-LFA: adding %s",
1079 vid2string(vertex
, buf
, sizeof(buf
)));
1081 isis_spf_node_new(nodes
, vertex
->N
.id
);
1087 * Helper function used to create an SPF tree structure and run reverse SPF on
1090 * @param spftree IS-IS SPF tree
1092 * @return Pointer to new SPF tree structure.
1094 struct isis_spftree
*isis_spf_reverse_run(const struct isis_spftree
*spftree
)
1096 struct isis_spftree
*spftree_reverse
;
1098 spftree_reverse
= isis_spftree_new(
1099 spftree
->area
, spftree
->lspdb
, spftree
->sysid
, spftree
->level
,
1100 spftree
->tree_id
, SPF_TYPE_REVERSE
,
1101 F_SPFTREE_NO_ADJACENCIES
| F_SPFTREE_NO_ROUTES
);
1102 isis_run_spf(spftree_reverse
);
1104 return spftree_reverse
;
1108 * Calculate the Extended P-space and Q-space associated to a given link
1111 static void lfa_calc_pq_spaces(struct isis_spftree
*spftree_pc
,
1112 const struct lfa_protected_resource
*resource
)
1114 struct isis_spftree
*spftree
;
1115 struct isis_spftree
*spftree_reverse
;
1116 struct isis_spf_nodes
*adj_nodes
;
1117 struct isis_spf_node
*adj_node
;
1119 /* Obtain pre-failure SPTs and list of adjacent nodes. */
1120 spftree
= spftree_pc
->lfa
.old
.spftree
;
1121 spftree_reverse
= spftree_pc
->lfa
.old
.spftree_reverse
;
1122 adj_nodes
= &spftree
->adj_nodes
;
1125 zlog_debug("ISIS-LFA: computing P-space (self)");
1126 lfa_calc_reach_nodes(spftree
, spftree
, adj_nodes
, true, resource
,
1127 &spftree_pc
->lfa
.p_space
);
1129 RB_FOREACH (adj_node
, isis_spf_nodes
, adj_nodes
) {
1130 if (spf_adj_node_is_affected(adj_node
, resource
,
1133 zlog_debug("ISIS-LFA: computing Q-space (%s)",
1134 print_sys_hostname(adj_node
->sysid
));
1137 * Compute the reverse SPF in the behalf of the node
1138 * adjacent to the failure, if we haven't done that
1141 if (!adj_node
->lfa
.spftree_reverse
)
1142 adj_node
->lfa
.spftree_reverse
=
1143 isis_spf_reverse_run(
1144 adj_node
->lfa
.spftree
);
1146 lfa_calc_reach_nodes(adj_node
->lfa
.spftree_reverse
,
1147 spftree_reverse
, adj_nodes
, false,
1149 &spftree_pc
->lfa
.q_space
);
1152 zlog_debug("ISIS-LFA: computing P-space (%s)",
1153 print_sys_hostname(adj_node
->sysid
));
1154 lfa_calc_reach_nodes(adj_node
->lfa
.spftree
, spftree
,
1155 adj_nodes
, true, resource
,
1156 &adj_node
->lfa
.p_space
);
1162 * Compute the TI-LFA backup paths for a given protected interface.
1164 * @param area IS-IS area
1165 * @param spftree IS-IS SPF tree
1166 * @param spftree_reverse IS-IS Reverse SPF tree
1167 * @param resource Protected resource
1169 * @return Pointer to the post-convergence SPF tree
1171 struct isis_spftree
*isis_tilfa_compute(struct isis_area
*area
,
1172 struct isis_spftree
*spftree
,
1173 struct isis_spftree
*spftree_reverse
,
1174 struct lfa_protected_resource
*resource
)
1176 struct isis_spftree
*spftree_pc
;
1177 struct isis_spf_node
*adj_node
;
1180 zlog_debug("ISIS-LFA: computing TI-LFAs for %s",
1181 lfa_protected_resource2str(resource
));
1183 /* Populate list of nodes affected by link failure. */
1184 if (resource
->type
== LFA_NODE_PROTECTION
) {
1185 isis_spf_node_list_init(&resource
->nodes
);
1186 RB_FOREACH (adj_node
, isis_spf_nodes
, &spftree
->adj_nodes
) {
1187 if (spf_adj_node_is_affected(adj_node
, resource
,
1189 isis_spf_node_new(&resource
->nodes
,
1194 /* Create post-convergence SPF tree. */
1195 spftree_pc
= isis_spftree_new(area
, spftree
->lspdb
, spftree
->sysid
,
1196 spftree
->level
, spftree
->tree_id
,
1197 SPF_TYPE_TI_LFA
, spftree
->flags
);
1198 spftree_pc
->lfa
.old
.spftree
= spftree
;
1199 spftree_pc
->lfa
.old
.spftree_reverse
= spftree_reverse
;
1200 spftree_pc
->lfa
.protected_resource
= *resource
;
1202 /* Compute the extended P-space and Q-space. */
1203 lfa_calc_pq_spaces(spftree_pc
, resource
);
1207 "ISIS-LFA: computing the post convergence SPT w.r.t. %s",
1208 lfa_protected_resource2str(resource
));
1210 /* Re-run SPF in the local node to find the post-convergence paths. */
1211 isis_run_spf(spftree_pc
);
1213 /* Clear list of nodes affeted by link failure. */
1214 if (resource
->type
== LFA_NODE_PROTECTION
)
1215 isis_spf_node_list_clear(&resource
->nodes
);
1221 * Run forward SPF on all adjacent routers.
1223 * @param spftree IS-IS SPF tree
1225 * @return 0 on success, -1 otherwise
1227 int isis_spf_run_neighbors(struct isis_spftree
*spftree
)
1229 struct isis_lsp
*lsp
;
1230 struct isis_spf_node
*adj_node
;
1232 lsp
= isis_root_system_lsp(spftree
->lspdb
, spftree
->sysid
);
1236 RB_FOREACH (adj_node
, isis_spf_nodes
, &spftree
->adj_nodes
) {
1238 zlog_debug("ISIS-LFA: running SPF on neighbor %s",
1239 print_sys_hostname(adj_node
->sysid
));
1241 /* Compute the SPT on behalf of the neighbor. */
1242 adj_node
->lfa
.spftree
= isis_spftree_new(
1243 spftree
->area
, spftree
->lspdb
, adj_node
->sysid
,
1244 spftree
->level
, spftree
->tree_id
, SPF_TYPE_FORWARD
,
1245 F_SPFTREE_NO_ADJACENCIES
| F_SPFTREE_NO_ROUTES
);
1246 isis_run_spf(adj_node
->lfa
.spftree
);
1252 /* Find Router ID of PQ node. */
1253 static struct in_addr
*rlfa_pq_node_rtr_id(struct isis_spftree
*spftree
,
1254 const struct isis_vertex
*vertex_pq
)
1256 struct isis_lsp
*lsp
;
1258 lsp
= isis_root_system_lsp(spftree
->lspdb
, vertex_pq
->N
.id
);
1262 if (lsp
->tlvs
->router_cap
->router_id
.s_addr
== INADDR_ANY
)
1265 return &lsp
->tlvs
->router_cap
->router_id
;
1268 /* Find PQ node by intersecting the P/Q spaces. This is a recursive function. */
1269 static const struct in_addr
*
1270 rlfa_find_pq_node(struct isis_spftree
*spftree_pc
,
1271 struct isis_vertex
*vertex_dest
,
1272 const struct isis_vertex
*vertex
,
1273 const struct isis_vertex
*vertex_child
)
1275 struct isis_area
*area
= spftree_pc
->area
;
1276 int level
= spftree_pc
->level
;
1277 struct isis_vertex
*pvertex
;
1278 struct listnode
*node
;
1279 bool is_pnode
, is_qnode
;
1283 if (vertex
->type
!= VTYPE_NONPSEUDO_IS
1284 && vertex
->type
!= VTYPE_NONPSEUDO_TE_IS
)
1286 if (!VTYPE_IS(vertex_child
->type
))
1287 vertex_child
= NULL
;
1289 /* Check if node is part of the extended P-space and/or Q-space. */
1290 is_pnode
= lfa_ext_p_space_check(spftree_pc
, vertex_dest
, vertex
);
1291 is_qnode
= lfa_q_space_check(spftree_pc
, vertex
);
1293 if (is_pnode
&& is_qnode
) {
1294 const struct in_addr
*rtr_id_pq
;
1295 uint32_t max_metric
;
1296 struct prefix_list
*plist
= NULL
;
1298 rtr_id_pq
= rlfa_pq_node_rtr_id(spftree_pc
, vertex
);
1301 char buf
[VID2STR_BUFFER
];
1303 vid2string(vertex
, buf
, sizeof(buf
));
1305 "ISIS-LFA: tentative PQ node (%s %s) doesn't have a router-ID",
1306 vtype2string(vertex
->type
), buf
);
1311 max_metric
= spftree_pc
->lfa
.remote
.max_metric
;
1312 if (max_metric
&& vertex
->d_N
> max_metric
) {
1315 "ISIS-LFA: skipping PQ node %pI4 (maximum metric)",
1320 plist
= area
->rlfa_plist
[level
- 1];
1325 p
.prefixlen
= IPV4_MAX_BITLEN
;
1326 p
.u
.prefix4
= *rtr_id_pq
;
1327 if (prefix_list_apply(plist
, &p
) == PREFIX_DENY
) {
1330 "ISIS-LFA: PQ node %pI4 filtered by prefix-list",
1337 zlog_debug("ISIS-LFA: found PQ node: %pI4", rtr_id_pq
);
1343 for (ALL_LIST_ELEMENTS_RO(vertex
->parents
, node
, pvertex
)) {
1344 const struct in_addr
*rtr_id_pq
;
1346 rtr_id_pq
= rlfa_find_pq_node(spftree_pc
, vertex_dest
, pvertex
,
1355 int rlfa_cmp(const struct rlfa
*a
, const struct rlfa
*b
)
1357 return prefix_cmp(&a
->prefix
, &b
->prefix
);
1360 static struct rlfa
*rlfa_add(struct isis_spftree
*spftree
,
1361 struct isis_vertex
*vertex
,
1362 struct in_addr pq_address
)
1366 assert(VTYPE_IP(vertex
->type
));
1367 rlfa
= XCALLOC(MTYPE_ISIS_RLFA
, sizeof(*rlfa
));
1368 rlfa
->prefix
= vertex
->N
.ip
.p
.dest
;
1369 rlfa
->vertex
= vertex
;
1370 rlfa
->pq_address
= pq_address
;
1371 rlfa_tree_add(&spftree
->lfa
.remote
.rlfas
, rlfa
);
1376 static void rlfa_delete(struct isis_spftree
*spftree
, struct rlfa
*rlfa
)
1378 rlfa_tree_del(&spftree
->lfa
.remote
.rlfas
, rlfa
);
1379 XFREE(MTYPE_ISIS_RLFA
, rlfa
);
1382 static struct rlfa
*rlfa_lookup(struct isis_spftree
*spftree
,
1383 union prefixconstptr pu
)
1388 return rlfa_tree_find(&spftree
->lfa
.remote
.rlfas
, &s
);
1391 static void isis_area_verify_routes_cb(struct thread
*thread
)
1393 struct isis_area
*area
= THREAD_ARG(thread
);
1396 zlog_debug("ISIS-LFA: updating RLFAs in the RIB");
1398 isis_area_verify_routes(area
);
1401 static mpls_label_t
rlfa_nexthop_label(struct isis_spftree
*spftree
,
1402 struct isis_vertex_adj
*vadj
,
1403 struct zapi_rlfa_response
*response
)
1405 struct isis_spf_adj
*sadj
= vadj
->sadj
;
1406 struct isis_adjacency
*adj
= sadj
->adj
;
1409 * Special case to make unit tests work (use implicit-null labels
1410 * instead of artifical ones).
1412 if (CHECK_FLAG(spftree
->flags
, F_SPFTREE_NO_ADJACENCIES
))
1413 return MPLS_LABEL_IMPLICIT_NULL
;
1415 for (unsigned int i
= 0; i
< response
->nexthop_num
; i
++) {
1416 switch (response
->nexthops
[i
].family
) {
1418 for (unsigned int j
= 0; j
< adj
->ipv4_address_count
;
1420 struct in_addr addr
= adj
->ipv4_addresses
[j
];
1422 if (!IPV4_ADDR_SAME(
1424 &response
->nexthops
[i
].gate
.ipv4
))
1427 return response
->nexthops
[i
].label
;
1431 for (unsigned int j
= 0; j
< adj
->ll_ipv6_count
; j
++) {
1432 struct in6_addr addr
= adj
->ll_ipv6_addrs
[j
];
1434 if (!IPV6_ADDR_SAME(
1436 &response
->nexthops
[i
].gate
.ipv6
))
1439 return response
->nexthops
[i
].label
;
1448 return MPLS_INVALID_LABEL
;
1451 int isis_rlfa_activate(struct isis_spftree
*spftree
, struct rlfa
*rlfa
,
1452 struct zapi_rlfa_response
*response
)
1454 struct isis_area
*area
= spftree
->area
;
1455 struct isis_vertex
*vertex
= rlfa
->vertex
;
1456 struct isis_vertex_adj
*vadj
;
1457 struct listnode
*node
;
1459 for (ALL_LIST_ELEMENTS_RO(vertex
->Adj_N
, node
, vadj
)) {
1460 mpls_label_t ldp_label
;
1461 struct mpls_label_stack
*label_stack
;
1462 size_t num_labels
= 0;
1465 ldp_label
= rlfa_nexthop_label(spftree
, vadj
, response
);
1466 if (ldp_label
== MPLS_INVALID_LABEL
) {
1469 "ISIS-LFA: failed to activate RLFA: missing LDP label to reach PQ node through %s",
1470 sysid_print(vadj
->sadj
->id
));
1474 if (ldp_label
!= MPLS_LABEL_IMPLICIT_NULL
)
1476 if (response
->pq_label
!= MPLS_LABEL_IMPLICIT_NULL
)
1478 if (vadj
->sr
.present
1479 && vadj
->sr
.label
!= MPLS_LABEL_IMPLICIT_NULL
)
1482 /* Allocate label stack. */
1484 XCALLOC(MTYPE_ISIS_NEXTHOP_LABELS
,
1485 sizeof(struct mpls_label_stack
)
1486 + num_labels
* sizeof(mpls_label_t
));
1487 label_stack
->num_labels
= num_labels
;
1489 /* Push label allocated by the nexthop (outer label). */
1490 if (ldp_label
!= MPLS_LABEL_IMPLICIT_NULL
)
1491 label_stack
->label
[i
++] = ldp_label
;
1492 /* Push label allocated by the PQ node (inner label). */
1493 if (response
->pq_label
!= MPLS_LABEL_IMPLICIT_NULL
)
1494 label_stack
->label
[i
++] = response
->pq_label
;
1495 /* Preserve the original Prefix-SID label when it's present. */
1496 if (vadj
->sr
.present
1497 && vadj
->sr
.label
!= MPLS_LABEL_IMPLICIT_NULL
)
1498 label_stack
->label
[i
++] = vadj
->sr
.label
;
1500 vadj
->label_stack
= label_stack
;
1503 isis_route_create(&vertex
->N
.ip
.p
.dest
, &vertex
->N
.ip
.p
.src
,
1504 vertex
->d_N
, vertex
->depth
, &vertex
->N
.ip
.sr
,
1505 vertex
->Adj_N
, true, area
,
1506 spftree
->route_table_backup
);
1507 spftree
->lfa
.protection_counters
.rlfa
[vertex
->N
.ip
.priority
] += 1;
1509 THREAD_OFF(area
->t_rlfa_rib_update
);
1510 thread_add_timer(master
, isis_area_verify_routes_cb
, area
, 2,
1511 &area
->t_rlfa_rib_update
);
1516 void isis_rlfa_deactivate(struct isis_spftree
*spftree
, struct rlfa
*rlfa
)
1518 struct isis_area
*area
= spftree
->area
;
1519 struct isis_vertex
*vertex
= rlfa
->vertex
;
1520 struct route_node
*rn
;
1522 rn
= route_node_lookup(spftree
->route_table_backup
, &rlfa
->prefix
);
1525 isis_route_delete(area
, rn
, spftree
->route_table_backup
);
1526 spftree
->lfa
.protection_counters
.rlfa
[vertex
->N
.ip
.priority
] -= 1;
1528 THREAD_OFF(area
->t_rlfa_rib_update
);
1529 thread_add_timer(master
, isis_area_verify_routes_cb
, area
, 2,
1530 &area
->t_rlfa_rib_update
);
1533 void isis_rlfa_list_init(struct isis_spftree
*spftree
)
1535 rlfa_tree_init(&spftree
->lfa
.remote
.rlfas
);
1538 void isis_rlfa_list_clear(struct isis_spftree
*spftree
)
1540 while (rlfa_tree_count(&spftree
->lfa
.remote
.rlfas
) > 0) {
1543 rlfa
= rlfa_tree_first(&spftree
->lfa
.remote
.rlfas
);
1544 isis_rlfa_deactivate(spftree
, rlfa
);
1545 rlfa_delete(spftree
, rlfa
);
1549 void isis_rlfa_process_ldp_response(struct zapi_rlfa_response
*response
)
1552 struct isis_area
*area
;
1553 struct isis_spftree
*spftree
;
1555 enum spf_tree_id tree_id
;
1556 uint32_t spf_run_id
;
1559 if (response
->igp
.protocol
!= ZEBRA_ROUTE_ISIS
)
1562 isis
= isis_lookup_by_vrfid(response
->igp
.vrf_id
);
1566 area
= isis_area_lookup(response
->igp
.isis
.area_tag
,
1567 response
->igp
.vrf_id
);
1571 tree_id
= response
->igp
.isis
.spf
.tree_id
;
1572 if (tree_id
!= SPFTREE_IPV4
&& tree_id
!= SPFTREE_IPV6
) {
1573 zlog_warn("ISIS-LFA: invalid SPF tree ID received from LDP");
1577 level
= response
->igp
.isis
.spf
.level
;
1578 if (level
!= ISIS_LEVEL1
&& level
!= ISIS_LEVEL2
) {
1579 zlog_warn("ISIS-LFA: invalid IS-IS level received from LDP");
1583 spf_run_id
= response
->igp
.isis
.spf
.run_id
;
1584 spftree
= area
->spftree
[tree_id
][level
- 1];
1585 if (spftree
->runcount
!= spf_run_id
)
1586 /* Outdated RLFA, ignore... */
1589 rlfa
= rlfa_lookup(spftree
, &response
->destination
);
1592 "ISIS-LFA: couldn't find Remote-LFA %pFX received from LDP",
1593 &response
->destination
);
1597 if (response
->pq_label
!= MPLS_INVALID_LABEL
) {
1600 "ISIS-LFA: activating/updating RLFA for %pFX",
1603 if (isis_rlfa_activate(spftree
, rlfa
, response
) != 0)
1604 isis_rlfa_deactivate(spftree
, rlfa
);
1607 zlog_debug("ISIS-LFA: deactivating RLFA for %pFX",
1610 isis_rlfa_deactivate(spftree
, rlfa
);
1614 void isis_ldp_rlfa_handle_client_close(struct zapi_client_close_info
*info
)
1616 struct isis
*isis
= isis_lookup_by_vrfid(VRF_DEFAULT
);
1617 struct isis_area
*area
;
1618 struct listnode
*node
;
1623 /* Check if the LDP main client session closed */
1624 if (info
->proto
!= ZEBRA_ROUTE_LDP
|| info
->session_id
== 0)
1628 zlog_debug("ISIS-LFA: LDP is down, deactivating all RLFAs");
1630 for (ALL_LIST_ELEMENTS_RO(isis
->area_list
, node
, area
)) {
1631 for (int tree
= SPFTREE_IPV4
; tree
< SPFTREE_COUNT
; tree
++) {
1632 for (int level
= ISIS_LEVEL1
; level
<= ISIS_LEVELS
;
1634 struct isis_spftree
*spftree
;
1636 if (!(area
->is_type
& level
))
1638 if (!area
->spftree
[tree
][level
- 1])
1641 spftree
= area
->spftree
[tree
][level
- 1];
1642 isis_rlfa_list_clear(spftree
);
1649 * Check if the given SPF vertex needs protection and, if so, attempt to
1650 * compute a Remote LFA for it.
1652 * @param spftree_pc The post-convergence SPF tree
1653 * @param vertex IS-IS SPF vertex to check
1655 void isis_rlfa_check(struct isis_spftree
*spftree_pc
,
1656 struct isis_vertex
*vertex
)
1658 struct isis_spftree
*spftree_old
= spftree_pc
->lfa
.old
.spftree
;
1660 const struct in_addr
*rtr_id_pq
;
1661 char buf
[VID2STR_BUFFER
];
1663 if (!lfa_check_needs_protection(spftree_pc
, vertex
)) {
1666 "ISIS-LFA: %s %s unaffected by %s",
1667 vtype2string(vertex
->type
),
1668 vid2string(vertex
, buf
, sizeof(buf
)),
1669 lfa_protected_resource2str(
1670 &spftree_pc
->lfa
.protected_resource
));
1677 "ISIS-LFA: computing repair path(s) of %s %s w.r.t %s",
1678 vtype2string(vertex
->type
),
1679 vid2string(vertex
, buf
, sizeof(buf
)),
1680 lfa_protected_resource2str(
1681 &spftree_pc
->lfa
.protected_resource
));
1684 rtr_id_pq
= rlfa_find_pq_node(spftree_pc
, vertex
, vertex
, NULL
);
1687 zlog_debug("ISIS-LFA: no acceptable PQ node found");
1691 /* Store valid RLFA and store LDP label for the PQ node. */
1692 rlfa
= rlfa_add(spftree_old
, vertex
, *rtr_id_pq
);
1694 /* Register RLFA with LDP. */
1695 if (isis_zebra_rlfa_register(spftree_old
, rlfa
) != 0)
1696 rlfa_delete(spftree_old
, rlfa
);
1700 * Compute the Remote LFA backup paths for a given protected interface.
1702 * @param area IS-IS area
1703 * @param spftree IS-IS SPF tree
1704 * @param spftree_reverse IS-IS Reverse SPF tree
1705 * @param max_metric Remote LFA maximum metric
1706 * @param resource Protected resource
1708 * @return Pointer to the post-convergence SPF tree
1710 struct isis_spftree
*isis_rlfa_compute(struct isis_area
*area
,
1711 struct isis_spftree
*spftree
,
1712 struct isis_spftree
*spftree_reverse
,
1713 uint32_t max_metric
,
1714 struct lfa_protected_resource
*resource
)
1716 struct isis_spftree
*spftree_pc
;
1719 zlog_debug("ISIS-LFA: computing remote LFAs for %s",
1720 lfa_protected_resource2str(resource
));
1722 /* Create post-convergence SPF tree. */
1723 spftree_pc
= isis_spftree_new(area
, spftree
->lspdb
, spftree
->sysid
,
1724 spftree
->level
, spftree
->tree_id
,
1725 SPF_TYPE_RLFA
, spftree
->flags
);
1726 spftree_pc
->lfa
.old
.spftree
= spftree
;
1727 spftree_pc
->lfa
.old
.spftree_reverse
= spftree_reverse
;
1728 spftree_pc
->lfa
.remote
.max_metric
= max_metric
;
1729 spftree_pc
->lfa
.protected_resource
= *resource
;
1731 /* Compute the extended P-space and Q-space. */
1732 lfa_calc_pq_spaces(spftree_pc
, resource
);
1736 "ISIS-LFA: computing the post convergence SPT w.r.t. %s",
1737 lfa_protected_resource2str(resource
));
1739 /* Re-run SPF in the local node to find the post-convergence paths. */
1740 isis_run_spf(spftree_pc
);
1745 /* Calculate the distance from the root node to the given IP destination. */
1746 static int lfa_calc_dist_destination(struct isis_spftree
*spftree
,
1747 const struct isis_vertex
*vertex_N
,
1750 struct isis_vertex
*vertex
, *vertex_best
= NULL
;
1752 switch (spftree
->family
) {
1754 for (int vtype
= VTYPE_IPREACH_INTERNAL
;
1755 vtype
<= VTYPE_IPREACH_TE
; vtype
++) {
1756 vertex
= isis_find_vertex(
1757 &spftree
->paths
, &vertex_N
->N
.ip
.p
.dest
, vtype
);
1761 /* Pick vertex with the best metric. */
1762 if (!vertex_best
|| vertex_best
->d_N
> vertex
->d_N
)
1763 vertex_best
= vertex
;
1767 for (int vtype
= VTYPE_IP6REACH_INTERNAL
;
1768 vtype
<= VTYPE_IP6REACH_EXTERNAL
; vtype
++) {
1769 vertex
= isis_find_vertex(
1770 &spftree
->paths
, &vertex_N
->N
.ip
.p
.dest
, vtype
);
1774 /* Pick vertex with the best metric. */
1775 if (!vertex_best
|| vertex_best
->d_N
> vertex
->d_N
)
1776 vertex_best
= vertex
;
1786 assert(VTYPE_IP(vertex_best
->type
));
1787 vertex_best
= listnode_head(vertex_best
->parents
);
1788 *distance
= vertex_best
->d_N
;
1793 /* Calculate the distance from the root node to the given node. */
1794 static int lfa_calc_dist_node(struct isis_spftree
*spftree
,
1795 const uint8_t *sysid
, uint32_t *distance
)
1797 struct isis_vertex
*vertex
, *vertex_best
= NULL
;
1799 for (int vtype
= VTYPE_PSEUDO_IS
; vtype
<= VTYPE_NONPSEUDO_TE_IS
;
1801 vertex
= isis_find_vertex(&spftree
->paths
, sysid
, vtype
);
1805 /* Pick vertex with the best metric. */
1806 if (!vertex_best
|| vertex_best
->d_N
> vertex
->d_N
)
1807 vertex_best
= vertex
;
1813 *distance
= vertex_best
->d_N
;
1819 * Check loop-free criterion (RFC 5286's inequality 1):
1820 * - Dist_opt(N, D) < Dist_opt(N, S) + Dist_opt(S, D)
1822 static bool clfa_loop_free_check(struct isis_spftree
*spftree
,
1823 struct isis_vertex
*vertex_S_D
,
1824 struct isis_spf_adj
*sadj_primary
,
1825 struct isis_spf_adj
*sadj_N
,
1826 uint32_t *path_metric
)
1828 struct isis_spf_node
*node_N
;
1833 node_N
= isis_spf_node_find(&spftree
->adj_nodes
, sadj_N
->id
);
1836 /* Distance from N to D. */
1837 if (lfa_calc_dist_destination(node_N
->lfa
.spftree
, vertex_S_D
,
1842 /* Distance from N to S (or PN). */
1843 if (CHECK_FLAG(sadj_primary
->flags
, F_ISIS_SPF_ADJ_BROADCAST
)) {
1844 static uint8_t pn_sysid
[ISIS_SYS_ID_LEN
+ 1];
1846 memcpy(pn_sysid
, sadj_primary
->id
, ISIS_SYS_ID_LEN
+ 1);
1847 if (lfa_calc_dist_node(node_N
->lfa
.spftree
, pn_sysid
, &dist_N_S
)
1851 static uint8_t root_sysid
[ISIS_SYS_ID_LEN
+ 1];
1853 memcpy(root_sysid
, spftree
->sysid
, ISIS_SYS_ID_LEN
);
1854 LSP_PSEUDO_ID(root_sysid
) = 0;
1855 if (lfa_calc_dist_node(node_N
->lfa
.spftree
, root_sysid
,
1861 /* Distance from S (or PN) to D. */
1862 vertex_S_D
= listnode_head(vertex_S_D
->parents
);
1863 dist_S_D
= vertex_S_D
->d_N
;
1864 if (CHECK_FLAG(sadj_primary
->flags
, F_ISIS_SPF_ADJ_BROADCAST
))
1865 dist_S_D
-= sadj_primary
->metric
;
1868 zlog_debug("ISIS-LFA: loop-free check: %u < %u + %u", dist_N_D
,
1869 dist_N_S
, dist_S_D
);
1871 if (dist_N_D
< (dist_N_S
+ dist_S_D
)) {
1872 *path_metric
= sadj_N
->metric
+ dist_N_D
;
1880 * Check loop-free criterion (RFC 5286's inequality 2):
1881 * - Distance_opt(N, D) < Distance_opt(S, D)
1883 static bool clfa_downstream_check(struct isis_spftree
*spftree
,
1884 struct isis_vertex
*vertex_S_D
,
1885 struct isis_spf_adj
*sadj_N
)
1887 struct isis_spf_node
*node_N
;
1891 node_N
= isis_spf_node_find(&spftree
->adj_nodes
, sadj_N
->id
);
1894 /* Distance from N to D. */
1895 if (lfa_calc_dist_destination(node_N
->lfa
.spftree
, vertex_S_D
,
1900 /* Distance from S (or PN) to D. */
1901 vertex_S_D
= listnode_head(vertex_S_D
->parents
);
1902 dist_S_D
= vertex_S_D
->d_N
;
1905 zlog_debug("ISIS-LFA: downstream check: %u < %u", dist_N_D
,
1908 if (dist_N_D
< dist_S_D
)
1915 * Check loop-free criterion (RFC 5286's inequality 3):
1916 * - Dist_opt(N, D) < Dist_opt(N, E) + Dist_opt(E, D)
1918 static bool clfa_node_protecting_check(struct isis_spftree
*spftree
,
1919 struct isis_vertex
*vertex_S_D
,
1920 struct isis_spf_adj
*sadj_N
,
1921 struct isis_spf_adj
*sadj_E
)
1923 struct isis_spf_node
*node_N
, *node_E
;
1928 node_N
= isis_spf_node_find(&spftree
->adj_nodes
, sadj_N
->id
);
1930 node_E
= isis_spf_node_find(&spftree
->adj_nodes
, sadj_E
->id
);
1933 /* Distance from N to D. */
1934 if (lfa_calc_dist_destination(node_N
->lfa
.spftree
, vertex_S_D
,
1939 /* Distance from N to E. */
1940 if (lfa_calc_dist_node(node_N
->lfa
.spftree
, node_E
->sysid
, &dist_N_E
)
1944 /* Distance from E to D. */
1945 if (lfa_calc_dist_destination(node_E
->lfa
.spftree
, vertex_S_D
,
1951 zlog_debug("ISIS-LFA: node protecting check: %u < %u + %u",
1952 dist_N_D
, dist_N_E
, dist_E_D
);
1954 return (dist_N_D
< (dist_N_E
+ dist_E_D
));
1957 static struct list
*
1958 isis_lfa_tiebreakers(struct isis_area
*area
, struct isis_spftree
*spftree
,
1959 struct lfa_protected_resource
*resource
,
1960 struct isis_vertex
*vertex
,
1961 struct isis_spf_adj
*sadj_primary
, struct list
*lfa_list
)
1963 struct lfa_tiebreaker
*tie_b
;
1964 int level
= spftree
->level
;
1965 struct list
*filtered_lfa_list
;
1966 struct list
*tent_lfa_list
;
1968 filtered_lfa_list
= list_dup(lfa_list
);
1969 filtered_lfa_list
->del
= NULL
;
1971 if (listcount(filtered_lfa_list
) == 1)
1972 return filtered_lfa_list
;
1974 /* Check tiebreakers in ascending order by index. */
1975 frr_each (lfa_tiebreaker_tree
, &area
->lfa_tiebreakers
[level
- 1],
1977 struct isis_vertex_adj
*lfa
;
1978 struct listnode
*node
, *nnode
;
1979 uint32_t best_metric
= UINT32_MAX
;
1981 tent_lfa_list
= list_dup(filtered_lfa_list
);
1983 switch (tie_b
->type
) {
1984 case LFA_TIEBREAKER_DOWNSTREAM
:
1985 for (ALL_LIST_ELEMENTS(tent_lfa_list
, node
, nnode
,
1987 if (clfa_downstream_check(spftree
, vertex
,
1993 "ISIS-LFA: LFA %s doesn't satisfy the downstream condition",
1996 listnode_delete(tent_lfa_list
, lfa
);
1999 case LFA_TIEBREAKER_LOWEST_METRIC
:
2000 /* Find the best metric first. */
2001 for (ALL_LIST_ELEMENTS_RO(tent_lfa_list
, node
, lfa
)) {
2002 if (lfa
->lfa_metric
< best_metric
)
2003 best_metric
= lfa
->lfa_metric
;
2006 /* Remove LFAs that don't have the best metric. */
2007 for (ALL_LIST_ELEMENTS(tent_lfa_list
, node
, nnode
,
2009 if (lfa
->lfa_metric
== best_metric
)
2014 "ISIS-LFA: LFA %s doesn't have the lowest cost metric",
2017 listnode_delete(tent_lfa_list
, lfa
);
2020 case LFA_TIEBREAKER_NODE_PROTECTING
:
2021 for (ALL_LIST_ELEMENTS(tent_lfa_list
, node
, nnode
,
2023 if (clfa_node_protecting_check(spftree
, vertex
,
2030 "ISIS-LFA: LFA %s doesn't provide node protection",
2033 listnode_delete(tent_lfa_list
, lfa
);
2039 * Decide what to do next based on the number of remaining LFAs.
2041 switch (listcount(tent_lfa_list
)) {
2044 * Ignore this tie-breaker since it excluded all LFAs.
2045 * Move on to the next one (if any).
2047 list_delete(&tent_lfa_list
);
2050 /* Finish tie-breaking once we get a single LFA. */
2051 list_delete(&filtered_lfa_list
);
2052 filtered_lfa_list
= tent_lfa_list
;
2053 return filtered_lfa_list
;
2056 * We still have two or more LFAs. Move on to the next
2057 * tie-breaker (if any).
2059 list_delete(&filtered_lfa_list
);
2060 filtered_lfa_list
= tent_lfa_list
;
2065 return filtered_lfa_list
;
2068 void isis_lfa_compute(struct isis_area
*area
, struct isis_circuit
*circuit
,
2069 struct isis_spftree
*spftree
,
2070 struct lfa_protected_resource
*resource
)
2072 struct isis_vertex
*vertex
, *parent_vertex
;
2073 struct listnode
*vnode
, *snode
;
2074 int level
= spftree
->level
;
2076 resource
->type
= LFA_LINK_PROTECTION
;
2079 zlog_debug("ISIS-LFA: computing local LFAs for %s",
2080 lfa_protected_resource2str(resource
));
2082 for (ALL_QUEUE_ELEMENTS_RO(&spftree
->paths
, vnode
, vertex
)) {
2083 struct list
*lfa_list
;
2084 struct list
*filtered_lfa_list
;
2085 struct isis_spf_adj
*sadj_N
;
2086 struct isis_vertex_adj
*vadj_primary
;
2087 struct isis_spf_adj
*sadj_primary
;
2089 uint32_t prefix_metric
, best_metric
= UINT32_MAX
;
2090 char buf
[VID2STR_BUFFER
];
2092 if (!VTYPE_IP(vertex
->type
))
2095 vid2string(vertex
, buf
, sizeof(buf
));
2097 if (!spf_vertex_check_is_affected(vertex
, spftree
->sysid
,
2101 "ISIS-LFA: %s %s unaffected by %s",
2102 vtype2string(vertex
->type
), buf
,
2103 lfa_protected_resource2str(resource
));
2108 zlog_debug("ISIS-LFA: checking %s %s w.r.t %s",
2109 vtype2string(vertex
->type
), buf
,
2110 lfa_protected_resource2str(resource
));
2112 if (vertex
->N
.ip
.priority
2113 > area
->lfa_priority_limit
[level
- 1]) {
2116 "ISIS-LFA: skipping computing LFAs due to low prefix priority");
2120 vadj_primary
= listnode_head(vertex
->Adj_N
);
2121 sadj_primary
= vadj_primary
->sadj
;
2123 parent_vertex
= listnode_head(vertex
->parents
);
2124 prefix_metric
= vertex
->d_N
- parent_vertex
->d_N
;
2127 * Loop over list of SPF adjacencies and compute a list of
2130 lfa_list
= list_new();
2131 lfa_list
->del
= isis_vertex_adj_free
;
2132 for (ALL_LIST_ELEMENTS_RO(spftree
->sadj_list
, snode
, sadj_N
)) {
2133 uint32_t lfa_metric
, path_metric
;
2134 struct isis_vertex_adj
*lfa
;
2135 struct isis_prefix_sid
*psid
= NULL
;
2136 bool last_hop
= false;
2138 /* Skip pseudonodes. */
2139 if (LSP_PSEUDO_ID(sadj_N
->id
))
2143 * Skip nexthops that are along a link whose cost is
2146 if (CHECK_FLAG(sadj_N
->flags
,
2147 F_ISIS_SPF_ADJ_METRIC_INFINITY
))
2150 /* Skip nexthops that have the overload bit set. */
2151 if (spftree
->mtid
!= ISIS_MT_IPV4_UNICAST
) {
2152 struct isis_mt_router_info
*mt_router_info
;
2155 isis_tlvs_lookup_mt_router_info(
2158 if (mt_router_info
&& mt_router_info
->overload
)
2160 } else if (ISIS_MASK_LSP_OL_BIT(
2161 sadj_N
->lsp
->hdr
.lsp_bits
))
2164 /* Skip primary nexthop. */
2165 if (spf_adj_check_is_affected(sadj_N
, resource
, NULL
,
2169 /* Skip excluded interfaces as per the configuration. */
2171 && isis_lfa_excluded_iface_check(
2173 sadj_N
->adj
->circuit
->interface
->name
))
2178 "ISIS-LFA: checking candidate LFA %s",
2179 print_sys_hostname(sadj_N
->id
));
2181 /* Check loop-free criterion. */
2182 if (!clfa_loop_free_check(spftree
, vertex
, sadj_primary
,
2183 sadj_N
, &path_metric
)) {
2186 "ISIS-LFA: LFA condition not met for %s",
2187 print_sys_hostname(sadj_N
->id
));
2191 lfa_metric
= path_metric
+ prefix_metric
;
2192 if (lfa_metric
< best_metric
)
2193 best_metric
= lfa_metric
;
2197 "ISIS-LFA: %s is a valid loop-free alternate",
2198 print_sys_hostname(sadj_N
->id
));
2200 if (vertex
->N
.ip
.sr
.present
) {
2201 psid
= &vertex
->N
.ip
.sr
.sid
;
2202 if (path_metric
== sadj_N
->metric
)
2205 lfa
= isis_vertex_adj_add(spftree
, vertex
, lfa_list
,
2206 sadj_N
, psid
, last_hop
);
2207 lfa
->lfa_metric
= lfa_metric
;
2210 if (list_isempty(lfa_list
)) {
2213 "ISIS-LFA: no valid local LFAs found");
2214 list_delete(&lfa_list
);
2218 SET_FLAG(vertex
->flags
, F_ISIS_VERTEX_LFA_PROTECTED
);
2220 /* Check tie-breakers. */
2222 isis_lfa_tiebreakers(area
, spftree
, resource
, vertex
,
2223 sadj_primary
, lfa_list
);
2225 /* Create backup route using the best LFAs. */
2226 allow_ecmp
= area
->lfa_load_sharing
[level
- 1];
2227 isis_route_create(&vertex
->N
.ip
.p
.dest
, &vertex
->N
.ip
.p
.src
,
2228 best_metric
, vertex
->depth
, &vertex
->N
.ip
.sr
,
2229 filtered_lfa_list
, allow_ecmp
, area
,
2230 spftree
->route_table_backup
);
2231 spftree
->lfa
.protection_counters
.lfa
[vertex
->N
.ip
.priority
] +=
2234 list_delete(&filtered_lfa_list
);
2235 list_delete(&lfa_list
);
2239 static void isis_spf_run_tilfa(struct isis_area
*area
,
2240 struct isis_circuit
*circuit
,
2241 struct isis_spftree
*spftree
,
2242 struct isis_spftree
*spftree_reverse
,
2243 struct lfa_protected_resource
*resource
)
2245 struct isis_spftree
*spftree_pc_link
;
2246 struct isis_spftree
*spftree_pc_node
;
2248 /* Compute node protecting repair paths first (if necessary). */
2249 if (circuit
->tilfa_node_protection
[spftree
->level
- 1]) {
2250 resource
->type
= LFA_NODE_PROTECTION
;
2251 spftree_pc_node
= isis_tilfa_compute(area
, spftree
,
2252 spftree_reverse
, resource
);
2253 isis_spftree_del(spftree_pc_node
);
2255 /* don't do link protection unless link-fallback is configured
2257 if (!circuit
->tilfa_link_fallback
[spftree
->level
- 1])
2261 /* Compute link protecting repair paths. */
2262 resource
->type
= LFA_LINK_PROTECTION
;
2264 isis_tilfa_compute(area
, spftree
, spftree_reverse
, resource
);
2265 isis_spftree_del(spftree_pc_link
);
2269 * Run the LFA/RLFA/TI-LFA algorithms for all protected interfaces.
2271 * @param area IS-IS area
2272 * @param spftree IS-IS SPF tree
2274 void isis_spf_run_lfa(struct isis_area
*area
, struct isis_spftree
*spftree
)
2276 struct isis_spftree
*spftree_reverse
= NULL
;
2277 struct isis_circuit
*circuit
;
2278 struct listnode
*node
;
2279 int level
= spftree
->level
;
2281 /* Run reverse SPF locally. */
2282 if (area
->rlfa_protected_links
[level
- 1] > 0
2283 || area
->tilfa_protected_links
[level
- 1] > 0)
2284 spftree_reverse
= isis_spf_reverse_run(spftree
);
2286 /* Run forward SPF on all adjacent routers. */
2287 isis_spf_run_neighbors(spftree
);
2289 /* Check which interfaces are protected. */
2290 for (ALL_LIST_ELEMENTS_RO(area
->circuit_list
, node
, circuit
)) {
2291 struct lfa_protected_resource resource
= {};
2292 struct isis_adjacency
*adj
;
2293 static uint8_t null_sysid
[ISIS_SYS_ID_LEN
+ 1];
2295 if (!(circuit
->is_type
& level
))
2298 if (!circuit
->lfa_protection
[level
- 1]
2299 && !circuit
->tilfa_protection
[level
- 1])
2302 /* Fill in the protected resource. */
2303 switch (circuit
->circ_type
) {
2304 case CIRCUIT_T_BROADCAST
:
2305 if (level
== ISIS_LEVEL1
)
2306 memcpy(resource
.adjacency
,
2307 circuit
->u
.bc
.l1_desig_is
,
2308 ISIS_SYS_ID_LEN
+ 1);
2310 memcpy(resource
.adjacency
,
2311 circuit
->u
.bc
.l2_desig_is
,
2312 ISIS_SYS_ID_LEN
+ 1);
2313 /* Do nothing if no DR was elected yet. */
2314 if (!memcmp(resource
.adjacency
, null_sysid
,
2315 ISIS_SYS_ID_LEN
+ 1))
2319 adj
= circuit
->u
.p2p
.neighbor
;
2322 memcpy(resource
.adjacency
, adj
->sysid
, ISIS_SYS_ID_LEN
);
2323 LSP_PSEUDO_ID(resource
.adjacency
) = 0;
2329 if (circuit
->lfa_protection
[level
- 1]) {
2330 /* Run local LFA. */
2331 isis_lfa_compute(area
, circuit
, spftree
, &resource
);
2333 if (circuit
->rlfa_protection
[level
- 1]) {
2334 struct isis_spftree
*spftree_pc
;
2335 uint32_t max_metric
;
2337 /* Run remote LFA. */
2338 assert(spftree_reverse
);
2340 circuit
->rlfa_max_metric
[level
- 1];
2341 spftree_pc
= isis_rlfa_compute(
2342 area
, spftree
, spftree_reverse
,
2343 max_metric
, &resource
);
2344 listnode_add(spftree
->lfa
.remote
.pc_spftrees
,
2347 } else if (circuit
->tilfa_protection
[level
- 1]) {
2349 assert(spftree_reverse
);
2350 isis_spf_run_tilfa(area
, circuit
, spftree
,
2351 spftree_reverse
, &resource
);
2355 if (spftree_reverse
)
2356 isis_spftree_del(spftree_reverse
);