Commit 39f8e58e authored by Eric Dumazet's avatar Eric Dumazet Committed by David S. Miller

tcp: md5: remove request sock argument of calc_md5_hash()

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: default avatarEric Dumazet <edumazet@google.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent ff74e23f
...@@ -1296,9 +1296,8 @@ struct tcp_md5sig_pool { ...@@ -1296,9 +1296,8 @@ struct tcp_md5sig_pool {
}; };
/* - functions */ /* - functions */
int tcp_v4_md5_hash_skb(char *md5_hash, struct tcp_md5sig_key *key, int tcp_v4_md5_hash_skb(char *md5_hash, const struct tcp_md5sig_key *key,
const struct sock *sk, const struct request_sock *req, const struct sock *sk, const struct sk_buff *skb);
const struct sk_buff *skb);
int tcp_md5_do_add(struct sock *sk, const union tcp_md5_addr *addr, 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 family, const u8 *newkey, u8 newkeylen, gfp_t gfp);
int tcp_md5_do_del(struct sock *sk, const union tcp_md5_addr *addr, int tcp_md5_do_del(struct sock *sk, const union tcp_md5_addr *addr,
...@@ -1616,14 +1615,13 @@ struct tcp_sock_af_ops { ...@@ -1616,14 +1615,13 @@ struct tcp_sock_af_ops {
#ifdef CONFIG_TCP_MD5SIG #ifdef CONFIG_TCP_MD5SIG
struct tcp_md5sig_key *(*md5_lookup) (struct sock *sk, struct tcp_md5sig_key *(*md5_lookup) (struct sock *sk,
struct sock *addr_sk); struct sock *addr_sk);
int (*calc_md5_hash) (char *location, int (*calc_md5_hash)(char *location,
struct tcp_md5sig_key *md5, const struct tcp_md5sig_key *md5,
const struct sock *sk, const struct sock *sk,
const struct request_sock *req, const struct sk_buff *skb);
const struct sk_buff *skb); int (*md5_parse)(struct sock *sk,
int (*md5_parse) (struct sock *sk, char __user *optval,
char __user *optval, int optlen);
int optlen);
#endif #endif
}; };
...@@ -1632,11 +1630,10 @@ struct tcp_request_sock_ops { ...@@ -1632,11 +1630,10 @@ struct tcp_request_sock_ops {
#ifdef CONFIG_TCP_MD5SIG #ifdef CONFIG_TCP_MD5SIG
struct tcp_md5sig_key *(*md5_lookup) (struct sock *sk, struct tcp_md5sig_key *(*md5_lookup) (struct sock *sk,
struct request_sock *req); struct request_sock *req);
int (*calc_md5_hash) (char *location, int (*calc_md5_hash) (char *location,
struct tcp_md5sig_key *md5, const struct tcp_md5sig_key *md5,
const struct sock *sk, const struct sock *sk,
const struct request_sock *req, const struct sk_buff *skb);
const struct sk_buff *skb);
#endif #endif
void (*init_req)(struct request_sock *req, struct sock *sk, void (*init_req)(struct request_sock *req, struct sock *sk,
struct sk_buff *skb); struct sk_buff *skb);
......
...@@ -648,7 +648,7 @@ static void tcp_v4_send_reset(struct sock *sk, struct sk_buff *skb) ...@@ -648,7 +648,7 @@ static void tcp_v4_send_reset(struct sock *sk, struct sk_buff *skb)
if (!key) if (!key)
goto release_sk1; 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) if (genhash || memcmp(hash_location, newhash, 16) != 0)
goto release_sk1; goto release_sk1;
} else { } else {
...@@ -1102,8 +1102,8 @@ static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key, ...@@ -1102,8 +1102,8 @@ static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
return 1; return 1;
} }
int tcp_v4_md5_hash_skb(char *md5_hash, struct tcp_md5sig_key *key, int tcp_v4_md5_hash_skb(char *md5_hash, const struct tcp_md5sig_key *key,
const struct sock *sk, const struct request_sock *req, const struct sock *sk,
const struct sk_buff *skb) const struct sk_buff *skb)
{ {
struct tcp_md5sig_pool *hp; struct tcp_md5sig_pool *hp;
...@@ -1111,12 +1111,9 @@ int tcp_v4_md5_hash_skb(char *md5_hash, struct tcp_md5sig_key *key, ...@@ -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); const struct tcphdr *th = tcp_hdr(skb);
__be32 saddr, daddr; __be32 saddr, daddr;
if (sk) { if (sk) { /* valid for establish/request sockets */
saddr = inet_sk(sk)->inet_saddr; saddr = sk->sk_rcv_saddr;
daddr = inet_sk(sk)->inet_daddr; daddr = sk->sk_daddr;
} else if (req) {
saddr = inet_rsk(req)->ir_loc_addr;
daddr = inet_rsk(req)->ir_rmt_addr;
} else { } else {
const struct iphdr *iph = ip_hdr(skb); const struct iphdr *iph = ip_hdr(skb);
saddr = iph->saddr; saddr = iph->saddr;
...@@ -1195,7 +1192,7 @@ static bool tcp_v4_inbound_md5_hash(struct sock *sk, ...@@ -1195,7 +1192,7 @@ static bool tcp_v4_inbound_md5_hash(struct sock *sk,
*/ */
genhash = tcp_v4_md5_hash_skb(newhash, genhash = tcp_v4_md5_hash_skb(newhash,
hash_expected, hash_expected,
NULL, NULL, skb); NULL, skb);
if (genhash || memcmp(hash_location, newhash, 16) != 0) { if (genhash || memcmp(hash_location, newhash, 16) != 0) {
net_info_ratelimited("MD5 Hash failed for (%pI4, %d)->(%pI4, %d)%s\n", net_info_ratelimited("MD5 Hash failed for (%pI4, %d)->(%pI4, %d)%s\n",
......
...@@ -986,7 +986,7 @@ static int tcp_transmit_skb(struct sock *sk, struct sk_buff *skb, int clone_it, ...@@ -986,7 +986,7 @@ static int tcp_transmit_skb(struct sock *sk, struct sk_buff *skb, int clone_it,
if (md5) { if (md5) {
sk_nocaps_add(sk, NETIF_F_GSO_MASK); sk_nocaps_add(sk, NETIF_F_GSO_MASK);
tp->af_specific->calc_md5_hash(opts.hash_location, tp->af_specific->calc_md5_hash(opts.hash_location,
md5, sk, NULL, skb); md5, sk, skb);
} }
#endif #endif
...@@ -2973,7 +2973,7 @@ struct sk_buff *tcp_make_synack(struct sock *sk, struct dst_entry *dst, ...@@ -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 */ /* Okay, we have all we need - do the md5 hash if needed */
if (md5) if (md5)
tcp_rsk(req)->af_specific->calc_md5_hash(opts.hash_location, tcp_rsk(req)->af_specific->calc_md5_hash(opts.hash_location,
md5, NULL, req, skb); md5, req_to_sk(req), skb);
rcu_read_unlock(); rcu_read_unlock();
#endif #endif
......
...@@ -582,9 +582,9 @@ static int tcp_v6_md5_hash_hdr(char *md5_hash, struct tcp_md5sig_key *key, ...@@ -582,9 +582,9 @@ static int tcp_v6_md5_hash_hdr(char *md5_hash, struct tcp_md5sig_key *key,
return 1; 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 sock *sk,
const struct request_sock *req,
const struct sk_buff *skb) const struct sk_buff *skb)
{ {
const struct in6_addr *saddr, *daddr; 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, ...@@ -592,12 +592,9 @@ static int tcp_v6_md5_hash_skb(char *md5_hash, struct tcp_md5sig_key *key,
struct hash_desc *desc; struct hash_desc *desc;
const struct tcphdr *th = tcp_hdr(skb); const struct tcphdr *th = tcp_hdr(skb);
if (sk) { if (sk) { /* valid for establish/request sockets */
saddr = &inet6_sk(sk)->saddr; saddr = &sk->sk_v6_rcv_saddr;
daddr = &sk->sk_v6_daddr; 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 { } else {
const struct ipv6hdr *ip6h = ipv6_hdr(skb); const struct ipv6hdr *ip6h = ipv6_hdr(skb);
saddr = &ip6h->saddr; saddr = &ip6h->saddr;
...@@ -662,7 +659,7 @@ static bool tcp_v6_inbound_md5_hash(struct sock *sk, const struct sk_buff *skb) ...@@ -662,7 +659,7 @@ static bool tcp_v6_inbound_md5_hash(struct sock *sk, const struct sk_buff *skb)
/* check the signature */ /* check the signature */
genhash = tcp_v6_md5_hash_skb(newhash, genhash = tcp_v6_md5_hash_skb(newhash,
hash_expected, hash_expected,
NULL, NULL, skb); NULL, skb);
if (genhash || memcmp(hash_location, newhash, 16) != 0) { if (genhash || memcmp(hash_location, newhash, 16) != 0) {
net_info_ratelimited("MD5 Hash %s for [%pI6c]:%u->[%pI6c]:%u\n", 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) ...@@ -880,7 +877,7 @@ static void tcp_v6_send_reset(struct sock *sk, struct sk_buff *skb)
if (!key) if (!key)
goto release_sk1; 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) if (genhash || memcmp(hash_location, newhash, 16) != 0)
goto release_sk1; goto release_sk1;
} else { } else {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment