aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/wg-quick.bash
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2017-05-18 14:40:26 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2017-05-18 14:41:34 +0200
commit682b15cb5e329aaf8d9d55e81605d82661dd5c2b (patch)
tree24efd4ac942ac2d6247907b893a0830a08041099 /src/wg-quick.bash
parentman: fix psk mention in wg-quick man page (diff)
downloadwireguard-tools-682b15cb5e329aaf8d9d55e81605d82661dd5c2b.tar.xz
wireguard-tools-682b15cb5e329aaf8d9d55e81605d82661dd5c2b.zip
wg-quick: use src routing for default routes in v6
Otherwise, traffic is sent with the IP address of a different interface, and then packets don't actually get delivered. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'src/wg-quick.bash')
-rwxr-xr-xsrc/wg-quick.bash14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/wg-quick.bash b/src/wg-quick.bash
index 8cb439a..a4f349a 100755
--- a/src/wg-quick.bash
+++ b/src/wg-quick.bash
@@ -143,10 +143,18 @@ add_default() {
DEFAULT_TABLE=51820
while [[ -n $(ip route show table $DEFAULT_TABLE) ]]; do ((DEFAULT_TABLE++)); done
fi
- local proto=-4
- [[ $1 == *:* ]] && proto=-6
+ local proto=-4 src ip
+ if [[ $1 == *:* ]]; then
+ proto=-6
+ for ip in "${ADDRESSES[@]}"; do
+ if [[ $ip == *:* ]]; then
+ src="src ${ip%/*}"
+ break
+ fi
+ done
+ fi
cmd wg set "$INTERFACE" fwmark $DEFAULT_TABLE
- cmd ip $proto route add "$1" dev "$INTERFACE" table $DEFAULT_TABLE
+ cmd ip $proto route add "$1" $src dev "$INTERFACE" table $DEFAULT_TABLE
cmd ip $proto rule add not fwmark $DEFAULT_TABLE table $DEFAULT_TABLE
cmd ip $proto rule add table main suppress_prefixlength 0
local key value