netns-sysctl.sh 910 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #!/bin/bash -e
  2. # SPDX-License-Identifier: GPL-2.0
  3. #
  4. # This test checks that the network buffer sysctls are present
  5. # in a network namespaces, and that they are readonly.
  6. source lib.sh
  7. cleanup() {
  8. cleanup_ns $test_ns
  9. }
  10. trap cleanup EXIT
  11. fail() {
  12. echo "ERROR: $*" >&2
  13. exit 1
  14. }
  15. setup_ns test_ns
  16. for sc in {r,w}mem_{default,max}; do
  17. # check that this is writable in a netns
  18. [ -w "/proc/sys/net/core/$sc" ] ||
  19. fail "$sc isn't writable in the init netns!"
  20. # change the value in the host netns
  21. sysctl -qw "net.core.$sc=300000" ||
  22. fail "Can't write $sc in init netns!"
  23. # check that the value is read from the init netns
  24. [ "$(ip netns exec $test_ns sysctl -n "net.core.$sc")" -eq 300000 ] ||
  25. fail "Value for $sc mismatch!"
  26. # check that this isn't writable in a netns
  27. ip netns exec $test_ns [ -w "/proc/sys/net/core/$sc" ] &&
  28. fail "$sc is writable in a netns!"
  29. done
  30. echo 'Test passed OK'