netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Phil Sutter <phil@nwl.cc>
To: Florian Westphal <fw@strlen.de>
Cc: Pablo Neira Ayuso <pablo@netfilter.org>, netfilter-devel@vger.kernel.org
Subject: Re: [PATCH iptables 4/4] nft: keep old cache around until batch is refreshed in case of ERESTART
Date: Mon, 20 May 2019 14:48:37 +0200	[thread overview]
Message-ID: <20190520124837.GB31548@orbyte.nwl.cc> (raw)
In-Reply-To: <20190520120620.nxxl65syr2b7eal7@breakpoint.cc>

On Mon, May 20, 2019 at 02:06:20PM +0200, Florian Westphal wrote:
> Phil Sutter <phil@nwl.cc> wrote:
> > On Sun, May 19, 2019 at 06:45:08PM +0200, Phil Sutter wrote:
> > [...]
> > > The only way to make the above work is by keeping the original cache
> > > copy around until mnl_batch_talk has finally succeeded or failed with
> > > something else than ERESTART.
> > 
> > How about a completely different approach:
> > 
> > If memory serves right (and from reading the related Red Hat ticket),
> > the actual problem we're trying to solve is that iptables-nft-restore
> > creates NFT_MSG_DELTABLE only if that table exists already at the point
> > of parsing but another client might create it in the mean time before
> > committing.
> > 
> > My idea for solving this was to unconditionally create NFT_MSG_NEWTABLE
> > followed by NFT_MSG_DELTABLE - in case the table exists, the first one
> > is a noop; in case the table doesn't exist, the second one won't provoke
> > an error message from kernel space.
> 
> Does that work even work?
> new table x
> del table x
> add rule to x // table was deleted?
> 
> Or are you talking about a new/del/new sequence?

Oh, yes of course. Existing iptables-nft-restore does:

1) delete table x if exists
2) add table x
3) add table x content

My idea is to:

+ 0) add table x
- 1) delete table x if exists
+ 1) delete table x
  2) add table x
  3) add table x content

> If it works, ok/fine, but it seems ugly.

Did you consider rule insert with index in your batch replay logic? I
did when duplicating it for nft, but decided it's not worth it and
people using 'add rule ... index IDX' have been warned already anyway.

> > Since NFT_MSG_DELTABLE removes the table recursively, we don't need to
> > care about any content added by the other client.
> 
> Yes, we can't do this in the --noflush case though.

My state from our last talk about it was "--noflush users are screwed
anyway". :)

> > Or is this about a generic solution for all commands not just
> > iptables-nft-restore (without --noflush)?
> 
> Its for ipt-nft-restore, including --noflush.
> 
> It would be good though to also speed up 'iptables-nft -A' later on
> by eliding cache completely.

The problem is that we can't unconditionally create NFT_MSG_NEWCHAIN
because that will reset the chain policy if non-default. So we need at
least a cache containing tables and chains, even for that simple rule
append command.

Cheers, Phil

      reply	other threads:[~2019-05-20 12:48 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-19 11:51 [PATCH iptables 1/4] nft: add struct nft_cache Pablo Neira Ayuso
2019-05-19 11:51 ` [PATCH iptables 2/4] nft: statify nft_rebuild_cache() Pablo Neira Ayuso
2019-05-19 11:51 ` [PATCH iptables 3/4] nft: add flush_cache() Pablo Neira Ayuso
2019-05-19 11:51 ` [PATCH iptables 4/4] nft: keep old cache around until batch is refreshed in case of ERESTART Pablo Neira Ayuso
2019-05-19 16:45   ` Phil Sutter
2019-05-20 12:00     ` Phil Sutter
2019-05-20 12:06       ` Florian Westphal
2019-05-20 12:48         ` Phil Sutter [this message]

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=20190520124837.GB31548@orbyte.nwl.cc \
    --to=phil@nwl.cc \
    --cc=fw@strlen.de \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=pablo@netfilter.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).