Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Thomas Graf | bfa83a9 | 2005-11-10 02:25:51 +0100 | [diff] [blame] | 2 | /* |
| 3 | * NETLINK Netlink attributes |
| 4 | * |
| 5 | * Authors: Thomas Graf <tgraf@suug.ch> |
| 6 | * Alexey Kuznetsov <kuznet@ms2.inr.ac.ru> |
| 7 | */ |
| 8 | |
Paul Gortmaker | 8bc3bcc | 2011-11-16 21:29:17 -0500 | [diff] [blame] | 9 | #include <linux/export.h> |
Thomas Graf | bfa83a9 | 2005-11-10 02:25:51 +0100 | [diff] [blame] | 10 | #include <linux/kernel.h> |
| 11 | #include <linux/errno.h> |
| 12 | #include <linux/jiffies.h> |
Thomas Graf | bfa83a9 | 2005-11-10 02:25:51 +0100 | [diff] [blame] | 13 | #include <linux/skbuff.h> |
| 14 | #include <linux/string.h> |
| 15 | #include <linux/types.h> |
| 16 | #include <net/netlink.h> |
| 17 | |
David Ahern | 6e237d0 | 2017-12-06 20:09:12 -0800 | [diff] [blame] | 18 | /* For these data types, attribute length should be exactly the given |
| 19 | * size. However, to maintain compatibility with broken commands, if the |
| 20 | * attribute length does not match the expected size a warning is emitted |
| 21 | * to the user that the command is sending invalid data and needs to be fixed. |
| 22 | */ |
David Ahern | 28033ae | 2017-11-07 21:59:40 -0800 | [diff] [blame] | 23 | static const u8 nla_attr_len[NLA_TYPE_MAX+1] = { |
Thomas Graf | bfa83a9 | 2005-11-10 02:25:51 +0100 | [diff] [blame] | 24 | [NLA_U8] = sizeof(u8), |
| 25 | [NLA_U16] = sizeof(u16), |
| 26 | [NLA_U32] = sizeof(u32), |
| 27 | [NLA_U64] = sizeof(u64), |
Julian Anastasov | 9eca2eb | 2012-08-25 22:47:57 +0000 | [diff] [blame] | 28 | [NLA_S8] = sizeof(s8), |
| 29 | [NLA_S16] = sizeof(s16), |
| 30 | [NLA_S32] = sizeof(s32), |
| 31 | [NLA_S64] = sizeof(s64), |
Thomas Graf | bfa83a9 | 2005-11-10 02:25:51 +0100 | [diff] [blame] | 32 | }; |
| 33 | |
David Ahern | 28033ae | 2017-11-07 21:59:40 -0800 | [diff] [blame] | 34 | static const u8 nla_attr_minlen[NLA_TYPE_MAX+1] = { |
David Ahern | 6e237d0 | 2017-12-06 20:09:12 -0800 | [diff] [blame] | 35 | [NLA_U8] = sizeof(u8), |
| 36 | [NLA_U16] = sizeof(u16), |
| 37 | [NLA_U32] = sizeof(u32), |
| 38 | [NLA_U64] = sizeof(u64), |
David Ahern | 28033ae | 2017-11-07 21:59:40 -0800 | [diff] [blame] | 39 | [NLA_MSECS] = sizeof(u64), |
| 40 | [NLA_NESTED] = NLA_HDRLEN, |
David Ahern | 6e237d0 | 2017-12-06 20:09:12 -0800 | [diff] [blame] | 41 | [NLA_S8] = sizeof(s8), |
| 42 | [NLA_S16] = sizeof(s16), |
| 43 | [NLA_S32] = sizeof(s32), |
| 44 | [NLA_S64] = sizeof(s64), |
David Ahern | 28033ae | 2017-11-07 21:59:40 -0800 | [diff] [blame] | 45 | }; |
| 46 | |
Jamal Hadi Salim | 64c83d8 | 2017-07-30 13:24:49 -0400 | [diff] [blame] | 47 | static int validate_nla_bitfield32(const struct nlattr *nla, |
Johannes Berg | 48fde90 | 2018-09-26 11:15:31 +0200 | [diff] [blame^] | 48 | const u32 *valid_flags_mask) |
Jamal Hadi Salim | 64c83d8 | 2017-07-30 13:24:49 -0400 | [diff] [blame] | 49 | { |
| 50 | const struct nla_bitfield32 *bf = nla_data(nla); |
Jamal Hadi Salim | 64c83d8 | 2017-07-30 13:24:49 -0400 | [diff] [blame] | 51 | |
Johannes Berg | 48fde90 | 2018-09-26 11:15:31 +0200 | [diff] [blame^] | 52 | if (!valid_flags_mask) |
Jamal Hadi Salim | 64c83d8 | 2017-07-30 13:24:49 -0400 | [diff] [blame] | 53 | return -EINVAL; |
| 54 | |
| 55 | /*disallow invalid bit selector */ |
| 56 | if (bf->selector & ~*valid_flags_mask) |
| 57 | return -EINVAL; |
| 58 | |
| 59 | /*disallow invalid bit values */ |
| 60 | if (bf->value & ~*valid_flags_mask) |
| 61 | return -EINVAL; |
| 62 | |
| 63 | /*disallow valid bit values that are not selected*/ |
| 64 | if (bf->value & ~bf->selector) |
| 65 | return -EINVAL; |
| 66 | |
| 67 | return 0; |
| 68 | } |
| 69 | |
Jan Engelhardt | 3654654 | 2010-11-16 09:52:32 -0800 | [diff] [blame] | 70 | static int validate_nla(const struct nlattr *nla, int maxtype, |
Johannes Berg | 568b742 | 2018-09-17 11:57:28 +0200 | [diff] [blame] | 71 | const struct nla_policy *policy, |
| 72 | const char **error_msg) |
Thomas Graf | bfa83a9 | 2005-11-10 02:25:51 +0100 | [diff] [blame] | 73 | { |
Patrick McHardy | ef7c79e | 2007-06-05 12:38:30 -0700 | [diff] [blame] | 74 | const struct nla_policy *pt; |
Thomas Graf | 8f4c1f9 | 2007-09-12 14:44:36 +0200 | [diff] [blame] | 75 | int minlen = 0, attrlen = nla_len(nla), type = nla_type(nla); |
Thomas Graf | bfa83a9 | 2005-11-10 02:25:51 +0100 | [diff] [blame] | 76 | |
Thomas Graf | 8f4c1f9 | 2007-09-12 14:44:36 +0200 | [diff] [blame] | 77 | if (type <= 0 || type > maxtype) |
Thomas Graf | bfa83a9 | 2005-11-10 02:25:51 +0100 | [diff] [blame] | 78 | return 0; |
| 79 | |
Thomas Graf | 8f4c1f9 | 2007-09-12 14:44:36 +0200 | [diff] [blame] | 80 | pt = &policy[type]; |
Thomas Graf | bfa83a9 | 2005-11-10 02:25:51 +0100 | [diff] [blame] | 81 | |
| 82 | BUG_ON(pt->type > NLA_TYPE_MAX); |
| 83 | |
Johannes Berg | b60b87f | 2018-09-17 11:57:29 +0200 | [diff] [blame] | 84 | if ((nla_attr_len[pt->type] && attrlen != nla_attr_len[pt->type]) || |
| 85 | (pt->type == NLA_EXACT_LEN_WARN && attrlen != pt->len)) { |
David Ahern | 6e237d0 | 2017-12-06 20:09:12 -0800 | [diff] [blame] | 86 | pr_warn_ratelimited("netlink: '%s': attribute type %d has an invalid length.\n", |
| 87 | current->comm, type); |
David Ahern | 28033ae | 2017-11-07 21:59:40 -0800 | [diff] [blame] | 88 | } |
| 89 | |
Thomas Graf | a5531a5 | 2006-08-26 20:11:47 -0700 | [diff] [blame] | 90 | switch (pt->type) { |
Johannes Berg | b60b87f | 2018-09-17 11:57:29 +0200 | [diff] [blame] | 91 | case NLA_EXACT_LEN: |
| 92 | if (attrlen != pt->len) |
| 93 | return -ERANGE; |
| 94 | break; |
| 95 | |
Johannes Berg | 568b742 | 2018-09-17 11:57:28 +0200 | [diff] [blame] | 96 | case NLA_REJECT: |
| 97 | if (pt->validation_data && error_msg) |
| 98 | *error_msg = pt->validation_data; |
| 99 | return -EINVAL; |
| 100 | |
Thomas Graf | a5531a5 | 2006-08-26 20:11:47 -0700 | [diff] [blame] | 101 | case NLA_FLAG: |
| 102 | if (attrlen > 0) |
| 103 | return -ERANGE; |
| 104 | break; |
Thomas Graf | bfa83a9 | 2005-11-10 02:25:51 +0100 | [diff] [blame] | 105 | |
Jamal Hadi Salim | 64c83d8 | 2017-07-30 13:24:49 -0400 | [diff] [blame] | 106 | case NLA_BITFIELD32: |
| 107 | if (attrlen != sizeof(struct nla_bitfield32)) |
| 108 | return -ERANGE; |
| 109 | |
| 110 | return validate_nla_bitfield32(nla, pt->validation_data); |
| 111 | |
Thomas Graf | a5531a5 | 2006-08-26 20:11:47 -0700 | [diff] [blame] | 112 | case NLA_NUL_STRING: |
| 113 | if (pt->len) |
| 114 | minlen = min_t(int, attrlen, pt->len + 1); |
| 115 | else |
| 116 | minlen = attrlen; |
Thomas Graf | bfa83a9 | 2005-11-10 02:25:51 +0100 | [diff] [blame] | 117 | |
Thomas Graf | a5531a5 | 2006-08-26 20:11:47 -0700 | [diff] [blame] | 118 | if (!minlen || memchr(nla_data(nla), '\0', minlen) == NULL) |
| 119 | return -EINVAL; |
| 120 | /* fall through */ |
| 121 | |
| 122 | case NLA_STRING: |
| 123 | if (attrlen < 1) |
| 124 | return -ERANGE; |
| 125 | |
| 126 | if (pt->len) { |
| 127 | char *buf = nla_data(nla); |
| 128 | |
| 129 | if (buf[attrlen - 1] == '\0') |
| 130 | attrlen--; |
| 131 | |
| 132 | if (attrlen > pt->len) |
| 133 | return -ERANGE; |
| 134 | } |
| 135 | break; |
| 136 | |
Johannes Berg | d30045a | 2007-03-23 11:37:48 -0700 | [diff] [blame] | 137 | case NLA_BINARY: |
| 138 | if (pt->len && attrlen > pt->len) |
| 139 | return -ERANGE; |
| 140 | break; |
| 141 | |
Patrick McHardy | ea5693c | 2008-11-28 03:05:19 -0800 | [diff] [blame] | 142 | case NLA_NESTED: |
| 143 | /* a nested attributes is allowed to be empty; if its not, |
| 144 | * it must have a size of at least NLA_HDRLEN. |
| 145 | */ |
| 146 | if (attrlen == 0) |
| 147 | break; |
Thomas Graf | a5531a5 | 2006-08-26 20:11:47 -0700 | [diff] [blame] | 148 | default: |
| 149 | if (pt->len) |
| 150 | minlen = pt->len; |
| 151 | else if (pt->type != NLA_UNSPEC) |
| 152 | minlen = nla_attr_minlen[pt->type]; |
| 153 | |
| 154 | if (attrlen < minlen) |
| 155 | return -ERANGE; |
| 156 | } |
Thomas Graf | bfa83a9 | 2005-11-10 02:25:51 +0100 | [diff] [blame] | 157 | |
| 158 | return 0; |
| 159 | } |
| 160 | |
| 161 | /** |
| 162 | * nla_validate - Validate a stream of attributes |
| 163 | * @head: head of attribute stream |
| 164 | * @len: length of attribute stream |
| 165 | * @maxtype: maximum attribute type to be expected |
| 166 | * @policy: validation policy |
Johannes Berg | fceb643 | 2017-04-12 14:34:07 +0200 | [diff] [blame] | 167 | * @extack: extended ACK report struct |
Thomas Graf | bfa83a9 | 2005-11-10 02:25:51 +0100 | [diff] [blame] | 168 | * |
| 169 | * Validates all attributes in the specified attribute stream against the |
| 170 | * specified policy. Attributes with a type exceeding maxtype will be |
| 171 | * ignored. See documenation of struct nla_policy for more details. |
| 172 | * |
| 173 | * Returns 0 on success or a negative error code. |
| 174 | */ |
Jan Engelhardt | 3654654 | 2010-11-16 09:52:32 -0800 | [diff] [blame] | 175 | int nla_validate(const struct nlattr *head, int len, int maxtype, |
Johannes Berg | fceb643 | 2017-04-12 14:34:07 +0200 | [diff] [blame] | 176 | const struct nla_policy *policy, |
| 177 | struct netlink_ext_ack *extack) |
Thomas Graf | bfa83a9 | 2005-11-10 02:25:51 +0100 | [diff] [blame] | 178 | { |
Jan Engelhardt | 3654654 | 2010-11-16 09:52:32 -0800 | [diff] [blame] | 179 | const struct nlattr *nla; |
Johannes Berg | fceb643 | 2017-04-12 14:34:07 +0200 | [diff] [blame] | 180 | int rem; |
Thomas Graf | bfa83a9 | 2005-11-10 02:25:51 +0100 | [diff] [blame] | 181 | |
| 182 | nla_for_each_attr(nla, head, len, rem) { |
Johannes Berg | 568b742 | 2018-09-17 11:57:28 +0200 | [diff] [blame] | 183 | int err = validate_nla(nla, maxtype, policy, NULL); |
Johannes Berg | fceb643 | 2017-04-12 14:34:07 +0200 | [diff] [blame] | 184 | |
| 185 | if (err < 0) { |
Johannes Berg | 568b742 | 2018-09-17 11:57:28 +0200 | [diff] [blame] | 186 | NL_SET_BAD_ATTR(extack, nla); |
Johannes Berg | fceb643 | 2017-04-12 14:34:07 +0200 | [diff] [blame] | 187 | return err; |
| 188 | } |
Thomas Graf | bfa83a9 | 2005-11-10 02:25:51 +0100 | [diff] [blame] | 189 | } |
| 190 | |
Johannes Berg | fceb643 | 2017-04-12 14:34:07 +0200 | [diff] [blame] | 191 | return 0; |
Thomas Graf | bfa83a9 | 2005-11-10 02:25:51 +0100 | [diff] [blame] | 192 | } |
Fabian Frederick | 6d6a138 | 2014-06-04 16:11:57 -0700 | [diff] [blame] | 193 | EXPORT_SYMBOL(nla_validate); |
Thomas Graf | bfa83a9 | 2005-11-10 02:25:51 +0100 | [diff] [blame] | 194 | |
| 195 | /** |
Holger Eitzenberger | e487eb99 | 2009-03-25 18:26:30 +0100 | [diff] [blame] | 196 | * nla_policy_len - Determin the max. length of a policy |
| 197 | * @policy: policy to use |
| 198 | * @n: number of policies |
| 199 | * |
| 200 | * Determines the max. length of the policy. It is currently used |
| 201 | * to allocated Netlink buffers roughly the size of the actual |
| 202 | * message. |
| 203 | * |
| 204 | * Returns 0 on success or a negative error code. |
| 205 | */ |
| 206 | int |
| 207 | nla_policy_len(const struct nla_policy *p, int n) |
| 208 | { |
| 209 | int i, len = 0; |
| 210 | |
Lars Ellenberg | e3fa3af | 2011-02-28 12:38:25 -0800 | [diff] [blame] | 211 | for (i = 0; i < n; i++, p++) { |
Holger Eitzenberger | e487eb99 | 2009-03-25 18:26:30 +0100 | [diff] [blame] | 212 | if (p->len) |
| 213 | len += nla_total_size(p->len); |
David Ahern | 28033ae | 2017-11-07 21:59:40 -0800 | [diff] [blame] | 214 | else if (nla_attr_len[p->type]) |
| 215 | len += nla_total_size(nla_attr_len[p->type]); |
Holger Eitzenberger | e487eb99 | 2009-03-25 18:26:30 +0100 | [diff] [blame] | 216 | else if (nla_attr_minlen[p->type]) |
| 217 | len += nla_total_size(nla_attr_minlen[p->type]); |
| 218 | } |
| 219 | |
| 220 | return len; |
| 221 | } |
Fabian Frederick | 6d6a138 | 2014-06-04 16:11:57 -0700 | [diff] [blame] | 222 | EXPORT_SYMBOL(nla_policy_len); |
Holger Eitzenberger | e487eb99 | 2009-03-25 18:26:30 +0100 | [diff] [blame] | 223 | |
| 224 | /** |
Thomas Graf | bfa83a9 | 2005-11-10 02:25:51 +0100 | [diff] [blame] | 225 | * nla_parse - Parse a stream of attributes into a tb buffer |
| 226 | * @tb: destination array with maxtype+1 elements |
| 227 | * @maxtype: maximum attribute type to be expected |
| 228 | * @head: head of attribute stream |
| 229 | * @len: length of attribute stream |
Julius Volz | 10b595a | 2008-06-27 20:02:14 -0700 | [diff] [blame] | 230 | * @policy: validation policy |
Thomas Graf | bfa83a9 | 2005-11-10 02:25:51 +0100 | [diff] [blame] | 231 | * |
| 232 | * Parses a stream of attributes and stores a pointer to each attribute in |
Uwe Kleine-König | b595076 | 2010-11-01 15:38:34 -0400 | [diff] [blame] | 233 | * the tb array accessible via the attribute type. Attributes with a type |
Thomas Graf | bfa83a9 | 2005-11-10 02:25:51 +0100 | [diff] [blame] | 234 | * exceeding maxtype will be silently ignored for backwards compatibility |
| 235 | * reasons. policy may be set to NULL if no validation is required. |
| 236 | * |
| 237 | * Returns 0 on success or a negative error code. |
| 238 | */ |
Jan Engelhardt | 3654654 | 2010-11-16 09:52:32 -0800 | [diff] [blame] | 239 | int nla_parse(struct nlattr **tb, int maxtype, const struct nlattr *head, |
Johannes Berg | fceb643 | 2017-04-12 14:34:07 +0200 | [diff] [blame] | 240 | int len, const struct nla_policy *policy, |
| 241 | struct netlink_ext_ack *extack) |
Thomas Graf | bfa83a9 | 2005-11-10 02:25:51 +0100 | [diff] [blame] | 242 | { |
Jan Engelhardt | 3654654 | 2010-11-16 09:52:32 -0800 | [diff] [blame] | 243 | const struct nlattr *nla; |
Thomas Graf | bfa83a9 | 2005-11-10 02:25:51 +0100 | [diff] [blame] | 244 | int rem, err; |
| 245 | |
| 246 | memset(tb, 0, sizeof(struct nlattr *) * (maxtype + 1)); |
| 247 | |
| 248 | nla_for_each_attr(nla, head, len, rem) { |
Thomas Graf | 8f4c1f9 | 2007-09-12 14:44:36 +0200 | [diff] [blame] | 249 | u16 type = nla_type(nla); |
Thomas Graf | bfa83a9 | 2005-11-10 02:25:51 +0100 | [diff] [blame] | 250 | |
| 251 | if (type > 0 && type <= maxtype) { |
Johannes Berg | 568b742 | 2018-09-17 11:57:28 +0200 | [diff] [blame] | 252 | static const char _msg[] = "Attribute failed policy validation"; |
| 253 | const char *msg = _msg; |
| 254 | |
Thomas Graf | bfa83a9 | 2005-11-10 02:25:51 +0100 | [diff] [blame] | 255 | if (policy) { |
Johannes Berg | 568b742 | 2018-09-17 11:57:28 +0200 | [diff] [blame] | 256 | err = validate_nla(nla, maxtype, policy, &msg); |
Johannes Berg | fceb643 | 2017-04-12 14:34:07 +0200 | [diff] [blame] | 257 | if (err < 0) { |
Johannes Berg | 568b742 | 2018-09-17 11:57:28 +0200 | [diff] [blame] | 258 | NL_SET_BAD_ATTR(extack, nla); |
| 259 | if (extack) |
| 260 | extack->_msg = msg; |
Thomas Graf | bfa83a9 | 2005-11-10 02:25:51 +0100 | [diff] [blame] | 261 | goto errout; |
Johannes Berg | fceb643 | 2017-04-12 14:34:07 +0200 | [diff] [blame] | 262 | } |
Thomas Graf | bfa83a9 | 2005-11-10 02:25:51 +0100 | [diff] [blame] | 263 | } |
| 264 | |
Jan Engelhardt | 3654654 | 2010-11-16 09:52:32 -0800 | [diff] [blame] | 265 | tb[type] = (struct nlattr *)nla; |
Thomas Graf | bfa83a9 | 2005-11-10 02:25:51 +0100 | [diff] [blame] | 266 | } |
| 267 | } |
| 268 | |
| 269 | if (unlikely(rem > 0)) |
Michal Schmidt | bfc5184 | 2014-06-02 18:25:02 +0200 | [diff] [blame] | 270 | pr_warn_ratelimited("netlink: %d bytes leftover after parsing attributes in process `%s'.\n", |
| 271 | rem, current->comm); |
Thomas Graf | bfa83a9 | 2005-11-10 02:25:51 +0100 | [diff] [blame] | 272 | |
| 273 | err = 0; |
| 274 | errout: |
| 275 | return err; |
| 276 | } |
Fabian Frederick | 6d6a138 | 2014-06-04 16:11:57 -0700 | [diff] [blame] | 277 | EXPORT_SYMBOL(nla_parse); |
Thomas Graf | bfa83a9 | 2005-11-10 02:25:51 +0100 | [diff] [blame] | 278 | |
| 279 | /** |
| 280 | * nla_find - Find a specific attribute in a stream of attributes |
| 281 | * @head: head of attribute stream |
| 282 | * @len: length of attribute stream |
| 283 | * @attrtype: type of attribute to look for |
| 284 | * |
| 285 | * Returns the first attribute in the stream matching the specified type. |
| 286 | */ |
Jan Engelhardt | 3654654 | 2010-11-16 09:52:32 -0800 | [diff] [blame] | 287 | struct nlattr *nla_find(const struct nlattr *head, int len, int attrtype) |
Thomas Graf | bfa83a9 | 2005-11-10 02:25:51 +0100 | [diff] [blame] | 288 | { |
Jan Engelhardt | 3654654 | 2010-11-16 09:52:32 -0800 | [diff] [blame] | 289 | const struct nlattr *nla; |
Thomas Graf | bfa83a9 | 2005-11-10 02:25:51 +0100 | [diff] [blame] | 290 | int rem; |
| 291 | |
| 292 | nla_for_each_attr(nla, head, len, rem) |
Thomas Graf | 8f4c1f9 | 2007-09-12 14:44:36 +0200 | [diff] [blame] | 293 | if (nla_type(nla) == attrtype) |
Jan Engelhardt | 3654654 | 2010-11-16 09:52:32 -0800 | [diff] [blame] | 294 | return (struct nlattr *)nla; |
Thomas Graf | bfa83a9 | 2005-11-10 02:25:51 +0100 | [diff] [blame] | 295 | |
| 296 | return NULL; |
| 297 | } |
Fabian Frederick | 6d6a138 | 2014-06-04 16:11:57 -0700 | [diff] [blame] | 298 | EXPORT_SYMBOL(nla_find); |
Thomas Graf | bfa83a9 | 2005-11-10 02:25:51 +0100 | [diff] [blame] | 299 | |
| 300 | /** |
| 301 | * nla_strlcpy - Copy string attribute payload into a sized buffer |
| 302 | * @dst: where to copy the string to |
Julius Volz | 10b595a | 2008-06-27 20:02:14 -0700 | [diff] [blame] | 303 | * @nla: attribute to copy the string from |
Thomas Graf | bfa83a9 | 2005-11-10 02:25:51 +0100 | [diff] [blame] | 304 | * @dstsize: size of destination buffer |
| 305 | * |
| 306 | * Copies at most dstsize - 1 bytes into the destination buffer. |
| 307 | * The result is always a valid NUL-terminated string. Unlike |
| 308 | * strlcpy the destination buffer is always padded out. |
| 309 | * |
| 310 | * Returns the length of the source buffer. |
| 311 | */ |
| 312 | size_t nla_strlcpy(char *dst, const struct nlattr *nla, size_t dstsize) |
| 313 | { |
| 314 | size_t srclen = nla_len(nla); |
| 315 | char *src = nla_data(nla); |
| 316 | |
| 317 | if (srclen > 0 && src[srclen - 1] == '\0') |
| 318 | srclen--; |
| 319 | |
| 320 | if (dstsize > 0) { |
| 321 | size_t len = (srclen >= dstsize) ? dstsize - 1 : srclen; |
| 322 | |
| 323 | memset(dst, 0, dstsize); |
| 324 | memcpy(dst, src, len); |
| 325 | } |
| 326 | |
| 327 | return srclen; |
| 328 | } |
Fabian Frederick | 6d6a138 | 2014-06-04 16:11:57 -0700 | [diff] [blame] | 329 | EXPORT_SYMBOL(nla_strlcpy); |
Thomas Graf | bfa83a9 | 2005-11-10 02:25:51 +0100 | [diff] [blame] | 330 | |
| 331 | /** |
Phil Sutter | 2cf0c8b | 2017-07-27 16:56:40 +0200 | [diff] [blame] | 332 | * nla_strdup - Copy string attribute payload into a newly allocated buffer |
| 333 | * @nla: attribute to copy the string from |
| 334 | * @flags: the type of memory to allocate (see kmalloc). |
| 335 | * |
| 336 | * Returns a pointer to the allocated buffer or NULL on error. |
| 337 | */ |
| 338 | char *nla_strdup(const struct nlattr *nla, gfp_t flags) |
| 339 | { |
| 340 | size_t srclen = nla_len(nla); |
| 341 | char *src = nla_data(nla), *dst; |
| 342 | |
| 343 | if (srclen > 0 && src[srclen - 1] == '\0') |
| 344 | srclen--; |
| 345 | |
| 346 | dst = kmalloc(srclen + 1, flags); |
| 347 | if (dst != NULL) { |
| 348 | memcpy(dst, src, srclen); |
| 349 | dst[srclen] = '\0'; |
| 350 | } |
| 351 | return dst; |
| 352 | } |
| 353 | EXPORT_SYMBOL(nla_strdup); |
| 354 | |
| 355 | /** |
Thomas Graf | bfa83a9 | 2005-11-10 02:25:51 +0100 | [diff] [blame] | 356 | * nla_memcpy - Copy a netlink attribute into another memory area |
| 357 | * @dest: where to copy to memcpy |
| 358 | * @src: netlink attribute to copy from |
| 359 | * @count: size of the destination area |
| 360 | * |
| 361 | * Note: The number of bytes copied is limited by the length of |
| 362 | * attribute's payload. memcpy |
| 363 | * |
| 364 | * Returns the number of bytes copied. |
| 365 | */ |
Patrick McHardy | b057efd | 2008-10-28 11:59:11 -0700 | [diff] [blame] | 366 | int nla_memcpy(void *dest, const struct nlattr *src, int count) |
Thomas Graf | bfa83a9 | 2005-11-10 02:25:51 +0100 | [diff] [blame] | 367 | { |
| 368 | int minlen = min_t(int, count, nla_len(src)); |
| 369 | |
| 370 | memcpy(dest, nla_data(src), minlen); |
Jiri Benc | 5899f04 | 2015-03-29 16:05:28 +0200 | [diff] [blame] | 371 | if (count > minlen) |
| 372 | memset(dest + minlen, 0, count - minlen); |
Thomas Graf | bfa83a9 | 2005-11-10 02:25:51 +0100 | [diff] [blame] | 373 | |
| 374 | return minlen; |
| 375 | } |
Fabian Frederick | 6d6a138 | 2014-06-04 16:11:57 -0700 | [diff] [blame] | 376 | EXPORT_SYMBOL(nla_memcpy); |
Thomas Graf | bfa83a9 | 2005-11-10 02:25:51 +0100 | [diff] [blame] | 377 | |
| 378 | /** |
| 379 | * nla_memcmp - Compare an attribute with sized memory area |
| 380 | * @nla: netlink attribute |
| 381 | * @data: memory area |
| 382 | * @size: size of memory area |
| 383 | */ |
| 384 | int nla_memcmp(const struct nlattr *nla, const void *data, |
| 385 | size_t size) |
| 386 | { |
| 387 | int d = nla_len(nla) - size; |
| 388 | |
| 389 | if (d == 0) |
| 390 | d = memcmp(nla_data(nla), data, size); |
| 391 | |
| 392 | return d; |
| 393 | } |
Fabian Frederick | 6d6a138 | 2014-06-04 16:11:57 -0700 | [diff] [blame] | 394 | EXPORT_SYMBOL(nla_memcmp); |
Thomas Graf | bfa83a9 | 2005-11-10 02:25:51 +0100 | [diff] [blame] | 395 | |
| 396 | /** |
| 397 | * nla_strcmp - Compare a string attribute against a string |
| 398 | * @nla: netlink string attribute |
| 399 | * @str: another string |
| 400 | */ |
| 401 | int nla_strcmp(const struct nlattr *nla, const char *str) |
| 402 | { |
Pablo Neira | 8b7b932 | 2014-04-01 19:38:44 +0200 | [diff] [blame] | 403 | int len = strlen(str); |
| 404 | char *buf = nla_data(nla); |
| 405 | int attrlen = nla_len(nla); |
| 406 | int d; |
Thomas Graf | bfa83a9 | 2005-11-10 02:25:51 +0100 | [diff] [blame] | 407 | |
Pablo Neira | 8b7b932 | 2014-04-01 19:38:44 +0200 | [diff] [blame] | 408 | if (attrlen > 0 && buf[attrlen - 1] == '\0') |
| 409 | attrlen--; |
| 410 | |
| 411 | d = attrlen - len; |
Thomas Graf | bfa83a9 | 2005-11-10 02:25:51 +0100 | [diff] [blame] | 412 | if (d == 0) |
| 413 | d = memcmp(nla_data(nla), str, len); |
| 414 | |
| 415 | return d; |
| 416 | } |
Fabian Frederick | 6d6a138 | 2014-06-04 16:11:57 -0700 | [diff] [blame] | 417 | EXPORT_SYMBOL(nla_strcmp); |
Thomas Graf | bfa83a9 | 2005-11-10 02:25:51 +0100 | [diff] [blame] | 418 | |
Herbert Xu | 9080021 | 2009-03-11 23:18:32 +0800 | [diff] [blame] | 419 | #ifdef CONFIG_NET |
Thomas Graf | bfa83a9 | 2005-11-10 02:25:51 +0100 | [diff] [blame] | 420 | /** |
| 421 | * __nla_reserve - reserve room for attribute on the skb |
| 422 | * @skb: socket buffer to reserve room on |
| 423 | * @attrtype: attribute type |
| 424 | * @attrlen: length of attribute payload |
| 425 | * |
| 426 | * Adds a netlink attribute header to a socket buffer and reserves |
| 427 | * room for the payload but does not copy it. |
| 428 | * |
| 429 | * The caller is responsible to ensure that the skb provides enough |
| 430 | * tailroom for the attribute header and payload. |
| 431 | */ |
| 432 | struct nlattr *__nla_reserve(struct sk_buff *skb, int attrtype, int attrlen) |
| 433 | { |
| 434 | struct nlattr *nla; |
| 435 | |
Johannes Berg | 4df864c | 2017-06-16 14:29:21 +0200 | [diff] [blame] | 436 | nla = skb_put(skb, nla_total_size(attrlen)); |
Thomas Graf | bfa83a9 | 2005-11-10 02:25:51 +0100 | [diff] [blame] | 437 | nla->nla_type = attrtype; |
| 438 | nla->nla_len = nla_attr_size(attrlen); |
| 439 | |
| 440 | memset((unsigned char *) nla + nla->nla_len, 0, nla_padlen(attrlen)); |
| 441 | |
| 442 | return nla; |
| 443 | } |
Herbert Xu | 9080021 | 2009-03-11 23:18:32 +0800 | [diff] [blame] | 444 | EXPORT_SYMBOL(__nla_reserve); |
Thomas Graf | bfa83a9 | 2005-11-10 02:25:51 +0100 | [diff] [blame] | 445 | |
| 446 | /** |
Nicolas Dichtel | 089bf1a | 2016-04-21 18:58:24 +0200 | [diff] [blame] | 447 | * __nla_reserve_64bit - reserve room for attribute on the skb and align it |
| 448 | * @skb: socket buffer to reserve room on |
| 449 | * @attrtype: attribute type |
| 450 | * @attrlen: length of attribute payload |
Nicolas Dichtel | 11a9957 | 2016-04-22 17:31:16 +0200 | [diff] [blame] | 451 | * @padattr: attribute type for the padding |
Nicolas Dichtel | 089bf1a | 2016-04-21 18:58:24 +0200 | [diff] [blame] | 452 | * |
| 453 | * Adds a netlink attribute header to a socket buffer and reserves |
| 454 | * room for the payload but does not copy it. It also ensure that this |
Nicolas Dichtel | 11a9957 | 2016-04-22 17:31:16 +0200 | [diff] [blame] | 455 | * attribute will have a 64-bit aligned nla_data() area. |
Nicolas Dichtel | 089bf1a | 2016-04-21 18:58:24 +0200 | [diff] [blame] | 456 | * |
| 457 | * The caller is responsible to ensure that the skb provides enough |
| 458 | * tailroom for the attribute header and payload. |
| 459 | */ |
| 460 | struct nlattr *__nla_reserve_64bit(struct sk_buff *skb, int attrtype, |
| 461 | int attrlen, int padattr) |
| 462 | { |
| 463 | if (nla_need_padding_for_64bit(skb)) |
| 464 | nla_align_64bit(skb, padattr); |
| 465 | |
| 466 | return __nla_reserve(skb, attrtype, attrlen); |
| 467 | } |
| 468 | EXPORT_SYMBOL(__nla_reserve_64bit); |
| 469 | |
| 470 | /** |
Thomas Graf | fe4944e | 2006-08-04 23:03:05 -0700 | [diff] [blame] | 471 | * __nla_reserve_nohdr - reserve room for attribute without header |
| 472 | * @skb: socket buffer to reserve room on |
| 473 | * @attrlen: length of attribute payload |
| 474 | * |
| 475 | * Reserves room for attribute payload without a header. |
| 476 | * |
| 477 | * The caller is responsible to ensure that the skb provides enough |
| 478 | * tailroom for the payload. |
| 479 | */ |
| 480 | void *__nla_reserve_nohdr(struct sk_buff *skb, int attrlen) |
| 481 | { |
yuan linyu | b952f4d | 2017-06-18 22:52:04 +0800 | [diff] [blame] | 482 | return skb_put_zero(skb, NLA_ALIGN(attrlen)); |
Thomas Graf | fe4944e | 2006-08-04 23:03:05 -0700 | [diff] [blame] | 483 | } |
Herbert Xu | 9080021 | 2009-03-11 23:18:32 +0800 | [diff] [blame] | 484 | EXPORT_SYMBOL(__nla_reserve_nohdr); |
Thomas Graf | fe4944e | 2006-08-04 23:03:05 -0700 | [diff] [blame] | 485 | |
| 486 | /** |
Thomas Graf | bfa83a9 | 2005-11-10 02:25:51 +0100 | [diff] [blame] | 487 | * nla_reserve - reserve room for attribute on the skb |
| 488 | * @skb: socket buffer to reserve room on |
| 489 | * @attrtype: attribute type |
| 490 | * @attrlen: length of attribute payload |
| 491 | * |
| 492 | * Adds a netlink attribute header to a socket buffer and reserves |
| 493 | * room for the payload but does not copy it. |
| 494 | * |
| 495 | * Returns NULL if the tailroom of the skb is insufficient to store |
| 496 | * the attribute header and payload. |
| 497 | */ |
| 498 | struct nlattr *nla_reserve(struct sk_buff *skb, int attrtype, int attrlen) |
| 499 | { |
| 500 | if (unlikely(skb_tailroom(skb) < nla_total_size(attrlen))) |
| 501 | return NULL; |
| 502 | |
| 503 | return __nla_reserve(skb, attrtype, attrlen); |
| 504 | } |
Herbert Xu | 9080021 | 2009-03-11 23:18:32 +0800 | [diff] [blame] | 505 | EXPORT_SYMBOL(nla_reserve); |
Thomas Graf | bfa83a9 | 2005-11-10 02:25:51 +0100 | [diff] [blame] | 506 | |
| 507 | /** |
Nicolas Dichtel | 089bf1a | 2016-04-21 18:58:24 +0200 | [diff] [blame] | 508 | * nla_reserve_64bit - reserve room for attribute on the skb and align it |
| 509 | * @skb: socket buffer to reserve room on |
| 510 | * @attrtype: attribute type |
| 511 | * @attrlen: length of attribute payload |
Nicolas Dichtel | 11a9957 | 2016-04-22 17:31:16 +0200 | [diff] [blame] | 512 | * @padattr: attribute type for the padding |
Nicolas Dichtel | 089bf1a | 2016-04-21 18:58:24 +0200 | [diff] [blame] | 513 | * |
| 514 | * Adds a netlink attribute header to a socket buffer and reserves |
| 515 | * room for the payload but does not copy it. It also ensure that this |
Nicolas Dichtel | 11a9957 | 2016-04-22 17:31:16 +0200 | [diff] [blame] | 516 | * attribute will have a 64-bit aligned nla_data() area. |
Nicolas Dichtel | 089bf1a | 2016-04-21 18:58:24 +0200 | [diff] [blame] | 517 | * |
| 518 | * Returns NULL if the tailroom of the skb is insufficient to store |
| 519 | * the attribute header and payload. |
| 520 | */ |
| 521 | struct nlattr *nla_reserve_64bit(struct sk_buff *skb, int attrtype, int attrlen, |
| 522 | int padattr) |
| 523 | { |
| 524 | size_t len; |
| 525 | |
| 526 | if (nla_need_padding_for_64bit(skb)) |
| 527 | len = nla_total_size_64bit(attrlen); |
| 528 | else |
| 529 | len = nla_total_size(attrlen); |
| 530 | if (unlikely(skb_tailroom(skb) < len)) |
| 531 | return NULL; |
| 532 | |
| 533 | return __nla_reserve_64bit(skb, attrtype, attrlen, padattr); |
| 534 | } |
| 535 | EXPORT_SYMBOL(nla_reserve_64bit); |
| 536 | |
| 537 | /** |
Julius Volz | 10b595a | 2008-06-27 20:02:14 -0700 | [diff] [blame] | 538 | * nla_reserve_nohdr - reserve room for attribute without header |
Thomas Graf | fe4944e | 2006-08-04 23:03:05 -0700 | [diff] [blame] | 539 | * @skb: socket buffer to reserve room on |
Julius Volz | 10b595a | 2008-06-27 20:02:14 -0700 | [diff] [blame] | 540 | * @attrlen: length of attribute payload |
Thomas Graf | fe4944e | 2006-08-04 23:03:05 -0700 | [diff] [blame] | 541 | * |
| 542 | * Reserves room for attribute payload without a header. |
| 543 | * |
| 544 | * Returns NULL if the tailroom of the skb is insufficient to store |
| 545 | * the attribute payload. |
| 546 | */ |
| 547 | void *nla_reserve_nohdr(struct sk_buff *skb, int attrlen) |
| 548 | { |
| 549 | if (unlikely(skb_tailroom(skb) < NLA_ALIGN(attrlen))) |
| 550 | return NULL; |
| 551 | |
| 552 | return __nla_reserve_nohdr(skb, attrlen); |
| 553 | } |
Herbert Xu | 9080021 | 2009-03-11 23:18:32 +0800 | [diff] [blame] | 554 | EXPORT_SYMBOL(nla_reserve_nohdr); |
Thomas Graf | fe4944e | 2006-08-04 23:03:05 -0700 | [diff] [blame] | 555 | |
| 556 | /** |
Thomas Graf | bfa83a9 | 2005-11-10 02:25:51 +0100 | [diff] [blame] | 557 | * __nla_put - Add a netlink attribute to a socket buffer |
| 558 | * @skb: socket buffer to add attribute to |
| 559 | * @attrtype: attribute type |
| 560 | * @attrlen: length of attribute payload |
| 561 | * @data: head of attribute payload |
| 562 | * |
| 563 | * The caller is responsible to ensure that the skb provides enough |
| 564 | * tailroom for the attribute header and payload. |
| 565 | */ |
| 566 | void __nla_put(struct sk_buff *skb, int attrtype, int attrlen, |
| 567 | const void *data) |
| 568 | { |
| 569 | struct nlattr *nla; |
| 570 | |
| 571 | nla = __nla_reserve(skb, attrtype, attrlen); |
| 572 | memcpy(nla_data(nla), data, attrlen); |
| 573 | } |
Herbert Xu | 9080021 | 2009-03-11 23:18:32 +0800 | [diff] [blame] | 574 | EXPORT_SYMBOL(__nla_put); |
Thomas Graf | bfa83a9 | 2005-11-10 02:25:51 +0100 | [diff] [blame] | 575 | |
Thomas Graf | fe4944e | 2006-08-04 23:03:05 -0700 | [diff] [blame] | 576 | /** |
Nicolas Dichtel | 089bf1a | 2016-04-21 18:58:24 +0200 | [diff] [blame] | 577 | * __nla_put_64bit - Add a netlink attribute to a socket buffer and align it |
| 578 | * @skb: socket buffer to add attribute to |
| 579 | * @attrtype: attribute type |
| 580 | * @attrlen: length of attribute payload |
| 581 | * @data: head of attribute payload |
Nicolas Dichtel | 11a9957 | 2016-04-22 17:31:16 +0200 | [diff] [blame] | 582 | * @padattr: attribute type for the padding |
Nicolas Dichtel | 089bf1a | 2016-04-21 18:58:24 +0200 | [diff] [blame] | 583 | * |
| 584 | * The caller is responsible to ensure that the skb provides enough |
| 585 | * tailroom for the attribute header and payload. |
| 586 | */ |
| 587 | void __nla_put_64bit(struct sk_buff *skb, int attrtype, int attrlen, |
| 588 | const void *data, int padattr) |
| 589 | { |
| 590 | struct nlattr *nla; |
| 591 | |
| 592 | nla = __nla_reserve_64bit(skb, attrtype, attrlen, padattr); |
| 593 | memcpy(nla_data(nla), data, attrlen); |
| 594 | } |
| 595 | EXPORT_SYMBOL(__nla_put_64bit); |
| 596 | |
| 597 | /** |
Thomas Graf | fe4944e | 2006-08-04 23:03:05 -0700 | [diff] [blame] | 598 | * __nla_put_nohdr - Add a netlink attribute without header |
| 599 | * @skb: socket buffer to add attribute to |
| 600 | * @attrlen: length of attribute payload |
| 601 | * @data: head of attribute payload |
| 602 | * |
| 603 | * The caller is responsible to ensure that the skb provides enough |
| 604 | * tailroom for the attribute payload. |
| 605 | */ |
| 606 | void __nla_put_nohdr(struct sk_buff *skb, int attrlen, const void *data) |
| 607 | { |
| 608 | void *start; |
| 609 | |
| 610 | start = __nla_reserve_nohdr(skb, attrlen); |
| 611 | memcpy(start, data, attrlen); |
| 612 | } |
Herbert Xu | 9080021 | 2009-03-11 23:18:32 +0800 | [diff] [blame] | 613 | EXPORT_SYMBOL(__nla_put_nohdr); |
Thomas Graf | bfa83a9 | 2005-11-10 02:25:51 +0100 | [diff] [blame] | 614 | |
| 615 | /** |
| 616 | * nla_put - Add a netlink attribute to a socket buffer |
| 617 | * @skb: socket buffer to add attribute to |
| 618 | * @attrtype: attribute type |
| 619 | * @attrlen: length of attribute payload |
| 620 | * @data: head of attribute payload |
| 621 | * |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 622 | * Returns -EMSGSIZE if the tailroom of the skb is insufficient to store |
Thomas Graf | bfa83a9 | 2005-11-10 02:25:51 +0100 | [diff] [blame] | 623 | * the attribute header and payload. |
| 624 | */ |
| 625 | int nla_put(struct sk_buff *skb, int attrtype, int attrlen, const void *data) |
| 626 | { |
| 627 | if (unlikely(skb_tailroom(skb) < nla_total_size(attrlen))) |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 628 | return -EMSGSIZE; |
Thomas Graf | bfa83a9 | 2005-11-10 02:25:51 +0100 | [diff] [blame] | 629 | |
| 630 | __nla_put(skb, attrtype, attrlen, data); |
| 631 | return 0; |
| 632 | } |
Herbert Xu | 9080021 | 2009-03-11 23:18:32 +0800 | [diff] [blame] | 633 | EXPORT_SYMBOL(nla_put); |
Thomas Graf | bfa83a9 | 2005-11-10 02:25:51 +0100 | [diff] [blame] | 634 | |
Thomas Graf | fe4944e | 2006-08-04 23:03:05 -0700 | [diff] [blame] | 635 | /** |
Nicolas Dichtel | 089bf1a | 2016-04-21 18:58:24 +0200 | [diff] [blame] | 636 | * nla_put_64bit - Add a netlink attribute to a socket buffer and align it |
| 637 | * @skb: socket buffer to add attribute to |
| 638 | * @attrtype: attribute type |
| 639 | * @attrlen: length of attribute payload |
| 640 | * @data: head of attribute payload |
Nicolas Dichtel | 11a9957 | 2016-04-22 17:31:16 +0200 | [diff] [blame] | 641 | * @padattr: attribute type for the padding |
Nicolas Dichtel | 089bf1a | 2016-04-21 18:58:24 +0200 | [diff] [blame] | 642 | * |
| 643 | * Returns -EMSGSIZE if the tailroom of the skb is insufficient to store |
| 644 | * the attribute header and payload. |
| 645 | */ |
| 646 | int nla_put_64bit(struct sk_buff *skb, int attrtype, int attrlen, |
| 647 | const void *data, int padattr) |
| 648 | { |
| 649 | size_t len; |
| 650 | |
| 651 | if (nla_need_padding_for_64bit(skb)) |
| 652 | len = nla_total_size_64bit(attrlen); |
| 653 | else |
| 654 | len = nla_total_size(attrlen); |
| 655 | if (unlikely(skb_tailroom(skb) < len)) |
| 656 | return -EMSGSIZE; |
| 657 | |
| 658 | __nla_put_64bit(skb, attrtype, attrlen, data, padattr); |
| 659 | return 0; |
| 660 | } |
| 661 | EXPORT_SYMBOL(nla_put_64bit); |
| 662 | |
| 663 | /** |
Thomas Graf | fe4944e | 2006-08-04 23:03:05 -0700 | [diff] [blame] | 664 | * nla_put_nohdr - Add a netlink attribute without header |
| 665 | * @skb: socket buffer to add attribute to |
| 666 | * @attrlen: length of attribute payload |
| 667 | * @data: head of attribute payload |
| 668 | * |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 669 | * Returns -EMSGSIZE if the tailroom of the skb is insufficient to store |
Thomas Graf | fe4944e | 2006-08-04 23:03:05 -0700 | [diff] [blame] | 670 | * the attribute payload. |
| 671 | */ |
| 672 | int nla_put_nohdr(struct sk_buff *skb, int attrlen, const void *data) |
| 673 | { |
| 674 | if (unlikely(skb_tailroom(skb) < NLA_ALIGN(attrlen))) |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 675 | return -EMSGSIZE; |
Thomas Graf | fe4944e | 2006-08-04 23:03:05 -0700 | [diff] [blame] | 676 | |
| 677 | __nla_put_nohdr(skb, attrlen, data); |
| 678 | return 0; |
| 679 | } |
Herbert Xu | 9080021 | 2009-03-11 23:18:32 +0800 | [diff] [blame] | 680 | EXPORT_SYMBOL(nla_put_nohdr); |
Thomas Graf | bfa83a9 | 2005-11-10 02:25:51 +0100 | [diff] [blame] | 681 | |
Patrick McHardy | 01480e1 | 2008-01-22 22:10:59 -0800 | [diff] [blame] | 682 | /** |
| 683 | * nla_append - Add a netlink attribute without header or padding |
| 684 | * @skb: socket buffer to add attribute to |
| 685 | * @attrlen: length of attribute payload |
| 686 | * @data: head of attribute payload |
| 687 | * |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 688 | * Returns -EMSGSIZE if the tailroom of the skb is insufficient to store |
Patrick McHardy | 01480e1 | 2008-01-22 22:10:59 -0800 | [diff] [blame] | 689 | * the attribute payload. |
| 690 | */ |
| 691 | int nla_append(struct sk_buff *skb, int attrlen, const void *data) |
| 692 | { |
| 693 | if (unlikely(skb_tailroom(skb) < NLA_ALIGN(attrlen))) |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 694 | return -EMSGSIZE; |
Patrick McHardy | 01480e1 | 2008-01-22 22:10:59 -0800 | [diff] [blame] | 695 | |
Johannes Berg | 59ae1d1 | 2017-06-16 14:29:20 +0200 | [diff] [blame] | 696 | skb_put_data(skb, data, attrlen); |
Patrick McHardy | 01480e1 | 2008-01-22 22:10:59 -0800 | [diff] [blame] | 697 | return 0; |
| 698 | } |
Herbert Xu | 9080021 | 2009-03-11 23:18:32 +0800 | [diff] [blame] | 699 | EXPORT_SYMBOL(nla_append); |
| 700 | #endif |