defaults.c revision 69bb4bb45c98da60d21839c4dc3c01ea1be60585
/*
* 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 <netinet/inetutil.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <dhcpmsg.h>
#include <stdio.h>
#include <libnvpair.h>
#include "defaults.h"
struct dhcp_default {
const char *df_name; /* parameter name */
const char *df_default; /* default value */
int df_min; /* min value if type DF_INTEGER */
int df_max; /* max value if type DF_INTEGER */
};
/*
* note: keep in the same order as tunable parameter constants in defaults.h
*/
static struct dhcp_default defaults[] = {
{ "RELEASE_ON_SIGTERM", "0", 0, 0 },
{ "IGNORE_FAILED_ARP", "1", 0, -1 },
{ "OFFER_WAIT", "3", 1, 20 },
{ "ARP_WAIT", "1000", 0, -1 },
{ "CLIENT_ID", NULL, 0, 0 },
{ "PARAM_REQUEST_LIST", NULL, 0, 0 },
{ "REQUEST_HOSTNAME", "1", 0, 0 }
};
/*
* df_build_cache(): builds the defaults nvlist cache
*
* input: void
* output: a pointer to an nvlist of the current defaults, or NULL on failure
*/
static nvlist_t *
df_build_cache(void)
{
char entry[1024];
int i;
struct dhcp_default *defp;
return (NULL);
"using built-in defaults");
return (NULL);
}
for (i = 0; entry[i] == ' '; i++)
;
continue;
*end = '\0';
*value++ = '\0';
/*
* to be compatible with the old defread()-based code
* which ignored case, store the parameters (except for the
* leading interface name) in upper case.
*/
else
param++;
defp++) {
}
break;
}
}
" using built-in defaults");
break;
}
}
return (nvlist);
}
/*
* df_get_string(): gets the string value of a given user-tunable parameter
*
* input: const char *: the interface the parameter applies to
* unsigned int: the parameter number to look up
* output: const char *: the parameter's value, or default if not set
* (must be copied by caller to be kept)
* NOTE: df_get_string() is both used by functions outside this source
* file to retrieve strings from the defaults file, *and*
* internally by other df_get_*() functions.
*/
const char *
df_get_string(const char *if_name, unsigned int p)
{
char *value;
char param[256];
static struct stat df_statbuf;
return (NULL);
if (!df_unavail_msg) {
"built-in defaults", DHCP_AGENT_DEFAULTS);
}
return (defaults[p].df_default);
}
/*
* if our cached parameters are stale, rebuild.
*/
df_nvlist = df_build_cache();
}
/*
* first look for `if_name.param', then `param'. if neither
* has been set, use the built-in default.
*/
return (value);
return (defaults[p].df_default);
}
/*
* df_get_octet(): gets the integer value of a given user-tunable parameter
*
* input: const char *: the interface the parameter applies to
* unsigned int: the parameter number to look up
* unsigned int *: the length of the returned value
* output: uchar_t *: a pointer to byte array (default value if not set)
* (must be copied by caller to be kept)
*/
uchar_t *
{
const char *value;
return (NULL);
goto do_default;
}
/* skip past the 0x and convert the value to binary */
value += 2;
*len = sizeof (octet_value);
goto do_default;
}
return (octet_value);
*len = 0;
return (NULL);
}
}
/*
* df_get_int(): gets the integer value of a given user-tunable parameter
*
* input: const char *: the interface the parameter applies to
* unsigned int: the parameter number to look up
* output: int: the parameter's value, or default if not set
*/
int
df_get_int(const char *if_name, unsigned int p)
{
const char *value;
int value_int;
return (0);
goto failure;
goto failure;
return (value_int);
}
/*
* df_get_bool(): gets the boolean value of a given user-tunable parameter
*
* input: const char *: the interface the parameter applies to
* unsigned int: the parameter number to look up
* output: boolean_t: B_TRUE if true, B_FALSE if false, default if not set
*/
df_get_bool(const char *if_name, unsigned int p)
{
const char *value;
return (0);
return (B_TRUE);
return (B_FALSE);
}
}