Skip to content

Commit aed6ece

Browse files
q2venkuba-moo
authored andcommitted
af_unix: Save listener for embryo socket.
This is a prep patch for the following change, where we need to fetch the listening socket from the successor embryo socket during GC. We add a new field to struct unix_sock to save a pointer to a listening socket. We set it when connect() creates a new socket, and clear it when accept() is called. Signed-off-by: Kuniyuki Iwashima <[email protected]> Acked-by: Paolo Abeni <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 3484f06 commit aed6ece

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

include/net/af_unix.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ struct unix_sock {
8383
struct path path;
8484
struct mutex iolock, bindlock;
8585
struct sock *peer;
86+
struct sock *listener;
8687
struct unix_vertex *vertex;
8788
struct list_head link;
8889
unsigned long inflight;

net/unix/af_unix.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -979,6 +979,7 @@ static struct sock *unix_create1(struct net *net, struct socket *sock, int kern,
979979
sk->sk_max_ack_backlog = net->unx.sysctl_max_dgram_qlen;
980980
sk->sk_destruct = unix_sock_destructor;
981981
u = unix_sk(sk);
982+
u->listener = NULL;
982983
u->inflight = 0;
983984
u->vertex = NULL;
984985
u->path.dentry = NULL;
@@ -1598,6 +1599,7 @@ static int unix_stream_connect(struct socket *sock, struct sockaddr *uaddr,
15981599
newsk->sk_type = sk->sk_type;
15991600
init_peercred(newsk);
16001601
newu = unix_sk(newsk);
1602+
newu->listener = other;
16011603
RCU_INIT_POINTER(newsk->sk_wq, &newu->peer_wq);
16021604
otheru = unix_sk(other);
16031605

@@ -1693,8 +1695,8 @@ static int unix_accept(struct socket *sock, struct socket *newsock, int flags,
16931695
bool kern)
16941696
{
16951697
struct sock *sk = sock->sk;
1696-
struct sock *tsk;
16971698
struct sk_buff *skb;
1699+
struct sock *tsk;
16981700
int err;
16991701

17001702
err = -EOPNOTSUPP;
@@ -1719,6 +1721,7 @@ static int unix_accept(struct socket *sock, struct socket *newsock, int flags,
17191721
}
17201722

17211723
tsk = skb->sk;
1724+
unix_sk(tsk)->listener = NULL;
17221725
skb_free_datagram(sk, skb);
17231726
wake_up_interruptible(&unix_sk(sk)->peer_wait);
17241727

0 commit comments

Comments
 (0)