]>
Commit | Line | Data |
---|---|---|
7758e3f3 | 1 | /* Zebra MPLS code |
2 | * Copyright (C) 2013 Cumulus Networks, Inc. | |
3 | * | |
4 | * This file is part of GNU Zebra. | |
5 | * | |
6 | * GNU Zebra is free software; you can redistribute it and/or modify it | |
7 | * under the terms of the GNU General Public License as published by the | |
8 | * Free Software Foundation; either version 2, or (at your option) any | |
9 | * later version. | |
10 | * | |
11 | * GNU Zebra is distributed in the hope that it will be useful, but | |
12 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 | * General Public License for more details. | |
15 | * | |
896014f4 DL |
16 | * You should have received a copy of the GNU General Public License along |
17 | * with this program; see the file COPYING; if not, write to the Free Software | |
18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
7758e3f3 | 19 | */ |
20 | ||
21 | #include <zebra.h> | |
22 | ||
23 | #include "prefix.h" | |
24 | #include "table.h" | |
25 | #include "memory.h" | |
7758e3f3 | 26 | #include "command.h" |
27 | #include "if.h" | |
28 | #include "log.h" | |
29 | #include "sockunion.h" | |
30 | #include "linklist.h" | |
31 | #include "thread.h" | |
32 | #include "workqueue.h" | |
33 | #include "prefix.h" | |
34 | #include "routemap.h" | |
35 | #include "stream.h" | |
36 | #include "nexthop.h" | |
b78b820d | 37 | #include "lib/json.h" |
7758e3f3 | 38 | |
39 | #include "zebra/rib.h" | |
40 | #include "zebra/rt.h" | |
86f07f44 | 41 | #include "zebra/interface.h" |
7758e3f3 | 42 | #include "zebra/zserv.h" |
43 | #include "zebra/redistribute.h" | |
44 | #include "zebra/debug.h" | |
45 | #include "zebra/zebra_memory.h" | |
46 | #include "zebra/zebra_vrf.h" | |
47 | #include "zebra/zebra_mpls.h" | |
48 | ||
d62a17ae | 49 | DEFINE_MTYPE_STATIC(ZEBRA, LSP, "MPLS LSP object") |
50 | DEFINE_MTYPE_STATIC(ZEBRA, FEC, "MPLS FEC object") | |
51 | DEFINE_MTYPE_STATIC(ZEBRA, SLSP, "MPLS static LSP config") | |
52 | DEFINE_MTYPE_STATIC(ZEBRA, NHLFE, "MPLS nexthop object") | |
53 | DEFINE_MTYPE_STATIC(ZEBRA, SNHLFE, "MPLS static nexthop object") | |
54 | DEFINE_MTYPE_STATIC(ZEBRA, SNHLFE_IFNAME, "MPLS static nexthop ifname") | |
7758e3f3 | 55 | |
fe6c7157 RW |
56 | int mpls_enabled; |
57 | ||
7758e3f3 | 58 | /* Default rtm_table for all clients */ |
59 | extern struct zebra_t zebrad; | |
60 | ||
61 | /* static function declarations */ | |
f31e084c | 62 | |
d62a17ae | 63 | static void fec_evaluate(struct zebra_vrf *zvrf); |
d7c0a89a QY |
64 | static uint32_t fec_derive_label_from_index(struct zebra_vrf *vrf, |
65 | zebra_fec_t *fec); | |
d62a17ae | 66 | static int lsp_install(struct zebra_vrf *zvrf, mpls_label_t label, |
67 | struct route_node *rn, struct route_entry *re); | |
68 | static int lsp_uninstall(struct zebra_vrf *zvrf, mpls_label_t label); | |
69 | static int fec_change_update_lsp(struct zebra_vrf *zvrf, zebra_fec_t *fec, | |
70 | mpls_label_t old_label); | |
71 | static int fec_send(zebra_fec_t *fec, struct zserv *client); | |
72 | static void fec_update_clients(zebra_fec_t *fec); | |
73 | static void fec_print(zebra_fec_t *fec, struct vty *vty); | |
74 | static zebra_fec_t *fec_find(struct route_table *table, struct prefix *p); | |
75 | static zebra_fec_t *fec_add(struct route_table *table, struct prefix *p, | |
d7c0a89a QY |
76 | mpls_label_t label, uint32_t flags, |
77 | uint32_t label_index); | |
d62a17ae | 78 | static int fec_del(zebra_fec_t *fec); |
79 | ||
80 | static unsigned int label_hash(void *p); | |
81 | static int label_cmp(const void *p1, const void *p2); | |
82 | static int nhlfe_nexthop_active_ipv4(zebra_nhlfe_t *nhlfe, | |
83 | struct nexthop *nexthop); | |
84 | static int nhlfe_nexthop_active_ipv6(zebra_nhlfe_t *nhlfe, | |
85 | struct nexthop *nexthop); | |
86 | static int nhlfe_nexthop_active(zebra_nhlfe_t *nhlfe); | |
87 | ||
88 | static void lsp_select_best_nhlfe(zebra_lsp_t *lsp); | |
89 | static void lsp_uninstall_from_kernel(struct hash_backet *backet, void *ctxt); | |
90 | static void lsp_schedule(struct hash_backet *backet, void *ctxt); | |
91 | static wq_item_status lsp_process(struct work_queue *wq, void *data); | |
92 | static void lsp_processq_del(struct work_queue *wq, void *data); | |
93 | static void lsp_processq_complete(struct work_queue *wq); | |
94 | static int lsp_processq_add(zebra_lsp_t *lsp); | |
95 | static void *lsp_alloc(void *p); | |
96 | ||
97 | static char *nhlfe2str(zebra_nhlfe_t *nhlfe, char *buf, int size); | |
98 | static int nhlfe_nhop_match(zebra_nhlfe_t *nhlfe, enum nexthop_types_t gtype, | |
99 | union g_addr *gate, ifindex_t ifindex); | |
100 | static zebra_nhlfe_t *nhlfe_find(zebra_lsp_t *lsp, enum lsp_types_t lsp_type, | |
101 | enum nexthop_types_t gtype, union g_addr *gate, | |
102 | ifindex_t ifindex); | |
103 | static zebra_nhlfe_t *nhlfe_add(zebra_lsp_t *lsp, enum lsp_types_t lsp_type, | |
104 | enum nexthop_types_t gtype, union g_addr *gate, | |
105 | ifindex_t ifindex, mpls_label_t out_label); | |
106 | static int nhlfe_del(zebra_nhlfe_t *snhlfe); | |
107 | static void nhlfe_out_label_update(zebra_nhlfe_t *nhlfe, | |
8ecdb26e | 108 | struct mpls_label_stack *nh_label); |
d62a17ae | 109 | static int mpls_lsp_uninstall_all(struct hash *lsp_table, zebra_lsp_t *lsp, |
110 | enum lsp_types_t type); | |
111 | static int mpls_static_lsp_uninstall_all(struct zebra_vrf *zvrf, | |
112 | mpls_label_t in_label); | |
113 | static void nhlfe_print(zebra_nhlfe_t *nhlfe, struct vty *vty); | |
114 | static void lsp_print(zebra_lsp_t *lsp, void *ctxt); | |
115 | static void *slsp_alloc(void *p); | |
116 | static int snhlfe_match(zebra_snhlfe_t *snhlfe, enum nexthop_types_t gtype, | |
117 | union g_addr *gate, ifindex_t ifindex); | |
118 | static zebra_snhlfe_t *snhlfe_find(zebra_slsp_t *slsp, | |
119 | enum nexthop_types_t gtype, | |
120 | union g_addr *gate, ifindex_t ifindex); | |
121 | static zebra_snhlfe_t *snhlfe_add(zebra_slsp_t *slsp, | |
122 | enum nexthop_types_t gtype, | |
123 | union g_addr *gate, ifindex_t ifindex, | |
124 | mpls_label_t out_label); | |
125 | static int snhlfe_del(zebra_snhlfe_t *snhlfe); | |
126 | static int snhlfe_del_all(zebra_slsp_t *slsp); | |
127 | static char *snhlfe2str(zebra_snhlfe_t *snhlfe, char *buf, int size); | |
128 | static int mpls_processq_init(struct zebra_t *zebra); | |
7758e3f3 | 129 | |
130 | ||
131 | /* Static functions */ | |
132 | ||
3d468f66 DS |
133 | /* |
134 | * Handle failure in LSP install, clear flags for NHLFE. | |
135 | */ | |
136 | static void clear_nhlfe_installed(zebra_lsp_t *lsp) | |
137 | { | |
138 | zebra_nhlfe_t *nhlfe; | |
139 | struct nexthop *nexthop; | |
140 | ||
141 | for (nhlfe = lsp->nhlfe_list; nhlfe; nhlfe = nhlfe->next) { | |
142 | nexthop = nhlfe->nexthop; | |
143 | if (!nexthop) | |
144 | continue; | |
145 | ||
146 | UNSET_FLAG(nhlfe->flags, NHLFE_FLAG_INSTALLED); | |
147 | UNSET_FLAG(nexthop->flags, NEXTHOP_FLAG_FIB); | |
148 | } | |
149 | } | |
150 | ||
a64448ba DS |
151 | /* |
152 | * Install label forwarding entry based on labeled-route entry. | |
153 | */ | |
d62a17ae | 154 | static int lsp_install(struct zebra_vrf *zvrf, mpls_label_t label, |
155 | struct route_node *rn, struct route_entry *re) | |
156 | { | |
157 | struct hash *lsp_table; | |
158 | zebra_ile_t tmp_ile; | |
159 | zebra_lsp_t *lsp; | |
160 | zebra_nhlfe_t *nhlfe; | |
161 | struct nexthop *nexthop; | |
162 | enum lsp_types_t lsp_type; | |
163 | char buf[BUFSIZ]; | |
164 | int added, changed; | |
165 | ||
166 | /* Lookup table. */ | |
167 | lsp_table = zvrf->lsp_table; | |
168 | if (!lsp_table) | |
169 | return -1; | |
170 | ||
171 | lsp_type = lsp_type_from_re_type(re->type); | |
172 | added = changed = 0; | |
173 | ||
174 | /* Locate or allocate LSP entry. */ | |
175 | tmp_ile.in_label = label; | |
176 | lsp = hash_get(lsp_table, &tmp_ile, lsp_alloc); | |
177 | if (!lsp) | |
178 | return -1; | |
179 | ||
180 | /* For each active nexthop, create NHLFE. Note that we deliberately skip | |
181 | * recursive nexthops right now, because intermediate hops won't | |
182 | * understand | |
183 | * the label advertised by the recursive nexthop (plus we don't have the | |
184 | * logic yet to push multiple labels). | |
185 | */ | |
7ee30f28 | 186 | for (nexthop = re->ng.nexthop; nexthop; nexthop = nexthop->next) { |
d62a17ae | 187 | /* Skip inactive and recursive entries. */ |
188 | if (!CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_ACTIVE)) | |
189 | continue; | |
190 | if (CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_RECURSIVE)) | |
191 | continue; | |
192 | ||
193 | nhlfe = nhlfe_find(lsp, lsp_type, nexthop->type, &nexthop->gate, | |
194 | nexthop->ifindex); | |
195 | if (nhlfe) { | |
196 | /* Clear deleted flag (in case it was set) */ | |
197 | UNSET_FLAG(nhlfe->flags, NHLFE_FLAG_DELETED); | |
198 | if (nexthop_labels_match(nhlfe->nexthop, nexthop)) | |
199 | /* No change */ | |
200 | continue; | |
201 | ||
202 | ||
203 | if (IS_ZEBRA_DEBUG_MPLS) { | |
204 | nhlfe2str(nhlfe, buf, BUFSIZ); | |
205 | zlog_debug( | |
206 | "LSP in-label %u type %d nexthop %s " | |
207 | "out-label changed", | |
208 | lsp->ile.in_label, lsp_type, buf); | |
209 | } | |
210 | ||
211 | /* Update out label, trigger processing. */ | |
212 | nhlfe_out_label_update(nhlfe, nexthop->nh_label); | |
213 | SET_FLAG(nhlfe->flags, NHLFE_FLAG_CHANGED); | |
214 | changed++; | |
215 | } else { | |
216 | /* Add LSP entry to this nexthop */ | |
217 | nhlfe = nhlfe_add(lsp, lsp_type, nexthop->type, | |
218 | &nexthop->gate, nexthop->ifindex, | |
219 | nexthop->nh_label->label[0]); | |
220 | if (!nhlfe) | |
221 | return -1; | |
222 | ||
223 | if (IS_ZEBRA_DEBUG_MPLS) { | |
224 | nhlfe2str(nhlfe, buf, BUFSIZ); | |
225 | zlog_debug( | |
226 | "Add LSP in-label %u type %d nexthop %s " | |
227 | "out-label %u", | |
228 | lsp->ile.in_label, lsp_type, buf, | |
229 | nexthop->nh_label->label[0]); | |
230 | } | |
231 | ||
232 | lsp->addr_family = NHLFE_FAMILY(nhlfe); | |
233 | ||
234 | /* Mark NHLFE as changed. */ | |
235 | SET_FLAG(nhlfe->flags, NHLFE_FLAG_CHANGED); | |
236 | added++; | |
237 | } | |
238 | } | |
239 | ||
240 | /* Queue LSP for processing if necessary. If no NHLFE got added (special | |
241 | * case), delete the LSP entry; this case results in somewhat ugly | |
242 | * logging. | |
243 | */ | |
244 | if (added || changed) { | |
245 | if (lsp_processq_add(lsp)) | |
246 | return -1; | |
247 | } else if (!lsp->nhlfe_list | |
248 | && !CHECK_FLAG(lsp->flags, LSP_FLAG_SCHEDULED)) { | |
249 | if (IS_ZEBRA_DEBUG_MPLS) | |
250 | zlog_debug("Free LSP in-label %u flags 0x%x", | |
251 | lsp->ile.in_label, lsp->flags); | |
252 | ||
253 | lsp = hash_release(lsp_table, &lsp->ile); | |
254 | if (lsp) | |
255 | XFREE(MTYPE_LSP, lsp); | |
256 | } | |
257 | ||
258 | return 0; | |
a64448ba DS |
259 | } |
260 | ||
261 | /* | |
262 | * Uninstall all non-static NHLFEs of a label forwarding entry. If all | |
263 | * NHLFEs are removed, the entire entry is deleted. | |
264 | */ | |
d62a17ae | 265 | static int lsp_uninstall(struct zebra_vrf *zvrf, mpls_label_t label) |
266 | { | |
267 | struct hash *lsp_table; | |
268 | zebra_ile_t tmp_ile; | |
269 | zebra_lsp_t *lsp; | |
270 | zebra_nhlfe_t *nhlfe, *nhlfe_next; | |
271 | char buf[BUFSIZ]; | |
272 | ||
273 | /* Lookup table. */ | |
274 | lsp_table = zvrf->lsp_table; | |
275 | if (!lsp_table) | |
276 | return -1; | |
277 | ||
278 | /* If entry is not present, exit. */ | |
279 | tmp_ile.in_label = label; | |
280 | lsp = hash_lookup(lsp_table, &tmp_ile); | |
281 | if (!lsp || !lsp->nhlfe_list) | |
282 | return 0; | |
283 | ||
284 | /* Mark NHLFEs for delete or directly delete, as appropriate. */ | |
285 | for (nhlfe = lsp->nhlfe_list; nhlfe; nhlfe = nhlfe_next) { | |
286 | nhlfe_next = nhlfe->next; | |
287 | ||
288 | /* Skip static NHLFEs */ | |
289 | if (nhlfe->type == ZEBRA_LSP_STATIC) | |
290 | continue; | |
291 | ||
292 | if (IS_ZEBRA_DEBUG_MPLS) { | |
293 | nhlfe2str(nhlfe, buf, BUFSIZ); | |
294 | zlog_debug( | |
295 | "Del LSP in-label %u type %d nexthop %s flags 0x%x", | |
296 | label, nhlfe->type, buf, nhlfe->flags); | |
297 | } | |
298 | ||
299 | if (CHECK_FLAG(nhlfe->flags, NHLFE_FLAG_SELECTED)) { | |
300 | UNSET_FLAG(nhlfe->flags, NHLFE_FLAG_CHANGED); | |
301 | SET_FLAG(nhlfe->flags, NHLFE_FLAG_DELETED); | |
302 | } else { | |
303 | nhlfe_del(nhlfe); | |
304 | } | |
305 | } | |
306 | ||
307 | /* Queue LSP for processing, if needed, else delete. */ | |
308 | if (CHECK_FLAG(lsp->flags, LSP_FLAG_INSTALLED)) { | |
309 | if (lsp_processq_add(lsp)) | |
310 | return -1; | |
311 | } else if (!lsp->nhlfe_list | |
312 | && !CHECK_FLAG(lsp->flags, LSP_FLAG_SCHEDULED)) { | |
313 | if (IS_ZEBRA_DEBUG_MPLS) | |
314 | zlog_debug("Del LSP in-label %u flags 0x%x", | |
315 | lsp->ile.in_label, lsp->flags); | |
316 | ||
317 | lsp = hash_release(lsp_table, &lsp->ile); | |
318 | if (lsp) | |
319 | XFREE(MTYPE_LSP, lsp); | |
320 | } | |
321 | ||
322 | return 0; | |
a64448ba DS |
323 | } |
324 | ||
28d58fd7 VV |
325 | /* |
326 | * This function is invoked upon change to label block configuration; it | |
327 | * will walk all registered FECs with label-index and appropriately update | |
328 | * their local labels and trigger client updates. | |
329 | */ | |
d62a17ae | 330 | static void fec_evaluate(struct zebra_vrf *zvrf) |
331 | { | |
332 | struct route_node *rn; | |
333 | zebra_fec_t *fec; | |
d7c0a89a | 334 | uint32_t old_label, new_label; |
d62a17ae | 335 | int af; |
336 | char buf[BUFSIZ]; | |
337 | ||
338 | for (af = AFI_IP; af < AFI_MAX; af++) { | |
339 | if (zvrf->fec_table[af] == NULL) | |
340 | continue; | |
341 | ||
342 | for (rn = route_top(zvrf->fec_table[af]); rn; | |
343 | rn = route_next(rn)) { | |
344 | if ((fec = rn->info) == NULL) | |
345 | continue; | |
346 | ||
347 | /* Skip configured FECs and those without a label index. | |
348 | */ | |
349 | if (fec->flags & FEC_FLAG_CONFIGURED | |
350 | || fec->label_index == MPLS_INVALID_LABEL_INDEX) | |
351 | continue; | |
352 | ||
353 | if (IS_ZEBRA_DEBUG_MPLS) | |
354 | prefix2str(&rn->p, buf, BUFSIZ); | |
355 | ||
356 | /* Save old label, determine new label. */ | |
357 | old_label = fec->label; | |
358 | new_label = | |
359 | zvrf->mpls_srgb.start_label + fec->label_index; | |
360 | if (new_label >= zvrf->mpls_srgb.end_label) | |
361 | new_label = MPLS_INVALID_LABEL; | |
362 | ||
363 | /* If label has changed, update FEC and clients. */ | |
364 | if (new_label == old_label) | |
365 | continue; | |
366 | ||
367 | if (IS_ZEBRA_DEBUG_MPLS) | |
368 | zlog_debug( | |
369 | "Update fec %s new label %u upon label block", | |
370 | buf, new_label); | |
371 | ||
372 | fec->label = new_label; | |
373 | fec_update_clients(fec); | |
374 | ||
375 | /* Update label forwarding entries appropriately */ | |
376 | fec_change_update_lsp(zvrf, fec, old_label); | |
377 | } | |
378 | } | |
28d58fd7 VV |
379 | } |
380 | ||
381 | /* | |
382 | * Derive (if possible) and update the local label for the FEC based on | |
383 | * its label index. The index is "acceptable" if it falls within the | |
384 | * globally configured label block (SRGB). | |
385 | */ | |
d7c0a89a QY |
386 | static uint32_t fec_derive_label_from_index(struct zebra_vrf *zvrf, |
387 | zebra_fec_t *fec) | |
28d58fd7 | 388 | { |
d7c0a89a | 389 | uint32_t label; |
28d58fd7 | 390 | |
d62a17ae | 391 | if (fec->label_index != MPLS_INVALID_LABEL_INDEX |
392 | && zvrf->mpls_srgb.start_label | |
393 | && ((label = zvrf->mpls_srgb.start_label + fec->label_index) | |
394 | < zvrf->mpls_srgb.end_label)) | |
395 | fec->label = label; | |
396 | else | |
397 | fec->label = MPLS_INVALID_LABEL; | |
28d58fd7 | 398 | |
d62a17ae | 399 | return fec->label; |
28d58fd7 VV |
400 | } |
401 | ||
a64448ba DS |
402 | /* |
403 | * There is a change for this FEC. Install or uninstall label forwarding | |
404 | * entries, as appropriate. | |
405 | */ | |
d62a17ae | 406 | static int fec_change_update_lsp(struct zebra_vrf *zvrf, zebra_fec_t *fec, |
407 | mpls_label_t old_label) | |
a64448ba | 408 | { |
d62a17ae | 409 | struct route_table *table; |
410 | struct route_node *rn; | |
411 | struct route_entry *re; | |
412 | afi_t afi; | |
a64448ba | 413 | |
d62a17ae | 414 | /* Uninstall label forwarding entry, if previously installed. */ |
996c9314 LB |
415 | if (old_label != MPLS_INVALID_LABEL |
416 | && old_label != MPLS_LABEL_IMPLICIT_NULL) | |
d62a17ae | 417 | lsp_uninstall(zvrf, old_label); |
a64448ba | 418 | |
d62a17ae | 419 | /* Install label forwarding entry corr. to new label, if needed. */ |
420 | if (fec->label == MPLS_INVALID_LABEL | |
70e98a7f | 421 | || fec->label == MPLS_LABEL_IMPLICIT_NULL) |
d62a17ae | 422 | return 0; |
a64448ba | 423 | |
d62a17ae | 424 | afi = family2afi(PREFIX_FAMILY(&fec->rn->p)); |
425 | table = zebra_vrf_table(afi, SAFI_UNICAST, zvrf_id(zvrf)); | |
426 | if (!table) | |
427 | return 0; | |
a64448ba | 428 | |
d62a17ae | 429 | /* See if labeled route exists. */ |
430 | rn = route_node_lookup(table, &fec->rn->p); | |
431 | if (!rn) | |
432 | return 0; | |
a64448ba | 433 | |
a2addae8 | 434 | RNODE_FOREACH_RE (rn, re) { |
d62a17ae | 435 | if (CHECK_FLAG(re->flags, ZEBRA_FLAG_SELECTED)) |
436 | break; | |
437 | } | |
a64448ba | 438 | |
d62a17ae | 439 | if (!re || !zebra_rib_labeled_unicast(re)) |
440 | return 0; | |
a64448ba | 441 | |
d62a17ae | 442 | if (lsp_install(zvrf, fec->label, rn, re)) |
443 | return -1; | |
a64448ba | 444 | |
d62a17ae | 445 | return 0; |
a64448ba DS |
446 | } |
447 | ||
5aba114a DS |
448 | /* |
449 | * Inform about FEC to a registered client. | |
450 | */ | |
d62a17ae | 451 | static int fec_send(zebra_fec_t *fec, struct zserv *client) |
5aba114a | 452 | { |
d62a17ae | 453 | struct stream *s; |
454 | struct route_node *rn; | |
5aba114a | 455 | |
d62a17ae | 456 | rn = fec->rn; |
5aba114a | 457 | |
d62a17ae | 458 | /* Get output stream. */ |
1002497a | 459 | s = stream_new(ZEBRA_MAX_PACKET_SIZ); |
5aba114a | 460 | |
7cf15b25 | 461 | zclient_create_header(s, ZEBRA_FEC_UPDATE, VRF_DEFAULT); |
5aba114a | 462 | |
d62a17ae | 463 | stream_putw(s, rn->p.family); |
464 | stream_put_prefix(s, &rn->p); | |
465 | stream_putl(s, fec->label); | |
466 | stream_putw_at(s, 0, stream_get_endp(s)); | |
21ccc0cf | 467 | return zserv_send_message(client, s); |
5aba114a DS |
468 | } |
469 | ||
470 | /* | |
471 | * Update all registered clients about this FEC. Caller should've updated | |
472 | * FEC and ensure no duplicate updates. | |
473 | */ | |
d62a17ae | 474 | static void fec_update_clients(zebra_fec_t *fec) |
5aba114a | 475 | { |
d62a17ae | 476 | struct listnode *node; |
477 | struct zserv *client; | |
5aba114a | 478 | |
d62a17ae | 479 | for (ALL_LIST_ELEMENTS_RO(fec->client_list, node, client)) { |
480 | if (IS_ZEBRA_DEBUG_MPLS) | |
481 | zlog_debug("Update client %s", | |
482 | zebra_route_string(client->proto)); | |
483 | fec_send(fec, client); | |
484 | } | |
5aba114a DS |
485 | } |
486 | ||
487 | ||
f31e084c DS |
488 | /* |
489 | * Print a FEC-label binding entry. | |
490 | */ | |
d62a17ae | 491 | static void fec_print(zebra_fec_t *fec, struct vty *vty) |
492 | { | |
493 | struct route_node *rn; | |
494 | struct listnode *node; | |
495 | struct zserv *client; | |
496 | char buf[BUFSIZ]; | |
497 | ||
498 | rn = fec->rn; | |
499 | prefix2str(&rn->p, buf, BUFSIZ); | |
500 | vty_out(vty, "%s\n", buf); | |
501 | vty_out(vty, " Label: %s", label2str(fec->label, buf, BUFSIZ)); | |
502 | if (fec->label_index != MPLS_INVALID_LABEL_INDEX) | |
503 | vty_out(vty, ", Label Index: %u", fec->label_index); | |
504 | vty_out(vty, "\n"); | |
505 | if (!list_isempty(fec->client_list)) { | |
506 | vty_out(vty, " Client list:"); | |
507 | for (ALL_LIST_ELEMENTS_RO(fec->client_list, node, client)) | |
508 | vty_out(vty, " %s(fd %d)", | |
509 | zebra_route_string(client->proto), | |
510 | client->sock); | |
511 | vty_out(vty, "\n"); | |
512 | } | |
f31e084c DS |
513 | } |
514 | ||
515 | /* | |
516 | * Locate FEC-label binding that matches with passed info. | |
517 | */ | |
d62a17ae | 518 | static zebra_fec_t *fec_find(struct route_table *table, struct prefix *p) |
f31e084c | 519 | { |
d62a17ae | 520 | struct route_node *rn; |
f31e084c | 521 | |
d62a17ae | 522 | apply_mask(p); |
523 | rn = route_node_lookup(table, p); | |
524 | if (!rn) | |
525 | return NULL; | |
f31e084c | 526 | |
d62a17ae | 527 | route_unlock_node(rn); |
528 | return (rn->info); | |
f31e084c DS |
529 | } |
530 | ||
531 | /* | |
5aba114a DS |
532 | * Add a FEC. This may be upon a client registering for a binding |
533 | * or when a binding is configured. | |
f31e084c | 534 | */ |
d62a17ae | 535 | static zebra_fec_t *fec_add(struct route_table *table, struct prefix *p, |
d7c0a89a QY |
536 | mpls_label_t label, uint32_t flags, |
537 | uint32_t label_index) | |
f31e084c | 538 | { |
d62a17ae | 539 | struct route_node *rn; |
540 | zebra_fec_t *fec; | |
f31e084c | 541 | |
d62a17ae | 542 | apply_mask(p); |
f31e084c | 543 | |
d62a17ae | 544 | /* Lookup (or add) route node.*/ |
545 | rn = route_node_get(table, p); | |
546 | if (!rn) | |
547 | return NULL; | |
f31e084c | 548 | |
d62a17ae | 549 | fec = rn->info; |
f31e084c | 550 | |
d62a17ae | 551 | if (!fec) { |
552 | fec = XCALLOC(MTYPE_FEC, sizeof(zebra_fec_t)); | |
f31e084c | 553 | |
d62a17ae | 554 | rn->info = fec; |
555 | fec->rn = rn; | |
556 | fec->label = label; | |
557 | fec->client_list = list_new(); | |
558 | } else | |
559 | route_unlock_node(rn); /* for the route_node_get */ | |
f31e084c | 560 | |
d62a17ae | 561 | fec->label_index = label_index; |
562 | fec->flags = flags; | |
f31e084c | 563 | |
d62a17ae | 564 | return fec; |
f31e084c DS |
565 | } |
566 | ||
567 | /* | |
5aba114a DS |
568 | * Delete a FEC. This may be upon the last client deregistering for |
569 | * a FEC and no binding exists or when the binding is deleted and there | |
570 | * are no registered clients. | |
f31e084c | 571 | */ |
d62a17ae | 572 | static int fec_del(zebra_fec_t *fec) |
f31e084c | 573 | { |
acdf5e25 | 574 | list_delete_and_null(&fec->client_list); |
d62a17ae | 575 | fec->rn->info = NULL; |
576 | route_unlock_node(fec->rn); | |
577 | XFREE(MTYPE_FEC, fec); | |
578 | return 0; | |
f31e084c DS |
579 | } |
580 | ||
7758e3f3 | 581 | /* |
582 | * Hash function for label. | |
583 | */ | |
d62a17ae | 584 | static unsigned int label_hash(void *p) |
7758e3f3 | 585 | { |
d62a17ae | 586 | const zebra_ile_t *ile = p; |
7758e3f3 | 587 | |
d62a17ae | 588 | return (jhash_1word(ile->in_label, 0)); |
7758e3f3 | 589 | } |
590 | ||
591 | /* | |
592 | * Compare 2 LSP hash entries based on in-label. | |
593 | */ | |
d62a17ae | 594 | static int label_cmp(const void *p1, const void *p2) |
7758e3f3 | 595 | { |
d62a17ae | 596 | const zebra_ile_t *ile1 = p1; |
597 | const zebra_ile_t *ile2 = p2; | |
7758e3f3 | 598 | |
d62a17ae | 599 | return (ile1->in_label == ile2->in_label); |
7758e3f3 | 600 | } |
601 | ||
40c7bdb0 | 602 | /* |
603 | * Check if an IPv4 nexthop for a NHLFE is active. Update nexthop based on | |
604 | * the passed flag. | |
605 | * NOTE: Looking only for connected routes right now. | |
606 | */ | |
d62a17ae | 607 | static int nhlfe_nexthop_active_ipv4(zebra_nhlfe_t *nhlfe, |
608 | struct nexthop *nexthop) | |
40c7bdb0 | 609 | { |
d62a17ae | 610 | struct route_table *table; |
611 | struct prefix_ipv4 p; | |
612 | struct route_node *rn; | |
613 | struct route_entry *match; | |
614 | struct nexthop *match_nh; | |
40c7bdb0 | 615 | |
4a7371e9 | 616 | table = zebra_vrf_table(AFI_IP, SAFI_UNICAST, nexthop->vrf_id); |
d62a17ae | 617 | if (!table) |
618 | return 0; | |
40c7bdb0 | 619 | |
d62a17ae | 620 | /* Lookup nexthop in IPv4 routing table. */ |
621 | memset(&p, 0, sizeof(struct prefix_ipv4)); | |
622 | p.family = AF_INET; | |
623 | p.prefixlen = IPV4_MAX_PREFIXLEN; | |
624 | p.prefix = nexthop->gate.ipv4; | |
40c7bdb0 | 625 | |
d62a17ae | 626 | rn = route_node_match(table, (struct prefix *)&p); |
627 | if (!rn) | |
628 | return 0; | |
40c7bdb0 | 629 | |
d62a17ae | 630 | route_unlock_node(rn); |
88d88a9c | 631 | |
d62a17ae | 632 | /* Locate a valid connected route. */ |
a2addae8 | 633 | RNODE_FOREACH_RE (rn, match) { |
d62a17ae | 634 | if (CHECK_FLAG(match->status, ROUTE_ENTRY_REMOVED) |
635 | || !CHECK_FLAG(match->flags, ZEBRA_FLAG_SELECTED)) | |
636 | continue; | |
637 | ||
7ee30f28 | 638 | for (match_nh = match->ng.nexthop; match_nh; |
d62a17ae | 639 | match_nh = match_nh->next) { |
640 | if (match->type == ZEBRA_ROUTE_CONNECT | |
641 | || nexthop->ifindex == match_nh->ifindex) { | |
642 | nexthop->ifindex = match_nh->ifindex; | |
643 | return 1; | |
644 | } | |
645 | } | |
88d88a9c | 646 | } |
40c7bdb0 | 647 | |
d62a17ae | 648 | return 0; |
40c7bdb0 | 649 | } |
650 | ||
651 | ||
652 | /* | |
653 | * Check if an IPv6 nexthop for a NHLFE is active. Update nexthop based on | |
654 | * the passed flag. | |
655 | * NOTE: Looking only for connected routes right now. | |
656 | */ | |
d62a17ae | 657 | static int nhlfe_nexthop_active_ipv6(zebra_nhlfe_t *nhlfe, |
658 | struct nexthop *nexthop) | |
40c7bdb0 | 659 | { |
d62a17ae | 660 | struct route_table *table; |
661 | struct prefix_ipv6 p; | |
662 | struct route_node *rn; | |
663 | struct route_entry *match; | |
40c7bdb0 | 664 | |
4a7371e9 | 665 | table = zebra_vrf_table(AFI_IP6, SAFI_UNICAST, nexthop->vrf_id); |
d62a17ae | 666 | if (!table) |
667 | return 0; | |
40c7bdb0 | 668 | |
d62a17ae | 669 | /* Lookup nexthop in IPv6 routing table. */ |
670 | memset(&p, 0, sizeof(struct prefix_ipv6)); | |
671 | p.family = AF_INET6; | |
672 | p.prefixlen = IPV6_MAX_PREFIXLEN; | |
673 | p.prefix = nexthop->gate.ipv6; | |
40c7bdb0 | 674 | |
d62a17ae | 675 | rn = route_node_match(table, (struct prefix *)&p); |
676 | if (!rn) | |
677 | return 0; | |
40c7bdb0 | 678 | |
d62a17ae | 679 | route_unlock_node(rn); |
40c7bdb0 | 680 | |
d62a17ae | 681 | /* Locate a valid connected route. */ |
a2addae8 | 682 | RNODE_FOREACH_RE (rn, match) { |
d62a17ae | 683 | if ((match->type == ZEBRA_ROUTE_CONNECT) |
684 | && !CHECK_FLAG(match->status, ROUTE_ENTRY_REMOVED) | |
685 | && CHECK_FLAG(match->flags, ZEBRA_FLAG_SELECTED)) | |
686 | break; | |
687 | } | |
40c7bdb0 | 688 | |
7ee30f28 | 689 | if (!match || !match->ng.nexthop) |
d62a17ae | 690 | return 0; |
40c7bdb0 | 691 | |
7ee30f28 | 692 | nexthop->ifindex = match->ng.nexthop->ifindex; |
d62a17ae | 693 | return 1; |
40c7bdb0 | 694 | } |
695 | ||
696 | ||
697 | /* | |
698 | * Check the nexthop reachability for a NHLFE and return if valid (reachable) | |
699 | * or not. | |
700 | * NOTE: Each NHLFE points to only 1 nexthop. | |
701 | */ | |
d62a17ae | 702 | static int nhlfe_nexthop_active(zebra_nhlfe_t *nhlfe) |
703 | { | |
704 | struct nexthop *nexthop; | |
705 | struct interface *ifp; | |
86f07f44 | 706 | struct zebra_ns *zns; |
d62a17ae | 707 | |
708 | nexthop = nhlfe->nexthop; | |
709 | if (!nexthop) // unexpected | |
710 | return 0; | |
711 | ||
712 | /* Check on nexthop based on type. */ | |
713 | switch (nexthop->type) { | |
b9abd9ad DS |
714 | case NEXTHOP_TYPE_IFINDEX: |
715 | /* | |
716 | * Lookup if this type is special. The | |
717 | * NEXTHOP_TYPE_IFINDEX is a pop and | |
718 | * forward into a different table for | |
719 | * processing. As such this ifindex | |
720 | * passed to us may be a VRF device | |
721 | * which will not be in the default | |
722 | * VRF. So let's look in all of them | |
723 | */ | |
86f07f44 PG |
724 | zns = zebra_ns_lookup(NS_DEFAULT); |
725 | ifp = if_lookup_by_index_per_ns(zns, nexthop->ifindex); | |
b9abd9ad DS |
726 | if (ifp && if_is_operative(ifp)) |
727 | SET_FLAG(nexthop->flags, NEXTHOP_FLAG_ACTIVE); | |
728 | else | |
729 | UNSET_FLAG(nexthop->flags, NEXTHOP_FLAG_ACTIVE); | |
730 | break; | |
d62a17ae | 731 | case NEXTHOP_TYPE_IPV4: |
732 | case NEXTHOP_TYPE_IPV4_IFINDEX: | |
733 | if (nhlfe_nexthop_active_ipv4(nhlfe, nexthop)) | |
734 | SET_FLAG(nexthop->flags, NEXTHOP_FLAG_ACTIVE); | |
735 | else | |
736 | UNSET_FLAG(nexthop->flags, NEXTHOP_FLAG_ACTIVE); | |
737 | break; | |
738 | ||
739 | case NEXTHOP_TYPE_IPV6: | |
740 | if (nhlfe_nexthop_active_ipv6(nhlfe, nexthop)) | |
741 | SET_FLAG(nexthop->flags, NEXTHOP_FLAG_ACTIVE); | |
742 | else | |
743 | UNSET_FLAG(nexthop->flags, NEXTHOP_FLAG_ACTIVE); | |
744 | break; | |
745 | ||
746 | case NEXTHOP_TYPE_IPV6_IFINDEX: | |
747 | if (IN6_IS_ADDR_LINKLOCAL(&nexthop->gate.ipv6)) { | |
4a7371e9 DS |
748 | ifp = if_lookup_by_index(nexthop->ifindex, |
749 | nexthop->vrf_id); | |
d62a17ae | 750 | if (ifp && if_is_operative(ifp)) |
751 | SET_FLAG(nexthop->flags, NEXTHOP_FLAG_ACTIVE); | |
752 | else | |
753 | UNSET_FLAG(nexthop->flags, NEXTHOP_FLAG_ACTIVE); | |
754 | } else { | |
755 | if (nhlfe_nexthop_active_ipv6(nhlfe, nexthop)) | |
756 | SET_FLAG(nexthop->flags, NEXTHOP_FLAG_ACTIVE); | |
757 | else | |
758 | UNSET_FLAG(nexthop->flags, NEXTHOP_FLAG_ACTIVE); | |
759 | } | |
760 | break; | |
761 | ||
762 | default: | |
763 | break; | |
764 | } | |
765 | ||
766 | return CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_ACTIVE); | |
40c7bdb0 | 767 | } |
768 | ||
769 | /* | |
770 | * Walk through NHLFEs for a LSP forwarding entry, verify nexthop | |
771 | * reachability and select the best. Multipath entries are also | |
772 | * marked. This is invoked when an LSP scheduled for processing (due | |
773 | * to some change) is examined. | |
774 | */ | |
d62a17ae | 775 | static void lsp_select_best_nhlfe(zebra_lsp_t *lsp) |
776 | { | |
777 | zebra_nhlfe_t *nhlfe; | |
778 | zebra_nhlfe_t *best; | |
779 | struct nexthop *nexthop; | |
780 | int changed = 0; | |
781 | ||
782 | if (!lsp) | |
783 | return; | |
784 | ||
785 | best = NULL; | |
786 | lsp->num_ecmp = 0; | |
787 | UNSET_FLAG(lsp->flags, LSP_FLAG_CHANGED); | |
788 | ||
789 | /* | |
790 | * First compute the best path, after checking nexthop status. We are | |
791 | * only | |
792 | * concerned with non-deleted NHLFEs. | |
793 | */ | |
794 | for (nhlfe = lsp->nhlfe_list; nhlfe; nhlfe = nhlfe->next) { | |
795 | /* Clear selection flags. */ | |
796 | UNSET_FLAG(nhlfe->flags, | |
797 | (NHLFE_FLAG_SELECTED | NHLFE_FLAG_MULTIPATH)); | |
798 | ||
799 | if (!CHECK_FLAG(nhlfe->flags, NHLFE_FLAG_DELETED) | |
800 | && nhlfe_nexthop_active(nhlfe)) { | |
801 | if (!best || (nhlfe->distance < best->distance)) | |
802 | best = nhlfe; | |
803 | } | |
804 | } | |
805 | ||
806 | lsp->best_nhlfe = best; | |
807 | if (!lsp->best_nhlfe) | |
808 | return; | |
809 | ||
810 | /* Mark best NHLFE as selected. */ | |
811 | SET_FLAG(lsp->best_nhlfe->flags, NHLFE_FLAG_SELECTED); | |
812 | ||
813 | /* | |
814 | * If best path exists, see if there is ECMP. While doing this, note if | |
815 | * a | |
816 | * new (uninstalled) NHLFE has been selected, an installed entry that is | |
817 | * still selected has a change or an installed entry is to be removed. | |
818 | */ | |
819 | for (nhlfe = lsp->nhlfe_list; nhlfe; nhlfe = nhlfe->next) { | |
820 | int nh_chg, nh_sel, nh_inst; | |
821 | ||
822 | nexthop = nhlfe->nexthop; | |
823 | if (!nexthop) // unexpected | |
824 | continue; | |
825 | ||
826 | if (!CHECK_FLAG(nhlfe->flags, NHLFE_FLAG_DELETED) | |
827 | && CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_ACTIVE) | |
828 | && (nhlfe->distance == lsp->best_nhlfe->distance)) { | |
829 | SET_FLAG(nhlfe->flags, NHLFE_FLAG_SELECTED); | |
830 | SET_FLAG(nhlfe->flags, NHLFE_FLAG_MULTIPATH); | |
831 | lsp->num_ecmp++; | |
832 | } | |
833 | ||
834 | if (CHECK_FLAG(lsp->flags, LSP_FLAG_INSTALLED) && !changed) { | |
835 | nh_chg = CHECK_FLAG(nhlfe->flags, NHLFE_FLAG_CHANGED); | |
836 | nh_sel = CHECK_FLAG(nhlfe->flags, NHLFE_FLAG_SELECTED); | |
837 | nh_inst = | |
838 | CHECK_FLAG(nhlfe->flags, NHLFE_FLAG_INSTALLED); | |
839 | ||
840 | if ((nh_sel && !nh_inst) | |
841 | || (nh_sel && nh_inst && nh_chg) | |
842 | || (nh_inst && !nh_sel)) | |
843 | changed = 1; | |
844 | } | |
845 | ||
846 | /* We have finished examining, clear changed flag. */ | |
847 | UNSET_FLAG(nhlfe->flags, NHLFE_FLAG_CHANGED); | |
848 | } | |
849 | ||
850 | if (changed) | |
851 | SET_FLAG(lsp->flags, LSP_FLAG_CHANGED); | |
40c7bdb0 | 852 | } |
853 | ||
854 | /* | |
855 | * Delete LSP forwarding entry from kernel, if installed. Called upon | |
856 | * process exit. | |
857 | */ | |
d62a17ae | 858 | static void lsp_uninstall_from_kernel(struct hash_backet *backet, void *ctxt) |
40c7bdb0 | 859 | { |
d62a17ae | 860 | zebra_lsp_t *lsp; |
40c7bdb0 | 861 | |
d62a17ae | 862 | lsp = (zebra_lsp_t *)backet->data; |
4a83e7a0 | 863 | if (CHECK_FLAG(lsp->flags, LSP_FLAG_INSTALLED)) |
7c5d0e18 | 864 | (void)kernel_del_lsp(lsp); |
40c7bdb0 | 865 | } |
866 | ||
867 | /* | |
868 | * Schedule LSP forwarding entry for processing. Called upon changes | |
869 | * that may impact LSPs such as nexthop / connected route changes. | |
870 | */ | |
d62a17ae | 871 | static void lsp_schedule(struct hash_backet *backet, void *ctxt) |
40c7bdb0 | 872 | { |
d62a17ae | 873 | zebra_lsp_t *lsp; |
40c7bdb0 | 874 | |
d62a17ae | 875 | lsp = (zebra_lsp_t *)backet->data; |
0af35d90 | 876 | (void)lsp_processq_add(lsp); |
40c7bdb0 | 877 | } |
878 | ||
879 | /* | |
880 | * Process a LSP entry that is in the queue. Recalculate best NHLFE and | |
881 | * any multipaths and update or delete from the kernel, as needed. | |
882 | */ | |
d62a17ae | 883 | static wq_item_status lsp_process(struct work_queue *wq, void *data) |
884 | { | |
885 | zebra_lsp_t *lsp; | |
886 | zebra_nhlfe_t *oldbest, *newbest; | |
887 | char buf[BUFSIZ], buf2[BUFSIZ]; | |
888 | struct zebra_vrf *zvrf = vrf_info_lookup(VRF_DEFAULT); | |
889 | ||
890 | lsp = (zebra_lsp_t *)data; | |
891 | if (!lsp) // unexpected | |
892 | return WQ_SUCCESS; | |
893 | ||
894 | oldbest = lsp->best_nhlfe; | |
895 | ||
896 | /* Select best NHLFE(s) */ | |
897 | lsp_select_best_nhlfe(lsp); | |
898 | ||
899 | newbest = lsp->best_nhlfe; | |
900 | ||
901 | if (IS_ZEBRA_DEBUG_MPLS) { | |
902 | if (oldbest) | |
903 | nhlfe2str(oldbest, buf, BUFSIZ); | |
904 | if (newbest) | |
905 | nhlfe2str(newbest, buf2, BUFSIZ); | |
906 | zlog_debug( | |
907 | "Process LSP in-label %u oldbest %s newbest %s " | |
908 | "flags 0x%x ecmp# %d", | |
909 | lsp->ile.in_label, oldbest ? buf : "NULL", | |
910 | newbest ? buf2 : "NULL", lsp->flags, lsp->num_ecmp); | |
911 | } | |
912 | ||
913 | if (!CHECK_FLAG(lsp->flags, LSP_FLAG_INSTALLED)) { | |
914 | /* Not already installed */ | |
915 | if (newbest) { | |
2b63430c DS |
916 | |
917 | UNSET_FLAG(lsp->flags, LSP_FLAG_CHANGED); | |
7c5d0e18 DS |
918 | switch (kernel_add_lsp(lsp)) { |
919 | case DP_REQUEST_QUEUED: | |
920 | zlog_err("No current DataPlane interfaces can return this, please fix"); | |
921 | break; | |
922 | case DP_REQUEST_FAILURE: | |
923 | break; | |
924 | case DP_REQUEST_SUCCESS: | |
925 | zvrf->lsp_installs++; | |
926 | break; | |
927 | } | |
d62a17ae | 928 | } |
929 | } else { | |
930 | /* Installed, may need an update and/or delete. */ | |
931 | if (!newbest) { | |
e6d44ec7 | 932 | |
7c5d0e18 DS |
933 | switch (kernel_del_lsp(lsp)) { |
934 | case DP_REQUEST_QUEUED: | |
935 | zlog_err("No current DataPlane interfaces can return this, please fix"); | |
936 | break; | |
937 | case DP_REQUEST_FAILURE: | |
938 | break; | |
939 | case DP_REQUEST_SUCCESS: | |
940 | zvrf->lsp_removals++; | |
941 | break; | |
942 | } | |
d62a17ae | 943 | } else if (CHECK_FLAG(lsp->flags, LSP_FLAG_CHANGED)) { |
9fa38ec6 DS |
944 | zebra_nhlfe_t *nhlfe; |
945 | struct nexthop *nexthop; | |
2b63430c DS |
946 | |
947 | UNSET_FLAG(lsp->flags, LSP_FLAG_CHANGED); | |
948 | UNSET_FLAG(lsp->flags, LSP_FLAG_INSTALLED); | |
e6d44ec7 | 949 | |
9fa38ec6 DS |
950 | /* |
951 | * Any NHLFE that was installed but is not | |
952 | * selected now needs to have its flags updated. | |
953 | */ | |
996c9314 LB |
954 | for (nhlfe = lsp->nhlfe_list; nhlfe; |
955 | nhlfe = nhlfe->next) { | |
9fa38ec6 DS |
956 | nexthop = nhlfe->nexthop; |
957 | if (!nexthop) | |
958 | continue; | |
959 | ||
960 | if (CHECK_FLAG(nhlfe->flags, | |
996c9314 LB |
961 | NHLFE_FLAG_INSTALLED) |
962 | && !CHECK_FLAG(nhlfe->flags, | |
963 | NHLFE_FLAG_SELECTED)) { | |
9fa38ec6 DS |
964 | UNSET_FLAG(nhlfe->flags, |
965 | NHLFE_FLAG_INSTALLED); | |
966 | UNSET_FLAG(nexthop->flags, | |
967 | NEXTHOP_FLAG_FIB); | |
968 | } | |
969 | } | |
970 | ||
7c5d0e18 DS |
971 | switch (kernel_upd_lsp(lsp)) { |
972 | case DP_REQUEST_QUEUED: | |
973 | zlog_err("No current DataPlane interfaces can return this, please fix"); | |
974 | break; | |
975 | case DP_REQUEST_FAILURE: | |
976 | break; | |
977 | case DP_REQUEST_SUCCESS: | |
978 | zvrf->lsp_installs++; | |
979 | break; | |
980 | } | |
d62a17ae | 981 | } |
982 | } | |
983 | ||
984 | return WQ_SUCCESS; | |
40c7bdb0 | 985 | } |
986 | ||
987 | ||
988 | /* | |
989 | * Callback upon processing completion of a LSP forwarding entry. | |
990 | */ | |
d62a17ae | 991 | static void lsp_processq_del(struct work_queue *wq, void *data) |
40c7bdb0 | 992 | { |
d62a17ae | 993 | struct zebra_vrf *zvrf; |
994 | zebra_lsp_t *lsp; | |
995 | struct hash *lsp_table; | |
996 | zebra_nhlfe_t *nhlfe, *nhlfe_next; | |
40c7bdb0 | 997 | |
d62a17ae | 998 | zvrf = vrf_info_lookup(VRF_DEFAULT); |
999 | assert(zvrf); | |
40c7bdb0 | 1000 | |
d62a17ae | 1001 | lsp_table = zvrf->lsp_table; |
1002 | if (!lsp_table) // unexpected | |
1003 | return; | |
40c7bdb0 | 1004 | |
d62a17ae | 1005 | lsp = (zebra_lsp_t *)data; |
1006 | if (!lsp) // unexpected | |
1007 | return; | |
40c7bdb0 | 1008 | |
d62a17ae | 1009 | /* Clear flag, remove any NHLFEs marked for deletion. If no NHLFEs |
1010 | * exist, | |
1011 | * delete LSP entry also. | |
1012 | */ | |
1013 | UNSET_FLAG(lsp->flags, LSP_FLAG_SCHEDULED); | |
40c7bdb0 | 1014 | |
d62a17ae | 1015 | for (nhlfe = lsp->nhlfe_list; nhlfe; nhlfe = nhlfe_next) { |
1016 | nhlfe_next = nhlfe->next; | |
1017 | if (CHECK_FLAG(nhlfe->flags, NHLFE_FLAG_DELETED)) | |
1018 | nhlfe_del(nhlfe); | |
1019 | } | |
40c7bdb0 | 1020 | |
d62a17ae | 1021 | if (!lsp->nhlfe_list) { |
1022 | if (IS_ZEBRA_DEBUG_MPLS) | |
1023 | zlog_debug("Free LSP in-label %u flags 0x%x", | |
1024 | lsp->ile.in_label, lsp->flags); | |
40c7bdb0 | 1025 | |
d62a17ae | 1026 | lsp = hash_release(lsp_table, &lsp->ile); |
1027 | if (lsp) | |
1028 | XFREE(MTYPE_LSP, lsp); | |
1029 | } | |
40c7bdb0 | 1030 | } |
1031 | ||
1032 | /* | |
1033 | * Callback upon finishing the processing of all scheduled | |
1034 | * LSP forwarding entries. | |
1035 | */ | |
d62a17ae | 1036 | static void lsp_processq_complete(struct work_queue *wq) |
40c7bdb0 | 1037 | { |
d62a17ae | 1038 | /* Nothing to do for now. */ |
40c7bdb0 | 1039 | } |
1040 | ||
1041 | /* | |
1042 | * Add LSP forwarding entry to queue for subsequent processing. | |
1043 | */ | |
d62a17ae | 1044 | static int lsp_processq_add(zebra_lsp_t *lsp) |
40c7bdb0 | 1045 | { |
d62a17ae | 1046 | /* If already scheduled, exit. */ |
1047 | if (CHECK_FLAG(lsp->flags, LSP_FLAG_SCHEDULED)) | |
1048 | return 0; | |
40c7bdb0 | 1049 | |
d62a17ae | 1050 | if (zebrad.lsp_process_q == NULL) { |
1051 | zlog_err("%s: work_queue does not exist!", __func__); | |
1052 | return -1; | |
1053 | } | |
33c32282 | 1054 | |
d62a17ae | 1055 | work_queue_add(zebrad.lsp_process_q, lsp); |
1056 | SET_FLAG(lsp->flags, LSP_FLAG_SCHEDULED); | |
1057 | return 0; | |
40c7bdb0 | 1058 | } |
1059 | ||
1060 | /* | |
1061 | * Callback to allocate LSP forwarding table entry. | |
1062 | */ | |
d62a17ae | 1063 | static void *lsp_alloc(void *p) |
40c7bdb0 | 1064 | { |
d62a17ae | 1065 | const zebra_ile_t *ile = p; |
1066 | zebra_lsp_t *lsp; | |
40c7bdb0 | 1067 | |
d62a17ae | 1068 | lsp = XCALLOC(MTYPE_LSP, sizeof(zebra_lsp_t)); |
1069 | lsp->ile = *ile; | |
40c7bdb0 | 1070 | |
d62a17ae | 1071 | if (IS_ZEBRA_DEBUG_MPLS) |
1072 | zlog_debug("Alloc LSP in-label %u", lsp->ile.in_label); | |
40c7bdb0 | 1073 | |
d62a17ae | 1074 | return ((void *)lsp); |
40c7bdb0 | 1075 | } |
1076 | ||
1077 | /* | |
1078 | * Create printable string for NHLFE entry. | |
1079 | */ | |
d62a17ae | 1080 | static char *nhlfe2str(zebra_nhlfe_t *nhlfe, char *buf, int size) |
40c7bdb0 | 1081 | { |
d62a17ae | 1082 | struct nexthop *nexthop; |
40c7bdb0 | 1083 | |
d62a17ae | 1084 | buf[0] = '\0'; |
1085 | nexthop = nhlfe->nexthop; | |
1086 | switch (nexthop->type) { | |
1087 | case NEXTHOP_TYPE_IPV4: | |
1088 | case NEXTHOP_TYPE_IPV4_IFINDEX: | |
1089 | inet_ntop(AF_INET, &nexthop->gate.ipv4, buf, size); | |
1090 | break; | |
1091 | case NEXTHOP_TYPE_IPV6: | |
1092 | inet_ntop(AF_INET6, &nexthop->gate.ipv6, buf, size); | |
1093 | break; | |
b9abd9ad DS |
1094 | case NEXTHOP_TYPE_IFINDEX: |
1095 | snprintf(buf, size, "Ifindex: %u", nexthop->ifindex); | |
d62a17ae | 1096 | default: |
1097 | break; | |
1098 | } | |
40c7bdb0 | 1099 | |
d62a17ae | 1100 | return buf; |
40c7bdb0 | 1101 | } |
1102 | ||
1103 | /* | |
1104 | * Check if NHLFE matches with search info passed. | |
1105 | */ | |
d62a17ae | 1106 | static int nhlfe_nhop_match(zebra_nhlfe_t *nhlfe, enum nexthop_types_t gtype, |
1107 | union g_addr *gate, ifindex_t ifindex) | |
40c7bdb0 | 1108 | { |
d62a17ae | 1109 | struct nexthop *nhop; |
1110 | int cmp = 1; | |
40c7bdb0 | 1111 | |
d62a17ae | 1112 | nhop = nhlfe->nexthop; |
1113 | if (!nhop) | |
1114 | return 1; | |
40c7bdb0 | 1115 | |
d62a17ae | 1116 | if (nhop->type != gtype) |
1117 | return 1; | |
40c7bdb0 | 1118 | |
d62a17ae | 1119 | switch (nhop->type) { |
1120 | case NEXTHOP_TYPE_IPV4: | |
1121 | case NEXTHOP_TYPE_IPV4_IFINDEX: | |
1122 | cmp = memcmp(&(nhop->gate.ipv4), &(gate->ipv4), | |
1123 | sizeof(struct in_addr)); | |
1124 | if (!cmp && nhop->type == NEXTHOP_TYPE_IPV4_IFINDEX) | |
1125 | cmp = !(nhop->ifindex == ifindex); | |
1126 | break; | |
1127 | case NEXTHOP_TYPE_IPV6: | |
1128 | case NEXTHOP_TYPE_IPV6_IFINDEX: | |
1129 | cmp = memcmp(&(nhop->gate.ipv6), &(gate->ipv6), | |
1130 | sizeof(struct in6_addr)); | |
1131 | if (!cmp && nhop->type == NEXTHOP_TYPE_IPV6_IFINDEX) | |
1132 | cmp = !(nhop->ifindex == ifindex); | |
1133 | break; | |
b9abd9ad DS |
1134 | case NEXTHOP_TYPE_IFINDEX: |
1135 | cmp = !(nhop->ifindex == ifindex); | |
1136 | break; | |
d62a17ae | 1137 | default: |
1138 | break; | |
1139 | } | |
40c7bdb0 | 1140 | |
d62a17ae | 1141 | return cmp; |
40c7bdb0 | 1142 | } |
1143 | ||
1144 | ||
1145 | /* | |
1146 | * Locate NHLFE that matches with passed info. | |
1147 | */ | |
d62a17ae | 1148 | static zebra_nhlfe_t *nhlfe_find(zebra_lsp_t *lsp, enum lsp_types_t lsp_type, |
1149 | enum nexthop_types_t gtype, union g_addr *gate, | |
1150 | ifindex_t ifindex) | |
40c7bdb0 | 1151 | { |
d62a17ae | 1152 | zebra_nhlfe_t *nhlfe; |
40c7bdb0 | 1153 | |
d62a17ae | 1154 | if (!lsp) |
1155 | return NULL; | |
40c7bdb0 | 1156 | |
d62a17ae | 1157 | for (nhlfe = lsp->nhlfe_list; nhlfe; nhlfe = nhlfe->next) { |
1158 | if (nhlfe->type != lsp_type) | |
1159 | continue; | |
1160 | if (!nhlfe_nhop_match(nhlfe, gtype, gate, ifindex)) | |
1161 | break; | |
1162 | } | |
40c7bdb0 | 1163 | |
d62a17ae | 1164 | return nhlfe; |
40c7bdb0 | 1165 | } |
1166 | ||
1167 | /* | |
1168 | * Add NHLFE. Base entry must have been created and duplicate | |
1169 | * check done. | |
1170 | */ | |
d62a17ae | 1171 | static zebra_nhlfe_t *nhlfe_add(zebra_lsp_t *lsp, enum lsp_types_t lsp_type, |
1172 | enum nexthop_types_t gtype, union g_addr *gate, | |
1173 | ifindex_t ifindex, mpls_label_t out_label) | |
1174 | { | |
1175 | zebra_nhlfe_t *nhlfe; | |
1176 | struct nexthop *nexthop; | |
1177 | ||
1178 | if (!lsp) | |
1179 | return NULL; | |
1180 | ||
1181 | nhlfe = XCALLOC(MTYPE_NHLFE, sizeof(zebra_nhlfe_t)); | |
d62a17ae | 1182 | |
1183 | nhlfe->lsp = lsp; | |
1184 | nhlfe->type = lsp_type; | |
1185 | nhlfe->distance = lsp_distance(lsp_type); | |
1186 | ||
1187 | nexthop = nexthop_new(); | |
1188 | if (!nexthop) { | |
1189 | XFREE(MTYPE_NHLFE, nhlfe); | |
1190 | return NULL; | |
1191 | } | |
1192 | nexthop_add_labels(nexthop, lsp_type, 1, &out_label); | |
1193 | ||
4a7371e9 | 1194 | nexthop->vrf_id = VRF_DEFAULT; |
d62a17ae | 1195 | nexthop->type = gtype; |
1196 | switch (nexthop->type) { | |
1197 | case NEXTHOP_TYPE_IPV4: | |
1198 | case NEXTHOP_TYPE_IPV4_IFINDEX: | |
1199 | nexthop->gate.ipv4 = gate->ipv4; | |
1200 | if (ifindex) | |
1201 | nexthop->ifindex = ifindex; | |
1202 | break; | |
1203 | case NEXTHOP_TYPE_IPV6: | |
1204 | case NEXTHOP_TYPE_IPV6_IFINDEX: | |
1205 | nexthop->gate.ipv6 = gate->ipv6; | |
1206 | if (ifindex) | |
1207 | nexthop->ifindex = ifindex; | |
1208 | break; | |
b9abd9ad DS |
1209 | case NEXTHOP_TYPE_IFINDEX: |
1210 | nexthop->ifindex = ifindex; | |
1211 | break; | |
d62a17ae | 1212 | default: |
1213 | nexthop_free(nexthop); | |
1214 | XFREE(MTYPE_NHLFE, nhlfe); | |
1215 | return NULL; | |
1216 | break; | |
1217 | } | |
1218 | ||
1219 | nhlfe->nexthop = nexthop; | |
1220 | if (lsp->nhlfe_list) | |
1221 | lsp->nhlfe_list->prev = nhlfe; | |
1222 | nhlfe->next = lsp->nhlfe_list; | |
1223 | lsp->nhlfe_list = nhlfe; | |
1224 | ||
1225 | return nhlfe; | |
40c7bdb0 | 1226 | } |
1227 | ||
1228 | /* | |
1229 | * Delete NHLFE. Entry must be present on list. | |
1230 | */ | |
d62a17ae | 1231 | static int nhlfe_del(zebra_nhlfe_t *nhlfe) |
40c7bdb0 | 1232 | { |
d62a17ae | 1233 | zebra_lsp_t *lsp; |
40c7bdb0 | 1234 | |
d62a17ae | 1235 | if (!nhlfe) |
1236 | return -1; | |
40c7bdb0 | 1237 | |
d62a17ae | 1238 | lsp = nhlfe->lsp; |
1239 | if (!lsp) | |
1240 | return -1; | |
40c7bdb0 | 1241 | |
d62a17ae | 1242 | /* Free nexthop. */ |
1243 | if (nhlfe->nexthop) | |
1244 | nexthop_free(nhlfe->nexthop); | |
40c7bdb0 | 1245 | |
d62a17ae | 1246 | /* Unlink from LSP */ |
1247 | if (nhlfe->next) | |
1248 | nhlfe->next->prev = nhlfe->prev; | |
1249 | if (nhlfe->prev) | |
1250 | nhlfe->prev->next = nhlfe->next; | |
1251 | else | |
1252 | lsp->nhlfe_list = nhlfe->next; | |
40c7bdb0 | 1253 | |
d62a17ae | 1254 | if (nhlfe == lsp->best_nhlfe) |
1255 | lsp->best_nhlfe = NULL; | |
bb49a121 | 1256 | |
d62a17ae | 1257 | XFREE(MTYPE_NHLFE, nhlfe); |
40c7bdb0 | 1258 | |
d62a17ae | 1259 | return 0; |
40c7bdb0 | 1260 | } |
1261 | ||
a64448ba DS |
1262 | /* |
1263 | * Update label for NHLFE entry. | |
1264 | */ | |
d62a17ae | 1265 | static void nhlfe_out_label_update(zebra_nhlfe_t *nhlfe, |
8ecdb26e | 1266 | struct mpls_label_stack *nh_label) |
d62a17ae | 1267 | { |
1268 | nhlfe->nexthop->nh_label->label[0] = nh_label->label[0]; | |
1269 | } | |
1270 | ||
1271 | static int mpls_lsp_uninstall_all(struct hash *lsp_table, zebra_lsp_t *lsp, | |
1272 | enum lsp_types_t type) | |
1273 | { | |
1274 | zebra_nhlfe_t *nhlfe, *nhlfe_next; | |
1275 | int schedule_lsp = 0; | |
1276 | char buf[BUFSIZ]; | |
1277 | ||
1278 | /* Mark NHLFEs for delete or directly delete, as appropriate. */ | |
1279 | for (nhlfe = lsp->nhlfe_list; nhlfe; nhlfe = nhlfe_next) { | |
1280 | nhlfe_next = nhlfe->next; | |
1281 | ||
1282 | /* Skip non-static NHLFEs */ | |
1283 | if (nhlfe->type != type) | |
1284 | continue; | |
1285 | ||
1286 | if (IS_ZEBRA_DEBUG_MPLS) { | |
1287 | nhlfe2str(nhlfe, buf, BUFSIZ); | |
1288 | zlog_debug( | |
1289 | "Del LSP in-label %u type %d nexthop %s flags 0x%x", | |
1290 | lsp->ile.in_label, type, buf, nhlfe->flags); | |
1291 | } | |
1292 | ||
1293 | if (CHECK_FLAG(nhlfe->flags, NHLFE_FLAG_INSTALLED)) { | |
1294 | UNSET_FLAG(nhlfe->flags, NHLFE_FLAG_CHANGED); | |
1295 | SET_FLAG(nhlfe->flags, NHLFE_FLAG_DELETED); | |
1296 | schedule_lsp = 1; | |
1297 | } else { | |
1298 | nhlfe_del(nhlfe); | |
1299 | } | |
1300 | } | |
1301 | ||
1302 | /* Queue LSP for processing, if needed, else delete. */ | |
1303 | if (schedule_lsp) { | |
1304 | if (lsp_processq_add(lsp)) | |
1305 | return -1; | |
1306 | } else if (!lsp->nhlfe_list | |
1307 | && !CHECK_FLAG(lsp->flags, LSP_FLAG_SCHEDULED)) { | |
1308 | if (IS_ZEBRA_DEBUG_MPLS) | |
1309 | zlog_debug("Free LSP in-label %u flags 0x%x", | |
1310 | lsp->ile.in_label, lsp->flags); | |
1311 | ||
1312 | lsp = hash_release(lsp_table, &lsp->ile); | |
1313 | if (lsp) | |
1314 | XFREE(MTYPE_LSP, lsp); | |
1315 | } | |
1316 | ||
1317 | return 0; | |
40c7bdb0 | 1318 | } |
1319 | ||
ce549947 RW |
1320 | /* |
1321 | * Uninstall all static NHLFEs for a particular LSP forwarding entry. | |
1322 | * If no other NHLFEs exist, the entry would be deleted. | |
1323 | */ | |
d62a17ae | 1324 | static int mpls_static_lsp_uninstall_all(struct zebra_vrf *zvrf, |
1325 | mpls_label_t in_label) | |
ce549947 | 1326 | { |
d62a17ae | 1327 | struct hash *lsp_table; |
1328 | zebra_ile_t tmp_ile; | |
1329 | zebra_lsp_t *lsp; | |
ce549947 | 1330 | |
d62a17ae | 1331 | /* Lookup table. */ |
1332 | lsp_table = zvrf->lsp_table; | |
1333 | if (!lsp_table) | |
1334 | return -1; | |
ce549947 | 1335 | |
d62a17ae | 1336 | /* If entry is not present, exit. */ |
1337 | tmp_ile.in_label = in_label; | |
1338 | lsp = hash_lookup(lsp_table, &tmp_ile); | |
1339 | if (!lsp || !lsp->nhlfe_list) | |
1340 | return 0; | |
ce549947 | 1341 | |
d62a17ae | 1342 | return mpls_lsp_uninstall_all(lsp_table, lsp, ZEBRA_LSP_STATIC); |
ce549947 RW |
1343 | } |
1344 | ||
d62a17ae | 1345 | static json_object *nhlfe_json(zebra_nhlfe_t *nhlfe) |
b78b820d | 1346 | { |
d62a17ae | 1347 | char buf[BUFSIZ]; |
1348 | json_object *json_nhlfe = NULL; | |
1349 | struct nexthop *nexthop = nhlfe->nexthop; | |
b78b820d | 1350 | |
d62a17ae | 1351 | json_nhlfe = json_object_new_object(); |
1352 | json_object_string_add(json_nhlfe, "type", nhlfe_type2str(nhlfe->type)); | |
1353 | json_object_int_add(json_nhlfe, "outLabel", | |
1354 | nexthop->nh_label->label[0]); | |
1355 | json_object_int_add(json_nhlfe, "distance", nhlfe->distance); | |
b78b820d | 1356 | |
d62a17ae | 1357 | if (CHECK_FLAG(nhlfe->flags, NHLFE_FLAG_INSTALLED)) |
1358 | json_object_boolean_true_add(json_nhlfe, "installed"); | |
b78b820d | 1359 | |
d62a17ae | 1360 | switch (nexthop->type) { |
1361 | case NEXTHOP_TYPE_IPV4: | |
1362 | case NEXTHOP_TYPE_IPV4_IFINDEX: | |
1363 | json_object_string_add(json_nhlfe, "nexthop", | |
1364 | inet_ntoa(nexthop->gate.ipv4)); | |
1365 | break; | |
1366 | case NEXTHOP_TYPE_IPV6: | |
1367 | case NEXTHOP_TYPE_IPV6_IFINDEX: | |
1368 | json_object_string_add( | |
1369 | json_nhlfe, "nexthop", | |
1370 | inet_ntop(AF_INET6, &nexthop->gate.ipv6, buf, BUFSIZ)); | |
1371 | ||
1372 | if (nexthop->ifindex) | |
4a7371e9 DS |
1373 | json_object_string_add(json_nhlfe, "interface", |
1374 | ifindex2ifname(nexthop->ifindex, | |
1375 | nexthop->vrf_id)); | |
d62a17ae | 1376 | break; |
1377 | default: | |
1378 | break; | |
1379 | } | |
1380 | return json_nhlfe; | |
b78b820d | 1381 | } |
1382 | ||
3ab18ff2 | 1383 | /* |
1384 | * Print the NHLFE for a LSP forwarding entry. | |
1385 | */ | |
d62a17ae | 1386 | static void nhlfe_print(zebra_nhlfe_t *nhlfe, struct vty *vty) |
1387 | { | |
1388 | struct nexthop *nexthop; | |
1389 | char buf[BUFSIZ]; | |
1390 | ||
1391 | nexthop = nhlfe->nexthop; | |
1392 | if (!nexthop || !nexthop->nh_label) // unexpected | |
1393 | return; | |
1394 | ||
1395 | vty_out(vty, " type: %s remote label: %s distance: %d\n", | |
1396 | nhlfe_type2str(nhlfe->type), | |
1397 | label2str(nexthop->nh_label->label[0], buf, BUFSIZ), | |
1398 | nhlfe->distance); | |
1399 | switch (nexthop->type) { | |
1400 | case NEXTHOP_TYPE_IPV4: | |
1401 | case NEXTHOP_TYPE_IPV4_IFINDEX: | |
1402 | vty_out(vty, " via %s", inet_ntoa(nexthop->gate.ipv4)); | |
1403 | if (nexthop->ifindex) | |
1404 | vty_out(vty, " dev %s", | |
4a7371e9 DS |
1405 | ifindex2ifname(nexthop->ifindex, |
1406 | nexthop->vrf_id)); | |
d62a17ae | 1407 | break; |
1408 | case NEXTHOP_TYPE_IPV6: | |
1409 | case NEXTHOP_TYPE_IPV6_IFINDEX: | |
1410 | vty_out(vty, " via %s", | |
1411 | inet_ntop(AF_INET6, &nexthop->gate.ipv6, buf, BUFSIZ)); | |
1412 | if (nexthop->ifindex) | |
1413 | vty_out(vty, " dev %s", | |
4a7371e9 DS |
1414 | ifindex2ifname(nexthop->ifindex, |
1415 | nexthop->vrf_id)); | |
d62a17ae | 1416 | break; |
1417 | default: | |
1418 | break; | |
1419 | } | |
996c9314 LB |
1420 | vty_out(vty, "%s", |
1421 | CHECK_FLAG(nhlfe->flags, NHLFE_FLAG_INSTALLED) ? " (installed)" | |
1422 | : ""); | |
d62a17ae | 1423 | vty_out(vty, "\n"); |
3ab18ff2 | 1424 | } |
1425 | ||
1426 | /* | |
1427 | * Print an LSP forwarding entry. | |
1428 | */ | |
d62a17ae | 1429 | static void lsp_print(zebra_lsp_t *lsp, void *ctxt) |
3ab18ff2 | 1430 | { |
d62a17ae | 1431 | zebra_nhlfe_t *nhlfe; |
1432 | struct vty *vty; | |
3ab18ff2 | 1433 | |
d62a17ae | 1434 | vty = (struct vty *)ctxt; |
3ab18ff2 | 1435 | |
d62a17ae | 1436 | vty_out(vty, "Local label: %u%s\n", lsp->ile.in_label, |
1437 | CHECK_FLAG(lsp->flags, LSP_FLAG_INSTALLED) ? " (installed)" | |
1438 | : ""); | |
3ab18ff2 | 1439 | |
d62a17ae | 1440 | for (nhlfe = lsp->nhlfe_list; nhlfe; nhlfe = nhlfe->next) |
1441 | nhlfe_print(nhlfe, vty); | |
3ab18ff2 | 1442 | } |
1443 | ||
1444 | /* | |
b78b820d | 1445 | * JSON objects for an LSP forwarding entry. |
3ab18ff2 | 1446 | */ |
d62a17ae | 1447 | static json_object *lsp_json(zebra_lsp_t *lsp) |
3ab18ff2 | 1448 | { |
d62a17ae | 1449 | zebra_nhlfe_t *nhlfe = NULL; |
1450 | json_object *json = json_object_new_object(); | |
1451 | json_object *json_nhlfe_list = json_object_new_array(); | |
3ab18ff2 | 1452 | |
d62a17ae | 1453 | json_object_int_add(json, "inLabel", lsp->ile.in_label); |
b78b820d | 1454 | |
d62a17ae | 1455 | if (CHECK_FLAG(lsp->flags, LSP_FLAG_INSTALLED)) |
1456 | json_object_boolean_true_add(json, "installed"); | |
3ab18ff2 | 1457 | |
d62a17ae | 1458 | for (nhlfe = lsp->nhlfe_list; nhlfe; nhlfe = nhlfe->next) |
1459 | json_object_array_add(json_nhlfe_list, nhlfe_json(nhlfe)); | |
b78b820d | 1460 | |
d62a17ae | 1461 | json_object_object_add(json, "nexthops", json_nhlfe_list); |
1462 | return json; | |
b78b820d | 1463 | } |
1464 | ||
1465 | ||
1466 | /* Return a sorted linked list of the hash contents */ | |
d62a17ae | 1467 | static struct list *hash_get_sorted_list(struct hash *hash, void *cmp) |
b78b820d | 1468 | { |
d62a17ae | 1469 | unsigned int i; |
1470 | struct hash_backet *hb; | |
1471 | struct list *sorted_list = list_new(); | |
b78b820d | 1472 | |
d62a17ae | 1473 | sorted_list->cmp = (int (*)(void *, void *))cmp; |
b78b820d | 1474 | |
d62a17ae | 1475 | for (i = 0; i < hash->size; i++) |
1476 | for (hb = hash->index[i]; hb; hb = hb->next) | |
1477 | listnode_add_sort(sorted_list, hb->data); | |
b78b820d | 1478 | |
d62a17ae | 1479 | return sorted_list; |
3ab18ff2 | 1480 | } |
1481 | ||
7758e3f3 | 1482 | /* |
b78b820d | 1483 | * Compare two LSPs based on their label values. |
7758e3f3 | 1484 | */ |
d62a17ae | 1485 | static int lsp_cmp(zebra_lsp_t *lsp1, zebra_lsp_t *lsp2) |
7758e3f3 | 1486 | { |
d62a17ae | 1487 | if (lsp1->ile.in_label < lsp2->ile.in_label) |
1488 | return -1; | |
7758e3f3 | 1489 | |
d62a17ae | 1490 | if (lsp1->ile.in_label > lsp2->ile.in_label) |
1491 | return 1; | |
7758e3f3 | 1492 | |
d62a17ae | 1493 | return 0; |
7758e3f3 | 1494 | } |
1495 | ||
1496 | /* | |
1497 | * Callback to allocate static LSP. | |
1498 | */ | |
d62a17ae | 1499 | static void *slsp_alloc(void *p) |
7758e3f3 | 1500 | { |
d62a17ae | 1501 | const zebra_ile_t *ile = p; |
1502 | zebra_slsp_t *slsp; | |
7758e3f3 | 1503 | |
d62a17ae | 1504 | slsp = XCALLOC(MTYPE_SLSP, sizeof(zebra_slsp_t)); |
1505 | slsp->ile = *ile; | |
1506 | return ((void *)slsp); | |
7758e3f3 | 1507 | } |
1508 | ||
b78b820d | 1509 | /* |
1510 | * Compare two static LSPs based on their label values. | |
1511 | */ | |
d62a17ae | 1512 | static int slsp_cmp(zebra_slsp_t *slsp1, zebra_slsp_t *slsp2) |
b78b820d | 1513 | { |
d62a17ae | 1514 | if (slsp1->ile.in_label < slsp2->ile.in_label) |
1515 | return -1; | |
b78b820d | 1516 | |
d62a17ae | 1517 | if (slsp1->ile.in_label > slsp2->ile.in_label) |
1518 | return 1; | |
b78b820d | 1519 | |
d62a17ae | 1520 | return 0; |
b78b820d | 1521 | } |
1522 | ||
7758e3f3 | 1523 | /* |
1524 | * Check if static NHLFE matches with search info passed. | |
1525 | */ | |
d62a17ae | 1526 | static int snhlfe_match(zebra_snhlfe_t *snhlfe, enum nexthop_types_t gtype, |
1527 | union g_addr *gate, ifindex_t ifindex) | |
7758e3f3 | 1528 | { |
d62a17ae | 1529 | int cmp = 1; |
7758e3f3 | 1530 | |
d62a17ae | 1531 | if (snhlfe->gtype != gtype) |
1532 | return 1; | |
7758e3f3 | 1533 | |
d62a17ae | 1534 | switch (snhlfe->gtype) { |
1535 | case NEXTHOP_TYPE_IPV4: | |
1536 | cmp = memcmp(&(snhlfe->gate.ipv4), &(gate->ipv4), | |
1537 | sizeof(struct in_addr)); | |
1538 | break; | |
1539 | case NEXTHOP_TYPE_IPV6: | |
1540 | case NEXTHOP_TYPE_IPV6_IFINDEX: | |
1541 | cmp = memcmp(&(snhlfe->gate.ipv6), &(gate->ipv6), | |
1542 | sizeof(struct in6_addr)); | |
1543 | if (!cmp && snhlfe->gtype == NEXTHOP_TYPE_IPV6_IFINDEX) | |
1544 | cmp = !(snhlfe->ifindex == ifindex); | |
1545 | break; | |
1546 | default: | |
1547 | break; | |
1548 | } | |
7758e3f3 | 1549 | |
d62a17ae | 1550 | return cmp; |
7758e3f3 | 1551 | } |
1552 | ||
1553 | /* | |
1554 | * Locate static NHLFE that matches with passed info. | |
1555 | */ | |
d62a17ae | 1556 | static zebra_snhlfe_t *snhlfe_find(zebra_slsp_t *slsp, |
1557 | enum nexthop_types_t gtype, | |
1558 | union g_addr *gate, ifindex_t ifindex) | |
7758e3f3 | 1559 | { |
d62a17ae | 1560 | zebra_snhlfe_t *snhlfe; |
7758e3f3 | 1561 | |
d62a17ae | 1562 | if (!slsp) |
1563 | return NULL; | |
7758e3f3 | 1564 | |
d62a17ae | 1565 | for (snhlfe = slsp->snhlfe_list; snhlfe; snhlfe = snhlfe->next) { |
1566 | if (!snhlfe_match(snhlfe, gtype, gate, ifindex)) | |
1567 | break; | |
1568 | } | |
7758e3f3 | 1569 | |
d62a17ae | 1570 | return snhlfe; |
7758e3f3 | 1571 | } |
1572 | ||
1573 | ||
1574 | /* | |
1575 | * Add static NHLFE. Base LSP config entry must have been created | |
1576 | * and duplicate check done. | |
1577 | */ | |
d62a17ae | 1578 | static zebra_snhlfe_t *snhlfe_add(zebra_slsp_t *slsp, |
1579 | enum nexthop_types_t gtype, | |
1580 | union g_addr *gate, ifindex_t ifindex, | |
1581 | mpls_label_t out_label) | |
1582 | { | |
1583 | zebra_snhlfe_t *snhlfe; | |
1584 | ||
1585 | if (!slsp) | |
1586 | return NULL; | |
1587 | ||
1588 | snhlfe = XCALLOC(MTYPE_SNHLFE, sizeof(zebra_snhlfe_t)); | |
1589 | snhlfe->slsp = slsp; | |
1590 | snhlfe->out_label = out_label; | |
1591 | snhlfe->gtype = gtype; | |
1592 | switch (gtype) { | |
1593 | case NEXTHOP_TYPE_IPV4: | |
1594 | snhlfe->gate.ipv4 = gate->ipv4; | |
1595 | break; | |
1596 | case NEXTHOP_TYPE_IPV6: | |
1597 | case NEXTHOP_TYPE_IPV6_IFINDEX: | |
1598 | snhlfe->gate.ipv6 = gate->ipv6; | |
1599 | if (ifindex) | |
1600 | snhlfe->ifindex = ifindex; | |
1601 | break; | |
1602 | default: | |
1603 | XFREE(MTYPE_SNHLFE, snhlfe); | |
1604 | return NULL; | |
1605 | } | |
1606 | ||
1607 | if (slsp->snhlfe_list) | |
1608 | slsp->snhlfe_list->prev = snhlfe; | |
1609 | snhlfe->next = slsp->snhlfe_list; | |
1610 | slsp->snhlfe_list = snhlfe; | |
1611 | ||
1612 | return snhlfe; | |
7758e3f3 | 1613 | } |
1614 | ||
1615 | /* | |
1616 | * Delete static NHLFE. Entry must be present on list. | |
1617 | */ | |
d62a17ae | 1618 | static int snhlfe_del(zebra_snhlfe_t *snhlfe) |
7758e3f3 | 1619 | { |
d62a17ae | 1620 | zebra_slsp_t *slsp; |
7758e3f3 | 1621 | |
d62a17ae | 1622 | if (!snhlfe) |
1623 | return -1; | |
7758e3f3 | 1624 | |
d62a17ae | 1625 | slsp = snhlfe->slsp; |
1626 | if (!slsp) | |
1627 | return -1; | |
7758e3f3 | 1628 | |
d62a17ae | 1629 | if (snhlfe->next) |
1630 | snhlfe->next->prev = snhlfe->prev; | |
1631 | if (snhlfe->prev) | |
1632 | snhlfe->prev->next = snhlfe->next; | |
1633 | else | |
1634 | slsp->snhlfe_list = snhlfe->next; | |
7758e3f3 | 1635 | |
d62a17ae | 1636 | snhlfe->prev = snhlfe->next = NULL; |
1637 | if (snhlfe->ifname) | |
1638 | XFREE(MTYPE_SNHLFE_IFNAME, snhlfe->ifname); | |
1639 | XFREE(MTYPE_SNHLFE, snhlfe); | |
7758e3f3 | 1640 | |
d62a17ae | 1641 | return 0; |
7758e3f3 | 1642 | } |
1643 | ||
1644 | /* | |
1645 | * Delete all static NHLFE entries for this LSP (in label). | |
1646 | */ | |
d62a17ae | 1647 | static int snhlfe_del_all(zebra_slsp_t *slsp) |
7758e3f3 | 1648 | { |
d62a17ae | 1649 | zebra_snhlfe_t *snhlfe, *snhlfe_next; |
7758e3f3 | 1650 | |
d62a17ae | 1651 | if (!slsp) |
1652 | return -1; | |
7758e3f3 | 1653 | |
d62a17ae | 1654 | for (snhlfe = slsp->snhlfe_list; snhlfe; snhlfe = snhlfe_next) { |
1655 | snhlfe_next = snhlfe->next; | |
1656 | snhlfe_del(snhlfe); | |
1657 | } | |
7758e3f3 | 1658 | |
d62a17ae | 1659 | return 0; |
7758e3f3 | 1660 | } |
1661 | ||
1662 | /* | |
1663 | * Create printable string for NHLFE configuration. | |
1664 | */ | |
d62a17ae | 1665 | static char *snhlfe2str(zebra_snhlfe_t *snhlfe, char *buf, int size) |
7758e3f3 | 1666 | { |
d62a17ae | 1667 | buf[0] = '\0'; |
1668 | switch (snhlfe->gtype) { | |
1669 | case NEXTHOP_TYPE_IPV4: | |
1670 | inet_ntop(AF_INET, &snhlfe->gate.ipv4, buf, size); | |
1671 | break; | |
1672 | case NEXTHOP_TYPE_IPV6: | |
1673 | case NEXTHOP_TYPE_IPV6_IFINDEX: | |
1674 | inet_ntop(AF_INET6, &snhlfe->gate.ipv6, buf, size); | |
1675 | if (snhlfe->ifindex) | |
1676 | strcat(buf, | |
1677 | ifindex2ifname(snhlfe->ifindex, VRF_DEFAULT)); | |
1678 | break; | |
1679 | default: | |
1680 | break; | |
1681 | } | |
7758e3f3 | 1682 | |
d62a17ae | 1683 | return buf; |
7758e3f3 | 1684 | } |
1685 | ||
40c7bdb0 | 1686 | /* |
1687 | * Initialize work queue for processing changed LSPs. | |
1688 | */ | |
d62a17ae | 1689 | static int mpls_processq_init(struct zebra_t *zebra) |
40c7bdb0 | 1690 | { |
d62a17ae | 1691 | zebra->lsp_process_q = work_queue_new(zebra->master, "LSP processing"); |
1692 | if (!zebra->lsp_process_q) { | |
1693 | zlog_err("%s: could not initialise work queue!", __func__); | |
1694 | return -1; | |
1695 | } | |
40c7bdb0 | 1696 | |
d62a17ae | 1697 | zebra->lsp_process_q->spec.workfunc = &lsp_process; |
1698 | zebra->lsp_process_q->spec.del_item_data = &lsp_processq_del; | |
1699 | zebra->lsp_process_q->spec.errorfunc = NULL; | |
1700 | zebra->lsp_process_q->spec.completion_func = &lsp_processq_complete; | |
1701 | zebra->lsp_process_q->spec.max_retries = 0; | |
1702 | zebra->lsp_process_q->spec.hold = 10; | |
33c32282 | 1703 | |
d62a17ae | 1704 | return 0; |
40c7bdb0 | 1705 | } |
1706 | ||
7758e3f3 | 1707 | |
7758e3f3 | 1708 | /* Public functions */ |
1709 | ||
215181cb | 1710 | void kernel_lsp_pass_fail(zebra_lsp_t *lsp, enum dp_results res) |
4a83e7a0 DS |
1711 | { |
1712 | struct nexthop *nexthop; | |
1713 | zebra_nhlfe_t *nhlfe; | |
1714 | ||
1715 | if (!lsp) | |
1716 | return; | |
1717 | ||
1718 | switch (res) { | |
215181cb | 1719 | case DP_INSTALL_FAILURE: |
4a83e7a0 DS |
1720 | UNSET_FLAG(lsp->flags, LSP_FLAG_INSTALLED); |
1721 | clear_nhlfe_installed(lsp); | |
1722 | zlog_warn("LSP Install Failure: %u", lsp->ile.in_label); | |
1723 | break; | |
215181cb | 1724 | case DP_INSTALL_SUCCESS: |
4a83e7a0 DS |
1725 | SET_FLAG(lsp->flags, LSP_FLAG_INSTALLED); |
1726 | for (nhlfe = lsp->nhlfe_list; nhlfe; nhlfe = nhlfe->next) { | |
1727 | nexthop = nhlfe->nexthop; | |
1728 | if (!nexthop) | |
1729 | continue; | |
1730 | ||
1731 | SET_FLAG(nhlfe->flags, NHLFE_FLAG_INSTALLED); | |
1732 | SET_FLAG(nexthop->flags, NEXTHOP_FLAG_FIB); | |
1733 | } | |
1734 | break; | |
215181cb | 1735 | case DP_DELETE_SUCCESS: |
4a83e7a0 DS |
1736 | UNSET_FLAG(lsp->flags, LSP_FLAG_INSTALLED); |
1737 | clear_nhlfe_installed(lsp); | |
1738 | break; | |
215181cb | 1739 | case DP_DELETE_FAILURE: |
4a83e7a0 DS |
1740 | zlog_warn("LSP Deletion Failure: %u", lsp->ile.in_label); |
1741 | break; | |
1742 | } | |
1743 | } | |
1744 | ||
a64448ba DS |
1745 | /* |
1746 | * Install dynamic LSP entry. | |
1747 | */ | |
d62a17ae | 1748 | int zebra_mpls_lsp_install(struct zebra_vrf *zvrf, struct route_node *rn, |
1749 | struct route_entry *re) | |
a64448ba | 1750 | { |
d62a17ae | 1751 | struct route_table *table; |
1752 | zebra_fec_t *fec; | |
a64448ba | 1753 | |
d62a17ae | 1754 | table = zvrf->fec_table[family2afi(PREFIX_FAMILY(&rn->p))]; |
1755 | if (!table) | |
1756 | return -1; | |
a64448ba | 1757 | |
d62a17ae | 1758 | /* See if there is a configured label binding for this FEC. */ |
1759 | fec = fec_find(table, &rn->p); | |
1760 | if (!fec || fec->label == MPLS_INVALID_LABEL) | |
1761 | return 0; | |
a64448ba | 1762 | |
d62a17ae | 1763 | /* We cannot install a label forwarding entry if local label is the |
1764 | * implicit-null label. | |
1765 | */ | |
70e98a7f | 1766 | if (fec->label == MPLS_LABEL_IMPLICIT_NULL) |
d62a17ae | 1767 | return 0; |
a64448ba | 1768 | |
d62a17ae | 1769 | if (lsp_install(zvrf, fec->label, rn, re)) |
1770 | return -1; | |
a64448ba | 1771 | |
d62a17ae | 1772 | return 0; |
a64448ba DS |
1773 | } |
1774 | ||
1775 | /* | |
1776 | * Uninstall dynamic LSP entry, if any. | |
1777 | */ | |
d62a17ae | 1778 | int zebra_mpls_lsp_uninstall(struct zebra_vrf *zvrf, struct route_node *rn, |
1779 | struct route_entry *re) | |
a64448ba | 1780 | { |
d62a17ae | 1781 | struct route_table *table; |
1782 | zebra_fec_t *fec; | |
a64448ba | 1783 | |
d62a17ae | 1784 | table = zvrf->fec_table[family2afi(PREFIX_FAMILY(&rn->p))]; |
1785 | if (!table) | |
1786 | return -1; | |
a64448ba | 1787 | |
d62a17ae | 1788 | /* See if there is a configured label binding for this FEC. */ |
1789 | fec = fec_find(table, &rn->p); | |
1790 | if (!fec || fec->label == MPLS_INVALID_LABEL) | |
1791 | return 0; | |
a64448ba | 1792 | |
d62a17ae | 1793 | /* Uninstall always removes all dynamic NHLFEs. */ |
1794 | return lsp_uninstall(zvrf, fec->label); | |
a64448ba DS |
1795 | } |
1796 | ||
5aba114a DS |
1797 | /* |
1798 | * Registration from a client for the label binding for a FEC. If a binding | |
1799 | * already exists, it is informed to the client. | |
28d58fd7 | 1800 | * NOTE: If there is a manually configured label binding, that is used. |
9bedbb1e | 1801 | * Otherwise, if a label index is specified, it means we have to allocate the |
28d58fd7 VV |
1802 | * label from a locally configured label block (SRGB), if one exists and index |
1803 | * is acceptable. | |
5aba114a | 1804 | */ |
d62a17ae | 1805 | int zebra_mpls_fec_register(struct zebra_vrf *zvrf, struct prefix *p, |
d7c0a89a | 1806 | uint32_t label_index, struct zserv *client) |
d62a17ae | 1807 | { |
1808 | struct route_table *table; | |
1809 | zebra_fec_t *fec; | |
1810 | char buf[BUFSIZ]; | |
1811 | int new_client; | |
1812 | int label_change = 0; | |
d7c0a89a | 1813 | uint32_t old_label; |
d62a17ae | 1814 | |
1815 | table = zvrf->fec_table[family2afi(PREFIX_FAMILY(p))]; | |
1816 | if (!table) | |
1817 | return -1; | |
1818 | ||
1819 | if (IS_ZEBRA_DEBUG_MPLS) | |
1820 | prefix2str(p, buf, BUFSIZ); | |
1821 | ||
1822 | /* Locate FEC */ | |
1823 | fec = fec_find(table, p); | |
1824 | if (!fec) { | |
1825 | fec = fec_add(table, p, MPLS_INVALID_LABEL, 0, label_index); | |
1826 | if (!fec) { | |
1827 | prefix2str(p, buf, BUFSIZ); | |
1828 | zlog_err( | |
1829 | "Failed to add FEC %s upon register, client %s", | |
1830 | buf, zebra_route_string(client->proto)); | |
1831 | return -1; | |
1832 | } | |
1833 | ||
1834 | old_label = MPLS_INVALID_LABEL; | |
1835 | new_client = 1; | |
1836 | } else { | |
1837 | /* Client may register same FEC with different label index. */ | |
1838 | new_client = | |
1839 | (listnode_lookup(fec->client_list, client) == NULL); | |
1840 | if (!new_client && fec->label_index == label_index) | |
1841 | /* Duplicate register */ | |
1842 | return 0; | |
1843 | ||
1844 | /* Save current label, update label index */ | |
1845 | old_label = fec->label; | |
1846 | fec->label_index = label_index; | |
1847 | } | |
1848 | ||
1849 | if (new_client) | |
1850 | listnode_add(fec->client_list, client); | |
1851 | ||
1852 | if (IS_ZEBRA_DEBUG_MPLS) | |
1853 | zlog_debug("FEC %s Label Index %u %s by client %s", buf, | |
1854 | label_index, new_client ? "registered" : "updated", | |
1855 | zebra_route_string(client->proto)); | |
1856 | ||
1857 | /* If not a configured FEC, derive the local label (from label index) | |
1858 | * or reset it. | |
1859 | */ | |
1860 | if (!(fec->flags & FEC_FLAG_CONFIGURED)) { | |
1861 | fec_derive_label_from_index(zvrf, fec); | |
1862 | ||
1863 | /* If no label change, exit. */ | |
1864 | if (fec->label == old_label) | |
1865 | return 0; | |
1866 | ||
1867 | label_change = 1; | |
1868 | } | |
1869 | ||
1870 | /* If new client or label change, update client and install or uninstall | |
1871 | * label forwarding entry as needed. | |
1872 | */ | |
1873 | /* Inform client of label, if needed. */ | |
1874 | if ((new_client && fec->label != MPLS_INVALID_LABEL) || label_change) { | |
1875 | if (IS_ZEBRA_DEBUG_MPLS) | |
1876 | zlog_debug("Update client label %u", fec->label); | |
1877 | fec_send(fec, client); | |
1878 | } | |
1879 | ||
1880 | if (new_client || label_change) | |
1881 | return fec_change_update_lsp(zvrf, fec, old_label); | |
1882 | ||
1883 | return 0; | |
5aba114a DS |
1884 | } |
1885 | ||
1886 | /* | |
1887 | * Deregistration from a client for the label binding for a FEC. The FEC | |
1888 | * itself is deleted if no other registered clients exist and there is no | |
1889 | * label bound to the FEC. | |
1890 | */ | |
d62a17ae | 1891 | int zebra_mpls_fec_unregister(struct zebra_vrf *zvrf, struct prefix *p, |
1892 | struct zserv *client) | |
5aba114a | 1893 | { |
d62a17ae | 1894 | struct route_table *table; |
1895 | zebra_fec_t *fec; | |
1896 | char buf[BUFSIZ]; | |
5aba114a | 1897 | |
d62a17ae | 1898 | table = zvrf->fec_table[family2afi(PREFIX_FAMILY(p))]; |
1899 | if (!table) | |
1900 | return -1; | |
5aba114a | 1901 | |
d62a17ae | 1902 | if (IS_ZEBRA_DEBUG_MPLS) |
1903 | prefix2str(p, buf, BUFSIZ); | |
5aba114a | 1904 | |
d62a17ae | 1905 | fec = fec_find(table, p); |
1906 | if (!fec) { | |
1907 | prefix2str(p, buf, BUFSIZ); | |
1908 | zlog_err("Failed to find FEC %s upon unregister, client %s", | |
1909 | buf, zebra_route_string(client->proto)); | |
1910 | return -1; | |
1911 | } | |
5aba114a | 1912 | |
d62a17ae | 1913 | listnode_delete(fec->client_list, client); |
1914 | ||
1915 | if (IS_ZEBRA_DEBUG_MPLS) | |
1916 | zlog_debug("FEC %s unregistered by client %s", buf, | |
1917 | zebra_route_string(client->proto)); | |
1918 | ||
1919 | /* If not a configured entry, delete the FEC if no other clients. Before | |
1920 | * deleting, see if any LSP needs to be uninstalled. | |
1921 | */ | |
1922 | if (!(fec->flags & FEC_FLAG_CONFIGURED) | |
1923 | && list_isempty(fec->client_list)) { | |
1924 | mpls_label_t old_label = fec->label; | |
1925 | fec->label = MPLS_INVALID_LABEL; /* reset */ | |
1926 | fec_change_update_lsp(zvrf, fec, old_label); | |
1927 | fec_del(fec); | |
1928 | } | |
5aba114a | 1929 | |
d62a17ae | 1930 | return 0; |
5aba114a DS |
1931 | } |
1932 | ||
1933 | /* | |
1934 | * Cleanup any FECs registered by this client. | |
1935 | */ | |
453844ab | 1936 | static int zebra_mpls_cleanup_fecs_for_client(struct zserv *client) |
d62a17ae | 1937 | { |
453844ab | 1938 | struct zebra_vrf *zvrf = vrf_info_lookup(VRF_DEFAULT); |
d62a17ae | 1939 | struct route_node *rn; |
1940 | zebra_fec_t *fec; | |
1941 | struct listnode *node; | |
1942 | struct zserv *fec_client; | |
1943 | int af; | |
1944 | ||
1945 | for (af = AFI_IP; af < AFI_MAX; af++) { | |
1946 | if (zvrf->fec_table[af] == NULL) | |
1947 | continue; | |
1948 | ||
1949 | for (rn = route_top(zvrf->fec_table[af]); rn; | |
1950 | rn = route_next(rn)) { | |
1951 | fec = rn->info; | |
1952 | if (!fec || list_isempty(fec->client_list)) | |
1953 | continue; | |
1954 | ||
1955 | for (ALL_LIST_ELEMENTS_RO(fec->client_list, node, | |
1956 | fec_client)) { | |
1957 | if (fec_client == client) { | |
1958 | listnode_delete(fec->client_list, | |
1959 | fec_client); | |
1960 | if (!(fec->flags & FEC_FLAG_CONFIGURED) | |
1961 | && list_isempty(fec->client_list)) | |
1962 | fec_del(fec); | |
1963 | break; | |
1964 | } | |
1965 | } | |
1966 | } | |
1967 | } | |
5aba114a | 1968 | |
d62a17ae | 1969 | return 0; |
5aba114a DS |
1970 | } |
1971 | ||
f31e084c DS |
1972 | /* |
1973 | * Return FEC (if any) to which this label is bound. | |
1974 | * Note: Only works for per-prefix binding and when the label is not | |
1975 | * implicit-null. | |
1976 | * TODO: Currently walks entire table, can optimize later with another | |
1977 | * hash.. | |
1978 | */ | |
d62a17ae | 1979 | zebra_fec_t *zebra_mpls_fec_for_label(struct zebra_vrf *zvrf, |
1980 | mpls_label_t label) | |
1981 | { | |
1982 | struct route_node *rn; | |
1983 | zebra_fec_t *fec; | |
1984 | int af; | |
1985 | ||
1986 | for (af = AFI_IP; af < AFI_MAX; af++) { | |
1987 | if (zvrf->fec_table[af] == NULL) | |
1988 | continue; | |
1989 | ||
1990 | for (rn = route_top(zvrf->fec_table[af]); rn; | |
1991 | rn = route_next(rn)) { | |
1992 | if (!rn->info) | |
1993 | continue; | |
1994 | fec = rn->info; | |
1995 | if (fec->label == label) | |
1996 | return fec; | |
1997 | } | |
1998 | } | |
f31e084c | 1999 | |
d62a17ae | 2000 | return NULL; |
f31e084c DS |
2001 | } |
2002 | ||
2003 | /* | |
2004 | * Inform if specified label is currently bound to a FEC or not. | |
2005 | */ | |
d62a17ae | 2006 | int zebra_mpls_label_already_bound(struct zebra_vrf *zvrf, mpls_label_t label) |
f31e084c | 2007 | { |
d62a17ae | 2008 | return (zebra_mpls_fec_for_label(zvrf, label) ? 1 : 0); |
f31e084c DS |
2009 | } |
2010 | ||
2011 | /* | |
5aba114a | 2012 | * Add static FEC to label binding. If there are clients registered for this |
a64448ba DS |
2013 | * FEC, notify them. If there are labeled routes for this FEC, install the |
2014 | * label forwarding entry. | |
9d303b37 | 2015 | */ |
d62a17ae | 2016 | int zebra_mpls_static_fec_add(struct zebra_vrf *zvrf, struct prefix *p, |
2017 | mpls_label_t in_label) | |
2018 | { | |
2019 | struct route_table *table; | |
2020 | zebra_fec_t *fec; | |
2021 | char buf[BUFSIZ]; | |
2022 | mpls_label_t old_label; | |
2023 | int ret = 0; | |
2024 | ||
2025 | table = zvrf->fec_table[family2afi(PREFIX_FAMILY(p))]; | |
2026 | if (!table) | |
2027 | return -1; | |
2028 | ||
2029 | if (IS_ZEBRA_DEBUG_MPLS) | |
2030 | prefix2str(p, buf, BUFSIZ); | |
2031 | ||
2032 | /* Update existing FEC or create a new one. */ | |
2033 | fec = fec_find(table, p); | |
2034 | if (!fec) { | |
2035 | fec = fec_add(table, p, in_label, FEC_FLAG_CONFIGURED, | |
2036 | MPLS_INVALID_LABEL_INDEX); | |
2037 | if (!fec) { | |
2038 | prefix2str(p, buf, BUFSIZ); | |
2039 | zlog_err("Failed to add FEC %s upon config", buf); | |
2040 | return -1; | |
2041 | } | |
2042 | ||
2043 | if (IS_ZEBRA_DEBUG_MPLS) | |
2044 | zlog_debug("Add fec %s label %u", buf, in_label); | |
2045 | } else { | |
2046 | fec->flags |= FEC_FLAG_CONFIGURED; | |
2047 | if (fec->label == in_label) | |
2048 | /* Duplicate config */ | |
2049 | return 0; | |
2050 | ||
2051 | /* Label change, update clients. */ | |
2052 | old_label = fec->label; | |
2053 | if (IS_ZEBRA_DEBUG_MPLS) | |
2054 | zlog_debug("Update fec %s new label %u", buf, in_label); | |
2055 | ||
2056 | fec->label = in_label; | |
2057 | fec_update_clients(fec); | |
2058 | ||
2059 | /* Update label forwarding entries appropriately */ | |
2060 | ret = fec_change_update_lsp(zvrf, fec, old_label); | |
2061 | } | |
2062 | ||
2063 | return ret; | |
f31e084c DS |
2064 | } |
2065 | ||
2066 | /* | |
5aba114a DS |
2067 | * Remove static FEC to label binding. If there are no clients registered |
2068 | * for this FEC, delete the FEC; else notify clients | |
28d58fd7 VV |
2069 | * Note: Upon delete of static binding, if label index exists for this FEC, |
2070 | * client may need to be updated with derived label. | |
f31e084c | 2071 | */ |
d62a17ae | 2072 | int zebra_mpls_static_fec_del(struct zebra_vrf *zvrf, struct prefix *p) |
2073 | { | |
2074 | struct route_table *table; | |
2075 | zebra_fec_t *fec; | |
2076 | mpls_label_t old_label; | |
2077 | char buf[BUFSIZ]; | |
2078 | ||
2079 | table = zvrf->fec_table[family2afi(PREFIX_FAMILY(p))]; | |
2080 | if (!table) | |
2081 | return -1; | |
2082 | ||
2083 | fec = fec_find(table, p); | |
2084 | if (!fec) { | |
2085 | prefix2str(p, buf, BUFSIZ); | |
2086 | zlog_err("Failed to find FEC %s upon delete", buf); | |
2087 | return -1; | |
2088 | } | |
2089 | ||
2090 | if (IS_ZEBRA_DEBUG_MPLS) { | |
2091 | prefix2str(p, buf, BUFSIZ); | |
2092 | zlog_debug("Delete fec %s label index %u", buf, | |
2093 | fec->label_index); | |
2094 | } | |
2095 | ||
2096 | old_label = fec->label; | |
2097 | fec->flags &= ~FEC_FLAG_CONFIGURED; | |
2098 | fec->label = MPLS_INVALID_LABEL; | |
2099 | ||
2100 | /* If no client exists, just delete the FEC. */ | |
2101 | if (list_isempty(fec->client_list)) { | |
2102 | fec_del(fec); | |
2103 | return 0; | |
2104 | } | |
2105 | ||
2106 | /* Derive the local label (from label index) or reset it. */ | |
2107 | fec_derive_label_from_index(zvrf, fec); | |
2108 | ||
2109 | /* If there is a label change, update clients. */ | |
2110 | if (fec->label == old_label) | |
2111 | return 0; | |
2112 | fec_update_clients(fec); | |
2113 | ||
2114 | /* Update label forwarding entries appropriately */ | |
2115 | return fec_change_update_lsp(zvrf, fec, old_label); | |
f31e084c DS |
2116 | } |
2117 | ||
2118 | /* | |
2119 | * Display MPLS FEC to label binding configuration (VTY command handler). | |
2120 | */ | |
d62a17ae | 2121 | int zebra_mpls_write_fec_config(struct vty *vty, struct zebra_vrf *zvrf) |
f31e084c | 2122 | { |
d62a17ae | 2123 | struct route_node *rn; |
2124 | int af; | |
2125 | zebra_fec_t *fec; | |
2126 | char buf[BUFSIZ]; | |
2127 | int write = 0; | |
f31e084c | 2128 | |
d62a17ae | 2129 | for (af = AFI_IP; af < AFI_MAX; af++) { |
2130 | if (zvrf->fec_table[af] == NULL) | |
2131 | continue; | |
f31e084c | 2132 | |
d62a17ae | 2133 | for (rn = route_top(zvrf->fec_table[af]); rn; |
2134 | rn = route_next(rn)) { | |
2135 | if (!rn->info) | |
2136 | continue; | |
f31e084c | 2137 | |
d62a17ae | 2138 | char lstr[BUFSIZ]; |
2139 | fec = rn->info; | |
f31e084c | 2140 | |
d62a17ae | 2141 | if (!(fec->flags & FEC_FLAG_CONFIGURED)) |
2142 | continue; | |
f31e084c | 2143 | |
d62a17ae | 2144 | write = 1; |
2145 | prefix2str(&rn->p, buf, BUFSIZ); | |
2146 | vty_out(vty, "mpls label bind %s %s\n", buf, | |
2147 | label2str(fec->label, lstr, BUFSIZ)); | |
2148 | } | |
2149 | } | |
f31e084c | 2150 | |
d62a17ae | 2151 | return write; |
f31e084c DS |
2152 | } |
2153 | ||
2154 | /* | |
2155 | * Display MPLS FEC to label binding (VTY command handler). | |
2156 | */ | |
d62a17ae | 2157 | void zebra_mpls_print_fec_table(struct vty *vty, struct zebra_vrf *zvrf) |
f31e084c | 2158 | { |
d62a17ae | 2159 | struct route_node *rn; |
2160 | int af; | |
f31e084c | 2161 | |
d62a17ae | 2162 | for (af = AFI_IP; af < AFI_MAX; af++) { |
2163 | if (zvrf->fec_table[af] == NULL) | |
2164 | continue; | |
f31e084c | 2165 | |
d62a17ae | 2166 | for (rn = route_top(zvrf->fec_table[af]); rn; |
2167 | rn = route_next(rn)) { | |
2168 | if (!rn->info) | |
2169 | continue; | |
2170 | fec_print(rn->info, vty); | |
2171 | } | |
2172 | } | |
f31e084c DS |
2173 | } |
2174 | ||
2175 | /* | |
2176 | * Display MPLS FEC to label binding for a specific FEC (VTY command handler). | |
2177 | */ | |
d62a17ae | 2178 | void zebra_mpls_print_fec(struct vty *vty, struct zebra_vrf *zvrf, |
2179 | struct prefix *p) | |
f31e084c | 2180 | { |
d62a17ae | 2181 | struct route_table *table; |
2182 | struct route_node *rn; | |
f31e084c | 2183 | |
d62a17ae | 2184 | table = zvrf->fec_table[family2afi(PREFIX_FAMILY(p))]; |
2185 | if (!table) | |
2186 | return; | |
f31e084c | 2187 | |
d62a17ae | 2188 | apply_mask(p); |
2189 | rn = route_node_lookup(table, p); | |
2190 | if (!rn) | |
2191 | return; | |
f31e084c | 2192 | |
d62a17ae | 2193 | route_unlock_node(rn); |
2194 | if (!rn->info) | |
2195 | return; | |
f31e084c | 2196 | |
d62a17ae | 2197 | fec_print(rn->info, vty); |
f31e084c DS |
2198 | } |
2199 | ||
8f77d0ee DS |
2200 | static bool mpls_ftn_update_nexthop(int add, struct nexthop *nexthop, |
2201 | enum lsp_types_t type, mpls_label_t label) | |
2202 | { | |
2203 | if (add && nexthop->nh_label_type == ZEBRA_LSP_NONE) | |
2204 | nexthop_add_labels(nexthop, type, 1, &label); | |
2205 | else if (!add && nexthop->nh_label_type == type) | |
2206 | nexthop_del_labels(nexthop); | |
2207 | else | |
2208 | return false; | |
2209 | ||
2210 | return true; | |
2211 | } | |
2212 | ||
ce549947 RW |
2213 | /* |
2214 | * Install/uninstall a FEC-To-NHLFE (FTN) binding. | |
2215 | */ | |
d62a17ae | 2216 | int mpls_ftn_update(int add, struct zebra_vrf *zvrf, enum lsp_types_t type, |
2217 | struct prefix *prefix, enum nexthop_types_t gtype, | |
d7c0a89a | 2218 | union g_addr *gate, ifindex_t ifindex, uint8_t distance, |
d62a17ae | 2219 | mpls_label_t out_label) |
2220 | { | |
2221 | struct route_table *table; | |
2222 | struct route_node *rn; | |
2223 | struct route_entry *re; | |
2224 | struct nexthop *nexthop; | |
8f77d0ee | 2225 | bool found; |
d62a17ae | 2226 | |
2227 | /* Lookup table. */ | |
2228 | table = zebra_vrf_table(family2afi(prefix->family), SAFI_UNICAST, | |
2229 | zvrf_id(zvrf)); | |
2230 | if (!table) | |
2231 | return -1; | |
2232 | ||
2233 | /* Lookup existing route */ | |
2234 | rn = route_node_get(table, prefix); | |
a2addae8 | 2235 | RNODE_FOREACH_RE (rn, re) { |
d62a17ae | 2236 | if (CHECK_FLAG(re->status, ROUTE_ENTRY_REMOVED)) |
2237 | continue; | |
2238 | if (re->distance == distance) | |
2239 | break; | |
88d88a9c | 2240 | } |
ce549947 | 2241 | |
d62a17ae | 2242 | if (re == NULL) |
2243 | return -1; | |
2244 | ||
8f77d0ee | 2245 | found = false; |
7ee30f28 | 2246 | for (nexthop = re->ng.nexthop; nexthop; nexthop = nexthop->next) { |
d62a17ae | 2247 | switch (nexthop->type) { |
2248 | case NEXTHOP_TYPE_IPV4: | |
2249 | case NEXTHOP_TYPE_IPV4_IFINDEX: | |
2250 | if (gtype != NEXTHOP_TYPE_IPV4 | |
2251 | && gtype != NEXTHOP_TYPE_IPV4_IFINDEX) | |
2252 | continue; | |
2253 | if (!IPV4_ADDR_SAME(&nexthop->gate.ipv4, &gate->ipv4)) | |
2254 | continue; | |
2255 | if (nexthop->type == NEXTHOP_TYPE_IPV4_IFINDEX | |
2256 | && nexthop->ifindex != ifindex) | |
2257 | continue; | |
8f77d0ee DS |
2258 | if (!mpls_ftn_update_nexthop(add, nexthop, type, |
2259 | out_label)) | |
2260 | return 0; | |
2261 | found = true; | |
2262 | break; | |
d62a17ae | 2263 | case NEXTHOP_TYPE_IPV6: |
2264 | case NEXTHOP_TYPE_IPV6_IFINDEX: | |
2265 | if (gtype != NEXTHOP_TYPE_IPV6 | |
2266 | && gtype != NEXTHOP_TYPE_IPV6_IFINDEX) | |
2267 | continue; | |
2268 | if (!IPV6_ADDR_SAME(&nexthop->gate.ipv6, &gate->ipv6)) | |
2269 | continue; | |
2270 | if (nexthop->type == NEXTHOP_TYPE_IPV6_IFINDEX | |
2271 | && nexthop->ifindex != ifindex) | |
2272 | continue; | |
8f77d0ee DS |
2273 | if (!mpls_ftn_update_nexthop(add, nexthop, type, |
2274 | out_label)) | |
2275 | return 0; | |
2276 | found = true; | |
2277 | break; | |
d62a17ae | 2278 | default: |
2279 | break; | |
2280 | } | |
2281 | } | |
d62a17ae | 2282 | |
8f77d0ee DS |
2283 | if (!found) |
2284 | return -1; | |
ce549947 | 2285 | |
d62a17ae | 2286 | SET_FLAG(re->status, ROUTE_ENTRY_CHANGED); |
332ad713 | 2287 | SET_FLAG(re->status, ROUTE_ENTRY_LABELS_CHANGED); |
d62a17ae | 2288 | rib_queue_add(rn); |
ce549947 | 2289 | |
d62a17ae | 2290 | return 0; |
ce549947 RW |
2291 | } |
2292 | ||
2293 | /* | |
2294 | * Install/update a NHLFE for an LSP in the forwarding table. This may be | |
2295 | * a new LSP entry or a new NHLFE for an existing in-label or an update of | |
2296 | * the out-label for an existing NHLFE (update case). | |
2297 | */ | |
d62a17ae | 2298 | int mpls_lsp_install(struct zebra_vrf *zvrf, enum lsp_types_t type, |
2299 | mpls_label_t in_label, mpls_label_t out_label, | |
2300 | enum nexthop_types_t gtype, union g_addr *gate, | |
2301 | ifindex_t ifindex) | |
2302 | { | |
2303 | struct hash *lsp_table; | |
2304 | zebra_ile_t tmp_ile; | |
2305 | zebra_lsp_t *lsp; | |
2306 | zebra_nhlfe_t *nhlfe; | |
2307 | char buf[BUFSIZ]; | |
2308 | ||
2309 | /* Lookup table. */ | |
2310 | lsp_table = zvrf->lsp_table; | |
2311 | if (!lsp_table) | |
2312 | return -1; | |
2313 | ||
2314 | /* If entry is present, exit. */ | |
2315 | tmp_ile.in_label = in_label; | |
2316 | lsp = hash_get(lsp_table, &tmp_ile, lsp_alloc); | |
2317 | if (!lsp) | |
2318 | return -1; | |
2319 | nhlfe = nhlfe_find(lsp, type, gtype, gate, ifindex); | |
2320 | if (nhlfe) { | |
2321 | struct nexthop *nh = nhlfe->nexthop; | |
2322 | ||
2323 | assert(nh); | |
2324 | assert(nh->nh_label); | |
2325 | ||
2326 | /* Clear deleted flag (in case it was set) */ | |
2327 | UNSET_FLAG(nhlfe->flags, NHLFE_FLAG_DELETED); | |
2328 | if (nh->nh_label->label[0] == out_label) | |
2329 | /* No change */ | |
2330 | return 0; | |
2331 | ||
2332 | if (IS_ZEBRA_DEBUG_MPLS) { | |
2333 | nhlfe2str(nhlfe, buf, BUFSIZ); | |
2334 | zlog_debug( | |
2335 | "LSP in-label %u type %d nexthop %s " | |
2336 | "out-label changed to %u (old %u)", | |
2337 | in_label, type, buf, out_label, | |
2338 | nh->nh_label->label[0]); | |
2339 | } | |
2340 | ||
2341 | /* Update out label, trigger processing. */ | |
2342 | nh->nh_label->label[0] = out_label; | |
2343 | } else { | |
2344 | /* Add LSP entry to this nexthop */ | |
2345 | nhlfe = nhlfe_add(lsp, type, gtype, gate, ifindex, out_label); | |
2346 | if (!nhlfe) | |
2347 | return -1; | |
2348 | ||
2349 | if (IS_ZEBRA_DEBUG_MPLS) { | |
2350 | nhlfe2str(nhlfe, buf, BUFSIZ); | |
2351 | zlog_debug( | |
2352 | "Add LSP in-label %u type %d nexthop %s " | |
2353 | "out-label %u", | |
2354 | in_label, type, buf, out_label); | |
2355 | } | |
2356 | ||
2357 | lsp->addr_family = NHLFE_FAMILY(nhlfe); | |
2358 | } | |
2359 | ||
2360 | /* Mark NHLFE, queue LSP for processing. */ | |
2361 | SET_FLAG(nhlfe->flags, NHLFE_FLAG_CHANGED); | |
2362 | if (lsp_processq_add(lsp)) | |
2363 | return -1; | |
2364 | ||
2365 | return 0; | |
ce549947 RW |
2366 | } |
2367 | ||
2368 | /* | |
2369 | * Uninstall a particular NHLFE in the forwarding table. If this is | |
2370 | * the only NHLFE, the entire LSP forwarding entry has to be deleted. | |
2371 | */ | |
d62a17ae | 2372 | int mpls_lsp_uninstall(struct zebra_vrf *zvrf, enum lsp_types_t type, |
2373 | mpls_label_t in_label, enum nexthop_types_t gtype, | |
2374 | union g_addr *gate, ifindex_t ifindex) | |
2375 | { | |
2376 | struct hash *lsp_table; | |
2377 | zebra_ile_t tmp_ile; | |
2378 | zebra_lsp_t *lsp; | |
2379 | zebra_nhlfe_t *nhlfe; | |
2380 | char buf[BUFSIZ]; | |
2381 | ||
2382 | /* Lookup table. */ | |
2383 | lsp_table = zvrf->lsp_table; | |
2384 | if (!lsp_table) | |
2385 | return -1; | |
2386 | ||
2387 | /* If entry is not present, exit. */ | |
2388 | tmp_ile.in_label = in_label; | |
2389 | lsp = hash_lookup(lsp_table, &tmp_ile); | |
2390 | if (!lsp) | |
2391 | return 0; | |
2392 | nhlfe = nhlfe_find(lsp, type, gtype, gate, ifindex); | |
2393 | if (!nhlfe) | |
2394 | return 0; | |
2395 | ||
2396 | if (IS_ZEBRA_DEBUG_MPLS) { | |
2397 | nhlfe2str(nhlfe, buf, BUFSIZ); | |
2398 | zlog_debug("Del LSP in-label %u type %d nexthop %s flags 0x%x", | |
2399 | in_label, type, buf, nhlfe->flags); | |
2400 | } | |
2401 | ||
2402 | /* Mark NHLFE for delete or directly delete, as appropriate. */ | |
2403 | if (CHECK_FLAG(nhlfe->flags, NHLFE_FLAG_INSTALLED)) { | |
2404 | UNSET_FLAG(nhlfe->flags, NHLFE_FLAG_CHANGED); | |
2405 | SET_FLAG(nhlfe->flags, NHLFE_FLAG_DELETED); | |
2406 | if (lsp_processq_add(lsp)) | |
2407 | return -1; | |
2408 | } else { | |
2409 | nhlfe_del(nhlfe); | |
2410 | ||
2411 | /* Free LSP entry if no other NHLFEs and not scheduled. */ | |
2412 | if (!lsp->nhlfe_list | |
2413 | && !CHECK_FLAG(lsp->flags, LSP_FLAG_SCHEDULED)) { | |
2414 | if (IS_ZEBRA_DEBUG_MPLS) | |
2415 | zlog_debug("Free LSP in-label %u flags 0x%x", | |
2416 | lsp->ile.in_label, lsp->flags); | |
2417 | ||
2418 | lsp = hash_release(lsp_table, &lsp->ile); | |
2419 | if (lsp) | |
2420 | XFREE(MTYPE_LSP, lsp); | |
2421 | } | |
2422 | } | |
2423 | return 0; | |
ce549947 RW |
2424 | } |
2425 | ||
2426 | /* | |
2427 | * Uninstall all LDP NHLFEs for a particular LSP forwarding entry. | |
2428 | * If no other NHLFEs exist, the entry would be deleted. | |
2429 | */ | |
d62a17ae | 2430 | void mpls_ldp_lsp_uninstall_all(struct hash_backet *backet, void *ctxt) |
ce549947 | 2431 | { |
d62a17ae | 2432 | zebra_lsp_t *lsp; |
2433 | struct hash *lsp_table; | |
ce549947 | 2434 | |
d62a17ae | 2435 | lsp = (zebra_lsp_t *)backet->data; |
9ea660be | 2436 | if (!lsp->nhlfe_list) |
d62a17ae | 2437 | return; |
ce549947 | 2438 | |
d62a17ae | 2439 | lsp_table = ctxt; |
2440 | if (!lsp_table) | |
2441 | return; | |
ce549947 | 2442 | |
d62a17ae | 2443 | mpls_lsp_uninstall_all(lsp_table, lsp, ZEBRA_LSP_LDP); |
ce549947 RW |
2444 | } |
2445 | ||
2446 | /* | |
2447 | * Uninstall all LDP FEC-To-NHLFE (FTN) bindings of the given address-family. | |
2448 | */ | |
d62a17ae | 2449 | void mpls_ldp_ftn_uninstall_all(struct zebra_vrf *zvrf, int afi) |
2450 | { | |
2451 | struct route_table *table; | |
2452 | struct route_node *rn; | |
2453 | struct route_entry *re; | |
2454 | struct nexthop *nexthop; | |
2455 | int update; | |
2456 | ||
2457 | /* Process routes of interested address-families. */ | |
2458 | table = zebra_vrf_table(afi, SAFI_UNICAST, zvrf_id(zvrf)); | |
2459 | if (!table) | |
2460 | return; | |
2461 | ||
2462 | for (rn = route_top(table); rn; rn = route_next(rn)) { | |
2463 | update = 0; | |
a2addae8 | 2464 | RNODE_FOREACH_RE (rn, re) { |
7ee30f28 | 2465 | for (nexthop = re->ng.nexthop; nexthop; |
407c87a6 DS |
2466 | nexthop = nexthop->next) { |
2467 | if (nexthop->nh_label_type != ZEBRA_LSP_LDP) | |
2468 | continue; | |
2469 | ||
d62a17ae | 2470 | nexthop_del_labels(nexthop); |
2471 | SET_FLAG(re->status, ROUTE_ENTRY_CHANGED); | |
2472 | SET_FLAG(re->status, | |
332ad713 | 2473 | ROUTE_ENTRY_LABELS_CHANGED); |
d62a17ae | 2474 | update = 1; |
2475 | } | |
407c87a6 | 2476 | } |
d62a17ae | 2477 | |
2478 | if (update) | |
2479 | rib_queue_add(rn); | |
2480 | } | |
ce549947 RW |
2481 | } |
2482 | ||
1c1cf002 | 2483 | #if defined(HAVE_CUMULUS) |
7758e3f3 | 2484 | /* |
2485 | * Check that the label values used in LSP creation are consistent. The | |
2486 | * main criteria is that if there is ECMP, the label operation must still | |
2487 | * be consistent - i.e., all paths either do a swap or do PHP. This is due | |
2488 | * to current HW restrictions. | |
2489 | */ | |
d62a17ae | 2490 | int zebra_mpls_lsp_label_consistent(struct zebra_vrf *zvrf, |
2491 | mpls_label_t in_label, | |
2492 | mpls_label_t out_label, | |
2493 | enum nexthop_types_t gtype, | |
2494 | union g_addr *gate, ifindex_t ifindex) | |
2495 | { | |
2496 | struct hash *slsp_table; | |
2497 | zebra_ile_t tmp_ile; | |
2498 | zebra_slsp_t *slsp; | |
2499 | zebra_snhlfe_t *snhlfe; | |
2500 | ||
2501 | /* Lookup table. */ | |
2502 | slsp_table = zvrf->slsp_table; | |
2503 | if (!slsp_table) | |
2504 | return 0; | |
2505 | ||
2506 | /* If entry is not present, exit. */ | |
2507 | tmp_ile.in_label = in_label; | |
2508 | slsp = hash_lookup(slsp_table, &tmp_ile); | |
2509 | if (!slsp) | |
2510 | return 1; | |
2511 | ||
2512 | snhlfe = snhlfe_find(slsp, gtype, gate, ifindex); | |
2513 | if (snhlfe) { | |
2514 | if (snhlfe->out_label == out_label) | |
2515 | return 1; | |
2516 | ||
2517 | /* If not only NHLFE, cannot allow label change. */ | |
2518 | if (snhlfe != slsp->snhlfe_list || snhlfe->next) | |
2519 | return 0; | |
2520 | } else { | |
2521 | /* If other NHLFEs exist, label operation must match. */ | |
2522 | if (slsp->snhlfe_list) { | |
2523 | int cur_op, new_op; | |
2524 | ||
2525 | cur_op = (slsp->snhlfe_list->out_label | |
70e98a7f DS |
2526 | == MPLS_LABEL_IMPLICIT_NULL); |
2527 | new_op = (out_label == MPLS_LABEL_IMPLICIT_NULL); | |
d62a17ae | 2528 | if (cur_op != new_op) |
2529 | return 0; | |
2530 | } | |
2531 | } | |
2532 | ||
2533 | /* Label values are good. */ | |
2534 | return 1; | |
7758e3f3 | 2535 | } |
1c1cf002 | 2536 | #endif /* HAVE_CUMULUS */ |
7758e3f3 | 2537 | |
2538 | /* | |
2539 | * Add static LSP entry. This may be the first entry for this incoming label | |
2540 | * or an additional nexthop; an existing entry may also have outgoing label | |
2541 | * changed. | |
2542 | * Note: The label operation (swap or PHP) is common for the LSP entry (all | |
2543 | * NHLFEs). | |
2544 | */ | |
d62a17ae | 2545 | int zebra_mpls_static_lsp_add(struct zebra_vrf *zvrf, mpls_label_t in_label, |
2546 | mpls_label_t out_label, | |
2547 | enum nexthop_types_t gtype, union g_addr *gate, | |
2548 | ifindex_t ifindex) | |
2549 | { | |
2550 | struct hash *slsp_table; | |
2551 | zebra_ile_t tmp_ile; | |
2552 | zebra_slsp_t *slsp; | |
2553 | zebra_snhlfe_t *snhlfe; | |
2554 | char buf[BUFSIZ]; | |
2555 | ||
2556 | /* Lookup table. */ | |
2557 | slsp_table = zvrf->slsp_table; | |
2558 | if (!slsp_table) | |
2559 | return -1; | |
2560 | ||
2561 | /* If entry is present, exit. */ | |
2562 | tmp_ile.in_label = in_label; | |
2563 | slsp = hash_get(slsp_table, &tmp_ile, slsp_alloc); | |
2564 | if (!slsp) | |
2565 | return -1; | |
2566 | snhlfe = snhlfe_find(slsp, gtype, gate, ifindex); | |
2567 | if (snhlfe) { | |
2568 | if (snhlfe->out_label == out_label) | |
2569 | /* No change */ | |
2570 | return 0; | |
2571 | ||
2572 | if (IS_ZEBRA_DEBUG_MPLS) { | |
2573 | snhlfe2str(snhlfe, buf, BUFSIZ); | |
2574 | zlog_debug( | |
2575 | "Upd static LSP in-label %u nexthop %s " | |
2576 | "out-label %u (old %u)", | |
2577 | in_label, buf, out_label, snhlfe->out_label); | |
2578 | } | |
2579 | snhlfe->out_label = out_label; | |
2580 | } else { | |
2581 | /* Add static LSP entry to this nexthop */ | |
2582 | snhlfe = snhlfe_add(slsp, gtype, gate, ifindex, out_label); | |
2583 | if (!snhlfe) | |
2584 | return -1; | |
2585 | ||
2586 | if (IS_ZEBRA_DEBUG_MPLS) { | |
2587 | snhlfe2str(snhlfe, buf, BUFSIZ); | |
2588 | zlog_debug( | |
2589 | "Add static LSP in-label %u nexthop %s out-label %u", | |
2590 | in_label, buf, out_label); | |
2591 | } | |
2592 | } | |
2593 | ||
2594 | /* (Re)Install LSP in the main table. */ | |
2595 | if (mpls_lsp_install(zvrf, ZEBRA_LSP_STATIC, in_label, out_label, gtype, | |
2596 | gate, ifindex)) | |
2597 | return -1; | |
2598 | ||
2599 | return 0; | |
7758e3f3 | 2600 | } |
2601 | ||
2602 | /* | |
2603 | * Delete static LSP entry. This may be the delete of one particular | |
2604 | * NHLFE for this incoming label or the delete of the entire entry (i.e., | |
2605 | * all NHLFEs). | |
2606 | * NOTE: Delete of the only NHLFE will also end up deleting the entire | |
2607 | * LSP configuration. | |
2608 | */ | |
d62a17ae | 2609 | int zebra_mpls_static_lsp_del(struct zebra_vrf *zvrf, mpls_label_t in_label, |
2610 | enum nexthop_types_t gtype, union g_addr *gate, | |
2611 | ifindex_t ifindex) | |
2612 | { | |
2613 | struct hash *slsp_table; | |
2614 | zebra_ile_t tmp_ile; | |
2615 | zebra_slsp_t *slsp; | |
2616 | zebra_snhlfe_t *snhlfe; | |
2617 | ||
2618 | /* Lookup table. */ | |
2619 | slsp_table = zvrf->slsp_table; | |
2620 | if (!slsp_table) | |
2621 | return -1; | |
2622 | ||
2623 | /* If entry is not present, exit. */ | |
2624 | tmp_ile.in_label = in_label; | |
2625 | slsp = hash_lookup(slsp_table, &tmp_ile); | |
2626 | if (!slsp) | |
2627 | return 0; | |
2628 | ||
2629 | /* Is it delete of entire LSP or a specific NHLFE? */ | |
2630 | if (gtype == NEXTHOP_TYPE_BLACKHOLE) { | |
2631 | if (IS_ZEBRA_DEBUG_MPLS) | |
2632 | zlog_debug("Del static LSP in-label %u", in_label); | |
2633 | ||
2634 | /* Uninstall entire LSP from the main table. */ | |
2635 | mpls_static_lsp_uninstall_all(zvrf, in_label); | |
2636 | ||
2637 | /* Delete all static NHLFEs */ | |
2638 | snhlfe_del_all(slsp); | |
2639 | } else { | |
2640 | /* Find specific NHLFE, exit if not found. */ | |
2641 | snhlfe = snhlfe_find(slsp, gtype, gate, ifindex); | |
2642 | if (!snhlfe) | |
2643 | return 0; | |
2644 | ||
2645 | if (IS_ZEBRA_DEBUG_MPLS) { | |
2646 | char buf[BUFSIZ]; | |
2647 | snhlfe2str(snhlfe, buf, BUFSIZ); | |
2648 | zlog_debug("Del static LSP in-label %u nexthop %s", | |
2649 | in_label, buf); | |
2650 | } | |
2651 | ||
2652 | /* Uninstall LSP from the main table. */ | |
2653 | mpls_lsp_uninstall(zvrf, ZEBRA_LSP_STATIC, in_label, gtype, | |
2654 | gate, ifindex); | |
2655 | ||
2656 | /* Delete static LSP NHLFE */ | |
2657 | snhlfe_del(snhlfe); | |
2658 | } | |
2659 | ||
2660 | /* Remove entire static LSP entry if no NHLFE - valid in either case | |
2661 | * above. */ | |
2662 | if (!slsp->snhlfe_list) { | |
2663 | slsp = hash_release(slsp_table, &tmp_ile); | |
2664 | if (slsp) | |
2665 | XFREE(MTYPE_SLSP, slsp); | |
2666 | } | |
2667 | ||
2668 | return 0; | |
7758e3f3 | 2669 | } |
2670 | ||
40c7bdb0 | 2671 | /* |
2672 | * Schedule all MPLS label forwarding entries for processing. | |
2673 | * Called upon changes that may affect one or more of them such as | |
2674 | * interface or nexthop state changes. | |
2675 | */ | |
d62a17ae | 2676 | void zebra_mpls_lsp_schedule(struct zebra_vrf *zvrf) |
40c7bdb0 | 2677 | { |
d62a17ae | 2678 | if (!zvrf) |
2679 | return; | |
2680 | hash_iterate(zvrf->lsp_table, lsp_schedule, NULL); | |
40c7bdb0 | 2681 | } |
2682 | ||
3ab18ff2 | 2683 | /* |
2684 | * Display MPLS label forwarding table for a specific LSP | |
2685 | * (VTY command handler). | |
2686 | */ | |
d62a17ae | 2687 | void zebra_mpls_print_lsp(struct vty *vty, struct zebra_vrf *zvrf, |
d7c0a89a | 2688 | mpls_label_t label, uint8_t use_json) |
3ab18ff2 | 2689 | { |
d62a17ae | 2690 | struct hash *lsp_table; |
2691 | zebra_lsp_t *lsp; | |
2692 | zebra_ile_t tmp_ile; | |
2693 | json_object *json = NULL; | |
3ab18ff2 | 2694 | |
d62a17ae | 2695 | /* Lookup table. */ |
2696 | lsp_table = zvrf->lsp_table; | |
2697 | if (!lsp_table) | |
2698 | return; | |
3ab18ff2 | 2699 | |
d62a17ae | 2700 | /* If entry is not present, exit. */ |
2701 | tmp_ile.in_label = label; | |
2702 | lsp = hash_lookup(lsp_table, &tmp_ile); | |
2703 | if (!lsp) | |
2704 | return; | |
3ab18ff2 | 2705 | |
d62a17ae | 2706 | if (use_json) { |
2707 | json = lsp_json(lsp); | |
9d303b37 DL |
2708 | vty_out(vty, "%s\n", json_object_to_json_string_ext( |
2709 | json, JSON_C_TO_STRING_PRETTY)); | |
d62a17ae | 2710 | json_object_free(json); |
2711 | } else | |
2712 | lsp_print(lsp, (void *)vty); | |
3ab18ff2 | 2713 | } |
2714 | ||
2715 | /* | |
2716 | * Display MPLS label forwarding table (VTY command handler). | |
2717 | */ | |
d62a17ae | 2718 | void zebra_mpls_print_lsp_table(struct vty *vty, struct zebra_vrf *zvrf, |
d7c0a89a | 2719 | uint8_t use_json) |
d62a17ae | 2720 | { |
2721 | char buf[BUFSIZ]; | |
2722 | json_object *json = NULL; | |
2723 | zebra_lsp_t *lsp = NULL; | |
2724 | zebra_nhlfe_t *nhlfe = NULL; | |
2725 | struct nexthop *nexthop = NULL; | |
2726 | struct listnode *node = NULL; | |
2727 | struct list *lsp_list = hash_get_sorted_list(zvrf->lsp_table, lsp_cmp); | |
2728 | ||
2729 | if (use_json) { | |
2730 | json = json_object_new_object(); | |
2731 | ||
2732 | for (ALL_LIST_ELEMENTS_RO(lsp_list, node, lsp)) | |
2733 | json_object_object_add( | |
2734 | json, label2str(lsp->ile.in_label, buf, BUFSIZ), | |
2735 | lsp_json(lsp)); | |
2736 | ||
9d303b37 DL |
2737 | vty_out(vty, "%s\n", json_object_to_json_string_ext( |
2738 | json, JSON_C_TO_STRING_PRETTY)); | |
d62a17ae | 2739 | json_object_free(json); |
2740 | } else { | |
2741 | vty_out(vty, " Inbound Outbound\n"); | |
2742 | vty_out(vty, " Label Type Nexthop Label\n"); | |
2743 | vty_out(vty, "-------- ------- --------------- --------\n"); | |
2744 | ||
2745 | for (ALL_LIST_ELEMENTS_RO(lsp_list, node, lsp)) { | |
2746 | for (nhlfe = lsp->nhlfe_list; nhlfe; | |
2747 | nhlfe = nhlfe->next) { | |
2748 | vty_out(vty, "%8d %7s ", lsp->ile.in_label, | |
2749 | nhlfe_type2str(nhlfe->type)); | |
2750 | nexthop = nhlfe->nexthop; | |
2751 | ||
2752 | switch (nexthop->type) { | |
996c9314 | 2753 | case NEXTHOP_TYPE_IFINDEX: { |
86f07f44 | 2754 | struct zebra_ns *zns; |
b9abd9ad DS |
2755 | struct interface *ifp; |
2756 | ||
86f07f44 PG |
2757 | zns = zebra_ns_lookup(NS_DEFAULT); |
2758 | ifp = if_lookup_by_index_per_ns( | |
2759 | zns, | |
2760 | nexthop->ifindex); | |
b9abd9ad DS |
2761 | vty_out(vty, "%15s", ifp->name); |
2762 | break; | |
2763 | } | |
d62a17ae | 2764 | case NEXTHOP_TYPE_IPV4: |
2765 | case NEXTHOP_TYPE_IPV4_IFINDEX: | |
2766 | vty_out(vty, "%15s", | |
2767 | inet_ntoa(nexthop->gate.ipv4)); | |
2768 | break; | |
2769 | case NEXTHOP_TYPE_IPV6: | |
2770 | case NEXTHOP_TYPE_IPV6_IFINDEX: | |
2771 | vty_out(vty, "%15s", | |
2772 | inet_ntop(AF_INET6, | |
2773 | &nexthop->gate.ipv6, | |
2774 | buf, BUFSIZ)); | |
2775 | break; | |
2776 | default: | |
2777 | break; | |
2778 | } | |
2779 | ||
b9abd9ad | 2780 | if (nexthop->type != NEXTHOP_TYPE_IFINDEX) |
fc5cca9f DS |
2781 | vty_out(vty, " %8s\n", |
2782 | mpls_label2str( | |
2783 | nexthop->nh_label | |
2784 | ->num_labels, | |
2785 | &nexthop->nh_label | |
2786 | ->label[0], | |
2787 | buf, BUFSIZ, 1)); | |
b9abd9ad DS |
2788 | else |
2789 | vty_out(vty, "\n"); | |
d62a17ae | 2790 | } |
2791 | } | |
2792 | ||
2793 | vty_out(vty, "\n"); | |
2794 | } | |
2795 | ||
affe9e99 | 2796 | list_delete_and_null(&lsp_list); |
3ab18ff2 | 2797 | } |
2798 | ||
7758e3f3 | 2799 | /* |
2800 | * Display MPLS LSP configuration of all static LSPs (VTY command handler). | |
2801 | */ | |
d62a17ae | 2802 | int zebra_mpls_write_lsp_config(struct vty *vty, struct zebra_vrf *zvrf) |
2803 | { | |
2804 | zebra_slsp_t *slsp; | |
2805 | zebra_snhlfe_t *snhlfe; | |
2806 | struct listnode *node; | |
2807 | struct list *slsp_list = | |
2808 | hash_get_sorted_list(zvrf->slsp_table, slsp_cmp); | |
2809 | ||
2810 | for (ALL_LIST_ELEMENTS_RO(slsp_list, node, slsp)) { | |
2811 | for (snhlfe = slsp->snhlfe_list; snhlfe; | |
2812 | snhlfe = snhlfe->next) { | |
0af35d90 | 2813 | char buf[BUFSIZ]; |
d62a17ae | 2814 | char lstr[30]; |
2815 | ||
0af35d90 | 2816 | snhlfe2str(snhlfe, buf, sizeof(buf)); |
d62a17ae | 2817 | switch (snhlfe->out_label) { |
70e98a7f DS |
2818 | case MPLS_LABEL_IPV4_EXPLICIT_NULL: |
2819 | case MPLS_LABEL_IPV6_EXPLICIT_NULL: | |
d62a17ae | 2820 | strlcpy(lstr, "explicit-null", sizeof(lstr)); |
2821 | break; | |
70e98a7f | 2822 | case MPLS_LABEL_IMPLICIT_NULL: |
d62a17ae | 2823 | strlcpy(lstr, "implicit-null", sizeof(lstr)); |
2824 | break; | |
2825 | default: | |
2826 | sprintf(lstr, "%u", snhlfe->out_label); | |
2827 | break; | |
2828 | } | |
2829 | ||
2830 | vty_out(vty, "mpls lsp %u %s %s\n", slsp->ile.in_label, | |
2831 | buf, lstr); | |
2832 | } | |
2833 | } | |
b78b820d | 2834 | |
affe9e99 | 2835 | list_delete_and_null(&slsp_list); |
d62a17ae | 2836 | return (zvrf->slsp_table->count ? 1 : 0); |
7758e3f3 | 2837 | } |
2838 | ||
1b6d5c7e VV |
2839 | /* |
2840 | * Add/update global label block. | |
2841 | */ | |
d7c0a89a QY |
2842 | int zebra_mpls_label_block_add(struct zebra_vrf *zvrf, uint32_t start_label, |
2843 | uint32_t end_label) | |
1b6d5c7e | 2844 | { |
d62a17ae | 2845 | zvrf->mpls_srgb.start_label = start_label; |
2846 | zvrf->mpls_srgb.end_label = end_label; | |
28d58fd7 | 2847 | |
d62a17ae | 2848 | /* Evaluate registered FECs to see if any get a label or not. */ |
2849 | fec_evaluate(zvrf); | |
2850 | return 0; | |
1b6d5c7e VV |
2851 | } |
2852 | ||
2853 | /* | |
2854 | * Delete global label block. | |
2855 | */ | |
d62a17ae | 2856 | int zebra_mpls_label_block_del(struct zebra_vrf *zvrf) |
1b6d5c7e | 2857 | { |
d62a17ae | 2858 | zvrf->mpls_srgb.start_label = MPLS_DEFAULT_MIN_SRGB_LABEL; |
2859 | zvrf->mpls_srgb.end_label = MPLS_DEFAULT_MAX_SRGB_LABEL; | |
28d58fd7 | 2860 | |
d62a17ae | 2861 | /* Process registered FECs to clear their local label, if needed. */ |
2862 | fec_evaluate(zvrf); | |
2863 | return 0; | |
1b6d5c7e VV |
2864 | } |
2865 | ||
2866 | /* | |
2867 | * Display MPLS global label block configuration (VTY command handler). | |
2868 | */ | |
d62a17ae | 2869 | int zebra_mpls_write_label_block_config(struct vty *vty, struct zebra_vrf *zvrf) |
1b6d5c7e | 2870 | { |
d62a17ae | 2871 | if (zvrf->mpls_srgb.start_label == 0) |
2872 | return 0; | |
1b6d5c7e | 2873 | |
d62a17ae | 2874 | if ((zvrf->mpls_srgb.start_label != MPLS_DEFAULT_MIN_SRGB_LABEL) |
2875 | || (zvrf->mpls_srgb.end_label != MPLS_DEFAULT_MAX_SRGB_LABEL)) { | |
2876 | vty_out(vty, "mpls label global-block %u %u\n", | |
2877 | zvrf->mpls_srgb.start_label, zvrf->mpls_srgb.end_label); | |
2878 | } | |
1b6d5c7e | 2879 | |
d62a17ae | 2880 | return 1; |
1b6d5c7e VV |
2881 | } |
2882 | ||
84915b0a | 2883 | /* |
2884 | * Called when VRF becomes inactive, cleans up information but keeps | |
2885 | * the table itself. | |
2886 | * NOTE: Currently supported only for default VRF. | |
2887 | */ | |
2888 | void zebra_mpls_cleanup_tables(struct zebra_vrf *zvrf) | |
2889 | { | |
2890 | hash_iterate(zvrf->lsp_table, lsp_uninstall_from_kernel, NULL); | |
2891 | } | |
2892 | ||
40c7bdb0 | 2893 | /* |
2894 | * Called upon process exiting, need to delete LSP forwarding | |
2895 | * entries from the kernel. | |
2896 | * NOTE: Currently supported only for default VRF. | |
2897 | */ | |
d62a17ae | 2898 | void zebra_mpls_close_tables(struct zebra_vrf *zvrf) |
40c7bdb0 | 2899 | { |
d62a17ae | 2900 | hash_iterate(zvrf->lsp_table, lsp_uninstall_from_kernel, NULL); |
2901 | hash_clean(zvrf->lsp_table, NULL); | |
2902 | hash_free(zvrf->lsp_table); | |
2903 | hash_clean(zvrf->slsp_table, NULL); | |
2904 | hash_free(zvrf->slsp_table); | |
9b67b514 DS |
2905 | route_table_finish(zvrf->fec_table[AFI_IP]); |
2906 | route_table_finish(zvrf->fec_table[AFI_IP6]); | |
40c7bdb0 | 2907 | } |
2908 | ||
7758e3f3 | 2909 | /* |
2910 | * Allocate MPLS tables for this VRF and do other initialization. | |
2911 | * NOTE: Currently supported only for default VRF. | |
2912 | */ | |
d62a17ae | 2913 | void zebra_mpls_init_tables(struct zebra_vrf *zvrf) |
7758e3f3 | 2914 | { |
d62a17ae | 2915 | if (!zvrf) |
2916 | return; | |
996c9314 LB |
2917 | zvrf->slsp_table = |
2918 | hash_create(label_hash, label_cmp, "ZEBRA SLSP table"); | |
2919 | zvrf->lsp_table = hash_create(label_hash, label_cmp, "ZEBRA LSP table"); | |
d62a17ae | 2920 | zvrf->fec_table[AFI_IP] = route_table_init(); |
2921 | zvrf->fec_table[AFI_IP6] = route_table_init(); | |
2922 | zvrf->mpls_flags = 0; | |
2923 | zvrf->mpls_srgb.start_label = MPLS_DEFAULT_MIN_SRGB_LABEL; | |
2924 | zvrf->mpls_srgb.end_label = MPLS_DEFAULT_MAX_SRGB_LABEL; | |
7758e3f3 | 2925 | } |
2926 | ||
2927 | /* | |
2928 | * Global MPLS initialization. | |
2929 | */ | |
d62a17ae | 2930 | void zebra_mpls_init(void) |
7758e3f3 | 2931 | { |
d62a17ae | 2932 | mpls_enabled = 0; |
33c32282 | 2933 | |
d62a17ae | 2934 | if (mpls_kernel_init() < 0) { |
2935 | zlog_warn("Disabling MPLS support (no kernel support)"); | |
2936 | return; | |
2937 | } | |
fe6c7157 | 2938 | |
d62a17ae | 2939 | if (!mpls_processq_init(&zebrad)) |
2940 | mpls_enabled = 1; | |
453844ab | 2941 | |
21ccc0cf | 2942 | hook_register(zserv_client_close, zebra_mpls_cleanup_fecs_for_client); |
7758e3f3 | 2943 | } |