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

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/cmd-inet/sbin/dhcpagent/defaults.c
          +++ new/usr/src/cmd/cmd-inet/sbin/dhcpagent/defaults.c
↓ open down ↓ 23 lines elided ↑ open up ↑
  24   24   */
  25   25  
  26   26  #include <sys/types.h>
  27   27  #include <stdlib.h>
  28   28  #include <string.h>
  29   29  #include <ctype.h>
  30   30  #include <dhcpmsg.h>
  31   31  #include <stdio.h>
  32   32  #include <sys/stat.h>
  33   33  #include <libnvpair.h>
       34 +#include <zone.h>
  34   35  
  35   36  #include "common.h"
  36   37  #include "defaults.h"
  37   38  
  38   39  struct dhcp_default {
  39   40  
  40   41          const char      *df_name;       /* parameter name */
  41   42          const char      *df_default;    /* default value */
  42   43          int             df_min;         /* min value if type DF_INTEGER */
  43   44          int             df_max;         /* max value if type DF_INTEGER */
↓ open down ↓ 11 lines elided ↑ open up ↑
  55   56          { "ARP_WAIT",            "1000", 0,   -1  },
  56   57          { "CLIENT_ID",           NULL,   0,   0   },
  57   58          { "PARAM_REQUEST_LIST",  NULL,   0,   0   },
  58   59          { "REQUEST_HOSTNAME",    "1",    0,   0   },
  59   60          { "DEBUG_LEVEL",         "0",    0,   3   },
  60   61          { "VERBOSE",             "0",    0,   0   },
  61   62          { "VERIFIED_LEASE_ONLY", "0",    0,   0   },
  62   63          { "PARAM_IGNORE_LIST",   NULL,   0,   0   }
  63   64  };
  64   65  
       66 +
  65   67  /*
       68 + * df_find_defaults(): builds the path to the default configuration file
       69 + *
       70 + *   input: void
       71 + *  output: void
       72 + */
       73 +
       74 +static const char *
       75 +df_find_defaults(void)
       76 +{
       77 +        static char agent_defaults_path[MAXPATHLEN] = { 0 };
       78 +        const char      *zroot = NULL;
       79 +
       80 +        if (agent_defaults_path[0] != '\0') {
       81 +                return agent_defaults_path;
       82 +        }
       83 +
       84 +        zroot = zone_get_nroot();
       85 +
       86 +        (void) snprintf(agent_defaults_path, MAXPATHLEN, "%s%s",
       87 +            zroot != NULL ?  zroot : "", DHCP_AGENT_DEFAULTS);
       88 +
       89 +        return agent_defaults_path;
       90 +}
       91 +
       92 +/*
  66   93   * df_build_cache(): builds the defaults nvlist cache
  67   94   *
  68   95   *   input: void
  69   96   *  output: a pointer to an nvlist of the current defaults, or NULL on failure
  70   97   */
  71   98  
  72   99  static nvlist_t *
  73  100  df_build_cache(void)
  74  101  {
      102 +        const char      *agent_defaults_path = df_find_defaults();
  75  103          char            entry[1024];
  76  104          int             i;
  77  105          char            *param, *pastv6, *value, *end;
  78  106          FILE            *fp;
  79  107          nvlist_t        *nvlist;
  80  108          struct dhcp_default *defp;
  81  109  
  82      -        if ((fp = fopen(DHCP_AGENT_DEFAULTS, "r")) == NULL)
      110 +        if ((fp = fopen(agent_defaults_path, "r")) == NULL)
  83  111                  return (NULL);
  84  112  
  85  113          if (nvlist_alloc(&nvlist, NV_UNIQUE_NAME, 0) != 0) {
  86  114                  dhcpmsg(MSG_WARNING, "cannot build default value cache; "
  87  115                      "using built-in defaults");
  88  116                  (void) fclose(fp);
  89  117                  return (NULL);
  90  118          }
  91  119  
  92  120          while (fgets(entry, sizeof (entry), fp) != NULL) {
↓ open down ↓ 59 lines elided ↑ open up ↑
 152  180   *  output: const char *: the parameter's value, or default if not set
 153  181   *                        (must be copied by caller to be kept)
 154  182   *    NOTE: df_get_string() is both used by functions outside this source
 155  183   *          file to retrieve strings from the defaults file, *and*
 156  184   *          internally by other df_get_*() functions.
 157  185   */
 158  186  
 159  187  const char *
 160  188  df_get_string(const char *if_name, boolean_t isv6, uint_t param)
 161  189  {
      190 +        const char              *agent_defaults_path = df_find_defaults();
 162  191          char                    *value;
 163  192          char                    paramstr[256];
 164  193          char                    name[256];
 165  194          struct stat             statbuf;
 166  195          static struct stat      df_statbuf;
 167  196          static boolean_t        df_unavail_msg = B_FALSE;
 168  197          static nvlist_t         *df_nvlist = NULL;
 169  198  
 170  199          if (param >= (sizeof (defaults) / sizeof (*defaults)))
 171  200                  return (NULL);
 172  201  
 173      -        if (stat(DHCP_AGENT_DEFAULTS, &statbuf) != 0) {
      202 +
      203 +        if (stat(agent_defaults_path, &statbuf) != 0) {
 174  204                  if (!df_unavail_msg) {
 175  205                          dhcpmsg(MSG_WARNING, "cannot access %s; using "
 176      -                            "built-in defaults", DHCP_AGENT_DEFAULTS);
      206 +                            "built-in defaults", agent_defaults_path);
 177  207                          df_unavail_msg = B_TRUE;
 178  208                  }
 179  209                  return (defaults[param].df_default);
 180  210          }
 181  211  
 182  212          /*
 183  213           * if our cached parameters are stale, rebuild.
 184  214           */
 185  215  
 186  216          if (statbuf.st_mtime != df_statbuf.st_mtime ||
↓ open down ↓ 101 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX