| .. | .. |
|---|
| 3 | 3 | #define __NET_GENERIC_NETLINK_H |
|---|
| 4 | 4 | |
|---|
| 5 | 5 | #include <linux/genetlink.h> |
|---|
| 6 | +#include <linux/android_kabi.h> |
|---|
| 6 | 7 | #include <net/netlink.h> |
|---|
| 7 | 8 | #include <net/net_namespace.h> |
|---|
| 8 | 9 | |
|---|
| .. | .. |
|---|
| 26 | 27 | * @name: name of family |
|---|
| 27 | 28 | * @version: protocol version |
|---|
| 28 | 29 | * @maxattr: maximum number of attributes supported |
|---|
| 30 | + * @policy: netlink policy |
|---|
| 29 | 31 | * @netnsok: set to true if the family can handle network |
|---|
| 30 | 32 | * namespaces and should be presented in all of them |
|---|
| 31 | 33 | * @parallel_ops: operations can be called in parallel and aren't |
|---|
| .. | .. |
|---|
| 34 | 36 | * do additional, common, filtering and return an error |
|---|
| 35 | 37 | * @post_doit: called after an operation's doit callback, it may |
|---|
| 36 | 38 | * 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) |
|---|
| 44 | 39 | * @mcgrps: multicast groups used by this family |
|---|
| 45 | 40 | * @n_mcgrps: number of multicast groups |
|---|
| 46 | 41 | * @mcgrp_offset: starting number of multicast group IDs in this family |
|---|
| 47 | 42 | * (private) |
|---|
| 48 | 43 | * @ops: the operations supported by this family |
|---|
| 49 | 44 | * @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 |
|---|
| 50 | 47 | */ |
|---|
| 51 | 48 | struct genl_family { |
|---|
| 52 | 49 | int id; /* private */ |
|---|
| .. | .. |
|---|
| 54 | 51 | char name[GENL_NAMSIZ]; |
|---|
| 55 | 52 | unsigned int version; |
|---|
| 56 | 53 | 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; |
|---|
| 59 | 61 | int (*pre_doit)(const struct genl_ops *ops, |
|---|
| 60 | 62 | struct sk_buff *skb, |
|---|
| 61 | 63 | struct genl_info *info); |
|---|
| 62 | 64 | void (*post_doit)(const struct genl_ops *ops, |
|---|
| 63 | 65 | struct sk_buff *skb, |
|---|
| 64 | 66 | 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 */ |
|---|
| 68 | 67 | const struct genl_ops * ops; |
|---|
| 68 | + const struct genl_small_ops *small_ops; |
|---|
| 69 | 69 | const struct genl_multicast_group *mcgrps; |
|---|
| 70 | | - unsigned int n_ops; |
|---|
| 71 | | - unsigned int n_mcgrps; |
|---|
| 72 | | - unsigned int mcgrp_offset; /* private */ |
|---|
| 73 | 70 | struct module *module; |
|---|
| 74 | | -}; |
|---|
| 75 | 71 | |
|---|
| 76 | | -struct nlattr **genl_family_attrbuf(const struct genl_family *family); |
|---|
| 72 | + ANDROID_KABI_RESERVE(1); |
|---|
| 73 | +}; |
|---|
| 77 | 74 | |
|---|
| 78 | 75 | /** |
|---|
| 79 | 76 | * struct genl_info - receiving information |
|---|
| .. | .. |
|---|
| 111 | 108 | |
|---|
| 112 | 109 | #define GENL_SET_ERR_MSG(info, msg) NL_SET_ERR_MSG((info)->extack, msg) |
|---|
| 113 | 110 | |
|---|
| 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 | +}; |
|---|
| 118 | 116 | |
|---|
| 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 | +}; |
|---|
| 121 | 137 | |
|---|
| 122 | 138 | /** |
|---|
| 123 | 139 | * struct genl_ops - generic netlink operations |
|---|
| 124 | 140 | * @cmd: command identifier |
|---|
| 125 | 141 | * @internal_flags: flags used by the family |
|---|
| 126 | 142 | * @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 |
|---|
| 128 | 146 | * @doit: standard command callback |
|---|
| 129 | 147 | * @start: start callback for dumps |
|---|
| 130 | 148 | * @dumpit: callback for dumpers |
|---|
| 131 | 149 | * @done: completion callback for dumps |
|---|
| 132 | 150 | */ |
|---|
| 133 | 151 | struct genl_ops { |
|---|
| 134 | | - const struct nla_policy *policy; |
|---|
| 135 | 152 | int (*doit)(struct sk_buff *skb, |
|---|
| 136 | 153 | struct genl_info *info); |
|---|
| 137 | 154 | int (*start)(struct netlink_callback *cb); |
|---|
| 138 | 155 | int (*dumpit)(struct sk_buff *skb, |
|---|
| 139 | 156 | struct netlink_callback *cb); |
|---|
| 140 | 157 | int (*done)(struct netlink_callback *cb); |
|---|
| 158 | + const struct nla_policy *policy; |
|---|
| 159 | + unsigned int maxattr; |
|---|
| 141 | 160 | u8 cmd; |
|---|
| 142 | 161 | u8 internal_flags; |
|---|
| 143 | 162 | u8 flags; |
|---|
| 163 | + u8 validate; |
|---|
| 164 | + |
|---|
| 165 | + ANDROID_KABI_RESERVE(1); |
|---|
| 144 | 166 | }; |
|---|
| 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 | +} |
|---|
| 145 | 185 | |
|---|
| 146 | 186 | int genl_register_family(struct genl_family *family); |
|---|
| 147 | 187 | int genl_unregister_family(const struct genl_family *family); |
|---|
| .. | .. |
|---|
| 165 | 205 | } |
|---|
| 166 | 206 | |
|---|
| 167 | 207 | /** |
|---|
| 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 | +/** |
|---|
| 168 | 227 | * genlmsg_parse - parse attributes of a genetlink message |
|---|
| 169 | 228 | * @nlh: netlink message header |
|---|
| 170 | 229 | * @family: genetlink message family |
|---|
| .. | .. |
|---|
| 179 | 238 | const struct nla_policy *policy, |
|---|
| 180 | 239 | struct netlink_ext_ack *extack) |
|---|
| 181 | 240 | { |
|---|
| 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); |
|---|
| 184 | 243 | } |
|---|
| 185 | 244 | |
|---|
| 186 | 245 | /** |
|---|