ip_icmp.c revision 5f8ee4264a4d1d5d5fcba26804ddc4cb91393d57
1879N/A * Copyright (c) 1982, 1986, 1988, 1993 0N/A * The Regents of the University of California. All rights reserved. 0N/A * Redistribution and use in source and binary forms, with or without 0N/A * modification, are permitted provided that the following conditions 0N/A * 1. Redistributions of source code must retain the above copyright 0N/A * notice, this list of conditions and the following disclaimer. 0N/A * 2. Redistributions in binary form must reproduce the above copyright 0N/A * notice, this list of conditions and the following disclaimer in the 0N/A * documentation and/or other materials provided with the distribution. 0N/A * 3. All advertising materials mentioning features or use of this software 0N/A * must display the following acknowledgement: 0N/A * This product includes software developed by the University of 0N/A * California, Berkeley and its contributors. 0N/A * 4. Neither the name of the University nor the names of its contributors 0N/A * may be used to endorse or promote products derived from this software 1472N/A * without specific prior written permission. 1472N/A * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 0N/A * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 0N/A * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 0N/A * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 1879N/A * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 3695N/A * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 3695N/A * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 3695N/A * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 3695N/A * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 1879N/A * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 0N/A#
else /* VBOX_WITH_SIMPLIFIED_SLIRP_SYNC */ 0N/A#
endif /* !VBOX_WITH_SIMPLIFIED_SLIRP_SYNC */ 0N/A/* The message sent when emulating PING */ 0N/A/* Be nice and tell them it's just a psuedo-ping packet */ 0N/Astatic const char icmp_ping_msg[] =
"This is a psuedo-PING packet used by Slirp to emulate ICMP ECHO-REQUEST packets.\n";
0N/A/* list of actions for icmp_error() on RX of an icmp message */ /* ROUTERADVERT (9) */ 1,
/* ROUTERSOLICIT (10) */ 1,
/* TIME EXCEEDED (11) */ 1,
/* PARAMETER PROBLEM (12) */ 1,
/* TIMESTAMP REPLY (14) */ 0,
/* ADDR MASK REPLY (18) */ 0
#
else /* !RT_OS_DARWIN */#
endif /* RT_OS_DARWIN */ LogRel((
"NAT: ICMP/ping not available (could open ICMP socket, error %Rrc)\n",
rc));
#
else /* RT_OS_WINDOWS */ LogRel((
"NAT: Icmp.dll could not be loaded\n"));
LogRel((
"NAT: Can't find IcmpParseReplies symbol\n"));
LogRel((
"NAT: Can't find IcmpCloseHandle symbol\n"));
#
endif /* VBOX_WITH_SIMPLIFIED_SLIRP_SYNC */#
endif /* RT_OS_WINDOWS */ * ip here is ip header + 64bytes readed from ICMP packet Log((
"Have found nothing\n"));
* for TCP and UDP logic little bit reverted, we try to find the HOST socket * from which the IP package has been sent. /* check last socket first */ /* Should be reaplaced by hash here */ Log((
"hit:%R[natsock]\n",
so));
/*XXX: this storage not very long, * better add flag if it should removed from lis * Process a received ICMP message. * Locate icmp structure in mbuf, and check * that its not corrupted and of at least minimum length. /* min 8 bytes payload */ /* icmpstat.icps_inhist[icp->icmp_type]++; */ /* code = icp->icmp_code; */ LogRel((
"NAT: Error (%s) occurred while setting TTL attribute of IP packet\n",
* We're freeing the ICMP message, which unable sent or process. * That behavior described in rfc 793, we shouldn't notify sender about * fail of processing it's ICMP packets #
else /* RT_OS_WINDOWS */ LogRel((
"NAT: Error (%d) occurred while sending ICMP (",
error));
LogRel((
"operation is unsupported)\n"));
LogRel((
"Buffer too small)\n"));
LogRel((
"Other error!!!)\n"));
#
endif /* RT_OS_WINDOWS */ /* XXX? report error? close socket? */ /* m is m_free()'d xor put in a socket xor or given to ip_send */ * 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 goto end_error;
/* Only reply to fragment 0 */ * Assume any unknown ICMP type is an error. This isn't * specified by the RFC, but think about it.. /* make the header of the reply packet */ hlen =
sizeof(
struct ip );
/* no options in reply */ /* min. size = 8+sizeof(struct ip)+8 */ /* DEBUG : append message to ICMP packet */ * Reflect the ip packet back to the source * Send an icmp packet back to the ip level, * after supplying a checksum.