Skip to contentSkip to conversation

wg-quick: avoid traffics from momentarily leaking into the tunnel

PATCH Applied Tom Yan 2 participants 2 messages Jun 17, 2022

lore
Share & tools
lore

Tom Yan

author
#0 lore raw

PATCH 1/1 wg-quick: avoid traffics from momentarily leaking into the tunnel

The wireguard route table ip rule should stay as a NOP until the suppress_prefixlength 0 table main rule is in effect. Therefore, add the wireguard default route to its route table after the latter rule is added.

---
 src/wg-quick/linux.bash | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
src/wg-quick/linux.bash +1 -1
index e4d4c4f..69e5bef 100755
@@ -220,9 +220,9 @@ add_default() {
 	fi
 	local proto=-4 iptables=iptables pf=ip
 	[[ $1 == *:* ]] && proto=-6 iptables=ip6tables pf=ip6
-	cmd ip $proto route add "$1" dev "$INTERFACE" table $table
 	cmd ip $proto rule add not fwmark $table table $table
 	cmd ip $proto rule add table main suppress_prefixlength 0
+	cmd ip $proto route add "$1" dev "$INTERFACE" table $table
 
 	local marker="-m comment --comment \"wg-quick(8) rule for $INTERFACE\"" restore=$'*raw\n' nftable="wg-quick-$INTERFACE" nftcmd 
 	printf -v nftcmd '%sadd table %s %s\n' "$nftcmd" "$pf" "$nftable"
Signature · 1 line
2.36.1
#1 lore raw
Quoted 6 lines · Tom Yan

The wireguard route table ip rule should stay as a NOP until the suppress_prefixlength 0 table main rule is in effect. Therefore, add the wireguard default route to its route table after the latter rule is added.

Applied, thanks.

Quoted 22 lines
---
 src/wg-quick/linux.bash | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
src/wg-quick/linux.bash +1 -1
index e4d4c4f..69e5bef 100755
@@ -220,9 +220,9 @@ add_default() {
 	fi
 	local proto=-4 iptables=iptables pf=ip
 	[[ $1 == *:* ]] && proto=-6 iptables=ip6tables pf=ip6
-	cmd ip $proto route add "$1" dev "$INTERFACE" table $table
 	cmd ip $proto rule add not fwmark $table table $table
 	cmd ip $proto rule add table main suppress_prefixlength 0
+	cmd ip $proto route add "$1" dev "$INTERFACE" table $table
 
 	local marker="-m comment --comment \"wg-quick(8) rule for $INTERFACE\"" restore=$'*raw\n' nftable="wg-quick-$INTERFACE" nftcmd 
 	printf -v nftcmd '%sadd table %s %s\n' "$nftcmd" "$pf" "$nftable"
Signature · 1 line
2.36.1