xref: /illumos-gate/usr/src/uts/common/sys/dls_mgmt.h (revision 85dff7a05711e1238299281f8a94d2d40834c775)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
23  * Copyright 2016 Joyent, Inc.
24  * Copyright 2023 Oxide Computer Company
25  */
26 
27 #ifndef	_DLS_MGMT_H
28 #define	_DLS_MGMT_H
29 
30 #include <sys/types.h>
31 #include <sys/param.h>
32 #include <sys/zone.h>
33 
34 /*
35  * Data-Link Services Module
36  */
37 
38 #ifdef	__cplusplus
39 extern "C" {
40 #endif
41 
42 typedef enum {
43 	DATALINK_CLASS_PHYS		= 0x01,
44 	DATALINK_CLASS_VLAN		= 0x02,
45 	DATALINK_CLASS_AGGR		= 0x04,
46 	DATALINK_CLASS_VNIC		= 0x08,
47 	DATALINK_CLASS_ETHERSTUB	= 0x10,
48 	DATALINK_CLASS_SIMNET		= 0x20,
49 	DATALINK_CLASS_BRIDGE		= 0x40,
50 	DATALINK_CLASS_IPTUN		= 0x80,
51 	DATALINK_CLASS_PART		= 0x100,
52 	DATALINK_CLASS_OVERLAY		= 0x200,
53 	DATALINK_CLASS_MISC		= 0x400
54 } datalink_class_t;
55 
56 #define	DATALINK_CLASS_ALL	(DATALINK_CLASS_PHYS |	\
57 	DATALINK_CLASS_VLAN | DATALINK_CLASS_AGGR | DATALINK_CLASS_VNIC | \
58 	DATALINK_CLASS_ETHERSTUB | DATALINK_CLASS_SIMNET | \
59 	DATALINK_CLASS_BRIDGE | DATALINK_CLASS_IPTUN | DATALINK_CLASS_PART | \
60 	DATALINK_CLASS_OVERLAY | DATALINK_CLASS_MISC)
61 
62 /*
63  * A combination of flags and media.
64  *   flags is the higher 32 bits, and if it is 0x01, it indicates all media
65  *   types can be accepted; otherwise, only the given media type (specified
66  *   in the lower 32 bits) is accepted.
67  */
68 typedef uint64_t	datalink_media_t;
69 
70 #define	DATALINK_ANY_MEDIATYPE		\
71 	((datalink_media_t)(((datalink_media_t)0x01) << 32))
72 
73 #define	DATALINK_MEDIA_ACCEPTED(dmedia, media)				\
74 	(((uint32_t)(((dmedia) >> 32) & 0xfffffffful) & 0x01) ?		\
75 	B_TRUE : ((uint32_t)((dmedia) & 0xfffffffful) == (media)))
76 
77 #define	MAXLINKATTRLEN		32
78 #define	MAXLINKATTRVALLEN	1024
79 
80 /*
81  * Link attributes used by the kernel.
82  */
83 /*
84  * The major number and instance number of the underlying physical device
85  * are kept as FPHYMAJ and FPHYINST (major, instance + 1).
86  *
87  * Set for physical links only.
88  */
89 #define	FPHYMAJ		"phymaj"	/* uint64_t */
90 #define	FPHYINST	"phyinst"	/* uint64_t */
91 
92 /*
93  * The devname of the physical link. For example, bge0, ce1. Set for physical
94  * links only.
95  */
96 #define	FDEVNAME	"devname"	/* string */
97 
98 /*
99  * The door file for the dlmgmtd (data-link management) daemon.
100  */
101 #define	DLMGMT_TMPFS_DIR	"/etc/svc/volatile/dladm"
102 #define	DLMGMT_DOOR		DLMGMT_TMPFS_DIR "/dlmgmt_door"
103 
104 /*
105  * Door upcall commands.
106  */
107 #define	DLMGMT_CMD_DLS_CREATE		1
108 #define	DLMGMT_CMD_DLS_GETATTR		2
109 #define	DLMGMT_CMD_DLS_DESTROY		3
110 #define	DLMGMT_CMD_GETNAME		4
111 #define	DLMGMT_CMD_GETLINKID		5
112 #define	DLMGMT_CMD_GETNEXT		6
113 #define	DLMGMT_CMD_DLS_UPDATE		7
114 #define	DLMGMT_CMD_LINKPROP_INIT	8
115 #define	DLMGMT_CMD_SETZONEID		9
116 #define	DLMGMT_CMD_BASE			128
117 
118 /*
119  * Indicate if the link mapping is active, persistent, or transient. A
120  * transient link is an active link with a twist -- it is an active
121  * link which is destroyed along with the zone rather than reassigned
122  * to the GZ.
123  */
124 #define	DLMGMT_ACTIVE		0x01
125 #define	DLMGMT_PERSIST		0x02
126 #define	DLMGMT_TRANSIENT	0x04
127 
128 /* upcall argument */
129 typedef struct dlmgmt_door_arg {
130 	uint_t			ld_cmd;
131 } dlmgmt_door_arg_t;
132 
133 typedef struct dlmgmt_upcall_arg_create {
134 	int			ld_cmd;
135 	datalink_class_t	ld_class;
136 	uint32_t		ld_media;
137 	boolean_t		ld_persist;
138 	uint64_t		ld_phymaj;
139 	uint64_t		ld_phyinst;
140 	char			ld_devname[MAXNAMELEN];
141 } dlmgmt_upcall_arg_create_t;
142 
143 /*
144  * Note: ld_padding is necessary to keep the size of the structure the
145  * same on amd64 and i386.  The same note applies to other ld_padding
146  * and lr_paddding fields in structures throughout this file.
147  */
148 typedef struct dlmgmt_upcall_arg_destroy {
149 	int			ld_cmd;
150 	datalink_id_t		ld_linkid;
151 	boolean_t		ld_persist;
152 	int			ld_padding;
153 } dlmgmt_upcall_arg_destroy_t;
154 
155 typedef struct dlmgmt_upcall_arg_update {
156 	int			ld_cmd;
157 	boolean_t		ld_novanity;
158 	uint32_t		ld_media;
159 	uint32_t		ld_padding;
160 	char			ld_devname[MAXNAMELEN];
161 } dlmgmt_upcall_arg_update_t;
162 
163 typedef struct dlmgmt_upcall_arg_getattr {
164 	int			ld_cmd;
165 	datalink_id_t		ld_linkid;
166 	char			ld_attr[MAXLINKATTRLEN];
167 } dlmgmt_upcall_arg_getattr_t;
168 
169 typedef struct dlmgmt_door_getname {
170 	int			ld_cmd;
171 	datalink_id_t		ld_linkid;
172 } dlmgmt_door_getname_t;
173 
174 typedef struct dlmgmt_door_getlinkid {
175 	int			ld_cmd;
176 	char			ld_link[MAXLINKNAMELEN];
177 } dlmgmt_door_getlinkid_t;
178 
179 typedef struct dlmgmt_door_getnext_s {
180 	int			ld_cmd;
181 	datalink_id_t		ld_linkid;
182 	datalink_class_t	ld_class;
183 	uint32_t		ld_flags;
184 	datalink_media_t	ld_dmedia;
185 } dlmgmt_door_getnext_t;
186 
187 typedef struct dlmgmt_door_linkprop_init {
188 	int			ld_cmd;
189 	datalink_id_t		ld_linkid;
190 } dlmgmt_door_linkprop_init_t;
191 
192 typedef struct dlmgmt_door_setzoneid {
193 	int			ld_cmd;
194 	datalink_id_t		ld_linkid;
195 	zoneid_t		ld_zoneid;
196 } dlmgmt_door_setzoneid_t;
197 
198 /* upcall return value */
199 typedef struct dlmgmt_retval_s {
200 	uint_t			lr_err; /* return error code */
201 } dlmgmt_retval_t;
202 
203 typedef dlmgmt_retval_t	dlmgmt_destroy_retval_t,
204 			dlmgmt_linkprop_init_retval_t,
205 			dlmgmt_setzoneid_retval_t;
206 
207 struct dlmgmt_linkid_retval_s {
208 	uint_t			lr_err;
209 	datalink_id_t		lr_linkid;
210 	uint32_t		lr_flags;
211 	datalink_class_t	lr_class;
212 	uint32_t		lr_media;
213 	uint32_t		lr_padding;
214 };
215 
216 typedef struct dlmgmt_linkid_retval_s	dlmgmt_create_retval_t,
217 					dlmgmt_update_retval_t,
218 					dlmgmt_getlinkid_retval_t,
219 					dlmgmt_getnext_retval_t;
220 
221 typedef struct dlmgmt_getname_retval_s {
222 	uint_t			lr_err;
223 	char			lr_link[MAXLINKNAMELEN];
224 	datalink_class_t	lr_class;
225 	uint32_t		lr_media;
226 	uint32_t		lr_flags;
227 } dlmgmt_getname_retval_t;
228 
229 typedef struct dlmgmt_getattr_retval_s {
230 	uint_t			lr_err;
231 	uint_t			lr_type;
232 	uint_t			lr_attrsz;
233 	uint_t			lr_padding;
234 	char			lr_attrval[MAXLINKATTRVALLEN];
235 } dlmgmt_getattr_retval_t;
236 
237 
238 #ifdef	__cplusplus
239 }
240 #endif
241 
242 #endif	/* _DLS_MGMT_H */
243