]> git.proxmox.com Git - mirror_frr.git/blob - zebra/zebra_mpls.h
lib: drop off "masters" list on master_free()
[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 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
20 */
21
22 #ifndef _ZEBRA_MPLS_H
23 #define _ZEBRA_MPLS_H
24
25 #include "prefix.h"
26 #include "table.h"
27 #include "queue.h"
28 #include "hash.h"
29 #include "jhash.h"
30 #include "nexthop.h"
31 #include "vty.h"
32 #include "memory.h"
33 #include "mpls.h"
34 #include "zebra/zserv.h"
35 #include "zebra/zebra_vrf.h"
36
37
38 /* Definitions and macros. */
39
40 #define MPLS_MAX_LABELS 2 /* Maximum # labels that can be pushed. */
41
42 #define NHLFE_FAMILY(nhlfe) \
43 (((nhlfe)->nexthop->type == NEXTHOP_TYPE_IPV6 || \
44 (nhlfe)->nexthop->type == NEXTHOP_TYPE_IPV6_IFINDEX) ? AF_INET6 : AF_INET)
45
46 #define MPLS_LABEL_HELPSTR "Specify label(s) for this route\nOne or more " \
47 "labels in the range (16-1048575) separated by '/'\n"
48
49 /* Typedefs */
50
51 typedef struct zebra_ile_t_ zebra_ile_t;
52 typedef struct zebra_snhlfe_t_ zebra_snhlfe_t;
53 typedef struct zebra_slsp_t_ zebra_slsp_t;
54 typedef struct zebra_nhlfe_t_ zebra_nhlfe_t;
55 typedef struct zebra_lsp_t_ zebra_lsp_t;
56 typedef struct zebra_fec_t_ zebra_fec_t;
57
58 /*
59 * (Outgoing) nexthop label forwarding entry configuration
60 */
61 struct zebra_snhlfe_t_
62 {
63 /* Nexthop information */
64 enum nexthop_types_t gtype;
65 union g_addr gate;
66 char *ifname;
67 ifindex_t ifindex;
68
69 /* Out label. */
70 mpls_label_t out_label;
71
72 /* Backpointer to base entry. */
73 zebra_slsp_t *slsp;
74
75 /* Pointers to more outgoing information for same in-label */
76 zebra_snhlfe_t *next;
77 zebra_snhlfe_t *prev;
78 };
79
80 /*
81 * (Outgoing) nexthop label forwarding entry
82 */
83 struct zebra_nhlfe_t_
84 {
85 /* Type of entry - static etc. */
86 enum lsp_types_t type;
87
88 /* Nexthop information (with outgoing label) */
89 struct nexthop *nexthop;
90
91 /* Backpointer to base entry. */
92 zebra_lsp_t *lsp;
93
94 /* Runtime info - flags, pointers etc. */
95 u_int32_t flags;
96 #define NHLFE_FLAG_CHANGED (1 << 0)
97 #define NHLFE_FLAG_SELECTED (1 << 1)
98 #define NHLFE_FLAG_MULTIPATH (1 << 2)
99 #define NHLFE_FLAG_DELETED (1 << 3)
100 #define NHLFE_FLAG_INSTALLED (1 << 4)
101
102 zebra_nhlfe_t *next;
103 zebra_nhlfe_t *prev;
104 u_char distance;
105 };
106
107 /*
108 * Incoming label entry
109 */
110 struct zebra_ile_t_
111 {
112 mpls_label_t in_label;
113 };
114
115 /*
116 * Label swap entry static configuration.
117 */
118 struct zebra_slsp_t_
119 {
120 /* Incoming label */
121 zebra_ile_t ile;
122
123 /* List of outgoing nexthop static configuration */
124 zebra_snhlfe_t *snhlfe_list;
125
126 };
127
128 /*
129 * Label swap entry (ile -> list of nhlfes)
130 */
131 struct zebra_lsp_t_
132 {
133 /* Incoming label */
134 zebra_ile_t ile;
135
136 /* List of NHLFE, pointer to best and num equal-cost. */
137 zebra_nhlfe_t *nhlfe_list;
138 zebra_nhlfe_t *best_nhlfe;
139 u_int32_t num_ecmp;
140
141 /* Flags */
142 u_int32_t flags;
143 #define LSP_FLAG_SCHEDULED (1 << 0)
144 #define LSP_FLAG_INSTALLED (1 << 1)
145 #define LSP_FLAG_CHANGED (1 << 2)
146
147 /* Address-family of NHLFE - saved here for delete. All NHLFEs */
148 /* have to be of the same AF */
149 u_char addr_family;
150 };
151
152 /*
153 * FEC to label binding.
154 */
155 struct zebra_fec_t_
156 {
157 /* FEC (prefix) */
158 struct route_node *rn;
159
160 /* In-label - either statically bound or derived from label block. */
161 mpls_label_t label;
162
163 /* Label index (into global label block), if valid */
164 u_int32_t label_index;
165
166 /* Flags. */
167 u_int32_t flags;
168 #define FEC_FLAG_CONFIGURED (1 << 0)
169
170 /* Clients interested in this FEC. */
171 struct list *client_list;
172 };
173
174 /* Function declarations. */
175
176 /*
177 * String to label conversion, labels separated by '/'.
178 */
179 int
180 mpls_str2label (const char *label_str, u_int8_t *num_labels,
181 mpls_label_t *labels);
182
183 /*
184 * Label to string conversion, labels in string separated by '/'.
185 */
186 char *
187 mpls_label2str (u_int8_t num_labels, mpls_label_t *labels,
188 char *buf, int len, int pretty);
189
190 /*
191 * Add/update global label block.
192 */
193 int
194 zebra_mpls_label_block_add (struct zebra_vrf *zvrf, u_int32_t start_label,
195 u_int32_t end_label);
196
197 /*
198 * Delete global label block.
199 */
200 int
201 zebra_mpls_label_block_del (struct zebra_vrf *vrf);
202
203 /*
204 * Display MPLS global label block configuration (VTY command handler).
205 */
206 int
207 zebra_mpls_write_label_block_config (struct vty *vty, struct zebra_vrf *vrf);
208
209 /*
210 * Install dynamic LSP entry.
211 */
212 int
213 zebra_mpls_lsp_install (struct zebra_vrf *zvrf, struct route_node *rn, struct route_entry *re);
214
215 /*
216 * Uninstall dynamic LSP entry, if any.
217 */
218 int
219 zebra_mpls_lsp_uninstall (struct zebra_vrf *zvrf, struct route_node *rn, struct route_entry *re);
220
221 /*
222 * Registration from a client for the label binding for a FEC. If a binding
223 * already exists, it is informed to the client.
224 * NOTE: If there is a manually configured label binding, that is used.
225 * Otherwise, if aa label index is specified, it means we have to allocate the
226 * label from a locally configured label block (SRGB), if one exists and index
227 * is acceptable.
228 */
229 int
230 zebra_mpls_fec_register (struct zebra_vrf *zvrf, struct prefix *p,
231 u_int32_t label_index, struct zserv *client);
232
233 /*
234 * Deregistration from a client for the label binding for a FEC. The FEC
235 * itself is deleted if no other registered clients exist and there is no
236 * label bound to the FEC.
237 */
238 int
239 zebra_mpls_fec_unregister (struct zebra_vrf *zvrf, struct prefix *p,
240 struct zserv *client);
241
242 /*
243 * Cleanup any FECs registered by this client.
244 */
245 int
246 zebra_mpls_cleanup_fecs_for_client (struct zebra_vrf *zvrf, struct zserv *client);
247
248 /*
249 * Return FEC (if any) to which this label is bound.
250 * Note: Only works for per-prefix binding and when the label is not
251 * implicit-null.
252 * TODO: Currently walks entire table, can optimize later with another
253 * hash..
254 */
255 zebra_fec_t *
256 zebra_mpls_fec_for_label (struct zebra_vrf *zvrf, mpls_label_t label);
257
258 /*
259 * Inform if specified label is currently bound to a FEC or not.
260 */
261 int
262 zebra_mpls_label_already_bound (struct zebra_vrf *zvrf, mpls_label_t label);
263
264 /*
265 * Add static FEC to label binding. If there are clients registered for this
266 * FEC, notify them. If there are labeled routes for this FEC, install the
267 * label forwarding entry.
268 */
269 int
270 zebra_mpls_static_fec_add (struct zebra_vrf *zvrf, struct prefix *p,
271 mpls_label_t in_label);
272
273 /*
274 * Remove static FEC to label binding. If there are no clients registered
275 * for this FEC, delete the FEC; else notify clients.
276 * Note: Upon delete of static binding, if label index exists for this FEC,
277 * client may need to be updated with derived label.
278 */
279 int
280 zebra_mpls_static_fec_del (struct zebra_vrf *zvrf, struct prefix *p);
281
282 /*
283 * Display MPLS FEC to label binding configuration (VTY command handler).
284 */
285 int
286 zebra_mpls_write_fec_config (struct vty *vty, struct zebra_vrf *zvrf);
287
288 /*
289 * Display MPLS FEC to label binding (VTY command handler).
290 */
291 void
292 zebra_mpls_print_fec_table (struct vty *vty, struct zebra_vrf *zvrf);
293
294 /*
295 * Display MPLS FEC to label binding for a specific FEC (VTY command handler).
296 */
297 void
298 zebra_mpls_print_fec (struct vty *vty, struct zebra_vrf *zvrf, struct prefix *p);
299
300 /*
301 * Install/uninstall a FEC-To-NHLFE (FTN) binding.
302 */
303 int
304 mpls_ftn_update (int add, struct zebra_vrf *zvrf, enum lsp_types_t type,
305 struct prefix *prefix, enum nexthop_types_t gtype,
306 union g_addr *gate, ifindex_t ifindex, u_int8_t distance,
307 mpls_label_t out_label);
308
309 /*
310 * Install/update a NHLFE for an LSP in the forwarding table. This may be
311 * a new LSP entry or a new NHLFE for an existing in-label or an update of
312 * the out-label for an existing NHLFE (update case).
313 */
314 int
315 mpls_lsp_install (struct zebra_vrf *zvrf, enum lsp_types_t type,
316 mpls_label_t in_label, mpls_label_t out_label,
317 enum nexthop_types_t gtype, union g_addr *gate,
318 ifindex_t ifindex);
319
320 /*
321 * Uninstall a particular NHLFE in the forwarding table. If this is
322 * the only NHLFE, the entire LSP forwarding entry has to be deleted.
323 */
324 int
325 mpls_lsp_uninstall (struct zebra_vrf *zvrf, enum lsp_types_t type,
326 mpls_label_t in_label, enum nexthop_types_t gtype,
327 union g_addr *gate, ifindex_t ifindex);
328
329 /*
330 * Uninstall all LDP NHLFEs for a particular LSP forwarding entry.
331 * If no other NHLFEs exist, the entry would be deleted.
332 */
333 void
334 mpls_ldp_lsp_uninstall_all (struct hash_backet *backet, void *ctxt);
335
336 /*
337 * Uninstall all LDP FEC-To-NHLFE (FTN) bindings of the given address-family.
338 */
339 void
340 mpls_ldp_ftn_uninstall_all (struct zebra_vrf *zvrf, int afi);
341
342 #if defined(HAVE_CUMULUS)
343 /*
344 * Check that the label values used in LSP creation are consistent. The
345 * main criteria is that if there is ECMP, the label operation must still
346 * be consistent - i.e., all paths either do a swap or do PHP. This is due
347 * to current HW restrictions.
348 */
349 int
350 zebra_mpls_lsp_label_consistent (struct zebra_vrf *zvrf, mpls_label_t in_label,
351 mpls_label_t out_label, enum nexthop_types_t gtype,
352 union g_addr *gate, ifindex_t ifindex);
353 #endif /* HAVE_CUMULUS */
354
355 /*
356 * Add static LSP entry. This may be the first entry for this incoming label
357 * or an additional nexthop; an existing entry may also have outgoing label
358 * changed.
359 * Note: The label operation (swap or PHP) is common for the LSP entry (all
360 * NHLFEs).
361 */
362 int
363 zebra_mpls_static_lsp_add (struct zebra_vrf *zvrf, mpls_label_t in_label,
364 mpls_label_t out_label, enum nexthop_types_t gtype,
365 union g_addr *gate, ifindex_t ifindex);
366
367 /*
368 * Delete static LSP entry. This may be the delete of one particular
369 * NHLFE for this incoming label or the delete of the entire entry (i.e.,
370 * all NHLFEs).
371 * NOTE: Delete of the only NHLFE will also end up deleting the entire
372 * LSP configuration.
373 */
374 int
375 zebra_mpls_static_lsp_del (struct zebra_vrf *zvrf, mpls_label_t in_label,
376 enum nexthop_types_t gtype, union g_addr *gate,
377 ifindex_t ifindex);
378
379 /*
380 * Schedule all MPLS label forwarding entries for processing.
381 * Called upon changes that may affect one or more of them such as
382 * interface or nexthop state changes.
383 */
384 void
385 zebra_mpls_lsp_schedule (struct zebra_vrf *zvrf);
386
387 /*
388 * Display MPLS label forwarding table for a specific LSP
389 * (VTY command handler).
390 */
391 void
392 zebra_mpls_print_lsp (struct vty *vty, struct zebra_vrf *zvrf, mpls_label_t label,
393 u_char use_json);
394
395 /*
396 * Display MPLS label forwarding table (VTY command handler).
397 */
398 void
399 zebra_mpls_print_lsp_table (struct vty *vty, struct zebra_vrf *zvrf,
400 u_char use_json);
401
402 /*
403 * Display MPLS LSP configuration of all static LSPs (VTY command handler).
404 */
405 int
406 zebra_mpls_write_lsp_config (struct vty *vty, struct zebra_vrf *zvrf);
407
408 /*
409 * Called upon process exiting, need to delete LSP forwarding
410 * entries from the kernel.
411 * NOTE: Currently supported only for default VRF.
412 */
413 void
414 zebra_mpls_close_tables (struct zebra_vrf *zvrf);
415
416 /*
417 * Allocate MPLS tables for this VRF.
418 * NOTE: Currently supported only for default VRF.
419 */
420 void
421 zebra_mpls_init_tables (struct zebra_vrf *zvrf);
422
423 /*
424 * Global MPLS initialization.
425 */
426 void
427 zebra_mpls_init (void);
428
429 /*
430 * MPLS VTY.
431 */
432 void
433 zebra_mpls_vty_init (void);
434
435 /* Inline functions. */
436
437 /*
438 * Distance (priority) definition for LSP NHLFE.
439 */
440 static inline u_char
441 lsp_distance (enum lsp_types_t type)
442 {
443 if (type == ZEBRA_LSP_STATIC)
444 return (route_distance (ZEBRA_ROUTE_STATIC));
445
446 return 150;
447 }
448
449 /*
450 * Map RIB type to LSP type. Used when labeled-routes from BGP
451 * are converted into LSPs.
452 */
453 static inline enum lsp_types_t
454 lsp_type_from_re_type (int re_type)
455 {
456 switch (re_type)
457 {
458 case ZEBRA_ROUTE_STATIC:
459 return ZEBRA_LSP_STATIC;
460 case ZEBRA_ROUTE_BGP:
461 return ZEBRA_LSP_BGP;
462 default:
463 return ZEBRA_LSP_NONE;
464 }
465 }
466
467 /* NHLFE type as printable string. */
468 static inline const char *
469 nhlfe_type2str(enum lsp_types_t lsp_type)
470 {
471 switch (lsp_type)
472 {
473 case ZEBRA_LSP_STATIC:
474 return "Static";
475 case ZEBRA_LSP_LDP:
476 return "LDP";
477 case ZEBRA_LSP_BGP:
478 return "BGP";
479 default:
480 return "Unknown";
481 }
482 }
483
484 static inline void
485 mpls_mark_lsps_for_processing(struct zebra_vrf *zvrf)
486 {
487 if (!zvrf)
488 return;
489
490 zvrf->mpls_flags |= MPLS_FLAG_SCHEDULE_LSPS;
491 }
492
493 static inline void
494 mpls_unmark_lsps_for_processing(struct zebra_vrf *zvrf)
495 {
496 if (!zvrf)
497 return;
498
499 zvrf->mpls_flags &= ~MPLS_FLAG_SCHEDULE_LSPS;
500 }
501
502 static inline int
503 mpls_should_lsps_be_processed(struct zebra_vrf *zvrf)
504 {
505 if (!zvrf)
506 return 0;
507
508 return ((zvrf->mpls_flags & MPLS_FLAG_SCHEDULE_LSPS) ? 1 : 0);
509 }
510
511 /* Global variables. */
512 extern int mpls_enabled;
513
514 #endif /*_ZEBRA_MPLS_H */