This patch consists of the files
child_1.sh - Creates the child NS1 and verifies the connection to child2 NS
child_2.sh - Creates the child NS2 and verifies the connection to child1 NS
parent_1.sh - Creates the parent NS1
parent_1.sh - Creates the parent NS2
two_children_ns.c - Basic file to create the 2 children NS
Signed-off-by: Veerendra C <[EMAIL PROTECTED]>
Index: containers/netns/child_1.sh
===================================================================
--- /dev/null
+++ containers/netns/child_1.sh
@@ -0,0 +1,60 @@
+#!/bin/bash
+# This script is trying to ping the Child2 from Child1
+# The test case ID, the test case count and the total number of test case
+TCID=${TCID:-child_1.sh}
+TST_TOTAL=1
+TST_COUNT=1
+export TCID
+export TST_COUNT
+export TST_TOTAL
+
+source initialize.sh
+
+ # Writing child PID number into /tmp/FIFO
+ echo $$ > /tmp/FIFO2
+
+ # Reading device name from parent
+ vnet1=`cat /tmp/FIFO1`;
+ debug "INFO: CHILD1: Network dev name received $vnet1";
+
+ # By now network is working
+ ifconfig $vnet1 $IP2$mask up > /dev/null 2>&1
+ ifconfig lo up
+
+ # Creating ssh session
+ /usr/sbin/sshd -p $PORT
+ if [ $? ]; then
+ debug "INFO: Started the sshd in CHILD1"
+ sshpid1=`ps -ef | grep "sshd -p $PORT" | awk '{ print $2 ; exit 0} ' `
+
+ ping -qc 2 $IP1 > /dev/null
+ if [ $? -ne 0 ] ; then
+ tst_resm TFAIL "FAIL: Unable to ping the Parent1 from Child1"
+ status=-1
+ fi
+ else
+ tst_resm TFAIL "FAIL: Unable to start sshd in child1"
+ status=-1
+ fi
+
+ # Waiting for CHILD2
+ ret=`cat /tmp/FIFO5`
+
+ if [ $ret -eq 0 ]; then
+ # Pinging CHILD2 from CHILD1
+ debug "INFO: Trying for pinging CHILD2..."
+ ping -qc 2 $IP4 > /dev/null
+ if [ $? == 0 ];
+ then
+ tst_resm TINFO "PASS: Child2 is pinging from CHILD1 !"
+ else
+ tst_resm TFAIL "FAIL: Unable to Ping Child2 from CHILD1 !"
+ status=-1
+ fi
+ else
+ tst_resm TFAIL "CHILD2 is unable to reach CHILD1"
+ status=-1
+ fi
+ cleanup $sshpid1 $vnet1
+exit $status
+ debug "INFO: ********End of Child-1 $0********"
Index: containers/netns/child_2.sh
===================================================================
--- /dev/null
+++ containers/netns/child_2.sh
@@ -0,0 +1,55 @@
+#!/bin/bash
+# This script is pinging the child NS.
+TCID=${TCID:-child_2.sh}
+TST_TOTAL=1
+TST_COUNT=1
+export TCID
+export TST_COUNT
+export TST_TOTAL
+source initialize.sh
+status=0
+
+ # Writing child PID number into /tmp/FIFO4
+ echo $$ > /tmp/FIFO4
+
+ # Reading device name from parent
+ vnet2=`cat /tmp/FIFO3`;
+ debug "INFO: CHILD2: Network dev name received $vnet2";
+
+ # By now networking is working
+ ifconfig $vnet2 $IP4$mask up 2> /dev/null
+ ifconfig lo up
+
+ # Creating ssh session
+ /usr/sbin/sshd -p $PORT2
+ if [ $? ]; then
+ debug "INFO: Started the sshd in CHILD2"
+ sshpid2=`ps -ef | grep "sshd -p $PORT2" | awk '{ print $2 ; exit 0} ' `
+
+ ping -qc 2 $IP3 > /dev/null
+ if [ $? -ne 0 ] ; then
+ tst_resm TFAIL "FAIL: Unable to ping Parent2 from Child2"
+ status=-1
+ fi
+ else
+ tst_resm TFAIL "FAIL: Unable to start sshd in child1"
+ status=-1
+ fi
+ # Pinging CHILD1 from CHILD2
+ debug "INFO: Trying for pinging CHILD1..."
+
+ ping -qc 2 $IP2 > /dev/null
+ if [ $? -eq 0 ]; then
+ tst_resm TINFO "PASS: CHILD1 is pinging from CHILD2 ! "
+ # Using /tmp/FIFO5 to synchronize with CHILD1
+ echo 0 > /tmp/FIFO5
+ sleep 2
+ else
+ tst_resm TFAIL "FAIL: Unable to ping Child1NS from Child2NS !"
+ echo 1 > /tmp/FIFO5
+ status=-1
+ fi
+
+ cleanup $sshpid2 $vnet2
+ exit $status
+ debug "INFO: ********End of Child-2 $0********"
Index: containers/netns/parent_1.sh
===================================================================
--- /dev/null
+++ containers/netns/parent_1.sh
@@ -0,0 +1,35 @@
+#!/bin/bash
+# This testcase creates the net devices
+
+# The test case ID, the test case count and the total number of test case
+TCID=${TCID:-parent_1.sh}
+TST_TOTAL=1
+TST_COUNT=1
+export TCID
+export TST_COUNT
+export TST_TOTAL
+
+ source initialize.sh
+ echo 1 > /proc/sys/net/ipv4/ip_forward
+ echo 1 > /proc/sys/net/ipv4/conf/eth0/proxy_arp
+ create_veth
+ vnet0=$dev0
+ vnet1=$dev1
+ if [[ -z $vnet0 || -z $vnet1 ]] ; then
+ tst_resm TFAIL "Error: unable to create veth pair in $0"
+ exit -1
+ else
+ debug "INFO: vnet0 = $vnet0 , vnet1 = $vnet1"
+ fi
+
+ ifconfig $vnet0 $IP1$mask up > /dev/null 2>&1
+ route add -host $IP2 dev $vnet0
+ echo 1 > /proc/sys/net/ipv4/conf/$vnet0/proxy_arp
+
+ pid=`cat /tmp/FIFO2`
+ debug "INFO: The pid of CHILD1 is $pid"
+ ip link set $vnet1 netns $pid
+ echo $vnet1 > /tmp/FIFO1
+
+ debug "INFO: PARENT_1: End of $0"
+ exit $status
Index: containers/netns/parent_2.sh
===================================================================
--- /dev/null
+++ containers/netns/parent_2.sh
@@ -0,0 +1,32 @@
+#!/bin/bash
+
+# The test case ID, the test case count and the total number of test case
+TCID=${TCID:-parent_2.sh}
+TST_TOTAL=1
+TST_COUNT=1
+export TCID
+export TST_COUNT
+export TST_TOTAL
+source initialize.sh
+
+ create_veth
+ vnet2=$dev0
+ vnet3=$dev1
+
+ if [[ -z $vnet2 || -z $vnet3 ]] ; then
+ tst_resm TFAIL "Error: unable to create veth pair in $0"
+ exit -1
+ else
+ debug "INFO: vnet2 = $vnet2 , vnet3 = $vnet3"
+ fi
+ ifconfig $vnet2 $IP3$mask up > /dev/null 2>&1
+ route add -host $IP4 dev $vnet2
+ echo 1 > /proc/sys/net/ipv4/conf/$vnet2/proxy_arp
+
+ pid=`cat /tmp/FIFO4`
+ debug "INFO: The pid of CHILD2 is $pid"
+ ip link set $vnet3 netns $pid
+ echo $vnet3 > /tmp/FIFO3
+
+ debug "INFO: PARENT-2: End of $0"
+ exit $status
Index: containers/netns/two_children_ns.c
===================================================================
--- /dev/null
+++ containers/netns/two_children_ns.c
@@ -0,0 +1,140 @@
+/*************************************************************************
+* Copyright (c) International Business Machines Corp., 2008
+* 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
+* the Free Software Foundation; either version 2 of the License, or
+* (at your option) any later version.
+*
+* 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, write to the Free Software
+* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*
+***************************************************************************/
+
+/*******************************************************************************
+* This testcase creates 2 network Namespace NS1 & NS2, oin the parent NS.
+* It creates veth device pair for NS1 and NS2
+* It checks the network connection between NS1 and NS2 .
+* On Success returns PASS else returns FAIL.
+*
+* scripts used: parent_1.sh parent_2.sh child_1.sh child_2.sh
+*
+* Authors: Veerendra C <[EMAIL PROTECTED]> ,
+ Munipradeep <[EMAIL PROTECTED]>
+* 31/07/2008
+*******************************************************************************/
+
+#include <sys/utsname.h>
+#include <sched.h>
+#include <stdio.h>
+#include "../libclone/libclone.h"
+#include "test.h"
+
+#include <stdlib.h>
+#include <sched.h>
+#include <sys/syscall.h>
+#include <unistd.h>
+#include <signal.h>
+#include <string.h>
+#include <errno.h>
+#include <libgen.h>
+#include <fcntl.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+
+#ifdef NO_LTP
+#define TFAIL "FAILURE: "
+#define TPASS "PASS: "
+#define TINFO "INFO: "
+#define TWARN "WARN: "
+#define tst_resm(x, format, arg...) printf("%s:" format, x, ## arg)
+#define tst_exit() exit(1)
+#endif
+
+char *TCID = "netns_2children";
+int TST_TOTAL=1;
+
+/* Creating Network Namespace */
+int crtchild(char *s)
+{
+ char *cmd[] = { "/bin/bash", s, (char *)0 };
+
+ execve("/bin/bash", cmd, __environ);
+ tst_resm(TINFO, "The code never reaches here on success\n");
+ perror("execve");
+ return 1;
+}
+
+int main()
+{
+ int ret, pid[2], status, i, len;
+ long long flags = 0;
+ char *child[2] , *par[2];
+ char *ltproot;
+
+ flags |= CLONE_NEWNS;
+ flags |= CLONE_NEWNET;
+
+ /* Checking for Kernel Version */
+ if (tst_kvercmp(2,6,19) < 0)
+ return 1;
+
+ ltproot = getenv("LTPROOT");
+ if (! ltproot) {
+ tst_resm(TINFO, "LTPROOT env variable is not set\n");
+ tst_resm(TINFO, "Please set LTPROOT and re-run the test.. Thankyou\n");
+ return -1;
+ }
+
+ len = strlen(ltproot);
+ child[0] = malloc (len + 50);
+ child[1] = malloc (len + 50);
+ par[0] = malloc (len + 50);
+ par[1] = malloc (len + 50);
+
+ sprintf(child[0], "%s/testcases/kernel/containers/netns/child_1.sh" , ltproot);
+ sprintf(child[1], "%s/testcases/kernel/containers/netns/child_2.sh" , ltproot);
+ sprintf(par[0], "%s/testcases/kernel/containers/netns/parent_1.sh" , ltproot);
+ sprintf(par[1], "%s/testcases/kernel/containers/netns/parent_2.sh" , ltproot);
+
+ /* Loop for creating two child Network Namespaces */
+ for(i=0;i<2;i++) {
+
+ if ((pid[i] = fork()) == 0) {
+ // Child1 and Child2 based on the iteration.
+
+ ret = unshare(flags);
+ if (ret < 0) {
+ perror("Unshare");
+ return ret;
+ }
+ return crtchild(child[i]);
+ }
+ else{
+ //Parent
+
+ ret = system(par[i]);
+ status = WEXITSTATUS(ret);
+ if (status != 0) {
+ tst_resm(TFAIL, "Error while running the scripts\n");
+ exit(status);
+ }
+ }
+ } //End of FOR Loop
+
+ /* Parent waiting for two children to quit */
+ for(i=0;i<2;i++) {
+ ret = waitpid(pid[i], &status,__WALL);
+
+ if (status != 0 || ret < 0){
+ tst_resm(TFAIL,"waitpid() returns %d, errno %d\n", ret, status);
+ fflush(stdout);
+ exit(status);
+ }
+ }
+ exit(0);
+}
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list