smoke-self.sh 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. #!/bin/bash
  2. # A host must be able to reach its own overlay address. Where the kernel sends
  3. # that traffic through the tun rather than over loopback, nebula sees it and
  4. # hands it straight back (immediatelyForwardToSelf), and whether the kernel
  5. # accepts what comes back is only answerable against a real kernel. Runs one
  6. # nebula on this machine as root and aims every probe at its own address.
  7. set -e -x
  8. set -o pipefail
  9. V4=192.0.2.1
  10. V6=2001:db8::1
  11. case "$(uname -s)" in
  12. Darwin) TUN_DEV=utun ;;
  13. *) TUN_DEV=tun0 ;;
  14. esac
  15. ROOT="$(cd ../../.. && pwd)"
  16. rm -rf build/self
  17. mkdir -p build/self
  18. cd build/self
  19. cleanup() {
  20. echo
  21. echo " *** cleanup"
  22. echo
  23. set +e
  24. if [ -n "$NEBULA_PID" ]
  25. then
  26. sudo kill "$NEBULA_PID"
  27. fi
  28. { kill $(jobs -p); wait; } 2>/dev/null
  29. sed 's/^/ [self] /' nebula.log
  30. }
  31. trap cleanup EXIT
  32. # perl is on every platform this runs on; timeout(1) is not.
  33. alarm() {
  34. perl -e 'alarm shift; exec @ARGV' "$@"
  35. }
  36. RESULTS=""
  37. FAILED=""
  38. probe() {
  39. local name="$1"
  40. shift
  41. if "$@"
  42. then
  43. RESULTS="$RESULTS $name=ok"
  44. else
  45. RESULTS="$RESULTS $name=FAIL"
  46. FAILED="$FAILED $name"
  47. fi
  48. }
  49. # Send one datagram, then wait for the listener to have written it out.
  50. udp_probe() {
  51. echo self | alarm 5 nc -u -w1 "$1" 3000 || true
  52. set +x
  53. for _ in $(seq 1 20)
  54. do
  55. if grep -q self "$2"
  56. then
  57. set -x
  58. return 0
  59. fi
  60. sleep 0.25
  61. done
  62. set -x
  63. return 1
  64. }
  65. "$ROOT/nebula-cert" ca -name "Smoke Test"
  66. "$ROOT/nebula-cert" sign -name self -networks "$V4/24,$V6/64"
  67. HOST=self AM_LIGHTHOUSE=true TUN_DEV="$TUN_DEV" ../../genconfig.sh >self.yml
  68. "$ROOT/nebula" -config self.yml -test
  69. sudo -v
  70. sudo "$ROOT/nebula" -config self.yml >nebula.log 2>&1 &
  71. NEBULA_PID=$!
  72. for _ in $(seq 1 40)
  73. do
  74. ifconfig | grep "inet6 $V6 " >/dev/null && break
  75. sleep 0.25
  76. done
  77. ifconfig | grep "inet $V4 "
  78. ifconfig | grep "inet6 $V6 "
  79. nc -l "$V4" 2000 >/dev/null &
  80. nc -l "$V6" 2000 >/dev/null &
  81. nc -u -l "$V4" 3000 >udp4.txt &
  82. nc -u -l "$V6" 3000 >udp6.txt &
  83. sleep 1
  84. set +x
  85. echo
  86. echo " *** Testing self traffic from $V4"
  87. echo
  88. set -x
  89. probe icmp4 alarm 5 ping -c1 "$V4"
  90. probe tcp4 alarm 5 nc -z "$V4" 2000
  91. probe udp4 udp_probe "$V4" udp4.txt
  92. set +x
  93. echo
  94. echo " *** Testing self traffic from $V6"
  95. echo
  96. set -x
  97. probe icmp6 alarm 5 ping6 -c1 "$V6"
  98. probe tcp6 alarm 5 nc -z "$V6" 2000
  99. probe udp6 udp_probe "$V6" udp6.txt
  100. set +x
  101. echo
  102. echo " *** self traffic:$RESULTS"
  103. echo
  104. if [ -n "$FAILED" ]
  105. then
  106. echo "self traffic failed:$FAILED" >&2
  107. exit 1
  108. fi