blob: e955d47306259c5867d80831bd78d99490849b0b [file] [log] [blame]
Harald Weltef9e815b2005-08-09 19:30:24 -07001#ifndef _NFNETLINK_H
2#define _NFNETLINK_H
Patrick McHardyac6d4392005-08-14 19:29:52 -07003
Harald Weltef9e815b2005-08-09 19:30:24 -07004
Harald Welte080774a2005-08-09 19:32:58 -07005#include <linux/netlink.h>
Harald Weltef9e815b2005-08-09 19:30:24 -07006#include <linux/capability.h>
Patrick McHardydf6fb862007-09-28 14:37:03 -07007#include <net/netlink.h>
David Howells94d0ec52012-10-09 09:48:54 +01008#include <uapi/linux/netfilter/nfnetlink.h>
Harald Weltef9e815b2005-08-09 19:30:24 -07009
Eric Dumazetd94d9fe2009-11-04 09:50:58 -080010struct nfnl_callback {
Harald Weltef9e815b2005-08-09 19:30:24 -070011 int (*call)(struct sock *nl, struct sk_buff *skb,
Patrick McHardy39938322009-08-25 16:07:58 +020012 const struct nlmsghdr *nlh,
13 const struct nlattr * const cda[]);
Eric Dumazet6b75e3e2011-07-18 16:08:07 +020014 int (*call_rcu)(struct sock *nl, struct sk_buff *skb,
15 const struct nlmsghdr *nlh,
16 const struct nlattr * const cda[]);
Pablo Neira Ayuso0628b122013-10-14 11:05:33 +020017 int (*call_batch)(struct sock *nl, struct sk_buff *skb,
18 const struct nlmsghdr *nlh,
19 const struct nlattr * const cda[]);
Patrick McHardye3730572007-09-28 14:38:52 -070020 const struct nla_policy *policy; /* netlink attribute policy */
21 const u_int16_t attr_count; /* number of nlattr's */
Harald Weltef9e815b2005-08-09 19:30:24 -070022};
23
Eric Dumazetd94d9fe2009-11-04 09:50:58 -080024struct nfnetlink_subsystem {
Harald Weltef9e815b2005-08-09 19:30:24 -070025 const char *name;
Patrick McHardy7c8d4cb2007-09-28 14:15:45 -070026 __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 Ayuso0628b122013-10-14 11:05:33 +020029 int (*commit)(struct sk_buff *skb);
30 int (*abort)(struct sk_buff *skb);
Harald Weltef9e815b2005-08-09 19:30:24 -070031};
32
Joe Perchesa0f4ecf2013-09-26 14:48:15 -070033int nfnetlink_subsys_register(const struct nfnetlink_subsystem *n);
34int nfnetlink_subsys_unregister(const struct nfnetlink_subsystem *n);
Harald Weltef9e815b2005-08-09 19:30:24 -070035
Joe Perchesa0f4ecf2013-09-26 14:48:15 -070036int nfnetlink_has_listeners(struct net *net, unsigned int group);
37struct sk_buff *nfnetlink_alloc_skb(struct net *net, unsigned int size,
38 u32 dst_portid, gfp_t gfp_mask);
39int nfnetlink_send(struct sk_buff *skb, struct net *net, u32 portid,
40 unsigned int group, int echo, gfp_t flags);
41int nfnetlink_set_err(struct net *net, u32 portid, u32 group, int error);
42int nfnetlink_unicast(struct sk_buff *skb, struct net *net, u32 portid,
43 int flags);
Harald Weltef9e815b2005-08-09 19:30:24 -070044
Joe Perchesa0f4ecf2013-09-26 14:48:15 -070045void nfnl_lock(__u8 subsys_id);
46void nfnl_unlock(__u8 subsys_id);
Patrick McHardy0eb5db72014-02-18 18:06:48 +000047#ifdef CONFIG_PROVE_LOCKING
48int lockdep_nfnl_is_held(__u8 subsys_id);
49#else
50static 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 Ayusoe6a7d3c2008-10-14 11:58:31 -070068
Harald Welte0ab43f82005-08-09 19:43:44 -070069#define MODULE_ALIAS_NFNL_SUBSYS(subsys) \
70 MODULE_ALIAS("nfnetlink-subsys-" __stringify(subsys))
71
Harald Weltef9e815b2005-08-09 19:30:24 -070072#endif /* _NFNETLINK_H */