]>
Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
f9e815b3 HW |
2 | #ifndef _NFNETLINK_H |
3 | #define _NFNETLINK_H | |
ac6d439d | 4 | |
080774a2 | 5 | #include <linux/netlink.h> |
f9e815b3 | 6 | #include <linux/capability.h> |
df6fb868 | 7 | #include <net/netlink.h> |
94d0ec58 | 8 | #include <uapi/linux/netfilter/nfnetlink.h> |
f9e815b3 | 9 | |
d94d9fee | 10 | struct nfnl_callback { |
7b8002a1 | 11 | int (*call)(struct net *net, struct sock *nl, struct sk_buff *skb, |
6b75e3e8 | 12 | const struct nlmsghdr *nlh, |
04ba724b PNA |
13 | const struct nlattr * const cda[], |
14 | struct netlink_ext_ack *extack); | |
7b8002a1 PNA |
15 | int (*call_rcu)(struct net *net, struct sock *nl, struct sk_buff *skb, |
16 | const struct nlmsghdr *nlh, | |
04ba724b PNA |
17 | const struct nlattr * const cda[], |
18 | struct netlink_ext_ack *extack); | |
633c9a84 | 19 | int (*call_batch)(struct net *net, struct sock *nl, struct sk_buff *skb, |
0628b123 | 20 | const struct nlmsghdr *nlh, |
04ba724b PNA |
21 | const struct nlattr * const cda[], |
22 | struct netlink_ext_ack *extack); | |
e3730578 PM |
23 | const struct nla_policy *policy; /* netlink attribute policy */ |
24 | const u_int16_t attr_count; /* number of nlattr's */ | |
f9e815b3 HW |
25 | }; |
26 | ||
c0391b6a PNA |
27 | enum nfnl_abort_action { |
28 | NFNL_ABORT_NONE = 0, | |
29 | NFNL_ABORT_AUTOLOAD, | |
30 | NFNL_ABORT_VALIDATE, | |
31 | }; | |
32 | ||
d94d9fee | 33 | struct nfnetlink_subsystem { |
f9e815b3 | 34 | const char *name; |
7c8d4cb4 PM |
35 | __u8 subsys_id; /* nfnetlink subsystem ID */ |
36 | __u8 cb_count; /* number of callbacks */ | |
37 | const struct nfnl_callback *cb; /* callback for individual types */ | |
be2ab5b4 | 38 | struct module *owner; |
5913beaf | 39 | int (*commit)(struct net *net, struct sk_buff *skb); |
c0391b6a PNA |
40 | int (*abort)(struct net *net, struct sk_buff *skb, |
41 | enum nfnl_abort_action action); | |
a654de8f | 42 | void (*cleanup)(struct net *net); |
8c4d4e8b | 43 | bool (*valid_genid)(struct net *net, u32 genid); |
f9e815b3 HW |
44 | }; |
45 | ||
a0f4ecf3 JP |
46 | int nfnetlink_subsys_register(const struct nfnetlink_subsystem *n); |
47 | int nfnetlink_subsys_unregister(const struct nfnetlink_subsystem *n); | |
48 | ||
49 | int nfnetlink_has_listeners(struct net *net, unsigned int group); | |
a0f4ecf3 JP |
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); | |
ee921183 | 53 | int nfnetlink_unicast(struct sk_buff *skb, struct net *net, u32 portid); |
a0f4ecf3 | 54 | |
dedb67c4 PNA |
55 | static inline u16 nfnl_msg_type(u8 subsys, u8 msg_type) |
56 | { | |
57 | return subsys << 8 | msg_type; | |
58 | } | |
59 | ||
19c28b13 PNA |
60 | static inline void nfnl_fill_hdr(struct nlmsghdr *nlh, u8 family, u8 version, |
61 | __be16 res_id) | |
62 | { | |
63 | struct nfgenmsg *nfmsg; | |
64 | ||
65 | nfmsg = nlmsg_data(nlh); | |
66 | nfmsg->nfgen_family = family; | |
67 | nfmsg->version = version; | |
68 | nfmsg->res_id = res_id; | |
69 | } | |
70 | ||
71 | static inline struct nlmsghdr *nfnl_msg_put(struct sk_buff *skb, u32 portid, | |
72 | u32 seq, int type, int flags, | |
73 | u8 family, u8 version, | |
74 | __be16 res_id) | |
75 | { | |
76 | struct nlmsghdr *nlh; | |
77 | ||
78 | nlh = nlmsg_put(skb, portid, seq, type, sizeof(struct nfgenmsg), flags); | |
79 | if (!nlh) | |
80 | return NULL; | |
81 | ||
82 | nfnl_fill_hdr(nlh, family, version, res_id); | |
83 | ||
84 | return nlh; | |
85 | } | |
86 | ||
a0f4ecf3 JP |
87 | void nfnl_lock(__u8 subsys_id); |
88 | void nfnl_unlock(__u8 subsys_id); | |
0eb5db7a | 89 | #ifdef CONFIG_PROVE_LOCKING |
875e0829 | 90 | bool lockdep_nfnl_is_held(__u8 subsys_id); |
0eb5db7a | 91 | #else |
875e0829 | 92 | static inline bool lockdep_nfnl_is_held(__u8 subsys_id) |
0eb5db7a | 93 | { |
875e0829 | 94 | return true; |
0eb5db7a PM |
95 | } |
96 | #endif /* CONFIG_PROVE_LOCKING */ | |
97 | ||
0ab43f84 HW |
98 | #define MODULE_ALIAS_NFNL_SUBSYS(subsys) \ |
99 | MODULE_ALIAS("nfnetlink-subsys-" __stringify(subsys)) | |
100 | ||
f9e815b3 | 101 | #endif /* _NFNETLINK_H */ |