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) \
46 #define MPLS_LABEL_HELPSTR \
47 "Specify label(s) for this route\nOne or more " \
48 "labels in the range (16-1048575) separated by '/'\n"
52 typedef struct zebra_ile_t_ zebra_ile_t
;
53 typedef struct zebra_snhlfe_t_ zebra_snhlfe_t
;
54 typedef struct zebra_slsp_t_ zebra_slsp_t
;
55 typedef struct zebra_nhlfe_t_ zebra_nhlfe_t
;
56 typedef struct zebra_lsp_t_ zebra_lsp_t
;
57 typedef struct zebra_fec_t_ zebra_fec_t
;
60 * (Outgoing) nexthop label forwarding entry configuration
62 struct zebra_snhlfe_t_
{
63 /* Nexthop information */
64 enum nexthop_types_t gtype
;
70 mpls_label_t out_label
;
72 /* Backpointer to base entry. */
75 /* Pointers to more outgoing information for same in-label */
81 * (Outgoing) nexthop label forwarding entry
83 struct zebra_nhlfe_t_
{
84 /* Type of entry - static etc. */
85 enum lsp_types_t type
;
87 /* Nexthop information (with outgoing label) */
88 struct nexthop
*nexthop
;
90 /* Backpointer to base entry. */
93 /* Runtime info - flags, pointers etc. */
95 #define NHLFE_FLAG_CHANGED (1 << 0)
96 #define NHLFE_FLAG_SELECTED (1 << 1)
97 #define NHLFE_FLAG_MULTIPATH (1 << 2)
98 #define NHLFE_FLAG_DELETED (1 << 3)
99 #define NHLFE_FLAG_INSTALLED (1 << 4)
107 * Incoming label entry
109 struct zebra_ile_t_
{
110 mpls_label_t in_label
;
114 * Label swap entry static configuration.
116 struct zebra_slsp_t_
{
120 /* List of outgoing nexthop static configuration */
121 zebra_snhlfe_t
*snhlfe_list
;
125 * Label swap entry (ile -> list of nhlfes)
127 struct zebra_lsp_t_
{
131 /* List of NHLFE, pointer to best and num equal-cost. */
132 zebra_nhlfe_t
*nhlfe_list
;
133 zebra_nhlfe_t
*best_nhlfe
;
138 #define LSP_FLAG_SCHEDULED (1 << 0)
139 #define LSP_FLAG_INSTALLED (1 << 1)
140 #define LSP_FLAG_CHANGED (1 << 2)
142 /* Address-family of NHLFE - saved here for delete. All NHLFEs */
143 /* have to be of the same AF */
148 * FEC to label binding.
150 struct zebra_fec_t_
{
152 struct route_node
*rn
;
154 /* In-label - either statically bound or derived from label block. */
157 /* Label index (into global label block), if valid */
158 u_int32_t label_index
;
162 #define FEC_FLAG_CONFIGURED (1 << 0)
164 /* Clients interested in this FEC. */
165 struct list
*client_list
;
168 /* Function declarations. */
171 * String to label conversion, labels separated by '/'.
173 int mpls_str2label(const char *label_str
, u_int8_t
*num_labels
,
174 mpls_label_t
*labels
);
177 * Label to string conversion, labels in string separated by '/'.
179 char *mpls_label2str(u_int8_t num_labels
, mpls_label_t
*labels
, char *buf
,
180 int len
, int pretty
);
183 * Add/update global label block.
185 int zebra_mpls_label_block_add(struct zebra_vrf
*zvrf
, u_int32_t start_label
,
186 u_int32_t end_label
);
189 * Delete global label block.
191 int zebra_mpls_label_block_del(struct zebra_vrf
*vrf
);
194 * Display MPLS global label block configuration (VTY command handler).
196 int zebra_mpls_write_label_block_config(struct vty
*vty
, struct zebra_vrf
*vrf
);
199 * Install dynamic LSP entry.
201 int zebra_mpls_lsp_install(struct zebra_vrf
*zvrf
, struct route_node
*rn
,
202 struct route_entry
*re
);
205 * Uninstall dynamic LSP entry, if any.
207 int zebra_mpls_lsp_uninstall(struct zebra_vrf
*zvrf
, struct route_node
*rn
,
208 struct route_entry
*re
);
211 * Registration from a client for the label binding for a FEC. If a binding
212 * already exists, it is informed to the client.
213 * NOTE: If there is a manually configured label binding, that is used.
214 * Otherwise, if aa label index is specified, it means we have to allocate the
215 * label from a locally configured label block (SRGB), if one exists and index
218 int zebra_mpls_fec_register(struct zebra_vrf
*zvrf
, struct prefix
*p
,
219 u_int32_t label_index
, struct zserv
*client
);
222 * Deregistration from a client for the label binding for a FEC. The FEC
223 * itself is deleted if no other registered clients exist and there is no
224 * label bound to the FEC.
226 int zebra_mpls_fec_unregister(struct zebra_vrf
*zvrf
, struct prefix
*p
,
227 struct zserv
*client
);
230 * Cleanup any FECs registered by this client.
232 int zebra_mpls_cleanup_fecs_for_client(struct zebra_vrf
*zvrf
,
233 struct zserv
*client
);
236 * Return FEC (if any) to which this label is bound.
237 * Note: Only works for per-prefix binding and when the label is not
239 * TODO: Currently walks entire table, can optimize later with another
242 zebra_fec_t
*zebra_mpls_fec_for_label(struct zebra_vrf
*zvrf
,
246 * Inform if specified label is currently bound to a FEC or not.
248 int zebra_mpls_label_already_bound(struct zebra_vrf
*zvrf
, mpls_label_t label
);
251 * Add static FEC to label binding. If there are clients registered for this
252 * FEC, notify them. If there are labeled routes for this FEC, install the
253 * label forwarding entry.
255 int zebra_mpls_static_fec_add(struct zebra_vrf
*zvrf
, struct prefix
*p
,
256 mpls_label_t in_label
);
259 * Remove static FEC to label binding. If there are no clients registered
260 * for this FEC, delete the FEC; else notify clients.
261 * Note: Upon delete of static binding, if label index exists for this FEC,
262 * client may need to be updated with derived label.
264 int zebra_mpls_static_fec_del(struct zebra_vrf
*zvrf
, struct prefix
*p
);
267 * Display MPLS FEC to label binding configuration (VTY command handler).
269 int zebra_mpls_write_fec_config(struct vty
*vty
, struct zebra_vrf
*zvrf
);
272 * Display MPLS FEC to label binding (VTY command handler).
274 void zebra_mpls_print_fec_table(struct vty
*vty
, struct zebra_vrf
*zvrf
);
277 * Display MPLS FEC to label binding for a specific FEC (VTY command handler).
279 void zebra_mpls_print_fec(struct vty
*vty
, struct zebra_vrf
*zvrf
,
283 * Install/uninstall a FEC-To-NHLFE (FTN) binding.
285 int mpls_ftn_update(int add
, struct zebra_vrf
*zvrf
, enum lsp_types_t type
,
286 struct prefix
*prefix
, enum nexthop_types_t gtype
,
287 union g_addr
*gate
, ifindex_t ifindex
, u_int8_t distance
,
288 mpls_label_t out_label
);
291 * Install/update a NHLFE for an LSP in the forwarding table. This may be
292 * a new LSP entry or a new NHLFE for an existing in-label or an update of
293 * the out-label for an existing NHLFE (update case).
295 int mpls_lsp_install(struct zebra_vrf
*zvrf
, enum lsp_types_t type
,
296 mpls_label_t in_label
, mpls_label_t out_label
,
297 enum nexthop_types_t gtype
, union g_addr
*gate
,
301 * Uninstall a particular NHLFE in the forwarding table. If this is
302 * the only NHLFE, the entire LSP forwarding entry has to be deleted.
304 int mpls_lsp_uninstall(struct zebra_vrf
*zvrf
, enum lsp_types_t type
,
305 mpls_label_t in_label
, enum nexthop_types_t gtype
,
306 union g_addr
*gate
, ifindex_t ifindex
);
309 * Uninstall all LDP NHLFEs for a particular LSP forwarding entry.
310 * If no other NHLFEs exist, the entry would be deleted.
312 void mpls_ldp_lsp_uninstall_all(struct hash_backet
*backet
, void *ctxt
);
315 * Uninstall all LDP FEC-To-NHLFE (FTN) bindings of the given address-family.
317 void mpls_ldp_ftn_uninstall_all(struct zebra_vrf
*zvrf
, int afi
);
319 #if defined(HAVE_CUMULUS)
321 * Check that the label values used in LSP creation are consistent. The
322 * main criteria is that if there is ECMP, the label operation must still
323 * be consistent - i.e., all paths either do a swap or do PHP. This is due
324 * to current HW restrictions.
326 int zebra_mpls_lsp_label_consistent(struct zebra_vrf
*zvrf
,
327 mpls_label_t in_label
,
328 mpls_label_t out_label
,
329 enum nexthop_types_t gtype
,
330 union g_addr
*gate
, ifindex_t ifindex
);
331 #endif /* HAVE_CUMULUS */
334 * Add static LSP entry. This may be the first entry for this incoming label
335 * or an additional nexthop; an existing entry may also have outgoing label
337 * Note: The label operation (swap or PHP) is common for the LSP entry (all
340 int zebra_mpls_static_lsp_add(struct zebra_vrf
*zvrf
, mpls_label_t in_label
,
341 mpls_label_t out_label
,
342 enum nexthop_types_t gtype
, union g_addr
*gate
,
346 * Delete static LSP entry. This may be the delete of one particular
347 * NHLFE for this incoming label or the delete of the entire entry (i.e.,
349 * NOTE: Delete of the only NHLFE will also end up deleting the entire
352 int zebra_mpls_static_lsp_del(struct zebra_vrf
*zvrf
, mpls_label_t in_label
,
353 enum nexthop_types_t gtype
, union g_addr
*gate
,
357 * Schedule all MPLS label forwarding entries for processing.
358 * Called upon changes that may affect one or more of them such as
359 * interface or nexthop state changes.
361 void zebra_mpls_lsp_schedule(struct zebra_vrf
*zvrf
);
364 * Display MPLS label forwarding table for a specific LSP
365 * (VTY command handler).
367 void zebra_mpls_print_lsp(struct vty
*vty
, struct zebra_vrf
*zvrf
,
368 mpls_label_t label
, u_char use_json
);
371 * Display MPLS label forwarding table (VTY command handler).
373 void zebra_mpls_print_lsp_table(struct vty
*vty
, struct zebra_vrf
*zvrf
,
377 * Display MPLS LSP configuration of all static LSPs (VTY command handler).
379 int zebra_mpls_write_lsp_config(struct vty
*vty
, struct zebra_vrf
*zvrf
);
382 * Called upon process exiting, need to delete LSP forwarding
383 * entries from the kernel.
384 * NOTE: Currently supported only for default VRF.
386 void zebra_mpls_close_tables(struct zebra_vrf
*zvrf
);
389 * Allocate MPLS tables for this VRF.
390 * NOTE: Currently supported only for default VRF.
392 void zebra_mpls_init_tables(struct zebra_vrf
*zvrf
);
395 * Global MPLS initialization.
397 void zebra_mpls_init(void);
402 void zebra_mpls_vty_init(void);
404 /* Inline functions. */
407 * Distance (priority) definition for LSP NHLFE.
409 static inline u_char
lsp_distance(enum lsp_types_t type
)
411 if (type
== ZEBRA_LSP_STATIC
)
412 return (route_distance(ZEBRA_ROUTE_STATIC
));
418 * Map RIB type to LSP type. Used when labeled-routes from BGP
419 * are converted into LSPs.
421 static inline enum lsp_types_t
lsp_type_from_re_type(int re_type
)
424 case ZEBRA_ROUTE_STATIC
:
425 return ZEBRA_LSP_STATIC
;
426 case ZEBRA_ROUTE_BGP
:
427 return ZEBRA_LSP_BGP
;
429 return ZEBRA_LSP_NONE
;
433 /* NHLFE type as printable string. */
434 static inline const char *nhlfe_type2str(enum lsp_types_t lsp_type
)
437 case ZEBRA_LSP_STATIC
:
448 static inline void mpls_mark_lsps_for_processing(struct zebra_vrf
*zvrf
)
453 zvrf
->mpls_flags
|= MPLS_FLAG_SCHEDULE_LSPS
;
456 static inline void mpls_unmark_lsps_for_processing(struct zebra_vrf
*zvrf
)
461 zvrf
->mpls_flags
&= ~MPLS_FLAG_SCHEDULE_LSPS
;
464 static inline int mpls_should_lsps_be_processed(struct zebra_vrf
*zvrf
)
469 return ((zvrf
->mpls_flags
& MPLS_FLAG_SCHEDULE_LSPS
) ? 1 : 0);
472 /* Global variables. */
473 extern int mpls_enabled
;
475 #endif /*_ZEBRA_MPLS_H */