mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-08-05 20:51:17 +00:00
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>
This commit is contained in:
parent
3ca68c9cf3
commit
a6751e2318
@ -341,9 +341,6 @@ union prefixconstptr {
|
||||
prefixtype(prefixconstptr, const struct prefix_rd, rd)
|
||||
} TRANSPARENT_UNION;
|
||||
|
||||
#undef prefixtype
|
||||
#undef TRANSPARENT_UNION
|
||||
|
||||
#ifndef INET_ADDRSTRLEN
|
||||
#define INET_ADDRSTRLEN 16
|
||||
#endif /* INET_ADDRSTRLEN */
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user