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