]> git.proxmox.com Git - mirror_frr.git/blame - zebra/zebra_mpls.h
zebra: print unknown rule family as number
[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
51e94aa7
EDP
37#ifdef __cplusplus
38extern "C" {
39#endif
54d48ea1 40
41/* Definitions and macros. */
42
d62a17ae 43#define NHLFE_FAMILY(nhlfe) \
44 (((nhlfe)->nexthop->type == NEXTHOP_TYPE_IPV6 \
45 || (nhlfe)->nexthop->type == NEXTHOP_TYPE_IPV6_IFINDEX) \
46 ? AF_INET6 \
47 : AF_INET)
54d48ea1 48
54d48ea1 49/* Typedefs */
50
51typedef struct zebra_ile_t_ zebra_ile_t;
52typedef struct zebra_snhlfe_t_ zebra_snhlfe_t;
53typedef struct zebra_slsp_t_ zebra_slsp_t;
54typedef struct zebra_nhlfe_t_ zebra_nhlfe_t;
55typedef struct zebra_lsp_t_ zebra_lsp_t;
f31e084c 56typedef struct zebra_fec_t_ zebra_fec_t;
54d48ea1 57
54d48ea1 58/*
59 * (Outgoing) nexthop label forwarding entry configuration
60 */
d62a17ae 61struct zebra_snhlfe_t_ {
62 /* Nexthop information */
63 enum nexthop_types_t gtype;
64 union g_addr gate;
65 char *ifname;
66 ifindex_t ifindex;
54d48ea1 67
d62a17ae 68 /* Out label. */
69 mpls_label_t out_label;
54d48ea1 70
d62a17ae 71 /* Backpointer to base entry. */
72 zebra_slsp_t *slsp;
54d48ea1 73
d62a17ae 74 /* Pointers to more outgoing information for same in-label */
75 zebra_snhlfe_t *next;
76 zebra_snhlfe_t *prev;
54d48ea1 77};
78
79/*
80 * (Outgoing) nexthop label forwarding entry
81 */
d62a17ae 82struct zebra_nhlfe_t_ {
83 /* Type of entry - static etc. */
84 enum lsp_types_t type;
54d48ea1 85
d62a17ae 86 /* Nexthop information (with outgoing label) */
87 struct nexthop *nexthop;
54d48ea1 88
d62a17ae 89 /* Backpointer to base entry. */
90 zebra_lsp_t *lsp;
54d48ea1 91
d62a17ae 92 /* Runtime info - flags, pointers etc. */
d7c0a89a 93 uint32_t flags;
54d48ea1 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
d62a17ae 100 zebra_nhlfe_t *next;
101 zebra_nhlfe_t *prev;
d7c0a89a 102 uint8_t distance;
54d48ea1 103};
104
105/*
106 * Incoming label entry
107 */
d62a17ae 108struct zebra_ile_t_ {
109 mpls_label_t in_label;
54d48ea1 110};
111
112/*
113 * Label swap entry static configuration.
114 */
d62a17ae 115struct zebra_slsp_t_ {
116 /* Incoming label */
117 zebra_ile_t ile;
54d48ea1 118
d62a17ae 119 /* List of outgoing nexthop static configuration */
120 zebra_snhlfe_t *snhlfe_list;
54d48ea1 121};
122
123/*
124 * Label swap entry (ile -> list of nhlfes)
125 */
d62a17ae 126struct zebra_lsp_t_ {
127 /* Incoming label */
128 zebra_ile_t ile;
54d48ea1 129
d62a17ae 130 /* List of NHLFE, pointer to best and num equal-cost. */
131 zebra_nhlfe_t *nhlfe_list;
132 zebra_nhlfe_t *best_nhlfe;
d7c0a89a 133 uint32_t num_ecmp;
54d48ea1 134
d62a17ae 135 /* Flags */
d7c0a89a 136 uint32_t flags;
54d48ea1 137#define LSP_FLAG_SCHEDULED (1 << 0)
138#define LSP_FLAG_INSTALLED (1 << 1)
139#define LSP_FLAG_CHANGED (1 << 2)
140
d62a17ae 141 /* Address-family of NHLFE - saved here for delete. All NHLFEs */
142 /* have to be of the same AF */
d7c0a89a 143 uint8_t addr_family;
54d48ea1 144};
145
f31e084c
DS
146/*
147 * FEC to label binding.
148 */
d62a17ae 149struct zebra_fec_t_ {
150 /* FEC (prefix) */
151 struct route_node *rn;
f31e084c 152
d62a17ae 153 /* In-label - either statically bound or derived from label block. */
154 mpls_label_t label;
f31e084c 155
d62a17ae 156 /* Label index (into global label block), if valid */
d7c0a89a 157 uint32_t label_index;
28d58fd7 158
d62a17ae 159 /* Flags. */
d7c0a89a 160 uint32_t flags;
f31e084c 161#define FEC_FLAG_CONFIGURED (1 << 0)
5aba114a 162
d62a17ae 163 /* Clients interested in this FEC. */
164 struct list *client_list;
f31e084c 165};
54d48ea1 166
7758e3f3 167/* Function declarations. */
168
1b6d5c7e
VV
169/*
170 * Add/update global label block.
171 */
d7c0a89a
QY
172int zebra_mpls_label_block_add(struct zebra_vrf *zvrf, uint32_t start_label,
173 uint32_t end_label);
1b6d5c7e
VV
174
175/*
176 * Delete global label block.
177 */
d62a17ae 178int zebra_mpls_label_block_del(struct zebra_vrf *vrf);
1b6d5c7e
VV
179
180/*
181 * Display MPLS global label block configuration (VTY command handler).
182 */
d62a17ae 183int zebra_mpls_write_label_block_config(struct vty *vty, struct zebra_vrf *vrf);
1b6d5c7e 184
a64448ba
DS
185/*
186 * Install dynamic LSP entry.
187 */
d62a17ae 188int zebra_mpls_lsp_install(struct zebra_vrf *zvrf, struct route_node *rn,
189 struct route_entry *re);
a64448ba
DS
190
191/*
d62a17ae 192 * Uninstall dynamic LSP entry, if any.
a64448ba 193 */
d62a17ae 194int zebra_mpls_lsp_uninstall(struct zebra_vrf *zvrf, struct route_node *rn,
195 struct route_entry *re);
a64448ba 196
d4cb23d7
MS
197/* Add an NHLFE to an LSP, return the newly-added object */
198zebra_nhlfe_t *zebra_mpls_lsp_add_nhlfe(zebra_lsp_t *lsp,
199 enum lsp_types_t lsp_type,
200 enum nexthop_types_t gtype,
201 union g_addr *gate,
202 ifindex_t ifindex,
5065db0a
RW
203 uint8_t num_labels,
204 mpls_label_t out_labels[]);
d4cb23d7
MS
205
206/* Free an allocated NHLFE */
207void zebra_mpls_nhlfe_del(zebra_nhlfe_t *nhlfe);
208
d62a17ae 209int zebra_mpls_fec_register(struct zebra_vrf *zvrf, struct prefix *p,
57592a53
AD
210 uint32_t label, uint32_t label_index,
211 struct zserv *client);
5aba114a
DS
212
213/*
214 * Deregistration from a client for the label binding for a FEC. The FEC
215 * itself is deleted if no other registered clients exist and there is no
216 * label bound to the FEC.
217 */
d62a17ae 218int zebra_mpls_fec_unregister(struct zebra_vrf *zvrf, struct prefix *p,
219 struct zserv *client);
5aba114a 220
f31e084c
DS
221/*
222 * Return FEC (if any) to which this label is bound.
223 * Note: Only works for per-prefix binding and when the label is not
224 * implicit-null.
225 * TODO: Currently walks entire table, can optimize later with another
226 * hash..
227 */
d62a17ae 228zebra_fec_t *zebra_mpls_fec_for_label(struct zebra_vrf *zvrf,
229 mpls_label_t label);
f31e084c
DS
230
231/*
232 * Inform if specified label is currently bound to a FEC or not.
233 */
d62a17ae 234int zebra_mpls_label_already_bound(struct zebra_vrf *zvrf, mpls_label_t label);
f31e084c
DS
235
236/*
5aba114a 237 * Add static FEC to label binding. If there are clients registered for this
a64448ba
DS
238 * FEC, notify them. If there are labeled routes for this FEC, install the
239 * label forwarding entry.
f31e084c 240 */
d62a17ae 241int zebra_mpls_static_fec_add(struct zebra_vrf *zvrf, struct prefix *p,
242 mpls_label_t in_label);
f31e084c
DS
243
244/*
5aba114a
DS
245 * Remove static FEC to label binding. If there are no clients registered
246 * for this FEC, delete the FEC; else notify clients.
28d58fd7
VV
247 * Note: Upon delete of static binding, if label index exists for this FEC,
248 * client may need to be updated with derived label.
f31e084c 249 */
d62a17ae 250int zebra_mpls_static_fec_del(struct zebra_vrf *zvrf, struct prefix *p);
f31e084c
DS
251
252/*
253 * Display MPLS FEC to label binding configuration (VTY command handler).
254 */
d62a17ae 255int zebra_mpls_write_fec_config(struct vty *vty, struct zebra_vrf *zvrf);
f31e084c
DS
256
257/*
258 * Display MPLS FEC to label binding (VTY command handler).
259 */
d62a17ae 260void zebra_mpls_print_fec_table(struct vty *vty, struct zebra_vrf *zvrf);
f31e084c
DS
261
262/*
263 * Display MPLS FEC to label binding for a specific FEC (VTY command handler).
264 */
d62a17ae 265void zebra_mpls_print_fec(struct vty *vty, struct zebra_vrf *zvrf,
266 struct prefix *p);
f31e084c 267
ce549947
RW
268/*
269 * Install/uninstall a FEC-To-NHLFE (FTN) binding.
270 */
d62a17ae 271int mpls_ftn_update(int add, struct zebra_vrf *zvrf, enum lsp_types_t type,
272 struct prefix *prefix, enum nexthop_types_t gtype,
e132dea0
RW
273 union g_addr *gate, ifindex_t ifindex, uint8_t route_type,
274 unsigned short route_instance, mpls_label_t out_label);
ce549947 275
ea6b290b
RW
276/*
277 * Uninstall all NHLFEs bound to a single FEC.
278 */
279int mpls_ftn_uninstall(struct zebra_vrf *zvrf, enum lsp_types_t type,
280 struct prefix *prefix, uint8_t route_type,
281 unsigned short route_instance);
282
ce549947
RW
283/*
284 * Install/update a NHLFE for an LSP in the forwarding table. This may be
285 * a new LSP entry or a new NHLFE for an existing in-label or an update of
5065db0a 286 * the out-label(s) for an existing NHLFE (update case).
ce549947 287 */
d62a17ae 288int mpls_lsp_install(struct zebra_vrf *zvrf, enum lsp_types_t type,
5065db0a
RW
289 mpls_label_t in_label, uint8_t num_out_labels,
290 mpls_label_t out_labels[], enum nexthop_types_t gtype,
291 union g_addr *gate, ifindex_t ifindex);
ce549947
RW
292
293/*
294 * Uninstall a particular NHLFE in the forwarding table. If this is
295 * the only NHLFE, the entire LSP forwarding entry has to be deleted.
296 */
d62a17ae 297int mpls_lsp_uninstall(struct zebra_vrf *zvrf, enum lsp_types_t type,
298 mpls_label_t in_label, enum nexthop_types_t gtype,
299 union g_addr *gate, ifindex_t ifindex);
ce549947
RW
300
301/*
ea6b290b 302 * Uninstall all NHLFEs for a particular LSP forwarding entry.
ce549947 303 */
ea6b290b
RW
304int mpls_lsp_uninstall_all_vrf(struct zebra_vrf *zvrf, enum lsp_types_t type,
305 mpls_label_t in_label);
ce549947 306
cf9b9f77
OD
307/*
308 * Uninstall all Segment Routing NHLFEs for a particular LSP forwarding entry.
309 * If no other NHLFEs exist, the entry would be deleted.
310 */
e3b78da8 311void mpls_sr_lsp_uninstall_all(struct hash_bucket *bucket, void *ctxt);
cf9b9f77 312
1c1cf002 313#if defined(HAVE_CUMULUS)
7758e3f3 314/*
315 * Check that the label values used in LSP creation are consistent. The
316 * main criteria is that if there is ECMP, the label operation must still
317 * be consistent - i.e., all paths either do a swap or do PHP. This is due
318 * to current HW restrictions.
319 */
d62a17ae 320int zebra_mpls_lsp_label_consistent(struct zebra_vrf *zvrf,
321 mpls_label_t in_label,
322 mpls_label_t out_label,
323 enum nexthop_types_t gtype,
324 union g_addr *gate, ifindex_t ifindex);
1c1cf002 325#endif /* HAVE_CUMULUS */
7758e3f3 326
327/*
328 * Add static LSP entry. This may be the first entry for this incoming label
329 * or an additional nexthop; an existing entry may also have outgoing label
330 * changed.
331 * Note: The label operation (swap or PHP) is common for the LSP entry (all
332 * NHLFEs).
333 */
d62a17ae 334int zebra_mpls_static_lsp_add(struct zebra_vrf *zvrf, mpls_label_t in_label,
335 mpls_label_t out_label,
336 enum nexthop_types_t gtype, union g_addr *gate,
337 ifindex_t ifindex);
7758e3f3 338
339/*
340 * Delete static LSP entry. This may be the delete of one particular
341 * NHLFE for this incoming label or the delete of the entire entry (i.e.,
342 * all NHLFEs).
343 * NOTE: Delete of the only NHLFE will also end up deleting the entire
344 * LSP configuration.
345 */
d62a17ae 346int zebra_mpls_static_lsp_del(struct zebra_vrf *zvrf, mpls_label_t in_label,
347 enum nexthop_types_t gtype, union g_addr *gate,
348 ifindex_t ifindex);
7758e3f3 349
d37f4d6c
MS
350/*
351 * Process LSP update results from zebra dataplane.
352 */
353/* Forward ref of dplane update context type */
354struct zebra_dplane_ctx;
355
356void zebra_mpls_lsp_dplane_result(struct zebra_dplane_ctx *ctx);
357
104e3ad9
MS
358/* Process async dplane notifications. */
359void zebra_mpls_process_dplane_notify(struct zebra_dplane_ctx *ctx);
360
40c7bdb0 361/*
362 * Schedule all MPLS label forwarding entries for processing.
363 * Called upon changes that may affect one or more of them such as
364 * interface or nexthop state changes.
365 */
d62a17ae 366void zebra_mpls_lsp_schedule(struct zebra_vrf *zvrf);
40c7bdb0 367
3ab18ff2 368/*
369 * Display MPLS label forwarding table for a specific LSP
370 * (VTY command handler).
371 */
d62a17ae 372void zebra_mpls_print_lsp(struct vty *vty, struct zebra_vrf *zvrf,
9f049418 373 mpls_label_t label, bool use_json);
3ab18ff2 374
375/*
376 * Display MPLS label forwarding table (VTY command handler).
377 */
d62a17ae 378void zebra_mpls_print_lsp_table(struct vty *vty, struct zebra_vrf *zvrf,
9f049418 379 bool use_json);
3ab18ff2 380
7758e3f3 381/*
382 * Display MPLS LSP configuration of all static LSPs (VTY command handler).
383 */
d62a17ae 384int zebra_mpls_write_lsp_config(struct vty *vty, struct zebra_vrf *zvrf);
7758e3f3 385
84915b0a 386/*
387 * Called when VRF becomes inactive, cleans up information but keeps
388 * the table itself.
389 * NOTE: Currently supported only for default VRF.
390 */
391void zebra_mpls_cleanup_tables(struct zebra_vrf *zvrf);
392
40c7bdb0 393/*
394 * Called upon process exiting, need to delete LSP forwarding
395 * entries from the kernel.
396 * NOTE: Currently supported only for default VRF.
397 */
d62a17ae 398void zebra_mpls_close_tables(struct zebra_vrf *zvrf);
40c7bdb0 399
7758e3f3 400/*
401 * Allocate MPLS tables for this VRF.
402 * NOTE: Currently supported only for default VRF.
403 */
d62a17ae 404void zebra_mpls_init_tables(struct zebra_vrf *zvrf);
7758e3f3 405
406/*
407 * Global MPLS initialization.
408 */
d62a17ae 409void zebra_mpls_init(void);
7758e3f3 410
fe6c7157
RW
411/*
412 * MPLS VTY.
413 */
d62a17ae 414void zebra_mpls_vty_init(void);
fe6c7157 415
40c7bdb0 416/* Inline functions. */
417
418/*
419 * Distance (priority) definition for LSP NHLFE.
420 */
d7c0a89a 421static inline uint8_t lsp_distance(enum lsp_types_t type)
40c7bdb0 422{
0492eea0
RW
423 switch (type) {
424 case ZEBRA_LSP_STATIC:
d62a17ae 425 return (route_distance(ZEBRA_ROUTE_STATIC));
0492eea0
RW
426 case ZEBRA_LSP_LDP:
427 return (route_distance(ZEBRA_ROUTE_LDP));
428 case ZEBRA_LSP_BGP:
429 return (route_distance(ZEBRA_ROUTE_BGP));
339e36d2
DS
430 case ZEBRA_LSP_NONE:
431 case ZEBRA_LSP_SHARP:
635a039e 432 case ZEBRA_LSP_OSPF_SR:
0492eea0
RW
433 return 150;
434 }
339e36d2
DS
435
436 /*
437 * For some reason certain compilers do not believe
438 * that all the cases have been handled. And
439 * WTF does this work differently than when I removed
440 * the default case????
441 */
442 return 150;
40c7bdb0 443}
444
445/*
446 * Map RIB type to LSP type. Used when labeled-routes from BGP
447 * are converted into LSPs.
448 */
d62a17ae 449static inline enum lsp_types_t lsp_type_from_re_type(int re_type)
40c7bdb0 450{
d62a17ae 451 switch (re_type) {
452 case ZEBRA_ROUTE_STATIC:
453 return ZEBRA_LSP_STATIC;
635a039e
RW
454 case ZEBRA_ROUTE_LDP:
455 return ZEBRA_LSP_LDP;
d62a17ae 456 case ZEBRA_ROUTE_BGP:
457 return ZEBRA_LSP_BGP;
635a039e
RW
458 case ZEBRA_ROUTE_OSPF:
459 return ZEBRA_LSP_OSPF_SR;
339e36d2
DS
460 case ZEBRA_ROUTE_SHARP:
461 return ZEBRA_LSP_SHARP;
d62a17ae 462 default:
463 return ZEBRA_LSP_NONE;
464 }
40c7bdb0 465}
466
805444ce
RW
467/*
468 * Map LSP type to RIB type.
469 */
470static inline int re_type_from_lsp_type(enum lsp_types_t lsp_type)
471{
472 switch (lsp_type) {
473 case ZEBRA_LSP_STATIC:
474 return ZEBRA_ROUTE_STATIC;
475 case ZEBRA_LSP_LDP:
476 return ZEBRA_ROUTE_LDP;
477 case ZEBRA_LSP_BGP:
478 return ZEBRA_ROUTE_BGP;
635a039e 479 case ZEBRA_LSP_OSPF_SR:
7726c479 480 return ZEBRA_ROUTE_OSPF;
805444ce 481 case ZEBRA_LSP_NONE:
805444ce 482 return ZEBRA_ROUTE_KERNEL;
339e36d2
DS
483 case ZEBRA_LSP_SHARP:
484 return ZEBRA_ROUTE_SHARP;
805444ce 485 }
339e36d2
DS
486
487 /*
488 * For some reason certain compilers do not believe
489 * that all the cases have been handled. And
490 * WTF does this work differently than when I removed
491 * the default case????
492 */
493 return ZEBRA_ROUTE_KERNEL;
805444ce
RW
494}
495
3ab18ff2 496/* NHLFE type as printable string. */
d62a17ae 497static inline const char *nhlfe_type2str(enum lsp_types_t lsp_type)
3ab18ff2 498{
d62a17ae 499 switch (lsp_type) {
500 case ZEBRA_LSP_STATIC:
501 return "Static";
502 case ZEBRA_LSP_LDP:
503 return "LDP";
504 case ZEBRA_LSP_BGP:
505 return "BGP";
635a039e
RW
506 case ZEBRA_LSP_OSPF_SR:
507 return "SR (OSPF)";
339e36d2
DS
508 case ZEBRA_LSP_SHARP:
509 return "SHARP";
510 case ZEBRA_LSP_NONE:
d62a17ae 511 return "Unknown";
512 }
339e36d2
DS
513
514 /*
515 * For some reason certain compilers do not believe
516 * that all the cases have been handled. And
517 * WTF does this work differently than when I removed
518 * the default case????
519 */
520 return "Unknown";
3ab18ff2 521}
522
a1494c25
DS
523static inline void mpls_mark_lsps_for_processing(struct zebra_vrf *zvrf,
524 struct prefix *p)
939fba27 525{
a1494c25
DS
526 struct route_table *table;
527 struct route_node *rn;
528 rib_dest_t *dest;
529
d62a17ae 530 if (!zvrf)
531 return;
939fba27 532
a1494c25
DS
533 table = zvrf->table[family2afi(p->family)][SAFI_UNICAST];
534 if (!table)
535 return;
536
537 rn = route_node_match(table, p);
538 if (!rn)
539 return;
540
541
542 dest = rib_dest_from_rnode(rn);
543 SET_FLAG(dest->flags, RIB_DEST_UPDATE_LSPS);
939fba27 544}
545
a1494c25 546static inline void mpls_unmark_lsps_for_processing(struct route_node *rn)
939fba27 547{
a1494c25 548 rib_dest_t *dest = rib_dest_from_rnode(rn);
939fba27 549
a1494c25 550 UNSET_FLAG(dest->flags, RIB_DEST_UPDATE_LSPS);
939fba27 551}
552
a1494c25 553static inline int mpls_should_lsps_be_processed(struct route_node *rn)
939fba27 554{
a1494c25 555 rib_dest_t *dest = rib_dest_from_rnode(rn);
939fba27 556
a1494c25 557 return !!CHECK_FLAG(dest->flags, RIB_DEST_UPDATE_LSPS);
939fba27 558}
559
fe6c7157
RW
560/* Global variables. */
561extern int mpls_enabled;
562
51e94aa7
EDP
563#ifdef __cplusplus
564}
565#endif
566
54d48ea1 567#endif /*_ZEBRA_MPLS_H */