snoop_icmp.c revision 7ba7860f5af89005c23337fb7cdc48145cc6b8ac
/*
* 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 <stdio.h>
#include <string.h>
#include <sys/sysmacros.h>
#include <netinet/in_systm.h>
#include <netdb.h>
#include "snoop.h"
#include "snoop_mip.h"
static void interpret_options(char *, int);
static void interpret_mldv2qry(icmp6_t *, int);
static void interpret_mldv2rpt(icmp6_t *, int);
/* Mobile-IP routines from snoop_mip.c */
extern void interpret_icmp_mip_ext(uchar_t *, int);
extern const char *get_mip_adv_desc(uint8_t);
/* Router advertisement message structure. */
struct icmp_ra_addr {
};
/*ARGSUSED*/
void
{
char *line;
/* Each router has a name 256 char long .. */
int num_rtr_addrs = 0;
extern char *prot_nest_prefix;
if (ilen < ICMP_MINLEN)
return; /* incomplete header */
pt = "Unknown";
pc = "";
px = "";
case ICMP_ECHOREPLY:
pt = "Echo reply";
break;
case ICMP_UNREACH:
pt = "Destination unreachable";
case ICMP_UNREACH_NET:
if (ilen >= ICMP_ADVLENMIN) {
} else {
pc = "Bad net";
}
break;
case ICMP_UNREACH_HOST:
if (ilen >= ICMP_ADVLENMIN) {
} else {
pc = "Bad host";
}
break;
case ICMP_UNREACH_PROTOCOL:
if (ilen >= ICMP_ADVLENMIN) {
} else {
pc = "Bad protocol";
}
break;
case ICMP_UNREACH_PORT:
if (ilen >= ICMP_ADVLENMIN) {
case IPPROTO_TCP:
" unreachable",
break;
case IPPROTO_UDP:
" unreachable",
break;
default:
pc = "Port unreachable";
break;
}
} else {
pc = "Bad port";
}
break;
case ICMP_UNREACH_NEEDFRAG:
" next hop MTU = %d",
} else {
pc = "Needed to fragment";
}
break;
case ICMP_UNREACH_SRCFAIL:
pc = "Source route failed";
break;
case ICMP_UNREACH_NET_UNKNOWN:
pc = "Unknown network";
break;
pc = "Unknown host";
break;
case ICMP_UNREACH_ISOLATED:
pc = "Source host isolated";
break;
case ICMP_UNREACH_NET_PROHIB:
pc = "Net administratively prohibited";
break;
case ICMP_UNREACH_HOST_PROHIB:
pc = "Host administratively prohibited";
break;
case ICMP_UNREACH_TOSNET:
pc = "Net unreachable for this TOS";
break;
case ICMP_UNREACH_TOSHOST:
pc = "Host unreachable for this TOS";
break;
pc = "Communication administratively prohibited";
break;
pc = "Host precedence violation";
break;
pc = "Precedence cutoff in effect";
break;
default:
break;
}
break;
case ICMP_SOURCEQUENCH:
pt = "Packet lost, slow down";
break;
case ICMP_REDIRECT:
pt = "Redirect";
case ICMP_REDIRECT_NET:
pc = "for network";
break;
case ICMP_REDIRECT_HOST:
pc = "for host";
break;
case ICMP_REDIRECT_TOSNET:
pc = "for tos and net";
break;
case ICMP_REDIRECT_TOSHOST:
pc = "for tos and host";
break;
default:
break;
}
break;
case ICMP_ECHO:
pt = "Echo request";
break;
case ICMP_ROUTERADVERT:
pt = "Router advertisement";
struct icmp_ra_addr *ra;
char ra_ext_buf[50];
int icmp_ra_len;
int i;
/* Cannot trust anything from the network... */
for (i = 0; i < num_rtr_addrs; i++) {
" {%s %u}",
sizeof (buff)) {
sizeof (buff));
break;
}
ra++;
}
sizeof (struct icmp_ra_addr);
if (ilen > icmp_ra_len) {
int ocurr_len;
extbuff[0] = '\0';
while (curr_len > 0) {
/* Append Mobile-IP description */
(void) snprintf(ra_ext_buf,
sizeof (ra_ext_buf), ", %s",
sizeof (extbuff));
/* Special case for padding */
curr_len--;
((char *)exthdr + 1);
continue;
}
/* else normal extension */
/* detect bad length */
break;
((char *)exthdr +
sizeof (*exthdr) +
}
}
}
break;
case ICMP_ROUTERSOLICIT:
pt = "Router solicitation";
break;
case ICMP_TIMXCEED:
pt = "Time exceeded";
case ICMP_TIMXCEED_INTRANS:
pc = "in transit";
break;
case ICMP_TIMXCEED_REASS:
pc = "in reassembly";
break;
default:
break;
}
break;
case ICMP_PARAMPROB:
pt = "IP parameter problem";
case ICMP_PARAMPROB_OPTABSENT:
pc = "Required option missing";
break;
case ICMP_PARAMPROB_BADLENGTH:
pc = "Bad length";
break;
case 0: /* Should this be the default? */
default:
break;
}
break;
case ICMP_TSTAMP:
pt = "Timestamp request";
break;
case ICMP_TSTAMPREPLY:
pt = "Timestamp reply";
break;
case ICMP_IREQ:
pt = "Information request";
break;
case ICMP_IREQREPLY:
pt = "Information reply";
break;
case ICMP_MASKREQ:
pt = "Address mask request";
break;
case ICMP_MASKREPLY:
pt = "Address mask reply";
break;
default:
break;
}
line = get_sum_line();
if (*pc) {
if (*px) {
} else {
}
} else {
}
}
show_space();
if (*pc) {
} else {
}
if (ilen > 28) {
show_space();
"[ subject header follows ]");
show_space();
prot_nest_prefix = "ICMP:";
(void) interpret_ip(flags,
prot_nest_prefix = "";
}
if (ilen > 28) {
show_space();
"[ subject header follows ]");
show_space();
prot_nest_prefix = "ICMP:";
(void) interpret_ip(flags,
prot_nest_prefix = "";
}
int icmp_ra_len;
show_space();
sizeof (struct icmp_ra_addr);
prot_nest_prefix = "";
if (ilen > icmp_ra_len) {
ilen - icmp_ra_len);
}
}
}
show_space();
}
}
/*ARGSUSED*/
void
int flags;
{
char *line;
extern char *prot_nest_prefix;
char addrstr[INET6_ADDRSTRLEN];
char buff[2048];
if (ilen < ICMP6_MINLEN)
return; /* incomplete header */
pt = "Unknown";
pc = "";
switch (icmp6->icmp6_type) {
case ICMP6_DST_UNREACH:
pt = "Destination unreachable";
switch (icmp6->icmp6_code) {
pc = "No route to destination";
break;
case ICMP6_DST_UNREACH_ADMIN:
pc = "Communication administratively prohibited";
break;
case ICMP6_DST_UNREACH_ADDR:
pc = "Address unreachable";
break;
case ICMP6_DST_UNREACH_NOPORT:
sizeof (struct udphdr)) {
switch (orig_ip6hdr->ip6_nxt) {
case IPPROTO_TCP: {
" unreachable",
break;
}
case IPPROTO_UDP: {
" unreachable",
break;
}
default:
pc = "Port unreachable";
break;
}
} else {
pc = "Bad port";
}
break;
default:
break;
}
break;
case ICMP6_PACKET_TOO_BIG:
pt = "Packet too big";
break;
case ND_REDIRECT:
pt = "Redirect";
break;
case ICMP6_TIME_EXCEEDED:
pt = "Time exceeded";
switch (icmp6->icmp6_code) {
pc = "Hop limit exceeded in transit";
break;
pc = "Fragment reassembly time exceeded";
break;
default:
break;
}
break;
case ICMP6_PARAM_PROB:
pt = "Parameter problem";
switch (icmp6->icmp6_code) {
case ICMP6_PARAMPROB_HEADER:
pc = "Erroneous header field";
break;
pc = "Unrecognized next header type";
break;
case ICMP6_PARAMPROB_OPTION:
pc = "Unrecognized IPv6 option";
break;
}
break;
case ICMP6_ECHO_REQUEST:
pt = "Echo request";
break;
case ICMP6_ECHO_REPLY:
pt = "Echo reply";
break;
case MLD_LISTENER_QUERY:
if (ilen == MLD_MINLEN)
pt = "Group membership query - MLDv1";
else if (ilen >= MLD_V2_QUERY_MINLEN)
pt = "Group membership query - MLDv2";
else
pt = "Unknown membership query";
break;
case MLD_LISTENER_REPORT:
pt = "Group membership report - MLDv1";
break;
case MLD_LISTENER_REDUCTION:
pt = "Group membership termination - MLDv1";
break;
case MLD_V2_LISTENER_REPORT:
pt = "Group membership report - MLDv2";
break;
case ND_ROUTER_SOLICIT:
pt = "Router solicitation";
break;
case ND_ROUTER_ADVERT:
pt = "Router advertisement";
break;
case ND_NEIGHBOR_SOLICIT:
pt = "Neighbor solicitation";
break;
case ND_NEIGHBOR_ADVERT:
pt = "Neighbor advertisement";
break;
default:
break;
}
line = get_sum_line();
if (*pc)
else
}
show_space();
if (*pc)
else
icmp6->icmp6_code);
switch (icmp6->icmp6_type) {
case ICMP6_DST_UNREACH:
show_space();
"[ subject header follows ]");
show_space();
prot_nest_prefix = "ICMPv6:";
prot_nest_prefix = "";
}
break;
case ICMP6_PACKET_TOO_BIG:
show_space();
" Packet too big MTU = %d",
show_space();
break;
case ND_REDIRECT: {
"Destination address= %s",
show_space();
break;
}
case ND_NEIGHBOR_SOLICIT: {
struct nd_neighbor_solicit *ns;
break;
show_space();
break;
}
case ND_NEIGHBOR_ADVERT: {
struct nd_neighbor_advert *na;
break;
"Router flag: %s, Solicited flag: %s, "
"Override flag: %s",
"SET" : "NOT SET",
"SET" : "NOT SET",
"SET" : "NOT SET");
show_space();
}
break;
case ND_ROUTER_SOLICIT: {
if (ilen < sizeof (struct nd_router_solicit))
break;
(char *)icmp6 + sizeof (struct nd_router_solicit),
ilen - sizeof (struct nd_router_solicit));
break;
}
case ND_ROUTER_ADVERT: {
struct nd_router_advert *ra;
break;
"Max hops= %d, Router lifetime= %d",
"Managed addr conf flag: %s, Other conf flag: %s",
"SET" : "NOT SET",
"SET" : "NOT SET");
"Reachable time: %u, Reachable retrans time %u",
show_space();
break;
}
case ICMP6_PARAM_PROB:
break;
show_space();
break;
case MLD_LISTENER_QUERY: {
if (ilen < MLD_MINLEN)
break;
if (ilen >= MLD_V2_QUERY_MINLEN) {
} else {
"Multicast address= %s",
}
show_space();
break;
}
case MLD_LISTENER_REPORT:
case MLD_LISTENER_REDUCTION: {
break;
show_space();
break;
}
case MLD_V2_LISTENER_REPORT: {
show_space();
break;
}
default:
break;
}
}
}
static void
char *optc;
int ilen;
{
#define PREFIX_OPTION_LENGTH 4
#define MTU_OPTION_LENGTH 1
#define PREFIX_INFINITY 0xffffffffUL
struct nd_opt_hdr *opt;
if (opt->nd_opt_len == 0)
return;
switch (opt->nd_opt_type) {
case ND_OPT_SOURCE_LINKADDR:
case ND_OPT_TARGET_LINKADDR:
{
struct nd_opt_lla *lopt;
int i;
break;
"+++ ICMPv6 Source LL Addr option +++");
} else {
"+++ ICMPv6 Target LL Addr option +++");
}
/*
* The option length is in 8 octet units, and
* includes the first two bytes (the type and
* lenght fields) of the option.
*/
for (i = 0; i < addr_len; i++) {
sizeof (chbuf));
break;
}
}
if (buf)
"Link Layer address: %s", chbuf);
show_space();
break;
}
case ND_OPT_MTU: {
struct nd_opt_mtu *mopt;
ilen < sizeof (struct nd_opt_mtu))
break;
"+++ ICMPv6 MTU option +++");
show_space();
break;
}
case ND_OPT_PREFIX_INFORMATION: {
struct nd_opt_prefix_info *popt;
char validstr[30];
char preferredstr[30];
char prefixstr[INET6_ADDRSTRLEN];
ilen < sizeof (struct nd_opt_prefix_info))
break;
"+++ ICMPv6 Prefix option +++");
"Onlink flag: %s, Autonomous addr conf flag: %s",
else
else
"Valid Lifetime %s, Preferred Lifetime %s",
show_space();
}
default:
break;
}
}
}
static void
{
int srccnt;
char addrstr[INET6_ADDRSTRLEN];
"Malformed MLD Query");
return;
}
srccnt--;
src++;
}
}
#define MAX_MLDV2_REPORT_TYPE 6
const char *mldv2rpt_types[] = {
"<unknown>",
"MODE_IS_INCLUDE",
"MODE_IS_EXCLUDE",
"CHANGE_TO_INCLUDE",
"CHANGE_TO_EXCLUDE",
"ALLOW_NEW_SOURCES",
"BLOCK_OLD_SOURCES",
};
static void
{
char addrstr[INET6_ADDRSTRLEN];
"Malformed MLDv2 Report");
return;
}
srccnt--;
src++;
}
marcnt--;
}
}