VirtualBox

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

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

NAT:ICMP socket non-blocking

  • Property svn:eol-style set to native
File size: 21.6 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#ifdef RT_OS_WINDOWS
45# ifdef VBOX_WITH_SIMPLIFIED_SLIRP_SYNC
46# define ICMP_SEND_ECHO(event, routine, addr, data, datasize, ipopt) \
47 IcmpSendEcho2(pData->icmp_socket.sh, (event), NULL, NULL, (addr), (data), (datasize), \
48 (ipopt), pData->pvIcmpBuffer, pData->szIcmpBuffer, 1)
49# else /* VBOX_WITH_SIMPLIFIED_SLIRP_SYNC */
50# define ICMP_SEND_ECHO(event, routine, addr, data, datasize, ipopt) \
51 IcmpSendEcho2(pData->icmp_socket.sh, NULL, (FARPROC)(routine), (void *)pData, (addr), (data), (datasize), \
52 (ipopt), pData->pvIcmpBuffer, pData->szIcmpBuffer, 1)
53static void WINAPI notify_slirp(void *);
54# endif /* !VBOX_WITH_SIMPLIFIED_SLIRP_SYNC */
55#endif /* RT_OS_WINDOWS */
56
57/* The message sent when emulating PING */
58/* Be nice and tell them it's just a psuedo-ping packet */
59static const char icmp_ping_msg[] = "This is a psuedo-PING packet used by Slirp to emulate ICMP ECHO-REQUEST packets.\n";
60
61/* list of actions for icmp_error() on RX of an icmp message */
62static const int icmp_flush[19] =
63{
64/* ECHO REPLY (0) */ 0,
65 1,
66 1,
67/* DEST UNREACH (3) */ 1,
68/* SOURCE QUENCH (4)*/ 1,
69/* REDIRECT (5) */ 1,
70 1,
71 1,
72/* ECHO (8) */ 0,
73/* ROUTERADVERT (9) */ 1,
74/* ROUTERSOLICIT (10) */ 1,
75/* TIME EXCEEDED (11) */ 1,
76/* PARAMETER PROBLEM (12) */ 1,
77/* TIMESTAMP (13) */ 0,
78/* TIMESTAMP REPLY (14) */ 0,
79/* INFO (15) */ 0,
80/* INFO REPLY (16) */ 0,
81/* ADDR MASK (17) */ 0,
82/* ADDR MASK REPLY (18) */ 0
83};
84
85int
86icmp_init(PNATState pData)
87{
88 pData->icmp_socket.so_type = IPPROTO_ICMP;
89 pData->icmp_socket.so_state = SS_ISFCONNECTED;
90#ifndef RT_OS_WINDOWS
91# ifndef RT_OS_DARWIN
92 pData->icmp_socket.s = socket(PF_INET, SOCK_RAW, IPPROTO_ICMP);
93# else /* !RT_OS_DARWIN */
94 pData->icmp_socket.s = socket(AF_INET, SOCK_DGRAM, IPPROTO_ICMP);
95# endif /* RT_OS_DARWIN */
96 if (pData->icmp_socket.s == -1)
97 {
98 int rc = RTErrConvertFromErrno(errno);
99 LogRel(("NAT: ICMP/ping not available (could open ICMP socket, error %Rrc)\n", rc));
100 return 1;
101 }
102 fd_nonblock(pData->icmp_socket.s);
103#else /* RT_OS_WINDOWS */
104 pData->hmIcmpLibrary = LoadLibrary("Iphlpapi.dll");
105 if (pData->hmIcmpLibrary != NULL)
106 {
107 pData->pfIcmpParseReplies = (long (WINAPI *)(void *, long))
108 GetProcAddress(pData->hmIcmpLibrary, "IcmpParseReplies");
109 pData->pfIcmpCloseHandle = (BOOL (WINAPI *)(HANDLE))
110 GetProcAddress(pData->hmIcmpLibrary, "IcmpCloseHandle");
111 }
112 if (pData->pfIcmpParseReplies == NULL)
113 {
114 FreeLibrary(pData->hmIcmpLibrary);
115 pData->hmIcmpLibrary = LoadLibrary("Icmp.dll");
116 if (pData->hmIcmpLibrary == NULL)
117 {
118 LogRel(("NAT: Icmp.dll could not be loaded\n"));
119 return 1;
120 }
121 pData->pfIcmpParseReplies = (long (WINAPI *)(void *, long))
122 GetProcAddress(pData->hmIcmpLibrary, "IcmpParseReplies");
123 pData->pfIcmpCloseHandle = (BOOL (WINAPI *)(HANDLE))
124 GetProcAddress(pData->hmIcmpLibrary, "IcmpCloseHandle");
125 }
126 if (pData->pfIcmpParseReplies == NULL)
127 {
128 LogRel(("NAT: Can't find IcmpParseReplies symbol\n"));
129 FreeLibrary(pData->hmIcmpLibrary);
130 return 1;
131 }
132 if (pData->pfIcmpCloseHandle == NULL)
133 {
134 LogRel(("NAT: Can't find IcmpCloseHandle symbol\n"));
135 FreeLibrary(pData->hmIcmpLibrary);
136 return 1;
137 }
138 pData->icmp_socket.sh = IcmpCreateFile();
139# ifdef VBOX_WITH_SIMPLIFIED_SLIRP_SYNC
140 pData->phEvents[VBOX_ICMP_EVENT_INDEX] = CreateEvent(NULL, FALSE, FALSE, NULL);
141# endif /* VBOX_WITH_SIMPLIFIED_SLIRP_SYNC */
142 pData->szIcmpBuffer = sizeof(ICMP_ECHO_REPLY) * 10;
143 pData->pvIcmpBuffer = RTMemAlloc(pData->szIcmpBuffer);
144#endif /* RT_OS_WINDOWS */
145 LIST_INIT(&pData->icmp_msg_head);
146 return 0;
147}
148
149/*
150 * ip here is ip header + 64bytes readed from ICMP packet
151 */
152struct icmp_msg *
153icmp_find_original_mbuf(PNATState pData, struct ip *ip)
154{
155 struct mbuf *m0;
156 struct ip *ip0;
157 struct icmp *icp, *icp0;
158 struct icmp_msg *icm = NULL;
159 int found = 0;
160 struct udphdr *udp;
161 struct tcphdr *tcp;
162 struct socket *head_socket = NULL;
163 struct socket *last_socket = NULL;
164 struct socket *so = NULL;
165 struct in_addr laddr, faddr;
166 u_short lport, fport;
167
168 laddr.s_addr = ~0;
169 faddr.s_addr = ~0;
170
171 lport = ~0;
172 fport = ~0;
173
174
175 Log(("%s: processing (proto:%d)\n", __FUNCTION__, ip->ip_p));
176 switch (ip->ip_p)
177 {
178 case IPPROTO_ICMP:
179 icp = (struct icmp *)((char *)ip + (ip->ip_hl << 2));
180 LIST_FOREACH(icm, &pData->icmp_msg_head, im_list)
181 {
182 m0 = icm->im_m;
183 ip0 = mtod(m0, struct ip *);
184 AssertRelease(ip0->ip_p == IPPROTO_ICMP);
185 icp0 = (struct icmp *)((char *)ip0 + (ip0->ip_hl << 2));
186 if ( ( (icp->icmp_type != ICMP_ECHO && ip->ip_src.s_addr == ip0->ip_dst.s_addr)
187 || (icp->icmp_type == ICMP_ECHO && ip->ip_dst.s_addr == ip0->ip_dst.s_addr))
188 && icp->icmp_id == icp0->icmp_id
189 && icp->icmp_seq == icp0->icmp_seq)
190 {
191 found = 1;
192 Log(("Have found %R[natsock]\n", icm->im_so));
193 break;
194 }
195 Log(("Have found nothing\n"));
196 }
197 break;
198
199 /*
200 * for TCP and UDP logic little bit reverted, we try to find the HOST socket
201 * from which the IP package has been sent.
202 */
203 case IPPROTO_UDP:
204 head_socket = &udb;
205 udp = (struct udphdr *)((char *)ip + (ip->ip_hl << 2));
206 faddr.s_addr = ip->ip_dst.s_addr;
207 fport = udp->uh_dport;
208 laddr.s_addr = ip->ip_src.s_addr;
209 lport = udp->uh_sport;
210 last_socket = udp_last_so;
211 /* fall through */
212
213 case IPPROTO_TCP:
214 if (head_socket == NULL)
215 {
216 tcp = (struct tcphdr *)((char *)ip + (ip->ip_hl << 2));
217 head_socket = &tcb; /* head_socket could be initialized with udb*/
218 faddr.s_addr = ip->ip_dst.s_addr;
219 fport = tcp->th_dport;
220 laddr.s_addr = ip->ip_src.s_addr;
221 lport = tcp->th_sport;
222 last_socket = tcp_last_so;
223 }
224 /* check last socket first */
225 if ( last_socket->so_faddr.s_addr == faddr.s_addr
226 && last_socket->so_fport == fport
227 && last_socket->so_hlport == lport)
228 {
229 found = 1;
230 so = last_socket;
231 goto sofound;
232 }
233 for (so = head_socket->so_prev; so != head_socket; so = so->so_prev)
234 {
235 /* Should be reaplaced by hash here */
236 Log(("trying:%R[natsock] against %R[IP4]:%d lport=%d hlport=%d\n", so, &faddr, fport, lport, so->so_hlport));
237 if ( so->so_faddr.s_addr == faddr.s_addr
238 && so->so_fport == fport
239 && so->so_hlport == lport)
240 {
241 found = 1;
242 break;
243 }
244 }
245 break;
246
247 default:
248 LogRel(("%s:ICMP: unsupported protocol(%d)\n", __FUNCTION__, ip->ip_p));
249 }
250 sofound:
251 if (found == 1 && icm == NULL)
252 {
253 icm = RTMemAlloc(sizeof(struct icmp_msg));
254 icm->im_m = so->so_m;
255 icm->im_so = so;
256 found = 1;
257 Log(("hit:%R[natsock]\n", so));
258 /*XXX: this storage not very long,
259 * better add flag if it should removed from lis
260 */
261 LIST_INSERT_HEAD(&pData->icmp_msg_head, icm, im_list);
262 return (icm);
263 }
264 if (found == 1)
265 return icm;
266
267 return NULL;
268}
269
270static int
271icmp_attach(PNATState pData, struct mbuf *m)
272{
273 struct icmp_msg *icm;
274 struct ip *ip;
275 ip = mtod(m, struct ip *);
276 Assert(ip->ip_p == IPPROTO_ICMP);
277 icm = RTMemAlloc(sizeof(struct icmp_msg));
278 icm->im_m = m;
279 icm->im_so = m->m_so;
280 LIST_INSERT_HEAD(&pData->icmp_msg_head, icm, im_list);
281 return 0;
282}
283
284/*
285 * Process a received ICMP message.
286 */
287void
288icmp_input(PNATState pData, struct mbuf *m, int hlen)
289{
290 register struct icmp *icp;
291 register struct ip *ip = mtod(m, struct ip *);
292 int icmplen = ip->ip_len;
293 int status;
294 uint32_t dst;
295#if !defined(RT_OS_WINDOWS)
296 int ttl;
297#endif
298
299 /* int code; */
300
301 DEBUG_CALL("icmp_input");
302 DEBUG_ARG("m = %lx", (long )m);
303 DEBUG_ARG("m_len = %d", m->m_len);
304
305 icmpstat.icps_received++;
306
307 /*
308 * Locate icmp structure in mbuf, and check
309 * that its not corrupted and of at least minimum length.
310 */
311 if (icmplen < ICMP_MINLEN)
312 {
313 /* min 8 bytes payload */
314 icmpstat.icps_tooshort++;
315freeit:
316 m_freem(pData, m);
317 goto end_error;
318 }
319
320 m->m_len -= hlen;
321 m->m_data += hlen;
322 icp = mtod(m, struct icmp *);
323 if (cksum(m, icmplen))
324 {
325 icmpstat.icps_checksum++;
326 goto freeit;
327 }
328 m->m_len += hlen;
329 m->m_data -= hlen;
330
331 /* icmpstat.icps_inhist[icp->icmp_type]++; */
332 /* code = icp->icmp_code; */
333
334 DEBUG_ARG("icmp_type = %d", icp->icmp_type);
335 switch (icp->icmp_type)
336 {
337 case ICMP_ECHO:
338 ip->ip_len += hlen; /* since ip_input subtracts this */
339 dst = ip->ip_dst.s_addr;
340 if (dst == alias_addr.s_addr)
341 {
342 icp->icmp_type = ICMP_ECHOREPLY;
343 ip->ip_dst.s_addr = ip->ip_src.s_addr;
344 ip->ip_src.s_addr = dst;
345 icmp_reflect(pData, m);
346 }
347 else
348 {
349 struct sockaddr_in addr;
350#ifdef RT_OS_WINDOWS
351 IP_OPTION_INFORMATION ipopt;
352 int error;
353#endif
354 addr.sin_family = AF_INET;
355 if ((ip->ip_dst.s_addr & htonl(pData->netmask)) == special_addr.s_addr)
356 {
357 /* It's an alias */
358 switch (ntohl(ip->ip_dst.s_addr) & ~pData->netmask)
359 {
360 case CTL_DNS:
361#ifndef VBOX_WITH_MULTI_DNS
362 addr.sin_addr = dns_addr;
363 break;
364#endif
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#ifndef RT_OS_WINDOWS
374 if (pData->icmp_socket.s != -1)
375 {
376 m->m_so = &pData->icmp_socket;
377 icmp_attach(pData, m);
378 ttl = ip->ip_ttl;
379 Log(("NAT/ICMP: try to set TTL(%d)\n", ttl));
380 status = setsockopt(pData->icmp_socket.s, IPPROTO_IP, IP_TTL,
381 (void *)&ttl, sizeof(ttl));
382 if (status < 0)
383 LogRel(("NAT: Error (%s) occurred while setting TTL attribute of IP packet\n",
384 strerror(errno)));
385 if (sendto(pData->icmp_socket.s, icp, icmplen, 0,
386 (struct sockaddr *)&addr, sizeof(addr)) == -1)
387 {
388 Log((dfd,"icmp_input udp sendto tx errno = %d-%s\n",
389 errno, strerror(errno)));
390 icmp_error(pData, m, ICMP_UNREACH,ICMP_UNREACH_NET, 0, strerror(errno));
391 m_free(pData, m);
392 }
393 }
394 else
395 {
396 /*
397 * We're freeing the ICMP message, which unable sent or process.
398 * That behavior described in rfc 793, we shouldn't notify sender about
399 * fail of processing it's ICMP packets
400 */
401 m_free(pData, m);
402 return;
403 }
404#else /* RT_OS_WINDOWS */
405 icmp_attach(pData, m);
406 pData->icmp_socket.so_laddr.s_addr = ip->ip_src.s_addr; /* XXX: hack*/
407 pData->icmp_socket.so_icmp_id = icp->icmp_id;
408 pData->icmp_socket.so_icmp_seq = icp->icmp_seq;
409 m->m_so = &pData->icmp_socket;
410 memset(&ipopt, 0, sizeof(IP_OPTION_INFORMATION));
411 ipopt.Ttl = ip->ip_ttl;
412 status = ICMP_SEND_ECHO(pData->phEvents[VBOX_ICMP_EVENT_INDEX], notify_slirp, addr.sin_addr.s_addr,
413 icp->icmp_data, icmplen - ICMP_MINLEN, &ipopt);
414 if (status == 0 && (error = GetLastError()) != ERROR_IO_PENDING)
415 {
416 error = GetLastError();
417 LogRel(("NAT: Error (%d) occurred while sending ICMP (", error));
418 switch (error)
419 {
420 case ERROR_INVALID_PARAMETER:
421 LogRel(("icmp_socket:%lx is invalid)\n", pData->icmp_socket.s));
422 break;
423 case ERROR_NOT_SUPPORTED:
424 LogRel(("operation is unsupported)\n"));
425 break;
426 case ERROR_NOT_ENOUGH_MEMORY:
427 LogRel(("OOM!!!)\n"));
428 break;
429 case IP_BUF_TOO_SMALL:
430 LogRel(("Buffer too small)\n"));
431 break;
432 default:
433 LogRel(("Other error!!!)\n"));
434 break;
435 }
436 }
437#endif /* RT_OS_WINDOWS */
438 } /* if ip->ip_dst.s_addr == alias_addr.s_addr */
439 break;
440 case ICMP_UNREACH:
441 /* XXX? report error? close socket? */
442 case ICMP_TIMXCEED:
443 case ICMP_PARAMPROB:
444 case ICMP_SOURCEQUENCH:
445 case ICMP_TSTAMP:
446 case ICMP_MASKREQ:
447 case ICMP_REDIRECT:
448 icmpstat.icps_notsupp++;
449 m_freem(pData, m);
450 break;
451
452 default:
453 icmpstat.icps_badtype++;
454 m_freem(pData, m);
455 } /* switch */
456
457end_error:
458 /* m is m_free()'d xor put in a socket xor or given to ip_send */
459 ;
460}
461
462
463/*
464 * Send an ICMP message in response to a situation
465 *
466 * RFC 1122: 3.2.2 MUST send at least the IP header and 8 bytes of header. MAY send more (we do).
467 * MUST NOT change this header information.
468 * MUST NOT reply to a multicast/broadcast IP address.
469 * MUST NOT reply to a multicast/broadcast MAC address.
470 * MUST reply to only the first fragment.
471 */
472/*
473 * Send ICMP_UNREACH back to the source regarding msrc.
474 * mbuf *msrc is used as a template, but is NOT m_free()'d.
475 * It is reported as the bad ip packet. The header should
476 * be fully correct and in host byte order.
477 * ICMP fragmentation is illegal. All machines must accept 576 bytes in one
478 * packet. The maximum payload is 576-20(ip hdr)-8(icmp hdr)=548
479 */
480
481#define ICMP_MAXDATALEN (IP_MSS-28)
482void icmp_error(PNATState pData, struct mbuf *msrc, u_char type, u_char code, int minsize, const char *message)
483{
484 unsigned hlen, shlen, s_ip_len;
485 register struct ip *ip;
486 register struct icmp *icp;
487 register struct mbuf *m;
488
489 DEBUG_CALL("icmp_error");
490 DEBUG_ARG("msrc = %lx", (long )msrc);
491 DEBUG_ARG("msrc_len = %d", msrc->m_len);
492
493 if (type!=ICMP_UNREACH && type!=ICMP_TIMXCEED)
494 goto end_error;
495
496 /* check msrc */
497 if (!msrc)
498 goto end_error;
499
500 ip = mtod(msrc, struct ip *);
501#if DEBUG
502 {
503 char bufa[20], bufb[20];
504 strcpy(bufa, inet_ntoa(ip->ip_src));
505 strcpy(bufb, inet_ntoa(ip->ip_dst));
506 DEBUG_MISC((dfd, " %.16s to %.16s\n", bufa, bufb));
507 }
508#endif
509 if (ip->ip_off & IP_OFFMASK)
510 goto end_error; /* Only reply to fragment 0 */
511
512 shlen = ip->ip_hl << 2;
513 s_ip_len = ip->ip_len;
514 if (ip->ip_p == IPPROTO_ICMP)
515 {
516 icp = (struct icmp *)((char *)ip + shlen);
517 /*
518 * Assume any unknown ICMP type is an error. This isn't
519 * specified by the RFC, but think about it..
520 */
521 if (icp->icmp_type>18 || icmp_flush[icp->icmp_type])
522 goto end_error;
523 }
524
525 /* make a copy */
526 if (!(m = m_get(pData)))
527 goto end_error; /* get mbuf */
528 {
529 int new_m_size;
530 m->m_data += if_maxlinkhdr;
531 new_m_size = sizeof(struct ip) + ICMP_MINLEN + msrc->m_len + ICMP_MAXDATALEN;
532 if (new_m_size>m->m_size)
533 m_inc(m, new_m_size);
534 }
535 memcpy(m->m_data, msrc->m_data, msrc->m_len);
536 m->m_len = msrc->m_len; /* copy msrc to m */
537
538 /* make the header of the reply packet */
539 ip = mtod(m, struct ip *);
540 hlen = sizeof(struct ip ); /* no options in reply */
541
542 /* fill in icmp */
543 m->m_data += hlen;
544 m->m_len -= hlen;
545
546 icp = mtod(m, struct icmp *);
547
548 if (minsize)
549 s_ip_len = shlen+ICMP_MINLEN; /* return header+8b only */
550 else if (s_ip_len > ICMP_MAXDATALEN) /* maximum size */
551 s_ip_len = ICMP_MAXDATALEN;
552
553 m->m_len = ICMP_MINLEN + s_ip_len; /* 8 bytes ICMP header */
554
555 /* min. size = 8+sizeof(struct ip)+8 */
556
557 icp->icmp_type = type;
558 icp->icmp_code = code;
559 icp->icmp_id = 0;
560 icp->icmp_seq = 0;
561
562 memcpy(&icp->icmp_ip, msrc->m_data, s_ip_len); /* report the ip packet */
563 HTONS(icp->icmp_ip.ip_len);
564 HTONS(icp->icmp_ip.ip_id);
565 HTONS(icp->icmp_ip.ip_off);
566
567#if DEBUG
568 if (message)
569 {
570 /* DEBUG : append message to ICMP packet */
571 int message_len;
572 char *cpnt;
573 message_len = strlen(message);
574 if (message_len > ICMP_MAXDATALEN)
575 message_len = ICMP_MAXDATALEN;
576 cpnt = (char *)m->m_data+m->m_len;
577 memcpy(cpnt, message, message_len);
578 m->m_len += message_len;
579 }
580#endif
581
582 icp->icmp_cksum = 0;
583 icp->icmp_cksum = cksum(m, m->m_len);
584
585 m->m_data -= hlen;
586 m->m_len += hlen;
587
588 /* fill in ip */
589 ip->ip_hl = hlen >> 2;
590 ip->ip_len = m->m_len;
591
592 ip->ip_tos = ((ip->ip_tos & 0x1E) | 0xC0); /* high priority for errors */
593
594 ip->ip_ttl = MAXTTL;
595 ip->ip_p = IPPROTO_ICMP;
596 ip->ip_dst = ip->ip_src; /* ip adresses */
597 ip->ip_src = alias_addr;
598
599 (void ) ip_output(pData, (struct socket *)NULL, m);
600
601 icmpstat.icps_reflect++;
602
603end_error:
604 ;
605}
606#undef ICMP_MAXDATALEN
607
608/*
609 * Reflect the ip packet back to the source
610 */
611void
612icmp_reflect(PNATState pData, struct mbuf *m)
613{
614 register struct ip *ip = mtod(m, struct ip *);
615 int hlen = ip->ip_hl << 2;
616 int optlen = hlen - sizeof(struct ip );
617 register struct icmp *icp;
618
619 /*
620 * Send an icmp packet back to the ip level,
621 * after supplying a checksum.
622 */
623 m->m_data += hlen;
624 m->m_len -= hlen;
625 icp = mtod(m, struct icmp *);
626
627 icp->icmp_cksum = 0;
628 icp->icmp_cksum = cksum(m, ip->ip_len - hlen);
629
630 m->m_data -= hlen;
631 m->m_len += hlen;
632
633 (void ) ip_output(pData, (struct socket *)NULL, m);
634
635 icmpstat.icps_reflect++;
636}
637#if defined(RT_OS_WINDOWS) && !defined(VBOX_WITH_SIMPLIFIED_SLIRP_SYNC)
638static void WINAPI
639notify_slirp(void *ctx)
640{
641 /* pData name is important see slirp_state.h */
642 PNATState pData = (PNATState)ctx;
643 fIcmp = 1;
644}
645#endif
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