netfilter: nft_set_pipapo: move cloning of match info to insert/removal path
authorFlorian Westphal <fw@strlen.de>
Thu, 25 Apr 2024 12:06:46 +0000 (14:06 +0200)
committerPablo Neira Ayuso <pablo@netfilter.org>
Fri, 10 May 2024 09:05:16 +0000 (11:05 +0200)
commit3f1d886cc7c3525d4dbeee24bfa9bb3fe0d48ddc
tree95514cff589ec9f54af3f2afcc20a4b3256fce5f
parenta238106703ab4ae1090b86eba128815b8626d8f1
netfilter: nft_set_pipapo: move cloning of match info to insert/removal path

This set type keeps two copies of the sets' content,
   priv->match (live version, used to match from packet path)
   priv->clone (work-in-progress version of the 'future' priv->match).

All additions and removals are done on priv->clone.  When transaction
completes, priv->clone becomes priv->match and a new clone is allocated
for use by next transaction.

Problem is that the cloning requires GFP_KERNEL allocations but we
cannot fail at either commit or abort time.

This patch defers the clone until we get an insertion or removal
request.  This allows us to handle OOM situations correctly.

This also allows to remove ->dirty in a followup change:

If ->clone exists, ->dirty is always true
If ->clone is NULL, ->dirty is always false, no elements were added
or removed (except catchall elements which are external to the specific
set backend).

Signed-off-by: Florian Westphal <fw@strlen.de>
Reviewed-by: Stefano Brivio <sbrivio@redhat.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
net/netfilter/nft_set_pipapo.c