]>
Commit | Line | Data |
---|---|---|
fb018d25 DS |
1 | /* Zebra next hop tracking 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 | |
fb018d25 DS |
19 | */ |
20 | ||
21 | #include <zebra.h> | |
22 | ||
23 | #include "prefix.h" | |
24 | #include "table.h" | |
25 | #include "memory.h" | |
fb018d25 DS |
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" | |
b72ede27 | 37 | #include "vrf.h" |
fb018d25 DS |
38 | |
39 | #include "zebra/rib.h" | |
40 | #include "zebra/rt.h" | |
41 | #include "zebra/zserv.h" | |
fe18ee2d | 42 | #include "zebra/zebra_ns.h" |
7c551956 | 43 | #include "zebra/zebra_vrf.h" |
fb018d25 DS |
44 | #include "zebra/redistribute.h" |
45 | #include "zebra/debug.h" | |
46 | #include "zebra/zebra_rnh.h" | |
8902474b | 47 | #include "zebra/zebra_routemap.h" |
a815b788 | 48 | #include "zebra/interface.h" |
4a1ab8e4 | 49 | #include "zebra/zebra_memory.h" |
43e52561 | 50 | #include "zebra/zebra_errors.h" |
fb018d25 | 51 | |
d62a17ae | 52 | static void free_state(vrf_id_t vrf_id, struct route_entry *re, |
53 | struct route_node *rn); | |
f0f77c9a | 54 | static void copy_state(struct rnh *rnh, struct route_entry *re, |
078430f6 | 55 | struct route_node *rn); |
d62a17ae | 56 | #define lookup_rnh_table(v, f) \ |
57 | ({ \ | |
58 | struct zebra_vrf *zvrf; \ | |
59 | struct route_table *t = NULL; \ | |
60 | zvrf = zebra_vrf_lookup_by_id(v); \ | |
61 | if (zvrf) \ | |
62 | t = zvrf->rnh_table[family2afi(f)]; \ | |
63 | t; \ | |
64 | }) | |
b72ede27 | 65 | |
f0f77c9a | 66 | static int compare_state(struct route_entry *r1, struct route_entry *r2); |
7076bb2f | 67 | static int send_client(struct rnh *rnh, struct zserv *client, rnh_type_t type, |
d62a17ae | 68 | vrf_id_t vrf_id); |
fb018d25 | 69 | static void print_rnh(struct route_node *rn, struct vty *vty); |
453844ab | 70 | static int zebra_client_cleanup_rnh(struct zserv *client); |
fb018d25 | 71 | |
a50b580a DS |
72 | int zebra_rnh_ip_default_route = 0; |
73 | int zebra_rnh_ipv6_default_route = 0; | |
74 | ||
453844ab QY |
75 | void zebra_rnh_init(void) |
76 | { | |
21ccc0cf | 77 | hook_register(zserv_client_close, zebra_client_cleanup_rnh); |
453844ab QY |
78 | } |
79 | ||
b72ede27 | 80 | static inline struct route_table *get_rnh_table(vrf_id_t vrfid, int family, |
078430f6 DS |
81 | rnh_type_t type) |
82 | { | |
d62a17ae | 83 | struct zebra_vrf *zvrf; |
84 | struct route_table *t = NULL; | |
85 | ||
86 | zvrf = zebra_vrf_lookup_by_id(vrfid); | |
87 | if (zvrf) | |
88 | switch (type) { | |
89 | case RNH_NEXTHOP_TYPE: | |
90 | t = zvrf->rnh_table[family2afi(family)]; | |
91 | break; | |
92 | case RNH_IMPORT_CHECK_TYPE: | |
93 | t = zvrf->import_check_table[family2afi(family)]; | |
94 | break; | |
95 | } | |
96 | ||
97 | return t; | |
078430f6 DS |
98 | } |
99 | ||
d62a17ae | 100 | char *rnh_str(struct rnh *rnh, char *buf, int size) |
fb018d25 | 101 | { |
d62a17ae | 102 | prefix2str(&(rnh->node->p), buf, size); |
103 | return buf; | |
fb018d25 DS |
104 | } |
105 | ||
d62a17ae | 106 | struct rnh *zebra_add_rnh(struct prefix *p, vrf_id_t vrfid, rnh_type_t type) |
fb018d25 | 107 | { |
d62a17ae | 108 | struct route_table *table; |
109 | struct route_node *rn; | |
110 | struct rnh *rnh = NULL; | |
111 | char buf[PREFIX2STR_BUFFER]; | |
112 | ||
113 | if (IS_ZEBRA_DEBUG_NHT) { | |
114 | prefix2str(p, buf, sizeof(buf)); | |
115 | zlog_debug("%u: Add RNH %s type %d", vrfid, buf, type); | |
116 | } | |
117 | table = get_rnh_table(vrfid, PREFIX_FAMILY(p), type); | |
118 | if (!table) { | |
119 | prefix2str(p, buf, sizeof(buf)); | |
120 | zlog_warn("%u: Add RNH %s type %d - table not found", vrfid, | |
121 | buf, type); | |
122 | return NULL; | |
123 | } | |
124 | ||
125 | /* Make it sure prefixlen is applied to the prefix. */ | |
126 | apply_mask(p); | |
127 | ||
128 | /* Lookup (or add) route node.*/ | |
129 | rn = route_node_get(table, p); | |
130 | ||
131 | if (!rn->info) { | |
132 | rnh = XCALLOC(MTYPE_RNH, sizeof(struct rnh)); | |
133 | rnh->client_list = list_new(); | |
134 | rnh->vrf_id = vrfid; | |
731a75fe | 135 | rnh->zebra_pseudowire_list = list_new(); |
d62a17ae | 136 | route_lock_node(rn); |
137 | rn->info = rnh; | |
138 | rnh->node = rn; | |
139 | } | |
140 | ||
141 | route_unlock_node(rn); | |
142 | return (rn->info); | |
fb018d25 DS |
143 | } |
144 | ||
d62a17ae | 145 | struct rnh *zebra_lookup_rnh(struct prefix *p, vrf_id_t vrfid, rnh_type_t type) |
fb018d25 | 146 | { |
d62a17ae | 147 | struct route_table *table; |
148 | struct route_node *rn; | |
fb018d25 | 149 | |
d62a17ae | 150 | table = get_rnh_table(vrfid, PREFIX_FAMILY(p), type); |
151 | if (!table) | |
152 | return NULL; | |
fb018d25 | 153 | |
d62a17ae | 154 | /* Make it sure prefixlen is applied to the prefix. */ |
155 | apply_mask(p); | |
fb018d25 | 156 | |
d62a17ae | 157 | /* Lookup route node.*/ |
158 | rn = route_node_lookup(table, p); | |
159 | if (!rn) | |
160 | return NULL; | |
fb018d25 | 161 | |
d62a17ae | 162 | route_unlock_node(rn); |
163 | return (rn->info); | |
fb018d25 DS |
164 | } |
165 | ||
d62a17ae | 166 | void zebra_free_rnh(struct rnh *rnh) |
5a8dfcd8 | 167 | { |
d62a17ae | 168 | rnh->flags |= ZEBRA_NHT_DELETED; |
acdf5e25 | 169 | list_delete_and_null(&rnh->client_list); |
acdf5e25 | 170 | list_delete_and_null(&rnh->zebra_pseudowire_list); |
d62a17ae | 171 | free_state(rnh->vrf_id, rnh->state, rnh->node); |
172 | XFREE(MTYPE_RNH, rnh); | |
5a8dfcd8 RW |
173 | } |
174 | ||
d62a17ae | 175 | void zebra_delete_rnh(struct rnh *rnh, rnh_type_t type) |
fb018d25 | 176 | { |
d62a17ae | 177 | struct route_node *rn; |
fb018d25 | 178 | |
d62a17ae | 179 | if (!rnh || (rnh->flags & ZEBRA_NHT_DELETED) || !(rn = rnh->node)) |
180 | return; | |
fb018d25 | 181 | |
d62a17ae | 182 | if (IS_ZEBRA_DEBUG_NHT) { |
183 | char buf[PREFIX2STR_BUFFER]; | |
184 | zlog_debug("%u: Del RNH %s type %d", rnh->vrf_id, | |
185 | rnh_str(rnh, buf, sizeof(buf)), type); | |
186 | } | |
fb018d25 | 187 | |
d62a17ae | 188 | zebra_free_rnh(rnh); |
189 | rn->info = NULL; | |
190 | route_unlock_node(rn); | |
fb018d25 DS |
191 | } |
192 | ||
d62a17ae | 193 | void zebra_add_rnh_client(struct rnh *rnh, struct zserv *client, |
194 | rnh_type_t type, vrf_id_t vrf_id) | |
fb018d25 | 195 | { |
d62a17ae | 196 | if (IS_ZEBRA_DEBUG_NHT) { |
197 | char buf[PREFIX2STR_BUFFER]; | |
198 | zlog_debug("%u: Client %s registers for RNH %s type %d", vrf_id, | |
199 | zebra_route_string(client->proto), | |
200 | rnh_str(rnh, buf, sizeof(buf)), type); | |
201 | } | |
202 | if (!listnode_lookup(rnh->client_list, client)) { | |
203 | listnode_add(rnh->client_list, client); | |
204 | send_client(rnh, client, type, | |
205 | vrf_id); // Pending: check if its needed | |
206 | } | |
fb018d25 DS |
207 | } |
208 | ||
d62a17ae | 209 | void zebra_remove_rnh_client(struct rnh *rnh, struct zserv *client, |
210 | rnh_type_t type) | |
fb018d25 | 211 | { |
d62a17ae | 212 | if (IS_ZEBRA_DEBUG_NHT) { |
213 | char buf[PREFIX2STR_BUFFER]; | |
214 | zlog_debug("Client %s unregisters for RNH %s type %d", | |
215 | zebra_route_string(client->proto), | |
216 | rnh_str(rnh, buf, sizeof(buf)), type); | |
217 | } | |
218 | listnode_delete(rnh->client_list, client); | |
219 | if (list_isempty(rnh->client_list) | |
731a75fe | 220 | && list_isempty(rnh->zebra_pseudowire_list)) |
d62a17ae | 221 | zebra_delete_rnh(rnh, type); |
6e26278c DS |
222 | } |
223 | ||
731a75fe RW |
224 | /* XXX move this utility function elsewhere? */ |
225 | static void addr2hostprefix(int af, const union g_addr *addr, | |
226 | struct prefix *prefix) | |
227 | { | |
228 | switch (af) { | |
229 | case AF_INET: | |
230 | prefix->family = AF_INET; | |
231 | prefix->prefixlen = IPV4_MAX_BITLEN; | |
232 | prefix->u.prefix4 = addr->ipv4; | |
233 | break; | |
234 | case AF_INET6: | |
235 | prefix->family = AF_INET6; | |
236 | prefix->prefixlen = IPV6_MAX_BITLEN; | |
237 | prefix->u.prefix6 = addr->ipv6; | |
238 | break; | |
239 | default: | |
c31a793b | 240 | memset(prefix, 0, sizeof(*prefix)); |
731a75fe RW |
241 | zlog_warn("%s: unknown address family %d", __func__, af); |
242 | break; | |
243 | } | |
244 | } | |
245 | ||
246 | void zebra_register_rnh_pseudowire(vrf_id_t vrf_id, struct zebra_pw *pw) | |
247 | { | |
248 | struct prefix nh; | |
249 | struct rnh *rnh; | |
250 | ||
251 | addr2hostprefix(pw->af, &pw->nexthop, &nh); | |
252 | rnh = zebra_add_rnh(&nh, vrf_id, RNH_NEXTHOP_TYPE); | |
253 | if (rnh && !listnode_lookup(rnh->zebra_pseudowire_list, pw)) { | |
254 | listnode_add(rnh->zebra_pseudowire_list, pw); | |
255 | pw->rnh = rnh; | |
256 | zebra_evaluate_rnh(vrf_id, pw->af, 1, RNH_NEXTHOP_TYPE, &nh); | |
257 | } | |
258 | } | |
259 | ||
260 | void zebra_deregister_rnh_pseudowire(vrf_id_t vrf_id, struct zebra_pw *pw) | |
261 | { | |
262 | struct rnh *rnh; | |
263 | ||
264 | rnh = pw->rnh; | |
265 | if (!rnh) | |
266 | return; | |
267 | ||
268 | listnode_delete(rnh->zebra_pseudowire_list, pw); | |
269 | pw->rnh = NULL; | |
270 | ||
271 | if (list_isempty(rnh->client_list) | |
731a75fe RW |
272 | && list_isempty(rnh->zebra_pseudowire_list)) |
273 | zebra_delete_rnh(rnh, RNH_NEXTHOP_TYPE); | |
274 | } | |
275 | ||
d50b5bdd | 276 | /* Apply the NHT route-map for a client to the route (and nexthops) |
277 | * resolving a NH. | |
278 | */ | |
d62a17ae | 279 | static int zebra_rnh_apply_nht_rmap(int family, struct route_node *prn, |
280 | struct route_entry *re, int proto) | |
6e26278c | 281 | { |
d62a17ae | 282 | int at_least_one = 0; |
283 | int rmap_family; /* Route map has diff AF family enum */ | |
284 | struct nexthop *nexthop; | |
285 | int ret; | |
286 | ||
287 | rmap_family = (family == AF_INET) ? AFI_IP : AFI_IP6; | |
288 | ||
289 | if (prn && re) { | |
7ee30f28 DS |
290 | for (nexthop = re->ng.nexthop; nexthop; |
291 | nexthop = nexthop->next) { | |
d62a17ae | 292 | ret = zebra_nht_route_map_check(rmap_family, proto, |
293 | &prn->p, re, nexthop); | |
294 | if (ret != RMAP_DENYMATCH) { | |
295 | SET_FLAG(nexthop->flags, NEXTHOP_FLAG_ACTIVE); | |
296 | at_least_one++; /* at least one valid NH */ | |
297 | } else { | |
298 | UNSET_FLAG(nexthop->flags, NEXTHOP_FLAG_ACTIVE); | |
299 | } | |
300 | } | |
6e26278c | 301 | } |
d62a17ae | 302 | return (at_least_one); |
6e26278c DS |
303 | } |
304 | ||
d50b5bdd | 305 | /* |
fd7fd9e5 DS |
306 | * Determine appropriate route (RE entry) resolving a tracked BGP route |
307 | * for BGP route for import. | |
d50b5bdd | 308 | */ |
996c9314 LB |
309 | static struct route_entry * |
310 | zebra_rnh_resolve_import_entry(vrf_id_t vrfid, int family, | |
311 | struct route_node *nrn, struct rnh *rnh, | |
312 | struct route_node **prn) | |
fb018d25 | 313 | { |
d62a17ae | 314 | struct route_table *route_table; |
315 | struct route_node *rn; | |
316 | struct route_entry *re; | |
317 | ||
318 | *prn = NULL; | |
319 | ||
320 | route_table = zebra_vrf_table(family2afi(family), SAFI_UNICAST, vrfid); | |
321 | if (!route_table) // unexpected | |
322 | return NULL; | |
323 | ||
324 | rn = route_node_match(route_table, &nrn->p); | |
325 | if (!rn) | |
326 | return NULL; | |
327 | ||
fd7fd9e5 DS |
328 | /* Unlock route node - we don't need to lock when walking the tree. */ |
329 | route_unlock_node(rn); | |
330 | ||
996c9314 LB |
331 | if (CHECK_FLAG(rnh->flags, ZEBRA_NHT_EXACT_MATCH) |
332 | && !prefix_same(&nrn->p, &rn->p)) | |
fd7fd9e5 | 333 | return NULL; |
d62a17ae | 334 | |
fd7fd9e5 | 335 | /* Identify appropriate route entry. */ |
996c9314 LB |
336 | RNODE_FOREACH_RE (rn, re) { |
337 | if (!CHECK_FLAG(re->status, ROUTE_ENTRY_REMOVED) | |
338 | && CHECK_FLAG(re->flags, ZEBRA_FLAG_SELECTED) | |
339 | && (re->type != ZEBRA_ROUTE_BGP)) | |
fd7fd9e5 | 340 | break; |
d62a17ae | 341 | } |
342 | ||
d62a17ae | 343 | if (re) |
344 | *prn = rn; | |
345 | return re; | |
d50b5bdd | 346 | } |
347 | ||
348 | /* | |
349 | * See if a tracked route entry for import (by BGP) has undergone any | |
350 | * change, and if so, notify the client. | |
351 | */ | |
d62a17ae | 352 | static void zebra_rnh_eval_import_check_entry(vrf_id_t vrfid, int family, |
353 | int force, struct route_node *nrn, | |
354 | struct rnh *rnh, | |
355 | struct route_entry *re) | |
d50b5bdd | 356 | { |
d62a17ae | 357 | int state_changed = 0; |
358 | struct zserv *client; | |
359 | char bufn[INET6_ADDRSTRLEN]; | |
360 | struct listnode *node; | |
361 | struct nexthop *nexthop; | |
362 | ||
363 | if (re && (rnh->state == NULL)) { | |
7ee30f28 | 364 | for (ALL_NEXTHOPS(re->ng, nexthop)) |
d62a17ae | 365 | if (CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_FIB)) { |
366 | state_changed = 1; | |
367 | break; | |
368 | } | |
369 | } else if (!re && (rnh->state != NULL)) | |
370 | state_changed = 1; | |
371 | ||
372 | if (compare_state(re, rnh->state)) | |
373 | copy_state(rnh, re, nrn); | |
374 | ||
375 | if (state_changed || force) { | |
376 | if (IS_ZEBRA_DEBUG_NHT) { | |
377 | prefix2str(&nrn->p, bufn, INET6_ADDRSTRLEN); | |
378 | zlog_debug("%u:%s: Route import check %s %s\n", vrfid, | |
379 | bufn, rnh->state ? "passed" : "failed", | |
380 | state_changed ? "(state changed)" : ""); | |
381 | } | |
382 | /* state changed, notify clients */ | |
383 | for (ALL_LIST_ELEMENTS_RO(rnh->client_list, node, client)) { | |
384 | send_client(rnh, client, RNH_IMPORT_CHECK_TYPE, vrfid); | |
385 | } | |
386 | } | |
d50b5bdd | 387 | } |
fb018d25 | 388 | |
d50b5bdd | 389 | /* |
390 | * Notify clients registered for this nexthop about a change. | |
391 | */ | |
d62a17ae | 392 | static void zebra_rnh_notify_protocol_clients(vrf_id_t vrfid, int family, |
393 | struct route_node *nrn, | |
394 | struct rnh *rnh, | |
395 | struct route_node *prn, | |
396 | struct route_entry *re) | |
d50b5bdd | 397 | { |
d62a17ae | 398 | struct listnode *node; |
399 | struct zserv *client; | |
400 | char bufn[INET6_ADDRSTRLEN]; | |
401 | char bufp[INET6_ADDRSTRLEN]; | |
402 | int num_resolving_nh; | |
403 | ||
404 | if (IS_ZEBRA_DEBUG_NHT) { | |
405 | prefix2str(&nrn->p, bufn, INET6_ADDRSTRLEN); | |
406 | if (prn && re) { | |
407 | prefix2str(&prn->p, bufp, INET6_ADDRSTRLEN); | |
408 | zlog_debug("%u:%s: NH resolved over route %s", vrfid, | |
409 | bufn, bufp); | |
410 | } else | |
411 | zlog_debug("%u:%s: NH has become unresolved", vrfid, | |
412 | bufn); | |
413 | } | |
414 | ||
415 | for (ALL_LIST_ELEMENTS_RO(rnh->client_list, node, client)) { | |
416 | if (prn && re) { | |
417 | /* Apply route-map for this client to route resolving | |
418 | * this | |
419 | * nexthop to see if it is filtered or not. | |
420 | */ | |
421 | num_resolving_nh = zebra_rnh_apply_nht_rmap( | |
422 | family, prn, re, client->proto); | |
423 | if (num_resolving_nh) | |
424 | rnh->filtered[client->proto] = 0; | |
425 | else | |
426 | rnh->filtered[client->proto] = 1; | |
427 | ||
428 | if (IS_ZEBRA_DEBUG_NHT) | |
429 | zlog_debug( | |
430 | "%u:%s: Notifying client %s about NH %s", | |
431 | vrfid, bufn, | |
432 | zebra_route_string(client->proto), | |
433 | num_resolving_nh | |
434 | ? "" | |
435 | : "(filtered by route-map)"); | |
436 | } else { | |
437 | rnh->filtered[client->proto] = 0; | |
438 | if (IS_ZEBRA_DEBUG_NHT) | |
439 | zlog_debug( | |
440 | "%u:%s: Notifying client %s about NH (unreachable)", | |
441 | vrfid, bufn, | |
442 | zebra_route_string(client->proto)); | |
443 | } | |
444 | ||
445 | send_client(rnh, client, RNH_NEXTHOP_TYPE, vrfid); | |
446 | } | |
d50b5bdd | 447 | } |
078430f6 | 448 | |
d61d5d88 DS |
449 | static void zebra_rnh_process_pbr_tables(int family, |
450 | struct route_node *nrn, | |
451 | struct rnh *rnh, | |
452 | struct route_node *prn, | |
453 | struct route_entry *re) | |
454 | { | |
455 | struct zebra_ns_table *znst; | |
456 | struct route_entry *o_re; | |
457 | struct route_node *o_rn; | |
458 | struct listnode *node; | |
459 | struct zserv *client; | |
460 | struct zebra_ns *zns; | |
461 | afi_t afi = AFI_IP; | |
462 | ||
463 | if (family == AF_INET6) | |
464 | afi = AFI_IP6; | |
465 | ||
466 | /* | |
467 | * We are only concerned about nexthops that change for | |
468 | * anyone using PBR | |
469 | */ | |
470 | for (ALL_LIST_ELEMENTS_RO(rnh->client_list, node, client)) { | |
471 | if (client->proto == ZEBRA_ROUTE_PBR) | |
472 | break; | |
473 | } | |
474 | ||
475 | if (!client) | |
476 | return; | |
477 | ||
478 | zns = zebra_ns_lookup(NS_DEFAULT); | |
479 | RB_FOREACH (znst, zebra_ns_table_head, &zns->ns_tables) { | |
480 | if (afi != znst->afi) | |
481 | continue; | |
482 | ||
483 | for (o_rn = route_top(znst->table); | |
484 | o_rn; o_rn = srcdest_route_next(o_rn)) { | |
485 | RNODE_FOREACH_RE (o_rn, o_re) { | |
486 | if (o_re->type == ZEBRA_ROUTE_PBR) | |
487 | break; | |
488 | ||
489 | } | |
490 | ||
491 | /* | |
492 | * If we have a PBR route and a nexthop changes | |
493 | * just rethink it. Yes this is a hammer, but | |
494 | * a small one | |
495 | */ | |
4d96fd9f DS |
496 | if (o_re) { |
497 | SET_FLAG(o_re->status, ROUTE_ENTRY_CHANGED); | |
d61d5d88 | 498 | rib_queue_add(o_rn); |
4d96fd9f | 499 | } |
d61d5d88 DS |
500 | } |
501 | } | |
502 | } | |
503 | ||
fd7fd9e5 DS |
504 | /* |
505 | * Determine appropriate route (route entry) resolving a tracked | |
506 | * nexthop. | |
507 | */ | |
996c9314 LB |
508 | static struct route_entry * |
509 | zebra_rnh_resolve_nexthop_entry(vrf_id_t vrfid, int family, | |
510 | struct route_node *nrn, struct rnh *rnh, | |
511 | struct route_node **prn) | |
fd7fd9e5 DS |
512 | { |
513 | struct route_table *route_table; | |
514 | struct route_node *rn; | |
515 | struct route_entry *re; | |
516 | ||
517 | *prn = NULL; | |
518 | ||
519 | route_table = zebra_vrf_table(family2afi(family), SAFI_UNICAST, vrfid); | |
520 | if (!route_table) | |
521 | return NULL; | |
522 | ||
523 | rn = route_node_match(route_table, &nrn->p); | |
524 | if (!rn) | |
525 | return NULL; | |
526 | ||
527 | /* Unlock route node - we don't need to lock when walking the tree. */ | |
528 | route_unlock_node(rn); | |
529 | ||
530 | /* While resolving nexthops, we may need to walk up the tree from the | |
531 | * most-specific match. Do similar logic as in zebra_rib.c | |
532 | */ | |
533 | while (rn) { | |
534 | /* Do not resolve over default route unless allowed && | |
535 | * match route to be exact if so specified | |
536 | */ | |
996c9314 LB |
537 | if (is_default_prefix(&rn->p) |
538 | && !rnh_resolve_via_default(rn->p.family)) | |
fd7fd9e5 DS |
539 | return NULL; |
540 | ||
541 | /* Identify appropriate route entry. */ | |
996c9314 | 542 | RNODE_FOREACH_RE (rn, re) { |
fd7fd9e5 DS |
543 | if (CHECK_FLAG(re->status, ROUTE_ENTRY_REMOVED)) |
544 | continue; | |
545 | if (!CHECK_FLAG(re->flags, ZEBRA_FLAG_SELECTED)) | |
546 | continue; | |
547 | ||
548 | if (CHECK_FLAG(rnh->flags, ZEBRA_NHT_CONNECTED)) { | |
549 | if ((re->type == ZEBRA_ROUTE_CONNECT) | |
550 | || (re->type == ZEBRA_ROUTE_STATIC)) | |
551 | break; | |
552 | if (re->type == ZEBRA_ROUTE_NHRP) { | |
553 | struct nexthop *nexthop; | |
554 | ||
7ee30f28 | 555 | for (nexthop = re->ng.nexthop; nexthop; |
fd7fd9e5 DS |
556 | nexthop = nexthop->next) |
557 | if (nexthop->type | |
996c9314 | 558 | == NEXTHOP_TYPE_IFINDEX) |
fd7fd9e5 DS |
559 | break; |
560 | if (nexthop) | |
561 | break; | |
562 | } | |
563 | } else | |
564 | break; | |
565 | } | |
566 | ||
567 | /* Route entry found, we're done; else, walk up the tree. */ | |
568 | if (re) { | |
569 | *prn = rn; | |
570 | return re; | |
571 | } | |
572 | ||
573 | if (CHECK_FLAG(rnh->flags, ZEBRA_NHT_CONNECTED)) | |
574 | rn = rn->parent; | |
575 | else | |
576 | return NULL; | |
577 | } | |
578 | ||
579 | return NULL; | |
580 | } | |
581 | ||
731a75fe RW |
582 | static void zebra_rnh_process_pseudowires(vrf_id_t vrfid, struct rnh *rnh) |
583 | { | |
584 | struct zebra_pw *pw; | |
585 | struct listnode *node; | |
586 | ||
587 | for (ALL_LIST_ELEMENTS_RO(rnh->zebra_pseudowire_list, node, pw)) | |
588 | zebra_pw_update(pw); | |
589 | } | |
590 | ||
d50b5bdd | 591 | /* |
592 | * See if a tracked nexthop entry has undergone any change, and if so, | |
593 | * take appropriate action; this involves notifying any clients and/or | |
594 | * scheduling dependent static routes for processing. | |
595 | */ | |
d62a17ae | 596 | static void zebra_rnh_eval_nexthop_entry(vrf_id_t vrfid, int family, int force, |
597 | struct route_node *nrn, | |
598 | struct rnh *rnh, | |
599 | struct route_node *prn, | |
600 | struct route_entry *re) | |
d50b5bdd | 601 | { |
d62a17ae | 602 | int state_changed = 0; |
603 | ||
604 | /* If we're resolving over a different route, resolution has changed or | |
605 | * the resolving route has some change (e.g., metric), there is a state | |
606 | * change. | |
607 | */ | |
608 | if (!prefix_same(&rnh->resolved_route, &prn->p)) { | |
609 | if (prn) | |
610 | prefix_copy(&rnh->resolved_route, &prn->p); | |
611 | else | |
612 | memset(&rnh->resolved_route, 0, sizeof(struct prefix)); | |
613 | ||
614 | copy_state(rnh, re, nrn); | |
615 | state_changed = 1; | |
616 | } else if (compare_state(re, rnh->state)) { | |
617 | copy_state(rnh, re, nrn); | |
618 | state_changed = 1; | |
619 | } | |
620 | ||
621 | if (state_changed || force) { | |
622 | /* NOTE: Use the "copy" of resolving route stored in 'rnh' i.e., | |
623 | * rnh->state. | |
624 | */ | |
625 | /* Notify registered protocol clients. */ | |
626 | zebra_rnh_notify_protocol_clients(vrfid, family, nrn, rnh, prn, | |
627 | rnh->state); | |
628 | ||
d61d5d88 DS |
629 | zebra_rnh_process_pbr_tables(family, nrn, rnh, prn, |
630 | rnh->state); | |
631 | ||
731a75fe RW |
632 | /* Process pseudowires attached to this nexthop */ |
633 | zebra_rnh_process_pseudowires(vrfid, rnh); | |
d62a17ae | 634 | } |
d50b5bdd | 635 | } |
6e26278c | 636 | |
d50b5bdd | 637 | /* Evaluate one tracked entry */ |
d62a17ae | 638 | static void zebra_rnh_evaluate_entry(vrf_id_t vrfid, int family, int force, |
639 | rnh_type_t type, struct route_node *nrn) | |
d50b5bdd | 640 | { |
d62a17ae | 641 | struct rnh *rnh; |
642 | struct route_entry *re; | |
643 | struct route_node *prn; | |
644 | char bufn[INET6_ADDRSTRLEN]; | |
645 | ||
646 | if (IS_ZEBRA_DEBUG_NHT) { | |
647 | prefix2str(&nrn->p, bufn, INET6_ADDRSTRLEN); | |
648 | zlog_debug("%u:%s: Evaluate RNH, type %d %s", vrfid, bufn, type, | |
649 | force ? "(force)" : ""); | |
650 | } | |
651 | ||
652 | rnh = nrn->info; | |
653 | ||
654 | /* Identify route entry (RE) resolving this tracked entry. */ | |
fd7fd9e5 | 655 | if (type == RNH_IMPORT_CHECK_TYPE) |
996c9314 LB |
656 | re = zebra_rnh_resolve_import_entry(vrfid, family, nrn, rnh, |
657 | &prn); | |
fd7fd9e5 DS |
658 | else |
659 | re = zebra_rnh_resolve_nexthop_entry(vrfid, family, nrn, rnh, | |
660 | &prn); | |
d62a17ae | 661 | |
662 | /* If the entry cannot be resolved and that is also the existing state, | |
663 | * there is nothing further to do. | |
664 | */ | |
665 | if (!re && rnh->state == NULL && !force) | |
666 | return; | |
667 | ||
668 | /* Process based on type of entry. */ | |
669 | if (type == RNH_IMPORT_CHECK_TYPE) | |
670 | zebra_rnh_eval_import_check_entry(vrfid, family, force, nrn, | |
671 | rnh, re); | |
672 | else | |
673 | zebra_rnh_eval_nexthop_entry(vrfid, family, force, nrn, rnh, | |
674 | prn, re); | |
d50b5bdd | 675 | } |
676 | ||
8ce5e6a3 | 677 | /* |
f0f77c9a DS |
678 | * Clear the ROUTE_ENTRY_NEXTHOPS_CHANGED flag |
679 | * from the re entries. | |
8ce5e6a3 DS |
680 | * |
681 | * Please note we are doing this *after* we have | |
682 | * notified the world about each nexthop as that | |
f0f77c9a | 683 | * we can have a situation where one re entry |
8ce5e6a3 DS |
684 | * covers multiple nexthops we are interested in. |
685 | */ | |
d62a17ae | 686 | static void zebra_rnh_clear_nhc_flag(vrf_id_t vrfid, int family, |
687 | rnh_type_t type, struct route_node *nrn) | |
8ce5e6a3 | 688 | { |
d62a17ae | 689 | struct rnh *rnh; |
690 | struct route_entry *re; | |
691 | struct route_node *prn; | |
8ce5e6a3 | 692 | |
d62a17ae | 693 | rnh = nrn->info; |
8ce5e6a3 | 694 | |
fd7fd9e5 DS |
695 | /* Identify route entry (RIB) resolving this tracked entry. */ |
696 | if (type == RNH_IMPORT_CHECK_TYPE) | |
996c9314 LB |
697 | re = zebra_rnh_resolve_import_entry(vrfid, family, nrn, rnh, |
698 | &prn); | |
fd7fd9e5 DS |
699 | else |
700 | re = zebra_rnh_resolve_nexthop_entry(vrfid, family, nrn, rnh, | |
701 | &prn); | |
8ce5e6a3 | 702 | |
332ad713 | 703 | if (re) { |
d62a17ae | 704 | UNSET_FLAG(re->status, ROUTE_ENTRY_NEXTHOPS_CHANGED); |
332ad713 RW |
705 | UNSET_FLAG(re->status, ROUTE_ENTRY_LABELS_CHANGED); |
706 | } | |
8ce5e6a3 | 707 | } |
d50b5bdd | 708 | |
709 | /* Evaluate all tracked entries (nexthops or routes for import into BGP) | |
710 | * of a particular VRF and address-family or a specific prefix. | |
711 | */ | |
d62a17ae | 712 | void zebra_evaluate_rnh(vrf_id_t vrfid, int family, int force, rnh_type_t type, |
713 | struct prefix *p) | |
d50b5bdd | 714 | { |
d62a17ae | 715 | struct route_table *rnh_table; |
716 | struct route_node *nrn; | |
717 | ||
718 | rnh_table = get_rnh_table(vrfid, family, type); | |
719 | if (!rnh_table) // unexpected | |
720 | return; | |
721 | ||
722 | if (p) { | |
723 | /* Evaluating a specific entry, make sure it exists. */ | |
724 | nrn = route_node_lookup(rnh_table, p); | |
725 | if (nrn && nrn->info) | |
726 | zebra_rnh_evaluate_entry(vrfid, family, force, type, | |
727 | nrn); | |
728 | ||
729 | if (nrn) | |
730 | route_unlock_node(nrn); | |
731 | } else { | |
732 | /* Evaluate entire table. */ | |
733 | nrn = route_top(rnh_table); | |
734 | while (nrn) { | |
735 | if (nrn->info) | |
736 | zebra_rnh_evaluate_entry(vrfid, family, force, | |
737 | type, nrn); | |
738 | nrn = route_next(nrn); /* this will also unlock nrn */ | |
739 | } | |
740 | nrn = route_top(rnh_table); | |
741 | while (nrn) { | |
742 | if (nrn->info) | |
743 | zebra_rnh_clear_nhc_flag(vrfid, family, type, | |
744 | nrn); | |
745 | nrn = route_next(nrn); /* this will also unlock nrn */ | |
746 | } | |
747 | } | |
fb018d25 DS |
748 | } |
749 | ||
d62a17ae | 750 | void zebra_print_rnh_table(vrf_id_t vrfid, int af, struct vty *vty, |
751 | rnh_type_t type) | |
fb018d25 | 752 | { |
d62a17ae | 753 | struct route_table *table; |
754 | struct route_node *rn; | |
755 | ||
756 | table = get_rnh_table(vrfid, af, type); | |
757 | if (!table) { | |
758 | zlog_debug("print_rnhs: rnh table not found\n"); | |
759 | return; | |
760 | } | |
761 | ||
762 | for (rn = route_top(table); rn; rn = route_next(rn)) | |
763 | if (rn->info) | |
764 | print_rnh(rn, vty); | |
fb018d25 DS |
765 | } |
766 | ||
fb018d25 | 767 | /** |
f0f77c9a | 768 | * free_state - free up the re structure associated with the rnh. |
fb018d25 | 769 | */ |
d62a17ae | 770 | static void free_state(vrf_id_t vrf_id, struct route_entry *re, |
771 | struct route_node *rn) | |
fb018d25 | 772 | { |
fb018d25 | 773 | |
d62a17ae | 774 | if (!re) |
775 | return; | |
fb018d25 | 776 | |
d62a17ae | 777 | /* free RE and nexthops */ |
7ee30f28 | 778 | nexthops_free(re->ng.nexthop); |
d62a17ae | 779 | XFREE(MTYPE_RE, re); |
fb018d25 DS |
780 | } |
781 | ||
d62a17ae | 782 | static void copy_state(struct rnh *rnh, struct route_entry *re, |
783 | struct route_node *rn) | |
fb018d25 | 784 | { |
d62a17ae | 785 | struct route_entry *state; |
fb018d25 | 786 | |
d62a17ae | 787 | if (rnh->state) { |
788 | free_state(rnh->vrf_id, rnh->state, rn); | |
789 | rnh->state = NULL; | |
790 | } | |
fb018d25 | 791 | |
d62a17ae | 792 | if (!re) |
793 | return; | |
fb018d25 | 794 | |
d62a17ae | 795 | state = XCALLOC(MTYPE_RE, sizeof(struct route_entry)); |
796 | state->type = re->type; | |
7733c6c4 | 797 | state->distance = re->distance; |
d62a17ae | 798 | state->metric = re->metric; |
8f43b4d8 | 799 | state->vrf_id = re->vrf_id; |
fb018d25 | 800 | |
7ee30f28 | 801 | route_entry_copy_nexthops(state, re->ng.nexthop); |
d62a17ae | 802 | rnh->state = state; |
fb018d25 DS |
803 | } |
804 | ||
d62a17ae | 805 | static int compare_state(struct route_entry *r1, struct route_entry *r2) |
fb018d25 | 806 | { |
fb018d25 | 807 | |
d62a17ae | 808 | if (!r1 && !r2) |
809 | return 0; | |
fb018d25 | 810 | |
d62a17ae | 811 | if ((!r1 && r2) || (r1 && !r2)) |
812 | return 1; | |
fb018d25 | 813 | |
7733c6c4 JB |
814 | if (r1->distance != r2->distance) |
815 | return 1; | |
816 | ||
d62a17ae | 817 | if (r1->metric != r2->metric) |
818 | return 1; | |
fb018d25 | 819 | |
d62a17ae | 820 | if (r1->nexthop_num != r2->nexthop_num) |
821 | return 1; | |
fb018d25 | 822 | |
332ad713 RW |
823 | if (CHECK_FLAG(r1->status, ROUTE_ENTRY_NEXTHOPS_CHANGED) |
824 | || CHECK_FLAG(r1->status, ROUTE_ENTRY_LABELS_CHANGED)) | |
d62a17ae | 825 | return 1; |
fb018d25 | 826 | |
d62a17ae | 827 | return 0; |
fb018d25 DS |
828 | } |
829 | ||
d62a17ae | 830 | static int send_client(struct rnh *rnh, struct zserv *client, rnh_type_t type, |
831 | vrf_id_t vrf_id) | |
fb018d25 | 832 | { |
d62a17ae | 833 | struct stream *s; |
834 | struct route_entry *re; | |
835 | unsigned long nump; | |
d7c0a89a | 836 | uint8_t num; |
0acf4df0 | 837 | struct nexthop *nh; |
d62a17ae | 838 | struct route_node *rn; |
839 | int cmd = (type == RNH_IMPORT_CHECK_TYPE) ? ZEBRA_IMPORT_CHECK_UPDATE | |
840 | : ZEBRA_NEXTHOP_UPDATE; | |
841 | ||
842 | rn = rnh->node; | |
843 | re = rnh->state; | |
844 | ||
845 | /* Get output stream. */ | |
1002497a | 846 | s = stream_new(ZEBRA_MAX_PACKET_SIZ); |
d62a17ae | 847 | |
7cf15b25 | 848 | zclient_create_header(s, cmd, vrf_id); |
d62a17ae | 849 | |
850 | stream_putw(s, rn->p.family); | |
851 | switch (rn->p.family) { | |
852 | case AF_INET: | |
853 | stream_putc(s, rn->p.prefixlen); | |
854 | stream_put_in_addr(s, &rn->p.u.prefix4); | |
fb018d25 | 855 | break; |
d62a17ae | 856 | case AF_INET6: |
857 | stream_putc(s, rn->p.prefixlen); | |
858 | stream_put(s, &rn->p.u.prefix6, IPV6_MAX_BYTELEN); | |
fb018d25 | 859 | break; |
d62a17ae | 860 | default: |
af4c2728 | 861 | flog_err(ZEBRA_ERR_RNH_UNKNOWN_FAMILY, |
43e52561 QY |
862 | "%s: Unknown family (%d) notification attempted\n", |
863 | __FUNCTION__, rn->p.family); | |
fb018d25 | 864 | break; |
d62a17ae | 865 | } |
866 | if (re) { | |
05dd5aaf DS |
867 | stream_putc(s, re->type); |
868 | stream_putw(s, re->instance); | |
d62a17ae | 869 | stream_putc(s, re->distance); |
870 | stream_putl(s, re->metric); | |
871 | num = 0; | |
872 | nump = stream_get_endp(s); | |
873 | stream_putc(s, 0); | |
0acf4df0 DS |
874 | for (nh = re->ng.nexthop; nh; nh = nh->next) |
875 | if ((CHECK_FLAG(nh->flags, NEXTHOP_FLAG_FIB) | |
876 | || CHECK_FLAG(nh->flags, NEXTHOP_FLAG_RECURSIVE)) | |
877 | && CHECK_FLAG(nh->flags, NEXTHOP_FLAG_ACTIVE)) { | |
878 | stream_putc(s, nh->type); | |
879 | switch (nh->type) { | |
d62a17ae | 880 | case NEXTHOP_TYPE_IPV4: |
aab09c10 | 881 | case NEXTHOP_TYPE_IPV4_IFINDEX: |
0acf4df0 DS |
882 | stream_put_in_addr(s, &nh->gate.ipv4); |
883 | stream_putl(s, nh->ifindex); | |
d62a17ae | 884 | break; |
885 | case NEXTHOP_TYPE_IFINDEX: | |
0acf4df0 | 886 | stream_putl(s, nh->ifindex); |
d62a17ae | 887 | break; |
d62a17ae | 888 | case NEXTHOP_TYPE_IPV6: |
d62a17ae | 889 | case NEXTHOP_TYPE_IPV6_IFINDEX: |
0acf4df0 DS |
890 | stream_put(s, &nh->gate.ipv6, 16); |
891 | stream_putl(s, nh->ifindex); | |
d62a17ae | 892 | break; |
893 | default: | |
894 | /* do nothing */ | |
895 | break; | |
896 | } | |
0acf4df0 DS |
897 | if (nh->nh_label) { |
898 | stream_putc(s, | |
899 | nh->nh_label->num_labels); | |
900 | if (nh->nh_label->num_labels) | |
901 | stream_put( | |
902 | s, | |
903 | &nh->nh_label->label[0], | |
904 | nh->nh_label->num_labels | |
905 | * sizeof(mpls_label_t)); | |
906 | } else | |
907 | stream_putc(s, 0); | |
d62a17ae | 908 | num++; |
909 | } | |
910 | stream_putc_at(s, nump, num); | |
911 | } else { | |
05dd5aaf DS |
912 | stream_putc(s, 0); // type |
913 | stream_putw(s, 0); // instance | |
d62a17ae | 914 | stream_putc(s, 0); // distance |
915 | stream_putl(s, 0); // metric | |
916 | stream_putc(s, 0); // nexthops | |
917 | } | |
918 | stream_putw_at(s, 0, stream_get_endp(s)); | |
919 | ||
920 | client->nh_last_upd_time = monotime(NULL); | |
921 | client->last_write_cmd = cmd; | |
21ccc0cf | 922 | return zserv_send_message(client, s); |
fb018d25 DS |
923 | } |
924 | ||
d62a17ae | 925 | static void print_nh(struct nexthop *nexthop, struct vty *vty) |
fb018d25 | 926 | { |
d62a17ae | 927 | char buf[BUFSIZ]; |
928 | struct zebra_ns *zns = zebra_ns_lookup(NS_DEFAULT); | |
929 | ||
930 | switch (nexthop->type) { | |
931 | case NEXTHOP_TYPE_IPV4: | |
932 | case NEXTHOP_TYPE_IPV4_IFINDEX: | |
933 | vty_out(vty, " via %s", inet_ntoa(nexthop->gate.ipv4)); | |
934 | if (nexthop->ifindex) | |
935 | vty_out(vty, ", %s", | |
936 | ifindex2ifname_per_ns(zns, nexthop->ifindex)); | |
937 | break; | |
938 | case NEXTHOP_TYPE_IPV6: | |
939 | case NEXTHOP_TYPE_IPV6_IFINDEX: | |
940 | vty_out(vty, " %s", | |
941 | inet_ntop(AF_INET6, &nexthop->gate.ipv6, buf, BUFSIZ)); | |
942 | if (nexthop->ifindex) | |
943 | vty_out(vty, ", via %s", | |
944 | ifindex2ifname_per_ns(zns, nexthop->ifindex)); | |
945 | break; | |
946 | case NEXTHOP_TYPE_IFINDEX: | |
947 | vty_out(vty, " is directly connected, %s", | |
948 | ifindex2ifname_per_ns(zns, nexthop->ifindex)); | |
949 | break; | |
950 | case NEXTHOP_TYPE_BLACKHOLE: | |
951 | vty_out(vty, " is directly connected, Null0"); | |
952 | break; | |
953 | default: | |
954 | break; | |
955 | } | |
956 | vty_out(vty, "\n"); | |
fb018d25 DS |
957 | } |
958 | ||
d62a17ae | 959 | static void print_rnh(struct route_node *rn, struct vty *vty) |
fb018d25 | 960 | { |
d62a17ae | 961 | struct rnh *rnh; |
962 | struct nexthop *nexthop; | |
963 | struct listnode *node; | |
964 | struct zserv *client; | |
965 | char buf[BUFSIZ]; | |
966 | ||
967 | rnh = rn->info; | |
968 | vty_out(vty, "%s%s\n", | |
969 | inet_ntop(rn->p.family, &rn->p.u.prefix, buf, BUFSIZ), | |
970 | CHECK_FLAG(rnh->flags, ZEBRA_NHT_CONNECTED) ? "(Connected)" | |
971 | : ""); | |
972 | if (rnh->state) { | |
973 | vty_out(vty, " resolved via %s\n", | |
974 | zebra_route_string(rnh->state->type)); | |
7ee30f28 | 975 | for (nexthop = rnh->state->ng.nexthop; nexthop; |
d62a17ae | 976 | nexthop = nexthop->next) |
977 | print_nh(nexthop, vty); | |
978 | } else | |
979 | vty_out(vty, " unresolved%s\n", | |
980 | CHECK_FLAG(rnh->flags, ZEBRA_NHT_CONNECTED) | |
981 | ? "(Connected)" | |
982 | : ""); | |
983 | ||
984 | vty_out(vty, " Client list:"); | |
985 | for (ALL_LIST_ELEMENTS_RO(rnh->client_list, node, client)) | |
986 | vty_out(vty, " %s(fd %d)%s", zebra_route_string(client->proto), | |
987 | client->sock, | |
988 | rnh->filtered[client->proto] ? "(filtered)" : ""); | |
731a75fe RW |
989 | if (!list_isempty(rnh->zebra_pseudowire_list)) |
990 | vty_out(vty, " zebra[pseudowires]"); | |
d62a17ae | 991 | vty_out(vty, "\n"); |
fb018d25 | 992 | } |
bf094f69 QY |
993 | |
994 | static int zebra_cleanup_rnh_client(vrf_id_t vrf_id, int family, | |
995 | struct zserv *client, rnh_type_t type) | |
996 | { | |
997 | struct route_table *ntable; | |
998 | struct route_node *nrn; | |
999 | struct rnh *rnh; | |
1000 | ||
1001 | if (IS_ZEBRA_DEBUG_NHT) | |
1002 | zlog_debug("%u: Client %s RNH cleanup for family %d type %d", | |
1003 | vrf_id, zebra_route_string(client->proto), family, | |
1004 | type); | |
1005 | ||
1006 | ntable = get_rnh_table(vrf_id, family, type); | |
1007 | if (!ntable) { | |
1008 | zlog_debug("cleanup_rnh_client: rnh table not found\n"); | |
1009 | return -1; | |
1010 | } | |
1011 | ||
1012 | for (nrn = route_top(ntable); nrn; nrn = route_next(nrn)) { | |
1013 | if (!nrn->info) | |
1014 | continue; | |
1015 | ||
1016 | rnh = nrn->info; | |
1017 | zebra_remove_rnh_client(rnh, client, type); | |
1018 | } | |
1019 | return 1; | |
1020 | } | |
1021 | ||
1022 | /* Cleanup registered nexthops (across VRFs) upon client disconnect. */ | |
453844ab | 1023 | static int zebra_client_cleanup_rnh(struct zserv *client) |
bf094f69 QY |
1024 | { |
1025 | struct vrf *vrf; | |
1026 | struct zebra_vrf *zvrf; | |
1027 | ||
1028 | RB_FOREACH (vrf, vrf_id_head, &vrfs_by_id) { | |
8b1766b1 QY |
1029 | zvrf = vrf->info; |
1030 | if (zvrf) { | |
bf094f69 QY |
1031 | zebra_cleanup_rnh_client(zvrf_id(zvrf), AF_INET, client, |
1032 | RNH_NEXTHOP_TYPE); | |
1033 | zebra_cleanup_rnh_client(zvrf_id(zvrf), AF_INET6, | |
1034 | client, RNH_NEXTHOP_TYPE); | |
1035 | zebra_cleanup_rnh_client(zvrf_id(zvrf), AF_INET, client, | |
1036 | RNH_IMPORT_CHECK_TYPE); | |
1037 | zebra_cleanup_rnh_client(zvrf_id(zvrf), AF_INET6, | |
1038 | client, RNH_IMPORT_CHECK_TYPE); | |
1039 | if (client->proto == ZEBRA_ROUTE_LDP) { | |
1040 | hash_iterate(zvrf->lsp_table, | |
1041 | mpls_ldp_lsp_uninstall_all, | |
1042 | zvrf->lsp_table); | |
1043 | mpls_ldp_ftn_uninstall_all(zvrf, AFI_IP); | |
1044 | mpls_ldp_ftn_uninstall_all(zvrf, AFI_IP6); | |
1045 | } | |
1046 | } | |
1047 | } | |
453844ab QY |
1048 | |
1049 | return 0; | |
bf094f69 | 1050 | } |