Print this page
OS-5073 lx-branded zones should request options when using DHCP
Reviewed by: Patrick Mooney <patrick.mooney@joyent.com>

*** 29,38 **** --- 29,39 ---- #include <ctype.h> #include <dhcpmsg.h> #include <stdio.h> #include <sys/stat.h> #include <libnvpair.h> + #include <zone.h> #include "common.h" #include "defaults.h" struct dhcp_default {
*** 60,87 **** { "VERBOSE", "0", 0, 0 }, { "VERIFIED_LEASE_ONLY", "0", 0, 0 }, { "PARAM_IGNORE_LIST", NULL, 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; char *param, *pastv6, *value, *end; FILE *fp; nvlist_t *nvlist; struct dhcp_default *defp; ! if ((fp = fopen(DHCP_AGENT_DEFAULTS, "r")) == NULL) return (NULL); if (nvlist_alloc(&nvlist, NV_UNIQUE_NAME, 0) != 0) { dhcpmsg(MSG_WARNING, "cannot build default value cache; " "using built-in defaults"); --- 61,115 ---- { "VERBOSE", "0", 0, 0 }, { "VERIFIED_LEASE_ONLY", "0", 0, 0 }, { "PARAM_IGNORE_LIST", NULL, 0, 0 } }; + /* + * df_find_defaults(): builds the path to the default configuration file + * + * input: void + * output: void + */ + + static const char * + df_find_defaults(void) + { + static char agent_defaults_path[MAXPATHLEN] = { 0 }; + const char *zroot = NULL; + + if (agent_defaults_path[0] != '\0') { + return agent_defaults_path; + } + + zroot = zone_get_nroot(); + + (void) snprintf(agent_defaults_path, MAXPATHLEN, "%s%s", + zroot != NULL ? zroot : "", DHCP_AGENT_DEFAULTS); + + return agent_defaults_path; + } + + /* * 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) { + const char *agent_defaults_path = df_find_defaults(); char entry[1024]; int i; char *param, *pastv6, *value, *end; FILE *fp; nvlist_t *nvlist; struct dhcp_default *defp; ! if ((fp = fopen(agent_defaults_path, "r")) == NULL) return (NULL); if (nvlist_alloc(&nvlist, NV_UNIQUE_NAME, 0) != 0) { dhcpmsg(MSG_WARNING, "cannot build default value cache; " "using built-in defaults");
*** 157,166 **** --- 185,195 ---- */ const char * df_get_string(const char *if_name, boolean_t isv6, uint_t param) { + const char *agent_defaults_path = df_find_defaults(); char *value; char paramstr[256]; char name[256]; struct stat statbuf; static struct stat df_statbuf;
*** 168,181 **** static nvlist_t *df_nvlist = NULL; if (param >= (sizeof (defaults) / sizeof (*defaults))) return (NULL); ! if (stat(DHCP_AGENT_DEFAULTS, &statbuf) != 0) { if (!df_unavail_msg) { dhcpmsg(MSG_WARNING, "cannot access %s; using " ! "built-in defaults", DHCP_AGENT_DEFAULTS); df_unavail_msg = B_TRUE; } return (defaults[param].df_default); } --- 197,211 ---- static nvlist_t *df_nvlist = NULL; if (param >= (sizeof (defaults) / sizeof (*defaults))) return (NULL); ! ! if (stat(agent_defaults_path, &statbuf) != 0) { if (!df_unavail_msg) { dhcpmsg(MSG_WARNING, "cannot access %s; using " ! "built-in defaults", agent_defaults_path); df_unavail_msg = B_TRUE; } return (defaults[param].df_default); }