netfilter_ingress.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #ifndef _NETFILTER_INGRESS_H_
  2. #define _NETFILTER_INGRESS_H_
  3. #include <linux/netfilter.h>
  4. #include <linux/netdevice.h>
  5. #ifdef CONFIG_NETFILTER_INGRESS
  6. static inline bool nf_hook_ingress_active(const struct sk_buff *skb)
  7. {
  8. #ifdef HAVE_JUMP_LABEL
  9. if (!static_key_false(&nf_hooks_needed[NFPROTO_NETDEV][NF_NETDEV_INGRESS]))
  10. return false;
  11. #endif
  12. return rcu_access_pointer(skb->dev->nf_hooks_ingress);
  13. }
  14. /* caller must hold rcu_read_lock */
  15. static inline int nf_hook_ingress(struct sk_buff *skb)
  16. {
  17. struct nf_hook_entry *e = rcu_dereference(skb->dev->nf_hooks_ingress);
  18. struct nf_hook_state state;
  19. /* Must recheck the ingress hook head, in the event it became NULL
  20. * after the check in nf_hook_ingress_active evaluated to true.
  21. */
  22. if (unlikely(!e))
  23. return 0;
  24. nf_hook_state_init(&state, e, NF_NETDEV_INGRESS, INT_MIN,
  25. NFPROTO_NETDEV, skb->dev, NULL, NULL,
  26. dev_net(skb->dev), NULL);
  27. return nf_hook_slow(skb, &state);
  28. }
  29. static inline void nf_hook_ingress_init(struct net_device *dev)
  30. {
  31. RCU_INIT_POINTER(dev->nf_hooks_ingress, NULL);
  32. }
  33. #else /* CONFIG_NETFILTER_INGRESS */
  34. static inline int nf_hook_ingress_active(struct sk_buff *skb)
  35. {
  36. return 0;
  37. }
  38. static inline int nf_hook_ingress(struct sk_buff *skb)
  39. {
  40. return 0;
  41. }
  42. static inline void nf_hook_ingress_init(struct net_device *dev) {}
  43. #endif /* CONFIG_NETFILTER_INGRESS */
  44. #endif /* _NETFILTER_INGRESS_H_ */