30-vpnclient-set-server-ipv6-route 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #!/bin/bash
  2. is_serverip6route_set() {
  3. local server_ip6s=${1}
  4. if [[ -z "${server_ip6s}" ]]; then
  5. return 0
  6. fi
  7. for server_ip6 in ${server_ip6s}; do
  8. if ! ip -6 route | grep -q "^${server_ip6}"; then
  9. return 1
  10. fi
  11. done
  12. }
  13. set_serverip6route() {
  14. local server_ip6s=${1}
  15. local ip6_gw=${2}
  16. local wired_device=${3}
  17. for server_ip6 in ${server_ip6s}; do
  18. ip route add "${server_ip6}/128" via "${ip6_gw}" dev "${wired_device}"
  19. done
  20. }
  21. wired_device=$(ip route | awk '/default via/ { print $5; }')
  22. echo "[INFO] Autodetected internet interface: ${wired_device}"
  23. if [[ -n "${ifconfig_ipv6_remote}" ]]; then
  24. echo "[INFO] Autodetected IPv6 address for the VPN server: ${ifconfig_ipv6_remote}"
  25. else
  26. echo "[INFO] No IPv6 address for the VPN server detected"
  27. echo "[INFO] No IPv6 route set"
  28. exit 0
  29. fi
  30. # Set the new server ipv6 route
  31. if [[ -n "${net_gateway_ipv6}" ]]; then
  32. if ! is_serverip6route_set "${ifconfig_ipv6_remote}"; then
  33. set_serverip6route "${ifconfig_ipv6_remote}" "${net_gateway_ipv6}" "${wired_device}"
  34. fi
  35. echo "[INFO] Native IPv6 detected"
  36. echo "[INFO] Autodetected native IPv6 gateway: ${net_gateway_ipv6}"
  37. if is_serverip6route_set "${ifconfig_ipv6_remote}"; then
  38. echo "[ OK ] IPv6 server route correctly set"
  39. else
  40. echo "[FAIL] No IPv6 server route set" >&2
  41. exit 1
  42. fi
  43. else
  44. echo "[INFO] No native IPv6 detected"
  45. echo "[INFO] No IPv6 server route to set"
  46. fi