1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- #!/bin/bash
- is_serverip6route_set() {
- local server_ip6s=${1}
- if [[ -z "${server_ip6s}" ]]; then
- return 0
- fi
- for server_ip6 in ${server_ip6s}; do
- if ! ip -6 route | grep -q "^${server_ip6}"; then
- return 1
- fi
- done
- }
- set_serverip6route() {
- local server_ip6s=${1}
- local ip6_gw=${2}
- local wired_device=${3}
- for server_ip6 in ${server_ip6s}; do
- ip route add "${server_ip6}/128" via "${ip6_gw}" dev "${wired_device}"
- done
- }
- wired_device=$(ip route | awk '/default via/ { print $5; }')
- 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
|