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 setns_check 33 if [ $? -eq 32 ]; then 34 tst_brkm TCONF "setns not supported" 35 fi 36 37 cleanup() 38 { 39 tst_rmdir 40 ip link del $DUMMYDEV_HOST 2>/dev/null 41 ip link del $DUMMYDEV 2>/dev/null 42 kill -9 $NS_HANDLE 2>/dev/null 43 } 44 45 tst_tmpdir 46 NS_HANDLE=$(ns_create $NS_TYPE) 47 if [ $? -eq 1 ]; then 48 tst_resm TINFO "$NS_HANDLE" 49 tst_brkm TBROK "unable to create a new network namespace" 50 fi 51 TST_CLEANUP=cleanup 52 53 ip link add $DUMMYDEV_HOST type dummy || \ 54 tst_brkm TBROK "failed to add a new (host) dummy device" 55 56 ns_exec $NS_HANDLE $NS_TYPE mount --make-rprivate /sys 57 ns_exec $NS_HANDLE $NS_TYPE ip link add $DUMMYDEV type dummy || \ 58 tst_brkm TBROK "failed to add a new dummy device" 59 ns_exec $NS_HANDLE $NS_TYPE mount -t sysfs none /sys 2>/dev/null 60 61 62 # TEST CASE #1 63 ns_exec $NS_HANDLE $NS_TYPE test -e /sys/class/net/$DUMMYDEV 64 if [ $? -eq 0 ]; then 65 tst_resm TPASS "sysfs in new namespace has $DUMMYDEV interface" 66 else 67 tst_resm TFAIL "sysfs in new namespace does not have $DUMMYDEV interface" 68 fi 69 70 71 # TEST CASE #2 72 ns_exec $NS_HANDLE $NS_TYPE test -e /sys/class/net/$DUMMYDEV_HOST 73 if [ $? -ne 0 ]; then 74 tst_resm TPASS "sysfs in new namespace does not have $DUMMYDEV_HOST interface" 75 else 76 tst_resm TFAIL "sysfs in new namespace contains $DUMMYDEV_HOST interface" 77 fi 78 79 80 # TEST CASE #3 81 test -e /sys/class/net/$DUMMYDEV 82 if [ $? -ne 0 ]; then 83 tst_resm TPASS "sysfs not affected by a separate namespace" 84 else 85 tst_resm TFAIL "sysfs affected by a separate namespace" 86 fi 87 88 89 tst_exit 90