/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
*/
/*
* Main door handler functions used by dlmgmtd to process the different door
* call requests. Door call requests can come from the user-land applications,
* or from the kernel.
*
* Note on zones handling:
*
* There are two zoneid's associated with a link. One is the zoneid of the
* zone in which the link was created (ll_zoneid in the dlmgmt_link_t), and
* the other is the zoneid of the zone where the link is currently assigned
* (the "zone" link property). The two can be different if a datalink is
* created in the global zone and subsequently assigned to a non-global zone
* via zonecfg or via explicitly setting the "zone" link property.
*
* Door clients can see links that were created in their zone, and links that
* are currently assigned to their zone. Door clients in a zone can only
* modify links that were created in their zone.
*
* The datalink ID space is global, while each zone has its own datalink name
* space. This allows each zone to have complete freedom over the names that
* they assign to links created within the zone.
*/
#include <assert.h>
#include <alloca.h>
#include <errno.h>
#include <priv_utils.h>
#include <stdlib.h>
#include <strings.h>
#include <syslog.h>
#include <zone.h>
#include <libsysevent.h>
#include <libdlmgmt.h>
#include <librcm.h>
#include "dlmgmt_impl.h"
ucred_t *);
typedef struct dlmgmt_door_info_s {
/*
* Check if the caller has the required privileges to operate on a link of the
* given class.
*/
static int
{
return (0);
return (EACCES);
}
static dlmgmt_link_t *
{
return (linkp);
}
}
return (NULL);
}
/*
* Post the EC_DATALINK sysevent for the given linkid. This sysevent will
* be consumed by the datalink sysevent module.
*/
static void
{
int err;
reconfigured)) != 0)) {
goto done;
}
}
done:
if (err != 0) {
}
}
/* ARGSUSED */
static void
{
int err = 0;
/*
* Determine whether this link is persistent. Note that this request
* is coming from kernel so this link must be active.
*/
/*
* Hold the writer lock to update the link table.
*/
goto done;
/*
* Check to see whether this is the reattachment of an existing
* physical link. If so, return its linkid.
*/
/*
* If nothing has been changed, directly return.
*/
goto noupdate;
}
if (err != 0)
goto done;
if (err != 0)
goto done;
/*
* This is a device that is dynamic reconfigured.
*/
goto done;
goto done;
}
/*
* The link name already exists. Return error if this is a
* non-physical link (in that case, the link name must be
* the same as the given name).
*/
if (class != DATALINK_CLASS_PHYS)
goto done;
/*
* The physical link's name already exists, request
* a suggested link name: net<nextppa>
*/
if (err != 0)
goto done;
&linkp);
}
if (err != 0)
goto done;
/*
* This is a new link. Only need to persist link attributes for
* physical links.
*/
if (class == DATALINK_CLASS_PHYS &&
sizeof (uint64_t), DLADM_TYPE_UINT64)) != 0) ||
sizeof (uint64_t), DLADM_TYPE_UINT64)) != 0))) {
}
done:
}
if (err == 0)
/*
* Post the ESC_DATALINK_PHYS_ADD sysevent. This sysevent
* is consumed by the datalink sysevent module which in
* turn generates the RCM_RESOURCE_LINK_NEW RCM event.
*/
}
}
/* ARGSUSED */
static void
{
int err = 0;
/*
* Hold the writer lock to update the link table.
*/
/*
* Check to see whether this is the reattachment of an existing
* physical link. If so, return its linkid.
*/
NULL) {
goto done;
}
goto done;
/*
* Assume a DL_ETHER link ce0, a DL_WIFI link ath0
* 1. # dladm rename-link ce0 net0
* 2. DR out ce0. net0 is down.
* 3. use rename-link to have the ath0 device inherit
* the configuration from net0
* # dladm rename-link ath0 net0
* 4. DR in ath0.
* As ath0 and ce0 do not have the same media type, ath0
* cannot inherit the configuration of net0.
*/
/*
* Return the media type of the existing link to indicate the
* reason for the name conflict.
*/
goto done;
}
if (update->ld_novanity &&
/*
* Return an error if this is a physical link that does not
* support vanity naming, but the link name is not the same
* as the given device name.
*/
goto done;
}
}
done:
}
/* ARGSUSED */
static void
{
int err = 0;
/*
* Hold the writer lock to update the link table.
*/
goto done;
}
goto done;
goto done;
dflags |= DLMGMT_ACTIVE;
}
goto done;
dflags |= DLMGMT_PERSIST;
}
done:
}
/* ARGSUSED */
static void
{
int err = 0;
/*
* Hold the reader lock to access the link
*/
} else {
}
}
/* ARGSUSED */
static void
{
int err = 0;
/*
* Hold the reader lock to access the link
*/
/*
* The link does not exist in this zone.
*/
goto done;
}
done:
}
/* ARGSUSED */
static void
{
int err = 0;
/*
* Hold the reader lock to access the link
*/
continue;
break;
}
} else {
}
}
/* ARGSUSED */
static void
{
/*
* Hold the reader lock to access the link
*/
} else {
}
}
/* ARGSUSED */
static void
{
int err;
/*
* Hold the writer lock to update the dlconf table.
*/
goto done;
if (err != 0)
goto done;
} else {
}
if (err == 0) {
/*
* Keep the active mapping.
*/
}
}
done:
}
/* ARGSUSED */
static void
{
int err = 0;
/*
* Hold the writer lock to update the link table.
*/
goto done;
}
goto done;
/*
* Delete the active mapping.
*/
if (flags & DLMGMT_ACTIVE)
if (err == 0)
done:
}
/*
* Remap a linkid to a given link name, i.e., rename an existing link1
* (ld_linkid) to a non-existent link2 (ld_link): rename link1's name to
* the given link name.
*/
/* ARGSUSED */
static void
{
int err = 0;
return;
}
/*
* Hold the writer lock to update the link table.
*/
goto done;
}
goto done;
goto done;
}
if (err != 0)
goto done;
}
if (err != 0) {
}
goto done;
}
}
done:
}
}
/* ARGSUSED */
static void
{
int err = 0;
/*
* Hold the writer lock to update the link table.
*/
goto done;
}
goto done;
goto done;
}
}
done:
}
/* ARGSUSED */
static void
{
int err;
/*
* Hold the writer lock to update the dlconf table.
*/
goto done;
if (err == 0) {
}
done:
}
/* ARGSUSED */
static void
{
int err = 0;
/*
* Hold the writer lock to update the dlconf table.
*/
goto done;
}
goto done;
done:
}
/* ARGSUSED */
static void
{
int err = 0;
/*
* Hold the writer lock to update the dlconf table.
*/
goto done;
}
goto done;
done:
}
/*
* Note that dlmgmt_openconf() returns a conf ID of a conf AVL tree entry,
* which is managed by dlmgmtd. The ID is used to find the conf entry when
* dlmgmt_write_conf() is called. The conf entry contains an ld_gen value
* (which is the generation number - ll_gen) of the dlmgmt_link_t at the time
* of dlmgmt_openconf(), and ll_gen changes every time the dlmgmt_link_t
* changes its attributes. Therefore, dlmgmt_write_conf() can compare ld_gen
* in the conf entry against the latest dlmgmt_link_t ll_gen value to see if
* anything has changed between the dlmgmt_openconf() and dlmgmt_writeconf()
* calls. If so, EAGAIN is returned. This mechanism can ensures atomicity
* across the pair of dladm_read_conf() and dladm_write_conf() calls.
*/
/* ARGSUSED */
static void
{
int err = 0;
/*
* Hold the lock to access the dlconf table.
*/
goto done;
}
goto done;
/*
* Hold the writer lock to update the link table.
*/
/*
* The link does not exist.
*/
goto done;
}
/*
* Something has changed the link configuration; try again.
*/
goto done;
}
/*
* Delete the old attribute list.
*/
}
/*
* Set the new attribute.
*/
goto done;
}
}
done:
}
/* ARGSUSED */
static void
{
int err;
goto done;
}
/*
* A non-global zone cannot remove the persistent
* configuration of a link that is on loan from the global
* zone.
*/
goto done;
}
goto done;
done:
}
/* ARGSUSED */
static void
{
int err = 0;
/*
* Hold the writer lock to update the dlconf table.
*/
goto done;
}
goto done;
done:
}
/*
* dlmgmt_openconf() returns a handle of the current configuration, which
* is then used to update the configuration by dlmgmt_writeconf(). Therefore,
* it requires privileges.
*
* Further, please see the comments above dladm_write_conf() to see how
* ld_gen is used to ensure atomicity across the {dlmgmt_openconf(),
* dlmgmt_writeconf()} pair.
*/
/* ARGSUSED */
static void
{
int err = 0;
/*
* Hold the writer lock to update the dlconf table.
*/
/*
* Hold the reader lock to access the link
*/
/* The persistent link configuration does not exist. */
goto done;
}
/*
* The caller is in a non-global zone and the persistent
* configuration belongs to the global zone.
*/
goto done;
}
goto done;
goto done;
goto done;
}
}
done:
}
/*
* dlmgmt_getconfsnapshot() returns a read-only snapshot of all the
* configuration, and requires no privileges.
*
* If the given size cannot hold all the configuration, set the size
* that is needed, and return ENOSPC.
*/
/* ARGSUSED */
static void
{
char *buf;
int err = 0;
/*
* Hold the reader lock to access the link
*/
/* The persistent link configuration does not exist. */
goto done;
}
/*
* The caller is in a non-global zone and the persistent
* configuration belongs to the global zone.
*/
goto done;
}
if (err != 0)
goto done;
goto done;
}
}
goto done;
goto done;
}
/*
* pack the the nvlist into the return value.
*/
done:
}
/* ARGSUSED */
static void
{
int err;
/*
* Hold the read lock to access the dlconf table.
*/
} else {
} else {
}
}
}
/* ARGSUSED */
static void
{
int err;
else
if (err == 0) {
if (s != DLADM_STATUS_OK) {
"linkprop initialization failed on link %d: %s",
}
}
}
/* ARGSUSED */
static void
{
int err = 0;
/* We currently only allow changing zoneid's from the global zone. */
if (zoneid != GLOBAL_ZONEID) {
goto done;
}
goto done;
}
goto done;
/* We can only assign an active link to a zone. */
goto done;
}
goto done;
/*
* Before we remove the link from its current zone, make sure that
* there isn't a link with the same name in the destination zone.
*/
if (zoneid != GLOBAL_ZONEID &&
goto done;
}
if (oldzoneid != GLOBAL_ZONEID) {
goto done;
}
}
if (newzoneid != GLOBAL_ZONEID) {
goto done;
}
}
done:
}
/* ARGSUSED */
static void
{
int err;
goto done;
if (zoneid != GLOBAL_ZONEID) {
goto done;
}
goto done;
}
if ((err = dlmgmt_elevate_privileges()) == 0) {
(void) dlmgmt_drop_privileges();
}
done:
}
/* ARGSUSED */
static void
{
int err = 0;
if (zoneid != GLOBAL_ZONEID) {
} else {
}
}
}
{ DLMGMT_CMD_DLS_CREATE, sizeof (dlmgmt_upcall_arg_create_t),
sizeof (dlmgmt_create_retval_t), dlmgmt_upcall_create },
{ DLMGMT_CMD_DLS_GETATTR, sizeof (dlmgmt_upcall_arg_getattr_t),
sizeof (dlmgmt_getattr_retval_t), dlmgmt_upcall_getattr },
{ DLMGMT_CMD_DLS_DESTROY, sizeof (dlmgmt_upcall_arg_destroy_t),
sizeof (dlmgmt_destroy_retval_t), dlmgmt_upcall_destroy },
{ DLMGMT_CMD_GETNAME, sizeof (dlmgmt_door_getname_t),
sizeof (dlmgmt_getname_retval_t), dlmgmt_getname },
{ DLMGMT_CMD_GETLINKID, sizeof (dlmgmt_door_getlinkid_t),
sizeof (dlmgmt_getlinkid_retval_t), dlmgmt_getlinkid },
{ DLMGMT_CMD_GETNEXT, sizeof (dlmgmt_door_getnext_t),
sizeof (dlmgmt_getnext_retval_t), dlmgmt_getnext },
{ DLMGMT_CMD_DLS_UPDATE, sizeof (dlmgmt_upcall_arg_update_t),
sizeof (dlmgmt_update_retval_t), dlmgmt_upcall_update },
{ DLMGMT_CMD_CREATE_LINKID, sizeof (dlmgmt_door_createid_t),
sizeof (dlmgmt_createid_retval_t), dlmgmt_createid },
{ DLMGMT_CMD_DESTROY_LINKID, sizeof (dlmgmt_door_destroyid_t),
sizeof (dlmgmt_destroyid_retval_t), dlmgmt_destroyid },
{ DLMGMT_CMD_REMAP_LINKID, sizeof (dlmgmt_door_remapid_t),
sizeof (dlmgmt_remapid_retval_t), dlmgmt_remapid },
{ DLMGMT_CMD_CREATECONF, sizeof (dlmgmt_door_createconf_t),
sizeof (dlmgmt_createconf_retval_t), dlmgmt_createconf },
{ DLMGMT_CMD_OPENCONF, sizeof (dlmgmt_door_openconf_t),
sizeof (dlmgmt_openconf_retval_t), dlmgmt_openconf },
{ DLMGMT_CMD_WRITECONF, sizeof (dlmgmt_door_writeconf_t),
sizeof (dlmgmt_writeconf_retval_t), dlmgmt_writeconf },
{ DLMGMT_CMD_UP_LINKID, sizeof (dlmgmt_door_upid_t),
sizeof (dlmgmt_upid_retval_t), dlmgmt_upid },
{ DLMGMT_CMD_SETATTR, sizeof (dlmgmt_door_setattr_t),
sizeof (dlmgmt_setattr_retval_t), dlmgmt_setattr },
{ DLMGMT_CMD_UNSETATTR, sizeof (dlmgmt_door_unsetattr_t),
sizeof (dlmgmt_unsetattr_retval_t), dlmgmt_unsetconfattr },
{ DLMGMT_CMD_REMOVECONF, sizeof (dlmgmt_door_removeconf_t),
sizeof (dlmgmt_removeconf_retval_t), dlmgmt_removeconf },
{ DLMGMT_CMD_DESTROYCONF, sizeof (dlmgmt_door_destroyconf_t),
sizeof (dlmgmt_destroyconf_retval_t), dlmgmt_destroyconf },
{ DLMGMT_CMD_GETATTR, sizeof (dlmgmt_door_getattr_t),
sizeof (dlmgmt_getattr_retval_t), dlmgmt_getattr },
{ DLMGMT_CMD_GETCONFSNAPSHOT, sizeof (dlmgmt_door_getconfsnapshot_t),
sizeof (dlmgmt_getconfsnapshot_retval_t), dlmgmt_getconfsnapshot },
{ DLMGMT_CMD_LINKPROP_INIT, sizeof (dlmgmt_door_linkprop_init_t),
sizeof (dlmgmt_linkprop_init_retval_t),
{ DLMGMT_CMD_SETZONEID, sizeof (dlmgmt_door_setzoneid_t),
sizeof (dlmgmt_setzoneid_retval_t), dlmgmt_setzoneid },
{ DLMGMT_CMD_ZONEBOOT, sizeof (dlmgmt_door_zoneboot_t),
sizeof (dlmgmt_zoneboot_retval_t), dlmgmt_zoneboot },
{ DLMGMT_CMD_ZONEHALT, sizeof (dlmgmt_door_zonehalt_t),
sizeof (dlmgmt_zonehalt_retval_t), dlmgmt_zonehalt },
{ 0, 0, 0, NULL }
};
static dlmgmt_door_info_t *
{
break;
infop++;
}
return (infop);
}
/* ARGSUSED */
void
{
int err = 0;
goto done;
}
goto done;
}
/*
* Note that malloc() cannot be used here because door_return
* never returns, and memory allocated by malloc() would get leaked.
* Use alloca() instead.
*/
/*
* If the specified buffer size is not big enough to hold the
* return value, reallocate the buffer and try to get the
* result one more time.
*/
goto again;
}
done:
if (err == 0) {
} else {
}
}