Commit f323d954 authored by Pablo Neira Ayuso's avatar Pablo Neira Ayuso

netfilter: nf_tables: add nft_is_base_chain() helper

This new helper function allows us to check if this is a basechain.
Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
parent 6f14f443
...@@ -911,6 +911,11 @@ static inline struct nft_base_chain *nft_base_chain(const struct nft_chain *chai ...@@ -911,6 +911,11 @@ static inline struct nft_base_chain *nft_base_chain(const struct nft_chain *chai
return container_of(chain, struct nft_base_chain, chain); return container_of(chain, struct nft_base_chain, chain);
} }
static inline bool nft_is_base_chain(const struct nft_chain *chain)
{
return chain->flags & NFT_BASE_CHAIN;
}
int __nft_release_basechain(struct nft_ctx *ctx); int __nft_release_basechain(struct nft_ctx *ctx);
unsigned int nft_do_chain(struct nft_pktinfo *pkt, void *priv); unsigned int nft_do_chain(struct nft_pktinfo *pkt, void *priv);
......
...@@ -144,7 +144,7 @@ static int nf_tables_register_hooks(struct net *net, ...@@ -144,7 +144,7 @@ static int nf_tables_register_hooks(struct net *net,
unsigned int hook_nops) unsigned int hook_nops)
{ {
if (table->flags & NFT_TABLE_F_DORMANT || if (table->flags & NFT_TABLE_F_DORMANT ||
!(chain->flags & NFT_BASE_CHAIN)) !nft_is_base_chain(chain))
return 0; return 0;
return nf_register_net_hooks(net, nft_base_chain(chain)->ops, return nf_register_net_hooks(net, nft_base_chain(chain)->ops,
...@@ -157,7 +157,7 @@ static void nf_tables_unregister_hooks(struct net *net, ...@@ -157,7 +157,7 @@ static void nf_tables_unregister_hooks(struct net *net,
unsigned int hook_nops) unsigned int hook_nops)
{ {
if (table->flags & NFT_TABLE_F_DORMANT || if (table->flags & NFT_TABLE_F_DORMANT ||
!(chain->flags & NFT_BASE_CHAIN)) !nft_is_base_chain(chain))
return; return;
nf_unregister_net_hooks(net, nft_base_chain(chain)->ops, hook_nops); nf_unregister_net_hooks(net, nft_base_chain(chain)->ops, hook_nops);
...@@ -587,7 +587,7 @@ static void _nf_tables_table_disable(struct net *net, ...@@ -587,7 +587,7 @@ static void _nf_tables_table_disable(struct net *net,
list_for_each_entry(chain, &table->chains, list) { list_for_each_entry(chain, &table->chains, list) {
if (!nft_is_active_next(net, chain)) if (!nft_is_active_next(net, chain))
continue; continue;
if (!(chain->flags & NFT_BASE_CHAIN)) if (!nft_is_base_chain(chain))
continue; continue;
if (cnt && i++ == cnt) if (cnt && i++ == cnt)
...@@ -608,7 +608,7 @@ static int nf_tables_table_enable(struct net *net, ...@@ -608,7 +608,7 @@ static int nf_tables_table_enable(struct net *net,
list_for_each_entry(chain, &table->chains, list) { list_for_each_entry(chain, &table->chains, list) {
if (!nft_is_active_next(net, chain)) if (!nft_is_active_next(net, chain))
continue; continue;
if (!(chain->flags & NFT_BASE_CHAIN)) if (!nft_is_base_chain(chain))
continue; continue;
err = nf_register_net_hooks(net, nft_base_chain(chain)->ops, err = nf_register_net_hooks(net, nft_base_chain(chain)->ops,
...@@ -1007,7 +1007,7 @@ static int nf_tables_fill_chain_info(struct sk_buff *skb, struct net *net, ...@@ -1007,7 +1007,7 @@ static int nf_tables_fill_chain_info(struct sk_buff *skb, struct net *net,
if (nla_put_string(skb, NFTA_CHAIN_NAME, chain->name)) if (nla_put_string(skb, NFTA_CHAIN_NAME, chain->name))
goto nla_put_failure; goto nla_put_failure;
if (chain->flags & NFT_BASE_CHAIN) { if (nft_is_base_chain(chain)) {
const struct nft_base_chain *basechain = nft_base_chain(chain); const struct nft_base_chain *basechain = nft_base_chain(chain);
const struct nf_hook_ops *ops = &basechain->ops[0]; const struct nf_hook_ops *ops = &basechain->ops[0];
struct nlattr *nest; struct nlattr *nest;
...@@ -1226,7 +1226,7 @@ static void nf_tables_chain_destroy(struct nft_chain *chain) ...@@ -1226,7 +1226,7 @@ static void nf_tables_chain_destroy(struct nft_chain *chain)
{ {
BUG_ON(chain->use > 0); BUG_ON(chain->use > 0);
if (chain->flags & NFT_BASE_CHAIN) { if (nft_is_base_chain(chain)) {
struct nft_base_chain *basechain = nft_base_chain(chain); struct nft_base_chain *basechain = nft_base_chain(chain);
module_put(basechain->type->owner); module_put(basechain->type->owner);
...@@ -1364,8 +1364,8 @@ static int nf_tables_newchain(struct net *net, struct sock *nlsk, ...@@ -1364,8 +1364,8 @@ static int nf_tables_newchain(struct net *net, struct sock *nlsk,
} }
if (nla[NFTA_CHAIN_POLICY]) { if (nla[NFTA_CHAIN_POLICY]) {
if ((chain != NULL && if (chain != NULL &&
!(chain->flags & NFT_BASE_CHAIN))) !nft_is_base_chain(chain))
return -EOPNOTSUPP; return -EOPNOTSUPP;
if (chain == NULL && if (chain == NULL &&
...@@ -1396,7 +1396,7 @@ static int nf_tables_newchain(struct net *net, struct sock *nlsk, ...@@ -1396,7 +1396,7 @@ static int nf_tables_newchain(struct net *net, struct sock *nlsk,
struct nft_chain_hook hook; struct nft_chain_hook hook;
struct nf_hook_ops *ops; struct nf_hook_ops *ops;
if (!(chain->flags & NFT_BASE_CHAIN)) if (!nft_is_base_chain(chain))
return -EBUSY; return -EBUSY;
err = nft_chain_parse_hook(net, nla, afi, &hook, err = nft_chain_parse_hook(net, nla, afi, &hook,
...@@ -1433,7 +1433,7 @@ static int nf_tables_newchain(struct net *net, struct sock *nlsk, ...@@ -1433,7 +1433,7 @@ static int nf_tables_newchain(struct net *net, struct sock *nlsk,
} }
if (nla[NFTA_CHAIN_COUNTERS]) { if (nla[NFTA_CHAIN_COUNTERS]) {
if (!(chain->flags & NFT_BASE_CHAIN)) if (!nft_is_base_chain(chain))
return -EOPNOTSUPP; return -EOPNOTSUPP;
stats = nft_stats_alloc(nla[NFTA_CHAIN_COUNTERS]); stats = nft_stats_alloc(nla[NFTA_CHAIN_COUNTERS]);
...@@ -4708,7 +4708,7 @@ static void nft_chain_commit_update(struct nft_trans *trans) ...@@ -4708,7 +4708,7 @@ static void nft_chain_commit_update(struct nft_trans *trans)
if (nft_trans_chain_name(trans)[0]) if (nft_trans_chain_name(trans)[0])
strcpy(trans->ctx.chain->name, nft_trans_chain_name(trans)); strcpy(trans->ctx.chain->name, nft_trans_chain_name(trans));
if (!(trans->ctx.chain->flags & NFT_BASE_CHAIN)) if (!nft_is_base_chain(trans->ctx.chain))
return; return;
basechain = nft_base_chain(trans->ctx.chain); basechain = nft_base_chain(trans->ctx.chain);
...@@ -5022,7 +5022,7 @@ int nft_chain_validate_dependency(const struct nft_chain *chain, ...@@ -5022,7 +5022,7 @@ int nft_chain_validate_dependency(const struct nft_chain *chain,
{ {
const struct nft_base_chain *basechain; const struct nft_base_chain *basechain;
if (chain->flags & NFT_BASE_CHAIN) { if (nft_is_base_chain(chain)) {
basechain = nft_base_chain(chain); basechain = nft_base_chain(chain);
if (basechain->type->type != type) if (basechain->type->type != type)
return -EOPNOTSUPP; return -EOPNOTSUPP;
...@@ -5036,7 +5036,7 @@ int nft_chain_validate_hooks(const struct nft_chain *chain, ...@@ -5036,7 +5036,7 @@ int nft_chain_validate_hooks(const struct nft_chain *chain,
{ {
struct nft_base_chain *basechain; struct nft_base_chain *basechain;
if (chain->flags & NFT_BASE_CHAIN) { if (nft_is_base_chain(chain)) {
basechain = nft_base_chain(chain); basechain = nft_base_chain(chain);
if ((1 << basechain->ops[0].hooknum) & hook_flags) if ((1 << basechain->ops[0].hooknum) & hook_flags)
...@@ -5345,7 +5345,7 @@ static int nft_verdict_init(const struct nft_ctx *ctx, struct nft_data *data, ...@@ -5345,7 +5345,7 @@ static int nft_verdict_init(const struct nft_ctx *ctx, struct nft_data *data,
tb[NFTA_VERDICT_CHAIN], genmask); tb[NFTA_VERDICT_CHAIN], genmask);
if (IS_ERR(chain)) if (IS_ERR(chain))
return PTR_ERR(chain); return PTR_ERR(chain);
if (chain->flags & NFT_BASE_CHAIN) if (nft_is_base_chain(chain))
return -EOPNOTSUPP; return -EOPNOTSUPP;
chain->use++; chain->use++;
...@@ -5518,7 +5518,7 @@ int __nft_release_basechain(struct nft_ctx *ctx) ...@@ -5518,7 +5518,7 @@ int __nft_release_basechain(struct nft_ctx *ctx)
{ {
struct nft_rule *rule, *nr; struct nft_rule *rule, *nr;
BUG_ON(!(ctx->chain->flags & NFT_BASE_CHAIN)); BUG_ON(!nft_is_base_chain(ctx->chain));
nf_tables_unregister_hooks(ctx->net, ctx->chain->table, ctx->chain, nf_tables_unregister_hooks(ctx->net, ctx->chain->table, ctx->chain,
ctx->afi->nops); ctx->afi->nops);
......
...@@ -128,7 +128,7 @@ static int nf_tables_netdev_event(struct notifier_block *this, ...@@ -128,7 +128,7 @@ static int nf_tables_netdev_event(struct notifier_block *this,
list_for_each_entry(table, &afi->tables, list) { list_for_each_entry(table, &afi->tables, list) {
ctx.table = table; ctx.table = table;
list_for_each_entry_safe(chain, nr, &table->chains, list) { list_for_each_entry_safe(chain, nr, &table->chains, list) {
if (!(chain->flags & NFT_BASE_CHAIN)) if (!nft_is_base_chain(chain))
continue; continue;
ctx.chain = chain; ctx.chain = chain;
......
...@@ -42,7 +42,8 @@ static int nft_compat_chain_validate_dependency(const char *tablename, ...@@ -42,7 +42,8 @@ static int nft_compat_chain_validate_dependency(const char *tablename,
{ {
const struct nft_base_chain *basechain; const struct nft_base_chain *basechain;
if (!tablename || !(chain->flags & NFT_BASE_CHAIN)) if (!tablename ||
!nft_is_base_chain(chain))
return 0; return 0;
basechain = nft_base_chain(chain); basechain = nft_base_chain(chain);
...@@ -165,7 +166,7 @@ nft_target_set_tgchk_param(struct xt_tgchk_param *par, ...@@ -165,7 +166,7 @@ nft_target_set_tgchk_param(struct xt_tgchk_param *par,
par->entryinfo = entry; par->entryinfo = entry;
par->target = target; par->target = target;
par->targinfo = info; par->targinfo = info;
if (ctx->chain->flags & NFT_BASE_CHAIN) { if (nft_is_base_chain(ctx->chain)) {
const struct nft_base_chain *basechain = const struct nft_base_chain *basechain =
nft_base_chain(ctx->chain); nft_base_chain(ctx->chain);
const struct nf_hook_ops *ops = &basechain->ops[0]; const struct nf_hook_ops *ops = &basechain->ops[0];
...@@ -298,7 +299,7 @@ static int nft_target_validate(const struct nft_ctx *ctx, ...@@ -298,7 +299,7 @@ static int nft_target_validate(const struct nft_ctx *ctx,
unsigned int hook_mask = 0; unsigned int hook_mask = 0;
int ret; int ret;
if (ctx->chain->flags & NFT_BASE_CHAIN) { if (nft_is_base_chain(ctx->chain)) {
const struct nft_base_chain *basechain = const struct nft_base_chain *basechain =
nft_base_chain(ctx->chain); nft_base_chain(ctx->chain);
const struct nf_hook_ops *ops = &basechain->ops[0]; const struct nf_hook_ops *ops = &basechain->ops[0];
...@@ -379,7 +380,7 @@ nft_match_set_mtchk_param(struct xt_mtchk_param *par, const struct nft_ctx *ctx, ...@@ -379,7 +380,7 @@ nft_match_set_mtchk_param(struct xt_mtchk_param *par, const struct nft_ctx *ctx,
par->entryinfo = entry; par->entryinfo = entry;
par->match = match; par->match = match;
par->matchinfo = info; par->matchinfo = info;
if (ctx->chain->flags & NFT_BASE_CHAIN) { if (nft_is_base_chain(ctx->chain)) {
const struct nft_base_chain *basechain = const struct nft_base_chain *basechain =
nft_base_chain(ctx->chain); nft_base_chain(ctx->chain);
const struct nf_hook_ops *ops = &basechain->ops[0]; const struct nf_hook_ops *ops = &basechain->ops[0];
...@@ -477,7 +478,7 @@ static int nft_match_validate(const struct nft_ctx *ctx, ...@@ -477,7 +478,7 @@ static int nft_match_validate(const struct nft_ctx *ctx,
unsigned int hook_mask = 0; unsigned int hook_mask = 0;
int ret; int ret;
if (ctx->chain->flags & NFT_BASE_CHAIN) { if (nft_is_base_chain(ctx->chain)) {
const struct nft_base_chain *basechain = const struct nft_base_chain *basechain =
nft_base_chain(ctx->chain); nft_base_chain(ctx->chain);
const struct nf_hook_ops *ops = &basechain->ops[0]; const struct nf_hook_ops *ops = &basechain->ops[0];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment