30-vpnclient-unset-server-ipv6-route 922 B

123456789101112131415161718192021222324252627282930313233343536
  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. unset_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 delete "${server_ip6}/128" via "${ip6_gw}" dev "${wired_device}"
  19. done
  20. }
  21. old_ip6_gw=$(yunohost app setting vpnclient ip6_gw)
  22. old_wired_device=$(yunohost app setting vpnclient wired_device)
  23. old_server_ip6=$(yunohost app setting vpnclient server_ip6)
  24. # Check old state of the server ipv6 route
  25. if [[ -n "${old_server_ip6}" && -n "${old_ip6_gw}" && -n "${old_wired_device}" ]]; then
  26. if is_serverip6route_set "${old_server_ip6}"; then
  27. unset_serverip6route "${old_server_ip6}" "${old_ip6_gw}" "${old_wired_device}"
  28. fi
  29. fi