wg-quick: if resolvconf/interface-order exists, use it
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>
This commit is contained in:
parent
4574967465
commit
99264cb88f
|
@ -136,16 +136,25 @@ set_mtu() {
|
||||||
cmd ip link set mtu $(( mtu - 80 )) dev "$INTERFACE"
|
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
|
HAVE_SET_DNS=0
|
||||||
set_dns() {
|
set_dns() {
|
||||||
[[ ${#DNS[@]} -gt 0 ]] || return 0
|
[[ ${#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
|
HAVE_SET_DNS=1
|
||||||
}
|
}
|
||||||
|
|
||||||
unset_dns() {
|
unset_dns() {
|
||||||
[[ ${#DNS[@]} -gt 0 ]] || return 0
|
[[ ${#DNS[@]} -gt 0 ]] || return 0
|
||||||
cmd resolvconf -d "tun.$INTERFACE"
|
cmd resolvconf -d "$(resolvconf_iface_prefix)$INTERFACE"
|
||||||
}
|
}
|
||||||
|
|
||||||
add_route() {
|
add_route() {
|
||||||
|
@ -194,7 +203,7 @@ save_config() {
|
||||||
done
|
done
|
||||||
while read -r address; do
|
while read -r address; do
|
||||||
[[ $address =~ ^nameserver\ ([a-zA-Z0-9_=+:%.-]+)$ ]] && new_config+="DNS = ${BASH_REMATCH[1]}"$'\n'
|
[[ $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 $MTU && $(ip link show dev "$INTERFACE") =~ mtu\ ([0-9]+) ]] && new_config+="MTU = ${BASH_REMATCH[1]}"$'\n'
|
||||||
[[ -n $TABLE ]] && new_config+="Table = $TABLE"$'\n'
|
[[ -n $TABLE ]] && new_config+="Table = $TABLE"$'\n'
|
||||||
[[ $SAVE_CONFIG -eq 0 ]] || new_config+=$'SaveConfig = true\n'
|
[[ $SAVE_CONFIG -eq 0 ]] || new_config+=$'SaveConfig = true\n'
|
||||||
|
|
Loading…
Reference in New Issue