xref: /OK3568_Linux_fs/kernel/include/linux/netfilter/nfnetlink.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _NFNETLINK_H
3 #define _NFNETLINK_H
4 
5 #include <linux/netlink.h>
6 #include <linux/capability.h>
7 #include <linux/android_kabi.h>
8 #include <net/netlink.h>
9 #include <uapi/linux/netfilter/nfnetlink.h>
10 
11 struct nfnl_callback {
12 	int (*call)(struct net *net, struct sock *nl, struct sk_buff *skb,
13 		    const struct nlmsghdr *nlh,
14 		    const struct nlattr * const cda[],
15 		    struct netlink_ext_ack *extack);
16 	int (*call_rcu)(struct net *net, struct sock *nl, struct sk_buff *skb,
17 			const struct nlmsghdr *nlh,
18 			const struct nlattr * const cda[],
19 			struct netlink_ext_ack *extack);
20 	int (*call_batch)(struct net *net, struct sock *nl, struct sk_buff *skb,
21 			  const struct nlmsghdr *nlh,
22 			  const struct nlattr * const cda[],
23 			  struct netlink_ext_ack *extack);
24 	const struct nla_policy *policy;	/* netlink attribute policy */
25 	const u_int16_t attr_count;		/* number of nlattr's */
26 
27 	ANDROID_KABI_RESERVE(1);
28 };
29 
30 enum nfnl_abort_action {
31 	NFNL_ABORT_NONE		= 0,
32 	NFNL_ABORT_AUTOLOAD,
33 	NFNL_ABORT_VALIDATE,
34 };
35 
36 struct nfnetlink_subsystem {
37 	const char *name;
38 	__u8 subsys_id;			/* nfnetlink subsystem ID */
39 	__u8 cb_count;			/* number of callbacks */
40 	const struct nfnl_callback *cb;	/* callback for individual types */
41 	struct module *owner;
42 	int (*commit)(struct net *net, struct sk_buff *skb);
43 	int (*abort)(struct net *net, struct sk_buff *skb,
44 		     enum nfnl_abort_action action);
45 	void (*cleanup)(struct net *net);
46 	bool (*valid_genid)(struct net *net, u32 genid);
47 
48 	ANDROID_KABI_RESERVE(1);
49 };
50 
51 int nfnetlink_subsys_register(const struct nfnetlink_subsystem *n);
52 int nfnetlink_subsys_unregister(const struct nfnetlink_subsystem *n);
53 
54 int nfnetlink_has_listeners(struct net *net, unsigned int group);
55 int nfnetlink_send(struct sk_buff *skb, struct net *net, u32 portid,
56 		   unsigned int group, int echo, gfp_t flags);
57 int nfnetlink_set_err(struct net *net, u32 portid, u32 group, int error);
58 int nfnetlink_unicast(struct sk_buff *skb, struct net *net, u32 portid);
59 
nfnl_msg_type(u8 subsys,u8 msg_type)60 static inline u16 nfnl_msg_type(u8 subsys, u8 msg_type)
61 {
62 	return subsys << 8 | msg_type;
63 }
64 
nfnl_fill_hdr(struct nlmsghdr * nlh,u8 family,u8 version,__be16 res_id)65 static inline void nfnl_fill_hdr(struct nlmsghdr *nlh, u8 family, u8 version,
66 				 __be16 res_id)
67 {
68 	struct nfgenmsg *nfmsg;
69 
70 	nfmsg = nlmsg_data(nlh);
71 	nfmsg->nfgen_family = family;
72 	nfmsg->version = version;
73 	nfmsg->res_id = res_id;
74 }
75 
nfnl_msg_put(struct sk_buff * skb,u32 portid,u32 seq,int type,int flags,u8 family,u8 version,__be16 res_id)76 static inline struct nlmsghdr *nfnl_msg_put(struct sk_buff *skb, u32 portid,
77 					    u32 seq, int type, int flags,
78 					    u8 family, u8 version,
79 					    __be16 res_id)
80 {
81 	struct nlmsghdr *nlh;
82 
83 	nlh = nlmsg_put(skb, portid, seq, type, sizeof(struct nfgenmsg), flags);
84 	if (!nlh)
85 		return NULL;
86 
87 	nfnl_fill_hdr(nlh, family, version, res_id);
88 
89 	return nlh;
90 }
91 
92 void nfnl_lock(__u8 subsys_id);
93 void nfnl_unlock(__u8 subsys_id);
94 #ifdef CONFIG_PROVE_LOCKING
95 bool lockdep_nfnl_is_held(__u8 subsys_id);
96 #else
lockdep_nfnl_is_held(__u8 subsys_id)97 static inline bool lockdep_nfnl_is_held(__u8 subsys_id)
98 {
99 	return true;
100 }
101 #endif /* CONFIG_PROVE_LOCKING */
102 
103 #define MODULE_ALIAS_NFNL_SUBSYS(subsys) \
104 	MODULE_ALIAS("nfnetlink-subsys-" __stringify(subsys))
105 
106 #endif	/* _NFNETLINK_H */
107