nfnetlink.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #ifndef _NFNETLINK_H
  2. #define _NFNETLINK_H
  3. #include <linux/netlink.h>
  4. #include <linux/capability.h>
  5. #include <net/netlink.h>
  6. #include <uapi/linux/netfilter/nfnetlink.h>
  7. struct nfnl_callback {
  8. int (*call)(struct sock *nl, struct sk_buff *skb,
  9. const struct nlmsghdr *nlh,
  10. const struct nlattr * const cda[]);
  11. int (*call_rcu)(struct sock *nl, struct sk_buff *skb,
  12. const struct nlmsghdr *nlh,
  13. const struct nlattr * const cda[]);
  14. int (*call_batch)(struct sock *nl, struct sk_buff *skb,
  15. const struct nlmsghdr *nlh,
  16. const struct nlattr * const cda[]);
  17. const struct nla_policy *policy; /* netlink attribute policy */
  18. const u_int16_t attr_count; /* number of nlattr's */
  19. };
  20. struct nfnetlink_subsystem {
  21. const char *name;
  22. __u8 subsys_id; /* nfnetlink subsystem ID */
  23. __u8 cb_count; /* number of callbacks */
  24. const struct nfnl_callback *cb; /* callback for individual types */
  25. int (*commit)(struct sk_buff *skb);
  26. int (*abort)(struct sk_buff *skb);
  27. };
  28. int nfnetlink_subsys_register(const struct nfnetlink_subsystem *n);
  29. int nfnetlink_subsys_unregister(const struct nfnetlink_subsystem *n);
  30. int nfnetlink_has_listeners(struct net *net, unsigned int group);
  31. struct sk_buff *nfnetlink_alloc_skb(struct net *net, unsigned int size,
  32. u32 dst_portid, gfp_t gfp_mask);
  33. int nfnetlink_send(struct sk_buff *skb, struct net *net, u32 portid,
  34. unsigned int group, int echo, gfp_t flags);
  35. int nfnetlink_set_err(struct net *net, u32 portid, u32 group, int error);
  36. int nfnetlink_unicast(struct sk_buff *skb, struct net *net, u32 portid,
  37. int flags);
  38. void nfnl_lock(__u8 subsys_id);
  39. void nfnl_unlock(__u8 subsys_id);
  40. #ifdef CONFIG_PROVE_LOCKING
  41. int lockdep_nfnl_is_held(__u8 subsys_id);
  42. #else
  43. static inline int lockdep_nfnl_is_held(__u8 subsys_id)
  44. {
  45. return 1;
  46. }
  47. #endif /* CONFIG_PROVE_LOCKING */
  48. /*
  49. * nfnl_dereference - fetch RCU pointer when updates are prevented by subsys mutex
  50. *
  51. * @p: The pointer to read, prior to dereferencing
  52. * @ss: The nfnetlink subsystem ID
  53. *
  54. * Return the value of the specified RCU-protected pointer, but omit
  55. * both the smp_read_barrier_depends() and the ACCESS_ONCE(), because
  56. * caller holds the NFNL subsystem mutex.
  57. */
  58. #define nfnl_dereference(p, ss) \
  59. rcu_dereference_protected(p, lockdep_nfnl_is_held(ss))
  60. #define MODULE_ALIAS_NFNL_SUBSYS(subsys) \
  61. MODULE_ALIAS("nfnetlink-subsys-" __stringify(subsys))
  62. #endif /* _NFNETLINK_H */