]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
selftests: net: tests net.core.{r,w}mem_{default,max} sysctls in a netns
authorMatteo Croce <teknoraver@meta.com>
Thu, 30 May 2024 23:27:22 +0000 (01:27 +0200)
committerJakub Kicinski <kuba@kernel.org>
Sat, 1 Jun 2024 23:03:21 +0000 (16:03 -0700)
Add a selftest which checks that the sysctl is present in a netns,
that the value is read from the init one, and that it's readonly.

Signed-off-by: Matteo Croce <teknoraver@meta.com>
Link: https://lore.kernel.org/r/20240530232722.45255-3-technoboy85@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
tools/testing/selftests/net/Makefile
tools/testing/selftests/net/netns-sysctl.sh [new file with mode: 0755]

index bd01e4a0be2c29663097f149cc359a892793611e..6da63d1831c11c36dfec93dd5027833a5067c3cb 100644 (file)
@@ -53,6 +53,7 @@ TEST_PROGS += bind_bhash.sh
 TEST_PROGS += ip_local_port_range.sh
 TEST_PROGS += rps_default_mask.sh
 TEST_PROGS += big_tcp.sh
+TEST_PROGS += netns-sysctl.sh
 TEST_PROGS_EXTENDED := toeplitz_client.sh toeplitz.sh
 TEST_GEN_FILES =  socket nettest
 TEST_GEN_FILES += psock_fanout psock_tpacket msg_zerocopy reuseport_addr_any
diff --git a/tools/testing/selftests/net/netns-sysctl.sh b/tools/testing/selftests/net/netns-sysctl.sh
new file mode 100755 (executable)
index 0000000..45c34a3
--- /dev/null
@@ -0,0 +1,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'