Print this page
4587 snoop misdecodes DHCPv6 DHCPV6_DUID_LL identifiers


  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 2009 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  */
  26 
  27 /*
  28  * Dynamic Host Configuration Protocol version 6, for IPv6.  Supports
  29  * RFCs 3315, 3319, 3646, 3898, 4075, 4242, 4280, 4580, 4649, and 4704.
  30  */
  31 

  32 #include <stdio.h>
  33 #include <stdlib.h>
  34 #include <string.h>
  35 #include <time.h>
  36 #include <sys/types.h>
  37 #include <sys/socket.h>
  38 #include <netinet/in.h>
  39 #include <netinet/dhcp6.h>
  40 #include <arpa/inet.h>
  41 #include <dhcp_impl.h>
  42 #include <dhcp_inittab.h>
  43 
  44 #include "snoop.h"
  45 
  46 static const char *mtype_to_str(uint8_t);
  47 static const char *option_to_str(uint8_t);
  48 static const char *duidtype_to_str(uint16_t);
  49 static const char *status_to_str(uint16_t);
  50 static const char *entr_to_str(uint32_t);
  51 static const char *reconf_to_str(uint8_t);


 614                 case DHCPV6_OPT_SERVERID:
 615                         if (olen < sizeof (val16))
 616                                 break;
 617                         (void) memcpy(&val16, data, sizeof (val16));
 618                         data += sizeof (val16);
 619                         olen -= sizeof (val16);
 620                         type = ntohs(val16);
 621                         (void) snprintf(get_line(0, 0), get_line_remain(),
 622                             "  DUID Type = %u (%s)", type,
 623                             duidtype_to_str(type));
 624                         if (type == DHCPV6_DUID_LLT || type == DHCPV6_DUID_LL) {
 625                                 if (olen < sizeof (val16))
 626                                         break;
 627                                 (void) memcpy(&val16, data, sizeof (val16));
 628                                 data += sizeof (val16);
 629                                 olen -= sizeof (val16);
 630                                 val16 = ntohs(val16);
 631                                 (void) snprintf(get_line(0, 0),
 632                                     get_line_remain(),
 633                                     "  Hardware Type = %u (%s)", val16,
 634                                     arp_htype(type));
 635                         }
 636                         if (type == DHCPV6_DUID_LLT) {
 637                                 time_t timevalue;
 638 
 639                                 if (olen < sizeof (val32))
 640                                         break;
 641                                 (void) memcpy(&val32, data, sizeof (val32));
 642                                 data += sizeof (val32);
 643                                 olen -= sizeof (val32);
 644                                 timevalue = ntohl(val32) + DUID_TIME_BASE;
 645                                 (void) snprintf(get_line(0, 0),
 646                                     get_line_remain(),
 647                                     "  Time = %lu (%.24s)", ntohl(val32),
 648                                     ctime(&timevalue));
 649                         }
 650                         if (type == DHCPV6_DUID_EN) {
 651                                 if (olen < sizeof (val32))
 652                                         break;
 653                                 (void) memcpy(&val32, data, sizeof (val32));
 654                                 data += sizeof (val32);




  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 2009 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  */
  26 
  27 /*
  28  * Dynamic Host Configuration Protocol version 6, for IPv6.  Supports
  29  * RFCs 3315, 3319, 3646, 3898, 4075, 4242, 4280, 4580, 4649, and 4704.
  30  */
  31 
  32 #include <ctype.h>
  33 #include <stdio.h>
  34 #include <stdlib.h>
  35 #include <string.h>
  36 #include <time.h>
  37 #include <sys/types.h>
  38 #include <sys/socket.h>
  39 #include <netinet/in.h>
  40 #include <netinet/dhcp6.h>
  41 #include <arpa/inet.h>
  42 #include <dhcp_impl.h>
  43 #include <dhcp_inittab.h>
  44 
  45 #include "snoop.h"
  46 
  47 static const char *mtype_to_str(uint8_t);
  48 static const char *option_to_str(uint8_t);
  49 static const char *duidtype_to_str(uint16_t);
  50 static const char *status_to_str(uint16_t);
  51 static const char *entr_to_str(uint32_t);
  52 static const char *reconf_to_str(uint8_t);


 615                 case DHCPV6_OPT_SERVERID:
 616                         if (olen < sizeof (val16))
 617                                 break;
 618                         (void) memcpy(&val16, data, sizeof (val16));
 619                         data += sizeof (val16);
 620                         olen -= sizeof (val16);
 621                         type = ntohs(val16);
 622                         (void) snprintf(get_line(0, 0), get_line_remain(),
 623                             "  DUID Type = %u (%s)", type,
 624                             duidtype_to_str(type));
 625                         if (type == DHCPV6_DUID_LLT || type == DHCPV6_DUID_LL) {
 626                                 if (olen < sizeof (val16))
 627                                         break;
 628                                 (void) memcpy(&val16, data, sizeof (val16));
 629                                 data += sizeof (val16);
 630                                 olen -= sizeof (val16);
 631                                 val16 = ntohs(val16);
 632                                 (void) snprintf(get_line(0, 0),
 633                                     get_line_remain(),
 634                                     "  Hardware Type = %u (%s)", val16,
 635                                     arp_htype(val16));
 636                         }
 637                         if (type == DHCPV6_DUID_LLT) {
 638                                 time_t timevalue;
 639 
 640                                 if (olen < sizeof (val32))
 641                                         break;
 642                                 (void) memcpy(&val32, data, sizeof (val32));
 643                                 data += sizeof (val32);
 644                                 olen -= sizeof (val32);
 645                                 timevalue = ntohl(val32) + DUID_TIME_BASE;
 646                                 (void) snprintf(get_line(0, 0),
 647                                     get_line_remain(),
 648                                     "  Time = %lu (%.24s)", ntohl(val32),
 649                                     ctime(&timevalue));
 650                         }
 651                         if (type == DHCPV6_DUID_EN) {
 652                                 if (olen < sizeof (val32))
 653                                         break;
 654                                 (void) memcpy(&val32, data, sizeof (val32));
 655                                 data += sizeof (val32);