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
, enum nexthop_types_t gtype
,
173 union g_addr
*gate
, ifindex_t ifindex
, u_int8_t distance
,
174 mpls_label_t out_label
);
177 * Install/update a NHLFE for an LSP in the forwarding table. This may be
178 * a new LSP entry or a new NHLFE for an existing in-label or an update of
179 * the out-label for an existing NHLFE (update case).
182 mpls_lsp_install (struct zebra_vrf
*zvrf
, enum lsp_types_t type
,
183 mpls_label_t in_label
, mpls_label_t out_label
,
184 enum nexthop_types_t gtype
, union g_addr
*gate
,
185 char *ifname
, ifindex_t ifindex
);
188 * Uninstall a particular NHLFE in the forwarding table. If this is
189 * the only NHLFE, the entire LSP forwarding entry has to be deleted.
192 mpls_lsp_uninstall (struct zebra_vrf
*zvrf
, enum lsp_types_t type
,
193 mpls_label_t in_label
, enum nexthop_types_t gtype
,
194 union g_addr
*gate
, char *ifname
, ifindex_t ifindex
);
197 * Uninstall all LDP NHLFEs for a particular LSP forwarding entry.
198 * If no other NHLFEs exist, the entry would be deleted.
201 mpls_ldp_lsp_uninstall_all (struct hash_backet
*backet
, void *ctxt
);
204 * Uninstall all LDP FEC-To-NHLFE (FTN) bindings of the given address-family.
207 mpls_ldp_ftn_uninstall_all (struct zebra_vrf
*zvrf
, int afi
);
209 #if defined(HAVE_CUMULUS)
211 * Check that the label values used in LSP creation are consistent. The
212 * main criteria is that if there is ECMP, the label operation must still
213 * be consistent - i.e., all paths either do a swap or do PHP. This is due
214 * to current HW restrictions.
217 zebra_mpls_lsp_label_consistent (struct zebra_vrf
*zvrf
, mpls_label_t in_label
,
218 mpls_label_t out_label
, enum nexthop_types_t gtype
,
219 union g_addr
*gate
, char *ifname
, ifindex_t ifindex
);
220 #endif /* HAVE_CUMULUS */
223 * Add static LSP entry. This may be the first entry for this incoming label
224 * or an additional nexthop; an existing entry may also have outgoing label
226 * Note: The label operation (swap or PHP) is common for the LSP entry (all
230 zebra_mpls_static_lsp_add (struct zebra_vrf
*zvrf
, mpls_label_t in_label
,
231 mpls_label_t out_label
, enum nexthop_types_t gtype
,
232 union g_addr
*gate
, char *ifname
, ifindex_t ifindex
);
235 * Delete static LSP entry. This may be the delete of one particular
236 * NHLFE for this incoming label or the delete of the entire entry (i.e.,
238 * NOTE: Delete of the only NHLFE will also end up deleting the entire
242 zebra_mpls_static_lsp_del (struct zebra_vrf
*zvrf
, mpls_label_t in_label
,
243 enum nexthop_types_t gtype
, union g_addr
*gate
,
244 char *ifname
, ifindex_t ifindex
);
247 * Schedule all MPLS label forwarding entries for processing.
248 * Called upon changes that may affect one or more of them such as
249 * interface or nexthop state changes.
252 zebra_mpls_lsp_schedule (struct zebra_vrf
*zvrf
);
255 * Display MPLS label forwarding table for a specific LSP
256 * (VTY command handler).
259 zebra_mpls_print_lsp (struct vty
*vty
, struct zebra_vrf
*zvrf
, mpls_label_t label
,
263 * Display MPLS label forwarding table (VTY command handler).
266 zebra_mpls_print_lsp_table (struct vty
*vty
, struct zebra_vrf
*zvrf
,
270 * Display MPLS LSP configuration of all static LSPs (VTY command handler).
273 zebra_mpls_write_lsp_config (struct vty
*vty
, struct zebra_vrf
*zvrf
);
276 * Called upon process exiting, need to delete LSP forwarding
277 * entries from the kernel.
278 * NOTE: Currently supported only for default VRF.
281 zebra_mpls_close_tables (struct zebra_vrf
*zvrf
);
284 * Allocate MPLS tables for this VRF.
285 * NOTE: Currently supported only for default VRF.
288 zebra_mpls_init_tables (struct zebra_vrf
*zvrf
);
291 * Global MPLS initialization.
294 zebra_mpls_init (void);
300 zebra_mpls_vty_init (void);
302 /* Inline functions. */
305 * Distance (priority) definition for LSP NHLFE.
308 lsp_distance (enum lsp_types_t type
)
310 if (type
== ZEBRA_LSP_STATIC
)
311 return (route_distance (ZEBRA_ROUTE_STATIC
));
317 * Map RIB type to LSP type. Used when labeled-routes from BGP
318 * are converted into LSPs.
320 static inline enum lsp_types_t
321 lsp_type_from_rib_type (int rib_type
)
325 case ZEBRA_ROUTE_STATIC
:
326 return ZEBRA_LSP_STATIC
;
328 return ZEBRA_LSP_NONE
;
332 /* NHLFE type as printable string. */
333 static inline const char *
334 nhlfe_type2str(enum lsp_types_t lsp_type
)
338 case ZEBRA_LSP_STATIC
:
348 mpls_mark_lsps_for_processing(struct zebra_vrf
*zvrf
)
353 zvrf
->mpls_flags
|= MPLS_FLAG_SCHEDULE_LSPS
;
357 mpls_unmark_lsps_for_processing(struct zebra_vrf
*zvrf
)
362 zvrf
->mpls_flags
&= ~MPLS_FLAG_SCHEDULE_LSPS
;
366 mpls_should_lsps_be_processed(struct zebra_vrf
*zvrf
)
371 return ((zvrf
->mpls_flags
& MPLS_FLAG_SCHEDULE_LSPS
) ? 1 : 0);
374 /* Global variables. */
375 extern int mpls_enabled
;
377 #endif /*_ZEBRA_MPLS_H */