tcp: md5: remove request sock argument of calc_md5_hash()
authorEric Dumazet <edumazet@google.com>
Tue, 24 Mar 2015 22:58:55 +0000 (15:58 -0700)
committerDavid S. Miller <davem@davemloft.net>
Wed, 25 Mar 2015 01:16:30 +0000 (21:16 -0400)
Since request and established sockets now have same base,
there is no need to pass two pointers to tcp_v4_md5_hash_skb()
or tcp_v6_md5_hash_skb()

Also add a const qualifier to their struct tcp_md5sig_key argument.

Signed-off-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/net/tcp.h
net/ipv4/tcp_ipv4.c
net/ipv4/tcp_output.c
net/ipv6/tcp_ipv6.c

index fe60e00..992be85 100644 (file)
@@ -1296,9 +1296,8 @@ struct tcp_md5sig_pool {
 };
 
 /* - functions */
-int tcp_v4_md5_hash_skb(char *md5_hash, struct tcp_md5sig_key *key,
-                       const struct sock *sk, const struct request_sock *req,
-                       const struct sk_buff *skb);
+int tcp_v4_md5_hash_skb(char *md5_hash, const struct tcp_md5sig_key *key,
+                       const struct sock *sk, const struct sk_buff *skb);
 int tcp_md5_do_add(struct sock *sk, const union tcp_md5_addr *addr,
                   int family, const u8 *newkey, u8 newkeylen, gfp_t gfp);
 int tcp_md5_do_del(struct sock *sk, const union tcp_md5_addr *addr,
@@ -1616,14 +1615,13 @@ struct tcp_sock_af_ops {
 #ifdef CONFIG_TCP_MD5SIG
        struct tcp_md5sig_key   *(*md5_lookup) (struct sock *sk,
                                                struct sock *addr_sk);
-       int                     (*calc_md5_hash) (char *location,
-                                                 struct tcp_md5sig_key *md5,
-                                                 const struct sock *sk,
-                                                 const struct request_sock *req,
-                                                 const struct sk_buff *skb);
-       int                     (*md5_parse) (struct sock *sk,
-                                             char __user *optval,
-                                             int optlen);
+       int             (*calc_md5_hash)(char *location,
+                                        const struct tcp_md5sig_key *md5,
+                                        const struct sock *sk,
+                                        const struct sk_buff *skb);
+       int             (*md5_parse)(struct sock *sk,
+                                    char __user *optval,
+                                    int optlen);
 #endif
 };
 
@@ -1632,11 +1630,10 @@ struct tcp_request_sock_ops {
 #ifdef CONFIG_TCP_MD5SIG
        struct tcp_md5sig_key   *(*md5_lookup) (struct sock *sk,
                                                struct request_sock *req);
-       int                     (*calc_md5_hash) (char *location,
-                                                 struct tcp_md5sig_key *md5,
-                                                 const struct sock *sk,
-                                                 const struct request_sock *req,
-                                                 const struct sk_buff *skb);
+       int             (*calc_md5_hash) (char *location,
+                                         const struct tcp_md5sig_key *md5,
+                                         const struct sock *sk,
+                                         const struct sk_buff *skb);
 #endif
        void (*init_req)(struct request_sock *req, struct sock *sk,
                         struct sk_buff *skb);
index d339a04..79d5c64 100644 (file)
@@ -648,7 +648,7 @@ static void tcp_v4_send_reset(struct sock *sk, struct sk_buff *skb)
                if (!key)
                        goto release_sk1;
 
-               genhash = tcp_v4_md5_hash_skb(newhash, key, NULL, NULL, skb);
+               genhash = tcp_v4_md5_hash_skb(newhash, key, NULL, skb);
                if (genhash || memcmp(hash_location, newhash, 16) != 0)
                        goto release_sk1;
        } else {
@@ -1102,8 +1102,8 @@ clear_hash_noput:
        return 1;
 }
 
-int tcp_v4_md5_hash_skb(char *md5_hash, struct tcp_md5sig_key *key,
-                       const struct sock *sk, const struct request_sock *req,
+int tcp_v4_md5_hash_skb(char *md5_hash, const struct tcp_md5sig_key *key,
+                       const struct sock *sk,
                        const struct sk_buff *skb)
 {
        struct tcp_md5sig_pool *hp;
@@ -1111,12 +1111,9 @@ int tcp_v4_md5_hash_skb(char *md5_hash, struct tcp_md5sig_key *key,
        const struct tcphdr *th = tcp_hdr(skb);
        __be32 saddr, daddr;
 
-       if (sk) {
-               saddr = inet_sk(sk)->inet_saddr;
-               daddr = inet_sk(sk)->inet_daddr;
-       } else if (req) {
-               saddr = inet_rsk(req)->ir_loc_addr;
-               daddr = inet_rsk(req)->ir_rmt_addr;
+       if (sk) { /* valid for establish/request sockets */
+               saddr = sk->sk_rcv_saddr;
+               daddr = sk->sk_daddr;
        } else {
                const struct iphdr *iph = ip_hdr(skb);
                saddr = iph->saddr;
@@ -1195,7 +1192,7 @@ static bool tcp_v4_inbound_md5_hash(struct sock *sk,
         */
        genhash = tcp_v4_md5_hash_skb(newhash,
                                      hash_expected,
-                                     NULL, NULL, skb);
+                                     NULL, skb);
 
        if (genhash || memcmp(hash_location, newhash, 16) != 0) {
                net_info_ratelimited("MD5 Hash failed for (%pI4, %d)->(%pI4, %d)%s\n",
index 5b7fad4..501cf9d 100644 (file)
@@ -986,7 +986,7 @@ static int tcp_transmit_skb(struct sock *sk, struct sk_buff *skb, int clone_it,
        if (md5) {
                sk_nocaps_add(sk, NETIF_F_GSO_MASK);
                tp->af_specific->calc_md5_hash(opts.hash_location,
-                                              md5, sk, NULL, skb);
+                                              md5, sk, skb);
        }
 #endif
 
@@ -2973,7 +2973,7 @@ struct sk_buff *tcp_make_synack(struct sock *sk, struct dst_entry *dst,
        /* Okay, we have all we need - do the md5 hash if needed */
        if (md5)
                tcp_rsk(req)->af_specific->calc_md5_hash(opts.hash_location,
-                                              md5, NULL, req, skb);
+                                              md5, req_to_sk(req), skb);
        rcu_read_unlock();
 #endif
 
index 078e7d0..57d1c41 100644 (file)
@@ -582,9 +582,9 @@ clear_hash_noput:
        return 1;
 }
 
-static int tcp_v6_md5_hash_skb(char *md5_hash, struct tcp_md5sig_key *key,
+static int tcp_v6_md5_hash_skb(char *md5_hash,
+                              const struct tcp_md5sig_key *key,
                               const struct sock *sk,
-                              const struct request_sock *req,
                               const struct sk_buff *skb)
 {
        const struct in6_addr *saddr, *daddr;
@@ -592,12 +592,9 @@ static int tcp_v6_md5_hash_skb(char *md5_hash, struct tcp_md5sig_key *key,
        struct hash_desc *desc;
        const struct tcphdr *th = tcp_hdr(skb);
 
-       if (sk) {
-               saddr = &inet6_sk(sk)->saddr;
+       if (sk) { /* valid for establish/request sockets */
+               saddr = &sk->sk_v6_rcv_saddr;
                daddr = &sk->sk_v6_daddr;
-       } else if (req) {
-               saddr = &inet_rsk(req)->ir_v6_loc_addr;
-               daddr = &inet_rsk(req)->ir_v6_rmt_addr;
        } else {
                const struct ipv6hdr *ip6h = ipv6_hdr(skb);
                saddr = &ip6h->saddr;
@@ -662,7 +659,7 @@ static bool tcp_v6_inbound_md5_hash(struct sock *sk, const struct sk_buff *skb)
        /* check the signature */
        genhash = tcp_v6_md5_hash_skb(newhash,
                                      hash_expected,
-                                     NULL, NULL, skb);
+                                     NULL, skb);
 
        if (genhash || memcmp(hash_location, newhash, 16) != 0) {
                net_info_ratelimited("MD5 Hash %s for [%pI6c]:%u->[%pI6c]:%u\n",
@@ -880,7 +877,7 @@ static void tcp_v6_send_reset(struct sock *sk, struct sk_buff *skb)
                if (!key)
                        goto release_sk1;
 
-               genhash = tcp_v6_md5_hash_skb(newhash, key, NULL, NULL, skb);
+               genhash = tcp_v6_md5_hash_skb(newhash, key, NULL, skb);
                if (genhash || memcmp(hash_location, newhash, 16) != 0)
                        goto release_sk1;
        } else {