xref: /titanic_50/usr/src/lib/libdladm/common/libdlmgmt.c (revision 327151705b7439cb7ab35c370f682cac7ef9523a)
1d62bc4baSyz147064 /*
2d62bc4baSyz147064  * CDDL HEADER START
3d62bc4baSyz147064  *
4d62bc4baSyz147064  * The contents of this file are subject to the terms of the
5d62bc4baSyz147064  * Common Development and Distribution License (the "License").
6d62bc4baSyz147064  * You may not use this file except in compliance with the License.
7d62bc4baSyz147064  *
8d62bc4baSyz147064  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9d62bc4baSyz147064  * or http://www.opensolaris.org/os/licensing.
10d62bc4baSyz147064  * See the License for the specific language governing permissions
11d62bc4baSyz147064  * and limitations under the License.
12d62bc4baSyz147064  *
13d62bc4baSyz147064  * When distributing Covered Code, include this CDDL HEADER in each
14d62bc4baSyz147064  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15d62bc4baSyz147064  * If applicable, add the following below this CDDL HEADER, with the
16d62bc4baSyz147064  * fields enclosed by brackets "[]" replaced with your own identifying
17d62bc4baSyz147064  * information: Portions Copyright [yyyy] [name of copyright owner]
18d62bc4baSyz147064  *
19d62bc4baSyz147064  * CDDL HEADER END
20d62bc4baSyz147064  */
21d62bc4baSyz147064 /*
22*32715170SCathy Zhou  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23d62bc4baSyz147064  */
24d62bc4baSyz147064 
25d62bc4baSyz147064 #include <door.h>
26d62bc4baSyz147064 #include <errno.h>
27d62bc4baSyz147064 #include <assert.h>
28d62bc4baSyz147064 #include <stdio.h>
29d62bc4baSyz147064 #include <stdlib.h>
30d62bc4baSyz147064 #include <unistd.h>
31d62bc4baSyz147064 #include <string.h>
32d62bc4baSyz147064 #include <strings.h>
332b24ab6bSSebastien Roy #include <zone.h>
34d62bc4baSyz147064 #include <sys/types.h>
35d62bc4baSyz147064 #include <sys/stat.h>
36d62bc4baSyz147064 #include <sys/aggr.h>
3782a2fc47SJames Carlson #include <sys/mman.h>
38d62bc4baSyz147064 #include <fcntl.h>
39d62bc4baSyz147064 #include <libdladm.h>
40d62bc4baSyz147064 #include <libdladm_impl.h>
41d62bc4baSyz147064 #include <libdllink.h>
42d62bc4baSyz147064 #include <libdlmgmt.h>
43d62bc4baSyz147064 
44d62bc4baSyz147064 /*
45d62bc4baSyz147064  * Table of data type sizes indexed by dladm_datatype_t.
46d62bc4baSyz147064  */
47d62bc4baSyz147064 static size_t dladm_datatype_size[] = {
48d62bc4baSyz147064 	0,				/* DLADM_TYPE_STR, use strnlen() */
49d62bc4baSyz147064 	sizeof (boolean_t),		/* DLADM_TYPE_BOOLEAN */
50d62bc4baSyz147064 	sizeof (uint64_t)		/* DLADM_TYPE_UINT64 */
51d62bc4baSyz147064 };
52d62bc4baSyz147064 
53d62bc4baSyz147064 static dladm_status_t
544ac67f02SAnurag S. Maskey dladm_door_call(dladm_handle_t handle, void *arg, size_t asize, void *rbuf,
55*32715170SCathy Zhou     size_t *rsizep)
56d62bc4baSyz147064 {
57d62bc4baSyz147064 	door_arg_t	darg;
584ac67f02SAnurag S. Maskey 	int		door_fd;
59d62bc4baSyz147064 	dladm_status_t	status = DLADM_STATUS_OK;
60d62bc4baSyz147064 
61d62bc4baSyz147064 	darg.data_ptr	= arg;
62d62bc4baSyz147064 	darg.data_size	= asize;
63d62bc4baSyz147064 	darg.desc_ptr	= NULL;
64d62bc4baSyz147064 	darg.desc_num	= 0;
65d62bc4baSyz147064 	darg.rbuf	= rbuf;
66*32715170SCathy Zhou 	darg.rsize	= *rsizep;
67d62bc4baSyz147064 
684ac67f02SAnurag S. Maskey 	/* The door descriptor is opened if it isn't already */
694ac67f02SAnurag S. Maskey 	if ((status = dladm_door_fd(handle, &door_fd)) != DLADM_STATUS_OK)
704ac67f02SAnurag S. Maskey 		return (status);
714ac67f02SAnurag S. Maskey 	if (door_call(door_fd, &darg) == -1)
72d62bc4baSyz147064 		status = dladm_errno2status(errno);
73d62bc4baSyz147064 	if (status != DLADM_STATUS_OK)
74d62bc4baSyz147064 		return (status);
75d62bc4baSyz147064 
76d62bc4baSyz147064 	if (darg.rbuf != rbuf) {
77d62bc4baSyz147064 		/*
78d62bc4baSyz147064 		 * The size of the input rbuf is not big enough so that
79*32715170SCathy Zhou 		 * the door allocate the rbuf itself. In this case, return
80*32715170SCathy Zhou 		 * the required size to the caller.
81d62bc4baSyz147064 		 */
82d62bc4baSyz147064 		(void) munmap(darg.rbuf, darg.rsize);
83*32715170SCathy Zhou 		*rsizep = darg.rsize;
84d62bc4baSyz147064 		return (DLADM_STATUS_TOOSMALL);
85*32715170SCathy Zhou 	} else if (darg.rsize != *rsizep) {
86d62bc4baSyz147064 		return (DLADM_STATUS_FAILED);
87*32715170SCathy Zhou 	}
88d62bc4baSyz147064 
89024b0a25Sseb 	return (dladm_errno2status(((dlmgmt_retval_t *)rbuf)->lr_err));
90d62bc4baSyz147064 }
91d62bc4baSyz147064 
92d62bc4baSyz147064 /*
93d62bc4baSyz147064  * Allocate a new linkid with the given name. Return the new linkid.
94d62bc4baSyz147064  */
95d62bc4baSyz147064 dladm_status_t
964ac67f02SAnurag S. Maskey dladm_create_datalink_id(dladm_handle_t handle, const char *link,
974ac67f02SAnurag S. Maskey     datalink_class_t class, uint32_t media, uint32_t flags,
984ac67f02SAnurag S. Maskey     datalink_id_t *linkidp)
99d62bc4baSyz147064 {
100d62bc4baSyz147064 	dlmgmt_door_createid_t	createid;
101d62bc4baSyz147064 	dlmgmt_createid_retval_t retval;
102d62bc4baSyz147064 	uint32_t		dlmgmt_flags;
103d62bc4baSyz147064 	dladm_status_t		status;
104*32715170SCathy Zhou 	size_t			sz = sizeof (retval);
105d62bc4baSyz147064 
106024b0a25Sseb 	if (link == NULL || class == DATALINK_CLASS_ALL ||
107d62bc4baSyz147064 	    !(flags & (DLADM_OPT_ACTIVE | DLADM_OPT_PERSIST)) ||
108d62bc4baSyz147064 	    linkidp == NULL) {
109d62bc4baSyz147064 		return (DLADM_STATUS_BADARG);
110d62bc4baSyz147064 	}
111d62bc4baSyz147064 
112d62bc4baSyz147064 	dlmgmt_flags = (flags & DLADM_OPT_ACTIVE) ? DLMGMT_ACTIVE : 0;
113d62bc4baSyz147064 	dlmgmt_flags |= (flags & DLADM_OPT_PERSIST) ? DLMGMT_PERSIST : 0;
114d62bc4baSyz147064 
115d62bc4baSyz147064 	(void) strlcpy(createid.ld_link, link, MAXLINKNAMELEN);
116d62bc4baSyz147064 	createid.ld_class = class;
117d62bc4baSyz147064 	createid.ld_media = media;
118d62bc4baSyz147064 	createid.ld_flags = dlmgmt_flags;
119d62bc4baSyz147064 	createid.ld_cmd = DLMGMT_CMD_CREATE_LINKID;
120d62bc4baSyz147064 	createid.ld_prefix = (flags & DLADM_OPT_PREFIX);
121d62bc4baSyz147064 
1224ac67f02SAnurag S. Maskey 	if ((status = dladm_door_call(handle, &createid, sizeof (createid),
123*32715170SCathy Zhou 	    &retval, &sz)) == DLADM_STATUS_OK) {
124d62bc4baSyz147064 		*linkidp = retval.lr_linkid;
125024b0a25Sseb 	}
126024b0a25Sseb 	return (status);
127d62bc4baSyz147064 }
128d62bc4baSyz147064 
129d62bc4baSyz147064 /*
130d62bc4baSyz147064  * Destroy the given link ID.
131d62bc4baSyz147064  */
132d62bc4baSyz147064 dladm_status_t
1334ac67f02SAnurag S. Maskey dladm_destroy_datalink_id(dladm_handle_t handle, datalink_id_t linkid,
1344ac67f02SAnurag S. Maskey     uint32_t flags)
135d62bc4baSyz147064 {
136d62bc4baSyz147064 	dlmgmt_door_destroyid_t		destroyid;
137d62bc4baSyz147064 	dlmgmt_destroyid_retval_t	retval;
138d62bc4baSyz147064 	uint32_t			dlmgmt_flags;
139*32715170SCathy Zhou 	size_t				sz = sizeof (retval);
140d62bc4baSyz147064 
141d62bc4baSyz147064 	dlmgmt_flags = (flags & DLADM_OPT_ACTIVE) ? DLMGMT_ACTIVE : 0;
142d62bc4baSyz147064 	dlmgmt_flags |= ((flags & DLADM_OPT_PERSIST) ? DLMGMT_PERSIST : 0);
143d62bc4baSyz147064 
144d62bc4baSyz147064 	destroyid.ld_cmd = DLMGMT_CMD_DESTROY_LINKID;
145d62bc4baSyz147064 	destroyid.ld_linkid = linkid;
146d62bc4baSyz147064 	destroyid.ld_flags = dlmgmt_flags;
147d62bc4baSyz147064 
148*32715170SCathy Zhou 	return (dladm_door_call(handle, &destroyid, sizeof (destroyid),
149*32715170SCathy Zhou 	    &retval, &sz));
150d62bc4baSyz147064 }
151d62bc4baSyz147064 
152d62bc4baSyz147064 /*
153d62bc4baSyz147064  * Remap a given link ID to a new name.
154d62bc4baSyz147064  */
155d62bc4baSyz147064 dladm_status_t
1564ac67f02SAnurag S. Maskey dladm_remap_datalink_id(dladm_handle_t handle, datalink_id_t linkid,
1574ac67f02SAnurag S. Maskey     const char *link)
158d62bc4baSyz147064 {
159d62bc4baSyz147064 	dlmgmt_door_remapid_t	remapid;
160d62bc4baSyz147064 	dlmgmt_remapid_retval_t	retval;
161*32715170SCathy Zhou 	size_t			sz = sizeof (retval);
162d62bc4baSyz147064 
163d62bc4baSyz147064 	remapid.ld_cmd = DLMGMT_CMD_REMAP_LINKID;
164d62bc4baSyz147064 	remapid.ld_linkid = linkid;
165d62bc4baSyz147064 	(void) strlcpy(remapid.ld_link, link, MAXLINKNAMELEN);
166d62bc4baSyz147064 
167*32715170SCathy Zhou 	return (dladm_door_call(handle, &remapid, sizeof (remapid),
168*32715170SCathy Zhou 	    &retval, &sz));
169d62bc4baSyz147064 }
170d62bc4baSyz147064 
171d62bc4baSyz147064 /*
172d62bc4baSyz147064  * Make a given link ID active.
173d62bc4baSyz147064  */
174d62bc4baSyz147064 dladm_status_t
1754ac67f02SAnurag S. Maskey dladm_up_datalink_id(dladm_handle_t handle, datalink_id_t linkid)
176d62bc4baSyz147064 {
177d62bc4baSyz147064 	dlmgmt_door_upid_t	upid;
178d62bc4baSyz147064 	dlmgmt_upid_retval_t	retval;
179*32715170SCathy Zhou 	size_t			sz = sizeof (retval);
180d62bc4baSyz147064 
181d62bc4baSyz147064 	upid.ld_cmd = DLMGMT_CMD_UP_LINKID;
182d62bc4baSyz147064 	upid.ld_linkid = linkid;
183d62bc4baSyz147064 
184*32715170SCathy Zhou 	return (dladm_door_call(handle, &upid, sizeof (upid), &retval, &sz));
185d62bc4baSyz147064 }
186d62bc4baSyz147064 
187d62bc4baSyz147064 /*
188d62bc4baSyz147064  * Create a new link with the given name.  Return the new link's handle
189d62bc4baSyz147064  */
190d62bc4baSyz147064 dladm_status_t
1914ac67f02SAnurag S. Maskey dladm_create_conf(dladm_handle_t handle, const char *link, datalink_id_t linkid,
192d62bc4baSyz147064     datalink_class_t class, uint32_t media, dladm_conf_t *confp)
193d62bc4baSyz147064 {
194d62bc4baSyz147064 	dlmgmt_door_createconf_t	createconf;
195d62bc4baSyz147064 	dlmgmt_createconf_retval_t	retval;
196d62bc4baSyz147064 	dladm_status_t			status;
197*32715170SCathy Zhou 	size_t				sz = sizeof (retval);
198d62bc4baSyz147064 
199024b0a25Sseb 	if (link == NULL || confp == NULL)
200d62bc4baSyz147064 		return (DLADM_STATUS_BADARG);
201d62bc4baSyz147064 
202d62bc4baSyz147064 	(void) strlcpy(createconf.ld_link, link, MAXLINKNAMELEN);
203d62bc4baSyz147064 	createconf.ld_class = class;
204d62bc4baSyz147064 	createconf.ld_media = media;
205d62bc4baSyz147064 	createconf.ld_linkid = linkid;
206d62bc4baSyz147064 	createconf.ld_cmd = DLMGMT_CMD_CREATECONF;
207*32715170SCathy Zhou 	confp->ds_confid = DLADM_INVALID_CONF;
208d62bc4baSyz147064 
2094ac67f02SAnurag S. Maskey 	if ((status = dladm_door_call(handle, &createconf, sizeof (createconf),
210*32715170SCathy Zhou 	    &retval, &sz)) == DLADM_STATUS_OK) {
211*32715170SCathy Zhou 		confp->ds_readonly = B_FALSE;
212*32715170SCathy Zhou 		confp->ds_confid = retval.lr_confid;
213024b0a25Sseb 	}
214024b0a25Sseb 	return (status);
215d62bc4baSyz147064 }
216d62bc4baSyz147064 
217d62bc4baSyz147064 /*
218d62bc4baSyz147064  * An active physical link reported by the dlmgmtd daemon might not be active
219d62bc4baSyz147064  * anymore as this link might be removed during system shutdown. Check its
220d62bc4baSyz147064  * real status by calling dladm_phys_info().
221d62bc4baSyz147064  */
222d62bc4baSyz147064 dladm_status_t
2234ac67f02SAnurag S. Maskey i_dladm_phys_status(dladm_handle_t handle, datalink_id_t linkid,
2244ac67f02SAnurag S. Maskey     uint32_t *flagsp)
225d62bc4baSyz147064 {
226d62bc4baSyz147064 	dladm_phys_attr_t	dpa;
227d62bc4baSyz147064 	dladm_status_t		status;
228d62bc4baSyz147064 
229d62bc4baSyz147064 	assert((*flagsp) & DLMGMT_ACTIVE);
230d62bc4baSyz147064 
2314ac67f02SAnurag S. Maskey 	status = dladm_phys_info(handle, linkid, &dpa, DLADM_OPT_ACTIVE);
232d62bc4baSyz147064 	if (status == DLADM_STATUS_NOTFOUND) {
233d62bc4baSyz147064 		/*
234d62bc4baSyz147064 		 * No active status, this link was removed. Update its status
235d62bc4baSyz147064 		 * in the daemon and delete all active linkprops.
2362d4eecfaSCathy Zhou 		 *
2372d4eecfaSCathy Zhou 		 * Note that the operation could fail. If it does, return
2382d4eecfaSCathy Zhou 		 * failure now since otherwise dladm_set_linkprop() might
2392d4eecfaSCathy Zhou 		 * call back to i_dladm_phys_status() recursively.
240d62bc4baSyz147064 		 */
2414ac67f02SAnurag S. Maskey 		if ((status = dladm_destroy_datalink_id(handle, linkid,
2424ac67f02SAnurag S. Maskey 		    DLADM_OPT_ACTIVE)) != DLADM_STATUS_OK)
2432d4eecfaSCathy Zhou 			return (status);
2442d4eecfaSCathy Zhou 
2454ac67f02SAnurag S. Maskey 		(void) dladm_set_linkprop(handle, linkid, NULL, NULL, 0,
246d62bc4baSyz147064 		    DLADM_OPT_ACTIVE);
247d62bc4baSyz147064 
248d62bc4baSyz147064 		(*flagsp) &= ~DLMGMT_ACTIVE;
249d62bc4baSyz147064 		status = DLADM_STATUS_OK;
250d62bc4baSyz147064 	}
251d62bc4baSyz147064 	return (status);
252d62bc4baSyz147064 }
253d62bc4baSyz147064 
254d62bc4baSyz147064 /*
255d62bc4baSyz147064  * Walk each entry in the data link configuration repository and
256d62bc4baSyz147064  * call fn on the linkid and arg.
257d62bc4baSyz147064  */
258d62bc4baSyz147064 dladm_status_t
2594ac67f02SAnurag S. Maskey dladm_walk_datalink_id(int (*fn)(dladm_handle_t, datalink_id_t, void *),
2604ac67f02SAnurag S. Maskey     dladm_handle_t handle, void *argp, datalink_class_t class,
2614ac67f02SAnurag S. Maskey     datalink_media_t dmedia, uint32_t flags)
262d62bc4baSyz147064 {
263d62bc4baSyz147064 	dlmgmt_door_getnext_t	getnext;
264d62bc4baSyz147064 	dlmgmt_getnext_retval_t	retval;
265d62bc4baSyz147064 	uint32_t 		dlmgmt_flags;
266d62bc4baSyz147064 	datalink_id_t		linkid = DATALINK_INVALID_LINKID;
267d62bc4baSyz147064 	dladm_status_t		status = DLADM_STATUS_OK;
268*32715170SCathy Zhou 	size_t			sz = sizeof (retval);
269d62bc4baSyz147064 
270d62bc4baSyz147064 	if (fn == NULL)
271d62bc4baSyz147064 		return (DLADM_STATUS_BADARG);
272d62bc4baSyz147064 
273d62bc4baSyz147064 	dlmgmt_flags = (flags & DLADM_OPT_ACTIVE) ? DLMGMT_ACTIVE : 0;
274d62bc4baSyz147064 	dlmgmt_flags |= ((flags & DLADM_OPT_PERSIST) ? DLMGMT_PERSIST : 0);
275d62bc4baSyz147064 
276d62bc4baSyz147064 	getnext.ld_cmd = DLMGMT_CMD_GETNEXT;
277d62bc4baSyz147064 	getnext.ld_class = class;
278d62bc4baSyz147064 	getnext.ld_dmedia = dmedia;
279d62bc4baSyz147064 	getnext.ld_flags = dlmgmt_flags;
280d62bc4baSyz147064 
281d62bc4baSyz147064 	do {
282d62bc4baSyz147064 		getnext.ld_linkid = linkid;
2834ac67f02SAnurag S. Maskey 		if ((status = dladm_door_call(handle, &getnext,
284*32715170SCathy Zhou 		    sizeof (getnext), &retval, &sz)) != DLADM_STATUS_OK) {
285d62bc4baSyz147064 			/*
2867363c184SCathy Zhou 			 * Done with walking. If no next datalink is found,
2877363c184SCathy Zhou 			 * return success.
288d62bc4baSyz147064 			 */
2897363c184SCathy Zhou 			if (status == DLADM_STATUS_NOTFOUND)
2907363c184SCathy Zhou 				status = DLADM_STATUS_OK;
291d62bc4baSyz147064 			break;
292d62bc4baSyz147064 		}
293d62bc4baSyz147064 
294d62bc4baSyz147064 		linkid = retval.lr_linkid;
295d62bc4baSyz147064 		if ((retval.lr_class == DATALINK_CLASS_PHYS) &&
296d62bc4baSyz147064 		    (retval.lr_flags & DLMGMT_ACTIVE)) {
297d62bc4baSyz147064 			/*
298d62bc4baSyz147064 			 * An active physical link reported by the dlmgmtd
299d62bc4baSyz147064 			 * daemon might not be active anymore. Check its
300d62bc4baSyz147064 			 * real status.
301d62bc4baSyz147064 			 */
3024ac67f02SAnurag S. Maskey 			if (i_dladm_phys_status(handle, linkid,
3034ac67f02SAnurag S. Maskey 			    &retval.lr_flags) != DLADM_STATUS_OK) {
304d62bc4baSyz147064 				continue;
305d62bc4baSyz147064 			}
306d62bc4baSyz147064 
307d62bc4baSyz147064 			if (!(dlmgmt_flags & retval.lr_flags))
308d62bc4baSyz147064 				continue;
309d62bc4baSyz147064 		}
310d62bc4baSyz147064 
3114ac67f02SAnurag S. Maskey 		if (fn(handle, linkid, argp) == DLADM_WALK_TERMINATE)
312d62bc4baSyz147064 			break;
313d62bc4baSyz147064 	} while (linkid != DATALINK_INVALID_LINKID);
314d62bc4baSyz147064 
315d62bc4baSyz147064 	return (status);
316d62bc4baSyz147064 }
317d62bc4baSyz147064 
318d62bc4baSyz147064 /*
319*32715170SCathy Zhou  * Get a handle of a copy of the link configuration (kept in the daemon)
320*32715170SCathy Zhou  * for the given link so it can be updated later by dladm_write_conf().
321d62bc4baSyz147064  */
322d62bc4baSyz147064 dladm_status_t
323*32715170SCathy Zhou dladm_open_conf(dladm_handle_t handle, datalink_id_t linkid,
3244ac67f02SAnurag S. Maskey     dladm_conf_t *confp)
325d62bc4baSyz147064 {
326*32715170SCathy Zhou 	dlmgmt_door_openconf_t		openconf;
327*32715170SCathy Zhou 	dlmgmt_openconf_retval_t	retval;
328d62bc4baSyz147064 	dladm_status_t			status;
329*32715170SCathy Zhou 	size_t				sz;
330d62bc4baSyz147064 
331d62bc4baSyz147064 	if (linkid == DATALINK_INVALID_LINKID || confp == NULL)
332d62bc4baSyz147064 		return (DLADM_STATUS_BADARG);
333d62bc4baSyz147064 
334*32715170SCathy Zhou 	sz = sizeof (retval);
335*32715170SCathy Zhou 	openconf.ld_linkid = linkid;
336*32715170SCathy Zhou 	openconf.ld_cmd = DLMGMT_CMD_OPENCONF;
337*32715170SCathy Zhou 	confp->ds_confid = DLADM_INVALID_CONF;
338*32715170SCathy Zhou 	if ((status = dladm_door_call(handle, &openconf,
339*32715170SCathy Zhou 	    sizeof (openconf), &retval, &sz)) == DLADM_STATUS_OK) {
340*32715170SCathy Zhou 		confp->ds_readonly = B_FALSE;
341*32715170SCathy Zhou 		confp->ds_confid = retval.lr_confid;
342024b0a25Sseb 	}
343*32715170SCathy Zhou 
344*32715170SCathy Zhou 	return (status);
345*32715170SCathy Zhou }
346*32715170SCathy Zhou 
347*32715170SCathy Zhou /*
348*32715170SCathy Zhou  * Get the handle of a local snapshot of the link configuration. Note that
349*32715170SCathy Zhou  * any operations with this handle are read-only, i.e., one can not update
350*32715170SCathy Zhou  * the configuration with this handle.
351*32715170SCathy Zhou  */
352*32715170SCathy Zhou dladm_status_t
353*32715170SCathy Zhou dladm_getsnap_conf(dladm_handle_t handle, datalink_id_t linkid,
354*32715170SCathy Zhou     dladm_conf_t *confp)
355*32715170SCathy Zhou {
356*32715170SCathy Zhou 	dlmgmt_door_getconfsnapshot_t	snapshot;
357*32715170SCathy Zhou 	dlmgmt_getconfsnapshot_retval_t	*retvalp;
358*32715170SCathy Zhou 	char				*nvlbuf;
359*32715170SCathy Zhou 	dladm_status_t			status;
360*32715170SCathy Zhou 	int				err;
361*32715170SCathy Zhou 	size_t				sz;
362*32715170SCathy Zhou 
363*32715170SCathy Zhou 	if (linkid == DATALINK_INVALID_LINKID || confp == NULL)
364*32715170SCathy Zhou 		return (DLADM_STATUS_BADARG);
365*32715170SCathy Zhou 
366*32715170SCathy Zhou 	sz = sizeof (dlmgmt_getconfsnapshot_retval_t);
367*32715170SCathy Zhou 	snapshot.ld_linkid = linkid;
368*32715170SCathy Zhou 	snapshot.ld_cmd = DLMGMT_CMD_GETCONFSNAPSHOT;
369*32715170SCathy Zhou again:
370*32715170SCathy Zhou 	if ((retvalp = malloc(sz)) == NULL)
371*32715170SCathy Zhou 		return (DLADM_STATUS_NOMEM);
372*32715170SCathy Zhou 
373*32715170SCathy Zhou 	if ((status = dladm_door_call(handle, &snapshot, sizeof (snapshot),
374*32715170SCathy Zhou 	    retvalp, &sz)) == DLADM_STATUS_TOOSMALL) {
375*32715170SCathy Zhou 		free(retvalp);
376*32715170SCathy Zhou 		goto again;
377*32715170SCathy Zhou 	}
378*32715170SCathy Zhou 
379*32715170SCathy Zhou 	if (status != DLADM_STATUS_OK) {
380*32715170SCathy Zhou 		free(retvalp);
381*32715170SCathy Zhou 		return (status);
382*32715170SCathy Zhou 	}
383*32715170SCathy Zhou 
384*32715170SCathy Zhou 	confp->ds_readonly = B_TRUE;
385*32715170SCathy Zhou 	nvlbuf = (char *)retvalp + sizeof (dlmgmt_getconfsnapshot_retval_t);
386*32715170SCathy Zhou 	if ((err = nvlist_unpack(nvlbuf, retvalp->lr_nvlsz,
387*32715170SCathy Zhou 	    &(confp->ds_nvl), NV_ENCODE_NATIVE)) != 0) {
388*32715170SCathy Zhou 		status = dladm_errno2status(err);
389*32715170SCathy Zhou 	}
390*32715170SCathy Zhou 	free(retvalp);
391024b0a25Sseb 	return (status);
392d62bc4baSyz147064 }
393d62bc4baSyz147064 
394d62bc4baSyz147064 /*
395d62bc4baSyz147064  * Commit the given link to the data link configuration repository so
396d62bc4baSyz147064  * that it will persist across reboots.
397d62bc4baSyz147064  */
398d62bc4baSyz147064 dladm_status_t
3994ac67f02SAnurag S. Maskey dladm_write_conf(dladm_handle_t handle, dladm_conf_t conf)
400d62bc4baSyz147064 {
401d62bc4baSyz147064 	dlmgmt_door_writeconf_t		writeconf;
402d62bc4baSyz147064 	dlmgmt_writeconf_retval_t	retval;
403*32715170SCathy Zhou 	size_t				sz = sizeof (retval);
404d62bc4baSyz147064 
405*32715170SCathy Zhou 	if (conf.ds_confid == DLADM_INVALID_CONF)
406d62bc4baSyz147064 		return (DLADM_STATUS_BADARG);
407d62bc4baSyz147064 
408*32715170SCathy Zhou 	if (conf.ds_readonly)
409*32715170SCathy Zhou 		return (DLADM_STATUS_DENIED);
410d62bc4baSyz147064 
411*32715170SCathy Zhou 	writeconf.ld_cmd = DLMGMT_CMD_WRITECONF;
412*32715170SCathy Zhou 	writeconf.ld_confid = conf.ds_confid;
413*32715170SCathy Zhou 
414*32715170SCathy Zhou 	return (dladm_door_call(handle, &writeconf, sizeof (writeconf),
415*32715170SCathy Zhou 	    &retval, &sz));
416d62bc4baSyz147064 }
417d62bc4baSyz147064 
418d62bc4baSyz147064 /*
419*32715170SCathy Zhou  * Given a dladm_conf_t, get the specific configuration field
420*32715170SCathy Zhou  *
421*32715170SCathy Zhou  * If the specified dladm_conf_t is a read-only snapshot of the configuration,
422*32715170SCathy Zhou  * get a specific link propertie from that snapshot (nvl), otherwise, get
423*32715170SCathy Zhou  * the link protperty from the dlmgmtd daemon using the given confid.
424d62bc4baSyz147064  */
425d62bc4baSyz147064 dladm_status_t
4264ac67f02SAnurag S. Maskey dladm_get_conf_field(dladm_handle_t handle, dladm_conf_t conf, const char *attr,
4274ac67f02SAnurag S. Maskey     void *attrval, size_t attrsz)
428d62bc4baSyz147064 {
429*32715170SCathy Zhou 	dladm_status_t		status = DLADM_STATUS_OK;
430*32715170SCathy Zhou 
431*32715170SCathy Zhou 	if (attrval == NULL || attrsz == 0 || attr == NULL)
432*32715170SCathy Zhou 		return (DLADM_STATUS_BADARG);
433*32715170SCathy Zhou 
434*32715170SCathy Zhou 	if (conf.ds_readonly) {
435*32715170SCathy Zhou 		uchar_t		*oattrval;
436*32715170SCathy Zhou 		uint32_t	oattrsz;
437*32715170SCathy Zhou 		int		err;
438*32715170SCathy Zhou 
439*32715170SCathy Zhou 		if ((err = nvlist_lookup_byte_array(conf.ds_nvl, (char *)attr,
440*32715170SCathy Zhou 		    &oattrval, &oattrsz)) != 0) {
441*32715170SCathy Zhou 			return (dladm_errno2status(err));
442*32715170SCathy Zhou 		}
443*32715170SCathy Zhou 		if (oattrsz > attrsz)
444*32715170SCathy Zhou 			return (DLADM_STATUS_TOOSMALL);
445*32715170SCathy Zhou 
446*32715170SCathy Zhou 		bcopy(oattrval, attrval, oattrsz);
447*32715170SCathy Zhou 	} else {
448d62bc4baSyz147064 		dlmgmt_door_getattr_t	getattr;
449024b0a25Sseb 		dlmgmt_getattr_retval_t	retval;
450*32715170SCathy Zhou 		size_t			sz = sizeof (retval);
451d62bc4baSyz147064 
452*32715170SCathy Zhou 		if (conf.ds_confid == DLADM_INVALID_CONF)
453d62bc4baSyz147064 			return (DLADM_STATUS_BADARG);
454d62bc4baSyz147064 
455d62bc4baSyz147064 		getattr.ld_cmd = DLMGMT_CMD_GETATTR;
456*32715170SCathy Zhou 		getattr.ld_confid = conf.ds_confid;
457d62bc4baSyz147064 		(void) strlcpy(getattr.ld_attr, attr, MAXLINKATTRLEN);
458d62bc4baSyz147064 
459*32715170SCathy Zhou 		if ((status = dladm_door_call(handle, &getattr,
460*32715170SCathy Zhou 		    sizeof (getattr), &retval, &sz)) != DLADM_STATUS_OK) {
461d62bc4baSyz147064 			return (status);
462d62bc4baSyz147064 		}
463d62bc4baSyz147064 
464024b0a25Sseb 		if (retval.lr_attrsz > attrsz)
465024b0a25Sseb 			return (DLADM_STATUS_TOOSMALL);
466024b0a25Sseb 
467024b0a25Sseb 		bcopy(retval.lr_attrval, attrval, retval.lr_attrsz);
468*32715170SCathy Zhou 	}
469*32715170SCathy Zhou 	return (status);
470024b0a25Sseb }
471024b0a25Sseb 
472d62bc4baSyz147064 /*
47362ee1d25SArtem Kachitchkine  * Get next property attribute from data link configuration repository.
474*32715170SCathy Zhou  * If last_attr is "", return the first property.
47562ee1d25SArtem Kachitchkine  */
476*32715170SCathy Zhou /* ARGSUSED */
47762ee1d25SArtem Kachitchkine dladm_status_t
47862ee1d25SArtem Kachitchkine dladm_getnext_conf_linkprop(dladm_handle_t handle, dladm_conf_t conf,
47962ee1d25SArtem Kachitchkine     const char *last_attr, char *attr, void *attrval, size_t attrsz,
48062ee1d25SArtem Kachitchkine     size_t *attrszp)
48162ee1d25SArtem Kachitchkine {
482*32715170SCathy Zhou 	nvlist_t	*nvl = conf.ds_nvl;
483*32715170SCathy Zhou 	nvpair_t	*last = NULL, *nvp;
484*32715170SCathy Zhou 	uchar_t		*oattrval;
485*32715170SCathy Zhou 	uint32_t	oattrsz;
486*32715170SCathy Zhou 	int		err;
48762ee1d25SArtem Kachitchkine 
488*32715170SCathy Zhou 	if (nvl == NULL || attrval == NULL || attrsz == 0 || attr == NULL ||
489*32715170SCathy Zhou 	    !conf.ds_readonly)
49062ee1d25SArtem Kachitchkine 		return (DLADM_STATUS_BADARG);
491*32715170SCathy Zhou 
492*32715170SCathy Zhou 	while ((nvp = nvlist_next_nvpair(nvl, last)) != NULL) {
493*32715170SCathy Zhou 		if (last_attr[0] == '\0')
494*32715170SCathy Zhou 			break;
495*32715170SCathy Zhou 		if (last != NULL && strcmp(last_attr, nvpair_name(last)) == 0)
496*32715170SCathy Zhou 			break;
497*32715170SCathy Zhou 		last = nvp;
49862ee1d25SArtem Kachitchkine 	}
49962ee1d25SArtem Kachitchkine 
500*32715170SCathy Zhou 	if (nvp == NULL)
501*32715170SCathy Zhou 		return (DLADM_STATUS_NOTFOUND);
50262ee1d25SArtem Kachitchkine 
503*32715170SCathy Zhou 	if ((err = nvpair_value_byte_array(nvp, (uchar_t **)&oattrval,
504*32715170SCathy Zhou 	    &oattrsz)) != NULL) {
505*32715170SCathy Zhou 		return (dladm_errno2status(err));
50662ee1d25SArtem Kachitchkine 	}
50762ee1d25SArtem Kachitchkine 
508*32715170SCathy Zhou 	*attrszp = oattrsz;
509*32715170SCathy Zhou 	if (oattrsz > attrsz)
51062ee1d25SArtem Kachitchkine 		return (DLADM_STATUS_TOOSMALL);
51162ee1d25SArtem Kachitchkine 
512*32715170SCathy Zhou 	(void) strlcpy(attr, nvpair_name(nvp), MAXLINKATTRLEN);
513*32715170SCathy Zhou 	bcopy(oattrval, attrval, oattrsz);
51462ee1d25SArtem Kachitchkine 	return (DLADM_STATUS_OK);
51562ee1d25SArtem Kachitchkine }
51662ee1d25SArtem Kachitchkine 
51762ee1d25SArtem Kachitchkine /*
518d62bc4baSyz147064  * Get the link ID that is associated with the given name.
519d62bc4baSyz147064  */
520d62bc4baSyz147064 dladm_status_t
5214ac67f02SAnurag S. Maskey dladm_name2info(dladm_handle_t handle, const char *link, datalink_id_t *linkidp,
5224ac67f02SAnurag S. Maskey     uint32_t *flagp, datalink_class_t *classp, uint32_t *mediap)
523d62bc4baSyz147064 {
524d62bc4baSyz147064 	dlmgmt_door_getlinkid_t		getlinkid;
525d62bc4baSyz147064 	dlmgmt_getlinkid_retval_t	retval;
526d62bc4baSyz147064 	datalink_id_t			linkid;
527d62bc4baSyz147064 	dladm_status_t			status;
528*32715170SCathy Zhou 	size_t				sz = sizeof (retval);
529d62bc4baSyz147064 
530d62bc4baSyz147064 	getlinkid.ld_cmd = DLMGMT_CMD_GETLINKID;
531d62bc4baSyz147064 	(void) strlcpy(getlinkid.ld_link, link, MAXLINKNAMELEN);
532d62bc4baSyz147064 
5334ac67f02SAnurag S. Maskey 	if ((status = dladm_door_call(handle, &getlinkid, sizeof (getlinkid),
534*32715170SCathy Zhou 	    &retval, &sz)) != DLADM_STATUS_OK) {
535d62bc4baSyz147064 		return (status);
536024b0a25Sseb 	}
537d62bc4baSyz147064 
538d62bc4baSyz147064 	linkid = retval.lr_linkid;
539d62bc4baSyz147064 	if (retval.lr_class == DATALINK_CLASS_PHYS &&
540d62bc4baSyz147064 	    retval.lr_flags & DLMGMT_ACTIVE) {
541d62bc4baSyz147064 		/*
542d62bc4baSyz147064 		 * An active physical link reported by the dlmgmtd daemon
543d62bc4baSyz147064 		 * might not be active anymore. Check and set its real status.
544d62bc4baSyz147064 		 */
5454ac67f02SAnurag S. Maskey 		status = i_dladm_phys_status(handle, linkid, &retval.lr_flags);
546d62bc4baSyz147064 		if (status != DLADM_STATUS_OK)
547d62bc4baSyz147064 			return (status);
548d62bc4baSyz147064 	}
549d62bc4baSyz147064 
550d62bc4baSyz147064 	if (linkidp != NULL)
551d62bc4baSyz147064 		*linkidp = linkid;
552d62bc4baSyz147064 	if (flagp != NULL) {
553d62bc4baSyz147064 		*flagp = retval.lr_flags & DLMGMT_ACTIVE ? DLADM_OPT_ACTIVE : 0;
554d62bc4baSyz147064 		*flagp |= (retval.lr_flags & DLMGMT_PERSIST) ?
555d62bc4baSyz147064 		    DLADM_OPT_PERSIST : 0;
556d62bc4baSyz147064 	}
557d62bc4baSyz147064 	if (classp != NULL)
558d62bc4baSyz147064 		*classp = retval.lr_class;
559d62bc4baSyz147064 	if (mediap != NULL)
560d62bc4baSyz147064 		*mediap = retval.lr_media;
561d62bc4baSyz147064 
562d62bc4baSyz147064 	return (DLADM_STATUS_OK);
563d62bc4baSyz147064 }
564d62bc4baSyz147064 
565d62bc4baSyz147064 /*
566d62bc4baSyz147064  * Get the link name that is associated with the given id.
567d62bc4baSyz147064  */
568d62bc4baSyz147064 dladm_status_t
5694ac67f02SAnurag S. Maskey dladm_datalink_id2info(dladm_handle_t handle, datalink_id_t linkid,
5704ac67f02SAnurag S. Maskey     uint32_t *flagp, datalink_class_t *classp, uint32_t *mediap, char *link,
5714ac67f02SAnurag S. Maskey     size_t len)
572d62bc4baSyz147064 {
573d62bc4baSyz147064 	dlmgmt_door_getname_t	getname;
574d62bc4baSyz147064 	dlmgmt_getname_retval_t	retval;
575d62bc4baSyz147064 	dladm_status_t		status;
576*32715170SCathy Zhou 	size_t			sz = sizeof (retval);
577d62bc4baSyz147064 
578d62bc4baSyz147064 	if ((linkid == DATALINK_INVALID_LINKID) || (link != NULL && len == 0) ||
579d62bc4baSyz147064 	    (link == NULL && len != 0)) {
580d62bc4baSyz147064 		return (DLADM_STATUS_BADARG);
581d62bc4baSyz147064 	}
582d62bc4baSyz147064 
583d62bc4baSyz147064 	getname.ld_cmd = DLMGMT_CMD_GETNAME;
584d62bc4baSyz147064 	getname.ld_linkid = linkid;
5854ac67f02SAnurag S. Maskey 	if ((status = dladm_door_call(handle, &getname, sizeof (getname),
586*32715170SCathy Zhou 	    &retval, &sz)) != DLADM_STATUS_OK) {
587d62bc4baSyz147064 		return (status);
588d62bc4baSyz147064 	}
589d62bc4baSyz147064 
590024b0a25Sseb 	if (len != 0 && (strlen(retval.lr_link) + 1 > len))
591024b0a25Sseb 		return (DLADM_STATUS_TOOSMALL);
592024b0a25Sseb 
593d62bc4baSyz147064 	if (retval.lr_class == DATALINK_CLASS_PHYS &&
594d62bc4baSyz147064 	    retval.lr_flags & DLMGMT_ACTIVE) {
595d62bc4baSyz147064 		/*
596d62bc4baSyz147064 		 * An active physical link reported by the dlmgmtd daemon
597d62bc4baSyz147064 		 * might not be active anymore. Check and set its real status.
598d62bc4baSyz147064 		 */
5994ac67f02SAnurag S. Maskey 		status = i_dladm_phys_status(handle, linkid, &retval.lr_flags);
600d62bc4baSyz147064 		if (status != DLADM_STATUS_OK)
601d62bc4baSyz147064 			return (status);
602d62bc4baSyz147064 	}
603d62bc4baSyz147064 
604d62bc4baSyz147064 	if (link != NULL)
605d62bc4baSyz147064 		(void) strlcpy(link, retval.lr_link, len);
606d62bc4baSyz147064 	if (classp != NULL)
607d62bc4baSyz147064 		*classp = retval.lr_class;
608d62bc4baSyz147064 	if (mediap != NULL)
609d62bc4baSyz147064 		*mediap = retval.lr_media;
610d62bc4baSyz147064 	if (flagp != NULL) {
611d62bc4baSyz147064 		*flagp = retval.lr_flags & DLMGMT_ACTIVE ?
612d62bc4baSyz147064 		    DLADM_OPT_ACTIVE : 0;
613d62bc4baSyz147064 		*flagp |= (retval.lr_flags & DLMGMT_PERSIST) ?
614d62bc4baSyz147064 		    DLADM_OPT_PERSIST : 0;
615d62bc4baSyz147064 	}
616d62bc4baSyz147064 	return (DLADM_STATUS_OK);
617d62bc4baSyz147064 }
618d62bc4baSyz147064 
619d62bc4baSyz147064 /*
620d62bc4baSyz147064  * Set the given attr with the given attrval for the given link.
621d62bc4baSyz147064  */
622d62bc4baSyz147064 dladm_status_t
6234ac67f02SAnurag S. Maskey dladm_set_conf_field(dladm_handle_t handle, dladm_conf_t conf, const char *attr,
624d62bc4baSyz147064     dladm_datatype_t type, const void *attrval)
625d62bc4baSyz147064 {
626024b0a25Sseb 	dlmgmt_door_setattr_t	setattr;
627d62bc4baSyz147064 	dlmgmt_setattr_retval_t	retval;
628024b0a25Sseb 	size_t			attrsz;
629*32715170SCathy Zhou 	size_t			sz = sizeof (retval);
630d62bc4baSyz147064 
631024b0a25Sseb 	if (attr == NULL || attrval == NULL)
632d62bc4baSyz147064 		return (DLADM_STATUS_BADARG);
633d62bc4baSyz147064 
634*32715170SCathy Zhou 	if (conf.ds_readonly)
635*32715170SCathy Zhou 		return (DLADM_STATUS_DENIED);
636*32715170SCathy Zhou 
637d62bc4baSyz147064 	if (type == DLADM_TYPE_STR)
638d62bc4baSyz147064 		attrsz = strlen(attrval) + 1;
639d62bc4baSyz147064 	else
640d62bc4baSyz147064 		attrsz = dladm_datatype_size[type];
641d62bc4baSyz147064 
642024b0a25Sseb 	if (attrsz > MAXLINKATTRVALLEN)
643024b0a25Sseb 		return (DLADM_STATUS_TOOSMALL);
644d62bc4baSyz147064 
645024b0a25Sseb 	setattr.ld_cmd = DLMGMT_CMD_SETATTR;
646*32715170SCathy Zhou 	setattr.ld_confid = conf.ds_confid;
647024b0a25Sseb 	(void) strlcpy(setattr.ld_attr, attr, MAXLINKATTRLEN);
648024b0a25Sseb 	setattr.ld_attrsz = attrsz;
649024b0a25Sseb 	setattr.ld_type = type;
650024b0a25Sseb 	bcopy(attrval, &setattr.ld_attrval, attrsz);
651d62bc4baSyz147064 
652*32715170SCathy Zhou 	return (dladm_door_call(handle, &setattr, sizeof (setattr),
653*32715170SCathy Zhou 	    &retval, &sz));
654d62bc4baSyz147064 }
655d62bc4baSyz147064 
656d62bc4baSyz147064 /*
657d62bc4baSyz147064  * Unset the given attr the given link.
658d62bc4baSyz147064  */
659d62bc4baSyz147064 dladm_status_t
6604ac67f02SAnurag S. Maskey dladm_unset_conf_field(dladm_handle_t handle, dladm_conf_t conf,
6614ac67f02SAnurag S. Maskey     const char *attr)
662d62bc4baSyz147064 {
663d62bc4baSyz147064 	dlmgmt_door_unsetattr_t		unsetattr;
664d62bc4baSyz147064 	dlmgmt_unsetattr_retval_t	retval;
665*32715170SCathy Zhou 	size_t				sz = sizeof (retval);
666d62bc4baSyz147064 
667024b0a25Sseb 	if (attr == NULL)
668d62bc4baSyz147064 		return (DLADM_STATUS_BADARG);
669d62bc4baSyz147064 
670*32715170SCathy Zhou 	if (conf.ds_readonly)
671*32715170SCathy Zhou 		return (DLADM_STATUS_DENIED);
672*32715170SCathy Zhou 
673d62bc4baSyz147064 	unsetattr.ld_cmd = DLMGMT_CMD_UNSETATTR;
674*32715170SCathy Zhou 	unsetattr.ld_confid = conf.ds_confid;
675d62bc4baSyz147064 	(void) strlcpy(unsetattr.ld_attr, attr, MAXLINKATTRLEN);
676d62bc4baSyz147064 
677*32715170SCathy Zhou 	return (dladm_door_call(handle, &unsetattr, sizeof (unsetattr),
678*32715170SCathy Zhou 	    &retval, &sz));
679d62bc4baSyz147064 }
680d62bc4baSyz147064 
681d62bc4baSyz147064 /*
682d62bc4baSyz147064  * Remove the given link ID and its entry from the data link configuration
683d62bc4baSyz147064  * repository.
684d62bc4baSyz147064  */
685d62bc4baSyz147064 dladm_status_t
6864ac67f02SAnurag S. Maskey dladm_remove_conf(dladm_handle_t handle, datalink_id_t linkid)
687d62bc4baSyz147064 {
688d62bc4baSyz147064 	dlmgmt_door_removeconf_t	removeconf;
689d62bc4baSyz147064 	dlmgmt_removeconf_retval_t	retval;
690*32715170SCathy Zhou 	size_t				sz = sizeof (retval);
691d62bc4baSyz147064 
692d62bc4baSyz147064 	removeconf.ld_cmd = DLMGMT_CMD_REMOVECONF;
693d62bc4baSyz147064 	removeconf.ld_linkid = linkid;
694d62bc4baSyz147064 
6954ac67f02SAnurag S. Maskey 	return (dladm_door_call(handle, &removeconf, sizeof (removeconf),
696*32715170SCathy Zhou 	    &retval, &sz));
697d62bc4baSyz147064 }
698d62bc4baSyz147064 
699d62bc4baSyz147064 /*
700d62bc4baSyz147064  * Free the contents of the link structure.
701d62bc4baSyz147064  */
702d62bc4baSyz147064 void
7034ac67f02SAnurag S. Maskey dladm_destroy_conf(dladm_handle_t handle, dladm_conf_t conf)
704d62bc4baSyz147064 {
705*32715170SCathy Zhou 	dlmgmt_door_destroyconf_t	dconf;
706d62bc4baSyz147064 	dlmgmt_destroyconf_retval_t	retval;
707*32715170SCathy Zhou 	size_t				sz = sizeof (retval);
708d62bc4baSyz147064 
709*32715170SCathy Zhou 	if (conf.ds_readonly) {
710*32715170SCathy Zhou 		nvlist_free(conf.ds_nvl);
711*32715170SCathy Zhou 	} else {
712*32715170SCathy Zhou 		if (conf.ds_confid == DLADM_INVALID_CONF)
713d62bc4baSyz147064 			return;
714d62bc4baSyz147064 
715*32715170SCathy Zhou 		dconf.ld_cmd = DLMGMT_CMD_DESTROYCONF;
716*32715170SCathy Zhou 		dconf.ld_confid = conf.ds_confid;
717d62bc4baSyz147064 
718*32715170SCathy Zhou 		(void) dladm_door_call(handle, &dconf, sizeof (dconf),
719*32715170SCathy Zhou 		    &retval, &sz);
720*32715170SCathy Zhou 	}
721d62bc4baSyz147064 }
7222b24ab6bSSebastien Roy 
7232b24ab6bSSebastien Roy dladm_status_t
7242b24ab6bSSebastien Roy dladm_zone_boot(dladm_handle_t handle, zoneid_t zoneid)
7252b24ab6bSSebastien Roy {
7262b24ab6bSSebastien Roy 	dlmgmt_door_zoneboot_t		zoneboot;
7272b24ab6bSSebastien Roy 	dlmgmt_zoneboot_retval_t	retval;
728*32715170SCathy Zhou 	size_t				sz = sizeof (retval);
7292b24ab6bSSebastien Roy 
7302b24ab6bSSebastien Roy 	zoneboot.ld_cmd = DLMGMT_CMD_ZONEBOOT;
7312b24ab6bSSebastien Roy 	zoneboot.ld_zoneid = zoneid;
732*32715170SCathy Zhou 	return (dladm_door_call(handle, &zoneboot, sizeof (zoneboot),
733*32715170SCathy Zhou 	    &retval, &sz));
7342b24ab6bSSebastien Roy }
7352b24ab6bSSebastien Roy 
7362b24ab6bSSebastien Roy dladm_status_t
7372b24ab6bSSebastien Roy dladm_zone_halt(dladm_handle_t handle, zoneid_t zoneid)
7382b24ab6bSSebastien Roy {
7392b24ab6bSSebastien Roy 	dlmgmt_door_zonehalt_t		zonehalt;
7402b24ab6bSSebastien Roy 	dlmgmt_zonehalt_retval_t	retval;
741*32715170SCathy Zhou 	size_t				sz = sizeof (retval);
7422b24ab6bSSebastien Roy 
7432b24ab6bSSebastien Roy 	zonehalt.ld_cmd = DLMGMT_CMD_ZONEHALT;
7442b24ab6bSSebastien Roy 	zonehalt.ld_zoneid = zoneid;
745*32715170SCathy Zhou 	return (dladm_door_call(handle, &zonehalt, sizeof (zonehalt),
746*32715170SCathy Zhou 	    &retval, &sz));
7472b24ab6bSSebastien Roy }
748