1 /* SPDX-License-Identifier: GPL-2.0 */
5 #include <linux/netlink.h>
6 #include <linux/capability.h>
7 #include <net/netlink.h>
8 #include <uapi/linux/netfilter/nfnetlink.h>
10 struct nfnl_callback {
11 int (*call)(struct net *net, struct sock *nl, struct sk_buff *skb,
12 const struct nlmsghdr *nlh,
13 const struct nlattr * const cda[],
14 struct netlink_ext_ack *extack);
15 int (*call_rcu)(struct net *net, struct sock *nl, struct sk_buff *skb,
16 const struct nlmsghdr *nlh,
17 const struct nlattr * const cda[],
18 struct netlink_ext_ack *extack);
19 int (*call_batch)(struct net *net, struct sock *nl, struct sk_buff *skb,
20 const struct nlmsghdr *nlh,
21 const struct nlattr * const cda[],
22 struct netlink_ext_ack *extack);
23 const struct nla_policy *policy; /* netlink attribute policy */
24 const u_int16_t attr_count; /* number of nlattr's */
27 enum nfnl_abort_action {
33 struct nfnetlink_subsystem {
35 __u8 subsys_id; /* nfnetlink subsystem ID */
36 __u8 cb_count; /* number of callbacks */
37 const struct nfnl_callback *cb; /* callback for individual types */
39 int (*commit)(struct net *net, struct sk_buff *skb);
40 int (*abort)(struct net *net, struct sk_buff *skb,
41 enum nfnl_abort_action action);
42 void (*cleanup)(struct net *net);
43 bool (*valid_genid)(struct net *net, u32 genid);
46 int nfnetlink_subsys_register(const struct nfnetlink_subsystem *n);
47 int nfnetlink_subsys_unregister(const struct nfnetlink_subsystem *n);
49 int nfnetlink_has_listeners(struct net *net, unsigned int group);
50 int nfnetlink_send(struct sk_buff *skb, struct net *net, u32 portid,
51 unsigned int group, int echo, gfp_t flags);
52 int nfnetlink_set_err(struct net *net, u32 portid, u32 group, int error);
53 int nfnetlink_unicast(struct sk_buff *skb, struct net *net, u32 portid);
55 static inline u16 nfnl_msg_type(u8 subsys, u8 msg_type)
57 return subsys << 8 | msg_type;
60 void nfnl_lock(__u8 subsys_id);
61 void nfnl_unlock(__u8 subsys_id);
62 #ifdef CONFIG_PROVE_LOCKING
63 bool lockdep_nfnl_is_held(__u8 subsys_id);
65 static inline bool lockdep_nfnl_is_held(__u8 subsys_id)
69 #endif /* CONFIG_PROVE_LOCKING */
71 #define MODULE_ALIAS_NFNL_SUBSYS(subsys) \
72 MODULE_ALIAS("nfnetlink-subsys-" __stringify(subsys))
74 #endif /* _NFNETLINK_H */