hc
2023-12-08 01573e231f18eb2d99162747186f59511f56b64d
kernel/include/net/genetlink.h
....@@ -3,6 +3,7 @@
33 #define __NET_GENERIC_NETLINK_H
44
55 #include <linux/genetlink.h>
6
+#include <linux/android_kabi.h>
67 #include <net/netlink.h>
78 #include <net/net_namespace.h>
89
....@@ -26,6 +27,7 @@
2627 * @name: name of family
2728 * @version: protocol version
2829 * @maxattr: maximum number of attributes supported
30
+ * @policy: netlink policy
2931 * @netnsok: set to true if the family can handle network
3032 * namespaces and should be presented in all of them
3133 * @parallel_ops: operations can be called in parallel and aren't
....@@ -34,19 +36,14 @@
3436 * do additional, common, filtering and return an error
3537 * @post_doit: called after an operation's doit callback, it may
3638 * undo operations done by pre_doit, for example release locks
37
- * @mcast_bind: a socket bound to the given multicast group (which
38
- * is given as the offset into the groups array)
39
- * @mcast_unbind: a socket was unbound from the given multicast group.
40
- * Note that unbind() will not be called symmetrically if the
41
- * generic netlink family is removed while there are still open
42
- * sockets.
43
- * @attrbuf: buffer to store parsed attributes (private)
4439 * @mcgrps: multicast groups used by this family
4540 * @n_mcgrps: number of multicast groups
4641 * @mcgrp_offset: starting number of multicast group IDs in this family
4742 * (private)
4843 * @ops: the operations supported by this family
4944 * @n_ops: number of operations supported by this family
45
+ * @small_ops: the small-struct operations supported by this family
46
+ * @n_small_ops: number of small-struct operations supported by this family
5047 */
5148 struct genl_family {
5249 int id; /* private */
....@@ -54,26 +51,26 @@
5451 char name[GENL_NAMSIZ];
5552 unsigned int version;
5653 unsigned int maxattr;
57
- bool netnsok;
58
- bool parallel_ops;
54
+ unsigned int mcgrp_offset; /* private */
55
+ u8 netnsok:1;
56
+ u8 parallel_ops:1;
57
+ u8 n_ops;
58
+ u8 n_small_ops;
59
+ u8 n_mcgrps;
60
+ const struct nla_policy *policy;
5961 int (*pre_doit)(const struct genl_ops *ops,
6062 struct sk_buff *skb,
6163 struct genl_info *info);
6264 void (*post_doit)(const struct genl_ops *ops,
6365 struct sk_buff *skb,
6466 struct genl_info *info);
65
- int (*mcast_bind)(struct net *net, int group);
66
- void (*mcast_unbind)(struct net *net, int group);
67
- struct nlattr ** attrbuf; /* private */
6867 const struct genl_ops * ops;
68
+ const struct genl_small_ops *small_ops;
6969 const struct genl_multicast_group *mcgrps;
70
- unsigned int n_ops;
71
- unsigned int n_mcgrps;
72
- unsigned int mcgrp_offset; /* private */
7370 struct module *module;
74
-};
7571
76
-struct nlattr **genl_family_attrbuf(const struct genl_family *family);
72
+ ANDROID_KABI_RESERVE(1);
73
+};
7774
7875 /**
7976 * struct genl_info - receiving information
....@@ -111,37 +108,80 @@
111108
112109 #define GENL_SET_ERR_MSG(info, msg) NL_SET_ERR_MSG((info)->extack, msg)
113110
114
-static inline int genl_err_attr(struct genl_info *info, int err,
115
- struct nlattr *attr)
116
-{
117
- info->extack->bad_attr = attr;
111
+enum genl_validate_flags {
112
+ GENL_DONT_VALIDATE_STRICT = BIT(0),
113
+ GENL_DONT_VALIDATE_DUMP = BIT(1),
114
+ GENL_DONT_VALIDATE_DUMP_STRICT = BIT(2),
115
+};
118116
119
- return err;
120
-}
117
+/**
118
+ * struct genl_small_ops - generic netlink operations (small version)
119
+ * @cmd: command identifier
120
+ * @internal_flags: flags used by the family
121
+ * @flags: flags
122
+ * @validate: validation flags from enum genl_validate_flags
123
+ * @doit: standard command callback
124
+ * @dumpit: callback for dumpers
125
+ *
126
+ * This is a cut-down version of struct genl_ops for users who don't need
127
+ * most of the ancillary infra and want to save space.
128
+ */
129
+struct genl_small_ops {
130
+ int (*doit)(struct sk_buff *skb, struct genl_info *info);
131
+ int (*dumpit)(struct sk_buff *skb, struct netlink_callback *cb);
132
+ u8 cmd;
133
+ u8 internal_flags;
134
+ u8 flags;
135
+ u8 validate;
136
+};
121137
122138 /**
123139 * struct genl_ops - generic netlink operations
124140 * @cmd: command identifier
125141 * @internal_flags: flags used by the family
126142 * @flags: flags
127
- * @policy: attribute validation policy
143
+ * @maxattr: maximum number of attributes supported
144
+ * @policy: netlink policy (takes precedence over family policy)
145
+ * @validate: validation flags from enum genl_validate_flags
128146 * @doit: standard command callback
129147 * @start: start callback for dumps
130148 * @dumpit: callback for dumpers
131149 * @done: completion callback for dumps
132150 */
133151 struct genl_ops {
134
- const struct nla_policy *policy;
135152 int (*doit)(struct sk_buff *skb,
136153 struct genl_info *info);
137154 int (*start)(struct netlink_callback *cb);
138155 int (*dumpit)(struct sk_buff *skb,
139156 struct netlink_callback *cb);
140157 int (*done)(struct netlink_callback *cb);
158
+ const struct nla_policy *policy;
159
+ unsigned int maxattr;
141160 u8 cmd;
142161 u8 internal_flags;
143162 u8 flags;
163
+ u8 validate;
164
+
165
+ ANDROID_KABI_RESERVE(1);
144166 };
167
+
168
+/**
169
+ * struct genl_info - info that is available during dumpit op call
170
+ * @family: generic netlink family - for internal genl code usage
171
+ * @ops: generic netlink ops - for internal genl code usage
172
+ * @attrs: netlink attributes
173
+ */
174
+struct genl_dumpit_info {
175
+ const struct genl_family *family;
176
+ struct genl_ops op;
177
+ struct nlattr **attrs;
178
+};
179
+
180
+static inline const struct genl_dumpit_info *
181
+genl_dumpit_info(struct netlink_callback *cb)
182
+{
183
+ return cb->data;
184
+}
145185
146186 int genl_register_family(struct genl_family *family);
147187 int genl_unregister_family(const struct genl_family *family);
....@@ -165,6 +205,25 @@
165205 }
166206
167207 /**
208
+ * genlmsg_parse_deprecated - parse attributes of a genetlink message
209
+ * @nlh: netlink message header
210
+ * @family: genetlink message family
211
+ * @tb: destination array with maxtype+1 elements
212
+ * @maxtype: maximum attribute type to be expected
213
+ * @policy: validation policy
214
+ * @extack: extended ACK report struct
215
+ */
216
+static inline int genlmsg_parse_deprecated(const struct nlmsghdr *nlh,
217
+ const struct genl_family *family,
218
+ struct nlattr *tb[], int maxtype,
219
+ const struct nla_policy *policy,
220
+ struct netlink_ext_ack *extack)
221
+{
222
+ return __nlmsg_parse(nlh, family->hdrsize + GENL_HDRLEN, tb, maxtype,
223
+ policy, NL_VALIDATE_LIBERAL, extack);
224
+}
225
+
226
+/**
168227 * genlmsg_parse - parse attributes of a genetlink message
169228 * @nlh: netlink message header
170229 * @family: genetlink message family
....@@ -179,8 +238,8 @@
179238 const struct nla_policy *policy,
180239 struct netlink_ext_ack *extack)
181240 {
182
- return nlmsg_parse(nlh, family->hdrsize + GENL_HDRLEN, tb, maxtype,
183
- policy, extack);
241
+ return __nlmsg_parse(nlh, family->hdrsize + GENL_HDRLEN, tb, maxtype,
242
+ policy, NL_VALIDATE_STRICT, extack);
184243 }
185244
186245 /**