Skip to content

Commit a2f538f

Browse files
committed
netfilter: nf_tables: add nft_chain_add()
jira VUlN-429 subsystem-sync netfilter:nf_tables 4.18.0-511 commit-author Pablo Neira Ayuso <pablo@netfilter.org> commit 04b7db4 upstream-diff same as most in this series, patch looks identical but has offset fuzz. This patch adds a helper function to add the chain to the hashtable and the chain list. Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org> (cherry picked from commit 04b7db4) Signed-off-by: Greg Rose <g.v.rose@ciq.com>
1 parent 3f2fa28 commit a2f538f

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

net/netfilter/nf_tables_api.c

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1986,6 +1986,20 @@ static int nft_basechain_init(struct nft_base_chain *basechain, u8 family,
19861986
return 0;
19871987
}
19881988

1989+
static int nft_chain_add(struct nft_table *table, struct nft_chain *chain)
1990+
{
1991+
int err;
1992+
1993+
err = rhltable_insert_key(&table->chains_ht, chain->name,
1994+
&chain->rhlhead, nft_chain_ht_params);
1995+
if (err)
1996+
return err;
1997+
1998+
list_add_tail_rcu(&chain->list, &table->chains);
1999+
2000+
return 0;
2001+
}
2002+
19892003
static int nf_tables_addchain(struct nft_ctx *ctx, u8 family, u8 genmask,
19902004
u8 policy, u32 flags)
19912005
{
@@ -2065,26 +2079,23 @@ static int nf_tables_addchain(struct nft_ctx *ctx, u8 family, u8 genmask,
20652079
if (err < 0)
20662080
goto err1;
20672081

2068-
err = rhltable_insert_key(&table->chains_ht, chain->name,
2069-
&chain->rhlhead, nft_chain_ht_params);
2070-
if (err)
2071-
goto err2;
2072-
20732082
trans = nft_trans_chain_add(ctx, NFT_MSG_NEWCHAIN);
20742083
if (IS_ERR(trans)) {
20752084
err = PTR_ERR(trans);
2076-
rhltable_remove(&table->chains_ht, &chain->rhlhead,
2077-
nft_chain_ht_params);
20782085
goto err2;
20792086
}
20802087

20812088
nft_trans_chain_policy(trans) = NFT_CHAIN_POLICY_UNSET;
20822089
if (nft_is_base_chain(chain))
20832090
nft_trans_chain_policy(trans) = policy;
20842091

2092+
err = nft_chain_add(table, chain);
2093+
if (err < 0) {
2094+
nft_trans_destroy(trans);
2095+
goto err2;
2096+
}
20852097

20862098
table->use++;
2087-
list_add_tail_rcu(&chain->list, &table->chains);
20882099

20892100
return 0;
20902101
err2:

0 commit comments

Comments
 (0)