[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 <[email protected]> Tue, 27 Jan 2026 10:59:00 +0000
Newsgroups com.zx2c4.lists.wireguard
Message-ID <mLw905RIKYUDmGlhcXnA3rHthtd4dX1INnV9YTRvpeu52Fb497VVyMpw8JXl3o_7jKdadiwBRCSnbPmdZJQfncbsOu0EAooF0YdER3I1SDQ=@proton.me>
This patch proposes to modify the wg-quick script for linux to avoid forcin=
g 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 edit=
ion of system parameters is not allowed. Such case can be found when runnin=
g a wireguard client with AllowedIPs=3D0.0.0.0/0 inside a container.
In such case, wq-quick up is aborted in the middle of the setup process eve=
n 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 t=
he parameter is used but nothing is modified. For more verbosity or whateve=
r else, I leave any adaptation of the patch at the discretion of the mainta=
iners.

Signed-off-by: ndmalc <[email protected]>
---
 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() {
 =09printf -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 --resto=
re-mark %s\nCOMMIT\n' "$restore" $table "$marker" "$marker"
 =09printf -v nftcmd '%sadd rule %s %s postmangle meta l4proto udp mark %d =
ct mark set mark \n' "$nftcmd" "$pf" "$nftable" $table
 =09printf -v nftcmd '%sadd rule %s %s premangle meta l4proto udp meta mark=
 set ct mark \n' "$nftcmd" "$pf" "$nftable"
-=09[[ $proto =3D=3D -4 ]] && cmd sysctl -q net.ipv4.conf.all.src_valid_mar=
k=3D1
+=09[[ $proto =3D=3D -4 ]] && [[ $(sysctl -n net.ipv4.conf.all.src_valid_ma=
rk) -ne 1 ]] && cmd sysctl -q net.ipv4.conf.all.src_valid_mark=3D1
 =09if type -p nft >/dev/null; then
 =09=09cmd nft -f <(echo -n "$nftcmd")
 =09else
--=20
2.52.0