Skip to content

Commit 04b7db4

Browse files
committed
netfilter: nf_tables: add nft_chain_add()
This patch adds a helper function to add the chain to the hashtable and the chain list. Signed-off-by: Pablo Neira Ayuso <[email protected]>
1 parent 67c49de commit 04b7db4

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

net/netfilter/nf_tables_api.c

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1914,6 +1914,20 @@ static int nft_basechain_init(struct nft_base_chain *basechain, u8 family,
19141914
return 0;
19151915
}
19161916

1917+
static int nft_chain_add(struct nft_table *table, struct nft_chain *chain)
1918+
{
1919+
int err;
1920+
1921+
err = rhltable_insert_key(&table->chains_ht, chain->name,
1922+
&chain->rhlhead, nft_chain_ht_params);
1923+
if (err)
1924+
return err;
1925+
1926+
list_add_tail_rcu(&chain->list, &table->chains);
1927+
1928+
return 0;
1929+
}
1930+
19171931
static int nf_tables_addchain(struct nft_ctx *ctx, u8 family, u8 genmask,
19181932
u8 policy, u32 flags)
19191933
{
@@ -1991,25 +2005,23 @@ static int nf_tables_addchain(struct nft_ctx *ctx, u8 family, u8 genmask,
19912005
if (err < 0)
19922006
goto err1;
19932007

1994-
err = rhltable_insert_key(&table->chains_ht, chain->name,
1995-
&chain->rhlhead, nft_chain_ht_params);
1996-
if (err)
1997-
goto err2;
1998-
19992008
trans = nft_trans_chain_add(ctx, NFT_MSG_NEWCHAIN);
20002009
if (IS_ERR(trans)) {
20012010
err = PTR_ERR(trans);
2002-
rhltable_remove(&table->chains_ht, &chain->rhlhead,
2003-
nft_chain_ht_params);
20042011
goto err2;
20052012
}
20062013

20072014
nft_trans_chain_policy(trans) = NFT_CHAIN_POLICY_UNSET;
20082015
if (nft_is_base_chain(chain))
20092016
nft_trans_chain_policy(trans) = policy;
20102017

2018+
err = nft_chain_add(table, chain);
2019+
if (err < 0) {
2020+
nft_trans_destroy(trans);
2021+
goto err2;
2022+
}
2023+
20112024
table->use++;
2012-
list_add_tail_rcu(&chain->list, &table->chains);
20132025

20142026
return 0;
20152027
err2:

0 commit comments

Comments
 (0)