libdladm.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (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 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <stropts.h>
#include <stdlib.h>
#include <errno.h>
#include <libdevinfo.h>
#include <libdlpi.h>
#include <libdladm.h>
#include <libintl.h>
#define DLADM_DB "/etc/datalink.conf"
#define DLADM_DB_TMP "/etc/datalink.conf.new"
#define DLADM_DB_LOCK "/tmp/datalink.conf.lock"
#define MAXLINELEN 1024
#define LISTSZ 1024
#define MAXPATHLEN 1024
typedef struct i_dladm_walk {
int fd;
const char *name;
/*
* Open and lock the aggregation configuration file lock. The lock is
* acquired as a reader (F_RDLCK) or writer (F_WRLCK).
*/
static int
i_dladm_lock_db(short type)
{
int lock_fd;
DLADM_DB_PERMS)) < 0)
return (-1);
(void) unlink(DLADM_DB_LOCK);
return (-1);
}
return (lock_fd);
}
/*
* Unlock and close the specified file.
*/
static void
i_dladm_unlock_db(int fd)
{
if (fd < 0)
return;
(void) unlink(DLADM_DB_LOCK);
}
/*
* Parse a line of the configuration file, returns -1 if an error
* occured.
*/
static int
{
uint_t i;
return (-1);
}
if (i != DLADM_NATTR + 1) {
return (-1);
}
errno = 0;
return (-1);
}
errno = 0;
return (-1);
}
return (0);
}
/*
* Add a datalink of the specified name and attributes to
* the configuration repository.
*/
static int
{
char line[MAXLINELEN];
char *db_file;
char db_file_buf[MAXPATHLEN];
} else {
DLADM_DB);
}
return (-1);
return (-1);
}
/* skip comments and blank lines */
if (BLANK_LINE(line))
continue;
/* skip corrupted lines */
continue;
goto failed;
}
goto failed;
}
}
goto failed;
}
goto failed;
retval = 0;
return (retval);
}
/*
* Remove the datalink of the specified name from the configuration repository.
*/
static int
{
char line[MAXLINELEN];
char copy[MAXLINELEN];
char *db_file, *tmp_db_file;
char db_file_buf[MAXPATHLEN];
char tmp_db_file_buf[MAXPATHLEN];
} else {
DLADM_DB);
}
return (-1);
return (-1);
}
DLADM_DB_PERMS)) < 0) {
return (-1);
}
(void) unlink(tmp_db_file);
return (-1);
}
/* skip comments */
if (!BLANK_LINE(line)) {
continue;
}
continue;
}
}
goto failed;
}
if (!found) {
goto failed;
}
goto failed;
(void) unlink(tmp_db_file);
return (-1);
}
return (0);
(void) unlink(tmp_db_file);
return (-1);
}
/*
* For each datalink in the configuration repository, invoke the specified
* callback. If the datalink name is specified, the callback is invoked
* only for datalink of the matching name.
*/
static void
{
int lock_fd;
char line[MAXLINELEN];
return;
}
/* skip comments */
if (BLANK_LINE(line))
continue;
continue;
continue;
}
}
/*
* For each datalink in the configuration repository, invoke the
* specified callback.
*/
void
void *arg)
{
}
/*
* Issue an ioctl to the specified file descriptor attached to the
* DLD control driver interface.
*/
static int
{
}
/*
* Issue a DLDIOCCREATE ioctl command.
*/
static int
{
return (-1);
}
}
/*
* Datalink bringup callback. Brings up the specified datalink.
*/
static void
{
}
/*
* Bring down the datalink of the specified name.
*/
static int
{
return (-1);
}
}
/*
* Bring down one or all currently active datalinks.
*/
/*ARGSUSED*/
static void
{
return;
}
/*
* Return the attributes of the specified datalink from the DLD driver.
*/
static int
{
return (-1);
}
return (-1);
return (0);
}
/*
* Callback function used to count the number of DDI_NT_NET.
*/
/* ARGSUSED */
static int
{
(*countp)++;
return (DI_WALK_CONTINUE);
}
/*
* Adds a datalink to the array corresponding to arg.
*/
static void
{
char *elem;
for (;;) {
if (elem[0] == '\0')
break;
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
{
char **array;
char *elem;
int i;
return (-1);
}
count = 0;
if (count == 0)
return (0);
goto done;
for (i = 0; i < count; i++) {
continue;
}
while (--i >= 0)
goto done;
}
for (i = 0; i < count; i++) {
if (elem[0] != '\0')
}
done:
return (0);
}
/*
* Create the link of specified name and attributes. Adds it to the
* configuration repository if DLADM_LINK_TEMP is not set. Errors
* will be ignored if DLADM_LINK_FORCED is set.
*/
int
{
int fd;
return (-1);
}
if (!tempop) {
goto failed;
}
}
if (!tempop)
goto failed;
}
return (0);
return (-1);
}
/*
* Instantiate the datalink of specified name. Brings up all datalinks
* if name is NULL.
*/
int
{
*diag =
return (-1);
}
return (-1);
}
return (0);
}
/*
* Deletes the link of specified name.
*/
int
{
int fd;
return (-1);
}
goto failed;
}
if (!tempop)
return (0);
return (-1);
}
/*
* Brings down the datalink of specified name. Brings down all datalinks
* if name == NULL.
*/
int
{
return (-1);
}
return (-1);
}
return (-1);
}
return (0);
}
/*
* Returns the current attributes of the specified datalink.
*/
int
{
int fd;
return (-1);
goto failed;
return (0);
return (-1);
}
/*
* Causes the nodes corresponding to created or deleted datalinks to
* be created or deleted.
*/
int
dladm_sync(void)
{
return (-1);
if (di_devlink_fini(&hdl) < 0)
return (-1);
return (0);
}
const char *
switch (diag) {
return (gettext("invalid datalink name"));
return (gettext("invalid interface name"));
return (gettext("configuration repository corrupt"));
return (gettext("configuration repository open failed"));
return (gettext("write to configuration repository failed"));
return (gettext("configuration repository close failed"));
return (gettext("dld device open fail"));
default:
return (gettext("unknown diagnostic"));
}
}