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
18 * along with GNU Zebra; see the file COPYING. If not, write to the Free
19 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
35 #include "zebra/zserv.h"
36 #include "zebra/zebra_vrf.h"
39 /* Definitions and macros. */
41 #define MPLS_MAX_LABELS 2 /* Maximum # labels that can be pushed. */
43 #define NHLFE_FAMILY(nhlfe) \
44 (((nhlfe)->nexthop->type == NEXTHOP_TYPE_IPV6 || \
45 (nhlfe)->nexthop->type == NEXTHOP_TYPE_IPV6_IFINDEX) ? AF_INET6 : AF_INET)
50 typedef struct zebra_ile_t_ zebra_ile_t
;
51 typedef struct zebra_snhlfe_t_ zebra_snhlfe_t
;
52 typedef struct zebra_slsp_t_ zebra_slsp_t
;
53 typedef struct zebra_nhlfe_t_ zebra_nhlfe_t
;
54 typedef struct zebra_lsp_t_ zebra_lsp_t
;
55 typedef struct zebra_fec_t_ zebra_fec_t
;
58 * (Outgoing) nexthop label forwarding entry configuration
60 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
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
111 mpls_label_t in_label
;
115 * Label swap entry static configuration.
122 /* List of outgoing nexthop static configuration */
123 zebra_snhlfe_t
*snhlfe_list
;
128 * Label swap entry (ile -> list of nhlfes)
135 /* List of NHLFE, pointer to best and num equal-cost. */
136 zebra_nhlfe_t
*nhlfe_list
;
137 zebra_nhlfe_t
*best_nhlfe
;
142 #define LSP_FLAG_SCHEDULED (1 << 0)
143 #define LSP_FLAG_INSTALLED (1 << 1)
144 #define LSP_FLAG_CHANGED (1 << 2)
146 /* Address-family of NHLFE - saved here for delete. All NHLFEs */
147 /* have to be of the same AF */
152 * FEC to label binding.
157 struct route_node
*rn
;
159 /* In-label - either statically bound or derived from label block. */
164 #define FEC_FLAG_CONFIGURED (1 << 0)
166 /* Clients interested in this FEC. */
167 struct list
*client_list
;
170 /* Function declarations. */
173 * String to label conversion, labels separated by '/'.
176 mpls_str2label (const char *label_str
, u_int8_t
*num_labels
,
177 mpls_label_t
*labels
);
180 * Label to string conversion, labels in string separated by '/'.
183 mpls_label2str (u_int8_t num_labels
, mpls_label_t
*labels
,
187 * Registration from a client for the label binding for a FEC. If a binding
188 * already exists, it is informed to the client.
191 zebra_mpls_fec_register (struct zebra_vrf
*zvrf
, struct prefix
*p
,
192 struct zserv
*client
);
195 * Deregistration from a client for the label binding for a FEC. The FEC
196 * itself is deleted if no other registered clients exist and there is no
197 * label bound to the FEC.
200 zebra_mpls_fec_unregister (struct zebra_vrf
*zvrf
, struct prefix
*p
,
201 struct zserv
*client
);
204 * Cleanup any FECs registered by this client.
207 zebra_mpls_cleanup_fecs_for_client (struct zebra_vrf
*zvrf
, struct zserv
*client
);
210 * Return FEC (if any) to which this label is bound.
211 * Note: Only works for per-prefix binding and when the label is not
213 * TODO: Currently walks entire table, can optimize later with another
217 zebra_mpls_fec_for_label (struct zebra_vrf
*zvrf
, mpls_label_t label
);
220 * Inform if specified label is currently bound to a FEC or not.
223 zebra_mpls_label_already_bound (struct zebra_vrf
*zvrf
, mpls_label_t label
);
226 * Add static FEC to label binding. If there are clients registered for this
230 zebra_mpls_static_fec_add (struct zebra_vrf
*zvrf
, struct prefix
*p
,
231 mpls_label_t in_label
);
234 * Remove static FEC to label binding. If there are no clients registered
235 * for this FEC, delete the FEC; else notify clients.
238 zebra_mpls_static_fec_del (struct zebra_vrf
*zvrf
, struct prefix
*p
);
241 * Display MPLS FEC to label binding configuration (VTY command handler).
244 zebra_mpls_write_fec_config (struct vty
*vty
, struct zebra_vrf
*zvrf
);
247 * Display MPLS FEC to label binding (VTY command handler).
250 zebra_mpls_print_fec_table (struct vty
*vty
, struct zebra_vrf
*zvrf
);
253 * Display MPLS FEC to label binding for a specific FEC (VTY command handler).
256 zebra_mpls_print_fec (struct vty
*vty
, struct zebra_vrf
*zvrf
, struct prefix
*p
);
259 * Install/uninstall a FEC-To-NHLFE (FTN) binding.
262 mpls_ftn_update (int add
, struct zebra_vrf
*zvrf
, enum lsp_types_t type
,
263 struct prefix
*prefix
, enum nexthop_types_t gtype
,
264 union g_addr
*gate
, ifindex_t ifindex
, u_int8_t distance
,
265 mpls_label_t out_label
);
268 * Install/update a NHLFE for an LSP in the forwarding table. This may be
269 * a new LSP entry or a new NHLFE for an existing in-label or an update of
270 * the out-label for an existing NHLFE (update case).
273 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
,
276 char *ifname
, ifindex_t ifindex
);
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.
283 mpls_lsp_uninstall (struct zebra_vrf
*zvrf
, enum lsp_types_t type
,
284 mpls_label_t in_label
, enum nexthop_types_t gtype
,
285 union g_addr
*gate
, char *ifname
, ifindex_t ifindex
);
288 * Uninstall all LDP NHLFEs for a particular LSP forwarding entry.
289 * If no other NHLFEs exist, the entry would be deleted.
292 mpls_ldp_lsp_uninstall_all (struct hash_backet
*backet
, void *ctxt
);
295 * Uninstall all LDP FEC-To-NHLFE (FTN) bindings of the given address-family.
298 mpls_ldp_ftn_uninstall_all (struct zebra_vrf
*zvrf
, int afi
);
300 #if defined(HAVE_CUMULUS)
302 * Check that the label values used in LSP creation are consistent. The
303 * main criteria is that if there is ECMP, the label operation must still
304 * be consistent - i.e., all paths either do a swap or do PHP. This is due
305 * to current HW restrictions.
308 zebra_mpls_lsp_label_consistent (struct zebra_vrf
*zvrf
, mpls_label_t in_label
,
309 mpls_label_t out_label
, enum nexthop_types_t gtype
,
310 union g_addr
*gate
, char *ifname
, ifindex_t ifindex
);
311 #endif /* HAVE_CUMULUS */
314 * Add static LSP entry. This may be the first entry for this incoming label
315 * or an additional nexthop; an existing entry may also have outgoing label
317 * Note: The label operation (swap or PHP) is common for the LSP entry (all
321 zebra_mpls_static_lsp_add (struct zebra_vrf
*zvrf
, mpls_label_t in_label
,
322 mpls_label_t out_label
, enum nexthop_types_t gtype
,
323 union g_addr
*gate
, char *ifname
, ifindex_t ifindex
);
326 * Delete static LSP entry. This may be the delete of one particular
327 * NHLFE for this incoming label or the delete of the entire entry (i.e.,
329 * NOTE: Delete of the only NHLFE will also end up deleting the entire
333 zebra_mpls_static_lsp_del (struct zebra_vrf
*zvrf
, mpls_label_t in_label
,
334 enum nexthop_types_t gtype
, union g_addr
*gate
,
335 char *ifname
, ifindex_t ifindex
);
338 * Schedule all MPLS label forwarding entries for processing.
339 * Called upon changes that may affect one or more of them such as
340 * interface or nexthop state changes.
343 zebra_mpls_lsp_schedule (struct zebra_vrf
*zvrf
);
346 * Display MPLS label forwarding table for a specific LSP
347 * (VTY command handler).
350 zebra_mpls_print_lsp (struct vty
*vty
, struct zebra_vrf
*zvrf
, mpls_label_t label
,
354 * Display MPLS label forwarding table (VTY command handler).
357 zebra_mpls_print_lsp_table (struct vty
*vty
, struct zebra_vrf
*zvrf
,
361 * Display MPLS LSP configuration of all static LSPs (VTY command handler).
364 zebra_mpls_write_lsp_config (struct vty
*vty
, struct zebra_vrf
*zvrf
);
367 * Called upon process exiting, need to delete LSP forwarding
368 * entries from the kernel.
369 * NOTE: Currently supported only for default VRF.
372 zebra_mpls_close_tables (struct zebra_vrf
*zvrf
);
375 * Allocate MPLS tables for this VRF.
376 * NOTE: Currently supported only for default VRF.
379 zebra_mpls_init_tables (struct zebra_vrf
*zvrf
);
382 * Global MPLS initialization.
385 zebra_mpls_init (void);
391 zebra_mpls_vty_init (void);
393 /* Inline functions. */
396 * Distance (priority) definition for LSP NHLFE.
399 lsp_distance (enum lsp_types_t type
)
401 if (type
== ZEBRA_LSP_STATIC
)
402 return (route_distance (ZEBRA_ROUTE_STATIC
));
408 * Map RIB type to LSP type. Used when labeled-routes from BGP
409 * are converted into LSPs.
411 static inline enum lsp_types_t
412 lsp_type_from_rib_type (int rib_type
)
416 case ZEBRA_ROUTE_STATIC
:
417 return ZEBRA_LSP_STATIC
;
419 return ZEBRA_LSP_NONE
;
423 /* NHLFE type as printable string. */
424 static inline const char *
425 nhlfe_type2str(enum lsp_types_t lsp_type
)
429 case ZEBRA_LSP_STATIC
:
439 mpls_mark_lsps_for_processing(struct zebra_vrf
*zvrf
)
444 zvrf
->mpls_flags
|= MPLS_FLAG_SCHEDULE_LSPS
;
448 mpls_unmark_lsps_for_processing(struct zebra_vrf
*zvrf
)
453 zvrf
->mpls_flags
&= ~MPLS_FLAG_SCHEDULE_LSPS
;
457 mpls_should_lsps_be_processed(struct zebra_vrf
*zvrf
)
462 return ((zvrf
->mpls_flags
& MPLS_FLAG_SCHEDULE_LSPS
) ? 1 : 0);
465 /* Global variables. */
466 extern int mpls_enabled
;
468 #endif /*_ZEBRA_MPLS_H */