/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <string.h>
#include <sys/sysmacros.h>
#include <dhcp_inittab.h>
#include <dhcp_symbol.h>
#include "snoop.h"
static const char *show_msgtype(unsigned char);
static int show_options(unsigned char *, int);
static void display_ip(int, char *, char *, unsigned char **);
static void display_ascii(char *, char *, unsigned char **);
static void display_number(char *, char *, unsigned char **);
static void display_ascii_hex(char *, unsigned char **);
static char *option_types[] = {
"", /* 0 */
"Subnet Mask", /* 1 */
"UTC Time Offset", /* 2 */
"Router", /* 3 */
"RFC868 Time Servers", /* 4 */
"IEN 116 Name Servers", /* 5 */
"DNS Servers", /* 6 */
"UDP LOG Servers", /* 7 */
"RFC 865 Cookie Servers", /* 8 */
"RFC 1179 Line Printer Servers (LPR)", /* 9 */
"Impress Servers", /* 10 */
"RFC 887 Resource Location Servers", /* 11 */
"Client Hostname", /* 12 */
"Boot File size in 512 byte Blocks", /* 13 */
"Merit Dump File", /* 14 */
"DNS Domain Name", /* 15 */
"SWAP Server", /* 16 */
"Client Root Path", /* 17 */
"BOOTP options extensions path", /* 18 */
"IP Forwarding Flag", /* 19 */
"NonLocal Source Routing Flag", /* 20 */
"Policy Filters for NonLocal Routing", /* 21 */
"Maximum Datagram Reassembly Size", /* 22 */
"Default IP Time To Live", /* 23 */
"Path MTU Aging Timeout", /* 24 */
"Path MTU Size Plateau Table", /* 25 */
"Interface MTU Size", /* 26 */
"All Subnets are Local Flag", /* 27 */
"Broadcast Address", /* 28 */
"Perform Mask Discovery Flag", /* 29 */
"Mask Supplier Flag", /* 30 */
"Perform Router Discovery Flag", /* 31 */
"Router Solicitation Address", /* 32 */
"Static Routes", /* 33 */
"Trailer Encapsulation Flag", /* 34 */
"ARP Cache Timeout Seconds", /* 35 */
"Ethernet Encapsulation Flag", /* 36 */
"TCP Default Time To Live", /* 37 */
"TCP Keepalive Interval Seconds", /* 38 */
"TCP Keepalive Garbage Flag", /* 39 */
"NIS Domainname", /* 40 */
"NIS Servers", /* 41 */
"Network Time Protocol Servers", /* 42 */
"Vendor Specific Options", /* 43 */
"NetBIOS RFC 1001/1002 Name Servers", /* 44 */
"NetBIOS Datagram Dist. Servers", /* 45 */
"NetBIOS Node Type", /* 46 */
"NetBIOS Scope", /* 47 */
"X Window Font Servers", /* 48 */
"X Window Display Manager Servers", /* 49 */
"Requested IP Address", /* 50 */
"IP Address Lease Time", /* 51 */
"Option Field Overload Flag", /* 52 */
"DHCP Message Type", /* 53 */
"DHCP Server Identifier", /* 54 */
"Option Request List", /* 55 */
"Error Message", /* 56 */
"Maximum DHCP Message Size", /* 57 */
"Renewal (T1) Time Value", /* 58 */
"Rebinding (T2) Time Value", /* 59 */
"Client Class Identifier =", /* 60 */
"Client Identifier =", /* 61 */
"Netware IP Domain =", /* 62 */
"Netware IP Options =", /* 63 */
"TFTP Server Name", /* 66 */
"Option BootFile Name", /* 67 */
"Mobile IP Agents", /* 68 */
"Simple Mail (SMTP) Servers", /* 69 */
"Post Office (POP3) Servers", /* 70 */
"Net News (NNTP) Servers", /* 71 */
"WorldWideWeb Servers", /* 72 */
"Finger Servers", /* 73 */
"Internet Relay Chat (IRC) Servers", /* 74 */
"StreetTalk Servers", /* 75 */
"StreetTalk Directory Assist. Servers", /* 76 */
"User Class Identifier", /* 77 */
};
int
{
(void) sprintf(get_sum_line(),
} else {
case BOOTREQUEST:
(void) sprintf(get_sum_line(),
break;
case BOOTREPLY:
(void) sprintf(get_sum_line(),
break;
}
}
}
len);
show_space();
dlc_header, 1),
dlc_header, 1),
dlc_header, 1),
dlc_header, 4),
dlc_header, 2),
dlc_header, 2),
"Your client address (yiaddr) = %s",
"Next server address (siaddr) = %s",
"Relay agent address (giaddr) = %s",
"Client hardware address (chaddr) = %.2X:%.2X:%.2X:%.2X:%.2X:%.2X",
}
/*
* Check cookie, process options
*/
"Unrecognized cookie: 0x%.2X%.2X%.2X%.2X\n",
return (0);
}
show_space();
show_space();
case 0:
/* No option overloading */
}
}
break;
case 1:
/* file field used */
}
show_space();
show_space();
break;
case 2:
/* sname field used for options */
}
show_space();
show_space();
break;
case 3:
show_space();
show_space();
show_space();
show_space();
break;
};
}
return (len);
}
static int
{
char *prmpt;
int items, i;
int nooverload = 0;
char *decoded_opt;
int opt_len;
start++;
continue;
}
break; /* done */
switch (save) {
/* Network order IP address(es) */
case CD_SUBNETMASK:
case CD_ROUTER_SOLICIT_SERV:
case CD_BROADCASTADDR:
case CD_REQUESTED_IP_ADDR:
case CD_SERVER_ID:
/* Single IP address */
if (*start != 4) {
} else {
start++;
&start);
}
break;
case CD_ROUTER:
case CD_TIMESERV:
case CD_IEN116_NAME_SERV:
case CD_DNSSERV:
case CD_LOG_SERV:
case CD_COOKIE_SERV:
case CD_LPR_SERV:
case CD_IMPRESS_SERV:
case CD_RESOURCE_SERV:
case CD_SWAP_SERV:
case CD_NIS_SERV:
case CD_NTP_SERV:
case CD_NETBIOS_NAME_SERV:
case CD_NETBIOS_DIST_SERV:
case CD_XWIN_FONT_SERV:
case CD_XWIN_DISP_SERV:
case CD_MOBILE_IP_AGENT:
case CD_SMTP_SERVS:
case CD_POP3_SERVS:
case CD_NNTP_SERVS:
case CD_WWW_SERVS:
case CD_FINGER_SERVS:
case CD_IRC_SERVS:
case CD_STREETTALK_SERVS:
case CD_STREETTALK_DA_SERVS:
/* Multiple IP addresses */
if ((*start % 4) != 0) {
"Error: Bad %s address",
option_types[save]);
} else {
}
break;
case CD_TFTP_SERV_NAME:
case CD_HOSTNAME:
case CD_DUMP_FILE:
case CD_DNSDOMAIN:
case CD_ROOT_PATH:
case CD_NIS_DOMAIN:
case CD_NETBIOS_SCOPE:
case CD_MESSAGE:
case CD_OPT_BOOTFILE_NAME:
case CD_USER_CLASS_ID:
/* Ascii strings */
break;
case CD_TIMEOFFSET:
case CD_IPTTL:
case CD_PATH_MTU_TIMEOUT:
case CD_ARP_TIMEOUT:
case CD_TCP_TTL:
case CD_TCP_KALIVE_INTVL:
case CD_T1_TIME:
case CD_T2_TIME:
case CD_LEASE_TIME:
/* Number: seconds */
&start);
break;
case CD_IP_FORWARDING_ON:
case CD_NON_LCL_ROUTE_ON:
case CD_ALL_SUBNETS_LCL_ON:
case CD_MASK_DISCVRY_ON:
case CD_MASK_SUPPLIER_ON:
case CD_ROUTER_DISCVRY_ON:
case CD_TRAILER_ENCAPS_ON:
case CD_ETHERNET_ENCAPS_ON:
case CD_TCP_KALIVE_GRBG_ON:
/* Number: hex flag */
&start);
break;
case CD_MAXIPSIZE:
case CD_MTU:
case CD_MAX_DHCP_SIZE:
/* Number: bytes */
&start);
break;
case CD_CLASS_ID:
case CD_CLIENT_ID:
case CD_NW_IP_DOMAIN:
case CD_NW_IP_OPTIONS:
/* Hex ascii strings */
break;
case CD_BOOT_SIZE:
display_number("%s = %d 512 byte blocks",
"Boot file size", &start);
break;
case CD_POLICY_FILTER:
if ((*start % 8) != 0) {
"Error: Bad Policy Filter option");
} else {
for (i = 0; i < items; i++) {
display_ip(1,
"%s = %s",
"Policy Destination",
&start);
&start);
}
}
break;
case CD_PATH_MTU_TABLE_SZ:
if (*start % 2 != 0) {
"Error: Bad Path MTU Table");
} else {
"\tPath MTU Plateau Table:");
"\t=======================");
++start;
for (i = 0; i < items; i++) {
if (IS_P2ALIGNED(start,
sizeof (ushort_t))) {
/* LINTED: improper alignment */
} else {
start, sizeof (short));
}
"\t\tEntry %d:\t\t%d", i,
}
}
break;
case CD_STATIC_ROUTE:
if ((*start % 8) != 0) {
"Error: Bad Static Route option: %d",
*start);
} else {
for (i = 0; i < items; i++) {
sizeof (struct in_addr));
sizeof (struct in_addr));
"Static route from %s to %s",
}
}
break;
case CD_VENDOR_SPEC:
i = *start++;
"Vendor-specific Options (%d total octets):", i);
/*
* We don't know what these things are, so just
* display the option number, length, and value
* (hex).
*/
start++;
continue;
}
"\t(%.2d) %.2d octets", *start,
start++;
}
break;
case CD_NETBIOS_NODE_TYPE:
if (*start != 1) {
"Error: Bad '%s' parameter",
} else {
char *type;
start++;
switch (*start) {
case 0x1:
type = "Broadcast Node";
break;
case 0x2:
type = "Point To Point Node";
break;
case 0x4:
type = "Mixed Mode Node";
break;
case 0x8:
type = "Hybrid Node";
break;
default:
type = "??? Node";
break;
};
"%s = %s (%d)",
start++;
}
break;
case CD_OPTION_OVERLOAD:
if (*start != 1) {
"Bad Option Overload value.");
} else {
start++;
nooverload = *start++;
}
break;
case CD_DHCP_TYPE:
"Bad DHCP Message Type.");
} else {
start++;
"Message type = %s",
show_msgtype(*start));
start++;
}
break;
case CD_REQUEST_LIST:
"Requested Options:");
for (i = 0; i < opt_len; i++) {
if (*start < OPTIONS_ARRAY_SIZE) {
} else {
ITAB_CONS_SNOOP, *start);
if (*start >= DHCP_SITE_OPT &&
*start <= DHCP_END_SITE) {
prmpt = "Site Option";
} else {
prmpt = "Unrecognized "
"Option";
}
} else {
}
}
start++;
}
break;
default:
if (save >= DHCP_SITE_OPT &&
save <= DHCP_END_SITE)
prmpt = "Site";
else
prmpt = "Unrecognized";
decoded_opt = NULL;
} else {
if (save < OPTIONS_ARRAY_SIZE) {
} else {
}
}
if (decoded_opt == NULL) {
"%s Option = %d, length = %d octets",
start--;
} else {
}
break;
};
}
return (nooverload);
}
static const char *
{
/*
* note: the ordering here allows direct indexing of the table
* based on the RFC2131 packet type value passed in.
*/
static const char *types[] = {
"BOOTP",
"DHCPDISCOVER", "DHCPOFFER", "DHCPREQUEST", "DHCPDECLINE",
"DHCPACK", "DHCPNAK", "DHCPRELEASE", "DHCPINFORM"
};
return ("UNKNOWN");
}
static void
{
int i;
for (i = 0; i < items; i++) {
*opt += 4;
}
}
static void
{
(*opt)++;
}
static void
{
unsigned long l_buf = 0;
unsigned short s_buf = 0;
if (len > 4) {
(*opt)++;
return;
}
switch (len) {
case sizeof (uchar_t):
(*opt)++;
break;
case sizeof (ushort_t):
(*opt)++;
/* LINTED: improper alignment */
else
break;
case sizeof (ulong_t):
(*opt)++;
/* LINTED: improper alignment */
else
break;
}
}
static void
{
int printable;
(*opt)++;
if (len >= 255) {
return;
}
else {
*ap++ = '.';
printable = 0;
}
}
*ap = '\0';
if (!printable) {
tmp++) {
}
/* Truncate the trailing space */
*(--ap) = '\0';
/* More bytes to print in hex but no space in buffer */
}
fmt = "%s\t%s (unprintable)";
} else {
fmt = "%s\t\"%s\"";
}
}