aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Ahern <dsa@cumulusnetworks.com>2015-08-27 19:07:00 -0400
committerDavid S. Miller <davem@davemloft.net>2015-08-28 16:32:36 -0400
commit3abef286cf2f138de353fb0b54453621de961043 (patch)
treed5039d81fdd2138172026509bc501609020b090e
parent72afa352d6a3d4da7783b5ddee02b94be49e051a (diff)
net: Add set,get helpers for inetpeer addresses
Use inetpeer set,get helpers in tcp_metrics rather than peeking into the inetpeer_addr struct. Signed-off-by: David Ahern <dsa@cumulusnetworks.com> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--include/net/inetpeer.h23
-rw-r--r--net/ipv4/tcp_metrics.c65
2 files changed, 50 insertions, 38 deletions
diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
index 002f0bd27001..f75b9e7036a2 100644
--- a/include/net/inetpeer.h
+++ b/include/net/inetpeer.h
@@ -71,6 +71,29 @@ void inet_initpeers(void) __init;
71 71
72#define INETPEER_METRICS_NEW (~(u32) 0) 72#define INETPEER_METRICS_NEW (~(u32) 0)
73 73
74static inline void inetpeer_set_addr_v4(struct inetpeer_addr *iaddr, __be32 ip)
75{
76 iaddr->addr.a4 = ip;
77 iaddr->family = AF_INET;
78}
79
80static inline __be32 inetpeer_get_addr_v4(struct inetpeer_addr *iaddr)
81{
82 return iaddr->addr.a4;
83}
84
85static inline void inetpeer_set_addr_v6(struct inetpeer_addr *iaddr,
86 struct in6_addr *in6)
87{
88 iaddr->addr.in6 = *in6;
89 iaddr->family = AF_INET6;
90}
91
92static inline struct in6_addr *inetpeer_get_addr_v6(struct inetpeer_addr *iaddr)
93{
94 return &iaddr->addr.in6;
95}
96
74/* can be called with or without local BH being disabled */ 97/* can be called with or without local BH being disabled */
75struct inet_peer *inet_getpeer(struct inet_peer_base *base, 98struct inet_peer *inet_getpeer(struct inet_peer_base *base,
76 const struct inetpeer_addr *daddr, 99 const struct inetpeer_addr *daddr,
diff --git a/net/ipv4/tcp_metrics.c b/net/ipv4/tcp_metrics.c
index 3a4289268f97..4ef4dd4bf38c 100644
--- a/net/ipv4/tcp_metrics.c
+++ b/net/ipv4/tcp_metrics.c
@@ -247,14 +247,14 @@ static struct tcp_metrics_block *__tcp_get_metrics_req(struct request_sock *req,
247 daddr.family = req->rsk_ops->family; 247 daddr.family = req->rsk_ops->family;
248 switch (daddr.family) { 248 switch (daddr.family) {
249 case AF_INET: 249 case AF_INET:
250 saddr.addr.a4 = inet_rsk(req)->ir_loc_addr; 250 inetpeer_set_addr_v4(&saddr, inet_rsk(req)->ir_loc_addr);
251 daddr.addr.a4 = inet_rsk(req)->ir_rmt_addr; 251 inetpeer_set_addr_v4(&daddr, inet_rsk(req)->ir_rmt_addr);
252 hash = ipv4_addr_hash(inet_rsk(req)->ir_rmt_addr); 252 hash = ipv4_addr_hash(inet_rsk(req)->ir_rmt_addr);
253 break; 253 break;
254#if IS_ENABLED(CONFIG_IPV6) 254#if IS_ENABLED(CONFIG_IPV6)
255 case AF_INET6: 255 case AF_INET6:
256 saddr.addr.in6 = inet_rsk(req)->ir_v6_loc_addr; 256 inetpeer_set_addr_v6(&saddr, &inet_rsk(req)->ir_v6_loc_addr);
257 daddr.addr.in6 = inet_rsk(req)->ir_v6_rmt_addr; 257 inetpeer_set_addr_v6(&daddr, &inet_rsk(req)->ir_v6_rmt_addr);
258 hash = ipv6_addr_hash(&inet_rsk(req)->ir_v6_rmt_addr); 258 hash = ipv6_addr_hash(&inet_rsk(req)->ir_v6_rmt_addr);
259 break; 259 break;
260#endif 260#endif
@@ -285,25 +285,19 @@ static struct tcp_metrics_block *__tcp_get_metrics_tw(struct inet_timewait_sock
285 struct net *net; 285 struct net *net;
286 286
287 if (tw->tw_family == AF_INET) { 287 if (tw->tw_family == AF_INET) {
288 saddr.family = AF_INET; 288 inetpeer_set_addr_v4(&saddr, tw->tw_rcv_saddr);
289 saddr.addr.a4 = tw->tw_rcv_saddr; 289 inetpeer_set_addr_v4(&daddr, tw->tw_daddr);
290 daddr.family = AF_INET;
291 daddr.addr.a4 = tw->tw_daddr;
292 hash = ipv4_addr_hash(tw->tw_daddr); 290 hash = ipv4_addr_hash(tw->tw_daddr);
293 } 291 }
294#if IS_ENABLED(CONFIG_IPV6) 292#if IS_ENABLED(CONFIG_IPV6)
295 else if (tw->tw_family == AF_INET6) { 293 else if (tw->tw_family == AF_INET6) {
296 if (ipv6_addr_v4mapped(&tw->tw_v6_daddr)) { 294 if (ipv6_addr_v4mapped(&tw->tw_v6_daddr)) {
297 saddr.family = AF_INET; 295 inetpeer_set_addr_v4(&saddr, tw->tw_rcv_saddr);
298 saddr.addr.a4 = tw->tw_rcv_saddr; 296 inetpeer_set_addr_v4(&daddr, tw->tw_daddr);
299 daddr.family = AF_INET;
300 daddr.addr.a4 = tw->tw_daddr;
301 hash = ipv4_addr_hash(tw->tw_daddr); 297 hash = ipv4_addr_hash(tw->tw_daddr);
302 } else { 298 } else {
303 saddr.family = AF_INET6; 299 inetpeer_set_addr_v6(&saddr, &tw->tw_v6_rcv_saddr);
304 saddr.addr.in6 = tw->tw_v6_rcv_saddr; 300 inetpeer_set_addr_v6(&daddr, &tw->tw_v6_daddr);
305 daddr.family = AF_INET6;
306 daddr.addr.in6 = tw->tw_v6_daddr;
307 hash = ipv6_addr_hash(&tw->tw_v6_daddr); 301 hash = ipv6_addr_hash(&tw->tw_v6_daddr);
308 } 302 }
309 } 303 }
@@ -335,25 +329,19 @@ static struct tcp_metrics_block *tcp_get_metrics(struct sock *sk,
335 struct net *net; 329 struct net *net;
336 330
337 if (sk->sk_family == AF_INET) { 331 if (sk->sk_family == AF_INET) {
338 saddr.family = AF_INET; 332 inetpeer_set_addr_v4(&saddr, inet_sk(sk)->inet_saddr);
339 saddr.addr.a4 = inet_sk(sk)->inet_saddr; 333 inetpeer_set_addr_v4(&daddr, inet_sk(sk)->inet_daddr);
340 daddr.family = AF_INET;
341 daddr.addr.a4 = inet_sk(sk)->inet_daddr;
342 hash = ipv4_addr_hash(inet_sk(sk)->inet_daddr); 334 hash = ipv4_addr_hash(inet_sk(sk)->inet_daddr);
343 } 335 }
344#if IS_ENABLED(CONFIG_IPV6) 336#if IS_ENABLED(CONFIG_IPV6)
345 else if (sk->sk_family == AF_INET6) { 337 else if (sk->sk_family == AF_INET6) {
346 if (ipv6_addr_v4mapped(&sk->sk_v6_daddr)) { 338 if (ipv6_addr_v4mapped(&sk->sk_v6_daddr)) {
347 saddr.family = AF_INET; 339 inetpeer_set_addr_v4(&saddr, inet_sk(sk)->inet_saddr);
348 saddr.addr.a4 = inet_sk(sk)->inet_saddr; 340 inetpeer_set_addr_v4(&daddr, inet_sk(sk)->inet_daddr);
349 daddr.family = AF_INET;
350 daddr.addr.a4 = inet_sk(sk)->inet_daddr;
351 hash = ipv4_addr_hash(inet_sk(sk)->inet_daddr); 341 hash = ipv4_addr_hash(inet_sk(sk)->inet_daddr);
352 } else { 342 } else {
353 saddr.family = AF_INET6; 343 inetpeer_set_addr_v6(&saddr, &sk->sk_v6_rcv_saddr);
354 saddr.addr.in6 = sk->sk_v6_rcv_saddr; 344 inetpeer_set_addr_v6(&daddr, &sk->sk_v6_daddr);
355 daddr.family = AF_INET6;
356 daddr.addr.in6 = sk->sk_v6_daddr;
357 hash = ipv6_addr_hash(&sk->sk_v6_daddr); 345 hash = ipv6_addr_hash(&sk->sk_v6_daddr);
358 } 346 }
359 } 347 }
@@ -796,18 +784,18 @@ static int tcp_metrics_fill_info(struct sk_buff *msg,
796 switch (tm->tcpm_daddr.family) { 784 switch (tm->tcpm_daddr.family) {
797 case AF_INET: 785 case AF_INET:
798 if (nla_put_in_addr(msg, TCP_METRICS_ATTR_ADDR_IPV4, 786 if (nla_put_in_addr(msg, TCP_METRICS_ATTR_ADDR_IPV4,
799 tm->tcpm_daddr.addr.a4) < 0) 787 inetpeer_get_addr_v4(&tm->tcpm_daddr)) < 0)
800 goto nla_put_failure; 788 goto nla_put_failure;
801 if (nla_put_in_addr(msg, TCP_METRICS_ATTR_SADDR_IPV4, 789 if (nla_put_in_addr(msg, TCP_METRICS_ATTR_SADDR_IPV4,
802 tm->tcpm_saddr.addr.a4) < 0) 790 inetpeer_get_addr_v4(&tm->tcpm_saddr)) < 0)
803 goto nla_put_failure; 791 goto nla_put_failure;
804 break; 792 break;
805 case AF_INET6: 793 case AF_INET6:
806 if (nla_put_in6_addr(msg, TCP_METRICS_ATTR_ADDR_IPV6, 794 if (nla_put_in6_addr(msg, TCP_METRICS_ATTR_ADDR_IPV6,
807 &tm->tcpm_daddr.addr.in6) < 0) 795 inetpeer_get_addr_v6(&tm->tcpm_daddr)) < 0)
808 goto nla_put_failure; 796 goto nla_put_failure;
809 if (nla_put_in6_addr(msg, TCP_METRICS_ATTR_SADDR_IPV6, 797 if (nla_put_in6_addr(msg, TCP_METRICS_ATTR_SADDR_IPV6,
810 &tm->tcpm_saddr.addr.in6) < 0) 798 inetpeer_get_addr_v6(&tm->tcpm_saddr)) < 0)
811 goto nla_put_failure; 799 goto nla_put_failure;
812 break; 800 break;
813 default: 801 default:
@@ -956,20 +944,21 @@ static int __parse_nl_addr(struct genl_info *info, struct inetpeer_addr *addr,
956 944
957 a = info->attrs[v4]; 945 a = info->attrs[v4];
958 if (a) { 946 if (a) {
959 addr->family = AF_INET; 947 inetpeer_set_addr_v4(addr, nla_get_in_addr(a));
960 addr->addr.a4 = nla_get_in_addr(a);
961 if (hash) 948 if (hash)
962 *hash = ipv4_addr_hash(addr->addr.a4); 949 *hash = ipv4_addr_hash(inetpeer_get_addr_v4(addr));
963 return 0; 950 return 0;
964 } 951 }
965 a = info->attrs[v6]; 952 a = info->attrs[v6];
966 if (a) { 953 if (a) {
954 struct in6_addr in6;
955
967 if (nla_len(a) != sizeof(struct in6_addr)) 956 if (nla_len(a) != sizeof(struct in6_addr))
968 return -EINVAL; 957 return -EINVAL;
969 addr->family = AF_INET6; 958 in6 = nla_get_in6_addr(a);
970 addr->addr.in6 = nla_get_in6_addr(a); 959 inetpeer_set_addr_v6(addr, &in6);
971 if (hash) 960 if (hash)
972 *hash = ipv6_addr_hash(&addr->addr.in6); 961 *hash = ipv6_addr_hash(inetpeer_get_addr_v6(addr));
973 return 0; 962 return 0;
974 } 963 }
975 return optional ? 1 : -EAFNOSUPPORT; 964 return optional ? 1 : -EAFNOSUPPORT;