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


   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  23  * Use is subject to license terms.

  24  *
  25  * INIT_REBOOT state of the DHCP client state machine.
  26  */
  27 
  28 #include <sys/types.h>
  29 #include <stdio.h>
  30 #include <limits.h>
  31 #include <sys/socket.h>
  32 #include <netinet/in.h>
  33 #include <netinet/dhcp.h>
  34 #include <netinet/udp.h>
  35 #include <netinet/ip_var.h>
  36 #include <netinet/udp_var.h>
  37 #include <dhcpmsg.h>
  38 #include <string.h>
  39 
  40 #include "agent.h"
  41 #include "packet.h"
  42 #include "states.h"
  43 #include "util.h"
  44 #include "interface.h"
  45 #include "defaults.h"
  46 
  47 static stop_func_t      stop_init_reboot;
  48 
  49 /*
  50  * dhcp_init_reboot_v4(): attempts to reuse a cached configuration for a state
  51  *                        machine.
  52  *
  53  *   input: dhcp_smach_t *: the state machine to examine for reuse
  54  *  output: void
  55  */
  56 
  57 static void
  58 dhcp_init_reboot_v4(dhcp_smach_t *dsmp)
  59 {
  60         dhcp_pkt_t              *dpkt;
  61         const char              *reqhost;
  62         char                    hostfile[PATH_MAX + 1];
  63 
  64         /*
  65          * assemble DHCPREQUEST message.  The max dhcp message size
  66          * option is set to the interface max, minus the size of the udp and
  67          * ip headers.
  68          */
  69 
  70         dpkt = init_pkt(dsmp, REQUEST);
  71         (void) add_pkt_opt32(dpkt, CD_REQUESTED_IP_ADDR,
  72             dsmp->dsm_ack->pkt->yiaddr.s_addr);
  73 
  74         (void) add_pkt_opt32(dpkt, CD_LEASE_TIME, htonl(DHCP_PERM));
  75         (void) add_pkt_opt16(dpkt, CD_MAX_DHCP_SIZE,
  76             htons(dsmp->dsm_lif->lif_pif->pif_max - sizeof (struct udpiphdr)));
  77 
  78         if (class_id_len != 0)
  79                 (void) add_pkt_opt(dpkt, CD_CLASS_ID, class_id, class_id_len);
  80         (void) add_pkt_prl(dpkt, dsmp);
  81 
  82         /*
  83          * Set CD_HOSTNAME option if REQUEST_HOSTNAME is set and a hostname
  84          * is found in /etc/hostname.<ifname>
  85          */
  86         if (df_get_bool(dsmp->dsm_name, dsmp->dsm_isv6, DF_REQUEST_HOSTNAME)) {
  87                 (void) snprintf(hostfile, sizeof (hostfile), "/etc/hostname.%s",
  88                     dsmp->dsm_name);
  89 
  90                 if ((reqhost = iffile_to_hostname(hostfile)) != NULL) {
  91                         dhcpmsg(MSG_DEBUG, "dhcp_selecting: host %s", reqhost);
  92                         if ((dsmp->dsm_reqhost = strdup(reqhost)) != NULL)
  93                                 (void) add_pkt_opt(dpkt, CD_HOSTNAME,
  94                                     dsmp->dsm_reqhost,
  95                                     strlen(dsmp->dsm_reqhost));
  96                         else
  97                                 dhcpmsg(MSG_WARNING, "dhcp_selecting: cannot"
  98                                     " allocate memory for host name option");
  99                 } else {
 100                         dhcpmsg(MSG_DEBUG,
 101                             "dhcp_selecting: no hostname for %s",
 102                             dsmp->dsm_name);
 103                 }
 104         }
 105 
 106         (void) add_pkt_opt(dpkt, CD_END, NULL, 0);
 107 
 108         (void) send_pkt(dsmp, dpkt, htonl(INADDR_BROADCAST), stop_init_reboot);
 109 }
 110 
 111 
 112 /*
 113  * dhcp_init_reboot_v6(): attempts to reuse a cached configuration for a state
 114  *                        machine.  Create a Confirm message and multicast it
 115  *                        out.
 116  *
 117  *   input: dhcp_smach_t *: the state machine to examine for reuse
 118  *  output: void
 119  */
 120 
 121 static void
 122 dhcp_init_reboot_v6(dhcp_smach_t *dsmp)
 123 {
 124         dhcp_pkt_t *dpkt;
 125         dhcpv6_option_t *d6o, *d6so, *popt;


 165                 obase = (char *)d6o + sizeof (dhcpv6_ia_na_t);
 166                 olen -= sizeof (dhcpv6_ia_na_t);
 167                 d6so = NULL;
 168                 while ((d6so = dhcpv6_find_option(obase, olen, d6so,
 169                     DHCPV6_OPT_IAADDR, &solen)) != NULL) {
 170                         if (solen < sizeof (dhcpv6_iaaddr_t))
 171                                 continue;
 172                         (void) memcpy(&d6ia, d6so, sizeof (d6ia));
 173                         d6ia.d6ia_preflife = 0;
 174                         d6ia.d6ia_vallife = 0;
 175                         if (add_pkt_subopt(dpkt, popt, DHCPV6_OPT_IAADDR,
 176                             (char *)&d6ia + sizeof (*d6so),
 177                             sizeof (d6ia) - sizeof (*d6so)) == NULL)
 178                                 goto failure;
 179                 }
 180         }
 181 
 182         /* Add required Option Request option */
 183         (void) add_pkt_prl(dpkt, dsmp);
 184 



 185         (void) send_pkt_v6(dsmp, dpkt, ipv6_all_dhcp_relay_and_servers,
 186             stop_init_reboot, DHCPV6_CNF_TIMEOUT, DHCPV6_CNF_MAX_RT);
 187 
 188         return;
 189 
 190 failure:
 191         if (!set_start_timer(dsmp))
 192                 dhcp_selecting(dsmp);
 193 }
 194 
 195 /*
 196  * dhcp_init_reboot(): attempts to reuse a cached configuration for a state
 197  *                     machine.
 198  *
 199  *   input: dhcp_smach_t *: the state machine to examine for reuse
 200  *  output: void
 201  */
 202 
 203 void
 204 dhcp_init_reboot(dhcp_smach_t *dsmp)




   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  23  * Use is subject to license terms.
  24  * Copyright (c) 2016, Chris Fraire <cfraire@me.com>.
  25  *
  26  * INIT_REBOOT state of the DHCP client state machine.
  27  */
  28 
  29 #include <sys/types.h>
  30 #include <stdio.h>

  31 #include <sys/socket.h>
  32 #include <netinet/in.h>
  33 #include <netinet/dhcp.h>
  34 #include <netinet/udp.h>
  35 #include <netinet/ip_var.h>
  36 #include <netinet/udp_var.h>
  37 #include <dhcpmsg.h>
  38 #include <string.h>
  39 
  40 #include "agent.h"
  41 #include "packet.h"
  42 #include "states.h"
  43 #include "util.h"
  44 #include "interface.h"
  45 #include "defaults.h"
  46 
  47 static stop_func_t      stop_init_reboot;
  48 
  49 /*
  50  * dhcp_init_reboot_v4(): attempts to reuse a cached configuration for a state
  51  *                        machine.
  52  *
  53  *   input: dhcp_smach_t *: the state machine to examine for reuse
  54  *  output: void
  55  */
  56 
  57 static void
  58 dhcp_init_reboot_v4(dhcp_smach_t *dsmp)
  59 {
  60         dhcp_pkt_t              *dpkt;


  61 
  62         /*
  63          * assemble DHCPREQUEST message.  The max dhcp message size
  64          * option is set to the interface max, minus the size of the udp and
  65          * ip headers.
  66          */
  67 
  68         dpkt = init_pkt(dsmp, REQUEST);
  69         (void) add_pkt_opt32(dpkt, CD_REQUESTED_IP_ADDR,
  70             dsmp->dsm_ack->pkt->yiaddr.s_addr);
  71 
  72         (void) add_pkt_opt32(dpkt, CD_LEASE_TIME, htonl(DHCP_PERM));
  73         (void) add_pkt_opt16(dpkt, CD_MAX_DHCP_SIZE,
  74             htons(dsmp->dsm_lif->lif_pif->pif_max - sizeof (struct udpiphdr)));
  75 
  76         if (class_id_len != 0)
  77                 (void) add_pkt_opt(dpkt, CD_CLASS_ID, class_id, class_id_len);
  78         (void) add_pkt_prl(dpkt, dsmp);
  79 
  80         if (dhcp_add_fqdn_opt(dpkt, dsmp) != 0)
  81                 (void) dhcp_add_hostname_opt(dpkt, dsmp);





  82 
















  83         (void) add_pkt_opt(dpkt, CD_END, NULL, 0);
  84 
  85         (void) send_pkt(dsmp, dpkt, htonl(INADDR_BROADCAST), stop_init_reboot);
  86 }
  87 
  88 
  89 /*
  90  * dhcp_init_reboot_v6(): attempts to reuse a cached configuration for a state
  91  *                        machine.  Create a Confirm message and multicast it
  92  *                        out.
  93  *
  94  *   input: dhcp_smach_t *: the state machine to examine for reuse
  95  *  output: void
  96  */
  97 
  98 static void
  99 dhcp_init_reboot_v6(dhcp_smach_t *dsmp)
 100 {
 101         dhcp_pkt_t *dpkt;
 102         dhcpv6_option_t *d6o, *d6so, *popt;


 142                 obase = (char *)d6o + sizeof (dhcpv6_ia_na_t);
 143                 olen -= sizeof (dhcpv6_ia_na_t);
 144                 d6so = NULL;
 145                 while ((d6so = dhcpv6_find_option(obase, olen, d6so,
 146                     DHCPV6_OPT_IAADDR, &solen)) != NULL) {
 147                         if (solen < sizeof (dhcpv6_iaaddr_t))
 148                                 continue;
 149                         (void) memcpy(&d6ia, d6so, sizeof (d6ia));
 150                         d6ia.d6ia_preflife = 0;
 151                         d6ia.d6ia_vallife = 0;
 152                         if (add_pkt_subopt(dpkt, popt, DHCPV6_OPT_IAADDR,
 153                             (char *)&d6ia + sizeof (*d6so),
 154                             sizeof (d6ia) - sizeof (*d6so)) == NULL)
 155                                 goto failure;
 156                 }
 157         }
 158 
 159         /* Add required Option Request option */
 160         (void) add_pkt_prl(dpkt, dsmp);
 161 
 162         /* Add FQDN if configured */
 163         (void) dhcp_add_fqdn_opt(dpkt, dsmp);
 164 
 165         (void) send_pkt_v6(dsmp, dpkt, ipv6_all_dhcp_relay_and_servers,
 166             stop_init_reboot, DHCPV6_CNF_TIMEOUT, DHCPV6_CNF_MAX_RT);
 167 
 168         return;
 169 
 170 failure:
 171         if (!set_start_timer(dsmp))
 172                 dhcp_selecting(dsmp);
 173 }
 174 
 175 /*
 176  * dhcp_init_reboot(): attempts to reuse a cached configuration for a state
 177  *                     machine.
 178  *
 179  *   input: dhcp_smach_t *: the state machine to examine for reuse
 180  *  output: void
 181  */
 182 
 183 void
 184 dhcp_init_reboot(dhcp_smach_t *dsmp)