net: Introduce ipv4_addr_hash and use it for tcp metrics
authorDavid Ahern <dsa@cumulusnetworks.com>
Thu, 27 Aug 2015 23:06:59 +0000 (16:06 -0700)
committerDavid S. Miller <davem@davemloft.net>
Fri, 28 Aug 2015 20:32:35 +0000 (13:32 -0700)
Refactors a common line into helper function.

Signed-off-by: David Ahern <dsa@cumulusnetworks.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/net/ip.h
net/ipv4/tcp_metrics.c

index bee5f35..7b9e1c7 100644 (file)
@@ -458,6 +458,11 @@ static __inline__ void inet_reset_saddr(struct sock *sk)
 
 #endif
 
+static inline unsigned int ipv4_addr_hash(__be32 ip)
+{
+       return (__force unsigned int) ip;
+}
+
 bool ip_call_ra_chain(struct sk_buff *skb);
 
 /*
index b3d64f6..3a42892 100644 (file)
@@ -249,7 +249,7 @@ static struct tcp_metrics_block *__tcp_get_metrics_req(struct request_sock *req,
        case AF_INET:
                saddr.addr.a4 = inet_rsk(req)->ir_loc_addr;
                daddr.addr.a4 = inet_rsk(req)->ir_rmt_addr;
-               hash = (__force unsigned int) daddr.addr.a4;
+               hash = ipv4_addr_hash(inet_rsk(req)->ir_rmt_addr);
                break;
 #if IS_ENABLED(CONFIG_IPV6)
        case AF_INET6:
@@ -289,7 +289,7 @@ static struct tcp_metrics_block *__tcp_get_metrics_tw(struct inet_timewait_sock
                saddr.addr.a4 = tw->tw_rcv_saddr;
                daddr.family = AF_INET;
                daddr.addr.a4 = tw->tw_daddr;
-               hash = (__force unsigned int) daddr.addr.a4;
+               hash = ipv4_addr_hash(tw->tw_daddr);
        }
 #if IS_ENABLED(CONFIG_IPV6)
        else if (tw->tw_family == AF_INET6) {
@@ -298,7 +298,7 @@ static struct tcp_metrics_block *__tcp_get_metrics_tw(struct inet_timewait_sock
                        saddr.addr.a4 = tw->tw_rcv_saddr;
                        daddr.family = AF_INET;
                        daddr.addr.a4 = tw->tw_daddr;
-                       hash = (__force unsigned int) daddr.addr.a4;
+                       hash = ipv4_addr_hash(tw->tw_daddr);
                } else {
                        saddr.family = AF_INET6;
                        saddr.addr.in6 = tw->tw_v6_rcv_saddr;
@@ -339,7 +339,7 @@ static struct tcp_metrics_block *tcp_get_metrics(struct sock *sk,
                saddr.addr.a4 = inet_sk(sk)->inet_saddr;
                daddr.family = AF_INET;
                daddr.addr.a4 = inet_sk(sk)->inet_daddr;
-               hash = (__force unsigned int) daddr.addr.a4;
+               hash = ipv4_addr_hash(inet_sk(sk)->inet_daddr);
        }
 #if IS_ENABLED(CONFIG_IPV6)
        else if (sk->sk_family == AF_INET6) {
@@ -348,7 +348,7 @@ static struct tcp_metrics_block *tcp_get_metrics(struct sock *sk,
                        saddr.addr.a4 = inet_sk(sk)->inet_saddr;
                        daddr.family = AF_INET;
                        daddr.addr.a4 = inet_sk(sk)->inet_daddr;
-                       hash = (__force unsigned int) daddr.addr.a4;
+                       hash = ipv4_addr_hash(inet_sk(sk)->inet_daddr);
                } else {
                        saddr.family = AF_INET6;
                        saddr.addr.in6 = sk->sk_v6_rcv_saddr;
@@ -959,7 +959,7 @@ static int __parse_nl_addr(struct genl_info *info, struct inetpeer_addr *addr,
                addr->family = AF_INET;
                addr->addr.a4 = nla_get_in_addr(a);
                if (hash)
-                       *hash = (__force unsigned int) addr->addr.a4;
+                       *hash = ipv4_addr_hash(addr->addr.a4);
                return 0;
        }
        a = info->attrs[v6];