1 #!/bin/sh 2 #============================================================================== 3 # Copyright (c) 2015 Red Hat, Inc. 4 # 5 # This program is free software: you can redistribute it and/or modify 6 # it under the terms of version 2 the GNU General Public License as 7 # published by the Free Software Foundation. 8 # 9 # This program is distributed in the hope that it will be useful, 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 # GNU General Public License for more details. 13 # 14 # You should have received a copy of the GNU General Public License 15 # along with this program. If not, see <http://www.gnu.org/licenses/>. 16 # 17 # Written by Matus Marhefka <mmarhefk (at] redhat.com> 18 # 19 #============================================================================== 20 # 21 # Tests that a separate network namespace cannot affect sysfs contents 22 # of the main namespace. 23 #============================================================================== 24 25 TCID="netns_sysfs" 26 TST_TOTAL=3 27 NS_TYPE="net,mnt" 28 DUMMYDEV_HOST="dummy_test0" 29 DUMMYDEV="dummy_test1" 30 . test.sh 31 32 if tst_kvcmp -lt "2.6.35"; then 33 tst_brkm TCONF "sysfs is not mount namespace aware for kernels older than 2.6.35" 34 fi 35 36 setns_check 37 if [ $? -eq 32 ]; then 38 tst_brkm TCONF "setns not supported" 39 fi 40 41 cleanup() 42 { 43 tst_rmdir 44 ip link del $DUMMYDEV_HOST 2>/dev/null 45 ip link del $DUMMYDEV 2>/dev/null 46 kill -9 $NS_HANDLE 2>/dev/null 47 } 48 49 tst_tmpdir 50 NS_HANDLE=$(ns_create $NS_TYPE) 51 if [ $? -eq 1 ]; then 52 tst_resm TINFO "$NS_HANDLE" 53 tst_brkm TBROK "unable to create a new network namespace" 54 fi 55 TST_CLEANUP=cleanup 56 57 ip link add $DUMMYDEV_HOST type dummy || \ 58 tst_brkm TBROK "failed to add a new (host) dummy device" 59 60 ns_exec $NS_HANDLE $NS_TYPE mount --make-rprivate /sys 61 ns_exec $NS_HANDLE $NS_TYPE ip link add $DUMMYDEV type dummy || \ 62 tst_brkm TBROK "failed to add a new dummy device" 63 ns_exec $NS_HANDLE $NS_TYPE mount -t sysfs none /sys 2>/dev/null 64 65 66 # TEST CASE #1 67 ns_exec $NS_HANDLE $NS_TYPE test -e /sys/class/net/$DUMMYDEV 68 if [ $? -eq 0 ]; then 69 tst_resm TPASS "sysfs in new namespace has $DUMMYDEV interface" 70 else 71 tst_resm TFAIL "sysfs in new namespace does not have $DUMMYDEV interface" 72 fi 73 74 75 # TEST CASE #2 76 ns_exec $NS_HANDLE $NS_TYPE test -e /sys/class/net/$DUMMYDEV_HOST 77 if [ $? -ne 0 ]; then 78 tst_resm TPASS "sysfs in new namespace does not have $DUMMYDEV_HOST interface" 79 else 80 tst_resm TFAIL "sysfs in new namespace contains $DUMMYDEV_HOST interface" 81 fi 82 83 84 # TEST CASE #3 85 test -e /sys/class/net/$DUMMYDEV 86 if [ $? -ne 0 ]; then 87 tst_resm TPASS "sysfs not affected by a separate namespace" 88 else 89 tst_resm TFAIL "sysfs affected by a separate namespace" 90 fi 91 92 93 tst_exit 94