wg-quick: support v6 dual stack
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
parent
3606898d23
commit
cf2cb85a08
|
@ -79,8 +79,10 @@ add_if() {
|
||||||
|
|
||||||
del_if() {
|
del_if() {
|
||||||
if [[ $(ip route show table all) =~ .*\ dev\ $INTERFACE\ table\ ([0-9]+)\ .* ]]; then
|
if [[ $(ip route show table all) =~ .*\ dev\ $INTERFACE\ table\ ([0-9]+)\ .* ]]; then
|
||||||
|
while [[ -n $(ip rule show table ${BASH_REMATCH[1]}) ]]; do
|
||||||
cmd ip rule delete table "${BASH_REMATCH[1]}"
|
cmd ip rule delete table "${BASH_REMATCH[1]}"
|
||||||
[[ $(ip rule show table main) == *"from all lookup main suppress_prefixlength 0"* ]] && cmd ip rule delete table main suppress_prefixlength 0
|
[[ $(ip rule show table main) == *"from all lookup main suppress_prefixlength 0"* ]] && cmd ip rule delete table main suppress_prefixlength 0
|
||||||
|
done
|
||||||
fi
|
fi
|
||||||
cmd ip link delete dev "$INTERFACE"
|
cmd ip link delete dev "$INTERFACE"
|
||||||
}
|
}
|
||||||
|
@ -101,13 +103,22 @@ add_route() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DEFAULT_TABLE=
|
||||||
|
PREVIOUS_ENDPOINT=
|
||||||
add_default() {
|
add_default() {
|
||||||
[[ $(join <(wg show "$INTERFACE" allowed-ips) <(wg show "$INTERFACE" endpoints)) =~ .*\ ${1//./\\.}\ \[?([0-9.:a-f]+)\]?:[0-9]+$ ]] && local endpoint="${BASH_REMATCH[1]}"
|
[[ $(join <(wg show "$INTERFACE" allowed-ips) <(wg show "$INTERFACE" endpoints)) =~ ([A-Za-z0-9/+=]{44})\ ([0-9a-f/.:]+ )*${1//./\\.}\ ([0-9a-f/.:]+ )*\[?([0-9.:a-f]+)\]?:[0-9]+ ]] && local endpoint="${BASH_REMATCH[4]}"
|
||||||
[[ -n $endpoint ]] || return 0
|
[[ -n $endpoint ]] || return 0
|
||||||
local table=51820
|
local first=0
|
||||||
while [[ -n $(ip route show table $table) ]]; do ((table++)); done
|
if [[ -z $DEFAULT_TABLE ]]; then
|
||||||
cmd ip route add "$1" dev "$INTERFACE" table $table
|
first=1
|
||||||
cmd ip rule add not to "$endpoint" table $table
|
DEFAULT_TABLE=51820
|
||||||
|
while [[ -n $(ip route show table $DEFAULT_TABLE) ]]; do ((DEFAULT_TABLE++)); done
|
||||||
|
fi
|
||||||
|
cmd ip route add "$1" dev "$INTERFACE" table $DEFAULT_TABLE
|
||||||
|
[[ $PREVIOUS_ENDPOINT == "$endpoint" ]] && return 0
|
||||||
|
PREVIOUS_ENDPOINT="$endpoint"
|
||||||
|
cmd ip rule add not to "$endpoint" table $DEFAULT_TABLE
|
||||||
|
[[ $first -eq 1 ]] || return 0
|
||||||
cmd ip rule add table main suppress_prefixlength 0
|
cmd ip rule add table main suppress_prefixlength 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue