Skip to content

Commit

Permalink
netfilter: add nf_static_key_{inc,dec}
Browse files Browse the repository at this point in the history
Add helper functions increment and decrement the hook static keys.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
  • Loading branch information
Pablo Neira Ayuso committed Oct 11, 2020
1 parent 073b04e commit afd9024
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions net/netfilter/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,20 @@ nf_hook_entry_head(struct net *net, int pf, unsigned int hooknum,
return NULL;
}

static void nf_static_key_inc(const struct nf_hook_ops *reg, int pf)
{
#ifdef CONFIG_JUMP_LABEL
static_key_slow_inc(&nf_hooks_needed[pf][reg->hooknum]);
#endif
}

static void nf_static_key_dec(const struct nf_hook_ops *reg, int pf)
{
#ifdef CONFIG_JUMP_LABEL
static_key_slow_dec(&nf_hooks_needed[pf][reg->hooknum]);
#endif
}

static int __nf_register_net_hook(struct net *net, int pf,
const struct nf_hook_ops *reg)
{
Expand Down Expand Up @@ -348,9 +362,8 @@ static int __nf_register_net_hook(struct net *net, int pf,
if (pf == NFPROTO_NETDEV && reg->hooknum == NF_NETDEV_INGRESS)
net_inc_ingress_queue();
#endif
#ifdef CONFIG_JUMP_LABEL
static_key_slow_inc(&nf_hooks_needed[pf][reg->hooknum]);
#endif
nf_static_key_inc(reg, pf);

BUG_ON(p == new_hooks);
nf_hook_entries_free(p);
return 0;
Expand Down Expand Up @@ -406,9 +419,7 @@ static void __nf_unregister_net_hook(struct net *net, int pf,
if (pf == NFPROTO_NETDEV && reg->hooknum == NF_NETDEV_INGRESS)
net_dec_ingress_queue();
#endif
#ifdef CONFIG_JUMP_LABEL
static_key_slow_dec(&nf_hooks_needed[pf][reg->hooknum]);
#endif
nf_static_key_dec(reg, pf);
} else {
WARN_ONCE(1, "hook not found, pf %d num %d", pf, reg->hooknum);
}
Expand Down

0 comments on commit afd9024

Please sign in to comment.