50-vpnclient-set-ipv6-send-over-tun 1.0 KB

12345678910111213141516171819202122232425262728293031
  1. #!/bin/bash
  2. # cf https://openvpn.net/community-resources/reference-manual-for-openvpn-2-4/#environmental-variables
  3. # to have a list of variables provided by OpenVPN, i.e:
  4. # - dev
  5. # - net_gateway_ipv6
  6. # - ifconfig_ipv6_local
  7. gateway_interface=${dev}
  8. ip6_gw=${net_gateway_ipv6}
  9. if [[ -n "${net_gateway_ipv6}" ]]; then
  10. echo "[INFO] Native IPv6 detected"
  11. echo "[INFO] Autodetected native IPv6 gateway: ${ip6_gw}"
  12. ip6_addr=$(yunohost app setting "vpnclient" "ip6_addr")
  13. if [[ -z "${ip6_addr}" ]] || [[ "${ip6_addr}" == none ]]; then
  14. if [[ -z ${ifconfig_ipv6_local} ]]; then
  15. echo "[FAIL] Cannot find IPv6 address"
  16. exit 1
  17. fi
  18. ip6_addr="${ifconfig_ipv6_local}"
  19. fi
  20. echo "[INFO] Found IPv6 address: ${ip6_addr}"
  21. echo "1 send_over_tun" > /etc/iproute2/rt_tables.d/vpnclient_ynh.conf
  22. ip -6 route flush table send_over_tun || true
  23. ip -6 route add default via "${ip6_gw}" dev "${gateway_interface}" table send_over_tun proto static
  24. ip -6 rule flush lookup send_over_tun
  25. ip -6 rule add from "${ip6_addr}/64" pref 1 table send_over_tun
  26. fi