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