• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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@redhat.com>
18#
19#==============================================================================
20#
21# Tests that a separate network namespace cannot affect sysfs contents
22# of the main namespace.
23#==============================================================================
24
25TCID="netns_sysfs"
26TST_TOTAL=3
27NS_TYPE="net,mnt"
28DUMMYDEV_HOST="dummy_test0"
29DUMMYDEV="dummy_test1"
30. test.sh
31
32if tst_kvcmp -lt "2.6.35"; then
33	tst_brkm TCONF "sysfs is not mount namespace aware for kernels older than 2.6.35"
34fi
35
36setns_check
37if [ $? -eq 32 ]; then
38	tst_brkm TCONF "setns not supported"
39fi
40
41cleanup()
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
49tst_tmpdir
50NS_HANDLE=$(ns_create $NS_TYPE)
51if [ $? -eq 1 ]; then
52	tst_resm TINFO "$NS_HANDLE"
53	tst_brkm TBROK "unable to create a new network namespace"
54fi
55TST_CLEANUP=cleanup
56
57ip link add $DUMMYDEV_HOST type dummy || \
58	tst_brkm TBROK "failed to add a new (host) dummy device"
59
60ns_exec $NS_HANDLE $NS_TYPE mount --make-rprivate /sys
61ns_exec $NS_HANDLE $NS_TYPE ip link add $DUMMYDEV type dummy || \
62	tst_brkm TBROK "failed to add a new dummy device"
63ns_exec $NS_HANDLE $NS_TYPE mount -t sysfs none /sys 2>/dev/null
64
65
66# TEST CASE #1
67ns_exec $NS_HANDLE $NS_TYPE test -e /sys/class/net/$DUMMYDEV
68if [ $? -eq 0 ]; then
69	tst_resm TPASS "sysfs in new namespace has $DUMMYDEV interface"
70else
71	tst_resm TFAIL "sysfs in new namespace does not have $DUMMYDEV interface"
72fi
73
74
75# TEST CASE #2
76ns_exec $NS_HANDLE $NS_TYPE test -e /sys/class/net/$DUMMYDEV_HOST
77if [ $? -ne 0 ]; then
78	tst_resm TPASS "sysfs in new namespace does not have $DUMMYDEV_HOST interface"
79else
80	tst_resm TFAIL "sysfs in new namespace contains $DUMMYDEV_HOST interface"
81fi
82
83
84# TEST CASE #3
85test -e /sys/class/net/$DUMMYDEV
86if [ $? -ne 0 ]; then
87	tst_resm TPASS "sysfs not affected by a separate namespace"
88else
89	tst_resm TFAIL "sysfs affected by a separate namespace"
90fi
91
92
93tst_exit
94