This patch consists of the files
crtchild_delchild.c - Basic program to create the namespace and rename veth dev
delchild.sh - This script deletes the child NS
rename_net.sh - Renames the veth device in child NS
Signed-off-by: Veerendra C <[EMAIL PROTECTED]>
Index: containers/netns/crtchild_delchild.c
===================================================================
--- /dev/null
+++ containers/netns/crtchild_delchild.c
@@ -0,0 +1,39 @@
+/*************************************************************************
+* 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 uses the libnetns.c from the lib to create network NS1.
+* In libnetns.c it uses 2 scripts parentns.sh and childns.sh to create this.
+*
+* This testcase creates Network-NS NS1 and renames the net-dev of NS1 to veth4.
+* Then it kills the Network-NS, and checks the contents of parent sysfs.
+* The system should remain stable and also checks sysfs contents of parent NS.
+* It returns PASS on Success else returns FAIL.
+*
+* Scripts used: parentns.sh, childns.sh , delchild.sh rename_net.sh
+*
+* Author: Veerendra C <[EMAIL PROTECTED]>
+* 31/07/2008
+* =========================================================================*/
+
+extern int create_net_namespace(char *, char *);
+
+int main()
+{
+ int status;
+ status = create_net_namespace("delchild.sh", "rename_net.sh");
+ return status;
+}
Index: containers/netns/delchild.sh
===================================================================
--- /dev/null
+++ containers/netns/delchild.sh
@@ -0,0 +1,47 @@
+# This script deletes the child ns, and checks the device
+# returned to the parent ns.
+
+# Reading contents of the sys fs to file in Parent
+# set -x
+
+# The test case ID, the test case count and the total number of test case
+TCID=${TCID:-delchild.sh}
+TST_TOTAL=1
+TST_COUNT=1
+export TCID
+export TST_COUNT
+export TST_TOTAL
+
+ sshpid=`cat /tmp/FIFO3`
+ debug "INFO: ssh pid is $sshpid"
+ newnet=`cat /tmp/FIFO4`
+ debug "INFO: new dev is $newnet"
+
+ if [ $newnet == -1 ] ; then
+ status=-1
+ fi
+
+ ls /sys/class/net > /tmp/sys_b4_child_killed
+ sleep 2
+
+ debug "INFO: Deleting the child NS created.. "
+ debug "INFO: Killing processes $sshpid $pid"
+ kill -9 $sshpid $pid > /dev/null 2>&1
+ sleep 1
+
+ ls /sys/class/net > /tmp/sys_aftr_child_killed
+ diff -q /tmp/sys_b4_child_killed /tmp/sys_aftr_child_killed
+
+ if [ $? == 0 ] ; then
+ debug "INFO: No difference in the contents of sysfs after deleting the child"
+ else
+ grep -qw $newnet /tmp/sys_aftr_child_killed
+ if [ $? == 0 ]; then
+ debug "INFO: Device $newnet is moved to ParentNS"
+ else
+ debug "INFO: Device $newnet is moved under diff name in ParentNS"
+ fi
+ fi
+ # Cleanup
+ rm -f /tmp/sys_b4_child_killed /tmp/sys_aftr_child_killed /tmp/FIFO6 > /dev/null
+
Index: containers/netns/rename_net.sh
===================================================================
--- /dev/null
+++ containers/netns/rename_net.sh
@@ -0,0 +1,42 @@
+# This sciprt Renames the net device of the child ns to $NewNetDev.
+
+# set -x
+TCID=${TCID:-rename_net.sh}
+TST_TOTAL=1
+TST_COUNT=1
+export TCID
+export TST_COUNT
+export TST_TOTAL
+
+ # Find the free dev name
+ for i in `seq 1 100`
+ do
+ newdev=veth$i
+ ip link show | grep -qw $newdev
+ # On finding free device break.
+ if [ $? != 0 ] ; then
+ break
+ fi
+ done
+
+ ifconfig $vnet1 down
+ ip link set $vnet1 name $newdev
+ ifconfig $newdev $IP2/24 up > /dev/null 2>&1
+
+ if [ $? == 0 ] ; then
+ tst_resm TINFO "Successfully Renamed device to $newdev"
+ if [ DEBUG == 1 ]; then
+ ifconfig
+ fi
+ else
+ tst_resm TFAIL "Renaming of device failed: FAIL"
+ status=-1
+ fi
+
+ if [ $status == 0 ] ; then
+ echo $sshpid > /tmp/FIFO3
+ echo $newdev > /tmp/FIFO4
+ else
+ echo FAIL > /tmp/FIFO3
+ echo -1 > /tmp/FIFO4
+ fi
-------------------------------------------------------------------------
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