logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

netlink.h (12392B)


  1. /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
  2. #ifndef __LINUX_NETLINK_H
  3. #define __LINUX_NETLINK_H
  4. #include <linux/const.h>
  5. #include <linux/socket.h> /* for __kernel_sa_family_t */
  6. #include <linux/types.h>
  7. #define NETLINK_ROUTE 0 /* Routing/device hook */
  8. #define NETLINK_UNUSED 1 /* Unused number */
  9. #define NETLINK_USERSOCK 2 /* Reserved for user mode socket protocols */
  10. #define NETLINK_FIREWALL 3 /* Unused number, formerly ip_queue */
  11. #define NETLINK_SOCK_DIAG 4 /* socket monitoring */
  12. #define NETLINK_NFLOG 5 /* netfilter/iptables ULOG */
  13. #define NETLINK_XFRM 6 /* ipsec */
  14. #define NETLINK_SELINUX 7 /* SELinux event notifications */
  15. #define NETLINK_ISCSI 8 /* Open-iSCSI */
  16. #define NETLINK_AUDIT 9 /* auditing */
  17. #define NETLINK_FIB_LOOKUP 10
  18. #define NETLINK_CONNECTOR 11
  19. #define NETLINK_NETFILTER 12 /* netfilter subsystem */
  20. #define NETLINK_IP6_FW 13
  21. #define NETLINK_DNRTMSG 14 /* DECnet routing messages (obsolete) */
  22. #define NETLINK_KOBJECT_UEVENT 15 /* Kernel messages to userspace */
  23. #define NETLINK_GENERIC 16
  24. /* leave room for NETLINK_DM (DM Events) */
  25. #define NETLINK_SCSITRANSPORT 18 /* SCSI Transports */
  26. #define NETLINK_ECRYPTFS 19
  27. #define NETLINK_RDMA 20
  28. #define NETLINK_CRYPTO 21 /* Crypto layer */
  29. #define NETLINK_SMC 22 /* SMC monitoring */
  30. #define NETLINK_INET_DIAG NETLINK_SOCK_DIAG
  31. #define MAX_LINKS 32
  32. struct sockaddr_nl {
  33. __kernel_sa_family_t nl_family; /* AF_NETLINK */
  34. unsigned short nl_pad; /* zero */
  35. __u32 nl_pid; /* port ID */
  36. __u32 nl_groups; /* multicast groups mask */
  37. };
  38. /**
  39. * struct nlmsghdr - fixed format metadata header of Netlink messages
  40. * @nlmsg_len: Length of message including header
  41. * @nlmsg_type: Message content type
  42. * @nlmsg_flags: Additional flags
  43. * @nlmsg_seq: Sequence number
  44. * @nlmsg_pid: Sending process port ID
  45. */
  46. struct nlmsghdr {
  47. __u32 nlmsg_len;
  48. __u16 nlmsg_type;
  49. __u16 nlmsg_flags;
  50. __u32 nlmsg_seq;
  51. __u32 nlmsg_pid;
  52. };
  53. /* Flags values */
  54. #define NLM_F_REQUEST 0x01 /* It is request message. */
  55. #define NLM_F_MULTI 0x02 /* Multipart message, terminated by NLMSG_DONE */
  56. #define NLM_F_ACK 0x04 /* Reply with ack, with zero or error code */
  57. #define NLM_F_ECHO 0x08 /* Receive resulting notifications */
  58. #define NLM_F_DUMP_INTR 0x10 /* Dump was inconsistent due to sequence change */
  59. #define NLM_F_DUMP_FILTERED 0x20 /* Dump was filtered as requested */
  60. /* Modifiers to GET request */
  61. #define NLM_F_ROOT 0x100 /* specify tree root */
  62. #define NLM_F_MATCH 0x200 /* return all matching */
  63. #define NLM_F_ATOMIC 0x400 /* atomic GET */
  64. #define NLM_F_DUMP (NLM_F_ROOT|NLM_F_MATCH)
  65. /* Modifiers to NEW request */
  66. #define NLM_F_REPLACE 0x100 /* Override existing */
  67. #define NLM_F_EXCL 0x200 /* Do not touch, if it exists */
  68. #define NLM_F_CREATE 0x400 /* Create, if it does not exist */
  69. #define NLM_F_APPEND 0x800 /* Add to end of list */
  70. /* Modifiers to DELETE request */
  71. #define NLM_F_NONREC 0x100 /* Do not delete recursively */
  72. #define NLM_F_BULK 0x200 /* Delete multiple objects */
  73. /* Flags for ACK message */
  74. #define NLM_F_CAPPED 0x100 /* request was capped */
  75. #define NLM_F_ACK_TLVS 0x200 /* extended ACK TVLs were included */
  76. /*
  77. 4.4BSD ADD NLM_F_CREATE|NLM_F_EXCL
  78. 4.4BSD CHANGE NLM_F_REPLACE
  79. True CHANGE NLM_F_CREATE|NLM_F_REPLACE
  80. Append NLM_F_CREATE
  81. Check NLM_F_EXCL
  82. */
  83. #define NLMSG_ALIGNTO 4U
  84. #define NLMSG_ALIGN(len) ( ((len)+NLMSG_ALIGNTO-1) & ~(NLMSG_ALIGNTO-1) )
  85. #define NLMSG_HDRLEN ((int) NLMSG_ALIGN(sizeof(struct nlmsghdr)))
  86. #define NLMSG_LENGTH(len) ((len) + NLMSG_HDRLEN)
  87. #define NLMSG_SPACE(len) NLMSG_ALIGN(NLMSG_LENGTH(len))
  88. #define NLMSG_DATA(nlh) ((void *)(((char *)nlh) + NLMSG_HDRLEN))
  89. #define NLMSG_NEXT(nlh,len) ((len) -= NLMSG_ALIGN((nlh)->nlmsg_len), \
  90. (struct nlmsghdr *)(((char *)(nlh)) + \
  91. NLMSG_ALIGN((nlh)->nlmsg_len)))
  92. #define NLMSG_OK(nlh,len) ((len) >= (int)sizeof(struct nlmsghdr) && \
  93. (nlh)->nlmsg_len >= sizeof(struct nlmsghdr) && \
  94. (nlh)->nlmsg_len <= (len))
  95. #define NLMSG_PAYLOAD(nlh,len) ((nlh)->nlmsg_len - NLMSG_SPACE((len)))
  96. #define NLMSG_NOOP 0x1 /* Nothing. */
  97. #define NLMSG_ERROR 0x2 /* Error */
  98. #define NLMSG_DONE 0x3 /* End of a dump */
  99. #define NLMSG_OVERRUN 0x4 /* Data lost */
  100. #define NLMSG_MIN_TYPE 0x10 /* < 0x10: reserved control messages */
  101. struct nlmsgerr {
  102. int error;
  103. struct nlmsghdr msg;
  104. /*
  105. * followed by the message contents unless NETLINK_CAP_ACK was set
  106. * or the ACK indicates success (error == 0)
  107. * message length is aligned with NLMSG_ALIGN()
  108. */
  109. /*
  110. * followed by TLVs defined in enum nlmsgerr_attrs
  111. * if NETLINK_EXT_ACK was set
  112. */
  113. };
  114. /**
  115. * enum nlmsgerr_attrs - nlmsgerr attributes
  116. * @NLMSGERR_ATTR_UNUSED: unused
  117. * @NLMSGERR_ATTR_MSG: error message string (string)
  118. * @NLMSGERR_ATTR_OFFS: offset of the invalid attribute in the original
  119. * message, counting from the beginning of the header (u32)
  120. * @NLMSGERR_ATTR_COOKIE: arbitrary subsystem specific cookie to
  121. * be used - in the success case - to identify a created
  122. * object or operation or similar (binary)
  123. * @NLMSGERR_ATTR_POLICY: policy for a rejected attribute
  124. * @NLMSGERR_ATTR_MISS_TYPE: type of a missing required attribute,
  125. * %NLMSGERR_ATTR_MISS_NEST will not be present if the attribute was
  126. * missing at the message level
  127. * @NLMSGERR_ATTR_MISS_NEST: offset of the nest where attribute was missing
  128. * @__NLMSGERR_ATTR_MAX: number of attributes
  129. * @NLMSGERR_ATTR_MAX: highest attribute number
  130. */
  131. enum nlmsgerr_attrs {
  132. NLMSGERR_ATTR_UNUSED,
  133. NLMSGERR_ATTR_MSG,
  134. NLMSGERR_ATTR_OFFS,
  135. NLMSGERR_ATTR_COOKIE,
  136. NLMSGERR_ATTR_POLICY,
  137. NLMSGERR_ATTR_MISS_TYPE,
  138. NLMSGERR_ATTR_MISS_NEST,
  139. __NLMSGERR_ATTR_MAX,
  140. NLMSGERR_ATTR_MAX = __NLMSGERR_ATTR_MAX - 1
  141. };
  142. #define NETLINK_ADD_MEMBERSHIP 1
  143. #define NETLINK_DROP_MEMBERSHIP 2
  144. #define NETLINK_PKTINFO 3
  145. #define NETLINK_BROADCAST_ERROR 4
  146. #define NETLINK_NO_ENOBUFS 5
  147. #define NETLINK_RX_RING 6
  148. #define NETLINK_TX_RING 7
  149. #define NETLINK_LISTEN_ALL_NSID 8
  150. #define NETLINK_LIST_MEMBERSHIPS 9
  151. #define NETLINK_CAP_ACK 10
  152. #define NETLINK_EXT_ACK 11
  153. #define NETLINK_GET_STRICT_CHK 12
  154. struct nl_pktinfo {
  155. __u32 group;
  156. };
  157. struct nl_mmap_req {
  158. unsigned int nm_block_size;
  159. unsigned int nm_block_nr;
  160. unsigned int nm_frame_size;
  161. unsigned int nm_frame_nr;
  162. };
  163. struct nl_mmap_hdr {
  164. unsigned int nm_status;
  165. unsigned int nm_len;
  166. __u32 nm_group;
  167. /* credentials */
  168. __u32 nm_pid;
  169. __u32 nm_uid;
  170. __u32 nm_gid;
  171. };
  172. enum nl_mmap_status {
  173. NL_MMAP_STATUS_UNUSED,
  174. NL_MMAP_STATUS_RESERVED,
  175. NL_MMAP_STATUS_VALID,
  176. NL_MMAP_STATUS_COPY,
  177. NL_MMAP_STATUS_SKIP,
  178. };
  179. #define NL_MMAP_MSG_ALIGNMENT NLMSG_ALIGNTO
  180. #define NL_MMAP_MSG_ALIGN(sz) __ALIGN_KERNEL(sz, NL_MMAP_MSG_ALIGNMENT)
  181. #define NL_MMAP_HDRLEN NL_MMAP_MSG_ALIGN(sizeof(struct nl_mmap_hdr))
  182. #define NET_MAJOR 36 /* Major 36 is reserved for networking */
  183. enum {
  184. NETLINK_UNCONNECTED = 0,
  185. NETLINK_CONNECTED,
  186. };
  187. /*
  188. * <------- NLA_HDRLEN ------> <-- NLA_ALIGN(payload)-->
  189. * +---------------------+- - -+- - - - - - - - - -+- - -+
  190. * | Header | Pad | Payload | Pad |
  191. * | (struct nlattr) | ing | | ing |
  192. * +---------------------+- - -+- - - - - - - - - -+- - -+
  193. * <-------------- nlattr->nla_len -------------->
  194. */
  195. struct nlattr {
  196. __u16 nla_len;
  197. __u16 nla_type;
  198. };
  199. /*
  200. * nla_type (16 bits)
  201. * +---+---+-------------------------------+
  202. * | N | O | Attribute Type |
  203. * +---+---+-------------------------------+
  204. * N := Carries nested attributes
  205. * O := Payload stored in network byte order
  206. *
  207. * Note: The N and O flag are mutually exclusive.
  208. */
  209. #define NLA_F_NESTED (1 << 15)
  210. #define NLA_F_NET_BYTEORDER (1 << 14)
  211. #define NLA_TYPE_MASK ~(NLA_F_NESTED | NLA_F_NET_BYTEORDER)
  212. #define NLA_ALIGNTO 4
  213. #define NLA_ALIGN(len) (((len) + NLA_ALIGNTO - 1) & ~(NLA_ALIGNTO - 1))
  214. #define NLA_HDRLEN ((int) NLA_ALIGN(sizeof(struct nlattr)))
  215. /* Generic 32 bitflags attribute content sent to the kernel.
  216. *
  217. * The value is a bitmap that defines the values being set
  218. * The selector is a bitmask that defines which value is legit
  219. *
  220. * Examples:
  221. * value = 0x0, and selector = 0x1
  222. * implies we are selecting bit 1 and we want to set its value to 0.
  223. *
  224. * value = 0x2, and selector = 0x2
  225. * implies we are selecting bit 2 and we want to set its value to 1.
  226. *
  227. */
  228. struct nla_bitfield32 {
  229. __u32 value;
  230. __u32 selector;
  231. };
  232. /*
  233. * policy descriptions - it's specific to each family how this is used
  234. * Normally, it should be retrieved via a dump inside another attribute
  235. * specifying where it applies.
  236. */
  237. /**
  238. * enum netlink_attribute_type - type of an attribute
  239. * @NL_ATTR_TYPE_INVALID: unused
  240. * @NL_ATTR_TYPE_FLAG: flag attribute (present/not present)
  241. * @NL_ATTR_TYPE_U8: 8-bit unsigned attribute
  242. * @NL_ATTR_TYPE_U16: 16-bit unsigned attribute
  243. * @NL_ATTR_TYPE_U32: 32-bit unsigned attribute
  244. * @NL_ATTR_TYPE_U64: 64-bit unsigned attribute
  245. * @NL_ATTR_TYPE_S8: 8-bit signed attribute
  246. * @NL_ATTR_TYPE_S16: 16-bit signed attribute
  247. * @NL_ATTR_TYPE_S32: 32-bit signed attribute
  248. * @NL_ATTR_TYPE_S64: 64-bit signed attribute
  249. * @NL_ATTR_TYPE_BINARY: binary data, min/max length may be specified
  250. * @NL_ATTR_TYPE_STRING: string, min/max length may be specified
  251. * @NL_ATTR_TYPE_NUL_STRING: NUL-terminated string,
  252. * min/max length may be specified
  253. * @NL_ATTR_TYPE_NESTED: nested, i.e. the content of this attribute
  254. * consists of sub-attributes. The nested policy and maxtype
  255. * inside may be specified.
  256. * @NL_ATTR_TYPE_NESTED_ARRAY: nested array, i.e. the content of this
  257. * attribute contains sub-attributes whose type is irrelevant
  258. * (just used to separate the array entries) and each such array
  259. * entry has attributes again, the policy for those inner ones
  260. * and the corresponding maxtype may be specified.
  261. * @NL_ATTR_TYPE_BITFIELD32: &struct nla_bitfield32 attribute
  262. * @NL_ATTR_TYPE_SINT: 32-bit or 64-bit signed attribute, aligned to 4B
  263. * @NL_ATTR_TYPE_UINT: 32-bit or 64-bit unsigned attribute, aligned to 4B
  264. */
  265. enum netlink_attribute_type {
  266. NL_ATTR_TYPE_INVALID,
  267. NL_ATTR_TYPE_FLAG,
  268. NL_ATTR_TYPE_U8,
  269. NL_ATTR_TYPE_U16,
  270. NL_ATTR_TYPE_U32,
  271. NL_ATTR_TYPE_U64,
  272. NL_ATTR_TYPE_S8,
  273. NL_ATTR_TYPE_S16,
  274. NL_ATTR_TYPE_S32,
  275. NL_ATTR_TYPE_S64,
  276. NL_ATTR_TYPE_BINARY,
  277. NL_ATTR_TYPE_STRING,
  278. NL_ATTR_TYPE_NUL_STRING,
  279. NL_ATTR_TYPE_NESTED,
  280. NL_ATTR_TYPE_NESTED_ARRAY,
  281. NL_ATTR_TYPE_BITFIELD32,
  282. NL_ATTR_TYPE_SINT,
  283. NL_ATTR_TYPE_UINT,
  284. };
  285. /**
  286. * enum netlink_policy_type_attr - policy type attributes
  287. * @NL_POLICY_TYPE_ATTR_UNSPEC: unused
  288. * @NL_POLICY_TYPE_ATTR_TYPE: type of the attribute,
  289. * &enum netlink_attribute_type (U32)
  290. * @NL_POLICY_TYPE_ATTR_MIN_VALUE_S: minimum value for signed
  291. * integers (S64)
  292. * @NL_POLICY_TYPE_ATTR_MAX_VALUE_S: maximum value for signed
  293. * integers (S64)
  294. * @NL_POLICY_TYPE_ATTR_MIN_VALUE_U: minimum value for unsigned
  295. * integers (U64)
  296. * @NL_POLICY_TYPE_ATTR_MAX_VALUE_U: maximum value for unsigned
  297. * integers (U64)
  298. * @NL_POLICY_TYPE_ATTR_MIN_LENGTH: minimum length for binary
  299. * attributes, no minimum if not given (U32)
  300. * @NL_POLICY_TYPE_ATTR_MAX_LENGTH: maximum length for binary
  301. * attributes, no maximum if not given (U32)
  302. * @NL_POLICY_TYPE_ATTR_POLICY_IDX: sub policy for nested and
  303. * nested array types (U32)
  304. * @NL_POLICY_TYPE_ATTR_POLICY_MAXTYPE: maximum sub policy
  305. * attribute for nested and nested array types, this can
  306. * in theory be < the size of the policy pointed to by
  307. * the index, if limited inside the nesting (U32)
  308. * @NL_POLICY_TYPE_ATTR_BITFIELD32_MASK: valid mask for the
  309. * bitfield32 type (U32)
  310. * @NL_POLICY_TYPE_ATTR_MASK: mask of valid bits for unsigned integers (U64)
  311. * @NL_POLICY_TYPE_ATTR_PAD: pad attribute for 64-bit alignment
  312. *
  313. * @__NL_POLICY_TYPE_ATTR_MAX: number of attributes
  314. * @NL_POLICY_TYPE_ATTR_MAX: highest attribute number
  315. */
  316. enum netlink_policy_type_attr {
  317. NL_POLICY_TYPE_ATTR_UNSPEC,
  318. NL_POLICY_TYPE_ATTR_TYPE,
  319. NL_POLICY_TYPE_ATTR_MIN_VALUE_S,
  320. NL_POLICY_TYPE_ATTR_MAX_VALUE_S,
  321. NL_POLICY_TYPE_ATTR_MIN_VALUE_U,
  322. NL_POLICY_TYPE_ATTR_MAX_VALUE_U,
  323. NL_POLICY_TYPE_ATTR_MIN_LENGTH,
  324. NL_POLICY_TYPE_ATTR_MAX_LENGTH,
  325. NL_POLICY_TYPE_ATTR_POLICY_IDX,
  326. NL_POLICY_TYPE_ATTR_POLICY_MAXTYPE,
  327. NL_POLICY_TYPE_ATTR_BITFIELD32_MASK,
  328. NL_POLICY_TYPE_ATTR_PAD,
  329. NL_POLICY_TYPE_ATTR_MASK,
  330. /* keep last */
  331. __NL_POLICY_TYPE_ATTR_MAX,
  332. NL_POLICY_TYPE_ATTR_MAX = __NL_POLICY_TYPE_ATTR_MAX - 1
  333. };
  334. #endif /* __LINUX_NETLINK_H */