aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJiri Benc <jbenc@redhat.com>2015-03-29 10:59:23 -0400
committerDavid S. Miller <davem@davemloft.net>2015-03-31 13:58:35 -0400
commit8f55db48608b109ad8c7ff4b946ad39b3189a540 (patch)
treeb7364235d94c0e15aa491858a4a574182292f5e1
parentf0ef31264cde8b489a0b87149ebc3a72cef4c58a (diff)
tcp: simplify inetpeer_addr_base use
In many places, the a6 field is typecasted to struct in6_addr. As the fields are in union anyway, just add in6_addr type to the union and get rid of the typecasting. Signed-off-by: Jiri Benc <jbenc@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--include/net/inetpeer.h3
-rw-r--r--net/ipv4/tcp_metrics.c22
2 files changed, 10 insertions, 15 deletions
diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
index 80479abddf73..d5332ddcea3f 100644
--- a/include/net/inetpeer.h
+++ b/include/net/inetpeer.h
@@ -19,6 +19,7 @@ struct inetpeer_addr_base {
19 union { 19 union {
20 __be32 a4; 20 __be32 a4;
21 __be32 a6[4]; 21 __be32 a6[4];
22 struct in6_addr in6;
22 }; 23 };
23}; 24};
24 25
@@ -151,7 +152,7 @@ static inline struct inet_peer *inet_getpeer_v6(struct inet_peer_base *base,
151{ 152{
152 struct inetpeer_addr daddr; 153 struct inetpeer_addr daddr;
153 154
154 *(struct in6_addr *)daddr.addr.a6 = *v6daddr; 155 daddr.addr.in6 = *v6daddr;
155 daddr.family = AF_INET6; 156 daddr.family = AF_INET6;
156 return inet_getpeer(base, &daddr, create); 157 return inet_getpeer(base, &daddr, create);
157} 158}
diff --git a/net/ipv4/tcp_metrics.c b/net/ipv4/tcp_metrics.c
index 5bef3513af77..f62c2c68ced0 100644
--- a/net/ipv4/tcp_metrics.c
+++ b/net/ipv4/tcp_metrics.c
@@ -80,17 +80,11 @@ static void tcp_metric_set(struct tcp_metrics_block *tm,
80static bool addr_same(const struct inetpeer_addr *a, 80static bool addr_same(const struct inetpeer_addr *a,
81 const struct inetpeer_addr *b) 81 const struct inetpeer_addr *b)
82{ 82{
83 const struct in6_addr *a6, *b6;
84
85 if (a->family != b->family) 83 if (a->family != b->family)
86 return false; 84 return false;
87 if (a->family == AF_INET) 85 if (a->family == AF_INET)
88 return a->addr.a4 == b->addr.a4; 86 return a->addr.a4 == b->addr.a4;
89 87 return ipv6_addr_equal(&a->addr.in6, &b->addr.in6);
90 a6 = (const struct in6_addr *) &a->addr.a6[0];
91 b6 = (const struct in6_addr *) &b->addr.a6[0];
92
93 return ipv6_addr_equal(a6, b6);
94} 88}
95 89
96struct tcpm_hash_bucket { 90struct tcpm_hash_bucket {
@@ -256,8 +250,8 @@ static struct tcp_metrics_block *__tcp_get_metrics_req(struct request_sock *req,
256 break; 250 break;
257#if IS_ENABLED(CONFIG_IPV6) 251#if IS_ENABLED(CONFIG_IPV6)
258 case AF_INET6: 252 case AF_INET6:
259 *(struct in6_addr *)saddr.addr.a6 = inet_rsk(req)->ir_v6_loc_addr; 253 saddr.addr.in6 = inet_rsk(req)->ir_v6_loc_addr;
260 *(struct in6_addr *)daddr.addr.a6 = inet_rsk(req)->ir_v6_rmt_addr; 254 daddr.addr.in6 = inet_rsk(req)->ir_v6_rmt_addr;
261 hash = ipv6_addr_hash(&inet_rsk(req)->ir_v6_rmt_addr); 255 hash = ipv6_addr_hash(&inet_rsk(req)->ir_v6_rmt_addr);
262 break; 256 break;
263#endif 257#endif
@@ -304,9 +298,9 @@ static struct tcp_metrics_block *__tcp_get_metrics_tw(struct inet_timewait_sock
304 hash = (__force unsigned int) daddr.addr.a4; 298 hash = (__force unsigned int) daddr.addr.a4;
305 } else { 299 } else {
306 saddr.family = AF_INET6; 300 saddr.family = AF_INET6;
307 *(struct in6_addr *)saddr.addr.a6 = tw->tw_v6_rcv_saddr; 301 saddr.addr.in6 = tw->tw_v6_rcv_saddr;
308 daddr.family = AF_INET6; 302 daddr.family = AF_INET6;
309 *(struct in6_addr *)daddr.addr.a6 = tw->tw_v6_daddr; 303 daddr.addr.in6 = tw->tw_v6_daddr;
310 hash = ipv6_addr_hash(&tw->tw_v6_daddr); 304 hash = ipv6_addr_hash(&tw->tw_v6_daddr);
311 } 305 }
312 } 306 }
@@ -354,9 +348,9 @@ static struct tcp_metrics_block *tcp_get_metrics(struct sock *sk,
354 hash = (__force unsigned int) daddr.addr.a4; 348 hash = (__force unsigned int) daddr.addr.a4;
355 } else { 349 } else {
356 saddr.family = AF_INET6; 350 saddr.family = AF_INET6;
357 *(struct in6_addr *)saddr.addr.a6 = sk->sk_v6_rcv_saddr; 351 saddr.addr.in6 = sk->sk_v6_rcv_saddr;
358 daddr.family = AF_INET6; 352 daddr.family = AF_INET6;
359 *(struct in6_addr *)daddr.addr.a6 = sk->sk_v6_daddr; 353 daddr.addr.in6 = sk->sk_v6_daddr;
360 hash = ipv6_addr_hash(&sk->sk_v6_daddr); 354 hash = ipv6_addr_hash(&sk->sk_v6_daddr);
361 } 355 }
362 } 356 }
@@ -966,7 +960,7 @@ static int __parse_nl_addr(struct genl_info *info, struct inetpeer_addr *addr,
966 addr->family = AF_INET6; 960 addr->family = AF_INET6;
967 memcpy(addr->addr.a6, nla_data(a), sizeof(addr->addr.a6)); 961 memcpy(addr->addr.a6, nla_data(a), sizeof(addr->addr.a6));
968 if (hash) 962 if (hash)
969 *hash = ipv6_addr_hash((struct in6_addr *) addr->addr.a6); 963 *hash = ipv6_addr_hash(&addr->addr.in6);
970 return 0; 964 return 0;
971 } 965 }
972 return optional ? 1 : -EAFNOSUPPORT; 966 return optional ? 1 : -EAFNOSUPPORT;