ip_defrag.sh 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #!/bin/sh
  2. # SPDX-License-Identifier: GPL-2.0
  3. #
  4. # Run a couple of IP defragmentation tests.
  5. set +x
  6. set -e
  7. modprobe -q nf_defrag_ipv6
  8. readonly NETNS="ns-$(mktemp -u XXXXXX)"
  9. setup() {
  10. ip netns add "${NETNS}"
  11. ip -netns "${NETNS}" link set lo up
  12. ip netns exec "${NETNS}" sysctl -w net.ipv4.ipfrag_high_thresh=9000000 >/dev/null 2>&1
  13. ip netns exec "${NETNS}" sysctl -w net.ipv4.ipfrag_low_thresh=7000000 >/dev/null 2>&1
  14. ip netns exec "${NETNS}" sysctl -w net.ipv4.ipfrag_time=1 >/dev/null 2>&1
  15. ip netns exec "${NETNS}" sysctl -w net.ipv6.ip6frag_high_thresh=9000000 >/dev/null 2>&1
  16. ip netns exec "${NETNS}" sysctl -w net.ipv6.ip6frag_low_thresh=7000000 >/dev/null 2>&1
  17. ip netns exec "${NETNS}" sysctl -w net.ipv6.ip6frag_time=1 >/dev/null 2>&1
  18. ip netns exec "${NETNS}" sysctl -w net.netfilter.nf_conntrack_frag6_high_thresh=9000000 >/dev/null 2>&1
  19. ip netns exec "${NETNS}" sysctl -w net.netfilter.nf_conntrack_frag6_low_thresh=7000000 >/dev/null 2>&1
  20. ip netns exec "${NETNS}" sysctl -w net.netfilter.nf_conntrack_frag6_timeout=1 >/dev/null 2>&1
  21. # DST cache can get full with a lot of frags, with GC not keeping up with the test.
  22. ip netns exec "${NETNS}" sysctl -w net.ipv6.route.max_size=65536 >/dev/null 2>&1
  23. }
  24. cleanup() {
  25. ip netns del "${NETNS}"
  26. }
  27. trap cleanup EXIT
  28. setup
  29. echo "ipv4 defrag"
  30. ip netns exec "${NETNS}" ./ip_defrag -4
  31. echo "ipv4 defrag with overlaps"
  32. ip netns exec "${NETNS}" ./ip_defrag -4o
  33. echo "ipv6 defrag"
  34. ip netns exec "${NETNS}" ./ip_defrag -6
  35. echo "ipv6 defrag with overlaps"
  36. ip netns exec "${NETNS}" ./ip_defrag -6o
  37. # insert an nf_conntrack rule so that the codepath in nf_conntrack_reasm.c taken
  38. ip netns exec "${NETNS}" ip6tables -A INPUT -m conntrack --ctstate INVALID -j ACCEPT
  39. echo "ipv6 nf_conntrack defrag"
  40. ip netns exec "${NETNS}" ./ip_defrag -6
  41. echo "ipv6 nf_conntrack defrag with overlaps"
  42. # netfilter will drop some invalid packets, so we run the test in
  43. # permissive mode: i.e. pass the test if the packet is correctly assembled
  44. # even if we sent an overlap
  45. ip netns exec "${NETNS}" ./ip_defrag -6op
  46. echo "all tests done"