selftests: add selftest for UDP SO_PEEK_OFF support
Subsystems (3)
PATCH 1/1 selftests: add selftest for UDP SO_PEEK_OFF support
From: Jason Xing <[email protected]>
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
---
---
tools/testing/selftests/net/Makefile | 2 +-
.../{tcp_so_peek_off.c => sk_so_peek_off.c} | 91 +++++++++++--------
2 files changed, 56 insertions(+), 37 deletions(-)
rename tools/testing/selftests/net/{tcp_so_peek_off.c => sk_so_peek_off.c} (58%)tools/testing/selftests/net/Makefile +1 -1
@@ -80,7 +80,7 @@ TEST_PROGS += io_uring_zerocopy_tx.sh TEST_GEN_FILES += bind_bhash TEST_GEN_PROGS += sk_bind_sendto_listen TEST_GEN_PROGS += sk_connect_zero_addr -TEST_GEN_PROGS += tcp_so_peek_off +TEST_GEN_PROGS += sk_so_peek_off TEST_PROGS += test_ingress_egress_chaining.sh TEST_GEN_PROGS += so_incoming_cpu TEST_PROGS += sctp_vrf.sh
tools/testing/selftests/net/sk_so_peek_off.c renamed from tools/testing/selftests/net/tcp_so_peek_off.c +55 -36
213 lines not on this page · raw message
Signature · 1 line
2.37.3
Quoted 23 lines · Jason Xing
From: Jason Xing <[email protected]>
Add the
SO_PEEK_OFFselftest for UDP. In this patch, I mainly do three things:
1. renametcp_so_peek_off.c
2. adjust for UDP protocol
3. add selftests into itSuggested-by Jon Maloy <[email protected]>Signed-off-by Jason Xing <[email protected]>---
--- tools/testing/selftests/net/Makefile | 2 +- .../{tcp_so_peek_off.c => sk_so_peek_off.c} | 91 +++++++++++-------- 2 files changed, 56 insertions(+), 37 deletions(-) rename tools/testing/selftests/net/{tcp_so_peek_off.c => sk_so_peek_off.c} (58%)tools/testing/selftests/net/Makefile +0
-0
tools/testing/selftests/net/Makefile TEST_PROGS += io_uring_zerocopy_tx.sh · line 83
Quoted 5 lines
tools/testing/selftests/net/Makefile +1
-1@@ -80,7 +80,7 @@ TEST_PROGS += io_uring_zerocopy_tx.sh TEST_GEN_FILES += bind_bhash TEST_GEN_PROGS += sk_bind_sendto_listen TEST_GEN_PROGS += sk_connect_zero_addr -TEST_GEN_PROGS += tcp_so_peek_off +TEST_GEN_PROGS += sk_so_peek_off
Should we also add sk_so_peek_off to gitignore?
Quoted 20 lines · Stanislav Fomichev
Quoted 18 lines · Jason Xing
From: Jason Xing <[email protected]>
Add the
SO_PEEK_OFFselftest for UDP. In this patch, I mainly do three things:
1. renametcp_so_peek_off.c
2. adjust for UDP protocol
3. add selftests into itSuggested-by Jon Maloy <[email protected]>Signed-off-by Jason Xing <[email protected]>---
--- tools/testing/selftests/net/Makefile | 2 +- .../{tcp_so_peek_off.c => sk_so_peek_off.c} | 91 +++++++++++-------- 2 files changed, 56 insertions(+), 37 deletions(-) rename tools/testing/selftests/net/{tcp_so_peek_off.c => sk_so_peek_off.c} (58%)
Quoted 12 lines
tools/testing/selftests/net/Makefile TEST_PROGS += io_uring_zerocopy_tx.sh · line 83
Quoted 10 lines
tools/testing/selftests/net/Makefile +1
-1@@ -80,7 +80,7 @@ TEST_PROGS += io_uring_zerocopy_tx.sh TEST_GEN_FILES += bind_bhash TEST_GEN_PROGS += sk_bind_sendto_listen TEST_GEN_PROGS += sk_connect_zero_addr -TEST_GEN_PROGS += tcp_so_peek_off +TEST_GEN_PROGS += sk_so_peek_offShould we also add
sk_so_peek_offto gitignore?
Good catch. Will update it in the next version :)
Thanks,
Jason
Quoted 10 lines · Jason Xing
From: Jason Xing <[email protected]>
Add the
SO_PEEK_OFFselftest for UDP. In this patch, I mainly do three things:
1. renametcp_so_peek_off.c
2. adjust for UDP protocol
3. add selftests into itSuggested-by Jon Maloy <[email protected]>Signed-off-by Jason Xing <[email protected]>
A few minor comments. Nothing important.
Subject to Stan's point about .gitignore:
tools/testing/selftests/net/sk_so_peek_off.c line 28
Quoted 10 lines
tools/testing/selftests/net/sk_so_peek_off.c renamed from tools/testing/selftests/net/tcp_so_peek_off.c +3
-2-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.
Quoted 40 lines
tools/testing/selftests/net/sk_so_peek_off.c renamed from tools/testing/selftests/net/tcp_so_peek_off.c +5
-4if (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;
tools/testing/selftests/net/sk_so_peek_off.c static int tcp_peek_offset_test(sa_family_t af) · line 76
Quoted 10 lines
tools/testing/selftests/net/sk_so_peek_off.c renamed from tools/testing/selftests/net/tcp_so_peek_off.c +3
-3-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
Quoted 7 lines
tools/testing/selftests/net/sk_so_peek_off.c renamed from tools/testing/selftests/net/tcp_so_peek_off.c +0
-0if (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; }
tools/testing/selftests/net/sk_so_peek_off.c static int tcp_peek_offset_test(sa_family_t af) · line 97
Quoted 10 lines
tools/testing/selftests/net/sk_so_peek_off.c renamed from tools/testing/selftests/net/tcp_so_peek_off.c +2
-2-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.
Quoted 10 lines
tools/testing/selftests/net/sk_so_peek_off.c renamed from tools/testing/selftests/net/tcp_so_peek_off.c +6
-4- 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; + }
Quoted 10 lines · Willem de Bruijn
Quoted 8 lines · Jason Xing
From: Jason Xing <[email protected]>
Add the
SO_PEEK_OFFselftest for UDP. In this patch, I mainly do three things:
1. renametcp_so_peek_off.c
2. adjust for UDP protocol
3. add selftests into it
Quoted 8 lines
Quoted 2 lines
Suggested-by Jon Maloy <[email protected]>Signed-off-by Jason Xing <[email protected]>A few minor comments. Nothing important.
Subject to Stan's point about .gitignore:
Reviewed-by Willem de Bruijn <[email protected]>
Thanks for your review!
Quoted 9 lines
Quoted 9 lines
tools/testing/selftests/net/sk_so_peek_off.c renamed from tools/testing/selftests/net/tcp_so_peek_off.c +2
-1-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;
Quoted 5 lines
tools/testing/selftests/net/sk_so_peek_off.c line 28
Quoted 2 lines
tools/testing/selftests/net/sk_so_peek_off.c renamed from tools/testing/selftests/net/tcp_so_peek_off.c +1
-1- s =socket (af,SOCK_STREAM |SOCK_CLOEXEC ,IPPROTO_TCP ); + s =socket (af, type, proto);Removing the
SOCK_CLOEXECbecause not relevant to this single thread process, I suppose?
Yep. We don't need this one.
Quoted 2 lines
Not important, but no need for proto, can just be 0.
You're right. I wonder if it is better if we explicitly pass the proto here? I would like not to touch it here.
Quoted 47 lines
Quoted 47 lines
if (s < 0) { ksft_perror("Temporary TCP socket creation failed"); } else { if (!setsockopt(s, SOL_SOCKET, SO_PEEK_OFF, &optv, sizeof(int))) ret = 1; elsetools/testing/selftests/net/sk_so_peek_off.c renamed from tools/testing/selftests/net/tcp_so_peek_off.c +6
-5-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;
Quoted 6 lines
tools/testing/selftests/net/sk_so_peek_off.c static int tcp_peek_offset_test(sa_family_t af) · line 76
Quoted 4 lines
tools/testing/selftests/net/sk_so_peek_off.c renamed from tools/testing/selftests/net/tcp_so_peek_off.c +2
-2- 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
I think we don't need this one, either.
As we can see, there are already some existing test files without the SOCK_NONBLOCK flag.
Quoted 13 lines
Quoted 13 lines
tools/testing/selftests/net/sk_so_peek_off.c renamed from tools/testing/selftests/net/tcp_so_peek_off.c +1
-1if (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; }
Quoted 8 lines
tools/testing/selftests/net/sk_so_peek_off.c static int tcp_peek_offset_test(sa_family_t af) · line 97
Quoted 5 lines
tools/testing/selftests/net/sk_so_peek_off.c renamed from tools/testing/selftests/net/tcp_so_peek_off.c +1
-1-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_NONBLOCKabove. Definitely simplifies the test.
Yep.
Quoted 3 lines
Just note that error test is == -1 or < 0, also for consistency with the rest of the file.
I will add "< 0" here as you said.
Thanks,
Jason
Quoted 38 lines · Jason Xing
Quoted 10 lines · Willem de Bruijn
Quoted 8 lines · Jason Xing
From: Jason Xing <[email protected]>
Add the
SO_PEEK_OFFselftest for UDP. In this patch, I mainly do three things:
1. renametcp_so_peek_off.c
2. adjust for UDP protocol
3. add selftests into itQuoted 8 lines
Quoted 2 lines
Suggested-by Jon Maloy <[email protected]>Signed-off-by Jason Xing <[email protected]>A few minor comments. Nothing important.
Subject to Stan's point about .gitignore:
Reviewed-by Willem de Bruijn <[email protected]>Thanks for your review!
Quoted 9 lines
Quoted 9 lines
tools/testing/selftests/net/sk_so_peek_off.c renamed from tools/testing/selftests/net/tcp_so_peek_off.c +2
-1-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;Quoted 5 lines
tools/testing/selftests/net/sk_so_peek_off.c line 28
Quoted 2 lines
tools/testing/selftests/net/sk_so_peek_off.c renamed from tools/testing/selftests/net/tcp_so_peek_off.c +1
-1- s =socket (af,SOCK_STREAM |SOCK_CLOEXEC ,IPPROTO_TCP ); + s =socket (af, type, proto);Removing the
SOCK_CLOEXECbecause not relevant to this single thread process, I suppose?
Quoted 7 lines
Yep. We don't need this one.
Quoted 2 lines
Not important, but no need for proto, can just be 0.
You're right. I wonder if it is better if we explicitly pass the proto here? I would like not to touch it here.
It's not better or worse. Just not needed. So either way.