Print this page
7388 Support DHCP Client FQDN. Allow IAID/DUID for all v4.

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/cmd-inet/sbin/dhcpagent/select.c
          +++ new/usr/src/cmd/cmd-inet/sbin/dhcpagent/select.c
↓ open down ↓ 12 lines elided ↑ open up ↑
  13   13   * When distributing Covered Code, include this CDDL HEADER in each
  14   14   * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15   15   * If applicable, add the following below this CDDL HEADER, with the
  16   16   * fields enclosed by brackets "[]" replaced with your own identifying
  17   17   * information: Portions Copyright [yyyy] [name of copyright owner]
  18   18   *
  19   19   * CDDL HEADER END
  20   20   */
  21   21  /*
  22   22   * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
       23 + * Copyright (c) 2016, Chris Fraire <cfraire@me.com>.
  23   24   *
  24   25   * SELECTING state of the client state machine.
  25   26   */
  26   27  
  27   28  #include <sys/types.h>
  28   29  #include <stdio.h>
  29   30  #include <stdlib.h>
  30   31  #include <strings.h>
  31   32  #include <time.h>
  32      -#include <limits.h>
  33   33  #include <netinet/in.h>
  34   34  #include <net/route.h>
  35   35  #include <net/if.h>
  36   36  #include <netinet/dhcp.h>
  37   37  #include <netinet/udp.h>
  38   38  #include <netinet/ip_var.h>
  39   39  #include <netinet/udp_var.h>
  40   40  #include <dhcpmsg.h>
  41   41  #include <dhcp_hostconf.h>
  42   42  
↓ open down ↓ 56 lines elided ↑ open up ↑
  99   99   *                   Advertisements for DHCPv6.
 100  100   *
 101  101   *   input: dhcp_smach_t *: the state machine on which to send the DISCOVER
 102  102   *  output: void
 103  103   */
 104  104  
 105  105  void
 106  106  dhcp_selecting(dhcp_smach_t *dsmp)
 107  107  {
 108  108          dhcp_pkt_t              *dpkt;
 109      -        const char              *reqhost;
 110      -        char                    hostfile[PATH_MAX + 1];
 111  109  
 112  110          /*
 113  111           * We first set up to collect OFFER/Advertise packets as they arrive.
 114  112           * We then send out DISCOVER/Solicit probes.  Then we wait a
 115  113           * user-tunable number of seconds before seeing if OFFERs/
 116  114           * Advertisements have come in response to our DISCOVER/Solicit.  If
 117  115           * none have come in, we continue to wait, sending out our DISCOVER/
 118  116           * Solicit probes with exponential backoff.  If no OFFER/Advertisement
 119  117           * is ever received, we will wait forever (note that since we're
 120  118           * event-driven though, we're still able to service other state
↓ open down ↓ 50 lines elided ↑ open up ↑
 171  169                      sizeof (d6in) - sizeof (dhcpv6_option_t));
 172  170  
 173  171                  /* Option Request option for desired information */
 174  172                  (void) add_pkt_prl(dpkt, dsmp);
 175  173  
 176  174                  /* Enable Rapid-Commit */
 177  175                  (void) add_pkt_opt(dpkt, DHCPV6_OPT_RAPID_COMMIT, NULL, 0);
 178  176  
 179  177                  /* xxx add Reconfigure Accept */
 180  178  
      179 +                /* Add FQDN if configured */
      180 +                (void) dhcp_add_fqdn_opt(dpkt, dsmp);
      181 +
 181  182                  (void) send_pkt_v6(dsmp, dpkt, ipv6_all_dhcp_relay_and_servers,
 182  183                      stop_selecting, DHCPV6_SOL_TIMEOUT, DHCPV6_SOL_MAX_RT);
 183  184          } else {
 184  185                  if ((dpkt = init_pkt(dsmp, DISCOVER)) == NULL) {
 185  186                          dhcpmsg(MSG_ERROR, "dhcp_selecting: unable to set up "
 186  187                              "DISCOVER packet");
 187  188                          return;
 188  189                  }
 189  190  
 190  191                  /*
↓ open down ↓ 3 lines elided ↑ open up ↑
 194  195                  (void) add_pkt_opt16(dpkt, CD_MAX_DHCP_SIZE,
 195  196                      htons(dsmp->dsm_lif->lif_max - sizeof (struct udpiphdr)));
 196  197                  (void) add_pkt_opt32(dpkt, CD_LEASE_TIME, htonl(DHCP_PERM));
 197  198  
 198  199                  if (class_id_len != 0) {
 199  200                          (void) add_pkt_opt(dpkt, CD_CLASS_ID, class_id,
 200  201                              class_id_len);
 201  202                  }
 202  203                  (void) add_pkt_prl(dpkt, dsmp);
 203  204  
 204      -                if (df_get_bool(dsmp->dsm_name, dsmp->dsm_isv6,
 205      -                    DF_REQUEST_HOSTNAME)) {
 206      -                        dhcpmsg(MSG_DEBUG,
 207      -                            "dhcp_selecting: DF_REQUEST_HOSTNAME");
 208      -                        (void) snprintf(hostfile, sizeof (hostfile),
 209      -                            "/etc/hostname.%s", dsmp->dsm_name);
      205 +                if (dhcp_add_fqdn_opt(dpkt, dsmp) != 0)
      206 +                        (void) dhcp_add_hostname_opt(dpkt, dsmp);
 210  207  
 211      -                        if ((reqhost = iffile_to_hostname(hostfile)) != NULL) {
 212      -                                dhcpmsg(MSG_DEBUG, "dhcp_selecting: host %s",
 213      -                                    reqhost);
 214      -                                dsmp->dsm_reqhost = strdup(reqhost);
 215      -                                if (dsmp->dsm_reqhost != NULL)
 216      -                                        (void) add_pkt_opt(dpkt, CD_HOSTNAME,
 217      -                                            dsmp->dsm_reqhost,
 218      -                                            strlen(dsmp->dsm_reqhost));
 219      -                                else
 220      -                                        dhcpmsg(MSG_WARNING,
 221      -                                            "dhcp_selecting: cannot allocate "
 222      -                                            "memory for host name option");
 223      -                        }
 224      -                }
 225  208                  (void) add_pkt_opt(dpkt, CD_END, NULL, 0);
 226  209  
 227  210                  (void) send_pkt(dsmp, dpkt, htonl(INADDR_BROADCAST),
 228  211                      stop_selecting);
 229  212          }
 230  213          return;
 231  214  
 232  215  failed:
 233  216          (void) set_smach_state(dsmp, INIT);
 234  217          dsmp->dsm_dflags |= DHCP_IF_FAILED;
↓ open down ↓ 35 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX