]> git.ipfire.org Git - thirdparty/wireguard-tools.git/commitdiff
wg-quick: use src routing for default routes in v6
authorJason A. Donenfeld <Jason@zx2c4.com>
Thu, 18 May 2017 12:40:26 +0000 (14:40 +0200)
committerJason A. Donenfeld <Jason@zx2c4.com>
Thu, 18 May 2017 12:41:34 +0000 (14:41 +0200)
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>
src/wg-quick.bash

index 8cb439ae8381e5a94b08ec1178fbaa7b0453f076..a4f349af8dcad97f8e924ab6e265aba6c9c156a8 100755 (executable)
@@ -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