Development discussion of WireGuard
 help / color / mirror / Atom feed
From: Dominique Martinet <asmadeus@codewreck.org>
To: wireguard@lists.zx2c4.com
Cc: Dominique Martinet <asmadeus@codewreck.org>
Subject: [RFC PATCH] wg-quick: linux: raise priority for mangle nft chain
Date: Mon, 27 Apr 2020 19:26:53 +0200	[thread overview]
Message-ID: <1588008413-5667-1-git-send-email-asmadeus@codewreck.org> (raw)

Setting mark must be done as early as possible in case there are
ipv6 rpfilter rules in the mangle table (a nft filter could be done
later but with ip6tables this is the latest it can be checked).
Mark must be set before the return path check for it to work correctly.

priority -160 gets rendered as "mangle - 10" in nft list table,
and will correctly set the mark before other mangle prerouting rules
if there are any and same as before if there aren't.
---

I've been discussing with firewalld folks about the ipv6_rpfilter rules
they add which block wireguard setup with wg-quick on ipv6 endpoints by
default ; see https://github.com/firewalld/firewalld/issues/603 for
recap issue.
Long story short: they'll move the rpfilter rule to take effect later
(after mark is set) and add mark matching so that it works always with
nft backend, and sometimes with iptables backend.

Sometimes, because the ip6tables rpfilter module can only be used up to
mangle's prerouting table, and that one's priority with nft `hook
prerouting priority mangle` is "random" (depends on module load order?)

Changing the priority to load a bit earlier is harmless in the default
case and should just work for most people once they get a fixed
firewalld; I believe that is easier to change than try to document
the issue (e.g. telling people to use nft backend or disable
ipv6_rpfilter if they have issues as that is hard to debug)

Thanks!


 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 7c2c002..9001c6a 100755
--- a/src/wg-quick/linux.bash
+++ b/src/wg-quick/linux.bash
@@ -222,7 +222,7 @@ add_default() {
 	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"
 	printf -v nftcmd '%sadd chain %s %s preraw { type filter hook prerouting priority -300; }\n' "$nftcmd" "$pf" "$nftable"
-	printf -v nftcmd '%sadd chain %s %s premangle { type filter hook prerouting priority -150; }\n' "$nftcmd" "$pf" "$nftable"
+	printf -v nftcmd '%sadd chain %s %s premangle { type filter hook prerouting priority -160; }\n' "$nftcmd" "$pf" "$nftable"
 	printf -v nftcmd '%sadd chain %s %s postmangle { type filter hook postrouting priority -150; }\n' "$nftcmd" "$pf" "$nftable"
 	while read -r line; do
 		[[ $line =~ .*inet6?\ ([0-9a-f:.]+)/[0-9]+.* ]] || continue
-- 
2.26.2


             reply	other threads:[~2020-04-27 20:02 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-27 17:26 Dominique Martinet [this message]
2020-04-28  0:04 ` Jason A. Donenfeld
2020-04-28  6:56   ` Dominique Martinet
2020-05-04 11:27 ` [PATCH] " Dominique Martinet
2020-06-21 21:50   ` [PATCH RESEND] " Dominique Martinet

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1588008413-5667-1-git-send-email-asmadeus@codewreck.org \
    --to=asmadeus@codewreck.org \
    --cc=wireguard@lists.zx2c4.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).