1/*-
2 * SPDX-License-Identifier: BSD-2-Clause
3 *
4 * Copyright (c) 2022 Alexander V. Chernikov <melifaro@FreeBSD.org>
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 *    notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 *    notice, this list of conditions and the following disclaimer in the
13 *    documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 */
27
28/*
29 * Generic netlink message header and attributes
30 */
31#ifndef _NETLINK_NETLINK_GENERIC_H_
32#define	_NETLINK_NETLINK_GENERIC_H_
33
34#include <netlink/netlink.h>
35
36/* Base header for all of the relevant messages */
37struct genlmsghdr {
38	uint8_t		cmd;		/* CTRL_CMD_ */
39	uint8_t		version;	/* ABI version for the cmd */
40	uint16_t	reserved;	/* reserved: set to 0 */
41};
42#define GENL_HDRLEN	NL_ITEM_ALIGN(sizeof(struct genlmsghdr))
43
44/* Dynamic family number range, inclusive */
45#define	GENL_MIN_ID	NLMSG_MIN_TYPE
46#define	GENL_MAX_ID	1023
47
48/* Pre-defined family numbers */
49#define	GENL_ID_CTRL	GENL_MIN_ID
50
51/* Available commands */
52enum {
53	CTRL_CMD_UNSPEC		= 0,
54	CTRL_CMD_NEWFAMILY	= 1,
55	CTRL_CMD_DELFAMILY	= 2,
56	CTRL_CMD_GETFAMILY	= 3, /* lists all (or matching) genetlink families */
57	CTRL_CMD_NEWOPS		= 4,
58	CTRL_CMD_DELOPS		= 5,
59	CTRL_CMD_GETOPS		= 6,
60	CTRL_CMD_NEWMCAST_GRP	= 7,
61	CTRL_CMD_DELMCAST_GRP	= 8,
62	CTRL_CMD_GETMCAST_GRP	= 9,
63	CTRL_CMD_GETPOLICY	= 10,
64	__CTRL_CMD_MAX,
65};
66#define	CTRL_CMD_MAX	(__CTRL_CMD_MAX - 1)
67
68/* Generic attributes */
69enum {
70	CTRL_ATTR_UNSPEC,
71	CTRL_ATTR_FAMILY_ID	= 1, /* u16, dynamically-assigned ID */
72	CTRL_ATTR_FAMILY_NAME	= 2, /* string, family name */
73	CTRL_ATTR_VERSION	= 3, /* u32, command version */
74	CTRL_ATTR_HDRSIZE	= 4, /* u32, family header size */
75	CTRL_ATTR_MAXATTR	= 5, /* u32, maximum family attr # */
76	CTRL_ATTR_OPS		= 6, /* nested, available operations */
77	CTRL_ATTR_MCAST_GROUPS	= 7,
78	CTRL_ATTR_POLICY	= 8,
79	CTRL_ATTR_OP_POLICY	= 9,
80	CTRL_ATTR_OP		= 10,
81	__CTRL_ATTR_MAX,
82};
83#define	CTRL_ATTR_MAX	(__CTRL_ATTR_MAX - 1)
84
85#define	GENL_NAMSIZ	16 /* max family name length including \0 */
86
87/* CTRL_ATTR_OPS attributes */
88enum {
89	CTRL_ATTR_OP_UNSPEC,
90	CTRL_ATTR_OP_ID		= 1, /* u32, operation # */
91	CTRL_ATTR_OP_FLAGS	= 2, /* u32, flags-based op description */
92	__CTRL_ATTR_OP_MAX,
93};
94#define	CTRL_ATTR_OP_MAX	(__CTRL_ATTR_OP_MAX - 1)
95
96/* CTRL_ATTR_OP_FLAGS values */
97#define GENL_ADMIN_PERM		0x0001 /* Requires elevated permissions */
98#define GENL_CMD_CAP_DO		0x0002 /* Operation is a modification request */
99#define GENL_CMD_CAP_DUMP	0x0004 /* Operation is a get/dump request */
100#define GENL_CMD_CAP_HASPOL	0x0008 /* Operation has a validation policy */
101#define GENL_UNS_ADMIN_PERM	0x0010
102
103/* CTRL_ATTR_MCAST_GROUPS attributes */
104enum {
105	CTRL_ATTR_MCAST_GRP_UNSPEC,
106	CTRL_ATTR_MCAST_GRP_NAME,	/* string, group name */
107	CTRL_ATTR_MCAST_GRP_ID,		/* u32, dynamically-assigned group id */
108	__CTRL_ATTR_MCAST_GRP_MAX,
109};
110#define	CTRL_ATTR_MCAST_GRP_MAX	(__CTRL_ATTR_MCAST_GRP_MAX - 1)
111
112
113#endif
114
115