Move the inetpeer_addr_base union to inetpeer_addr and drop
inetpeer_addr_base.
Both the a6 and in6_addr overlays are not needed; drop the __be32 version
and rename in6 to a6 for consistency with ipv4. Add a new u32 array to
the union which removes the need for the typecast in the compare function
and the use of a consistent arg for both ipv4 and ipv6 addresses which
makes the compare function more readable.
Signed-off-by: David Ahern <dsa@cumulusnetworks.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
#include <net/ipv6.h>
#include <linux/atomic.h>
#include <net/ipv6.h>
#include <linux/atomic.h>
-struct inetpeer_addr_base {
+#define INETPEER_MAXKEYSZ (sizeof(struct in6_addr) / sizeof(u32))
+
+struct inetpeer_addr {
- __be32 a6[4];
- struct in6_addr in6;
+ struct in6_addr a6;
+ u32 key[INETPEER_MAXKEYSZ];
-};
-
-struct inetpeer_addr {
- struct inetpeer_addr_base addr;
static inline void inetpeer_set_addr_v4(struct inetpeer_addr *iaddr, __be32 ip)
{
static inline void inetpeer_set_addr_v4(struct inetpeer_addr *iaddr, __be32 ip)
{
iaddr->family = AF_INET;
}
static inline __be32 inetpeer_get_addr_v4(struct inetpeer_addr *iaddr)
{
iaddr->family = AF_INET;
}
static inline __be32 inetpeer_get_addr_v4(struct inetpeer_addr *iaddr)
{
}
static inline void inetpeer_set_addr_v6(struct inetpeer_addr *iaddr,
struct in6_addr *in6)
{
}
static inline void inetpeer_set_addr_v6(struct inetpeer_addr *iaddr,
struct in6_addr *in6)
{
- iaddr->addr.in6 = *in6;
iaddr->family = AF_INET6;
}
static inline struct in6_addr *inetpeer_get_addr_v6(struct inetpeer_addr *iaddr)
{
iaddr->family = AF_INET6;
}
static inline struct in6_addr *inetpeer_get_addr_v6(struct inetpeer_addr *iaddr)
{
- return &iaddr->addr.in6;
}
/* can be called with or without local BH being disabled */
}
/* can be called with or without local BH being disabled */
{
struct inetpeer_addr daddr;
{
struct inetpeer_addr daddr;
- daddr.addr.a4 = v4daddr;
daddr.family = AF_INET;
return inet_getpeer(base, &daddr, create);
}
daddr.family = AF_INET;
return inet_getpeer(base, &daddr, create);
}
{
struct inetpeer_addr daddr;
{
struct inetpeer_addr daddr;
- daddr.addr.in6 = *v6daddr;
daddr.family = AF_INET6;
return inet_getpeer(base, &daddr, create);
}
daddr.family = AF_INET6;
return inet_getpeer(base, &daddr, create);
}
static inline int inetpeer_addr_cmp(const struct inetpeer_addr *a,
const struct inetpeer_addr *b)
{
static inline int inetpeer_addr_cmp(const struct inetpeer_addr *a,
const struct inetpeer_addr *b)
{
- int i, n = (a->family == AF_INET ? 1 : 4);
+ int i, n;
+
+ if (a->family == AF_INET)
+ n = sizeof(a->a4) / sizeof(u32);
+ else
+ n = sizeof(a->a6) / sizeof(u32);
for (i = 0; i < n; i++) {
for (i = 0; i < n; i++) {
- if (a->addr.a6[i] == b->addr.a6[i])
+ if (a->key[i] == b->key[i])
- if ((__force u32)a->addr.a6[i] < (__force u32)b->addr.a6[i])
+ if (a->key[i] < b->key[i])