From: Duncan Roe <duncan_roe@optusnet.com.au>
To: netfilter@vger.kernel.org
Subject: Re: Is viewing a "candidate" ruleset in 'nft list ruleset' format possible?
Date: Thu, 23 Apr 2020 12:06:13 +1000 [thread overview]
Message-ID: <20200423020613.GE30155@dimstar.local.net> (raw)
In-Reply-To: <CANf9dFN=DA1eP6W8A5GOAseXvB57_wf=U9Trjk6fY1M58qgfaA@mail.gmail.com>
On Wed, Apr 22, 2020 at 12:34:26PM -0400, Martin Gignac wrote:
> > You can simply put "list ruleset" at the bottom of the foo.nft file.
> > However in my experience this routinely gives outright wrong rulesets
> > (as at nftables 0.9.1), so I don't trust it.
"list ruleset" at the bottom of an nft script is completely accurate. The
command "nft list ruleset" discards portions of rules that are implicit, in the
interests of brevity.
>
> That's a pretty good tip, thanks!... And you're absolutely right, it
> gives some weird output. See below the diff of 'nft -c -f foo.nft'
> with a 'list ruleset' at the bottom and the actual output of 'nft list
> ruleset' once foot.nft is applied to the kernel:
>
> [root@bouboule ~]# diff -u /tmp/toto1.txt /tmp/toto2.txt
> --- /tmp/toto1.txt 2020-04-22 11:55:55.718378603 -0400
> +++ /tmp/toto2.txt 2020-04-22 11:56:01.888551779 -0400
> @@ -1,12 +1,12 @@
> table ip filter {
> chain input {
> type filter hook input priority filter; policy drop;
> - ct state 0x6 accept
> + ct state established,related accept
> ct state invalid drop
> iif "lo" accept
> - meta l4proto icmp icmp type echo-request accept
> comment "You can restrict this if you want"
> - meta l4proto tcp tcp dport 22 accept comment "You can
> restrict this if you want"
> - meta l4proto tcp tcp dport 179 accept comment "For BGP"
> + icmp type echo-request accept comment "You can
> restrict this if you want"
> + tcp dport 22 accept comment "You can restrict this if you want"
> + tcp dport 179 accept comment "For BGP"
> }
>
> chain output {
> @@ -15,7 +15,7 @@
>
> chain forward {
> type filter hook forward priority filter; policy drop;
> - ct state 0x6 counter packets 0 bytes 0 accept
> + ct state established,related counter packets 0 bytes 0 accept
> ct state invalid drop
> }
> }
>
> Of note is the fact that the 'ct state' line does not contain both
> states.
It does show it. There are 2 bits set in 0x6. Perhaps it is an oversight that
the code path does not interpret them.
> As well, the addition of 'meta l4proto' adds a lot of
> unecessary verbiage.
They are necessary *for the kernel*. The nft user interface is smart enough that
you don't have to specify them.
> But still, good to know that this is somewhat
> doable as it never dawned on me to put 'list ruleset' at the end of
> foo.nft.
>
> > A possible short-term workaround would be to spin up a netns, load the
> > new ruleset in *there*, then dump it and tear the ns down again...
>
> This is actually a very cool idea! I never realized that nftables
> rulesets are bound to a specific namespace, but now it makes perfect
> sense. The only "drawback" (I guess) is that I cannot use 'iif' for
> any other interface than 'lo' in the temp namespace; I'll need to use
> 'iifname' instead since the referenced interfaces won't exist in the
> temp namespace. But it's not a deal breaker.
>
> I think I will go with this workaround until (if) nftables supports
> this functionality natively.
>
> Thanks!
> -Martin
next prev parent reply other threads:[~2020-04-23 2:06 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-19 2:12 Is viewing a "candidate" ruleset in 'nft list ruleset' format possible? Martin Gignac
2020-04-22 4:51 ` Trent W. Buck
2020-04-22 16:34 ` Martin Gignac
2020-04-23 2:06 ` Duncan Roe [this message]
2020-04-23 12:10 ` Martin Gignac
2020-04-30 3:25 ` Trent W. Buck
2020-04-30 8:05 ` Trent W. Buck
2020-04-30 3:10 ` Trent W. Buck
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=20200423020613.GE30155@dimstar.local.net \
--to=duncan_roe@optusnet.com.au \
--cc=netfilter@vger.kernel.org \
/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