tests/inet_socket: add tests for TCP Fast Open
Stephen Smalley
maintainerPATCH 1/1 tests/inet_socket: add tests for TCP Fast Open
Add tests for TCP Fast Open. These are expected to fail until the corresponding kernel patch is merged.
Signed-off-by Stephen Smalley <[email protected]>
--- tests/inet_socket/connect.c | 55 ++++++++++++++++++++++++++++--------- tests/inet_socket/test | 13 ++++++++- 2 files changed, 54 insertions(+), 14 deletions(-)
tests/inet_socket/connect.c +42 -13
@@ -17,7 +17,7 @@void usage (char *progname) { -fprintf (stderr,"usage: %s protocol port\n" , progname); +fprintf (stderr,"usage: %s [-f] protocol port\n" , progname);exit (1 ); }
@@ -30,26 +30,42 @@ main(int argc, char **argv)int result;struct sockaddr_in sin;socklen_t sinlen; -int type, protocol; +int type, protocol, opt;unsigned short port; +bool tcpfastopen = false; -if (argc !=3 ) +while ((opt =getopt (argc, argv,"f" )) !=-1 ) { +switch (opt) { +case 'f' : + tcpfastopen = true; +break ; +default : +usage (argv[0 ]); + } + } + +if ((argc - optind +1 ) !=3 )usage (argv[0 ]); -if (!strcmp (argv[1 ],"tcp" )) { +if (!strcmp (argv[optind],"tcp" )) { type =SOCK_STREAM ; protocol =IPPROTO_TCP ; - }else if (!strcmp (argv[1 ],"mptcp" )) { + }else if (!strcmp (argv[optind],"mptcp" )) { type =SOCK_STREAM ; protocol =IPPROTO_MPTCP ; - }else if (!strcmp (argv[1 ],"udp" )) { + }else if (!strcmp (argv[optind],"udp" )) { type =SOCK_DGRAM ; protocol =IPPROTO_UDP ; }else {usage (argv[0 ]); } - port =atoi (argv[2 ]); +if (protocol ==IPPROTO_UDP && tcpfastopen) { +fprintf (stderr,"TCP Fast Open only works with TCP or MPTCP\n" ); +exit (1 ); + } + + port =atoi (argv[optind +1 ]);if (!port)usage (argv[0 ]);
@@ -95,13 +111,26 @@ main(int argc, char **argv)exit (1 ); } - result =connect (csock, (struct sockaddr *) &sin, sinlen); -if (result <0 ) { -perror ("connect" ); -close (ssock); -close (csock); -exit (1 ); +if (tcpfastopen) { +char byte =0 ; + result =sendto (csock, &byte,1 ,MSG_FASTOPEN , + (struct sockaddr *) &sin, sinlen); +if (result <0 ) { +perror ("sendto" ); +close (ssock); +close (csock); +exit (1 ); + } + }else { + result =connect (csock, (struct sockaddr *) &sin, sinlen); +if (result <0 ) { +perror ("connect" ); +close (ssock); +close (csock); +exit (1 ); + } } +close (ssock);close (csock);exit (0 );
tests/inet_socket/test +12 -1
@@ -12,7 +12,7 @@ BEGIN { $is_stream = 1; $fail_value1 = 5; $fail_value2 = 5; - $test_count = 19; + $test_count = 21; } elsif ( $proto eq "udp" ) { $is_stream = 0;
@@ -308,6 +308,17 @@ if ($is_stream) { system "runcon -t test_inet_no_name_connect_t -- $basedir/connect $proto 65535 2>&1"; ok($result); + + # Verify that authorized domain can connect to TCP socket via TCP Fast Open. + $result = system + "runcon -t test_inet_connect_t -- $basedir/connect -f $proto 65535 2>&1"; + ok( $result eq 0 ); + +# Verify that domain without name_connect cannot connect to TCP socket via TCP Fast Open. + $result = + system +"runcon -t test_inet_no_name_connect_t -- $basedir/connect -f $proto 65535 2>&1"; + ok($result); } if ($test_ipsec) {
Signature · 1 line
2.54.0
Quoted 10 lines · Stephen Smalley
Add tests for TCP Fast Open. These are expected to fail until the corresponding kernel patch is merged.
Signed-off-by Stephen Smalley <[email protected]>--- tests/inet_socket/connect.c | 55 ++++++++++++++++++++++++++++--------- tests/inet_socket/test | 13 ++++++++- 2 files changed, 54 insertions(+), 14 deletions(-)
Thanks, this is now applied:
https://github.com/SELinuxProject/selinux-testsuite/commit/433c597a6a9a711aeb8a21d13abe6a09a68707a8
Signature · 3 lines
Ondrej Mosnacek Senior Software Engineer, Linux Security - SELinux kernel Red Hat, Inc.