Harald Welte | f9e815b | 2005-08-09 19:30:24 -0700 | [diff] [blame] | 1 | #ifndef _NFNETLINK_H |
| 2 | #define _NFNETLINK_H |
Patrick McHardy | ac6d439 | 2005-08-14 19:29:52 -0700 | [diff] [blame] | 3 | |
Harald Welte | f9e815b | 2005-08-09 19:30:24 -0700 | [diff] [blame] | 4 | |
Harald Welte | 080774a | 2005-08-09 19:32:58 -0700 | [diff] [blame] | 5 | #include <linux/netlink.h> |
Harald Welte | f9e815b | 2005-08-09 19:30:24 -0700 | [diff] [blame] | 6 | #include <linux/capability.h> |
Patrick McHardy | df6fb86 | 2007-09-28 14:37:03 -0700 | [diff] [blame] | 7 | #include <net/netlink.h> |
David Howells | 94d0ec5 | 2012-10-09 09:48:54 +0100 | [diff] [blame] | 8 | #include <uapi/linux/netfilter/nfnetlink.h> |
Harald Welte | f9e815b | 2005-08-09 19:30:24 -0700 | [diff] [blame] | 9 | |
Eric Dumazet | d94d9fe | 2009-11-04 09:50:58 -0800 | [diff] [blame] | 10 | struct nfnl_callback { |
Harald Welte | f9e815b | 2005-08-09 19:30:24 -0700 | [diff] [blame] | 11 | int (*call)(struct sock *nl, struct sk_buff *skb, |
Patrick McHardy | 3993832 | 2009-08-25 16:07:58 +0200 | [diff] [blame] | 12 | const struct nlmsghdr *nlh, |
| 13 | const struct nlattr * const cda[]); |
Eric Dumazet | 6b75e3e | 2011-07-18 16:08:07 +0200 | [diff] [blame] | 14 | int (*call_rcu)(struct sock *nl, struct sk_buff *skb, |
| 15 | const struct nlmsghdr *nlh, |
| 16 | const struct nlattr * const cda[]); |
Pablo Neira Ayuso | 0628b12 | 2013-10-14 11:05:33 +0200 | [diff] [blame] | 17 | int (*call_batch)(struct sock *nl, struct sk_buff *skb, |
| 18 | const struct nlmsghdr *nlh, |
| 19 | const struct nlattr * const cda[]); |
Patrick McHardy | e373057 | 2007-09-28 14:38:52 -0700 | [diff] [blame] | 20 | const struct nla_policy *policy; /* netlink attribute policy */ |
| 21 | const u_int16_t attr_count; /* number of nlattr's */ |
Harald Welte | f9e815b | 2005-08-09 19:30:24 -0700 | [diff] [blame] | 22 | }; |
| 23 | |
Eric Dumazet | d94d9fe | 2009-11-04 09:50:58 -0800 | [diff] [blame] | 24 | struct nfnetlink_subsystem { |
Harald Welte | f9e815b | 2005-08-09 19:30:24 -0700 | [diff] [blame] | 25 | const char *name; |
Patrick McHardy | 7c8d4cb | 2007-09-28 14:15:45 -0700 | [diff] [blame] | 26 | __u8 subsys_id; /* nfnetlink subsystem ID */ |
| 27 | __u8 cb_count; /* number of callbacks */ |
| 28 | const struct nfnl_callback *cb; /* callback for individual types */ |
Pablo Neira Ayuso | 0628b12 | 2013-10-14 11:05:33 +0200 | [diff] [blame] | 29 | int (*commit)(struct sk_buff *skb); |
| 30 | int (*abort)(struct sk_buff *skb); |
Harald Welte | f9e815b | 2005-08-09 19:30:24 -0700 | [diff] [blame] | 31 | }; |
| 32 | |
Joe Perches | a0f4ecf | 2013-09-26 14:48:15 -0700 | [diff] [blame] | 33 | int nfnetlink_subsys_register(const struct nfnetlink_subsystem *n); |
| 34 | int nfnetlink_subsys_unregister(const struct nfnetlink_subsystem *n); |
Harald Welte | f9e815b | 2005-08-09 19:30:24 -0700 | [diff] [blame] | 35 | |
Joe Perches | a0f4ecf | 2013-09-26 14:48:15 -0700 | [diff] [blame] | 36 | int nfnetlink_has_listeners(struct net *net, unsigned int group); |
| 37 | struct sk_buff *nfnetlink_alloc_skb(struct net *net, unsigned int size, |
| 38 | u32 dst_portid, gfp_t gfp_mask); |
| 39 | int nfnetlink_send(struct sk_buff *skb, struct net *net, u32 portid, |
| 40 | unsigned int group, int echo, gfp_t flags); |
| 41 | int nfnetlink_set_err(struct net *net, u32 portid, u32 group, int error); |
| 42 | int nfnetlink_unicast(struct sk_buff *skb, struct net *net, u32 portid, |
| 43 | int flags); |
Harald Welte | f9e815b | 2005-08-09 19:30:24 -0700 | [diff] [blame] | 44 | |
Joe Perches | a0f4ecf | 2013-09-26 14:48:15 -0700 | [diff] [blame] | 45 | void nfnl_lock(__u8 subsys_id); |
| 46 | void nfnl_unlock(__u8 subsys_id); |
Patrick McHardy | 0eb5db7 | 2014-02-18 18:06:48 +0000 | [diff] [blame] | 47 | #ifdef CONFIG_PROVE_LOCKING |
| 48 | int lockdep_nfnl_is_held(__u8 subsys_id); |
| 49 | #else |
| 50 | static inline int lockdep_nfnl_is_held(__u8 subsys_id) |
| 51 | { |
| 52 | return 1; |
| 53 | } |
| 54 | #endif /* CONFIG_PROVE_LOCKING */ |
| 55 | |
| 56 | /* |
| 57 | * nfnl_dereference - fetch RCU pointer when updates are prevented by subsys mutex |
| 58 | * |
| 59 | * @p: The pointer to read, prior to dereferencing |
| 60 | * @ss: The nfnetlink subsystem ID |
| 61 | * |
| 62 | * Return the value of the specified RCU-protected pointer, but omit |
| 63 | * both the smp_read_barrier_depends() and the ACCESS_ONCE(), because |
| 64 | * caller holds the NFNL subsystem mutex. |
| 65 | */ |
| 66 | #define nfnl_dereference(p, ss) \ |
| 67 | rcu_dereference_protected(p, lockdep_nfnl_is_held(ss)) |
Pablo Neira Ayuso | e6a7d3c | 2008-10-14 11:58:31 -0700 | [diff] [blame] | 68 | |
Harald Welte | 0ab43f8 | 2005-08-09 19:43:44 -0700 | [diff] [blame] | 69 | #define MODULE_ALIAS_NFNL_SUBSYS(subsys) \ |
| 70 | MODULE_ALIAS("nfnetlink-subsys-" __stringify(subsys)) |
| 71 | |
Harald Welte | f9e815b | 2005-08-09 19:30:24 -0700 | [diff] [blame] | 72 | #endif /* _NFNETLINK_H */ |