public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] [PATCH] containers: added netns/netns_interfaces.c
@ 2014-08-27 15:32 Matus Marhefka
  2014-09-01 10:30 ` [LTP] [PATCH v2] containers: added netns/netns_devices.sh and netns/netns_devices2.sh Matus Marhefka
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Matus Marhefka @ 2014-08-27 15:32 UTC (permalink / raw)
  To: ltp-list

* Tests that a separate network namespace can only communicate over
  the devices it sees

Signed-off-by: Matus Marhefka <mmarhefk@redhat.com>
---
 runtest/containers                                 |   1 +
 testcases/kernel/containers/netns/.gitignore       |   1 +
 testcases/kernel/containers/netns/Makefile         |   3 +-
 .../kernel/containers/netns/netns_interfaces.c     | 205 +++++++++++++++++++++
 4 files changed, 209 insertions(+), 1 deletion(-)
 create mode 100644 testcases/kernel/containers/netns/netns_interfaces.c

diff --git a/runtest/containers b/runtest/containers
index 7d01a44..01ed4cc 100644
--- a/runtest/containers
+++ b/runtest/containers
@@ -29,6 +29,7 @@ netns_crtchild_delchild netns_crtchild_delchild
 netns_par_chld_ipv6 netns_par_chld_ipv6
 netns_par_chld_ftp netns_par_chld_ftp.sh
 netns_netlink netns_netlink
+netns_interfaces netns_interfaces
 
 shmnstest_none shmnstest none
 shmnstest_clone shmnstest clone
diff --git a/testcases/kernel/containers/netns/.gitignore b/testcases/kernel/containers/netns/.gitignore
index 65f96be..a134677 100644
--- a/testcases/kernel/containers/netns/.gitignore
+++ b/testcases/kernel/containers/netns/.gitignore
@@ -6,3 +6,4 @@
 /netns_sysfsview
 /netns_two_children_ns
 /netns_netlink
+/netns_interfaces
diff --git a/testcases/kernel/containers/netns/Makefile b/testcases/kernel/containers/netns/Makefile
index eea0d88..cc8827f 100644
--- a/testcases/kernel/containers/netns/Makefile
+++ b/testcases/kernel/containers/netns/Makefile
@@ -31,7 +31,8 @@ LDLIBS			+= -lclone
 MAKE_TARGETS		:= netns_create_container netns_crtchild \
 			   netns_crtchild_delchild netns_par_chld_ftp \
 			   netns_par_chld_ipv6 netns_sysfsview \
-			   netns_two_children_ns netns_netlink
+			   netns_two_children_ns netns_netlink \
+			   netns_interfaces
 
 $(MAKE_TARGETS): %: common.o %.o
 
diff --git a/testcases/kernel/containers/netns/netns_interfaces.c b/testcases/kernel/containers/netns/netns_interfaces.c
new file mode 100644
index 0000000..b4b7834
--- /dev/null
+++ b/testcases/kernel/containers/netns/netns_interfaces.c
@@ -0,0 +1,205 @@
+/* Copyright (c) 2014 Red Hat, Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of version 2 the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * 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, see <http://www.gnu.org/licenses/>.
+ ***********************************************************************
+ * File: netns_interfaces.c
+ *
+ * Tests that a separate network namespace can only communicate over
+ * the devices it sees. There are three test cases:
+ * 1. communication over paired veth (virtual ethernet) devices
+ *    from two different network namespaces (each namespace has
+ *    one device) should work
+ * 2. communication over the lo (localhost) device in a separate
+ *    network namespace should work
+ * 3. communication over a device which a separate network namespace
+ *    does not see should not work
+ */
+
+#define _GNU_SOURCE
+#include <sys/wait.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+#include "usctest.h"
+#include "test.h"
+#include "safe_macros.h"
+#include "netns_helper.h"
+
+
+/* by convention a named network namespace is an object
+ * at /var/run/netns/NAME that can be opened. (man 8 ip-netns) */
+#define NETNS     "/var/run/netns"
+char *TCID	= "netns_sendintf";
+int TST_TOTAL	= 3;
+int pipefd[2];
+
+
+static void cleanup(void)
+{
+	close(pipefd[0]);
+	close(pipefd[1]);
+
+	/* removes veth0 device (which also removes paired veth1 device) */
+	if (WEXITSTATUS(system("ip link delete veth0")))
+		perror("system");
+	/* removes the network namespace myns */
+	if (WEXITSTATUS(system("ip netns del myns")))
+		perror("system");
+}
+
+static void setup(void)
+{
+	tst_require_root(NULL);
+	check_netns();
+}
+
+int child_func(void)
+{
+	int status, fd;
+	char c;
+
+	fd = open(NETNS"/myns", O_RDONLY);
+	if (fd == -1) {
+		perror("open");
+		return 1;
+	}
+
+	/* associates child with the namespace referred by fd (myns) */
+	if (setns(fd, 0) == -1) {
+		perror("setns");
+		return 1;
+	}
+
+	/* setup for veth1 device */
+	if (WEXITSTATUS(system("ip address add 192.168.0.2/24 dev veth1"))) {
+		perror("system");
+		return 1;
+	}
+	if (WEXITSTATUS(system("ip link set dev veth1 up"))) {
+		perror("system");
+		return 1;
+	}
+
+	/* waits for parent to confirm that veth0 device setup is done */
+	if (read(pipefd[0], &c, 1) == -1) {
+		perror("read");
+		return 1;
+	}
+
+	/* ping veth0 address through veth1 device */
+	if (WEXITSTATUS(
+	    system("ping -q -c 2 -I veth1 192.168.0.1 &>/dev/null")))
+		return 1;
+
+	return 0;
+}
+
+static void test(void)
+{
+	pid_t pid;
+	int status, ret = 0;
+
+	/* creates a pipe for synchronization between parent and child */
+	SAFE_PIPE(cleanup, pipefd);
+
+	/* unshares a network and a mount namespace */
+	if (unshare(CLONE_NEWNET|CLONE_NEWNS) == -1)
+		tst_brkm(TBROK | TERRNO, cleanup, "unshare failed");
+
+
+	/* TEST CASE #1 */
+	/* creates a pair of virtual ethernet devices */
+	if (WEXITSTATUS(system("ip link add veth0 type veth peer name veth1")))
+		tst_brkm(TBROK | TERRNO, cleanup, "system failed");
+	/* creates a new network namespace "myns" (man 8 ip-netns) */
+	if (WEXITSTATUS(system("ip netns add myns")))
+		tst_brkm(TBROK | TERRNO, cleanup, "system failed");
+	/* adds device veth1 to myns namespace */
+	if (WEXITSTATUS(system("ip link set veth1 netns myns")))
+		tst_brkm(TBROK | TERRNO, cleanup, "system failed");
+
+
+	pid = fork();
+	if (pid < 0) {  /* error */
+		tst_brkm(TBROK | TERRNO, cleanup, "fork failed");
+	}
+	if (pid == 0) { /* child */
+		_exit(child_func());
+	}
+
+	/* parent */
+	/* setup for veth0 device */
+	if (WEXITSTATUS(system("ip address add 192.168.0.1/24 dev veth0")))
+		tst_brkm(TBROK | TERRNO, cleanup, "system failed");
+	if (WEXITSTATUS(system("ip link set dev veth0 up")))
+		tst_brkm(TBROK | TERRNO, cleanup, "system failed");
+
+	/* allow child to continue */
+	SAFE_WRITE(cleanup, 0, pipefd[1], "0", 1);
+
+	/* ping veth1 address through veth0 device */
+	ret = system("ping -q -c 2 -I veth0 192.168.0.2 &>/dev/null");
+	if (WEXITSTATUS(ret))
+		tst_resm(TFAIL, "communication over veth devices fail");
+
+	SAFE_WAITPID(cleanup, pid, &status, 0);
+	if (WIFEXITED(status) && WEXITSTATUS(status)) {
+		if (WEXITSTATUS(ret) == 0) {
+			tst_resm(TFAIL, "communication over veth devices fail");
+			ret = status;
+		}
+	}
+
+	if (WEXITSTATUS(ret) == 0)
+		tst_resm(TPASS, "communication over veth devices pass");
+
+
+	/* TEST CASE #2 */
+	/* enable lo device */
+	if (WEXITSTATUS(system("ip link set dev lo up")))
+		tst_brkm(TBROK | TERRNO, cleanup, "system failed");
+	/* ping localhost */
+	if (WEXITSTATUS(system("ping -q -c 2 -I lo 127.0.0.1 &>/dev/null")))
+		tst_resm(TFAIL, "communication over lo device fail");
+	else
+		tst_resm(TPASS, "communication over lo device pass");
+
+
+	/* TEST CASE #3 */
+	/* ping over a device which this separate network namespace
+	 * does not see - this should not work */
+	if (WEXITSTATUS(
+	    system("ping -q -c 2 -I veth1 192.168.0.1 &>/dev/null")))
+		tst_resm(TPASS, "communication over non-existent device pass");
+	else
+		tst_resm(TFAIL, "communication over non-existent device fail");
+}
+
+int main(int argc, char *argv[])
+{
+	const char *msg;
+	int lc;
+
+	msg = parse_opts(argc, argv, NULL, NULL);
+	if (msg != NULL)
+		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
+
+	setup();
+
+	for (lc = 0; TEST_LOOPING(lc); lc++) {
+		test();
+		cleanup();
+	}
+
+	tst_exit();
+}
-- 
1.8.3.1


------------------------------------------------------------------------------
Slashdot TV.  
Video for Nerds.  Stuff that matters.
http://tv.slashdot.org/
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [LTP] [PATCH v2] containers: added netns/netns_devices.sh and netns/netns_devices2.sh
  2014-08-27 15:32 [LTP] [PATCH] containers: added netns/netns_interfaces.c Matus Marhefka
@ 2014-09-01 10:30 ` Matus Marhefka
  2014-09-04 12:43 ` [LTP] [PATCH v3] " Matus Marhefka
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 8+ messages in thread
From: Matus Marhefka @ 2014-09-01 10:30 UTC (permalink / raw)
  To: ltp-list

* Tests that a separate network namespace can configure and communicate
  over the devices it sees
* netns/netns_devices.sh  -- uses netlink(7) for configuration
* netns/netns_devices2.sh -- uses ioctl(2) for configuration

Signed-off-by: Matus Marhefka <mmarhefk@redhat.com>
---
 runtest/containers                                 |   2 +
 testcases/kernel/containers/netns/netns_devices.sh | 110 ++++++++++++++++++++
 .../kernel/containers/netns/netns_devices2.sh      | 112 +++++++++++++++++++++
 3 files changed, 224 insertions(+)
 create mode 100755 testcases/kernel/containers/netns/netns_devices.sh
 create mode 100755 testcases/kernel/containers/netns/netns_devices2.sh

diff --git a/runtest/containers b/runtest/containers
index 7d01a44..69eac82 100644
--- a/runtest/containers
+++ b/runtest/containers
@@ -29,6 +29,8 @@ netns_crtchild_delchild netns_crtchild_delchild
 netns_par_chld_ipv6 netns_par_chld_ipv6
 netns_par_chld_ftp netns_par_chld_ftp.sh
 netns_netlink netns_netlink
+netns_devices netns_devices.sh
+netns_devices2 netns_devices2.sh
 
 shmnstest_none shmnstest none
 shmnstest_clone shmnstest clone
diff --git a/testcases/kernel/containers/netns/netns_devices.sh b/testcases/kernel/containers/netns/netns_devices.sh
new file mode 100755
index 0000000..0be9e02
--- /dev/null
+++ b/testcases/kernel/containers/netns/netns_devices.sh
@@ -0,0 +1,110 @@
+#!/bin/sh
+#==============================================================================
+# Copyright (c) 2014 Red Hat, Inc.
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of version 2 the GNU General Public License as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful,
+# 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, see <http://www.gnu.org/licenses/>.
+#==============================================================================
+# File: netns_devices.sh
+#
+# Tests that a separate network namespace can configure and communicate
+# over the devices it sees. Tests are done using ip command which uses
+# netlink(7) sockets to control devices. There are two test cases:
+# 1. communication over paired veth (virtual ethernet) devices
+#    from two different network namespaces (each namespace has
+#    one device)
+# 2. communication over the lo (localhost) device in a separate
+#    network namespace
+#
+
+TCID=netns_devices
+TST_TOTAL=2
+. test.sh
+IP0=192.168.0.1
+IP1=192.168.0.2
+
+
+cleanup()
+{
+	# removes veth0 device (which also removes paired veth1 device)
+	ip link delete veth0
+	# removes the network namespace myns
+	ip netns del myns
+}
+
+
+# SETUP
+tst_require_root
+which ip &>/dev/null || tst_brkm TCONF "ip utility is required for this test"
+TST_CLEANUP=cleanup
+
+# creates a pair of virtual ethernet devices
+ip link add veth0 type veth peer name veth1 &>/dev/null || \
+	tst_brkm TBROK "unable to create veth pair devices"
+
+# creates a new network namespace "myns" (man 8 ip-netns)
+ip netns add myns &>/dev/null || \
+	tst_brkm TBROK "unable to create a new network namespace"
+
+# adds device veth1 to myns namespace
+ip link set veth1 netns myns &>/dev/null || \
+	tst_brkm TBROK "unable to add device veth1 to the network namespace myns"
+
+
+# TEST CASE #1
+# setup for veth0 device
+ip address add $IP0/24 dev veth0 || \
+	tst_brkm TBROK "adding address to veth0 failed"
+ip link set dev veth0 up || \
+	tst_brkm TBROK "enabling veth0 device failed"
+
+# setup for veth1 (which is inside myns namespace)
+ip netns exec myns ip address add $IP1/24 dev veth1 || \
+	tst_brkm TBROK "adding address to veth1 failed"
+ip netns exec myns ip link set dev veth1 up || \
+	tst_brkm TBROK "enabling veth1 device failed"
+
+ping -q -c 2 -I veth0 $IP1 &>/dev/null
+ret=$?
+failed=0
+if [ $ret -ne 0 ]; then
+	failed=1
+fi
+
+ip netns exec myns ping -q -c 2 -I veth1 $IP0 &>/dev/null
+ret=$?
+if [ $ret -ne 0 ]; then
+	failed=1
+fi
+
+if [ $failed -eq 0 ]; then
+	tst_resm TPASS "netlink configuration and communication over veth devices"
+else
+	tst_resm TFAIL "netlink configuration and communication over veth devices"
+fi
+
+
+# TEST CASE #2
+# enables lo device
+ip netns exec myns ip link set dev lo up || \
+	tst_brkm TBROK "enabling lo device failed"
+
+ip netns exec myns ping -q -c 2 -I lo 127.0.0.1 &>/dev/null
+ret=$?
+if [ $ret -eq 0 ]; then
+	tst_resm TPASS "netlink configuration and communication over lo device"
+else
+	tst_resm TFAIL "netlink configuration and communication over lo device"
+fi
+
+
+tst_exit
diff --git a/testcases/kernel/containers/netns/netns_devices2.sh b/testcases/kernel/containers/netns/netns_devices2.sh
new file mode 100755
index 0000000..ca08c1d
--- /dev/null
+++ b/testcases/kernel/containers/netns/netns_devices2.sh
@@ -0,0 +1,112 @@
+#!/bin/sh
+#==============================================================================
+# Copyright (c) 2014 Red Hat, Inc.
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of version 2 the GNU General Public License as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful,
+# 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, see <http://www.gnu.org/licenses/>.
+#==============================================================================
+# File: netns_devices2.sh
+#
+# Tests that a separate network namespace can configure and communicate
+# over the devices it sees. Tests are done using ifconfig command which
+# uses ioctl(2) to control devices. There are two test cases:
+# 1. communication over paired veth (virtual ethernet) devices
+#    from two different network namespaces (each namespace has
+#    one device)
+# 2. communication over the lo (localhost) device in a separate
+#    network namespace
+#
+
+TCID=netns_devices2
+TST_TOTAL=2
+. test.sh
+IP0=192.168.0.1
+IP1=192.168.0.2
+
+
+cleanup()
+{
+	# removes veth0 device (which also removes paired veth1 device)
+	ip link delete veth0
+	# removes the network namespace myns
+	ip netns del myns
+}
+
+
+# SETUP
+tst_require_root
+which ifconfig &>/dev/null ||
+	tst_brkm TCONF "ifconfig utility is required for this test"
+which ip &>/dev/null || tst_brkm TCONF "ip utility is required for this test"
+TST_CLEANUP=cleanup
+
+# creates a pair of virtual ethernet devices
+ip link add veth0 type veth peer name veth1 &>/dev/null || \
+	tst_brkm TBROK "unable to create veth pair devices"
+
+# creates a new network namespace "myns" (man 8 ip-netns)
+ip netns add myns &>/dev/null || \
+	tst_brkm TBROK "unable to create a new network namespace"
+
+# adds device veth1 to myns namespace
+ip link set veth1 netns myns &>/dev/null || \
+	tst_brkm TBROK "unable to add device veth1 to the network namespace myns"
+
+
+# TEST CASE #1
+# setup for veth0 device
+ifconfig veth0 $IP0/24 || \
+	tst_brkm TBROK "adding address to veth0 failed"
+ifconfig veth0 up || \
+	tst_brkm TBROK "enabling veth0 device failed"
+
+# setup for veth1 (which is inside myns namespace)
+ip netns exec myns ifconfig veth1 $IP1/24 || \
+	tst_brkm TBROK "adding address to veth1 failed"
+ip netns exec myns ifconfig veth1 up || \
+	tst_brkm TBROK "enabling veth1 device failed"
+
+ping -q -c 2 -I veth0 $IP1 &>/dev/null
+ret=$?
+failed=0
+if [ $ret -ne 0 ]; then
+	failed=1
+fi
+
+ip netns exec myns ping -q -c 2 -I veth1 $IP0 &>/dev/null
+ret=$?
+if [ $ret -ne 0 ]; then
+	failed=1
+fi
+
+if [ $failed -eq 0 ]; then
+	tst_resm TPASS "ioctl configuration and communication over veth devices"
+else
+	tst_resm TFAIL "ioctl configuration and communication over veth devices"
+fi
+
+
+# TEST CASE #2
+# enables lo device
+ip netns exec myns ifconfig lo up || \
+	tst_brkm TBROK "enabling lo device failed"
+
+ip netns exec myns ping -q -c 2 -I lo 127.0.0.1 &>/dev/null
+ret=$?
+if [ $ret -eq 0 ]; then
+	tst_resm TPASS "ioctl configuration and communication over lo device"
+else
+	tst_resm TFAIL "ioctl configuration and communication over lo device"
+fi
+
+
+tst_exit
-- 
1.8.3.1


------------------------------------------------------------------------------
Slashdot TV.  
Video for Nerds.  Stuff that matters.
http://tv.slashdot.org/
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [LTP] [PATCH v3] containers: added netns/netns_devices.sh and netns/netns_devices2.sh
  2014-08-27 15:32 [LTP] [PATCH] containers: added netns/netns_interfaces.c Matus Marhefka
  2014-09-01 10:30 ` [LTP] [PATCH v2] containers: added netns/netns_devices.sh and netns/netns_devices2.sh Matus Marhefka
@ 2014-09-04 12:43 ` Matus Marhefka
  2014-09-24  9:38   ` chrubis
  2014-10-02 14:18 ` [LTP] [PATCH v4] " Matus Marhefka
  2014-10-15 12:56 ` [LTP] [PATCH] containers: added netns/netns_interfaces.c Cyril Hrubis
  3 siblings, 1 reply; 8+ messages in thread
From: Matus Marhefka @ 2014-09-04 12:43 UTC (permalink / raw)
  To: ltp-list

* Tests that a separate network namespace can configure and communicate
  over the devices it sees
* netns/netns_devices.sh  -- uses netlink(7) for configuration
* netns/netns_devices2.sh -- uses ioctl(2) for configuration

Signed-off-by: Matus Marhefka <mmarhefk@redhat.com>
---
 runtest/containers                                 |   2 +
 testcases/kernel/containers/netns/netns_devices.sh | 110 +++++++++++++++++++++
 .../kernel/containers/netns/netns_devices2.sh      | 110 +++++++++++++++++++++
 3 files changed, 222 insertions(+)
 create mode 100755 testcases/kernel/containers/netns/netns_devices.sh
 create mode 100755 testcases/kernel/containers/netns/netns_devices2.sh

diff --git a/runtest/containers b/runtest/containers
index 7d01a44..69eac82 100644
--- a/runtest/containers
+++ b/runtest/containers
@@ -29,6 +29,8 @@ netns_crtchild_delchild netns_crtchild_delchild
 netns_par_chld_ipv6 netns_par_chld_ipv6
 netns_par_chld_ftp netns_par_chld_ftp.sh
 netns_netlink netns_netlink
+netns_devices netns_devices.sh
+netns_devices2 netns_devices2.sh
 
 shmnstest_none shmnstest none
 shmnstest_clone shmnstest clone
diff --git a/testcases/kernel/containers/netns/netns_devices.sh b/testcases/kernel/containers/netns/netns_devices.sh
new file mode 100755
index 0000000..df55971
--- /dev/null
+++ b/testcases/kernel/containers/netns/netns_devices.sh
@@ -0,0 +1,110 @@
+#!/bin/sh
+#==============================================================================
+# Copyright (c) 2014 Red Hat, Inc.
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of version 2 the GNU General Public License as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful,
+# 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, see <http://www.gnu.org/licenses/>.
+#==============================================================================
+# File: netns_devices.sh
+#
+# Tests that a separate network namespace can configure and communicate
+# over the devices it sees. Tests are done using ip command which uses
+# netlink(7) sockets to control devices. There are two test cases:
+# 1. communication over paired veth (virtual ethernet) devices
+#    from two different network namespaces (each namespace has
+#    one device)
+# 2. communication over the lo (localhost) device in a separate
+#    network namespace
+#
+
+TCID=netns_devices
+TST_TOTAL=2
+. test.sh
+IP0=192.168.0.1
+IP1=192.168.0.2
+
+
+cleanup()
+{
+	# removes veth0 device (which also removes paired veth1 device)
+	ip link delete veth0
+	# removes the network namespace myns
+	ip netns del myns
+}
+
+
+# SETUP
+tst_require_root
+tst_check_cmds ip
+TST_CLEANUP=cleanup
+
+# creates a pair of virtual ethernet devices
+ip link add veth0 type veth peer name veth1 &>/dev/null || \
+	tst_brkm TBROK "unable to create veth pair devices"
+
+# creates a new network namespace "myns" (man 8 ip-netns)
+ip netns add myns &>/dev/null || \
+	tst_brkm TBROK "unable to create a new network namespace"
+
+# adds device veth1 to myns namespace
+ip link set veth1 netns myns &>/dev/null || \
+	tst_brkm TBROK "unable to add device veth1 to the network namespace myns"
+
+
+# TEST CASE #1
+# setup for veth0 device
+ip address add $IP0/24 dev veth0 || \
+	tst_brkm TBROK "adding address to veth0 failed"
+ip link set dev veth0 up || \
+	tst_brkm TBROK "enabling veth0 device failed"
+
+# setup for veth1 (which is inside myns namespace)
+ip netns exec myns ip address add $IP1/24 dev veth1 || \
+	tst_brkm TBROK "adding address to veth1 failed"
+ip netns exec myns ip link set dev veth1 up || \
+	tst_brkm TBROK "enabling veth1 device failed"
+
+ping -q -c 2 -I veth0 $IP1 &>/dev/null
+ret=$?
+failed=0
+if [ $ret -ne 0 ]; then
+	failed=1
+fi
+
+ip netns exec myns ping -q -c 2 -I veth1 $IP0 &>/dev/null
+ret=$?
+if [ $ret -ne 0 ]; then
+	failed=1
+fi
+
+if [ $failed -eq 0 ]; then
+	tst_resm TPASS "netlink configuration and communication over veth devices"
+else
+	tst_resm TFAIL "netlink configuration and communication over veth devices"
+fi
+
+
+# TEST CASE #2
+# enables lo device
+ip netns exec myns ip link set dev lo up || \
+	tst_brkm TBROK "enabling lo device failed"
+
+ip netns exec myns ping -q -c 2 -I lo 127.0.0.1 &>/dev/null
+ret=$?
+if [ $ret -eq 0 ]; then
+	tst_resm TPASS "netlink configuration and communication over lo device"
+else
+	tst_resm TFAIL "netlink configuration and communication over lo device"
+fi
+
+
+tst_exit
diff --git a/testcases/kernel/containers/netns/netns_devices2.sh b/testcases/kernel/containers/netns/netns_devices2.sh
new file mode 100755
index 0000000..ed3f5eb
--- /dev/null
+++ b/testcases/kernel/containers/netns/netns_devices2.sh
@@ -0,0 +1,110 @@
+#!/bin/sh
+#==============================================================================
+# Copyright (c) 2014 Red Hat, Inc.
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of version 2 the GNU General Public License as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful,
+# 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, see <http://www.gnu.org/licenses/>.
+#==============================================================================
+# File: netns_devices2.sh
+#
+# Tests that a separate network namespace can configure and communicate
+# over the devices it sees. Tests are done using ifconfig command which
+# uses ioctl(2) to control devices. There are two test cases:
+# 1. communication over paired veth (virtual ethernet) devices
+#    from two different network namespaces (each namespace has
+#    one device)
+# 2. communication over the lo (localhost) device in a separate
+#    network namespace
+#
+
+TCID=netns_devices2
+TST_TOTAL=2
+. test.sh
+IP0=192.168.0.1
+IP1=192.168.0.2
+
+
+cleanup()
+{
+	# removes veth0 device (which also removes paired veth1 device)
+	ip link delete veth0
+	# removes the network namespace myns
+	ip netns del myns
+}
+
+
+# SETUP
+tst_require_root
+tst_check_cmds ip ifconfig
+TST_CLEANUP=cleanup
+
+# creates a pair of virtual ethernet devices
+ip link add veth0 type veth peer name veth1 &>/dev/null || \
+	tst_brkm TBROK "unable to create veth pair devices"
+
+# creates a new network namespace "myns" (man 8 ip-netns)
+ip netns add myns &>/dev/null || \
+	tst_brkm TBROK "unable to create a new network namespace"
+
+# adds device veth1 to myns namespace
+ip link set veth1 netns myns &>/dev/null || \
+	tst_brkm TBROK "unable to add device veth1 to the network namespace myns"
+
+
+# TEST CASE #1
+# setup for veth0 device
+ifconfig veth0 $IP0/24 || \
+	tst_brkm TBROK "adding address to veth0 failed"
+ifconfig veth0 up || \
+	tst_brkm TBROK "enabling veth0 device failed"
+
+# setup for veth1 (which is inside myns namespace)
+ip netns exec myns ifconfig veth1 $IP1/24 || \
+	tst_brkm TBROK "adding address to veth1 failed"
+ip netns exec myns ifconfig veth1 up || \
+	tst_brkm TBROK "enabling veth1 device failed"
+
+ping -q -c 2 -I veth0 $IP1 &>/dev/null
+ret=$?
+failed=0
+if [ $ret -ne 0 ]; then
+	failed=1
+fi
+
+ip netns exec myns ping -q -c 2 -I veth1 $IP0 &>/dev/null
+ret=$?
+if [ $ret -ne 0 ]; then
+	failed=1
+fi
+
+if [ $failed -eq 0 ]; then
+	tst_resm TPASS "ioctl configuration and communication over veth devices"
+else
+	tst_resm TFAIL "ioctl configuration and communication over veth devices"
+fi
+
+
+# TEST CASE #2
+# enables lo device
+ip netns exec myns ifconfig lo up || \
+	tst_brkm TBROK "enabling lo device failed"
+
+ip netns exec myns ping -q -c 2 -I lo 127.0.0.1 &>/dev/null
+ret=$?
+if [ $ret -eq 0 ]; then
+	tst_resm TPASS "ioctl configuration and communication over lo device"
+else
+	tst_resm TFAIL "ioctl configuration and communication over lo device"
+fi
+
+
+tst_exit
-- 
1.8.3.1


------------------------------------------------------------------------------
Slashdot TV.  
Video for Nerds.  Stuff that matters.
http://tv.slashdot.org/
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [LTP] [PATCH v3] containers: added netns/netns_devices.sh and netns/netns_devices2.sh
  2014-09-04 12:43 ` [LTP] [PATCH v3] " Matus Marhefka
@ 2014-09-24  9:38   ` chrubis
  0 siblings, 0 replies; 8+ messages in thread
From: chrubis @ 2014-09-24  9:38 UTC (permalink / raw)
  To: Matus Marhefka; +Cc: ltp-list

Hi!
> +# creates a pair of virtual ethernet devices
> +ip link add veth0 type veth peer name veth1 &>/dev/null || \
> +	tst_brkm TBROK "unable to create veth pair devices"

The &> operator is bashism and the testcases should be runable with
other shells too. Generally it's a good idea to try to run them with
dash or bussy box sh before submission.

And also I'm not 100% sure that it's a good idea to hide the nature of
the problem. Are these commands too verbose by default?

> +# creates a new network namespace "myns" (man 8 ip-netns)
> +ip netns add myns &>/dev/null || \
> +	tst_brkm TBROK "unable to create a new network namespace"
> +
> +# adds device veth1 to myns namespace
> +ip link set veth1 netns myns &>/dev/null || \
> +	tst_brkm TBROK "unable to add device veth1 to the network namespace myns"
> +
> +
> +# TEST CASE #1
> +# setup for veth0 device
> +ip address add $IP0/24 dev veth0 || \
> +	tst_brkm TBROK "adding address to veth0 failed"
> +ip link set dev veth0 up || \
> +	tst_brkm TBROK "enabling veth0 device failed"
> +
> +# setup for veth1 (which is inside myns namespace)
> +ip netns exec myns ip address add $IP1/24 dev veth1 || \
> +	tst_brkm TBROK "adding address to veth1 failed"
> +ip netns exec myns ip link set dev veth1 up || \
> +	tst_brkm TBROK "enabling veth1 device failed"
> +
> +ping -q -c 2 -I veth0 $IP1 &>/dev/null
> +ret=$?
> +failed=0
> +if [ $ret -ne 0 ]; then
> +	failed=1
> +fi
> +
> +ip netns exec myns ping -q -c 2 -I veth1 $IP0 &>/dev/null
> +ret=$?
> +if [ $ret -ne 0 ]; then
> +	failed=1
> +fi

It would be cleaner to do tst_resm in both cases and declare that the
test has three testcases.

> +if [ $failed -eq 0 ]; then
> +	tst_resm TPASS "netlink configuration and communication over veth devices"
> +else
> +	tst_resm TFAIL "netlink configuration and communication over veth devices"
> +fi
> +
> +
> +# TEST CASE #2
> +# enables lo device
> +ip netns exec myns ip link set dev lo up || \
> +	tst_brkm TBROK "enabling lo device failed"
> +
> +ip netns exec myns ping -q -c 2 -I lo 127.0.0.1 &>/dev/null
> +ret=$?
> +if [ $ret -eq 0 ]; then
> +	tst_resm TPASS "netlink configuration and communication over lo device"
> +else
> +	tst_resm TFAIL "netlink configuration and communication over lo device"
> +fi
> +
> +
> +tst_exit
> diff --git a/testcases/kernel/containers/netns/netns_devices2.sh b/testcases/kernel/containers/netns/netns_devices2.sh
> new file mode 100755
> index 0000000..ed3f5eb
> --- /dev/null
> +++ b/testcases/kernel/containers/netns/netns_devices2.sh
> @@ -0,0 +1,110 @@
> +#!/bin/sh
> +#==============================================================================
> +# Copyright (c) 2014 Red Hat, Inc.
> +#
> +# This program is free software: you can redistribute it and/or modify
> +# it under the terms of version 2 the GNU General Public License as
> +# published by the Free Software Foundation.
> +#
> +# This program is distributed in the hope that it will be useful,
> +# 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, see <http://www.gnu.org/licenses/>.
> +#==============================================================================
> +# File: netns_devices2.sh
> +#
> +# Tests that a separate network namespace can configure and communicate
> +# over the devices it sees. Tests are done using ifconfig command which
> +# uses ioctl(2) to control devices. There are two test cases:
> +# 1. communication over paired veth (virtual ethernet) devices
> +#    from two different network namespaces (each namespace has
> +#    one device)
> +# 2. communication over the lo (localhost) device in a separate
> +#    network namespace
> +#
> +
> +TCID=netns_devices2
> +TST_TOTAL=2
> +. test.sh
> +IP0=192.168.0.1
> +IP1=192.168.0.2
> +
> +
> +cleanup()
> +{
> +	# removes veth0 device (which also removes paired veth1 device)
> +	ip link delete veth0
> +	# removes the network namespace myns
> +	ip netns del myns
> +}
> +
> +
> +# SETUP
> +tst_require_root
> +tst_check_cmds ip ifconfig
> +TST_CLEANUP=cleanup
> +
> +# creates a pair of virtual ethernet devices
> +ip link add veth0 type veth peer name veth1 &>/dev/null || \
> +	tst_brkm TBROK "unable to create veth pair devices"
> +
> +# creates a new network namespace "myns" (man 8 ip-netns)
> +ip netns add myns &>/dev/null || \
> +	tst_brkm TBROK "unable to create a new network namespace"
> +
> +# adds device veth1 to myns namespace
> +ip link set veth1 netns myns &>/dev/null || \
> +	tst_brkm TBROK "unable to add device veth1 to the network namespace myns"

Here the &>/dev/null as well.

> +# TEST CASE #1
> +# setup for veth0 device
> +ifconfig veth0 $IP0/24 || \
> +	tst_brkm TBROK "adding address to veth0 failed"
> +ifconfig veth0 up || \
> +	tst_brkm TBROK "enabling veth0 device failed"
> +
> +# setup for veth1 (which is inside myns namespace)
> +ip netns exec myns ifconfig veth1 $IP1/24 || \
> +	tst_brkm TBROK "adding address to veth1 failed"
> +ip netns exec myns ifconfig veth1 up || \
> +	tst_brkm TBROK "enabling veth1 device failed"
> +
> +ping -q -c 2 -I veth0 $IP1 &>/dev/null
> +ret=$?
> +failed=0
> +if [ $ret -ne 0 ]; then
> +	failed=1
> +fi
> +
> +ip netns exec myns ping -q -c 2 -I veth1 $IP0 &>/dev/null
> +ret=$?
> +if [ $ret -ne 0 ]; then
> +	failed=1
> +fi
> +
> +if [ $failed -eq 0 ]; then
> +	tst_resm TPASS "ioctl configuration and communication over veth devices"
> +else
> +	tst_resm TFAIL "ioctl configuration and communication over veth devices"
> +fi

Here the same applies as well.

> +# TEST CASE #2
> +# enables lo device
> +ip netns exec myns ifconfig lo up || \
> +	tst_brkm TBROK "enabling lo device failed"
> +
> +ip netns exec myns ping -q -c 2 -I lo 127.0.0.1 &>/dev/null
> +ret=$?
> +if [ $ret -eq 0 ]; then
> +	tst_resm TPASS "ioctl configuration and communication over lo device"
> +else
> +	tst_resm TFAIL "ioctl configuration and communication over lo device"
> +fi
> +
> +
> +tst_exit

-- 
Cyril Hrubis
chrubis@suse.cz

------------------------------------------------------------------------------
Meet PCI DSS 3.0 Compliance Requirements with EventLog Analyzer
Achieve PCI DSS 3.0 Compliant Status with Out-of-the-box PCI DSS Reports
Are you Audit-Ready for PCI DSS 3.0 Compliance? Download White paper
Comply to PCI DSS 3.0 Requirement 10 and 11.5 with EventLog Analyzer
http://pubads.g.doubleclick.net/gampad/clk?id=154622311&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [LTP] [PATCH v4] containers: added netns/netns_devices.sh and netns/netns_devices2.sh
  2014-08-27 15:32 [LTP] [PATCH] containers: added netns/netns_interfaces.c Matus Marhefka
  2014-09-01 10:30 ` [LTP] [PATCH v2] containers: added netns/netns_devices.sh and netns/netns_devices2.sh Matus Marhefka
  2014-09-04 12:43 ` [LTP] [PATCH v3] " Matus Marhefka
@ 2014-10-02 14:18 ` Matus Marhefka
  2014-10-27 14:49   ` Cyril Hrubis
  2014-10-15 12:56 ` [LTP] [PATCH] containers: added netns/netns_interfaces.c Cyril Hrubis
  3 siblings, 1 reply; 8+ messages in thread
From: Matus Marhefka @ 2014-10-02 14:18 UTC (permalink / raw)
  To: ltp-list

* Tests that a separate network namespace can configure and communicate
  over the devices it sees
* netns/netns_devices.sh  -- uses netlink(7) for configuration
* netns/netns_devices2.sh -- uses ioctl(2) for configuration

Signed-off-by: Matus Marhefka <mmarhefk@redhat.com>
---
 runtest/containers                                 |   2 +
 testcases/kernel/containers/netns/netns_devices.sh | 115 +++++++++++++++++++++
 .../kernel/containers/netns/netns_devices2.sh      | 115 +++++++++++++++++++++
 3 files changed, 232 insertions(+)
 create mode 100755 testcases/kernel/containers/netns/netns_devices.sh
 create mode 100755 testcases/kernel/containers/netns/netns_devices2.sh

diff --git a/runtest/containers b/runtest/containers
index 7d01a44..69eac82 100644
--- a/runtest/containers
+++ b/runtest/containers
@@ -29,6 +29,8 @@ netns_crtchild_delchild netns_crtchild_delchild
 netns_par_chld_ipv6 netns_par_chld_ipv6
 netns_par_chld_ftp netns_par_chld_ftp.sh
 netns_netlink netns_netlink
+netns_devices netns_devices.sh
+netns_devices2 netns_devices2.sh
 
 shmnstest_none shmnstest none
 shmnstest_clone shmnstest clone
diff --git a/testcases/kernel/containers/netns/netns_devices.sh b/testcases/kernel/containers/netns/netns_devices.sh
new file mode 100755
index 0000000..7126267
--- /dev/null
+++ b/testcases/kernel/containers/netns/netns_devices.sh
@@ -0,0 +1,115 @@
+#!/bin/sh
+#==============================================================================
+# Copyright (c) 2014 Red Hat, Inc.
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of version 2 the GNU General Public License as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful,
+# 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, see <http://www.gnu.org/licenses/>.
+#==============================================================================
+# File: netns_devices.sh
+#
+# Tests that a separate network namespace can configure and communicate
+# over the devices it sees. Tests are done using ip command which uses
+# netlink(7) sockets to control devices. There are three test cases:
+# 1,2. communication over paired veth (virtual ethernet) devices
+#      from two different network namespaces (each namespace has
+#      one device)
+#   3. communication over the lo (localhost) device in a separate
+#      network namespace
+#
+
+TCID=netns_devices
+TST_TOTAL=3
+. test.sh
+IP0=192.168.0.1
+IP1=192.168.0.2
+
+
+cleanup()
+{
+	# removes veth0 device (which also removes paired veth1 device)
+	ip netns exec myns0 ip link delete veth0
+	# removes the network namespace myns
+	ip netns del myns0
+	ip netns del myns1
+}
+
+
+# SETUP
+tst_require_root
+tst_check_cmds ip
+TST_CLEANUP=cleanup
+
+# creates a new network namespace "myns0" (man 8 ip-netns)
+ip netns add myns0 || \
+	tst_brkm TBROK "unable to create a new network namespace (myns0)"
+
+# creates a new network namespace "myns1"
+ip netns add myns1 || \
+	tst_brkm TBROK "unable to create a new network namespace (myns1)"
+
+# creates a pair of virtual ethernet devices
+ip netns exec myns0 ip link add veth0 type veth peer name veth1 || \
+	tst_brkm TBROK "unable to create veth pair devices"
+
+# adds device veth1 to myns1 namespace
+ip netns exec myns0 ip link set veth1 netns myns1 || \
+	tst_brkm TBROK "unable to add device veth1 to the network namespace myns1"
+
+
+# setup for veth0 device (which is inside myns0 namespace)
+ip netns exec myns0 ip address add $IP0/24 dev veth0 || \
+	tst_brkm TBROK "adding address to veth0 failed"
+ip netns exec myns0 ip link set dev veth0 up || \
+	tst_brkm TBROK "enabling veth0 device failed"
+
+# setup for veth1 (which is inside myns1 namespace)
+ip netns exec myns1 ip address add $IP1/24 dev veth1 || \
+	tst_brkm TBROK "adding address to veth1 failed"
+ip netns exec myns1 ip link set dev veth1 up || \
+	tst_brkm TBROK "enabling veth1 device failed"
+
+
+# TEST CASE #1
+ip netns exec myns0 ping -q -c 2 -I veth0 $IP1 >/dev/null
+ret=$?
+if [ $ret -eq 0 ]; then
+	tst_resm TPASS "netlink configuration and communication over veth0 device"
+else
+	tst_resm TFAIL "netlink configuration and communication over veth0 device"
+fi
+
+
+# TEST CASE #2
+ip netns exec myns1 ping -q -c 2 -I veth1 $IP0 >/dev/null
+ret=$?
+if [ $ret -eq 0 ]; then
+	tst_resm TPASS "netlink configuration and communication over veth1 device"
+else
+	tst_resm TFAIL "netlink configuration and communication over veth1 device"
+fi
+
+
+# TEST CASE #3
+# enables lo device
+ip netns exec myns0 ip link set dev lo up || \
+	tst_brkm TBROK "enabling lo device failed"
+
+ip netns exec myns0 ping -q -c 2 -I lo 127.0.0.1 >/dev/null
+ret=$?
+if [ $ret -eq 0 ]; then
+	tst_resm TPASS "netlink configuration and communication over lo device"
+else
+	tst_resm TFAIL "netlink configuration and communication over lo device"
+fi
+
+
+tst_exit
diff --git a/testcases/kernel/containers/netns/netns_devices2.sh b/testcases/kernel/containers/netns/netns_devices2.sh
new file mode 100755
index 0000000..f0d0651
--- /dev/null
+++ b/testcases/kernel/containers/netns/netns_devices2.sh
@@ -0,0 +1,115 @@
+#!/bin/sh
+#==============================================================================
+# Copyright (c) 2014 Red Hat, Inc.
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of version 2 the GNU General Public License as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful,
+# 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, see <http://www.gnu.org/licenses/>.
+#==============================================================================
+# File: netns_devices2.sh
+#
+# Tests that a separate network namespace can configure and communicate
+# over the devices it sees. Tests are done using ifconfig command which
+# uses ioctl(2) to control devices. There are three test cases:
+# 1,2. communication over paired veth (virtual ethernet) devices
+#      from two different network namespaces (each namespace has
+#      one device)
+#   3. communication over the lo (localhost) device in a separate
+#      network namespace
+#
+
+TCID=netns_devices2
+TST_TOTAL=3
+. test.sh
+IP0=192.168.0.1
+IP1=192.168.0.2
+
+
+cleanup()
+{
+	# removes veth0 device (which also removes paired veth1 device)
+	ip netns exec myns0 ip link delete veth0
+	# removes the network namespace myns
+	ip netns del myns0
+	ip netns del myns1
+}
+
+
+# SETUP
+tst_require_root
+tst_check_cmds ip ifconfig
+TST_CLEANUP=cleanup
+
+# creates a new network namespace "myns0" (man 8 ip-netns)
+ip netns add myns0 || \
+	tst_brkm TBROK "unable to create a new network namespace (myns0)"
+
+# creates a new network namespace "myns1"
+ip netns add myns1 || \
+	tst_brkm TBROK "unable to create a new network namespace (myns1)"
+
+# creates a pair of virtual ethernet devices
+ip netns exec myns0 ip link add veth0 type veth peer name veth1 || \
+	tst_brkm TBROK "unable to create veth pair devices"
+
+# adds device veth1 to myns1 namespace
+ip netns exec myns0 ip link set veth1 netns myns1 || \
+	tst_brkm TBROK "unable to add device veth1 to the network namespace myns1"
+
+
+# setup for veth0 device (which is inside myns0 namespace)
+ip netns exec myns0 ifconfig veth0 $IP0/24 || \
+	tst_brkm TBROK "adding address to veth0 failed"
+ip netns exec myns0 ifconfig veth0 up || \
+	tst_brkm TBROK "enabling veth0 device failed"
+
+# setup for veth1 (which is inside myns1 namespace)
+ip netns exec myns1 ifconfig veth1 $IP1/24 || \
+	tst_brkm TBROK "adding address to veth1 failed"
+ip netns exec myns1 ifconfig veth1 up || \
+	tst_brkm TBROK "enabling veth1 device failed"
+
+
+# TEST CASE #1
+ip netns exec myns0 ping -q -c 2 -I veth0 $IP1 >/dev/null
+ret=$?
+if [ $ret -eq 0 ]; then
+	tst_resm TPASS "ioctl configuration and communication over veth0 device"
+else
+	tst_resm TFAIL "ioctl configuration and communication over veth0 device"
+fi
+
+
+# TEST CASE #2
+ip netns exec myns1 ping -q -c 2 -I veth1 $IP0 >/dev/null
+ret=$?
+if [ $ret -eq 0 ]; then
+	tst_resm TPASS "ioctl configuration and communication over veth1 device"
+else
+	tst_resm TFAIL "ioctl configuration and communication over veth1 device"
+fi
+
+
+# TEST CASE #3
+# enables lo device
+ip netns exec myns0 ifconfig lo up || \
+	tst_brkm TBROK "enabling lo device failed"
+
+ip netns exec myns0 ping -q -c 2 -I lo 127.0.0.1 >/dev/null
+ret=$?
+if [ $ret -eq 0 ]; then
+	tst_resm TPASS "ioctl configuration and communication over lo device"
+else
+	tst_resm TFAIL "ioctl configuration and communication over lo device"
+fi
+
+
+tst_exit
-- 
1.8.3.1


------------------------------------------------------------------------------
Meet PCI DSS 3.0 Compliance Requirements with EventLog Analyzer
Achieve PCI DSS 3.0 Compliant Status with Out-of-the-box PCI DSS Reports
Are you Audit-Ready for PCI DSS 3.0 Compliance? Download White paper
Comply to PCI DSS 3.0 Requirement 10 and 11.5 with EventLog Analyzer
http://pubads.g.doubleclick.net/gampad/clk?id=154622311&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [LTP] [PATCH] containers: added netns/netns_interfaces.c
  2014-08-27 15:32 [LTP] [PATCH] containers: added netns/netns_interfaces.c Matus Marhefka
                   ` (2 preceding siblings ...)
  2014-10-02 14:18 ` [LTP] [PATCH v4] " Matus Marhefka
@ 2014-10-15 12:56 ` Cyril Hrubis
       [not found]   ` <1887162987.52427068.1413453459206.JavaMail.zimbra@redhat.com>
  3 siblings, 1 reply; 8+ messages in thread
From: Cyril Hrubis @ 2014-10-15 12:56 UTC (permalink / raw)
  To: Matus Marhefka; +Cc: ltp-list

Hi!
> +#define _GNU_SOURCE
> +#include <sys/wait.h>
> +#include <stdio.h>
> +#include <stdlib.h>
> +#include <errno.h>
> +#include "usctest.h"
> +#include "test.h"
> +#include "safe_macros.h"
> +#include "netns_helper.h"
> +
> +
> +/* by convention a named network namespace is an object
> + * at /var/run/netns/NAME that can be opened. (man 8 ip-netns) */
> +#define NETNS     "/var/run/netns"
> +char *TCID	= "netns_sendintf";
> +int TST_TOTAL	= 3;
> +int pipefd[2];
> +
> +
> +static void cleanup(void)
> +{
> +	close(pipefd[0]);
> +	close(pipefd[1]);

This should be ported to the checkpoint interface.

> +	/* removes veth0 device (which also removes paired veth1 device) */
> +	if (WEXITSTATUS(system("ip link delete veth0")))
> +		perror("system");
> +	/* removes the network namespace myns */
> +	if (WEXITSTATUS(system("ip netns del myns")))
> +		perror("system");
> +}
> +
> +static void setup(void)
> +{
> +	tst_require_root(NULL);
> +	check_netns();
> +}
> +
> +int child_func(void)
> +{
> +	int status, fd;
> +	char c;
> +
> +	fd = open(NETNS"/myns", O_RDONLY);
> +	if (fd == -1) {
> +		perror("open");
> +		return 1;
> +	}
> +
> +	/* associates child with the namespace referred by fd (myns) */
> +	if (setns(fd, 0) == -1) {
> +		perror("setns");
> +		return 1;
> +	}
> +
> +	/* setup for veth1 device */
> +	if (WEXITSTATUS(system("ip address add 192.168.0.2/24 dev veth1"))) {
> +		perror("system");
> +		return 1;
> +	}
> +	if (WEXITSTATUS(system("ip link set dev veth1 up"))) {
> +		perror("system");
> +		return 1;
> +	}
> +
> +	/* waits for parent to confirm that veth0 device setup is done */
> +	if (read(pipefd[0], &c, 1) == -1) {
> +		perror("read");
> +		return 1;
> +	}
> +
> +	/* ping veth0 address through veth1 device */
> +	if (WEXITSTATUS(
> +	    system("ping -q -c 2 -I veth1 192.168.0.1 &>/dev/null")))
> +		return 1;
> +
> +	return 0;
> +}
> +
> +static void test(void)
> +{
> +	pid_t pid;
> +	int status, ret = 0;
> +
> +	/* creates a pipe for synchronization between parent and child */
> +	SAFE_PIPE(cleanup, pipefd);
> +
> +	/* unshares a network and a mount namespace */
> +	if (unshare(CLONE_NEWNET|CLONE_NEWNS) == -1)
> +		tst_brkm(TBROK | TERRNO, cleanup, "unshare failed");
> +
> +
> +	/* TEST CASE #1 */
> +	/* creates a pair of virtual ethernet devices */
> +	if (WEXITSTATUS(system("ip link add veth0 type veth peer name veth1")))
> +		tst_brkm(TBROK | TERRNO, cleanup, "system failed");
> +	/* creates a new network namespace "myns" (man 8 ip-netns) */
> +	if (WEXITSTATUS(system("ip netns add myns")))
> +		tst_brkm(TBROK | TERRNO, cleanup, "system failed");
> +	/* adds device veth1 to myns namespace */
> +	if (WEXITSTATUS(system("ip link set veth1 netns myns")))
> +		tst_brkm(TBROK | TERRNO, cleanup, "system failed");
> +
> +
> +	pid = fork();
> +	if (pid < 0) {  /* error */
> +		tst_brkm(TBROK | TERRNO, cleanup, "fork failed");
> +	}
> +	if (pid == 0) { /* child */
> +		_exit(child_func());
> +	}
> +
> +	/* parent */

And also freed from trivial comments like these.

-- 
Cyril Hrubis
chrubis@suse.cz

------------------------------------------------------------------------------
Comprehensive Server Monitoring with Site24x7.
Monitor 10 servers for $9/Month.
Get alerted through email, SMS, voice calls or mobile push notifications.
Take corrective actions from your mobile device.
http://p.sf.net/sfu/Zoho
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [LTP] [PATCH] containers: added netns/netns_interfaces.c
       [not found]   ` <1887162987.52427068.1413453459206.JavaMail.zimbra@redhat.com>
@ 2014-10-16 12:23     ` Cyril Hrubis
  0 siblings, 0 replies; 8+ messages in thread
From: Cyril Hrubis @ 2014-10-16 12:23 UTC (permalink / raw)
  To: Matus Marhefka; +Cc: ltp-list

Hi!
> consider this patch discarded as it  was replaced with newer version:
> [PATCH v4] containers: added netns/netns_devices.sh and netns/netns_devices2.sh
> 
> the main reason was use of many system() calls in code what looks rather
> ugly, so I decided to rewrite it into shell script and also extend the test.

Ack.

-- 
Cyril Hrubis
chrubis@suse.cz

------------------------------------------------------------------------------
Comprehensive Server Monitoring with Site24x7.
Monitor 10 servers for $9/Month.
Get alerted through email, SMS, voice calls or mobile push notifications.
Take corrective actions from your mobile device.
http://p.sf.net/sfu/Zoho
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [LTP] [PATCH v4] containers: added netns/netns_devices.sh and netns/netns_devices2.sh
  2014-10-02 14:18 ` [LTP] [PATCH v4] " Matus Marhefka
@ 2014-10-27 14:49   ` Cyril Hrubis
  0 siblings, 0 replies; 8+ messages in thread
From: Cyril Hrubis @ 2014-10-27 14:49 UTC (permalink / raw)
  To: Matus Marhefka; +Cc: ltp-list

Hi!
Pushed, thanks.

-- 
Cyril Hrubis
chrubis@suse.cz

------------------------------------------------------------------------------
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2014-10-27 14:49 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-08-27 15:32 [LTP] [PATCH] containers: added netns/netns_interfaces.c Matus Marhefka
2014-09-01 10:30 ` [LTP] [PATCH v2] containers: added netns/netns_devices.sh and netns/netns_devices2.sh Matus Marhefka
2014-09-04 12:43 ` [LTP] [PATCH v3] " Matus Marhefka
2014-09-24  9:38   ` chrubis
2014-10-02 14:18 ` [LTP] [PATCH v4] " Matus Marhefka
2014-10-27 14:49   ` Cyril Hrubis
2014-10-15 12:56 ` [LTP] [PATCH] containers: added netns/netns_interfaces.c Cyril Hrubis
     [not found]   ` <1887162987.52427068.1413453459206.JavaMail.zimbra@redhat.com>
2014-10-16 12:23     ` Cyril Hrubis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox