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. Thanks, Matus Marhefka ----- Original Message ----- From: "Cyril Hrubis" <chru...@suse.cz> To: "Matus Marhefka" <mmarh...@redhat.com> Cc: ltp-list@lists.sourceforge.net Sent: Wednesday, October 15, 2014 2:56:01 PM Subject: Re: [LTP] [PATCH] containers: added netns/netns_interfaces.c 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 chru...@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