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