libdladm.c revision 0ba2cbe97e0678a691742f98d2532caed0a2c4aa
/*
* 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 2006 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 <fcntl.h>
#include <strings.h>
#include <dirent.h>
#include <libdlpi.h>
#include <libdevinfo.h>
#include <libdladm_impl.h>
typedef struct dladm_dev {
} dladm_dev_t;
typedef struct dladm_walk {
} dladm_walk_t;
/*
* Issue an ioctl to the specified file descriptor attached to the
* DLD control driver interface.
*/
int
{
}
/*
* Return the attributes of the specified datalink from the DLD driver.
*/
static int
{
return (-1);
}
return (-1);
return (0);
}
/*
* Adds a datalink to the array corresponding to arg.
*/
static void
{
while (ddp) {
/*
* Skip duplicates.
*/
return;
}
return;
}
/*
* Walker callback invoked for each DDI_NT_NET node.
*/
static int
{
int fd;
char *provider;
return (DI_WALK_CONTINUE);
(void) dlpi_close(fd);
return (DI_WALK_CONTINUE);
}
(void) dlpi_close(fd);
return (DI_WALK_CONTINUE);
}
(void) dlpi_close(fd);
return (DI_WALK_CONTINUE);
}
(void) dlpi_close(fd);
return (DI_WALK_CONTINUE);
}
/*
* Invoke the specified callback function for each active DDI_NT_NET
* node.
*/
int
{
return (-1);
}
while (ddp) {
}
return (0);
}
/*
* Invoke the specified callback function for each vlan managed by dld
*/
int
{
int nvlan = 4094;
return (-1);
return (-1);
}
/*
* Note: Callers of dladm_walk_vlan() ignore the return
* value of this routine. So ignoring ioctl failure case
* and just returning 0.
*/
return (0);
}
/*
* Returns the current attributes of the specified datalink.
*/
int
{
int fd;
return (-1);
goto failed;
return (0);
return (-1);
}
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;
default:
s = "";
}
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 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 EACCES:
return (DLADM_STATUS_DENIED);
case EIO:
return (DLADM_STATUS_IOERR);
default:
return (DLADM_STATUS_FAILED);
}
}
/*
* These are the uid and gid of the user 'dladm'.
*/
#define DLADM_DB_OWNER 15
#define DLADM_DB_GROUP 3
static int
{
int lock_fd;
LOCK_DB_PERMS)) < 0)
return (-1);
return (-1);
}
return (lock_fd);
}
static void
{
if (fd < 0)
return;
}
{
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);
}