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