dladm.c revision ad091ee10b4de077c116313fba8195f16565e722
/*
* 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 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <stdio.h>
#include <ctype.h>
#include <locale.h>
#include <signal.h>
#include <stdarg.h>
#include <stdlib.h>
#include <fcntl.h>
#include <string.h>
#include <stropts.h>
#include <errno.h>
#include <kstat.h>
#include <strings.h>
#include <getopt.h>
#include <unistd.h>
#include <priv.h>
#include <termios.h>
#include <pwd.h>
#include <auth_attr.h>
#include <auth_list.h>
#include <libintl.h>
#include <libdevinfo.h>
#include <libdlpi.h>
#include <libdladm.h>
#include <libdllink.h>
#include <libdlstat.h>
#include <libdlaggr.h>
#include <libdlwlan.h>
#include <libdlvlan.h>
#include <libdlvnic.h>
#include <libdlether.h>
#include <libinetutil.h>
#include <bsm/adt_event.h>
#include <libdlvnic.h>
#include <sys/processor.h>
#include <net/if_types.h>
#include <stddef.h>
#define STR_UNDEF_VAL "--"
#define MAXPORT 256
#define MAXVNIC 256
#define MAXLINELEN 1024
#define SMF_UPGRADE_FILE "/var/svc/profile/upgrade"
#define SMF_UPGRADEDATALINK_FILE "/var/svc/profile/upgrade_datalink"
#define SMF_DLADM_UPGRADE_MSG " # added by dladm(1M)"
#define CMD_TYPE_ANY 0xffffffff
#define WIFI_CMD_SCAN 0x00000001
#define WIFI_CMD_SHOW 0x00000002
/*
* Data structures and routines for printing output.
* All non-parseable output is assumed to be in a columnar format.
* Multiple fields in parsable output are separated by ':'; single
* field output is printed as-is.
*
* Each sub-command is associated with a global array of pointers,
* print_field_t *fields[], where the print_field_t contains information
* about the format in which the output is to be printed.
*
* Sub-commands may be implemented in one of two ways:
* (i) the implementation could get all field values into a character
* buffer, with pf_offset containing the offset (for pf_name) within
* the buffer. The sub-command would make the needed system calls
* to obtain all possible column values and then invoke the
* dladm_print_field() function to print the specific fields
* requested in the command line. See the comments for dladm_print_field
* for further details.
* (ii) Alternatively, each fields[i] entry could store a pf_index value
* that uniquely identifies the column to be printed. The implementation
* of the sub-command would then invoke dladm_print_output() with a
* callback function whose semantics are described below (see comments
* for dladm_print_output())
*
* Thus, an implementation of a sub-command must provide the following:
*
* static print_field_t sub_command_fields[] = {
* {<name>, <header>,<field width>, <offset_or_index>, cmdtype},
* :
* {<name>, <header>,<field width>, <offset_or_index>, cmdtype}
* };
*
* #define SUB_COMMAND_MAX_FIELDS sizeof \
* (sub_comand_fields) / sizeof (print_field_t))
*
* print_state_t sub_command_print_state;
*
* The function that parses command line arguments (typically
* do_sub_command()) should then contain an invocation like:
*
* fields = parse_output_fields(fields_str, sub_command_fields,
* SUB_COMMAND_MAX_FIELDS, CMD_TYPE_ANY, &nfields);
*
* and store the resulting fields and nfields value in a print_state_t
* structure tracked for the command.
*
* sub_command_print_state.ps_fields = fields;
* sub_command_print_state.ps_nfields = nfields;
*
* To print the column header for the output, the print_header()
* function must then be invoked by do_sub_command().
*
* Then if method (i) is used for the sub_command, the do_sub_command()
* function should make the necessary system calls to fill up the buffer
* and then invoke dladm_print_field(). An example of this method is
* the implementation of do_show_link() and show_link();
*
* If method (ii) is used, do_sub_command should invoke dladm_print_output()
* with a callback function that will be called for each field to be printed.
* The callback function will be passed a pointer to the print_field_t
* for the field, and the pf_index may then be used to identify the
* system call required to find the value to be printed.
*/
typedef struct print_field_s {
const char *pf_name; /* name of column to be printed */
const char *pf_header; /* header for this column */
union {
}_pf_un;
/*
* The state of the output is tracked in a print_state_t structure.
* Each ps_fields[i] entry points at the global print_field_t array for
* the sub-command, where ps_nfields is the number of requested fields.
*/
typedef struct print_state_s {
typedef char *(*print_callback_t)(print_field_t *, void *);
/*
* print the header for the output
*/
static void print_header(print_state_t *);
/*
* to print output values, call dladm_print_output with a callback
* function (*func)() that should parse the args and return an
* unformatted character buffer with the value to be printed.
*
* dladm_print_output() prints the character buffer using the formatting
* information provided in the print_field_t for that column.
*/
print_callback_t, void *);
/*
* helper function that, when invoked as dladm_print_field(pf, buf)
* prints string which is offset by pf->pf_offset within buf.
*/
static char *dladm_print_field(print_field_t *, void *);
#define MAX_FIELD_LEN 32
typedef struct show_state {
} show_state_t;
typedef struct show_grp_state {
typedef struct show_vnic_state {
char vs_vnic[MAXLINKNAMELEN];
char vs_link[MAXLINKNAMELEN];
typedef struct show_usage_state_s {
typedef void cmdfunc_t(int, char **, const char *);
static cmdfunc_t do_show_linkmap;
static cmdfunc_t do_show_ether;
static cmdfunc_t do_up_vnic;
static cmdfunc_t do_show_usage;
static void do_up_vnic_common(int, char **, const char *, boolean_t);
static void altroot_cmd(char *, int, char **);
static int get_one_kstat(const char *, const char *, uint8_t,
void *, boolean_t);
static void get_mac_stats(const char *, pktsum_t *);
static void get_link_stats(const char *, pktsum_t *);
static const char *get_linkstate(const char *, boolean_t, char *);
static const char *get_linkduplex(const char *, boolean_t, char *);
static void show_ether_xprop(void *, dladm_ether_info_t *);
static void die(const char *, ...);
static void die_optdup(int);
static void die_opterr(int, int, const char *);
static void die_dlerr(dladm_status_t, const char *, ...);
static void warn(const char *, ...);
static void warn_dlerr(dladm_status_t, const char *, ...);
typedef struct cmd {
char *c_name;
const char *c_usage;
} cmd_t;
{ "rename-link", do_rename_link,
" rename-link <oldlink> <newlink>" },
{ "show-link", do_show_link,
" show-link [-pP] [-o <field>,..] [-s [-i <interval>]] "
"[<link>]\n" },
{ "create-aggr", do_create_aggr,
" create-aggr [-t] [-P <policy>] [-L <mode>] [-T <time>] "
"[-u <address>]\n"
"\t\t -l <link> [-l <link>...] <link>" },
{ "delete-aggr", do_delete_aggr,
" delete-aggr [-t] <link>" },
{ "add-aggr", do_add_aggr,
" add-aggr [-t] -l <link> [-l <link>...] <link>" },
{ "remove-aggr", do_remove_aggr,
" remove-aggr [-t] -l <link> [-l <link>...] <link>" },
{ "modify-aggr", do_modify_aggr,
" modify-aggr [-t] [-P <policy>] [-L <mode>] [-T <time>] "
"[-u <address>]\n"
"\t\t <link>" },
{ "show-aggr", do_show_aggr,
" show-aggr [-pPLx] [-o <field>,..] [-s [-i <interval>]] "
"[<link>]\n" },
{ "scan-wifi", do_scan_wifi,
" scan-wifi [-p] [-o <field>,...] [<link>]" },
{ "connect-wifi", do_connect_wifi,
" connect-wifi [-e <essid>] [-i <bssid>] [-k <key>,...] "
"[-s wep|wpa]\n"
"\t\t [-a open|shared] [-b bss|ibss] [-c] [-m a|b|g] "
"[-T <time>]\n"
"\t\t [<link>]" },
{ "disconnect-wifi", do_disconnect_wifi,
" disconnect-wifi [-a] [<link>]" },
{ "show-wifi", do_show_wifi,
" show-wifi [-p] [-o <field>,...] [<link>]\n" },
{ "set-linkprop", do_set_linkprop,
" set-linkprop [-t] -p <prop>=<value>[,...] <name>" },
{ "reset-linkprop", do_reset_linkprop,
" reset-linkprop [-t] [-p <prop>,...] <name>" },
{ "show-linkprop", do_show_linkprop,
" show-linkprop [-cP] [-o <field>,...] [-p <prop>,...] "
"<name>\n" },
{ "show-ether", do_show_ether,
" show-ether [-px][-o <field>,...] <link>\n" },
{ "create-secobj", do_create_secobj,
" create-secobj [-t] [-f <file>] -c <class> <secobj>" },
{ "delete-secobj", do_delete_secobj,
" delete-secobj [-t] <secobj>[,...]" },
{ "show-secobj", do_show_secobj,
" show-secobj [-pP] [-o <field>,...] [<secobj>,...]\n" },
{ "create-vlan", do_create_vlan,
" create-vlan [-ft] -l <link> -v <vid> [link]" },
{ "delete-vlan", do_delete_vlan,
" delete-vlan [-t] <link>" },
{ "show-vlan", do_show_vlan,
" show-vlan [-pP] [-o <field>,..] [<link>]\n" },
{ "delete-phys", do_delete_phys,
" delete-phys <link>" },
{ "show-phys", do_show_phys,
" show-phys [-pP] [-o <field>,..] [-H] [<link>]\n"},
{ "create-vnic", do_create_vnic,
" create-vnic [-t] -l <link> [-m <value> | auto |\n"
"\t\t {factory [-n <slot-id>]} | {random [-r <prefix>]}]\n"
"\t\t [-v <vid> [-f]] [-p <prop>=<value>[,...]] [-H] "
"<vnic-link>" },
{ "delete-vnic", do_delete_vnic,
" delete-vnic [-t] <vnic-link>" },
{ "show-vnic", do_show_vnic,
" show-vnic [-pP] [-l <link>] [-s [-i <interval>]] "
"[<link>]\n" },
{ "create-etherstub", do_create_etherstub,
" create-etherstub [-t] <link>" },
{ "delete-etherstub", do_delete_etherstub,
" delete-etherstub [-t] <link>" },
{ "show-etherstub", do_show_etherstub,
" show-etherstub [-t] [<link>]\n" },
{ "show-usage", do_show_usage,
" show-usage [-d|-p -F <format>] "
};
{ 0, 0, 0, 0 }
};
static const struct option show_lopts[] = {
{ 0, 0, 0, 0 }
};
static const struct option prop_longopts[] = {
{ 0, 0, 0, 0 }
};
static const struct option wifi_longopts[] = {
{ 0, 0, 0, 0 }
};
static const struct option showeth_lopts[] = {
{ 0, 0, 0, 0 }
};
static const struct option vnic_lopts[] = {
{ 0, 0, 0, 0 }
};
static const struct option etherstub_lopts[] = {
{ 0, 0, 0, 0 }
};
/*
* structures for 'dladm show-ether'
*/
static const char *ptype[] = {LEI_ATTR_NAMES};
typedef struct ether_fields_buf_s
{
char eth_link[15];
char eth_ptype[8];
char eth_state[8];
char eth_autoneg[5];
char eth_spdx[31];
char eth_pause[6];
char eth_rem_fault[16];
static print_field_t ether_fields[] = {
/* name, header, field width, offset, cmdtype */
{ "link", "LINK", 15,
{ "ptype", "PTYPE", 8,
{ "state", "STATE", 8,
{ "auto", "AUTO", 5,
{ "speed-duplex", "SPEED-DUPLEX", 31,
{ "pause", "PAUSE", 6,
{ "rem_fault", "REM_FAULT", 16,
;
typedef struct print_ether_state {
const char *es_link;
/*
* structures for 'dladm show-link -s' (print statistics)
*/
typedef enum {
static print_field_t devs_fields[] = {
/* name, header, field width, index, cmdtype */
;
/*
* buffer used by print functions for show-{link,phys,vlan} commands.
*/
typedef struct link_fields_buf_s {
char link_name[MAXLINKNAMELEN];
char link_class[DLADM_STRSIZE];
char link_mtu[11];
char link_state[DLADM_STRSIZE];
char link_over[MAXLINKNAMELEN];
char link_phys_state[DLADM_STRSIZE];
char link_phys_media[DLADM_STRSIZE];
char link_phys_speed[DLADM_STRSIZE];
char link_flags[6];
char link_vlan_vid[6];
/*
* structures for 'dladm show-link'
*/
static print_field_t link_fields[] = {
/* name, header, field width, offset, cmdtype */
{ "link", "LINK", 11,
{ "class", "CLASS", 8,
{ "mtu", "MTU", 6,
{ "state", "STATE", 8,
;
/*
* structures for 'dladm show-aggr'
*/
typedef struct laggr_fields_buf_s {
char laggr_name[DLPI_LINKNAME_MAX];
char laggr_policy[9];
char laggr_lacpactivity[14];
char laggr_lacptimer[DLADM_STRSIZE];
char laggr_flags[7];
typedef struct laggr_args_s {
int laggr_lport; /* -1 indicates the aggr itself */
const char *laggr_link;
} laggr_args_t;
static print_field_t laggr_fields[] = {
/* name, header, field width, offset, cmdtype */
{ "link", "LINK", 15,
{ "policy", "POLICY", 8,
{ "lacpactivity", "LACPACTIVITY", 13,
{ "lacptimer", "LACPTIMER", 11,
{ "flags", "FLAGS", 7,
;
/*
* structures for 'dladm show-aggr -x'.
*/
typedef enum {
static print_field_t aggr_x_fields[] = {
/* name, header, field width, index, cmdtype */
;
#define AGGR_X_MAX_FIELDS \
(sizeof (aggr_x_fields) / sizeof (print_field_t))
/*
* structures for 'dladm show-aggr -s'.
*/
typedef enum {
static print_field_t aggr_s_fields[] = {
/* name, header, field width, index, cmdtype */
;
#define AGGR_S_MAX_FIELDS \
(sizeof (aggr_s_fields) / sizeof (print_field_t))
/*
* structures for 'dladm show-aggr -L'.
*/
typedef enum {
static print_field_t aggr_l_fields[] = {
/* name, header, field width, index, cmdtype */
;
#define AGGR_L_MAX_FIELDS \
(sizeof (aggr_l_fields) / sizeof (print_field_t))
/*
* structures for 'dladm show-phys'
*/
static print_field_t phys_fields[] = {
/* name, header, field width, offset, cmdtype */
{ "link", "LINK", 12,
{ "media", "MEDIA", 20,
{ "state", "STATE", 10,
{ "speed", "SPEED", 6,
{ "duplex", "DUPLEX", 9,
{ "device", "DEVICE", 12,
{ "flags", "FLAGS", 6,
;
/*
* structures for 'dladm show-phys -m'
*/
typedef enum {
static print_field_t phys_m_fields[] = {
/* name, header, field width, offset, cmdtype */
;
/*
* structures for 'dladm show-phys -H'
*/
typedef enum {
static print_field_t phys_h_fields[] = {
/* name, header, field width, offset, cmdtype */
;
/*
* structures for 'dladm show-vlan'
*/
static print_field_t vlan_fields[] = {
/* name, header, field width, offset, cmdtype */
{ "link", "LINK", 15,
{ "vid", "VID", 8,
{ "over", "OVER", 12,
{ "flags", "FLAGS", 6,
;
/*
* structures for 'dladm show-wifi'
*/
static print_field_t wifi_fields[] = {
;
static char *all_scan_wifi_fields =
"link,essid,bssid,sec,strength,mode,speed,bsstype";
static char *all_show_wifi_fields =
"link,status,essid,sec,strength,mode,speed,auth,bssid,bsstype";
static char *def_scan_wifi_fields =
"link,essid,bssid,sec,strength,mode,speed";
static char *def_show_wifi_fields =
"link,status,essid,sec,strength,mode,speed";
/*
* structures for 'dladm show-linkprop'
*/
typedef enum {
static print_field_t linkprop_fields[] = {
/* name, header, field width, index, cmdtype */
;
#define LINKPROP_MAX_FIELDS \
(sizeof (linkprop_fields) / sizeof (print_field_t))
#define MAX_PROP_LINE 512
typedef struct show_linkprop_state {
char ls_link[MAXLINKNAMELEN];
char *ls_line;
char **ls_propvals;
typedef struct set_linkprop_state {
const char *ls_name;
typedef struct linkprop_args_s {
char *ls_propname;
/*
* structures for 'dladm show-secobj'
*/
typedef struct secobj_fields_buf_s {
char ss_obj_name[DLADM_SECOBJ_VAL_MAX];
char ss_class[20];
char ss_val[30];
static print_field_t secobj_fields[] = {
/* name, header, field width, offset, cmdtype */
{ "object", "OBJECT", 20,
{ "class", "CLASS", 20,
{ "value", "VALUE", 30,
;
/*
* structures for 'dladm show-vnic'
*/
typedef struct vnic_fields_buf_s
{
char vnic_link[DLPI_LINKNAME_MAX];
char vnic_over[DLPI_LINKNAME_MAX];
char vnic_speed[6];
char vnic_macaddr[19];
char vnic_macaddrtype[19];
char vnic_vid[6];
static print_field_t vnic_fields[] = {
/* name, header, field width, offset, cmdtype */
{ "link", "LINK", 12,
{ "over", "OVER", 12,
{ "speed", "SPEED", 6,
{ "macaddr", "MACADDRESS", 20,
{ "macaddrtype", "MACADDRTYPE", 19,
{ "vid", "VID", 6,
;
/*
* structures for 'dladm show-usage'
*/
typedef struct usage_fields_buf_s {
char usage_link[12];
char usage_duration[10];
char usage_ipackets[9];
char usage_rbytes[10];
char usage_opackets[9];
char usage_obytes[10];
char usage_bandwidth[14];
static print_field_t usage_fields[] = {
/* name, header, field width, offset, cmdtype */
{ "link", "LINK", 12,
{ "duration", "DURATION", 10,
{ "ipackets", "IPACKETS", 9,
{ "rbytes", "RBYTES", 10,
{ "opackets", "OPACKETS", 9,
{ "obytes", "OBYTES", 10,
{ "bandwidth", "BANDWIDTH", 14,
;
/*
* structures for 'dladm show-usage link'
*/
typedef struct usage_l_fields_buf_s {
char usage_l_link[12];
char usage_l_stime[13];
char usage_l_etime[13];
char usage_l_rbytes[8];
char usage_l_obytes[8];
char usage_l_bandwidth[14];
static print_field_t usage_l_fields[] = {
/* name, header, field width, offset, cmdtype */
{ "link", "LINK", 12,
{ "start", "START", 13,
{ "end", "END", 13,
{ "rbytes", "RBYTES", 8,
{ "obytes", "OBYTES", 8,
{ "bandwidth", "BANDWIDTH", 14,
;
#define USAGE_L_MAX_FIELDS \
(sizeof (usage_l_fields) /sizeof (print_field_t))
static char *progname;
static sig_atomic_t signalled;
/*
* Handle to libdladm. Opened in main() before the sub-command
* specific function is called.
*/
#define DLADM_ETHERSTUB_NAME "etherstub"
static void
usage(void)
{
int i;
"\n"));
}
/* close dladm handle if it was opened */
exit(1);
}
int
{
int i;
#if !defined(TEXT_DOMAIN)
#define TEXT_DOMAIN "SYS_TEST"
#endif
(void) textdomain(TEXT_DOMAIN);
if (argc < 2)
usage();
/* Open the libdladm handle */
}
exit(0);
}
}
usage();
return (0);
}
/*ARGSUSED*/
static int
{
char timebuf[20];
return (DLADM_STATUS_OK);
}
static int
{
char buf[DLADM_STRSIZE];
double bw;
if (!state->us_printheader) {
(void) printf("# Time");
}
(void) printf("\n");
}
} else {
}
(void) printf("\n");
}
}
return (DLADM_STATUS_OK);
}
buf);
buf);
}
dladm_print_field, (void *)&ubuf);
return (DLADM_STATUS_OK);
}
static int
{
char buf[DLADM_STRSIZE];
}
dladm_print_field, (void *)&ubuf);
return (DLADM_STATUS_OK);
}
static boolean_t
valid_formatspec(char *formatspec_str)
{
return (B_TRUE);
return (B_FALSE);
}
/*ARGSUSED*/
static void
{
int opt;
char *fields_str = NULL;
char *formatspec_str = NULL;
char *all_fields =
"link,duration,ipackets,rbytes,opackets,obytes,bandwidth";
char *all_l_fields =
"link,start,end,rbytes,obytes,bandwidth";
switch (opt) {
case 'd':
break;
case 'p':
break;
case 'f':
break;
case 's':
break;
case 'e':
break;
case 'o':
fields_str = optarg;
break;
case 'F':
break;
default:
break;
}
}
die("show-usage requires a file");
}
} else {
}
die("invalid fields(s) specified");
return;
}
die("plot and date options are incompatible");
die("specify format speicifier: -F <format>");
if (d_arg) {
/* Print log dates */
!p_arg) {
/* Print summary */
/* Print log entries for named resource */
} else {
/* Print time and information for each link */
}
if (status != DLADM_STATUS_OK)
}
static void
{
char option;
int key = 0;
char name[MAXLINKNAMELEN];
int i;
switch (option) {
case 'd':
die("too many ports specified");
break;
case 'P':
if (P_arg)
break;
case 'u':
if (u_arg)
mac_addr))
break;
case 'l':
/*
* Ended with digit, possibly a link name.
*/
die("too many ports specified");
break;
}
/* FALLTHROUGH */
case 'L':
if (l_arg)
break;
case 'T':
if (T_arg)
break;
case 't':
flags &= ~DLADM_OPT_PERSIST;
break;
case 'f':
flags |= DLADM_OPT_FORCE;
break;
case 'R':
break;
case 'p':
!= DLADM_STATUS_OK)
die("invalid aggregation property");
break;
default:
break;
}
}
usage();
/* get key value or the aggregation name (required last argument) */
usage();
}
if (!dladm_valid_linkname(name))
} else {
}
for (n = 0; n < ndev; n++) {
}
}
for (n = 0; n < nlink; n++) {
}
}
lacp_timer, flags);
if (status != DLADM_STATUS_OK)
goto done;
return;
if (status != DLADM_STATUS_OK)
goto done;
if (pstatus != DLADM_STATUS_OK) {
"aggr creation succeeded but "
}
}
done:
if (status != DLADM_STATUS_OK) {
if (status == DLADM_STATUS_NONOTIF) {
"detection; must use -f (see dladm(1M))\n");
} else {
}
}
}
/*
* arg is either the key or the aggr name. Validate it and convert it to
* the linkid if altroot is NULL.
*/
static dladm_status_t
{
int key = 0;
return (DLADM_STATUS_LINKINVAL);
return (DLADM_STATUS_OK);
NULL);
} else {
}
return (status);
}
static void
{
char option;
opterr = 0;
switch (option) {
case 't':
flags &= ~DLADM_OPT_PERSIST;
break;
case 'R':
break;
default:
break;
}
}
/* get key value or the aggregation name (required last argument) */
usage();
if (status != DLADM_STATUS_OK)
goto done;
done:
if (status != DLADM_STATUS_OK)
}
static void
{
char option;
NULL)) != -1) {
switch (option) {
case 'd':
die("too many ports specified");
break;
case 'l':
die("too many ports specified");
break;
case 't':
flags &= ~DLADM_OPT_PERSIST;
break;
case 'f':
flags |= DLADM_OPT_FORCE;
break;
case 'R':
break;
default:
break;
}
}
usage();
/* get key value or the aggregation name (required last argument) */
usage();
goto done;
}
for (n = 0; n < ndev; n++) {
}
}
for (n = 0; n < nlink; n++) {
}
}
done:
if (status != DLADM_STATUS_OK) {
/*
* checking DLADM_STATUS_NOTSUP is a temporary workaround
* and should be removed once 6399681 is fixed.
*/
if (status == DLADM_STATUS_NOTSUP) {
gettext("%s: add operation failed: %s\n"),
gettext("link capabilities don't match"));
} else if (status == DLADM_STATUS_NONOTIF) {
"detection; must use -f (see dladm(1M))\n");
} else {
}
}
}
static void
{
char option;
switch (option) {
case 'd':
die("too many ports specified");
break;
case 'l':
die("too many ports specified");
break;
case 't':
flags &= ~DLADM_OPT_PERSIST;
break;
case 'R':
break;
default:
break;
}
}
usage();
/* get key value or the aggregation name (required last argument) */
usage();
if (status != DLADM_STATUS_OK)
goto done;
for (n = 0; n < ndev; n++) {
}
}
for (n = 0; n < nlink; n++) {
}
}
done:
if (status != DLADM_STATUS_OK)
}
static void
{
char option;
uint8_t modify_mask = 0;
opterr = 0;
NULL)) != -1) {
switch (option) {
case 'P':
break;
case 'u':
if (modify_mask & DLADM_AGGR_MODIFY_MAC)
mac_addr))
break;
case 'l':
case 'L':
break;
case 'T':
break;
case 't':
flags &= ~DLADM_OPT_PERSIST;
break;
case 'R':
break;
default:
break;
}
}
if (modify_mask == 0)
die("at least one of the -PulT options must be specified");
/* get key value or the aggregation name (required last argument) */
usage();
if (status != DLADM_STATUS_OK)
goto done;
flags);
done:
if (status != DLADM_STATUS_OK)
}
/*ARGSUSED*/
static void
{
/*
* get the key or the name of the aggregation (optional last argument)
*/
if (argc == 2) {
goto done;
} else if (argc > 2) {
usage();
}
done:
if (status != DLADM_STATUS_OK) {
if (argc == 2) {
} else {
}
}
}
static void
{
char drv[DLPI_LINKNAME_MAX];
int vid = 0;
char option;
char vlan[MAXLINKNAMELEN];
opterr = 0;
switch (option) {
case 'v':
if (vid != 0)
break;
case 'l':
break;
case 't':
flags &= ~DLADM_OPT_PERSIST;
break;
case 'R':
break;
case 'p':
!= DLADM_STATUS_OK) {
die("invalid vlan property");
}
break;
case 'f':
flags |= DLADM_OPT_FORCE;
break;
default:
break;
}
}
/* get vlan name if there is any */
usage();
}
} else {
(ppa >= 1000) ||
DLPI_SUCCESS)) {
}
}
}
}
}
static void
{
char option;
opterr = 0;
switch (option) {
case 't':
flags &= ~DLADM_OPT_PERSIST;
break;
case 'R':
break;
default:
break;
}
}
/* get VLAN link name (required last argument) */
usage();
NULL);
if (status != DLADM_STATUS_OK)
goto done;
done:
if (status != DLADM_STATUS_OK)
}
/*ARGSUSED*/
static void
{
}
static void
{
char option;
opterr = 0;
switch (option) {
case 'R':
break;
default:
break;
}
}
/* get link1 and link2 name (required the last 2 arguments) */
usage();
}
/*ARGSUSED*/
static void
{
/* get link name (required the last argument) */
if (argc > 2)
usage();
if (argc == 2) {
}
if (argc == 2)
else
}
}
/*ARGSUSED*/
static int
{
char name[MAXLINKNAMELEN];
char mediabuf[DLADM_STRSIZE];
char classbuf[DLADM_STRSIZE];
MAXLINKNAMELEN) == DLADM_STATUS_OK) {
}
return (DLADM_WALK_CONTINUE);
}
/*ARGSUSED*/
static void
{
if (argc != 1)
die("invalid arguments");
"CLASS", "MEDIA", "FLAGS");
}
/*
* Delete inactive physical links.
*/
/*ARGSUSED*/
static int
{
!= DLADM_STATUS_OK) {
return (DLADM_WALK_CONTINUE);
}
return (DLADM_WALK_CONTINUE);
}
/*ARGSUSED*/
static void
{
if (argc > 1)
usage();
/*
* Force all the devices to attach, therefore all the network physical
* devices can be known to the dlmgmtd daemon.
*/
}
/*
* Print the active topology information.
*/
static dladm_status_t
{
char tmpbuf[MAXLINKNAMELEN];
if (!state->ls_parseable)
else
if (class == DATALINK_CLASS_VLAN) {
if (status != DLADM_STATUS_OK)
goto done;
if (status != DLADM_STATUS_OK)
goto done;
} else if (class == DATALINK_CLASS_AGGR) {
int i;
if (status != DLADM_STATUS_OK)
goto done;
goto done;
}
if (status != DLADM_STATUS_OK) {
goto done;
}
}
}
} else if (class == DATALINK_CLASS_VNIC) {
goto done;
}
}
done:
return (status);
}
static dladm_status_t
{
char link[MAXLINKNAMELEN];
goto done;
}
goto done;
}
if (class == DATALINK_CLASS_PHYS) {
DLADM_OPT_ACTIVE)) != DLADM_STATUS_OK) {
goto done;
}
if (!dpa.dp_novanity)
goto link_mtu;
/*
* This is a physical link that does not have
* vanity naming support.
*/
DLPI_SUCCESS) {
goto done;
}
dlpi_close(dh);
goto done;
}
dlpi_close(dh);
} else {
if (status != DLADM_STATUS_OK)
goto done;
}
}
"%s", link);
"%u", mtu);
}
if (status != DLADM_STATUS_OK)
goto done;
done:
return (status);
}
/* ARGSUSED */
static int
{
/*
* first get all the link attributes into lbuf;
*/
if (status != DLADM_STATUS_OK)
goto done;
}
dladm_print_field, (void *)&lbuf);
done:
return (DLADM_WALK_CONTINUE);
}
static int
{
char link[DLPI_LINKNAME_MAX];
if (state->ls_firstonly) {
if (state->ls_donefirst)
return (DLADM_WALK_CONTINUE);
} else {
}
DLPI_LINKNAME_MAX) != DLADM_STATUS_OK) {
return (DLADM_WALK_CONTINUE);
}
if (class == DATALINK_CLASS_PHYS) {
return (DLADM_WALK_CONTINUE);
}
if (dpa.dp_novanity)
else
} else {
}
return (DLADM_WALK_CONTINUE);
}
static dladm_status_t
{
"%s", link);
if (ginfop->lg_mac_fixed) {
} else {
}
}
dladm_print_field, (void *)&lbuf);
return (DLADM_STATUS_OK);
}
static char *
{
const laggr_args_t *l = arg;
int portnum;
static char buf[DLADM_STRSIZE];
stat = l->laggr_status;
*stat = DLADM_STATUS_OK;
if (is_port) {
portnum = l->laggr_lport;
goto err;
}
goto err;
}
}
case AGGR_X_LINK:
break;
case AGGR_X_PORT:
if (is_port)
break;
return ("");
break;
case AGGR_X_SPEED:
if (is_port) {
B_FALSE)) / 1000000ull));
} else {
B_TRUE)) / 1000000ull));
}
break;
case AGGR_X_DUPLEX:
if (is_port)
else
break;
case AGGR_X_STATE:
if (is_port)
else
break;
case AGGR_X_ADDRESS:
(void) dladm_aggr_macaddr2str(
buf);
break;
case AGGR_X_PORTSTATE:
if (is_port)
(void) dladm_aggr_portstate2str(
else
return ("");
break;
}
return (buf);
err:
buf[0] = '\0';
return (buf);
}
static dladm_status_t
{
int i;
}
if (status != DLADM_STATUS_OK)
goto done;
largs.laggr_lport = i;
if (status != DLADM_STATUS_OK)
goto done;
}
done:
return (status);
}
static char *
{
const laggr_args_t *l = arg;
int portnum;
static char buf[DLADM_STRSIZE];
if (!is_port) {
return (NULL); /* cannot happen! */
}
stat = l->laggr_status;
portnum = l->laggr_lport;
goto err;
}
case AGGR_L_LINK:
break;
case AGGR_L_PORT:
break;
case AGGR_L_AGGREGATABLE:
break;
case AGGR_L_SYNC:
break;
case AGGR_L_COLL:
break;
case AGGR_L_DIST:
break;
case AGGR_L_DEFAULTED:
break;
case AGGR_L_EXPIRED:
break;
}
*stat = DLADM_STATUS_OK;
return (buf);
err:
buf[0] = '\0';
return (buf);
}
static dladm_status_t
{
int i;
}
largs.laggr_lport = i;
if (status != DLADM_STATUS_OK)
goto done;
}
done:
return (status);
}
static char *
{
const laggr_args_t *l = arg;
int portnum;
static char buf[DLADM_STRSIZE];
stat = l->laggr_status;
*stat = DLADM_STATUS_OK;
if (is_port) {
portnum = l->laggr_lport;
goto err;
}
goto err;
}
}
case AGGR_S_LINK:
break;
case AGGR_S_PORT:
if (is_port)
break;
return ("");
break;
case AGGR_S_IPKTS:
if (is_port) {
} else {
l->laggr_pktsumtot->ipackets);
}
break;
case AGGR_S_RBYTES:
if (is_port) {
} else {
l->laggr_pktsumtot->rbytes);
}
break;
case AGGR_S_OPKTS:
if (is_port) {
} else {
l->laggr_pktsumtot->opackets);
}
break;
case AGGR_S_OBYTES:
if (is_port) {
} else {
l->laggr_pktsumtot->obytes);
}
break;
case AGGR_S_IPKTDIST:
if (is_port) {
(double)diff_stats.opackets/
} else {
return ("");
}
break;
case AGGR_S_OPKTDIST:
if (is_port) {
(double)diff_stats.opackets/
} else {
return ("");
}
break;
}
return (buf);
err:
buf[0] = '\0';
return (buf);
}
static dladm_status_t
{
int i;
/* sum the ports statistics */
DLADM_OPT_ACTIVE)) != DLADM_STATUS_OK) {
goto done;
}
&state->gs_prevstats[i]);
}
}
if (status != DLADM_STATUS_OK)
goto done;
largs.laggr_lport = i;
if (status != DLADM_STATUS_OK)
goto done;
}
done:
return (status);
}
static dladm_status_t
{
char link[MAXLINKNAMELEN];
return (status);
}
return (DLADM_STATUS_NOTFOUND);
if (status != DLADM_STATUS_OK)
return (status);
else if (state->gs_extended)
else
done:
return (status);
}
/* ARGSUSED */
static int
{
goto done;
done:
return (DLADM_WALK_CONTINUE);
}
static void
{
int option;
char linkname[MAXLINKNAMELEN];
int interval = 0;
char *fields_str = NULL;
char *all_active_fields = "link,class,mtu,state,over";
char *all_inactive_fields = "link,class,over";
char *allstat_fields =
"link,ipackets,rbytes,ierrors,opackets,obytes,oerrors";
opterr = 0;
switch (option) {
case 'p':
if (p_arg)
break;
case 's':
if (s_arg)
break;
case 'P':
if (flags != DLADM_OPT_ACTIVE)
break;
case 'S':
if (S_arg)
break;
case 'o':
fields_str = optarg;
break;
case 'i':
if (i_arg)
break;
default:
break;
}
}
die("the option -i can be used only with -s or -S");
die("the -s option cannot be used with -S");
die("the option -P cannot be used with -s");
/* get link name (optional last argument) */
uint32_t f;
>= MAXLINKNAMELEN) {
gettext("%s: link name too long\n"),
progname);
exit(1);
}
}
if (!(f & flags)) {
"a temporary link" : "temporarily removed");
}
usage();
}
die("-p requires -o");
if (S_arg) {
return;
}
die("\"-o all\" is invalid with -p");
if (s_arg)
else if (flags & DLADM_OPT_ACTIVE)
else
}
if (s_arg) {
return;
}
CMD_TYPE_ANY, &nfields);
die("invalid field(s) specified");
if (linkid == DATALINK_ALL_LINKID) {
} else {
}
}
}
static void
{
int option;
int interval = 0;
int key;
char *fields_str = NULL;
char *all_fields =
"link,policy,addrpolicy,lacpactivity,lacptimer,flags";
char *all_lacp_fields =
"link,port,aggregatable,sync,coll,dist,defaulted,expired";
char *all_stats_fields =
"link,port,ipackets,rbytes,opackets,obytes,ipktdist,opktdist";
char *all_extended_fields =
"link,port,speed,duplex,state,address,portstate";
int pfmax;
opterr = 0;
switch (option) {
case 'L':
if (L_arg)
break;
case 'p':
if (p_arg)
break;
case 'x':
if (x_arg)
break;
case 'P':
if (flags != DLADM_OPT_ACTIVE)
break;
case 's':
if (s_arg)
break;
case 'o':
fields_str = optarg;
break;
case 'i':
if (i_arg)
break;
default:
break;
}
}
die("-p requires -o");
die("\"-o all\" is invalid with -p");
die("the option -i can be used only with -s");
die("the option -%c cannot be used with -s",
}
die("the option -P cannot be used with -L");
/* get aggregation key or aggrname (optional last argument) */
} else {
}
if (status != DLADM_STATUS_OK)
usage();
}
else if (state.gs_extended)
else
}
pf = aggr_l_fields;
pf = aggr_s_fields;
} else if (state.gs_extended) {
pf = aggr_x_fields;
} else {
pf = laggr_fields;
}
&nfields);
die("invalid field(s) specified");
return;
}
if (s_arg) {
return;
}
if (linkid == DATALINK_ALL_LINKID) {
} else {
}
}
}
static dladm_status_t
{
if (status != DLADM_STATUS_OK)
goto done;
if (!dpa.dp_novanity) {
} else {
/*
* This is a physical link that does not have
* vanity naming support.
*/
}
islink)) / 1000000ull));
} else {
"%s", link);
}
}
dladm_print_field, (void *)&pattr);
done:
return (status);
}
typedef struct {
char *ms_link;
/* callback of dladm_print_output() */
static char *
{
static char buf[DLADM_STRSIZE];
case PHYS_M_LINK:
break;
case PHYS_M_SLOT:
if (is_primary)
else
break;
case PHYS_M_ADDRESS:
break;
case PHYS_M_INUSE:
gettext("no"));
break;
case PHYS_M_CLIENT:
/*
* CR 6678526: resolve link id to actual link name if
* it is valid.
*/
break;
}
return (buf);
}
typedef struct {
char *hs_link;
static char *
{
static char buf[DLADM_STRSIZE];
case PHYS_H_LINK:
break;
case PHYS_H_GROUP:
break;
case PHYS_H_GRPTYPE:
break;
case PHYS_H_RINGS:
break;
case PHYS_H_CLIENTS:
} else {
}
break;
}
return (buf);
}
/* callback of dladm_walk_macaddr, invoked for each MAC address slot */
static boolean_t
{
}
return (B_TRUE);
}
/* invoked by show-phys -m for each physical data-link */
static dladm_status_t
{
}
/* callback of dladm_walk_hwgrp, invoked for each MAC hwgrp */
static boolean_t
{
}
return (B_TRUE);
}
/* invoked by show-phys -H for each physical data-link */
static dladm_status_t
{
}
static dladm_status_t
{
char link[MAXLINKNAMELEN];
goto done;
}
if (class != DATALINK_CLASS_PHYS) {
goto done;
}
goto done;
}
else
done:
return (status);
}
/* ARGSUSED */
static int
{
return (DLADM_WALK_CONTINUE);
}
/*
* Print the active topology information.
*/
static dladm_status_t
{
goto done;
}
goto done;
}
goto done;
}
done:
return (status);
}
/* ARGSUSED */
static int
{
if (status != DLADM_STATUS_OK)
goto done;
}
dladm_print_field, (void *)&lbuf);
done:
return (DLADM_WALK_CONTINUE);
}
static void
{
int option;
char *fields_str = NULL;
char *all_active_fields =
"link,media,state,speed,duplex,device";
char *all_inactive_fields = "link,device,media,flags";
char *all_mac_fields = "link,slot,address,inuse,client";
char *all_hwgrp_fields =
"link,group,grouptype,rings,clients";
int pfmax;
opterr = 0;
switch (option) {
case 'p':
if (p_arg)
break;
case 'P':
if (flags != DLADM_OPT_ACTIVE)
break;
case 'o':
fields_str = optarg;
break;
case 'm':
break;
case 'H':
break;
default:
break;
}
}
die("-p requires -o");
die("-m cannot combine with -H");
die("\"-o all\" is invalid with -p");
/* get link name (optional last argument) */
}
usage();
}
/*
* We can only display the factory MAC addresses of
* active data-links.
*/
die("-m not compatible with -P");
}
} else {
}
}
pf = phys_m_fields;
pf = phys_h_fields;
} else {
pf = phys_fields;
}
die("invalid field(s) specified");
return;
}
if (linkid == DATALINK_ALL_LINKID) {
} else {
}
}
}
static void
{
int option;
char *fields_str = NULL;
char *all_fields = "link,vid,over,flags";
opterr = 0;
switch (option) {
case 'p':
if (p_arg)
break;
case 'P':
if (flags != DLADM_OPT_ACTIVE)
break;
case 'o':
fields_str = optarg;
break;
default:
break;
}
}
die("-p requires -o");
die("\"-o all\" is invalid with -p");
/* get link name (optional last argument) */
}
usage();
}
CMD_TYPE_ANY, &nfields);
die("invalid field(s) specified");
return;
}
if (linkid == DATALINK_ALL_LINKID) {
} else {
}
}
}
static void
{
char devname[MAXLINKNAMELEN];
char name[MAXLINKNAMELEN];
char option;
opterr = 0;
switch (option) {
case 't':
flags &= ~DLADM_OPT_PERSIST;
break;
case 'R':
break;
case 'l':
die("link name too long");
break;
case 'm':
/*
* A fixed MAC address must be specified
* by its value, not by the keyword 'fixed'.
*/
die("'fixed' is not a valid MAC address");
}
&mac_addr_type) != DLADM_STATUS_OK) {
/* MAC address specified by value */
if (maclen == -1)
die("invalid MAC address");
else
die("out of memory");
}
}
break;
case 'n':
errno = 0;
die("invalid slot number");
break;
case 'p':
!= DLADM_STATUS_OK)
die("invalid vnic property");
break;
case 'r':
if (mac_prefix_len == -1)
die("invalid MAC address");
else
die("out of memory");
}
break;
case 'v':
/* VID of 0 is invalid */
die("invalid VLAN id");
break;
case 'f':
flags |= DLADM_OPT_FORCE;
break;
case 'H':
break;
default:
}
}
/*
* 'f' - force, flag can be specified only with 'v' - vlan.
*/
die("-f option can only be used with -v");
usage();
/* check required options */
if (!l_arg)
usage();
usage();
/* the VNIC id is the required operand */
usage();
if (!dladm_valid_linkname(name))
flags);
if (status != DLADM_STATUS_OK)
}
static void
{
/*
* Let the delete continue anyway.
*/
return;
}
if (is_etherstub != etherstub) {
}
}
static void
{
char option;
opterr = 0;
NULL)) != -1) {
switch (option) {
case 't':
flags &= ~DLADM_OPT_PERSIST;
break;
case 'R':
break;
default:
}
}
/* get vnic name (required last argument) */
usage();
NULL);
if (status != DLADM_STATUS_OK)
if ((flags & DLADM_OPT_ACTIVE) != 0) {
}
if ((flags & DLADM_OPT_PERSIST) != 0) {
}
if (status != DLADM_STATUS_OK)
}
static void
{
}
/* ARGSUSED */
static void
{
char *type;
/*
*/
if (argc == 2) {
NULL);
if (status != DLADM_STATUS_OK)
goto done;
} else if (argc > 2) {
usage();
}
if (vlan)
else
done:
if (status != DLADM_STATUS_OK) {
if (argc == 2) {
} else {
}
}
}
static void
{
}
static void
dump_vnics_head(const char *dev)
{
(void) printf("\tipackets rbytes opackets obytes ");
(void) printf("%%ipkts %%opkts\n");
else
(void) printf("\n");
}
static void
{
if (tot_stats) {
(void) printf("\t-");
} else {
}
(void) printf("\t-");
} else {
}
}
(void) printf("\n");
*old_stats = *vnic_stats;
}
/*
* Called from the walker dladm_vnic_walk_sys() for each vnic to display
* vnic information or statistics.
*/
static dladm_status_t
{
char devname[MAXLINKNAMELEN];
char vnic_name[MAXLINKNAMELEN];
return (status);
/*
* Want all etherstub but it's not one, or want
* non-etherstub and it's one.
*/
return (DLADM_STATUS_OK);
}
return (DLADM_STATUS_OK);
}
return (DLADM_STATUS_BADARG);
if (!is_etherstub &&
return (DLADM_STATUS_BADARG);
/* print vnic statistics */
if (state->vs_firstonly) {
if (state->vs_donefirst)
return (0);
}
if (!state->vs_printstats) {
/*
* get vnic statistics and add to the sum for the
* named device.
*/
} else {
/* get and print vnic statistics */
&state->vs_totalstats);
}
return (DLADM_STATUS_OK);
} else {
"%s", vnic_name);
if (!is_etherstub) {
"%s", devname);
/ 1000000ull));
switch (vnic->va_mac_addr_type) {
case VNIC_MAC_ADDR_TYPE_FIXED:
sizeof (vbuf.vnic_macaddrtype),
gettext("fixed"));
break;
sizeof (vbuf.vnic_macaddrtype),
gettext("random"));
break;
sizeof (vbuf.vnic_macaddrtype),
gettext("factory, slot %d"),
vnic->va_mac_slot);
break;
}
mstr));
}
}
}
dladm_print_field, (void *)&vbuf);
return (DLADM_STATUS_OK);
}
}
/* ARGSUSED */
static int
{
return (DLADM_WALK_CONTINUE);
}
static void
{
int option;
char *fields_str = NULL;
int pfmax;
char *all_fields =
"link,over,speed,macaddr,macaddrtype,vid";
char *all_e_fields =
"link";
opterr = 0;
NULL)) != -1) {
switch (option) {
case 'p':
break;
case 'P':
break;
case 'l':
if (etherstub)
die("option not supported for this command");
die("link name too long");
break;
case 's':
if (s_arg) {
die("the option -s cannot be specified "
"more than once");
}
break;
case 'i':
if (i_arg) {
die("the option -i cannot be specified "
"more than once");
}
break;
case 'o':
fields_str = optarg;
break;
default:
}
}
die("-p requires -o");
die("\"-o all\" is invalid with -p");
die("the option -i can be used only with -s");
/* get vnic ID (optional last argument) */
if (status != DLADM_STATUS_OK) {
}
usage();
}
if (l_arg) {
if (status != DLADM_STATUS_OK) {
}
}
if (etherstub)
else
}
pf = vnic_fields;
&nfields);
die("invalid field(s) specified");
return;
}
if (s_arg) {
/* Display vnic statistics */
return;
}
/* Display vnic information */
if (linkid == DATALINK_ALL_LINKID) {
} else {
}
}
}
static void
{
}
static void
{
char option;
char name[MAXLINKNAMELEN];
name[0] = '\0';
opterr = 0;
switch (option) {
case 't':
flags &= ~DLADM_OPT_PERSIST;
break;
case 'R':
break;
default:
}
}
/* the etherstub id is the required operand */
usage();
if (!dladm_valid_linkname(name))
if (status != DLADM_STATUS_OK)
}
static void
{
}
/* ARGSUSED */
static void
{
}
static void
{
CMD_TYPE_ANY, &nfields);
die("invalid field(s) specified");
return;
}
/*
* If an interval is specified, continuously show the stats
* only for the first MAC port.
*/
if (!state->ls_parseable)
for (;;) {
if (linkid == DATALINK_ALL_LINKID) {
} else {
}
if (interval == 0)
break;
}
}
static void
{
/*
* If an interval is specified, continuously show the stats
* only for the first group.
*/
for (;;) {
if (linkid == DATALINK_ALL_LINKID)
else
if (interval == 0)
break;
}
}
/* ARGSUSED */
static void
{
/* Display vnic statistics */
/*
* If an interval is specified, and a vnic ID is not specified,
* continuously show the stats only for the first vnic.
*/
for (;;) {
/* Get stats for each vnic */
if (!specific_link) {
} else {
}
}
/* Show totals */
(void) printf("Total");
(void) printf("\t%-10llu",
(void) printf("%-12llu",
(void) printf("%-10llu",
(void) printf("%-12llu\n",
}
/* Show stats for each vnic */
if (!specific_link) {
} else {
}
}
if (interval == 0)
break;
}
}
static void
{
char module[DLPI_LINKNAME_MAX];
return;
warn("kstat open operation failed");
return;
}
(void) kstat_close(kcp);
}
static void
{
warn("kstat_open operation failed");
return;
}
(void) kstat_close(kcp);
}
static int
{
warn("kstat open operation failed");
return (-1);
}
/*
* The kstat query could fail if the underlying MAC
* driver was already detached.
*/
goto bail;
}
warn("kstat read failed");
goto bail;
}
goto bail;
(void) kstat_close(kcp);
return (0);
bail:
(void) kstat_close(kcp);
return (-1);
}
static int
{
char module[DLPI_LINKNAME_MAX];
if (islink) {
} else {
return (-1);
}
}
static uint64_t
{
return (ifspeed);
}
static const char *
{
return (buf);
}
}
static const char *
{
&linkduplex, islink) != 0) {
return (buf);
}
}
typedef struct {
char *s_buf;
char **s_fields; /* array of pointer to the fields in s_buf */
} split_t;
/*
* Free the split_t structure pointed to by `sp'.
*/
static void
{
}
/*
* Split `str' into at most `maxfields' fields, each field at most `maxlen' in
* length. Return a pointer to a split_t containing the split fields, or NULL
* on failure.
*/
static split_t *
{
return (NULL);
return (NULL);
goto fail;
goto fail;
}
return (sp);
fail:
return (NULL);
}
static int
{
if (cmdtype == WIFI_CMD_SCAN) {
} else if (cmdtype == WIFI_CMD_SHOW) {
} else {
return (-1);
}
return (0);
return (-1);
}
static print_field_t **
{
uint_t i, j;
return (NULL);
goto fail;
for (j = 0; j < max_fields; j++) {
break;
}
}
if (!good_match)
goto fail;
}
*countp = i;
return (pf);
fail:
return (NULL);
}
typedef struct print_wifi_state {
char *ws_link;
typedef struct wlan_scan_args_s {
void *ws_attr;
static void
{
/*
* Parsable fields are separated by ':'. If such a field contains
* a ':' or '\', this character is prefixed by a '\'.
*/
if (parseable) {
char c;
return;
}
while ((c = *value++) != '\0') {
if (c == ':' || c == '\\')
(void) putchar('\\');
(void) putchar(c);
}
if (!statep->ps_lastfield)
(void) putchar(':');
return;
} else {
if (value[0] == '\0')
if (statep->ps_lastfield) {
statep->ps_overflow = 0;
return;
}
}
}
if (!statep->ps_lastfield)
(void) putchar(' ');
}
static char *
{
static char buf[DLADM_STRSIZE];
wlan_scan_args_t *w = warg;
}
return ("");
}
case DLADM_WLAN_ATTR_ESSID:
break;
case DLADM_WLAN_ATTR_BSSID:
break;
case DLADM_WLAN_ATTR_SECMODE:
break;
case DLADM_WLAN_ATTR_STRENGTH:
break;
case DLADM_WLAN_ATTR_MODE:
break;
case DLADM_WLAN_ATTR_SPEED:
break;
case DLADM_WLAN_ATTR_AUTH:
break;
case DLADM_WLAN_ATTR_BSSTYPE:
break;
}
return (buf);
}
static boolean_t
{
if (!statep->ws_parseable)
}
print_wlan_attr, &warg);
return (B_TRUE);
}
static int
{
char link[MAXLINKNAMELEN];
sizeof (link))) != DLADM_STATUS_OK) {
return (DLADM_WALK_CONTINUE);
}
if (status != DLADM_STATUS_OK)
return (DLADM_WALK_CONTINUE);
}
static char *
{
static char buf[DLADM_STRSIZE];
char *ptr;
(void) dladm_wlan_linkstatus2str(
return (buf);
}
return (ptr);
}
static int
{
char link[MAXLINKNAMELEN];
sizeof (link))) != DLADM_STATUS_OK) {
return (DLADM_WALK_CONTINUE);
}
/* dladm_wlan_get_linkattr() memsets attr with 0 */
if (status != DLADM_STATUS_OK)
if (!statep->ws_parseable)
}
print_link_attr, &warg);
return (DLADM_WALK_CONTINUE);
}
static void
{
int option;
char *fields_str = NULL;
if (cmd == WIFI_CMD_SCAN)
else if (cmd == WIFI_CMD_SHOW)
else
return;
opterr = 0;
switch (option) {
case 'o':
fields_str = optarg;
break;
case 'p':
break;
default:
}
}
die("-p requires -o");
die("\"-o all\" is invalid with -p");
}
usage();
}
die("invalid field(s) specified");
if (linkid == DATALINK_ALL_LINKID) {
} else {
}
}
static void
{
}
static void
{
}
typedef struct wlan_count_attr {
/* ARGSUSED */
static int
{
return (DLADM_WALK_CONTINUE);
}
static int
{
uint_t i;
return (-1);
goto fail;
char *s;
goto fail;
*s = '\0';
}
if (status != DLADM_STATUS_OK) {
if (status == DLADM_STATUS_NOTFOUND) {
}
if (status != DLADM_STATUS_OK)
goto fail;
}
}
*key_countp = i;
return (0);
fail:
return (-1);
}
static void
{
int option;
char buf[DLADM_STRSIZE];
opterr = 0;
switch (option) {
case 'e':
if (status != DLADM_STATUS_OK)
/*
* Try to connect without doing a scan.
*/
break;
case 'i':
if (status != DLADM_STATUS_OK)
break;
case 'a':
if (status != DLADM_STATUS_OK)
break;
case 'm':
if (status != DLADM_STATUS_OK)
break;
case 'b':
}
break;
case 's':
}
break;
case 'k':
else
break;
case 'T':
timeout = -1;
break;
}
break;
case 'c':
break;
default:
break;
}
}
if (keysecmode == DLADM_WLAN_SECMODE_NONE) {
die("key required for security mode '%s'",
}
} else {
die("incompatible -s and -k options");
}
}
usage();
}
if (linkid == DATALINK_ALL_LINKID) {
die("no wifi links are available");
die("link name is required when more than one wifi "
"link is available");
}
}
if ((flags & DLADM_WLAN_CONNECT_NOSCAN) != 0) {
/*
* Try again with scanning and filtering.
*/
goto again;
}
if (status == DLADM_STATUS_NOTFOUND) {
die("no wifi networks are available");
} else {
die("no wifi networks with the specified "
"criteria are available");
}
}
}
}
/* ARGSUSED */
static int
{
if (status != DLADM_STATUS_OK)
return (DLADM_WALK_CONTINUE);
}
static void
{
int option;
opterr = 0;
switch (option) {
case 'a':
break;
default:
break;
}
}
}
usage();
}
if (linkid == DATALINK_ALL_LINKID) {
if (!all_links) {
die("no wifi links are available");
die("link name is required when more than "
"one wifi link is available");
}
} else {
return;
}
}
if (status != DLADM_STATUS_OK)
}
static void
char **pptr)
{
int i;
char buf[DLADM_STRSIZE];
&valcnt);
if (status != DLADM_STATUS_OK) {
if (status == DLADM_STATUS_TEMPONLY) {
if (type == DLADM_PROP_VAL_MODIFIABLE &&
statep->ls_persist) {
valcnt = 1;
} else {
return;
}
} else if (status == DLADM_STATUS_NOTSUP ||
statep->ls_persist) {
valcnt = 1;
if (type == DLADM_PROP_VAL_CURRENT ||
else
} else if (status == DLADM_STATUS_NOTDEFINED) {
} else {
if (statep->ls_proplist &&
"cannot get link property '%s' for %s",
}
return;
}
}
for (i = 0; i < valcnt; i++) {
else
break;
}
if (valcnt > 0)
if (statep->ls_parseable) {
"%s", buf);
} else {
}
}
static char *
{
case LINKPROP_LINK:
break;
case LINKPROP_PROPERTY:
break;
case LINKPROP_VALUE:
/*
* If we failed to query the link property, for example, query
* the persistent value of a non-persistable link property,
* simply skip the output.
*/
goto skip;
break;
case LINKPROP_PERM:
goto skip;
break;
case LINKPROP_DEFAULT:
goto skip;
break;
case LINKPROP_POSSIBLE:
goto skip;
break;
default:
die("invalid input");
break;
}
return (ptr);
skip:
return (NULL);
else
return ("");
}
static boolean_t
{
/* if used with -p flag, always print output */
return (B_TRUE);
if (status == DLADM_STATUS_OK)
return (B_TRUE);
/*
* A system wide default value is not available for the
* property. Check if current value can be retrieved.
*/
return (status == DLADM_STATUS_OK);
}
/* ARGSUSED */
static int
void *arg)
{
if (!statep->ls_parseable)
}
/*
* This will need to be fixed when kernel interfaces are added
* to enable walking of all known private properties. For now,
* we are limited to walking persistent private properties only.
*/
return (DLADM_WALK_CONTINUE);
if (!statep->ls_parseable &&
return (DLADM_WALK_CONTINUE);
linkprop_callback, (void *)&ls_arg);
return (DLADM_WALK_CONTINUE);
}
static void
{
int option;
char *fields_str = NULL;
char *all_fields =
"link,property,perm,value,default,possible";
opterr = 0;
switch (option) {
case 'p':
!= DLADM_STATUS_OK)
die("invalid link properties specified");
break;
case 'c':
break;
case 'P':
break;
case 'o':
else
fields_str = optarg;
break;
default:
break;
}
}
die("-c requires -o");
die("\"-o all\" is invalid with -c");
}
usage();
}
die("invalid field(s) specified");
return;
}
if (linkid == DATALINK_ALL_LINKID) {
} else {
}
}
}
static int
{
int i;
char *buf;
return (DLADM_WALK_CONTINUE);
}
return (DLADM_WALK_CONTINUE);
}
/*
* When some WiFi links are opened for the first time, their hardware
* automatically scans for APs and does other slow operations. Thus,
* if there are no open links, the retrieval of link properties
* (below) will proceed slowly unless we hold the link open.
*
* Note that failure of dlpi_open() does not necessarily mean invalid
* link properties, because dlpi_open() may fail because of incorrect
* autopush configuration. Therefore, we ingore the return value of
* dlpi_open().
*/
if (!statep->ls_persist)
die("insufficient memory");
for (i = 0; i < DLADM_MAX_PROP_VALCNT; i++) {
sizeof (char *) * DLADM_MAX_PROP_VALCNT +
i * DLADM_PROP_VAL_MAX;
}
(sizeof (char *) + DLADM_PROP_VAL_MAX) * DLADM_MAX_PROP_VALCNT;
}
} else {
}
dlpi_close(dh);
return (DLADM_WALK_CONTINUE);
}
static dladm_status_t
{
if (status != DLADM_STATUS_OK) {
}
return (status);
}
static int
{
if (status != DLADM_STATUS_OK) {
}
if (s != DLADM_STATUS_OK)
status = s;
}
if (status != DLADM_STATUS_OK)
return (DLADM_WALK_CONTINUE);
}
static void
{
int i, option;
char errmsg[DLADM_STRSIZE];
opterr = 0;
switch (option) {
case 'p':
die("invalid link properties specified");
}
break;
case 't':
break;
case 'R':
break;
default:
}
}
/* get link name (required last argument) */
usage();
die("link property must be specified");
}
NULL);
if (status != DLADM_STATUS_OK)
goto done;
}
char **val;
if (reset) {
count = 0;
} else {
if (count == 0) {
warn("no value specified for '%s'",
continue;
}
}
if (s == DLADM_STATUS_OK) {
if (!temp) {
if (s != DLADM_STATUS_OK)
status = s;
}
continue;
}
status = s;
switch (s) {
case DLADM_STATUS_NOTFOUND:
break;
case DLADM_STATUS_BADVAL: {
int j;
die("insufficient memory");
for (j = 0; j < DLADM_MAX_PROP_VALCNT; j++) {
j * DLADM_PROP_VAL_MAX;
}
&valcnt);
if (s != DLADM_STATUS_OK) {
break;
}
*ptr = '\0';
for (j = 0; j < valcnt; j++) {
propvals[j]);
break;
}
warn("link property '%s' must be one of: %s",
} else
break;
}
default:
if (reset) {
} else {
}
break;
}
}
done:
if (status != DLADM_STATUS_OK) {
exit(1);
}
}
static void
{
}
static void
{
}
static int
{
int error = 0;
if (class == DLADM_SECOBJ_CLASS_WPA) {
return (EINVAL);
return (error);
}
if (class == DLADM_SECOBJ_CLASS_WEP) {
switch (len) {
case 5: /* ASCII key sizes */
case 13:
break;
case 10: /* Hex key sizes, not preceded by 0x */
case 26:
break;
case 12: /* Hex key sizes, preceded by 0x */
case 28:
return (EINVAL);
break;
default:
return (EINVAL);
}
return (error);
}
return (ENOENT);
}
static void
{
}
static int
{
int c;
void (*sigfunc)(int);
/*
* Turn off echo -- but before we do so, defer SIGINT handling
* so that a ^C doesn't leave the terminal corrupted.
*/
if (try == 1)
else
while (signalled == 0) {
c = getchar();
if (c == '\n' || c == '\r') {
if (len != 0)
break;
(void) putchar('\n');
goto again;
}
break;
(void) putchar('*');
}
(void) putchar('\n');
/*
* Restore terminal setting and handle deferred signals.
*/
if (signalled != 0)
return (len);
}
static int
{
int rval;
if (rval == 0) {
}
return (rval);
} else {
for (;;) {
break;
continue;
len--;
}
break;
}
}
}
static boolean_t
check_auth(const char *auth)
{
return (B_FALSE);
}
static void
{
char *errstr;
if (create) {
errstr = "ADT_dladm_create_secobj";
} else {
errstr = "ADT_dladm_delete_secobj";
}
/* fill in audit info */
if (create) {
} else {
}
if (success) {
}
} else {
ADT_FAIL_VALUE_AUTH) != 0) {
}
}
(void) adt_end_session(ah);
}
#define MAX_SECOBJS 32
#define MAX_SECOBJ_NAMELEN 32
static void
{
char *class_name = NULL;
opterr = 0;
switch (option) {
case 'f':
}
break;
case 'c':
class_name = optarg;
if (status != DLADM_STATUS_OK) {
die("invalid secure object class '%s', "
"valid values are: wep, wpa", optarg);
}
break;
case 't':
break;
case 'R':
if (status != DLADM_STATUS_OK) {
"specified");
}
break;
default:
break;
}
}
usage();
if (class == -1)
die("secure object class required");
die("secure object name required");
if (!dladm_valid_secobj_name(obj_name))
if (!success)
if (rval != 0) {
switch (rval) {
case ENOENT:
die("invalid secure object class");
break;
case EINVAL:
die("invalid secure object value");
break;
case ENOTSUP:
die("verification failed");
break;
default:
break;
}
}
if (status != DLADM_STATUS_OK) {
obj_name);
}
if (temp)
return;
if (status != DLADM_STATUS_OK) {
"object '%s'", obj_name);
}
}
static void
{
int i, option;
opterr = 0;
switch (option) {
case 't':
break;
case 'R':
if (status != DLADM_STATUS_OK) {
"specified");
}
break;
default:
break;
}
}
die("invalid secure object name(s): '%s'",
}
usage();
die("secure object name required");
if (!success)
if (!temp) {
} else {
}
if (status != DLADM_STATUS_OK) {
}
if (pstatus != DLADM_STATUS_OK) {
}
}
exit(1);
}
}
typedef struct show_secobj_state {
static boolean_t
{
char buf[DLADM_STRSIZE];
if (statep->ss_persist)
flags);
if (status != DLADM_STATUS_OK)
if (!statep->ss_parseable)
}
obj_name);
if (getuid() == 0) {
}
dladm_print_field, (void *)&sbuf);
return (B_TRUE);
}
static void
{
int option;
uint_t i;
char *fields_str = NULL;
char *def_fields = "object,class";
char *all_fields = "object,class,value";
opterr = 0;
switch (option) {
case 'p':
break;
case 'P':
break;
case 'o':
else
fields_str = optarg;
break;
default:
break;
}
}
die("option -c requires -o");
die("\"-o all\" is invalid with -p");
die("invalid field(s) specified");
return;
}
die("invalid secure object name(s): '%s'",
}
break;
}
return;
usage();
if (status != DLADM_STATUS_OK)
}
/*ARGSUSED*/
static int
{
return (DLADM_WALK_CONTINUE);
}
/*ARGSUSED*/
void
{
int option;
opterr = 0;
switch (option) {
case 'w':
break;
default:
/*
* Because init-linkprop is not a public command,
* print the usage instead.
*/
usage();
break;
}
}
usage();
}
if (linkid == DATALINK_ALL_LINKID) {
/*
* linkprops of links of other classes have been initialized as
* part of the dladm up-xxx operation.
*/
} else {
}
}
static void
{
int option;
char *fields_str;
char *all_fields =
"link,ptype,state,auto,speed-duplex,pause,rem_fault";
char *default_fields =
"link,ptype,state,auto,speed-duplex,pause";
switch (option) {
case 'x':
break;
case 'p':
break;
case 'o':
else
fields_str = optarg;
break;
default:
break;
}
}
die("-p requires -o");
die("\"-o all\" is invalid with -p");
die("invalid field(s) specified");
} else {
die("invalid link specified");
}
}
static char *
{
char *value;
return (value);
}
static int
{
return (DLADM_WALK_CONTINUE);
}
}
if (status != DLADM_STATUS_OK)
goto cleanup;
sizeof (ebuf.eth_rem_fault));
if (statep->es_extended)
return (DLADM_WALK_CONTINUE);
}
/* ARGSUSED */
static void
{
if (status != DLADM_STATUS_OK)
}
/*
* "-R" option support. It is used for live upgrading. Append dladm commands
* to a upgrade script which will be run when the alternative root boots up:
*
* - If the /etc/dladm/datalink.conf file exists on the alternative root,
* append dladm commands to the <altroot>/var/svc/profile/upgrade_datalink
* plumbs various interfaces.
*
* - If the /etc/dladm/datalink.conf file does not exist on the alternative
* which will be run in the manifest-import service.
*
* Note that the SMF team is considering to move the manifest-import service
* to be run at the very begining of boot. Once that is done, the need for
* the /var/svc/profile/upgrade_datalink script will not exist any more.
*/
static void
{
char path[MAXPATHLEN];
int i;
/*
* Check for the existence of the /etc/dladm/datalink.conf
* configuration file, and determine the name of script file.
*/
altroot);
} else {
}
for (i = 0; i < argc; i++) {
/*
* Directly write to the file if it is not the "-R <altroot>"
* option. In which case, skip it.
*/
else
i ++;
}
exit(0);
}
/*
* Convert the string to an integer. Note that the string must not have any
* trailing non-integer characters.
*/
static boolean_t
{
int val;
errno = 0;
return (B_FALSE);
return (B_TRUE);
}
/* PRINTFLIKE1 */
static void
{
(void) putchar('\n');
}
/* PRINTFLIKE2 */
static void
{
char errmsg[DLADM_STRSIZE];
}
/*
* Also closes the dladm handle if it is not NULL.
*/
/* PRINTFLIKE2 */
static void
{
char errmsg[DLADM_STRSIZE];
/* close dladm handle if it was opened */
}
/* PRINTFLIKE1 */
static void
{
(void) putchar('\n');
/* close dladm handle if it was opened */
}
static void
die_optdup(int opt)
{
}
static void
{
switch (opterr) {
case ':':
break;
case '?':
default:
break;
}
}
static void
{
int i;
sizeof (ebuf.eth_rem_fault));
}
}
static void
{
int i;
char *value;
print_field_t **pf;
for (i = 0; i < statep->ps_nfields; i++) {
}
(void) putchar('\n');
}
static void
{
int i;
print_field_t **pf;
for (i = 0; i < ps->ps_nfields; i++) {
}
(void) putchar('\n');
}
static boolean_t
{
return (B_TRUE);
}
return (B_FALSE);
}