File: netns-sysctl.sh

package info (click to toggle)
linux 6.17.9-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,734,892 kB
  • sloc: ansic: 26,684,085; asm: 271,195; sh: 147,401; python: 75,980; makefile: 57,306; perl: 36,943; xml: 19,562; cpp: 5,899; yacc: 4,909; lex: 2,943; awk: 1,556; sed: 29; ruby: 25
file content (40 lines) | stat: -rwxr-xr-x 910 bytes parent folder | download | duplicates (18)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/bin/bash -e
# SPDX-License-Identifier: GPL-2.0
#
# This test checks that the network buffer sysctls are present
# in a network namespaces, and that they are readonly.

source lib.sh

cleanup() {
    cleanup_ns $test_ns
}

trap cleanup EXIT

fail() {
	echo "ERROR: $*" >&2
	exit 1
}

setup_ns test_ns

for sc in {r,w}mem_{default,max}; do
	# check that this is writable in a netns
	[ -w "/proc/sys/net/core/$sc" ] ||
		fail "$sc isn't writable in the init netns!"

	# change the value in the host netns
	sysctl -qw "net.core.$sc=300000" ||
		fail "Can't write $sc in init netns!"

	# check that the value is read from the init netns
	[ "$(ip netns exec $test_ns sysctl -n "net.core.$sc")" -eq 300000 ] ||
		fail "Value for $sc mismatch!"

	# check that this isn't writable in a netns
	ip netns exec $test_ns [ -w "/proc/sys/net/core/$sc" ] &&
		fail "$sc is writable in a netns!"
done

echo 'Test passed OK'