blob: 6dcbe1bedd3bbdb5f2b78e225ade822507b93b92 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Thomas Grafbfa83a92005-11-10 02:25:51 +01002/*
3 * NETLINK Netlink attributes
4 *
5 * Authors: Thomas Graf <tgraf@suug.ch>
6 * Alexey Kuznetsov <kuznet@ms2.inr.ac.ru>
7 */
8
Paul Gortmaker8bc3bcc2011-11-16 21:29:17 -05009#include <linux/export.h>
Thomas Grafbfa83a92005-11-10 02:25:51 +010010#include <linux/kernel.h>
11#include <linux/errno.h>
12#include <linux/jiffies.h>
Thomas Grafbfa83a92005-11-10 02:25:51 +010013#include <linux/skbuff.h>
14#include <linux/string.h>
15#include <linux/types.h>
16#include <net/netlink.h>
17
David Ahern6e237d02017-12-06 20:09:12 -080018/* 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 Ahern28033ae2017-11-07 21:59:40 -080023static const u8 nla_attr_len[NLA_TYPE_MAX+1] = {
Thomas Grafbfa83a92005-11-10 02:25:51 +010024 [NLA_U8] = sizeof(u8),
25 [NLA_U16] = sizeof(u16),
26 [NLA_U32] = sizeof(u32),
27 [NLA_U64] = sizeof(u64),
Julian Anastasov9eca2eb2012-08-25 22:47:57 +000028 [NLA_S8] = sizeof(s8),
29 [NLA_S16] = sizeof(s16),
30 [NLA_S32] = sizeof(s32),
31 [NLA_S64] = sizeof(s64),
Thomas Grafbfa83a92005-11-10 02:25:51 +010032};
33
David Ahern28033ae2017-11-07 21:59:40 -080034static const u8 nla_attr_minlen[NLA_TYPE_MAX+1] = {
David Ahern6e237d02017-12-06 20:09:12 -080035 [NLA_U8] = sizeof(u8),
36 [NLA_U16] = sizeof(u16),
37 [NLA_U32] = sizeof(u32),
38 [NLA_U64] = sizeof(u64),
David Ahern28033ae2017-11-07 21:59:40 -080039 [NLA_MSECS] = sizeof(u64),
40 [NLA_NESTED] = NLA_HDRLEN,
David Ahern6e237d02017-12-06 20:09:12 -080041 [NLA_S8] = sizeof(s8),
42 [NLA_S16] = sizeof(s16),
43 [NLA_S32] = sizeof(s32),
44 [NLA_S64] = sizeof(s64),
David Ahern28033ae2017-11-07 21:59:40 -080045};
46
Johannes Berg7690aa12020-04-30 22:13:06 +020047/*
48 * Nested policies might refer back to the original
49 * policy in some cases, and userspace could try to
50 * abuse that and recurse by nesting in the right
51 * ways. Limit recursion to avoid this problem.
52 */
53#define MAX_POLICY_RECURSION_DEPTH 10
54
55static int __nla_validate_parse(const struct nlattr *head, int len, int maxtype,
56 const struct nla_policy *policy,
57 unsigned int validate,
58 struct netlink_ext_ack *extack,
59 struct nlattr **tb, unsigned int depth);
60
Jamal Hadi Salim64c83d82017-07-30 13:24:49 -040061static int validate_nla_bitfield32(const struct nlattr *nla,
Johannes Berg47a14942020-04-30 22:13:05 +020062 const u32 valid_flags_mask)
Jamal Hadi Salim64c83d82017-07-30 13:24:49 -040063{
64 const struct nla_bitfield32 *bf = nla_data(nla);
Jamal Hadi Salim64c83d82017-07-30 13:24:49 -040065
Johannes Berg48fde902018-09-26 11:15:31 +020066 if (!valid_flags_mask)
Jamal Hadi Salim64c83d82017-07-30 13:24:49 -040067 return -EINVAL;
68
69 /*disallow invalid bit selector */
Johannes Berg47a14942020-04-30 22:13:05 +020070 if (bf->selector & ~valid_flags_mask)
Jamal Hadi Salim64c83d82017-07-30 13:24:49 -040071 return -EINVAL;
72
73 /*disallow invalid bit values */
Johannes Berg47a14942020-04-30 22:13:05 +020074 if (bf->value & ~valid_flags_mask)
Jamal Hadi Salim64c83d82017-07-30 13:24:49 -040075 return -EINVAL;
76
77 /*disallow valid bit values that are not selected*/
78 if (bf->value & ~bf->selector)
79 return -EINVAL;
80
81 return 0;
82}
83
Johannes Berg1501d132018-09-26 11:15:34 +020084static int nla_validate_array(const struct nlattr *head, int len, int maxtype,
85 const struct nla_policy *policy,
Johannes Berg8cb08172019-04-26 14:07:28 +020086 struct netlink_ext_ack *extack,
Johannes Berg7690aa12020-04-30 22:13:06 +020087 unsigned int validate, unsigned int depth)
Johannes Berg1501d132018-09-26 11:15:34 +020088{
89 const struct nlattr *entry;
90 int rem;
91
92 nla_for_each_attr(entry, head, len, rem) {
93 int ret;
94
95 if (nla_len(entry) == 0)
96 continue;
97
98 if (nla_len(entry) < NLA_HDRLEN) {
99 NL_SET_ERR_MSG_ATTR(extack, entry,
100 "Array element too short");
101 return -ERANGE;
102 }
103
Johannes Berg7690aa12020-04-30 22:13:06 +0200104 ret = __nla_validate_parse(nla_data(entry), nla_len(entry),
105 maxtype, policy, validate, extack,
106 NULL, depth + 1);
Johannes Berg1501d132018-09-26 11:15:34 +0200107 if (ret < 0)
108 return ret;
109 }
110
111 return 0;
112}
113
Johannes Bergd06a09b2020-04-30 22:13:08 +0200114static int nla_validate_int_range_unsigned(const struct nla_policy *pt,
115 const struct nlattr *nla,
116 struct netlink_ext_ack *extack)
Johannes Berg3e48be02018-09-27 11:28:35 +0200117{
Johannes Bergd06a09b2020-04-30 22:13:08 +0200118 struct netlink_range_validation _range = {
119 .min = 0,
120 .max = U64_MAX,
121 }, *range = &_range;
122 u64 value;
Johannes Berg3e48be02018-09-27 11:28:35 +0200123
Johannes Bergd06a09b2020-04-30 22:13:08 +0200124 WARN_ON_ONCE(pt->validation_type != NLA_VALIDATE_RANGE_PTR &&
125 (pt->min < 0 || pt->max < 0));
126
127 switch (pt->validation_type) {
128 case NLA_VALIDATE_RANGE:
129 range->min = pt->min;
130 range->max = pt->max;
131 break;
132 case NLA_VALIDATE_RANGE_PTR:
133 range = pt->range;
134 break;
135 case NLA_VALIDATE_MIN:
136 range->min = pt->min;
137 break;
138 case NLA_VALIDATE_MAX:
139 range->max = pt->max;
140 break;
141 }
Johannes Berg3e48be02018-09-27 11:28:35 +0200142
143 switch (pt->type) {
144 case NLA_U8:
145 value = nla_get_u8(nla);
146 break;
147 case NLA_U16:
148 value = nla_get_u16(nla);
149 break;
150 case NLA_U32:
151 value = nla_get_u32(nla);
152 break;
Johannes Bergd06a09b2020-04-30 22:13:08 +0200153 case NLA_U64:
Johannes Bergda4063b2020-04-30 22:13:09 +0200154 case NLA_MSECS:
Johannes Bergd06a09b2020-04-30 22:13:08 +0200155 value = nla_get_u64(nla);
156 break;
157 default:
158 return -EINVAL;
159 }
160
161 if (value < range->min || value > range->max) {
162 NL_SET_ERR_MSG_ATTR(extack, nla,
163 "integer out of range");
164 return -ERANGE;
165 }
166
167 return 0;
168}
169
170static int nla_validate_int_range_signed(const struct nla_policy *pt,
171 const struct nlattr *nla,
172 struct netlink_ext_ack *extack)
173{
174 struct netlink_range_validation_signed _range = {
175 .min = S64_MIN,
176 .max = S64_MAX,
177 }, *range = &_range;
178 s64 value;
179
180 switch (pt->validation_type) {
181 case NLA_VALIDATE_RANGE:
182 range->min = pt->min;
183 range->max = pt->max;
184 break;
185 case NLA_VALIDATE_RANGE_PTR:
186 range = pt->range_signed;
187 break;
188 case NLA_VALIDATE_MIN:
189 range->min = pt->min;
190 break;
191 case NLA_VALIDATE_MAX:
192 range->max = pt->max;
193 break;
194 }
195
196 switch (pt->type) {
Johannes Berg3e48be02018-09-27 11:28:35 +0200197 case NLA_S8:
198 value = nla_get_s8(nla);
199 break;
200 case NLA_S16:
201 value = nla_get_s16(nla);
202 break;
203 case NLA_S32:
204 value = nla_get_s32(nla);
205 break;
206 case NLA_S64:
207 value = nla_get_s64(nla);
208 break;
Johannes Berg3e48be02018-09-27 11:28:35 +0200209 default:
Johannes Berg3e48be02018-09-27 11:28:35 +0200210 return -EINVAL;
211 }
212
Johannes Bergd06a09b2020-04-30 22:13:08 +0200213 if (value < range->min || value > range->max) {
Johannes Berg3e48be02018-09-27 11:28:35 +0200214 NL_SET_ERR_MSG_ATTR(extack, nla,
215 "integer out of range");
216 return -ERANGE;
217 }
218
219 return 0;
220}
221
Johannes Bergd06a09b2020-04-30 22:13:08 +0200222static int nla_validate_int_range(const struct nla_policy *pt,
223 const struct nlattr *nla,
224 struct netlink_ext_ack *extack)
225{
226 switch (pt->type) {
227 case NLA_U8:
228 case NLA_U16:
229 case NLA_U32:
230 case NLA_U64:
Johannes Bergda4063b2020-04-30 22:13:09 +0200231 case NLA_MSECS:
Johannes Bergd06a09b2020-04-30 22:13:08 +0200232 return nla_validate_int_range_unsigned(pt, nla, extack);
233 case NLA_S8:
234 case NLA_S16:
235 case NLA_S32:
236 case NLA_S64:
237 return nla_validate_int_range_signed(pt, nla, extack);
238 default:
239 WARN_ON(1);
240 return -EINVAL;
241 }
242}
243
Jan Engelhardt36546542010-11-16 09:52:32 -0800244static int validate_nla(const struct nlattr *nla, int maxtype,
Johannes Berg8cb08172019-04-26 14:07:28 +0200245 const struct nla_policy *policy, unsigned int validate,
Johannes Berg7690aa12020-04-30 22:13:06 +0200246 struct netlink_ext_ack *extack, unsigned int depth)
Thomas Grafbfa83a92005-11-10 02:25:51 +0100247{
Johannes Berg56738f42019-04-26 14:07:30 +0200248 u16 strict_start_type = policy[0].strict_start_type;
Patrick McHardyef7c79e2007-06-05 12:38:30 -0700249 const struct nla_policy *pt;
Thomas Graf8f4c1f92007-09-12 14:44:36 +0200250 int minlen = 0, attrlen = nla_len(nla), type = nla_type(nla);
Johannes Bergc29f1842018-09-26 11:15:32 +0200251 int err = -ERANGE;
Thomas Grafbfa83a92005-11-10 02:25:51 +0100252
Johannes Berg56738f42019-04-26 14:07:30 +0200253 if (strict_start_type && type >= strict_start_type)
254 validate |= NL_VALIDATE_STRICT;
255
Thomas Graf8f4c1f92007-09-12 14:44:36 +0200256 if (type <= 0 || type > maxtype)
Thomas Grafbfa83a92005-11-10 02:25:51 +0100257 return 0;
258
Thomas Graf8f4c1f92007-09-12 14:44:36 +0200259 pt = &policy[type];
Thomas Grafbfa83a92005-11-10 02:25:51 +0100260
261 BUG_ON(pt->type > NLA_TYPE_MAX);
262
Johannes Bergb60b87f2018-09-17 11:57:29 +0200263 if ((nla_attr_len[pt->type] && attrlen != nla_attr_len[pt->type]) ||
Johannes Bergc7721c02020-04-30 22:13:10 +0200264 (pt->type == NLA_EXACT_LEN &&
265 pt->validation_type == NLA_VALIDATE_WARN_TOO_LONG &&
266 attrlen != pt->len)) {
David Ahern6e237d02017-12-06 20:09:12 -0800267 pr_warn_ratelimited("netlink: '%s': attribute type %d has an invalid length.\n",
268 current->comm, type);
Johannes Berg8cb08172019-04-26 14:07:28 +0200269 if (validate & NL_VALIDATE_STRICT_ATTRS) {
270 NL_SET_ERR_MSG_ATTR(extack, nla,
271 "invalid attribute length");
272 return -EINVAL;
273 }
David Ahern28033ae2017-11-07 21:59:40 -0800274 }
275
Michal Kubecekb424e432019-05-02 16:15:10 +0200276 if (validate & NL_VALIDATE_NESTED) {
277 if ((pt->type == NLA_NESTED || pt->type == NLA_NESTED_ARRAY) &&
278 !(nla->nla_type & NLA_F_NESTED)) {
279 NL_SET_ERR_MSG_ATTR(extack, nla,
280 "NLA_F_NESTED is missing");
281 return -EINVAL;
282 }
283 if (pt->type != NLA_NESTED && pt->type != NLA_NESTED_ARRAY &&
284 pt->type != NLA_UNSPEC && (nla->nla_type & NLA_F_NESTED)) {
285 NL_SET_ERR_MSG_ATTR(extack, nla,
286 "NLA_F_NESTED not expected");
287 return -EINVAL;
288 }
289 }
290
Thomas Grafa5531a52006-08-26 20:11:47 -0700291 switch (pt->type) {
Johannes Berg568b7422018-09-17 11:57:28 +0200292 case NLA_REJECT:
Johannes Berg47a14942020-04-30 22:13:05 +0200293 if (extack && pt->reject_message) {
Johannes Bergc29f1842018-09-26 11:15:32 +0200294 NL_SET_BAD_ATTR(extack, nla);
Johannes Berg47a14942020-04-30 22:13:05 +0200295 extack->_msg = pt->reject_message;
Johannes Bergc29f1842018-09-26 11:15:32 +0200296 return -EINVAL;
297 }
298 err = -EINVAL;
299 goto out_err;
Johannes Berg568b7422018-09-17 11:57:28 +0200300
Thomas Grafa5531a52006-08-26 20:11:47 -0700301 case NLA_FLAG:
302 if (attrlen > 0)
Johannes Bergc29f1842018-09-26 11:15:32 +0200303 goto out_err;
Thomas Grafa5531a52006-08-26 20:11:47 -0700304 break;
Thomas Grafbfa83a92005-11-10 02:25:51 +0100305
Jamal Hadi Salim64c83d82017-07-30 13:24:49 -0400306 case NLA_BITFIELD32:
307 if (attrlen != sizeof(struct nla_bitfield32))
Johannes Bergc29f1842018-09-26 11:15:32 +0200308 goto out_err;
Jamal Hadi Salim64c83d82017-07-30 13:24:49 -0400309
Johannes Berg47a14942020-04-30 22:13:05 +0200310 err = validate_nla_bitfield32(nla, pt->bitfield32_valid);
Johannes Bergc29f1842018-09-26 11:15:32 +0200311 if (err)
312 goto out_err;
313 break;
Jamal Hadi Salim64c83d82017-07-30 13:24:49 -0400314
Thomas Grafa5531a52006-08-26 20:11:47 -0700315 case NLA_NUL_STRING:
316 if (pt->len)
317 minlen = min_t(int, attrlen, pt->len + 1);
318 else
319 minlen = attrlen;
Thomas Grafbfa83a92005-11-10 02:25:51 +0100320
Johannes Bergc29f1842018-09-26 11:15:32 +0200321 if (!minlen || memchr(nla_data(nla), '\0', minlen) == NULL) {
322 err = -EINVAL;
323 goto out_err;
324 }
Thomas Grafa5531a52006-08-26 20:11:47 -0700325 /* fall through */
326
327 case NLA_STRING:
328 if (attrlen < 1)
Johannes Bergc29f1842018-09-26 11:15:32 +0200329 goto out_err;
Thomas Grafa5531a52006-08-26 20:11:47 -0700330
331 if (pt->len) {
332 char *buf = nla_data(nla);
333
334 if (buf[attrlen - 1] == '\0')
335 attrlen--;
336
337 if (attrlen > pt->len)
Johannes Bergc29f1842018-09-26 11:15:32 +0200338 goto out_err;
Thomas Grafa5531a52006-08-26 20:11:47 -0700339 }
340 break;
341
Johannes Bergd30045a2007-03-23 11:37:48 -0700342 case NLA_BINARY:
343 if (pt->len && attrlen > pt->len)
Johannes Bergc29f1842018-09-26 11:15:32 +0200344 goto out_err;
Johannes Bergd30045a2007-03-23 11:37:48 -0700345 break;
346
Patrick McHardyea5693c2008-11-28 03:05:19 -0800347 case NLA_NESTED:
348 /* a nested attributes is allowed to be empty; if its not,
349 * it must have a size of at least NLA_HDRLEN.
350 */
351 if (attrlen == 0)
352 break;
Johannes Berg9a659a32018-09-26 11:15:33 +0200353 if (attrlen < NLA_HDRLEN)
354 goto out_err;
Johannes Berg47a14942020-04-30 22:13:05 +0200355 if (pt->nested_policy) {
Johannes Berg7690aa12020-04-30 22:13:06 +0200356 err = __nla_validate_parse(nla_data(nla), nla_len(nla),
357 pt->len, pt->nested_policy,
358 validate, extack, NULL,
359 depth + 1);
Johannes Berg9a659a32018-09-26 11:15:33 +0200360 if (err < 0) {
361 /*
362 * return directly to preserve the inner
363 * error message/attribute pointer
364 */
365 return err;
366 }
367 }
368 break;
Johannes Berg1501d132018-09-26 11:15:34 +0200369 case NLA_NESTED_ARRAY:
370 /* a nested array attribute is allowed to be empty; if its not,
371 * it must have a size of at least NLA_HDRLEN.
372 */
373 if (attrlen == 0)
374 break;
375 if (attrlen < NLA_HDRLEN)
376 goto out_err;
Johannes Berg47a14942020-04-30 22:13:05 +0200377 if (pt->nested_policy) {
Johannes Berg1501d132018-09-26 11:15:34 +0200378 int err;
379
380 err = nla_validate_array(nla_data(nla), nla_len(nla),
Johannes Berg47a14942020-04-30 22:13:05 +0200381 pt->len, pt->nested_policy,
Johannes Berg7690aa12020-04-30 22:13:06 +0200382 extack, validate, depth);
Johannes Berg1501d132018-09-26 11:15:34 +0200383 if (err < 0) {
384 /*
385 * return directly to preserve the inner
386 * error message/attribute pointer
387 */
388 return err;
389 }
390 }
391 break;
Johannes Berg6f455f52019-04-26 14:07:27 +0200392
393 case NLA_UNSPEC:
Johannes Berg8cb08172019-04-26 14:07:28 +0200394 if (validate & NL_VALIDATE_UNSPEC) {
395 NL_SET_ERR_MSG_ATTR(extack, nla,
396 "Unsupported attribute");
397 return -EINVAL;
398 }
399 /* fall through */
Johannes Berg6f455f52019-04-26 14:07:27 +0200400 case NLA_MIN_LEN:
401 if (attrlen < pt->len)
402 goto out_err;
403 break;
404
Johannes Bergc7721c02020-04-30 22:13:10 +0200405 case NLA_EXACT_LEN:
406 if (pt->validation_type != NLA_VALIDATE_WARN_TOO_LONG) {
407 if (attrlen != pt->len)
408 goto out_err;
409 break;
410 }
411 /* fall through */
Thomas Grafa5531a52006-08-26 20:11:47 -0700412 default:
413 if (pt->len)
414 minlen = pt->len;
Johannes Berg6f455f52019-04-26 14:07:27 +0200415 else
Thomas Grafa5531a52006-08-26 20:11:47 -0700416 minlen = nla_attr_minlen[pt->type];
417
418 if (attrlen < minlen)
Johannes Bergc29f1842018-09-26 11:15:32 +0200419 goto out_err;
Thomas Grafa5531a52006-08-26 20:11:47 -0700420 }
Thomas Grafbfa83a92005-11-10 02:25:51 +0100421
Johannes Berg3e48be02018-09-27 11:28:35 +0200422 /* further validation */
423 switch (pt->validation_type) {
424 case NLA_VALIDATE_NONE:
425 /* nothing to do */
426 break;
Johannes Bergd06a09b2020-04-30 22:13:08 +0200427 case NLA_VALIDATE_RANGE_PTR:
Johannes Berg3e48be02018-09-27 11:28:35 +0200428 case NLA_VALIDATE_RANGE:
429 case NLA_VALIDATE_MIN:
430 case NLA_VALIDATE_MAX:
431 err = nla_validate_int_range(pt, nla, extack);
432 if (err)
433 return err;
434 break;
Johannes Berg33188bd2018-09-27 11:28:36 +0200435 case NLA_VALIDATE_FUNCTION:
436 if (pt->validate) {
437 err = pt->validate(nla, extack);
438 if (err)
439 return err;
440 }
441 break;
Johannes Berg3e48be02018-09-27 11:28:35 +0200442 }
443
Thomas Grafbfa83a92005-11-10 02:25:51 +0100444 return 0;
Johannes Bergc29f1842018-09-26 11:15:32 +0200445out_err:
446 NL_SET_ERR_MSG_ATTR(extack, nla, "Attribute failed policy validation");
447 return err;
Thomas Grafbfa83a92005-11-10 02:25:51 +0100448}
449
Johannes Berg8cb08172019-04-26 14:07:28 +0200450static int __nla_validate_parse(const struct nlattr *head, int len, int maxtype,
451 const struct nla_policy *policy,
452 unsigned int validate,
453 struct netlink_ext_ack *extack,
Johannes Berg7690aa12020-04-30 22:13:06 +0200454 struct nlattr **tb, unsigned int depth)
Thomas Grafbfa83a92005-11-10 02:25:51 +0100455{
Jan Engelhardt36546542010-11-16 09:52:32 -0800456 const struct nlattr *nla;
Johannes Bergfceb6432017-04-12 14:34:07 +0200457 int rem;
Thomas Grafbfa83a92005-11-10 02:25:51 +0100458
Johannes Berg7690aa12020-04-30 22:13:06 +0200459 if (depth >= MAX_POLICY_RECURSION_DEPTH) {
460 NL_SET_ERR_MSG(extack,
461 "allowed policy recursion depth exceeded");
462 return -EINVAL;
463 }
464
Johannes Berg8cb08172019-04-26 14:07:28 +0200465 if (tb)
466 memset(tb, 0, sizeof(struct nlattr *) * (maxtype + 1));
Johannes Bergfceb6432017-04-12 14:34:07 +0200467
Johannes Berg8cb08172019-04-26 14:07:28 +0200468 nla_for_each_attr(nla, head, len, rem) {
469 u16 type = nla_type(nla);
470
471 if (type == 0 || type > maxtype) {
472 if (validate & NL_VALIDATE_MAXTYPE) {
Michal Kubecekd54a16b2019-05-02 16:15:10 +0200473 NL_SET_ERR_MSG_ATTR(extack, nla,
474 "Unknown attribute type");
Johannes Berg8cb08172019-04-26 14:07:28 +0200475 return -EINVAL;
476 }
477 continue;
478 }
479 if (policy) {
480 int err = validate_nla(nla, maxtype, policy,
Johannes Berg7690aa12020-04-30 22:13:06 +0200481 validate, extack, depth);
Johannes Berg8cb08172019-04-26 14:07:28 +0200482
483 if (err < 0)
484 return err;
485 }
486
487 if (tb)
488 tb[type] = (struct nlattr *)nla;
489 }
490
491 if (unlikely(rem > 0)) {
492 pr_warn_ratelimited("netlink: %d bytes leftover after parsing attributes in process `%s'.\n",
493 rem, current->comm);
494 NL_SET_ERR_MSG(extack, "bytes leftover after parsing attributes");
495 if (validate & NL_VALIDATE_TRAILING)
496 return -EINVAL;
Thomas Grafbfa83a92005-11-10 02:25:51 +0100497 }
498
Johannes Bergfceb6432017-04-12 14:34:07 +0200499 return 0;
Thomas Grafbfa83a92005-11-10 02:25:51 +0100500}
Johannes Berg8cb08172019-04-26 14:07:28 +0200501
502/**
503 * __nla_validate - Validate a stream of attributes
504 * @head: head of attribute stream
505 * @len: length of attribute stream
506 * @maxtype: maximum attribute type to be expected
507 * @policy: validation policy
508 * @validate: validation strictness
509 * @extack: extended ACK report struct
510 *
511 * Validates all attributes in the specified attribute stream against the
512 * specified policy. Validation depends on the validate flags passed, see
513 * &enum netlink_validation for more details on that.
514 * See documenation of struct nla_policy for more details.
515 *
516 * Returns 0 on success or a negative error code.
517 */
518int __nla_validate(const struct nlattr *head, int len, int maxtype,
519 const struct nla_policy *policy, unsigned int validate,
520 struct netlink_ext_ack *extack)
521{
522 return __nla_validate_parse(head, len, maxtype, policy, validate,
Johannes Berg7690aa12020-04-30 22:13:06 +0200523 extack, NULL, 0);
Johannes Berg8cb08172019-04-26 14:07:28 +0200524}
525EXPORT_SYMBOL(__nla_validate);
Thomas Grafbfa83a92005-11-10 02:25:51 +0100526
527/**
Holger Eitzenbergere487eb992009-03-25 18:26:30 +0100528 * nla_policy_len - Determin the max. length of a policy
529 * @policy: policy to use
530 * @n: number of policies
531 *
532 * Determines the max. length of the policy. It is currently used
533 * to allocated Netlink buffers roughly the size of the actual
534 * message.
535 *
536 * Returns 0 on success or a negative error code.
537 */
538int
539nla_policy_len(const struct nla_policy *p, int n)
540{
541 int i, len = 0;
542
Lars Ellenberge3fa3af2011-02-28 12:38:25 -0800543 for (i = 0; i < n; i++, p++) {
Holger Eitzenbergere487eb992009-03-25 18:26:30 +0100544 if (p->len)
545 len += nla_total_size(p->len);
David Ahern28033ae2017-11-07 21:59:40 -0800546 else if (nla_attr_len[p->type])
547 len += nla_total_size(nla_attr_len[p->type]);
Holger Eitzenbergere487eb992009-03-25 18:26:30 +0100548 else if (nla_attr_minlen[p->type])
549 len += nla_total_size(nla_attr_minlen[p->type]);
550 }
551
552 return len;
553}
Fabian Frederick6d6a1382014-06-04 16:11:57 -0700554EXPORT_SYMBOL(nla_policy_len);
Holger Eitzenbergere487eb992009-03-25 18:26:30 +0100555
556/**
Johannes Berg8cb08172019-04-26 14:07:28 +0200557 * __nla_parse - Parse a stream of attributes into a tb buffer
Thomas Grafbfa83a92005-11-10 02:25:51 +0100558 * @tb: destination array with maxtype+1 elements
559 * @maxtype: maximum attribute type to be expected
560 * @head: head of attribute stream
561 * @len: length of attribute stream
Julius Volz10b595a2008-06-27 20:02:14 -0700562 * @policy: validation policy
Johannes Berg8cb08172019-04-26 14:07:28 +0200563 * @validate: validation strictness
564 * @extack: extended ACK pointer
Thomas Grafbfa83a92005-11-10 02:25:51 +0100565 *
566 * Parses a stream of attributes and stores a pointer to each attribute in
Johannes Berg8cb08172019-04-26 14:07:28 +0200567 * the tb array accessible via the attribute type.
568 * Validation is controlled by the @validate parameter.
Thomas Grafbfa83a92005-11-10 02:25:51 +0100569 *
570 * Returns 0 on success or a negative error code.
571 */
Johannes Berg8cb08172019-04-26 14:07:28 +0200572int __nla_parse(struct nlattr **tb, int maxtype,
573 const struct nlattr *head, int len,
574 const struct nla_policy *policy, unsigned int validate,
575 struct netlink_ext_ack *extack)
Thomas Grafbfa83a92005-11-10 02:25:51 +0100576{
Johannes Berg8cb08172019-04-26 14:07:28 +0200577 return __nla_validate_parse(head, len, maxtype, policy, validate,
Johannes Berg7690aa12020-04-30 22:13:06 +0200578 extack, tb, 0);
Thomas Grafbfa83a92005-11-10 02:25:51 +0100579}
Johannes Berg8cb08172019-04-26 14:07:28 +0200580EXPORT_SYMBOL(__nla_parse);
David Aherna5f6cba2018-10-07 20:16:25 -0700581
Thomas Grafbfa83a92005-11-10 02:25:51 +0100582/**
583 * nla_find - Find a specific attribute in a stream of attributes
584 * @head: head of attribute stream
585 * @len: length of attribute stream
586 * @attrtype: type of attribute to look for
587 *
588 * Returns the first attribute in the stream matching the specified type.
589 */
Jan Engelhardt36546542010-11-16 09:52:32 -0800590struct nlattr *nla_find(const struct nlattr *head, int len, int attrtype)
Thomas Grafbfa83a92005-11-10 02:25:51 +0100591{
Jan Engelhardt36546542010-11-16 09:52:32 -0800592 const struct nlattr *nla;
Thomas Grafbfa83a92005-11-10 02:25:51 +0100593 int rem;
594
595 nla_for_each_attr(nla, head, len, rem)
Thomas Graf8f4c1f92007-09-12 14:44:36 +0200596 if (nla_type(nla) == attrtype)
Jan Engelhardt36546542010-11-16 09:52:32 -0800597 return (struct nlattr *)nla;
Thomas Grafbfa83a92005-11-10 02:25:51 +0100598
599 return NULL;
600}
Fabian Frederick6d6a1382014-06-04 16:11:57 -0700601EXPORT_SYMBOL(nla_find);
Thomas Grafbfa83a92005-11-10 02:25:51 +0100602
603/**
604 * nla_strlcpy - Copy string attribute payload into a sized buffer
605 * @dst: where to copy the string to
Julius Volz10b595a2008-06-27 20:02:14 -0700606 * @nla: attribute to copy the string from
Thomas Grafbfa83a92005-11-10 02:25:51 +0100607 * @dstsize: size of destination buffer
608 *
609 * Copies at most dstsize - 1 bytes into the destination buffer.
610 * The result is always a valid NUL-terminated string. Unlike
611 * strlcpy the destination buffer is always padded out.
612 *
613 * Returns the length of the source buffer.
614 */
615size_t nla_strlcpy(char *dst, const struct nlattr *nla, size_t dstsize)
616{
617 size_t srclen = nla_len(nla);
618 char *src = nla_data(nla);
619
620 if (srclen > 0 && src[srclen - 1] == '\0')
621 srclen--;
622
623 if (dstsize > 0) {
624 size_t len = (srclen >= dstsize) ? dstsize - 1 : srclen;
625
626 memset(dst, 0, dstsize);
627 memcpy(dst, src, len);
628 }
629
630 return srclen;
631}
Fabian Frederick6d6a1382014-06-04 16:11:57 -0700632EXPORT_SYMBOL(nla_strlcpy);
Thomas Grafbfa83a92005-11-10 02:25:51 +0100633
634/**
Phil Sutter2cf0c8b2017-07-27 16:56:40 +0200635 * nla_strdup - Copy string attribute payload into a newly allocated buffer
636 * @nla: attribute to copy the string from
637 * @flags: the type of memory to allocate (see kmalloc).
638 *
639 * Returns a pointer to the allocated buffer or NULL on error.
640 */
641char *nla_strdup(const struct nlattr *nla, gfp_t flags)
642{
643 size_t srclen = nla_len(nla);
644 char *src = nla_data(nla), *dst;
645
646 if (srclen > 0 && src[srclen - 1] == '\0')
647 srclen--;
648
649 dst = kmalloc(srclen + 1, flags);
650 if (dst != NULL) {
651 memcpy(dst, src, srclen);
652 dst[srclen] = '\0';
653 }
654 return dst;
655}
656EXPORT_SYMBOL(nla_strdup);
657
658/**
Thomas Grafbfa83a92005-11-10 02:25:51 +0100659 * nla_memcpy - Copy a netlink attribute into another memory area
660 * @dest: where to copy to memcpy
661 * @src: netlink attribute to copy from
662 * @count: size of the destination area
663 *
664 * Note: The number of bytes copied is limited by the length of
665 * attribute's payload. memcpy
666 *
667 * Returns the number of bytes copied.
668 */
Patrick McHardyb057efd2008-10-28 11:59:11 -0700669int nla_memcpy(void *dest, const struct nlattr *src, int count)
Thomas Grafbfa83a92005-11-10 02:25:51 +0100670{
671 int minlen = min_t(int, count, nla_len(src));
672
673 memcpy(dest, nla_data(src), minlen);
Jiri Benc5899f042015-03-29 16:05:28 +0200674 if (count > minlen)
675 memset(dest + minlen, 0, count - minlen);
Thomas Grafbfa83a92005-11-10 02:25:51 +0100676
677 return minlen;
678}
Fabian Frederick6d6a1382014-06-04 16:11:57 -0700679EXPORT_SYMBOL(nla_memcpy);
Thomas Grafbfa83a92005-11-10 02:25:51 +0100680
681/**
682 * nla_memcmp - Compare an attribute with sized memory area
683 * @nla: netlink attribute
684 * @data: memory area
685 * @size: size of memory area
686 */
687int nla_memcmp(const struct nlattr *nla, const void *data,
688 size_t size)
689{
690 int d = nla_len(nla) - size;
691
692 if (d == 0)
693 d = memcmp(nla_data(nla), data, size);
694
695 return d;
696}
Fabian Frederick6d6a1382014-06-04 16:11:57 -0700697EXPORT_SYMBOL(nla_memcmp);
Thomas Grafbfa83a92005-11-10 02:25:51 +0100698
699/**
700 * nla_strcmp - Compare a string attribute against a string
701 * @nla: netlink string attribute
702 * @str: another string
703 */
704int nla_strcmp(const struct nlattr *nla, const char *str)
705{
Pablo Neira8b7b9322014-04-01 19:38:44 +0200706 int len = strlen(str);
707 char *buf = nla_data(nla);
708 int attrlen = nla_len(nla);
709 int d;
Thomas Grafbfa83a92005-11-10 02:25:51 +0100710
Pablo Neira8b7b9322014-04-01 19:38:44 +0200711 if (attrlen > 0 && buf[attrlen - 1] == '\0')
712 attrlen--;
713
714 d = attrlen - len;
Thomas Grafbfa83a92005-11-10 02:25:51 +0100715 if (d == 0)
716 d = memcmp(nla_data(nla), str, len);
717
718 return d;
719}
Fabian Frederick6d6a1382014-06-04 16:11:57 -0700720EXPORT_SYMBOL(nla_strcmp);
Thomas Grafbfa83a92005-11-10 02:25:51 +0100721
Herbert Xu90800212009-03-11 23:18:32 +0800722#ifdef CONFIG_NET
Thomas Grafbfa83a92005-11-10 02:25:51 +0100723/**
724 * __nla_reserve - reserve room for attribute on the skb
725 * @skb: socket buffer to reserve room on
726 * @attrtype: attribute type
727 * @attrlen: length of attribute payload
728 *
729 * Adds a netlink attribute header to a socket buffer and reserves
730 * room for the payload but does not copy it.
731 *
732 * The caller is responsible to ensure that the skb provides enough
733 * tailroom for the attribute header and payload.
734 */
735struct nlattr *__nla_reserve(struct sk_buff *skb, int attrtype, int attrlen)
736{
737 struct nlattr *nla;
738
Johannes Berg4df864c2017-06-16 14:29:21 +0200739 nla = skb_put(skb, nla_total_size(attrlen));
Thomas Grafbfa83a92005-11-10 02:25:51 +0100740 nla->nla_type = attrtype;
741 nla->nla_len = nla_attr_size(attrlen);
742
743 memset((unsigned char *) nla + nla->nla_len, 0, nla_padlen(attrlen));
744
745 return nla;
746}
Herbert Xu90800212009-03-11 23:18:32 +0800747EXPORT_SYMBOL(__nla_reserve);
Thomas Grafbfa83a92005-11-10 02:25:51 +0100748
749/**
Nicolas Dichtel089bf1a2016-04-21 18:58:24 +0200750 * __nla_reserve_64bit - reserve room for attribute on the skb and align it
751 * @skb: socket buffer to reserve room on
752 * @attrtype: attribute type
753 * @attrlen: length of attribute payload
Nicolas Dichtel11a99572016-04-22 17:31:16 +0200754 * @padattr: attribute type for the padding
Nicolas Dichtel089bf1a2016-04-21 18:58:24 +0200755 *
756 * Adds a netlink attribute header to a socket buffer and reserves
757 * room for the payload but does not copy it. It also ensure that this
Nicolas Dichtel11a99572016-04-22 17:31:16 +0200758 * attribute will have a 64-bit aligned nla_data() area.
Nicolas Dichtel089bf1a2016-04-21 18:58:24 +0200759 *
760 * The caller is responsible to ensure that the skb provides enough
761 * tailroom for the attribute header and payload.
762 */
763struct nlattr *__nla_reserve_64bit(struct sk_buff *skb, int attrtype,
764 int attrlen, int padattr)
765{
766 if (nla_need_padding_for_64bit(skb))
767 nla_align_64bit(skb, padattr);
768
769 return __nla_reserve(skb, attrtype, attrlen);
770}
771EXPORT_SYMBOL(__nla_reserve_64bit);
772
773/**
Thomas Graffe4944e2006-08-04 23:03:05 -0700774 * __nla_reserve_nohdr - reserve room for attribute without header
775 * @skb: socket buffer to reserve room on
776 * @attrlen: length of attribute payload
777 *
778 * Reserves room for attribute payload without a header.
779 *
780 * The caller is responsible to ensure that the skb provides enough
781 * tailroom for the payload.
782 */
783void *__nla_reserve_nohdr(struct sk_buff *skb, int attrlen)
784{
yuan linyub952f4d2017-06-18 22:52:04 +0800785 return skb_put_zero(skb, NLA_ALIGN(attrlen));
Thomas Graffe4944e2006-08-04 23:03:05 -0700786}
Herbert Xu90800212009-03-11 23:18:32 +0800787EXPORT_SYMBOL(__nla_reserve_nohdr);
Thomas Graffe4944e2006-08-04 23:03:05 -0700788
789/**
Thomas Grafbfa83a92005-11-10 02:25:51 +0100790 * nla_reserve - reserve room for attribute on the skb
791 * @skb: socket buffer to reserve room on
792 * @attrtype: attribute type
793 * @attrlen: length of attribute payload
794 *
795 * Adds a netlink attribute header to a socket buffer and reserves
796 * room for the payload but does not copy it.
797 *
798 * Returns NULL if the tailroom of the skb is insufficient to store
799 * the attribute header and payload.
800 */
801struct nlattr *nla_reserve(struct sk_buff *skb, int attrtype, int attrlen)
802{
803 if (unlikely(skb_tailroom(skb) < nla_total_size(attrlen)))
804 return NULL;
805
806 return __nla_reserve(skb, attrtype, attrlen);
807}
Herbert Xu90800212009-03-11 23:18:32 +0800808EXPORT_SYMBOL(nla_reserve);
Thomas Grafbfa83a92005-11-10 02:25:51 +0100809
810/**
Nicolas Dichtel089bf1a2016-04-21 18:58:24 +0200811 * nla_reserve_64bit - reserve room for attribute on the skb and align it
812 * @skb: socket buffer to reserve room on
813 * @attrtype: attribute type
814 * @attrlen: length of attribute payload
Nicolas Dichtel11a99572016-04-22 17:31:16 +0200815 * @padattr: attribute type for the padding
Nicolas Dichtel089bf1a2016-04-21 18:58:24 +0200816 *
817 * Adds a netlink attribute header to a socket buffer and reserves
818 * room for the payload but does not copy it. It also ensure that this
Nicolas Dichtel11a99572016-04-22 17:31:16 +0200819 * attribute will have a 64-bit aligned nla_data() area.
Nicolas Dichtel089bf1a2016-04-21 18:58:24 +0200820 *
821 * Returns NULL if the tailroom of the skb is insufficient to store
822 * the attribute header and payload.
823 */
824struct nlattr *nla_reserve_64bit(struct sk_buff *skb, int attrtype, int attrlen,
825 int padattr)
826{
827 size_t len;
828
829 if (nla_need_padding_for_64bit(skb))
830 len = nla_total_size_64bit(attrlen);
831 else
832 len = nla_total_size(attrlen);
833 if (unlikely(skb_tailroom(skb) < len))
834 return NULL;
835
836 return __nla_reserve_64bit(skb, attrtype, attrlen, padattr);
837}
838EXPORT_SYMBOL(nla_reserve_64bit);
839
840/**
Julius Volz10b595a2008-06-27 20:02:14 -0700841 * nla_reserve_nohdr - reserve room for attribute without header
Thomas Graffe4944e2006-08-04 23:03:05 -0700842 * @skb: socket buffer to reserve room on
Julius Volz10b595a2008-06-27 20:02:14 -0700843 * @attrlen: length of attribute payload
Thomas Graffe4944e2006-08-04 23:03:05 -0700844 *
845 * Reserves room for attribute payload without a header.
846 *
847 * Returns NULL if the tailroom of the skb is insufficient to store
848 * the attribute payload.
849 */
850void *nla_reserve_nohdr(struct sk_buff *skb, int attrlen)
851{
852 if (unlikely(skb_tailroom(skb) < NLA_ALIGN(attrlen)))
853 return NULL;
854
855 return __nla_reserve_nohdr(skb, attrlen);
856}
Herbert Xu90800212009-03-11 23:18:32 +0800857EXPORT_SYMBOL(nla_reserve_nohdr);
Thomas Graffe4944e2006-08-04 23:03:05 -0700858
859/**
Thomas Grafbfa83a92005-11-10 02:25:51 +0100860 * __nla_put - Add a netlink attribute to a socket buffer
861 * @skb: socket buffer to add attribute to
862 * @attrtype: attribute type
863 * @attrlen: length of attribute payload
864 * @data: head of attribute payload
865 *
866 * The caller is responsible to ensure that the skb provides enough
867 * tailroom for the attribute header and payload.
868 */
869void __nla_put(struct sk_buff *skb, int attrtype, int attrlen,
870 const void *data)
871{
872 struct nlattr *nla;
873
874 nla = __nla_reserve(skb, attrtype, attrlen);
875 memcpy(nla_data(nla), data, attrlen);
876}
Herbert Xu90800212009-03-11 23:18:32 +0800877EXPORT_SYMBOL(__nla_put);
Thomas Grafbfa83a92005-11-10 02:25:51 +0100878
Thomas Graffe4944e2006-08-04 23:03:05 -0700879/**
Nicolas Dichtel089bf1a2016-04-21 18:58:24 +0200880 * __nla_put_64bit - Add a netlink attribute to a socket buffer and align it
881 * @skb: socket buffer to add attribute to
882 * @attrtype: attribute type
883 * @attrlen: length of attribute payload
884 * @data: head of attribute payload
Nicolas Dichtel11a99572016-04-22 17:31:16 +0200885 * @padattr: attribute type for the padding
Nicolas Dichtel089bf1a2016-04-21 18:58:24 +0200886 *
887 * The caller is responsible to ensure that the skb provides enough
888 * tailroom for the attribute header and payload.
889 */
890void __nla_put_64bit(struct sk_buff *skb, int attrtype, int attrlen,
891 const void *data, int padattr)
892{
893 struct nlattr *nla;
894
895 nla = __nla_reserve_64bit(skb, attrtype, attrlen, padattr);
896 memcpy(nla_data(nla), data, attrlen);
897}
898EXPORT_SYMBOL(__nla_put_64bit);
899
900/**
Thomas Graffe4944e2006-08-04 23:03:05 -0700901 * __nla_put_nohdr - Add a netlink attribute without header
902 * @skb: socket buffer to add attribute to
903 * @attrlen: length of attribute payload
904 * @data: head of attribute payload
905 *
906 * The caller is responsible to ensure that the skb provides enough
907 * tailroom for the attribute payload.
908 */
909void __nla_put_nohdr(struct sk_buff *skb, int attrlen, const void *data)
910{
911 void *start;
912
913 start = __nla_reserve_nohdr(skb, attrlen);
914 memcpy(start, data, attrlen);
915}
Herbert Xu90800212009-03-11 23:18:32 +0800916EXPORT_SYMBOL(__nla_put_nohdr);
Thomas Grafbfa83a92005-11-10 02:25:51 +0100917
918/**
919 * nla_put - Add a netlink attribute to a socket buffer
920 * @skb: socket buffer to add attribute to
921 * @attrtype: attribute type
922 * @attrlen: length of attribute payload
923 * @data: head of attribute payload
924 *
Thomas Grafbc3ed282008-06-03 16:36:54 -0700925 * Returns -EMSGSIZE if the tailroom of the skb is insufficient to store
Thomas Grafbfa83a92005-11-10 02:25:51 +0100926 * the attribute header and payload.
927 */
928int nla_put(struct sk_buff *skb, int attrtype, int attrlen, const void *data)
929{
930 if (unlikely(skb_tailroom(skb) < nla_total_size(attrlen)))
Thomas Grafbc3ed282008-06-03 16:36:54 -0700931 return -EMSGSIZE;
Thomas Grafbfa83a92005-11-10 02:25:51 +0100932
933 __nla_put(skb, attrtype, attrlen, data);
934 return 0;
935}
Herbert Xu90800212009-03-11 23:18:32 +0800936EXPORT_SYMBOL(nla_put);
Thomas Grafbfa83a92005-11-10 02:25:51 +0100937
Thomas Graffe4944e2006-08-04 23:03:05 -0700938/**
Nicolas Dichtel089bf1a2016-04-21 18:58:24 +0200939 * nla_put_64bit - Add a netlink attribute to a socket buffer and align it
940 * @skb: socket buffer to add attribute to
941 * @attrtype: attribute type
942 * @attrlen: length of attribute payload
943 * @data: head of attribute payload
Nicolas Dichtel11a99572016-04-22 17:31:16 +0200944 * @padattr: attribute type for the padding
Nicolas Dichtel089bf1a2016-04-21 18:58:24 +0200945 *
946 * Returns -EMSGSIZE if the tailroom of the skb is insufficient to store
947 * the attribute header and payload.
948 */
949int nla_put_64bit(struct sk_buff *skb, int attrtype, int attrlen,
950 const void *data, int padattr)
951{
952 size_t len;
953
954 if (nla_need_padding_for_64bit(skb))
955 len = nla_total_size_64bit(attrlen);
956 else
957 len = nla_total_size(attrlen);
958 if (unlikely(skb_tailroom(skb) < len))
959 return -EMSGSIZE;
960
961 __nla_put_64bit(skb, attrtype, attrlen, data, padattr);
962 return 0;
963}
964EXPORT_SYMBOL(nla_put_64bit);
965
966/**
Thomas Graffe4944e2006-08-04 23:03:05 -0700967 * nla_put_nohdr - Add a netlink attribute without header
968 * @skb: socket buffer to add attribute to
969 * @attrlen: length of attribute payload
970 * @data: head of attribute payload
971 *
Thomas Grafbc3ed282008-06-03 16:36:54 -0700972 * Returns -EMSGSIZE if the tailroom of the skb is insufficient to store
Thomas Graffe4944e2006-08-04 23:03:05 -0700973 * the attribute payload.
974 */
975int nla_put_nohdr(struct sk_buff *skb, int attrlen, const void *data)
976{
977 if (unlikely(skb_tailroom(skb) < NLA_ALIGN(attrlen)))
Thomas Grafbc3ed282008-06-03 16:36:54 -0700978 return -EMSGSIZE;
Thomas Graffe4944e2006-08-04 23:03:05 -0700979
980 __nla_put_nohdr(skb, attrlen, data);
981 return 0;
982}
Herbert Xu90800212009-03-11 23:18:32 +0800983EXPORT_SYMBOL(nla_put_nohdr);
Thomas Grafbfa83a92005-11-10 02:25:51 +0100984
Patrick McHardy01480e12008-01-22 22:10:59 -0800985/**
986 * nla_append - Add a netlink attribute without header or padding
987 * @skb: socket buffer to add attribute to
988 * @attrlen: length of attribute payload
989 * @data: head of attribute payload
990 *
Thomas Grafbc3ed282008-06-03 16:36:54 -0700991 * Returns -EMSGSIZE if the tailroom of the skb is insufficient to store
Patrick McHardy01480e12008-01-22 22:10:59 -0800992 * the attribute payload.
993 */
994int nla_append(struct sk_buff *skb, int attrlen, const void *data)
995{
996 if (unlikely(skb_tailroom(skb) < NLA_ALIGN(attrlen)))
Thomas Grafbc3ed282008-06-03 16:36:54 -0700997 return -EMSGSIZE;
Patrick McHardy01480e12008-01-22 22:10:59 -0800998
Johannes Berg59ae1d12017-06-16 14:29:20 +0200999 skb_put_data(skb, data, attrlen);
Patrick McHardy01480e12008-01-22 22:10:59 -08001000 return 0;
1001}
Herbert Xu90800212009-03-11 23:18:32 +08001002EXPORT_SYMBOL(nla_append);
1003#endif