netlink-kernel.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. #ifndef __NETLINK_KERNEL_H_
  2. #define __NETLINK_KERNEL_H_
  3. #if 0
  4. /*
  5. * FIXME: Goal is to preseve the documentation but make it simple
  6. * to keep linux/netlink.h in sync. Maybe use named documentation
  7. * sections.
  8. */
  9. /**
  10. * Netlink socket address
  11. * @ingroup nl
  12. */
  13. struct sockaddr_nl
  14. {
  15. /** socket family (AF_NETLINK) */
  16. sa_family_t nl_family;
  17. /** Padding (unused) */
  18. unsigned short nl_pad;
  19. /** Unique process ID */
  20. uint32_t nl_pid;
  21. /** Multicast group subscriptions */
  22. uint32_t nl_groups;
  23. };
  24. /**
  25. * @addtogroup msg
  26. * @{
  27. */
  28. /**
  29. * Netlink message header
  30. */
  31. struct nlmsghdr
  32. {
  33. /** Length of message including header and padding. */
  34. uint32_t nlmsg_len;
  35. /** Message type (content type) */
  36. uint16_t nlmsg_type;
  37. /** Message flags */
  38. uint16_t nlmsg_flags;
  39. /** Sequence number of message \see core_sk_seq_num. */
  40. uint32_t nlmsg_seq;
  41. /** Netlink port */
  42. uint32_t nlmsg_pid;
  43. };
  44. /**
  45. * @name Standard message flags
  46. * @{
  47. */
  48. /**
  49. * Must be set on all request messages (typically from user space to
  50. * kernel space).
  51. */
  52. #define NLM_F_REQUEST 1
  53. /**
  54. * Indicates the message is part of a multipart message terminated
  55. * by NLMSG_DONE.
  56. */
  57. #define NLM_F_MULTI 2
  58. /**
  59. * Request for an acknowledgment on success.
  60. */
  61. #define NLM_F_ACK 4
  62. /**
  63. * Echo this request
  64. */
  65. #define NLM_F_ECHO 8
  66. /** @} */
  67. /**
  68. * @name Additional message flags for GET requests
  69. * @{
  70. */
  71. /**
  72. * Return the complete table instead of a single entry.
  73. */
  74. #define NLM_F_ROOT 0x100
  75. /**
  76. * Return all entries matching criteria passed in message content.
  77. */
  78. #define NLM_F_MATCH 0x200
  79. /**
  80. * Return an atomic snapshot of the table being referenced. This
  81. * may require special privileges because it has the potential to
  82. * interrupt service in the FE for a longer time.
  83. */
  84. #define NLM_F_ATOMIC 0x400
  85. /**
  86. * Dump all entries
  87. */
  88. #define NLM_F_DUMP (NLM_F_ROOT|NLM_F_MATCH)
  89. /** @} */
  90. /**
  91. * @name Additional messsage flags for NEW requests
  92. * @{
  93. */
  94. /**
  95. * Replace existing matching config object with this request.
  96. */
  97. #define NLM_F_REPLACE 0x100
  98. /**
  99. * Don't replace the config object if it already exists.
  100. */
  101. #define NLM_F_EXCL 0x200
  102. /**
  103. * Create config object if it doesn't already exist.
  104. */
  105. #define NLM_F_CREATE 0x400
  106. /**
  107. * Add to the end of the object list.
  108. */
  109. #define NLM_F_APPEND 0x800
  110. /** @} */
  111. /**
  112. * @name Standard Message types
  113. * @{
  114. */
  115. /**
  116. * No operation, message must be ignored
  117. */
  118. #define NLMSG_NOOP 0x1
  119. /**
  120. * The message signals an error and the payload contains a nlmsgerr
  121. * structure. This can be looked at as a NACK and typically it is
  122. * from FEC to CPC.
  123. */
  124. #define NLMSG_ERROR 0x2
  125. /**
  126. * Message terminates a multipart message.
  127. */
  128. #define NLMSG_DONE 0x3
  129. /**
  130. * The message signals that data got lost
  131. */
  132. #define NLMSG_OVERRUN 0x4
  133. /**
  134. * Lower limit of reserved message types
  135. */
  136. #define NLMSG_MIN_TYPE 0x10
  137. /** @} */
  138. /**
  139. * Netlink error message header
  140. */
  141. struct nlmsgerr
  142. {
  143. /** Error code (errno number) */
  144. int error;
  145. /** Original netlink message causing the error */
  146. struct nlmsghdr msg;
  147. };
  148. struct nl_pktinfo
  149. {
  150. __u32 group;
  151. };
  152. /**
  153. * Netlink alignment constant, all boundries within messages must be align to this.
  154. *
  155. * See \ref core_msg_fmt_align for more information on message alignment.
  156. */
  157. #define NLMSG_ALIGNTO 4
  158. /**
  159. * Returns \p len properly aligned to NLMSG_ALIGNTO.
  160. *
  161. * See \ref core_msg_fmt_align for more information on message alignment.
  162. */
  163. #define NLMSG_ALIGN(len) ( ((len)+NLMSG_ALIGNTO-1) & ~(NLMSG_ALIGNTO-1) )
  164. /**
  165. * Length of a netlink message header including padding.
  166. *
  167. * See \ref core_msg_fmt_align for more information on message alignment.
  168. */
  169. #define NLMSG_HDRLEN ((int) NLMSG_ALIGN(sizeof(struct nlmsghdr)))
  170. /** @} */
  171. /**
  172. * @addtogroup attr
  173. * @{
  174. */
  175. /*
  176. */
  177. /**
  178. * Netlink attribute structure
  179. *
  180. * @code
  181. * <------- NLA_HDRLEN ------> <-- NLA_ALIGN(payload)-->
  182. * +---------------------+- - -+- - - - - - - - - -+- - -+
  183. * | Header | Pad | Payload | Pad |
  184. * | (struct nlattr) | ing | | ing |
  185. * +---------------------+- - -+- - - - - - - - - -+- - -+
  186. * <-------------- nlattr->nla_len -------------->
  187. * @endcode
  188. */
  189. struct nlattr {
  190. /**
  191. * Attribute length in bytes including header
  192. */
  193. __u16 nla_len;
  194. /**
  195. * Netlink attribute type
  196. */
  197. __u16 nla_type;
  198. };
  199. /**
  200. * @name Attribute Type Flags
  201. *
  202. * @code
  203. * nla_type (16 bits)
  204. * +---+---+-------------------------------+
  205. * | N | O | Attribute Type |
  206. * +---+---+-------------------------------+
  207. * N := Carries nested attributes
  208. * O := Payload stored in network byte order
  209. * @endcode
  210. *
  211. * @note The N and O flag are mutually exclusive.
  212. *
  213. * @{
  214. */
  215. /*
  216. */
  217. #define NLA_F_NESTED (1 << 15)
  218. #define NLA_F_NET_BYTEORDER (1 << 14)
  219. #define NLA_TYPE_MASK ~(NLA_F_NESTED | NLA_F_NET_BYTEORDER)
  220. /** @} */
  221. #define NLA_ALIGNTO 4
  222. /**
  223. * Returns \p len properly aligned to NLA_ALIGNTO.
  224. *
  225. * See \ref core_msg_fmt_align for more information on message alignment.
  226. */
  227. #define NLA_ALIGN(len) (((len) + NLA_ALIGNTO - 1) & ~(NLA_ALIGNTO - 1))
  228. /**
  229. * Length of a netlink attribute header including padding.
  230. *
  231. * See \ref core_msg_fmt_align for more information on message alignment.
  232. */
  233. #define NLA_HDRLEN ((int) NLA_ALIGN(sizeof(struct nlattr)))
  234. /** @} */
  235. #endif
  236. #endif /* __LINUX_NETLINK_H */