2 * Copyright (C) 2013 Cumulus Networks, Inc.
4 * This file is part of GNU Zebra.
6 * GNU Zebra is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
11 * GNU Zebra is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29 #include "sockunion.h"
32 #include "workqueue.h"
39 #include "zebra/rib.h"
41 #include "zebra/interface.h"
42 #include "zebra/zserv.h"
43 #include "zebra/zebra_router.h"
44 #include "zebra/redistribute.h"
45 #include "zebra/debug.h"
46 #include "zebra/zebra_memory.h"
47 #include "zebra/zebra_vrf.h"
48 #include "zebra/zebra_mpls.h"
49 #include "zebra/zebra_errors.h"
51 DEFINE_MTYPE_STATIC(ZEBRA
, LSP
, "MPLS LSP object")
52 DEFINE_MTYPE_STATIC(ZEBRA
, FEC
, "MPLS FEC object")
53 DEFINE_MTYPE_STATIC(ZEBRA
, SLSP
, "MPLS static LSP config")
54 DEFINE_MTYPE_STATIC(ZEBRA
, NHLFE
, "MPLS nexthop object")
55 DEFINE_MTYPE_STATIC(ZEBRA
, SNHLFE
, "MPLS static nexthop object")
56 DEFINE_MTYPE_STATIC(ZEBRA
, SNHLFE_IFNAME
, "MPLS static nexthop ifname")
60 /* static function declarations */
62 static void fec_evaluate(struct zebra_vrf
*zvrf
);
63 static uint32_t fec_derive_label_from_index(struct zebra_vrf
*vrf
,
65 static int lsp_install(struct zebra_vrf
*zvrf
, mpls_label_t label
,
66 struct route_node
*rn
, struct route_entry
*re
);
67 static int lsp_uninstall(struct zebra_vrf
*zvrf
, mpls_label_t label
);
68 static int fec_change_update_lsp(struct zebra_vrf
*zvrf
, zebra_fec_t
*fec
,
69 mpls_label_t old_label
);
70 static int fec_send(zebra_fec_t
*fec
, struct zserv
*client
);
71 static void fec_update_clients(zebra_fec_t
*fec
);
72 static void fec_print(zebra_fec_t
*fec
, struct vty
*vty
);
73 static zebra_fec_t
*fec_find(struct route_table
*table
, struct prefix
*p
);
74 static zebra_fec_t
*fec_add(struct route_table
*table
, struct prefix
*p
,
75 mpls_label_t label
, uint32_t flags
,
76 uint32_t label_index
);
77 static int fec_del(zebra_fec_t
*fec
);
79 static unsigned int label_hash(void *p
);
80 static bool label_cmp(const void *p1
, const void *p2
);
81 static int nhlfe_nexthop_active_ipv4(zebra_nhlfe_t
*nhlfe
,
82 struct nexthop
*nexthop
);
83 static int nhlfe_nexthop_active_ipv6(zebra_nhlfe_t
*nhlfe
,
84 struct nexthop
*nexthop
);
85 static int nhlfe_nexthop_active(zebra_nhlfe_t
*nhlfe
);
87 static void lsp_select_best_nhlfe(zebra_lsp_t
*lsp
);
88 static void lsp_uninstall_from_kernel(struct hash_backet
*backet
, void *ctxt
);
89 static void lsp_schedule(struct hash_backet
*backet
, void *ctxt
);
90 static wq_item_status
lsp_process(struct work_queue
*wq
, void *data
);
91 static void lsp_processq_del(struct work_queue
*wq
, void *data
);
92 static void lsp_processq_complete(struct work_queue
*wq
);
93 static int lsp_processq_add(zebra_lsp_t
*lsp
);
94 static void *lsp_alloc(void *p
);
96 static char *nhlfe2str(zebra_nhlfe_t
*nhlfe
, char *buf
, int size
);
97 static int nhlfe_nhop_match(zebra_nhlfe_t
*nhlfe
, enum nexthop_types_t gtype
,
98 union g_addr
*gate
, ifindex_t ifindex
);
99 static zebra_nhlfe_t
*nhlfe_find(zebra_lsp_t
*lsp
, enum lsp_types_t lsp_type
,
100 enum nexthop_types_t gtype
, union g_addr
*gate
,
102 static zebra_nhlfe_t
*nhlfe_add(zebra_lsp_t
*lsp
, enum lsp_types_t lsp_type
,
103 enum nexthop_types_t gtype
, union g_addr
*gate
,
104 ifindex_t ifindex
, mpls_label_t out_label
);
105 static int nhlfe_del(zebra_nhlfe_t
*snhlfe
);
106 static void nhlfe_out_label_update(zebra_nhlfe_t
*nhlfe
,
107 struct mpls_label_stack
*nh_label
);
108 static int mpls_lsp_uninstall_all(struct hash
*lsp_table
, zebra_lsp_t
*lsp
,
109 enum lsp_types_t type
);
110 static int mpls_static_lsp_uninstall_all(struct zebra_vrf
*zvrf
,
111 mpls_label_t in_label
);
112 static void nhlfe_print(zebra_nhlfe_t
*nhlfe
, struct vty
*vty
);
113 static void lsp_print(zebra_lsp_t
*lsp
, void *ctxt
);
114 static void *slsp_alloc(void *p
);
115 static int snhlfe_match(zebra_snhlfe_t
*snhlfe
, enum nexthop_types_t gtype
,
116 union g_addr
*gate
, ifindex_t ifindex
);
117 static zebra_snhlfe_t
*snhlfe_find(zebra_slsp_t
*slsp
,
118 enum nexthop_types_t gtype
,
119 union g_addr
*gate
, ifindex_t ifindex
);
120 static zebra_snhlfe_t
*snhlfe_add(zebra_slsp_t
*slsp
,
121 enum nexthop_types_t gtype
,
122 union g_addr
*gate
, ifindex_t ifindex
,
123 mpls_label_t out_label
);
124 static int snhlfe_del(zebra_snhlfe_t
*snhlfe
);
125 static int snhlfe_del_all(zebra_slsp_t
*slsp
);
126 static char *snhlfe2str(zebra_snhlfe_t
*snhlfe
, char *buf
, int size
);
129 /* Static functions */
132 * Handle failure in LSP install, clear flags for NHLFE.
134 static void clear_nhlfe_installed(zebra_lsp_t
*lsp
)
136 zebra_nhlfe_t
*nhlfe
;
137 struct nexthop
*nexthop
;
139 for (nhlfe
= lsp
->nhlfe_list
; nhlfe
; nhlfe
= nhlfe
->next
) {
140 nexthop
= nhlfe
->nexthop
;
144 UNSET_FLAG(nhlfe
->flags
, NHLFE_FLAG_INSTALLED
);
145 UNSET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_FIB
);
150 * Install label forwarding entry based on labeled-route entry.
152 static int lsp_install(struct zebra_vrf
*zvrf
, mpls_label_t label
,
153 struct route_node
*rn
, struct route_entry
*re
)
155 struct hash
*lsp_table
;
158 zebra_nhlfe_t
*nhlfe
;
159 struct nexthop
*nexthop
;
160 enum lsp_types_t lsp_type
;
165 lsp_table
= zvrf
->lsp_table
;
169 lsp_type
= lsp_type_from_re_type(re
->type
);
172 /* Locate or allocate LSP entry. */
173 tmp_ile
.in_label
= label
;
174 lsp
= hash_get(lsp_table
, &tmp_ile
, lsp_alloc
);
178 /* For each active nexthop, create NHLFE. Note that we deliberately skip
179 * recursive nexthops right now, because intermediate hops won't
181 * the label advertised by the recursive nexthop (plus we don't have the
182 * logic yet to push multiple labels).
184 for (nexthop
= re
->ng
.nexthop
; nexthop
; nexthop
= nexthop
->next
) {
185 /* Skip inactive and recursive entries. */
186 if (!CHECK_FLAG(nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
))
188 if (CHECK_FLAG(nexthop
->flags
, NEXTHOP_FLAG_RECURSIVE
))
191 nhlfe
= nhlfe_find(lsp
, lsp_type
, nexthop
->type
, &nexthop
->gate
,
194 /* Clear deleted flag (in case it was set) */
195 UNSET_FLAG(nhlfe
->flags
, NHLFE_FLAG_DELETED
);
196 if (nexthop_labels_match(nhlfe
->nexthop
, nexthop
))
201 if (IS_ZEBRA_DEBUG_MPLS
) {
202 nhlfe2str(nhlfe
, buf
, BUFSIZ
);
204 "LSP in-label %u type %d nexthop %s "
206 lsp
->ile
.in_label
, lsp_type
, buf
);
209 /* Update out label, trigger processing. */
210 nhlfe_out_label_update(nhlfe
, nexthop
->nh_label
);
211 SET_FLAG(nhlfe
->flags
, NHLFE_FLAG_CHANGED
);
214 /* Add LSP entry to this nexthop */
215 nhlfe
= nhlfe_add(lsp
, lsp_type
, nexthop
->type
,
216 &nexthop
->gate
, nexthop
->ifindex
,
217 nexthop
->nh_label
->label
[0]);
221 if (IS_ZEBRA_DEBUG_MPLS
) {
222 nhlfe2str(nhlfe
, buf
, BUFSIZ
);
224 "Add LSP in-label %u type %d nexthop %s "
226 lsp
->ile
.in_label
, lsp_type
, buf
,
227 nexthop
->nh_label
->label
[0]);
230 lsp
->addr_family
= NHLFE_FAMILY(nhlfe
);
232 /* Mark NHLFE as changed. */
233 SET_FLAG(nhlfe
->flags
, NHLFE_FLAG_CHANGED
);
238 /* Queue LSP for processing if necessary. If no NHLFE got added (special
239 * case), delete the LSP entry; this case results in somewhat ugly
242 if (added
|| changed
) {
243 if (lsp_processq_add(lsp
))
245 } else if (!lsp
->nhlfe_list
246 && !CHECK_FLAG(lsp
->flags
, LSP_FLAG_SCHEDULED
)) {
247 if (IS_ZEBRA_DEBUG_MPLS
)
248 zlog_debug("Free LSP in-label %u flags 0x%x",
249 lsp
->ile
.in_label
, lsp
->flags
);
251 lsp
= hash_release(lsp_table
, &lsp
->ile
);
253 XFREE(MTYPE_LSP
, lsp
);
260 * Uninstall all non-static NHLFEs of a label forwarding entry. If all
261 * NHLFEs are removed, the entire entry is deleted.
263 static int lsp_uninstall(struct zebra_vrf
*zvrf
, mpls_label_t label
)
265 struct hash
*lsp_table
;
268 zebra_nhlfe_t
*nhlfe
, *nhlfe_next
;
272 lsp_table
= zvrf
->lsp_table
;
276 /* If entry is not present, exit. */
277 tmp_ile
.in_label
= label
;
278 lsp
= hash_lookup(lsp_table
, &tmp_ile
);
279 if (!lsp
|| !lsp
->nhlfe_list
)
282 /* Mark NHLFEs for delete or directly delete, as appropriate. */
283 for (nhlfe
= lsp
->nhlfe_list
; nhlfe
; nhlfe
= nhlfe_next
) {
284 nhlfe_next
= nhlfe
->next
;
286 /* Skip static NHLFEs */
287 if (nhlfe
->type
== ZEBRA_LSP_STATIC
)
290 if (IS_ZEBRA_DEBUG_MPLS
) {
291 nhlfe2str(nhlfe
, buf
, BUFSIZ
);
293 "Del LSP in-label %u type %d nexthop %s flags 0x%x",
294 label
, nhlfe
->type
, buf
, nhlfe
->flags
);
297 if (CHECK_FLAG(nhlfe
->flags
, NHLFE_FLAG_SELECTED
)) {
298 UNSET_FLAG(nhlfe
->flags
, NHLFE_FLAG_CHANGED
);
299 SET_FLAG(nhlfe
->flags
, NHLFE_FLAG_DELETED
);
305 /* Queue LSP for processing, if needed, else delete. */
306 if (CHECK_FLAG(lsp
->flags
, LSP_FLAG_INSTALLED
)) {
307 if (lsp_processq_add(lsp
))
309 } else if (!lsp
->nhlfe_list
310 && !CHECK_FLAG(lsp
->flags
, LSP_FLAG_SCHEDULED
)) {
311 if (IS_ZEBRA_DEBUG_MPLS
)
312 zlog_debug("Del LSP in-label %u flags 0x%x",
313 lsp
->ile
.in_label
, lsp
->flags
);
315 lsp
= hash_release(lsp_table
, &lsp
->ile
);
317 XFREE(MTYPE_LSP
, lsp
);
324 * This function is invoked upon change to label block configuration; it
325 * will walk all registered FECs with label-index and appropriately update
326 * their local labels and trigger client updates.
328 static void fec_evaluate(struct zebra_vrf
*zvrf
)
330 struct route_node
*rn
;
332 uint32_t old_label
, new_label
;
336 for (af
= AFI_IP
; af
< AFI_MAX
; af
++) {
337 if (zvrf
->fec_table
[af
] == NULL
)
340 for (rn
= route_top(zvrf
->fec_table
[af
]); rn
;
341 rn
= route_next(rn
)) {
342 if ((fec
= rn
->info
) == NULL
)
345 /* Skip configured FECs and those without a label index.
347 if (fec
->flags
& FEC_FLAG_CONFIGURED
348 || fec
->label_index
== MPLS_INVALID_LABEL_INDEX
)
351 if (IS_ZEBRA_DEBUG_MPLS
)
352 prefix2str(&rn
->p
, buf
, BUFSIZ
);
354 /* Save old label, determine new label. */
355 old_label
= fec
->label
;
357 zvrf
->mpls_srgb
.start_label
+ fec
->label_index
;
358 if (new_label
>= zvrf
->mpls_srgb
.end_label
)
359 new_label
= MPLS_INVALID_LABEL
;
361 /* If label has changed, update FEC and clients. */
362 if (new_label
== old_label
)
365 if (IS_ZEBRA_DEBUG_MPLS
)
367 "Update fec %s new label %u upon label block",
370 fec
->label
= new_label
;
371 fec_update_clients(fec
);
373 /* Update label forwarding entries appropriately */
374 fec_change_update_lsp(zvrf
, fec
, old_label
);
380 * Derive (if possible) and update the local label for the FEC based on
381 * its label index. The index is "acceptable" if it falls within the
382 * globally configured label block (SRGB).
384 static uint32_t fec_derive_label_from_index(struct zebra_vrf
*zvrf
,
389 if (fec
->label_index
!= MPLS_INVALID_LABEL_INDEX
390 && zvrf
->mpls_srgb
.start_label
391 && ((label
= zvrf
->mpls_srgb
.start_label
+ fec
->label_index
)
392 < zvrf
->mpls_srgb
.end_label
))
395 fec
->label
= MPLS_INVALID_LABEL
;
401 * There is a change for this FEC. Install or uninstall label forwarding
402 * entries, as appropriate.
404 static int fec_change_update_lsp(struct zebra_vrf
*zvrf
, zebra_fec_t
*fec
,
405 mpls_label_t old_label
)
407 struct route_table
*table
;
408 struct route_node
*rn
;
409 struct route_entry
*re
;
412 /* Uninstall label forwarding entry, if previously installed. */
413 if (old_label
!= MPLS_INVALID_LABEL
414 && old_label
!= MPLS_LABEL_IMPLICIT_NULL
)
415 lsp_uninstall(zvrf
, old_label
);
417 /* Install label forwarding entry corr. to new label, if needed. */
418 if (fec
->label
== MPLS_INVALID_LABEL
419 || fec
->label
== MPLS_LABEL_IMPLICIT_NULL
)
422 afi
= family2afi(PREFIX_FAMILY(&fec
->rn
->p
));
423 table
= zebra_vrf_table(afi
, SAFI_UNICAST
, zvrf_id(zvrf
));
427 /* See if labeled route exists. */
428 rn
= route_node_lookup(table
, &fec
->rn
->p
);
432 RNODE_FOREACH_RE (rn
, re
) {
433 if (CHECK_FLAG(re
->flags
, ZEBRA_FLAG_SELECTED
))
437 if (!re
|| !zebra_rib_labeled_unicast(re
))
440 if (lsp_install(zvrf
, fec
->label
, rn
, re
))
447 * Inform about FEC to a registered client.
449 static int fec_send(zebra_fec_t
*fec
, struct zserv
*client
)
452 struct route_node
*rn
;
456 /* Get output stream. */
457 s
= stream_new(ZEBRA_MAX_PACKET_SIZ
);
459 zclient_create_header(s
, ZEBRA_FEC_UPDATE
, VRF_DEFAULT
);
461 stream_putw(s
, rn
->p
.family
);
462 stream_put_prefix(s
, &rn
->p
);
463 stream_putl(s
, fec
->label
);
464 stream_putw_at(s
, 0, stream_get_endp(s
));
465 return zserv_send_message(client
, s
);
469 * Update all registered clients about this FEC. Caller should've updated
470 * FEC and ensure no duplicate updates.
472 static void fec_update_clients(zebra_fec_t
*fec
)
474 struct listnode
*node
;
475 struct zserv
*client
;
477 for (ALL_LIST_ELEMENTS_RO(fec
->client_list
, node
, client
)) {
478 if (IS_ZEBRA_DEBUG_MPLS
)
479 zlog_debug("Update client %s",
480 zebra_route_string(client
->proto
));
481 fec_send(fec
, client
);
487 * Print a FEC-label binding entry.
489 static void fec_print(zebra_fec_t
*fec
, struct vty
*vty
)
491 struct route_node
*rn
;
492 struct listnode
*node
;
493 struct zserv
*client
;
497 prefix2str(&rn
->p
, buf
, BUFSIZ
);
498 vty_out(vty
, "%s\n", buf
);
499 vty_out(vty
, " Label: %s", label2str(fec
->label
, buf
, BUFSIZ
));
500 if (fec
->label_index
!= MPLS_INVALID_LABEL_INDEX
)
501 vty_out(vty
, ", Label Index: %u", fec
->label_index
);
503 if (!list_isempty(fec
->client_list
)) {
504 vty_out(vty
, " Client list:");
505 for (ALL_LIST_ELEMENTS_RO(fec
->client_list
, node
, client
))
506 vty_out(vty
, " %s(fd %d)",
507 zebra_route_string(client
->proto
),
514 * Locate FEC-label binding that matches with passed info.
516 static zebra_fec_t
*fec_find(struct route_table
*table
, struct prefix
*p
)
518 struct route_node
*rn
;
521 rn
= route_node_lookup(table
, p
);
525 route_unlock_node(rn
);
530 * Add a FEC. This may be upon a client registering for a binding
531 * or when a binding is configured.
533 static zebra_fec_t
*fec_add(struct route_table
*table
, struct prefix
*p
,
534 mpls_label_t label
, uint32_t flags
,
535 uint32_t label_index
)
537 struct route_node
*rn
;
542 /* Lookup (or add) route node.*/
543 rn
= route_node_get(table
, p
);
550 fec
= XCALLOC(MTYPE_FEC
, sizeof(zebra_fec_t
));
555 fec
->client_list
= list_new();
557 route_unlock_node(rn
); /* for the route_node_get */
559 fec
->label_index
= label_index
;
566 * Delete a FEC. This may be upon the last client deregistering for
567 * a FEC and no binding exists or when the binding is deleted and there
568 * are no registered clients.
570 static int fec_del(zebra_fec_t
*fec
)
572 list_delete(&fec
->client_list
);
573 fec
->rn
->info
= NULL
;
574 route_unlock_node(fec
->rn
);
575 XFREE(MTYPE_FEC
, fec
);
580 * Hash function for label.
582 static unsigned int label_hash(void *p
)
584 const zebra_ile_t
*ile
= p
;
586 return (jhash_1word(ile
->in_label
, 0));
590 * Compare 2 LSP hash entries based on in-label.
592 static bool label_cmp(const void *p1
, const void *p2
)
594 const zebra_ile_t
*ile1
= p1
;
595 const zebra_ile_t
*ile2
= p2
;
597 return (ile1
->in_label
== ile2
->in_label
);
601 * Check if an IPv4 nexthop for a NHLFE is active. Update nexthop based on
603 * NOTE: Looking only for connected routes right now.
605 static int nhlfe_nexthop_active_ipv4(zebra_nhlfe_t
*nhlfe
,
606 struct nexthop
*nexthop
)
608 struct route_table
*table
;
609 struct prefix_ipv4 p
;
610 struct route_node
*rn
;
611 struct route_entry
*match
;
612 struct nexthop
*match_nh
;
614 table
= zebra_vrf_table(AFI_IP
, SAFI_UNICAST
, nexthop
->vrf_id
);
618 /* Lookup nexthop in IPv4 routing table. */
619 memset(&p
, 0, sizeof(struct prefix_ipv4
));
621 p
.prefixlen
= IPV4_MAX_PREFIXLEN
;
622 p
.prefix
= nexthop
->gate
.ipv4
;
624 rn
= route_node_match(table
, (struct prefix
*)&p
);
628 route_unlock_node(rn
);
630 /* Locate a valid connected route. */
631 RNODE_FOREACH_RE (rn
, match
) {
632 if (CHECK_FLAG(match
->status
, ROUTE_ENTRY_REMOVED
)
633 || !CHECK_FLAG(match
->flags
, ZEBRA_FLAG_SELECTED
))
636 for (match_nh
= match
->ng
.nexthop
; match_nh
;
637 match_nh
= match_nh
->next
) {
638 if (match
->type
== ZEBRA_ROUTE_CONNECT
639 || nexthop
->ifindex
== match_nh
->ifindex
) {
640 nexthop
->ifindex
= match_nh
->ifindex
;
651 * Check if an IPv6 nexthop for a NHLFE is active. Update nexthop based on
653 * NOTE: Looking only for connected routes right now.
655 static int nhlfe_nexthop_active_ipv6(zebra_nhlfe_t
*nhlfe
,
656 struct nexthop
*nexthop
)
658 struct route_table
*table
;
659 struct prefix_ipv6 p
;
660 struct route_node
*rn
;
661 struct route_entry
*match
;
663 table
= zebra_vrf_table(AFI_IP6
, SAFI_UNICAST
, nexthop
->vrf_id
);
667 /* Lookup nexthop in IPv6 routing table. */
668 memset(&p
, 0, sizeof(struct prefix_ipv6
));
670 p
.prefixlen
= IPV6_MAX_PREFIXLEN
;
671 p
.prefix
= nexthop
->gate
.ipv6
;
673 rn
= route_node_match(table
, (struct prefix
*)&p
);
677 route_unlock_node(rn
);
679 /* Locate a valid connected route. */
680 RNODE_FOREACH_RE (rn
, match
) {
681 if ((match
->type
== ZEBRA_ROUTE_CONNECT
)
682 && !CHECK_FLAG(match
->status
, ROUTE_ENTRY_REMOVED
)
683 && CHECK_FLAG(match
->flags
, ZEBRA_FLAG_SELECTED
))
687 if (!match
|| !match
->ng
.nexthop
)
690 nexthop
->ifindex
= match
->ng
.nexthop
->ifindex
;
696 * Check the nexthop reachability for a NHLFE and return if valid (reachable)
698 * NOTE: Each NHLFE points to only 1 nexthop.
700 static int nhlfe_nexthop_active(zebra_nhlfe_t
*nhlfe
)
702 struct nexthop
*nexthop
;
703 struct interface
*ifp
;
704 struct zebra_ns
*zns
;
706 nexthop
= nhlfe
->nexthop
;
707 if (!nexthop
) // unexpected
710 /* Check on nexthop based on type. */
711 switch (nexthop
->type
) {
712 case NEXTHOP_TYPE_IFINDEX
:
714 * Lookup if this type is special. The
715 * NEXTHOP_TYPE_IFINDEX is a pop and
716 * forward into a different table for
717 * processing. As such this ifindex
718 * passed to us may be a VRF device
719 * which will not be in the default
720 * VRF. So let's look in all of them
722 zns
= zebra_ns_lookup(NS_DEFAULT
);
723 ifp
= if_lookup_by_index_per_ns(zns
, nexthop
->ifindex
);
724 if (ifp
&& if_is_operative(ifp
))
725 SET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
);
727 UNSET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
);
729 case NEXTHOP_TYPE_IPV4
:
730 case NEXTHOP_TYPE_IPV4_IFINDEX
:
731 if (nhlfe_nexthop_active_ipv4(nhlfe
, nexthop
))
732 SET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
);
734 UNSET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
);
737 case NEXTHOP_TYPE_IPV6
:
738 if (nhlfe_nexthop_active_ipv6(nhlfe
, nexthop
))
739 SET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
);
741 UNSET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
);
744 case NEXTHOP_TYPE_IPV6_IFINDEX
:
745 if (IN6_IS_ADDR_LINKLOCAL(&nexthop
->gate
.ipv6
)) {
746 ifp
= if_lookup_by_index(nexthop
->ifindex
,
748 if (ifp
&& if_is_operative(ifp
))
749 SET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
);
751 UNSET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
);
753 if (nhlfe_nexthop_active_ipv6(nhlfe
, nexthop
))
754 SET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
);
756 UNSET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
);
764 return CHECK_FLAG(nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
);
768 * Walk through NHLFEs for a LSP forwarding entry, verify nexthop
769 * reachability and select the best. Multipath entries are also
770 * marked. This is invoked when an LSP scheduled for processing (due
771 * to some change) is examined.
773 static void lsp_select_best_nhlfe(zebra_lsp_t
*lsp
)
775 zebra_nhlfe_t
*nhlfe
;
777 struct nexthop
*nexthop
;
785 UNSET_FLAG(lsp
->flags
, LSP_FLAG_CHANGED
);
788 * First compute the best path, after checking nexthop status. We are
790 * concerned with non-deleted NHLFEs.
792 for (nhlfe
= lsp
->nhlfe_list
; nhlfe
; nhlfe
= nhlfe
->next
) {
793 /* Clear selection flags. */
794 UNSET_FLAG(nhlfe
->flags
,
795 (NHLFE_FLAG_SELECTED
| NHLFE_FLAG_MULTIPATH
));
797 if (!CHECK_FLAG(nhlfe
->flags
, NHLFE_FLAG_DELETED
)
798 && nhlfe_nexthop_active(nhlfe
)) {
799 if (!best
|| (nhlfe
->distance
< best
->distance
))
804 lsp
->best_nhlfe
= best
;
805 if (!lsp
->best_nhlfe
)
808 /* Mark best NHLFE as selected. */
809 SET_FLAG(lsp
->best_nhlfe
->flags
, NHLFE_FLAG_SELECTED
);
812 * If best path exists, see if there is ECMP. While doing this, note if
814 * new (uninstalled) NHLFE has been selected, an installed entry that is
815 * still selected has a change or an installed entry is to be removed.
817 for (nhlfe
= lsp
->nhlfe_list
; nhlfe
; nhlfe
= nhlfe
->next
) {
818 int nh_chg
, nh_sel
, nh_inst
;
820 nexthop
= nhlfe
->nexthop
;
821 if (!nexthop
) // unexpected
824 if (!CHECK_FLAG(nhlfe
->flags
, NHLFE_FLAG_DELETED
)
825 && CHECK_FLAG(nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
)
826 && (nhlfe
->distance
== lsp
->best_nhlfe
->distance
)) {
827 SET_FLAG(nhlfe
->flags
, NHLFE_FLAG_SELECTED
);
828 SET_FLAG(nhlfe
->flags
, NHLFE_FLAG_MULTIPATH
);
832 if (CHECK_FLAG(lsp
->flags
, LSP_FLAG_INSTALLED
) && !changed
) {
833 nh_chg
= CHECK_FLAG(nhlfe
->flags
, NHLFE_FLAG_CHANGED
);
834 nh_sel
= CHECK_FLAG(nhlfe
->flags
, NHLFE_FLAG_SELECTED
);
836 CHECK_FLAG(nhlfe
->flags
, NHLFE_FLAG_INSTALLED
);
838 if ((nh_sel
&& !nh_inst
)
839 || (nh_sel
&& nh_inst
&& nh_chg
)
840 || (nh_inst
&& !nh_sel
))
844 /* We have finished examining, clear changed flag. */
845 UNSET_FLAG(nhlfe
->flags
, NHLFE_FLAG_CHANGED
);
849 SET_FLAG(lsp
->flags
, LSP_FLAG_CHANGED
);
853 * Delete LSP forwarding entry from kernel, if installed. Called upon
856 static void lsp_uninstall_from_kernel(struct hash_backet
*backet
, void *ctxt
)
860 lsp
= (zebra_lsp_t
*)backet
->data
;
861 if (CHECK_FLAG(lsp
->flags
, LSP_FLAG_INSTALLED
))
862 (void)dplane_lsp_delete(lsp
);
866 * Schedule LSP forwarding entry for processing. Called upon changes
867 * that may impact LSPs such as nexthop / connected route changes.
869 static void lsp_schedule(struct hash_backet
*backet
, void *ctxt
)
873 lsp
= (zebra_lsp_t
*)backet
->data
;
874 (void)lsp_processq_add(lsp
);
878 * Process a LSP entry that is in the queue. Recalculate best NHLFE and
879 * any multipaths and update or delete from the kernel, as needed.
881 static wq_item_status
lsp_process(struct work_queue
*wq
, void *data
)
884 zebra_nhlfe_t
*oldbest
, *newbest
;
885 char buf
[BUFSIZ
], buf2
[BUFSIZ
];
886 struct zebra_vrf
*zvrf
= vrf_info_lookup(VRF_DEFAULT
);
887 enum zebra_dplane_result res
;
889 lsp
= (zebra_lsp_t
*)data
;
890 if (!lsp
) // unexpected
893 oldbest
= lsp
->best_nhlfe
;
895 /* Select best NHLFE(s) */
896 lsp_select_best_nhlfe(lsp
);
898 newbest
= lsp
->best_nhlfe
;
900 if (IS_ZEBRA_DEBUG_MPLS
) {
902 nhlfe2str(oldbest
, buf
, BUFSIZ
);
904 nhlfe2str(newbest
, buf2
, BUFSIZ
);
906 "Process LSP in-label %u oldbest %s newbest %s "
907 "flags 0x%x ecmp# %d",
908 lsp
->ile
.in_label
, oldbest
? buf
: "NULL",
909 newbest
? buf2
: "NULL", lsp
->flags
, lsp
->num_ecmp
);
912 if (!CHECK_FLAG(lsp
->flags
, LSP_FLAG_INSTALLED
)) {
913 /* Not already installed */
916 UNSET_FLAG(lsp
->flags
, LSP_FLAG_CHANGED
);
918 switch (dplane_lsp_add(lsp
)) {
919 case ZEBRA_DPLANE_REQUEST_QUEUED
:
920 /* Set 'installed' flag so we will know
921 * that an install is in-flight.
923 SET_FLAG(lsp
->flags
, LSP_FLAG_INSTALLED
);
925 zvrf
->lsp_installs_queued
++;
927 case ZEBRA_DPLANE_REQUEST_FAILURE
:
928 flog_warn(EC_ZEBRA_LSP_INSTALL_FAILURE
,
929 "LSP Install Failure: %u",
932 case ZEBRA_DPLANE_REQUEST_SUCCESS
:
933 zvrf
->lsp_installs
++;
938 /* Installed, may need an update and/or delete. */
940 res
= dplane_lsp_delete(lsp
);
942 /* We do some of the lsp cleanup immediately for
945 UNSET_FLAG(lsp
->flags
, LSP_FLAG_INSTALLED
);
946 clear_nhlfe_installed(lsp
);
949 case ZEBRA_DPLANE_REQUEST_QUEUED
:
950 zvrf
->lsp_removals_queued
++;
952 case ZEBRA_DPLANE_REQUEST_FAILURE
:
953 flog_warn(EC_ZEBRA_LSP_DELETE_FAILURE
,
954 "LSP Deletion Failure: %u",
957 case ZEBRA_DPLANE_REQUEST_SUCCESS
:
958 zvrf
->lsp_removals
++;
961 } else if (CHECK_FLAG(lsp
->flags
, LSP_FLAG_CHANGED
)) {
962 zebra_nhlfe_t
*nhlfe
;
963 struct nexthop
*nexthop
;
965 UNSET_FLAG(lsp
->flags
, LSP_FLAG_CHANGED
);
967 /* We leave the INSTALLED flag set here
968 * so we know an update in in-flight.
972 * Any NHLFE that was installed but is not
973 * selected now needs to have its flags updated.
975 for (nhlfe
= lsp
->nhlfe_list
; nhlfe
;
976 nhlfe
= nhlfe
->next
) {
977 nexthop
= nhlfe
->nexthop
;
981 if (CHECK_FLAG(nhlfe
->flags
,
982 NHLFE_FLAG_INSTALLED
)
983 && !CHECK_FLAG(nhlfe
->flags
,
984 NHLFE_FLAG_SELECTED
)) {
985 UNSET_FLAG(nhlfe
->flags
,
986 NHLFE_FLAG_INSTALLED
);
987 UNSET_FLAG(nexthop
->flags
,
992 switch (dplane_lsp_update(lsp
)) {
993 case ZEBRA_DPLANE_REQUEST_QUEUED
:
994 zvrf
->lsp_installs_queued
++;
996 case ZEBRA_DPLANE_REQUEST_FAILURE
:
997 flog_warn(EC_ZEBRA_LSP_INSTALL_FAILURE
,
998 "LSP Update Failure: %u",
1001 case ZEBRA_DPLANE_REQUEST_SUCCESS
:
1002 zvrf
->lsp_installs
++;
1013 * Callback upon processing completion of a LSP forwarding entry.
1015 static void lsp_processq_del(struct work_queue
*wq
, void *data
)
1017 struct zebra_vrf
*zvrf
;
1019 struct hash
*lsp_table
;
1020 zebra_nhlfe_t
*nhlfe
, *nhlfe_next
;
1022 zvrf
= vrf_info_lookup(VRF_DEFAULT
);
1025 lsp_table
= zvrf
->lsp_table
;
1026 if (!lsp_table
) // unexpected
1029 lsp
= (zebra_lsp_t
*)data
;
1030 if (!lsp
) // unexpected
1033 /* Clear flag, remove any NHLFEs marked for deletion. If no NHLFEs
1035 * delete LSP entry also.
1037 UNSET_FLAG(lsp
->flags
, LSP_FLAG_SCHEDULED
);
1039 for (nhlfe
= lsp
->nhlfe_list
; nhlfe
; nhlfe
= nhlfe_next
) {
1040 nhlfe_next
= nhlfe
->next
;
1041 if (CHECK_FLAG(nhlfe
->flags
, NHLFE_FLAG_DELETED
))
1045 if (!lsp
->nhlfe_list
) {
1046 if (IS_ZEBRA_DEBUG_MPLS
)
1047 zlog_debug("Free LSP in-label %u flags 0x%x",
1048 lsp
->ile
.in_label
, lsp
->flags
);
1050 lsp
= hash_release(lsp_table
, &lsp
->ile
);
1052 XFREE(MTYPE_LSP
, lsp
);
1057 * Callback upon finishing the processing of all scheduled
1058 * LSP forwarding entries.
1060 static void lsp_processq_complete(struct work_queue
*wq
)
1062 /* Nothing to do for now. */
1066 * Add LSP forwarding entry to queue for subsequent processing.
1068 static int lsp_processq_add(zebra_lsp_t
*lsp
)
1070 /* If already scheduled, exit. */
1071 if (CHECK_FLAG(lsp
->flags
, LSP_FLAG_SCHEDULED
))
1074 if (zrouter
.lsp_process_q
== NULL
) {
1075 flog_err(EC_ZEBRA_WQ_NONEXISTENT
,
1076 "%s: work_queue does not exist!", __func__
);
1080 work_queue_add(zrouter
.lsp_process_q
, lsp
);
1081 SET_FLAG(lsp
->flags
, LSP_FLAG_SCHEDULED
);
1086 * Callback to allocate LSP forwarding table entry.
1088 static void *lsp_alloc(void *p
)
1090 const zebra_ile_t
*ile
= p
;
1093 lsp
= XCALLOC(MTYPE_LSP
, sizeof(zebra_lsp_t
));
1096 if (IS_ZEBRA_DEBUG_MPLS
)
1097 zlog_debug("Alloc LSP in-label %u", lsp
->ile
.in_label
);
1099 return ((void *)lsp
);
1103 * Create printable string for NHLFE entry.
1105 static char *nhlfe2str(zebra_nhlfe_t
*nhlfe
, char *buf
, int size
)
1107 struct nexthop
*nexthop
;
1110 nexthop
= nhlfe
->nexthop
;
1111 switch (nexthop
->type
) {
1112 case NEXTHOP_TYPE_IPV4
:
1113 case NEXTHOP_TYPE_IPV4_IFINDEX
:
1114 inet_ntop(AF_INET
, &nexthop
->gate
.ipv4
, buf
, size
);
1116 case NEXTHOP_TYPE_IPV6
:
1117 inet_ntop(AF_INET6
, &nexthop
->gate
.ipv6
, buf
, size
);
1119 case NEXTHOP_TYPE_IFINDEX
:
1120 snprintf(buf
, size
, "Ifindex: %u", nexthop
->ifindex
);
1129 * Check if NHLFE matches with search info passed.
1131 static int nhlfe_nhop_match(zebra_nhlfe_t
*nhlfe
, enum nexthop_types_t gtype
,
1132 union g_addr
*gate
, ifindex_t ifindex
)
1134 struct nexthop
*nhop
;
1137 nhop
= nhlfe
->nexthop
;
1141 if (nhop
->type
!= gtype
)
1144 switch (nhop
->type
) {
1145 case NEXTHOP_TYPE_IPV4
:
1146 case NEXTHOP_TYPE_IPV4_IFINDEX
:
1147 cmp
= memcmp(&(nhop
->gate
.ipv4
), &(gate
->ipv4
),
1148 sizeof(struct in_addr
));
1149 if (!cmp
&& nhop
->type
== NEXTHOP_TYPE_IPV4_IFINDEX
)
1150 cmp
= !(nhop
->ifindex
== ifindex
);
1152 case NEXTHOP_TYPE_IPV6
:
1153 case NEXTHOP_TYPE_IPV6_IFINDEX
:
1154 cmp
= memcmp(&(nhop
->gate
.ipv6
), &(gate
->ipv6
),
1155 sizeof(struct in6_addr
));
1156 if (!cmp
&& nhop
->type
== NEXTHOP_TYPE_IPV6_IFINDEX
)
1157 cmp
= !(nhop
->ifindex
== ifindex
);
1159 case NEXTHOP_TYPE_IFINDEX
:
1160 cmp
= !(nhop
->ifindex
== ifindex
);
1171 * Locate NHLFE that matches with passed info.
1173 static zebra_nhlfe_t
*nhlfe_find(zebra_lsp_t
*lsp
, enum lsp_types_t lsp_type
,
1174 enum nexthop_types_t gtype
, union g_addr
*gate
,
1177 zebra_nhlfe_t
*nhlfe
;
1182 for (nhlfe
= lsp
->nhlfe_list
; nhlfe
; nhlfe
= nhlfe
->next
) {
1183 if (nhlfe
->type
!= lsp_type
)
1185 if (!nhlfe_nhop_match(nhlfe
, gtype
, gate
, ifindex
))
1193 * Add NHLFE. Base entry must have been created and duplicate
1196 static zebra_nhlfe_t
*nhlfe_add(zebra_lsp_t
*lsp
, enum lsp_types_t lsp_type
,
1197 enum nexthop_types_t gtype
, union g_addr
*gate
,
1198 ifindex_t ifindex
, mpls_label_t out_label
)
1200 zebra_nhlfe_t
*nhlfe
;
1201 struct nexthop
*nexthop
;
1206 nhlfe
= XCALLOC(MTYPE_NHLFE
, sizeof(zebra_nhlfe_t
));
1209 nhlfe
->type
= lsp_type
;
1210 nhlfe
->distance
= lsp_distance(lsp_type
);
1212 nexthop
= nexthop_new();
1214 XFREE(MTYPE_NHLFE
, nhlfe
);
1217 nexthop_add_labels(nexthop
, lsp_type
, 1, &out_label
);
1219 nexthop
->vrf_id
= VRF_DEFAULT
;
1220 nexthop
->type
= gtype
;
1221 switch (nexthop
->type
) {
1222 case NEXTHOP_TYPE_IPV4
:
1223 case NEXTHOP_TYPE_IPV4_IFINDEX
:
1224 nexthop
->gate
.ipv4
= gate
->ipv4
;
1226 nexthop
->ifindex
= ifindex
;
1228 case NEXTHOP_TYPE_IPV6
:
1229 case NEXTHOP_TYPE_IPV6_IFINDEX
:
1230 nexthop
->gate
.ipv6
= gate
->ipv6
;
1232 nexthop
->ifindex
= ifindex
;
1234 case NEXTHOP_TYPE_IFINDEX
:
1235 nexthop
->ifindex
= ifindex
;
1238 nexthop_free(nexthop
);
1239 XFREE(MTYPE_NHLFE
, nhlfe
);
1244 nhlfe
->nexthop
= nexthop
;
1245 if (lsp
->nhlfe_list
)
1246 lsp
->nhlfe_list
->prev
= nhlfe
;
1247 nhlfe
->next
= lsp
->nhlfe_list
;
1248 lsp
->nhlfe_list
= nhlfe
;
1254 * Delete NHLFE. Entry must be present on list.
1256 static int nhlfe_del(zebra_nhlfe_t
*nhlfe
)
1269 nexthop_free(nhlfe
->nexthop
);
1271 /* Unlink from LSP */
1273 nhlfe
->next
->prev
= nhlfe
->prev
;
1275 nhlfe
->prev
->next
= nhlfe
->next
;
1277 lsp
->nhlfe_list
= nhlfe
->next
;
1279 if (nhlfe
== lsp
->best_nhlfe
)
1280 lsp
->best_nhlfe
= NULL
;
1282 XFREE(MTYPE_NHLFE
, nhlfe
);
1288 * Update label for NHLFE entry.
1290 static void nhlfe_out_label_update(zebra_nhlfe_t
*nhlfe
,
1291 struct mpls_label_stack
*nh_label
)
1293 nhlfe
->nexthop
->nh_label
->label
[0] = nh_label
->label
[0];
1296 static int mpls_lsp_uninstall_all(struct hash
*lsp_table
, zebra_lsp_t
*lsp
,
1297 enum lsp_types_t type
)
1299 zebra_nhlfe_t
*nhlfe
, *nhlfe_next
;
1300 int schedule_lsp
= 0;
1303 /* Mark NHLFEs for delete or directly delete, as appropriate. */
1304 for (nhlfe
= lsp
->nhlfe_list
; nhlfe
; nhlfe
= nhlfe_next
) {
1305 nhlfe_next
= nhlfe
->next
;
1307 /* Skip non-static NHLFEs */
1308 if (nhlfe
->type
!= type
)
1311 if (IS_ZEBRA_DEBUG_MPLS
) {
1312 nhlfe2str(nhlfe
, buf
, BUFSIZ
);
1314 "Del LSP in-label %u type %d nexthop %s flags 0x%x",
1315 lsp
->ile
.in_label
, type
, buf
, nhlfe
->flags
);
1318 if (CHECK_FLAG(nhlfe
->flags
, NHLFE_FLAG_INSTALLED
)) {
1319 UNSET_FLAG(nhlfe
->flags
, NHLFE_FLAG_CHANGED
);
1320 SET_FLAG(nhlfe
->flags
, NHLFE_FLAG_DELETED
);
1327 /* Queue LSP for processing, if needed, else delete. */
1329 if (lsp_processq_add(lsp
))
1331 } else if (!lsp
->nhlfe_list
1332 && !CHECK_FLAG(lsp
->flags
, LSP_FLAG_SCHEDULED
)) {
1333 if (IS_ZEBRA_DEBUG_MPLS
)
1334 zlog_debug("Free LSP in-label %u flags 0x%x",
1335 lsp
->ile
.in_label
, lsp
->flags
);
1337 lsp
= hash_release(lsp_table
, &lsp
->ile
);
1339 XFREE(MTYPE_LSP
, lsp
);
1346 * Uninstall all static NHLFEs for a particular LSP forwarding entry.
1347 * If no other NHLFEs exist, the entry would be deleted.
1349 static int mpls_static_lsp_uninstall_all(struct zebra_vrf
*zvrf
,
1350 mpls_label_t in_label
)
1352 struct hash
*lsp_table
;
1353 zebra_ile_t tmp_ile
;
1357 lsp_table
= zvrf
->lsp_table
;
1361 /* If entry is not present, exit. */
1362 tmp_ile
.in_label
= in_label
;
1363 lsp
= hash_lookup(lsp_table
, &tmp_ile
);
1364 if (!lsp
|| !lsp
->nhlfe_list
)
1367 return mpls_lsp_uninstall_all(lsp_table
, lsp
, ZEBRA_LSP_STATIC
);
1370 static json_object
*nhlfe_json(zebra_nhlfe_t
*nhlfe
)
1373 json_object
*json_nhlfe
= NULL
;
1374 struct nexthop
*nexthop
= nhlfe
->nexthop
;
1376 json_nhlfe
= json_object_new_object();
1377 json_object_string_add(json_nhlfe
, "type", nhlfe_type2str(nhlfe
->type
));
1378 json_object_int_add(json_nhlfe
, "outLabel",
1379 nexthop
->nh_label
->label
[0]);
1380 json_object_int_add(json_nhlfe
, "distance", nhlfe
->distance
);
1382 if (CHECK_FLAG(nhlfe
->flags
, NHLFE_FLAG_INSTALLED
))
1383 json_object_boolean_true_add(json_nhlfe
, "installed");
1385 switch (nexthop
->type
) {
1386 case NEXTHOP_TYPE_IPV4
:
1387 case NEXTHOP_TYPE_IPV4_IFINDEX
:
1388 json_object_string_add(json_nhlfe
, "nexthop",
1389 inet_ntoa(nexthop
->gate
.ipv4
));
1391 case NEXTHOP_TYPE_IPV6
:
1392 case NEXTHOP_TYPE_IPV6_IFINDEX
:
1393 json_object_string_add(
1394 json_nhlfe
, "nexthop",
1395 inet_ntop(AF_INET6
, &nexthop
->gate
.ipv6
, buf
, BUFSIZ
));
1397 if (nexthop
->ifindex
)
1398 json_object_string_add(json_nhlfe
, "interface",
1399 ifindex2ifname(nexthop
->ifindex
,
1409 * Print the NHLFE for a LSP forwarding entry.
1411 static void nhlfe_print(zebra_nhlfe_t
*nhlfe
, struct vty
*vty
)
1413 struct nexthop
*nexthop
;
1416 nexthop
= nhlfe
->nexthop
;
1417 if (!nexthop
|| !nexthop
->nh_label
) // unexpected
1420 vty_out(vty
, " type: %s remote label: %s distance: %d\n",
1421 nhlfe_type2str(nhlfe
->type
),
1422 label2str(nexthop
->nh_label
->label
[0], buf
, BUFSIZ
),
1424 switch (nexthop
->type
) {
1425 case NEXTHOP_TYPE_IPV4
:
1426 case NEXTHOP_TYPE_IPV4_IFINDEX
:
1427 vty_out(vty
, " via %s", inet_ntoa(nexthop
->gate
.ipv4
));
1428 if (nexthop
->ifindex
)
1429 vty_out(vty
, " dev %s",
1430 ifindex2ifname(nexthop
->ifindex
,
1433 case NEXTHOP_TYPE_IPV6
:
1434 case NEXTHOP_TYPE_IPV6_IFINDEX
:
1435 vty_out(vty
, " via %s",
1436 inet_ntop(AF_INET6
, &nexthop
->gate
.ipv6
, buf
, BUFSIZ
));
1437 if (nexthop
->ifindex
)
1438 vty_out(vty
, " dev %s",
1439 ifindex2ifname(nexthop
->ifindex
,
1446 CHECK_FLAG(nhlfe
->flags
, NHLFE_FLAG_INSTALLED
) ? " (installed)"
1452 * Print an LSP forwarding entry.
1454 static void lsp_print(zebra_lsp_t
*lsp
, void *ctxt
)
1456 zebra_nhlfe_t
*nhlfe
;
1459 vty
= (struct vty
*)ctxt
;
1461 vty_out(vty
, "Local label: %u%s\n", lsp
->ile
.in_label
,
1462 CHECK_FLAG(lsp
->flags
, LSP_FLAG_INSTALLED
) ? " (installed)"
1465 for (nhlfe
= lsp
->nhlfe_list
; nhlfe
; nhlfe
= nhlfe
->next
)
1466 nhlfe_print(nhlfe
, vty
);
1470 * JSON objects for an LSP forwarding entry.
1472 static json_object
*lsp_json(zebra_lsp_t
*lsp
)
1474 zebra_nhlfe_t
*nhlfe
= NULL
;
1475 json_object
*json
= json_object_new_object();
1476 json_object
*json_nhlfe_list
= json_object_new_array();
1478 json_object_int_add(json
, "inLabel", lsp
->ile
.in_label
);
1480 if (CHECK_FLAG(lsp
->flags
, LSP_FLAG_INSTALLED
))
1481 json_object_boolean_true_add(json
, "installed");
1483 for (nhlfe
= lsp
->nhlfe_list
; nhlfe
; nhlfe
= nhlfe
->next
)
1484 json_object_array_add(json_nhlfe_list
, nhlfe_json(nhlfe
));
1486 json_object_object_add(json
, "nexthops", json_nhlfe_list
);
1491 /* Return a sorted linked list of the hash contents */
1492 static struct list
*hash_get_sorted_list(struct hash
*hash
, void *cmp
)
1495 struct hash_backet
*hb
;
1496 struct list
*sorted_list
= list_new();
1498 sorted_list
->cmp
= (int (*)(void *, void *))cmp
;
1500 for (i
= 0; i
< hash
->size
; i
++)
1501 for (hb
= hash
->index
[i
]; hb
; hb
= hb
->next
)
1502 listnode_add_sort(sorted_list
, hb
->data
);
1508 * Compare two LSPs based on their label values.
1510 static int lsp_cmp(zebra_lsp_t
*lsp1
, zebra_lsp_t
*lsp2
)
1512 if (lsp1
->ile
.in_label
< lsp2
->ile
.in_label
)
1515 if (lsp1
->ile
.in_label
> lsp2
->ile
.in_label
)
1522 * Callback to allocate static LSP.
1524 static void *slsp_alloc(void *p
)
1526 const zebra_ile_t
*ile
= p
;
1529 slsp
= XCALLOC(MTYPE_SLSP
, sizeof(zebra_slsp_t
));
1531 return ((void *)slsp
);
1535 * Compare two static LSPs based on their label values.
1537 static int slsp_cmp(zebra_slsp_t
*slsp1
, zebra_slsp_t
*slsp2
)
1539 if (slsp1
->ile
.in_label
< slsp2
->ile
.in_label
)
1542 if (slsp1
->ile
.in_label
> slsp2
->ile
.in_label
)
1549 * Check if static NHLFE matches with search info passed.
1551 static int snhlfe_match(zebra_snhlfe_t
*snhlfe
, enum nexthop_types_t gtype
,
1552 union g_addr
*gate
, ifindex_t ifindex
)
1556 if (snhlfe
->gtype
!= gtype
)
1559 switch (snhlfe
->gtype
) {
1560 case NEXTHOP_TYPE_IPV4
:
1561 cmp
= memcmp(&(snhlfe
->gate
.ipv4
), &(gate
->ipv4
),
1562 sizeof(struct in_addr
));
1564 case NEXTHOP_TYPE_IPV6
:
1565 case NEXTHOP_TYPE_IPV6_IFINDEX
:
1566 cmp
= memcmp(&(snhlfe
->gate
.ipv6
), &(gate
->ipv6
),
1567 sizeof(struct in6_addr
));
1568 if (!cmp
&& snhlfe
->gtype
== NEXTHOP_TYPE_IPV6_IFINDEX
)
1569 cmp
= !(snhlfe
->ifindex
== ifindex
);
1579 * Locate static NHLFE that matches with passed info.
1581 static zebra_snhlfe_t
*snhlfe_find(zebra_slsp_t
*slsp
,
1582 enum nexthop_types_t gtype
,
1583 union g_addr
*gate
, ifindex_t ifindex
)
1585 zebra_snhlfe_t
*snhlfe
;
1590 for (snhlfe
= slsp
->snhlfe_list
; snhlfe
; snhlfe
= snhlfe
->next
) {
1591 if (!snhlfe_match(snhlfe
, gtype
, gate
, ifindex
))
1600 * Add static NHLFE. Base LSP config entry must have been created
1601 * and duplicate check done.
1603 static zebra_snhlfe_t
*snhlfe_add(zebra_slsp_t
*slsp
,
1604 enum nexthop_types_t gtype
,
1605 union g_addr
*gate
, ifindex_t ifindex
,
1606 mpls_label_t out_label
)
1608 zebra_snhlfe_t
*snhlfe
;
1613 snhlfe
= XCALLOC(MTYPE_SNHLFE
, sizeof(zebra_snhlfe_t
));
1614 snhlfe
->slsp
= slsp
;
1615 snhlfe
->out_label
= out_label
;
1616 snhlfe
->gtype
= gtype
;
1618 case NEXTHOP_TYPE_IPV4
:
1619 snhlfe
->gate
.ipv4
= gate
->ipv4
;
1621 case NEXTHOP_TYPE_IPV6
:
1622 case NEXTHOP_TYPE_IPV6_IFINDEX
:
1623 snhlfe
->gate
.ipv6
= gate
->ipv6
;
1625 snhlfe
->ifindex
= ifindex
;
1628 XFREE(MTYPE_SNHLFE
, snhlfe
);
1632 if (slsp
->snhlfe_list
)
1633 slsp
->snhlfe_list
->prev
= snhlfe
;
1634 snhlfe
->next
= slsp
->snhlfe_list
;
1635 slsp
->snhlfe_list
= snhlfe
;
1641 * Delete static NHLFE. Entry must be present on list.
1643 static int snhlfe_del(zebra_snhlfe_t
*snhlfe
)
1650 slsp
= snhlfe
->slsp
;
1655 snhlfe
->next
->prev
= snhlfe
->prev
;
1657 snhlfe
->prev
->next
= snhlfe
->next
;
1659 slsp
->snhlfe_list
= snhlfe
->next
;
1661 snhlfe
->prev
= snhlfe
->next
= NULL
;
1663 XFREE(MTYPE_SNHLFE_IFNAME
, snhlfe
->ifname
);
1664 XFREE(MTYPE_SNHLFE
, snhlfe
);
1670 * Delete all static NHLFE entries for this LSP (in label).
1672 static int snhlfe_del_all(zebra_slsp_t
*slsp
)
1674 zebra_snhlfe_t
*snhlfe
, *snhlfe_next
;
1679 for (snhlfe
= slsp
->snhlfe_list
; snhlfe
; snhlfe
= snhlfe_next
) {
1680 snhlfe_next
= snhlfe
->next
;
1688 * Create printable string for NHLFE configuration.
1690 static char *snhlfe2str(zebra_snhlfe_t
*snhlfe
, char *buf
, int size
)
1693 switch (snhlfe
->gtype
) {
1694 case NEXTHOP_TYPE_IPV4
:
1695 inet_ntop(AF_INET
, &snhlfe
->gate
.ipv4
, buf
, size
);
1697 case NEXTHOP_TYPE_IPV6
:
1698 case NEXTHOP_TYPE_IPV6_IFINDEX
:
1699 inet_ntop(AF_INET6
, &snhlfe
->gate
.ipv6
, buf
, size
);
1700 if (snhlfe
->ifindex
)
1702 ifindex2ifname(snhlfe
->ifindex
, VRF_DEFAULT
));
1712 * Initialize work queue for processing changed LSPs.
1714 static int mpls_processq_init(void)
1716 zrouter
.lsp_process_q
= work_queue_new(zrouter
.master
, "LSP processing");
1717 if (!zrouter
.lsp_process_q
) {
1718 flog_err(EC_ZEBRA_WQ_NONEXISTENT
,
1719 "%s: could not initialise work queue!", __func__
);
1723 zrouter
.lsp_process_q
->spec
.workfunc
= &lsp_process
;
1724 zrouter
.lsp_process_q
->spec
.del_item_data
= &lsp_processq_del
;
1725 zrouter
.lsp_process_q
->spec
.errorfunc
= NULL
;
1726 zrouter
.lsp_process_q
->spec
.completion_func
= &lsp_processq_complete
;
1727 zrouter
.lsp_process_q
->spec
.max_retries
= 0;
1728 zrouter
.lsp_process_q
->spec
.hold
= 10;
1734 /* Public functions */
1737 * Process LSP update results from zebra dataplane.
1739 void zebra_mpls_lsp_dplane_result(struct zebra_dplane_ctx
*ctx
)
1741 struct zebra_vrf
*zvrf
;
1742 zebra_ile_t tmp_ile
;
1743 struct hash
*lsp_table
;
1745 zebra_nhlfe_t
*nhlfe
;
1746 struct nexthop
*nexthop
;
1747 enum dplane_op_e op
;
1748 enum zebra_dplane_result status
;
1750 op
= dplane_ctx_get_op(ctx
);
1751 status
= dplane_ctx_get_status(ctx
);
1753 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
)
1754 zlog_debug("LSP dplane ctx %p, op %s, in-label %u, result %s",
1755 ctx
, dplane_op2str(op
),
1756 dplane_ctx_get_in_label(ctx
),
1757 dplane_res2str(status
));
1760 case DPLANE_OP_LSP_INSTALL
:
1761 case DPLANE_OP_LSP_UPDATE
:
1762 /* Look for zebra LSP object */
1763 zvrf
= vrf_info_lookup(VRF_DEFAULT
);
1767 lsp_table
= zvrf
->lsp_table
;
1769 tmp_ile
.in_label
= dplane_ctx_get_in_label(ctx
);
1770 lsp
= hash_lookup(lsp_table
, &tmp_ile
);
1772 if (IS_ZEBRA_DEBUG_DPLANE
)
1773 zlog_debug("LSP ctx %p: in-label %u not found",
1774 ctx
, dplane_ctx_get_in_label(ctx
));
1778 /* TODO -- Confirm that this result is still 'current' */
1780 if (status
== ZEBRA_DPLANE_REQUEST_SUCCESS
) {
1781 /* Update zebra object */
1782 SET_FLAG(lsp
->flags
, LSP_FLAG_INSTALLED
);
1783 for (nhlfe
= lsp
->nhlfe_list
; nhlfe
;
1784 nhlfe
= nhlfe
->next
) {
1785 nexthop
= nhlfe
->nexthop
;
1789 SET_FLAG(nhlfe
->flags
, NHLFE_FLAG_INSTALLED
);
1790 SET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_FIB
);
1793 UNSET_FLAG(lsp
->flags
, LSP_FLAG_INSTALLED
);
1794 clear_nhlfe_installed(lsp
);
1795 flog_warn(EC_ZEBRA_LSP_INSTALL_FAILURE
,
1796 "LSP Install Failure: in-label %u",
1802 case DPLANE_OP_LSP_DELETE
:
1803 if (status
!= ZEBRA_DPLANE_REQUEST_SUCCESS
)
1804 flog_warn(EC_ZEBRA_LSP_DELETE_FAILURE
,
1805 "LSP Deletion Failure: in-label %u",
1806 dplane_ctx_get_in_label(ctx
));
1814 dplane_ctx_fini(&ctx
);
1818 * Install dynamic LSP entry.
1820 int zebra_mpls_lsp_install(struct zebra_vrf
*zvrf
, struct route_node
*rn
,
1821 struct route_entry
*re
)
1823 struct route_table
*table
;
1826 table
= zvrf
->fec_table
[family2afi(PREFIX_FAMILY(&rn
->p
))];
1830 /* See if there is a configured label binding for this FEC. */
1831 fec
= fec_find(table
, &rn
->p
);
1832 if (!fec
|| fec
->label
== MPLS_INVALID_LABEL
)
1835 /* We cannot install a label forwarding entry if local label is the
1836 * implicit-null label.
1838 if (fec
->label
== MPLS_LABEL_IMPLICIT_NULL
)
1841 if (lsp_install(zvrf
, fec
->label
, rn
, re
))
1848 * Uninstall dynamic LSP entry, if any.
1850 int zebra_mpls_lsp_uninstall(struct zebra_vrf
*zvrf
, struct route_node
*rn
,
1851 struct route_entry
*re
)
1853 struct route_table
*table
;
1856 table
= zvrf
->fec_table
[family2afi(PREFIX_FAMILY(&rn
->p
))];
1860 /* See if there is a configured label binding for this FEC. */
1861 fec
= fec_find(table
, &rn
->p
);
1862 if (!fec
|| fec
->label
== MPLS_INVALID_LABEL
)
1865 /* Uninstall always removes all dynamic NHLFEs. */
1866 return lsp_uninstall(zvrf
, fec
->label
);
1870 * Add an NHLFE to an LSP, return the newly-added object
1872 zebra_nhlfe_t
*zebra_mpls_lsp_add_nhlfe(zebra_lsp_t
*lsp
,
1873 enum lsp_types_t lsp_type
,
1874 enum nexthop_types_t gtype
,
1877 mpls_label_t out_label
)
1879 /* Just a public pass-through to the internal implementation */
1880 return nhlfe_add(lsp
, lsp_type
, gtype
, gate
, ifindex
, out_label
);
1884 * Free an allocated NHLFE
1886 void zebra_mpls_nhlfe_del(zebra_nhlfe_t
*nhlfe
)
1888 /* Just a pass-through to the internal implementation */
1893 * Registration from a client for the label binding for a FEC. If a binding
1894 * already exists, it is informed to the client.
1895 * NOTE: If there is a manually configured label binding, that is used.
1896 * Otherwise, if a label index is specified, it means we have to allocate the
1897 * label from a locally configured label block (SRGB), if one exists and index
1898 * is acceptable. If no label index then just register the specified label.
1899 * NOTE2: Either label or label_index is expected to be set to MPLS_INVALID_*
1900 * by the calling function. Register requests with both will be rejected.
1902 int zebra_mpls_fec_register(struct zebra_vrf
*zvrf
, struct prefix
*p
,
1903 uint32_t label
, uint32_t label_index
,
1904 struct zserv
*client
)
1906 struct route_table
*table
;
1910 bool label_change
= false;
1912 bool have_label_index
= (label_index
!= MPLS_INVALID_LABEL_INDEX
);
1913 bool is_configured_fec
= false; /* indicate statically configured FEC */
1915 table
= zvrf
->fec_table
[family2afi(PREFIX_FAMILY(p
))];
1919 if (IS_ZEBRA_DEBUG_MPLS
)
1920 prefix2str(p
, buf
, BUFSIZ
);
1922 if (label
!= MPLS_INVALID_LABEL
&& have_label_index
) {
1924 EC_ZEBRA_FEC_LABEL_INDEX_LABEL_CONFLICT
,
1925 "Rejecting FEC register for %s with both label %u and Label Index %u specified, client %s",
1926 buf
, label
, label_index
,
1927 zebra_route_string(client
->proto
));
1932 fec
= fec_find(table
, p
);
1934 fec
= fec_add(table
, p
, label
, 0, label_index
);
1937 EC_ZEBRA_FEC_ADD_FAILED
,
1938 "Failed to add FEC %s upon register, client %s",
1939 buf
, zebra_route_string(client
->proto
));
1943 old_label
= MPLS_INVALID_LABEL
;
1946 /* Check if the FEC has been statically defined in the config */
1947 is_configured_fec
= fec
->flags
& FEC_FLAG_CONFIGURED
;
1948 /* Client may register same FEC with different label index. */
1950 (listnode_lookup(fec
->client_list
, client
) == NULL
);
1951 if (!new_client
&& fec
->label_index
== label_index
1952 && fec
->label
== label
)
1953 /* Duplicate register */
1956 /* Save current label, update the FEC */
1957 old_label
= fec
->label
;
1958 fec
->label_index
= label_index
;
1962 listnode_add(fec
->client_list
, client
);
1964 if (IS_ZEBRA_DEBUG_MPLS
)
1965 zlog_debug("FEC %s label%s %u %s by client %s%s", buf
,
1966 have_label_index
? " index" : "",
1967 have_label_index
? label_index
: label
,
1968 new_client
? "registered" : "updated",
1969 zebra_route_string(client
->proto
),
1971 ? ", but using statically configured label"
1974 /* If not a statically configured FEC, derive the local label
1975 * from label index or use the provided label
1977 if (!is_configured_fec
) {
1978 if (have_label_index
)
1979 fec_derive_label_from_index(zvrf
, fec
);
1983 /* If no label change, exit. */
1984 if (fec
->label
== old_label
)
1987 label_change
= true;
1990 /* If new client or label change, update client and install or uninstall
1991 * label forwarding entry as needed.
1993 /* Inform client of label, if needed. */
1994 if ((new_client
&& fec
->label
!= MPLS_INVALID_LABEL
) || label_change
) {
1995 if (IS_ZEBRA_DEBUG_MPLS
)
1996 zlog_debug("Update client label %u", fec
->label
);
1997 fec_send(fec
, client
);
2000 if (new_client
|| label_change
)
2001 return fec_change_update_lsp(zvrf
, fec
, old_label
);
2007 * Deregistration from a client for the label binding for a FEC. The FEC
2008 * itself is deleted if no other registered clients exist and there is no
2009 * label bound to the FEC.
2011 int zebra_mpls_fec_unregister(struct zebra_vrf
*zvrf
, struct prefix
*p
,
2012 struct zserv
*client
)
2014 struct route_table
*table
;
2018 table
= zvrf
->fec_table
[family2afi(PREFIX_FAMILY(p
))];
2022 if (IS_ZEBRA_DEBUG_MPLS
)
2023 prefix2str(p
, buf
, BUFSIZ
);
2025 fec
= fec_find(table
, p
);
2027 prefix2str(p
, buf
, BUFSIZ
);
2028 flog_err(EC_ZEBRA_FEC_RM_FAILED
,
2029 "Failed to find FEC %s upon unregister, client %s",
2030 buf
, zebra_route_string(client
->proto
));
2034 listnode_delete(fec
->client_list
, client
);
2036 if (IS_ZEBRA_DEBUG_MPLS
)
2037 zlog_debug("FEC %s unregistered by client %s", buf
,
2038 zebra_route_string(client
->proto
));
2040 /* If not a configured entry, delete the FEC if no other clients. Before
2041 * deleting, see if any LSP needs to be uninstalled.
2043 if (!(fec
->flags
& FEC_FLAG_CONFIGURED
)
2044 && list_isempty(fec
->client_list
)) {
2045 mpls_label_t old_label
= fec
->label
;
2046 fec
->label
= MPLS_INVALID_LABEL
; /* reset */
2047 fec_change_update_lsp(zvrf
, fec
, old_label
);
2055 * Cleanup any FECs registered by this client.
2057 static int zebra_mpls_cleanup_fecs_for_client(struct zserv
*client
)
2059 struct zebra_vrf
*zvrf
= vrf_info_lookup(VRF_DEFAULT
);
2060 struct route_node
*rn
;
2062 struct listnode
*node
;
2063 struct zserv
*fec_client
;
2066 for (af
= AFI_IP
; af
< AFI_MAX
; af
++) {
2067 if (zvrf
->fec_table
[af
] == NULL
)
2070 for (rn
= route_top(zvrf
->fec_table
[af
]); rn
;
2071 rn
= route_next(rn
)) {
2073 if (!fec
|| list_isempty(fec
->client_list
))
2076 for (ALL_LIST_ELEMENTS_RO(fec
->client_list
, node
,
2078 if (fec_client
== client
) {
2079 listnode_delete(fec
->client_list
,
2081 if (!(fec
->flags
& FEC_FLAG_CONFIGURED
)
2082 && list_isempty(fec
->client_list
))
2094 * Return FEC (if any) to which this label is bound.
2095 * Note: Only works for per-prefix binding and when the label is not
2097 * TODO: Currently walks entire table, can optimize later with another
2100 zebra_fec_t
*zebra_mpls_fec_for_label(struct zebra_vrf
*zvrf
,
2103 struct route_node
*rn
;
2107 for (af
= AFI_IP
; af
< AFI_MAX
; af
++) {
2108 if (zvrf
->fec_table
[af
] == NULL
)
2111 for (rn
= route_top(zvrf
->fec_table
[af
]); rn
;
2112 rn
= route_next(rn
)) {
2116 if (fec
->label
== label
)
2125 * Inform if specified label is currently bound to a FEC or not.
2127 int zebra_mpls_label_already_bound(struct zebra_vrf
*zvrf
, mpls_label_t label
)
2129 return (zebra_mpls_fec_for_label(zvrf
, label
) ? 1 : 0);
2133 * Add static FEC to label binding. If there are clients registered for this
2134 * FEC, notify them. If there are labeled routes for this FEC, install the
2135 * label forwarding entry.
2137 int zebra_mpls_static_fec_add(struct zebra_vrf
*zvrf
, struct prefix
*p
,
2138 mpls_label_t in_label
)
2140 struct route_table
*table
;
2143 mpls_label_t old_label
;
2146 table
= zvrf
->fec_table
[family2afi(PREFIX_FAMILY(p
))];
2150 if (IS_ZEBRA_DEBUG_MPLS
)
2151 prefix2str(p
, buf
, BUFSIZ
);
2153 /* Update existing FEC or create a new one. */
2154 fec
= fec_find(table
, p
);
2156 fec
= fec_add(table
, p
, in_label
, FEC_FLAG_CONFIGURED
,
2157 MPLS_INVALID_LABEL_INDEX
);
2159 prefix2str(p
, buf
, BUFSIZ
);
2160 flog_err(EC_ZEBRA_FEC_ADD_FAILED
,
2161 "Failed to add FEC %s upon config", buf
);
2165 if (IS_ZEBRA_DEBUG_MPLS
)
2166 zlog_debug("Add fec %s label %u", buf
, in_label
);
2168 fec
->flags
|= FEC_FLAG_CONFIGURED
;
2169 if (fec
->label
== in_label
)
2170 /* Duplicate config */
2173 /* Label change, update clients. */
2174 old_label
= fec
->label
;
2175 if (IS_ZEBRA_DEBUG_MPLS
)
2176 zlog_debug("Update fec %s new label %u", buf
, in_label
);
2178 fec
->label
= in_label
;
2179 fec_update_clients(fec
);
2181 /* Update label forwarding entries appropriately */
2182 ret
= fec_change_update_lsp(zvrf
, fec
, old_label
);
2189 * Remove static FEC to label binding. If there are no clients registered
2190 * for this FEC, delete the FEC; else notify clients
2191 * Note: Upon delete of static binding, if label index exists for this FEC,
2192 * client may need to be updated with derived label.
2194 int zebra_mpls_static_fec_del(struct zebra_vrf
*zvrf
, struct prefix
*p
)
2196 struct route_table
*table
;
2198 mpls_label_t old_label
;
2201 table
= zvrf
->fec_table
[family2afi(PREFIX_FAMILY(p
))];
2205 fec
= fec_find(table
, p
);
2207 prefix2str(p
, buf
, BUFSIZ
);
2208 flog_err(EC_ZEBRA_FEC_RM_FAILED
,
2209 "Failed to find FEC %s upon delete", buf
);
2213 if (IS_ZEBRA_DEBUG_MPLS
) {
2214 prefix2str(p
, buf
, BUFSIZ
);
2215 zlog_debug("Delete fec %s label %u label index %u", buf
,
2216 fec
->label
, fec
->label_index
);
2219 old_label
= fec
->label
;
2220 fec
->flags
&= ~FEC_FLAG_CONFIGURED
;
2221 fec
->label
= MPLS_INVALID_LABEL
;
2223 /* If no client exists, just delete the FEC. */
2224 if (list_isempty(fec
->client_list
)) {
2229 /* Derive the local label (from label index) or reset it. */
2230 fec_derive_label_from_index(zvrf
, fec
);
2232 /* If there is a label change, update clients. */
2233 if (fec
->label
== old_label
)
2235 fec_update_clients(fec
);
2237 /* Update label forwarding entries appropriately */
2238 return fec_change_update_lsp(zvrf
, fec
, old_label
);
2242 * Display MPLS FEC to label binding configuration (VTY command handler).
2244 int zebra_mpls_write_fec_config(struct vty
*vty
, struct zebra_vrf
*zvrf
)
2246 struct route_node
*rn
;
2252 for (af
= AFI_IP
; af
< AFI_MAX
; af
++) {
2253 if (zvrf
->fec_table
[af
] == NULL
)
2256 for (rn
= route_top(zvrf
->fec_table
[af
]); rn
;
2257 rn
= route_next(rn
)) {
2264 if (!(fec
->flags
& FEC_FLAG_CONFIGURED
))
2268 prefix2str(&rn
->p
, buf
, BUFSIZ
);
2269 vty_out(vty
, "mpls label bind %s %s\n", buf
,
2270 label2str(fec
->label
, lstr
, BUFSIZ
));
2278 * Display MPLS FEC to label binding (VTY command handler).
2280 void zebra_mpls_print_fec_table(struct vty
*vty
, struct zebra_vrf
*zvrf
)
2282 struct route_node
*rn
;
2285 for (af
= AFI_IP
; af
< AFI_MAX
; af
++) {
2286 if (zvrf
->fec_table
[af
] == NULL
)
2289 for (rn
= route_top(zvrf
->fec_table
[af
]); rn
;
2290 rn
= route_next(rn
)) {
2293 fec_print(rn
->info
, vty
);
2299 * Display MPLS FEC to label binding for a specific FEC (VTY command handler).
2301 void zebra_mpls_print_fec(struct vty
*vty
, struct zebra_vrf
*zvrf
,
2304 struct route_table
*table
;
2305 struct route_node
*rn
;
2307 table
= zvrf
->fec_table
[family2afi(PREFIX_FAMILY(p
))];
2312 rn
= route_node_lookup(table
, p
);
2316 route_unlock_node(rn
);
2320 fec_print(rn
->info
, vty
);
2323 static bool mpls_ftn_update_nexthop(int add
, struct nexthop
*nexthop
,
2324 enum lsp_types_t type
, mpls_label_t label
)
2326 if (add
&& nexthop
->nh_label_type
== ZEBRA_LSP_NONE
)
2327 nexthop_add_labels(nexthop
, type
, 1, &label
);
2328 else if (!add
&& nexthop
->nh_label_type
== type
)
2329 nexthop_del_labels(nexthop
);
2337 * Install/uninstall a FEC-To-NHLFE (FTN) binding.
2339 int mpls_ftn_update(int add
, struct zebra_vrf
*zvrf
, enum lsp_types_t type
,
2340 struct prefix
*prefix
, enum nexthop_types_t gtype
,
2341 union g_addr
*gate
, ifindex_t ifindex
, uint8_t distance
,
2342 mpls_label_t out_label
)
2344 struct route_table
*table
;
2345 struct route_node
*rn
;
2346 struct route_entry
*re
;
2347 struct nexthop
*nexthop
;
2351 table
= zebra_vrf_table(family2afi(prefix
->family
), SAFI_UNICAST
,
2356 /* Lookup existing route */
2357 rn
= route_node_get(table
, prefix
);
2358 RNODE_FOREACH_RE (rn
, re
) {
2359 if (CHECK_FLAG(re
->status
, ROUTE_ENTRY_REMOVED
))
2361 if (re
->distance
== distance
)
2369 for (nexthop
= re
->ng
.nexthop
; nexthop
; nexthop
= nexthop
->next
) {
2370 switch (nexthop
->type
) {
2371 case NEXTHOP_TYPE_IPV4
:
2372 case NEXTHOP_TYPE_IPV4_IFINDEX
:
2373 if (gtype
!= NEXTHOP_TYPE_IPV4
2374 && gtype
!= NEXTHOP_TYPE_IPV4_IFINDEX
)
2376 if (!IPV4_ADDR_SAME(&nexthop
->gate
.ipv4
, &gate
->ipv4
))
2378 if (nexthop
->type
== NEXTHOP_TYPE_IPV4_IFINDEX
2379 && nexthop
->ifindex
!= ifindex
)
2381 if (!mpls_ftn_update_nexthop(add
, nexthop
, type
,
2386 case NEXTHOP_TYPE_IPV6
:
2387 case NEXTHOP_TYPE_IPV6_IFINDEX
:
2388 if (gtype
!= NEXTHOP_TYPE_IPV6
2389 && gtype
!= NEXTHOP_TYPE_IPV6_IFINDEX
)
2391 if (!IPV6_ADDR_SAME(&nexthop
->gate
.ipv6
, &gate
->ipv6
))
2393 if (nexthop
->type
== NEXTHOP_TYPE_IPV6_IFINDEX
2394 && nexthop
->ifindex
!= ifindex
)
2396 if (!mpls_ftn_update_nexthop(add
, nexthop
, type
,
2409 SET_FLAG(re
->status
, ROUTE_ENTRY_CHANGED
);
2410 SET_FLAG(re
->status
, ROUTE_ENTRY_LABELS_CHANGED
);
2417 * Install/update a NHLFE for an LSP in the forwarding table. This may be
2418 * a new LSP entry or a new NHLFE for an existing in-label or an update of
2419 * the out-label for an existing NHLFE (update case).
2421 int mpls_lsp_install(struct zebra_vrf
*zvrf
, enum lsp_types_t type
,
2422 mpls_label_t in_label
, mpls_label_t out_label
,
2423 enum nexthop_types_t gtype
, union g_addr
*gate
,
2426 struct hash
*lsp_table
;
2427 zebra_ile_t tmp_ile
;
2429 zebra_nhlfe_t
*nhlfe
;
2433 lsp_table
= zvrf
->lsp_table
;
2437 /* If entry is present, exit. */
2438 tmp_ile
.in_label
= in_label
;
2439 lsp
= hash_get(lsp_table
, &tmp_ile
, lsp_alloc
);
2442 nhlfe
= nhlfe_find(lsp
, type
, gtype
, gate
, ifindex
);
2444 struct nexthop
*nh
= nhlfe
->nexthop
;
2447 assert(nh
->nh_label
);
2449 /* Clear deleted flag (in case it was set) */
2450 UNSET_FLAG(nhlfe
->flags
, NHLFE_FLAG_DELETED
);
2451 if (nh
->nh_label
->label
[0] == out_label
)
2455 if (IS_ZEBRA_DEBUG_MPLS
) {
2456 nhlfe2str(nhlfe
, buf
, BUFSIZ
);
2458 "LSP in-label %u type %d nexthop %s "
2459 "out-label changed to %u (old %u)",
2460 in_label
, type
, buf
, out_label
,
2461 nh
->nh_label
->label
[0]);
2464 /* Update out label, trigger processing. */
2465 nh
->nh_label
->label
[0] = out_label
;
2467 /* Add LSP entry to this nexthop */
2468 nhlfe
= nhlfe_add(lsp
, type
, gtype
, gate
, ifindex
, out_label
);
2472 if (IS_ZEBRA_DEBUG_MPLS
) {
2473 nhlfe2str(nhlfe
, buf
, BUFSIZ
);
2475 "Add LSP in-label %u type %d nexthop %s "
2477 in_label
, type
, buf
, out_label
);
2480 lsp
->addr_family
= NHLFE_FAMILY(nhlfe
);
2483 /* Mark NHLFE, queue LSP for processing. */
2484 SET_FLAG(nhlfe
->flags
, NHLFE_FLAG_CHANGED
);
2485 if (lsp_processq_add(lsp
))
2492 * Uninstall a particular NHLFE in the forwarding table. If this is
2493 * the only NHLFE, the entire LSP forwarding entry has to be deleted.
2495 int mpls_lsp_uninstall(struct zebra_vrf
*zvrf
, enum lsp_types_t type
,
2496 mpls_label_t in_label
, enum nexthop_types_t gtype
,
2497 union g_addr
*gate
, ifindex_t ifindex
)
2499 struct hash
*lsp_table
;
2500 zebra_ile_t tmp_ile
;
2502 zebra_nhlfe_t
*nhlfe
;
2506 lsp_table
= zvrf
->lsp_table
;
2510 /* If entry is not present, exit. */
2511 tmp_ile
.in_label
= in_label
;
2512 lsp
= hash_lookup(lsp_table
, &tmp_ile
);
2515 nhlfe
= nhlfe_find(lsp
, type
, gtype
, gate
, ifindex
);
2519 if (IS_ZEBRA_DEBUG_MPLS
) {
2520 nhlfe2str(nhlfe
, buf
, BUFSIZ
);
2521 zlog_debug("Del LSP in-label %u type %d nexthop %s flags 0x%x",
2522 in_label
, type
, buf
, nhlfe
->flags
);
2525 /* Mark NHLFE for delete or directly delete, as appropriate. */
2526 if (CHECK_FLAG(nhlfe
->flags
, NHLFE_FLAG_INSTALLED
)) {
2527 UNSET_FLAG(nhlfe
->flags
, NHLFE_FLAG_CHANGED
);
2528 SET_FLAG(nhlfe
->flags
, NHLFE_FLAG_DELETED
);
2529 if (lsp_processq_add(lsp
))
2534 /* Free LSP entry if no other NHLFEs and not scheduled. */
2535 if (!lsp
->nhlfe_list
2536 && !CHECK_FLAG(lsp
->flags
, LSP_FLAG_SCHEDULED
)) {
2537 if (IS_ZEBRA_DEBUG_MPLS
)
2538 zlog_debug("Free LSP in-label %u flags 0x%x",
2539 lsp
->ile
.in_label
, lsp
->flags
);
2541 lsp
= hash_release(lsp_table
, &lsp
->ile
);
2543 XFREE(MTYPE_LSP
, lsp
);
2550 * Uninstall all LDP NHLFEs for a particular LSP forwarding entry.
2551 * If no other NHLFEs exist, the entry would be deleted.
2553 void mpls_ldp_lsp_uninstall_all(struct hash_backet
*backet
, void *ctxt
)
2556 struct hash
*lsp_table
;
2558 lsp
= (zebra_lsp_t
*)backet
->data
;
2559 if (!lsp
->nhlfe_list
)
2566 mpls_lsp_uninstall_all(lsp_table
, lsp
, ZEBRA_LSP_LDP
);
2570 * Uninstall all LDP FEC-To-NHLFE (FTN) bindings of the given address-family.
2572 void mpls_ldp_ftn_uninstall_all(struct zebra_vrf
*zvrf
, int afi
)
2574 struct route_table
*table
;
2575 struct route_node
*rn
;
2576 struct route_entry
*re
;
2577 struct nexthop
*nexthop
;
2580 /* Process routes of interested address-families. */
2581 table
= zebra_vrf_table(afi
, SAFI_UNICAST
, zvrf_id(zvrf
));
2585 for (rn
= route_top(table
); rn
; rn
= route_next(rn
)) {
2587 RNODE_FOREACH_RE (rn
, re
) {
2588 for (nexthop
= re
->ng
.nexthop
; nexthop
;
2589 nexthop
= nexthop
->next
) {
2590 if (nexthop
->nh_label_type
!= ZEBRA_LSP_LDP
)
2593 nexthop_del_labels(nexthop
);
2594 SET_FLAG(re
->status
, ROUTE_ENTRY_CHANGED
);
2595 SET_FLAG(re
->status
,
2596 ROUTE_ENTRY_LABELS_CHANGED
);
2606 #if defined(HAVE_CUMULUS)
2608 * Check that the label values used in LSP creation are consistent. The
2609 * main criteria is that if there is ECMP, the label operation must still
2610 * be consistent - i.e., all paths either do a swap or do PHP. This is due
2611 * to current HW restrictions.
2613 int zebra_mpls_lsp_label_consistent(struct zebra_vrf
*zvrf
,
2614 mpls_label_t in_label
,
2615 mpls_label_t out_label
,
2616 enum nexthop_types_t gtype
,
2617 union g_addr
*gate
, ifindex_t ifindex
)
2619 struct hash
*slsp_table
;
2620 zebra_ile_t tmp_ile
;
2622 zebra_snhlfe_t
*snhlfe
;
2625 slsp_table
= zvrf
->slsp_table
;
2629 /* If entry is not present, exit. */
2630 tmp_ile
.in_label
= in_label
;
2631 slsp
= hash_lookup(slsp_table
, &tmp_ile
);
2635 snhlfe
= snhlfe_find(slsp
, gtype
, gate
, ifindex
);
2637 if (snhlfe
->out_label
== out_label
)
2640 /* If not only NHLFE, cannot allow label change. */
2641 if (snhlfe
!= slsp
->snhlfe_list
|| snhlfe
->next
)
2644 /* If other NHLFEs exist, label operation must match. */
2645 if (slsp
->snhlfe_list
) {
2648 cur_op
= (slsp
->snhlfe_list
->out_label
2649 == MPLS_LABEL_IMPLICIT_NULL
);
2650 new_op
= (out_label
== MPLS_LABEL_IMPLICIT_NULL
);
2651 if (cur_op
!= new_op
)
2656 /* Label values are good. */
2659 #endif /* HAVE_CUMULUS */
2662 * Add static LSP entry. This may be the first entry for this incoming label
2663 * or an additional nexthop; an existing entry may also have outgoing label
2665 * Note: The label operation (swap or PHP) is common for the LSP entry (all
2668 int zebra_mpls_static_lsp_add(struct zebra_vrf
*zvrf
, mpls_label_t in_label
,
2669 mpls_label_t out_label
,
2670 enum nexthop_types_t gtype
, union g_addr
*gate
,
2673 struct hash
*slsp_table
;
2674 zebra_ile_t tmp_ile
;
2676 zebra_snhlfe_t
*snhlfe
;
2680 slsp_table
= zvrf
->slsp_table
;
2684 /* If entry is present, exit. */
2685 tmp_ile
.in_label
= in_label
;
2686 slsp
= hash_get(slsp_table
, &tmp_ile
, slsp_alloc
);
2689 snhlfe
= snhlfe_find(slsp
, gtype
, gate
, ifindex
);
2691 if (snhlfe
->out_label
== out_label
)
2695 if (IS_ZEBRA_DEBUG_MPLS
) {
2696 snhlfe2str(snhlfe
, buf
, BUFSIZ
);
2698 "Upd static LSP in-label %u nexthop %s "
2699 "out-label %u (old %u)",
2700 in_label
, buf
, out_label
, snhlfe
->out_label
);
2702 snhlfe
->out_label
= out_label
;
2704 /* Add static LSP entry to this nexthop */
2705 snhlfe
= snhlfe_add(slsp
, gtype
, gate
, ifindex
, out_label
);
2709 if (IS_ZEBRA_DEBUG_MPLS
) {
2710 snhlfe2str(snhlfe
, buf
, BUFSIZ
);
2712 "Add static LSP in-label %u nexthop %s out-label %u",
2713 in_label
, buf
, out_label
);
2717 /* (Re)Install LSP in the main table. */
2718 if (mpls_lsp_install(zvrf
, ZEBRA_LSP_STATIC
, in_label
, out_label
, gtype
,
2726 * Delete static LSP entry. This may be the delete of one particular
2727 * NHLFE for this incoming label or the delete of the entire entry (i.e.,
2729 * NOTE: Delete of the only NHLFE will also end up deleting the entire
2730 * LSP configuration.
2732 int zebra_mpls_static_lsp_del(struct zebra_vrf
*zvrf
, mpls_label_t in_label
,
2733 enum nexthop_types_t gtype
, union g_addr
*gate
,
2736 struct hash
*slsp_table
;
2737 zebra_ile_t tmp_ile
;
2739 zebra_snhlfe_t
*snhlfe
;
2742 slsp_table
= zvrf
->slsp_table
;
2746 /* If entry is not present, exit. */
2747 tmp_ile
.in_label
= in_label
;
2748 slsp
= hash_lookup(slsp_table
, &tmp_ile
);
2752 /* Is it delete of entire LSP or a specific NHLFE? */
2753 if (gtype
== NEXTHOP_TYPE_BLACKHOLE
) {
2754 if (IS_ZEBRA_DEBUG_MPLS
)
2755 zlog_debug("Del static LSP in-label %u", in_label
);
2757 /* Uninstall entire LSP from the main table. */
2758 mpls_static_lsp_uninstall_all(zvrf
, in_label
);
2760 /* Delete all static NHLFEs */
2761 snhlfe_del_all(slsp
);
2763 /* Find specific NHLFE, exit if not found. */
2764 snhlfe
= snhlfe_find(slsp
, gtype
, gate
, ifindex
);
2768 if (IS_ZEBRA_DEBUG_MPLS
) {
2770 snhlfe2str(snhlfe
, buf
, BUFSIZ
);
2771 zlog_debug("Del static LSP in-label %u nexthop %s",
2775 /* Uninstall LSP from the main table. */
2776 mpls_lsp_uninstall(zvrf
, ZEBRA_LSP_STATIC
, in_label
, gtype
,
2779 /* Delete static LSP NHLFE */
2783 /* Remove entire static LSP entry if no NHLFE - valid in either case
2785 if (!slsp
->snhlfe_list
) {
2786 slsp
= hash_release(slsp_table
, &tmp_ile
);
2788 XFREE(MTYPE_SLSP
, slsp
);
2795 * Schedule all MPLS label forwarding entries for processing.
2796 * Called upon changes that may affect one or more of them such as
2797 * interface or nexthop state changes.
2799 void zebra_mpls_lsp_schedule(struct zebra_vrf
*zvrf
)
2803 hash_iterate(zvrf
->lsp_table
, lsp_schedule
, NULL
);
2807 * Display MPLS label forwarding table for a specific LSP
2808 * (VTY command handler).
2810 void zebra_mpls_print_lsp(struct vty
*vty
, struct zebra_vrf
*zvrf
,
2811 mpls_label_t label
, bool use_json
)
2813 struct hash
*lsp_table
;
2815 zebra_ile_t tmp_ile
;
2816 json_object
*json
= NULL
;
2819 lsp_table
= zvrf
->lsp_table
;
2823 /* If entry is not present, exit. */
2824 tmp_ile
.in_label
= label
;
2825 lsp
= hash_lookup(lsp_table
, &tmp_ile
);
2830 json
= lsp_json(lsp
);
2831 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
2832 json
, JSON_C_TO_STRING_PRETTY
));
2833 json_object_free(json
);
2835 lsp_print(lsp
, (void *)vty
);
2839 * Display MPLS label forwarding table (VTY command handler).
2841 void zebra_mpls_print_lsp_table(struct vty
*vty
, struct zebra_vrf
*zvrf
,
2845 json_object
*json
= NULL
;
2846 zebra_lsp_t
*lsp
= NULL
;
2847 zebra_nhlfe_t
*nhlfe
= NULL
;
2848 struct nexthop
*nexthop
= NULL
;
2849 struct listnode
*node
= NULL
;
2850 struct list
*lsp_list
= hash_get_sorted_list(zvrf
->lsp_table
, lsp_cmp
);
2853 json
= json_object_new_object();
2855 for (ALL_LIST_ELEMENTS_RO(lsp_list
, node
, lsp
))
2856 json_object_object_add(
2857 json
, label2str(lsp
->ile
.in_label
, buf
, BUFSIZ
),
2860 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
2861 json
, JSON_C_TO_STRING_PRETTY
));
2862 json_object_free(json
);
2864 vty_out(vty
, " Inbound Outbound\n");
2865 vty_out(vty
, " Label Type Nexthop Label\n");
2866 vty_out(vty
, "-------- ------- --------------- --------\n");
2868 for (ALL_LIST_ELEMENTS_RO(lsp_list
, node
, lsp
)) {
2869 for (nhlfe
= lsp
->nhlfe_list
; nhlfe
;
2870 nhlfe
= nhlfe
->next
) {
2871 vty_out(vty
, "%8d %7s ", lsp
->ile
.in_label
,
2872 nhlfe_type2str(nhlfe
->type
));
2873 nexthop
= nhlfe
->nexthop
;
2875 switch (nexthop
->type
) {
2876 case NEXTHOP_TYPE_IFINDEX
: {
2877 struct zebra_ns
*zns
;
2878 struct interface
*ifp
;
2880 zns
= zebra_ns_lookup(NS_DEFAULT
);
2881 ifp
= if_lookup_by_index_per_ns(
2884 vty_out(vty
, "%15s", ifp
->name
);
2887 case NEXTHOP_TYPE_IPV4
:
2888 case NEXTHOP_TYPE_IPV4_IFINDEX
:
2889 vty_out(vty
, "%15s",
2890 inet_ntoa(nexthop
->gate
.ipv4
));
2892 case NEXTHOP_TYPE_IPV6
:
2893 case NEXTHOP_TYPE_IPV6_IFINDEX
:
2894 vty_out(vty
, "%15s",
2896 &nexthop
->gate
.ipv6
,
2903 if (nexthop
->type
!= NEXTHOP_TYPE_IFINDEX
)
2904 vty_out(vty
, " %8s\n",
2919 list_delete(&lsp_list
);
2923 * Display MPLS LSP configuration of all static LSPs (VTY command handler).
2925 int zebra_mpls_write_lsp_config(struct vty
*vty
, struct zebra_vrf
*zvrf
)
2928 zebra_snhlfe_t
*snhlfe
;
2929 struct listnode
*node
;
2930 struct list
*slsp_list
=
2931 hash_get_sorted_list(zvrf
->slsp_table
, slsp_cmp
);
2933 for (ALL_LIST_ELEMENTS_RO(slsp_list
, node
, slsp
)) {
2934 for (snhlfe
= slsp
->snhlfe_list
; snhlfe
;
2935 snhlfe
= snhlfe
->next
) {
2939 snhlfe2str(snhlfe
, buf
, sizeof(buf
));
2940 switch (snhlfe
->out_label
) {
2941 case MPLS_LABEL_IPV4_EXPLICIT_NULL
:
2942 case MPLS_LABEL_IPV6_EXPLICIT_NULL
:
2943 strlcpy(lstr
, "explicit-null", sizeof(lstr
));
2945 case MPLS_LABEL_IMPLICIT_NULL
:
2946 strlcpy(lstr
, "implicit-null", sizeof(lstr
));
2949 sprintf(lstr
, "%u", snhlfe
->out_label
);
2953 vty_out(vty
, "mpls lsp %u %s %s\n", slsp
->ile
.in_label
,
2958 list_delete(&slsp_list
);
2959 return (zvrf
->slsp_table
->count
? 1 : 0);
2963 * Add/update global label block.
2965 int zebra_mpls_label_block_add(struct zebra_vrf
*zvrf
, uint32_t start_label
,
2968 zvrf
->mpls_srgb
.start_label
= start_label
;
2969 zvrf
->mpls_srgb
.end_label
= end_label
;
2971 /* Evaluate registered FECs to see if any get a label or not. */
2977 * Delete global label block.
2979 int zebra_mpls_label_block_del(struct zebra_vrf
*zvrf
)
2981 zvrf
->mpls_srgb
.start_label
= MPLS_DEFAULT_MIN_SRGB_LABEL
;
2982 zvrf
->mpls_srgb
.end_label
= MPLS_DEFAULT_MAX_SRGB_LABEL
;
2984 /* Process registered FECs to clear their local label, if needed. */
2990 * Display MPLS global label block configuration (VTY command handler).
2992 int zebra_mpls_write_label_block_config(struct vty
*vty
, struct zebra_vrf
*zvrf
)
2994 if (zvrf
->mpls_srgb
.start_label
== 0)
2997 if ((zvrf
->mpls_srgb
.start_label
!= MPLS_DEFAULT_MIN_SRGB_LABEL
)
2998 || (zvrf
->mpls_srgb
.end_label
!= MPLS_DEFAULT_MAX_SRGB_LABEL
)) {
2999 vty_out(vty
, "mpls label global-block %u %u\n",
3000 zvrf
->mpls_srgb
.start_label
, zvrf
->mpls_srgb
.end_label
);
3007 * Called when VRF becomes inactive, cleans up information but keeps
3009 * NOTE: Currently supported only for default VRF.
3011 void zebra_mpls_cleanup_tables(struct zebra_vrf
*zvrf
)
3013 hash_iterate(zvrf
->lsp_table
, lsp_uninstall_from_kernel
, NULL
);
3017 * Called upon process exiting, need to delete LSP forwarding
3018 * entries from the kernel.
3019 * NOTE: Currently supported only for default VRF.
3021 void zebra_mpls_close_tables(struct zebra_vrf
*zvrf
)
3023 hash_iterate(zvrf
->lsp_table
, lsp_uninstall_from_kernel
, NULL
);
3024 hash_clean(zvrf
->lsp_table
, NULL
);
3025 hash_free(zvrf
->lsp_table
);
3026 hash_clean(zvrf
->slsp_table
, NULL
);
3027 hash_free(zvrf
->slsp_table
);
3028 route_table_finish(zvrf
->fec_table
[AFI_IP
]);
3029 route_table_finish(zvrf
->fec_table
[AFI_IP6
]);
3033 * Allocate MPLS tables for this VRF and do other initialization.
3034 * NOTE: Currently supported only for default VRF.
3036 void zebra_mpls_init_tables(struct zebra_vrf
*zvrf
)
3041 hash_create(label_hash
, label_cmp
, "ZEBRA SLSP table");
3042 zvrf
->lsp_table
= hash_create(label_hash
, label_cmp
, "ZEBRA LSP table");
3043 zvrf
->fec_table
[AFI_IP
] = route_table_init();
3044 zvrf
->fec_table
[AFI_IP6
] = route_table_init();
3045 zvrf
->mpls_flags
= 0;
3046 zvrf
->mpls_srgb
.start_label
= MPLS_DEFAULT_MIN_SRGB_LABEL
;
3047 zvrf
->mpls_srgb
.end_label
= MPLS_DEFAULT_MAX_SRGB_LABEL
;
3051 * Global MPLS initialization.
3053 void zebra_mpls_init(void)
3057 if (mpls_kernel_init() < 0) {
3058 flog_warn(EC_ZEBRA_MPLS_SUPPORT_DISABLED
,
3059 "Disabling MPLS support (no kernel support)");
3063 if (!mpls_processq_init())
3066 hook_register(zserv_client_close
, zebra_mpls_cleanup_fecs_for_client
);