17c2aad20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
27c2aad20Sopenharmony_ci#ifndef _UAPI__LINUX_NETLINK_H
37c2aad20Sopenharmony_ci#define _UAPI__LINUX_NETLINK_H
47c2aad20Sopenharmony_ci
57c2aad20Sopenharmony_ci#include <linux/kernel.h>
67c2aad20Sopenharmony_ci#include <linux/socket.h> /* for __kernel_sa_family_t */
77c2aad20Sopenharmony_ci#include <linux/types.h>
87c2aad20Sopenharmony_ci
97c2aad20Sopenharmony_ci#define NETLINK_ROUTE		0	/* Routing/device hook				*/
107c2aad20Sopenharmony_ci#define NETLINK_UNUSED		1	/* Unused number				*/
117c2aad20Sopenharmony_ci#define NETLINK_USERSOCK	2	/* Reserved for user mode socket protocols 	*/
127c2aad20Sopenharmony_ci#define NETLINK_FIREWALL	3	/* Unused number, formerly ip_queue		*/
137c2aad20Sopenharmony_ci#define NETLINK_SOCK_DIAG	4	/* socket monitoring				*/
147c2aad20Sopenharmony_ci#define NETLINK_NFLOG		5	/* netfilter/iptables ULOG */
157c2aad20Sopenharmony_ci#define NETLINK_XFRM		6	/* ipsec */
167c2aad20Sopenharmony_ci#define NETLINK_SELINUX		7	/* SELinux event notifications */
177c2aad20Sopenharmony_ci#define NETLINK_ISCSI		8	/* Open-iSCSI */
187c2aad20Sopenharmony_ci#define NETLINK_AUDIT		9	/* auditing */
197c2aad20Sopenharmony_ci#define NETLINK_FIB_LOOKUP	10
207c2aad20Sopenharmony_ci#define NETLINK_CONNECTOR	11
217c2aad20Sopenharmony_ci#define NETLINK_NETFILTER	12	/* netfilter subsystem */
227c2aad20Sopenharmony_ci#define NETLINK_IP6_FW		13
237c2aad20Sopenharmony_ci#define NETLINK_DNRTMSG		14	/* DECnet routing messages */
247c2aad20Sopenharmony_ci#define NETLINK_KOBJECT_UEVENT	15	/* Kernel messages to userspace */
257c2aad20Sopenharmony_ci#define NETLINK_GENERIC		16
267c2aad20Sopenharmony_ci/* leave room for NETLINK_DM (DM Events) */
277c2aad20Sopenharmony_ci#define NETLINK_SCSITRANSPORT	18	/* SCSI Transports */
287c2aad20Sopenharmony_ci#define NETLINK_ECRYPTFS	19
297c2aad20Sopenharmony_ci#define NETLINK_RDMA		20
307c2aad20Sopenharmony_ci#define NETLINK_CRYPTO		21	/* Crypto layer */
317c2aad20Sopenharmony_ci#define NETLINK_SMC		22	/* SMC monitoring */
327c2aad20Sopenharmony_ci
337c2aad20Sopenharmony_ci#define NETLINK_INET_DIAG	NETLINK_SOCK_DIAG
347c2aad20Sopenharmony_ci
357c2aad20Sopenharmony_ci#define MAX_LINKS 32
367c2aad20Sopenharmony_ci
377c2aad20Sopenharmony_cistruct sockaddr_nl {
387c2aad20Sopenharmony_ci	__kernel_sa_family_t	nl_family;	/* AF_NETLINK	*/
397c2aad20Sopenharmony_ci	unsigned short	nl_pad;		/* zero		*/
407c2aad20Sopenharmony_ci	__u32		nl_pid;		/* port ID	*/
417c2aad20Sopenharmony_ci       	__u32		nl_groups;	/* multicast groups mask */
427c2aad20Sopenharmony_ci};
437c2aad20Sopenharmony_ci
447c2aad20Sopenharmony_cistruct nlmsghdr {
457c2aad20Sopenharmony_ci	__u32		nlmsg_len;	/* Length of message including header */
467c2aad20Sopenharmony_ci	__u16		nlmsg_type;	/* Message content */
477c2aad20Sopenharmony_ci	__u16		nlmsg_flags;	/* Additional flags */
487c2aad20Sopenharmony_ci	__u32		nlmsg_seq;	/* Sequence number */
497c2aad20Sopenharmony_ci	__u32		nlmsg_pid;	/* Sending process port ID */
507c2aad20Sopenharmony_ci};
517c2aad20Sopenharmony_ci
527c2aad20Sopenharmony_ci/* Flags values */
537c2aad20Sopenharmony_ci
547c2aad20Sopenharmony_ci#define NLM_F_REQUEST		0x01	/* It is request message. 	*/
557c2aad20Sopenharmony_ci#define NLM_F_MULTI		0x02	/* Multipart message, terminated by NLMSG_DONE */
567c2aad20Sopenharmony_ci#define NLM_F_ACK		0x04	/* Reply with ack, with zero or error code */
577c2aad20Sopenharmony_ci#define NLM_F_ECHO		0x08	/* Echo this request 		*/
587c2aad20Sopenharmony_ci#define NLM_F_DUMP_INTR		0x10	/* Dump was inconsistent due to sequence change */
597c2aad20Sopenharmony_ci#define NLM_F_DUMP_FILTERED	0x20	/* Dump was filtered as requested */
607c2aad20Sopenharmony_ci
617c2aad20Sopenharmony_ci/* Modifiers to GET request */
627c2aad20Sopenharmony_ci#define NLM_F_ROOT	0x100	/* specify tree	root	*/
637c2aad20Sopenharmony_ci#define NLM_F_MATCH	0x200	/* return all matching	*/
647c2aad20Sopenharmony_ci#define NLM_F_ATOMIC	0x400	/* atomic GET		*/
657c2aad20Sopenharmony_ci#define NLM_F_DUMP	(NLM_F_ROOT|NLM_F_MATCH)
667c2aad20Sopenharmony_ci
677c2aad20Sopenharmony_ci/* Modifiers to NEW request */
687c2aad20Sopenharmony_ci#define NLM_F_REPLACE	0x100	/* Override existing		*/
697c2aad20Sopenharmony_ci#define NLM_F_EXCL	0x200	/* Do not touch, if it exists	*/
707c2aad20Sopenharmony_ci#define NLM_F_CREATE	0x400	/* Create, if it does not exist	*/
717c2aad20Sopenharmony_ci#define NLM_F_APPEND	0x800	/* Add to end of list		*/
727c2aad20Sopenharmony_ci
737c2aad20Sopenharmony_ci/* Modifiers to DELETE request */
747c2aad20Sopenharmony_ci#define NLM_F_NONREC	0x100	/* Do not delete recursively	*/
757c2aad20Sopenharmony_ci
767c2aad20Sopenharmony_ci/* Flags for ACK message */
777c2aad20Sopenharmony_ci#define NLM_F_CAPPED	0x100	/* request was capped */
787c2aad20Sopenharmony_ci#define NLM_F_ACK_TLVS	0x200	/* extended ACK TVLs were included */
797c2aad20Sopenharmony_ci
807c2aad20Sopenharmony_ci/*
817c2aad20Sopenharmony_ci   4.4BSD ADD		NLM_F_CREATE|NLM_F_EXCL
827c2aad20Sopenharmony_ci   4.4BSD CHANGE	NLM_F_REPLACE
837c2aad20Sopenharmony_ci
847c2aad20Sopenharmony_ci   True CHANGE		NLM_F_CREATE|NLM_F_REPLACE
857c2aad20Sopenharmony_ci   Append		NLM_F_CREATE
867c2aad20Sopenharmony_ci   Check		NLM_F_EXCL
877c2aad20Sopenharmony_ci */
887c2aad20Sopenharmony_ci
897c2aad20Sopenharmony_ci#define NLMSG_ALIGNTO	4U
907c2aad20Sopenharmony_ci#define NLMSG_ALIGN(len) ( ((len)+NLMSG_ALIGNTO-1) & ~(NLMSG_ALIGNTO-1) )
917c2aad20Sopenharmony_ci#define NLMSG_HDRLEN	 ((int) NLMSG_ALIGN(sizeof(struct nlmsghdr)))
927c2aad20Sopenharmony_ci#define NLMSG_LENGTH(len) ((len) + NLMSG_HDRLEN)
937c2aad20Sopenharmony_ci#define NLMSG_SPACE(len) NLMSG_ALIGN(NLMSG_LENGTH(len))
947c2aad20Sopenharmony_ci#define NLMSG_DATA(nlh)  ((void*)(((char*)nlh) + NLMSG_LENGTH(0)))
957c2aad20Sopenharmony_ci#define NLMSG_NEXT(nlh,len)	 ((len) -= NLMSG_ALIGN((nlh)->nlmsg_len), \
967c2aad20Sopenharmony_ci				  (struct nlmsghdr*)(((char*)(nlh)) + NLMSG_ALIGN((nlh)->nlmsg_len)))
977c2aad20Sopenharmony_ci#define NLMSG_OK(nlh,len) ((len) >= (int)sizeof(struct nlmsghdr) && \
987c2aad20Sopenharmony_ci			   (nlh)->nlmsg_len >= sizeof(struct nlmsghdr) && \
997c2aad20Sopenharmony_ci			   (nlh)->nlmsg_len <= (len))
1007c2aad20Sopenharmony_ci#define NLMSG_PAYLOAD(nlh,len) ((nlh)->nlmsg_len - NLMSG_SPACE((len)))
1017c2aad20Sopenharmony_ci
1027c2aad20Sopenharmony_ci#define NLMSG_NOOP		0x1	/* Nothing.		*/
1037c2aad20Sopenharmony_ci#define NLMSG_ERROR		0x2	/* Error		*/
1047c2aad20Sopenharmony_ci#define NLMSG_DONE		0x3	/* End of a dump	*/
1057c2aad20Sopenharmony_ci#define NLMSG_OVERRUN		0x4	/* Data lost		*/
1067c2aad20Sopenharmony_ci
1077c2aad20Sopenharmony_ci#define NLMSG_MIN_TYPE		0x10	/* < 0x10: reserved control messages */
1087c2aad20Sopenharmony_ci
1097c2aad20Sopenharmony_cistruct nlmsgerr {
1107c2aad20Sopenharmony_ci	int		error;
1117c2aad20Sopenharmony_ci	struct nlmsghdr msg;
1127c2aad20Sopenharmony_ci	/*
1137c2aad20Sopenharmony_ci	 * followed by the message contents unless NETLINK_CAP_ACK was set
1147c2aad20Sopenharmony_ci	 * or the ACK indicates success (error == 0)
1157c2aad20Sopenharmony_ci	 * message length is aligned with NLMSG_ALIGN()
1167c2aad20Sopenharmony_ci	 */
1177c2aad20Sopenharmony_ci	/*
1187c2aad20Sopenharmony_ci	 * followed by TLVs defined in enum nlmsgerr_attrs
1197c2aad20Sopenharmony_ci	 * if NETLINK_EXT_ACK was set
1207c2aad20Sopenharmony_ci	 */
1217c2aad20Sopenharmony_ci};
1227c2aad20Sopenharmony_ci
1237c2aad20Sopenharmony_ci/**
1247c2aad20Sopenharmony_ci * enum nlmsgerr_attrs - nlmsgerr attributes
1257c2aad20Sopenharmony_ci * @NLMSGERR_ATTR_UNUSED: unused
1267c2aad20Sopenharmony_ci * @NLMSGERR_ATTR_MSG: error message string (string)
1277c2aad20Sopenharmony_ci * @NLMSGERR_ATTR_OFFS: offset of the invalid attribute in the original
1287c2aad20Sopenharmony_ci *	 message, counting from the beginning of the header (u32)
1297c2aad20Sopenharmony_ci * @NLMSGERR_ATTR_COOKIE: arbitrary subsystem specific cookie to
1307c2aad20Sopenharmony_ci *	be used - in the success case - to identify a created
1317c2aad20Sopenharmony_ci *	object or operation or similar (binary)
1327c2aad20Sopenharmony_ci * @__NLMSGERR_ATTR_MAX: number of attributes
1337c2aad20Sopenharmony_ci * @NLMSGERR_ATTR_MAX: highest attribute number
1347c2aad20Sopenharmony_ci */
1357c2aad20Sopenharmony_cienum nlmsgerr_attrs {
1367c2aad20Sopenharmony_ci	NLMSGERR_ATTR_UNUSED,
1377c2aad20Sopenharmony_ci	NLMSGERR_ATTR_MSG,
1387c2aad20Sopenharmony_ci	NLMSGERR_ATTR_OFFS,
1397c2aad20Sopenharmony_ci	NLMSGERR_ATTR_COOKIE,
1407c2aad20Sopenharmony_ci
1417c2aad20Sopenharmony_ci	__NLMSGERR_ATTR_MAX,
1427c2aad20Sopenharmony_ci	NLMSGERR_ATTR_MAX = __NLMSGERR_ATTR_MAX - 1
1437c2aad20Sopenharmony_ci};
1447c2aad20Sopenharmony_ci
1457c2aad20Sopenharmony_ci#define NETLINK_ADD_MEMBERSHIP		1
1467c2aad20Sopenharmony_ci#define NETLINK_DROP_MEMBERSHIP		2
1477c2aad20Sopenharmony_ci#define NETLINK_PKTINFO			3
1487c2aad20Sopenharmony_ci#define NETLINK_BROADCAST_ERROR		4
1497c2aad20Sopenharmony_ci#define NETLINK_NO_ENOBUFS		5
1507c2aad20Sopenharmony_ci#ifndef __KERNEL__
1517c2aad20Sopenharmony_ci#define NETLINK_RX_RING			6
1527c2aad20Sopenharmony_ci#define NETLINK_TX_RING			7
1537c2aad20Sopenharmony_ci#endif
1547c2aad20Sopenharmony_ci#define NETLINK_LISTEN_ALL_NSID		8
1557c2aad20Sopenharmony_ci#define NETLINK_LIST_MEMBERSHIPS	9
1567c2aad20Sopenharmony_ci#define NETLINK_CAP_ACK			10
1577c2aad20Sopenharmony_ci#define NETLINK_EXT_ACK			11
1587c2aad20Sopenharmony_ci#define NETLINK_GET_STRICT_CHK		12
1597c2aad20Sopenharmony_ci
1607c2aad20Sopenharmony_cistruct nl_pktinfo {
1617c2aad20Sopenharmony_ci	__u32	group;
1627c2aad20Sopenharmony_ci};
1637c2aad20Sopenharmony_ci
1647c2aad20Sopenharmony_cistruct nl_mmap_req {
1657c2aad20Sopenharmony_ci	unsigned int	nm_block_size;
1667c2aad20Sopenharmony_ci	unsigned int	nm_block_nr;
1677c2aad20Sopenharmony_ci	unsigned int	nm_frame_size;
1687c2aad20Sopenharmony_ci	unsigned int	nm_frame_nr;
1697c2aad20Sopenharmony_ci};
1707c2aad20Sopenharmony_ci
1717c2aad20Sopenharmony_cistruct nl_mmap_hdr {
1727c2aad20Sopenharmony_ci	unsigned int	nm_status;
1737c2aad20Sopenharmony_ci	unsigned int	nm_len;
1747c2aad20Sopenharmony_ci	__u32		nm_group;
1757c2aad20Sopenharmony_ci	/* credentials */
1767c2aad20Sopenharmony_ci	__u32		nm_pid;
1777c2aad20Sopenharmony_ci	__u32		nm_uid;
1787c2aad20Sopenharmony_ci	__u32		nm_gid;
1797c2aad20Sopenharmony_ci};
1807c2aad20Sopenharmony_ci
1817c2aad20Sopenharmony_ci#ifndef __KERNEL__
1827c2aad20Sopenharmony_cienum nl_mmap_status {
1837c2aad20Sopenharmony_ci	NL_MMAP_STATUS_UNUSED,
1847c2aad20Sopenharmony_ci	NL_MMAP_STATUS_RESERVED,
1857c2aad20Sopenharmony_ci	NL_MMAP_STATUS_VALID,
1867c2aad20Sopenharmony_ci	NL_MMAP_STATUS_COPY,
1877c2aad20Sopenharmony_ci	NL_MMAP_STATUS_SKIP,
1887c2aad20Sopenharmony_ci};
1897c2aad20Sopenharmony_ci
1907c2aad20Sopenharmony_ci#define NL_MMAP_MSG_ALIGNMENT		NLMSG_ALIGNTO
1917c2aad20Sopenharmony_ci#define NL_MMAP_MSG_ALIGN(sz)		__ALIGN_KERNEL(sz, NL_MMAP_MSG_ALIGNMENT)
1927c2aad20Sopenharmony_ci#define NL_MMAP_HDRLEN			NL_MMAP_MSG_ALIGN(sizeof(struct nl_mmap_hdr))
1937c2aad20Sopenharmony_ci#endif
1947c2aad20Sopenharmony_ci
1957c2aad20Sopenharmony_ci#define NET_MAJOR 36		/* Major 36 is reserved for networking 						*/
1967c2aad20Sopenharmony_ci
1977c2aad20Sopenharmony_cienum {
1987c2aad20Sopenharmony_ci	NETLINK_UNCONNECTED = 0,
1997c2aad20Sopenharmony_ci	NETLINK_CONNECTED,
2007c2aad20Sopenharmony_ci};
2017c2aad20Sopenharmony_ci
2027c2aad20Sopenharmony_ci/*
2037c2aad20Sopenharmony_ci *  <------- NLA_HDRLEN ------> <-- NLA_ALIGN(payload)-->
2047c2aad20Sopenharmony_ci * +---------------------+- - -+- - - - - - - - - -+- - -+
2057c2aad20Sopenharmony_ci * |        Header       | Pad |     Payload       | Pad |
2067c2aad20Sopenharmony_ci * |   (struct nlattr)   | ing |                   | ing |
2077c2aad20Sopenharmony_ci * +---------------------+- - -+- - - - - - - - - -+- - -+
2087c2aad20Sopenharmony_ci *  <-------------- nlattr->nla_len -------------->
2097c2aad20Sopenharmony_ci */
2107c2aad20Sopenharmony_ci
2117c2aad20Sopenharmony_cistruct nlattr {
2127c2aad20Sopenharmony_ci	__u16           nla_len;
2137c2aad20Sopenharmony_ci	__u16           nla_type;
2147c2aad20Sopenharmony_ci};
2157c2aad20Sopenharmony_ci
2167c2aad20Sopenharmony_ci/*
2177c2aad20Sopenharmony_ci * nla_type (16 bits)
2187c2aad20Sopenharmony_ci * +---+---+-------------------------------+
2197c2aad20Sopenharmony_ci * | N | O | Attribute Type                |
2207c2aad20Sopenharmony_ci * +---+---+-------------------------------+
2217c2aad20Sopenharmony_ci * N := Carries nested attributes
2227c2aad20Sopenharmony_ci * O := Payload stored in network byte order
2237c2aad20Sopenharmony_ci *
2247c2aad20Sopenharmony_ci * Note: The N and O flag are mutually exclusive.
2257c2aad20Sopenharmony_ci */
2267c2aad20Sopenharmony_ci#define NLA_F_NESTED		(1 << 15)
2277c2aad20Sopenharmony_ci#define NLA_F_NET_BYTEORDER	(1 << 14)
2287c2aad20Sopenharmony_ci#define NLA_TYPE_MASK		~(NLA_F_NESTED | NLA_F_NET_BYTEORDER)
2297c2aad20Sopenharmony_ci
2307c2aad20Sopenharmony_ci#define NLA_ALIGNTO		4
2317c2aad20Sopenharmony_ci#define NLA_ALIGN(len)		(((len) + NLA_ALIGNTO - 1) & ~(NLA_ALIGNTO - 1))
2327c2aad20Sopenharmony_ci#define NLA_HDRLEN		((int) NLA_ALIGN(sizeof(struct nlattr)))
2337c2aad20Sopenharmony_ci
2347c2aad20Sopenharmony_ci/* Generic 32 bitflags attribute content sent to the kernel.
2357c2aad20Sopenharmony_ci *
2367c2aad20Sopenharmony_ci * The value is a bitmap that defines the values being set
2377c2aad20Sopenharmony_ci * The selector is a bitmask that defines which value is legit
2387c2aad20Sopenharmony_ci *
2397c2aad20Sopenharmony_ci * Examples:
2407c2aad20Sopenharmony_ci *  value = 0x0, and selector = 0x1
2417c2aad20Sopenharmony_ci *  implies we are selecting bit 1 and we want to set its value to 0.
2427c2aad20Sopenharmony_ci *
2437c2aad20Sopenharmony_ci *  value = 0x2, and selector = 0x2
2447c2aad20Sopenharmony_ci *  implies we are selecting bit 2 and we want to set its value to 1.
2457c2aad20Sopenharmony_ci *
2467c2aad20Sopenharmony_ci */
2477c2aad20Sopenharmony_cistruct nla_bitfield32 {
2487c2aad20Sopenharmony_ci	__u32 value;
2497c2aad20Sopenharmony_ci	__u32 selector;
2507c2aad20Sopenharmony_ci};
2517c2aad20Sopenharmony_ci
2527c2aad20Sopenharmony_ci#endif /* _UAPI__LINUX_NETLINK_H */
253