linkprop.c revision d62bc4badc1c1f1549c961cfb8b420e650e1272b
/*
* 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
*/
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <stdlib.h>
#include <strings.h>
#include <errno.h>
#include <ctype.h>
#include <stddef.h>
#include <fcntl.h>
#include <unistd.h>
#include <libdevinfo.h>
#include <zone.h>
#include <libdllink.h>
#include <libdladm_impl.h>
#include <libdlwlan_impl.h>
#include <libdlwlan.h>
#include <libdlvlan.h>
#include <dlfcn.h>
#include <link.h>
#include <inet/wifi_ioctl.h>
/*
* The linkprop get() callback.
* - propstrp: a property string array to keep the returned property.
* Caller allocated.
* - cntp: number of returned properties.
* Caller also uses it to indicate how many it expects.
*/
/*
* The linkprop set() callback.
* - propval: a val_desc_t array which keeps the property values to be set.
* - cnt: number of properties to be set.
*/
#define PD_TEMPONLY 0x1
/*
* The linkprop check() callback.
* - propstrp: property string array which keeps the property to be checked.
* - cnt: number of properties.
* - propval: return value; the property values of the given property strings.
* - dofree: indicates whether the caller needs to free propvalp->vd_val.
*/
typedef struct prop_desc {
/*
* link property name
*/
char *pd_name;
/*
* default property value, can be set to { "", NULL }
*/
/*
* list of optional property values, can be NULL.
*
* This is set to non-NULL if there is a list of possible property
* values. pd_optval would point to the array of possible values.
*/
/*
* count of the above optional property values. 0 if pd_optval is NULL.
*/
/*
* callback to set link property;
* set to NULL if this property is read-only
*/
/*
* callback to get modifiable link property
*/
/*
* callback to get current link property
*/
/*
* callback to validate link property value, set to NULL if pd_optval
* is not NULL. In that case, validate the value by comparing it with
* the pd_optval. Return a val_desc_t array pointer if the value is
* valid.
*/
/*
* currently only PD_TEMPONLY is valid, which indicates the property
* is temporary only.
*/
/*
* indicate link classes this property applies to.
*/
/*
* indicate link media type this property applies to.
*/
} prop_desc_t;
static val_desc_t dladm_wlan_radio_vals[] = {
{ "on", DLADM_WLAN_RADIO_ON },
{ "off", DLADM_WLAN_RADIO_OFF }
};
static val_desc_t dladm_wlan_powermode_vals[] = {
{ "off", DLADM_WLAN_PM_OFF },
{ "fast", DLADM_WLAN_PM_FAST },
{ "max", DLADM_WLAN_PM_MAX }
};
static prop_desc_t prop_table[] = {
do_get_channel_prop, NULL, 0,
do_get_radio_prop, NULL, 0,
};
char **, uint_t);
char **, uint_t *);
/*
* Unfortunately, MAX_SCAN_SUPPORT_RATES is too small to allow all
* rates to be retrieved. However, we cannot increase it at this
* time because it will break binary compatibility with unbundled
* WiFi drivers and utilities. So for now we define an additional
* constant, MAX_SUPPORT_RATES, to allow all rates to be retrieved.
*/
#define MAX_SUPPORT_RATES 64
#define AP_ANCHOR "[anchor]"
#define AP_DELIMITER '.'
static dladm_status_t
{
int i, j;
for (j = 0; j < val_cnt; j++) {
for (i = 0; i < pdp->pd_noptval; i++) {
if (strcasecmp(*prop_val,
break;
}
}
if (i == pdp->pd_noptval) {
goto done;
}
}
done:
return (status);
}
static dladm_status_t
{
return (DLADM_STATUS_BADARG);
return (DLADM_STATUS_BADARG);
return (DLADM_STATUS_TEMPONLY);
if (!(flags & DLADM_OPT_ACTIVE))
return (DLADM_STATUS_OK);
return (DLADM_STATUS_PROPRDONLY);
return (DLADM_STATUS_NOMEM);
&needfree);
} else {
}
if (status != DLADM_STATUS_OK)
goto done;
} else {
return (DLADM_STATUS_NOTSUP);
return (DLADM_STATUS_NOMEM);
cnt = 1;
}
if (needfree) {
for (i = 0; i < cnt; i++)
}
done:
return (status);
}
static dladm_status_t
{
int i;
if (status != DLADM_STATUS_OK)
return (status);
for (i = 0; i < DLADM_MAX_PROPS; i++) {
continue;
status = s;
break;
} else {
if (s != DLADM_STATUS_OK &&
s != DLADM_STATUS_NOTSUP)
status = s;
}
}
if (!found)
return (status);
}
/*
*/
{
return (DLADM_STATUS_BADARG);
}
if (status != DLADM_STATUS_OK)
return (status);
if (flags & DLADM_OPT_PERSIST) {
}
return (status);
}
/*
* Walk link properties of the given specific link.
*/
int (*func)(datalink_id_t, const char *, void *))
{
int i;
return (DLADM_STATUS_BADARG);
if (status != DLADM_STATUS_OK)
return (status);
for (i = 0; i < DLADM_MAX_PROPS; i++) {
continue;
continue;
break;
}
}
return (DLADM_STATUS_OK);
}
/*
* Get linkprop of the given specific link.
*/
{
int i;
return (DLADM_STATUS_BADARG);
for (i = 0; i < DLADM_MAX_PROPS; i++)
break;
if (i == DLADM_MAX_PROPS)
return (DLADM_STATUS_NOTFOUND);
pdp = &prop_table[i];
if (status != DLADM_STATUS_OK)
return (status);
return (DLADM_STATUS_BADARG);
return (DLADM_STATUS_BADARG);
switch (type) {
case DLADM_PROP_VAL_CURRENT:
break;
case DLADM_PROP_VAL_DEFAULT:
break;
}
*val_cntp = 1;
break;
break;
}
if (cnt == 0) {
} else {
for (i = 0; i < cnt; i++) {
}
}
break;
return (DLADM_STATUS_TEMPONLY);
break;
default:
break;
}
return (status);
}
/*ARGSUSED*/
static int
{
DLADM_MAX_PROP_VALCNT)) == NULL) {
return (DLADM_WALK_CONTINUE);
}
for (i = 0; i < valcnt; i++) {
sizeof (char *) * DLADM_MAX_PROP_VALCNT +
i * DLADM_PROP_VAL_MAX;
}
goto done;
}
done:
return (DLADM_WALK_CONTINUE);
}
/*ARGSUSED*/
static int
{
(void) dladm_init_linkprop(linkid);
return (DLADM_WALK_CONTINUE);
}
{
if (linkid == DATALINK_ALL_LINKID) {
} else {
}
return (DLADM_STATUS_OK);
}
static dladm_status_t
{
char zone_name[ZONENAME_MAX];
if (status != DLADM_STATUS_OK)
return (status);
*val_cnt = 1;
if (zid != GLOBAL_ZONEID) {
return (dladm_errno2status(errno));
} else {
*prop_val[0] = '\0';
}
return (DLADM_STATUS_OK);
}
typedef int (*zone_get_devroot_t)(char *, char *, size_t);
static int
{
char root[MAXPATHLEN];
void *dlhandle;
void *sym;
int ret;
return (-1);
return (-1);
}
return (ret);
}
static dladm_status_t
{
char path[MAXPATHLEN];
char name[MAXLINKNAMELEN];
char zone_name[ZONENAME_MAX];
int ret;
return (dladm_errno2status(errno));
return (dladm_errno2status(errno));
return (dladm_errno2status(errno));
if (status != DLADM_STATUS_OK)
goto cleanup;
if (add)
else
if (ret != 0) {
goto cleanup;
}
if (di_prof_commit(prof) != 0)
if (prof)
return (status);
}
static dladm_status_t
{
char link[MAXLINKNAMELEN];
if (val_cnt != 1)
return (DLADM_STATUS_BADVALCNT);
if (status != DLADM_STATUS_OK)
return (status);
/* Do nothing if setting to current value */
return (DLADM_STATUS_OK);
return (status);
}
if (zid_new != GLOBAL_ZONEID) {
/*
* If the new zoneid is the global zone, we could destroy
* the link (in the case of an implicitly-created VLAN) as a
* result of the dladm_setzid() operation. In that case,
* we defer the operation to the end of this function to avoid
* recreating the VLAN and getting a different linkid during
* the rollback if other operation fails.
*
* Otherwise, dladm_setzid() will hold a reference to the
* link and prevent a link renaming, so we need to do it
* before other operations.
*/
if (status != DLADM_STATUS_OK)
return (status);
}
if (zid_old != GLOBAL_ZONEID) {
goto rollback1;
}
/*
* It is okay to fail to update the /dev entry (some
* vanity-named links do not have a /dev entry).
*/
}
if (zid_new != GLOBAL_ZONEID) {
goto rollback2;
}
} else {
if (status != DLADM_STATUS_OK)
goto rollback2;
}
return (DLADM_STATUS_OK);
if (zid_old != GLOBAL_ZONEID)
if (zid_old != GLOBAL_ZONEID)
if (zid_new != GLOBAL_ZONEID)
return (status);
}
/* ARGSUSED */
static dladm_status_t
{
if (val_cnt != 1)
return (DLADM_STATUS_BADVALCNT);
return (DLADM_STATUS_BADVAL);
if (zid != GLOBAL_ZONEID) {
sizeof (flags)) < 0) {
return (dladm_errno2status(errno));
}
if (!(flags & ZF_NET_EXCL)) {
return (DLADM_STATUS_BADVAL);
}
}
return (DLADM_STATUS_OK);
}
static dladm_status_t
{
return (dladm_errno2status(errno));
*val_cnt = 1;
(*prop_val)[0] = '\0';
goto done;
}
if (i != 0) {
len += 1;
}
}
}
done:
return (DLADM_STATUS_OK);
}
static dladm_status_t
{
int fd, i;
int ic_cmd;
if (val_cnt != 1)
return (DLADM_STATUS_BADVALCNT);
return (dladm_errno2status(errno));
FMNAMESZ+1);
}
} else {
}
return (status);
}
/*
* Add the specified module to the dlautopush structure; returns a
* DLADM_STATUS_* code.
*/
{
return (DLADM_STATUS_BADVAL);
/*
* We don't allow multiple anchors, and the anchor must
* be after at least one module.
*/
if (dlap->dap_anchor != 0)
return (DLADM_STATUS_BADVAL);
return (DLADM_STATUS_BADVAL);
return (DLADM_STATUS_OK);
}
return (DLADM_STATUS_BADVALCNT);
FMNAMESZ + 1);
return (DLADM_STATUS_OK);
}
/*
* Currently, both '.' and ' '(space) can be used as the delimiters between
* autopush modules. The former is used in dladm set-linkprop, and the
* latter is used in the autopush(1M) file.
*/
/* ARGSUSED */
static dladm_status_t
{
char *module;
struct dlautopush *dlap;
char val[DLADM_PROP_VAL_MAX];
char delimiters[4];
if (val_cnt != 1)
return (DLADM_STATUS_BADVALCNT);
return (DLADM_STATUS_NOMEM);
if (status != DLADM_STATUS_OK)
return (status);
}
return (DLADM_STATUS_OK);
}
static dladm_status_t
{
uint_t i;
goto done;
}
if (status != DLADM_STATUS_OK)
goto done;
goto done;
}
if (wrp->wl_rates_rates[0] == 0) {
prop_val[0][0] = '\0';
*val_cnt = 1;
goto done;
}
for (i = 0; i < wrp->wl_rates_num; i++) {
}
done:
return (status);
}
static dladm_status_t
{
}
static dladm_status_t
{
}
static dladm_status_t
{
int i;
return (DLADM_STATUS_NOMEM);
return (status);
}
static dladm_status_t
{
if (val_cnt != 1)
return (DLADM_STATUS_BADVALCNT);
done:
return (status);
}
/* ARGSUSED */
static dladm_status_t
{
int i;
if (val_cnt != 1)
return (DLADM_STATUS_BADVALCNT);
goto done;
}
for (i = 0; i < MAX_SUPPORT_RATES; i++) {
i * DLADM_STRSIZE;
}
if (status != DLADM_STATUS_OK)
goto done;
for (i = 0; i < modval_cnt; i++) {
/*
* Does not need the caller to free the vdp->vd_val
*/
break;
}
}
if (i == modval_cnt)
done:
return (status);
}
static dladm_status_t
{
}
static dladm_status_t
{
return (DLADM_STATUS_NOMEM);
goto done;
&channel)) {
goto done;
}
*val_cnt = 1;
done:
return (status);
}
static dladm_status_t
{
}
static dladm_status_t
{
const char *s;
return (DLADM_STATUS_NOMEM);
goto done;
switch (mode->wl_ps_mode) {
case WL_PM_AM:
s = "off";
break;
case WL_PM_MPS:
s = "max";
break;
case WL_PM_FAST:
s = "fast";
break;
default:
goto done;
}
*val_cnt = 1;
done:
return (status);
}
static dladm_status_t
{
switch (*pm) {
case DLADM_WLAN_PM_OFF:
break;
case DLADM_WLAN_PM_MAX:
break;
case DLADM_WLAN_PM_FAST:
break;
default:
return (DLADM_STATUS_NOTSUP);
}
sizeof (ps_mode)));
}
/* ARGSUSED */
static dladm_status_t
{
if (val_cnt != 1)
return (DLADM_STATUS_BADVALCNT);
return (status);
}
static dladm_status_t
{
}
static dladm_status_t
{
const char *s;
return (DLADM_STATUS_NOMEM);
goto done;
switch (radio) {
case B_TRUE:
s = "on";
break;
case B_FALSE:
s = "off";
break;
default:
goto done;
}
*val_cnt = 1;
done:
return (status);
}
static dladm_status_t
{
wl_radio_t r;
switch (*radio) {
case DLADM_WLAN_RADIO_ON:
r = B_TRUE;
break;
case DLADM_WLAN_RADIO_OFF:
r = B_FALSE;
break;
default:
return (DLADM_STATUS_NOTSUP);
}
}
/* ARGSUSED */
static dladm_status_t
{
if (val_cnt != 1)
return (DLADM_STATUS_BADVALCNT);
return (status);
}
static dladm_status_t
{
char buf[MAXLINELEN];
int i;
if (status != DLADM_STATUS_OK)
return (status);
/*
* reset case.
*/
if (val_cnt == 0) {
if (status == DLADM_STATUS_OK)
goto done;
}
buf[0] = '\0';
for (i = 0; i < val_cnt; i++) {
if (i != val_cnt - 1)
}
if (status == DLADM_STATUS_OK)
done:
return (status);
}
static dladm_status_t
{
if (status != DLADM_STATUS_OK)
return (status);
if (status != DLADM_STATUS_OK)
goto done;
goto done;
}
}
done:
return (status);
}