diff options
Diffstat (limited to 'lib/prefix.h')
| -rw-r--r-- | lib/prefix.h | 42 |
1 files changed, 22 insertions, 20 deletions
diff --git a/lib/prefix.h b/lib/prefix.h index 217a23d561..944c94f57f 100644 --- a/lib/prefix.h +++ b/lib/prefix.h @@ -372,7 +372,6 @@ union prefixconstptr { /* Max bit/byte length of IPv4 address. */ #define IPV4_MAX_BYTELEN 4 #define IPV4_MAX_BITLEN 32 -#define IPV4_MAX_PREFIXLEN 32 #define IPV4_ADDR_CMP(D,S) memcmp ((D), (S), IPV4_MAX_BYTELEN) static inline bool ipv4_addr_same(const struct in_addr *a, @@ -398,7 +397,6 @@ static inline void ipv4_addr_copy(struct in_addr *dst, /* Max bit/byte length of IPv6 address. */ #define IPV6_MAX_BYTELEN 16 #define IPV6_MAX_BITLEN 128 -#define IPV6_MAX_PREFIXLEN 128 #define IPV6_ADDR_CMP(D,S) memcmp ((D), (S), IPV6_MAX_BYTELEN) #define IPV6_ADDR_SAME(D,S) (memcmp ((D), (S), IPV6_MAX_BYTELEN) == 0) #define IPV6_ADDR_COPY(D,S) memcpy ((D), (S), IPV6_MAX_BYTELEN) @@ -481,11 +479,6 @@ extern void prefix_ipv4_free(struct prefix_ipv4 **p); extern int str2prefix_ipv4(const char *, struct prefix_ipv4 *); extern void apply_mask_ipv4(struct prefix_ipv4 *); -#define PREFIX_COPY(DST, SRC) \ - *((struct prefix *)(DST)) = *((const struct prefix *)(SRC)) -#define PREFIX_COPY_IPV4(DST, SRC) \ - *((struct prefix_ipv4 *)(DST)) = *((const struct prefix_ipv4 *)(SRC)) - extern int prefix_ipv4_any(const struct prefix_ipv4 *); extern void apply_classful_mask_ipv4(struct prefix_ipv4 *); @@ -503,9 +496,6 @@ extern void prefix_ipv6_free(struct prefix_ipv6 **p); extern int str2prefix_ipv6(const char *, struct prefix_ipv6 *); extern void apply_mask_ipv6(struct prefix_ipv6 *); -#define PREFIX_COPY_IPV6(DST, SRC) \ - *((struct prefix_ipv6 *)(DST)) = *((const struct prefix_ipv6 *)(SRC)) - extern int ip6_masklen(struct in6_addr); extern void masklen2ip6(const int, struct in6_addr *); @@ -547,20 +537,32 @@ static inline int ipv4_martian(struct in_addr *addr) return 0; } -static inline int is_default_prefix(const struct prefix *p) +static inline bool is_default_prefix4(const struct prefix_ipv4 *p) { - if (!p) - return 0; + return p && p->family == AF_INET && p->prefixlen == 0 + && p->prefix.s_addr == INADDR_ANY; +} - if ((p->family == AF_INET) && (p->u.prefix4.s_addr == INADDR_ANY) - && (p->prefixlen == 0)) - return 1; +static inline bool is_default_prefix6(const struct prefix_ipv6 *p) +{ + return p && p->family == AF_INET6 && p->prefixlen == 0 + && memcmp(&p->prefix, &in6addr_any, sizeof(struct in6_addr)) + == 0; +} - if ((p->family == AF_INET6) && (p->prefixlen == 0) - && (!memcmp(&p->u.prefix6, &in6addr_any, sizeof(struct in6_addr)))) - return 1; +static inline bool is_default_prefix(const struct prefix *p) +{ + if (p == NULL) + return false; + + switch (p->family) { + case AF_INET: + return is_default_prefix4((const struct prefix_ipv4 *)p); + case AF_INET6: + return is_default_prefix6((const struct prefix_ipv6 *)p); + } - return 0; + return false; } static inline int is_host_route(const struct prefix *p) |
