diff options
author | David Ahern <dsa@cumulusnetworks.com> | 2015-08-27 19:07:02 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2015-08-28 16:32:36 -0400 |
commit | 5345c2e12d41f815c1009c9dee72f3d5fcfd4282 (patch) | |
tree | 65e011d6d82252a935a93044dc7bc99beb32bf90 | |
parent | d39d14ffa24cca9f0e44aa4a63315f4c44c56a93 (diff) |
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>
-rw-r--r-- | include/net/inetpeer.h | 35 |
1 files changed, 19 insertions, 16 deletions
diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h index 9d9b3446731d..e34f98aa93b1 100644 --- a/include/net/inetpeer.h +++ b/include/net/inetpeer.h | |||
@@ -15,16 +15,14 @@ | |||
15 | #include <net/ipv6.h> | 15 | #include <net/ipv6.h> |
16 | #include <linux/atomic.h> | 16 | #include <linux/atomic.h> |
17 | 17 | ||
18 | struct inetpeer_addr_base { | 18 | #define INETPEER_MAXKEYSZ (sizeof(struct in6_addr) / sizeof(u32)) |
19 | |||
20 | struct inetpeer_addr { | ||
19 | union { | 21 | union { |
20 | __be32 a4; | 22 | __be32 a4; |
21 | __be32 a6[4]; | 23 | struct in6_addr a6; |
22 | struct in6_addr in6; | 24 | u32 key[INETPEER_MAXKEYSZ]; |
23 | }; | 25 | }; |
24 | }; | ||
25 | |||
26 | struct inetpeer_addr { | ||
27 | struct inetpeer_addr_base addr; | ||
28 | __u16 family; | 26 | __u16 family; |
29 | }; | 27 | }; |
30 | 28 | ||
@@ -73,25 +71,25 @@ void inet_initpeers(void) __init; | |||
73 | 71 | ||
74 | static inline void inetpeer_set_addr_v4(struct inetpeer_addr *iaddr, __be32 ip) | 72 | static inline void inetpeer_set_addr_v4(struct inetpeer_addr *iaddr, __be32 ip) |
75 | { | 73 | { |
76 | iaddr->addr.a4 = ip; | 74 | iaddr->a4 = ip; |
77 | iaddr->family = AF_INET; | 75 | iaddr->family = AF_INET; |
78 | } | 76 | } |
79 | 77 | ||
80 | static inline __be32 inetpeer_get_addr_v4(struct inetpeer_addr *iaddr) | 78 | static inline __be32 inetpeer_get_addr_v4(struct inetpeer_addr *iaddr) |
81 | { | 79 | { |
82 | return iaddr->addr.a4; | 80 | return iaddr->a4; |
83 | } | 81 | } |
84 | 82 | ||
85 | static inline void inetpeer_set_addr_v6(struct inetpeer_addr *iaddr, | 83 | static inline void inetpeer_set_addr_v6(struct inetpeer_addr *iaddr, |
86 | struct in6_addr *in6) | 84 | struct in6_addr *in6) |
87 | { | 85 | { |
88 | iaddr->addr.in6 = *in6; | 86 | iaddr->a6 = *in6; |
89 | iaddr->family = AF_INET6; | 87 | iaddr->family = AF_INET6; |
90 | } | 88 | } |
91 | 89 | ||
92 | static inline struct in6_addr *inetpeer_get_addr_v6(struct inetpeer_addr *iaddr) | 90 | static inline struct in6_addr *inetpeer_get_addr_v6(struct inetpeer_addr *iaddr) |
93 | { | 91 | { |
94 | return &iaddr->addr.in6; | 92 | return &iaddr->a6; |
95 | } | 93 | } |
96 | 94 | ||
97 | /* can be called with or without local BH being disabled */ | 95 | /* 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, | |||
105 | { | 103 | { |
106 | struct inetpeer_addr daddr; | 104 | struct inetpeer_addr daddr; |
107 | 105 | ||
108 | daddr.addr.a4 = v4daddr; | 106 | daddr.a4 = v4daddr; |
109 | daddr.family = AF_INET; | 107 | daddr.family = AF_INET; |
110 | return inet_getpeer(base, &daddr, create); | 108 | return inet_getpeer(base, &daddr, create); |
111 | } | 109 | } |
@@ -116,7 +114,7 @@ static inline struct inet_peer *inet_getpeer_v6(struct inet_peer_base *base, | |||
116 | { | 114 | { |
117 | struct inetpeer_addr daddr; | 115 | struct inetpeer_addr daddr; |
118 | 116 | ||
119 | daddr.addr.in6 = *v6daddr; | 117 | daddr.a6 = *v6daddr; |
120 | daddr.family = AF_INET6; | 118 | daddr.family = AF_INET6; |
121 | return inet_getpeer(base, &daddr, create); | 119 | return inet_getpeer(base, &daddr, create); |
122 | } | 120 | } |
@@ -124,12 +122,17 @@ static inline struct inet_peer *inet_getpeer_v6(struct inet_peer_base *base, | |||
124 | static inline int inetpeer_addr_cmp(const struct inetpeer_addr *a, | 122 | static inline int inetpeer_addr_cmp(const struct inetpeer_addr *a, |
125 | const struct inetpeer_addr *b) | 123 | const struct inetpeer_addr *b) |
126 | { | 124 | { |
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); | ||
128 | 131 | ||
129 | for (i = 0; i < n; i++) { | 132 | for (i = 0; i < n; i++) { |
130 | if (a->addr.a6[i] == b->addr.a6[i]) | 133 | if (a->key[i] == b->key[i]) |
131 | continue; | 134 | continue; |
132 | if ((__force u32)a->addr.a6[i] < (__force u32)b->addr.a6[i]) | 135 | if (a->key[i] < b->key[i]) |
133 | return -1; | 136 | return -1; |
134 | return 1; | 137 | return 1; |
135 | } | 138 | } |