/*
* 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
*/
/*
*/
/*
* libipadm data store /etc/ipadm/ipadm.conf. Each entry in the DB is a
* series of IPADM_NVPAIR_SEP separated (name, value) pairs, as shown
* below:
* name=value[;...]
*
* The 'name' determines how to interpret 'value'. The supported names are:
*
* IPADM_NVP_IPV6ADDR - value holds local and remote IPv6 addresses and when
* converted to nvlist, will contain nvpairs for local and remote
* addresses. These nvpairs are of type DATA_TYPE_STRING
*
* IPADM_NVP_IPV4ADDR - value holds local and remote IPv4 addresses and when
* converted to nvlist, will contain nvpairs for local and remote
* addresses. These nvpairs are of type DATA_TYPE_STRING
*
* IPADM_NVP_INTFID - value holds token, prefixlen, stateless and stateful
* info and when converted to nvlist, will contain following nvpairs
* interface_id: DATA_TYPE_UINT8_ARRAY
* prefixlen: DATA_TYPE_UINT32
* stateless: DATA_TYPE_STRING
* stateful: DATA_TYPE_STRING
*
* IPADM_NVP_DHCP - value holds wait time and primary info and when converted
* to nvlist, will contain following nvpairs
* wait: DATA_TYPE_INT32
* primary: DATA_TYPE_BOOLEAN
*
* default - value is a single entity and when converted to nvlist, will
* contain nvpair of type DATA_TYPE_STRING. nvpairs private to
* ipadm are of this type. Further the property name and property
* values are stored as nvpairs of this type.
*
* The syntax for each line is described above the respective functions below.
*/
#include <stdlib.h>
#include <strings.h>
#include <errno.h>
#include <ctype.h>
#include <fcntl.h>
#include <dirent.h>
#include <unistd.h>
#include <assert.h>
#include "libipadm_impl.h"
/*
* convert nvpair to a "name=value" string for writing to the DB.
*/
/*
* ipadm_rfunc_t takes (`name', `value') and adds the appropriately typed
* nvpair to the nvlist.
*/
/*
* ipadm.conf.
*/
typedef struct ipadm_conf_ent_s {
const char *ipent_type_name;
};
static ipadm_conf_ent_t *
{
int i;
break;
return (&ipadm_conf_ent[i]);
}
/*
* Extracts the hostnames IPADM_NVP_IPADDRHNAME and IPADM_NVP_IPDADDRHNAME from
* the given nvlist `nvl' and adds the strings to `buf'.
*/
{
char *cp;
/* Add the local hostname */
return (0);
/* Add the dst hostname */
/* no dst addr. just add a NULL character */
} else {
}
}
/*
* Converts IPADM_NVP_IPV4ADDR nvpair to a string representation for writing to
* the DB. The converted string format:
* ipv4addr=<local numeric IP string or hostname,remote numeric IP
* string or hostname>
*/
static size_t
{
nvlist_t *v;
int nbytes;
if (nvpair_value_nvlist(nvp, &v) != 0)
goto fail;
if (nbytes != 0)
return (nbytes);
fail:
buf[0] = '\0';
return (0);
}
/*
* Converts IPADM_NVP_IPV6ADDR nvpair to a string representation for writing to
* the DB. The converted string format:
* ipv6addr=<local numeric IP string or hostname,remote numeric IP
* string or hostname>
*/
static size_t
{
nvlist_t *v;
int nbytes;
if (nvpair_value_nvlist(nvp, &v) != 0)
goto fail;
if (nbytes != 0)
return (nbytes);
fail:
buf[0] = '\0';
return (0);
}
/*
* Converts IPADM_NVP_INTFID nvpair to a string representation for writing to
* the DB. The converted string format:
*/
static size_t
{
nvlist_t *v;
char *stateless;
char *stateful;
if (nvpair_value_nvlist(nvp, &v) != 0)
goto fail;
goto fail;
sizeof (addrbuf));
goto fail;
fail:
buf[0] = '\0';
return (0);
}
/*
* Converts IPADM_NVP_DHCP nvpair to a string representation for writing to the
* DB. The converted string format:
* IPADM_NVP_DHCP=<wait_time>,{yes|no}
*/
static size_t
{
nvlist_t *v;
if (nvpair_value_nvlist(nvp, &v) != 0 ||
return (0);
}
}
/*
* Constructs a "<name>=<value>" string from the nvpair, whose type must
* be STRING.
*/
static size_t
{
return (0);
}
/*
* Converts a nvlist to string of the form:
* <prop0>=<val0>,...,<valn>;...;<propn>=<val0>,...,<valn>;
*/
{
/* add nvpair separator */
return (0);
}
return (0);
return (tbytes);
}
/*
* Adds a nvpair, using the `name' and `value', to the nvlist in `nvl'.
* The value will be interpreted as explained at the top of this file.
*/
static void
{
}
/*
* Adds an nvpair for IPv4 addr to the nvlist. The "name" is the string in
* IPADM_NVP_IPV4ADDR. The "value" for IPADM_NVP_IPV4ADDR is another nvlist.
* Allocate the value nvlist for IPADM_NVP_IPV4ADDR if necessary, and add
* the address and hostnames from the address object `ipaddr' to it.
* Then add the allocated nvlist to `nvl'.
*/
{
int err;
char *name;
} else {
}
return (ipadm_errno2status(err));
return (ipadm_errno2status(err));
}
}
ipaddr->ipadm_static_aname)) != 0)
return (ipadm_errno2status(err));
ipaddr->ipadm_static_dname)) != 0)
return (ipadm_errno2status(err));
}
return (IPADM_SUCCESS);
}
/*
* Adds an nvpair for IPv6 interface id to the nvlist. The "name" is
* the string in IPADM_NVP_INTFID. The "value" for IPADM_NVP_INTFID is another
* nvlist. Allocate the value nvlist for IPADM_NVP_INTFID if necessary, and add
* the interface id and its prefixlen from the address object `ipaddr' to it.
* Then add the allocated nvlist to `nvl'.
*/
{
int err;
return (ipadm_errno2status(err));
nvl_addr)) != 0) {
return (ipadm_errno2status(err));
}
}
return (ipadm_errno2status(err));
}
return (ipadm_errno2status(err));
}
if (addr->ipadm_stateless)
else
if (err != 0)
return (ipadm_errno2status(err));
if (addr->ipadm_stateful)
else
if (err != 0)
return (ipadm_errno2status(err));
return (IPADM_SUCCESS);
}
/*
* Adds an nvpair for a dhcp address object to the nvlist. The "name" is
* the string in IPADM_NVP_DHCP. The "value" for IPADM_NVP_DHCP is another
* nvlist. Allocate the value nvlist for IPADM_NVP_DHCP if necessary, and add
* the parameters from the arguments `primary' and `wait'.
* Then add the allocated nvlist to `nvl'.
*/
{
int err;
return (ipadm_errno2status(err));
nvl_dhcp)) != 0) {
return (ipadm_errno2status(err));
}
}
primary)) != 0) {
return (ipadm_errno2status(err));
}
return (IPADM_SUCCESS);
}
/*
* Add (name, value) as an nvpair of type DATA_TYPE_STRING to nvlist.
*/
static void
{
/* if value is NULL create an empty node */
else
}
/*
* `name' = IPADM_NVP_IPV4ADDR and
* `value' = <local numeric IP string or hostname,remote numeric IP string or
* hostname>
* This function will add an nvlist with the hostname information in
* nvpairs to the nvlist in `nvl'.
*/
static void
{
*cp++ = '\0';
sizeof (ipaddr.ipadm_static_aname));
if (*cp != '\0') {
/* we have a dst hostname */
sizeof (ipaddr.ipadm_static_dname));
}
}
/*
* `name' = IPADM_NVP_IPV6ADDR and
* `value' = <local numeric IP string or hostname,remote numeric IP string or
* hostname>
* This function will add an nvlist with the hostname information in
* nvpairs to the nvlist in `nvl'.
*/
static void
{
*cp++ = '\0';
sizeof (ipaddr.ipadm_static_aname));
if (*cp != '\0') {
/* we have a dst hostname */
sizeof (ipaddr.ipadm_static_dname));
}
}
/*
* This function will add an nvlist with the address object information in
* nvpairs to the nvlist in `nvl'.
*/
static void
{
char *cp;
char *endp;
char *prefixlen;
char *stateless;
char *stateful;
*cp++ = '\0';
*cp++ = '\0';
errno = 0;
return;
*stateful++ = '\0';
/* Add all of it to the given nvlist */
}
/*
* `name' = IPADM_NVP_DHCP and `value' = <wait_time>,{yes|no}
* This function will add an nvlist with the dhcp address object information in
* nvpairs to the nvlist in `nvl'.
*/
static void
{
char *cp;
char *endp;
long wait_time;
*cp++ = '\0';
errno = 0;
return;
}
/*
* Parses the buffer, for name-value pairs and creates nvlist. The value
* is always considered to be a string.
*/
int
{
int err;
return (EINVAL);
/*
* If IPADM_NORVAL is set, then `inbuf' should be comma delimited values
*/
return (EINVAL);
return (errno);
buf++;
if (*buf == '\0') {
goto fail;
}
/*
* work on one nvpair at a time and extract the name and value
*/
if (*nv == '\n')
continue;
*val++ = '\0';
goto fail;
goto fail;
}
/* Add the extracted nvpair to the nvlist `ipnvl'. */
}
return (0);
fail:
nvlist_free(*ipnvl);
return (err);
}
/*
* another file and scribble the changes to it and copy the new file back to
* old file.
*/
int
{
int nfd;
int err = 0;
/* open the data store */
return (errno);
if (writeop) {
db_perms)) < 0) {
return (err);
}
return (err);
}
}
if (!writeop)
goto done;
goto done;
goto done;
}
}
return (err);
done:
if (err != 0)
}
return (err);
}
/*
* Processes each line of the configuration file, skipping lines with
* leading spaces, blank lines and comments. The line form the DB
* is converted to nvlist and the callback function is called to process
* the list. The buf could be modified by the callback function and
* if this is a write operation and buf is not truncated, buf will
* be written to disk.
*
* Further if cont is set to B_FALSE, the remainder of the file will
* continue to be read (however callback function will not be called) and,
* if necessary, written to disk as well.
*/
static int
{
int err = 0;
int i, len;
/*
* Skip leading spaces, blank lines, and comments.
*/
for (i = 0; i < len; i++) {
break;
}
MAXLINELEN, &err);
} else {
/* Delete corrupted line. */
buf[0] = '\0';
}
}
if (err != 0)
break;
break;
}
}
return (err);
if (db_op == IPADM_DB_WRITE) {
/*
* `arg' will be NULL when we are doing in-line update of
* entries.
*/
/*
* If the specified entry is not found above, we add
* the entry to the configuration file, here.
*/
}
return (err);
}
return (0);
/* if we have come this far, then we didn't find any match */
return (ENOENT);
}