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"
38 /* Definitions and macros. */
40 #define NHLFE_FAMILY(nhlfe) \
41 (((nhlfe)->nexthop->type == NEXTHOP_TYPE_IPV6 \
42 || (nhlfe)->nexthop->type == NEXTHOP_TYPE_IPV6_IFINDEX) \
48 typedef struct zebra_ile_t_ zebra_ile_t
;
49 typedef struct zebra_snhlfe_t_ zebra_snhlfe_t
;
50 typedef struct zebra_slsp_t_ zebra_slsp_t
;
51 typedef struct zebra_nhlfe_t_ zebra_nhlfe_t
;
52 typedef struct zebra_lsp_t_ zebra_lsp_t
;
53 typedef struct zebra_fec_t_ zebra_fec_t
;
56 * (Outgoing) nexthop label forwarding entry configuration
58 struct zebra_snhlfe_t_
{
59 /* Nexthop information */
60 enum nexthop_types_t gtype
;
66 mpls_label_t out_label
;
68 /* Backpointer to base entry. */
71 /* Pointers to more outgoing information for same in-label */
77 * (Outgoing) nexthop label forwarding entry
79 struct zebra_nhlfe_t_
{
80 /* Type of entry - static etc. */
81 enum lsp_types_t type
;
83 /* Nexthop information (with outgoing label) */
84 struct nexthop
*nexthop
;
86 /* Backpointer to base entry. */
89 /* Runtime info - flags, pointers etc. */
91 #define NHLFE_FLAG_CHANGED (1 << 0)
92 #define NHLFE_FLAG_SELECTED (1 << 1)
93 #define NHLFE_FLAG_MULTIPATH (1 << 2)
94 #define NHLFE_FLAG_DELETED (1 << 3)
95 #define NHLFE_FLAG_INSTALLED (1 << 4)
103 * Incoming label entry
105 struct zebra_ile_t_
{
106 mpls_label_t in_label
;
110 * Label swap entry static configuration.
112 struct zebra_slsp_t_
{
116 /* List of outgoing nexthop static configuration */
117 zebra_snhlfe_t
*snhlfe_list
;
121 * Label swap entry (ile -> list of nhlfes)
123 struct zebra_lsp_t_
{
127 /* List of NHLFE, pointer to best and num equal-cost. */
128 zebra_nhlfe_t
*nhlfe_list
;
129 zebra_nhlfe_t
*best_nhlfe
;
134 #define LSP_FLAG_SCHEDULED (1 << 0)
135 #define LSP_FLAG_INSTALLED (1 << 1)
136 #define LSP_FLAG_CHANGED (1 << 2)
138 /* Address-family of NHLFE - saved here for delete. All NHLFEs */
139 /* have to be of the same AF */
144 * FEC to label binding.
146 struct zebra_fec_t_
{
148 struct route_node
*rn
;
150 /* In-label - either statically bound or derived from label block. */
153 /* Label index (into global label block), if valid */
154 uint32_t label_index
;
158 #define FEC_FLAG_CONFIGURED (1 << 0)
160 /* Clients interested in this FEC. */
161 struct list
*client_list
;
164 /* Function declarations. */
167 * Add/update global label block.
169 int zebra_mpls_label_block_add(struct zebra_vrf
*zvrf
, uint32_t start_label
,
173 * Delete global label block.
175 int zebra_mpls_label_block_del(struct zebra_vrf
*vrf
);
178 * Display MPLS global label block configuration (VTY command handler).
180 int zebra_mpls_write_label_block_config(struct vty
*vty
, struct zebra_vrf
*vrf
);
183 * Install dynamic LSP entry.
185 int zebra_mpls_lsp_install(struct zebra_vrf
*zvrf
, struct route_node
*rn
,
186 struct route_entry
*re
);
189 * Uninstall dynamic LSP entry, if any.
191 int zebra_mpls_lsp_uninstall(struct zebra_vrf
*zvrf
, struct route_node
*rn
,
192 struct route_entry
*re
);
195 * Registration from a client for the label binding for a FEC. If a binding
196 * already exists, it is informed to the client.
197 * NOTE: If there is a manually configured label binding, that is used.
198 * Otherwise, if aa label index is specified, it means we have to allocate the
199 * label from a locally configured label block (SRGB), if one exists and index
202 int zebra_mpls_fec_register(struct zebra_vrf
*zvrf
, struct prefix
*p
,
203 uint32_t label_index
, struct zserv
*client
);
206 * Deregistration from a client for the label binding for a FEC. The FEC
207 * itself is deleted if no other registered clients exist and there is no
208 * label bound to the FEC.
210 int zebra_mpls_fec_unregister(struct zebra_vrf
*zvrf
, struct prefix
*p
,
211 struct zserv
*client
);
214 * Return FEC (if any) to which this label is bound.
215 * Note: Only works for per-prefix binding and when the label is not
217 * TODO: Currently walks entire table, can optimize later with another
220 zebra_fec_t
*zebra_mpls_fec_for_label(struct zebra_vrf
*zvrf
,
224 * Inform if specified label is currently bound to a FEC or not.
226 int zebra_mpls_label_already_bound(struct zebra_vrf
*zvrf
, mpls_label_t label
);
229 * Add static FEC to label binding. If there are clients registered for this
230 * FEC, notify them. If there are labeled routes for this FEC, install the
231 * label forwarding entry.
233 int zebra_mpls_static_fec_add(struct zebra_vrf
*zvrf
, struct prefix
*p
,
234 mpls_label_t in_label
);
237 * Remove static FEC to label binding. If there are no clients registered
238 * for this FEC, delete the FEC; else notify clients.
239 * Note: Upon delete of static binding, if label index exists for this FEC,
240 * client may need to be updated with derived label.
242 int zebra_mpls_static_fec_del(struct zebra_vrf
*zvrf
, struct prefix
*p
);
245 * Display MPLS FEC to label binding configuration (VTY command handler).
247 int zebra_mpls_write_fec_config(struct vty
*vty
, struct zebra_vrf
*zvrf
);
250 * Display MPLS FEC to label binding (VTY command handler).
252 void zebra_mpls_print_fec_table(struct vty
*vty
, struct zebra_vrf
*zvrf
);
255 * Display MPLS FEC to label binding for a specific FEC (VTY command handler).
257 void zebra_mpls_print_fec(struct vty
*vty
, struct zebra_vrf
*zvrf
,
261 * Install/uninstall a FEC-To-NHLFE (FTN) binding.
263 int mpls_ftn_update(int add
, struct zebra_vrf
*zvrf
, enum lsp_types_t type
,
264 struct prefix
*prefix
, enum nexthop_types_t gtype
,
265 union g_addr
*gate
, ifindex_t ifindex
, uint8_t distance
,
266 mpls_label_t out_label
);
269 * Install/update a NHLFE for an LSP in the forwarding table. This may be
270 * a new LSP entry or a new NHLFE for an existing in-label or an update of
271 * the out-label for an existing NHLFE (update case).
273 int mpls_lsp_install(struct zebra_vrf
*zvrf
, enum lsp_types_t type
,
274 mpls_label_t in_label
, mpls_label_t out_label
,
275 enum nexthop_types_t gtype
, union g_addr
*gate
,
279 * Uninstall a particular NHLFE in the forwarding table. If this is
280 * the only NHLFE, the entire LSP forwarding entry has to be deleted.
282 int mpls_lsp_uninstall(struct zebra_vrf
*zvrf
, enum lsp_types_t type
,
283 mpls_label_t in_label
, enum nexthop_types_t gtype
,
284 union g_addr
*gate
, ifindex_t ifindex
);
287 * Uninstall all LDP NHLFEs for a particular LSP forwarding entry.
288 * If no other NHLFEs exist, the entry would be deleted.
290 void mpls_ldp_lsp_uninstall_all(struct hash_backet
*backet
, void *ctxt
);
293 * Uninstall all LDP FEC-To-NHLFE (FTN) bindings of the given address-family.
295 void mpls_ldp_ftn_uninstall_all(struct zebra_vrf
*zvrf
, int afi
);
298 * Uninstall all Segment Routing NHLFEs for a particular LSP forwarding entry.
299 * If no other NHLFEs exist, the entry would be deleted.
301 void mpls_sr_lsp_uninstall_all(struct hash_backet
*backet
, void *ctxt
);
303 #if defined(HAVE_CUMULUS)
305 * Check that the label values used in LSP creation are consistent. The
306 * main criteria is that if there is ECMP, the label operation must still
307 * be consistent - i.e., all paths either do a swap or do PHP. This is due
308 * to current HW restrictions.
310 int zebra_mpls_lsp_label_consistent(struct zebra_vrf
*zvrf
,
311 mpls_label_t in_label
,
312 mpls_label_t out_label
,
313 enum nexthop_types_t gtype
,
314 union g_addr
*gate
, ifindex_t ifindex
);
315 #endif /* HAVE_CUMULUS */
318 * Add static LSP entry. This may be the first entry for this incoming label
319 * or an additional nexthop; an existing entry may also have outgoing label
321 * Note: The label operation (swap or PHP) is common for the LSP entry (all
324 int zebra_mpls_static_lsp_add(struct zebra_vrf
*zvrf
, mpls_label_t in_label
,
325 mpls_label_t out_label
,
326 enum nexthop_types_t gtype
, union g_addr
*gate
,
330 * Delete static LSP entry. This may be the delete of one particular
331 * NHLFE for this incoming label or the delete of the entire entry (i.e.,
333 * NOTE: Delete of the only NHLFE will also end up deleting the entire
336 int zebra_mpls_static_lsp_del(struct zebra_vrf
*zvrf
, mpls_label_t in_label
,
337 enum nexthop_types_t gtype
, union g_addr
*gate
,
341 * Schedule all MPLS label forwarding entries for processing.
342 * Called upon changes that may affect one or more of them such as
343 * interface or nexthop state changes.
345 void zebra_mpls_lsp_schedule(struct zebra_vrf
*zvrf
);
348 * Display MPLS label forwarding table for a specific LSP
349 * (VTY command handler).
351 void zebra_mpls_print_lsp(struct vty
*vty
, struct zebra_vrf
*zvrf
,
352 mpls_label_t label
, bool use_json
);
355 * Display MPLS label forwarding table (VTY command handler).
357 void zebra_mpls_print_lsp_table(struct vty
*vty
, struct zebra_vrf
*zvrf
,
361 * Display MPLS LSP configuration of all static LSPs (VTY command handler).
363 int zebra_mpls_write_lsp_config(struct vty
*vty
, struct zebra_vrf
*zvrf
);
366 * Called when VRF becomes inactive, cleans up information but keeps
368 * NOTE: Currently supported only for default VRF.
370 void zebra_mpls_cleanup_tables(struct zebra_vrf
*zvrf
);
373 * Called upon process exiting, need to delete LSP forwarding
374 * entries from the kernel.
375 * NOTE: Currently supported only for default VRF.
377 void zebra_mpls_close_tables(struct zebra_vrf
*zvrf
);
380 * Allocate MPLS tables for this VRF.
381 * NOTE: Currently supported only for default VRF.
383 void zebra_mpls_init_tables(struct zebra_vrf
*zvrf
);
386 * Global MPLS initialization.
388 void zebra_mpls_init(void);
393 void zebra_mpls_vty_init(void);
395 /* Inline functions. */
398 * Distance (priority) definition for LSP NHLFE.
400 static inline uint8_t lsp_distance(enum lsp_types_t type
)
403 case ZEBRA_LSP_STATIC
:
404 return (route_distance(ZEBRA_ROUTE_STATIC
));
406 return (route_distance(ZEBRA_ROUTE_LDP
));
408 return (route_distance(ZEBRA_ROUTE_BGP
));
410 case ZEBRA_LSP_SHARP
:
416 * For some reason certain compilers do not believe
417 * that all the cases have been handled. And
418 * WTF does this work differently than when I removed
419 * the default case????
425 * Map RIB type to LSP type. Used when labeled-routes from BGP
426 * are converted into LSPs.
428 static inline enum lsp_types_t
lsp_type_from_re_type(int re_type
)
431 case ZEBRA_ROUTE_STATIC
:
432 return ZEBRA_LSP_STATIC
;
433 case ZEBRA_ROUTE_BGP
:
434 return ZEBRA_LSP_BGP
;
435 case ZEBRA_ROUTE_SHARP
:
436 return ZEBRA_LSP_SHARP
;
438 return ZEBRA_LSP_NONE
;
443 * Map LSP type to RIB type.
445 static inline int re_type_from_lsp_type(enum lsp_types_t lsp_type
)
448 case ZEBRA_LSP_STATIC
:
449 return ZEBRA_ROUTE_STATIC
;
451 return ZEBRA_ROUTE_LDP
;
453 return ZEBRA_ROUTE_BGP
;
455 return ZEBRA_ROUTE_OSPF
;
457 return ZEBRA_ROUTE_KERNEL
;
458 case ZEBRA_LSP_SHARP
:
459 return ZEBRA_ROUTE_SHARP
;
463 * For some reason certain compilers do not believe
464 * that all the cases have been handled. And
465 * WTF does this work differently than when I removed
466 * the default case????
468 return ZEBRA_ROUTE_KERNEL
;
471 /* NHLFE type as printable string. */
472 static inline const char *nhlfe_type2str(enum lsp_types_t lsp_type
)
475 case ZEBRA_LSP_STATIC
:
483 case ZEBRA_LSP_SHARP
:
490 * For some reason certain compilers do not believe
491 * that all the cases have been handled. And
492 * WTF does this work differently than when I removed
493 * the default case????
498 static inline void mpls_mark_lsps_for_processing(struct zebra_vrf
*zvrf
)
503 zvrf
->mpls_flags
|= MPLS_FLAG_SCHEDULE_LSPS
;
506 static inline void mpls_unmark_lsps_for_processing(struct zebra_vrf
*zvrf
)
511 zvrf
->mpls_flags
&= ~MPLS_FLAG_SCHEDULE_LSPS
;
514 static inline int mpls_should_lsps_be_processed(struct zebra_vrf
*zvrf
)
519 return ((zvrf
->mpls_flags
& MPLS_FLAG_SCHEDULE_LSPS
) ? 1 : 0);
522 /* Global variables. */
523 extern int mpls_enabled
;
525 #endif /*_ZEBRA_MPLS_H */