VirtualBox

source: vbox/trunk/src/VBox/Devices/Network/slirp/ip_icmp.c@ 15266

Last change on this file since 15266 was 15241, checked in by vboxsync, 16 years ago

slirp:icmp: Vista fix (according the forums) IcmpSendEchoes require any non-0 timeout to work on Vista.

  • Property svn:eol-style set to native
File size: 21.5 KB
Line 
1/*
2 * Copyright (c) 1982, 1986, 1988, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 *
33 * @(#)ip_icmp.c 8.2 (Berkeley) 1/4/94
34 * ip_icmp.c,v 1.7 1995/05/30 08:09:42 rgrimes Exp
35 */
36
37#include "slirp.h"
38#include "ip_icmp.h"
39#ifdef RT_OS_WINDOWS
40#include <Icmpapi.h>
41#include <Iphlpapi.h>
42#endif
43
44
45/* The message sent when emulating PING */
46/* Be nice and tell them it's just a psuedo-ping packet */
47static const char icmp_ping_msg[] = "This is a psuedo-PING packet used by Slirp to emulate ICMP ECHO-REQUEST packets.\n";
48
49/* list of actions for icmp_error() on RX of an icmp message */
50static const int icmp_flush[19] =
51{
52/* ECHO REPLY (0) */ 0,
53 1,
54 1,
55/* DEST UNREACH (3) */ 1,
56/* SOURCE QUENCH (4)*/ 1,
57/* REDIRECT (5) */ 1,
58 1,
59 1,
60/* ECHO (8) */ 0,
61/* ROUTERADVERT (9) */ 1,
62/* ROUTERSOLICIT (10) */ 1,
63/* TIME EXCEEDED (11) */ 1,
64/* PARAMETER PROBLEM (12) */ 1,
65/* TIMESTAMP (13) */ 0,
66/* TIMESTAMP REPLY (14) */ 0,
67/* INFO (15) */ 0,
68/* INFO REPLY (16) */ 0,
69/* ADDR MASK (17) */ 0,
70/* ADDR MASK REPLY (18) */ 0
71};
72
73#ifdef VBOX_WITH_SLIRP_ICMP
74int
75icmp_init(PNATState pData)
76{
77 pData->icmp_socket.so_type = IPPROTO_ICMP;
78 pData->icmp_socket.so_state = SS_ISFCONNECTED;
79#ifndef RT_OS_WINDOWS
80# ifndef RT_OS_DARWIN
81 pData->icmp_socket.s = socket(PF_INET, SOCK_RAW, IPPROTO_ICMP);
82# else /* !RT_OS_DARWIN */
83 pData->icmp_socket.s = socket(PF_INET, SOCK_DGRAM, IPPROTO_ICMP);
84# endif /* RT_OS_DARWIN */
85 if (pData->icmp_socket.s == -1)
86 {
87 int rc = RTErrConvertFromErrno(errno);
88 LogRel(("NAT: ICMP/ping not available (could open ICMP socket, error %Rrc)\n", rc));
89 return 1;
90 }
91#else /* RT_OS_WINDOWS */
92 pData->hmIcmpLibrary = LoadLibrary("Iphlpapi.dll");
93 if (pData->hmIcmpLibrary != NULL)
94 {
95 pData->pfIcmpParseReplies = (long (WINAPI *)(void *, long))
96 GetProcAddress(pData->hmIcmpLibrary, "IcmpParseReplies");
97 pData->pfIcmpCloseHandle = (BOOL (WINAPI *)(HANDLE))
98 GetProcAddress(pData->hmIcmpLibrary, "IcmpCloseHandle");
99 }
100 if (pData->pfIcmpParseReplies == NULL)
101 {
102 FreeLibrary(pData->hmIcmpLibrary);
103 pData->hmIcmpLibrary = LoadLibrary("Icmp.dll");
104 if (pData->hmIcmpLibrary == NULL)
105 {
106 LogRel(("NAT: Icmp.dll could not be loaded\n"));
107 return 1;
108 }
109 pData->pfIcmpParseReplies = (long (WINAPI *)(void *, long))
110 GetProcAddress(pData->hmIcmpLibrary, "IcmpParseReplies");
111 pData->pfIcmpCloseHandle = (BOOL (WINAPI *)(HANDLE))
112 GetProcAddress(pData->hmIcmpLibrary, "IcmpCloseHandle");
113 }
114 if (pData->pfIcmpParseReplies == NULL)
115 {
116 LogRel(("NAT: Can't find IcmpParseReplies symbol\n"));
117 FreeLibrary(pData->hmIcmpLibrary);
118 return 1;
119 }
120 if (pData->pfIcmpCloseHandle == NULL)
121 {
122 LogRel(("NAT: Can't find IcmpCloseHandle symbol\n"));
123 FreeLibrary(pData->hmIcmpLibrary);
124 return 1;
125 }
126 pData->icmp_socket.sh = IcmpCreateFile();
127 pData->phEvents[VBOX_ICMP_EVENT_INDEX] = CreateEvent(NULL, FALSE, FALSE, NULL);
128 pData->szIcmpBuffer = sizeof(ICMP_ECHO_REPLY) * 10;
129 pData->pvIcmpBuffer = malloc(pData->szIcmpBuffer);
130#endif /* RT_OS_WINDOWS */
131 LIST_INIT(&pData->icmp_msg_head);
132 return 0;
133}
134
135/*
136 * ip here is ip header + 64bytes readed from ICMP packet
137 */
138struct icmp_msg *
139icmp_find_original_mbuf(PNATState pData, struct ip *ip)
140{
141 struct mbuf *m0;
142 struct ip *ip0;
143 struct icmp *icp, *icp0;
144 struct icmp_msg *icm = NULL;
145 int found = 0;
146 struct udphdr *udp;
147 struct tcphdr *tcp;
148 struct socket *head_socket, *so;
149 struct in_addr laddr, faddr;
150 u_int lport, fport;
151
152 laddr.s_addr = ~0;
153 faddr.s_addr = ~0;
154
155 lport = ~0;
156 fport = ~0;
157
158
159 switch (ip->ip_p)
160 {
161 case IPPROTO_ICMP:
162 icp = (struct icmp *)((char *)ip + (ip->ip_hl << 2));
163 LIST_FOREACH(icm, &pData->icmp_msg_head, im_list)
164 {
165 m0 = icm->im_m;
166 ip0 = mtod(m0, struct ip *);
167 AssertRelease(ip0->ip_p == IPPROTO_ICMP);
168 icp0 = (struct icmp *)((char *)ip0 + (ip0->ip_hl << 2));
169 if ( ( (icp->icmp_type != ICMP_ECHO && ip->ip_src.s_addr == ip0->ip_dst.s_addr)
170 || (icp->icmp_type == ICMP_ECHO && ip->ip_dst.s_addr == ip0->ip_dst.s_addr))
171 && icp->icmp_id == icp0->icmp_id
172 && icp->icmp_seq == icp->icmp_seq)
173 {
174 found = 1;
175 break;
176 }
177 }
178 /*
179 * for TCP and UDP logic little bit reverted, we try to find the HOST socket
180 * from which the IP package has been sent.
181 */
182 case IPPROTO_UDP:
183 head_socket = &udb;
184 udp = (struct udphdr *)((char *)ip + (ip->ip_hl >> 2));
185 faddr.s_addr = ip->ip_dst.s_addr;
186 fport = udp->uh_dport;
187 laddr.s_addr = ip->ip_src.s_addr;
188 lport = udp->uh_sport;
189 case IPPROTO_TCP:
190 if (head_socket == NULL)
191 {
192 tcp = (struct tcphdr *)((char *)ip + (ip->ip_hl >> 2));
193 head_socket = &tcb; /* head_socket could be initialized with udb*/
194 faddr.s_addr = ip->ip_dst.s_addr;
195 fport = tcp->th_dport;
196 laddr.s_addr = ip->ip_src.s_addr;
197 lport = tcp->th_sport;
198 }
199 for (so = head_socket; so != head_socket; so = so->so_next)
200 {
201 /* Should be reaplaced by hash here */
202 if (so->so_faddr.s_addr == faddr.s_addr
203 && so->so_fport == fport
204 && so->so_hladdr.s_addr == laddr.s_addr
205 && so->so_hlport == lport) {
206 icm = malloc(sizeof(struct icmp_msg));
207 icm->im_m = so->so_m;
208 found = 1;
209 }
210 }
211 break;
212 default:
213 LogRel(("%s:ICMP: unsupported protocol(%d)\n", __FUNCTION__, ip->ip_p));
214 }
215 if (found == 1)
216 return icm;
217
218 return NULL;
219}
220
221static int
222icmp_attach(PNATState pData, struct mbuf *m)
223{
224 struct icmp_msg *icm;
225 struct ip *ip;
226 ip = mtod(m, struct ip *);
227 Assert(ip->ip_p == IPPROTO_ICMP);
228 icm = malloc(sizeof(struct icmp_msg));
229 icm->im_m = m;
230 LIST_INSERT_HEAD(&pData->icmp_msg_head, icm, im_list);
231 return (0);
232}
233#endif /* VBOX_WITH_SLIRP_ICMP */
234
235/*
236 * Process a received ICMP message.
237 */
238void
239icmp_input(PNATState pData, struct mbuf *m, int hlen)
240{
241 register struct icmp *icp;
242 register struct ip *ip=mtod(m, struct ip *);
243 int icmplen=ip->ip_len;
244 int status;
245 uint32_t dst;
246
247 /* int code; */
248
249 DEBUG_CALL("icmp_input");
250 DEBUG_ARG("m = %lx", (long )m);
251 DEBUG_ARG("m_len = %d", m->m_len);
252
253 icmpstat.icps_received++;
254
255 /*
256 * Locate icmp structure in mbuf, and check
257 * that its not corrupted and of at least minimum length.
258 */
259 if (icmplen < ICMP_MINLEN)
260 {
261 /* min 8 bytes payload */
262 icmpstat.icps_tooshort++;
263freeit:
264 m_freem(pData, m);
265 goto end_error;
266 }
267
268 m->m_len -= hlen;
269 m->m_data += hlen;
270 icp = mtod(m, struct icmp *);
271 if (cksum(m, icmplen))
272 {
273 icmpstat.icps_checksum++;
274 goto freeit;
275 }
276 m->m_len += hlen;
277 m->m_data -= hlen;
278
279 /* icmpstat.icps_inhist[icp->icmp_type]++; */
280 /* code = icp->icmp_code; */
281
282 DEBUG_ARG("icmp_type = %d", icp->icmp_type);
283 switch (icp->icmp_type)
284 {
285 case ICMP_ECHO:
286#ifndef VBOX_WITH_SLIRP_ICMP
287 icp->icmp_type = ICMP_ECHOREPLY;
288#endif /* !VBOX_WITH_SLIRP_ICMP */
289
290 ip->ip_len += hlen; /* since ip_input subtracts this */
291 dst = ip->ip_dst.s_addr;
292 if (dst == alias_addr.s_addr)
293 {
294#ifdef VBOX_WITH_SLIRP_ICMP
295 icp->icmp_type = ICMP_ECHOREPLY;
296 ip->ip_dst.s_addr = ip->ip_src.s_addr;
297 ip->ip_src.s_addr = dst;
298#endif /* VBOX_WITH_SLIRP_ICMP */
299 icmp_reflect(pData, m);
300 }
301 else
302 {
303 struct socket *so;
304 struct sockaddr_in addr;
305#ifndef VBOX_WITH_SLIRP_ICMP
306 if ((so = socreate()) == NULL)
307 goto freeit;
308 if (udp_attach(pData, so) == -1)
309 {
310 DEBUG_MISC((dfd,"icmp_input udp_attach errno = %d-%s\n",
311 errno,strerror(errno)));
312 sofree(pData, so);
313 m_free(pData, m);
314 goto end_error;
315 }
316 so->so_m = m;
317 so->so_faddr = ip->ip_dst;
318 so->so_fport = htons(7);
319 so->so_laddr = ip->ip_src;
320 so->so_lport = htons(9);
321 so->so_iptos = ip->ip_tos;
322 so->so_type = IPPROTO_ICMP;
323 so->so_state = SS_ISFCONNECTED;
324
325 addr.sin_family = AF_INET;
326 if ((so->so_faddr.s_addr & htonl(pData->netmask)) == special_addr.s_addr)
327 {
328 /* It's an alias */
329 switch (ntohl(so->so_faddr.s_addr) & ~pData->netmask)
330 {
331 case CTL_DNS:
332 addr.sin_addr = dns_addr;
333 break;
334 case CTL_ALIAS:
335 default:
336 addr.sin_addr = loopback_addr;
337 break;
338 }
339 }
340 else
341 addr.sin_addr = so->so_faddr;
342 addr.sin_port = so->so_fport;
343 if (sendto(so->s, icmp_ping_msg, strlen(icmp_ping_msg), 0,
344 (struct sockaddr *)&addr, sizeof(addr)) == -1)
345 {
346 DEBUG_MISC((dfd,"icmp_input udp sendto tx errno = %d-%s\n",
347 errno,strerror(errno)));
348 icmp_error(pData, m, ICMP_UNREACH,ICMP_UNREACH_NET, 0,strerror(errno));
349 udp_detach(pData, so);
350 }
351#else /* VBOX_WITH_SLIRP_ICMP */
352# ifdef RT_OS_WINDOWS
353 IP_OPTION_INFORMATION ipopt;
354 int error;
355# endif
356 addr.sin_family = AF_INET;
357 if ((ip->ip_dst.s_addr & htonl(pData->netmask)) == special_addr.s_addr)
358 {
359 /* It's an alias */
360 switch(ntohl(ip->ip_dst.s_addr) & ~pData->netmask)
361 {
362 case CTL_DNS:
363 addr.sin_addr = dns_addr;
364 break;
365 case CTL_ALIAS:
366 default:
367 addr.sin_addr = loopback_addr;
368 break;
369 }
370 }
371 else
372 addr.sin_addr.s_addr = ip->ip_dst.s_addr;
373 icmp_attach(pData, m);
374 /* Send the packet */
375# ifndef RT_OS_WINDOWS
376 status = setsockopt(pData->icmp_socket.s, IPPROTO_IP, IP_TTL, (void *)&ip->ip_ttl, sizeof(ip->ip_ttl));
377 if (status < 0)
378 {
379 LogRel(("NAT: Error (%s) occurred while setting TTL attribute of IP packet\n", strerror(errno)));
380 }
381 if (sendto(pData->icmp_socket.s, icp, icmplen, 0,
382 (struct sockaddr *)&addr, sizeof(addr)) == -1)
383 {
384 DEBUG_MISC((dfd,"icmp_input udp sendto tx errno = %d-%s\n",
385 errno,strerror(errno)));
386 icmp_error(pData, m, ICMP_UNREACH,ICMP_UNREACH_NET, 0,strerror(errno));
387 m_free(pData, m);
388 }
389# else /* RT_OS_WINDOWS */
390 pData->icmp_socket.so_laddr.s_addr = ip->ip_src.s_addr; /* XXX: hack*/
391 pData->icmp_socket.so_icmp_id = icp->icmp_id;
392 pData->icmp_socket.so_icmp_seq = icp->icmp_seq;
393 memset(&ipopt, 0, sizeof(IP_OPTION_INFORMATION));
394 ipopt.Ttl = ip->ip_ttl;
395 status = IcmpSendEcho2(pData->icmp_socket.sh, pData->phEvents[VBOX_ICMP_EVENT_INDEX],
396 NULL, NULL, addr.sin_addr.s_addr, icp->icmp_data,
397 icmplen - offsetof(struct icmp, icmp_data) , &ipopt,
398 pData->pvIcmpBuffer, pData->szIcmpBuffer, 1);
399 if (status == 0 && (error = GetLastError()) != ERROR_IO_PENDING)
400 {
401 error = GetLastError();
402 LogRel(("NAT: Error (%d) occurred while sending ICMP (", error));
403 switch (error)
404 {
405 case ERROR_INVALID_PARAMETER:
406 LogRel(("icmp_socket:%lx is invalid)\n", pData->icmp_socket.s));
407 break;
408 case ERROR_NOT_SUPPORTED:
409 LogRel(("operation is unsupported)\n"));
410 break;
411 case ERROR_NOT_ENOUGH_MEMORY:
412 LogRel(("OOM!!!)\n"));
413 break;
414 case IP_BUF_TOO_SMALL:
415 LogRel(("Buffer too small)\n"));
416 break;
417 default:
418 LogRel(("Other error!!!)\n"));
419 break;
420 }
421 }
422# endif /* RT_OS_WINDOWS */
423#endif /* VBOX_WITH_SLIRP_ICMP */
424 } /* if ip->ip_dst.s_addr == alias_addr.s_addr */
425 break;
426 case ICMP_UNREACH:
427 /* XXX? report error? close socket? */
428 case ICMP_TIMXCEED:
429 case ICMP_PARAMPROB:
430 case ICMP_SOURCEQUENCH:
431 case ICMP_TSTAMP:
432 case ICMP_MASKREQ:
433 case ICMP_REDIRECT:
434 icmpstat.icps_notsupp++;
435 m_freem(pData, m);
436 break;
437
438 default:
439 icmpstat.icps_badtype++;
440 m_freem(pData, m);
441 } /* switch */
442
443end_error:
444 /* m is m_free()'d xor put in a socket xor or given to ip_send */
445 ;
446}
447
448
449/*
450 * Send an ICMP message in response to a situation
451 *
452 * RFC 1122: 3.2.2 MUST send at least the IP header and 8 bytes of header. MAY send more (we do).
453 * MUST NOT change this header information.
454 * MUST NOT reply to a multicast/broadcast IP address.
455 * MUST NOT reply to a multicast/broadcast MAC address.
456 * MUST reply to only the first fragment.
457 */
458/*
459 * Send ICMP_UNREACH back to the source regarding msrc.
460 * mbuf *msrc is used as a template, but is NOT m_free()'d.
461 * It is reported as the bad ip packet. The header should
462 * be fully correct and in host byte order.
463 * ICMP fragmentation is illegal. All machines must accept 576 bytes in one
464 * packet. The maximum payload is 576-20(ip hdr)-8(icmp hdr)=548
465 */
466
467#define ICMP_MAXDATALEN (IP_MSS-28)
468void icmp_error(PNATState pData, struct mbuf *msrc, u_char type, u_char code, int minsize, char *message)
469{
470 unsigned hlen, shlen, s_ip_len;
471 register struct ip *ip;
472 register struct icmp *icp;
473 register struct mbuf *m;
474
475 DEBUG_CALL("icmp_error");
476 DEBUG_ARG("msrc = %lx", (long )msrc);
477 DEBUG_ARG("msrc_len = %d", msrc->m_len);
478
479 if (type!=ICMP_UNREACH && type!=ICMP_TIMXCEED)
480 goto end_error;
481
482 /* check msrc */
483 if (!msrc)
484 goto end_error;
485
486 ip = mtod(msrc, struct ip *);
487#if DEBUG
488 {
489 char bufa[20], bufb[20];
490 strcpy(bufa, inet_ntoa(ip->ip_src));
491 strcpy(bufb, inet_ntoa(ip->ip_dst));
492 DEBUG_MISC((dfd, " %.16s to %.16s\n", bufa, bufb));
493 }
494#endif
495 if (ip->ip_off & IP_OFFMASK)
496 goto end_error; /* Only reply to fragment 0 */
497
498 shlen=ip->ip_hl << 2;
499 s_ip_len=ip->ip_len;
500 if (ip->ip_p == IPPROTO_ICMP)
501 {
502 icp = (struct icmp *)((char *)ip + shlen);
503 /*
504 * Assume any unknown ICMP type is an error. This isn't
505 * specified by the RFC, but think about it..
506 */
507 if (icp->icmp_type>18 || icmp_flush[icp->icmp_type])
508 goto end_error;
509 }
510
511 /* make a copy */
512 if (!(m=m_get(pData)))
513 goto end_error; /* get mbuf */
514 {
515 int new_m_size;
516 new_m_size = sizeof(struct ip) + ICMP_MINLEN + msrc->m_len + ICMP_MAXDATALEN;
517 if (new_m_size>m->m_size)
518 m_inc(m, new_m_size);
519 }
520 memcpy(m->m_data, msrc->m_data, msrc->m_len);
521 m->m_len = msrc->m_len; /* copy msrc to m */
522
523 /* make the header of the reply packet */
524 ip = mtod(m, struct ip *);
525 hlen = sizeof(struct ip ); /* no options in reply */
526
527 /* fill in icmp */
528 m->m_data += hlen;
529 m->m_len -= hlen;
530
531 icp = mtod(m, struct icmp *);
532
533 if (minsize)
534 s_ip_len=shlen+ICMP_MINLEN; /* return header+8b only */
535 else if (s_ip_len>ICMP_MAXDATALEN) /* maximum size */
536 s_ip_len=ICMP_MAXDATALEN;
537
538 m->m_len=ICMP_MINLEN+s_ip_len; /* 8 bytes ICMP header */
539
540 /* min. size = 8+sizeof(struct ip)+8 */
541
542 icp->icmp_type = type;
543 icp->icmp_code = code;
544 icp->icmp_id = 0;
545 icp->icmp_seq = 0;
546
547 memcpy(&icp->icmp_ip, msrc->m_data, s_ip_len); /* report the ip packet */
548 HTONS(icp->icmp_ip.ip_len);
549 HTONS(icp->icmp_ip.ip_id);
550 HTONS(icp->icmp_ip.ip_off);
551
552#if DEBUG
553 if (message)
554 {
555 /* DEBUG : append message to ICMP packet */
556 int message_len;
557 char *cpnt;
558 message_len=strlen(message);
559 if (message_len>ICMP_MAXDATALEN) message_len=ICMP_MAXDATALEN;
560 cpnt=(char *)m->m_data+m->m_len;
561 memcpy(cpnt, message, message_len);
562 m->m_len+=message_len;
563 }
564#endif
565
566 icp->icmp_cksum = 0;
567 icp->icmp_cksum = cksum(m, m->m_len);
568
569 m->m_data -= hlen;
570 m->m_len += hlen;
571
572 /* fill in ip */
573 ip->ip_hl = hlen >> 2;
574 ip->ip_len = m->m_len;
575
576 ip->ip_tos=((ip->ip_tos & 0x1E) | 0xC0); /* high priority for errors */
577
578 ip->ip_ttl = MAXTTL;
579 ip->ip_p = IPPROTO_ICMP;
580 ip->ip_dst = ip->ip_src; /* ip adresses */
581 ip->ip_src = alias_addr;
582
583 (void ) ip_output(pData, (struct socket *)NULL, m);
584
585 icmpstat.icps_reflect++;
586
587end_error:
588 ;
589}
590#undef ICMP_MAXDATALEN
591
592/*
593 * Reflect the ip packet back to the source
594 */
595void
596icmp_reflect(PNATState pData, struct mbuf *m)
597{
598 register struct ip *ip = mtod(m, struct ip *);
599 int hlen = ip->ip_hl << 2;
600 int optlen = hlen - sizeof(struct ip );
601 register struct icmp *icp;
602
603 /*
604 * Send an icmp packet back to the ip level,
605 * after supplying a checksum.
606 */
607 m->m_data += hlen;
608 m->m_len -= hlen;
609 icp = mtod(m, struct icmp *);
610
611 icp->icmp_cksum = 0;
612 icp->icmp_cksum = cksum(m, ip->ip_len - hlen);
613
614 m->m_data -= hlen;
615 m->m_len += hlen;
616
617#ifndef VBOX_WITH_SLIRP_ICMP
618 /* fill in ip */
619 if (optlen > 0)
620 {
621 /*
622 * Strip out original options by copying rest of first
623 * mbuf's data back, and adjust the IP length.
624 */
625 memmove((caddr_t)(ip + 1), (caddr_t)ip + hlen,
626 (unsigned )(m->m_len - hlen));
627 hlen -= optlen;
628 ip->ip_hl = hlen >> 2;
629 ip->ip_len -= optlen;
630 m->m_len -= optlen;
631 }
632 ip->ip_ttl = MAXTTL;
633 {
634 /* swap */
635 struct in_addr icmp_dst;
636 icmp_dst = ip->ip_dst;
637 ip->ip_dst = ip->ip_src;
638 ip->ip_src = icmp_dst;
639 }
640#endif /* !VBOX_WITH_SLIRP_ICMP */
641
642 (void ) ip_output(pData, (struct socket *)NULL, m);
643
644 icmpstat.icps_reflect++;
645}
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette