From 64e47de870a2f0575b5564a70e5680b48ab83ff9 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Thu, 18 May 2017 14:40:26 +0200 Subject: 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. --- src/tools/wg-quick.bash | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/tools/wg-quick.bash b/src/tools/wg-quick.bash index 8cb439a..a4f349a 100755 --- a/src/tools/wg-quick.bash +++ b/src/tools/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 -- cgit v1.2.3-59-g8ed1b