diff options
| author | Gaurav Goyal <gaurav.goyal@4rf.com> | 2020-11-02 12:11:19 +1300 |
|---|---|---|
| committer | Reuben Dowle <reuben.dowle@4rf.com> | 2020-12-17 10:17:07 +1300 |
| commit | ddd8d8c84522297b13b9b1068ea93553b53b27d5 (patch) | |
| tree | ad99187c8eb9b10a82f0521f1fcdafe35fba4696 | |
| parent | 46d380217d5e44e3f48b1a6192c578430e832caa (diff) | |
nhrpd: Clear shortcut routes properly for all protocols
Currently when nhrp shortcuts are purged they will not be recreated. This
patch fixes that by ensuring the shortcut routes get purged correctly.
This situation can be reproduced by first allowing a shortcut to be created
then clearing the shortcut:
clear ip nhrp cache
clear ip nhrp shortcuts
Signed-off-by: Reuben Dowle <reuben.dowle@4rf.com>
| -rwxr-xr-x[-rw-r--r--] | lib/sockunion.c | 17 | ||||
| -rwxr-xr-x[-rw-r--r--] | lib/sockunion.h | 1 | ||||
| -rwxr-xr-x[-rw-r--r--] | nhrpd/nhrp_route.c | 7 |
3 files changed, 21 insertions, 4 deletions
diff --git a/lib/sockunion.c b/lib/sockunion.c index c999845659..1dbf77efa4 100644..100755 --- a/lib/sockunion.c +++ b/lib/sockunion.c @@ -708,3 +708,20 @@ static ssize_t printfrr_psu(char *buf, size_t bsz, const char *fmt, fb.pos[0] = '\0'; return consumed; } + +int sockunion_is_null(const union sockunion *su) +{ + unsigned char null_s6_addr[16] = {0}; + + switch (sockunion_family(su)) { + case AF_UNSPEC: + return 1; + case AF_INET: + return (su->sin.sin_addr.s_addr == 0); + case AF_INET6: + return !memcmp(su->sin6.sin6_addr.s6_addr, null_s6_addr, + sizeof(null_s6_addr)); + default: + return 0; + } +} diff --git a/lib/sockunion.h b/lib/sockunion.h index 72f12b77ca..5e80ba1090 100644..100755 --- a/lib/sockunion.h +++ b/lib/sockunion.h @@ -102,6 +102,7 @@ extern union sockunion *sockunion_getpeername(int); extern union sockunion *sockunion_dup(const union sockunion *); extern void sockunion_free(union sockunion *); extern void sockunion_init(union sockunion *); +extern int sockunion_is_null(const union sockunion *su); #ifdef _FRR_ATTRIBUTE_PRINTFRR #pragma FRR printfrr_ext "%pSU" (union sockunion *) diff --git a/nhrpd/nhrp_route.c b/nhrpd/nhrp_route.c index e7d35b90ff..ce2b1fe2ff 100644..100755 --- a/nhrpd/nhrp_route.c +++ b/nhrpd/nhrp_route.c @@ -56,7 +56,7 @@ static void nhrp_route_update_put(struct route_node *rn) struct route_info *ri = rn->info; if (!ri->ifp && !ri->nhrp_ifp - && sockunion_family(&ri->via) == AF_UNSPEC) { + && sockunion_is_null(&ri->via)) { XFREE(MTYPE_NHRP_ROUTE, rn->info); route_unlock_node(rn); } @@ -70,8 +70,7 @@ static void nhrp_route_update_zebra(const struct prefix *p, struct route_node *rn; struct route_info *ri; - rn = nhrp_route_update_get( - p, (sockunion_family(nexthop) != AF_UNSPEC) || ifp); + rn = nhrp_route_update_get(p, !sockunion_is_null(nexthop) || ifp); if (rn) { ri = rn->info; ri->via = *nexthop; @@ -225,7 +224,7 @@ int nhrp_route_read(ZAPI_CALLBACK_ARGS) sockunion2str(&nexthop_addr, buf, sizeof(buf)), ifp ? ifp->name : "(none)"); - nhrp_route_update_zebra(&api.prefix, &nexthop_addr, ifp); + nhrp_route_update_zebra(&api.prefix, &nexthop_addr, added ? ifp : NULL); nhrp_shortcut_prefix_change(&api.prefix, !added); return 0; |
