Skip to content

Commit bbd6819

Browse files
Florian Westphalgregkh
authored andcommitted
netfilter: nf_tables: pass nft_chain to destroy function, not nft_ctx
commit 8965d42bcf54d42cbc72fe34a9d0ec3f8527debd upstream. It would be better to not store nft_ctx inside nft_trans object, the netlink ctx strucutre is huge and most of its information is never needed in places that use trans->ctx. Avoid/reduce its usage if possible, no runtime behaviour change intended. Signed-off-by: Florian Westphal <[email protected]> Signed-off-by: Pablo Neira Ayuso <[email protected]> Stable-dep-of: c03d278fdf35 ("netfilter: nf_tables: wait for rcu grace period on net_device removal") Signed-off-by: Sasha Levin <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 18eb53a commit bbd6819

File tree

3 files changed

+10
-11
lines changed

3 files changed

+10
-11
lines changed

include/net/netfilter/nf_tables.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1121,7 +1121,7 @@ static inline bool nft_chain_is_bound(struct nft_chain *chain)
11211121

11221122
int nft_chain_add(struct nft_table *table, struct nft_chain *chain);
11231123
void nft_chain_del(struct nft_chain *chain);
1124-
void nf_tables_chain_destroy(struct nft_ctx *ctx);
1124+
void nf_tables_chain_destroy(struct nft_chain *chain);
11251125

11261126
struct nft_stats {
11271127
u64 bytes;

net/netfilter/nf_tables_api.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2034,9 +2034,9 @@ static void nf_tables_chain_free_chain_rules(struct nft_chain *chain)
20342034
kvfree(chain->blob_next);
20352035
}
20362036

2037-
void nf_tables_chain_destroy(struct nft_ctx *ctx)
2037+
void nf_tables_chain_destroy(struct nft_chain *chain)
20382038
{
2039-
struct nft_chain *chain = ctx->chain;
2039+
const struct nft_table *table = chain->table;
20402040
struct nft_hook *hook, *next;
20412041

20422042
if (WARN_ON(chain->use > 0))
@@ -2048,7 +2048,7 @@ void nf_tables_chain_destroy(struct nft_ctx *ctx)
20482048
if (nft_is_base_chain(chain)) {
20492049
struct nft_base_chain *basechain = nft_base_chain(chain);
20502050

2051-
if (nft_base_chain_netdev(ctx->family, basechain->ops.hooknum)) {
2051+
if (nft_base_chain_netdev(table->family, basechain->ops.hooknum)) {
20522052
list_for_each_entry_safe(hook, next,
20532053
&basechain->hook_list, list) {
20542054
list_del_rcu(&hook->list);
@@ -2515,7 +2515,7 @@ static int nf_tables_addchain(struct nft_ctx *ctx, u8 family, u8 genmask,
25152515
err_trans:
25162516
nft_use_dec_restore(&table->use);
25172517
err_destroy_chain:
2518-
nf_tables_chain_destroy(ctx);
2518+
nf_tables_chain_destroy(chain);
25192519

25202520
return err;
25212521
}
@@ -8994,7 +8994,7 @@ static void nft_commit_release(struct nft_trans *trans)
89948994
kfree(nft_trans_chain_name(trans));
89958995
break;
89968996
case NFT_MSG_DELCHAIN:
8997-
nf_tables_chain_destroy(&trans->ctx);
8997+
nf_tables_chain_destroy(nft_trans_chain(trans));
89988998
break;
89998999
case NFT_MSG_DELRULE:
90009000
nf_tables_rule_destroy(&trans->ctx, nft_trans_rule(trans));
@@ -9955,7 +9955,7 @@ static void nf_tables_abort_release(struct nft_trans *trans)
99559955
nf_tables_table_destroy(&trans->ctx);
99569956
break;
99579957
case NFT_MSG_NEWCHAIN:
9958-
nf_tables_chain_destroy(&trans->ctx);
9958+
nf_tables_chain_destroy(nft_trans_chain(trans));
99599959
break;
99609960
case NFT_MSG_NEWRULE:
99619961
nf_tables_rule_destroy(&trans->ctx, nft_trans_rule(trans));
@@ -10677,7 +10677,7 @@ int __nft_release_basechain(struct nft_ctx *ctx)
1067710677
}
1067810678
nft_chain_del(ctx->chain);
1067910679
nft_use_dec(&ctx->table->use);
10680-
nf_tables_chain_destroy(ctx);
10680+
nf_tables_chain_destroy(ctx->chain);
1068110681

1068210682
return 0;
1068310683
}
@@ -10753,10 +10753,9 @@ static void __nft_release_table(struct net *net, struct nft_table *table)
1075310753
nft_obj_destroy(&ctx, obj);
1075410754
}
1075510755
list_for_each_entry_safe(chain, nc, &table->chains, list) {
10756-
ctx.chain = chain;
1075710756
nft_chain_del(chain);
1075810757
nft_use_dec(&table->use);
10759-
nf_tables_chain_destroy(&ctx);
10758+
nf_tables_chain_destroy(chain);
1076010759
}
1076110760
nf_tables_table_destroy(&ctx);
1076210761
}

net/netfilter/nft_immediate.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ static void nft_immediate_destroy(const struct nft_ctx *ctx,
221221
list_del(&rule->list);
222222
nf_tables_rule_destroy(&chain_ctx, rule);
223223
}
224-
nf_tables_chain_destroy(&chain_ctx);
224+
nf_tables_chain_destroy(chain);
225225
break;
226226
default:
227227
break;

0 commit comments

Comments
 (0)