From: Florian Westphal <fw@strlen.de>
To: Tom Yan <tom.ty89@gmail.com>
Cc: netfilter@vger.kernel.org, netfilter-devel@vger.kernel.org
Subject: Re: [nft] Regarding `tcp flags` (and a potential bug)
Date: Tue, 27 Jul 2021 17:10:18 +0200 [thread overview]
Message-ID: <20210727151018.GA15121@breakpoint.cc> (raw)
In-Reply-To: <CAGnHSEncHuO2BduzGx1L9eVtAozdGb-XabQyrS7S+CO2swa1dw@mail.gmail.com>
Tom Yan <tom.ty89@gmail.com> wrote:
> Just noticed something that is even worse:
>
> # nft add rule meh tcp_flags 'tcp flags { fin, rst, ack }'
> # nft add rule meh tcp_flags 'tcp flags == { fin, rst, ack }'
These two are identical.
> # nft add rule meh tcp_flags 'tcp flags & ( fin | rst | ack ) != 0'
This matches if any one of fin/rst/ack is set.
> # nft add rule meh tcp_flags 'tcp flags & ( fin | rst | ack ) == 0'
This matches if fin/rst/ack are all 0 (not set).
> # nft list table meh
> table ip meh {
> chain tcp_flags {
> tcp flags { fin, rst, ack }
> tcp flags { fin, rst, ack }
> tcp flags fin,rst,ack
> tcp flags ! fin,rst,ack
> }
> }
Can you elaborate?
This looks correct to me.
> > # nft add rule meh tcp_flags 'tcp flags & (fin | syn | rst | ack) ! syn'
Its unfortunate nft accepts this. The trailing ! syn is nonsensical.
This is equal to tcp flags ! syn.
> > # nft add rule meh tcp_flags 'tcp flags & (fin | syn | rst | ack) == syn'
> > # nft add rule meh tcp_flags 'tcp flags & (fin | syn | rst | ack) != syn'
> > # nft list table meh
> > table ip meh {
> > chain tcp_flags {
> > tcp flags & (fin | syn | rst | ack) syn
> > tcp flags & (fin | syn | rst | ack) ! syn
> > tcp flags syn / fin,syn,rst,ack
> > tcp flags syn / fin,syn,rst,ack
> > }
> > }
> >
> > I don't suppose the mask in the first two rules would matter. And with
> > `tcp flags syn / fin,syn,rst,ack`, I assume it would be false when
> > "syn is cleared and/or any/all of fin/rst/ack is/are set"?
> >
> > Also, as you can see, for the last two rules, `nft` interpreted them
> > as an identical rule, which I assume to be a bug. These does NOT seem
> > to workaround it either:
> >
> > # nft flush chain meh tcp_flags
> > # nft add rule meh tcp_flags 'tcp flags == syn / fin,syn,rst,ack'
> > # nft add rule meh tcp_flags 'tcp flags != syn / fin,syn,rst,ack'
> > # nft list table meh
> > table ip meh {
> > chain tcp_flags {
> > tcp flags syn / fin,syn,rst,ack
> > tcp flags syn / fin,syn,rst,ack
Seems the reverse translation is broken, the negation is lost.
The rule is added correctly (i.e., flags == syn vs. != syn adds
different rules, see nft --debug=netlink add ..
next prev parent reply other threads:[~2021-07-27 15:10 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-27 11:18 [nft] Regarding `tcp flags` (and a potential bug) Tom Yan
2021-07-27 14:52 ` Tom Yan
2021-07-27 15:10 ` Florian Westphal [this message]
2021-07-27 21:11 ` Pablo Neira Ayuso
2021-07-29 2:27 ` Tom Yan
2021-07-29 7:12 ` 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=20210727151018.GA15121@breakpoint.cc \
--to=fw@strlen.de \
--cc=netfilter-devel@vger.kernel.org \
--cc=netfilter@vger.kernel.org \
--cc=tom.ty89@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 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).