nlattr.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /* SPDX-License-Identifier: LGPL-2.1 */
  2. /*
  3. * NETLINK Netlink attributes
  4. *
  5. * This library is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU Lesser General Public
  7. * License as published by the Free Software Foundation version 2.1
  8. * of the License.
  9. *
  10. * Copyright (c) 2003-2013 Thomas Graf <tgraf@suug.ch>
  11. */
  12. #ifndef __NLATTR_H
  13. #define __NLATTR_H
  14. #include <stdint.h>
  15. #include <linux/netlink.h>
  16. /* avoid multiple definition of netlink features */
  17. #define __LINUX_NETLINK_H
  18. /**
  19. * Standard attribute types to specify validation policy
  20. */
  21. enum {
  22. NLA_UNSPEC, /**< Unspecified type, binary data chunk */
  23. NLA_U8, /**< 8 bit integer */
  24. NLA_U16, /**< 16 bit integer */
  25. NLA_U32, /**< 32 bit integer */
  26. NLA_U64, /**< 64 bit integer */
  27. NLA_STRING, /**< NUL terminated character string */
  28. NLA_FLAG, /**< Flag */
  29. NLA_MSECS, /**< Micro seconds (64bit) */
  30. NLA_NESTED, /**< Nested attributes */
  31. __NLA_TYPE_MAX,
  32. };
  33. #define NLA_TYPE_MAX (__NLA_TYPE_MAX - 1)
  34. /**
  35. * @ingroup attr
  36. * Attribute validation policy.
  37. *
  38. * See section @core_doc{core_attr_parse,Attribute Parsing} for more details.
  39. */
  40. struct nla_policy {
  41. /** Type of attribute or NLA_UNSPEC */
  42. uint16_t type;
  43. /** Minimal length of payload required */
  44. uint16_t minlen;
  45. /** Maximal length of payload allowed */
  46. uint16_t maxlen;
  47. };
  48. /**
  49. * @ingroup attr
  50. * Iterate over a stream of attributes
  51. * @arg pos loop counter, set to current attribute
  52. * @arg head head of attribute stream
  53. * @arg len length of attribute stream
  54. * @arg rem initialized to len, holds bytes currently remaining in stream
  55. */
  56. #define nla_for_each_attr(pos, head, len, rem) \
  57. for (pos = head, rem = len; \
  58. nla_ok(pos, rem); \
  59. pos = nla_next(pos, &(rem)))
  60. int nla_dump_errormsg(struct nlmsghdr *nlh);
  61. #endif /* __NLATTR_H */