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