diff options
author | David Lamparter <equinox@opensourcerouting.org> | 2022-01-13 15:14:16 +0100 |
---|---|---|
committer | David Lamparter <equinox@opensourcerouting.org> | 2022-01-17 14:19:11 +0100 |
commit | a6751e2318c7dd0d754a427999e23b93c96388ca (patch) | |
tree | 14cca00e70bbd46a0819b2a33a51c6ea93c3bc41 /pimd/pim_addr.h | |
parent | pimd: remove PIM_INADDR_IS[NOT]_ANY macros (diff) | |
download | frr-a6751e2318c7dd0d754a427999e23b93c96388ca.tar.xz frr-a6751e2318c7dd0d754a427999e23b93c96388ca.zip |
pimd: add more dual-family address bits
Another few definitions to aid in dealing with IPv4 and IPv6.
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
Diffstat (limited to 'pimd/pim_addr.h')
-rw-r--r-- | pimd/pim_addr.h | 56 |
1 files changed, 54 insertions, 2 deletions
diff --git a/pimd/pim_addr.h b/pimd/pim_addr.h index c7b37b02c..3c4b5a84d 100644 --- a/pimd/pim_addr.h +++ b/pimd/pim_addr.h @@ -21,6 +21,9 @@ #define _PIMD_PIM_ADDR_H #include "jhash.h" +#include "prefix.h" + +/* clang-format off */ /* temporarily disable IPv6 types to keep code compiling. * Defining PIM_V6_TEMP_BREAK will show a lot of compile errors - they are @@ -28,10 +31,39 @@ */ #if PIM_IPV == 4 || !defined(PIM_V6_TEMP_BREAK) typedef struct in_addr pim_addr; -#define PIM_ADDRSTRLEN INET_ADDRSTRLEN + +#define PIM_ADDRSTRLEN INET_ADDRSTRLEN +#define PIM_AF AF_INET +#define PIM_AFI AFI_IP +#define PIM_MAX_BITLEN IPV4_MAX_BITLEN + +union pimprefixptr { + prefixtype(pimprefixptr, struct prefix, p) + prefixtype(pimprefixptr, struct prefix_ipv4, p4) +} TRANSPARENT_UNION; + +union pimprefixconstptr { + prefixtype(pimprefixconstptr, const struct prefix, p) + prefixtype(pimprefixconstptr, const struct prefix_ipv4, p4) +} TRANSPARENT_UNION; + #else typedef struct in6_addr pim_addr; -#define PIM_ADDRSTRLEN INET6_ADDRSTRLEN + +#define PIM_ADDRSTRLEN INET6_ADDRSTRLEN +#define PIM_AF AF_INET6 +#define PIM_AFI AFI_IP6 +#define PIM_MAX_BITLEN IPV6_MAX_BITLEN + +union pimprefixptr { + prefixtype(pimprefixptr, struct prefix, p) + prefixtype(pimprefixptr, struct prefix_ipv6, p6) +} TRANSPARENT_UNION; + +union pimprefixconstptr { + prefixtype(pimprefixconstptr, const struct prefix, p) + prefixtype(pimprefixconstptr, const struct prefix_ipv6, p6) +} TRANSPARENT_UNION; #endif /* for assignment/initialization (C99 compound literal) @@ -39,6 +71,8 @@ typedef struct in6_addr pim_addr; */ #define PIMADDR_ANY (pim_addr){ } +/* clang-format on */ + static inline bool pim_addr_is_any(pim_addr addr) { pim_addr zero = {}; @@ -51,6 +85,24 @@ static inline int pim_addr_cmp(pim_addr a, pim_addr b) return memcmp(&a, &b, sizeof(a)); } +static inline void pim_addr_to_prefix(union pimprefixptr out, pim_addr in) +{ + out.p->family = PIM_AF; + out.p->prefixlen = PIM_MAX_BITLEN; + memcpy(out.p->u.val, &in, sizeof(in)); +} + +static inline pim_addr pim_addr_from_prefix(union pimprefixconstptr in) +{ + pim_addr ret; + + if (in.p->family != PIM_AF) + return PIMADDR_ANY; + + memcpy(&ret, in.p->u.val, sizeof(ret)); + return ret; +} + /* don't use this struct directly, use the pim_sgaddr typedef */ struct _pim_sgaddr { pim_addr grp; |