10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 51481Skcpoon * Common Development and Distribution License (the "License"). 61481Skcpoon * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 211481Skcpoon 220Sstevel@tonic-gate /* 23*9759SVasumathi.Sundaram@Sun.COM * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 240Sstevel@tonic-gate * Use is subject to license terms. 250Sstevel@tonic-gate */ 260Sstevel@tonic-gate 270Sstevel@tonic-gate #include <ctype.h> 280Sstevel@tonic-gate #include <stdio.h> 290Sstevel@tonic-gate #include <stdlib.h> 300Sstevel@tonic-gate #include <fcntl.h> 310Sstevel@tonic-gate #include <string.h> 320Sstevel@tonic-gate #include <sys/types.h> 330Sstevel@tonic-gate #include <sys/socket.h> 340Sstevel@tonic-gate #include <sys/sysmacros.h> 350Sstevel@tonic-gate #include <netinet/in.h> 360Sstevel@tonic-gate #include <netinet/dhcp.h> 370Sstevel@tonic-gate #include <arpa/inet.h> 380Sstevel@tonic-gate #include <dhcp_inittab.h> 390Sstevel@tonic-gate #include <dhcp_symbol.h> 400Sstevel@tonic-gate #include "snoop.h" 410Sstevel@tonic-gate 420Sstevel@tonic-gate static const char *show_msgtype(unsigned char); 430Sstevel@tonic-gate static int show_options(unsigned char *, int); 440Sstevel@tonic-gate static void display_ip(int, char *, char *, unsigned char **); 450Sstevel@tonic-gate static void display_ascii(char *, char *, unsigned char **); 460Sstevel@tonic-gate static void display_number(char *, char *, unsigned char **); 470Sstevel@tonic-gate static void display_ascii_hex(char *, unsigned char **); 480Sstevel@tonic-gate static unsigned char bootmagic[] = BOOTMAGIC; /* rfc 1048 */ 490Sstevel@tonic-gate 500Sstevel@tonic-gate static char *option_types[] = { 510Sstevel@tonic-gate "", /* 0 */ 520Sstevel@tonic-gate "Subnet Mask", /* 1 */ 530Sstevel@tonic-gate "UTC Time Offset", /* 2 */ 540Sstevel@tonic-gate "Router", /* 3 */ 550Sstevel@tonic-gate "RFC868 Time Servers", /* 4 */ 560Sstevel@tonic-gate "IEN 116 Name Servers", /* 5 */ 570Sstevel@tonic-gate "DNS Servers", /* 6 */ 580Sstevel@tonic-gate "UDP LOG Servers", /* 7 */ 590Sstevel@tonic-gate "RFC 865 Cookie Servers", /* 8 */ 600Sstevel@tonic-gate "RFC 1179 Line Printer Servers (LPR)", /* 9 */ 610Sstevel@tonic-gate "Impress Servers", /* 10 */ 620Sstevel@tonic-gate "RFC 887 Resource Location Servers", /* 11 */ 630Sstevel@tonic-gate "Client Hostname", /* 12 */ 640Sstevel@tonic-gate "Boot File size in 512 byte Blocks", /* 13 */ 650Sstevel@tonic-gate "Merit Dump File", /* 14 */ 660Sstevel@tonic-gate "DNS Domain Name", /* 15 */ 670Sstevel@tonic-gate "SWAP Server", /* 16 */ 680Sstevel@tonic-gate "Client Root Path", /* 17 */ 690Sstevel@tonic-gate "BOOTP options extensions path", /* 18 */ 700Sstevel@tonic-gate "IP Forwarding Flag", /* 19 */ 710Sstevel@tonic-gate "NonLocal Source Routing Flag", /* 20 */ 720Sstevel@tonic-gate "Policy Filters for NonLocal Routing", /* 21 */ 730Sstevel@tonic-gate "Maximum Datagram Reassembly Size", /* 22 */ 740Sstevel@tonic-gate "Default IP Time To Live", /* 23 */ 750Sstevel@tonic-gate "Path MTU Aging Timeout", /* 24 */ 760Sstevel@tonic-gate "Path MTU Size Plateau Table", /* 25 */ 770Sstevel@tonic-gate "Interface MTU Size", /* 26 */ 780Sstevel@tonic-gate "All Subnets are Local Flag", /* 27 */ 790Sstevel@tonic-gate "Broadcast Address", /* 28 */ 800Sstevel@tonic-gate "Perform Mask Discovery Flag", /* 29 */ 810Sstevel@tonic-gate "Mask Supplier Flag", /* 30 */ 820Sstevel@tonic-gate "Perform Router Discovery Flag", /* 31 */ 830Sstevel@tonic-gate "Router Solicitation Address", /* 32 */ 840Sstevel@tonic-gate "Static Routes", /* 33 */ 850Sstevel@tonic-gate "Trailer Encapsulation Flag", /* 34 */ 860Sstevel@tonic-gate "ARP Cache Timeout Seconds", /* 35 */ 870Sstevel@tonic-gate "Ethernet Encapsulation Flag", /* 36 */ 880Sstevel@tonic-gate "TCP Default Time To Live", /* 37 */ 890Sstevel@tonic-gate "TCP Keepalive Interval Seconds", /* 38 */ 900Sstevel@tonic-gate "TCP Keepalive Garbage Flag", /* 39 */ 910Sstevel@tonic-gate "NIS Domainname", /* 40 */ 920Sstevel@tonic-gate "NIS Servers", /* 41 */ 930Sstevel@tonic-gate "Network Time Protocol Servers", /* 42 */ 940Sstevel@tonic-gate "Vendor Specific Options", /* 43 */ 950Sstevel@tonic-gate "NetBIOS RFC 1001/1002 Name Servers", /* 44 */ 960Sstevel@tonic-gate "NetBIOS Datagram Dist. Servers", /* 45 */ 970Sstevel@tonic-gate "NetBIOS Node Type", /* 46 */ 980Sstevel@tonic-gate "NetBIOS Scope", /* 47 */ 990Sstevel@tonic-gate "X Window Font Servers", /* 48 */ 1000Sstevel@tonic-gate "X Window Display Manager Servers", /* 49 */ 1010Sstevel@tonic-gate "Requested IP Address", /* 50 */ 1020Sstevel@tonic-gate "IP Address Lease Time", /* 51 */ 1030Sstevel@tonic-gate "Option Field Overload Flag", /* 52 */ 1040Sstevel@tonic-gate "DHCP Message Type", /* 53 */ 1050Sstevel@tonic-gate "DHCP Server Identifier", /* 54 */ 1060Sstevel@tonic-gate "Option Request List", /* 55 */ 1070Sstevel@tonic-gate "Error Message", /* 56 */ 1080Sstevel@tonic-gate "Maximum DHCP Message Size", /* 57 */ 1090Sstevel@tonic-gate "Renewal (T1) Time Value", /* 58 */ 1100Sstevel@tonic-gate "Rebinding (T2) Time Value", /* 59 */ 1110Sstevel@tonic-gate "Client Class Identifier =", /* 60 */ 1120Sstevel@tonic-gate "Client Identifier =", /* 61 */ 1130Sstevel@tonic-gate "Netware IP Domain =", /* 62 */ 1140Sstevel@tonic-gate "Netware IP Options =", /* 63 */ 1150Sstevel@tonic-gate "NISPLUS Domainname", /* 64 */ 1160Sstevel@tonic-gate "NISPLUS Servers", /* 65 */ 1170Sstevel@tonic-gate "TFTP Server Name", /* 66 */ 1180Sstevel@tonic-gate "Option BootFile Name", /* 67 */ 1190Sstevel@tonic-gate "Mobile IP Agents", /* 68 */ 1200Sstevel@tonic-gate "Simple Mail (SMTP) Servers", /* 69 */ 1210Sstevel@tonic-gate "Post Office (POP3) Servers", /* 70 */ 1220Sstevel@tonic-gate "Net News (NNTP) Servers", /* 71 */ 1230Sstevel@tonic-gate "WorldWideWeb Servers", /* 72 */ 1240Sstevel@tonic-gate "Finger Servers", /* 73 */ 1250Sstevel@tonic-gate "Internet Relay Chat (IRC) Servers", /* 74 */ 1260Sstevel@tonic-gate "StreetTalk Servers", /* 75 */ 1270Sstevel@tonic-gate "StreetTalk Directory Assist. Servers", /* 76 */ 1280Sstevel@tonic-gate "User Class Identifier", /* 77 */ 1290Sstevel@tonic-gate }; 1300Sstevel@tonic-gate 1310Sstevel@tonic-gate #define OPTIONS_ARRAY_SIZE 78 1320Sstevel@tonic-gate 1330Sstevel@tonic-gate int 1341676Sjpk interpret_dhcp(int flags, struct dhcp *dp, int len) 1350Sstevel@tonic-gate { 1360Sstevel@tonic-gate if (flags & F_SUM) { 1370Sstevel@tonic-gate if ((memcmp(dp->cookie, bootmagic, sizeof (bootmagic)) == 0) && 1380Sstevel@tonic-gate (len >= BASE_PKT_SIZE + 3) && 1390Sstevel@tonic-gate dp->options[0] == CD_DHCP_TYPE) { 1400Sstevel@tonic-gate (void) sprintf(get_sum_line(), 1410Sstevel@tonic-gate "DHCP/BOOTP %s", show_msgtype(dp->options[2])); 1420Sstevel@tonic-gate } else { 1430Sstevel@tonic-gate switch (ntohs(dp->op)) { 1440Sstevel@tonic-gate case BOOTREQUEST: 1450Sstevel@tonic-gate (void) sprintf(get_sum_line(), 1460Sstevel@tonic-gate "DHCP/BOOTP BOOTREQUEST"); 1470Sstevel@tonic-gate break; 1480Sstevel@tonic-gate case BOOTREPLY: 1490Sstevel@tonic-gate (void) sprintf(get_sum_line(), 1500Sstevel@tonic-gate "DHCP/BOOTP BOOTREPLY"); 1510Sstevel@tonic-gate break; 1520Sstevel@tonic-gate } 1530Sstevel@tonic-gate } 1540Sstevel@tonic-gate } 1550Sstevel@tonic-gate if (flags & F_DTAIL) { 1560Sstevel@tonic-gate show_header("DHCP: ", "Dynamic Host Configuration Protocol", 1570Sstevel@tonic-gate len); 1580Sstevel@tonic-gate show_space(); 159410Skcpoon (void) sprintf(get_line((char *)(uintptr_t)dp->htype - 160410Skcpoon dlc_header, 1), 1610Sstevel@tonic-gate "Hardware address type (htype) = %d (%s)", dp->htype, 1623431Scarlsonj arp_htype(dp->htype)); 163410Skcpoon (void) sprintf(get_line((char *)(uintptr_t)dp->hlen - 164410Skcpoon dlc_header, 1), 1650Sstevel@tonic-gate "Hardware address length (hlen) = %d octets", dp->hlen); 166410Skcpoon (void) sprintf(get_line((char *)(uintptr_t)dp->hops - 167410Skcpoon dlc_header, 1), 1680Sstevel@tonic-gate "Relay agent hops = %d", dp->hops); 169410Skcpoon (void) sprintf(get_line((char *)(uintptr_t)dp->xid - 170410Skcpoon dlc_header, 4), 1710Sstevel@tonic-gate "Transaction ID = 0x%x", ntohl(dp->xid)); 172410Skcpoon (void) sprintf(get_line((char *)(uintptr_t)dp->secs - 173410Skcpoon dlc_header, 2), 1740Sstevel@tonic-gate "Time since boot = %d seconds", ntohs(dp->secs)); 175410Skcpoon (void) sprintf(get_line((char *)(uintptr_t)dp->flags - 176410Skcpoon dlc_header, 2), 1770Sstevel@tonic-gate "Flags = 0x%.4x", ntohs(dp->flags)); 1780Sstevel@tonic-gate (void) sprintf(get_line((char *)&dp->ciaddr - dlc_header, 4), 1790Sstevel@tonic-gate "Client address (ciaddr) = %s", inet_ntoa(dp->ciaddr)); 1800Sstevel@tonic-gate (void) sprintf(get_line((char *)&dp->yiaddr - dlc_header, 4), 1810Sstevel@tonic-gate "Your client address (yiaddr) = %s", 1820Sstevel@tonic-gate inet_ntoa(dp->yiaddr)); 1830Sstevel@tonic-gate (void) sprintf(get_line((char *)&dp->siaddr - dlc_header, 4), 1840Sstevel@tonic-gate "Next server address (siaddr) = %s", 1850Sstevel@tonic-gate inet_ntoa(dp->siaddr)); 1860Sstevel@tonic-gate (void) sprintf(get_line((char *)&dp->giaddr - dlc_header, 4), 1870Sstevel@tonic-gate "Relay agent address (giaddr) = %s", 1880Sstevel@tonic-gate inet_ntoa(dp->giaddr)); 1890Sstevel@tonic-gate if (dp->htype == 1) { 1900Sstevel@tonic-gate (void) sprintf(get_line((char *)dp->chaddr - 1910Sstevel@tonic-gate dlc_header, dp->hlen), 1920Sstevel@tonic-gate "Client hardware address (chaddr) = %.2X:%.2X:%.2X:%.2X:%.2X:%.2X", 1930Sstevel@tonic-gate dp->chaddr[0], 1940Sstevel@tonic-gate dp->chaddr[1], 1950Sstevel@tonic-gate dp->chaddr[2], 1960Sstevel@tonic-gate dp->chaddr[3], 1970Sstevel@tonic-gate dp->chaddr[4], 1980Sstevel@tonic-gate dp->chaddr[5]); 1990Sstevel@tonic-gate } 2000Sstevel@tonic-gate /* 2010Sstevel@tonic-gate * Check cookie, process options 2020Sstevel@tonic-gate */ 2030Sstevel@tonic-gate if (memcmp(dp->cookie, bootmagic, sizeof (bootmagic)) != 0) { 2040Sstevel@tonic-gate (void) sprintf(get_line(0, 0), 2050Sstevel@tonic-gate "Unrecognized cookie: 0x%.2X%.2X%.2X%.2X\n", 2060Sstevel@tonic-gate dp->cookie[0], 2070Sstevel@tonic-gate dp->cookie[1], 2080Sstevel@tonic-gate dp->cookie[2], 2090Sstevel@tonic-gate dp->cookie[3]); 2100Sstevel@tonic-gate return (0); 2110Sstevel@tonic-gate } 2120Sstevel@tonic-gate show_space(); 2130Sstevel@tonic-gate show_header("DHCP: ", "(Options) field options", len); 2140Sstevel@tonic-gate show_space(); 2150Sstevel@tonic-gate switch (show_options(dp->options, (len - BASE_PKT_SIZE))) { 2160Sstevel@tonic-gate case 0: 2170Sstevel@tonic-gate /* No option overloading */ 2180Sstevel@tonic-gate if (*(unsigned char *)(dp->sname) != '\0') { 2190Sstevel@tonic-gate (void) sprintf(get_line(0, 0), 2200Sstevel@tonic-gate "Server Name = %s", dp->sname); 2210Sstevel@tonic-gate } 2220Sstevel@tonic-gate if (*(unsigned char *)(dp->file) != '\0') { 2230Sstevel@tonic-gate (void) sprintf(get_line(0, 0), 2240Sstevel@tonic-gate "Boot File Name = %s", dp->file); 2250Sstevel@tonic-gate } 2260Sstevel@tonic-gate break; 2270Sstevel@tonic-gate case 1: 2280Sstevel@tonic-gate /* file field used */ 2290Sstevel@tonic-gate if (*(unsigned char *)(dp->sname) != '\0') { 2300Sstevel@tonic-gate (void) sprintf(get_line(0, 0), 2310Sstevel@tonic-gate "Server Name = %s", dp->sname); 2320Sstevel@tonic-gate } 2330Sstevel@tonic-gate show_space(); 2340Sstevel@tonic-gate show_header("DHCP: ", "(File) field options", len); 2350Sstevel@tonic-gate show_space(); 2360Sstevel@tonic-gate (void) show_options(dp->file, 128); 2370Sstevel@tonic-gate break; 2380Sstevel@tonic-gate case 2: 2390Sstevel@tonic-gate /* sname field used for options */ 2400Sstevel@tonic-gate if (*(unsigned char *)(dp->file) != '\0') { 2410Sstevel@tonic-gate (void) sprintf(get_line(0, 0), 2420Sstevel@tonic-gate "Boot File Name = %s", dp->file); 2430Sstevel@tonic-gate } 2440Sstevel@tonic-gate show_space(); 2450Sstevel@tonic-gate show_header("DHCP: ", "(Sname) field options", len); 2460Sstevel@tonic-gate show_space(); 2470Sstevel@tonic-gate (void) show_options(dp->sname, 64); 2480Sstevel@tonic-gate break; 2490Sstevel@tonic-gate case 3: 2500Sstevel@tonic-gate show_space(); 2510Sstevel@tonic-gate show_header("DHCP: ", "(File) field options", len); 2520Sstevel@tonic-gate show_space(); 2530Sstevel@tonic-gate (void) show_options(dp->file, 128); 2540Sstevel@tonic-gate show_space(); 2550Sstevel@tonic-gate show_header("DHCP: ", "(Sname) field options", len); 2560Sstevel@tonic-gate show_space(); 2570Sstevel@tonic-gate (void) show_options(dp->sname, 64); 2580Sstevel@tonic-gate break; 2590Sstevel@tonic-gate }; 2600Sstevel@tonic-gate } 2610Sstevel@tonic-gate return (len); 2620Sstevel@tonic-gate } 2633431Scarlsonj 2640Sstevel@tonic-gate static int 2650Sstevel@tonic-gate show_options(unsigned char *cp, int len) 2660Sstevel@tonic-gate { 2670Sstevel@tonic-gate char *prmpt; 2680Sstevel@tonic-gate unsigned char *end, *vend; 2690Sstevel@tonic-gate unsigned char *start, save; 2700Sstevel@tonic-gate int items, i; 2710Sstevel@tonic-gate int nooverload = 0; 2720Sstevel@tonic-gate ushort_t s_buf; 2730Sstevel@tonic-gate struct in_addr tmp; 2740Sstevel@tonic-gate char scratch[128]; 2750Sstevel@tonic-gate dhcp_symbol_t *entry; 2760Sstevel@tonic-gate char *decoded_opt; 2770Sstevel@tonic-gate int opt_len; 2780Sstevel@tonic-gate 2790Sstevel@tonic-gate start = cp; 2800Sstevel@tonic-gate end = (unsigned char *)cp + len; 2810Sstevel@tonic-gate 2820Sstevel@tonic-gate while (start < end) { 2830Sstevel@tonic-gate if (*start == CD_PAD) { 2840Sstevel@tonic-gate start++; 2850Sstevel@tonic-gate continue; 2860Sstevel@tonic-gate } 2870Sstevel@tonic-gate if (*start == CD_END) 2880Sstevel@tonic-gate break; /* done */ 2890Sstevel@tonic-gate 2900Sstevel@tonic-gate save = *start++; 2910Sstevel@tonic-gate switch (save) { 2920Sstevel@tonic-gate /* Network order IP address(es) */ 2930Sstevel@tonic-gate case CD_SUBNETMASK: 2940Sstevel@tonic-gate case CD_ROUTER_SOLICIT_SERV: 2950Sstevel@tonic-gate case CD_BROADCASTADDR: 2960Sstevel@tonic-gate case CD_REQUESTED_IP_ADDR: 2970Sstevel@tonic-gate case CD_SERVER_ID: 2980Sstevel@tonic-gate /* Single IP address */ 2990Sstevel@tonic-gate if (*start != 4) { 3000Sstevel@tonic-gate (void) sprintf(get_line(0, 0), 3010Sstevel@tonic-gate "Error: Bad %s", option_types[save]); 3020Sstevel@tonic-gate } else { 3030Sstevel@tonic-gate start++; 3040Sstevel@tonic-gate display_ip(1, "%s = %s", option_types[save], 3050Sstevel@tonic-gate &start); 3060Sstevel@tonic-gate } 3070Sstevel@tonic-gate break; 3080Sstevel@tonic-gate case CD_ROUTER: 3090Sstevel@tonic-gate case CD_TIMESERV: 3100Sstevel@tonic-gate case CD_IEN116_NAME_SERV: 3110Sstevel@tonic-gate case CD_DNSSERV: 3120Sstevel@tonic-gate case CD_LOG_SERV: 3130Sstevel@tonic-gate case CD_COOKIE_SERV: 3140Sstevel@tonic-gate case CD_LPR_SERV: 3150Sstevel@tonic-gate case CD_IMPRESS_SERV: 3160Sstevel@tonic-gate case CD_RESOURCE_SERV: 3170Sstevel@tonic-gate case CD_SWAP_SERV: 3180Sstevel@tonic-gate case CD_NIS_SERV: 3190Sstevel@tonic-gate case CD_NTP_SERV: 3200Sstevel@tonic-gate case CD_NETBIOS_NAME_SERV: 3210Sstevel@tonic-gate case CD_NETBIOS_DIST_SERV: 3220Sstevel@tonic-gate case CD_XWIN_FONT_SERV: 3230Sstevel@tonic-gate case CD_XWIN_DISP_SERV: 3240Sstevel@tonic-gate case CD_NISPLUS_SERVS: 3250Sstevel@tonic-gate case CD_MOBILE_IP_AGENT: 3260Sstevel@tonic-gate case CD_SMTP_SERVS: 3270Sstevel@tonic-gate case CD_POP3_SERVS: 3280Sstevel@tonic-gate case CD_NNTP_SERVS: 3290Sstevel@tonic-gate case CD_WWW_SERVS: 3300Sstevel@tonic-gate case CD_FINGER_SERVS: 3310Sstevel@tonic-gate case CD_IRC_SERVS: 3320Sstevel@tonic-gate case CD_STREETTALK_SERVS: 3330Sstevel@tonic-gate case CD_STREETTALK_DA_SERVS: 3340Sstevel@tonic-gate /* Multiple IP addresses */ 3350Sstevel@tonic-gate if ((*start % 4) != 0) { 3360Sstevel@tonic-gate (void) sprintf(get_line(0, 0), 3370Sstevel@tonic-gate "Error: Bad %s address", 3380Sstevel@tonic-gate option_types[save]); 3390Sstevel@tonic-gate } else { 3401481Skcpoon items = *start++ / 4; 3411481Skcpoon display_ip(items, "%s at = %s", 3420Sstevel@tonic-gate option_types[save], &start); 3430Sstevel@tonic-gate } 3440Sstevel@tonic-gate break; 3450Sstevel@tonic-gate case CD_TFTP_SERV_NAME: 3460Sstevel@tonic-gate case CD_HOSTNAME: 3470Sstevel@tonic-gate case CD_DUMP_FILE: 3480Sstevel@tonic-gate case CD_DNSDOMAIN: 3490Sstevel@tonic-gate case CD_ROOT_PATH: 3500Sstevel@tonic-gate case CD_NIS_DOMAIN: 3510Sstevel@tonic-gate case CD_NETBIOS_SCOPE: 3520Sstevel@tonic-gate case CD_MESSAGE: 3530Sstevel@tonic-gate case CD_NISPLUS_DMAIN: 3540Sstevel@tonic-gate case CD_OPT_BOOTFILE_NAME: 3550Sstevel@tonic-gate case CD_USER_CLASS_ID: 3560Sstevel@tonic-gate /* Ascii strings */ 3570Sstevel@tonic-gate display_ascii("%s = %s", option_types[save], &start); 3580Sstevel@tonic-gate break; 3590Sstevel@tonic-gate case CD_TIMEOFFSET: 3600Sstevel@tonic-gate case CD_IPTTL: 3610Sstevel@tonic-gate case CD_PATH_MTU_TIMEOUT: 3620Sstevel@tonic-gate case CD_ARP_TIMEOUT: 3630Sstevel@tonic-gate case CD_TCP_TTL: 3640Sstevel@tonic-gate case CD_TCP_KALIVE_INTVL: 3650Sstevel@tonic-gate case CD_T1_TIME: 3660Sstevel@tonic-gate case CD_T2_TIME: 3670Sstevel@tonic-gate case CD_LEASE_TIME: 3680Sstevel@tonic-gate /* Number: seconds */ 3690Sstevel@tonic-gate display_number("%s = %d seconds", option_types[save], 3700Sstevel@tonic-gate &start); 3710Sstevel@tonic-gate break; 3720Sstevel@tonic-gate case CD_IP_FORWARDING_ON: 3730Sstevel@tonic-gate case CD_NON_LCL_ROUTE_ON: 3740Sstevel@tonic-gate case CD_ALL_SUBNETS_LCL_ON: 3750Sstevel@tonic-gate case CD_MASK_DISCVRY_ON: 3760Sstevel@tonic-gate case CD_MASK_SUPPLIER_ON: 3770Sstevel@tonic-gate case CD_ROUTER_DISCVRY_ON: 3780Sstevel@tonic-gate case CD_TRAILER_ENCAPS_ON: 3790Sstevel@tonic-gate case CD_ETHERNET_ENCAPS_ON: 3800Sstevel@tonic-gate case CD_TCP_KALIVE_GRBG_ON: 3810Sstevel@tonic-gate /* Number: hex flag */ 3820Sstevel@tonic-gate display_number("%s flag = 0x%x", option_types[save], 3830Sstevel@tonic-gate &start); 3840Sstevel@tonic-gate break; 3850Sstevel@tonic-gate case CD_MAXIPSIZE: 3860Sstevel@tonic-gate case CD_MTU: 3870Sstevel@tonic-gate case CD_MAX_DHCP_SIZE: 3880Sstevel@tonic-gate /* Number: bytes */ 3890Sstevel@tonic-gate display_number("%s = %d bytes", option_types[save], 3900Sstevel@tonic-gate &start); 3910Sstevel@tonic-gate break; 3920Sstevel@tonic-gate case CD_CLASS_ID: 3930Sstevel@tonic-gate case CD_CLIENT_ID: 3940Sstevel@tonic-gate case CD_NW_IP_DOMAIN: 3950Sstevel@tonic-gate case CD_NW_IP_OPTIONS: 3960Sstevel@tonic-gate /* Hex ascii strings */ 3970Sstevel@tonic-gate display_ascii_hex(option_types[save], &start); 3980Sstevel@tonic-gate break; 3990Sstevel@tonic-gate case CD_BOOT_SIZE: 4000Sstevel@tonic-gate display_number("%s = %d 512 byte blocks", 4010Sstevel@tonic-gate "Boot file size", &start); 4020Sstevel@tonic-gate break; 4030Sstevel@tonic-gate case CD_POLICY_FILTER: 4040Sstevel@tonic-gate if ((*start % 8) != 0) { 4050Sstevel@tonic-gate (void) sprintf(get_line(0, 0), 4060Sstevel@tonic-gate "Error: Bad Policy Filter option"); 4070Sstevel@tonic-gate } else { 4080Sstevel@tonic-gate items = *start++ / 8; 4090Sstevel@tonic-gate for (i = 0; i < items; i++) { 4100Sstevel@tonic-gate display_ip(1, 4110Sstevel@tonic-gate "%s = %s", 4120Sstevel@tonic-gate "Policy Destination", 4130Sstevel@tonic-gate &start); 4140Sstevel@tonic-gate display_ip(1, "%s = %s", "Mask", 4150Sstevel@tonic-gate &start); 4160Sstevel@tonic-gate } 4170Sstevel@tonic-gate } 4180Sstevel@tonic-gate break; 4190Sstevel@tonic-gate case CD_PATH_MTU_TABLE_SZ: 4200Sstevel@tonic-gate if (*start % 2 != 0) { 4210Sstevel@tonic-gate (void) sprintf(get_line(0, 0), 4220Sstevel@tonic-gate "Error: Bad Path MTU Table"); 4230Sstevel@tonic-gate } else { 4240Sstevel@tonic-gate (void) sprintf(get_line(0, 0), 4250Sstevel@tonic-gate "\tPath MTU Plateau Table:"); 4260Sstevel@tonic-gate (void) sprintf(get_line(0, 0), 4270Sstevel@tonic-gate "\t======================="); 4280Sstevel@tonic-gate items = *start / sizeof (ushort_t); 4290Sstevel@tonic-gate ++start; 4300Sstevel@tonic-gate for (i = 0; i < items; i++) { 4310Sstevel@tonic-gate if (IS_P2ALIGNED(start, 432*9759SVasumathi.Sundaram@Sun.COM sizeof (ushort_t))) { 4330Sstevel@tonic-gate /* LINTED: improper alignment */ 4340Sstevel@tonic-gate s_buf = *(ushort_t *)start; 4350Sstevel@tonic-gate } else { 4360Sstevel@tonic-gate memcpy((char *)&s_buf, 4370Sstevel@tonic-gate start, sizeof (short)); 4380Sstevel@tonic-gate } 4390Sstevel@tonic-gate (void) sprintf(get_line(0, 0), 4400Sstevel@tonic-gate "\t\tEntry %d:\t\t%d", i, 4410Sstevel@tonic-gate ntohs(s_buf)); 4420Sstevel@tonic-gate start += sizeof (ushort_t); 4430Sstevel@tonic-gate } 4440Sstevel@tonic-gate } 4450Sstevel@tonic-gate break; 4460Sstevel@tonic-gate case CD_STATIC_ROUTE: 4470Sstevel@tonic-gate if ((*start % 8) != 0) { 4480Sstevel@tonic-gate (void) sprintf(get_line(0, 0), 4490Sstevel@tonic-gate "Error: Bad Static Route option: %d", 4500Sstevel@tonic-gate *start); 4510Sstevel@tonic-gate } else { 4520Sstevel@tonic-gate items = *start++ / 8; 4530Sstevel@tonic-gate for (i = 0; i < items; i++) { 4540Sstevel@tonic-gate memcpy((char *)&tmp, start, 4550Sstevel@tonic-gate sizeof (struct in_addr)); 4560Sstevel@tonic-gate (void) strcpy(scratch, inet_ntoa(tmp)); 4570Sstevel@tonic-gate start += sizeof (ulong_t); 4580Sstevel@tonic-gate memcpy((char *)&tmp, start, 4590Sstevel@tonic-gate sizeof (struct in_addr)); 4600Sstevel@tonic-gate (void) sprintf(get_line(0, 0), 4610Sstevel@tonic-gate "Static route from %s to %s", 4620Sstevel@tonic-gate scratch, inet_ntoa(tmp)); 4630Sstevel@tonic-gate start += sizeof (ulong_t); 4640Sstevel@tonic-gate } 4650Sstevel@tonic-gate } 4660Sstevel@tonic-gate break; 4670Sstevel@tonic-gate case CD_VENDOR_SPEC: 4680Sstevel@tonic-gate i = *start++; 4690Sstevel@tonic-gate (void) sprintf(get_line(0, 0), 4700Sstevel@tonic-gate "Vendor-specific Options (%d total octets):", i); 4710Sstevel@tonic-gate /* 4720Sstevel@tonic-gate * We don't know what these things are, so just 4730Sstevel@tonic-gate * display the option number, length, and value 4740Sstevel@tonic-gate * (hex). 4750Sstevel@tonic-gate */ 4760Sstevel@tonic-gate vend = (uchar_t *)((uchar_t *)start + i); 4770Sstevel@tonic-gate while (start < vend && *start != CD_END) { 4780Sstevel@tonic-gate if (*start == CD_PAD) { 4790Sstevel@tonic-gate start++; 4800Sstevel@tonic-gate continue; 4810Sstevel@tonic-gate } 4820Sstevel@tonic-gate (void) sprintf(scratch, 4830Sstevel@tonic-gate "\t(%.2d) %.2d octets", *start, 4840Sstevel@tonic-gate *(uchar_t *)((uchar_t *)start + 1)); 4850Sstevel@tonic-gate start++; 4860Sstevel@tonic-gate display_ascii_hex(scratch, &start); 4870Sstevel@tonic-gate } 4880Sstevel@tonic-gate start = vend; /* in case CD_END found */ 4890Sstevel@tonic-gate break; 4900Sstevel@tonic-gate case CD_NETBIOS_NODE_TYPE: 4910Sstevel@tonic-gate if (*start != 1) { 4920Sstevel@tonic-gate (void) sprintf(get_line(0, 0), 4930Sstevel@tonic-gate "Error: Bad '%s' parameter", 4940Sstevel@tonic-gate option_types[CD_NETBIOS_NODE_TYPE]); 4950Sstevel@tonic-gate } else { 4960Sstevel@tonic-gate char *type; 4970Sstevel@tonic-gate start++; 4980Sstevel@tonic-gate switch (*start) { 4990Sstevel@tonic-gate case 0x1: 5000Sstevel@tonic-gate type = "Broadcast Node"; 5010Sstevel@tonic-gate break; 5020Sstevel@tonic-gate case 0x2: 5030Sstevel@tonic-gate type = "Point To Point Node"; 5040Sstevel@tonic-gate break; 5050Sstevel@tonic-gate case 0x4: 5060Sstevel@tonic-gate type = "Mixed Mode Node"; 5070Sstevel@tonic-gate break; 5080Sstevel@tonic-gate case 0x8: 5090Sstevel@tonic-gate type = "Hybrid Node"; 5100Sstevel@tonic-gate break; 5110Sstevel@tonic-gate default: 5120Sstevel@tonic-gate type = "??? Node"; 5130Sstevel@tonic-gate break; 5140Sstevel@tonic-gate }; 5150Sstevel@tonic-gate (void) sprintf(get_line(0, 0), 5160Sstevel@tonic-gate "%s = %s (%d)", 5170Sstevel@tonic-gate option_types[CD_NETBIOS_NODE_TYPE], 5180Sstevel@tonic-gate type, *start); 5190Sstevel@tonic-gate start++; 5200Sstevel@tonic-gate } 5210Sstevel@tonic-gate break; 5220Sstevel@tonic-gate case CD_OPTION_OVERLOAD: 5230Sstevel@tonic-gate if (*start != 1) { 5240Sstevel@tonic-gate (void) sprintf(get_line(0, 0), 5250Sstevel@tonic-gate "Bad Option Overload value."); 5260Sstevel@tonic-gate } else { 5270Sstevel@tonic-gate start++; 5280Sstevel@tonic-gate nooverload = *start++; 5290Sstevel@tonic-gate } 5300Sstevel@tonic-gate break; 5310Sstevel@tonic-gate case CD_DHCP_TYPE: 5320Sstevel@tonic-gate if (*start < 1 || *start > 7) { 5330Sstevel@tonic-gate (void) sprintf(get_line(0, 0), 5340Sstevel@tonic-gate "Bad DHCP Message Type."); 5350Sstevel@tonic-gate } else { 5360Sstevel@tonic-gate start++; 5370Sstevel@tonic-gate (void) sprintf(get_line(0, 0), 5380Sstevel@tonic-gate "Message type = %s", 5390Sstevel@tonic-gate show_msgtype(*start)); 5400Sstevel@tonic-gate start++; 5410Sstevel@tonic-gate } 5420Sstevel@tonic-gate break; 5430Sstevel@tonic-gate case CD_REQUEST_LIST: 5440Sstevel@tonic-gate opt_len = *start++; 5450Sstevel@tonic-gate (void) sprintf(get_line(0, 0), 5460Sstevel@tonic-gate "Requested Options:"); 5470Sstevel@tonic-gate for (i = 0; i < opt_len; i++) { 5480Sstevel@tonic-gate entry = NULL; 5490Sstevel@tonic-gate if (*start < OPTIONS_ARRAY_SIZE) { 5500Sstevel@tonic-gate prmpt = option_types[*start]; 5510Sstevel@tonic-gate } else { 5520Sstevel@tonic-gate entry = inittab_getbycode( 553*9759SVasumathi.Sundaram@Sun.COM ITAB_CAT_STANDARD|ITAB_CAT_SITE, 554*9759SVasumathi.Sundaram@Sun.COM ITAB_CONS_SNOOP, *start); 5550Sstevel@tonic-gate if (entry == NULL) { 5560Sstevel@tonic-gate if (*start >= DHCP_SITE_OPT && 5570Sstevel@tonic-gate *start <= DHCP_END_SITE) { 5580Sstevel@tonic-gate prmpt = "Site Option"; 5590Sstevel@tonic-gate } else { 5600Sstevel@tonic-gate prmpt = "Unrecognized " 561*9759SVasumathi.Sundaram@Sun.COM "Option"; 5620Sstevel@tonic-gate } 5630Sstevel@tonic-gate } else { 5640Sstevel@tonic-gate prmpt = entry->ds_name; 5650Sstevel@tonic-gate } 5660Sstevel@tonic-gate } 5670Sstevel@tonic-gate (void) sprintf(get_line(0, 0), 5680Sstevel@tonic-gate "\t%2d (%s)", *start, prmpt); 5690Sstevel@tonic-gate start++; 5700Sstevel@tonic-gate free(entry); 5710Sstevel@tonic-gate } 5720Sstevel@tonic-gate break; 5730Sstevel@tonic-gate default: 5740Sstevel@tonic-gate opt_len = *start++; 5750Sstevel@tonic-gate entry = inittab_getbycode( 576*9759SVasumathi.Sundaram@Sun.COM ITAB_CAT_STANDARD|ITAB_CAT_SITE, 577*9759SVasumathi.Sundaram@Sun.COM ITAB_CONS_SNOOP, save); 5780Sstevel@tonic-gate if (entry == NULL) { 5790Sstevel@tonic-gate if (save >= DHCP_SITE_OPT && 5800Sstevel@tonic-gate save <= DHCP_END_SITE) 5810Sstevel@tonic-gate prmpt = "Site"; 5820Sstevel@tonic-gate else 5830Sstevel@tonic-gate prmpt = "Unrecognized"; 5840Sstevel@tonic-gate decoded_opt = NULL; 5850Sstevel@tonic-gate } else { 5860Sstevel@tonic-gate if (save < OPTIONS_ARRAY_SIZE) { 5870Sstevel@tonic-gate prmpt = option_types[save]; 5880Sstevel@tonic-gate } else { 5890Sstevel@tonic-gate prmpt = entry->ds_name; 5900Sstevel@tonic-gate } 5910Sstevel@tonic-gate decoded_opt = inittab_decode(entry, start, 592*9759SVasumathi.Sundaram@Sun.COM opt_len, B_TRUE); 5930Sstevel@tonic-gate } 5940Sstevel@tonic-gate if (decoded_opt == NULL) { 5950Sstevel@tonic-gate (void) sprintf(get_line(0, 0), 5960Sstevel@tonic-gate "%s Option = %d, length = %d octets", 5970Sstevel@tonic-gate prmpt, save, opt_len); 5980Sstevel@tonic-gate start--; 5990Sstevel@tonic-gate display_ascii_hex("\tValue =", &start); 6000Sstevel@tonic-gate } else { 6010Sstevel@tonic-gate (void) sprintf(get_line(0, 0), "%s = %s", prmpt, 602*9759SVasumathi.Sundaram@Sun.COM decoded_opt); 6030Sstevel@tonic-gate start += opt_len; 6040Sstevel@tonic-gate free(decoded_opt); 6050Sstevel@tonic-gate } 6060Sstevel@tonic-gate free(entry); 6070Sstevel@tonic-gate break; 6080Sstevel@tonic-gate }; 6090Sstevel@tonic-gate } 6100Sstevel@tonic-gate return (nooverload); 6110Sstevel@tonic-gate } 6123431Scarlsonj 6130Sstevel@tonic-gate static const char * 6140Sstevel@tonic-gate show_msgtype(unsigned char type) 6150Sstevel@tonic-gate { 6160Sstevel@tonic-gate /* 6170Sstevel@tonic-gate * note: the ordering here allows direct indexing of the table 6180Sstevel@tonic-gate * based on the RFC2131 packet type value passed in. 6190Sstevel@tonic-gate */ 6200Sstevel@tonic-gate 6210Sstevel@tonic-gate static const char *types[] = { 6220Sstevel@tonic-gate "BOOTP", 6230Sstevel@tonic-gate "DHCPDISCOVER", "DHCPOFFER", "DHCPREQUEST", "DHCPDECLINE", 6240Sstevel@tonic-gate "DHCPACK", "DHCPNAK", "DHCPRELEASE", "DHCPINFORM" 6250Sstevel@tonic-gate }; 6260Sstevel@tonic-gate 627*9759SVasumathi.Sundaram@Sun.COM if (type >= (sizeof (types) / sizeof (*types)) || types[type] == NULL) 6280Sstevel@tonic-gate return ("UNKNOWN"); 6290Sstevel@tonic-gate 6300Sstevel@tonic-gate return (types[type]); 6310Sstevel@tonic-gate } 6323431Scarlsonj 6330Sstevel@tonic-gate static void 6340Sstevel@tonic-gate display_ip(int items, char *fmt, char *msg, unsigned char **opt) 6350Sstevel@tonic-gate { 6360Sstevel@tonic-gate struct in_addr tmp; 6370Sstevel@tonic-gate int i; 6380Sstevel@tonic-gate 6390Sstevel@tonic-gate for (i = 0; i < items; i++) { 6400Sstevel@tonic-gate memcpy((char *)&tmp, *opt, sizeof (struct in_addr)); 6410Sstevel@tonic-gate (void) sprintf(get_line(0, 0), fmt, msg, inet_ntoa(tmp)); 6420Sstevel@tonic-gate *opt += 4; 6430Sstevel@tonic-gate } 6440Sstevel@tonic-gate } 6453431Scarlsonj 6460Sstevel@tonic-gate static void 6470Sstevel@tonic-gate display_ascii(char *fmt, char *msg, unsigned char **opt) 6480Sstevel@tonic-gate { 6490Sstevel@tonic-gate static unsigned char buf[256]; 650410Skcpoon int len = **opt; 6510Sstevel@tonic-gate unsigned char slen = len; 6520Sstevel@tonic-gate 6530Sstevel@tonic-gate if (len >= sizeof (buf)) 6540Sstevel@tonic-gate len = sizeof (buf) - 1; 6550Sstevel@tonic-gate (*opt)++; 6560Sstevel@tonic-gate memcpy(buf, *opt, len); 6570Sstevel@tonic-gate *(unsigned char *)(buf + len) = '\0'; 6580Sstevel@tonic-gate (void) sprintf(get_line(0, 0), fmt, msg, buf); 6590Sstevel@tonic-gate (*opt) += slen; 6600Sstevel@tonic-gate } 6613431Scarlsonj 6620Sstevel@tonic-gate static void 6630Sstevel@tonic-gate display_number(char *fmt, char *msg, unsigned char **opt) 6640Sstevel@tonic-gate { 6650Sstevel@tonic-gate int len = **opt; 6660Sstevel@tonic-gate unsigned long l_buf = 0; 6670Sstevel@tonic-gate unsigned short s_buf = 0; 6680Sstevel@tonic-gate 6690Sstevel@tonic-gate if (len > 4) { 6700Sstevel@tonic-gate (*opt)++; 6710Sstevel@tonic-gate (void) sprintf(get_line(0, 0), fmt, msg, 0xdeadbeef); 6720Sstevel@tonic-gate return; 6730Sstevel@tonic-gate } 6740Sstevel@tonic-gate switch (len) { 6750Sstevel@tonic-gate case sizeof (uchar_t): 6760Sstevel@tonic-gate (*opt)++; 6770Sstevel@tonic-gate (void) sprintf(get_line(0, 0), fmt, msg, **opt); 6780Sstevel@tonic-gate break; 6790Sstevel@tonic-gate case sizeof (ushort_t): 6800Sstevel@tonic-gate (*opt)++; 6810Sstevel@tonic-gate if (IS_P2ALIGNED(*opt, sizeof (ushort_t))) 6820Sstevel@tonic-gate /* LINTED: improper alignment */ 6830Sstevel@tonic-gate s_buf = *(unsigned short *)*opt; 6840Sstevel@tonic-gate else 6850Sstevel@tonic-gate memcpy((char *)&s_buf, *opt, len); 6860Sstevel@tonic-gate (void) sprintf(get_line(0, 0), fmt, msg, ntohs(s_buf)); 6870Sstevel@tonic-gate break; 6880Sstevel@tonic-gate case sizeof (ulong_t): 6890Sstevel@tonic-gate (*opt)++; 6900Sstevel@tonic-gate if (IS_P2ALIGNED(*opt, sizeof (ulong_t))) 6910Sstevel@tonic-gate /* LINTED: improper alignment */ 6920Sstevel@tonic-gate l_buf = *(unsigned long *)*opt; 6930Sstevel@tonic-gate else 6940Sstevel@tonic-gate memcpy((char *)&l_buf, *opt, len); 6950Sstevel@tonic-gate (void) sprintf(get_line(0, 0), fmt, msg, ntohl(l_buf)); 6960Sstevel@tonic-gate break; 6970Sstevel@tonic-gate } 6980Sstevel@tonic-gate (*opt) += len; 6990Sstevel@tonic-gate } 7003431Scarlsonj 7010Sstevel@tonic-gate static void 7020Sstevel@tonic-gate display_ascii_hex(char *msg, unsigned char **opt) 7030Sstevel@tonic-gate { 7040Sstevel@tonic-gate int printable; 7050Sstevel@tonic-gate char buffer[512]; 7060Sstevel@tonic-gate char *line, *tmp, *ap, *fmt; 707*9759SVasumathi.Sundaram@Sun.COM int i, len = **opt; 7080Sstevel@tonic-gate 7090Sstevel@tonic-gate line = get_line(0, 0); 7100Sstevel@tonic-gate 7110Sstevel@tonic-gate (*opt)++; 7120Sstevel@tonic-gate 7130Sstevel@tonic-gate if (len >= 255) { 7140Sstevel@tonic-gate (void) sprintf(line, "\t%s <TOO LONG>", msg); 7150Sstevel@tonic-gate return; 7160Sstevel@tonic-gate } 7170Sstevel@tonic-gate 7180Sstevel@tonic-gate for (printable = 1, tmp = (char *)(*opt), ap = buffer; 7190Sstevel@tonic-gate tmp < (char *)&((*opt)[len]); tmp++) { 7200Sstevel@tonic-gate if (isprint(*tmp)) 7210Sstevel@tonic-gate *ap++ = *tmp; 7220Sstevel@tonic-gate else { 7230Sstevel@tonic-gate *ap++ = '.'; 7240Sstevel@tonic-gate printable = 0; 7250Sstevel@tonic-gate } 7260Sstevel@tonic-gate } 7270Sstevel@tonic-gate *ap = '\0'; 7280Sstevel@tonic-gate 7290Sstevel@tonic-gate if (!printable) { 7300Sstevel@tonic-gate for (tmp = (char *)(*opt), ap = buffer; 731*9759SVasumathi.Sundaram@Sun.COM (tmp < (char *)&((*opt)[len])) && ((ap + 5) < &buffer[512]); 7320Sstevel@tonic-gate tmp++) { 7330Sstevel@tonic-gate ap += sprintf(ap, "0x%02X ", *(uchar_t *)(tmp)); 7340Sstevel@tonic-gate } 735*9759SVasumathi.Sundaram@Sun.COM /* Truncate the trailing space */ 7360Sstevel@tonic-gate *(--ap) = '\0'; 737*9759SVasumathi.Sundaram@Sun.COM /* More bytes to print in hex but no space in buffer */ 738*9759SVasumathi.Sundaram@Sun.COM if (tmp < (char *)&((*opt)[len])) { 739*9759SVasumathi.Sundaram@Sun.COM i = ap - buffer; 740*9759SVasumathi.Sundaram@Sun.COM buffer[i - 1] = '.'; 741*9759SVasumathi.Sundaram@Sun.COM buffer[i - 2] = '.'; 742*9759SVasumathi.Sundaram@Sun.COM buffer[i - 3] = '.'; 743*9759SVasumathi.Sundaram@Sun.COM } 7440Sstevel@tonic-gate fmt = "%s\t%s (unprintable)"; 7450Sstevel@tonic-gate } else { 7460Sstevel@tonic-gate fmt = "%s\t\"%s\""; 7470Sstevel@tonic-gate } 7480Sstevel@tonic-gate (*opt) += len; 7490Sstevel@tonic-gate (void) sprintf(line, fmt, msg, buffer); 7500Sstevel@tonic-gate } 751