All of lore.kernel.org
 help / color / mirror / Atom feed
From: Florian Westphal <fw@strlen.de>
To: Laura Garcia <nevola@gmail.com>
Cc: Florian Westphal <fw@strlen.de>,
	netfilter-devel <netfilter-devel@vger.kernel.org>
Subject: Re: What is 'dynamic' set flag supposed to mean?
Date: Wed, 18 Sep 2019 16:42:35 +0200	[thread overview]
Message-ID: <20190918144235.GN6961@breakpoint.cc> (raw)
In-Reply-To: <CAF90-WifdkWm5xu0utZqjoAtW9SW4JyFrVqyxf5EbD9vUZJucw@mail.gmail.com>

Laura Garcia <nevola@gmail.com> wrote:
> > Following example loads fine:
> > table ip NAT {
> >   set set1 {
> >     type ipv4_addr
> >     size 64
> >     flags dynamic,timeout
> >     timeout 1m
> >   }
> >
> >   chain PREROUTING {
> >      type nat hook prerouting priority -101; policy accept;
> >   }
> > }
> >
> > But adding/using this set doesn't work:
> > nft -- add rule NAT PREROUTING tcp dport 80 ip saddr @set1 counter
> > Error: Could not process rule: Operation not supported
> 
> If this set is only for matching, 'dynamic' is not required.

I know, and the example above works if the 'dynamic' flag is omitted.

> > This is because the 'dynamic' flag sets NFT_SET_EVAL.
> >
> > According to kernel comment, that flag means:
> >  * @NFT_SET_EVAL: set can be updated from the evaluation path
> >
> > The rule add is rejected from the lookup expression (nft_lookup_init)
> > which has:
> >
> > if (set->flags & NFT_SET_EVAL)
> >     return -EOPNOTSUPP;
> >
> > From looking at the git history, the NFT_SET_EVAL flag means that the
> > set contains expressions (i.e., a meter).
> >
> > And I can see why doing a lookup on meters isn't meaningful.
> >
> > Can someone please explain the exact precise meaning of 'dynamic'?
> > Was it supposed to mean 'set can be updated from packet path'?
> > Or was it supposed to mean 'set contains expressions'?
> >
> 
> AFAIK, I traduce the 'dynamic' flag as a 'set that is updated from the
> packet path using an expression', formerly 'meter'.

That would mean the kernel comment quoted above is wrong and should be
patched to say

* @NFT_SET_EVAL: set can be updated from the packet path and stores expressions.

Unfortunately, this seems to contradict various nftables.git changelog
messages which seem to imply that 'dynamic' means

@NFT_SET_EVAL: set can be updated from the evaluation path

i.e., make sure that set provides an ->update() implementation so

'add @set1 { ip saddr }' and the like work.

The core issue is that when saying

   set set1 {
      type ipv4_addr
      size 64
       flags timeout
       timeout 1m
    }

The kernel has no information on how this set is going to be used.
For 'ip saddr @set1' this will just work as all sets implement
->lookup().

But will this work reliably:
nft add rule ... add @set1 { ip saddr }

At this time, it looks like when specifiying the mandatory 'timeout'
flag, the kernel happens to pick the rhashtable backend so it will work.

But I wonder if we're just lucky or if this is intentional, i.e.
'timeout' means that the set can be altered from the packet path.

In any case, this needs to be documented in nft.8, its telling that I
can't be 100% about the intent of dynamic/EVAL even after reading both
nftables.git and kernel implementation.

  reply	other threads:[~2019-09-18 14:42 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-18 11:53 What is 'dynamic' set flag supposed to mean? Florian Westphal
2019-09-18 14:10 ` Laura Garcia
2019-09-18 14:42   ` Florian Westphal [this message]
2019-09-19  8:43     ` Pablo Neira Ayuso
2019-09-19  9:24       ` Florian Westphal
2019-09-19  9:40         ` Pablo Neira Ayuso
2019-09-19 10:03           ` Florian Westphal
2019-09-19 11:52             ` Pablo Neira Ayuso
2019-09-19 11:56             ` Florian Westphal
2019-09-19 13:28               ` Pablo Neira Ayuso
2019-09-19 14:01                 ` Florian Westphal
2019-09-19 14:22                   ` Pablo Neira Ayuso
2019-09-19 14:34                     ` Florian Westphal
2019-09-19 14:55                       ` Pablo Neira Ayuso

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=20190918144235.GN6961@breakpoint.cc \
    --to=fw@strlen.de \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=nevola@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.