Subject: Re: [Patch bpf-next v3 04/10] af_unix: set TCP_ESTABLISHED for datagram sockets too

From: Jakub Sitnicki <[email-masked]>
Date: Fri, 07 May 2021 10:18:54 +0200

On Mon, Apr 26, 2021 at 04:49 AM CEST, Cong Wang wrote:
> From: Cong Wang <[email-masked]>
>
> 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 by the next patch to determine whether an
> AF_UNIX datagram socket can be redirected in sockmap.
>
> Cc: John Fastabend <[email-masked]>
> Cc: Daniel Borkmann <[email-masked]>
> Cc: Jakub Sitnicki <[email-masked]>
> Cc: Lorenz Bauer <[email-masked]>
> Signed-off-by: Cong Wang <[email-masked]>
> ---
>  net/unix/af_unix.c | 12 ++++++------
>  1 file changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
> index 8968ed44a89f..c4afc5fbe137 100644
> --- a/net/unix/af_unix.c
> +++ b/net/unix/af_unix.c
> @@ -1206,6 +1206,8 @@ static int unix_dgram_connect(struct socket *sock, struct sockaddr *addr,
>  		unix_peer(sk) = other;
>  		unix_state_double_unlock(sk, other);
>  	}
> +
> +	sk->sk_state = other->sk_state = TCP_ESTABLISHED;

`other` can be NULL. In such case we're back to UNCONNECTED state.

>  	return 0;
>  out_unlock:

[...]