libdladm.c revision b9e076dcc05b713d74073c0d692dfbb0f6f2c594
/*
* 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 <unistd.h>
#include <stropts.h>
#include <errno.h>
#include <ctype.h>
#include <fcntl.h>
#include <strings.h>
#include <dirent.h>
#include <libdladm_impl.h>
#include <libintl.h>
#include <libdlpi.h>
/*
* Issue an ioctl to the specified file descriptor attached to the
* DLD control driver interface.
*/
int
{
}
const char *
{
const char *s;
switch (status) {
case DLADM_STATUS_OK:
s = "ok";
break;
case DLADM_STATUS_BADARG:
s = "invalid argument";
break;
case DLADM_STATUS_FAILED:
s = "operation failed";
break;
case DLADM_STATUS_TOOSMALL:
s = "buffer size too small";
break;
case DLADM_STATUS_NOTSUP:
s = "operation not supported";
break;
case DLADM_STATUS_NOTFOUND:
s = "object not found";
break;
case DLADM_STATUS_BADVAL:
s = "invalid value";
break;
case DLADM_STATUS_NOMEM:
s = "insufficient memory";
break;
case DLADM_STATUS_EXIST:
s = "object already exists";
break;
case DLADM_STATUS_LINKINVAL:
s = "invalid link";
break;
case DLADM_STATUS_PROPRDONLY:
s = "read-only property";
break;
case DLADM_STATUS_BADVALCNT:
s = "invalid number of values";
break;
case DLADM_STATUS_DBNOTFOUND:
s = "database not found";
break;
case DLADM_STATUS_DENIED:
s = "permission denied";
break;
case DLADM_STATUS_IOERR:
s = "I/O error";
break;
case DLADM_STATUS_TEMPONLY:
s = "change cannot be persistent, specify -t please";
break;
case DLADM_STATUS_TIMEDOUT:
s = "operation timed out";
break;
case DLADM_STATUS_ISCONN:
s = "already connected";
break;
case DLADM_STATUS_NOTCONN:
s = "not connected";
break;
s = "invalid configuration repository";
break;
s = "invalid MAC address";
break;
case DLADM_STATUS_KEYINVAL:
s = "invalid key";
break;
s = "invalid MAC address length";
break;
s = "invalid MAC address type";
break;
case DLADM_STATUS_LINKBUSY:
s = "link busy";
break;
case DLADM_STATUS_VIDINVAL:
s = "invalid VLAN identifier";
break;
case DLADM_STATUS_TRYAGAIN:
s = "try again later";
break;
case DLADM_STATUS_NONOTIF:
s = "link notification is not supported";
break;
default:
s = "<unknown error>";
break;
}
return (buf);
}
/*
* Convert a unix errno to a dladm_status_t.
* We only convert errnos that are likely to be encountered. All others
* are mapped to DLADM_STATUS_FAILED.
*/
dladm_errno2status(int err)
{
switch (err) {
case 0:
return (DLADM_STATUS_OK);
case EINVAL:
return (DLADM_STATUS_BADARG);
case EEXIST:
return (DLADM_STATUS_EXIST);
case ENOENT:
return (DLADM_STATUS_NOTFOUND);
case ENOSPC:
return (DLADM_STATUS_TOOSMALL);
case ENOMEM:
return (DLADM_STATUS_NOMEM);
case ENOTSUP:
return (DLADM_STATUS_NOTSUP);
case ENETDOWN:
return (DLADM_STATUS_NONOTIF);
case EACCES:
return (DLADM_STATUS_DENIED);
case EIO:
return (DLADM_STATUS_IOERR);
case EBUSY:
return (DLADM_STATUS_LINKBUSY);
case EAGAIN:
return (DLADM_STATUS_TRYAGAIN);
default:
return (DLADM_STATUS_FAILED);
}
}
static int
{
int lock_fd;
LOCK_DB_PERMS)) < 0)
return (-1);
return (-1);
}
return (lock_fd);
}
static void
{
if (fd < 0)
return;
}
/*
* Given a link class, returns its class string.
*/
const char *
{
const char *s;
switch (class) {
case DATALINK_CLASS_PHYS:
s = "phys";
break;
case DATALINK_CLASS_VLAN:
s = "vlan";
break;
case DATALINK_CLASS_AGGR:
s = "aggr";
break;
case DATALINK_CLASS_VNIC:
s = "vnic";
break;
default:
s = "unknown";
break;
}
return (buf);
}
/*
* Given a physical link media type, returns its media type string.
*/
const char *
{
const char *s;
switch (media) {
case DL_ETHER:
s = "Ethernet";
break;
case DL_WIFI:
s = "WiFi";
break;
case DL_IB:
s = "Infiniband";
break;
case DL_IPV4:
s = "IPv4Tunnel";
break;
case DL_IPV6:
s = "IPv6Tunnel";
break;
case DL_CSMACD:
break;
case DL_TPB:
s = "TokenBus";
break;
case DL_TPR:
s = "TokenRing";
break;
case DL_METRO:
s = "MetroNet";
break;
case DL_HDLC:
s = "HDLC";
break;
case DL_CHAR:
s = "SyncCharacter";
break;
case DL_CTCA:
s = "CTCA";
break;
case DL_FDDI:
s = "FDDI";
break;
case DL_FC:
s = "FiberChannel";
break;
case DL_ATM:
s = "ATM";
break;
case DL_IPATM:
s = "ATM(ClassicIP)";
break;
case DL_X25:
s = "X.25";
break;
case DL_IPX25:
s = "X.25(ClassicIP)";
break;
case DL_ISDN:
s = "ISDN";
break;
case DL_HIPPI:
s = "HIPPI";
break;
case DL_100VG:
s = "100BaseVGEthernet";
break;
case DL_100VGTPR:
s = "100BaseVGTokenRing";
break;
case DL_ETH_CSMA:
s = "IEEE802.3";
break;
case DL_100BT:
s = "100BaseT";
break;
case DL_FRAME:
s = "FrameRelay";
break;
case DL_MPFRAME:
s = "MPFrameRelay";
break;
case DL_ASYNC:
s = "AsyncCharacter";
break;
default:
s = "--";
break;
}
return (buf);
}
{
char lock[MAXPATHLEN];
char file[MAXPATHLEN];
char newfile[MAXPATHLEN];
char *db_basename;
/*
* If we are called from a boot script such as net-physical,
* it's quite likely that the root fs is still not writable.
* For this case, it's ok for the lock creation to fail since
* no one else could be accessing our configuration file.
*/
return (dladm_errno2status(EINVAL));
db_basename++;
if ((lock_fd = i_dladm_lock_db
return (dladm_errno2status(errno));
return (DLADM_STATUS_DBNOTFOUND);
return (dladm_errno2status(err));
}
if (writeop) {
db_perms)) < 0) {
return (dladm_errno2status(errno));
}
return (dladm_errno2status(errno));
}
}
goto done;
/*
* Configuration files need to be owned by the 'dladm' user.
* If we are invoked by root, the file ownership needs to be fixed.
*/
goto done;
}
}
goto done;
}
return (dladm_errno2status(errno));
}
return (DLADM_STATUS_OK);
done:
if (status != DLADM_STATUS_OK)
}
return (status);
}
dladm_set_rootdir(const char *rootdir)
{
return (DLADM_STATUS_BADARG);
return (DLADM_STATUS_OK);
}
dladm_valid_linkname(const char *link)
{
const char *cp;
return (B_FALSE);
/*
* The link name cannot start with a digit and must end with a digit.
*/
return (B_FALSE);
/*
* The legal characters in a link name are:
* alphanumeric (a-z, A-Z, 0-9), and the underscore ('_').
*/
return (B_FALSE);
}
return (B_TRUE);
}