]> git.ipfire.org Git - thirdparty/wireguard-tools.git/commitdiff
wg-quick: if resolvconf/interface-order exists, use it
authorJason A. Donenfeld <Jason@zx2c4.com>
Wed, 28 Feb 2018 18:24:31 +0000 (19:24 +0100)
committerJason A. Donenfeld <Jason@zx2c4.com>
Sun, 4 Mar 2018 17:50:25 +0000 (18:50 +0100)
Some older broken resolvconf implementations ignore -m, but do have an
interface-order list. It's better to use this list dynamically, in case
it changes, or in case it's not used by the OS's resolvconf
implementation, such as in the case of systemd or openresolv.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
src/wg-quick.bash

index af72f7d2d0125ab39184fcaecdfac7f8aa8031f2..e93fb80fb00a93a1bfe2f6a5dd03d8d6a09547e1 100755 (executable)
@@ -136,16 +136,25 @@ set_mtu() {
        cmd ip link set mtu $(( mtu - 80 )) dev "$INTERFACE"
 }
 
+resolvconf_iface_prefix() {
+       [[ -f /etc/resolvconf/interface-order ]] || return 0
+       local iface
+       while read -r iface; do
+               [[ $iface =~ ^([A-Za-z0-9-]+)\*$ ]] || continue
+               echo "${BASH_REMATCH[1]}." && return 0
+       done < /etc/resolvconf/interface-order
+}
+
 HAVE_SET_DNS=0
 set_dns() {
        [[ ${#DNS[@]} -gt 0 ]] || return 0
-       printf 'nameserver %s\n' "${DNS[@]}" | cmd resolvconf -a "tun.$INTERFACE" -m 0 -x
+       printf 'nameserver %s\n' "${DNS[@]}" | cmd resolvconf -a "$(resolvconf_iface_prefix)$INTERFACE" -m 0 -x
        HAVE_SET_DNS=1
 }
 
 unset_dns() {
        [[ ${#DNS[@]} -gt 0 ]] || return 0
-       cmd resolvconf -d "tun.$INTERFACE"
+       cmd resolvconf -d "$(resolvconf_iface_prefix)$INTERFACE"
 }
 
 add_route() {
@@ -194,7 +203,7 @@ save_config() {
        done
        while read -r address; do
                [[ $address =~ ^nameserver\ ([a-zA-Z0-9_=+:%.-]+)$ ]] && new_config+="DNS = ${BASH_REMATCH[1]}"$'\n'
-       done < <(resolvconf -l "tun.$INTERFACE" 2>/dev/null)
+       done < <(resolvconf -l "$(resolvconf_iface_prefix)$INTERFACE" 2>/dev/null)
        [[ -n $MTU && $(ip link show dev "$INTERFACE") =~ mtu\ ([0-9]+) ]] && new_config+="MTU = ${BASH_REMATCH[1]}"$'\n'
        [[ -n $TABLE ]] && new_config+="Table = $TABLE"$'\n'
        [[ $SAVE_CONFIG -eq 0 ]] || new_config+=$'SaveConfig = true\n'