ioctl: add two receive mode checking for TUN/TAP driver
PATCH v2 1/2 ioctl: add two receive mode checking for TUN/TAP driver
IFF_NAPI(1) and IFF_NAPI_FRAGS(2) are two new flags for TUN/TAP driver, but currently ioctl03 does not hanlde them so it always failed on latest kernel-4.15.0-rc2 like:
ioctl03 0 TINFO : Available features are: 0x7133 ioctl03 0 TINFO : TUN 0x1 ioctl03 0 TINFO : TAP 0x2 ioctl03 0 TINFO : NO_PI 0x1000 ioctl03 0 TINFO : ONE_QUEUE 0x2000 ioctl03 0 TINFO : VNET_HDR 0x4000 ioctl03 0 TINFO : MULTI_QUEUE 0x100 ioctl03 1 TFAIL : ioctl03.c:114: (UNKNOWN 0x30)
See kernel commit:
(1) commit 943170998b2 (tun: enable NAPI for TUN/TAP driver)
(2) commit 90e33d45940 (tun: enable napi_gro_frags() for TUN/TAP driver)
--- testcases/kernel/syscalls/ioctl/ioctl03.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
testcases/kernel/syscalls/ioctl/ioctl03.c +11 -1
@@ -60,6 +60,14 @@#define IFF_MULTI_QUEUE 0x0100#endif +#ifndef IFF_NAPI +#define IFF_NAPI 0x0010 +#endif + +#ifndef IFF_NAPI_FRAGS +#define IFF_NAPI_FRAGS 0x0020 +#endif +char *TCID ="ioctl03" ;int TST_TOTAL =1 ;
@@ -84,7 +92,9 @@ static struct { IFF_NO_PI, "NO_PI"}, { IFF_ONE_QUEUE, "ONE_QUEUE"}, { IFF_VNET_HDR, "VNET_HDR"}, { - IFF_MULTI_QUEUE, "MULTI_QUEUE"} + IFF_MULTI_QUEUE, "MULTI_QUEUE"}, { + IFF_NAPI, "IFF_NAPI"}, { + IFF_NAPI_FRAGS, "IFF_NAPI_FRAGS"} };int main (void )
Signature · 1 line
2.9.3
PATCH v2 2/2 ioctl: convert ioctl03 to new API
--- testcases/kernel/syscalls/ioctl/ioctl03.c | 84 +++++++++++-------------------- 1 file changed, 29 insertions(+), 55 deletions(-)
testcases/kernel/syscalls/ioctl/ioctl03.c +29 -55
@@ -1,7 +1,6 @@/* -* -* Copyright (c) Rusty Russell <[email protected]> * Copyright (c) International Business Machines Corp., 2008 +* Copyright (c) Linux Test Project, 2017 * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by
@@ -12,30 +11,22 @@* but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See * the GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ /* -* -* * File: ioctl03.c * * Description: This program tests whether all the valid IFF flags are * returned properly by implementation of TUNGETFEATURES ioctl * on kernel 2.6.27 * -* Total Tests: 1 -* * Test Name: ioctl03 * * Author: Rusty Russell <[email protected]> * -* History: Created - Nov 28 2008 - Rusty Russell <[email protected]> -* Ported to LTP -* - Nov 28 2008 - Subrata <[email protected]> +* history: created - nov 28 2008 - rusty russell <[email protected]> +* ported to ltp +* - nov 28 2008 - subrata <[email protected]> */ #include <sys/types.h>
@@ -45,8 +36,7 @@#include <errno.h> #include <stdio.h> #include <linux/if_tun.h> - -#include "test.h" +#include "tst_test.h" #ifndef TUNGETFEATURES #define TUNGETFEATURES _IOR('T', 207, unsigned int)
@@ -61,67 +51,51 @@#endif #ifndef IFF_NAPI -#define IFF_NAPI 0x0010 +#define IFF_NAPI 0x0010#endif #ifndef IFF_NAPI_FRAGS -#define IFF_NAPI_FRAGS 0x0020 +#define IFF_NAPI_FRAGS 0x0020#endif -char *TCID ="ioctl03" ; -int TST_TOTAL =1 ; - -static void cleanup (void ) -{ -tst_rmdir (); -} - -static void setup (void ) -{ -TEST_PAUSE ; -tst_tmpdir (); -} -static struct {unsigned int flag;const char *name; } known_flags[] = { - { -IFF_TUN ,"TUN" }, { -IFF_TAP ,"TAP" }, { -IFF_NO_PI ,"NO_PI" }, { -IFF_ONE_QUEUE ,"ONE_QUEUE" }, { -IFF_VNET_HDR ,"VNET_HDR" }, { -IFF_MULTI_QUEUE ,"MULTI_QUEUE" }, { -IFF_NAPI ,"IFF_NAPI" }, { -IFF_NAPI_FRAGS ,"IFF_NAPI_FRAGS" } + {IFF_TUN ,"TUN" }, + {IFF_TAP ,"TAP" }, + {IFF_NO_PI ,"NO_PI" }, + {IFF_ONE_QUEUE ,"ONE_QUEUE" }, + {IFF_VNET_HDR ,"VNET_HDR" }, + {IFF_MULTI_QUEUE ,"MULTI_QUEUE" }, + {IFF_NAPI ,"IFF_NAPI" }, + {IFF_NAPI_FRAGS ,"IFF_NAPI_FRAGS" } }; -int main (void ) +static void verify_features (void ) {unsigned int features, i; -setup (); -tst_require_root (); +int netfd =SAFE_OPEN ("/dev/net/tun" ,O_RDWR ); -int netfd =open ("/dev/net/tun" ,O_RDWR ); -if (netfd <0 ) -tst_brkm (TBROK |TERRNO , cleanup, -"opening /dev/net/tun failed" ); +SAFE_IOCTL (netfd,TUNGETFEATURES , &features); -if (ioctl (netfd,TUNGETFEATURES , &features) !=0 ) -tst_brkm (TCONF , cleanup, -"Kernel does not support TUNGETFEATURES" ); -tst_resm (TINFO ,"Available features are: %#x" , features); +tst_res (TINFO ,"Available features are: %#x" , features);for (i =0 ; i <sizeof (known_flags) /sizeof (known_flags[0 ]); i++) {if (features & known_flags[i].flag) { features &= ~known_flags[i].flag; -tst_resm (TINFO ,"%s %#x" , known_flags[i].name, +tst_res (TPASS ,"%s %#x" , known_flags[i].name, known_flags[i].flag); } }if (features) -tst_resm (TFAIL ,"(UNKNOWN %#x)" , features); -cleanup (); -tst_exit (); +tst_res (TFAIL ,"(UNKNOWN %#x)" , features); + +SAFE_CLOSE (netfd); } + +static struct tst_test test = { + .test_all = verify_features, + .needs_tmpdir =1 , + .needs_root =1 , +};
Signature · 1 line
2.9.3
PATCH v2 2/2 ioctl: convert ioctl03 to new API
Hi!
Quoted 14 lines
testcases/kernel/syscalls/ioctl/ioctl03.c +1
-2@@ -1,7 +1,6 @@/* -* -* Copyright (c) Rusty Russell <[email protected]> * Copyright (c) International Business Machines Corp., 2008 +* Copyright (c) Linux Test Project, 2017 * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by
testcases/kernel/syscalls/ioctl/ioctl03.c line 18
Quoted 7 lines
testcases/kernel/syscalls/ioctl/ioctl03.c +0
-4@@ -12,30 +11,22 @@* but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See * the GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
If you are touching this, you should have replaced it with the version with URL link.
Quoted 27 lines
testcases/kernel/syscalls/ioctl/ioctl03.c +3
-7*/ /* -* -* * File: ioctl03.c * * Description: This program tests whether all the valid IFF flags are * returned properly by implementation of TUNGETFEATURES ioctl * on kernel 2.6.27 * -* Total Tests: 1 -* * Test Name: ioctl03 * * Author: Rusty Russell <[email protected]> * -* History: Created - Nov 28 2008 - Rusty Russell <[email protected]> -* Ported to LTP -* - Nov 28 2008 - Subrata <[email protected]> +* history: created - nov 28 2008 - rusty russell <[email protected]> +* ported to ltp +* - nov 28 2008 - subrata <[email protected]> */ #include <sys/types.h>
testcases/kernel/syscalls/ioctl/ioctl03.c line 37
Quoted 2 lines
testcases/kernel/syscalls/ioctl/ioctl03.c +0
-0@@ -45,8 +36,7 @@#include <errno.h> #include <stdio.h>
^
There is no need to include this header here.
Quoted 65 lines
testcases/kernel/syscalls/ioctl/ioctl03.c +13
-30#include <linux/if_tun.h> - -#include "test.h" +#include "tst_test.h" #ifndef TUNGETFEATURES #define TUNGETFEATURES _IOR('T', 207, unsigned int)@@ -61,67 +51,51 @@#endif #ifndef IFF_NAPI -#define IFF_NAPI 0x0010 +#define IFF_NAPI 0x0010#endif #ifndef IFF_NAPI_FRAGS -#define IFF_NAPI_FRAGS 0x0020 +#define IFF_NAPI_FRAGS 0x0020#endif -char *TCID ="ioctl03" ; -int TST_TOTAL =1 ; - -static void cleanup (void ) -{ -tst_rmdir (); -} - -static void setup (void ) -{ -TEST_PAUSE ; -tst_tmpdir (); -} -static struct {unsigned int flag;const char *name; } known_flags[] = { - { -IFF_TUN ,"TUN" }, { -IFF_TAP ,"TAP" }, { -IFF_NO_PI ,"NO_PI" }, { -IFF_ONE_QUEUE ,"ONE_QUEUE" }, { -IFF_VNET_HDR ,"VNET_HDR" }, { -IFF_MULTI_QUEUE ,"MULTI_QUEUE" }, { -IFF_NAPI ,"IFF_NAPI" }, { -IFF_NAPI_FRAGS ,"IFF_NAPI_FRAGS" } + {IFF_TUN ,"TUN" }, + {IFF_TAP ,"TAP" }, + {IFF_NO_PI ,"NO_PI" }, + {IFF_ONE_QUEUE ,"ONE_QUEUE" }, + {IFF_VNET_HDR ,"VNET_HDR" }, + {IFF_MULTI_QUEUE ,"MULTI_QUEUE" }, + {IFF_NAPI ,"IFF_NAPI" }, + {IFF_NAPI_FRAGS ,"IFF_NAPI_FRAGS" } }; -int main (void ) +static void verify_features (void ) {unsigned int features, i; -setup (); -tst_require_root (); +int netfd =SAFE_OPEN ("/dev/net/tun" ,O_RDWR );
testcases/kernel/syscalls/ioctl/ioctl03.c line 114
Quoted 10 lines
testcases/kernel/syscalls/ioctl/ioctl03.c +1
-8-int netfd =open ("/dev/net/tun" ,O_RDWR ); -if (netfd <0 ) -tst_brkm (TBROK |TERRNO , cleanup, -"opening /dev/net/tun failed" ); +SAFE_IOCTL (netfd,TUNGETFEATURES , &features); - -if (ioctl (netfd,TUNGETFEATURES , &features) !=0 ) -tst_brkm (TCONF , cleanup, -"Kernel does not support TUNGETFEATURES" );
After this change the test fails with TBROK instead of TCONF when the ioctl() fails.
I suppose that the tun driver can be compiled out of the kernel and that we should still handle this situation as TCONF rather than TBROK. The question is what kind of errno we get in that case, I suppose that it may be ENOTTY but that should be tested.
testcases/kernel/syscalls/ioctl/ioctl03.c line 84
Quoted 3 lines
testcases/kernel/syscalls/ioctl/ioctl03.c +1
-1-tst_resm (TINFO ,"Available features are: %#x" , features); +tst_res (TINFO ,"Available features are: %#x" , features);for (i =0 ; i <sizeof (known_flags) /sizeof (known_flags[0 ]); i++) {
^
We do have ARRAY_SIZE() macro in LTP.
Quoted 9 lines
testcases/kernel/syscalls/ioctl/ioctl03.c +1
-2if (features & known_flags[i].flag) { features &= ~known_flags[i].flag; -tst_resm (TINFO ,"%s %#x" , known_flags[i].name, +tst_res (TPASS ,"%s %#x" , known_flags[i].name, known_flags[i].flag); } }if (features) -tst_resm (TFAIL ,"(UNKNOWN %#x)" , features);
testcases/kernel/syscalls/ioctl/ioctl03.c line 99
Quoted 10 lines
testcases/kernel/syscalls/ioctl/ioctl03.c +7
-2-cleanup (); -tst_exit (); +tst_res (TFAIL ,"(UNKNOWN %#x)" , features); + +SAFE_CLOSE (netfd); } + +static struct tst_test test = { + .test_all = verify_features, + .needs_tmpdir =1 ,
^
Is this useful for something?
The test does not seem to be creating any files at all.
Quoted 8 lines
testcases/kernel/syscalls/ioctl/ioctl03.c +2
-0+ .needs_root = 1, +};Signature · 5 lines
2.9.3 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v2 2/2 ioctl: convert ioctl03 to new API
Quoted 6 lines · Cyril Hrubis
testcases/kernel/syscalls/ioctl/ioctl03.c line 114
Quoted 5 lines
testcases/kernel/syscalls/ioctl/ioctl03.c +1
-4+SAFE_IOCTL (netfd,TUNGETFEATURES , &features); - -if (ioctl (netfd,TUNGETFEATURES , &features) !=0 ) -tst_brkm (TCONF , cleanup, -"Kernel does not support TUNGETFEATURES" );
Quoted 7 lines
After this change the test fails with TBROK instead of TCONF when the
ioctl()fails.I suppose that the tun driver can be compiled out of the kernel and that we should still handle this situation as TCONF rather than TBROK. The question is what kind of errno we get in that case, I suppose that it may be ENOTTY but that should be tested.
Do you mean that ioctl(netfd, TUNGETFEATURES, &features) may be failed with erron==ENOTTY while testing on a kernel without TUN driver loaded?
I tried that with kernel-4.15-rc4 but get "No Such Device" error when open "/dev/net/tun" file. And the worth to say, /dev/net/tun is still exist after removing TUN module.
=========
# uname -r 4.15.0-rc4
# rmmod tun
# ll /dev/net/tun crw-rw-rw-. 1 root root 10, 200 Dec 20 04:59 /dev/net/tun
# ./ioctl03 tst_test.c:977: INFO: Timeout per run is 0h 05m 00s safe_macros.c:225: BROK: ioctl03.c:82: open(/dev/net/tun,2,063200020) failed: ENODEV
Thanks for reviewing patiently. I'm OK with the rest comments.
Signature · 2 lines
Li Wang [email protected]
PATCH v2 2/2 ioctl: convert ioctl03 to new API
Hi!
Quoted 11 lines
Quoted 7 lines
After this change the test fails with TBROK instead of TCONF when the
ioctl()fails.I suppose that the tun driver can be compiled out of the kernel and that we should still handle this situation as TCONF rather than TBROK. The question is what kind of errno we get in that case, I suppose that it may be ENOTTY but that should be tested.
Do you mean that
ioctl(netfd, TUNGETFEATURES, &features)may be failed with erron==ENOTTY while testing on a kernel without TUN driver loaded?
That was my expectation, but with ioctl() you cannot be really sure.
Quoted 3 lines
I tried that with kernel-4.15-rc4 but get "No Such Device" error when open "
/dev/net/tun" file. And the worth to say,/dev/net/tunis still exist after removing TUN module.
Ok, then we need to handle ENODEV as TCONF there and anything else as TBROK.
Signature · 2 lines
Cyril Hrubis [email protected]