Skip to content

Commit 5345c2e

Browse files
David Aherndavem330
authored andcommitted
net: Refactor inetpeer address struct
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>
1 parent d39d14f commit 5345c2e

1 file changed

Lines changed: 19 additions & 16 deletions

File tree

‎include/net/inetpeer.h‎

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,14 @@
1515
#include <net/ipv6.h>
1616
#include <linux/atomic.h>
1717

18-
struct inetpeer_addr_base {
18+
#define INETPEER_MAXKEYSZ (sizeof(struct in6_addr) / sizeof(u32))
19+
20+
struct inetpeer_addr {
1921
union {
2022
__be32 a4;
21-
__be32 a6[4];
22-
struct in6_addr in6;
23+
struct in6_addr a6;
24+
u32 key[INETPEER_MAXKEYSZ];
2325
};
24-
};
25-
26-
struct inetpeer_addr {
27-
struct inetpeer_addr_base addr;
2826
__u16 family;
2927
};
3028

@@ -73,25 +71,25 @@ void inet_initpeers(void) __init;
7371

7472
static inline void inetpeer_set_addr_v4(struct inetpeer_addr *iaddr, __be32 ip)
7573
{
76-
iaddr->addr.a4 = ip;
74+
iaddr->a4 = ip;
7775
iaddr->family = AF_INET;
7876
}
7977

8078
static inline __be32 inetpeer_get_addr_v4(struct inetpeer_addr *iaddr)
8179
{
82-
return iaddr->addr.a4;
80+
return iaddr->a4;
8381
}
8482

8583
static inline void inetpeer_set_addr_v6(struct inetpeer_addr *iaddr,
8684
struct in6_addr *in6)
8785
{
88-
iaddr->addr.in6 = *in6;
86+
iaddr->a6 = *in6;
8987
iaddr->family = AF_INET6;
9088
}
9189

9290
static inline struct in6_addr *inetpeer_get_addr_v6(struct inetpeer_addr *iaddr)
9391
{
94-
return &iaddr->addr.in6;
92+
return &iaddr->a6;
9593
}
9694

9795
/* can be called with or without local BH being disabled */
@@ -105,7 +103,7 @@ static inline struct inet_peer *inet_getpeer_v4(struct inet_peer_base *base,
105103
{
106104
struct inetpeer_addr daddr;
107105

108-
daddr.addr.a4 = v4daddr;
106+
daddr.a4 = v4daddr;
109107
daddr.family = AF_INET;
110108
return inet_getpeer(base, &daddr, create);
111109
}
@@ -116,20 +114,25 @@ static inline struct inet_peer *inet_getpeer_v6(struct inet_peer_base *base,
116114
{
117115
struct inetpeer_addr daddr;
118116

119-
daddr.addr.in6 = *v6daddr;
117+
daddr.a6 = *v6daddr;
120118
daddr.family = AF_INET6;
121119
return inet_getpeer(base, &daddr, create);
122120
}
123121

124122
static inline int inetpeer_addr_cmp(const struct inetpeer_addr *a,
125123
const struct inetpeer_addr *b)
126124
{
127-
int i, n = (a->family == AF_INET ? 1 : 4);
125+
int i, n;
126+
127+
if (a->family == AF_INET)
128+
n = sizeof(a->a4) / sizeof(u32);
129+
else
130+
n = sizeof(a->a6) / sizeof(u32);
128131

129132
for (i = 0; i < n; i++) {
130-
if (a->addr.a6[i] == b->addr.a6[i])
133+
if (a->key[i] == b->key[i])
131134
continue;
132-
if ((__force u32)a->addr.a6[i] < (__force u32)b->addr.a6[i])
135+
if (a->key[i] < b->key[i])
133136
return -1;
134137
return 1;
135138
}

0 commit comments

Comments
 (0)