diff options
author | Donatas Abraitis <donatas.abraitis@gmail.com> | 2021-07-01 22:29:26 +0200 |
---|---|---|
committer | Donatas Abraitis <donatas.abraitis@gmail.com> | 2021-07-01 22:54:39 +0200 |
commit | 8643c2e5f7b5541f136a3dfff5abe5b537159442 (patch) | |
tree | 5951d4ae8a28244fa2545c56d06629ef009ccf87 /babeld | |
parent | *: Convert numeric 32 into IPV4_MAX_BITLEN for prefixlen (diff) | |
download | frr-8643c2e5f7b5541f136a3dfff5abe5b537159442.tar.xz frr-8643c2e5f7b5541f136a3dfff5abe5b537159442.zip |
*: Replace 4/16 integers to IPV4_MAX_BYTELEN/IPV6_MAX_BYTELEN
Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
Diffstat (limited to 'babeld')
-rw-r--r-- | babeld/babel_interface.c | 83 | ||||
-rw-r--r-- | babeld/util.c | 17 |
2 files changed, 54 insertions, 46 deletions
diff --git a/babeld/babel_interface.c b/babeld/babel_interface.c index 41391c51a..43ed97cf1 100644 --- a/babeld/babel_interface.c +++ b/babeld/babel_interface.c @@ -177,10 +177,11 @@ babel_interface_address_delete (ZAPI_CALLBACK_ARGS) if (prefix->family == AF_INET) { flush_interface_routes(ifc->ifp, 0); babel_ifp = babel_get_if_nfo(ifc->ifp); - if (babel_ifp->ipv4 != NULL - && memcmp(babel_ifp->ipv4, &prefix->u.prefix4, 4) == 0) { - free(babel_ifp->ipv4); - babel_ifp->ipv4 = NULL; + if (babel_ifp->ipv4 != NULL + && memcmp(babel_ifp->ipv4, &prefix->u.prefix4, IPV4_MAX_BYTELEN) + == 0) { + free(babel_ifp->ipv4); + babel_ifp->ipv4 = NULL; } } @@ -825,9 +826,11 @@ is_interface_ll_address(struct interface *ifp, const unsigned char *address) return 0; FOR_ALL_INTERFACES_ADDRESSES(ifp, connected, node) { - if(connected->address->family == AF_INET6 && - memcmp(&connected->address->u.prefix6, address, 16) == 0) - return 1; + if (connected->address->family == AF_INET6 + && memcmp(&connected->address->u.prefix6, address, + IPV6_MAX_BYTELEN) + == 0) + return 1; } return 0; @@ -941,13 +944,13 @@ static int babel_prefix_eq(struct prefix *prefix, unsigned char *p, int plen) { if(prefix->family == AF_INET6) { - if(prefix->prefixlen != plen || - memcmp(&prefix->u.prefix6, p, 16) != 0) - return 0; + if (prefix->prefixlen != plen + || memcmp(&prefix->u.prefix6, p, IPV6_MAX_BYTELEN) != 0) + return 0; } else if(prefix->family == AF_INET) { - if(plen < 96 || !v4mapped(p) || prefix->prefixlen != plen - 96 || - memcmp(&prefix->u.prefix4, p + 12, 4) != 0) - return 0; + if (plen < 96 || !v4mapped(p) || prefix->prefixlen != plen - 96 + || memcmp(&prefix->u.prefix4, p + 12, IPV4_MAX_BYTELEN) != 0) + return 0; } else { return 0; } @@ -959,31 +962,35 @@ static void show_babel_routes_sub(struct babel_route *route, struct vty *vty, struct prefix *prefix) { - const unsigned char *nexthop = - memcmp(route->nexthop, route->neigh->address, 16) == 0 ? - NULL : route->nexthop; - char channels[100]; - - if(prefix && !babel_prefix_eq(prefix, route->src->prefix, route->src->plen)) - return; - - if(route->channels[0] == 0) - channels[0] = '\0'; - else { - int k, j = 0; - snprintf(channels, sizeof(channels), " chan ("); - j = strlen(channels); - for(k = 0; k < DIVERSITY_HOPS; k++) { - if(route->channels[k] == 0) - break; - if(k > 0) - channels[j++] = ','; - snprintf(channels + j, 100 - j, "%u", route->channels[k]); - j = strlen(channels); - } - snprintf(channels + j, 100 - j, ")"); - if(k == 0) - channels[0] = '\0'; + const unsigned char *nexthop = + memcmp(route->nexthop, route->neigh->address, IPV6_MAX_BYTELEN) + == 0 + ? NULL + : route->nexthop; + char channels[100]; + + if (prefix + && !babel_prefix_eq(prefix, route->src->prefix, route->src->plen)) + return; + + if (route->channels[0] == 0) + channels[0] = '\0'; + else { + int k, j = 0; + snprintf(channels, sizeof(channels), " chan ("); + j = strlen(channels); + for (k = 0; k < DIVERSITY_HOPS; k++) { + if (route->channels[k] == 0) + break; + if (k > 0) + channels[j++] = ','; + snprintf(channels + j, 100 - j, "%u", + route->channels[k]); + j = strlen(channels); + } + snprintf(channels + j, 100 - j, ")"); + if (k == 0) + channels[0] = '\0'; } vty_out (vty, diff --git a/babeld/util.c b/babeld/util.c index be838fa43..e2db75996 100644 --- a/babeld/util.c +++ b/babeld/util.c @@ -220,9 +220,9 @@ unsigned char * mask_prefix(unsigned char *restrict ret, const unsigned char *restrict prefix, unsigned char plen) { - if(plen >= 128) { - memcpy(ret, prefix, 16); - return ret; + if (plen >= IPV6_MAX_BITLEN) { + memcpy(ret, prefix, IPV6_MAX_BYTELEN); + return ret; } memset(ret, 0, 16); @@ -309,9 +309,10 @@ parse_address(const char *address, unsigned char *addr_r, int *af_r) rc = inet_pton(AF_INET6, address, &ina6); if(rc > 0) { - memcpy(addr_r, &ina6, 16); - if(af_r) *af_r = AF_INET6; - return 0; + memcpy(addr_r, &ina6, IPV6_MAX_BYTELEN); + if (af_r) + *af_r = AF_INET6; + return 0; } return -1; @@ -413,13 +414,13 @@ uchar_to_inaddr(struct in_addr *dest, const unsigned char *src) void in6addr_to_uchar(unsigned char *dest, const struct in6_addr *src) { - memcpy(dest, src, 16); + memcpy(dest, src, IPV6_MAX_BYTELEN); } void uchar_to_in6addr(struct in6_addr *dest, const unsigned char *src) { - memcpy(dest, src, 16); + memcpy(dest, src, IPV6_MAX_BYTELEN); } int |