diff options
author | Cong Wang <cong.wang@bytedance.com> | 2021-07-04 12:02:45 -0700 |
---|---|---|
committer | Alexei Starovoitov <ast@kernel.org> | 2021-07-15 18:17:50 -0700 |
commit | 83301b5367a98c17ec0d76c7bc0ccdc3c7e7ad6d (patch) | |
tree | 41df0f676467ff7bf58da5bef2384923144ceed7 /net | |
parent | 29df44fa52b70c330d8f2a3871e028a3522b8494 (diff) | |
download | linux-stable-83301b5367a98c17ec0d76c7bc0ccdc3c7e7ad6d.tar.gz linux-stable-83301b5367a98c17ec0d76c7bc0ccdc3c7e7ad6d.tar.bz2 linux-stable-83301b5367a98c17ec0d76c7bc0ccdc3c7e7ad6d.zip |
af_unix: Set TCP_ESTABLISHED for datagram sockets too
Currently only unix stream socket sets TCP_ESTABLISHED,
datagram socket can set this too when they connect to its
peer socket. At least __ip4_datagram_connect() does the same.
This will be used to determine whether an AF_UNIX datagram
socket can be redirected to in sockmap.
Signed-off-by: Cong Wang <cong.wang@bytedance.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20210704190252.11866-5-xiyou.wangcong@gmail.com
Diffstat (limited to 'net')
-rw-r--r-- | net/unix/af_unix.c | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c index 38863468768a..77fb3910e1c3 100644 --- a/net/unix/af_unix.c +++ b/net/unix/af_unix.c @@ -494,6 +494,7 @@ static void unix_dgram_disconnected(struct sock *sk, struct sock *other) sk_error_report(other); } } + sk->sk_state = other->sk_state = TCP_CLOSE; } static void unix_sock_destructor(struct sock *sk) @@ -1202,6 +1203,9 @@ restart: unix_peer(sk) = other; unix_state_double_unlock(sk, other); } + + if (unix_peer(sk)) + sk->sk_state = other->sk_state = TCP_ESTABLISHED; return 0; out_unlock: @@ -1434,12 +1438,10 @@ static int unix_socketpair(struct socket *socka, struct socket *sockb) init_peercred(ska); init_peercred(skb); - if (ska->sk_type != SOCK_DGRAM) { - ska->sk_state = TCP_ESTABLISHED; - skb->sk_state = TCP_ESTABLISHED; - socka->state = SS_CONNECTED; - sockb->state = SS_CONNECTED; - } + ska->sk_state = TCP_ESTABLISHED; + skb->sk_state = TCP_ESTABLISHED; + socka->state = SS_CONNECTED; + sockb->state = SS_CONNECTED; return 0; } |