Netdev List
 help / color / mirror / Atom feed
From: Willem de Bruijn <willemdebruijn.kernel@gmail.com>
To: Jason Xing <kerneljasonxing@gmail.com>,
	 davem@davemloft.net,  edumazet@google.com,  kuba@kernel.org,
	 pabeni@redhat.com,  shuah@kernel.org,  jmaloy@redhat.com
Cc: linux-kselftest@vger.kernel.org,  netdev@vger.kernel.org,
	 Jason Xing <kernelxing@tencent.com>
Subject: Re: [PATCH net-next] selftests: add selftest for UDP SO_PEEK_OFF support
Date: Mon, 02 Sep 2024 11:02:36 -0400	[thread overview]
Message-ID: <66d5d38c1d4b_61388294f0@willemb.c.googlers.com.notmuch> (raw)
In-Reply-To: <20240901051821.94956-1-kerneljasonxing@gmail.com>

Jason Xing wrote:
> From: Jason Xing <kernelxing@tencent.com>
> 
> Add the SO_PEEK_OFF selftest for UDP. In this patch, I mainly do
> three things:
> 1. rename tcp_so_peek_off.c
> 2. adjust for UDP protocol
> 3. add selftests into it
> 
> Suggested-by: Jon Maloy <jmaloy@redhat.com>
> Signed-off-by: Jason Xing <kernelxing@tencent.com>

A few minor comments. Nothing important.

Subject to Stan's point about .gitignore:

Reviewed-by: Willem de Bruijn <willemb@google.com>

> -int tcp_peek_offset_probe(sa_family_t af)
> +int sk_peek_offset_probe(sa_family_t af, int proto)
>  {
> +	int type = (proto == IPPROTO_TCP ? SOCK_STREAM : SOCK_DGRAM);
>  	int optv = 0;
>  	int ret = 0;
>  	int s;
>  
> -	s = socket(af, SOCK_STREAM | SOCK_CLOEXEC, IPPROTO_TCP);
> +	s = socket(af, type, proto);

Removing the SOCK_CLOEXEC because not relevant to this single thread
process, I suppose?

Not important, but no need for proto, can just be 0.

>  	if (s < 0) {
>  		ksft_perror("Temporary TCP socket creation failed");
>  	} else {
>  		if (!setsockopt(s, SOL_SOCKET, SO_PEEK_OFF, &optv, sizeof(int)))
>  			ret = 1;
>  		else
> -			printf("%s does not support SO_PEEK_OFF\n", afstr(af));
> +			printf("%s does not support SO_PEEK_OFF\n", afstr(af, proto));
>  		close(s);
>  	}
>  	return ret;
>  }
>  
> -static void tcp_peek_offset_set(int s, int offset)
> +static void sk_peek_offset_set(int s, int offset)
>  {
>  	if (setsockopt(s, SOL_SOCKET, SO_PEEK_OFF, &offset, sizeof(offset)))
>  		ksft_perror("Failed to set SO_PEEK_OFF value\n");
>  }
>  
> -static int tcp_peek_offset_get(int s)
> +static int sk_peek_offset_get(int s)
>  {
>  	int offset;
>  	socklen_t len = sizeof(offset);
> @@ -50,8 +54,9 @@ static int tcp_peek_offset_get(int s)
>  	return offset;
>  }
>  
> -static int tcp_peek_offset_test(sa_family_t af)
> +static int sk_peek_offset_test(sa_family_t af, int proto)
>  {
> +	int type = (proto == IPPROTO_TCP ? SOCK_STREAM : SOCK_DGRAM);
>  	union {
>  		struct sockaddr sa;
>  		struct sockaddr_in a4;
> @@ -62,13 +67,13 @@ static int tcp_peek_offset_test(sa_family_t af)
>  	int recv_sock = 0;
>  	int offset = 0;
>  	ssize_t len;
> -	char buf;
> +	char buf[2];
>  
>  	memset(&a, 0, sizeof(a));
>  	a.sa.sa_family = af;
>  
> -	s[0] = socket(af, SOCK_STREAM, IPPROTO_TCP);
> -	s[1] = socket(af, SOCK_STREAM | SOCK_NONBLOCK, IPPROTO_TCP);
> +	s[0] = recv_sock = socket(af, type, proto);
> +	s[1] = socket(af, type, proto);

Same

>  
>  	if (s[0] < 0 || s[1] < 0) {
>  		ksft_perror("Temporary socket creation failed\n");
> @@ -82,76 +87,78 @@ static int tcp_peek_offset_test(sa_family_t af)
>  		ksft_perror("Temporary socket getsockname() failed\n");
>  		goto out;
>  	}
> -	if (listen(s[0], 0) < 0) {
> +	if (proto == IPPROTO_TCP && listen(s[0], 0) < 0) {
>  		ksft_perror("Temporary socket listen() failed\n");
>  		goto out;
>  	}
> -	if (connect(s[1], &a.sa, sizeof(a)) >= 0 || errno != EINPROGRESS) {
> +	if (connect(s[1], &a.sa, sizeof(a))) {
>  		ksft_perror("Temporary socket connect() failed\n");
>  		goto out;
>  	}

Changed due to the removal of SOCK_NONBLOCK above. Definitely
simplifies the test.

Just note that error test is == -1 or < 0, also for consistency with
the rest of the file.

> -	recv_sock = accept(s[0], NULL, NULL);
> -	if (recv_sock <= 0) {
> -		ksft_perror("Temporary socket accept() failed\n");
> -		goto out;
> +	if (proto == IPPROTO_TCP) {
> +		recv_sock = accept(s[0], NULL, NULL);
> +		if (recv_sock <= 0) {
> +			ksft_perror("Temporary socket accept() failed\n");
> +			goto out;
> +		}



  parent reply	other threads:[~2024-09-02 15:02 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-01  5:18 [PATCH net-next] selftests: add selftest for UDP SO_PEEK_OFF support Jason Xing
2024-09-02  1:07 ` Stanislav Fomichev
2024-09-02  2:54   ` Jason Xing
2024-09-02 15:02 ` Willem de Bruijn [this message]
2024-09-02 15:33   ` Jason Xing
2024-09-02 16:45     ` Willem de Bruijn

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=66d5d38c1d4b_61388294f0@willemb.c.googlers.com.notmuch \
    --to=willemdebruijn.kernel@gmail.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=jmaloy@redhat.com \
    --cc=kerneljasonxing@gmail.com \
    --cc=kernelxing@tencent.com \
    --cc=kuba@kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=shuah@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox