route_hint.sh 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #!/bin/bash
  2. # SPDX-License-Identifier: GPL-2.0
  3. # This test ensures directed broadcast routes use dst hint mechanism
  4. source lib.sh
  5. CLIENT_IP4="192.168.0.1"
  6. SERVER_IP4="192.168.0.2"
  7. BROADCAST_ADDRESS="192.168.0.255"
  8. setup() {
  9. setup_ns CLIENT_NS SERVER_NS
  10. ip -net "${SERVER_NS}" link add link1 type veth peer name link0 netns "${CLIENT_NS}"
  11. ip -net "${CLIENT_NS}" link set link0 up
  12. ip -net "${CLIENT_NS}" addr add "${CLIENT_IP4}/24" dev link0
  13. ip -net "${SERVER_NS}" link set link1 up
  14. ip -net "${SERVER_NS}" addr add "${SERVER_IP4}/24" dev link1
  15. ip netns exec "${CLIENT_NS}" ethtool -K link0 tcp-segmentation-offload off
  16. ip netns exec "${SERVER_NS}" sh -c "echo 500000000 > /sys/class/net/link1/gro_flush_timeout"
  17. ip netns exec "${SERVER_NS}" sh -c "echo 1 > /sys/class/net/link1/napi_defer_hard_irqs"
  18. ip netns exec "${SERVER_NS}" ethtool -K link1 generic-receive-offload on
  19. }
  20. cleanup() {
  21. ip -net "${SERVER_NS}" link del link1
  22. cleanup_ns "${CLIENT_NS}" "${SERVER_NS}"
  23. }
  24. directed_bcast_hint_test()
  25. {
  26. local rc=0
  27. echo "Testing for directed broadcast route hint"
  28. orig_in_brd=$(ip netns exec "${SERVER_NS}" lnstat -j -i1 -c1 | jq '.in_brd')
  29. ip netns exec "${CLIENT_NS}" mausezahn link0 -a own -b bcast -A "${CLIENT_IP4}" \
  30. -B "${BROADCAST_ADDRESS}" -c1 -t tcp "sp=1-100,dp=1234,s=1,a=0" -p 5 -q
  31. sleep 1
  32. new_in_brd=$(ip netns exec "${SERVER_NS}" lnstat -j -i1 -c1 | jq '.in_brd')
  33. res=$(echo "${new_in_brd} - ${orig_in_brd}" | bc)
  34. if [ "${res}" -lt 100 ]; then
  35. echo "[ OK ]"
  36. rc="${ksft_pass}"
  37. else
  38. echo "[FAIL] expected in_brd to be under 100, got ${res}"
  39. rc="${ksft_fail}"
  40. fi
  41. return "${rc}"
  42. }
  43. if [ ! -x "$(command -v mausezahn)" ]; then
  44. echo "SKIP: Could not run test without mausezahn tool"
  45. exit "${ksft_skip}"
  46. fi
  47. if [ ! -x "$(command -v jq)" ]; then
  48. echo "SKIP: Could not run test without jq tool"
  49. exit "${ksft_skip}"
  50. fi
  51. if [ ! -x "$(command -v bc)" ]; then
  52. echo "SKIP: Could not run test without bc tool"
  53. exit "${ksft_skip}"
  54. fi
  55. trap cleanup EXIT
  56. setup
  57. directed_bcast_hint_test
  58. exit $?