VirtualBox

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

最後變更 在這個檔案從22664是 22664,由 vboxsync 提交於 16 年 前

NAT: hide away dhcp internals, adds helper lookups functions

  • 屬性 svn:eol-style 設為 native
檔案大小: 60.2 KB
 
1#include "slirp.h"
2#ifdef RT_OS_OS2
3# include <paths.h>
4#endif
5
6#include <VBox/err.h>
7#include <VBox/pdmdrv.h>
8#include <iprt/assert.h>
9#ifndef RT_OS_WINDOWS
10# include <sys/ioctl.h>
11# include <poll.h>
12#else
13# include <Winnls.h>
14# define _WINSOCK2API_
15# include <IPHlpApi.h>
16#endif
17#include <alias.h>
18
19#if !defined(RT_OS_WINDOWS)
20
21# define DO_ENGAGE_EVENT1(so, fdset, label) \
22 do { \
23 if( so->so_poll_index != -1 \
24 && so->s == polls[so->so_poll_index].fd) { \
25 polls[so->so_poll_index].events |= N_(fdset ## _poll); \
26 break; /* out of this loop */ \
27 } \
28 AssertRelease(poll_index < (nfds)); \
29 AssertRelease(poll_index >= 0 && poll_index < (nfds)); \
30 polls[poll_index].fd = (so)->s; \
31 (so)->so_poll_index = poll_index; \
32 polls[poll_index].events = N_(fdset ## _poll); \
33 polls[poll_index].revents = 0; \
34 poll_index++; \
35 } while(0)
36
37
38# define DO_ENGAGE_EVENT2(so, fdset1, fdset2, label) \
39 do { \
40 if( so->so_poll_index != -1 \
41 && so->s == polls[so->so_poll_index].fd) { \
42 polls[so->so_poll_index].events |= \
43 N_(fdset1 ## _poll) | N_(fdset1 ## _poll); \
44 break; /* out of this loop */ \
45 } \
46 AssertRelease(poll_index < (nfds)); \
47 polls[poll_index].fd = (so)->s; \
48 (so)->so_poll_index = poll_index; \
49 polls[poll_index].events = \
50 N_(fdset1 ## _poll) | N_(fdset1 ## _poll); \
51 poll_index++; \
52 } while(0)
53
54# define DO_POLL_EVENTS(rc, error, so, events, label) do {} while (0)
55
56# define DO_CHECK_FD_SET(so, events, fdset) ( ((so)->so_poll_index != -1) \
57 && ((so)->so_poll_index <= ndfs) \
58 && ((so)->s == polls[so->so_poll_index].fd) \
59 && (polls[(so)->so_poll_index].revents & N_(fdset ## _poll)))
60# define DO_UNIX_CHECK_FD_SET(so, events, fdset ) DO_CHECK_FD_SET((so), (events), fdset) /*specific for Unix API */
61# define DO_WIN_CHECK_FD_SET(so, events, fdset ) 0 /* specific for Windows Winsock API */
62
63# ifndef RT_OS_WINDOWS
64
65# ifndef RT_OS_LINUX
66# define readfds_poll (POLLRDNORM)
67# define writefds_poll (POLLWRNORM)
68# define xfds_poll (POLLRDBAND|POLLWRBAND|POLLPRI)
69# else
70# define readfds_poll (POLLIN)
71# define writefds_poll (POLLOUT)
72# define xfds_poll (POLLPRI)
73# endif
74# define rderr_poll (POLLERR)
75# define rdhup_poll (POLLHUP)
76# define nval_poll (POLLNVAL)
77
78# define ICMP_ENGAGE_EVENT(so, fdset) \
79 do { \
80 if (pData->icmp_socket.s != -1) \
81 DO_ENGAGE_EVENT1((so), fdset, ICMP); \
82 } while (0)
83# else /* !RT_OS_WINDOWS */
84# define DO_WIN_CHECK_FD_SET(so, events, fdset ) DO_CHECK_FD_SET((so), (events), fdset)
85# define ICMP_ENGAGE_EVENT(so, fdset) do {} while(0)
86#endif /* RT_OS_WINDOWS */
87
88#else /* defined(RT_OS_WINDOWS) */
89
90/*
91 * On Windows, we will be notified by IcmpSendEcho2() when the response arrives.
92 * So no call to WSAEventSelect necessary.
93 */
94# define ICMP_ENGAGE_EVENT(so, fdset) do {} while(0)
95
96# define DO_ENGAGE_EVENT1(so, fdset1, label) \
97 do { \
98 rc = WSAEventSelect((so)->s, VBOX_SOCKET_EVENT, FD_ALL_EVENTS); \
99 if (rc == SOCKET_ERROR) \
100 { \
101 /* This should not happen */ \
102 error = WSAGetLastError(); \
103 LogRel(("WSAEventSelect (" #label ") error %d (so=%x, socket=%s, event=%x)\n", \
104 error, (so), (so)->s, VBOX_SOCKET_EVENT)); \
105 } \
106 } while(0); \
107 CONTINUE(label)
108
109# define DO_ENGAGE_EVENT2(so, fdset1, fdset2, label) \
110 DO_ENGAGE_EVENT1((so), (fdset1), label)
111
112# define DO_POLL_EVENTS(rc, error, so, events, label) \
113 (rc) = WSAEnumNetworkEvents((so)->s, VBOX_SOCKET_EVENT, (events)); \
114 if ((rc) == SOCKET_ERROR) \
115 { \
116 (error) = WSAGetLastError(); \
117 LogRel(("WSAEnumNetworkEvents " #label " error %d\n", (error))); \
118 CONTINUE(label); \
119 }
120
121# define acceptds_win FD_ACCEPT
122# define acceptds_win_bit FD_ACCEPT_BIT
123
124# define readfds_win FD_READ
125# define readfds_win_bit FD_READ_BIT
126
127# define writefds_win FD_WRITE
128# define writefds_win_bit FD_WRITE_BIT
129
130# define xfds_win FD_OOB
131# define xfds_win_bit FD_OOB_BIT
132
133# define DO_CHECK_FD_SET(so, events, fdset) \
134 (((events).lNetworkEvents & fdset ## _win) && ((events).iErrorCode[fdset ## _win_bit] == 0))
135
136# define DO_WIN_CHECK_FD_SET(so, events, fdset ) DO_CHECK_FD_SET((so), (events), fdset)
137# define DO_UNIX_CHECK_FD_SET(so, events, fdset ) 1 /*specific for Unix API */
138
139#endif /* defined(RT_OS_WINDOWS) */
140
141#define TCP_ENGAGE_EVENT1(so, fdset) \
142 DO_ENGAGE_EVENT1((so), fdset, tcp)
143
144#define TCP_ENGAGE_EVENT2(so, fdset1, fdset2) \
145 DO_ENGAGE_EVENT2((so), fdset1, fdset2, tcp)
146
147#define UDP_ENGAGE_EVENT(so, fdset) \
148 DO_ENGAGE_EVENT1((so), fdset, udp)
149
150#define POLL_TCP_EVENTS(rc, error, so, events) \
151 DO_POLL_EVENTS((rc), (error), (so), (events), tcp)
152
153#define POLL_UDP_EVENTS(rc, error, so, events) \
154 DO_POLL_EVENTS((rc), (error), (so), (events), udp)
155
156#define CHECK_FD_SET(so, events, set) \
157 (DO_CHECK_FD_SET((so), (events), set))
158
159#define WIN_CHECK_FD_SET(so, events, set) \
160 (DO_WIN_CHECK_FD_SET((so), (events), set))
161#define UNIX_CHECK_FD_SET(so, events, set) \
162 (DO_UNIX_CHECK_FD_SET(so, events, set))
163
164/*
165 * Loging macros
166 */
167#if VBOX_WITH_DEBUG_NAT_SOCKETS
168# if defined(RT_OS_WINDOWS)
169# define DO_LOG_NAT_SOCK(so, proto, winevent, r_fdset, w_fdset, x_fdset) \
170 do { \
171 LogRel((" " #proto " %R[natsock] %R[natwinnetevents]\n", (so), (winevent))); \
172 } while (0)
173# else /* RT_OS_WINDOWS */
174# define DO_LOG_NAT_SOCK(so, proto, winevent, r_fdset, w_fdset, x_fdset) \
175 do { \
176 LogRel((" " #proto " %R[natsock] %s %s %s er: %s, %s, %s\n", (so), \
177 CHECK_FD_SET(so, ign ,r_fdset) ? "READ":"", \
178 CHECK_FD_SET(so, ign, w_fdset) ? "WRITE":"", \
179 CHECK_FD_SET(so, ign, x_fdset) ? "OOB":"", \
180 CHECK_FD_SET(so, ign, rderr) ? "RDERR":"", \
181 CHECK_FD_SET(so, ign, rdhup) ? "RDHUP":"", \
182 CHECK_FD_SET(so, ign, nval) ? "RDNVAL":"")); \
183 } while (0)
184# endif /* !RT_OS_WINDOWS */
185#else /* VBOX_WITH_DEBUG_NAT_SOCKETS */
186# define DO_LOG_NAT_SOCK(so, proto, winevent, r_fdset, w_fdset, x_fdset) do {} while (0)
187#endif /* !VBOX_WITH_DEBUG_NAT_SOCKETS */
188
189#define LOG_NAT_SOCK(so, proto, winevent, r_fdset, w_fdset, x_fdset) DO_LOG_NAT_SOCK((so), proto, (winevent), r_fdset, w_fdset, x_fdset)
190
191static void activate_port_forwarding(PNATState, struct ethhdr *);
192static uint32_t find_guest_ip(PNATState, const uint8_t *);
193
194static const uint8_t special_ethaddr[6] =
195{
196 0x52, 0x54, 0x00, 0x12, 0x35, 0x00
197};
198
199static const uint8_t broadcast_ethaddr[6] =
200{
201 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
202};
203
204const uint8_t zerro_ethaddr[6] =
205{
206 0x0, 0x0, 0x0, 0x0, 0x0, 0x0
207};
208
209#ifdef RT_OS_WINDOWS
210static int get_dns_addr_domain(PNATState pData, bool fVerbose,
211 struct in_addr *pdns_addr,
212 const char **ppszDomain)
213{
214 /* Get amount of memory required for operation */
215 ULONG flags = GAA_FLAG_INCLUDE_PREFIX; /*GAA_FLAG_INCLUDE_ALL_INTERFACES;*/ /* all interfaces registered in NDIS */
216 PIP_ADAPTER_ADDRESSES addresses = NULL;
217 PIP_ADAPTER_ADDRESSES addr = NULL;
218 PIP_ADAPTER_DNS_SERVER_ADDRESS dns = NULL;
219 ULONG size = 0;
220 int wlen = 0;
221 char *suffix;
222 struct dns_entry *da = NULL;
223 struct dns_domain_entry *dd = NULL;
224 ULONG ret = ERROR_SUCCESS;
225
226 /* @todo add SKIPing flags to get only required information */
227
228 ret = pData->pfGetAdaptersAddresses(AF_INET, 0, NULL /* reserved */, addresses, &size);
229 if (ret != ERROR_BUFFER_OVERFLOW)
230 {
231 LogRel(("NAT: error %lu occurred on capacity detection operation\n", ret));
232 return -1;
233 }
234
235 if (size == 0)
236 {
237 LogRel(("NAT: Win socket API returns non capacity\n"));
238 return -1;
239 }
240
241 addresses = RTMemAllocZ(size);
242 if (addresses == NULL)
243 {
244 LogRel(("NAT: No memory available \n"));
245 return -1;
246 }
247
248 ret = pData->pfGetAdaptersAddresses(AF_INET, 0, NULL /* reserved */, addresses, &size);
249 if (ret != ERROR_SUCCESS)
250 {
251 LogRel(("NAT: error %lu occurred on fetching adapters info\n", ret));
252 RTMemFree(addresses);
253 return -1;
254 }
255 addr = addresses;
256 while(addr != NULL)
257 {
258 int found;
259 if (addr->OperStatus != IfOperStatusUp)
260 goto next;
261 dns = addr->FirstDnsServerAddress;
262 while (dns != NULL)
263 {
264 struct sockaddr *saddr = dns->Address.lpSockaddr;
265 if (saddr->sa_family != AF_INET)
266 goto next_dns;
267 /* add dns server to list */
268 da = RTMemAllocZ(sizeof(struct dns_entry));
269 if (da == NULL)
270 {
271 LogRel(("NAT: Can't allocate buffer for DNS entry\n"));
272 RTMemFree(addresses);
273 return VERR_NO_MEMORY;
274 }
275 LogRel(("NAT: adding %R[IP4] to DNS server list\n", &((struct sockaddr_in *)saddr)->sin_addr));
276 if ((((struct sockaddr_in *)saddr)->sin_addr.s_addr & htonl(IN_CLASSA_NET)) == ntohl(INADDR_LOOPBACK & IN_CLASSA_NET)) {
277 da->de_addr.s_addr = htonl(ntohl(special_addr.s_addr) | CTL_ALIAS);
278 }
279 else
280 {
281 da->de_addr.s_addr = ((struct sockaddr_in *)saddr)->sin_addr.s_addr;
282 }
283 TAILQ_INSERT_HEAD(&pData->dns_list_head, da, de_list);
284
285 if (addr->DnsSuffix == NULL)
286 goto next_dns;
287
288 /*uniq*/
289 RTUtf16ToUtf8(addr->DnsSuffix, &suffix);
290
291 if (!suffix || strlen(suffix) == 0) {
292 RTStrFree(suffix);
293 goto next_dns;
294 }
295
296 found = 0;
297 LIST_FOREACH(dd, &pData->dns_domain_list_head, dd_list)
298 {
299 if ( dd->dd_pszDomain != NULL
300 && strcmp(dd->dd_pszDomain, suffix) == 0)
301 {
302 found = 1;
303 RTStrFree(suffix);
304 break;
305 }
306 }
307 if (found == 0)
308 {
309 dd = RTMemAllocZ(sizeof(struct dns_domain_entry));
310 if (dd == NULL)
311 {
312 LogRel(("NAT: not enough memory\n"));
313 RTStrFree(suffix);
314 RTMemFree(addresses);
315 return VERR_NO_MEMORY;
316 }
317 dd->dd_pszDomain = suffix;
318 LogRel(("NAT: adding domain name %s to search list\n", dd->dd_pszDomain));
319 LIST_INSERT_HEAD(&pData->dns_domain_list_head, dd, dd_list);
320 }
321 next_dns:
322 dns = dns->Next;
323 }
324 next:
325 addr = addr->Next;
326 }
327 RTMemFree(addresses);
328 return 0;
329}
330
331#else /* !RT_OS_WINDOWS */
332
333static int get_dns_addr_domain(PNATState pData, bool fVerbose,
334 struct in_addr *pdns_addr,
335 const char **ppszDomain)
336{
337 char buff[512];
338 char buff2[256];
339 FILE *f = NULL;
340 int found = 0;
341 struct in_addr tmp_addr;
342
343#ifdef RT_OS_OS2
344 /* Try various locations. */
345 char *etc = getenv("ETC");
346 if (etc)
347 {
348 snprintf(buff, sizeof(buff), "%s/RESOLV2", etc);
349 f = fopen(buff, "rt");
350 }
351 if (!f)
352 {
353 snprintf(buff, sizeof(buff), "%s/RESOLV2", _PATH_ETC);
354 f = fopen(buff, "rt");
355 }
356 if (!f)
357 {
358 snprintf(buff, sizeof(buff), "%s/resolv.conf", _PATH_ETC);
359 f = fopen(buff, "rt");
360 }
361#else
362#ifndef DEBUG_vvl
363 f = fopen("/etc/resolv.conf", "r");
364#else
365 char *home = getenv("HOME");
366 snprintf(buff, sizeof(buff), "%s/resolv.conf", home);
367 f = fopen(buff, "r");
368 if (f != NULL)
369 {
370 Log(("NAT: DNS we're using %s\n", buff));
371 }
372 else
373 {
374 f = fopen("/etc/resolv.conf", "r");
375 Log(("NAT: DNS we're using %s\n", buff));
376 }
377#endif
378#endif
379 if (!f)
380 return -1;
381
382 if (ppszDomain)
383 *ppszDomain = NULL;
384 Log(("nat: DNS Servers:\n"));
385 while (fgets(buff, 512, f) != NULL)
386 {
387 struct dns_entry *da = NULL;
388 if (sscanf(buff, "nameserver%*[ \t]%256s", buff2) == 1)
389 {
390 if (!inet_aton(buff2, &tmp_addr))
391 continue;
392 /*localhost mask */
393 da = RTMemAllocZ(sizeof (struct dns_entry));
394 if (da == NULL)
395 {
396 LogRel(("can't alloc memory for DNS entry\n"));
397 return -1;
398 }
399 /*check */
400 da->de_addr.s_addr = tmp_addr.s_addr;
401 if ((da->de_addr.s_addr & htonl(IN_CLASSA_NET)) == ntohl(INADDR_LOOPBACK & IN_CLASSA_NET)) {
402 da->de_addr.s_addr = htonl(ntohl(special_addr.s_addr) | CTL_ALIAS);
403 }
404 TAILQ_INSERT_HEAD(&pData->dns_list_head, da, de_list);
405 found++;
406 }
407 if ((!strncmp(buff, "domain", 6) || !strncmp(buff, "search", 6)))
408 {
409 char *tok;
410 char *saveptr;
411 struct dns_domain_entry *dd = NULL;
412 int found = 0;
413 tok = strtok_r(&buff[6], " \t\n", &saveptr);
414 LIST_FOREACH(dd, &pData->dns_domain_list_head, dd_list)
415 {
416 if( tok != NULL
417 && strcmp(tok, dd->dd_pszDomain) == 0)
418 {
419 found = 1;
420 break;
421 }
422 }
423 if (tok != NULL && found == 0) {
424 dd = RTMemAllocZ(sizeof(struct dns_domain_entry));
425 if (dd == NULL)
426 {
427 LogRel(("NAT: not enought memory to add domain list\n"));
428 return VERR_NO_MEMORY;
429 }
430 dd->dd_pszDomain = RTStrDup(tok);
431 LogRel(("NAT: adding domain name %s to search list\n", dd->dd_pszDomain));
432 LIST_INSERT_HEAD(&pData->dns_domain_list_head, dd, dd_list);
433 }
434 }
435 }
436 fclose(f);
437 if (!found)
438 return -1;
439 return 0;
440}
441
442#endif
443
444static int slirp_init_dns_list(PNATState pData)
445{
446 TAILQ_INIT(&pData->dns_list_head);
447 LIST_INIT(&pData->dns_domain_list_head);
448 return get_dns_addr_domain(pData, true, NULL, NULL);
449}
450
451static void slirp_release_dns_list(PNATState pData)
452{
453 struct dns_entry *de = NULL;
454 struct dns_domain_entry *dd = NULL;
455 while(!TAILQ_EMPTY(&pData->dns_list_head)) {
456 de = TAILQ_FIRST(&pData->dns_list_head);
457 TAILQ_REMOVE(&pData->dns_list_head, de, de_list);
458 RTMemFree(de);
459 }
460 while(!LIST_EMPTY(&pData->dns_domain_list_head)) {
461 dd = LIST_FIRST(&pData->dns_domain_list_head);
462 LIST_REMOVE(dd, dd_list);
463 if (dd->dd_pszDomain != NULL)
464 RTStrFree(dd->dd_pszDomain);
465 RTMemFree(dd);
466 }
467}
468
469int get_dns_addr(PNATState pData, struct in_addr *pdns_addr)
470{
471 return get_dns_addr_domain(pData, false, pdns_addr, NULL);
472}
473
474#ifndef VBOX_WITH_NAT_SERVICE
475int slirp_init(PNATState *ppData, const char *pszNetAddr, uint32_t u32Netmask,
476 bool fPassDomain, void *pvUser)
477#else
478int slirp_init(PNATState *ppData, uint32_t u32NetAddr, uint32_t u32Netmask,
479 bool fPassDomain, void *pvUser)
480#endif
481{
482 int fNATfailed = 0;
483 int rc;
484 PNATState pData = RTMemAllocZ(sizeof(NATState));
485 *ppData = pData;
486 if (!pData)
487 return VERR_NO_MEMORY;
488 if (u32Netmask & 0x1f)
489 /* CTL is x.x.x.15, bootp passes up to 16 IPs (15..31) */
490 return VERR_INVALID_PARAMETER;
491 pData->fPassDomain = fPassDomain;
492 pData->pvUser = pvUser;
493 pData->netmask = u32Netmask;
494
495 /* sockets & TCP defaults */
496 pData->socket_rcv = 64 * _1K;
497 pData->socket_snd = 64 * _1K;
498 tcp_sndspace = 64 * _1K;
499 tcp_rcvspace = 64 * _1K;
500
501#ifdef RT_OS_WINDOWS
502 {
503 WSADATA Data;
504 WSAStartup(MAKEWORD(2, 0), &Data);
505 }
506 pData->phEvents[VBOX_SOCKET_EVENT_INDEX] = CreateEvent(NULL, FALSE, FALSE, NULL);
507#endif
508#ifdef VBOX_WITH_SLIRP_MT
509 QSOCKET_LOCK_CREATE(tcb);
510 QSOCKET_LOCK_CREATE(udb);
511 rc = RTReqCreateQueue(&pData->pReqQueue);
512 AssertReleaseRC(rc);
513#endif
514
515 link_up = 1;
516
517 bootp_dhcp_init(pData);
518 debug_init();
519 if_init(pData);
520 ip_init(pData);
521 icmp_init(pData);
522
523 /* Initialise mbufs *after* setting the MTU */
524 m_init(pData);
525
526#ifndef VBOX_WITH_NAT_SERVICE
527 inet_aton(pszNetAddr, &special_addr);
528#else
529 special_addr.s_addr = u32NetAddr;
530#endif
531 pData->slirp_ethaddr = &special_ethaddr[0];
532 alias_addr.s_addr = special_addr.s_addr | htonl(CTL_ALIAS);
533 /* @todo: add ability to configure this staff */
534
535 /* set default addresses */
536 inet_aton("127.0.0.1", &loopback_addr);
537 if (slirp_init_dns_list(pData) < 0)
538 fNATfailed = 1;
539
540 dnsproxy_init(pData);
541
542 getouraddr(pData);
543 {
544 int flags = 0;
545 struct in_addr proxy_addr;
546 pData->proxy_alias = LibAliasInit(pData, NULL);
547 if (pData->proxy_alias == NULL)
548 {
549 LogRel(("NAT: LibAlias default rule wasn't initialized\n"));
550 AssertMsgFailed(("NAT: LibAlias default rule wasn't initialized\n"));
551 }
552 flags = LibAliasSetMode(pData->proxy_alias, 0, 0);
553#ifndef NO_FW_PUNCH
554 flags |= PKT_ALIAS_PUNCH_FW;
555#endif
556 flags |= PKT_ALIAS_LOG; /* set logging */
557 flags = LibAliasSetMode(pData->proxy_alias, flags, ~0);
558 proxy_addr.s_addr = htonl(ntohl(special_addr.s_addr) | CTL_ALIAS);
559 LibAliasSetAddress(pData->proxy_alias, proxy_addr);
560 ftp_alias_load(pData);
561 nbt_alias_load(pData);
562 }
563 return fNATfailed ? VINF_NAT_DNS : VINF_SUCCESS;
564}
565
566/**
567 * Register statistics.
568 */
569void slirp_register_statistics(PNATState pData, PPDMDRVINS pDrvIns)
570{
571#ifdef VBOX_WITH_STATISTICS
572# define PROFILE_COUNTER(name, dsc) REGISTER_COUNTER(name, pData, STAMTYPE_PROFILE, STAMUNIT_TICKS_PER_CALL, dsc)
573# define COUNTING_COUNTER(name, dsc) REGISTER_COUNTER(name, pData, STAMTYPE_COUNTER, STAMUNIT_COUNT, dsc)
574# include "counters.h"
575# undef COUNTER
576/** @todo register statistics for the variables dumped by:
577 * ipstats(pData); tcpstats(pData); udpstats(pData); icmpstats(pData);
578 * mbufstats(pData); sockstats(pData); */
579#endif /* VBOX_WITH_STATISTICS */
580}
581
582/**
583 * Deregister statistics.
584 */
585void slirp_deregister_statistics(PNATState pData, PPDMDRVINS pDrvIns)
586{
587#ifdef VBOX_WITH_STATISTICS
588# define PROFILE_COUNTER(name, dsc) DEREGISTER_COUNTER(name, pData)
589# define COUNTING_COUNTER(name, dsc) DEREGISTER_COUNTER(name, pData)
590# include "counters.h"
591#endif /* VBOX_WITH_STATISTICS */
592}
593
594/**
595 * Marks the link as up, making it possible to establish new connections.
596 */
597void slirp_link_up(PNATState pData)
598{
599 link_up = 1;
600}
601
602/**
603 * Marks the link as down and cleans up the current connections.
604 */
605void slirp_link_down(PNATState pData)
606{
607 struct socket *so;
608
609 while ((so = tcb.so_next) != &tcb)
610 {
611 if (so->so_state & SS_NOFDREF || so->s == -1)
612 sofree(pData, so);
613 else
614 tcp_drop(pData, sototcpcb(so), 0);
615 }
616
617 while ((so = udb.so_next) != &udb)
618 udp_detach(pData, so);
619
620 link_up = 0;
621}
622
623/**
624 * Terminates the slirp component.
625 */
626void slirp_term(PNATState pData)
627{
628#ifdef RT_OS_WINDOWS
629 pData->pfIcmpCloseHandle(pData->icmp_socket.sh);
630 FreeLibrary(pData->hmIcmpLibrary);
631 RTMemFree(pData->pvIcmpBuffer);
632#else
633 closesocket(pData->icmp_socket.s);
634#endif
635
636 slirp_link_down(pData);
637 slirp_release_dns_list(pData);
638 ftp_alias_unload(pData);
639 nbt_alias_unload(pData);
640 while(!LIST_EMPTY(&instancehead))
641 {
642 struct libalias *la = LIST_FIRST(&instancehead);
643 /* libalias do all clean up */
644 LibAliasUninit(la);
645 }
646 while(!LIST_EMPTY(&pData->arp_cache))
647 {
648 struct arp_cache_entry *ac = LIST_FIRST(&pData->arp_cache);
649 LIST_REMOVE(ac, list);
650 RTMemFree(ac);
651 }
652 bootp_dhcp_fini(pData);
653#ifdef RT_OS_WINDOWS
654 WSACleanup();
655#endif
656#ifdef LOG_ENABLED
657 Log(("\n"
658 "NAT statistics\n"
659 "--------------\n"
660 "\n"));
661 ipstats(pData);
662 tcpstats(pData);
663 udpstats(pData);
664 icmpstats(pData);
665 mbufstats(pData);
666 sockstats(pData);
667 Log(("\n"
668 "\n"
669 "\n"));
670#endif
671 RTMemFree(pData);
672}
673
674
675#define CONN_CANFSEND(so) (((so)->so_state & (SS_FCANTSENDMORE|SS_ISFCONNECTED)) == SS_ISFCONNECTED)
676#define CONN_CANFRCV(so) (((so)->so_state & (SS_FCANTRCVMORE|SS_ISFCONNECTED)) == SS_ISFCONNECTED)
677
678/*
679 * curtime kept to an accuracy of 1ms
680 */
681static void updtime(PNATState pData)
682{
683#ifdef RT_OS_WINDOWS
684 struct _timeb tb;
685
686 _ftime(&tb);
687 curtime = (u_int)tb.time * (u_int)1000;
688 curtime += (u_int)tb.millitm;
689#else
690 gettimeofday(&tt, 0);
691
692 curtime = (u_int)tt.tv_sec * (u_int)1000;
693 curtime += (u_int)tt.tv_usec / (u_int)1000;
694
695 if ((tt.tv_usec % 1000) >= 500)
696 curtime++;
697#endif
698}
699
700#ifdef RT_OS_WINDOWS
701void slirp_select_fill(PNATState pData, int *pnfds)
702#else /* RT_OS_WINDOWS */
703void slirp_select_fill(PNATState pData, int *pnfds, struct pollfd *polls)
704#endif /* !RT_OS_WINDOWS */
705{
706 struct socket *so, *so_next;
707 int nfds;
708#if defined(RT_OS_WINDOWS)
709 int rc;
710 int error;
711#else
712 int poll_index = 0;
713#endif
714 int i;
715
716 STAM_PROFILE_START(&pData->StatFill, a);
717
718 nfds = *pnfds;
719
720 /*
721 * First, TCP sockets
722 */
723 do_slowtimo = 0;
724 if (!link_up)
725 goto done;
726 /*
727 * *_slowtimo needs calling if there are IP fragments
728 * in the fragment queue, or there are TCP connections active
729 */
730 /* XXX:
731 * triggering of fragment expiration should be the same but use new macroses
732 */
733 do_slowtimo = (tcb.so_next != &tcb);
734 if (!do_slowtimo)
735 {
736 for (i = 0; i < IPREASS_NHASH; i++)
737 {
738 if (!TAILQ_EMPTY(&ipq[i]))
739 {
740 do_slowtimo = 1;
741 break;
742 }
743 }
744 }
745 ICMP_ENGAGE_EVENT(&pData->icmp_socket, readfds);
746
747 STAM_COUNTER_RESET(&pData->StatTCP);
748 STAM_COUNTER_RESET(&pData->StatTCPHot);
749
750 QSOCKET_FOREACH(so, so_next, tcp)
751 /* { */
752#if !defined(RT_OS_WINDOWS)
753 so->so_poll_index = -1;
754#endif
755 STAM_COUNTER_INC(&pData->StatTCP);
756
757 /*
758 * See if we need a tcp_fasttimo
759 */
760 if ( time_fasttimo == 0
761 && so->so_tcpcb != NULL
762 && so->so_tcpcb->t_flags & TF_DELACK)
763 time_fasttimo = curtime; /* Flag when we want a fasttimo */
764
765 /*
766 * NOFDREF can include still connecting to local-host,
767 * newly socreated() sockets etc. Don't want to select these.
768 */
769 if (so->so_state & SS_NOFDREF || so->s == -1)
770 CONTINUE(tcp);
771
772 /*
773 * Set for reading sockets which are accepting
774 */
775 if (so->so_state & SS_FACCEPTCONN)
776 {
777 STAM_COUNTER_INC(&pData->StatTCPHot);
778 TCP_ENGAGE_EVENT1(so, readfds);
779 CONTINUE(tcp);
780 }
781
782 /*
783 * Set for writing sockets which are connecting
784 */
785 if (so->so_state & SS_ISFCONNECTING)
786 {
787 Log2(("connecting %R[natsock] engaged\n",so));
788 STAM_COUNTER_INC(&pData->StatTCPHot);
789 TCP_ENGAGE_EVENT1(so, writefds);
790 }
791
792 /*
793 * Set for writing if we are connected, can send more, and
794 * we have something to send
795 */
796 if (CONN_CANFSEND(so) && so->so_rcv.sb_cc)
797 {
798 STAM_COUNTER_INC(&pData->StatTCPHot);
799 TCP_ENGAGE_EVENT1(so, writefds);
800 }
801
802 /*
803 * Set for reading (and urgent data) if we are connected, can
804 * receive more, and we have room for it XXX /2 ?
805 */
806 if (CONN_CANFRCV(so) && (so->so_snd.sb_cc < (so->so_snd.sb_datalen/2)))
807 {
808 STAM_COUNTER_INC(&pData->StatTCPHot);
809 TCP_ENGAGE_EVENT2(so, readfds, xfds);
810 }
811 LOOP_LABEL(tcp, so, so_next);
812 }
813
814 /*
815 * UDP sockets
816 */
817 STAM_COUNTER_RESET(&pData->StatUDP);
818 STAM_COUNTER_RESET(&pData->StatUDPHot);
819
820 QSOCKET_FOREACH(so, so_next, udp)
821 /* { */
822
823 STAM_COUNTER_INC(&pData->StatUDP);
824#if !defined(RT_OS_WINDOWS)
825 so->so_poll_index = -1;
826#endif
827
828 /*
829 * See if it's timed out
830 */
831 if (so->so_expire)
832 {
833 if (so->so_expire <= curtime)
834 {
835 Log2(("NAT: %R[natsock] expired\n", so));
836 if (so->so_timeout != NULL)
837 {
838 so->so_timeout(pData, so, so->so_timeout_arg);
839 }
840#ifdef VBOX_WITH_SLIRP_MT
841 /* we need so_next for continue our cycle*/
842 so_next = so->so_next;
843#endif
844 UDP_DETACH(pData, so, so_next);
845 CONTINUE_NO_UNLOCK(udp);
846 }
847 else
848 do_slowtimo = 1; /* Let socket expire */
849 }
850
851 /*
852 * When UDP packets are received from over the link, they're
853 * sendto()'d straight away, so no need for setting for writing
854 * Limit the number of packets queued by this session to 4.
855 * Note that even though we try and limit this to 4 packets,
856 * the session could have more queued if the packets needed
857 * to be fragmented.
858 *
859 * (XXX <= 4 ?)
860 */
861 if ((so->so_state & SS_ISFCONNECTED) && so->so_queued <= 4)
862 {
863 STAM_COUNTER_INC(&pData->StatUDPHot);
864 UDP_ENGAGE_EVENT(so, readfds);
865 }
866 LOOP_LABEL(udp, so, so_next);
867 }
868done:
869
870#if defined(RT_OS_WINDOWS)
871 *pnfds = VBOX_EVENT_COUNT;
872#else /* RT_OS_WINDOWS */
873 AssertRelease(poll_index <= *pnfds);
874 *pnfds = poll_index;
875#endif /* !RT_OS_WINDOWS */
876
877 STAM_PROFILE_STOP(&pData->StatFill, a);
878}
879
880#if defined(RT_OS_WINDOWS)
881void slirp_select_poll(PNATState pData, int fTimeout, int fIcmp)
882#else /* RT_OS_WINDOWS */
883void slirp_select_poll(PNATState pData, struct pollfd *polls, int ndfs)
884#endif /* !RT_OS_WINDOWS */
885{
886 struct socket *so, *so_next;
887 int ret;
888#if defined(RT_OS_WINDOWS)
889 WSANETWORKEVENTS NetworkEvents;
890 int rc;
891 int error;
892#else
893 int poll_index = 0;
894#endif
895
896 STAM_PROFILE_START(&pData->StatPoll, a);
897
898 /* Update time */
899 updtime(pData);
900
901 /*
902 * See if anything has timed out
903 */
904 if (link_up)
905 {
906 if (time_fasttimo && ((curtime - time_fasttimo) >= 2))
907 {
908 STAM_PROFILE_START(&pData->StatFastTimer, a);
909 tcp_fasttimo(pData);
910 time_fasttimo = 0;
911 STAM_PROFILE_STOP(&pData->StatFastTimer, a);
912 }
913 if (do_slowtimo && ((curtime - last_slowtimo) >= 499))
914 {
915 STAM_PROFILE_START(&pData->StatSlowTimer, a);
916 ip_slowtimo(pData);
917 tcp_slowtimo(pData);
918 last_slowtimo = curtime;
919 STAM_PROFILE_STOP(&pData->StatSlowTimer, a);
920 }
921 }
922#if defined(RT_OS_WINDOWS)
923 if (fTimeout)
924 return; /* only timer update */
925#endif
926
927 /*
928 * Check sockets
929 */
930 if (!link_up)
931 goto done;
932#if defined(RT_OS_WINDOWS)
933 /*XXX: before renaming please make see define
934 * fIcmp in slirp_state.h
935 */
936 if (fIcmp)
937 sorecvfrom(pData, &pData->icmp_socket);
938#else
939 if ( (pData->icmp_socket.s != -1)
940 && CHECK_FD_SET(&pData->icmp_socket, ignored, readfds))
941 sorecvfrom(pData, &pData->icmp_socket);
942#endif
943 /*
944 * Check TCP sockets
945 */
946 QSOCKET_FOREACH(so, so_next, tcp)
947 /* { */
948
949#ifdef VBOX_WITH_SLIRP_MT
950 if ( so->so_state & SS_NOFDREF
951 && so->so_deleted == 1)
952 {
953 struct socket *son, *sop = NULL;
954 QSOCKET_LOCK(tcb);
955 if (so->so_next != NULL)
956 {
957 if (so->so_next != &tcb)
958 SOCKET_LOCK(so->so_next);
959 son = so->so_next;
960 }
961 if ( so->so_prev != &tcb
962 && so->so_prev != NULL)
963 {
964 SOCKET_LOCK(so->so_prev);
965 sop = so->so_prev;
966 }
967 QSOCKET_UNLOCK(tcb);
968 remque(pData, so);
969 NSOCK_DEC();
970 SOCKET_UNLOCK(so);
971 SOCKET_LOCK_DESTROY(so);
972 RTMemFree(so);
973 so_next = son;
974 if (sop != NULL)
975 SOCKET_UNLOCK(sop);
976 CONTINUE_NO_UNLOCK(tcp);
977 }
978#endif
979 /*
980 * FD_ISSET is meaningless on these sockets
981 * (and they can crash the program)
982 */
983 if (so->so_state & SS_NOFDREF || so->s == -1)
984 CONTINUE(tcp);
985
986 POLL_TCP_EVENTS(rc, error, so, &NetworkEvents);
987
988 LOG_NAT_SOCK(so, TCP, &NetworkEvents, readfds, writefds, xfds);
989
990
991 /*
992 * Check for URG data
993 * This will soread as well, so no need to
994 * test for readfds below if this succeeds
995 */
996
997 /* out-of-band data */
998 if (CHECK_FD_SET(so, NetworkEvents, xfds))
999 {
1000 sorecvoob(pData, so);
1001 }
1002
1003 /*
1004 * Check sockets for reading
1005 */
1006 else if ( CHECK_FD_SET(so, NetworkEvents, readfds)
1007 || WIN_CHECK_FD_SET(so, NetworkEvents, acceptds))
1008 {
1009 /*
1010 * Check for incoming connections
1011 */
1012 if (so->so_state & SS_FACCEPTCONN)
1013 {
1014 TCP_CONNECT(pData, so);
1015#if defined(RT_OS_WINDOWS)
1016 if (!(NetworkEvents.lNetworkEvents & FD_CLOSE))
1017#endif
1018 CONTINUE(tcp);
1019 }
1020
1021 ret = soread(pData, so);
1022 /* Output it if we read something */
1023 if (RT_LIKELY(ret > 0))
1024 TCP_OUTPUT(pData, sototcpcb(so));
1025 }
1026
1027#if defined(RT_OS_WINDOWS)
1028 /*
1029 * Check for FD_CLOSE events.
1030 * in some cases once FD_CLOSE engaged on socket it could be flashed latter (for some reasons)
1031 */
1032 if ( (NetworkEvents.lNetworkEvents & FD_CLOSE)
1033 || (so->so_close == 1))
1034 {
1035 so->so_close = 1; /* mark it */
1036 /*
1037 * drain the socket
1038 */
1039 for (;;)
1040 {
1041 ret = soread(pData, so);
1042 if (ret > 0)
1043 TCP_OUTPUT(pData, sototcpcb(so));
1044 else
1045 break;
1046 }
1047 CONTINUE(tcp);
1048 }
1049#endif
1050
1051 /*
1052 * Check sockets for writing
1053 */
1054 if (CHECK_FD_SET(so, NetworkEvents, writefds))
1055 {
1056 /*
1057 * Check for non-blocking, still-connecting sockets
1058 */
1059 if (so->so_state & SS_ISFCONNECTING)
1060 {
1061 Log2(("connecting %R[natsock] catched\n", so));
1062 /* Connected */
1063 so->so_state &= ~SS_ISFCONNECTING;
1064
1065 /*
1066 * This should be probably guarded by PROBE_CONN too. Anyway,
1067 * we disable it on OS/2 because the below send call returns
1068 * EFAULT which causes the opened TCP socket to close right
1069 * after it has been opened and connected.
1070 */
1071#ifndef RT_OS_OS2
1072 ret = send(so->s, (const char *)&ret, 0, 0);
1073 if (ret < 0)
1074 {
1075 /* XXXXX Must fix, zero bytes is a NOP */
1076 if ( errno == EAGAIN
1077 || errno == EWOULDBLOCK
1078 || errno == EINPROGRESS
1079 || errno == ENOTCONN)
1080 CONTINUE(tcp);
1081
1082 /* else failed */
1083 so->so_state = SS_NOFDREF;
1084 }
1085 /* else so->so_state &= ~SS_ISFCONNECTING; */
1086#endif
1087
1088 /*
1089 * Continue tcp_input
1090 */
1091 TCP_INPUT(pData, (struct mbuf *)NULL, sizeof(struct ip), so);
1092 /* continue; */
1093 }
1094 else
1095 SOWRITE(ret, pData, so);
1096 /*
1097 * XXX If we wrote something (a lot), there could be the need
1098 * for a window update. In the worst case, the remote will send
1099 * a window probe to get things going again.
1100 */
1101 }
1102
1103 /*
1104 * Probe a still-connecting, non-blocking socket
1105 * to check if it's still alive
1106 */
1107#ifdef PROBE_CONN
1108 if (so->so_state & SS_ISFCONNECTING)
1109 {
1110 ret = recv(so->s, (char *)&ret, 0, 0);
1111
1112 if (ret < 0)
1113 {
1114 /* XXX */
1115 if ( errno == EAGAIN
1116 || errno == EWOULDBLOCK
1117 || errno == EINPROGRESS
1118 || errno == ENOTCONN)
1119 {
1120 CONTINUE(tcp); /* Still connecting, continue */
1121 }
1122
1123 /* else failed */
1124 so->so_state = SS_NOFDREF;
1125
1126 /* tcp_input will take care of it */
1127 }
1128 else
1129 {
1130 ret = send(so->s, &ret, 0, 0);
1131 if (ret < 0)
1132 {
1133 /* XXX */
1134 if ( errno == EAGAIN
1135 || errno == EWOULDBLOCK
1136 || errno == EINPROGRESS
1137 || errno == ENOTCONN)
1138 {
1139 CONTINUE(tcp);
1140 }
1141 /* else failed */
1142 so->so_state = SS_NOFDREF;
1143 }
1144 else
1145 so->so_state &= ~SS_ISFCONNECTING;
1146
1147 }
1148 TCP_INPUT((struct mbuf *)NULL, sizeof(struct ip),so);
1149 } /* SS_ISFCONNECTING */
1150#endif
1151#ifndef RT_OS_WINDOWS
1152 if ( UNIX_CHECK_FD_SET(so, NetworkEvents, rdhup)
1153 || UNIX_CHECK_FD_SET(so, NetworkEvents, rderr))
1154 {
1155 int err;
1156 int inq, outq;
1157 int status;
1158 socklen_t optlen = sizeof(int);
1159 inq = outq = 0;
1160 status = getsockopt(so->s, SOL_SOCKET, SO_ERROR, &err, &optlen);
1161 if (status != 0)
1162 Log(("NAT: can't get error status from %R[natsock]\n", so));
1163#ifndef RT_OS_SOLARIS
1164 status = ioctl(so->s, FIONREAD, &inq); /* tcp(7) recommends SIOCINQ which is Linux specific */
1165 if (status != 0 || status != EINVAL)
1166 {
1167 /* EINVAL returned if socket in listen state tcp(7)*/
1168 Log(("NAT: can't get depth of IN queue status from %R[natsock]\n", so));
1169 }
1170 status = ioctl(so->s, TIOCOUTQ, &outq); /* SIOCOUTQ see previous comment */
1171 if (status != 0)
1172 Log(("NAT: can't get depth of OUT queue from %R[natsock]\n", so));
1173#else
1174 /*
1175 * Solaris has bit different ioctl commands and its handlings
1176 * hint: streamio(7) I_NREAD
1177 */
1178#endif
1179 if ( so->so_state & SS_ISFCONNECTING
1180 || UNIX_CHECK_FD_SET(so, NetworkEvents, readfds))
1181 {
1182 /**
1183 * Check if we need here take care about gracefull connection
1184 * @todo try with proxy server
1185 */
1186 if (UNIX_CHECK_FD_SET(so, NetworkEvents, readfds))
1187 {
1188 /*
1189 * Never meet inq != 0 or outq != 0, anyway let it stay for a while
1190 * in case it happens we'll able to detect it.
1191 * Give TCP/IP stack wait or expire the socket.
1192 */
1193 Log(("NAT: %R[natsock] err(%d:%s) s(in:%d,out:%d)happens on read I/O, "
1194 "other side close connection \n", so, err, strerror(err), inq, outq));
1195 CONTINUE(tcp);
1196 }
1197 goto tcp_input_close;
1198 }
1199 if ( !UNIX_CHECK_FD_SET(so, NetworkEvents, readfds)
1200 && !UNIX_CHECK_FD_SET(so, NetworkEvents, writefds)
1201 && !UNIX_CHECK_FD_SET(so, NetworkEvents, xfds))
1202 {
1203 Log(("NAT: system expires the socket %R[natsock] err(%d:%s) s(in:%d,out:%d) happens on non-I/O. ",
1204 so, err, strerror(err), inq, outq));
1205 goto tcp_input_close;
1206 }
1207 Log(("NAT: %R[natsock] we've met(%d:%s) s(in:%d, out:%d) unhandled combination hup (%d) "
1208 "rederr(%d) on (r:%d, w:%d, x:%d)\n",
1209 so, err, strerror(err),
1210 inq, outq,
1211 UNIX_CHECK_FD_SET(so, ign, rdhup),
1212 UNIX_CHECK_FD_SET(so, ign, rderr),
1213 UNIX_CHECK_FD_SET(so, ign, readfds),
1214 UNIX_CHECK_FD_SET(so, ign, writefds),
1215 UNIX_CHECK_FD_SET(so, ign, xfds)));
1216 /*
1217 * Give OS's TCP/IP stack a chance to resolve an issue or expire the socket.
1218 */
1219 CONTINUE(tcp);
1220tcp_input_close:
1221 so->so_state = SS_NOFDREF; /*cause connection valid tcp connection termination and socket closing */
1222 TCP_INPUT(pData, (struct mbuf *)NULL, sizeof(struct ip), so);
1223 CONTINUE(tcp);
1224 }
1225#endif
1226 LOOP_LABEL(tcp, so, so_next);
1227 }
1228
1229 /*
1230 * Now UDP sockets.
1231 * Incoming packets are sent straight away, they're not buffered.
1232 * Incoming UDP data isn't buffered either.
1233 */
1234 QSOCKET_FOREACH(so, so_next, udp)
1235 /* { */
1236#ifdef VBOX_WITH_SLIRP_MT
1237 if ( so->so_state & SS_NOFDREF
1238 && so->so_deleted == 1)
1239 {
1240 struct socket *son, *sop = NULL;
1241 QSOCKET_LOCK(udb);
1242 if (so->so_next != NULL)
1243 {
1244 if (so->so_next != &udb)
1245 SOCKET_LOCK(so->so_next);
1246 son = so->so_next;
1247 }
1248 if ( so->so_prev != &udb
1249 && so->so_prev != NULL)
1250 {
1251 SOCKET_LOCK(so->so_prev);
1252 sop = so->so_prev;
1253 }
1254 QSOCKET_UNLOCK(udb);
1255 remque(pData, so);
1256 NSOCK_DEC();
1257 SOCKET_UNLOCK(so);
1258 SOCKET_LOCK_DESTROY(so);
1259 RTMemFree(so);
1260 so_next = son;
1261 if (sop != NULL)
1262 SOCKET_UNLOCK(sop);
1263 CONTINUE_NO_UNLOCK(udp);
1264 }
1265#endif
1266 POLL_UDP_EVENTS(rc, error, so, &NetworkEvents);
1267
1268 LOG_NAT_SOCK(so, UDP, &NetworkEvents, readfds, writefds, xfds);
1269
1270 if (so->s != -1 && CHECK_FD_SET(so, NetworkEvents, readfds))
1271 {
1272 SORECVFROM(pData, so);
1273 }
1274 LOOP_LABEL(udp, so, so_next);
1275 }
1276
1277done:
1278#ifndef VBOX_WITH_SLIRP_MT
1279 /*
1280 * See if we can start outputting
1281 */
1282 if (if_queued && link_up)
1283 if_start(pData);
1284#endif
1285
1286 STAM_PROFILE_STOP(&pData->StatPoll, a);
1287}
1288
1289
1290struct arphdr
1291{
1292 unsigned short ar_hrd; /* format of hardware address */
1293 unsigned short ar_pro; /* format of protocol address */
1294 unsigned char ar_hln; /* length of hardware address */
1295 unsigned char ar_pln; /* length of protocol address */
1296 unsigned short ar_op; /* ARP opcode (command) */
1297
1298 /*
1299 * Ethernet looks like this : This bit is variable sized however...
1300 */
1301 unsigned char ar_sha[ETH_ALEN]; /* sender hardware address */
1302 unsigned char ar_sip[4]; /* sender IP address */
1303 unsigned char ar_tha[ETH_ALEN]; /* target hardware address */
1304 unsigned char ar_tip[4]; /* target IP address */
1305};
1306AssertCompileSize(struct arphdr, 28);
1307
1308static void arp_input(PNATState pData, struct mbuf *m)
1309{
1310 struct ethhdr *eh;
1311 struct ethhdr *reh;
1312 struct arphdr *ah;
1313 struct arphdr *rah;
1314 int ar_op;
1315 struct ex_list *ex_ptr;
1316 uint32_t htip;
1317 uint32_t tip;
1318 struct mbuf *mr;
1319 eh = mtod(m, struct ethhdr *);
1320 ah = (struct arphdr *)&eh[1];
1321 htip = ntohl(*(uint32_t*)ah->ar_tip);
1322 tip = *(uint32_t*)ah->ar_tip;
1323
1324
1325 ar_op = ntohs(ah->ar_op);
1326 switch(ar_op)
1327 {
1328 case ARPOP_REQUEST:
1329 mr = m_get(pData);
1330
1331 reh = mtod(mr, struct ethhdr *);
1332 memcpy(reh->h_source, eh->h_source, ETH_ALEN); /* XXX: if_encap will swap src and dst*/
1333 Log4(("NAT: arp:%R[ether]->%R[ether]\n",
1334 reh->h_source, reh->h_dest));
1335 Log4(("NAT: arp: %R[IP4]\n", &tip));
1336
1337 mr->m_data += if_maxlinkhdr;
1338 mr->m_len = sizeof(struct arphdr);
1339 rah = mtod(mr, struct arphdr *);
1340#ifdef VBOX_WITH_NAT_SERVICE
1341 if (tip == special_addr.s_addr) goto arp_ok;
1342#endif
1343 if ((htip & pData->netmask) == ntohl(special_addr.s_addr))
1344 {
1345 if ( CTL_CHECK(htip, CTL_DNS)
1346 || CTL_CHECK(htip, CTL_ALIAS)
1347 || CTL_CHECK(htip, CTL_TFTP))
1348 goto arp_ok;
1349 for (ex_ptr = exec_list; ex_ptr; ex_ptr = ex_ptr->ex_next)
1350 {
1351 if ((htip & ~pData->netmask) == ex_ptr->ex_addr)
1352 {
1353 goto arp_ok;
1354 }
1355 }
1356 return;
1357 arp_ok:
1358 rah->ar_hrd = htons(1);
1359 rah->ar_pro = htons(ETH_P_IP);
1360 rah->ar_hln = ETH_ALEN;
1361 rah->ar_pln = 4;
1362 rah->ar_op = htons(ARPOP_REPLY);
1363 memcpy(rah->ar_sha, special_ethaddr, ETH_ALEN);
1364
1365 switch (htip & ~pData->netmask)
1366 {
1367 case CTL_DNS:
1368 case CTL_ALIAS:
1369 rah->ar_sha[5] = (uint8_t)(htip & ~pData->netmask);
1370 break;
1371 default:;
1372 }
1373
1374 memcpy(rah->ar_sip, ah->ar_tip, 4);
1375 memcpy(rah->ar_tha, ah->ar_sha, ETH_ALEN);
1376 memcpy(rah->ar_tip, ah->ar_sip, 4);
1377 if_encap(pData, ETH_P_ARP, mr);
1378 m_free(pData, m);
1379 }
1380 /*Gratuitous ARP*/
1381 if ( *(uint32_t *)ah->ar_sip == *(uint32_t *)ah->ar_tip
1382 && memcmp(ah->ar_tha, broadcast_ethaddr, ETH_ALEN) == 0
1383 && memcmp(eh->h_dest, broadcast_ethaddr, ETH_ALEN) == 0)
1384 {
1385 /* we've received anounce about address asignment
1386 * Let's do ARP cache update
1387 */
1388 if (slirp_arp_cache_update(pData, *(uint32_t *)ah->ar_tip, &eh->h_dest[0]) == 0)
1389 {
1390 m_free(pData, mr);
1391 m_free(pData, m);
1392 break;
1393 }
1394 slirp_arp_cache_add(pData, *(uint32_t *)ah->ar_tip, &eh->h_dest[0]);
1395 /* good opportunity to activate port-forwarding on address (self)asignment*/
1396 activate_port_forwarding(pData, eh);
1397 }
1398 break;
1399 case ARPOP_REPLY:
1400 {
1401 if (slirp_arp_cache_update(pData, *(uint32_t *)ah->ar_sip, &ah->ar_sha[0]) == 0)
1402 {
1403 m_free(pData, m);
1404 break;
1405 }
1406 slirp_arp_cache_add(pData, *(uint32_t *)ah->ar_sip, ah->ar_sha);
1407 /*after/save restore we need up port forwarding again*/
1408 if (pData->port_forwarding_activated == 0)
1409 activate_port_forwarding(pData, eh);
1410 m_free(pData, m);
1411 }
1412 break;
1413 default:
1414 break;
1415 }
1416}
1417
1418void slirp_input(PNATState pData, const uint8_t *pkt, int pkt_len)
1419{
1420 struct mbuf *m;
1421 int proto;
1422 static bool fWarnedIpv6;
1423 struct ethhdr *eh = (struct ethhdr*)pkt;
1424
1425 Log2(("NAT: slirp_input %d\n", pkt_len));
1426 if (pkt_len < ETH_HLEN)
1427 {
1428 LogRel(("NAT: packet having size %d has been ingnored\n", pkt_len));
1429 return;
1430 }
1431 Log4(("NAT: in:%R[ether]->%R[ether]\n", &eh->h_source, &eh->h_dest));
1432
1433 if (memcmp(eh->h_source, special_ethaddr, ETH_ALEN) == 0)
1434 {
1435 /* @todo vasily: add ether logging routine in debug.c */
1436 Log(("NAT: packet was addressed to other MAC\n"));
1437 RTMemFree((void *)pkt);
1438 return;
1439 }
1440
1441 m = m_get(pData);
1442 if (!m)
1443 {
1444 LogRel(("NAT: can't allocate new mbuf\n"));
1445 return;
1446 }
1447
1448 /* Note: we add to align the IP header */
1449
1450 if (M_FREEROOM(m) < pkt_len)
1451 m_inc(m, pkt_len);
1452
1453 m->m_len = pkt_len ;
1454 memcpy(m->m_data, pkt, pkt_len);
1455
1456#if 1
1457 if (pData->port_forwarding_activated == 0)
1458 activate_port_forwarding(pData, mtod(m, struct ethhdr *));
1459#endif
1460
1461 proto = ntohs(*(uint16_t *)(pkt + 12));
1462 switch(proto)
1463 {
1464 case ETH_P_ARP:
1465 arp_input(pData, m);
1466 break;
1467 case ETH_P_IP:
1468 /* Update time. Important if the network is very quiet, as otherwise
1469 * the first outgoing connection gets an incorrect timestamp. */
1470 updtime(pData);
1471 m_adj(m, ETH_HLEN);
1472 ip_input(pData, m);
1473 break;
1474 case ETH_P_IPV6:
1475 m_free(pData, m);
1476 if (!fWarnedIpv6)
1477 {
1478 LogRel(("NAT: IPv6 not supported\n"));
1479 fWarnedIpv6 = true;
1480 }
1481 break;
1482 default:
1483 Log(("NAT: Unsupported protocol %x\n", proto));
1484 m_free(pData, m);
1485 break;
1486 }
1487 RTMemFree((void *)pkt);
1488}
1489
1490/* output the IP packet to the ethernet device */
1491void if_encap(PNATState pData, uint16_t eth_proto, struct mbuf *m)
1492{
1493 struct ethhdr *eh;
1494 uint8_t *buf = NULL;
1495 STAM_PROFILE_START(&pData->StatIF_encap, a);
1496
1497 m->m_data -= if_maxlinkhdr;
1498 m->m_len += ETH_HLEN;
1499 eh = mtod(m, struct ethhdr *);
1500
1501 if(MBUF_HEAD(m) != m->m_data)
1502 {
1503 LogRel(("NAT: ethernet detects corruption of the packet"));
1504 AssertMsgFailed(("!!Ethernet frame corrupted!!"));
1505 }
1506
1507 if (memcmp(eh->h_source, special_ethaddr, ETH_ALEN) != 0)
1508 {
1509 memcpy(eh->h_dest, eh->h_source, ETH_ALEN);
1510 memcpy(eh->h_source, special_ethaddr, ETH_ALEN);
1511 Assert(memcmp(eh->h_dest, special_ethaddr, ETH_ALEN) != 0);
1512 if (memcmp(eh->h_dest, zerro_ethaddr, ETH_ALEN) == 0)
1513 {
1514 /* don't do anything */
1515 goto done;
1516 }
1517 }
1518 buf = RTMemAlloc(1600);
1519 if (buf == NULL)
1520 {
1521 LogRel(("NAT: Can't alloc memory for outgoing buffer\n"));
1522 goto done;
1523 }
1524 eh->h_proto = htons(eth_proto);
1525 memcpy(buf, mtod(m, uint8_t *), m->m_len);
1526 slirp_output(pData->pvUser, NULL, buf, m->m_len);
1527done:
1528 STAM_PROFILE_STOP(&pData->StatIF_encap, a);
1529 m_free(pData, m);
1530}
1531
1532/**
1533 * Still we're using dhcp server leasing to map ether to IP
1534 * @todo see rt_lookup_in_cache
1535 */
1536static uint32_t find_guest_ip(PNATState pData, const uint8_t *eth_addr)
1537{
1538 int i;
1539 uint32_t ip = INADDR_ANY;
1540 if (eth_addr == NULL)
1541 goto done;
1542 if (memcmp(eth_addr, zerro_ethaddr, ETH_ALEN) == 0
1543 || memcmp(eth_addr, broadcast_ethaddr, ETH_ALEN) == 0)
1544 goto done;
1545 if(slirp_arp_lookup_ip_by_ether(pData, eth_addr, &ip) == 0)
1546 goto done;
1547 bootp_cache_lookup_ip_by_ether(pData, eth_addr, &ip);
1548done:
1549 return ip;
1550}
1551
1552/**
1553 * We need check if we've activated port forwarding
1554 * for specific machine ... that of course relates to
1555 * service mode
1556 * @todo finish this for service case
1557 */
1558static void activate_port_forwarding(PNATState pData, struct ethhdr *ethdr)
1559{
1560 struct port_forward_rule *rule = NULL;
1561
1562 pData->port_forwarding_activated = 1;
1563 /* check mac here */
1564 LIST_FOREACH(rule, &pData->port_forward_rule_head, list)
1565 {
1566 struct socket *so;
1567 struct alias_link *link;
1568 struct libalias *lib;
1569 int flags;
1570 struct sockaddr sa;
1571 struct sockaddr_in *psin;
1572 socklen_t socketlen;
1573 struct in_addr alias;
1574 int rc;
1575 uint32_t guest_addr; /* need to understand if we already give address to guest */
1576
1577 if (rule->activated)
1578 continue; /*already activated */
1579#ifdef VBOX_WITH_NAT_SERVICE
1580 if (memcmp(rule->mac_address, ethdr->h_source, ETH_ALEN) != 0)
1581 continue; /*not right mac, @todo: it'd be better do the list port forwarding per mac */
1582 guest_addr = find_guest_ip(pData, ethdr->h_source);
1583#else
1584#if 0
1585 if (memcmp(client_ethaddr, ethdr->h_source, ETH_ALEN) != 0)
1586 continue;
1587#endif
1588 guest_addr = find_guest_ip(pData, ethdr->h_source);
1589#endif
1590 if (guest_addr == INADDR_ANY)
1591 {
1592 /* the address wasn't granted */
1593 pData->port_forwarding_activated = 0;
1594 return;
1595 }
1596#if defined(DEBUG_vvl) && !defined(VBOX_WITH_NAT_SERVICE)
1597 Assert(rule->guest_addr.s_addr == guest_addr);
1598#endif
1599
1600 LogRel(("NAT: set redirect %s hp:%d gp:%d\n", (rule->proto == IPPROTO_UDP?"UDP":"TCP"),
1601 rule->host_port, rule->guest_port));
1602 if (rule->proto == IPPROTO_UDP)
1603 {
1604 so = udp_listen(pData, rule->bind_ip.s_addr, htons(rule->host_port), guest_addr,
1605 htons(rule->guest_port), 0);
1606 }
1607 else
1608 {
1609 so = solisten(pData, rule->bind_ip.s_addr, htons(rule->host_port), guest_addr,
1610 htons(rule->guest_port), 0);
1611 }
1612 if (so == NULL)
1613 {
1614 LogRel(("NAT: failed redirect %s hp:%d gp:%d\n", (rule->proto == IPPROTO_UDP?"UDP":"TCP"),
1615 rule->host_port, rule->guest_port));
1616 goto remove_port_forwarding;
1617 }
1618
1619 psin = (struct sockaddr_in *)&sa;
1620 psin->sin_family = AF_INET;
1621 psin->sin_port = 0;
1622 psin->sin_addr.s_addr = INADDR_ANY;
1623 socketlen = sizeof(struct sockaddr);
1624
1625 rc = getsockname(so->s, &sa, &socketlen);
1626 if (rc < 0 || sa.sa_family != AF_INET)
1627 {
1628 LogRel(("NAT: failed redirect %s hp:%d gp:%d\n", (rule->proto == IPPROTO_UDP?"UDP":"TCP"),
1629 rule->host_port, rule->guest_port));
1630 goto remove_port_forwarding;
1631 }
1632
1633 psin = (struct sockaddr_in *)&sa;
1634
1635 lib = LibAliasInit(pData, NULL);
1636 flags = LibAliasSetMode(lib, 0, 0);
1637 flags |= PKT_ALIAS_LOG; /* set logging */
1638 flags |= PKT_ALIAS_REVERSE; /* set logging */
1639 flags = LibAliasSetMode(lib, flags, ~0);
1640
1641 alias.s_addr = htonl(ntohl(guest_addr) | CTL_ALIAS);
1642 link = LibAliasRedirectPort(lib, psin->sin_addr, htons(rule->host_port),
1643 alias, htons(rule->guest_port),
1644 special_addr, -1, /* not very clear for now*/
1645 rule->proto);
1646 if (link == NULL)
1647 {
1648 LogRel(("NAT: failed redirect %s hp:%d gp:%d\n", (rule->proto == IPPROTO_UDP?"UDP":"TCP"),
1649 rule->host_port, rule->guest_port));
1650 goto remove_port_forwarding;
1651 }
1652 so->so_la = lib;
1653 rule->activated = 1;
1654 continue;
1655 remove_port_forwarding:
1656 LIST_REMOVE(rule, list);
1657 RTMemFree(rule);
1658 }
1659}
1660
1661/**
1662 * Changes in 3.1 instead of opening new socket do the following:
1663 * gain more information:
1664 * 1. bind IP
1665 * 2. host port
1666 * 3. guest port
1667 * 4. proto
1668 * 5. guest MAC address
1669 * the guest's MAC address is rather important for service, but we easily
1670 * could get it from VM configuration in DrvNAT or Service, the idea is activating
1671 * corresponding port-forwarding
1672 */
1673int slirp_redir(PNATState pData, int is_udp, struct in_addr host_addr, int host_port,
1674 struct in_addr guest_addr, int guest_port, const uint8_t *ethaddr)
1675{
1676 struct port_forward_rule *rule = NULL;
1677 Assert(memcmp(ethaddr, zerro_ethaddr, ETH_ALEN) == 0);
1678 rule = RTMemAllocZ(sizeof(struct port_forward_rule));
1679 if (rule == NULL)
1680 return 1;
1681 rule->proto = (is_udp ? IPPROTO_UDP : IPPROTO_TCP);
1682 rule->host_port = host_port;
1683 rule->guest_port = guest_port;
1684#ifndef VBOX_WITH_NAT_SERVICE
1685 rule->guest_addr.s_addr = guest_addr.s_addr;
1686#endif
1687 rule->bind_ip.s_addr = host_addr.s_addr;
1688 memcpy(rule->mac_address, ethaddr, ETH_ALEN);
1689 /* @todo add mac address */
1690 LIST_INSERT_HEAD(&pData->port_forward_rule_head, rule, list);
1691 return 0;
1692}
1693
1694int slirp_add_exec(PNATState pData, int do_pty, const char *args, int addr_low_byte,
1695 int guest_port)
1696{
1697 return add_exec(&exec_list, do_pty, (char *)args,
1698 addr_low_byte, htons(guest_port));
1699}
1700
1701void slirp_set_ethaddr(PNATState pData, const uint8_t *ethaddr)
1702{
1703#ifndef VBOX_WITH_NAT_SERVICE
1704 memcpy(client_ethaddr, ethaddr, ETH_ALEN);
1705#endif
1706}
1707
1708#if defined(RT_OS_WINDOWS)
1709HANDLE *slirp_get_events(PNATState pData)
1710{
1711 return pData->phEvents;
1712}
1713void slirp_register_external_event(PNATState pData, HANDLE hEvent, int index)
1714{
1715 pData->phEvents[index] = hEvent;
1716}
1717#endif
1718
1719unsigned int slirp_get_timeout_ms(PNATState pData)
1720{
1721 if (link_up)
1722 {
1723 if (time_fasttimo)
1724 return 2;
1725 if (do_slowtimo)
1726 return 500; /* see PR_SLOWHZ */
1727 }
1728 return 0;
1729}
1730
1731#ifndef RT_OS_WINDOWS
1732int slirp_get_nsock(PNATState pData)
1733{
1734 return pData->nsock;
1735}
1736#endif
1737
1738/*
1739 * this function called from NAT thread
1740 */
1741void slirp_post_sent(PNATState pData, void *pvArg)
1742{
1743 struct socket *so = 0;
1744 struct tcpcb *tp = 0;
1745 struct mbuf *m = (struct mbuf *)pvArg;
1746 m_free(pData, m);
1747}
1748#ifdef VBOX_WITH_SLIRP_MT
1749void slirp_process_queue(PNATState pData)
1750{
1751 RTReqProcess(pData->pReqQueue, RT_INDEFINITE_WAIT);
1752}
1753void *slirp_get_queue(PNATState pData)
1754{
1755 return pData->pReqQueue;
1756}
1757#endif
1758
1759void slirp_set_dhcp_TFTP_prefix(PNATState pData, const char *tftpPrefix)
1760{
1761 Log2(("tftp_prefix:%s\n", tftpPrefix));
1762 tftp_prefix = tftpPrefix;
1763}
1764
1765void slirp_set_dhcp_TFTP_bootfile(PNATState pData, const char *bootFile)
1766{
1767 Log2(("bootFile:%s\n", bootFile));
1768 bootp_filename = bootFile;
1769}
1770
1771void slirp_set_dhcp_next_server(PNATState pData, const char *next_server)
1772{
1773 Log2(("next_server:%s\n", next_server));
1774 if (next_server == NULL)
1775 pData->tftp_server.s_addr = htonl(ntohl(special_addr.s_addr) | CTL_TFTP);
1776 else
1777 inet_aton(next_server, &pData->tftp_server);
1778}
1779
1780int slirp_set_binding_address(PNATState pData, char *addr)
1781{
1782 if (addr == NULL || (inet_aton(addr, &pData->bindIP) == 0))
1783 {
1784 pData->bindIP.s_addr = INADDR_ANY;
1785 return 1;
1786 }
1787 return 0;
1788}
1789
1790void slirp_set_dhcp_dns_proxy(PNATState pData, bool fDNSProxy)
1791{
1792 Log2(("NAT: DNS proxy switched %s\n", (fDNSProxy ? "on" : "off")));
1793 pData->use_dns_proxy = fDNSProxy;
1794}
1795
1796#define CHECK_ARG(name, val, lim_min, lim_max) \
1797do { \
1798 if ((val) < (lim_min) || (val) > (lim_max)) \
1799 { \
1800 LogRel(("NAT: (" #name ":%d) has been ignored, " \
1801 "because out of range (%d, %d)\n", (val), (lim_min), (lim_max))); \
1802 return; \
1803 } \
1804 else \
1805 { \
1806 LogRel(("NAT: (" #name ":%d)\n", (val))); \
1807 } \
1808} while (0)
1809
1810/* don't allow user set less 8kB and more than 1M values */
1811#define _8K_1M_CHECK_ARG(name, val) CHECK_ARG(name, (val), 8, 1024)
1812void slirp_set_rcvbuf(PNATState pData, int kilobytes)
1813{
1814 _8K_1M_CHECK_ARG("SOCKET_RCVBUF", kilobytes);
1815 pData->socket_rcv = kilobytes;
1816}
1817void slirp_set_sndbuf(PNATState pData, int kilobytes)
1818{
1819 _8K_1M_CHECK_ARG("SOCKET_SNDBUF", kilobytes);
1820 pData->socket_snd = kilobytes * _1K;
1821}
1822void slirp_set_tcp_rcvspace(PNATState pData, int kilobytes)
1823{
1824 _8K_1M_CHECK_ARG("TCP_RCVSPACE", kilobytes);
1825 tcp_rcvspace = kilobytes * _1K;
1826}
1827void slirp_set_tcp_sndspace(PNATState pData, int kilobytes)
1828{
1829 _8K_1M_CHECK_ARG("TCP_SNDSPACE", kilobytes);
1830 tcp_sndspace = kilobytes * _1K;
1831}
1832
1833/*
1834 * Looking for Ether by ip in ARP-cache
1835 * Note: it´s responsible of caller to allocate buffer for result
1836 * @returns 0 - if found, 1 - otherwise
1837 */
1838int slirp_arp_lookup_ether_by_ip(PNATState pData, uint32_t ip, uint8_t *ether)
1839{
1840 struct arp_cache_entry *ac = NULL;
1841 int rc = 1;
1842 if (ether == NULL)
1843 return rc;
1844
1845 if (LIST_EMPTY(&pData->arp_cache))
1846 return rc;
1847
1848 LIST_FOREACH(ac, &pData->arp_cache, list)
1849 {
1850 if (ac->ip == ip)
1851 {
1852 memcpy(ether, ac->ether, ETH_ALEN);
1853 rc = 0;
1854 return rc;
1855 }
1856 }
1857 return rc;
1858}
1859
1860/*
1861 * Looking for IP by Ether in ARP-cache
1862 * Note: it´s responsible of caller to allocate buffer for result
1863 * @returns 0 - if found, 1 - otherwise
1864 */
1865int slirp_arp_lookup_ip_by_ether(PNATState pData, const uint8_t *ether, uint32_t *ip)
1866{
1867 struct arp_cache_entry *ac = NULL;
1868 int rc = 1;
1869 *ip = INADDR_ANY;
1870 if (LIST_EMPTY(&pData->arp_cache))
1871 return rc;
1872 LIST_FOREACH(ac, &pData->arp_cache, list)
1873 {
1874 if (memcmp(ether, ac->ether, ETH_ALEN))
1875 {
1876 *ip = ac->ip;
1877 rc = 0;
1878 return rc;
1879 }
1880 }
1881 return rc;
1882}
1883
1884void slirp_arp_who_has(PNATState pData, uint32_t dst)
1885{
1886 struct mbuf *m;
1887 struct ethhdr *ehdr;
1888 struct arphdr *ahdr;
1889
1890 m = m_get(pData);
1891 if (m == NULL)
1892 {
1893 LogRel(("NAT: Can't alloc mbuf for ARP request\n"));
1894 return;
1895 }
1896 ehdr = mtod(m, struct ethhdr *);
1897 memset(ehdr->h_source, 0xff, ETH_ALEN);
1898 ahdr = (struct arphdr *)&ehdr[1];
1899 ahdr->ar_hrd = htons(1);
1900 ahdr->ar_pro = htons(ETH_P_IP);
1901 ahdr->ar_hln = ETH_ALEN;
1902 ahdr->ar_pln = 4;
1903 ahdr->ar_op = htons(ARPOP_REQUEST);
1904 memcpy(ahdr->ar_sha, special_ethaddr, ETH_ALEN);
1905 *(uint32_t *)ahdr->ar_sip = htonl(ntohl(special_addr.s_addr) | CTL_ALIAS);
1906 memset(ahdr->ar_tha, 0xff, ETH_ALEN); /*broadcast*/
1907 *(uint32_t *)ahdr->ar_tip = dst;
1908 m->m_data += if_maxlinkhdr;
1909 m->m_len = sizeof(struct arphdr);
1910 if_encap(pData, ETH_P_ARP, m);
1911 LogRel(("NAT: ARP request sent\n"));
1912}
1913
1914/* updates the arp cache
1915 * @returns 0 - if has found and updated
1916 * 1 - if hasn't found.
1917 */
1918int slirp_arp_cache_update(PNATState pData, uint32_t dst, const uint8_t *mac)
1919{
1920 struct arp_cache_entry *ac;
1921 LIST_FOREACH(ac, &pData->arp_cache, list)
1922 {
1923 if (memcmp(ac->ether, mac, ETH_ALEN) == 0)
1924 {
1925 ac->ip = dst;
1926 return 0;
1927 }
1928 }
1929 return 1;
1930}
1931
1932void slirp_arp_cache_add(PNATState pData, uint32_t ip, const uint8_t *ether)
1933{
1934 struct arp_cache_entry *ac = NULL;
1935 ac = RTMemAllocZ(sizeof(struct arp_cache_entry));
1936 if (ac == NULL)
1937 {
1938 LogRel(("NAT: Can't allocate arp cache entry\n"));
1939 return;
1940 }
1941 ac->ip = ip;
1942 memcpy(ac->ether, ether, ETH_ALEN);
1943 LIST_INSERT_HEAD(&pData->arp_cache, ac, list);
1944}
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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