Commit 83a76006 authored by David S. Miller's avatar David S. Miller

Merge branch 'bindtodevice_tw_rst'

Florian Westphal says:

====================
tcp: honour SO_BINDTODEVICE for TW_RST case too

This is V2, this time as a small series since I followed Erics advice
to split this into smaller chunks, I hope this makes it easier to
review.

First patch adds inet_sk_transparent helper.
Second patch contains an if/else swap that I split from the
original TW_RST v1 one.
Third patch is the actual change without the superfluous sock_net change.
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents f4cee3af 271c3b9b
...@@ -68,7 +68,7 @@ struct request_sock { ...@@ -68,7 +68,7 @@ struct request_sock {
u32 peer_secid; u32 peer_secid;
}; };
static inline struct request_sock *inet_reqsk(struct sock *sk) static inline struct request_sock *inet_reqsk(const struct sock *sk)
{ {
return (struct request_sock *)sk; return (struct request_sock *)sk;
} }
......
...@@ -1620,6 +1620,18 @@ static inline void tcp_highest_sack_combine(struct sock *sk, ...@@ -1620,6 +1620,18 @@ static inline void tcp_highest_sack_combine(struct sock *sk,
tcp_sk(sk)->highest_sack = new; tcp_sk(sk)->highest_sack = new;
} }
/* This helper checks if socket has IP_TRANSPARENT set */
static inline bool inet_sk_transparent(const struct sock *sk)
{
switch (sk->sk_state) {
case TCP_TIME_WAIT:
return inet_twsk(sk)->tw_transparent;
case TCP_NEW_SYN_RECV:
return inet_rsk(inet_reqsk(sk))->no_srccheck;
}
return inet_sk(sk)->transparent;
}
/* Determines whether this is a thin stream (which may suffer from /* Determines whether this is a thin stream (which may suffer from
* increased latency). Used to trigger latency-reducing mechanisms. * increased latency). Used to trigger latency-reducing mechanisms.
*/ */
......
...@@ -587,7 +587,7 @@ static void tcp_v4_send_reset(const struct sock *sk, struct sk_buff *skb) ...@@ -587,7 +587,7 @@ static void tcp_v4_send_reset(const struct sock *sk, struct sk_buff *skb)
} rep; } rep;
struct ip_reply_arg arg; struct ip_reply_arg arg;
#ifdef CONFIG_TCP_MD5SIG #ifdef CONFIG_TCP_MD5SIG
struct tcp_md5sig_key *key; struct tcp_md5sig_key *key = NULL;
const __u8 *hash_location = NULL; const __u8 *hash_location = NULL;
unsigned char newhash[16]; unsigned char newhash[16];
int genhash; int genhash;
...@@ -627,7 +627,10 @@ static void tcp_v4_send_reset(const struct sock *sk, struct sk_buff *skb) ...@@ -627,7 +627,10 @@ static void tcp_v4_send_reset(const struct sock *sk, struct sk_buff *skb)
net = sk ? sock_net(sk) : dev_net(skb_dst(skb)->dev); net = sk ? sock_net(sk) : dev_net(skb_dst(skb)->dev);
#ifdef CONFIG_TCP_MD5SIG #ifdef CONFIG_TCP_MD5SIG
hash_location = tcp_parse_md5sig_option(th); hash_location = tcp_parse_md5sig_option(th);
if (!sk && hash_location) { if (sk && sk_fullsock(sk)) {
key = tcp_md5_do_lookup(sk, (union tcp_md5_addr *)
&ip_hdr(skb)->saddr, AF_INET);
} else if (hash_location) {
/* /*
* active side is lost. Try to find listening socket through * active side is lost. Try to find listening socket through
* source port, and then find md5 key through listening socket. * source port, and then find md5 key through listening socket.
...@@ -651,10 +654,6 @@ static void tcp_v4_send_reset(const struct sock *sk, struct sk_buff *skb) ...@@ -651,10 +654,6 @@ static void tcp_v4_send_reset(const struct sock *sk, struct sk_buff *skb)
genhash = tcp_v4_md5_hash_skb(newhash, key, 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 {
key = sk ? tcp_md5_do_lookup(sk, (union tcp_md5_addr *)
&ip_hdr(skb)->saddr,
AF_INET) : NULL;
} }
if (key) { if (key) {
...@@ -675,7 +674,8 @@ static void tcp_v4_send_reset(const struct sock *sk, struct sk_buff *skb) ...@@ -675,7 +674,8 @@ static void tcp_v4_send_reset(const struct sock *sk, struct sk_buff *skb)
ip_hdr(skb)->saddr, /* XXX */ ip_hdr(skb)->saddr, /* XXX */
arg.iov[0].iov_len, IPPROTO_TCP, 0); arg.iov[0].iov_len, IPPROTO_TCP, 0);
arg.csumoffset = offsetof(struct tcphdr, check) / 2; arg.csumoffset = offsetof(struct tcphdr, check) / 2;
arg.flags = (sk && inet_sk(sk)->transparent) ? IP_REPLY_ARG_NOSRCCHECK : 0; arg.flags = (sk && inet_sk_transparent(sk)) ? IP_REPLY_ARG_NOSRCCHECK : 0;
/* When socket is gone, all binding information is lost. /* When socket is gone, all binding information is lost.
* routing might fail in this case. No choice here, if we choose to force * routing might fail in this case. No choice here, if we choose to force
* input interface, we will misroute in case of asymmetric route. * input interface, we will misroute in case of asymmetric route.
...@@ -683,6 +683,9 @@ static void tcp_v4_send_reset(const struct sock *sk, struct sk_buff *skb) ...@@ -683,6 +683,9 @@ static void tcp_v4_send_reset(const struct sock *sk, struct sk_buff *skb)
if (sk) if (sk)
arg.bound_dev_if = sk->sk_bound_dev_if; arg.bound_dev_if = sk->sk_bound_dev_if;
BUILD_BUG_ON(offsetof(struct sock, sk_bound_dev_if) !=
offsetof(struct inet_timewait_sock, tw_bound_dev_if));
arg.tos = ip_hdr(skb)->tos; arg.tos = ip_hdr(skb)->tos;
ip_send_unicast_reply(*this_cpu_ptr(net->ipv4.tcp_sk), ip_send_unicast_reply(*this_cpu_ptr(net->ipv4.tcp_sk),
skb, &TCP_SKB_CB(skb)->header.h4.opt, skb, &TCP_SKB_CB(skb)->header.h4.opt,
...@@ -1706,7 +1709,9 @@ int tcp_v4_rcv(struct sk_buff *skb) ...@@ -1706,7 +1709,9 @@ int tcp_v4_rcv(struct sk_buff *skb)
tcp_v4_timewait_ack(sk, skb); tcp_v4_timewait_ack(sk, skb);
break; break;
case TCP_TW_RST: case TCP_TW_RST:
goto no_tcp_socket; tcp_v4_send_reset(sk, skb);
inet_twsk_deschedule_put(inet_twsk(sk));
goto discard_it;
case TCP_TW_SUCCESS:; case TCP_TW_SUCCESS:;
} }
goto discard_it; goto discard_it;
......
...@@ -131,7 +131,7 @@ tcp_timewait_state_process(struct inet_timewait_sock *tw, struct sk_buff *skb, ...@@ -131,7 +131,7 @@ tcp_timewait_state_process(struct inet_timewait_sock *tw, struct sk_buff *skb,
goto kill; goto kill;
if (th->syn && !before(TCP_SKB_CB(skb)->seq, tcptw->tw_rcv_nxt)) if (th->syn && !before(TCP_SKB_CB(skb)->seq, tcptw->tw_rcv_nxt))
goto kill_with_rst; return TCP_TW_RST;
/* Dup ACK? */ /* Dup ACK? */
if (!th->ack || if (!th->ack ||
...@@ -145,11 +145,8 @@ tcp_timewait_state_process(struct inet_timewait_sock *tw, struct sk_buff *skb, ...@@ -145,11 +145,8 @@ tcp_timewait_state_process(struct inet_timewait_sock *tw, struct sk_buff *skb,
* reset. * reset.
*/ */
if (!th->fin || if (!th->fin ||
TCP_SKB_CB(skb)->end_seq != tcptw->tw_rcv_nxt + 1) { TCP_SKB_CB(skb)->end_seq != tcptw->tw_rcv_nxt + 1)
kill_with_rst:
inet_twsk_deschedule_put(tw);
return TCP_TW_RST; return TCP_TW_RST;
}
/* FIN arrived, enter true time-wait state. */ /* FIN arrived, enter true time-wait state. */
tw->tw_substate = TCP_TIME_WAIT; tw->tw_substate = TCP_TIME_WAIT;
......
...@@ -854,7 +854,9 @@ static void tcp_v6_send_reset(const struct sock *sk, struct sk_buff *skb) ...@@ -854,7 +854,9 @@ static void tcp_v6_send_reset(const struct sock *sk, struct sk_buff *skb)
#ifdef CONFIG_TCP_MD5SIG #ifdef CONFIG_TCP_MD5SIG
hash_location = tcp_parse_md5sig_option(th); hash_location = tcp_parse_md5sig_option(th);
if (!sk && hash_location) { if (sk && sk_fullsock(sk)) {
key = tcp_v6_md5_do_lookup(sk, &ipv6h->saddr);
} else if (hash_location) {
/* /*
* active side is lost. Try to find listening socket through * active side is lost. Try to find listening socket through
* source port, and then find md5 key through listening socket. * source port, and then find md5 key through listening socket.
...@@ -877,8 +879,6 @@ static void tcp_v6_send_reset(const struct sock *sk, struct sk_buff *skb) ...@@ -877,8 +879,6 @@ static void tcp_v6_send_reset(const struct sock *sk, struct sk_buff *skb)
genhash = tcp_v6_md5_hash_skb(newhash, key, 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 {
key = sk ? tcp_v6_md5_do_lookup(sk, &ipv6h->saddr) : NULL;
} }
#endif #endif
...@@ -1516,7 +1516,9 @@ static int tcp_v6_rcv(struct sk_buff *skb) ...@@ -1516,7 +1516,9 @@ static int tcp_v6_rcv(struct sk_buff *skb)
break; break;
case TCP_TW_RST: case TCP_TW_RST:
tcp_v6_restore_cb(skb); tcp_v6_restore_cb(skb);
goto no_tcp_socket; tcp_v6_send_reset(sk, skb);
inet_twsk_deschedule_put(inet_twsk(sk));
goto discard_it;
case TCP_TW_SUCCESS: case TCP_TW_SUCCESS:
; ;
} }
......
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