|
@@ -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 {
|
|
@@ -898,10 +898,10 @@ struct tcp_md5sig_key *tcp_md5_do_lookup(struct sock *sk,
|
|
|
const union tcp_md5_addr *addr,
|
|
|
int family)
|
|
|
{
|
|
|
- struct tcp_sock *tp = tcp_sk(sk);
|
|
|
+ const struct tcp_sock *tp = tcp_sk(sk);
|
|
|
struct tcp_md5sig_key *key;
|
|
|
unsigned int size = sizeof(struct in_addr);
|
|
|
- struct tcp_md5sig_info *md5sig;
|
|
|
+ const struct tcp_md5sig_info *md5sig;
|
|
|
|
|
|
/* caller either holds rcu_read_lock() or socket lock */
|
|
|
md5sig = rcu_dereference_check(tp->md5sig_info,
|
|
@@ -924,24 +924,15 @@ struct tcp_md5sig_key *tcp_md5_do_lookup(struct sock *sk,
|
|
|
EXPORT_SYMBOL(tcp_md5_do_lookup);
|
|
|
|
|
|
struct tcp_md5sig_key *tcp_v4_md5_lookup(struct sock *sk,
|
|
|
- struct sock *addr_sk)
|
|
|
+ const struct sock *addr_sk)
|
|
|
{
|
|
|
union tcp_md5_addr *addr;
|
|
|
|
|
|
- addr = (union tcp_md5_addr *)&inet_sk(addr_sk)->inet_daddr;
|
|
|
+ addr = (union tcp_md5_addr *)&sk->sk_daddr;
|
|
|
return tcp_md5_do_lookup(sk, addr, AF_INET);
|
|
|
}
|
|
|
EXPORT_SYMBOL(tcp_v4_md5_lookup);
|
|
|
|
|
|
-static struct tcp_md5sig_key *tcp_v4_reqsk_md5_lookup(struct sock *sk,
|
|
|
- struct request_sock *req)
|
|
|
-{
|
|
|
- union tcp_md5_addr *addr;
|
|
|
-
|
|
|
- addr = (union tcp_md5_addr *)&inet_rsk(req)->ir_rmt_addr;
|
|
|
- return tcp_md5_do_lookup(sk, addr, AF_INET);
|
|
|
-}
|
|
|
-
|
|
|
/* This can be called on a newly created socket, from other files */
|
|
|
int tcp_md5_do_add(struct sock *sk, const union tcp_md5_addr *addr,
|
|
|
int family, const u8 *newkey, u8 newkeylen, gfp_t gfp)
|
|
@@ -1102,8 +1093,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 +1102,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;
|
|
@@ -1153,8 +1141,9 @@ clear_hash_noput:
|
|
|
}
|
|
|
EXPORT_SYMBOL(tcp_v4_md5_hash_skb);
|
|
|
|
|
|
-static bool __tcp_v4_inbound_md5_hash(struct sock *sk,
|
|
|
- const struct sk_buff *skb)
|
|
|
+/* Called with rcu_read_lock() */
|
|
|
+static bool tcp_v4_inbound_md5_hash(struct sock *sk,
|
|
|
+ const struct sk_buff *skb)
|
|
|
{
|
|
|
/*
|
|
|
* This gets called for each TCP segment that arrives
|
|
@@ -1194,7 +1183,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",
|
|
@@ -1206,18 +1195,6 @@ static bool __tcp_v4_inbound_md5_hash(struct sock *sk,
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
-
|
|
|
-static bool tcp_v4_inbound_md5_hash(struct sock *sk, const struct sk_buff *skb)
|
|
|
-{
|
|
|
- bool ret;
|
|
|
-
|
|
|
- rcu_read_lock();
|
|
|
- ret = __tcp_v4_inbound_md5_hash(sk, skb);
|
|
|
- rcu_read_unlock();
|
|
|
-
|
|
|
- return ret;
|
|
|
-}
|
|
|
-
|
|
|
#endif
|
|
|
|
|
|
static void tcp_v4_init_req(struct request_sock *req, struct sock *sk_listener,
|
|
@@ -1261,7 +1238,7 @@ struct request_sock_ops tcp_request_sock_ops __read_mostly = {
|
|
|
static const struct tcp_request_sock_ops tcp_request_sock_ipv4_ops = {
|
|
|
.mss_clamp = TCP_MSS_DEFAULT,
|
|
|
#ifdef CONFIG_TCP_MD5SIG
|
|
|
- .md5_lookup = tcp_v4_reqsk_md5_lookup,
|
|
|
+ .req_md5_lookup = tcp_v4_md5_lookup,
|
|
|
.calc_md5_hash = tcp_v4_md5_hash_skb,
|
|
|
#endif
|
|
|
.init_req = tcp_v4_init_req,
|