From: Pablo Neira Ayuso <pablo@netfilter.org>
To: Florian Westphal <fw@strlen.de>
Cc: netfilter-devel <netfilter-devel@vger.kernel.org>
Subject: Re: nft -f fails to restore ruleset listing with cetain dynamic set types
Date: Mon, 10 Jan 2022 18:30:16 +0100 [thread overview]
Message-ID: <YdxtKNCoNJ2IGXIQ@salvia> (raw)
In-Reply-To: <20220110152820.GE317@breakpoint.cc>
On Mon, Jan 10, 2022 at 04:28:20PM +0100, Florian Westphal wrote:
> I was given this reproducer:
>
> ----------------
> #!/bin/bash -x
> nft flush ruleset
>
> nft add table ip filter
> nft add chain ip filter output { type filter hook output priority 0 \; }
> nft add set ip filter black-list '{type ipv4_addr; flags dynamic; }'
> nft add rule ip filter output oifname lo meta l4proto udp update @black-list { ip daddr } counter
> nft list ruleset |tee ruleset
>
> nft -f ruleset # success
> nft flush ruleset
> nft list ruleset
> sleep 1
> nft -f ruleset # failed
>
> -----------
>
> The ruleset generated by 'nft list ruleset'
> cannot be restored.
>
> Ruleset looks like this:
>
> table ip filter {
> set black-list {
> type ipv4_addr
> size 65535
> }
>
> chain output {
> type filter hook output priority filter; policy accept;
> oifname "lo" meta l4proto udp update @black-list { ip daddr } counter packets 0 bytes 0
> }
> }
>
> Reason for the failure on restore is that the set is created with 'size
> 65536' but no 'dynamic' flag.
>
> This causes a failure because the kernel picks the 'hash' set that
> lacks the update() function.
>
> The initial commands work because lack of 'size' picks the rhash
> backend, so the ->update works since the check for the timeout flag was
> removed in commit "netfilter: nft_dynset: relax superfluous check on set
> updates".
>
> First restore works because the set is not created anew, so this is
> still 'rhash' backend.
>
> Second restore fails because 'hash' is chosen.
>
> Workaround is to edit the ruleset file to add 'flags dynamic' or 'flags
> timeout', or both.
>
> Any suggestions on how to fix this?
Could you set on the dynamic flag from the evaluation path?
If there is a rule with the set statement that uses the set, then turn
on this dynamic flag.
next prev parent reply other threads:[~2022-01-10 17:30 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-10 15:28 nft -f fails to restore ruleset listing with cetain dynamic set types Florian Westphal
2022-01-10 17:30 ` Pablo Neira Ayuso [this message]
2022-01-10 17:37 ` Florian Westphal
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=YdxtKNCoNJ2IGXIQ@salvia \
--to=pablo@netfilter.org \
--cc=fw@strlen.de \
--cc=netfilter-devel@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;
as well as URLs for NNTP newsgroup(s).