netlink.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
  2. #ifndef _UAPI__LINUX_NETLINK_H
  3. #define _UAPI__LINUX_NETLINK_H
  4. #include <linux/kernel.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 */
  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. struct nlmsghdr {
  39. __u32 nlmsg_len; /* Length of message including header */
  40. __u16 nlmsg_type; /* Message content */
  41. __u16 nlmsg_flags; /* Additional flags */
  42. __u32 nlmsg_seq; /* Sequence number */
  43. __u32 nlmsg_pid; /* Sending process port ID */
  44. };
  45. /* Flags values */
  46. #define NLM_F_REQUEST 0x01 /* It is request message. */
  47. #define NLM_F_MULTI 0x02 /* Multipart message, terminated by NLMSG_DONE */
  48. #define NLM_F_ACK 0x04 /* Reply with ack, with zero or error code */
  49. #define NLM_F_ECHO 0x08 /* Echo this request */
  50. #define NLM_F_DUMP_INTR 0x10 /* Dump was inconsistent due to sequence change */
  51. #define NLM_F_DUMP_FILTERED 0x20 /* Dump was filtered as requested */
  52. /* Modifiers to GET request */
  53. #define NLM_F_ROOT 0x100 /* specify tree root */
  54. #define NLM_F_MATCH 0x200 /* return all matching */
  55. #define NLM_F_ATOMIC 0x400 /* atomic GET */
  56. #define NLM_F_DUMP (NLM_F_ROOT|NLM_F_MATCH)
  57. /* Modifiers to NEW request */
  58. #define NLM_F_REPLACE 0x100 /* Override existing */
  59. #define NLM_F_EXCL 0x200 /* Do not touch, if it exists */
  60. #define NLM_F_CREATE 0x400 /* Create, if it does not exist */
  61. #define NLM_F_APPEND 0x800 /* Add to end of list */
  62. /* Modifiers to DELETE request */
  63. #define NLM_F_NONREC 0x100 /* Do not delete recursively */
  64. /* Flags for ACK message */
  65. #define NLM_F_CAPPED 0x100 /* request was capped */
  66. #define NLM_F_ACK_TLVS 0x200 /* extended ACK TVLs were included */
  67. /*
  68. 4.4BSD ADD NLM_F_CREATE|NLM_F_EXCL
  69. 4.4BSD CHANGE NLM_F_REPLACE
  70. True CHANGE NLM_F_CREATE|NLM_F_REPLACE
  71. Append NLM_F_CREATE
  72. Check NLM_F_EXCL
  73. */
  74. #define NLMSG_ALIGNTO 4U
  75. #define NLMSG_ALIGN(len) ( ((len)+NLMSG_ALIGNTO-1) & ~(NLMSG_ALIGNTO-1) )
  76. #define NLMSG_HDRLEN ((int) NLMSG_ALIGN(sizeof(struct nlmsghdr)))
  77. #define NLMSG_LENGTH(len) ((len) + NLMSG_HDRLEN)
  78. #define NLMSG_SPACE(len) NLMSG_ALIGN(NLMSG_LENGTH(len))
  79. #define NLMSG_DATA(nlh) ((void*)(((char*)nlh) + NLMSG_LENGTH(0)))
  80. #define NLMSG_NEXT(nlh,len) ((len) -= NLMSG_ALIGN((nlh)->nlmsg_len), \
  81. (struct nlmsghdr*)(((char*)(nlh)) + NLMSG_ALIGN((nlh)->nlmsg_len)))
  82. #define NLMSG_OK(nlh,len) ((len) >= (int)sizeof(struct nlmsghdr) && \
  83. (nlh)->nlmsg_len >= sizeof(struct nlmsghdr) && \
  84. (nlh)->nlmsg_len <= (len))
  85. #define NLMSG_PAYLOAD(nlh,len) ((nlh)->nlmsg_len - NLMSG_SPACE((len)))
  86. #define NLMSG_NOOP 0x1 /* Nothing. */
  87. #define NLMSG_ERROR 0x2 /* Error */
  88. #define NLMSG_DONE 0x3 /* End of a dump */
  89. #define NLMSG_OVERRUN 0x4 /* Data lost */
  90. #define NLMSG_MIN_TYPE 0x10 /* < 0x10: reserved control messages */
  91. struct nlmsgerr {
  92. int error;
  93. struct nlmsghdr msg;
  94. /*
  95. * followed by the message contents unless NETLINK_CAP_ACK was set
  96. * or the ACK indicates success (error == 0)
  97. * message length is aligned with NLMSG_ALIGN()
  98. */
  99. /*
  100. * followed by TLVs defined in enum nlmsgerr_attrs
  101. * if NETLINK_EXT_ACK was set
  102. */
  103. };
  104. /**
  105. * enum nlmsgerr_attrs - nlmsgerr attributes
  106. * @NLMSGERR_ATTR_UNUSED: unused
  107. * @NLMSGERR_ATTR_MSG: error message string (string)
  108. * @NLMSGERR_ATTR_OFFS: offset of the invalid attribute in the original
  109. * message, counting from the beginning of the header (u32)
  110. * @NLMSGERR_ATTR_COOKIE: arbitrary subsystem specific cookie to
  111. * be used - in the success case - to identify a created
  112. * object or operation or similar (binary)
  113. * @__NLMSGERR_ATTR_MAX: number of attributes
  114. * @NLMSGERR_ATTR_MAX: highest attribute number
  115. */
  116. enum nlmsgerr_attrs {
  117. NLMSGERR_ATTR_UNUSED,
  118. NLMSGERR_ATTR_MSG,
  119. NLMSGERR_ATTR_OFFS,
  120. NLMSGERR_ATTR_COOKIE,
  121. __NLMSGERR_ATTR_MAX,
  122. NLMSGERR_ATTR_MAX = __NLMSGERR_ATTR_MAX - 1
  123. };
  124. #define NETLINK_ADD_MEMBERSHIP 1
  125. #define NETLINK_DROP_MEMBERSHIP 2
  126. #define NETLINK_PKTINFO 3
  127. #define NETLINK_BROADCAST_ERROR 4
  128. #define NETLINK_NO_ENOBUFS 5
  129. #ifndef __KERNEL__
  130. #define NETLINK_RX_RING 6
  131. #define NETLINK_TX_RING 7
  132. #endif
  133. #define NETLINK_LISTEN_ALL_NSID 8
  134. #define NETLINK_LIST_MEMBERSHIPS 9
  135. #define NETLINK_CAP_ACK 10
  136. #define NETLINK_EXT_ACK 11
  137. #define NETLINK_GET_STRICT_CHK 12
  138. struct nl_pktinfo {
  139. __u32 group;
  140. };
  141. struct nl_mmap_req {
  142. unsigned int nm_block_size;
  143. unsigned int nm_block_nr;
  144. unsigned int nm_frame_size;
  145. unsigned int nm_frame_nr;
  146. };
  147. struct nl_mmap_hdr {
  148. unsigned int nm_status;
  149. unsigned int nm_len;
  150. __u32 nm_group;
  151. /* credentials */
  152. __u32 nm_pid;
  153. __u32 nm_uid;
  154. __u32 nm_gid;
  155. };
  156. #ifndef __KERNEL__
  157. enum nl_mmap_status {
  158. NL_MMAP_STATUS_UNUSED,
  159. NL_MMAP_STATUS_RESERVED,
  160. NL_MMAP_STATUS_VALID,
  161. NL_MMAP_STATUS_COPY,
  162. NL_MMAP_STATUS_SKIP,
  163. };
  164. #define NL_MMAP_MSG_ALIGNMENT NLMSG_ALIGNTO
  165. #define NL_MMAP_MSG_ALIGN(sz) __ALIGN_KERNEL(sz, NL_MMAP_MSG_ALIGNMENT)
  166. #define NL_MMAP_HDRLEN NL_MMAP_MSG_ALIGN(sizeof(struct nl_mmap_hdr))
  167. #endif
  168. #define NET_MAJOR 36 /* Major 36 is reserved for networking */
  169. enum {
  170. NETLINK_UNCONNECTED = 0,
  171. NETLINK_CONNECTED,
  172. };
  173. /*
  174. * <------- NLA_HDRLEN ------> <-- NLA_ALIGN(payload)-->
  175. * +---------------------+- - -+- - - - - - - - - -+- - -+
  176. * | Header | Pad | Payload | Pad |
  177. * | (struct nlattr) | ing | | ing |
  178. * +---------------------+- - -+- - - - - - - - - -+- - -+
  179. * <-------------- nlattr->nla_len -------------->
  180. */
  181. struct nlattr {
  182. __u16 nla_len;
  183. __u16 nla_type;
  184. };
  185. /*
  186. * nla_type (16 bits)
  187. * +---+---+-------------------------------+
  188. * | N | O | Attribute Type |
  189. * +---+---+-------------------------------+
  190. * N := Carries nested attributes
  191. * O := Payload stored in network byte order
  192. *
  193. * Note: The N and O flag are mutually exclusive.
  194. */
  195. #define NLA_F_NESTED (1 << 15)
  196. #define NLA_F_NET_BYTEORDER (1 << 14)
  197. #define NLA_TYPE_MASK ~(NLA_F_NESTED | NLA_F_NET_BYTEORDER)
  198. #define NLA_ALIGNTO 4
  199. #define NLA_ALIGN(len) (((len) + NLA_ALIGNTO - 1) & ~(NLA_ALIGNTO - 1))
  200. #define NLA_HDRLEN ((int) NLA_ALIGN(sizeof(struct nlattr)))
  201. /* Generic 32 bitflags attribute content sent to the kernel.
  202. *
  203. * The value is a bitmap that defines the values being set
  204. * The selector is a bitmask that defines which value is legit
  205. *
  206. * Examples:
  207. * value = 0x0, and selector = 0x1
  208. * implies we are selecting bit 1 and we want to set its value to 0.
  209. *
  210. * value = 0x2, and selector = 0x2
  211. * implies we are selecting bit 2 and we want to set its value to 1.
  212. *
  213. */
  214. struct nla_bitfield32 {
  215. __u32 value;
  216. __u32 selector;
  217. };
  218. #endif /* _UAPI__LINUX_NETLINK_H */