]> git.proxmox.com Git - mirror_frr.git/blame - nhrpd/nhrp_shortcut.c
nhrpd: Set prefix length in NAT extension in resolution-reply
[mirror_frr.git] / nhrpd / nhrp_shortcut.c
CommitLineData
2fb975da
TT
1/* NHRP shortcut related functions
2 * Copyright (c) 2014-2015 Timo Teräs
3 *
4 * This file is free software: you may copy, redistribute and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
8 */
9
b45ac5f5
DL
10#ifdef HAVE_CONFIG_H
11#include "config.h"
12#endif
13
2fb975da
TT
14#include "nhrpd.h"
15#include "table.h"
16#include "memory.h"
17#include "thread.h"
18#include "log.h"
19#include "nhrp_protocol.h"
20
819dc8bb
DL
21DEFINE_MTYPE_STATIC(NHRPD, NHRP_SHORTCUT, "NHRP shortcut")
22
2fb975da
TT
23static struct route_table *shortcut_rib[AFI_MAX];
24
25static int nhrp_shortcut_do_purge(struct thread *t);
26static void nhrp_shortcut_delete(struct nhrp_shortcut *s);
27static void nhrp_shortcut_send_resolution_req(struct nhrp_shortcut *s);
28
29static void nhrp_shortcut_check_use(struct nhrp_shortcut *s)
30{
2fb975da 31 if (s->expiring && s->cache && s->cache->used) {
2dbe669b
DA
32 debugf(NHRP_DEBUG_ROUTE, "Shortcut %pFX used and expiring",
33 s->p);
2fb975da
TT
34 nhrp_shortcut_send_resolution_req(s);
35 }
36}
37
38static int nhrp_shortcut_do_expire(struct thread *t)
39{
40 struct nhrp_shortcut *s = THREAD_ARG(t);
41
42 s->t_timer = NULL;
996c9314
LB
43 thread_add_timer(master, nhrp_shortcut_do_purge, s, s->holding_time / 3,
44 &s->t_timer);
2fb975da
TT
45 s->expiring = 1;
46 nhrp_shortcut_check_use(s);
47
48 return 0;
49}
50
996c9314
LB
51static void nhrp_shortcut_cache_notify(struct notifier_block *n,
52 unsigned long cmd)
2fb975da 53{
ef91ff04
PG
54 char buf2[PREFIX_STRLEN];
55
996c9314
LB
56 struct nhrp_shortcut *s =
57 container_of(n, struct nhrp_shortcut, cache_notifier);
ef91ff04 58 struct nhrp_cache *c = s->cache;
2fb975da 59
ef91ff04
PG
60 if (c)
61 sockunion2str(&c->remote_addr, buf2, sizeof(buf2));
62 else
63 snprintf(buf2, sizeof(buf2), "(unspec)");
2fb975da
TT
64 switch (cmd) {
65 case NOTIFY_CACHE_UP:
66 if (!s->route_installed) {
912c556b 67 debugf(NHRP_DEBUG_ROUTE,
ef91ff04
PG
68 "Shortcut: route install %pFX nh %s dev %s",
69 s->p, buf2, c && c->ifp ?
70 c->ifp->name : "<unk>");
912c556b 71
ef91ff04
PG
72 nhrp_route_announce(1, s->type, s->p, c ? c->ifp : NULL,
73 c ? &c->remote_addr : NULL, 0);
2fb975da
TT
74 s->route_installed = 1;
75 }
76 break;
77 case NOTIFY_CACHE_USED:
78 nhrp_shortcut_check_use(s);
79 break;
80 case NOTIFY_CACHE_DOWN:
81 case NOTIFY_CACHE_DELETE:
82 if (s->route_installed) {
996c9314
LB
83 nhrp_route_announce(0, NHRP_CACHE_INVALID, s->p, NULL,
84 NULL, 0);
2fb975da
TT
85 s->route_installed = 0;
86 }
87 if (cmd == NOTIFY_CACHE_DELETE)
88 nhrp_shortcut_delete(s);
89 break;
90 }
91}
92
996c9314
LB
93static void nhrp_shortcut_update_binding(struct nhrp_shortcut *s,
94 enum nhrp_cache_type type,
95 struct nhrp_cache *c, int holding_time)
2fb975da
TT
96{
97 s->type = type;
98 if (c != s->cache) {
99 if (s->cache) {
100 nhrp_cache_notify_del(s->cache, &s->cache_notifier);
101 s->cache = NULL;
102 }
103 s->cache = c;
104 if (s->cache) {
996c9314
LB
105 nhrp_cache_notify_add(s->cache, &s->cache_notifier,
106 nhrp_shortcut_cache_notify);
2fb975da 107 if (s->cache->route_installed) {
996c9314
LB
108 /* Force renewal of Zebra announce on prefix
109 * change */
2fb975da 110 s->route_installed = 0;
912c556b 111 debugf(NHRP_DEBUG_ROUTE,
b6c48481
DS
112 "Shortcut: forcing renewal of zebra announce on prefix change peer %pSU ht %u cur nbma %pSU dev %s",
113 &s->cache->remote_addr, holding_time,
114 &s->cache->cur.remote_nbma_natoa,
912c556b 115 s->cache->ifp->name);
996c9314
LB
116 nhrp_shortcut_cache_notify(&s->cache_notifier,
117 NOTIFY_CACHE_UP);
2fb975da
TT
118 }
119 }
912c556b
GN
120 if (!s->cache || !s->cache->route_installed) {
121 debugf(NHRP_DEBUG_ROUTE,
5f36c26c 122 "Shortcut: notify cache down because cache?%s or ri?%s",
912c556b
GN
123 s->cache ? "yes" : "no",
124 s->cache ? (s->cache->route_installed ? "yes"
125 : "no")
126 : "n/a");
996c9314
LB
127 nhrp_shortcut_cache_notify(&s->cache_notifier,
128 NOTIFY_CACHE_DOWN);
912c556b 129 }
2fb975da
TT
130 }
131 if (s->type == NHRP_CACHE_NEGATIVE && !s->route_installed) {
132 nhrp_route_announce(1, s->type, s->p, NULL, NULL, 0);
133 s->route_installed = 1;
134 } else if (s->type == NHRP_CACHE_INVALID && s->route_installed) {
135 nhrp_route_announce(0, NHRP_CACHE_INVALID, s->p, NULL, NULL, 0);
136 s->route_installed = 0;
137 }
138
139 THREAD_OFF(s->t_timer);
140 if (holding_time) {
141 s->expiring = 0;
142 s->holding_time = holding_time;
ffa2c898
QY
143 thread_add_timer(master, nhrp_shortcut_do_expire, s,
144 2 * holding_time / 3, &s->t_timer);
2fb975da
TT
145 }
146}
147
148static void nhrp_shortcut_delete(struct nhrp_shortcut *s)
149{
150 struct route_node *rn;
151 afi_t afi = family2afi(PREFIX_FAMILY(s->p));
2fb975da
TT
152
153 THREAD_OFF(s->t_timer);
154 nhrp_reqid_free(&nhrp_packet_reqid, &s->reqid);
155
2dbe669b 156 debugf(NHRP_DEBUG_ROUTE, "Shortcut %pFX purged", s->p);
2fb975da
TT
157
158 nhrp_shortcut_update_binding(s, NHRP_CACHE_INVALID, NULL, 0);
159
160 /* Delete node */
161 rn = route_node_lookup(shortcut_rib[afi], s->p);
162 if (rn) {
163 XFREE(MTYPE_NHRP_SHORTCUT, rn->info);
912c556b 164 rn->info = NULL;
2fb975da
TT
165 route_unlock_node(rn);
166 route_unlock_node(rn);
167 }
168}
169
170static int nhrp_shortcut_do_purge(struct thread *t)
171{
172 struct nhrp_shortcut *s = THREAD_ARG(t);
173 s->t_timer = NULL;
174 nhrp_shortcut_delete(s);
175 return 0;
176}
177
178static struct nhrp_shortcut *nhrp_shortcut_get(struct prefix *p)
179{
180 struct nhrp_shortcut *s;
181 struct route_node *rn;
2fb975da
TT
182 afi_t afi = family2afi(PREFIX_FAMILY(p));
183
184 if (!shortcut_rib[afi])
185 return 0;
186
187 rn = route_node_get(shortcut_rib[afi], p);
188 if (!rn->info) {
996c9314
LB
189 s = rn->info = XCALLOC(MTYPE_NHRP_SHORTCUT,
190 sizeof(struct nhrp_shortcut));
2fb975da
TT
191 s->type = NHRP_CACHE_INVALID;
192 s->p = &rn->p;
193
2dbe669b 194 debugf(NHRP_DEBUG_ROUTE, "Shortcut %pFX created", s->p);
2fb975da
TT
195 } else {
196 s = rn->info;
197 route_unlock_node(rn);
198 }
199 return s;
200}
201
996c9314
LB
202static void nhrp_shortcut_recv_resolution_rep(struct nhrp_reqid *reqid,
203 void *arg)
2fb975da
TT
204{
205 struct nhrp_packet_parser *pp = arg;
bb58f442
GG
206 struct interface *ifp = pp->ifp;
207 struct nhrp_interface *nifp = ifp->info;
996c9314
LB
208 struct nhrp_shortcut *s =
209 container_of(reqid, struct nhrp_shortcut, reqid);
2fb975da
TT
210 struct nhrp_shortcut *ps;
211 struct nhrp_extension_header *ext;
212 struct nhrp_cie_header *cie;
213 struct nhrp_cache *c = NULL;
ac95bcef 214 struct nhrp_cache *c_dst_proto = NULL;
9c292647 215 union sockunion *proto, cie_proto, *nbma, cie_nbma, nat_nbma;
2fb975da
TT
216 struct prefix prefix, route_prefix;
217 struct zbuf extpl;
2dbe669b 218 char buf[4][SU_ADDRSTRLEN];
2fb975da
TT
219 int holding_time = pp->if_ad->holdtime;
220
221 nhrp_reqid_free(&nhrp_packet_reqid, &s->reqid);
222 THREAD_OFF(s->t_timer);
ffa2c898 223 thread_add_timer(master, nhrp_shortcut_do_purge, s, 1, &s->t_timer);
2fb975da
TT
224
225 if (pp->hdr->type != NHRP_PACKET_RESOLUTION_REPLY) {
996c9314
LB
226 if (pp->hdr->type == NHRP_PACKET_ERROR_INDICATION
227 && pp->hdr->u.error.code
228 == NHRP_ERROR_PROTOCOL_ADDRESS_UNREACHABLE) {
229 debugf(NHRP_DEBUG_COMMON,
230 "Shortcut: Resolution: Protocol address unreachable");
231 nhrp_shortcut_update_binding(s, NHRP_CACHE_NEGATIVE,
232 NULL, holding_time);
2fb975da 233 } else {
996c9314
LB
234 debugf(NHRP_DEBUG_COMMON,
235 "Shortcut: Resolution failed");
2fb975da
TT
236 }
237 return;
238 }
239
2fb975da
TT
240 /* Minor sanity check */
241 prefix2sockunion(s->p, &cie_proto);
242 if (!sockunion_same(&cie_proto, &pp->dst_proto)) {
996c9314 243 debugf(NHRP_DEBUG_COMMON,
b6c48481
DS
244 "Shortcut: Warning dst_proto altered from %pSU to %pSU",
245 &cie_proto, &pp->dst_proto);
246 ;
2fb975da
TT
247 }
248
249 /* One or more CIEs should be given as reply, we support only one */
250 cie = nhrp_cie_pull(&pp->payload, pp->hdr, &cie_nbma, &cie_proto);
251 if (!cie || cie->code != NHRP_CODE_SUCCESS) {
996c9314
LB
252 debugf(NHRP_DEBUG_COMMON, "Shortcut: CIE code %d",
253 cie ? cie->code : -1);
2fb975da
TT
254 return;
255 }
256
996c9314
LB
257 proto = sockunion_family(&cie_proto) != AF_UNSPEC ? &cie_proto
258 : &pp->dst_proto;
2fb975da
TT
259 if (cie->holding_time)
260 holding_time = htons(cie->holding_time);
261
262 prefix = *s->p;
263 prefix.prefixlen = cie->prefix_length;
264
265 /* Sanity check prefix length */
996c9314
LB
266 if (prefix.prefixlen >= 8 * prefix_blen(&prefix)
267 || prefix.prefixlen == 0) {
268 prefix.prefixlen = 8 * prefix_blen(&prefix);
269 } else if (nhrp_route_address(NULL, &pp->dst_proto, &route_prefix, NULL)
270 == NHRP_ROUTE_NBMA_NEXTHOP) {
2fb975da
TT
271 if (prefix.prefixlen < route_prefix.prefixlen)
272 prefix.prefixlen = route_prefix.prefixlen;
273 }
274
9c292647
AL
275 /* Parse extensions */
276 memset(&nat_nbma, 0, sizeof(nat_nbma));
277 while ((ext = nhrp_ext_pull(&pp->extensions, &extpl)) != NULL) {
278 switch (htons(ext->type) & ~NHRP_EXTENSION_FLAG_COMPULSORY) {
279 case NHRP_EXTENSION_NAT_ADDRESS: {
280 struct nhrp_cie_header *cie_nat;
281 do {
282 union sockunion cie_nat_proto, cie_nat_nbma;
283 sockunion_family(&cie_nat_proto) = AF_UNSPEC;
284 sockunion_family(&cie_nat_nbma) = AF_UNSPEC;
611915ae
AL
285 cie_nat = nhrp_cie_pull(&extpl, pp->hdr,
286 &cie_nat_nbma,
287 &cie_nat_proto);
9c292647 288 /* We are interested only in peer CIE */
611915ae
AL
289 if (cie_nat
290 && sockunion_same(&cie_nat_proto, proto)) {
9c292647
AL
291 nat_nbma = cie_nat_nbma;
292 }
293 } while (cie_nat);
294 } break;
295 default:
296 break;
297 }
298 }
299
bb58f442
GG
300 /* Update cache entry for the protocol to nbma binding */
301 if (sockunion_family(&nat_nbma) != AF_UNSPEC) {
611915ae
AL
302 debugf(NHRP_DEBUG_COMMON,
303 "Remote Device is NATTED, NHRP NAT Extension present");
304 debugf(NHRP_DEBUG_COMMON,
305 "Client NBMA Address %s",
306 sockunion2str(&nat_nbma, buf[1], sizeof(buf[1])));
9c292647 307 nbma = &nat_nbma;
611915ae
AL
308 }
309 /* For NHRP resolution reply the cie_nbma in mandatory part is the
310 * address of the actual address of the sender */
311 else if (!sockunion_same(&cie_nbma, &pp->peer->vc->remote.nbma)
312 && !nhrp_nhs_match_ip(&pp->peer->vc->remote.nbma, nifp)) {
313 debugf(NHRP_DEBUG_COMMON,
314 "Remote Device is NATTED, NHRP NAT Extension not present for proto %s",
315 sockunion2str(proto, buf[0], sizeof(buf[0])));
316 debugf(NHRP_DEBUG_COMMON, "cie_nbma %s",
317 sockunion2str(&cie_nbma, buf[1], sizeof(buf[1])));
318 debugf(NHRP_DEBUG_COMMON, "remote.nbma %s",
319 sockunion2str(&pp->peer->vc->remote.nbma, buf[1],
320 sizeof(buf[1])));
bb58f442
GG
321 nbma = &pp->peer->vc->remote.nbma;
322 nat_nbma = *nbma;
323 } else {
324 nbma = &cie_nbma;
325 }
326
996c9314 327 debugf(NHRP_DEBUG_COMMON,
b6c48481
DS
328 "Shortcut: %pFX is at proto %pSU dst_proto %pSU cie-nbma %pSU nat-nbma %pSU cie-holdtime %d",
329 &prefix, proto, &pp->dst_proto, &cie_nbma, &nat_nbma,
996c9314 330 htons(cie->holding_time));
2fb975da 331
912c556b 332
2fb975da
TT
333 if (sockunion_family(nbma)) {
334 c = nhrp_cache_get(pp->ifp, proto, 1);
335 if (c) {
912c556b
GN
336 debugf(NHRP_DEBUG_COMMON,
337 "Shortcut: cache found, update binding");
338 nhrp_cache_update_binding(c, NHRP_CACHE_DYNAMIC,
996c9314
LB
339 holding_time,
340 nhrp_peer_get(pp->ifp, nbma),
85365e51 341 htons(cie->mtu), nbma, &cie_nbma);
912c556b
GN
342 } else {
343 debugf(NHRP_DEBUG_COMMON,
344 "Shortcut: no cache for nbma %s", buf[2]);
2fb975da 345 }
ac95bcef
GG
346
347 /* Update cache binding for dst_proto as well */
bb58f442 348 if (sockunion_cmp(proto, &pp->dst_proto)) {
ac95bcef
GG
349 c_dst_proto = nhrp_cache_get(pp->ifp, &pp->dst_proto, 1);
350 if (c_dst_proto) {
351 debugf(NHRP_DEBUG_COMMON,
352 "Shortcut: cache found, update binding");
353 nhrp_cache_update_binding(c_dst_proto, NHRP_CACHE_DYNAMIC,
354 holding_time,
355 nhrp_peer_get(pp->ifp, nbma),
85365e51 356 htons(cie->mtu), nbma, &cie_nbma);
ac95bcef
GG
357 } else {
358 debugf(NHRP_DEBUG_COMMON,
359 "Shortcut: no cache for nbma %s", buf[2]);
360 }
361 }
2fb975da
TT
362 }
363
364 /* Update shortcut entry for subnet to protocol gw binding */
912c556b 365 if (c) {
2fb975da
TT
366 ps = nhrp_shortcut_get(&prefix);
367 if (ps) {
368 ps->addr = s->addr;
912c556b 369 debugf(NHRP_DEBUG_COMMON,
5f36c26c 370 "Shortcut: calling update_binding");
912c556b 371 nhrp_shortcut_update_binding(ps, NHRP_CACHE_DYNAMIC, c,
996c9314 372 holding_time);
912c556b
GN
373 } else {
374 debugf(NHRP_DEBUG_COMMON,
375 "Shortcut: proto diff but no ps");
2fb975da 376 }
912c556b
GN
377 } else {
378 debugf(NHRP_DEBUG_COMMON,
5f36c26c 379 "NO Shortcut because c NULL?%s or same proto?%s",
912c556b
GN
380 c ? "no" : "yes",
381 proto && pp && sockunion_same(proto, &pp->dst_proto)
382 ? "yes"
383 : "no");
2fb975da
TT
384 }
385
386 debugf(NHRP_DEBUG_COMMON, "Shortcut: Resolution reply handled");
387}
388
389static void nhrp_shortcut_send_resolution_req(struct nhrp_shortcut *s)
390{
391 struct zbuf *zb;
392 struct nhrp_packet_header *hdr;
393 struct interface *ifp;
394 struct nhrp_interface *nifp;
47d40757 395 struct nhrp_afi_data *if_ad;
2fb975da 396 struct nhrp_peer *peer;
47d40757 397 struct nhrp_cie_header *cie;
c2cffffb 398 struct nhrp_extension_header *ext;
2fb975da 399
996c9314
LB
400 if (nhrp_route_address(NULL, &s->addr, NULL, &peer)
401 != NHRP_ROUTE_NBMA_NEXTHOP)
2fb975da
TT
402 return;
403
404 if (s->type == NHRP_CACHE_INVALID || s->type == NHRP_CACHE_NEGATIVE)
405 s->type = NHRP_CACHE_INCOMPLETE;
406
407 ifp = peer->ifp;
408 nifp = ifp->info;
409
410 /* Create request */
411 zb = zbuf_alloc(1500);
996c9314
LB
412 hdr = nhrp_packet_push(
413 zb, NHRP_PACKET_RESOLUTION_REQUEST, &nifp->nbma,
414 &nifp->afi[family2afi(sockunion_family(&s->addr))].addr,
415 &s->addr);
416 hdr->u.request_id =
417 htonl(nhrp_reqid_alloc(&nhrp_packet_reqid, &s->reqid,
418 nhrp_shortcut_recv_resolution_rep));
419 hdr->flags = htons(NHRP_FLAG_RESOLUTION_SOURCE_IS_ROUTER
420 | NHRP_FLAG_RESOLUTION_AUTHORATIVE
421 | NHRP_FLAG_RESOLUTION_SOURCE_STABLE);
2fb975da
TT
422
423 /* RFC2332 - One or zero CIEs, if CIE is present contains:
424 * - Prefix length: widest acceptable prefix we accept (if U set, 0xff)
425 * - MTU: MTU of the source station
426 * - Holding Time: Max time to cache the source information
427 * */
47d40757
GN
428 /* FIXME: push CIE for each local protocol address */
429 cie = nhrp_cie_push(zb, NHRP_CODE_SUCCESS, NULL, NULL);
430 cie->prefix_length = 0xff;
431 if_ad = &nifp->afi[family2afi(sockunion_family(&s->addr))];
432 cie->holding_time = htons(if_ad->holdtime);
433 cie->mtu = htons(if_ad->mtu);
434 debugf(NHRP_DEBUG_COMMON,
5f36c26c 435 "Shortcut res_req: set cie ht to %u and mtu to %u. shortcut ht is %u",
47d40757 436 ntohs(cie->holding_time), ntohs(cie->mtu), s->holding_time);
2fb975da
TT
437
438 nhrp_ext_request(zb, hdr, ifp);
439
440 /* Cisco NAT detection extension */
441 hdr->flags |= htons(NHRP_FLAG_RESOLUTION_NAT);
c2cffffb 442 ext = nhrp_ext_push(zb, hdr, NHRP_EXTENSION_NAT_ADDRESS);
611915ae
AL
443 if (sockunion_family(&nifp->nat_nbma) != AF_UNSPEC) {
444 cie = nhrp_cie_push(zb, NHRP_CODE_SUCCESS, &nifp->nat_nbma,
445 &if_ad->addr);
999a07f0 446 cie->prefix_length = 8 * sockunion_get_addrlen(&if_ad->addr);
1e52c954 447 cie->mtu = htons(if_ad->mtu);
c2cffffb
GG
448 nhrp_ext_complete(zb, ext);
449 }
2fb975da
TT
450
451 nhrp_packet_complete(zb, hdr);
452
453 nhrp_peer_send(peer, zb);
454 nhrp_peer_unref(peer);
455 zbuf_free(zb);
456}
457
458void nhrp_shortcut_initiate(union sockunion *addr)
459{
460 struct prefix p;
461 struct nhrp_shortcut *s;
462
0154d8ce
DS
463 if (!sockunion2hostprefix(addr, &p))
464 return;
465
2fb975da
TT
466 s = nhrp_shortcut_get(&p);
467 if (s && s->type != NHRP_CACHE_INCOMPLETE) {
468 s->addr = *addr;
469 THREAD_OFF(s->t_timer);
ffa2c898
QY
470 thread_add_timer(master, nhrp_shortcut_do_purge, s, 30,
471 &s->t_timer);
2fb975da
TT
472 nhrp_shortcut_send_resolution_req(s);
473 }
474}
475
476void nhrp_shortcut_init(void)
477{
478 shortcut_rib[AFI_IP] = route_table_init();
479 shortcut_rib[AFI_IP6] = route_table_init();
480}
481
482void nhrp_shortcut_terminate(void)
483{
484 route_table_finish(shortcut_rib[AFI_IP]);
485 route_table_finish(shortcut_rib[AFI_IP6]);
486}
487
996c9314
LB
488void nhrp_shortcut_foreach(afi_t afi,
489 void (*cb)(struct nhrp_shortcut *, void *),
490 void *ctx)
2fb975da
TT
491{
492 struct route_table *rt = shortcut_rib[afi];
493 struct route_node *rn;
494 route_table_iter_t iter;
495
996c9314
LB
496 if (!rt)
497 return;
2fb975da
TT
498
499 route_table_iter_init(&iter, rt);
500 while ((rn = route_table_iter_next(&iter)) != NULL) {
996c9314
LB
501 if (rn->info)
502 cb(rn->info, ctx);
2fb975da
TT
503 }
504 route_table_iter_cleanup(&iter);
505}
506
507struct purge_ctx {
508 const struct prefix *p;
509 int deleted;
510};
511
512void nhrp_shortcut_purge(struct nhrp_shortcut *s, int force)
513{
514 THREAD_OFF(s->t_timer);
515 nhrp_reqid_free(&nhrp_packet_reqid, &s->reqid);
516
517 if (force) {
518 /* Immediate purge on route with draw or pending shortcut */
ffa2c898
QY
519 thread_add_timer_msec(master, nhrp_shortcut_do_purge, s, 5,
520 &s->t_timer);
2fb975da
TT
521 } else {
522 /* Soft expire - force immediate renewal, but purge
523 * in few seconds to make sure stale route is not
524 * used too long. In practice most purges are caused
525 * by hub bgp change, but target usually stays same.
526 * This allows to keep nhrp route up, and to not
527 * cause temporary rerouting via hubs causing latency
528 * jitter. */
ffa2c898
QY
529 thread_add_timer_msec(master, nhrp_shortcut_do_purge, s, 3000,
530 &s->t_timer);
2fb975da
TT
531 s->expiring = 1;
532 nhrp_shortcut_check_use(s);
533 }
534}
535
536static void nhrp_shortcut_purge_prefix(struct nhrp_shortcut *s, void *ctx)
537{
538 struct purge_ctx *pctx = ctx;
539
540 if (prefix_match(pctx->p, s->p))
541 nhrp_shortcut_purge(s, pctx->deleted || !s->cache);
542}
543
544void nhrp_shortcut_prefix_change(const struct prefix *p, int deleted)
545{
546 struct purge_ctx pctx = {
996c9314 547 .p = p, .deleted = deleted,
2fb975da 548 };
996c9314
LB
549 nhrp_shortcut_foreach(family2afi(PREFIX_FAMILY(p)),
550 nhrp_shortcut_purge_prefix, &pctx);
2fb975da 551}