2 * SPDX-License-Identifier: BSD-2-Clause
4 * Copyright (c) 2022 Alexander V. Chernikov <melifaro@FreeBSD.org>
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
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.
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
29 * Generic netlink message header and attributes
31 #ifndef _NETLINK_NETLINK_GENERIC_H_
32 #define _NETLINK_NETLINK_GENERIC_H_
34 #include <netlink/netlink.h>
36 /* Base header for all of the relevant messages */
38 uint8_t cmd; /* CTRL_CMD_ */
39 uint8_t version; /* ABI version for the cmd */
40 uint16_t reserved; /* reserved: set to 0 */
42 #define GENL_HDRLEN NL_ITEM_ALIGN(sizeof(struct genlmsghdr))
44 /* Dynamic family number range, inclusive */
45 #define GENL_MIN_ID NLMSG_MIN_TYPE
46 #define GENL_MAX_ID 1023
48 /* Pre-defined family numbers */
49 #define GENL_ID_CTRL GENL_MIN_ID
51 /* Available commands */
54 CTRL_CMD_NEWFAMILY = 1,
55 CTRL_CMD_DELFAMILY = 2,
56 CTRL_CMD_GETFAMILY = 3, /* lists all (or matching) genetlink families */
60 CTRL_CMD_NEWMCAST_GRP = 7,
61 CTRL_CMD_DELMCAST_GRP = 8,
62 CTRL_CMD_GETMCAST_GRP = 9,
63 CTRL_CMD_GETPOLICY = 10,
66 #define CTRL_CMD_MAX (__CTRL_CMD_MAX - 1)
68 /* Generic attributes */
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,
79 CTRL_ATTR_OP_POLICY = 9,
83 #define CTRL_ATTR_MAX (__CTRL_ATTR_MAX - 1)
85 #define GENL_NAMSIZ 16 /* max family name length including \0 */
87 /* CTRL_ATTR_OPS attributes */
90 CTRL_ATTR_OP_ID = 1, /* u32, operation # */
91 CTRL_ATTR_OP_FLAGS = 2, /* u32, flags-based op description */
94 #define CTRL_ATTR_OP_MAX (__CTRL_ATTR_OP_MAX - 1)
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
103 /* CTRL_ATTR_MCAST_GROUPS attributes */
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,
110 #define CTRL_ATTR_MCAST_GRP_MAX (__CTRL_ATTR_MCAST_GRP_MAX - 1)