Skip to content

Commit 83301b5

Browse files
Cong WangAlexei Starovoitov
authored andcommitted
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
1 parent 29df44f commit 83301b5

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

net/unix/af_unix.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,7 @@ static void unix_dgram_disconnected(struct sock *sk, struct sock *other)
494494
sk_error_report(other);
495495
}
496496
}
497+
sk->sk_state = other->sk_state = TCP_CLOSE;
497498
}
498499

499500
static void unix_sock_destructor(struct sock *sk)
@@ -1202,6 +1203,9 @@ static int unix_dgram_connect(struct socket *sock, struct sockaddr *addr,
12021203
unix_peer(sk) = other;
12031204
unix_state_double_unlock(sk, other);
12041205
}
1206+
1207+
if (unix_peer(sk))
1208+
sk->sk_state = other->sk_state = TCP_ESTABLISHED;
12051209
return 0;
12061210

12071211
out_unlock:
@@ -1434,12 +1438,10 @@ static int unix_socketpair(struct socket *socka, struct socket *sockb)
14341438
init_peercred(ska);
14351439
init_peercred(skb);
14361440

1437-
if (ska->sk_type != SOCK_DGRAM) {
1438-
ska->sk_state = TCP_ESTABLISHED;
1439-
skb->sk_state = TCP_ESTABLISHED;
1440-
socka->state = SS_CONNECTED;
1441-
sockb->state = SS_CONNECTED;
1442-
}
1441+
ska->sk_state = TCP_ESTABLISHED;
1442+
skb->sk_state = TCP_ESTABLISHED;
1443+
socka->state = SS_CONNECTED;
1444+
sockb->state = SS_CONNECTED;
14431445
return 0;
14441446
}
14451447

0 commit comments

Comments
 (0)