2 * Zebra MPLS Data structures and definitions
3 * Copyright (C) 2015 Cumulus Networks, Inc.
5 * This file is part of GNU Zebra.
7 * GNU Zebra is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2, or (at your option) any
12 * GNU Zebra is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; see the file COPYING; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
34 #include "zebra/zserv.h"
35 #include "zebra/zebra_vrf.h"
41 /* Definitions and macros. */
43 #define NHLFE_FAMILY(nhlfe) \
44 (((nhlfe)->nexthop->type == NEXTHOP_TYPE_IPV6 \
45 || (nhlfe)->nexthop->type == NEXTHOP_TYPE_IPV6_IFINDEX) \
51 typedef struct zebra_ile_t_ zebra_ile_t
;
52 typedef struct zebra_snhlfe_t_ zebra_snhlfe_t
;
53 typedef struct zebra_slsp_t_ zebra_slsp_t
;
54 typedef struct zebra_nhlfe_t_ zebra_nhlfe_t
;
55 typedef struct zebra_lsp_t_ zebra_lsp_t
;
56 typedef struct zebra_fec_t_ zebra_fec_t
;
59 * (Outgoing) nexthop label forwarding entry configuration
61 struct zebra_snhlfe_t_
{
62 /* Nexthop information */
63 enum nexthop_types_t gtype
;
69 mpls_label_t out_label
;
71 /* Backpointer to base entry. */
74 /* Pointers to more outgoing information for same in-label */
80 * (Outgoing) nexthop label forwarding entry
82 struct zebra_nhlfe_t_
{
83 /* Type of entry - static etc. */
84 enum lsp_types_t type
;
86 /* Nexthop information (with outgoing label) */
87 struct nexthop
*nexthop
;
89 /* Backpointer to base entry. */
92 /* Runtime info - flags, pointers etc. */
94 #define NHLFE_FLAG_CHANGED (1 << 0)
95 #define NHLFE_FLAG_SELECTED (1 << 1)
96 #define NHLFE_FLAG_MULTIPATH (1 << 2)
97 #define NHLFE_FLAG_DELETED (1 << 3)
98 #define NHLFE_FLAG_INSTALLED (1 << 4)
106 * Incoming label entry
108 struct zebra_ile_t_
{
109 mpls_label_t in_label
;
113 * Label swap entry static configuration.
115 struct zebra_slsp_t_
{
119 /* List of outgoing nexthop static configuration */
120 zebra_snhlfe_t
*snhlfe_list
;
124 * Label swap entry (ile -> list of nhlfes)
126 struct zebra_lsp_t_
{
130 /* List of NHLFE, pointer to best and num equal-cost. */
131 zebra_nhlfe_t
*nhlfe_list
;
132 zebra_nhlfe_t
*best_nhlfe
;
137 #define LSP_FLAG_SCHEDULED (1 << 0)
138 #define LSP_FLAG_INSTALLED (1 << 1)
139 #define LSP_FLAG_CHANGED (1 << 2)
141 /* Address-family of NHLFE - saved here for delete. All NHLFEs */
142 /* have to be of the same AF */
147 * FEC to label binding.
149 struct zebra_fec_t_
{
151 struct route_node
*rn
;
153 /* In-label - either statically bound or derived from label block. */
156 /* Label index (into global label block), if valid */
157 uint32_t label_index
;
161 #define FEC_FLAG_CONFIGURED (1 << 0)
163 /* Clients interested in this FEC. */
164 struct list
*client_list
;
167 /* Function declarations. */
170 * Add/update global label block.
172 int zebra_mpls_label_block_add(struct zebra_vrf
*zvrf
, uint32_t start_label
,
176 * Delete global label block.
178 int zebra_mpls_label_block_del(struct zebra_vrf
*vrf
);
181 * Display MPLS global label block configuration (VTY command handler).
183 int zebra_mpls_write_label_block_config(struct vty
*vty
, struct zebra_vrf
*vrf
);
186 * Install dynamic LSP entry.
188 int zebra_mpls_lsp_install(struct zebra_vrf
*zvrf
, struct route_node
*rn
,
189 struct route_entry
*re
);
192 * Uninstall dynamic LSP entry, if any.
194 int zebra_mpls_lsp_uninstall(struct zebra_vrf
*zvrf
, struct route_node
*rn
,
195 struct route_entry
*re
);
197 /* Add an NHLFE to an LSP, return the newly-added object */
198 zebra_nhlfe_t
*zebra_mpls_lsp_add_nhlfe(zebra_lsp_t
*lsp
,
199 enum lsp_types_t lsp_type
,
200 enum nexthop_types_t gtype
,
203 mpls_label_t out_label
);
205 /* Free an allocated NHLFE */
206 void zebra_mpls_nhlfe_del(zebra_nhlfe_t
*nhlfe
);
208 int zebra_mpls_fec_register(struct zebra_vrf
*zvrf
, struct prefix
*p
,
209 uint32_t label
, uint32_t label_index
,
210 struct zserv
*client
);
213 * Deregistration from a client for the label binding for a FEC. The FEC
214 * itself is deleted if no other registered clients exist and there is no
215 * label bound to the FEC.
217 int zebra_mpls_fec_unregister(struct zebra_vrf
*zvrf
, struct prefix
*p
,
218 struct zserv
*client
);
221 * Return FEC (if any) to which this label is bound.
222 * Note: Only works for per-prefix binding and when the label is not
224 * TODO: Currently walks entire table, can optimize later with another
227 zebra_fec_t
*zebra_mpls_fec_for_label(struct zebra_vrf
*zvrf
,
231 * Inform if specified label is currently bound to a FEC or not.
233 int zebra_mpls_label_already_bound(struct zebra_vrf
*zvrf
, mpls_label_t label
);
236 * Add static FEC to label binding. If there are clients registered for this
237 * FEC, notify them. If there are labeled routes for this FEC, install the
238 * label forwarding entry.
240 int zebra_mpls_static_fec_add(struct zebra_vrf
*zvrf
, struct prefix
*p
,
241 mpls_label_t in_label
);
244 * Remove static FEC to label binding. If there are no clients registered
245 * for this FEC, delete the FEC; else notify clients.
246 * Note: Upon delete of static binding, if label index exists for this FEC,
247 * client may need to be updated with derived label.
249 int zebra_mpls_static_fec_del(struct zebra_vrf
*zvrf
, struct prefix
*p
);
252 * Display MPLS FEC to label binding configuration (VTY command handler).
254 int zebra_mpls_write_fec_config(struct vty
*vty
, struct zebra_vrf
*zvrf
);
257 * Display MPLS FEC to label binding (VTY command handler).
259 void zebra_mpls_print_fec_table(struct vty
*vty
, struct zebra_vrf
*zvrf
);
262 * Display MPLS FEC to label binding for a specific FEC (VTY command handler).
264 void zebra_mpls_print_fec(struct vty
*vty
, struct zebra_vrf
*zvrf
,
268 * Install/uninstall a FEC-To-NHLFE (FTN) binding.
270 int mpls_ftn_update(int add
, struct zebra_vrf
*zvrf
, enum lsp_types_t type
,
271 struct prefix
*prefix
, enum nexthop_types_t gtype
,
272 union g_addr
*gate
, ifindex_t ifindex
, uint8_t distance
,
273 mpls_label_t out_label
);
276 * Install/update a NHLFE for an LSP in the forwarding table. This may be
277 * a new LSP entry or a new NHLFE for an existing in-label or an update of
278 * the out-label for an existing NHLFE (update case).
280 int mpls_lsp_install(struct zebra_vrf
*zvrf
, enum lsp_types_t type
,
281 mpls_label_t in_label
, mpls_label_t out_label
,
282 enum nexthop_types_t gtype
, union g_addr
*gate
,
286 * Uninstall a particular NHLFE in the forwarding table. If this is
287 * the only NHLFE, the entire LSP forwarding entry has to be deleted.
289 int mpls_lsp_uninstall(struct zebra_vrf
*zvrf
, enum lsp_types_t type
,
290 mpls_label_t in_label
, enum nexthop_types_t gtype
,
291 union g_addr
*gate
, ifindex_t ifindex
);
294 * Uninstall all LDP NHLFEs for a particular LSP forwarding entry.
295 * If no other NHLFEs exist, the entry would be deleted.
297 void mpls_ldp_lsp_uninstall_all(struct hash_bucket
*bucket
, void *ctxt
);
300 * Uninstall all LDP FEC-To-NHLFE (FTN) bindings of the given address-family.
302 void mpls_ldp_ftn_uninstall_all(struct zebra_vrf
*zvrf
, int afi
);
305 * Uninstall all Segment Routing NHLFEs for a particular LSP forwarding entry.
306 * If no other NHLFEs exist, the entry would be deleted.
308 void mpls_sr_lsp_uninstall_all(struct hash_bucket
*bucket
, void *ctxt
);
310 #if defined(HAVE_CUMULUS)
312 * Check that the label values used in LSP creation are consistent. The
313 * main criteria is that if there is ECMP, the label operation must still
314 * be consistent - i.e., all paths either do a swap or do PHP. This is due
315 * to current HW restrictions.
317 int zebra_mpls_lsp_label_consistent(struct zebra_vrf
*zvrf
,
318 mpls_label_t in_label
,
319 mpls_label_t out_label
,
320 enum nexthop_types_t gtype
,
321 union g_addr
*gate
, ifindex_t ifindex
);
322 #endif /* HAVE_CUMULUS */
325 * Add static LSP entry. This may be the first entry for this incoming label
326 * or an additional nexthop; an existing entry may also have outgoing label
328 * Note: The label operation (swap or PHP) is common for the LSP entry (all
331 int zebra_mpls_static_lsp_add(struct zebra_vrf
*zvrf
, mpls_label_t in_label
,
332 mpls_label_t out_label
,
333 enum nexthop_types_t gtype
, union g_addr
*gate
,
337 * Delete static LSP entry. This may be the delete of one particular
338 * NHLFE for this incoming label or the delete of the entire entry (i.e.,
340 * NOTE: Delete of the only NHLFE will also end up deleting the entire
343 int zebra_mpls_static_lsp_del(struct zebra_vrf
*zvrf
, mpls_label_t in_label
,
344 enum nexthop_types_t gtype
, union g_addr
*gate
,
348 * Process LSP update results from zebra dataplane.
350 /* Forward ref of dplane update context type */
351 struct zebra_dplane_ctx
;
353 void zebra_mpls_lsp_dplane_result(struct zebra_dplane_ctx
*ctx
);
355 /* Process async dplane notifications. */
356 void zebra_mpls_process_dplane_notify(struct zebra_dplane_ctx
*ctx
);
359 * Schedule all MPLS label forwarding entries for processing.
360 * Called upon changes that may affect one or more of them such as
361 * interface or nexthop state changes.
363 void zebra_mpls_lsp_schedule(struct zebra_vrf
*zvrf
);
366 * Display MPLS label forwarding table for a specific LSP
367 * (VTY command handler).
369 void zebra_mpls_print_lsp(struct vty
*vty
, struct zebra_vrf
*zvrf
,
370 mpls_label_t label
, bool use_json
);
373 * Display MPLS label forwarding table (VTY command handler).
375 void zebra_mpls_print_lsp_table(struct vty
*vty
, struct zebra_vrf
*zvrf
,
379 * Display MPLS LSP configuration of all static LSPs (VTY command handler).
381 int zebra_mpls_write_lsp_config(struct vty
*vty
, struct zebra_vrf
*zvrf
);
384 * Called when VRF becomes inactive, cleans up information but keeps
386 * NOTE: Currently supported only for default VRF.
388 void zebra_mpls_cleanup_tables(struct zebra_vrf
*zvrf
);
391 * Called upon process exiting, need to delete LSP forwarding
392 * entries from the kernel.
393 * NOTE: Currently supported only for default VRF.
395 void zebra_mpls_close_tables(struct zebra_vrf
*zvrf
);
398 * Allocate MPLS tables for this VRF.
399 * NOTE: Currently supported only for default VRF.
401 void zebra_mpls_init_tables(struct zebra_vrf
*zvrf
);
404 * Global MPLS initialization.
406 void zebra_mpls_init(void);
411 void zebra_mpls_vty_init(void);
413 /* Inline functions. */
416 * Distance (priority) definition for LSP NHLFE.
418 static inline uint8_t lsp_distance(enum lsp_types_t type
)
421 case ZEBRA_LSP_STATIC
:
422 return (route_distance(ZEBRA_ROUTE_STATIC
));
424 return (route_distance(ZEBRA_ROUTE_LDP
));
426 return (route_distance(ZEBRA_ROUTE_BGP
));
428 case ZEBRA_LSP_SHARP
:
434 * For some reason certain compilers do not believe
435 * that all the cases have been handled. And
436 * WTF does this work differently than when I removed
437 * the default case????
443 * Map RIB type to LSP type. Used when labeled-routes from BGP
444 * are converted into LSPs.
446 static inline enum lsp_types_t
lsp_type_from_re_type(int re_type
)
449 case ZEBRA_ROUTE_STATIC
:
450 return ZEBRA_LSP_STATIC
;
451 case ZEBRA_ROUTE_BGP
:
452 return ZEBRA_LSP_BGP
;
453 case ZEBRA_ROUTE_SHARP
:
454 return ZEBRA_LSP_SHARP
;
456 return ZEBRA_LSP_NONE
;
461 * Map LSP type to RIB type.
463 static inline int re_type_from_lsp_type(enum lsp_types_t lsp_type
)
466 case ZEBRA_LSP_STATIC
:
467 return ZEBRA_ROUTE_STATIC
;
469 return ZEBRA_ROUTE_LDP
;
471 return ZEBRA_ROUTE_BGP
;
473 return ZEBRA_ROUTE_OSPF
;
475 return ZEBRA_ROUTE_KERNEL
;
476 case ZEBRA_LSP_SHARP
:
477 return ZEBRA_ROUTE_SHARP
;
481 * For some reason certain compilers do not believe
482 * that all the cases have been handled. And
483 * WTF does this work differently than when I removed
484 * the default case????
486 return ZEBRA_ROUTE_KERNEL
;
489 /* NHLFE type as printable string. */
490 static inline const char *nhlfe_type2str(enum lsp_types_t lsp_type
)
493 case ZEBRA_LSP_STATIC
:
501 case ZEBRA_LSP_SHARP
:
508 * For some reason certain compilers do not believe
509 * that all the cases have been handled. And
510 * WTF does this work differently than when I removed
511 * the default case????
516 static inline void mpls_mark_lsps_for_processing(struct zebra_vrf
*zvrf
,
519 struct route_table
*table
;
520 struct route_node
*rn
;
526 table
= zvrf
->table
[family2afi(p
->family
)][SAFI_UNICAST
];
530 rn
= route_node_match(table
, p
);
535 dest
= rib_dest_from_rnode(rn
);
536 SET_FLAG(dest
->flags
, RIB_DEST_UPDATE_LSPS
);
539 static inline void mpls_unmark_lsps_for_processing(struct route_node
*rn
)
541 rib_dest_t
*dest
= rib_dest_from_rnode(rn
);
543 UNSET_FLAG(dest
->flags
, RIB_DEST_UPDATE_LSPS
);
546 static inline int mpls_should_lsps_be_processed(struct route_node
*rn
)
548 rib_dest_t
*dest
= rib_dest_from_rnode(rn
);
550 return !!CHECK_FLAG(dest
->flags
, RIB_DEST_UPDATE_LSPS
);
553 /* Global variables. */
554 extern int mpls_enabled
;
560 #endif /*_ZEBRA_MPLS_H */