libdlether.c revision 0dc2366f7b9f9f36e10909b1e95edbf2a261c2ac
/*
* 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 2010 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <libdladm_impl.h>
#include <libdllink.h>
#include <libdlstat.h>
#include <libdlether.h>
/*
* Ethernet administration library.
*/
/*
* kstat names for extracting attributes.
*/
typedef struct ether_spdx_s {
char *eth_spdx_stat_name;
} ether_spdx_t;
static ether_spdx_t cap_spdx[] = {
{{0, LINK_DUPLEX_UNKNOWN}, NULL}
};
static ether_spdx_t adv_cap_spdx[] = {
{{0, LINK_DUPLEX_UNKNOWN}, NULL}
};
static ether_spdx_t lp_cap_spdx[] = {
{{0, LINK_DUPLEX_UNKNOWN}, NULL}
};
typedef struct attr_kstat_s {
char *autoneg_stat;
char *pause_stat;
char *asmpause_stat;
char *fault_stat;
} attr_kstat_t;
static attr_kstat_t attrstat[] = {
{"link_autoneg", /* current */
NULL},
{"cap_autoneg", /* capable */
"cap_pause", "cap_asmpause", "cap_rem_fault",
cap_spdx},
{"adv_cap_autoneg", /* advertised */
"adv_cap_pause", "adv_cap_asmpause", "adv_rem_fault",
{"lp_cap_autoneg", /* peer advertised */
"lp_cap_pause", "lp_cap_asmpause", "lp_rem_fault",
};
/*
* Get the speed-duplex stats specified in the ether_spdx_t table passed in
* by querying the appropriate kstat for each entry in the table.
*/
static dladm_status_t
{
int i, nspdx = 0;
void *ptr;
if (status == DLADM_STATUS_NOTFOUND) {
/*
* Missing statistic.
* Skip this one and try the rest.
*/
continue;
} else {
eattr->le_num_spdx = 0;
return (status);
}
}
if (speed == 0)
continue;
nspdx++;
nspdx * sizeof (dladm_ether_spdx_t));
} else {
eattr->le_num_spdx = 0;
return (DLADM_STATUS_NOMEM);
}
}
return (DLADM_STATUS_OK);
}
/*
* Returns "yes" or "no" based on the autonegotion capabilities
* for the parameter type indicated by ptype. The permissible
* values for ptype are CURRENT, CAPABLE, ADV, PEERADV.
*/
char *
int ptype)
{
return (buf);
}
/*
* Returns {"bi", "tx", "none"} based on the flow-control capabilities
* for the parameter type indicated by ptype. The permissible
* values for ptype are CURRENT, CAPABLE, ADV, PEERADV.
*/
char *
int ptype)
{
if (pause)
else if (asmpause)
else
return (buf);
}
/*
* For a given param type, parse the list of speed-duplex pairs in
* the dladm_ether_info_t and return a comma-separated string formatted
* as <speed><speed-unit-char>-<duplex-chars> where <speed> is the value of
* speed, in units specifid by the <speed-unit-char> which is one
* 'f', 'h' (indicating full-duplex and half-duplex respectively)
*/
extern char *
int ptype)
{
int i, j;
int speed;
char speed_unit;
char tmpbuf[DLADM_STRSIZE];
for (i = 0; i < nspdx; i++) {
/*
* if we have already covered this speed for
* the <other>-duplex case before this, skip it
*/
for (j = 0; j < i; j++) {
break;
}
if (j < i)
continue;
if (speed >= 1000) {
speed_unit = 'G';
} else {
speed_unit = 'M';
}
speed, speed_unit);
if (i > 0)
/*
* Find all the supported duplex values for this speed.
*/
for (j = 0; j < nspdx; j++) {
continue;
}
else if (is_full)
else if (is_half)
}
return (buf);
}
/*
* Extract Ethernet attributes of the link specified by linkid.
* Information for the CURRENT, CAPABLE, ADV and PEERADV parameter
* types is extracted into the lei_attr[] entries in the dladm_ether_info_t.
* On succesful return, the memory allocated in this function should be
* freed by calling dladm_ether_info_done().
*/
extern dladm_status_t
{
int i;
if (status != DLADM_STATUS_OK)
goto bail;
/* get current values of speed, duplex, state of link */
goto bail;
}
goto bail;
goto bail;
if (status != DLADM_STATUS_OK)
goto bail;
/* get the auto, pause, asmpause, fault values */
if (status != DLADM_STATUS_OK)
goto bail;
if (status != DLADM_STATUS_OK)
goto bail;
if (status != DLADM_STATUS_OK)
goto bail;
if (i == CURRENT)
continue;
if (status != DLADM_STATUS_OK)
goto bail;
if (status != DLADM_STATUS_OK)
goto bail;
}
bail:
if (status != DLADM_STATUS_OK)
return (status);
}
extern void
{
int i;
}