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