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
;
57 * (Outgoing) nexthop label forwarding entry configuration
59 struct zebra_snhlfe_t_
61 /* Nexthop information */
62 enum nexthop_types_t gtype
;
68 mpls_label_t out_label
;
70 /* Backpointer to base entry. */
73 /* Pointers to more outgoing information for same in-label */
79 * (Outgoing) nexthop label forwarding entry
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
110 mpls_label_t in_label
;
114 * Label swap entry static configuration.
121 /* List of outgoing nexthop static configuration */
122 zebra_snhlfe_t
*snhlfe_list
;
127 * Label swap entry (ile -> list of nhlfes)
134 /* List of NHLFE, pointer to best and num equal-cost. */
135 zebra_nhlfe_t
*nhlfe_list
;
136 zebra_nhlfe_t
*best_nhlfe
;
141 #define LSP_FLAG_SCHEDULED (1 << 0)
142 #define LSP_FLAG_INSTALLED (1 << 1)
143 #define LSP_FLAG_CHANGED (1 << 2)
145 /* Address-family of NHLFE - saved here for delete. All NHLFEs */
146 /* have to be of the same AF */
151 /* Function declarations. */
154 * String to label conversion, labels separated by '/'.
157 mpls_str2label (const char *label_str
, u_int8_t
*num_labels
,
158 mpls_label_t
*labels
);
161 * Label to string conversion, labels in string separated by '/'.
164 mpls_label2str (u_int8_t num_labels
, mpls_label_t
*labels
,
168 * Install/uninstall a FEC-To-NHLFE (FTN) binding.
171 mpls_ftn_update (int add
, struct zebra_vrf
*zvrf
, enum lsp_types_t type
,
172 struct prefix
*prefix
, union g_addr
*gate
, u_int8_t distance
,
173 mpls_label_t out_label
);
176 * Install/update a NHLFE for an LSP in the forwarding table. This may be
177 * a new LSP entry or a new NHLFE for an existing in-label or an update of
178 * the out-label for an existing NHLFE (update case).
181 mpls_lsp_install (struct zebra_vrf
*zvrf
, enum lsp_types_t type
,
182 mpls_label_t in_label
, mpls_label_t out_label
,
183 enum nexthop_types_t gtype
, union g_addr
*gate
,
184 char *ifname
, ifindex_t ifindex
);
187 * Uninstall a particular NHLFE in the forwarding table. If this is
188 * the only NHLFE, the entire LSP forwarding entry has to be deleted.
191 mpls_lsp_uninstall (struct zebra_vrf
*zvrf
, enum lsp_types_t type
,
192 mpls_label_t in_label
, enum nexthop_types_t gtype
,
193 union g_addr
*gate
, char *ifname
, ifindex_t ifindex
);
196 * Uninstall all LDP NHLFEs for a particular LSP forwarding entry.
197 * If no other NHLFEs exist, the entry would be deleted.
200 mpls_ldp_lsp_uninstall_all (struct hash_backet
*backet
, void *ctxt
);
203 * Uninstall all LDP FEC-To-NHLFE (FTN) bindings of the given address-family.
206 mpls_ldp_ftn_uninstall_all (struct zebra_vrf
*zvrf
, int afi
);
208 #if defined(HAVE_CUMULUS)
210 * Check that the label values used in LSP creation are consistent. The
211 * main criteria is that if there is ECMP, the label operation must still
212 * be consistent - i.e., all paths either do a swap or do PHP. This is due
213 * to current HW restrictions.
216 zebra_mpls_lsp_label_consistent (struct zebra_vrf
*zvrf
, mpls_label_t in_label
,
217 mpls_label_t out_label
, enum nexthop_types_t gtype
,
218 union g_addr
*gate
, char *ifname
, ifindex_t ifindex
);
219 #endif /* HAVE_CUMULUS */
222 * Add static LSP entry. This may be the first entry for this incoming label
223 * or an additional nexthop; an existing entry may also have outgoing label
225 * Note: The label operation (swap or PHP) is common for the LSP entry (all
229 zebra_mpls_static_lsp_add (struct zebra_vrf
*zvrf
, mpls_label_t in_label
,
230 mpls_label_t out_label
, enum nexthop_types_t gtype
,
231 union g_addr
*gate
, char *ifname
, ifindex_t ifindex
);
234 * Delete static LSP entry. This may be the delete of one particular
235 * NHLFE for this incoming label or the delete of the entire entry (i.e.,
237 * NOTE: Delete of the only NHLFE will also end up deleting the entire
241 zebra_mpls_static_lsp_del (struct zebra_vrf
*zvrf
, mpls_label_t in_label
,
242 enum nexthop_types_t gtype
, union g_addr
*gate
,
243 char *ifname
, ifindex_t ifindex
);
246 * Schedule all MPLS label forwarding entries for processing.
247 * Called upon changes that may affect one or more of them such as
248 * interface or nexthop state changes.
251 zebra_mpls_lsp_schedule (struct zebra_vrf
*zvrf
);
254 * Display MPLS label forwarding table for a specific LSP
255 * (VTY command handler).
258 zebra_mpls_print_lsp (struct vty
*vty
, struct zebra_vrf
*zvrf
, mpls_label_t label
,
262 * Display MPLS label forwarding table (VTY command handler).
265 zebra_mpls_print_lsp_table (struct vty
*vty
, struct zebra_vrf
*zvrf
,
269 * Display MPLS LSP configuration of all static LSPs (VTY command handler).
272 zebra_mpls_write_lsp_config (struct vty
*vty
, struct zebra_vrf
*zvrf
);
275 * Called upon process exiting, need to delete LSP forwarding
276 * entries from the kernel.
277 * NOTE: Currently supported only for default VRF.
280 zebra_mpls_close_tables (struct zebra_vrf
*zvrf
);
283 * Allocate MPLS tables for this VRF.
284 * NOTE: Currently supported only for default VRF.
287 zebra_mpls_init_tables (struct zebra_vrf
*zvrf
);
290 * Global MPLS initialization.
293 zebra_mpls_init (void);
299 zebra_mpls_vty_init (void);
301 /* Inline functions. */
304 * Distance (priority) definition for LSP NHLFE.
307 lsp_distance (enum lsp_types_t type
)
309 if (type
== ZEBRA_LSP_STATIC
)
310 return (route_distance (ZEBRA_ROUTE_STATIC
));
316 * Map RIB type to LSP type. Used when labeled-routes from BGP
317 * are converted into LSPs.
319 static inline enum lsp_types_t
320 lsp_type_from_rib_type (int rib_type
)
324 case ZEBRA_ROUTE_STATIC
:
325 return ZEBRA_LSP_STATIC
;
327 return ZEBRA_LSP_NONE
;
331 /* NHLFE type as printable string. */
332 static inline const char *
333 nhlfe_type2str(enum lsp_types_t lsp_type
)
337 case ZEBRA_LSP_STATIC
:
347 mpls_mark_lsps_for_processing(struct zebra_vrf
*zvrf
)
352 zvrf
->mpls_flags
|= MPLS_FLAG_SCHEDULE_LSPS
;
356 mpls_unmark_lsps_for_processing(struct zebra_vrf
*zvrf
)
361 zvrf
->mpls_flags
&= ~MPLS_FLAG_SCHEDULE_LSPS
;
365 mpls_should_lsps_be_processed(struct zebra_vrf
*zvrf
)
370 return ((zvrf
->mpls_flags
& MPLS_FLAG_SCHEDULE_LSPS
) ? 1 : 0);
373 /* Global variables. */
374 extern int mpls_enabled
;
376 #endif /*_ZEBRA_MPLS_H */