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