]> git.proxmox.com Git - mirror_frr.git/blob - zebra/zebra_mpls.h
Merge remote-tracking branch 'origin/cmaster' into cmaster-next
[mirror_frr.git] / zebra / zebra_mpls.h
1 /*
2 * Zebra MPLS Data structures and definitions
3 * Copyright (C) 2015 Cumulus Networks, Inc.
4 *
5 * This file is part of GNU Zebra.
6 *
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
10 * later version.
11 *
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.
16 *
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
20 * 02111-1307, USA.
21 */
22
23 #ifndef _ZEBRA_MPLS_H
24 #define _ZEBRA_MPLS_H
25
26 #include "prefix.h"
27 #include "table.h"
28 #include "queue.h"
29 #include "hash.h"
30 #include "jhash.h"
31 #include "nexthop.h"
32 #include "vty.h"
33 #include "memory.h"
34 #include "mpls.h"
35 #include "zebra/zserv.h"
36 #include "zebra/zebra_vrf.h"
37
38
39 /* Definitions and macros. */
40
41 #define MPLS_MAX_LABELS 2 /* Maximum # labels that can be pushed. */
42
43 #define NHLFE_FAMILY(nhlfe) \
44 (((nhlfe)->nexthop->type == NEXTHOP_TYPE_IPV6 || \
45 (nhlfe)->nexthop->type == NEXTHOP_TYPE_IPV6_IFINDEX) ? AF_INET6 : AF_INET)
46
47
48 /* Typedefs */
49
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
56 /*
57 * (Outgoing) nexthop label forwarding entry configuration
58 */
59 struct zebra_snhlfe_t_
60 {
61 /* Nexthop information */
62 enum nexthop_types_t gtype;
63 union g_addr gate;
64 char *ifname;
65 ifindex_t ifindex;
66
67 /* Out label. */
68 mpls_label_t out_label;
69
70 /* Backpointer to base entry. */
71 zebra_slsp_t *slsp;
72
73 /* Pointers to more outgoing information for same in-label */
74 zebra_snhlfe_t *next;
75 zebra_snhlfe_t *prev;
76 };
77
78 /*
79 * (Outgoing) nexthop label forwarding entry
80 */
81 struct zebra_nhlfe_t_
82 {
83 /* Type of entry - static etc. */
84 enum lsp_types_t type;
85
86 /* Nexthop information (with outgoing label) */
87 struct nexthop *nexthop;
88
89 /* Backpointer to base entry. */
90 zebra_lsp_t *lsp;
91
92 /* Runtime info - flags, pointers etc. */
93 u_int32_t flags;
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)
99
100 zebra_nhlfe_t *next;
101 zebra_nhlfe_t *prev;
102 u_char distance;
103 };
104
105 /*
106 * Incoming label entry
107 */
108 struct zebra_ile_t_
109 {
110 mpls_label_t in_label;
111 };
112
113 /*
114 * Label swap entry static configuration.
115 */
116 struct zebra_slsp_t_
117 {
118 /* Incoming label */
119 zebra_ile_t ile;
120
121 /* List of outgoing nexthop static configuration */
122 zebra_snhlfe_t *snhlfe_list;
123
124 };
125
126 /*
127 * Label swap entry (ile -> list of nhlfes)
128 */
129 struct zebra_lsp_t_
130 {
131 /* Incoming label */
132 zebra_ile_t ile;
133
134 /* List of NHLFE, pointer to best and num equal-cost. */
135 zebra_nhlfe_t *nhlfe_list;
136 zebra_nhlfe_t *best_nhlfe;
137 u_int32_t num_ecmp;
138
139 /* Flags */
140 u_int32_t flags;
141 #define LSP_FLAG_SCHEDULED (1 << 0)
142 #define LSP_FLAG_INSTALLED (1 << 1)
143 #define LSP_FLAG_CHANGED (1 << 2)
144
145 /* Address-family of NHLFE - saved here for delete. All NHLFEs */
146 /* have to be of the same AF */
147 u_char addr_family;
148 };
149
150
151 /* Function declarations. */
152
153 /*
154 * String to label conversion, labels separated by '/'.
155 */
156 int
157 mpls_str2label (const char *label_str, u_int8_t *num_labels,
158 mpls_label_t *labels);
159
160 /*
161 * Label to string conversion, labels in string separated by '/'.
162 */
163 char *
164 mpls_label2str (u_int8_t num_labels, mpls_label_t *labels,
165 char *buf, int len);
166
167 /*
168 * Install/uninstall a FEC-To-NHLFE (FTN) binding.
169 */
170 int
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);
174
175 /*
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).
179 */
180 int
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);
185
186 /*
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.
189 */
190 int
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);
194
195 /*
196 * Uninstall all LDP NHLFEs for a particular LSP forwarding entry.
197 * If no other NHLFEs exist, the entry would be deleted.
198 */
199 void
200 mpls_ldp_lsp_uninstall_all (struct hash_backet *backet, void *ctxt);
201
202 /*
203 * Uninstall all LDP FEC-To-NHLFE (FTN) bindings of the given address-family.
204 */
205 void
206 mpls_ldp_ftn_uninstall_all (struct zebra_vrf *zvrf, int afi);
207
208 #if defined(HAVE_CUMULUS)
209 /*
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.
214 */
215 int
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 */
220
221 /*
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
224 * changed.
225 * Note: The label operation (swap or PHP) is common for the LSP entry (all
226 * NHLFEs).
227 */
228 int
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);
232
233 /*
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.,
236 * all NHLFEs).
237 * NOTE: Delete of the only NHLFE will also end up deleting the entire
238 * LSP configuration.
239 */
240 int
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);
244
245 /*
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.
249 */
250 void
251 zebra_mpls_lsp_schedule (struct zebra_vrf *zvrf);
252
253 /*
254 * Display MPLS label forwarding table for a specific LSP
255 * (VTY command handler).
256 */
257 void
258 zebra_mpls_print_lsp (struct vty *vty, struct zebra_vrf *zvrf, mpls_label_t label,
259 u_char use_json);
260
261 /*
262 * Display MPLS label forwarding table (VTY command handler).
263 */
264 void
265 zebra_mpls_print_lsp_table (struct vty *vty, struct zebra_vrf *zvrf,
266 u_char use_json);
267
268 /*
269 * Display MPLS LSP configuration of all static LSPs (VTY command handler).
270 */
271 int
272 zebra_mpls_write_lsp_config (struct vty *vty, struct zebra_vrf *zvrf);
273
274 /*
275 * Called upon process exiting, need to delete LSP forwarding
276 * entries from the kernel.
277 * NOTE: Currently supported only for default VRF.
278 */
279 void
280 zebra_mpls_close_tables (struct zebra_vrf *zvrf);
281
282 /*
283 * Allocate MPLS tables for this VRF.
284 * NOTE: Currently supported only for default VRF.
285 */
286 void
287 zebra_mpls_init_tables (struct zebra_vrf *zvrf);
288
289 /*
290 * Global MPLS initialization.
291 */
292 void
293 zebra_mpls_init (void);
294
295 /*
296 * MPLS VTY.
297 */
298 void
299 zebra_mpls_vty_init (void);
300
301 /* Inline functions. */
302
303 /*
304 * Distance (priority) definition for LSP NHLFE.
305 */
306 static inline u_char
307 lsp_distance (enum lsp_types_t type)
308 {
309 if (type == ZEBRA_LSP_STATIC)
310 return (route_distance (ZEBRA_ROUTE_STATIC));
311
312 return 150;
313 }
314
315 /*
316 * Map RIB type to LSP type. Used when labeled-routes from BGP
317 * are converted into LSPs.
318 */
319 static inline enum lsp_types_t
320 lsp_type_from_rib_type (int rib_type)
321 {
322 switch (rib_type)
323 {
324 case ZEBRA_ROUTE_STATIC:
325 return ZEBRA_LSP_STATIC;
326 default:
327 return ZEBRA_LSP_NONE;
328 }
329 }
330
331 /* NHLFE type as printable string. */
332 static inline const char *
333 nhlfe_type2str(enum lsp_types_t lsp_type)
334 {
335 switch (lsp_type)
336 {
337 case ZEBRA_LSP_STATIC:
338 return "Static";
339 case ZEBRA_LSP_LDP:
340 return "LDP";
341 default:
342 return "Unknown";
343 }
344 }
345
346 static inline void
347 mpls_mark_lsps_for_processing(struct zebra_vrf *zvrf)
348 {
349 if (!zvrf)
350 return;
351
352 zvrf->mpls_flags |= MPLS_FLAG_SCHEDULE_LSPS;
353 }
354
355 static inline void
356 mpls_unmark_lsps_for_processing(struct zebra_vrf *zvrf)
357 {
358 if (!zvrf)
359 return;
360
361 zvrf->mpls_flags &= ~MPLS_FLAG_SCHEDULE_LSPS;
362 }
363
364 static inline int
365 mpls_should_lsps_be_processed(struct zebra_vrf *zvrf)
366 {
367 if (!zvrf)
368 return 0;
369
370 return ((zvrf->mpls_flags & MPLS_FLAG_SCHEDULE_LSPS) ? 1 : 0);
371 }
372
373 /* Global variables. */
374 extern int mpls_enabled;
375
376 #endif /*_ZEBRA_MPLS_H */