Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/klassert/ipsec...
[linux-2.6/btrfs-unstable.git] / include / linux / netfilter_ingress.h
blob554c920691dd297ca74df0770c6df40eba5f30c6
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _NETFILTER_INGRESS_H_
3 #define _NETFILTER_INGRESS_H_
5 #include <linux/netfilter.h>
6 #include <linux/netdevice.h>
8 #ifdef CONFIG_NETFILTER_INGRESS
9 static inline bool nf_hook_ingress_active(const struct sk_buff *skb)
11 #ifdef HAVE_JUMP_LABEL
12 if (!static_key_false(&nf_hooks_needed[NFPROTO_NETDEV][NF_NETDEV_INGRESS]))
13 return false;
14 #endif
15 return rcu_access_pointer(skb->dev->nf_hooks_ingress);
18 /* caller must hold rcu_read_lock */
19 static inline int nf_hook_ingress(struct sk_buff *skb)
21 struct nf_hook_entries *e = rcu_dereference(skb->dev->nf_hooks_ingress);
22 struct nf_hook_state state;
23 int ret;
25 /* Must recheck the ingress hook head, in the event it became NULL
26 * after the check in nf_hook_ingress_active evaluated to true.
28 if (unlikely(!e))
29 return 0;
31 nf_hook_state_init(&state, NF_NETDEV_INGRESS,
32 NFPROTO_NETDEV, skb->dev, NULL, NULL,
33 dev_net(skb->dev), NULL);
34 ret = nf_hook_slow(skb, &state, e, 0);
35 if (ret == 0)
36 return -1;
38 return ret;
41 static inline void nf_hook_ingress_init(struct net_device *dev)
43 RCU_INIT_POINTER(dev->nf_hooks_ingress, NULL);
45 #else /* CONFIG_NETFILTER_INGRESS */
46 static inline int nf_hook_ingress_active(struct sk_buff *skb)
48 return 0;
51 static inline int nf_hook_ingress(struct sk_buff *skb)
53 return 0;
56 static inline void nf_hook_ingress_init(struct net_device *dev) {}
57 #endif /* CONFIG_NETFILTER_INGRESS */
58 #endif /* _NETFILTER_INGRESS_H_ */