[PATCH] wireguard-tools/wg-quick for linux, avoid modifying net.ipv4.conf.all.src_valid_mark system parameter when its value is already set to 1
ndmalc
ndmalc at proton.me
Tue Jan 27 10:59:00 UTC 2026
This patch proposes to modify the wg-quick script for linux to avoid forcing the setting of the system parameter net.ipv4.conf.all.src_valid_mark when its value is already valid.
This is to avoid edge cases where the use of wireguard is possible but edition of system parameters is not allowed. Such case can be found when running a wireguard client with AllowedIPs=0.0.0.0/0 inside a container.
In such case, wq-quick up is aborted in the middle of the setup process even if src_valid_mark system parameter is properly set.
I propose a simple patch as below by adding a check. During the setup phase, this will no longer display any messages related to src_valid_mark when the parameter is used but nothing is modified. For more verbosity or whatever else, I leave any adaptation of the patch at the discretion of the maintainers.
Signed-off-by: ndmalc <ndmalc at proton.me>
---
src/wg-quick/linux.bash | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/wg-quick/linux.bash b/src/wg-quick/linux.bash
index 34fa5f9..8c22d6e 100755
--- a/src/wg-quick/linux.bash
+++ b/src/wg-quick/linux.bash
@@ -238,7 +238,7 @@ add_default() {
printf -v restore '%sCOMMIT\n*mangle\n-I POSTROUTING -m mark --mark %d -p udp -j CONNMARK --save-mark %s\n-I PREROUTING -p udp -j CONNMARK --restore-mark %s\nCOMMIT\n' "$restore" $table "$marker" "$marker"
printf -v nftcmd '%sadd rule %s %s postmangle meta l4proto udp mark %d ct mark set mark \n' "$nftcmd" "$pf" "$nftable" $table
printf -v nftcmd '%sadd rule %s %s premangle meta l4proto udp meta mark set ct mark \n' "$nftcmd" "$pf" "$nftable"
- [[ $proto == -4 ]] && cmd sysctl -q net.ipv4.conf.all.src_valid_mark=1
+ [[ $proto == -4 ]] && [[ $(sysctl -n net.ipv4.conf.all.src_valid_mark) -ne 1 ]] && cmd sysctl -q net.ipv4.conf.all.src_valid_mark=1
if type -p nft >/dev/null; then
cmd nft -f <(echo -n "$nftcmd")
else
--
2.52.0
More information about the WireGuard
mailing list