From: Pablo Neira Ayuso <pablo@netfilter.org>
To: Rick van Rein <rick@openfortress.nl>
Cc: netfilter-devel@vger.kernel.org
Subject: Re: Expressive limitation: (daddr,dport) <--> (daddr',dport')
Date: Mon, 8 Jun 2020 12:31:40 +0200 [thread overview]
Message-ID: <20200608103140.GA15655@salvia> (raw)
In-Reply-To: <5EDE0C9B.2020701@openfortress.nl>
Hi Rick,
On Mon, Jun 08, 2020 at 12:02:03PM +0200, Rick van Rein wrote:
> Hi Pablo / NFT-dev,
>
> >> This is bound to work in many cases, but it can give undesired
> >> crossover behaviours [namely between incoming IPs if they map to the
> >> same daddr' while coming from the same dport]:
> >>
> >> nft add rule ip6 raw prerouting \
> >> ip6 daddr set \
> >> ip6 daddr . tcp dport \
> >> map { $PREFIX::64:75 . 8080 : $PREFIX::100:20 } \
> >> tcp dport set \
> >> ip6 daddr . tcp dport \
> >> map { $PREFIX::100:20 . 8080 : 80 } \
> >
> > So, you would consolidate this in one single rule? So there is one
> > single lookup to obtain the IP address and the destination port for
> > the stateless packet mangling.
>
> It already is a single rule, but a single mapping, or one that appears
> like one. In reality, I use dynamic map @refs, of course.
Right, one single mapping.
> A single lookup would avoid the problem that the key has changed in the
> second lookup.
>
> I played around, trying if I could "ip6 daddr . tcp dport set" and
> perhaps have a map with elements like "{ $PREFIX::64:75 . 8080 :
> $PREFIX::100:20 . 80 }" but did not find a syntax. [I've been missing a
> formal syntax, it's all examples so I wasn't sure if this was possible
> at all.] It'd look like
>
> new_nft add rule ip6 raw prerouting \
> ip6 daddr . tcp dport set \
> ip6 daddr . tcp dport \
> map { $PREFIX::64:75 . 8080 : $PREFIX::100:20 . 80 }
I see.
> >> 0. Is there a way to use maps as atomic setter for (daddr,dport)?
> >
> > Not yet.
>
> Ah, you spotted the problem too. No surprise ;-)
>
> >> 1. Can I reach back to the original value of a just-modified value?
> >
> > You mean, the original header field that was just mangled? Like
> > matching on the former IP address before the mangling?
>
> Yes, exactly. That way, I can use two maps but find the right
> combination of addr/port without intermediate key changes.
>
> >> 2. Is there a variable, or stack, to prepare with the old value?
> >
> > But this is to achieve the atomic mangling that you describe above or
> > you have something else in mind? You would like to store the former IP
> > daddr in some scratchpad area that can be accessed later on, right?
>
> It is another possible way to get to the old value so I can make the
> same mapping.
>
> I could imagine storing the old daddr in daddr2 then mapping daddr and
> using daddr2 in the second map looking to find the matching port. That
> might look like
>
> new_nft add rule ip6 raw prerouting \
> rulevar set ip6 daddr \
> ip6 daddr set \
> ip6 daddr . tcp dport \
> map { $PREFIX::64:75 . 8080 : $PREFIX::100:20 } \
> tcp dport set \
> rulevar . tcp dport \
> map { $PREFIX::100:20 . 8080 : 80 } \
>
> If the language internally uses a stack, I could imagine pushing the old
> value(s) to prepare for the second map, then perform the first map and
> continue with the second. That might look like
>
> new_nft add rule ip6 raw prerouting \
> ip6 daddr push \
> ip6 daddr set \
> ip6 daddr . tcp dport \
> map { $PREFIX::64:75 . 8080 : $PREFIX::100:20 } \
> tcp dport set \
> pop . tcp dport \
> map { $PREFIX::100:20 . 8080 : 80 } \
>
>
> The examples are just three syntaxes I can think of.
OK, but you only need this "stack" idea is alternative proposal to get
the "one single mapping" idea working, correct?
Thanks.
next prev parent reply other threads:[~2020-06-08 10:31 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-07 5:08 Expressive limitation: (daddr,dport) <--> (daddr',dport') Rick van Rein
2020-06-07 22:08 ` Pablo Neira Ayuso
2020-06-08 10:02 ` Rick van Rein
2020-06-08 10:31 ` Pablo Neira Ayuso [this message]
2020-06-08 11:01 ` Rick van Rein
-- strict thread matches above, loose matches on Subject: below --
2020-06-01 16:08 Rick van Rein
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=20200608103140.GA15655@salvia \
--to=pablo@netfilter.org \
--cc=netfilter-devel@vger.kernel.org \
--cc=rick@openfortress.nl \
/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.