nlattr.c 18 KB

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