libdlmgmt.c revision 024b0a258461f282a92b1b1283c3b8b083f9f33f
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * CDDL HEADER START
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * The contents of this file are subject to the terms of the
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * Common Development and Distribution License (the "License").
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * You may not use this file except in compliance with the License.
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * See the License for the specific language governing permissions
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * and limitations under the License.
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * When distributing Covered Code, include this CDDL HEADER in each
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * If applicable, add the following below this CDDL HEADER, with the
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * fields enclosed by brackets "[]" replaced with your own identifying
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * information: Portions Copyright [yyyy] [name of copyright owner]
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * CDDL HEADER END
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * Use is subject to license terms.
d62bc4badc1c1f1549c961cfb8b420e650e1272byz#pragma ident "%Z%%M% %I% %E% SMI"
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * Table of data type sizes indexed by dladm_datatype_t.
d62bc4badc1c1f1549c961cfb8b420e650e1272byz 0, /* DLADM_TYPE_STR, use strnlen() */
024b0a258461f282a92b1b1283c3b8b083f9f33fsebdladm_door_call(void *arg, size_t asize, void *rbuf, size_t rsize)
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * The size of the input rbuf is not big enough so that
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * the door allocate the rbuf itself. In this case, simply
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * think something wrong with the door call.
024b0a258461f282a92b1b1283c3b8b083f9f33fseb return (dladm_errno2status(((dlmgmt_retval_t *)rbuf)->lr_err));
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * Allocate a new linkid with the given name. Return the new linkid.
d62bc4badc1c1f1549c961cfb8b420e650e1272byzdladm_create_datalink_id(const char *link, datalink_class_t class,
d62bc4badc1c1f1549c961cfb8b420e650e1272byz dlmgmt_flags = (flags & DLADM_OPT_ACTIVE) ? DLMGMT_ACTIVE : 0;
d62bc4badc1c1f1549c961cfb8b420e650e1272byz dlmgmt_flags |= (flags & DLADM_OPT_PERSIST) ? DLMGMT_PERSIST : 0;
024b0a258461f282a92b1b1283c3b8b083f9f33fseb if ((status = dladm_door_call(&createid, sizeof (createid), &retval,
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * Destroy the given link ID.
d62bc4badc1c1f1549c961cfb8b420e650e1272byzdladm_destroy_datalink_id(datalink_id_t linkid, uint32_t flags)
d62bc4badc1c1f1549c961cfb8b420e650e1272byz dlmgmt_flags = (flags & DLADM_OPT_ACTIVE) ? DLMGMT_ACTIVE : 0;
d62bc4badc1c1f1549c961cfb8b420e650e1272byz dlmgmt_flags |= ((flags & DLADM_OPT_PERSIST) ? DLMGMT_PERSIST : 0);
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * Remap a given link ID to a new name.
d62bc4badc1c1f1549c961cfb8b420e650e1272byzdladm_remap_datalink_id(datalink_id_t linkid, const char *link)
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * Make a given link ID active.
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * Create a new link with the given name. Return the new link's handle
d62bc4badc1c1f1549c961cfb8b420e650e1272byz datalink_class_t class, uint32_t media, dladm_conf_t *confp)
d62bc4badc1c1f1549c961cfb8b420e650e1272byz (void) strlcpy(createconf.ld_link, link, MAXLINKNAMELEN);
024b0a258461f282a92b1b1283c3b8b083f9f33fseb if ((status = dladm_door_call(&createconf, sizeof (createconf),
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * An active physical link reported by the dlmgmtd daemon might not be active
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * anymore as this link might be removed during system shutdown. Check its
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * real status by calling dladm_phys_info().
d62bc4badc1c1f1549c961cfb8b420e650e1272byzi_dladm_phys_status(datalink_id_t linkid, uint32_t *flagsp)
d62bc4badc1c1f1549c961cfb8b420e650e1272byz status = dladm_phys_info(linkid, &dpa, DLADM_OPT_ACTIVE);
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * No active status, this link was removed. Update its status
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * in the daemon and delete all active linkprops.
d62bc4badc1c1f1549c961cfb8b420e650e1272byz (void) dladm_destroy_datalink_id(linkid, DLADM_OPT_ACTIVE);
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * Walk each entry in the data link configuration repository and
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * call fn on the linkid and arg.
d62bc4badc1c1f1549c961cfb8b420e650e1272byzdladm_walk_datalink_id(int (*fn)(datalink_id_t, void *), void *argp,
d62bc4badc1c1f1549c961cfb8b420e650e1272byz datalink_class_t class, datalink_media_t dmedia, uint32_t flags)
d62bc4badc1c1f1549c961cfb8b420e650e1272byz dlmgmt_flags = (flags & DLADM_OPT_ACTIVE) ? DLMGMT_ACTIVE : 0;
d62bc4badc1c1f1549c961cfb8b420e650e1272byz dlmgmt_flags |= ((flags & DLADM_OPT_PERSIST) ? DLMGMT_PERSIST : 0);
024b0a258461f282a92b1b1283c3b8b083f9f33fseb if ((status = dladm_door_call(&getnext, sizeof (getnext),
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * done with walking
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * An active physical link reported by the dlmgmtd
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * daemon might not be active anymore. Check its
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * real status.
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * Get the link properties structure for the given link.
d62bc4badc1c1f1549c961cfb8b420e650e1272byzdladm_read_conf(datalink_id_t linkid, dladm_conf_t *confp)
024b0a258461f282a92b1b1283c3b8b083f9f33fseb if ((status = dladm_door_call(&readconf, sizeof (readconf),
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * Commit the given link to the data link configuration repository so
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * that it will persist across reboots.
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * Given a link ID and a key, get the matching information from
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * data link configuration repository.
d62bc4badc1c1f1549c961cfb8b420e650e1272byzdladm_get_conf_field(dladm_conf_t conf, const char *attr, void *attrval,
024b0a258461f282a92b1b1283c3b8b083f9f33fseb if ((status = dladm_door_call(&getattr, sizeof (getattr), &retval,
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * Get the link ID that is associated with the given name.
d62bc4badc1c1f1549c961cfb8b420e650e1272byzdladm_name2info(const char *link, datalink_id_t *linkidp, uint32_t *flagp,
024b0a258461f282a92b1b1283c3b8b083f9f33fseb if ((status = dladm_door_call(&getlinkid, sizeof (getlinkid),
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * An active physical link reported by the dlmgmtd daemon
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * might not be active anymore. Check and set its real status.
d62bc4badc1c1f1549c961cfb8b420e650e1272byz *flagp = retval.lr_flags & DLMGMT_ACTIVE ? DLADM_OPT_ACTIVE : 0;
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * Get the link name that is associated with the given id.
d62bc4badc1c1f1549c961cfb8b420e650e1272byzdladm_datalink_id2info(datalink_id_t linkid, uint32_t *flagp,
d62bc4badc1c1f1549c961cfb8b420e650e1272byz datalink_class_t *classp, uint32_t *mediap, char *link, size_t len)
d62bc4badc1c1f1549c961cfb8b420e650e1272byz if ((linkid == DATALINK_INVALID_LINKID) || (link != NULL && len == 0) ||
024b0a258461f282a92b1b1283c3b8b083f9f33fseb if ((status = dladm_door_call(&getname, sizeof (getname), &retval,
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * An active physical link reported by the dlmgmtd daemon
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * might not be active anymore. Check and set its real status.
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * Set the given attr with the given attrval for the given link.
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * Unset the given attr the given link.
d62bc4badc1c1f1549c961cfb8b420e650e1272byzdladm_unset_conf_field(dladm_conf_t conf, const char *attr)
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * Remove the given link ID and its entry from the data link configuration
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * repository.
024b0a258461f282a92b1b1283c3b8b083f9f33fseb return (dladm_door_call(&removeconf, sizeof (removeconf),
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * Free the contents of the link structure.
024b0a258461f282a92b1b1283c3b8b083f9f33fseb (void) dladm_door_call(&destroyconf, sizeof (destroyconf),