ip_icmp.c revision a68b0110cd3338c318b355c0ac5ac72f92e510b7
/*
* Copyright (c) 1982, 1986, 1988, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)ip_icmp.c 8.2 (Berkeley) 1/4/94
* ip_icmp.c,v 1.7 1995/05/30 08:09:42 rgrimes Exp
*/
#include "slirp.h"
#include "ip_icmp.h"
/* The message sent when emulating PING */
/* Be nice and tell them it's just a psuedo-ping packet */
static const char icmp_ping_msg[] = "This is a psuedo-PING packet used by Slirp to emulate ICMP ECHO-REQUEST packets.\n";
/* list of actions for icmp_error() on RX of an icmp message */
static const int icmp_flush[19] = {
/* ECHO REPLY (0) */ 0,
1,
1,
/* DEST UNREACH (3) */ 1,
/* SOURCE QUENCH (4)*/ 1,
/* REDIRECT (5) */ 1,
1,
1,
/* ECHO (8) */ 0,
/* ROUTERADVERT (9) */ 1,
/* ROUTERSOLICIT (10) */ 1,
/* TIME EXCEEDED (11) */ 1,
/* PARAMETER PROBLEM (12) */ 1,
/* TIMESTAMP (13) */ 0,
/* TIMESTAMP REPLY (14) */ 0,
/* INFO (15) */ 0,
/* INFO REPLY (16) */ 0,
/* ADDR MASK (17) */ 0,
/* ADDR MASK REPLY (18) */ 0
};
/*
* Process a received ICMP message.
*/
void
{
/* int code; */
DEBUG_CALL("icmp_input");
DEBUG_ARG("m = %lx", (long )m);
/*
* Locate icmp structure in mbuf, and check
* that its not corrupted and of at least minimum length.
*/
goto end_error;
}
goto freeit;
}
/* icmpstat.icps_inhist[icp->icmp_type]++; */
/* code = icp->icmp_code; */
case ICMP_ECHO:
icmp_reflect(pData, m);
} else {
struct sockaddr_in addr;
goto end_error;
}
/* Send the packet */
/* It's an alias */
case CTL_DNS:
break;
case CTL_ALIAS:
default:
break;
}
} else {
}
}
} /* if ip->ip_dst.s_addr == alias_addr.s_addr */
break;
case ICMP_UNREACH:
/* XXX? report error? close socket? */
case ICMP_TIMXCEED:
case ICMP_PARAMPROB:
case ICMP_SOURCEQUENCH:
case ICMP_TSTAMP:
case ICMP_MASKREQ:
case ICMP_REDIRECT:
break;
default:
} /* swith */
/* m is m_free()'d xor put in a socket xor or given to ip_send */
return;
}
/*
* Send an ICMP message in response to a situation
*
* RFC 1122: 3.2.2 MUST send at least the IP header and 8 bytes of header. MAY send more (we do).
* MUST NOT change this header information.
* MUST reply to only the first fragment.
*/
/*
* Send ICMP_UNREACH back to the source regarding msrc.
* mbuf *msrc is used as a template, but is NOT m_free()'d.
* It is reported as the bad ip packet. The header should
* be fully correct and in host byte order.
* ICMP fragmentation is illegal. All machines must accept 576 bytes in one
* packet. The maximum payload is 576-20(ip hdr)-8(icmp hdr)=548
*/
void icmp_error(PNATState pData, struct mbuf *msrc, u_char type, u_char code, int minsize, char *message)
{
register struct mbuf *m;
DEBUG_CALL("icmp_error");
/* check msrc */
#if DEBUG
}
#endif
/*
* Assume any unknown ICMP type is an error. This isn't
* specified by the RFC, but think about it..
*/
}
/* make a copy */
{ int new_m_size;
}
/* make the header of the reply packet */
/* fill in icmp */
/* min. size = 8+sizeof(struct ip)+8 */
#if DEBUG
if(message) { /* DEBUG : append message to ICMP packet */
int message_len;
char *cpnt;
m->m_len+=message_len;
}
#endif
icp->icmp_cksum = 0;
/* fill in ip */
return;
}
/*
* Reflect the ip packet back to the source
*/
void
{
/*
* Send an icmp packet back to the ip level,
* after supplying a checksum.
*/
icp->icmp_cksum = 0;
/* fill in ip */
if (optlen > 0) {
/*
* Strip out original options by copying rest of first
* mbuf's data back, and adjust the IP length.
*/
}
{ /* swap */
}
}