Skip to content

Commit 4ee2918

Browse files
Florian Westphalummakynes
authored andcommitted
netfilter: nf_tables: add nft_trans_commit_list_add_elem helper
Add and use a wrapper to append trans_elem structures to the transaction log. Unlike the existing helper, pass a gfp_t to indicate if sleeping is allowed. This will be used by a followup patch to realloc nft_trans_elem structures after they gain a flexible array member to reduce number of such container structures on the transaction list. Signed-off-by: Florian Westphal <fw@strlen.de> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
1 parent 8340b00 commit 4ee2918

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

net/netfilter/nf_tables_api.c

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,17 @@ static void nft_trans_commit_list_add_tail(struct net *net, struct nft_trans *tr
421421
}
422422
}
423423

424+
static void nft_trans_commit_list_add_elem(struct net *net, struct nft_trans *trans,
425+
gfp_t gfp)
426+
{
427+
WARN_ON_ONCE(trans->msg_type != NFT_MSG_NEWSETELEM &&
428+
trans->msg_type != NFT_MSG_DELSETELEM);
429+
430+
might_alloc(gfp);
431+
432+
nft_trans_commit_list_add_tail(net, trans);
433+
}
434+
424435
static int nft_trans_table_add(struct nft_ctx *ctx, int msg_type)
425436
{
426437
struct nft_trans *trans;
@@ -7205,7 +7216,7 @@ static int nft_add_set_elem(struct nft_ctx *ctx, struct nft_set *set,
72057216
if (update_flags) {
72067217
nft_trans_elem_priv(trans) = elem_priv;
72077218
nft_trans_elem_update_flags(trans) = update_flags;
7208-
nft_trans_commit_list_add_tail(ctx->net, trans);
7219+
nft_trans_commit_list_add_elem(ctx->net, trans, GFP_KERNEL);
72097220
goto err_elem_free;
72107221
}
72117222
}
@@ -7229,7 +7240,7 @@ static int nft_add_set_elem(struct nft_ctx *ctx, struct nft_set *set,
72297240
}
72307241

72317242
nft_trans_elem_priv(trans) = elem.priv;
7232-
nft_trans_commit_list_add_tail(ctx->net, trans);
7243+
nft_trans_commit_list_add_elem(ctx->net, trans, GFP_KERNEL);
72337244
return 0;
72347245

72357246
err_set_full:
@@ -7446,7 +7457,7 @@ static int nft_del_setelem(struct nft_ctx *ctx, struct nft_set *set,
74467457
nft_setelem_data_deactivate(ctx->net, set, elem.priv);
74477458

74487459
nft_trans_elem_priv(trans) = elem.priv;
7449-
nft_trans_commit_list_add_tail(ctx->net, trans);
7460+
nft_trans_commit_list_add_elem(ctx->net, trans, GFP_KERNEL);
74507461
return 0;
74517462

74527463
fail_ops:
@@ -7482,7 +7493,7 @@ static int nft_setelem_flush(const struct nft_ctx *ctx,
74827493
nft_setelem_data_deactivate(ctx->net, set, elem_priv);
74837494
nft_trans_elem_set(trans) = set;
74847495
nft_trans_elem_priv(trans) = elem_priv;
7485-
nft_trans_commit_list_add_tail(ctx->net, trans);
7496+
nft_trans_commit_list_add_elem(ctx->net, trans, GFP_ATOMIC);
74867497

74877498
return 0;
74887499
}
@@ -7499,7 +7510,7 @@ static int __nft_set_catchall_flush(const struct nft_ctx *ctx,
74997510

75007511
nft_setelem_data_deactivate(ctx->net, set, elem_priv);
75017512
nft_trans_elem_priv(trans) = elem_priv;
7502-
nft_trans_commit_list_add_tail(ctx->net, trans);
7513+
nft_trans_commit_list_add_elem(ctx->net, trans, GFP_KERNEL);
75037514

75047515
return 0;
75057516
}

0 commit comments

Comments
 (0)