From 45cc7a7735436389312c77f495934e2ee7d0aff2 Mon Sep 17 00:00:00 2001 From: de4np Date: Wed, 21 Apr 2021 22:39:23 +0200 Subject: [PATCH] wg-quick: linux: query kernel param before trying to set it Running wg-quick in docker will fail even though the container namespace has net.ipv4.conf.all.src_valid_mark enabled. --- 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 e4d4c4f..1b3b2c7 100755 --- a/src/wg-quick/linux.bash +++ b/src/wg-quick/linux.bash @@ -237,7 +237,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