Skip to contentSkip to conversation

testcases: netns: Check TUN support enabled

PATCH New Mylène Josserand 5 participants 12 messages Aug 2, 2018 – Oct 8, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 testcases: netns: Check TUN support enabled

In case TUN support is not enabled, the test will fail while performing the "ip" command with following error:
open: No such file or directory
netns_netlink 1 TBROK : netns_netlink.c:143: system() failed

As the system() call is not setting errno, we are not able to know if the error is produced by a mis-configuration or not.

Because of that, this commit adds a check during the setup function to see if the device "/dev/net/tun" is available or not. It is the file that "ip tuntap add mode tap" command is looking for (and fails with the "open" error).

---
 testcases/kernel/containers/netns/netns_netlink.c | 9 +++++++++
 1 file changed, 9 insertions(+)
testcases/kernel/containers/netns/netns_netlink.c +9 -0
index 47e8235d6..077ec5dab 100644
@@ -57,6 +57,15 @@ static void cleanup(void)
 
 static void setup(void)
 {
+	/* Check that the TUN support is available */
+	int netfd = open("/dev/net/tun", O_RDWR);
+	if (netfd == -1) {
+		if (errno == ENODEV || errno == ENOENT)
+			tst_brkm(TCONF, NULL, "TUN support is missing?");
+
+		tst_brkm(TBROK | TERRNO, NULL, "opening /dev/net/tun failed");
+	}
+
 	tst_require_root();
 	check_iproute(IP_TUNTAP_MIN_VER);
 	check_netns();
Signature · 1 line
2.11.0
#1 lore raw

PATCH 2/2 testcases: netns: Handle "Operation not supported" error

If there is no support for "dummy" or "veth", the tests will fail with errors:
RTNETLINK answers: Operation not supported
netns_sysfs 1 TBROK: failed to add a new (host) dummy device
and
RTNETLINK answers: Operation not supported netns_comm_ip_ipv6_ioctl 1 TBROK: unable to create veth pair devices Cannot find device "veth0"

This commit is storing the output of the commands and verifies if there is any reference to "Operation not supported". This code is based on what it is already done in "ipsec_lib.sh" stress test.

---
 testcases/kernel/containers/netns/netns_helper.sh | 16 ++++++++++++++--
 testcases/kernel/containers/netns/netns_sysfs.sh  |  6 +++++-
 2 files changed, 19 insertions(+), 3 deletions(-)
testcases/kernel/containers/netns/netns_helper.sh +14 -2
index 6aea10b47..58be60148 100755
@@ -199,8 +199,14 @@ netns_ns_exec_setup()
 		tst_brkm TBROK "unable to create a new network namespace"
 	fi
 
-	$NS_EXEC $NS_HANDLE0 $NS_TYPE ip link add veth0 type veth peer name veth1 || \
+	local output=$($NS_EXEC $NS_HANDLE0 $NS_TYPE ip link add veth0 type \
+				veth peer name veth1 2>&1 || echo 'TERR')
+	if echo "$output" | grep -q "TERR"; then
+		echo "$output" | grep -q \
+			'RTNETLINK answers: Operation not supported' && \
+			tst_brkm TCONF "Command not supported (maybe missing 'veth' support)"
 		tst_brkm TBROK "unable to create veth pair devices"
+	fi
 
 	$NS_EXEC $NS_HANDLE0 $NS_TYPE ns_ifmove veth1 $NS_HANDLE1
 	ret=$?
@@ -235,8 +241,14 @@ netns_ip_setup()
 	ip netns add $NS_HANDLE1 || \
 		tst_brkm TBROK "unable to create a new network namespace"
 
-	$NS_EXEC $NS_HANDLE0 ip link add veth0 type veth peer name veth1 || \
+	local output=$($NS_EXEC $NS_HANDLE0 ip link add veth0 type \
+				veth peer name veth1 2>&1 || echo 'TERR')
+	if echo "$output" | grep -q "TERR"; then
+		echo "$output" | grep -q \
+			'RTNETLINK answers: Operation not supported' && \
+			tst_brkm TCONF "Command not supported (maybe missing 'veth' support)"
 		tst_brkm TBROK "unable to create veth pair devices"
+	fi
 
 	$NS_EXEC $NS_HANDLE0 ip link set veth1 netns $NS_HANDLE1 || \
 		tst_brkm TBROK "unable to add device veth1 to the separate network namespace"
testcases/kernel/containers/netns/netns_sysfs.sh +5 -1
index 944a4c152..138d11402 100644
@@ -54,8 +54,12 @@ if [ $? -eq 1 ]; then
 fi
 TST_CLEANUP=cleanup
 
-ip link add $DUMMYDEV_HOST type dummy || \
+output=$(ip link add $DUMMYDEV_HOST type dummy 2>&1 || echo 'TERR')
+if echo "$output" | grep -q "TERR"; then
+	echo "$output" | grep -q 'RTNETLINK answers: Operation not supported' && \
+		tst_brkm TCONF "Command not supported (maybe missing 'dummy' support)"
 	tst_brkm TBROK "failed to add a new (host) dummy device"
+fi
 
 ns_exec $NS_HANDLE $NS_TYPE mount --make-rprivate /sys
 ns_exec $NS_HANDLE $NS_TYPE ip link add $DUMMYDEV type dummy || \
Signature · 1 line
2.11.0
#2 lore raw

PATCH 2/2 testcases: netns: Handle "Operation not supported" error

Quoted 9 lines · Mylène Josserand

If there is no support for "dummy" or "veth", the tests will fail with errors:
RTNETLINK answers: Operation not supported
netns_sysfs 1 TBROK: failed to add a new (host) dummy device
and
RTNETLINK answers: Operation not supported netns_comm_ip_ipv6_ioctl 1 TBROK: unable to create veth pair devices Cannot find device "veth0"

Quoted 4 lines

This commit is storing the output of the commands and verifies if there is any reference to "Operation not supported". This code is based on what it is already done in "ipsec_lib.sh" stress test.

Not sure if the same should be here. The test-cases with IPsec involve various crypto drivers that are much easier and better to check with ip/netlink, and we also check both: the support in iproute and kernel. I guess, veth and dummy virtual drivers could be checked with:

modprobe -q veth || tst_brkm TCONF ...

Perhaps, we could add tst_drivers_available() helper to the library.

Thanks,
Alexey

Quoted 62 lines
---
 testcases/kernel/containers/netns/netns_helper.sh | 16 ++++++++++++++--
 testcases/kernel/containers/netns/netns_sysfs.sh  |  6 +++++-
 2 files changed, 19 insertions(+), 3 deletions(-)
testcases/kernel/containers/netns/netns_helper.sh +14 -2
index 6aea10b47..58be60148 100755
@@ -199,8 +199,14 @@ netns_ns_exec_setup()
 		tst_brkm TBROK "unable to create a new network namespace"
 	fi
 
-	$NS_EXEC $NS_HANDLE0 $NS_TYPE ip link add veth0 type veth peer name veth1 || \
+	local output=$($NS_EXEC $NS_HANDLE0 $NS_TYPE ip link add veth0 type \
+				veth peer name veth1 2>&1 || echo 'TERR')
+	if echo "$output" | grep -q "TERR"; then
+		echo "$output" | grep -q \
+			'RTNETLINK answers: Operation not supported' && \
+			tst_brkm TCONF "Command not supported (maybe missing 'veth' support)"
 		tst_brkm TBROK "unable to create veth pair devices"
+	fi
 
 	$NS_EXEC $NS_HANDLE0 $NS_TYPE ns_ifmove veth1 $NS_HANDLE1
 	ret=$?
@@ -235,8 +241,14 @@ netns_ip_setup()
 	ip netns add $NS_HANDLE1 || \
 		tst_brkm TBROK "unable to create a new network namespace"
 
-	$NS_EXEC $NS_HANDLE0 ip link add veth0 type veth peer name veth1 || \
+	local output=$($NS_EXEC $NS_HANDLE0 ip link add veth0 type \
+				veth peer name veth1 2>&1 || echo 'TERR')
+	if echo "$output" | grep -q "TERR"; then
+		echo "$output" | grep -q \
+			'RTNETLINK answers: Operation not supported' && \
+			tst_brkm TCONF "Command not supported (maybe missing 'veth' support)"
 		tst_brkm TBROK "unable to create veth pair devices"
+	fi
 
 	$NS_EXEC $NS_HANDLE0 ip link set veth1 netns $NS_HANDLE1 || \
 		tst_brkm TBROK "unable to add device veth1 to the separate network namespace"
testcases/kernel/containers/netns/netns_sysfs.sh +5 -1
index 944a4c152..138d11402 100644
@@ -54,8 +54,12 @@ if [ $? -eq 1 ]; then
 fi
 TST_CLEANUP=cleanup
 
-ip link add $DUMMYDEV_HOST type dummy || \
+output=$(ip link add $DUMMYDEV_HOST type dummy 2>&1 || echo 'TERR')
+if echo "$output" | grep -q "TERR"; then
+	echo "$output" | grep -q 'RTNETLINK answers: Operation not supported' && \
+		tst_brkm TCONF "Command not supported (maybe missing 'dummy' support)"
 	tst_brkm TBROK "failed to add a new (host) dummy device"
+fi
 
 ns_exec $NS_HANDLE $NS_TYPE mount --make-rprivate /sys
 ns_exec $NS_HANDLE $NS_TYPE ip link add $DUMMYDEV type dummy || \
#3 lore raw

PATCH 2/2 testcases: netns: Handle "Operation not supported" error

Hi!

Quoted 6 lines

Not sure if the same should be here. The test-cases with IPsec involve various crypto drivers that are much easier and better to check with ip/netlink, and we also check both: the support in iproute and kernel. I guess, veth and dummy virtual drivers could be checked with:

   modprobe -q veth || tst_brkm TCONF ...

That will possibly break on embedded systems that have everything compiled-in kernel, not sure if there are any out there.

Quoted 1 line

Perhaps, we could add tst_drivers_available() helper to the library.

That's a good idea, that way it could be at least tweaked in a single place.

Signature · 2 lines
Cyril Hrubis
[email protected]
#4 lore raw

PATCH 2/2 testcases: netns: Handle "Operation not supported" error

Hello,

Quoted 9 lines · Cyril Hrubis
Quoted 6 lines

Not sure if the same should be here. The test-cases with IPsec involve various crypto drivers that are much easier and better to check with ip/netlink, and we also check both: the support in iproute and kernel. I guess, veth and dummy virtual drivers could be checked with:

   modprobe -q veth || tst_brkm TCONF ...  

That will possibly break on embedded systems that have everything compiled-in kernel, not sure if there are any out there.

Perhaps LTP should require the kernel to be compiled with CONFIG_IKCONFIG_PROC=y, so that LTP tests can check in /proc/config.gz whether a given kernel feature is available or not ?

Best regards,

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Bootlin (formerly Free Electrons)
Embedded Linux and Kernel engineering
https://bootlin.com
#5 lore raw

PATCH 2/2 testcases: netns: Handle "Operation not supported" error

Hi!

Quoted 6 lines
Quoted 2 lines

That will possibly break on embedded systems that have everything compiled-in kernel, not sure if there are any out there.

Perhaps LTP should require the kernel to be compiled with CONFIG_IKCONFIG_PROC=y, so that LTP tests can check in /proc/config.gz whether a given kernel feature is available or not ?

The problem is that several major distributions does not do that, so it's not an option.

Signature · 2 lines
Cyril Hrubis
[email protected]
#6 lore raw

PATCH 2/2 testcases: netns: Handle "Operation not supported" error

In reply to Cyril Hrubis
Quoted 10 lines · Cyril Hrubis

Hi!

Quoted 6 lines

Not sure if the same should be here. The test-cases with IPsec involve various crypto drivers that are much easier and better to check with ip/netlink, and we also check both: the support in iproute and kernel. I guess, veth and dummy virtual drivers could be checked with:

   modprobe -q veth || tst_brkm TCONF ...

That will possibly break on embedded systems that have everything compiled-in kernel, not sure if there are any out there.

modprobe looks for modules.builtin as well and will just return 0 if it finds the driver there. But it might not be available for kernels before 2.6.33: bc081dd6e9f6 ("kbuild: generate modules.builtin").

Quoted 6 lines
Quoted 2 lines

Perhaps, we could add tst_drivers_available() helper to the library.

That's a good idea, that way it could be at least tweaked in a single place.

#7 lore raw

PATCH 2/2 testcases: netns: Handle "Operation not supported" error

Hi!

Quoted 6 lines
Quoted 2 lines

That will possibly break on embedded systems that have everything compiled-in kernel, not sure if there are any out there.

modprobe looks for modules.builtin as well and will just return 0 if it finds the driver there. But it might not be available for kernels before 2.6.33: bc081dd6e9f6 ("kbuild: generate modules.builtin").

I was also thinking of embedded hardware that does not even install modprobe, but maybe I'm overthinking it and such special cases will have to manualy specify what is supported and what is not, which would be at least doable if we added a library function for checking what is suppored.

Signature · 2 lines
Cyril Hrubis
[email protected]
#8 lore raw

PATCH 2/2 testcases: netns: Handle "Operation not supported" error

In reply to Mylène Josserand

Hi Mylène,

Quoted 15 lines

If there is no support for "dummy" or "veth", the tests will fail with errors:
RTNETLINK answers: Operation not supported
netns_sysfs 1 TBROK: failed to add a new (host) dummy device
and
RTNETLINK answers: Operation not supported netns_comm_ip_ipv6_ioctl 1 TBROK: unable to create veth pair devices Cannot find device "veth0"

This commit is storing the output of the commands and verifies if there is any reference to "Operation not supported". This code is based on what it is already done in "ipsec_lib.sh" stress test.

..

Quoted 1 line
testcases/kernel/containers/netns/netns_helper.sh +0 -0

...

Quoted 1 line
testcases/kernel/containers/netns/netns_helper.sh +1 -0
+			tst_brkm TCONF "Command not supported (maybe missing 'veth' support)"

..

Quoted 1 line
testcases/kernel/containers/netns/netns_sysfs.sh +0 -0

..

testcases/kernel/containers/netns/netns_sysfs.sh if [ $? -eq 1 ]; then · line 60

Quoted 1 line
testcases/kernel/containers/netns/netns_sysfs.sh +1 -0
+		tst_brkm TCONF "Command not supported (maybe missing 'dummy' support)"

Can you implement this patch with TST_NEEDS_DRIVERS (recently contributed by Alexey Kodanev)? Thanks a lot!

Kind regards,
Petr

#9 lore raw

PATCH 2/2 testcases: netns: Handle "Operation not supported" error

Hello,

Quoted 24 lines · On Thu, 4 Oct 2018 15:06:11 +0200 Petr Vorel <[email protected]> wrote:

Hi Mylène,

Quoted 15 lines

If there is no support for "dummy" or "veth", the tests will fail with errors:
RTNETLINK answers: Operation not supported
netns_sysfs 1 TBROK: failed to add a new (host) dummy device
and
RTNETLINK answers: Operation not supported netns_comm_ip_ipv6_ioctl 1 TBROK: unable to create veth pair devices Cannot find device "veth0"

This commit is storing the output of the commands and verifies if there is any reference to "Operation not supported". This code is based on what it is already done in "ipsec_lib.sh" stress test.

..

Quoted 1 line
testcases/kernel/containers/netns/netns_helper.sh +0 -0

...

Quoted 1 line
testcases/kernel/containers/netns/netns_helper.sh +1 -0
+			tst_brkm TCONF "Command not supported (maybe missing 'veth' support)"  

..

Quoted 6 lines
Quoted 1 line
testcases/kernel/containers/netns/netns_sysfs.sh +0 -0

..

testcases/kernel/containers/netns/netns_sysfs.sh if [ $? -eq 1 ]; then · line 60

Quoted 1 line
testcases/kernel/containers/netns/netns_sysfs.sh +1 -0
+		tst_brkm TCONF "Command not supported (maybe missing 'dummy' support)"  

Can you implement this patch with TST_NEEDS_DRIVERS (recently contributed by Alexey Kodanev)? Thanks a lot!

Yes, sure !

I will implement it but not in the next weeks because I am going to be away until the end of November.

Best regards,

Signature · 3 lines
Mylène Josserand, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
#10 lore raw

PATCH 2/2 testcases: netns: Handle "Operation not supported" error

Hi Mylène,

Quoted 12 lines
Quoted 11 lines
Quoted 1 line
testcases/kernel/containers/netns/netns_helper.sh +0 -0

...

Quoted 1 line
testcases/kernel/containers/netns/netns_helper.sh +1 -0
+			tst_brkm TCONF "Command not supported (maybe missing 'veth' support)"  

..

Quoted 1 line
testcases/kernel/containers/netns/netns_sysfs.sh +0 -0

..

testcases/kernel/containers/netns/netns_sysfs.sh if [ $? -eq 1 ]; then · line 60

Quoted 1 line
testcases/kernel/containers/netns/netns_sysfs.sh +1 -0
+		tst_brkm TCONF "Command not supported (maybe missing 'dummy' support)"  

Can you implement this patch with TST_NEEDS_DRIVERS (recently contributed by Alexey Kodanev)? Thanks a lot!

Quoted 4 lines

Yes, sure !

I will implement it but not in the next weeks because I am going to be away until the end of November.

Both are pretty simple one liner patches, but no problem, it can wait for you :).

Kind regards,
Petr

#11 lore raw

PATCH 1/2 testcases: netns: Check TUN support enabled

In reply to Mylène Josserand

Hi Mylène,

Quoted 24 lines

In case TUN support is not enabled, the test will fail while performing the "ip" command with following error:
open: No such file or directory
netns_netlink 1 TBROK : netns_netlink.c:143: system() failed

As the system() call is not setting errno, we are not able to know if the error is produced by a mis-configuration or not.

Because of that, this commit adds a check during the setup function to see if the device "/dev/net/tun" is available or not. It is the file that "ip tuntap add mode tap" command is looking for (and fails with the "open" error).

---
 testcases/kernel/containers/netns/netns_netlink.c | 9 +++++++++
 1 file changed, 9 insertions(+)
testcases/kernel/containers/netns/netns_netlink.c +0 -0
index 47e8235d6..077ec5dab 100644
@@ -57,6 +57,15 @@ static void cleanup(void)
 

testcases/kernel/containers/netns/netns_netlink.c static void cleanup(void) · line 67

Quoted 10 lines
testcases/kernel/containers/netns/netns_netlink.c +8 -0
 static void setup(void)
 {
+	/* Check that the TUN support is available */
+	int netfd = open("/dev/net/tun", O_RDWR);
+	if (netfd == -1) {
+		if (errno == ENODEV || errno == ENOENT)
+			tst_brkm(TCONF, NULL, "TUN support is missing?");
+
+		tst_brkm(TBROK | TERRNO, NULL, "opening /dev/net/tun failed");
+	}

Can you please implement your patch via .needs_drivers (recently contributed by Alexey Kodanev)?

Kind regards,
Petr