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_bucket
*bucket
, void *ctxt
);
89 static void lsp_schedule(struct hash_bucket
*bucket
, 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
);
252 XFREE(MTYPE_LSP
, lsp
);
259 * Uninstall all non-static NHLFEs of a label forwarding entry. If all
260 * NHLFEs are removed, the entire entry is deleted.
262 static int lsp_uninstall(struct zebra_vrf
*zvrf
, mpls_label_t label
)
264 struct hash
*lsp_table
;
267 zebra_nhlfe_t
*nhlfe
, *nhlfe_next
;
271 lsp_table
= zvrf
->lsp_table
;
275 /* If entry is not present, exit. */
276 tmp_ile
.in_label
= label
;
277 lsp
= hash_lookup(lsp_table
, &tmp_ile
);
278 if (!lsp
|| !lsp
->nhlfe_list
)
281 /* Mark NHLFEs for delete or directly delete, as appropriate. */
282 for (nhlfe
= lsp
->nhlfe_list
; nhlfe
; nhlfe
= nhlfe_next
) {
283 nhlfe_next
= nhlfe
->next
;
285 /* Skip static NHLFEs */
286 if (nhlfe
->type
== ZEBRA_LSP_STATIC
)
289 if (IS_ZEBRA_DEBUG_MPLS
) {
290 nhlfe2str(nhlfe
, buf
, BUFSIZ
);
292 "Del LSP in-label %u type %d nexthop %s flags 0x%x",
293 label
, nhlfe
->type
, buf
, nhlfe
->flags
);
296 if (CHECK_FLAG(nhlfe
->flags
, NHLFE_FLAG_SELECTED
)) {
297 UNSET_FLAG(nhlfe
->flags
, NHLFE_FLAG_CHANGED
);
298 SET_FLAG(nhlfe
->flags
, NHLFE_FLAG_DELETED
);
304 /* Queue LSP for processing, if needed, else delete. */
305 if (CHECK_FLAG(lsp
->flags
, LSP_FLAG_INSTALLED
)) {
306 if (lsp_processq_add(lsp
))
308 } else if (!lsp
->nhlfe_list
309 && !CHECK_FLAG(lsp
->flags
, LSP_FLAG_SCHEDULED
)) {
310 if (IS_ZEBRA_DEBUG_MPLS
)
311 zlog_debug("Del LSP in-label %u flags 0x%x",
312 lsp
->ile
.in_label
, lsp
->flags
);
314 lsp
= hash_release(lsp_table
, &lsp
->ile
);
315 XFREE(MTYPE_LSP
, lsp
);
322 * This function is invoked upon change to label block configuration; it
323 * will walk all registered FECs with label-index and appropriately update
324 * their local labels and trigger client updates.
326 static void fec_evaluate(struct zebra_vrf
*zvrf
)
328 struct route_node
*rn
;
330 uint32_t old_label
, new_label
;
334 for (af
= AFI_IP
; af
< AFI_MAX
; af
++) {
335 if (zvrf
->fec_table
[af
] == NULL
)
338 for (rn
= route_top(zvrf
->fec_table
[af
]); rn
;
339 rn
= route_next(rn
)) {
340 if ((fec
= rn
->info
) == NULL
)
343 /* Skip configured FECs and those without a label index.
345 if (fec
->flags
& FEC_FLAG_CONFIGURED
346 || fec
->label_index
== MPLS_INVALID_LABEL_INDEX
)
349 if (IS_ZEBRA_DEBUG_MPLS
)
350 prefix2str(&rn
->p
, buf
, BUFSIZ
);
352 /* Save old label, determine new label. */
353 old_label
= fec
->label
;
355 zvrf
->mpls_srgb
.start_label
+ fec
->label_index
;
356 if (new_label
>= zvrf
->mpls_srgb
.end_label
)
357 new_label
= MPLS_INVALID_LABEL
;
359 /* If label has changed, update FEC and clients. */
360 if (new_label
== old_label
)
363 if (IS_ZEBRA_DEBUG_MPLS
)
365 "Update fec %s new label %u upon label block",
368 fec
->label
= new_label
;
369 fec_update_clients(fec
);
371 /* Update label forwarding entries appropriately */
372 fec_change_update_lsp(zvrf
, fec
, old_label
);
378 * Derive (if possible) and update the local label for the FEC based on
379 * its label index. The index is "acceptable" if it falls within the
380 * globally configured label block (SRGB).
382 static uint32_t fec_derive_label_from_index(struct zebra_vrf
*zvrf
,
387 if (fec
->label_index
!= MPLS_INVALID_LABEL_INDEX
388 && zvrf
->mpls_srgb
.start_label
389 && ((label
= zvrf
->mpls_srgb
.start_label
+ fec
->label_index
)
390 < zvrf
->mpls_srgb
.end_label
))
393 fec
->label
= MPLS_INVALID_LABEL
;
399 * There is a change for this FEC. Install or uninstall label forwarding
400 * entries, as appropriate.
402 static int fec_change_update_lsp(struct zebra_vrf
*zvrf
, zebra_fec_t
*fec
,
403 mpls_label_t old_label
)
405 struct route_table
*table
;
406 struct route_node
*rn
;
407 struct route_entry
*re
;
410 /* Uninstall label forwarding entry, if previously installed. */
411 if (old_label
!= MPLS_INVALID_LABEL
412 && old_label
!= MPLS_LABEL_IMPLICIT_NULL
)
413 lsp_uninstall(zvrf
, old_label
);
415 /* Install label forwarding entry corr. to new label, if needed. */
416 if (fec
->label
== MPLS_INVALID_LABEL
417 || fec
->label
== MPLS_LABEL_IMPLICIT_NULL
)
420 afi
= family2afi(PREFIX_FAMILY(&fec
->rn
->p
));
421 table
= zebra_vrf_table(afi
, SAFI_UNICAST
, zvrf_id(zvrf
));
425 /* See if labeled route exists. */
426 rn
= route_node_lookup(table
, &fec
->rn
->p
);
430 RNODE_FOREACH_RE (rn
, re
) {
431 if (CHECK_FLAG(re
->flags
, ZEBRA_FLAG_SELECTED
))
435 if (!re
|| !zebra_rib_labeled_unicast(re
))
438 if (lsp_install(zvrf
, fec
->label
, rn
, re
))
445 * Inform about FEC to a registered client.
447 static int fec_send(zebra_fec_t
*fec
, struct zserv
*client
)
450 struct route_node
*rn
;
454 /* Get output stream. */
455 s
= stream_new(ZEBRA_MAX_PACKET_SIZ
);
457 zclient_create_header(s
, ZEBRA_FEC_UPDATE
, VRF_DEFAULT
);
459 stream_putw(s
, rn
->p
.family
);
460 stream_put_prefix(s
, &rn
->p
);
461 stream_putl(s
, fec
->label
);
462 stream_putw_at(s
, 0, stream_get_endp(s
));
463 return zserv_send_message(client
, s
);
467 * Update all registered clients about this FEC. Caller should've updated
468 * FEC and ensure no duplicate updates.
470 static void fec_update_clients(zebra_fec_t
*fec
)
472 struct listnode
*node
;
473 struct zserv
*client
;
475 for (ALL_LIST_ELEMENTS_RO(fec
->client_list
, node
, client
)) {
476 if (IS_ZEBRA_DEBUG_MPLS
)
477 zlog_debug("Update client %s",
478 zebra_route_string(client
->proto
));
479 fec_send(fec
, client
);
485 * Print a FEC-label binding entry.
487 static void fec_print(zebra_fec_t
*fec
, struct vty
*vty
)
489 struct route_node
*rn
;
490 struct listnode
*node
;
491 struct zserv
*client
;
495 prefix2str(&rn
->p
, buf
, BUFSIZ
);
496 vty_out(vty
, "%s\n", buf
);
497 vty_out(vty
, " Label: %s", label2str(fec
->label
, buf
, BUFSIZ
));
498 if (fec
->label_index
!= MPLS_INVALID_LABEL_INDEX
)
499 vty_out(vty
, ", Label Index: %u", fec
->label_index
);
501 if (!list_isempty(fec
->client_list
)) {
502 vty_out(vty
, " Client list:");
503 for (ALL_LIST_ELEMENTS_RO(fec
->client_list
, node
, client
))
504 vty_out(vty
, " %s(fd %d)",
505 zebra_route_string(client
->proto
),
512 * Locate FEC-label binding that matches with passed info.
514 static zebra_fec_t
*fec_find(struct route_table
*table
, struct prefix
*p
)
516 struct route_node
*rn
;
519 rn
= route_node_lookup(table
, p
);
523 route_unlock_node(rn
);
528 * Add a FEC. This may be upon a client registering for a binding
529 * or when a binding is configured.
531 static zebra_fec_t
*fec_add(struct route_table
*table
, struct prefix
*p
,
532 mpls_label_t label
, uint32_t flags
,
533 uint32_t label_index
)
535 struct route_node
*rn
;
540 /* Lookup (or add) route node.*/
541 rn
= route_node_get(table
, p
);
548 fec
= XCALLOC(MTYPE_FEC
, sizeof(zebra_fec_t
));
553 fec
->client_list
= list_new();
555 route_unlock_node(rn
); /* for the route_node_get */
557 fec
->label_index
= label_index
;
564 * Delete a FEC. This may be upon the last client deregistering for
565 * a FEC and no binding exists or when the binding is deleted and there
566 * are no registered clients.
568 static int fec_del(zebra_fec_t
*fec
)
570 list_delete(&fec
->client_list
);
571 fec
->rn
->info
= NULL
;
572 route_unlock_node(fec
->rn
);
573 XFREE(MTYPE_FEC
, fec
);
578 * Hash function for label.
580 static unsigned int label_hash(void *p
)
582 const zebra_ile_t
*ile
= p
;
584 return (jhash_1word(ile
->in_label
, 0));
588 * Compare 2 LSP hash entries based on in-label.
590 static bool label_cmp(const void *p1
, const void *p2
)
592 const zebra_ile_t
*ile1
= p1
;
593 const zebra_ile_t
*ile2
= p2
;
595 return (ile1
->in_label
== ile2
->in_label
);
599 * Check if an IPv4 nexthop for a NHLFE is active. Update nexthop based on
601 * NOTE: Looking only for connected routes right now.
603 static int nhlfe_nexthop_active_ipv4(zebra_nhlfe_t
*nhlfe
,
604 struct nexthop
*nexthop
)
606 struct route_table
*table
;
607 struct prefix_ipv4 p
;
608 struct route_node
*rn
;
609 struct route_entry
*match
;
610 struct nexthop
*match_nh
;
612 table
= zebra_vrf_table(AFI_IP
, SAFI_UNICAST
, nexthop
->vrf_id
);
616 /* Lookup nexthop in IPv4 routing table. */
617 memset(&p
, 0, sizeof(struct prefix_ipv4
));
619 p
.prefixlen
= IPV4_MAX_PREFIXLEN
;
620 p
.prefix
= nexthop
->gate
.ipv4
;
622 rn
= route_node_match(table
, (struct prefix
*)&p
);
626 route_unlock_node(rn
);
628 /* Locate a valid connected route. */
629 RNODE_FOREACH_RE (rn
, match
) {
630 if (CHECK_FLAG(match
->status
, ROUTE_ENTRY_REMOVED
)
631 || !CHECK_FLAG(match
->flags
, ZEBRA_FLAG_SELECTED
))
634 for (match_nh
= match
->ng
.nexthop
; match_nh
;
635 match_nh
= match_nh
->next
) {
636 if (match
->type
== ZEBRA_ROUTE_CONNECT
637 || nexthop
->ifindex
== match_nh
->ifindex
) {
638 nexthop
->ifindex
= match_nh
->ifindex
;
649 * Check if an IPv6 nexthop for a NHLFE is active. Update nexthop based on
651 * NOTE: Looking only for connected routes right now.
653 static int nhlfe_nexthop_active_ipv6(zebra_nhlfe_t
*nhlfe
,
654 struct nexthop
*nexthop
)
656 struct route_table
*table
;
657 struct prefix_ipv6 p
;
658 struct route_node
*rn
;
659 struct route_entry
*match
;
661 table
= zebra_vrf_table(AFI_IP6
, SAFI_UNICAST
, nexthop
->vrf_id
);
665 /* Lookup nexthop in IPv6 routing table. */
666 memset(&p
, 0, sizeof(struct prefix_ipv6
));
668 p
.prefixlen
= IPV6_MAX_PREFIXLEN
;
669 p
.prefix
= nexthop
->gate
.ipv6
;
671 rn
= route_node_match(table
, (struct prefix
*)&p
);
675 route_unlock_node(rn
);
677 /* Locate a valid connected route. */
678 RNODE_FOREACH_RE (rn
, match
) {
679 if ((match
->type
== ZEBRA_ROUTE_CONNECT
)
680 && !CHECK_FLAG(match
->status
, ROUTE_ENTRY_REMOVED
)
681 && CHECK_FLAG(match
->flags
, ZEBRA_FLAG_SELECTED
))
685 if (!match
|| !match
->ng
.nexthop
)
688 nexthop
->ifindex
= match
->ng
.nexthop
->ifindex
;
694 * Check the nexthop reachability for a NHLFE and return if valid (reachable)
696 * NOTE: Each NHLFE points to only 1 nexthop.
698 static int nhlfe_nexthop_active(zebra_nhlfe_t
*nhlfe
)
700 struct nexthop
*nexthop
;
701 struct interface
*ifp
;
702 struct zebra_ns
*zns
;
704 nexthop
= nhlfe
->nexthop
;
705 if (!nexthop
) // unexpected
708 /* Check on nexthop based on type. */
709 switch (nexthop
->type
) {
710 case NEXTHOP_TYPE_IFINDEX
:
712 * Lookup if this type is special. The
713 * NEXTHOP_TYPE_IFINDEX is a pop and
714 * forward into a different table for
715 * processing. As such this ifindex
716 * passed to us may be a VRF device
717 * which will not be in the default
718 * VRF. So let's look in all of them
720 zns
= zebra_ns_lookup(NS_DEFAULT
);
721 ifp
= if_lookup_by_index_per_ns(zns
, nexthop
->ifindex
);
722 if (ifp
&& if_is_operative(ifp
))
723 SET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
);
725 UNSET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
);
727 case NEXTHOP_TYPE_IPV4
:
728 case NEXTHOP_TYPE_IPV4_IFINDEX
:
729 if (nhlfe_nexthop_active_ipv4(nhlfe
, nexthop
))
730 SET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
);
732 UNSET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
);
735 case NEXTHOP_TYPE_IPV6
:
736 if (nhlfe_nexthop_active_ipv6(nhlfe
, nexthop
))
737 SET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
);
739 UNSET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
);
742 case NEXTHOP_TYPE_IPV6_IFINDEX
:
743 if (IN6_IS_ADDR_LINKLOCAL(&nexthop
->gate
.ipv6
)) {
744 ifp
= if_lookup_by_index(nexthop
->ifindex
,
746 if (ifp
&& if_is_operative(ifp
))
747 SET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
);
749 UNSET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
);
751 if (nhlfe_nexthop_active_ipv6(nhlfe
, nexthop
))
752 SET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
);
754 UNSET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
);
762 return CHECK_FLAG(nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
);
766 * Walk through NHLFEs for a LSP forwarding entry, verify nexthop
767 * reachability and select the best. Multipath entries are also
768 * marked. This is invoked when an LSP scheduled for processing (due
769 * to some change) is examined.
771 static void lsp_select_best_nhlfe(zebra_lsp_t
*lsp
)
773 zebra_nhlfe_t
*nhlfe
;
775 struct nexthop
*nexthop
;
783 UNSET_FLAG(lsp
->flags
, LSP_FLAG_CHANGED
);
786 * First compute the best path, after checking nexthop status. We are
788 * concerned with non-deleted NHLFEs.
790 for (nhlfe
= lsp
->nhlfe_list
; nhlfe
; nhlfe
= nhlfe
->next
) {
791 /* Clear selection flags. */
792 UNSET_FLAG(nhlfe
->flags
,
793 (NHLFE_FLAG_SELECTED
| NHLFE_FLAG_MULTIPATH
));
795 if (!CHECK_FLAG(nhlfe
->flags
, NHLFE_FLAG_DELETED
)
796 && nhlfe_nexthop_active(nhlfe
)) {
797 if (!best
|| (nhlfe
->distance
< best
->distance
))
802 lsp
->best_nhlfe
= best
;
803 if (!lsp
->best_nhlfe
)
806 /* Mark best NHLFE as selected. */
807 SET_FLAG(lsp
->best_nhlfe
->flags
, NHLFE_FLAG_SELECTED
);
810 * If best path exists, see if there is ECMP. While doing this, note if
812 * new (uninstalled) NHLFE has been selected, an installed entry that is
813 * still selected has a change or an installed entry is to be removed.
815 for (nhlfe
= lsp
->nhlfe_list
; nhlfe
; nhlfe
= nhlfe
->next
) {
816 int nh_chg
, nh_sel
, nh_inst
;
818 nexthop
= nhlfe
->nexthop
;
819 if (!nexthop
) // unexpected
822 if (!CHECK_FLAG(nhlfe
->flags
, NHLFE_FLAG_DELETED
)
823 && CHECK_FLAG(nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
)
824 && (nhlfe
->distance
== lsp
->best_nhlfe
->distance
)) {
825 SET_FLAG(nhlfe
->flags
, NHLFE_FLAG_SELECTED
);
826 SET_FLAG(nhlfe
->flags
, NHLFE_FLAG_MULTIPATH
);
830 if (CHECK_FLAG(lsp
->flags
, LSP_FLAG_INSTALLED
) && !changed
) {
831 nh_chg
= CHECK_FLAG(nhlfe
->flags
, NHLFE_FLAG_CHANGED
);
832 nh_sel
= CHECK_FLAG(nhlfe
->flags
, NHLFE_FLAG_SELECTED
);
834 CHECK_FLAG(nhlfe
->flags
, NHLFE_FLAG_INSTALLED
);
836 if ((nh_sel
&& !nh_inst
)
837 || (nh_sel
&& nh_inst
&& nh_chg
)
838 || (nh_inst
&& !nh_sel
))
842 /* We have finished examining, clear changed flag. */
843 UNSET_FLAG(nhlfe
->flags
, NHLFE_FLAG_CHANGED
);
847 SET_FLAG(lsp
->flags
, LSP_FLAG_CHANGED
);
851 * Delete LSP forwarding entry from kernel, if installed. Called upon
854 static void lsp_uninstall_from_kernel(struct hash_bucket
*bucket
, void *ctxt
)
858 lsp
= (zebra_lsp_t
*)bucket
->data
;
859 if (CHECK_FLAG(lsp
->flags
, LSP_FLAG_INSTALLED
))
860 (void)dplane_lsp_delete(lsp
);
864 * Schedule LSP forwarding entry for processing. Called upon changes
865 * that may impact LSPs such as nexthop / connected route changes.
867 static void lsp_schedule(struct hash_bucket
*bucket
, void *ctxt
)
871 lsp
= (zebra_lsp_t
*)bucket
->data
;
872 (void)lsp_processq_add(lsp
);
876 * Process a LSP entry that is in the queue. Recalculate best NHLFE and
877 * any multipaths and update or delete from the kernel, as needed.
879 static wq_item_status
lsp_process(struct work_queue
*wq
, void *data
)
882 zebra_nhlfe_t
*oldbest
, *newbest
;
883 char buf
[BUFSIZ
], buf2
[BUFSIZ
];
884 struct zebra_vrf
*zvrf
= vrf_info_lookup(VRF_DEFAULT
);
885 enum zebra_dplane_result res
;
887 lsp
= (zebra_lsp_t
*)data
;
888 if (!lsp
) // unexpected
891 oldbest
= lsp
->best_nhlfe
;
893 /* Select best NHLFE(s) */
894 lsp_select_best_nhlfe(lsp
);
896 newbest
= lsp
->best_nhlfe
;
898 if (IS_ZEBRA_DEBUG_MPLS
) {
900 nhlfe2str(oldbest
, buf
, BUFSIZ
);
902 nhlfe2str(newbest
, buf2
, BUFSIZ
);
904 "Process LSP in-label %u oldbest %s newbest %s "
905 "flags 0x%x ecmp# %d",
906 lsp
->ile
.in_label
, oldbest
? buf
: "NULL",
907 newbest
? buf2
: "NULL", lsp
->flags
, lsp
->num_ecmp
);
910 if (!CHECK_FLAG(lsp
->flags
, LSP_FLAG_INSTALLED
)) {
911 /* Not already installed */
914 UNSET_FLAG(lsp
->flags
, LSP_FLAG_CHANGED
);
916 switch (dplane_lsp_add(lsp
)) {
917 case ZEBRA_DPLANE_REQUEST_QUEUED
:
918 /* Set 'installed' flag so we will know
919 * that an install is in-flight.
921 SET_FLAG(lsp
->flags
, LSP_FLAG_INSTALLED
);
923 zvrf
->lsp_installs_queued
++;
925 case ZEBRA_DPLANE_REQUEST_FAILURE
:
926 flog_warn(EC_ZEBRA_LSP_INSTALL_FAILURE
,
927 "LSP Install Failure: %u",
930 case ZEBRA_DPLANE_REQUEST_SUCCESS
:
931 zvrf
->lsp_installs
++;
936 /* Installed, may need an update and/or delete. */
938 res
= dplane_lsp_delete(lsp
);
940 /* We do some of the lsp cleanup immediately for
943 UNSET_FLAG(lsp
->flags
, LSP_FLAG_INSTALLED
);
944 clear_nhlfe_installed(lsp
);
947 case ZEBRA_DPLANE_REQUEST_QUEUED
:
948 zvrf
->lsp_removals_queued
++;
950 case ZEBRA_DPLANE_REQUEST_FAILURE
:
951 flog_warn(EC_ZEBRA_LSP_DELETE_FAILURE
,
952 "LSP Deletion Failure: %u",
955 case ZEBRA_DPLANE_REQUEST_SUCCESS
:
956 zvrf
->lsp_removals
++;
959 } else if (CHECK_FLAG(lsp
->flags
, LSP_FLAG_CHANGED
)) {
960 zebra_nhlfe_t
*nhlfe
;
961 struct nexthop
*nexthop
;
963 UNSET_FLAG(lsp
->flags
, LSP_FLAG_CHANGED
);
965 /* We leave the INSTALLED flag set here
966 * so we know an update in in-flight.
970 * Any NHLFE that was installed but is not
971 * selected now needs to have its flags updated.
973 for (nhlfe
= lsp
->nhlfe_list
; nhlfe
;
974 nhlfe
= nhlfe
->next
) {
975 nexthop
= nhlfe
->nexthop
;
979 if (CHECK_FLAG(nhlfe
->flags
,
980 NHLFE_FLAG_INSTALLED
)
981 && !CHECK_FLAG(nhlfe
->flags
,
982 NHLFE_FLAG_SELECTED
)) {
983 UNSET_FLAG(nhlfe
->flags
,
984 NHLFE_FLAG_INSTALLED
);
985 UNSET_FLAG(nexthop
->flags
,
990 switch (dplane_lsp_update(lsp
)) {
991 case ZEBRA_DPLANE_REQUEST_QUEUED
:
992 zvrf
->lsp_installs_queued
++;
994 case ZEBRA_DPLANE_REQUEST_FAILURE
:
995 flog_warn(EC_ZEBRA_LSP_INSTALL_FAILURE
,
996 "LSP Update Failure: %u",
999 case ZEBRA_DPLANE_REQUEST_SUCCESS
:
1000 zvrf
->lsp_installs
++;
1011 * Callback upon processing completion of a LSP forwarding entry.
1013 static void lsp_processq_del(struct work_queue
*wq
, void *data
)
1015 struct zebra_vrf
*zvrf
;
1017 struct hash
*lsp_table
;
1018 zebra_nhlfe_t
*nhlfe
, *nhlfe_next
;
1020 zvrf
= vrf_info_lookup(VRF_DEFAULT
);
1023 lsp_table
= zvrf
->lsp_table
;
1024 if (!lsp_table
) // unexpected
1027 lsp
= (zebra_lsp_t
*)data
;
1028 if (!lsp
) // unexpected
1031 /* Clear flag, remove any NHLFEs marked for deletion. If no NHLFEs
1033 * delete LSP entry also.
1035 UNSET_FLAG(lsp
->flags
, LSP_FLAG_SCHEDULED
);
1037 for (nhlfe
= lsp
->nhlfe_list
; nhlfe
; nhlfe
= nhlfe_next
) {
1038 nhlfe_next
= nhlfe
->next
;
1039 if (CHECK_FLAG(nhlfe
->flags
, NHLFE_FLAG_DELETED
))
1043 if (!lsp
->nhlfe_list
) {
1044 if (IS_ZEBRA_DEBUG_MPLS
)
1045 zlog_debug("Free LSP in-label %u flags 0x%x",
1046 lsp
->ile
.in_label
, lsp
->flags
);
1048 lsp
= hash_release(lsp_table
, &lsp
->ile
);
1049 XFREE(MTYPE_LSP
, lsp
);
1054 * Callback upon finishing the processing of all scheduled
1055 * LSP forwarding entries.
1057 static void lsp_processq_complete(struct work_queue
*wq
)
1059 /* Nothing to do for now. */
1063 * Add LSP forwarding entry to queue for subsequent processing.
1065 static int lsp_processq_add(zebra_lsp_t
*lsp
)
1067 /* If already scheduled, exit. */
1068 if (CHECK_FLAG(lsp
->flags
, LSP_FLAG_SCHEDULED
))
1071 if (zrouter
.lsp_process_q
== NULL
) {
1072 flog_err(EC_ZEBRA_WQ_NONEXISTENT
,
1073 "%s: work_queue does not exist!", __func__
);
1077 work_queue_add(zrouter
.lsp_process_q
, lsp
);
1078 SET_FLAG(lsp
->flags
, LSP_FLAG_SCHEDULED
);
1083 * Callback to allocate LSP forwarding table entry.
1085 static void *lsp_alloc(void *p
)
1087 const zebra_ile_t
*ile
= p
;
1090 lsp
= XCALLOC(MTYPE_LSP
, sizeof(zebra_lsp_t
));
1093 if (IS_ZEBRA_DEBUG_MPLS
)
1094 zlog_debug("Alloc LSP in-label %u", lsp
->ile
.in_label
);
1096 return ((void *)lsp
);
1100 * Create printable string for NHLFE entry.
1102 static char *nhlfe2str(zebra_nhlfe_t
*nhlfe
, char *buf
, int size
)
1104 struct nexthop
*nexthop
;
1107 nexthop
= nhlfe
->nexthop
;
1108 switch (nexthop
->type
) {
1109 case NEXTHOP_TYPE_IPV4
:
1110 case NEXTHOP_TYPE_IPV4_IFINDEX
:
1111 inet_ntop(AF_INET
, &nexthop
->gate
.ipv4
, buf
, size
);
1113 case NEXTHOP_TYPE_IPV6
:
1114 inet_ntop(AF_INET6
, &nexthop
->gate
.ipv6
, buf
, size
);
1116 case NEXTHOP_TYPE_IFINDEX
:
1117 snprintf(buf
, size
, "Ifindex: %u", nexthop
->ifindex
);
1126 * Check if NHLFE matches with search info passed.
1128 static int nhlfe_nhop_match(zebra_nhlfe_t
*nhlfe
, enum nexthop_types_t gtype
,
1129 union g_addr
*gate
, ifindex_t ifindex
)
1131 struct nexthop
*nhop
;
1134 nhop
= nhlfe
->nexthop
;
1138 if (nhop
->type
!= gtype
)
1141 switch (nhop
->type
) {
1142 case NEXTHOP_TYPE_IPV4
:
1143 case NEXTHOP_TYPE_IPV4_IFINDEX
:
1144 cmp
= memcmp(&(nhop
->gate
.ipv4
), &(gate
->ipv4
),
1145 sizeof(struct in_addr
));
1146 if (!cmp
&& nhop
->type
== NEXTHOP_TYPE_IPV4_IFINDEX
)
1147 cmp
= !(nhop
->ifindex
== ifindex
);
1149 case NEXTHOP_TYPE_IPV6
:
1150 case NEXTHOP_TYPE_IPV6_IFINDEX
:
1151 cmp
= memcmp(&(nhop
->gate
.ipv6
), &(gate
->ipv6
),
1152 sizeof(struct in6_addr
));
1153 if (!cmp
&& nhop
->type
== NEXTHOP_TYPE_IPV6_IFINDEX
)
1154 cmp
= !(nhop
->ifindex
== ifindex
);
1156 case NEXTHOP_TYPE_IFINDEX
:
1157 cmp
= !(nhop
->ifindex
== ifindex
);
1168 * Locate NHLFE that matches with passed info.
1170 static zebra_nhlfe_t
*nhlfe_find(zebra_lsp_t
*lsp
, enum lsp_types_t lsp_type
,
1171 enum nexthop_types_t gtype
, union g_addr
*gate
,
1174 zebra_nhlfe_t
*nhlfe
;
1179 for (nhlfe
= lsp
->nhlfe_list
; nhlfe
; nhlfe
= nhlfe
->next
) {
1180 if (nhlfe
->type
!= lsp_type
)
1182 if (!nhlfe_nhop_match(nhlfe
, gtype
, gate
, ifindex
))
1190 * Add NHLFE. Base entry must have been created and duplicate
1193 static zebra_nhlfe_t
*nhlfe_add(zebra_lsp_t
*lsp
, enum lsp_types_t lsp_type
,
1194 enum nexthop_types_t gtype
, union g_addr
*gate
,
1195 ifindex_t ifindex
, mpls_label_t out_label
)
1197 zebra_nhlfe_t
*nhlfe
;
1198 struct nexthop
*nexthop
;
1203 nhlfe
= XCALLOC(MTYPE_NHLFE
, sizeof(zebra_nhlfe_t
));
1206 nhlfe
->type
= lsp_type
;
1207 nhlfe
->distance
= lsp_distance(lsp_type
);
1209 nexthop
= nexthop_new();
1211 XFREE(MTYPE_NHLFE
, nhlfe
);
1214 nexthop_add_labels(nexthop
, lsp_type
, 1, &out_label
);
1216 nexthop
->vrf_id
= VRF_DEFAULT
;
1217 nexthop
->type
= gtype
;
1218 switch (nexthop
->type
) {
1219 case NEXTHOP_TYPE_IPV4
:
1220 case NEXTHOP_TYPE_IPV4_IFINDEX
:
1221 nexthop
->gate
.ipv4
= gate
->ipv4
;
1223 nexthop
->ifindex
= ifindex
;
1225 case NEXTHOP_TYPE_IPV6
:
1226 case NEXTHOP_TYPE_IPV6_IFINDEX
:
1227 nexthop
->gate
.ipv6
= gate
->ipv6
;
1229 nexthop
->ifindex
= ifindex
;
1231 case NEXTHOP_TYPE_IFINDEX
:
1232 nexthop
->ifindex
= ifindex
;
1235 nexthop_free(nexthop
);
1236 XFREE(MTYPE_NHLFE
, nhlfe
);
1241 nhlfe
->nexthop
= nexthop
;
1242 if (lsp
->nhlfe_list
)
1243 lsp
->nhlfe_list
->prev
= nhlfe
;
1244 nhlfe
->next
= lsp
->nhlfe_list
;
1245 lsp
->nhlfe_list
= nhlfe
;
1251 * Delete NHLFE. Entry must be present on list.
1253 static int nhlfe_del(zebra_nhlfe_t
*nhlfe
)
1266 nexthop_free(nhlfe
->nexthop
);
1268 /* Unlink from LSP */
1270 nhlfe
->next
->prev
= nhlfe
->prev
;
1272 nhlfe
->prev
->next
= nhlfe
->next
;
1274 lsp
->nhlfe_list
= nhlfe
->next
;
1276 if (nhlfe
== lsp
->best_nhlfe
)
1277 lsp
->best_nhlfe
= NULL
;
1279 XFREE(MTYPE_NHLFE
, nhlfe
);
1285 * Update label for NHLFE entry.
1287 static void nhlfe_out_label_update(zebra_nhlfe_t
*nhlfe
,
1288 struct mpls_label_stack
*nh_label
)
1290 nhlfe
->nexthop
->nh_label
->label
[0] = nh_label
->label
[0];
1293 static int mpls_lsp_uninstall_all(struct hash
*lsp_table
, zebra_lsp_t
*lsp
,
1294 enum lsp_types_t type
)
1296 zebra_nhlfe_t
*nhlfe
, *nhlfe_next
;
1297 int schedule_lsp
= 0;
1300 /* Mark NHLFEs for delete or directly delete, as appropriate. */
1301 for (nhlfe
= lsp
->nhlfe_list
; nhlfe
; nhlfe
= nhlfe_next
) {
1302 nhlfe_next
= nhlfe
->next
;
1304 /* Skip non-static NHLFEs */
1305 if (nhlfe
->type
!= type
)
1308 if (IS_ZEBRA_DEBUG_MPLS
) {
1309 nhlfe2str(nhlfe
, buf
, BUFSIZ
);
1311 "Del LSP in-label %u type %d nexthop %s flags 0x%x",
1312 lsp
->ile
.in_label
, type
, buf
, nhlfe
->flags
);
1315 if (CHECK_FLAG(nhlfe
->flags
, NHLFE_FLAG_INSTALLED
)) {
1316 UNSET_FLAG(nhlfe
->flags
, NHLFE_FLAG_CHANGED
);
1317 SET_FLAG(nhlfe
->flags
, NHLFE_FLAG_DELETED
);
1324 /* Queue LSP for processing, if needed, else delete. */
1326 if (lsp_processq_add(lsp
))
1328 } else if (!lsp
->nhlfe_list
1329 && !CHECK_FLAG(lsp
->flags
, LSP_FLAG_SCHEDULED
)) {
1330 if (IS_ZEBRA_DEBUG_MPLS
)
1331 zlog_debug("Free LSP in-label %u flags 0x%x",
1332 lsp
->ile
.in_label
, lsp
->flags
);
1334 lsp
= hash_release(lsp_table
, &lsp
->ile
);
1335 XFREE(MTYPE_LSP
, lsp
);
1342 * Uninstall all static NHLFEs for a particular LSP forwarding entry.
1343 * If no other NHLFEs exist, the entry would be deleted.
1345 static int mpls_static_lsp_uninstall_all(struct zebra_vrf
*zvrf
,
1346 mpls_label_t in_label
)
1348 struct hash
*lsp_table
;
1349 zebra_ile_t tmp_ile
;
1353 lsp_table
= zvrf
->lsp_table
;
1357 /* If entry is not present, exit. */
1358 tmp_ile
.in_label
= in_label
;
1359 lsp
= hash_lookup(lsp_table
, &tmp_ile
);
1360 if (!lsp
|| !lsp
->nhlfe_list
)
1363 return mpls_lsp_uninstall_all(lsp_table
, lsp
, ZEBRA_LSP_STATIC
);
1366 static json_object
*nhlfe_json(zebra_nhlfe_t
*nhlfe
)
1369 json_object
*json_nhlfe
= NULL
;
1370 struct nexthop
*nexthop
= nhlfe
->nexthop
;
1372 json_nhlfe
= json_object_new_object();
1373 json_object_string_add(json_nhlfe
, "type", nhlfe_type2str(nhlfe
->type
));
1374 json_object_int_add(json_nhlfe
, "outLabel",
1375 nexthop
->nh_label
->label
[0]);
1376 json_object_int_add(json_nhlfe
, "distance", nhlfe
->distance
);
1378 if (CHECK_FLAG(nhlfe
->flags
, NHLFE_FLAG_INSTALLED
))
1379 json_object_boolean_true_add(json_nhlfe
, "installed");
1381 switch (nexthop
->type
) {
1382 case NEXTHOP_TYPE_IPV4
:
1383 case NEXTHOP_TYPE_IPV4_IFINDEX
:
1384 json_object_string_add(json_nhlfe
, "nexthop",
1385 inet_ntoa(nexthop
->gate
.ipv4
));
1387 case NEXTHOP_TYPE_IPV6
:
1388 case NEXTHOP_TYPE_IPV6_IFINDEX
:
1389 json_object_string_add(
1390 json_nhlfe
, "nexthop",
1391 inet_ntop(AF_INET6
, &nexthop
->gate
.ipv6
, buf
, BUFSIZ
));
1393 if (nexthop
->ifindex
)
1394 json_object_string_add(json_nhlfe
, "interface",
1395 ifindex2ifname(nexthop
->ifindex
,
1405 * Print the NHLFE for a LSP forwarding entry.
1407 static void nhlfe_print(zebra_nhlfe_t
*nhlfe
, struct vty
*vty
)
1409 struct nexthop
*nexthop
;
1412 nexthop
= nhlfe
->nexthop
;
1413 if (!nexthop
|| !nexthop
->nh_label
) // unexpected
1416 vty_out(vty
, " type: %s remote label: %s distance: %d\n",
1417 nhlfe_type2str(nhlfe
->type
),
1418 label2str(nexthop
->nh_label
->label
[0], buf
, BUFSIZ
),
1420 switch (nexthop
->type
) {
1421 case NEXTHOP_TYPE_IPV4
:
1422 case NEXTHOP_TYPE_IPV4_IFINDEX
:
1423 vty_out(vty
, " via %s", inet_ntoa(nexthop
->gate
.ipv4
));
1424 if (nexthop
->ifindex
)
1425 vty_out(vty
, " dev %s",
1426 ifindex2ifname(nexthop
->ifindex
,
1429 case NEXTHOP_TYPE_IPV6
:
1430 case NEXTHOP_TYPE_IPV6_IFINDEX
:
1431 vty_out(vty
, " via %s",
1432 inet_ntop(AF_INET6
, &nexthop
->gate
.ipv6
, buf
, BUFSIZ
));
1433 if (nexthop
->ifindex
)
1434 vty_out(vty
, " dev %s",
1435 ifindex2ifname(nexthop
->ifindex
,
1442 CHECK_FLAG(nhlfe
->flags
, NHLFE_FLAG_INSTALLED
) ? " (installed)"
1448 * Print an LSP forwarding entry.
1450 static void lsp_print(zebra_lsp_t
*lsp
, void *ctxt
)
1452 zebra_nhlfe_t
*nhlfe
;
1455 vty
= (struct vty
*)ctxt
;
1457 vty_out(vty
, "Local label: %u%s\n", lsp
->ile
.in_label
,
1458 CHECK_FLAG(lsp
->flags
, LSP_FLAG_INSTALLED
) ? " (installed)"
1461 for (nhlfe
= lsp
->nhlfe_list
; nhlfe
; nhlfe
= nhlfe
->next
)
1462 nhlfe_print(nhlfe
, vty
);
1466 * JSON objects for an LSP forwarding entry.
1468 static json_object
*lsp_json(zebra_lsp_t
*lsp
)
1470 zebra_nhlfe_t
*nhlfe
= NULL
;
1471 json_object
*json
= json_object_new_object();
1472 json_object
*json_nhlfe_list
= json_object_new_array();
1474 json_object_int_add(json
, "inLabel", lsp
->ile
.in_label
);
1476 if (CHECK_FLAG(lsp
->flags
, LSP_FLAG_INSTALLED
))
1477 json_object_boolean_true_add(json
, "installed");
1479 for (nhlfe
= lsp
->nhlfe_list
; nhlfe
; nhlfe
= nhlfe
->next
)
1480 json_object_array_add(json_nhlfe_list
, nhlfe_json(nhlfe
));
1482 json_object_object_add(json
, "nexthops", json_nhlfe_list
);
1487 /* Return a sorted linked list of the hash contents */
1488 static struct list
*hash_get_sorted_list(struct hash
*hash
, void *cmp
)
1491 struct hash_bucket
*hb
;
1492 struct list
*sorted_list
= list_new();
1494 sorted_list
->cmp
= (int (*)(void *, void *))cmp
;
1496 for (i
= 0; i
< hash
->size
; i
++)
1497 for (hb
= hash
->index
[i
]; hb
; hb
= hb
->next
)
1498 listnode_add_sort(sorted_list
, hb
->data
);
1504 * Compare two LSPs based on their label values.
1506 static int lsp_cmp(zebra_lsp_t
*lsp1
, zebra_lsp_t
*lsp2
)
1508 if (lsp1
->ile
.in_label
< lsp2
->ile
.in_label
)
1511 if (lsp1
->ile
.in_label
> lsp2
->ile
.in_label
)
1518 * Callback to allocate static LSP.
1520 static void *slsp_alloc(void *p
)
1522 const zebra_ile_t
*ile
= p
;
1525 slsp
= XCALLOC(MTYPE_SLSP
, sizeof(zebra_slsp_t
));
1527 return ((void *)slsp
);
1531 * Compare two static LSPs based on their label values.
1533 static int slsp_cmp(zebra_slsp_t
*slsp1
, zebra_slsp_t
*slsp2
)
1535 if (slsp1
->ile
.in_label
< slsp2
->ile
.in_label
)
1538 if (slsp1
->ile
.in_label
> slsp2
->ile
.in_label
)
1545 * Check if static NHLFE matches with search info passed.
1547 static int snhlfe_match(zebra_snhlfe_t
*snhlfe
, enum nexthop_types_t gtype
,
1548 union g_addr
*gate
, ifindex_t ifindex
)
1552 if (snhlfe
->gtype
!= gtype
)
1555 switch (snhlfe
->gtype
) {
1556 case NEXTHOP_TYPE_IPV4
:
1557 cmp
= memcmp(&(snhlfe
->gate
.ipv4
), &(gate
->ipv4
),
1558 sizeof(struct in_addr
));
1560 case NEXTHOP_TYPE_IPV6
:
1561 case NEXTHOP_TYPE_IPV6_IFINDEX
:
1562 cmp
= memcmp(&(snhlfe
->gate
.ipv6
), &(gate
->ipv6
),
1563 sizeof(struct in6_addr
));
1564 if (!cmp
&& snhlfe
->gtype
== NEXTHOP_TYPE_IPV6_IFINDEX
)
1565 cmp
= !(snhlfe
->ifindex
== ifindex
);
1575 * Locate static NHLFE that matches with passed info.
1577 static zebra_snhlfe_t
*snhlfe_find(zebra_slsp_t
*slsp
,
1578 enum nexthop_types_t gtype
,
1579 union g_addr
*gate
, ifindex_t ifindex
)
1581 zebra_snhlfe_t
*snhlfe
;
1586 for (snhlfe
= slsp
->snhlfe_list
; snhlfe
; snhlfe
= snhlfe
->next
) {
1587 if (!snhlfe_match(snhlfe
, gtype
, gate
, ifindex
))
1596 * Add static NHLFE. Base LSP config entry must have been created
1597 * and duplicate check done.
1599 static zebra_snhlfe_t
*snhlfe_add(zebra_slsp_t
*slsp
,
1600 enum nexthop_types_t gtype
,
1601 union g_addr
*gate
, ifindex_t ifindex
,
1602 mpls_label_t out_label
)
1604 zebra_snhlfe_t
*snhlfe
;
1609 snhlfe
= XCALLOC(MTYPE_SNHLFE
, sizeof(zebra_snhlfe_t
));
1610 snhlfe
->slsp
= slsp
;
1611 snhlfe
->out_label
= out_label
;
1612 snhlfe
->gtype
= gtype
;
1614 case NEXTHOP_TYPE_IPV4
:
1615 snhlfe
->gate
.ipv4
= gate
->ipv4
;
1617 case NEXTHOP_TYPE_IPV6
:
1618 case NEXTHOP_TYPE_IPV6_IFINDEX
:
1619 snhlfe
->gate
.ipv6
= gate
->ipv6
;
1621 snhlfe
->ifindex
= ifindex
;
1624 XFREE(MTYPE_SNHLFE
, snhlfe
);
1628 if (slsp
->snhlfe_list
)
1629 slsp
->snhlfe_list
->prev
= snhlfe
;
1630 snhlfe
->next
= slsp
->snhlfe_list
;
1631 slsp
->snhlfe_list
= snhlfe
;
1637 * Delete static NHLFE. Entry must be present on list.
1639 static int snhlfe_del(zebra_snhlfe_t
*snhlfe
)
1646 slsp
= snhlfe
->slsp
;
1651 snhlfe
->next
->prev
= snhlfe
->prev
;
1653 snhlfe
->prev
->next
= snhlfe
->next
;
1655 slsp
->snhlfe_list
= snhlfe
->next
;
1657 snhlfe
->prev
= snhlfe
->next
= NULL
;
1658 XFREE(MTYPE_SNHLFE_IFNAME
, snhlfe
->ifname
);
1659 XFREE(MTYPE_SNHLFE
, snhlfe
);
1665 * Delete all static NHLFE entries for this LSP (in label).
1667 static int snhlfe_del_all(zebra_slsp_t
*slsp
)
1669 zebra_snhlfe_t
*snhlfe
, *snhlfe_next
;
1674 for (snhlfe
= slsp
->snhlfe_list
; snhlfe
; snhlfe
= snhlfe_next
) {
1675 snhlfe_next
= snhlfe
->next
;
1683 * Create printable string for NHLFE configuration.
1685 static char *snhlfe2str(zebra_snhlfe_t
*snhlfe
, char *buf
, int size
)
1688 switch (snhlfe
->gtype
) {
1689 case NEXTHOP_TYPE_IPV4
:
1690 inet_ntop(AF_INET
, &snhlfe
->gate
.ipv4
, buf
, size
);
1692 case NEXTHOP_TYPE_IPV6
:
1693 case NEXTHOP_TYPE_IPV6_IFINDEX
:
1694 inet_ntop(AF_INET6
, &snhlfe
->gate
.ipv6
, buf
, size
);
1695 if (snhlfe
->ifindex
)
1697 ifindex2ifname(snhlfe
->ifindex
, VRF_DEFAULT
));
1707 * Initialize work queue for processing changed LSPs.
1709 static int mpls_processq_init(void)
1711 zrouter
.lsp_process_q
= work_queue_new(zrouter
.master
, "LSP processing");
1712 if (!zrouter
.lsp_process_q
) {
1713 flog_err(EC_ZEBRA_WQ_NONEXISTENT
,
1714 "%s: could not initialise work queue!", __func__
);
1718 zrouter
.lsp_process_q
->spec
.workfunc
= &lsp_process
;
1719 zrouter
.lsp_process_q
->spec
.del_item_data
= &lsp_processq_del
;
1720 zrouter
.lsp_process_q
->spec
.errorfunc
= NULL
;
1721 zrouter
.lsp_process_q
->spec
.completion_func
= &lsp_processq_complete
;
1722 zrouter
.lsp_process_q
->spec
.max_retries
= 0;
1723 zrouter
.lsp_process_q
->spec
.hold
= 10;
1729 /* Public functions */
1732 * Process LSP update results from zebra dataplane.
1734 void zebra_mpls_lsp_dplane_result(struct zebra_dplane_ctx
*ctx
)
1736 struct zebra_vrf
*zvrf
;
1737 zebra_ile_t tmp_ile
;
1738 struct hash
*lsp_table
;
1740 zebra_nhlfe_t
*nhlfe
;
1741 struct nexthop
*nexthop
;
1742 enum dplane_op_e op
;
1743 enum zebra_dplane_result status
;
1745 op
= dplane_ctx_get_op(ctx
);
1746 status
= dplane_ctx_get_status(ctx
);
1748 if (IS_ZEBRA_DEBUG_DPLANE_DETAIL
)
1749 zlog_debug("LSP dplane ctx %p, op %s, in-label %u, result %s",
1750 ctx
, dplane_op2str(op
),
1751 dplane_ctx_get_in_label(ctx
),
1752 dplane_res2str(status
));
1755 case DPLANE_OP_LSP_INSTALL
:
1756 case DPLANE_OP_LSP_UPDATE
:
1757 /* Look for zebra LSP object */
1758 zvrf
= vrf_info_lookup(VRF_DEFAULT
);
1762 lsp_table
= zvrf
->lsp_table
;
1764 tmp_ile
.in_label
= dplane_ctx_get_in_label(ctx
);
1765 lsp
= hash_lookup(lsp_table
, &tmp_ile
);
1767 if (IS_ZEBRA_DEBUG_DPLANE
)
1768 zlog_debug("LSP ctx %p: in-label %u not found",
1769 ctx
, dplane_ctx_get_in_label(ctx
));
1773 /* TODO -- Confirm that this result is still 'current' */
1775 if (status
== ZEBRA_DPLANE_REQUEST_SUCCESS
) {
1776 /* Update zebra object */
1777 SET_FLAG(lsp
->flags
, LSP_FLAG_INSTALLED
);
1778 for (nhlfe
= lsp
->nhlfe_list
; nhlfe
;
1779 nhlfe
= nhlfe
->next
) {
1780 nexthop
= nhlfe
->nexthop
;
1784 SET_FLAG(nhlfe
->flags
, NHLFE_FLAG_INSTALLED
);
1785 SET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_FIB
);
1788 UNSET_FLAG(lsp
->flags
, LSP_FLAG_INSTALLED
);
1789 clear_nhlfe_installed(lsp
);
1790 flog_warn(EC_ZEBRA_LSP_INSTALL_FAILURE
,
1791 "LSP Install Failure: in-label %u",
1797 case DPLANE_OP_LSP_DELETE
:
1798 if (status
!= ZEBRA_DPLANE_REQUEST_SUCCESS
)
1799 flog_warn(EC_ZEBRA_LSP_DELETE_FAILURE
,
1800 "LSP Deletion Failure: in-label %u",
1801 dplane_ctx_get_in_label(ctx
));
1809 dplane_ctx_fini(&ctx
);
1813 * Install dynamic LSP entry.
1815 int zebra_mpls_lsp_install(struct zebra_vrf
*zvrf
, struct route_node
*rn
,
1816 struct route_entry
*re
)
1818 struct route_table
*table
;
1821 table
= zvrf
->fec_table
[family2afi(PREFIX_FAMILY(&rn
->p
))];
1825 /* See if there is a configured label binding for this FEC. */
1826 fec
= fec_find(table
, &rn
->p
);
1827 if (!fec
|| fec
->label
== MPLS_INVALID_LABEL
)
1830 /* We cannot install a label forwarding entry if local label is the
1831 * implicit-null label.
1833 if (fec
->label
== MPLS_LABEL_IMPLICIT_NULL
)
1836 if (lsp_install(zvrf
, fec
->label
, rn
, re
))
1843 * Uninstall dynamic LSP entry, if any.
1845 int zebra_mpls_lsp_uninstall(struct zebra_vrf
*zvrf
, struct route_node
*rn
,
1846 struct route_entry
*re
)
1848 struct route_table
*table
;
1851 table
= zvrf
->fec_table
[family2afi(PREFIX_FAMILY(&rn
->p
))];
1855 /* See if there is a configured label binding for this FEC. */
1856 fec
= fec_find(table
, &rn
->p
);
1857 if (!fec
|| fec
->label
== MPLS_INVALID_LABEL
)
1860 /* Uninstall always removes all dynamic NHLFEs. */
1861 return lsp_uninstall(zvrf
, fec
->label
);
1865 * Add an NHLFE to an LSP, return the newly-added object
1867 zebra_nhlfe_t
*zebra_mpls_lsp_add_nhlfe(zebra_lsp_t
*lsp
,
1868 enum lsp_types_t lsp_type
,
1869 enum nexthop_types_t gtype
,
1872 mpls_label_t out_label
)
1874 /* Just a public pass-through to the internal implementation */
1875 return nhlfe_add(lsp
, lsp_type
, gtype
, gate
, ifindex
, out_label
);
1879 * Free an allocated NHLFE
1881 void zebra_mpls_nhlfe_del(zebra_nhlfe_t
*nhlfe
)
1883 /* Just a pass-through to the internal implementation */
1888 * Registration from a client for the label binding for a FEC. If a binding
1889 * already exists, it is informed to the client.
1890 * NOTE: If there is a manually configured label binding, that is used.
1891 * Otherwise, if a label index is specified, it means we have to allocate the
1892 * label from a locally configured label block (SRGB), if one exists and index
1893 * is acceptable. If no label index then just register the specified label.
1894 * NOTE2: Either label or label_index is expected to be set to MPLS_INVALID_*
1895 * by the calling function. Register requests with both will be rejected.
1897 int zebra_mpls_fec_register(struct zebra_vrf
*zvrf
, struct prefix
*p
,
1898 uint32_t label
, uint32_t label_index
,
1899 struct zserv
*client
)
1901 struct route_table
*table
;
1905 bool label_change
= false;
1907 bool have_label_index
= (label_index
!= MPLS_INVALID_LABEL_INDEX
);
1908 bool is_configured_fec
= false; /* indicate statically configured FEC */
1910 table
= zvrf
->fec_table
[family2afi(PREFIX_FAMILY(p
))];
1914 if (IS_ZEBRA_DEBUG_MPLS
)
1915 prefix2str(p
, buf
, BUFSIZ
);
1917 if (label
!= MPLS_INVALID_LABEL
&& have_label_index
) {
1919 EC_ZEBRA_FEC_LABEL_INDEX_LABEL_CONFLICT
,
1920 "Rejecting FEC register for %s with both label %u and Label Index %u specified, client %s",
1921 buf
, label
, label_index
,
1922 zebra_route_string(client
->proto
));
1927 fec
= fec_find(table
, p
);
1929 fec
= fec_add(table
, p
, label
, 0, label_index
);
1932 EC_ZEBRA_FEC_ADD_FAILED
,
1933 "Failed to add FEC %s upon register, client %s",
1934 buf
, zebra_route_string(client
->proto
));
1938 old_label
= MPLS_INVALID_LABEL
;
1941 /* Check if the FEC has been statically defined in the config */
1942 is_configured_fec
= fec
->flags
& FEC_FLAG_CONFIGURED
;
1943 /* Client may register same FEC with different label index. */
1945 (listnode_lookup(fec
->client_list
, client
) == NULL
);
1946 if (!new_client
&& fec
->label_index
== label_index
1947 && fec
->label
== label
)
1948 /* Duplicate register */
1951 /* Save current label, update the FEC */
1952 old_label
= fec
->label
;
1953 fec
->label_index
= label_index
;
1957 listnode_add(fec
->client_list
, client
);
1959 if (IS_ZEBRA_DEBUG_MPLS
)
1960 zlog_debug("FEC %s label%s %u %s by client %s%s", buf
,
1961 have_label_index
? " index" : "",
1962 have_label_index
? label_index
: label
,
1963 new_client
? "registered" : "updated",
1964 zebra_route_string(client
->proto
),
1966 ? ", but using statically configured label"
1969 /* If not a statically configured FEC, derive the local label
1970 * from label index or use the provided label
1972 if (!is_configured_fec
) {
1973 if (have_label_index
)
1974 fec_derive_label_from_index(zvrf
, fec
);
1978 /* If no label change, exit. */
1979 if (fec
->label
== old_label
)
1982 label_change
= true;
1985 /* If new client or label change, update client and install or uninstall
1986 * label forwarding entry as needed.
1988 /* Inform client of label, if needed. */
1989 if ((new_client
&& fec
->label
!= MPLS_INVALID_LABEL
) || label_change
) {
1990 if (IS_ZEBRA_DEBUG_MPLS
)
1991 zlog_debug("Update client label %u", fec
->label
);
1992 fec_send(fec
, client
);
1995 if (new_client
|| label_change
)
1996 return fec_change_update_lsp(zvrf
, fec
, old_label
);
2002 * Deregistration from a client for the label binding for a FEC. The FEC
2003 * itself is deleted if no other registered clients exist and there is no
2004 * label bound to the FEC.
2006 int zebra_mpls_fec_unregister(struct zebra_vrf
*zvrf
, struct prefix
*p
,
2007 struct zserv
*client
)
2009 struct route_table
*table
;
2013 table
= zvrf
->fec_table
[family2afi(PREFIX_FAMILY(p
))];
2017 if (IS_ZEBRA_DEBUG_MPLS
)
2018 prefix2str(p
, buf
, BUFSIZ
);
2020 fec
= fec_find(table
, p
);
2022 prefix2str(p
, buf
, BUFSIZ
);
2023 flog_err(EC_ZEBRA_FEC_RM_FAILED
,
2024 "Failed to find FEC %s upon unregister, client %s",
2025 buf
, zebra_route_string(client
->proto
));
2029 listnode_delete(fec
->client_list
, client
);
2031 if (IS_ZEBRA_DEBUG_MPLS
)
2032 zlog_debug("FEC %s unregistered by client %s", buf
,
2033 zebra_route_string(client
->proto
));
2035 /* If not a configured entry, delete the FEC if no other clients. Before
2036 * deleting, see if any LSP needs to be uninstalled.
2038 if (!(fec
->flags
& FEC_FLAG_CONFIGURED
)
2039 && list_isempty(fec
->client_list
)) {
2040 mpls_label_t old_label
= fec
->label
;
2041 fec
->label
= MPLS_INVALID_LABEL
; /* reset */
2042 fec_change_update_lsp(zvrf
, fec
, old_label
);
2050 * Cleanup any FECs registered by this client.
2052 static int zebra_mpls_cleanup_fecs_for_client(struct zserv
*client
)
2054 struct zebra_vrf
*zvrf
= vrf_info_lookup(VRF_DEFAULT
);
2055 struct route_node
*rn
;
2057 struct listnode
*node
;
2058 struct zserv
*fec_client
;
2061 for (af
= AFI_IP
; af
< AFI_MAX
; af
++) {
2062 if (zvrf
->fec_table
[af
] == NULL
)
2065 for (rn
= route_top(zvrf
->fec_table
[af
]); rn
;
2066 rn
= route_next(rn
)) {
2068 if (!fec
|| list_isempty(fec
->client_list
))
2071 for (ALL_LIST_ELEMENTS_RO(fec
->client_list
, node
,
2073 if (fec_client
== client
) {
2074 listnode_delete(fec
->client_list
,
2076 if (!(fec
->flags
& FEC_FLAG_CONFIGURED
)
2077 && list_isempty(fec
->client_list
))
2089 * Return FEC (if any) to which this label is bound.
2090 * Note: Only works for per-prefix binding and when the label is not
2092 * TODO: Currently walks entire table, can optimize later with another
2095 zebra_fec_t
*zebra_mpls_fec_for_label(struct zebra_vrf
*zvrf
,
2098 struct route_node
*rn
;
2102 for (af
= AFI_IP
; af
< AFI_MAX
; af
++) {
2103 if (zvrf
->fec_table
[af
] == NULL
)
2106 for (rn
= route_top(zvrf
->fec_table
[af
]); rn
;
2107 rn
= route_next(rn
)) {
2111 if (fec
->label
== label
)
2120 * Inform if specified label is currently bound to a FEC or not.
2122 int zebra_mpls_label_already_bound(struct zebra_vrf
*zvrf
, mpls_label_t label
)
2124 return (zebra_mpls_fec_for_label(zvrf
, label
) ? 1 : 0);
2128 * Add static FEC to label binding. If there are clients registered for this
2129 * FEC, notify them. If there are labeled routes for this FEC, install the
2130 * label forwarding entry.
2132 int zebra_mpls_static_fec_add(struct zebra_vrf
*zvrf
, struct prefix
*p
,
2133 mpls_label_t in_label
)
2135 struct route_table
*table
;
2138 mpls_label_t old_label
;
2141 table
= zvrf
->fec_table
[family2afi(PREFIX_FAMILY(p
))];
2145 if (IS_ZEBRA_DEBUG_MPLS
)
2146 prefix2str(p
, buf
, BUFSIZ
);
2148 /* Update existing FEC or create a new one. */
2149 fec
= fec_find(table
, p
);
2151 fec
= fec_add(table
, p
, in_label
, FEC_FLAG_CONFIGURED
,
2152 MPLS_INVALID_LABEL_INDEX
);
2154 prefix2str(p
, buf
, BUFSIZ
);
2155 flog_err(EC_ZEBRA_FEC_ADD_FAILED
,
2156 "Failed to add FEC %s upon config", buf
);
2160 if (IS_ZEBRA_DEBUG_MPLS
)
2161 zlog_debug("Add fec %s label %u", buf
, in_label
);
2163 fec
->flags
|= FEC_FLAG_CONFIGURED
;
2164 if (fec
->label
== in_label
)
2165 /* Duplicate config */
2168 /* Label change, update clients. */
2169 old_label
= fec
->label
;
2170 if (IS_ZEBRA_DEBUG_MPLS
)
2171 zlog_debug("Update fec %s new label %u", buf
, in_label
);
2173 fec
->label
= in_label
;
2174 fec_update_clients(fec
);
2176 /* Update label forwarding entries appropriately */
2177 ret
= fec_change_update_lsp(zvrf
, fec
, old_label
);
2184 * Remove static FEC to label binding. If there are no clients registered
2185 * for this FEC, delete the FEC; else notify clients
2186 * Note: Upon delete of static binding, if label index exists for this FEC,
2187 * client may need to be updated with derived label.
2189 int zebra_mpls_static_fec_del(struct zebra_vrf
*zvrf
, struct prefix
*p
)
2191 struct route_table
*table
;
2193 mpls_label_t old_label
;
2196 table
= zvrf
->fec_table
[family2afi(PREFIX_FAMILY(p
))];
2200 fec
= fec_find(table
, p
);
2202 prefix2str(p
, buf
, BUFSIZ
);
2203 flog_err(EC_ZEBRA_FEC_RM_FAILED
,
2204 "Failed to find FEC %s upon delete", buf
);
2208 if (IS_ZEBRA_DEBUG_MPLS
) {
2209 prefix2str(p
, buf
, BUFSIZ
);
2210 zlog_debug("Delete fec %s label %u label index %u", buf
,
2211 fec
->label
, fec
->label_index
);
2214 old_label
= fec
->label
;
2215 fec
->flags
&= ~FEC_FLAG_CONFIGURED
;
2216 fec
->label
= MPLS_INVALID_LABEL
;
2218 /* If no client exists, just delete the FEC. */
2219 if (list_isempty(fec
->client_list
)) {
2224 /* Derive the local label (from label index) or reset it. */
2225 fec_derive_label_from_index(zvrf
, fec
);
2227 /* If there is a label change, update clients. */
2228 if (fec
->label
== old_label
)
2230 fec_update_clients(fec
);
2232 /* Update label forwarding entries appropriately */
2233 return fec_change_update_lsp(zvrf
, fec
, old_label
);
2237 * Display MPLS FEC to label binding configuration (VTY command handler).
2239 int zebra_mpls_write_fec_config(struct vty
*vty
, struct zebra_vrf
*zvrf
)
2241 struct route_node
*rn
;
2247 for (af
= AFI_IP
; af
< AFI_MAX
; af
++) {
2248 if (zvrf
->fec_table
[af
] == NULL
)
2251 for (rn
= route_top(zvrf
->fec_table
[af
]); rn
;
2252 rn
= route_next(rn
)) {
2259 if (!(fec
->flags
& FEC_FLAG_CONFIGURED
))
2263 prefix2str(&rn
->p
, buf
, BUFSIZ
);
2264 vty_out(vty
, "mpls label bind %s %s\n", buf
,
2265 label2str(fec
->label
, lstr
, BUFSIZ
));
2273 * Display MPLS FEC to label binding (VTY command handler).
2275 void zebra_mpls_print_fec_table(struct vty
*vty
, struct zebra_vrf
*zvrf
)
2277 struct route_node
*rn
;
2280 for (af
= AFI_IP
; af
< AFI_MAX
; af
++) {
2281 if (zvrf
->fec_table
[af
] == NULL
)
2284 for (rn
= route_top(zvrf
->fec_table
[af
]); rn
;
2285 rn
= route_next(rn
)) {
2288 fec_print(rn
->info
, vty
);
2294 * Display MPLS FEC to label binding for a specific FEC (VTY command handler).
2296 void zebra_mpls_print_fec(struct vty
*vty
, struct zebra_vrf
*zvrf
,
2299 struct route_table
*table
;
2300 struct route_node
*rn
;
2302 table
= zvrf
->fec_table
[family2afi(PREFIX_FAMILY(p
))];
2307 rn
= route_node_lookup(table
, p
);
2311 route_unlock_node(rn
);
2315 fec_print(rn
->info
, vty
);
2318 static bool mpls_ftn_update_nexthop(int add
, struct nexthop
*nexthop
,
2319 enum lsp_types_t type
, mpls_label_t label
)
2321 if (add
&& nexthop
->nh_label_type
== ZEBRA_LSP_NONE
)
2322 nexthop_add_labels(nexthop
, type
, 1, &label
);
2323 else if (!add
&& nexthop
->nh_label_type
== type
)
2324 nexthop_del_labels(nexthop
);
2332 * Install/uninstall a FEC-To-NHLFE (FTN) binding.
2334 int mpls_ftn_update(int add
, struct zebra_vrf
*zvrf
, enum lsp_types_t type
,
2335 struct prefix
*prefix
, enum nexthop_types_t gtype
,
2336 union g_addr
*gate
, ifindex_t ifindex
, uint8_t distance
,
2337 mpls_label_t out_label
)
2339 struct route_table
*table
;
2340 struct route_node
*rn
;
2341 struct route_entry
*re
;
2342 struct nexthop
*nexthop
;
2346 table
= zebra_vrf_table(family2afi(prefix
->family
), SAFI_UNICAST
,
2351 /* Lookup existing route */
2352 rn
= route_node_get(table
, prefix
);
2353 RNODE_FOREACH_RE (rn
, re
) {
2354 if (CHECK_FLAG(re
->status
, ROUTE_ENTRY_REMOVED
))
2356 if (re
->distance
== distance
)
2364 for (nexthop
= re
->ng
.nexthop
; nexthop
; nexthop
= nexthop
->next
) {
2365 switch (nexthop
->type
) {
2366 case NEXTHOP_TYPE_IPV4
:
2367 case NEXTHOP_TYPE_IPV4_IFINDEX
:
2368 if (gtype
!= NEXTHOP_TYPE_IPV4
2369 && gtype
!= NEXTHOP_TYPE_IPV4_IFINDEX
)
2371 if (!IPV4_ADDR_SAME(&nexthop
->gate
.ipv4
, &gate
->ipv4
))
2373 if (nexthop
->type
== NEXTHOP_TYPE_IPV4_IFINDEX
2374 && nexthop
->ifindex
!= ifindex
)
2376 if (!mpls_ftn_update_nexthop(add
, nexthop
, type
,
2381 case NEXTHOP_TYPE_IPV6
:
2382 case NEXTHOP_TYPE_IPV6_IFINDEX
:
2383 if (gtype
!= NEXTHOP_TYPE_IPV6
2384 && gtype
!= NEXTHOP_TYPE_IPV6_IFINDEX
)
2386 if (!IPV6_ADDR_SAME(&nexthop
->gate
.ipv6
, &gate
->ipv6
))
2388 if (nexthop
->type
== NEXTHOP_TYPE_IPV6_IFINDEX
2389 && nexthop
->ifindex
!= ifindex
)
2391 if (!mpls_ftn_update_nexthop(add
, nexthop
, type
,
2404 SET_FLAG(re
->status
, ROUTE_ENTRY_CHANGED
);
2405 SET_FLAG(re
->status
, ROUTE_ENTRY_LABELS_CHANGED
);
2412 * Install/update a NHLFE for an LSP in the forwarding table. This may be
2413 * a new LSP entry or a new NHLFE for an existing in-label or an update of
2414 * the out-label for an existing NHLFE (update case).
2416 int mpls_lsp_install(struct zebra_vrf
*zvrf
, enum lsp_types_t type
,
2417 mpls_label_t in_label
, mpls_label_t out_label
,
2418 enum nexthop_types_t gtype
, union g_addr
*gate
,
2421 struct hash
*lsp_table
;
2422 zebra_ile_t tmp_ile
;
2424 zebra_nhlfe_t
*nhlfe
;
2428 lsp_table
= zvrf
->lsp_table
;
2432 /* If entry is present, exit. */
2433 tmp_ile
.in_label
= in_label
;
2434 lsp
= hash_get(lsp_table
, &tmp_ile
, lsp_alloc
);
2437 nhlfe
= nhlfe_find(lsp
, type
, gtype
, gate
, ifindex
);
2439 struct nexthop
*nh
= nhlfe
->nexthop
;
2442 assert(nh
->nh_label
);
2444 /* Clear deleted flag (in case it was set) */
2445 UNSET_FLAG(nhlfe
->flags
, NHLFE_FLAG_DELETED
);
2446 if (nh
->nh_label
->label
[0] == out_label
)
2450 if (IS_ZEBRA_DEBUG_MPLS
) {
2451 nhlfe2str(nhlfe
, buf
, BUFSIZ
);
2453 "LSP in-label %u type %d nexthop %s "
2454 "out-label changed to %u (old %u)",
2455 in_label
, type
, buf
, out_label
,
2456 nh
->nh_label
->label
[0]);
2459 /* Update out label, trigger processing. */
2460 nh
->nh_label
->label
[0] = out_label
;
2462 /* Add LSP entry to this nexthop */
2463 nhlfe
= nhlfe_add(lsp
, type
, gtype
, gate
, ifindex
, out_label
);
2467 if (IS_ZEBRA_DEBUG_MPLS
) {
2468 nhlfe2str(nhlfe
, buf
, BUFSIZ
);
2470 "Add LSP in-label %u type %d nexthop %s "
2472 in_label
, type
, buf
, out_label
);
2475 lsp
->addr_family
= NHLFE_FAMILY(nhlfe
);
2478 /* Mark NHLFE, queue LSP for processing. */
2479 SET_FLAG(nhlfe
->flags
, NHLFE_FLAG_CHANGED
);
2480 if (lsp_processq_add(lsp
))
2487 * Uninstall a particular NHLFE in the forwarding table. If this is
2488 * the only NHLFE, the entire LSP forwarding entry has to be deleted.
2490 int mpls_lsp_uninstall(struct zebra_vrf
*zvrf
, enum lsp_types_t type
,
2491 mpls_label_t in_label
, enum nexthop_types_t gtype
,
2492 union g_addr
*gate
, ifindex_t ifindex
)
2494 struct hash
*lsp_table
;
2495 zebra_ile_t tmp_ile
;
2497 zebra_nhlfe_t
*nhlfe
;
2501 lsp_table
= zvrf
->lsp_table
;
2505 /* If entry is not present, exit. */
2506 tmp_ile
.in_label
= in_label
;
2507 lsp
= hash_lookup(lsp_table
, &tmp_ile
);
2510 nhlfe
= nhlfe_find(lsp
, type
, gtype
, gate
, ifindex
);
2514 if (IS_ZEBRA_DEBUG_MPLS
) {
2515 nhlfe2str(nhlfe
, buf
, BUFSIZ
);
2516 zlog_debug("Del LSP in-label %u type %d nexthop %s flags 0x%x",
2517 in_label
, type
, buf
, nhlfe
->flags
);
2520 /* Mark NHLFE for delete or directly delete, as appropriate. */
2521 if (CHECK_FLAG(nhlfe
->flags
, NHLFE_FLAG_INSTALLED
)) {
2522 UNSET_FLAG(nhlfe
->flags
, NHLFE_FLAG_CHANGED
);
2523 SET_FLAG(nhlfe
->flags
, NHLFE_FLAG_DELETED
);
2524 if (lsp_processq_add(lsp
))
2529 /* Free LSP entry if no other NHLFEs and not scheduled. */
2530 if (!lsp
->nhlfe_list
2531 && !CHECK_FLAG(lsp
->flags
, LSP_FLAG_SCHEDULED
)) {
2532 if (IS_ZEBRA_DEBUG_MPLS
)
2533 zlog_debug("Free LSP in-label %u flags 0x%x",
2534 lsp
->ile
.in_label
, lsp
->flags
);
2536 lsp
= hash_release(lsp_table
, &lsp
->ile
);
2537 XFREE(MTYPE_LSP
, lsp
);
2544 * Uninstall all LDP NHLFEs for a particular LSP forwarding entry.
2545 * If no other NHLFEs exist, the entry would be deleted.
2547 void mpls_ldp_lsp_uninstall_all(struct hash_bucket
*bucket
, void *ctxt
)
2550 struct hash
*lsp_table
;
2552 lsp
= (zebra_lsp_t
*)bucket
->data
;
2553 if (!lsp
->nhlfe_list
)
2560 mpls_lsp_uninstall_all(lsp_table
, lsp
, ZEBRA_LSP_LDP
);
2564 * Uninstall all LDP FEC-To-NHLFE (FTN) bindings of the given address-family.
2566 void mpls_ldp_ftn_uninstall_all(struct zebra_vrf
*zvrf
, int afi
)
2568 struct route_table
*table
;
2569 struct route_node
*rn
;
2570 struct route_entry
*re
;
2571 struct nexthop
*nexthop
;
2574 /* Process routes of interested address-families. */
2575 table
= zebra_vrf_table(afi
, SAFI_UNICAST
, zvrf_id(zvrf
));
2579 for (rn
= route_top(table
); rn
; rn
= route_next(rn
)) {
2581 RNODE_FOREACH_RE (rn
, re
) {
2582 for (nexthop
= re
->ng
.nexthop
; nexthop
;
2583 nexthop
= nexthop
->next
) {
2584 if (nexthop
->nh_label_type
!= ZEBRA_LSP_LDP
)
2587 nexthop_del_labels(nexthop
);
2588 SET_FLAG(re
->status
, ROUTE_ENTRY_CHANGED
);
2589 SET_FLAG(re
->status
,
2590 ROUTE_ENTRY_LABELS_CHANGED
);
2600 #if defined(HAVE_CUMULUS)
2602 * Check that the label values used in LSP creation are consistent. The
2603 * main criteria is that if there is ECMP, the label operation must still
2604 * be consistent - i.e., all paths either do a swap or do PHP. This is due
2605 * to current HW restrictions.
2607 int zebra_mpls_lsp_label_consistent(struct zebra_vrf
*zvrf
,
2608 mpls_label_t in_label
,
2609 mpls_label_t out_label
,
2610 enum nexthop_types_t gtype
,
2611 union g_addr
*gate
, ifindex_t ifindex
)
2613 struct hash
*slsp_table
;
2614 zebra_ile_t tmp_ile
;
2616 zebra_snhlfe_t
*snhlfe
;
2619 slsp_table
= zvrf
->slsp_table
;
2623 /* If entry is not present, exit. */
2624 tmp_ile
.in_label
= in_label
;
2625 slsp
= hash_lookup(slsp_table
, &tmp_ile
);
2629 snhlfe
= snhlfe_find(slsp
, gtype
, gate
, ifindex
);
2631 if (snhlfe
->out_label
== out_label
)
2634 /* If not only NHLFE, cannot allow label change. */
2635 if (snhlfe
!= slsp
->snhlfe_list
|| snhlfe
->next
)
2638 /* If other NHLFEs exist, label operation must match. */
2639 if (slsp
->snhlfe_list
) {
2642 cur_op
= (slsp
->snhlfe_list
->out_label
2643 == MPLS_LABEL_IMPLICIT_NULL
);
2644 new_op
= (out_label
== MPLS_LABEL_IMPLICIT_NULL
);
2645 if (cur_op
!= new_op
)
2650 /* Label values are good. */
2653 #endif /* HAVE_CUMULUS */
2656 * Add static LSP entry. This may be the first entry for this incoming label
2657 * or an additional nexthop; an existing entry may also have outgoing label
2659 * Note: The label operation (swap or PHP) is common for the LSP entry (all
2662 int zebra_mpls_static_lsp_add(struct zebra_vrf
*zvrf
, mpls_label_t in_label
,
2663 mpls_label_t out_label
,
2664 enum nexthop_types_t gtype
, union g_addr
*gate
,
2667 struct hash
*slsp_table
;
2668 zebra_ile_t tmp_ile
;
2670 zebra_snhlfe_t
*snhlfe
;
2674 slsp_table
= zvrf
->slsp_table
;
2678 /* If entry is present, exit. */
2679 tmp_ile
.in_label
= in_label
;
2680 slsp
= hash_get(slsp_table
, &tmp_ile
, slsp_alloc
);
2683 snhlfe
= snhlfe_find(slsp
, gtype
, gate
, ifindex
);
2685 if (snhlfe
->out_label
== out_label
)
2689 if (IS_ZEBRA_DEBUG_MPLS
) {
2690 snhlfe2str(snhlfe
, buf
, BUFSIZ
);
2692 "Upd static LSP in-label %u nexthop %s "
2693 "out-label %u (old %u)",
2694 in_label
, buf
, out_label
, snhlfe
->out_label
);
2696 snhlfe
->out_label
= out_label
;
2698 /* Add static LSP entry to this nexthop */
2699 snhlfe
= snhlfe_add(slsp
, gtype
, gate
, ifindex
, out_label
);
2703 if (IS_ZEBRA_DEBUG_MPLS
) {
2704 snhlfe2str(snhlfe
, buf
, BUFSIZ
);
2706 "Add static LSP in-label %u nexthop %s out-label %u",
2707 in_label
, buf
, out_label
);
2711 /* (Re)Install LSP in the main table. */
2712 if (mpls_lsp_install(zvrf
, ZEBRA_LSP_STATIC
, in_label
, out_label
, gtype
,
2720 * Delete static LSP entry. This may be the delete of one particular
2721 * NHLFE for this incoming label or the delete of the entire entry (i.e.,
2723 * NOTE: Delete of the only NHLFE will also end up deleting the entire
2724 * LSP configuration.
2726 int zebra_mpls_static_lsp_del(struct zebra_vrf
*zvrf
, mpls_label_t in_label
,
2727 enum nexthop_types_t gtype
, union g_addr
*gate
,
2730 struct hash
*slsp_table
;
2731 zebra_ile_t tmp_ile
;
2733 zebra_snhlfe_t
*snhlfe
;
2736 slsp_table
= zvrf
->slsp_table
;
2740 /* If entry is not present, exit. */
2741 tmp_ile
.in_label
= in_label
;
2742 slsp
= hash_lookup(slsp_table
, &tmp_ile
);
2746 /* Is it delete of entire LSP or a specific NHLFE? */
2747 if (gtype
== NEXTHOP_TYPE_BLACKHOLE
) {
2748 if (IS_ZEBRA_DEBUG_MPLS
)
2749 zlog_debug("Del static LSP in-label %u", in_label
);
2751 /* Uninstall entire LSP from the main table. */
2752 mpls_static_lsp_uninstall_all(zvrf
, in_label
);
2754 /* Delete all static NHLFEs */
2755 snhlfe_del_all(slsp
);
2757 /* Find specific NHLFE, exit if not found. */
2758 snhlfe
= snhlfe_find(slsp
, gtype
, gate
, ifindex
);
2762 if (IS_ZEBRA_DEBUG_MPLS
) {
2764 snhlfe2str(snhlfe
, buf
, BUFSIZ
);
2765 zlog_debug("Del static LSP in-label %u nexthop %s",
2769 /* Uninstall LSP from the main table. */
2770 mpls_lsp_uninstall(zvrf
, ZEBRA_LSP_STATIC
, in_label
, gtype
,
2773 /* Delete static LSP NHLFE */
2777 /* Remove entire static LSP entry if no NHLFE - valid in either case
2779 if (!slsp
->snhlfe_list
) {
2780 slsp
= hash_release(slsp_table
, &tmp_ile
);
2781 XFREE(MTYPE_SLSP
, slsp
);
2788 * Schedule all MPLS label forwarding entries for processing.
2789 * Called upon changes that may affect one or more of them such as
2790 * interface or nexthop state changes.
2792 void zebra_mpls_lsp_schedule(struct zebra_vrf
*zvrf
)
2796 hash_iterate(zvrf
->lsp_table
, lsp_schedule
, NULL
);
2800 * Display MPLS label forwarding table for a specific LSP
2801 * (VTY command handler).
2803 void zebra_mpls_print_lsp(struct vty
*vty
, struct zebra_vrf
*zvrf
,
2804 mpls_label_t label
, bool use_json
)
2806 struct hash
*lsp_table
;
2808 zebra_ile_t tmp_ile
;
2809 json_object
*json
= NULL
;
2812 lsp_table
= zvrf
->lsp_table
;
2816 /* If entry is not present, exit. */
2817 tmp_ile
.in_label
= label
;
2818 lsp
= hash_lookup(lsp_table
, &tmp_ile
);
2823 json
= lsp_json(lsp
);
2824 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
2825 json
, JSON_C_TO_STRING_PRETTY
));
2826 json_object_free(json
);
2828 lsp_print(lsp
, (void *)vty
);
2832 * Display MPLS label forwarding table (VTY command handler).
2834 void zebra_mpls_print_lsp_table(struct vty
*vty
, struct zebra_vrf
*zvrf
,
2838 json_object
*json
= NULL
;
2839 zebra_lsp_t
*lsp
= NULL
;
2840 zebra_nhlfe_t
*nhlfe
= NULL
;
2841 struct nexthop
*nexthop
= NULL
;
2842 struct listnode
*node
= NULL
;
2843 struct list
*lsp_list
= hash_get_sorted_list(zvrf
->lsp_table
, lsp_cmp
);
2846 json
= json_object_new_object();
2848 for (ALL_LIST_ELEMENTS_RO(lsp_list
, node
, lsp
))
2849 json_object_object_add(
2850 json
, label2str(lsp
->ile
.in_label
, buf
, BUFSIZ
),
2853 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
2854 json
, JSON_C_TO_STRING_PRETTY
));
2855 json_object_free(json
);
2857 vty_out(vty
, " Inbound Outbound\n");
2858 vty_out(vty
, " Label Type Nexthop Label\n");
2859 vty_out(vty
, "-------- ------- --------------- --------\n");
2861 for (ALL_LIST_ELEMENTS_RO(lsp_list
, node
, lsp
)) {
2862 for (nhlfe
= lsp
->nhlfe_list
; nhlfe
;
2863 nhlfe
= nhlfe
->next
) {
2864 vty_out(vty
, "%8d %7s ", lsp
->ile
.in_label
,
2865 nhlfe_type2str(nhlfe
->type
));
2866 nexthop
= nhlfe
->nexthop
;
2868 switch (nexthop
->type
) {
2869 case NEXTHOP_TYPE_IFINDEX
: {
2870 struct zebra_ns
*zns
;
2871 struct interface
*ifp
;
2873 zns
= zebra_ns_lookup(NS_DEFAULT
);
2874 ifp
= if_lookup_by_index_per_ns(
2877 vty_out(vty
, "%15s", ifp
->name
);
2880 case NEXTHOP_TYPE_IPV4
:
2881 case NEXTHOP_TYPE_IPV4_IFINDEX
:
2882 vty_out(vty
, "%15s",
2883 inet_ntoa(nexthop
->gate
.ipv4
));
2885 case NEXTHOP_TYPE_IPV6
:
2886 case NEXTHOP_TYPE_IPV6_IFINDEX
:
2887 vty_out(vty
, "%15s",
2889 &nexthop
->gate
.ipv6
,
2896 if (nexthop
->type
!= NEXTHOP_TYPE_IFINDEX
)
2897 vty_out(vty
, " %8s\n",
2912 list_delete(&lsp_list
);
2916 * Display MPLS LSP configuration of all static LSPs (VTY command handler).
2918 int zebra_mpls_write_lsp_config(struct vty
*vty
, struct zebra_vrf
*zvrf
)
2921 zebra_snhlfe_t
*snhlfe
;
2922 struct listnode
*node
;
2923 struct list
*slsp_list
=
2924 hash_get_sorted_list(zvrf
->slsp_table
, slsp_cmp
);
2926 for (ALL_LIST_ELEMENTS_RO(slsp_list
, node
, slsp
)) {
2927 for (snhlfe
= slsp
->snhlfe_list
; snhlfe
;
2928 snhlfe
= snhlfe
->next
) {
2932 snhlfe2str(snhlfe
, buf
, sizeof(buf
));
2933 switch (snhlfe
->out_label
) {
2934 case MPLS_LABEL_IPV4_EXPLICIT_NULL
:
2935 case MPLS_LABEL_IPV6_EXPLICIT_NULL
:
2936 strlcpy(lstr
, "explicit-null", sizeof(lstr
));
2938 case MPLS_LABEL_IMPLICIT_NULL
:
2939 strlcpy(lstr
, "implicit-null", sizeof(lstr
));
2942 sprintf(lstr
, "%u", snhlfe
->out_label
);
2946 vty_out(vty
, "mpls lsp %u %s %s\n", slsp
->ile
.in_label
,
2951 list_delete(&slsp_list
);
2952 return (zvrf
->slsp_table
->count
? 1 : 0);
2956 * Add/update global label block.
2958 int zebra_mpls_label_block_add(struct zebra_vrf
*zvrf
, uint32_t start_label
,
2961 zvrf
->mpls_srgb
.start_label
= start_label
;
2962 zvrf
->mpls_srgb
.end_label
= end_label
;
2964 /* Evaluate registered FECs to see if any get a label or not. */
2970 * Delete global label block.
2972 int zebra_mpls_label_block_del(struct zebra_vrf
*zvrf
)
2974 zvrf
->mpls_srgb
.start_label
= MPLS_DEFAULT_MIN_SRGB_LABEL
;
2975 zvrf
->mpls_srgb
.end_label
= MPLS_DEFAULT_MAX_SRGB_LABEL
;
2977 /* Process registered FECs to clear their local label, if needed. */
2983 * Display MPLS global label block configuration (VTY command handler).
2985 int zebra_mpls_write_label_block_config(struct vty
*vty
, struct zebra_vrf
*zvrf
)
2987 if (zvrf
->mpls_srgb
.start_label
== 0)
2990 if ((zvrf
->mpls_srgb
.start_label
!= MPLS_DEFAULT_MIN_SRGB_LABEL
)
2991 || (zvrf
->mpls_srgb
.end_label
!= MPLS_DEFAULT_MAX_SRGB_LABEL
)) {
2992 vty_out(vty
, "mpls label global-block %u %u\n",
2993 zvrf
->mpls_srgb
.start_label
, zvrf
->mpls_srgb
.end_label
);
3000 * Called when VRF becomes inactive, cleans up information but keeps
3002 * NOTE: Currently supported only for default VRF.
3004 void zebra_mpls_cleanup_tables(struct zebra_vrf
*zvrf
)
3006 hash_iterate(zvrf
->lsp_table
, lsp_uninstall_from_kernel
, NULL
);
3010 * Called upon process exiting, need to delete LSP forwarding
3011 * entries from the kernel.
3012 * NOTE: Currently supported only for default VRF.
3014 void zebra_mpls_close_tables(struct zebra_vrf
*zvrf
)
3016 hash_iterate(zvrf
->lsp_table
, lsp_uninstall_from_kernel
, NULL
);
3017 hash_clean(zvrf
->lsp_table
, NULL
);
3018 hash_free(zvrf
->lsp_table
);
3019 hash_clean(zvrf
->slsp_table
, NULL
);
3020 hash_free(zvrf
->slsp_table
);
3021 route_table_finish(zvrf
->fec_table
[AFI_IP
]);
3022 route_table_finish(zvrf
->fec_table
[AFI_IP6
]);
3026 * Allocate MPLS tables for this VRF and do other initialization.
3027 * NOTE: Currently supported only for default VRF.
3029 void zebra_mpls_init_tables(struct zebra_vrf
*zvrf
)
3034 hash_create(label_hash
, label_cmp
, "ZEBRA SLSP table");
3035 zvrf
->lsp_table
= hash_create(label_hash
, label_cmp
, "ZEBRA LSP table");
3036 zvrf
->fec_table
[AFI_IP
] = route_table_init();
3037 zvrf
->fec_table
[AFI_IP6
] = route_table_init();
3038 zvrf
->mpls_flags
= 0;
3039 zvrf
->mpls_srgb
.start_label
= MPLS_DEFAULT_MIN_SRGB_LABEL
;
3040 zvrf
->mpls_srgb
.end_label
= MPLS_DEFAULT_MAX_SRGB_LABEL
;
3044 * Global MPLS initialization.
3046 void zebra_mpls_init(void)
3050 if (mpls_kernel_init() < 0) {
3051 flog_warn(EC_ZEBRA_MPLS_SUPPORT_DISABLED
,
3052 "Disabling MPLS support (no kernel support)");
3056 if (!mpls_processq_init())
3059 hook_register(zserv_client_close
, zebra_mpls_cleanup_fecs_for_client
);