xref: /linux-6.15/tools/include/uapi/linux/netlink.h (revision d3e8869e)
1dc2b9f19SEric Leblond /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2dc2b9f19SEric Leblond #ifndef _UAPI__LINUX_NETLINK_H
3dc2b9f19SEric Leblond #define _UAPI__LINUX_NETLINK_H
4dc2b9f19SEric Leblond 
5dc2b9f19SEric Leblond #include <linux/kernel.h>
6dc2b9f19SEric Leblond #include <linux/socket.h> /* for __kernel_sa_family_t */
7dc2b9f19SEric Leblond #include <linux/types.h>
8dc2b9f19SEric Leblond 
9dc2b9f19SEric Leblond #define NETLINK_ROUTE		0	/* Routing/device hook				*/
10dc2b9f19SEric Leblond #define NETLINK_UNUSED		1	/* Unused number				*/
11dc2b9f19SEric Leblond #define NETLINK_USERSOCK	2	/* Reserved for user mode socket protocols 	*/
12dc2b9f19SEric Leblond #define NETLINK_FIREWALL	3	/* Unused number, formerly ip_queue		*/
13dc2b9f19SEric Leblond #define NETLINK_SOCK_DIAG	4	/* socket monitoring				*/
14dc2b9f19SEric Leblond #define NETLINK_NFLOG		5	/* netfilter/iptables ULOG */
15dc2b9f19SEric Leblond #define NETLINK_XFRM		6	/* ipsec */
16dc2b9f19SEric Leblond #define NETLINK_SELINUX		7	/* SELinux event notifications */
17dc2b9f19SEric Leblond #define NETLINK_ISCSI		8	/* Open-iSCSI */
18dc2b9f19SEric Leblond #define NETLINK_AUDIT		9	/* auditing */
19dc2b9f19SEric Leblond #define NETLINK_FIB_LOOKUP	10
20dc2b9f19SEric Leblond #define NETLINK_CONNECTOR	11
21dc2b9f19SEric Leblond #define NETLINK_NETFILTER	12	/* netfilter subsystem */
22dc2b9f19SEric Leblond #define NETLINK_IP6_FW		13
23dc2b9f19SEric Leblond #define NETLINK_DNRTMSG		14	/* DECnet routing messages */
24dc2b9f19SEric Leblond #define NETLINK_KOBJECT_UEVENT	15	/* Kernel messages to userspace */
25dc2b9f19SEric Leblond #define NETLINK_GENERIC		16
26dc2b9f19SEric Leblond /* leave room for NETLINK_DM (DM Events) */
27dc2b9f19SEric Leblond #define NETLINK_SCSITRANSPORT	18	/* SCSI Transports */
28dc2b9f19SEric Leblond #define NETLINK_ECRYPTFS	19
29dc2b9f19SEric Leblond #define NETLINK_RDMA		20
30dc2b9f19SEric Leblond #define NETLINK_CRYPTO		21	/* Crypto layer */
31dc2b9f19SEric Leblond #define NETLINK_SMC		22	/* SMC monitoring */
32dc2b9f19SEric Leblond 
33dc2b9f19SEric Leblond #define NETLINK_INET_DIAG	NETLINK_SOCK_DIAG
34dc2b9f19SEric Leblond 
35dc2b9f19SEric Leblond #define MAX_LINKS 32
36dc2b9f19SEric Leblond 
37dc2b9f19SEric Leblond struct sockaddr_nl {
38dc2b9f19SEric Leblond 	__kernel_sa_family_t	nl_family;	/* AF_NETLINK	*/
39dc2b9f19SEric Leblond 	unsigned short	nl_pad;		/* zero		*/
40dc2b9f19SEric Leblond 	__u32		nl_pid;		/* port ID	*/
41dc2b9f19SEric Leblond        	__u32		nl_groups;	/* multicast groups mask */
42dc2b9f19SEric Leblond };
43dc2b9f19SEric Leblond 
44dc2b9f19SEric Leblond struct nlmsghdr {
45dc2b9f19SEric Leblond 	__u32		nlmsg_len;	/* Length of message including header */
46dc2b9f19SEric Leblond 	__u16		nlmsg_type;	/* Message content */
47dc2b9f19SEric Leblond 	__u16		nlmsg_flags;	/* Additional flags */
48dc2b9f19SEric Leblond 	__u32		nlmsg_seq;	/* Sequence number */
49dc2b9f19SEric Leblond 	__u32		nlmsg_pid;	/* Sending process port ID */
50dc2b9f19SEric Leblond };
51dc2b9f19SEric Leblond 
52dc2b9f19SEric Leblond /* Flags values */
53dc2b9f19SEric Leblond 
54dc2b9f19SEric Leblond #define NLM_F_REQUEST		0x01	/* It is request message. 	*/
55dc2b9f19SEric Leblond #define NLM_F_MULTI		0x02	/* Multipart message, terminated by NLMSG_DONE */
56dc2b9f19SEric Leblond #define NLM_F_ACK		0x04	/* Reply with ack, with zero or error code */
57dc2b9f19SEric Leblond #define NLM_F_ECHO		0x08	/* Echo this request 		*/
58dc2b9f19SEric Leblond #define NLM_F_DUMP_INTR		0x10	/* Dump was inconsistent due to sequence change */
59dc2b9f19SEric Leblond #define NLM_F_DUMP_FILTERED	0x20	/* Dump was filtered as requested */
60dc2b9f19SEric Leblond 
61dc2b9f19SEric Leblond /* Modifiers to GET request */
62dc2b9f19SEric Leblond #define NLM_F_ROOT	0x100	/* specify tree	root	*/
63dc2b9f19SEric Leblond #define NLM_F_MATCH	0x200	/* return all matching	*/
64dc2b9f19SEric Leblond #define NLM_F_ATOMIC	0x400	/* atomic GET		*/
65dc2b9f19SEric Leblond #define NLM_F_DUMP	(NLM_F_ROOT|NLM_F_MATCH)
66dc2b9f19SEric Leblond 
67dc2b9f19SEric Leblond /* Modifiers to NEW request */
68dc2b9f19SEric Leblond #define NLM_F_REPLACE	0x100	/* Override existing		*/
69dc2b9f19SEric Leblond #define NLM_F_EXCL	0x200	/* Do not touch, if it exists	*/
70dc2b9f19SEric Leblond #define NLM_F_CREATE	0x400	/* Create, if it does not exist	*/
71dc2b9f19SEric Leblond #define NLM_F_APPEND	0x800	/* Add to end of list		*/
72dc2b9f19SEric Leblond 
73dc2b9f19SEric Leblond /* Modifiers to DELETE request */
74dc2b9f19SEric Leblond #define NLM_F_NONREC	0x100	/* Do not delete recursively	*/
75dc2b9f19SEric Leblond 
76dc2b9f19SEric Leblond /* Flags for ACK message */
77dc2b9f19SEric Leblond #define NLM_F_CAPPED	0x100	/* request was capped */
78dc2b9f19SEric Leblond #define NLM_F_ACK_TLVS	0x200	/* extended ACK TVLs were included */
79dc2b9f19SEric Leblond 
80dc2b9f19SEric Leblond /*
81dc2b9f19SEric Leblond    4.4BSD ADD		NLM_F_CREATE|NLM_F_EXCL
82dc2b9f19SEric Leblond    4.4BSD CHANGE	NLM_F_REPLACE
83dc2b9f19SEric Leblond 
84dc2b9f19SEric Leblond    True CHANGE		NLM_F_CREATE|NLM_F_REPLACE
85dc2b9f19SEric Leblond    Append		NLM_F_CREATE
86dc2b9f19SEric Leblond    Check		NLM_F_EXCL
87dc2b9f19SEric Leblond  */
88dc2b9f19SEric Leblond 
89dc2b9f19SEric Leblond #define NLMSG_ALIGNTO	4U
90dc2b9f19SEric Leblond #define NLMSG_ALIGN(len) ( ((len)+NLMSG_ALIGNTO-1) & ~(NLMSG_ALIGNTO-1) )
91dc2b9f19SEric Leblond #define NLMSG_HDRLEN	 ((int) NLMSG_ALIGN(sizeof(struct nlmsghdr)))
92dc2b9f19SEric Leblond #define NLMSG_LENGTH(len) ((len) + NLMSG_HDRLEN)
93dc2b9f19SEric Leblond #define NLMSG_SPACE(len) NLMSG_ALIGN(NLMSG_LENGTH(len))
94dc2b9f19SEric Leblond #define NLMSG_DATA(nlh)  ((void*)(((char*)nlh) + NLMSG_LENGTH(0)))
95dc2b9f19SEric Leblond #define NLMSG_NEXT(nlh,len)	 ((len) -= NLMSG_ALIGN((nlh)->nlmsg_len), \
96dc2b9f19SEric Leblond 				  (struct nlmsghdr*)(((char*)(nlh)) + NLMSG_ALIGN((nlh)->nlmsg_len)))
97dc2b9f19SEric Leblond #define NLMSG_OK(nlh,len) ((len) >= (int)sizeof(struct nlmsghdr) && \
98dc2b9f19SEric Leblond 			   (nlh)->nlmsg_len >= sizeof(struct nlmsghdr) && \
99dc2b9f19SEric Leblond 			   (nlh)->nlmsg_len <= (len))
100dc2b9f19SEric Leblond #define NLMSG_PAYLOAD(nlh,len) ((nlh)->nlmsg_len - NLMSG_SPACE((len)))
101dc2b9f19SEric Leblond 
102dc2b9f19SEric Leblond #define NLMSG_NOOP		0x1	/* Nothing.		*/
103dc2b9f19SEric Leblond #define NLMSG_ERROR		0x2	/* Error		*/
104dc2b9f19SEric Leblond #define NLMSG_DONE		0x3	/* End of a dump	*/
105dc2b9f19SEric Leblond #define NLMSG_OVERRUN		0x4	/* Data lost		*/
106dc2b9f19SEric Leblond 
107dc2b9f19SEric Leblond #define NLMSG_MIN_TYPE		0x10	/* < 0x10: reserved control messages */
108dc2b9f19SEric Leblond 
109dc2b9f19SEric Leblond struct nlmsgerr {
110dc2b9f19SEric Leblond 	int		error;
111dc2b9f19SEric Leblond 	struct nlmsghdr msg;
112dc2b9f19SEric Leblond 	/*
113dc2b9f19SEric Leblond 	 * followed by the message contents unless NETLINK_CAP_ACK was set
114dc2b9f19SEric Leblond 	 * or the ACK indicates success (error == 0)
115dc2b9f19SEric Leblond 	 * message length is aligned with NLMSG_ALIGN()
116dc2b9f19SEric Leblond 	 */
117dc2b9f19SEric Leblond 	/*
118dc2b9f19SEric Leblond 	 * followed by TLVs defined in enum nlmsgerr_attrs
119dc2b9f19SEric Leblond 	 * if NETLINK_EXT_ACK was set
120dc2b9f19SEric Leblond 	 */
121dc2b9f19SEric Leblond };
122dc2b9f19SEric Leblond 
123dc2b9f19SEric Leblond /**
124dc2b9f19SEric Leblond  * enum nlmsgerr_attrs - nlmsgerr attributes
125dc2b9f19SEric Leblond  * @NLMSGERR_ATTR_UNUSED: unused
126dc2b9f19SEric Leblond  * @NLMSGERR_ATTR_MSG: error message string (string)
127dc2b9f19SEric Leblond  * @NLMSGERR_ATTR_OFFS: offset of the invalid attribute in the original
128dc2b9f19SEric Leblond  *	 message, counting from the beginning of the header (u32)
129dc2b9f19SEric Leblond  * @NLMSGERR_ATTR_COOKIE: arbitrary subsystem specific cookie to
130dc2b9f19SEric Leblond  *	be used - in the success case - to identify a created
131dc2b9f19SEric Leblond  *	object or operation or similar (binary)
132dc2b9f19SEric Leblond  * @__NLMSGERR_ATTR_MAX: number of attributes
133dc2b9f19SEric Leblond  * @NLMSGERR_ATTR_MAX: highest attribute number
134dc2b9f19SEric Leblond  */
135dc2b9f19SEric Leblond enum nlmsgerr_attrs {
136dc2b9f19SEric Leblond 	NLMSGERR_ATTR_UNUSED,
137dc2b9f19SEric Leblond 	NLMSGERR_ATTR_MSG,
138dc2b9f19SEric Leblond 	NLMSGERR_ATTR_OFFS,
139dc2b9f19SEric Leblond 	NLMSGERR_ATTR_COOKIE,
140dc2b9f19SEric Leblond 
141dc2b9f19SEric Leblond 	__NLMSGERR_ATTR_MAX,
142dc2b9f19SEric Leblond 	NLMSGERR_ATTR_MAX = __NLMSGERR_ATTR_MAX - 1
143dc2b9f19SEric Leblond };
144dc2b9f19SEric Leblond 
145dc2b9f19SEric Leblond #define NETLINK_ADD_MEMBERSHIP		1
146dc2b9f19SEric Leblond #define NETLINK_DROP_MEMBERSHIP		2
147dc2b9f19SEric Leblond #define NETLINK_PKTINFO			3
148dc2b9f19SEric Leblond #define NETLINK_BROADCAST_ERROR		4
149dc2b9f19SEric Leblond #define NETLINK_NO_ENOBUFS		5
150dc2b9f19SEric Leblond #ifndef __KERNEL__
151dc2b9f19SEric Leblond #define NETLINK_RX_RING			6
152dc2b9f19SEric Leblond #define NETLINK_TX_RING			7
153dc2b9f19SEric Leblond #endif
154dc2b9f19SEric Leblond #define NETLINK_LISTEN_ALL_NSID		8
155dc2b9f19SEric Leblond #define NETLINK_LIST_MEMBERSHIPS	9
156dc2b9f19SEric Leblond #define NETLINK_CAP_ACK			10
157dc2b9f19SEric Leblond #define NETLINK_EXT_ACK			11
158*d3e8869eSJakub Kicinski #define NETLINK_GET_STRICT_CHK		12
159dc2b9f19SEric Leblond 
160dc2b9f19SEric Leblond struct nl_pktinfo {
161dc2b9f19SEric Leblond 	__u32	group;
162dc2b9f19SEric Leblond };
163dc2b9f19SEric Leblond 
164dc2b9f19SEric Leblond struct nl_mmap_req {
165dc2b9f19SEric Leblond 	unsigned int	nm_block_size;
166dc2b9f19SEric Leblond 	unsigned int	nm_block_nr;
167dc2b9f19SEric Leblond 	unsigned int	nm_frame_size;
168dc2b9f19SEric Leblond 	unsigned int	nm_frame_nr;
169dc2b9f19SEric Leblond };
170dc2b9f19SEric Leblond 
171dc2b9f19SEric Leblond struct nl_mmap_hdr {
172dc2b9f19SEric Leblond 	unsigned int	nm_status;
173dc2b9f19SEric Leblond 	unsigned int	nm_len;
174dc2b9f19SEric Leblond 	__u32		nm_group;
175dc2b9f19SEric Leblond 	/* credentials */
176dc2b9f19SEric Leblond 	__u32		nm_pid;
177dc2b9f19SEric Leblond 	__u32		nm_uid;
178dc2b9f19SEric Leblond 	__u32		nm_gid;
179dc2b9f19SEric Leblond };
180dc2b9f19SEric Leblond 
181dc2b9f19SEric Leblond #ifndef __KERNEL__
182dc2b9f19SEric Leblond enum nl_mmap_status {
183dc2b9f19SEric Leblond 	NL_MMAP_STATUS_UNUSED,
184dc2b9f19SEric Leblond 	NL_MMAP_STATUS_RESERVED,
185dc2b9f19SEric Leblond 	NL_MMAP_STATUS_VALID,
186dc2b9f19SEric Leblond 	NL_MMAP_STATUS_COPY,
187dc2b9f19SEric Leblond 	NL_MMAP_STATUS_SKIP,
188dc2b9f19SEric Leblond };
189dc2b9f19SEric Leblond 
190dc2b9f19SEric Leblond #define NL_MMAP_MSG_ALIGNMENT		NLMSG_ALIGNTO
191dc2b9f19SEric Leblond #define NL_MMAP_MSG_ALIGN(sz)		__ALIGN_KERNEL(sz, NL_MMAP_MSG_ALIGNMENT)
192dc2b9f19SEric Leblond #define NL_MMAP_HDRLEN			NL_MMAP_MSG_ALIGN(sizeof(struct nl_mmap_hdr))
193dc2b9f19SEric Leblond #endif
194dc2b9f19SEric Leblond 
195dc2b9f19SEric Leblond #define NET_MAJOR 36		/* Major 36 is reserved for networking 						*/
196dc2b9f19SEric Leblond 
197dc2b9f19SEric Leblond enum {
198dc2b9f19SEric Leblond 	NETLINK_UNCONNECTED = 0,
199dc2b9f19SEric Leblond 	NETLINK_CONNECTED,
200dc2b9f19SEric Leblond };
201dc2b9f19SEric Leblond 
202dc2b9f19SEric Leblond /*
203dc2b9f19SEric Leblond  *  <------- NLA_HDRLEN ------> <-- NLA_ALIGN(payload)-->
204dc2b9f19SEric Leblond  * +---------------------+- - -+- - - - - - - - - -+- - -+
205dc2b9f19SEric Leblond  * |        Header       | Pad |     Payload       | Pad |
206dc2b9f19SEric Leblond  * |   (struct nlattr)   | ing |                   | ing |
207dc2b9f19SEric Leblond  * +---------------------+- - -+- - - - - - - - - -+- - -+
208dc2b9f19SEric Leblond  *  <-------------- nlattr->nla_len -------------->
209dc2b9f19SEric Leblond  */
210dc2b9f19SEric Leblond 
211dc2b9f19SEric Leblond struct nlattr {
212dc2b9f19SEric Leblond 	__u16           nla_len;
213dc2b9f19SEric Leblond 	__u16           nla_type;
214dc2b9f19SEric Leblond };
215dc2b9f19SEric Leblond 
216dc2b9f19SEric Leblond /*
217dc2b9f19SEric Leblond  * nla_type (16 bits)
218dc2b9f19SEric Leblond  * +---+---+-------------------------------+
219dc2b9f19SEric Leblond  * | N | O | Attribute Type                |
220dc2b9f19SEric Leblond  * +---+---+-------------------------------+
221dc2b9f19SEric Leblond  * N := Carries nested attributes
222dc2b9f19SEric Leblond  * O := Payload stored in network byte order
223dc2b9f19SEric Leblond  *
224dc2b9f19SEric Leblond  * Note: The N and O flag are mutually exclusive.
225dc2b9f19SEric Leblond  */
226dc2b9f19SEric Leblond #define NLA_F_NESTED		(1 << 15)
227dc2b9f19SEric Leblond #define NLA_F_NET_BYTEORDER	(1 << 14)
228dc2b9f19SEric Leblond #define NLA_TYPE_MASK		~(NLA_F_NESTED | NLA_F_NET_BYTEORDER)
229dc2b9f19SEric Leblond 
230dc2b9f19SEric Leblond #define NLA_ALIGNTO		4
231dc2b9f19SEric Leblond #define NLA_ALIGN(len)		(((len) + NLA_ALIGNTO - 1) & ~(NLA_ALIGNTO - 1))
232dc2b9f19SEric Leblond #define NLA_HDRLEN		((int) NLA_ALIGN(sizeof(struct nlattr)))
233dc2b9f19SEric Leblond 
234dc2b9f19SEric Leblond /* Generic 32 bitflags attribute content sent to the kernel.
235dc2b9f19SEric Leblond  *
236dc2b9f19SEric Leblond  * The value is a bitmap that defines the values being set
237dc2b9f19SEric Leblond  * The selector is a bitmask that defines which value is legit
238dc2b9f19SEric Leblond  *
239dc2b9f19SEric Leblond  * Examples:
240dc2b9f19SEric Leblond  *  value = 0x0, and selector = 0x1
241dc2b9f19SEric Leblond  *  implies we are selecting bit 1 and we want to set its value to 0.
242dc2b9f19SEric Leblond  *
243dc2b9f19SEric Leblond  *  value = 0x2, and selector = 0x2
244dc2b9f19SEric Leblond  *  implies we are selecting bit 2 and we want to set its value to 1.
245dc2b9f19SEric Leblond  *
246dc2b9f19SEric Leblond  */
247dc2b9f19SEric Leblond struct nla_bitfield32 {
248dc2b9f19SEric Leblond 	__u32 value;
249dc2b9f19SEric Leblond 	__u32 selector;
250dc2b9f19SEric Leblond };
251dc2b9f19SEric Leblond 
252dc2b9f19SEric Leblond #endif /* _UAPI__LINUX_NETLINK_H */
253