Print this page
4586 dhcpv6 client id malformed
Reviewed by: Sebastien Roy <sebastien.roy@delphix.com>
Reviewed by: Marcel Telka <marcel@telka.sk>


   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 /*
  23  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  */
  26 
  27 #pragma ident   "%Z%%M% %I%     %E% SMI"
  28 
  29 /*
  30  * This module reads and writes the stable identifier values, DUID and IAID.
  31  */
  32 
  33 #include <stdio.h>
  34 #include <stdlib.h>
  35 #include <unistd.h>
  36 #include <string.h>
  37 #include <limits.h>
  38 #include <fcntl.h>
  39 #include <errno.h>
  40 #include <libdlpi.h>
  41 #include <uuid/uuid.h>
  42 #include <sys/types.h>
  43 #include <sys/stat.h>
  44 #include <net/if.h>
  45 #include <netinet/dhcp6.h>
  46 #include <dhcp_inittab.h>
  47 
  48 #define DUID_FILE       "/etc/dhcp/duid"


 126  *          size_t *: pointer to a size_t to return the DUID length
 127  *  output: uchar_t *: the DUID buffer, or NULL on error (and errno is set)
 128  *    note: memory returned is from malloc; caller must free.
 129  */
 130 
 131 uchar_t *
 132 make_stable_duid(const char *physintf, size_t *duidlen)
 133 {
 134         int len;
 135         dlpi_info_t dlinfo;
 136         dlpi_handle_t dh = NULL;
 137         uint_t arptype;
 138         duid_en_t *den;
 139 
 140         /*
 141          * Try to read the MAC layer address for the physical interface
 142          * provided as a hint.  If that works, we can use a DUID-LLT.
 143          */
 144 
 145         if (dlpi_open(physintf, &dh, 0) == DLPI_SUCCESS &&

 146             dlpi_info(dh, &dlinfo, 0) == DLPI_SUCCESS &&
 147             (len = dlinfo.di_physaddrlen) > 0 &&
 148             (arptype = dlpi_arptype(dlinfo.di_mactype) != 0)) {
 149                 duid_llt_t *dllt;
 150                 time_t now;
 151 
 152                 if ((dllt = malloc(sizeof (*dllt) + len)) == NULL) {
 153                         dlpi_close(dh);
 154                         return (NULL);
 155                 }
 156 
 157                 (void) memcpy((dllt + 1), dlinfo.di_physaddr, len);
 158                 dllt->dllt_dutype = htons(DHCPV6_DUID_LLT);
 159                 dllt->dllt_hwtype = htons(arptype);
 160                 now = time(NULL) - DUID_TIME_BASE;
 161                 dllt->dllt_time = htonl(now);
 162                 *duidlen = sizeof (*dllt) + len;
 163                 dlpi_close(dh);
 164                 return ((uchar_t *)dllt);
 165         }




   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 /*
  23  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  */
  26 


  27 /*
  28  * This module reads and writes the stable identifier values, DUID and IAID.
  29  */
  30 
  31 #include <stdio.h>
  32 #include <stdlib.h>
  33 #include <unistd.h>
  34 #include <string.h>
  35 #include <limits.h>
  36 #include <fcntl.h>
  37 #include <errno.h>
  38 #include <libdlpi.h>
  39 #include <uuid/uuid.h>
  40 #include <sys/types.h>
  41 #include <sys/stat.h>
  42 #include <net/if.h>
  43 #include <netinet/dhcp6.h>
  44 #include <dhcp_inittab.h>
  45 
  46 #define DUID_FILE       "/etc/dhcp/duid"


 124  *          size_t *: pointer to a size_t to return the DUID length
 125  *  output: uchar_t *: the DUID buffer, or NULL on error (and errno is set)
 126  *    note: memory returned is from malloc; caller must free.
 127  */
 128 
 129 uchar_t *
 130 make_stable_duid(const char *physintf, size_t *duidlen)
 131 {
 132         int len;
 133         dlpi_info_t dlinfo;
 134         dlpi_handle_t dh = NULL;
 135         uint_t arptype;
 136         duid_en_t *den;
 137 
 138         /*
 139          * Try to read the MAC layer address for the physical interface
 140          * provided as a hint.  If that works, we can use a DUID-LLT.
 141          */
 142 
 143         if (dlpi_open(physintf, &dh, 0) == DLPI_SUCCESS &&
 144             dlpi_bind(dh, DLPI_ANY_SAP, NULL) == DLPI_SUCCESS &&
 145             dlpi_info(dh, &dlinfo, 0) == DLPI_SUCCESS &&
 146             (len = dlinfo.di_physaddrlen) > 0 &&
 147             (arptype = dlpi_arptype(dlinfo.di_mactype) != 0)) {
 148                 duid_llt_t *dllt;
 149                 time_t now;
 150 
 151                 if ((dllt = malloc(sizeof (*dllt) + len)) == NULL) {
 152                         dlpi_close(dh);
 153                         return (NULL);
 154                 }
 155 
 156                 (void) memcpy((dllt + 1), dlinfo.di_physaddr, len);
 157                 dllt->dllt_dutype = htons(DHCPV6_DUID_LLT);
 158                 dllt->dllt_hwtype = htons(arptype);
 159                 now = time(NULL) - DUID_TIME_BASE;
 160                 dllt->dllt_time = htonl(now);
 161                 *duidlen = sizeof (*dllt) + len;
 162                 dlpi_close(dh);
 163                 return ((uchar_t *)dllt);
 164         }