xref: /linux/include/uapi/linux/netlink.h (revision d3e8869ec82645599e6497d6974593bf00f7b19b)
16f52b16cSGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2607ca46eSDavid Howells #ifndef _UAPI__LINUX_NETLINK_H
3607ca46eSDavid Howells #define _UAPI__LINUX_NETLINK_H
4607ca46eSDavid Howells 
5ccdfcc39SPatrick McHardy #include <linux/kernel.h>
6607ca46eSDavid Howells #include <linux/socket.h> /* for __kernel_sa_family_t */
7607ca46eSDavid Howells #include <linux/types.h>
8607ca46eSDavid Howells 
9607ca46eSDavid Howells #define NETLINK_ROUTE		0	/* Routing/device hook				*/
10607ca46eSDavid Howells #define NETLINK_UNUSED		1	/* Unused number				*/
11607ca46eSDavid Howells #define NETLINK_USERSOCK	2	/* Reserved for user mode socket protocols 	*/
12607ca46eSDavid Howells #define NETLINK_FIREWALL	3	/* Unused number, formerly ip_queue		*/
13607ca46eSDavid Howells #define NETLINK_SOCK_DIAG	4	/* socket monitoring				*/
14607ca46eSDavid Howells #define NETLINK_NFLOG		5	/* netfilter/iptables ULOG */
15607ca46eSDavid Howells #define NETLINK_XFRM		6	/* ipsec */
16607ca46eSDavid Howells #define NETLINK_SELINUX		7	/* SELinux event notifications */
17607ca46eSDavid Howells #define NETLINK_ISCSI		8	/* Open-iSCSI */
18607ca46eSDavid Howells #define NETLINK_AUDIT		9	/* auditing */
19607ca46eSDavid Howells #define NETLINK_FIB_LOOKUP	10
20607ca46eSDavid Howells #define NETLINK_CONNECTOR	11
21607ca46eSDavid Howells #define NETLINK_NETFILTER	12	/* netfilter subsystem */
22607ca46eSDavid Howells #define NETLINK_IP6_FW		13
23607ca46eSDavid Howells #define NETLINK_DNRTMSG		14	/* DECnet routing messages */
24607ca46eSDavid Howells #define NETLINK_KOBJECT_UEVENT	15	/* Kernel messages to userspace */
25607ca46eSDavid Howells #define NETLINK_GENERIC		16
26607ca46eSDavid Howells /* leave room for NETLINK_DM (DM Events) */
27607ca46eSDavid Howells #define NETLINK_SCSITRANSPORT	18	/* SCSI Transports */
28607ca46eSDavid Howells #define NETLINK_ECRYPTFS	19
29607ca46eSDavid Howells #define NETLINK_RDMA		20
30607ca46eSDavid Howells #define NETLINK_CRYPTO		21	/* Crypto layer */
31f16a7dd5SUrsula Braun #define NETLINK_SMC		22	/* SMC monitoring */
32607ca46eSDavid Howells 
33607ca46eSDavid Howells #define NETLINK_INET_DIAG	NETLINK_SOCK_DIAG
34607ca46eSDavid Howells 
35607ca46eSDavid Howells #define MAX_LINKS 32
36607ca46eSDavid Howells 
37607ca46eSDavid Howells struct sockaddr_nl {
38607ca46eSDavid Howells 	__kernel_sa_family_t	nl_family;	/* AF_NETLINK	*/
39607ca46eSDavid Howells 	unsigned short	nl_pad;		/* zero		*/
40607ca46eSDavid Howells 	__u32		nl_pid;		/* port ID	*/
41607ca46eSDavid Howells        	__u32		nl_groups;	/* multicast groups mask */
42607ca46eSDavid Howells };
43607ca46eSDavid Howells 
44607ca46eSDavid Howells struct nlmsghdr {
45607ca46eSDavid Howells 	__u32		nlmsg_len;	/* Length of message including header */
46607ca46eSDavid Howells 	__u16		nlmsg_type;	/* Message content */
47607ca46eSDavid Howells 	__u16		nlmsg_flags;	/* Additional flags */
48607ca46eSDavid Howells 	__u32		nlmsg_seq;	/* Sequence number */
49607ca46eSDavid Howells 	__u32		nlmsg_pid;	/* Sending process port ID */
50607ca46eSDavid Howells };
51607ca46eSDavid Howells 
52607ca46eSDavid Howells /* Flags values */
53607ca46eSDavid Howells 
54261a0a54SJohannes Berg #define NLM_F_REQUEST		0x01	/* It is request message. 	*/
55261a0a54SJohannes Berg #define NLM_F_MULTI		0x02	/* Multipart message, terminated by NLMSG_DONE */
56261a0a54SJohannes Berg #define NLM_F_ACK		0x04	/* Reply with ack, with zero or error code */
57261a0a54SJohannes Berg #define NLM_F_ECHO		0x08	/* Echo this request 		*/
58261a0a54SJohannes Berg #define NLM_F_DUMP_INTR		0x10	/* Dump was inconsistent due to sequence change */
59261a0a54SJohannes Berg #define NLM_F_DUMP_FILTERED	0x20	/* Dump was filtered as requested */
60607ca46eSDavid Howells 
61607ca46eSDavid Howells /* Modifiers to GET request */
62607ca46eSDavid Howells #define NLM_F_ROOT	0x100	/* specify tree	root	*/
63607ca46eSDavid Howells #define NLM_F_MATCH	0x200	/* return all matching	*/
64607ca46eSDavid Howells #define NLM_F_ATOMIC	0x400	/* atomic GET		*/
65607ca46eSDavid Howells #define NLM_F_DUMP	(NLM_F_ROOT|NLM_F_MATCH)
66607ca46eSDavid Howells 
67607ca46eSDavid Howells /* Modifiers to NEW request */
68607ca46eSDavid Howells #define NLM_F_REPLACE	0x100	/* Override existing		*/
69607ca46eSDavid Howells #define NLM_F_EXCL	0x200	/* Do not touch, if it exists	*/
70607ca46eSDavid Howells #define NLM_F_CREATE	0x400	/* Create, if it does not exist	*/
71607ca46eSDavid Howells #define NLM_F_APPEND	0x800	/* Add to end of list		*/
72607ca46eSDavid Howells 
732335ba70SPablo Neira Ayuso /* Modifiers to DELETE request */
742335ba70SPablo Neira Ayuso #define NLM_F_NONREC	0x100	/* Do not delete recursively	*/
752335ba70SPablo Neira Ayuso 
762d4bc933SJohannes Berg /* Flags for ACK message */
772d4bc933SJohannes Berg #define NLM_F_CAPPED	0x100	/* request was capped */
782d4bc933SJohannes Berg #define NLM_F_ACK_TLVS	0x200	/* extended ACK TVLs were included */
792d4bc933SJohannes Berg 
80607ca46eSDavid Howells /*
81607ca46eSDavid Howells    4.4BSD ADD		NLM_F_CREATE|NLM_F_EXCL
82607ca46eSDavid Howells    4.4BSD CHANGE	NLM_F_REPLACE
83607ca46eSDavid Howells 
84607ca46eSDavid Howells    True CHANGE		NLM_F_CREATE|NLM_F_REPLACE
85607ca46eSDavid Howells    Append		NLM_F_CREATE
86607ca46eSDavid Howells    Check		NLM_F_EXCL
87607ca46eSDavid Howells  */
88607ca46eSDavid Howells 
89607ca46eSDavid Howells #define NLMSG_ALIGNTO	4U
90607ca46eSDavid Howells #define NLMSG_ALIGN(len) ( ((len)+NLMSG_ALIGNTO-1) & ~(NLMSG_ALIGNTO-1) )
91607ca46eSDavid Howells #define NLMSG_HDRLEN	 ((int) NLMSG_ALIGN(sizeof(struct nlmsghdr)))
92a88b9ce5SHong zhi guo #define NLMSG_LENGTH(len) ((len) + NLMSG_HDRLEN)
93607ca46eSDavid Howells #define NLMSG_SPACE(len) NLMSG_ALIGN(NLMSG_LENGTH(len))
94607ca46eSDavid Howells #define NLMSG_DATA(nlh)  ((void*)(((char*)nlh) + NLMSG_LENGTH(0)))
95607ca46eSDavid Howells #define NLMSG_NEXT(nlh,len)	 ((len) -= NLMSG_ALIGN((nlh)->nlmsg_len), \
96607ca46eSDavid Howells 				  (struct nlmsghdr*)(((char*)(nlh)) + NLMSG_ALIGN((nlh)->nlmsg_len)))
97607ca46eSDavid Howells #define NLMSG_OK(nlh,len) ((len) >= (int)sizeof(struct nlmsghdr) && \
98607ca46eSDavid Howells 			   (nlh)->nlmsg_len >= sizeof(struct nlmsghdr) && \
99607ca46eSDavid Howells 			   (nlh)->nlmsg_len <= (len))
100607ca46eSDavid Howells #define NLMSG_PAYLOAD(nlh,len) ((nlh)->nlmsg_len - NLMSG_SPACE((len)))
101607ca46eSDavid Howells 
102607ca46eSDavid Howells #define NLMSG_NOOP		0x1	/* Nothing.		*/
103607ca46eSDavid Howells #define NLMSG_ERROR		0x2	/* Error		*/
104607ca46eSDavid Howells #define NLMSG_DONE		0x3	/* End of a dump	*/
105607ca46eSDavid Howells #define NLMSG_OVERRUN		0x4	/* Data lost		*/
106607ca46eSDavid Howells 
107607ca46eSDavid Howells #define NLMSG_MIN_TYPE		0x10	/* < 0x10: reserved control messages */
108607ca46eSDavid Howells 
109607ca46eSDavid Howells struct nlmsgerr {
110607ca46eSDavid Howells 	int		error;
111607ca46eSDavid Howells 	struct nlmsghdr msg;
1122d4bc933SJohannes Berg 	/*
1132d4bc933SJohannes Berg 	 * followed by the message contents unless NETLINK_CAP_ACK was set
1142d4bc933SJohannes Berg 	 * or the ACK indicates success (error == 0)
1152d4bc933SJohannes Berg 	 * message length is aligned with NLMSG_ALIGN()
1162d4bc933SJohannes Berg 	 */
1172d4bc933SJohannes Berg 	/*
1182d4bc933SJohannes Berg 	 * followed by TLVs defined in enum nlmsgerr_attrs
1192d4bc933SJohannes Berg 	 * if NETLINK_EXT_ACK was set
1202d4bc933SJohannes Berg 	 */
1212d4bc933SJohannes Berg };
1222d4bc933SJohannes Berg 
1232d4bc933SJohannes Berg /**
1242d4bc933SJohannes Berg  * enum nlmsgerr_attrs - nlmsgerr attributes
1252d4bc933SJohannes Berg  * @NLMSGERR_ATTR_UNUSED: unused
1262d4bc933SJohannes Berg  * @NLMSGERR_ATTR_MSG: error message string (string)
1272d4bc933SJohannes Berg  * @NLMSGERR_ATTR_OFFS: offset of the invalid attribute in the original
1282d4bc933SJohannes Berg  *	 message, counting from the beginning of the header (u32)
129ba0dc5f6SJohannes Berg  * @NLMSGERR_ATTR_COOKIE: arbitrary subsystem specific cookie to
130ba0dc5f6SJohannes Berg  *	be used - in the success case - to identify a created
131ba0dc5f6SJohannes Berg  *	object or operation or similar (binary)
1322d4bc933SJohannes Berg  * @__NLMSGERR_ATTR_MAX: number of attributes
1332d4bc933SJohannes Berg  * @NLMSGERR_ATTR_MAX: highest attribute number
1342d4bc933SJohannes Berg  */
1352d4bc933SJohannes Berg enum nlmsgerr_attrs {
1362d4bc933SJohannes Berg 	NLMSGERR_ATTR_UNUSED,
1372d4bc933SJohannes Berg 	NLMSGERR_ATTR_MSG,
1382d4bc933SJohannes Berg 	NLMSGERR_ATTR_OFFS,
139ba0dc5f6SJohannes Berg 	NLMSGERR_ATTR_COOKIE,
1402d4bc933SJohannes Berg 
1412d4bc933SJohannes Berg 	__NLMSGERR_ATTR_MAX,
1422d4bc933SJohannes Berg 	NLMSGERR_ATTR_MAX = __NLMSGERR_ATTR_MAX - 1
143607ca46eSDavid Howells };
144607ca46eSDavid Howells 
145607ca46eSDavid Howells #define NETLINK_ADD_MEMBERSHIP		1
146607ca46eSDavid Howells #define NETLINK_DROP_MEMBERSHIP		2
147607ca46eSDavid Howells #define NETLINK_PKTINFO			3
148607ca46eSDavid Howells #define NETLINK_BROADCAST_ERROR		4
149607ca46eSDavid Howells #define NETLINK_NO_ENOBUFS		5
150d1b4c689SFlorian Westphal #ifndef __KERNEL__
151ccdfcc39SPatrick McHardy #define NETLINK_RX_RING			6
152ccdfcc39SPatrick McHardy #define NETLINK_TX_RING			7
153d1b4c689SFlorian Westphal #endif
15459324cf3SNicolas Dichtel #define NETLINK_LISTEN_ALL_NSID		8
155b42be38bSDavid Herrmann #define NETLINK_LIST_MEMBERSHIPS	9
1560a6a3a23SChristophe Ricard #define NETLINK_CAP_ACK			10
1572d4bc933SJohannes Berg #define NETLINK_EXT_ACK			11
158*d3e8869eSJakub Kicinski #define NETLINK_GET_STRICT_CHK		12
159607ca46eSDavid Howells 
160607ca46eSDavid Howells struct nl_pktinfo {
161607ca46eSDavid Howells 	__u32	group;
162607ca46eSDavid Howells };
163607ca46eSDavid Howells 
164ccdfcc39SPatrick McHardy struct nl_mmap_req {
165ccdfcc39SPatrick McHardy 	unsigned int	nm_block_size;
166ccdfcc39SPatrick McHardy 	unsigned int	nm_block_nr;
167ccdfcc39SPatrick McHardy 	unsigned int	nm_frame_size;
168ccdfcc39SPatrick McHardy 	unsigned int	nm_frame_nr;
169ccdfcc39SPatrick McHardy };
170ccdfcc39SPatrick McHardy 
171ccdfcc39SPatrick McHardy struct nl_mmap_hdr {
172ccdfcc39SPatrick McHardy 	unsigned int	nm_status;
173ccdfcc39SPatrick McHardy 	unsigned int	nm_len;
174ccdfcc39SPatrick McHardy 	__u32		nm_group;
175ccdfcc39SPatrick McHardy 	/* credentials */
176ccdfcc39SPatrick McHardy 	__u32		nm_pid;
177ccdfcc39SPatrick McHardy 	__u32		nm_uid;
178ccdfcc39SPatrick McHardy 	__u32		nm_gid;
179ccdfcc39SPatrick McHardy };
180ccdfcc39SPatrick McHardy 
181d1b4c689SFlorian Westphal #ifndef __KERNEL__
182ccdfcc39SPatrick McHardy enum nl_mmap_status {
183ccdfcc39SPatrick McHardy 	NL_MMAP_STATUS_UNUSED,
184ccdfcc39SPatrick McHardy 	NL_MMAP_STATUS_RESERVED,
185ccdfcc39SPatrick McHardy 	NL_MMAP_STATUS_VALID,
186ccdfcc39SPatrick McHardy 	NL_MMAP_STATUS_COPY,
187ccdfcc39SPatrick McHardy 	NL_MMAP_STATUS_SKIP,
188ccdfcc39SPatrick McHardy };
189ccdfcc39SPatrick McHardy 
190ccdfcc39SPatrick McHardy #define NL_MMAP_MSG_ALIGNMENT		NLMSG_ALIGNTO
191ccdfcc39SPatrick McHardy #define NL_MMAP_MSG_ALIGN(sz)		__ALIGN_KERNEL(sz, NL_MMAP_MSG_ALIGNMENT)
192ccdfcc39SPatrick McHardy #define NL_MMAP_HDRLEN			NL_MMAP_MSG_ALIGN(sizeof(struct nl_mmap_hdr))
193d1b4c689SFlorian Westphal #endif
194ccdfcc39SPatrick McHardy 
195607ca46eSDavid Howells #define NET_MAJOR 36		/* Major 36 is reserved for networking 						*/
196607ca46eSDavid Howells 
197607ca46eSDavid Howells enum {
198607ca46eSDavid Howells 	NETLINK_UNCONNECTED = 0,
199607ca46eSDavid Howells 	NETLINK_CONNECTED,
200607ca46eSDavid Howells };
201607ca46eSDavid Howells 
202607ca46eSDavid Howells /*
203607ca46eSDavid Howells  *  <------- NLA_HDRLEN ------> <-- NLA_ALIGN(payload)-->
204607ca46eSDavid Howells  * +---------------------+- - -+- - - - - - - - - -+- - -+
205607ca46eSDavid Howells  * |        Header       | Pad |     Payload       | Pad |
206607ca46eSDavid Howells  * |   (struct nlattr)   | ing |                   | ing |
207607ca46eSDavid Howells  * +---------------------+- - -+- - - - - - - - - -+- - -+
208607ca46eSDavid Howells  *  <-------------- nlattr->nla_len -------------->
209607ca46eSDavid Howells  */
210607ca46eSDavid Howells 
211607ca46eSDavid Howells struct nlattr {
212607ca46eSDavid Howells 	__u16           nla_len;
213607ca46eSDavid Howells 	__u16           nla_type;
214607ca46eSDavid Howells };
215607ca46eSDavid Howells 
216607ca46eSDavid Howells /*
217607ca46eSDavid Howells  * nla_type (16 bits)
218607ca46eSDavid Howells  * +---+---+-------------------------------+
219607ca46eSDavid Howells  * | N | O | Attribute Type                |
220607ca46eSDavid Howells  * +---+---+-------------------------------+
221607ca46eSDavid Howells  * N := Carries nested attributes
222607ca46eSDavid Howells  * O := Payload stored in network byte order
223607ca46eSDavid Howells  *
224607ca46eSDavid Howells  * Note: The N and O flag are mutually exclusive.
225607ca46eSDavid Howells  */
226607ca46eSDavid Howells #define NLA_F_NESTED		(1 << 15)
227607ca46eSDavid Howells #define NLA_F_NET_BYTEORDER	(1 << 14)
228607ca46eSDavid Howells #define NLA_TYPE_MASK		~(NLA_F_NESTED | NLA_F_NET_BYTEORDER)
229607ca46eSDavid Howells 
230607ca46eSDavid Howells #define NLA_ALIGNTO		4
231607ca46eSDavid Howells #define NLA_ALIGN(len)		(((len) + NLA_ALIGNTO - 1) & ~(NLA_ALIGNTO - 1))
232607ca46eSDavid Howells #define NLA_HDRLEN		((int) NLA_ALIGN(sizeof(struct nlattr)))
233607ca46eSDavid Howells 
23464c83d83SJamal Hadi Salim /* Generic 32 bitflags attribute content sent to the kernel.
23564c83d83SJamal Hadi Salim  *
23664c83d83SJamal Hadi Salim  * The value is a bitmap that defines the values being set
23764c83d83SJamal Hadi Salim  * The selector is a bitmask that defines which value is legit
23864c83d83SJamal Hadi Salim  *
23964c83d83SJamal Hadi Salim  * Examples:
24064c83d83SJamal Hadi Salim  *  value = 0x0, and selector = 0x1
24164c83d83SJamal Hadi Salim  *  implies we are selecting bit 1 and we want to set its value to 0.
24264c83d83SJamal Hadi Salim  *
24364c83d83SJamal Hadi Salim  *  value = 0x2, and selector = 0x2
24464c83d83SJamal Hadi Salim  *  implies we are selecting bit 2 and we want to set its value to 1.
24564c83d83SJamal Hadi Salim  *
24664c83d83SJamal Hadi Salim  */
24764c83d83SJamal Hadi Salim struct nla_bitfield32 {
24864c83d83SJamal Hadi Salim 	__u32 value;
24964c83d83SJamal Hadi Salim 	__u32 selector;
25064c83d83SJamal Hadi Salim };
251607ca46eSDavid Howells 
252607ca46eSDavid Howells #endif /* _UAPI__LINUX_NETLINK_H */
253