123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- #!/bin/bash
- is_serverip6route_set() {
- local server_ip6=${1}
- if [[ -z "${server_ip6}" ]]; then
- return 0
- fi
- if ! ip -6 route | grep -q "^${server_ip6}"; then
- return 1
- fi
- }
- set_serverip6route() {
- local server_ip6=${1}
- local ip6_gw=${2}
- local wired_device=${3}
- ip route add "${server_ip6}/128" via "${ip6_gw}" dev "${wired_device}"
- }
- wired_device=$(ip route | awk '/default via/ { print $5; }')
- # See https://openvpn.net/community-resources/reference-manual-for-openvpn-2-4/#environmental-variables
- # to have a list of variables provided by OpenVPN, i.e:
- # - ifconfig_ipv6_remote
- # - net_gateway_ipv6
- echo "[INFO] Autodetected internet interface: ${wired_device}"
- if [[ -n "${ifconfig_ipv6_remote}" ]]; then
- echo "[INFO] Autodetected IPv6 address for the VPN server: ${ifconfig_ipv6_remote}"
- else
- echo "[INFO] No IPv6 address for the VPN server detected"
- echo "[INFO] No IPv6 route set"
- exit 0
- fi
- # Set the new server ipv6 route
- if [[ -n "${net_gateway_ipv6}" ]]; then
- if ! is_serverip6route_set "${ifconfig_ipv6_remote}"; then
- set_serverip6route "${ifconfig_ipv6_remote}" "${net_gateway_ipv6}" "${wired_device}"
- fi
- echo "[INFO] Native IPv6 detected"
- echo "[INFO] Autodetected native IPv6 gateway: ${net_gateway_ipv6}"
- if is_serverip6route_set "${ifconfig_ipv6_remote}"; then
- echo "[ OK ] IPv6 server route correctly set"
- else
- echo "[FAIL] No IPv6 server route set" >&2
- exit 1
- fi
- else
- echo "[INFO] No native IPv6 detected"
- echo "[INFO] No IPv6 server route to set"
- fi
|