VirtualBox

source: vbox/trunk/src/VBox/NetworkServices/NAT/VBoxNetLwipNAT.cpp@ 49835

Last change on this file since 49835 was 49835, checked in by vboxsync, 11 years ago

VBoxNetLwipNAT.cpp: uses exported functions and listener declaration.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 36.5 KB
Line 
1/* $Id: VBoxNetLwipNAT.cpp 49835 2013-12-09 11:45:07Z vboxsync $ */
2/** @file
3 * VBoxNetNAT - NAT Service for connecting to IntNet.
4 */
5
6/*
7 * Copyright (C) 2009 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18#include "winutils.h"
19
20#include <VBox/com/com.h>
21#include <VBox/com/listeners.h>
22#include <VBox/com/string.h>
23#include <VBox/com/Guid.h>
24#include <VBox/com/array.h>
25#include <VBox/com/ErrorInfo.h>
26#include <VBox/com/errorprint.h>
27#include <VBox/com/VirtualBox.h>
28#include <VBox/com/NativeEventQueue.h>
29
30#include <iprt/net.h>
31#include <iprt/initterm.h>
32#include <iprt/alloca.h>
33#ifndef RT_OS_WINDOWS
34# include <arpa/inet.h>
35#endif
36#include <iprt/err.h>
37#include <iprt/time.h>
38#include <iprt/timer.h>
39#include <iprt/thread.h>
40#include <iprt/stream.h>
41#include <iprt/path.h>
42#include <iprt/param.h>
43#include <iprt/pipe.h>
44#include <iprt/getopt.h>
45#include <iprt/string.h>
46#include <iprt/mem.h>
47#include <iprt/message.h>
48#include <iprt/req.h>
49#include <iprt/file.h>
50#include <iprt/semaphore.h>
51#include <iprt/cpp/utils.h>
52#define LOG_GROUP LOG_GROUP_NAT_SERVICE
53#include <VBox/log.h>
54
55#include <VBox/sup.h>
56#include <VBox/intnet.h>
57#include <VBox/intnetinline.h>
58#include <VBox/vmm/pdmnetinline.h>
59#include <VBox/vmm/vmm.h>
60#include <VBox/version.h>
61
62#ifndef RT_OS_WINDOWS
63# include <sys/poll.h>
64# include <sys/socket.h>
65# include <netinet/in.h>
66# ifdef RT_OS_LINUX
67# include <linux/icmp.h> /* ICMP_FILTER */
68# endif
69# include <netinet/icmp6.h>
70#endif
71
72#include <map>
73#include <vector>
74#include <string>
75
76#include "../NetLib/VBoxNetLib.h"
77#include "../NetLib/VBoxNetBaseService.h"
78#include "../NetLib/utils.h"
79#include "VBoxLwipCore.h"
80
81extern "C"
82{
83/* bunch of LWIP headers */
84#include "lwip/opt.h"
85#ifdef LWIP_SOCKET
86# undef LWIP_SOCKET
87# define LWIP_SOCKET 0
88#endif
89#include "lwip/sys.h"
90#include "lwip/pbuf.h"
91#include "lwip/netif.h"
92#include "lwip/ethip6.h"
93#include "lwip/nd6.h" // for proxy_na_hook
94#include "lwip/mld6.h"
95#include "lwip/tcpip.h"
96#include "netif/etharp.h"
97
98#include "proxy.h"
99#include "pxremap.h"
100#include "portfwd.h"
101}
102
103#include "../NetLib/VBoxPortForwardString.h"
104
105static RTGETOPTDEF g_aGetOptDef[] =
106{
107 { "--port-forward4", 'p', RTGETOPT_REQ_STRING },
108 { "--port-forward6", 'P', RTGETOPT_REQ_STRING }
109};
110
111typedef struct NATSEVICEPORTFORWARDRULE
112{
113 PORTFORWARDRULE Pfr;
114 fwspec FWSpec;
115} NATSEVICEPORTFORWARDRULE, *PNATSEVICEPORTFORWARDRULE;
116
117typedef std::vector<NATSEVICEPORTFORWARDRULE> VECNATSERVICEPF;
118typedef VECNATSERVICEPF::iterator ITERATORNATSERVICEPF;
119typedef VECNATSERVICEPF::const_iterator CITERATORNATSERVICEPF;
120
121
122
123class VBoxNetLwipNAT: public VBoxNetBaseService, public NATNetworkEventAdapter
124{
125 friend class NATNetworkListener;
126 public:
127 VBoxNetLwipNAT(SOCKET icmpsock4, SOCKET icmpsock6);
128 virtual ~VBoxNetLwipNAT();
129 void usage(){ /* @todo: should be implemented */ };
130 int run();
131 virtual int init(void);
132 /* @todo: when configuration would be really needed */
133 virtual int parseOpt(int rc, const RTGETOPTUNION& getOptVal);
134 /* VBoxNetNAT always needs Main */
135 virtual bool isMainNeeded() const { return true; }
136 virtual int processFrame(void *, size_t);
137 virtual int processGSO(PCPDMNETWORKGSO, size_t);
138 virtual int processUDP(void *, size_t) { return VERR_IGNORED; }
139
140 private:
141 struct proxy_options m_ProxyOptions;
142 struct sockaddr_in m_src4;
143 struct sockaddr_in6 m_src6;
144 /**
145 * place for registered local interfaces.
146 */
147 ip4_lomap m_lo2off[10];
148 ip4_lomap_desc m_loOptDescriptor;
149
150 uint16_t m_u16Mtu;
151 netif m_LwipNetIf;
152 /* thread where we're waiting for a frames, no semaphores needed */
153 RTTHREAD hThrIntNetRecv;
154
155 /* Our NAT network descriptor in Main */
156 ComPtr<INATNetwork> m_net;
157 ComNatListenerPtr m_listener;
158
159 ComPtr<IHost> m_host;
160 ComNatListenerPtr m_vboxListener;
161 static INTNETSEG aXmitSeg[64];
162
163 HRESULT HandleEvent(VBoxEventType_T aEventType, IEvent *pEvent);
164
165 const char **getHostNameservers();
166
167 /* Only for debug needs, by default NAT service should load rules from SVC
168 * on startup, and then on sync them on events.
169 */
170 bool fDontLoadRulesOnStartup;
171 static void onLwipTcpIpInit(void *arg);
172 static void onLwipTcpIpFini(void *arg);
173 static err_t netifInit(netif *pNetif);
174 static err_t netifLinkoutput(netif *pNetif, pbuf *pBuf);
175 static int intNetThreadRecv(RTTHREAD, void *);
176
177 VECNATSERVICEPF m_vecPortForwardRule4;
178 VECNATSERVICEPF m_vecPortForwardRule6;
179
180 static int natServicePfRegister(NATSEVICEPORTFORWARDRULE& natServicePf);
181 static int natServiceProcessRegisteredPf(VECNATSERVICEPF& vecPf);
182};
183
184
185static VBoxNetLwipNAT *g_pLwipNat;
186INTNETSEG VBoxNetLwipNAT::aXmitSeg[64];
187
188STDMETHODIMP VBoxNetLwipNAT::HandleEvent(VBoxEventType_T aEventType,
189 IEvent *pEvent)
190{
191 HRESULT hrc = S_OK;
192 switch (aEventType)
193 {
194 case VBoxEventType_OnNATNetworkSetting:
195 {
196 ComPtr<INATNetworkSettingEvent> evSettings(pEvent);
197 // XXX: only handle IPv6 default route for now
198
199 if (!m_ProxyOptions.ipv6_enabled)
200 {
201 break;
202 }
203
204 BOOL fIPv6DefaultRoute = FALSE;
205 hrc = evSettings->COMGETTER(AdvertiseDefaultIPv6RouteEnabled)(&fIPv6DefaultRoute);
206 AssertReturn(SUCCEEDED(hrc), hrc);
207
208 if (m_ProxyOptions.ipv6_defroute == fIPv6DefaultRoute)
209 {
210 break;
211 }
212
213 m_ProxyOptions.ipv6_defroute = fIPv6DefaultRoute;
214 tcpip_callback_with_block(proxy_rtadvd_do_quick, &m_LwipNetIf, 0);
215
216 break;
217 }
218
219 case VBoxEventType_OnNATNetworkPortForward:
220 {
221 com::Bstr name, strHostAddr, strGuestAddr;
222 LONG lHostPort, lGuestPort;
223 BOOL fCreateFW, fIPv6FW;
224 NATProtocol_T proto = NATProtocol_TCP;
225
226
227 ComPtr<INATNetworkPortForwardEvent> pfEvt = pEvent;
228
229 hrc = pfEvt->COMGETTER(Name)(name.asOutParam());
230 AssertReturn(SUCCEEDED(hrc), hrc);
231
232 hrc = pfEvt->COMGETTER(Proto)(&proto);
233 AssertReturn(SUCCEEDED(hrc), hrc);
234
235 hrc = pfEvt->COMGETTER(HostIp)(strHostAddr.asOutParam());
236 AssertReturn(SUCCEEDED(hrc), hrc);
237
238 hrc = pfEvt->COMGETTER(HostPort)(&lHostPort);
239 AssertReturn(SUCCEEDED(hrc), hrc);
240
241 hrc = pfEvt->COMGETTER(GuestIp)(strGuestAddr.asOutParam());
242 AssertReturn(SUCCEEDED(hrc), hrc);
243
244 hrc = pfEvt->COMGETTER(GuestPort)(&lGuestPort);
245 AssertReturn(SUCCEEDED(hrc), hrc);
246
247 hrc = pfEvt->COMGETTER(Create)(&fCreateFW);
248 AssertReturn(SUCCEEDED(hrc), hrc);
249
250 hrc = pfEvt->COMGETTER(Ipv6)(&fIPv6FW);
251 AssertReturn(SUCCEEDED(hrc), hrc);
252
253 VECNATSERVICEPF& rules = (fIPv6FW ?
254 m_vecPortForwardRule6 :
255 m_vecPortForwardRule4);
256
257 NATSEVICEPORTFORWARDRULE r;
258
259 RT_ZERO(r);
260
261 if (name.length() > sizeof(r.Pfr.szPfrName))
262 {
263 hrc = E_INVALIDARG;
264 goto port_forward_done;
265 }
266
267 r.Pfr.fPfrIPv6 = fIPv6FW;
268
269 switch (proto)
270 {
271 case NATProtocol_TCP:
272 r.Pfr.iPfrProto = IPPROTO_TCP;
273 break;
274 case NATProtocol_UDP:
275 r.Pfr.iPfrProto = IPPROTO_UDP;
276 break;
277 default:
278 goto port_forward_done;
279 }
280
281
282 RTStrPrintf(r.Pfr.szPfrName, sizeof(r.Pfr.szPfrName),
283 "%s", com::Utf8Str(name).c_str());
284
285 RTStrPrintf(r.Pfr.szPfrHostAddr, sizeof(r.Pfr.szPfrHostAddr),
286 "%s", com::Utf8Str(strHostAddr).c_str());
287
288 /* XXX: limits should be checked */
289 r.Pfr.u16PfrHostPort = (uint16_t)lHostPort;
290
291 RTStrPrintf(r.Pfr.szPfrGuestAddr, sizeof(r.Pfr.szPfrGuestAddr),
292 "%s", com::Utf8Str(strGuestAddr).c_str());
293
294 /* XXX: limits should be checked */
295 r.Pfr.u16PfrGuestPort = (uint16_t)lGuestPort;
296
297 if (fCreateFW) /* Addition */
298 {
299 rules.push_back(r);
300
301 natServicePfRegister(rules.back());
302 }
303 else /* Deletion */
304 {
305 ITERATORNATSERVICEPF it;
306 for (it = rules.begin(); it != rules.end(); ++it)
307 {
308 /* compare */
309 NATSEVICEPORTFORWARDRULE& natFw = *it;
310 if ( natFw.Pfr.iPfrProto == r.Pfr.iPfrProto
311 && natFw.Pfr.u16PfrHostPort == r.Pfr.u16PfrHostPort
312 && (strncmp(natFw.Pfr.szPfrHostAddr, r.Pfr.szPfrHostAddr, INET6_ADDRSTRLEN) == 0)
313 && natFw.Pfr.u16PfrGuestPort == r.Pfr.u16PfrGuestPort
314 && (strncmp(natFw.Pfr.szPfrGuestAddr, r.Pfr.szPfrGuestAddr, INET6_ADDRSTRLEN) == 0))
315 {
316 fwspec *pFwCopy = (fwspec *)RTMemAllocZ(sizeof(fwspec));
317 if (!pFwCopy)
318 {
319 break;
320 }
321 memcpy(pFwCopy, &natFw.FWSpec, sizeof(fwspec));
322
323 /* We shouldn't care about pFwCopy this memory will be freed when
324 * will message will arrive to the destination.
325 */
326 portfwd_rule_del(pFwCopy);
327
328 rules.erase(it);
329 break;
330 }
331 } /* loop over vector elements */
332 } /* condition add or delete */
333 port_forward_done:
334 /* clean up strings */
335 name.setNull();
336 strHostAddr.setNull();
337 strGuestAddr.setNull();
338 break;
339 }
340
341 case VBoxEventType_OnHostNameResolutionConfigurationChange:
342 {
343 const char **ppcszNameServers = getHostNameservers();
344 err_t error;
345
346 error = tcpip_callback_with_block(pxdns_set_nameservers,
347 ppcszNameServers,
348 /* :block */ 0);
349 if (error != ERR_OK && ppcszNameServers != NULL)
350 {
351 RTMemFree(ppcszNameServers);
352 }
353 break;
354 }
355 }
356 return hrc;
357}
358
359
360void VBoxNetLwipNAT::onLwipTcpIpInit(void* arg)
361{
362 AssertPtrReturnVoid(arg);
363 VBoxNetLwipNAT *pNat = static_cast<VBoxNetLwipNAT *>(arg);
364
365 HRESULT hrc = com::Initialize();
366 Assert(!FAILED(hrc));
367
368 proxy_arp_hook = pxremap_proxy_arp;
369 proxy_ip4_divert_hook = pxremap_ip4_divert;
370
371 proxy_na_hook = pxremap_proxy_na;
372 proxy_ip6_divert_hook = pxremap_ip6_divert;
373
374 /* lwip thread */
375 RTNETADDRIPV4 network;
376 RTNETADDRIPV4 address = g_pLwipNat->getIpv4Address();
377 RTNETADDRIPV4 netmask = g_pLwipNat->getIpv4Netmask();
378 network.u = address.u & netmask.u;
379
380 ip_addr LwipIpAddr, LwipIpNetMask, LwipIpNetwork;
381
382 memcpy(&LwipIpAddr, &address, sizeof(ip_addr));
383 memcpy(&LwipIpNetMask, &netmask, sizeof(ip_addr));
384 memcpy(&LwipIpNetwork, &network, sizeof(ip_addr));
385
386 netif *pNetif = netif_add(&g_pLwipNat->m_LwipNetIf /* Lwip Interface */,
387 &LwipIpAddr /* IP address*/,
388 &LwipIpNetMask /* Network mask */,
389 &LwipIpAddr /* gateway address, @todo: is self IP acceptable? */,
390 g_pLwipNat /* state */,
391 VBoxNetLwipNAT::netifInit /* netif_init_fn */,
392 lwip_tcpip_input /* netif_input_fn */);
393
394 AssertPtrReturnVoid(pNetif);
395
396 netif_set_up(pNetif);
397 netif_set_link_up(pNetif);
398
399 if (pNat->m_ProxyOptions.ipv6_enabled) {
400 /*
401 * XXX: lwIP currently only ever calls mld6_joingroup() in
402 * nd6_tmr() for fresh tentative addresses, which is a wrong place
403 * to do it - but I'm not keen on fixing this properly for now
404 * (with correct handling of interface up and down transitions,
405 * etc). So stick it here as a kludge.
406 */
407 for (int i = 0; i <= 1; ++i) {
408 ip6_addr_t *paddr = netif_ip6_addr(pNetif, i);
409
410 ip6_addr_t solicited_node_multicast_address;
411 ip6_addr_set_solicitednode(&solicited_node_multicast_address,
412 paddr->addr[3]);
413 mld6_joingroup(paddr, &solicited_node_multicast_address);
414 }
415
416 /*
417 * XXX: We must join the solicited-node multicast for the
418 * addresses we do IPv6 NA-proxy for. We map IPv6 loopback to
419 * proxy address + 1. We only need the low 24 bits, and those are
420 * fixed.
421 */
422 {
423 ip6_addr_t solicited_node_multicast_address;
424
425 ip6_addr_set_solicitednode(&solicited_node_multicast_address,
426 /* last 24 bits of the address */
427 PP_HTONL(0x00000002));
428 mld6_netif_joingroup(pNetif, &solicited_node_multicast_address);
429 }
430 }
431
432 proxy_init(&g_pLwipNat->m_LwipNetIf, &g_pLwipNat->m_ProxyOptions);
433
434 natServiceProcessRegisteredPf(g_pLwipNat->m_vecPortForwardRule4);
435 natServiceProcessRegisteredPf(g_pLwipNat->m_vecPortForwardRule6);
436}
437
438
439void VBoxNetLwipNAT::onLwipTcpIpFini(void* arg)
440{
441 AssertPtrReturnVoid(arg);
442 VBoxNetLwipNAT *pThis = (VBoxNetLwipNAT *)arg;
443
444 /* XXX: proxy finalization */
445 netif_set_link_down(&g_pLwipNat->m_LwipNetIf);
446 netif_set_down(&g_pLwipNat->m_LwipNetIf);
447 netif_remove(&g_pLwipNat->m_LwipNetIf);
448
449}
450
451/*
452 * Callback for netif_add() to initialize the interface.
453 */
454err_t VBoxNetLwipNAT::netifInit(netif *pNetif)
455{
456 err_t rcLwip = ERR_OK;
457
458 AssertPtrReturn(pNetif, ERR_ARG);
459
460 VBoxNetLwipNAT *pNat = static_cast<VBoxNetLwipNAT *>(pNetif->state);
461 AssertPtrReturn(pNat, ERR_ARG);
462
463 LogFlowFunc(("ENTER: pNetif[%c%c%d]\n", pNetif->name[0], pNetif->name[1], pNetif->num));
464 /* validity */
465 AssertReturn( pNetif->name[0] == 'N'
466 && pNetif->name[1] == 'T', ERR_ARG);
467
468
469 pNetif->hwaddr_len = sizeof(RTMAC);
470 RTMAC mac = g_pLwipNat->getMacAddress();
471 memcpy(pNetif->hwaddr, &mac, sizeof(RTMAC));
472
473 pNat->m_u16Mtu = 1500; // XXX: FIXME
474 pNetif->mtu = pNat->m_u16Mtu;
475
476 pNetif->flags = NETIF_FLAG_BROADCAST
477 | NETIF_FLAG_ETHARP /* Don't bother driver with ARP and let Lwip resolve ARP handling */
478 | NETIF_FLAG_ETHERNET; /* Lwip works with ethernet too */
479
480 pNetif->linkoutput = netifLinkoutput; /* ether-level-pipe */
481 pNetif->output = lwip_etharp_output; /* ip-pipe */
482
483 if (pNat->m_ProxyOptions.ipv6_enabled) {
484 pNetif->output_ip6 = ethip6_output;
485
486 /* IPv6 link-local address in slot 0 */
487 netif_create_ip6_linklocal_address(pNetif, /* :from_mac_48bit */ 1);
488 netif_ip6_addr_set_state(pNetif, 0, IP6_ADDR_PREFERRED); // skip DAD
489
490 /*
491 * RFC 4193 Locally Assigned Global ID (ULA) in slot 1
492 * [fd17:625c:f037:XXXX::1] where XXXX, 16 bit Subnet ID, are two
493 * bytes from the middle of the IPv4 address, e.g. :dead: for
494 * 10.222.173.1
495 */
496 u8_t nethi = ip4_addr2(&pNetif->ip_addr);
497 u8_t netlo = ip4_addr3(&pNetif->ip_addr);
498
499 ip6_addr_t *paddr = netif_ip6_addr(pNetif, 1);
500 IP6_ADDR(paddr, 0, 0xFD, 0x17, 0x62, 0x5C);
501 IP6_ADDR(paddr, 1, 0xF0, 0x37, nethi, netlo);
502 IP6_ADDR(paddr, 2, 0x00, 0x00, 0x00, 0x00);
503 IP6_ADDR(paddr, 3, 0x00, 0x00, 0x00, 0x01);
504 netif_ip6_addr_set_state(pNetif, 1, IP6_ADDR_PREFERRED);
505
506#if LWIP_IPV6_SEND_ROUTER_SOLICIT
507 pNetif->rs_count = 0;
508#endif
509 }
510
511 LogFlowFunc(("LEAVE: %d\n", rcLwip));
512 return rcLwip;
513}
514
515
516/**
517 * Intnet-recv thread
518 */
519int VBoxNetLwipNAT::intNetThreadRecv(RTTHREAD, void *)
520{
521 int rc = VINF_SUCCESS;
522
523 /* 1. initialization and connection */
524 HRESULT hrc = com::Initialize();
525 if (FAILED(hrc))
526 return RTMsgErrorExit(RTEXITCODE_FAILURE, "Failed to initialize COM!");
527
528 g_pLwipNat->doReceiveLoop();
529 /* 3. deinitilization and termination */
530 LogFlowFuncLeaveRC(rc);
531 return rc;
532}
533
534
535err_t VBoxNetLwipNAT::netifLinkoutput(netif *pNetif, pbuf *pPBuf)
536{
537 AssertPtrReturn(pNetif, ERR_ARG);
538 AssertPtrReturn(pPBuf, ERR_ARG);
539 AssertReturn((void *)g_pLwipNat == pNetif->state, ERR_ARG);
540
541 LogFlowFunc(("ENTER: pNetif[%c%c%d], pPbuf:%p\n",
542 pNetif->name[0],
543 pNetif->name[1],
544 pNetif->num,
545 pPBuf));
546
547 RT_ZERO(VBoxNetLwipNAT::aXmitSeg);
548
549 unsigned idx = 0;
550 for( struct pbuf *pPBufPtr = pPBuf;
551 pPBufPtr;
552 pPBufPtr = pPBufPtr->next, ++idx)
553 {
554 AssertReturn(idx < RT_ELEMENTS(VBoxNetLwipNAT::aXmitSeg), ERR_MEM);
555 VBoxNetLwipNAT::aXmitSeg[idx].pv = pPBufPtr->payload;
556 VBoxNetLwipNAT::aXmitSeg[idx].cb = pPBufPtr->len;
557 }
558
559 int rc = g_pLwipNat->sendBufferOnWire(VBoxNetLwipNAT::aXmitSeg, idx, pPBuf->tot_len);
560 AssertRCReturn(rc, ERR_IF);
561
562 g_pLwipNat->flushWire();
563
564 LogFlowFunc(("LEAVE: %d\n", ERR_OK));
565 return ERR_OK;
566}
567
568
569VBoxNetLwipNAT::VBoxNetLwipNAT(SOCKET icmpsock4, SOCKET icmpsock6) : VBoxNetBaseService("VBoxNetNAT", "nat-network")
570{
571 LogFlowFuncEnter();
572
573 m_ProxyOptions.ipv6_enabled = 0;
574 m_ProxyOptions.ipv6_defroute = 0;
575 m_ProxyOptions.icmpsock4 = icmpsock4;
576 m_ProxyOptions.icmpsock6 = icmpsock6;
577 m_ProxyOptions.tftp_root = NULL;
578 m_ProxyOptions.src4 = NULL;
579 m_ProxyOptions.src6 = NULL;
580 memset(&m_src4, 0, sizeof(m_src4));
581 memset(&m_src6, 0, sizeof(m_src6));
582 m_src4.sin_family = AF_INET;
583 m_src6.sin6_family = AF_INET6;
584#if HAVE_SA_LEN
585 m_src4.sin_len = sizeof(m_src4);
586 m_src6.sin6_len = sizeof(m_src6);
587#endif
588 m_ProxyOptions.nameservers = NULL;
589
590 m_LwipNetIf.name[0] = 'N';
591 m_LwipNetIf.name[1] = 'T';
592
593 RTMAC mac;
594 mac.au8[0] = 0x52;
595 mac.au8[1] = 0x54;
596 mac.au8[2] = 0;
597 mac.au8[3] = 0x12;
598 mac.au8[4] = 0x35;
599 mac.au8[5] = 0;
600 setMacAddress(mac);
601
602 RTNETADDRIPV4 address;
603 address.u = RT_MAKE_U32_FROM_U8( 10, 0, 2, 2); // NB: big-endian
604 setIpv4Address(address);
605
606 address.u = RT_H2N_U32_C(0xffffff00);
607 setIpv4Netmask(address);
608
609 fDontLoadRulesOnStartup = false;
610
611 for(unsigned int i = 0; i < RT_ELEMENTS(g_aGetOptDef); ++i)
612 addCommandLineOption(&g_aGetOptDef[i]);
613
614 LogFlowFuncLeave();
615}
616
617
618VBoxNetLwipNAT::~VBoxNetLwipNAT()
619{
620 if (m_ProxyOptions.tftp_root != NULL)
621 {
622 RTStrFree((char *)m_ProxyOptions.tftp_root);
623 }
624}
625
626
627int VBoxNetLwipNAT::natServicePfRegister(NATSEVICEPORTFORWARDRULE& natPf)
628{
629 int lrc = 0;
630 int rc = VINF_SUCCESS;
631 int socketSpec = SOCK_STREAM;
632 char *pszHostAddr;
633 int sockFamily = (natPf.Pfr.fPfrIPv6 ? PF_INET6 : PF_INET);
634
635 switch(natPf.Pfr.iPfrProto)
636 {
637 case IPPROTO_TCP:
638 socketSpec = SOCK_STREAM;
639 break;
640 case IPPROTO_UDP:
641 socketSpec = SOCK_DGRAM;
642 break;
643 default:
644 return VERR_IGNORED; /* Ah, just ignore the garbage */
645 }
646
647 pszHostAddr = natPf.Pfr.szPfrHostAddr;
648
649 /* XXX: workaround for inet_pton and an empty ipv4 address
650 * in rule declaration.
651 */
652 if ( sockFamily == PF_INET
653 && pszHostAddr[0] == 0)
654 pszHostAddr = (char *)"0.0.0.0"; /* XXX: fix it! without type cast */
655
656
657 lrc = fwspec_set(&natPf.FWSpec,
658 sockFamily,
659 socketSpec,
660 pszHostAddr,
661 natPf.Pfr.u16PfrHostPort,
662 natPf.Pfr.szPfrGuestAddr,
663 natPf.Pfr.u16PfrGuestPort);
664
665 AssertReturn(!lrc, VERR_IGNORED);
666
667 fwspec *pFwCopy = (fwspec *)RTMemAllocZ(sizeof(fwspec));
668 AssertPtrReturn(pFwCopy, VERR_IGNORED);
669
670 /*
671 * We need pass the copy, because we can't be sure
672 * how much this pointer will be valid in LWIP environment.
673 */
674 memcpy(pFwCopy, &natPf.FWSpec, sizeof(fwspec));
675
676 lrc = portfwd_rule_add(pFwCopy);
677
678 AssertReturn(!lrc, VERR_IGNORED);
679
680 return VINF_SUCCESS;
681}
682
683
684int VBoxNetLwipNAT::natServiceProcessRegisteredPf(VECNATSERVICEPF& vecRules){
685 ITERATORNATSERVICEPF it;
686 for (it = vecRules.begin();
687 it != vecRules.end(); ++it)
688 {
689 int rc = natServicePfRegister((*it));
690 if (RT_FAILURE(rc))
691 {
692 LogRel(("PF: %s is ignored\n", (*it).Pfr.szPfrName));
693 continue;
694 }
695 }
696 return VINF_SUCCESS;
697}
698
699
700int VBoxNetLwipNAT::init()
701{
702 LogFlowFuncEnter();
703
704 /* virtualbox initialized in super class */
705 int rc = ::VBoxNetBaseService::init();
706 AssertRCReturn(rc, rc);
707
708 std::string networkName = getNetwork();
709 rc = findNatNetwork(virtualbox, networkName, m_net);
710 AssertRCReturn(rc, rc);
711
712 ComEventTypeArray aNetEvents;
713 aNetEvents.push_back(VBoxEventType_OnNATNetworkPortForward);
714 aNetEvents.push_back(VBoxEventType_OnNATNetworkSetting);
715 rc = createNatListener(m_listener, virtualbox, this, aNetEvents);
716 AssertRCReturn(rc, rc);
717
718
719 // resolver changes are reported on vbox but are retrieved from
720 // host so stash a pointer for future lookups
721 HRESULT hrc = virtualbox->COMGETTER(Host)(m_host.asOutParam());
722 AssertComRCReturn(hrc, VERR_INTERNAL_ERROR);
723
724 ComEventTypeArray aVBoxEvents;
725 aVBoxEvents.push_back(VBoxEventType_OnHostNameResolutionConfigurationChange);
726 rc = createNatListener(m_vboxListener, virtualbox, this, aVBoxEvents);
727 AssertRCReturn(rc, rc);
728
729 BOOL fIPv6Enabled = FALSE;
730 hrc = m_net->COMGETTER(IPv6Enabled)(&fIPv6Enabled);
731 AssertComRCReturn(hrc, VERR_NOT_FOUND);
732
733 BOOL fIPv6DefaultRoute = FALSE;
734 if (fIPv6Enabled)
735 {
736 hrc = m_net->COMGETTER(AdvertiseDefaultIPv6RouteEnabled)(&fIPv6DefaultRoute);
737 AssertComRCReturn(hrc, VERR_NOT_FOUND);
738 }
739
740 m_ProxyOptions.ipv6_enabled = fIPv6Enabled;
741 m_ProxyOptions.ipv6_defroute = fIPv6DefaultRoute;
742
743
744 com::Bstr bstrSourceIp4Key = com::BstrFmt("NAT/%s/SourceIp4", networkName.c_str());
745 com::Bstr bstrSourceIpX;
746 hrc = virtualbox->GetExtraData(bstrSourceIp4Key.raw(), bstrSourceIpX.asOutParam());
747 if (SUCCEEDED(hrc))
748 {
749 RTNETADDRIPV4 addr;
750 rc = RTNetStrToIPv4Addr(com::Utf8Str(bstrSourceIpX).c_str(), &addr);
751 if (RT_SUCCESS(rc))
752 {
753 RT_ZERO(m_src4);
754
755 m_src4.sin_addr.s_addr = addr.u;
756 m_ProxyOptions.src4 = &m_src4;
757
758 bstrSourceIpX.setNull();
759 }
760 }
761
762 if (!fDontLoadRulesOnStartup)
763 {
764 /* XXX: extract function and do not duplicate */
765 com::SafeArray<BSTR> rules;
766 hrc = m_net->COMGETTER(PortForwardRules4)(ComSafeArrayAsOutParam(rules));
767 Assert(SUCCEEDED(hrc));
768
769 size_t idxRules = 0;
770 for (idxRules = 0; idxRules < rules.size(); ++idxRules)
771 {
772 Log(("%d-rule: %ls\n", idxRules, rules[idxRules]));
773 NATSEVICEPORTFORWARDRULE Rule;
774 RT_ZERO(Rule);
775 rc = netPfStrToPf(com::Utf8Str(rules[idxRules]).c_str(), 0, &Rule.Pfr);
776 AssertRC(rc);
777 m_vecPortForwardRule4.push_back(Rule);
778 }
779
780 rules.setNull();
781 hrc = m_net->COMGETTER(PortForwardRules6)(ComSafeArrayAsOutParam(rules));
782 Assert(SUCCEEDED(hrc));
783
784 for (idxRules = 0; idxRules < rules.size(); ++idxRules)
785 {
786 Log(("%d-rule: %ls\n", idxRules, rules[idxRules]));
787 NATSEVICEPORTFORWARDRULE Rule;
788 netPfStrToPf(com::Utf8Str(rules[idxRules]).c_str(), 1, &Rule.Pfr);
789 m_vecPortForwardRule6.push_back(Rule);
790 }
791 } /* if (!fDontLoadRulesOnStartup) */
792
793 com::SafeArray<BSTR> strs;
794 int count_strs;
795 hrc = m_net->COMGETTER(LocalMappings)(ComSafeArrayAsOutParam(strs));
796 if ( SUCCEEDED(hrc)
797 && (count_strs = strs.size()))
798 {
799 unsigned int j = 0;
800 int i;
801
802 for (i = 0; i < count_strs && j < RT_ELEMENTS(m_lo2off); ++i)
803 {
804 char szAddr[17];
805 RTNETADDRIPV4 ip4addr;
806 char *pszTerm;
807 uint32_t u32Off;
808 com::Utf8Str strLo2Off(strs[i]);
809 const char *pszLo2Off = strLo2Off.c_str();
810
811 RT_ZERO(szAddr);
812
813 pszTerm = RTStrStr(pszLo2Off, "=");
814
815 if ( !pszTerm
816 || (pszTerm - pszLo2Off) >= 17)
817 continue;
818
819 memcpy(szAddr, pszLo2Off, (pszTerm - pszLo2Off));
820 rc = RTNetStrToIPv4Addr(szAddr, &ip4addr);
821 if (RT_FAILURE(rc))
822 continue;
823
824 u32Off = RTStrToUInt32(pszTerm + 1);
825 if (u32Off == 0)
826 continue;
827
828 ip4_addr_set_u32(&m_lo2off[j].loaddr, ip4addr.u);
829 m_lo2off[j].off = u32Off;
830 ++j;
831 }
832
833 m_loOptDescriptor.lomap = m_lo2off;
834 m_loOptDescriptor.num_lomap = j;
835 m_ProxyOptions.lomap_desc = &m_loOptDescriptor;
836 }
837
838 com::Bstr bstr;
839 hrc = virtualbox->COMGETTER(HomeFolder)(bstr.asOutParam());
840 AssertComRCReturn(hrc, VERR_NOT_FOUND);
841 if (!bstr.isEmpty())
842 {
843 com::Utf8Str strTftpRoot(com::Utf8StrFmt("%ls%c%s",
844 bstr.raw(), RTPATH_DELIMITER, "TFTP"));
845 char *pszStrTemp; // avoid const char ** vs char **
846 rc = RTStrUtf8ToCurrentCP(&pszStrTemp, strTftpRoot.c_str());
847 AssertRC(rc);
848 m_ProxyOptions.tftp_root = pszStrTemp;
849 }
850
851 m_ProxyOptions.nameservers = getHostNameservers();
852
853 /* end of COM initialization */
854
855 rc = g_pLwipNat->tryGoOnline();
856 if (RT_FAILURE(rc))
857 {
858 return rc;
859 }
860
861 vboxLwipCoreInitialize(VBoxNetLwipNAT::onLwipTcpIpInit, this);
862
863 rc = RTThreadCreate(&g_pLwipNat->hThrIntNetRecv, /* thread handle*/
864 VBoxNetLwipNAT::intNetThreadRecv, /* routine */
865 NULL, /* user data */
866 128 * _1K, /* stack size */
867 RTTHREADTYPE_IO, /* type */
868 0, /* flags, @todo: waitable ?*/
869 "INTNET-RECV");
870 AssertRCReturn(rc,rc);
871
872
873
874 LogFlowFuncLeaveRC(rc);
875 return rc;
876}
877
878
879const char **VBoxNetLwipNAT::getHostNameservers()
880{
881 HRESULT hrc;
882
883 if (m_host.isNull())
884 {
885 return NULL;
886 }
887
888 com::SafeArray<BSTR> aNameServers;
889 hrc = m_host->COMGETTER(NameServers)(ComSafeArrayAsOutParam(aNameServers));
890 if (FAILED(hrc))
891 {
892 return NULL;
893 }
894
895 const size_t cNameServers = aNameServers.size();
896 if (cNameServers == 0)
897 {
898 return NULL;
899 }
900
901 const char **ppcszNameServers =
902 (const char **)RTMemAllocZ(sizeof(char *) * (cNameServers + 1));
903 if (ppcszNameServers == NULL)
904 {
905 return NULL;
906 }
907
908 size_t idxLast = 0;
909 for (size_t i = 0; i < cNameServers; ++i)
910 {
911 com::Utf8Str strNameServer(aNameServers[i]);
912 ppcszNameServers[idxLast] = RTStrDup(strNameServer.c_str());
913 if (ppcszNameServers[idxLast] != NULL)
914 {
915 ++idxLast;
916 }
917 }
918
919 if (idxLast == 0)
920 {
921 RTMemFree(ppcszNameServers);
922 return NULL;
923 }
924
925 return ppcszNameServers;
926}
927
928
929int VBoxNetLwipNAT::parseOpt(int rc, const RTGETOPTUNION& Val)
930{
931 switch (rc)
932 {
933 case 'p':
934 case 'P':
935 {
936 NATSEVICEPORTFORWARDRULE Rule;
937 VECNATSERVICEPF& rules = (rc == 'P'?
938 m_vecPortForwardRule6
939 : m_vecPortForwardRule4);
940
941 fDontLoadRulesOnStartup = true;
942
943 RT_ZERO(Rule);
944
945 int irc = netPfStrToPf(Val.psz, (rc == 'P'), &Rule.Pfr);
946 rules.push_back(Rule);
947 return VINF_SUCCESS;
948 }
949 default:;
950 }
951 return VERR_NOT_FOUND;
952}
953
954
955int VBoxNetLwipNAT::processFrame(void *pvFrame, size_t cbFrame)
956{
957 AssertReturn(pvFrame && cbFrame, VERR_INVALID_PARAMETER);
958
959 struct pbuf *pPbufHdr, *pPbuf;
960 pPbufHdr = pPbuf = pbuf_alloc(PBUF_RAW, cbFrame, PBUF_POOL);
961
962 AssertMsgReturn(pPbuf, ("NAT: Can't allocate send buffer cbFrame=%u\n", cbFrame), VERR_INTERNAL_ERROR);
963 AssertReturn(pPbufHdr->tot_len == cbFrame, VERR_INTERNAL_ERROR);
964
965 uint8_t *pu8Frame = (uint8_t *)pvFrame;
966 while(pPbuf)
967 {
968 memcpy(pPbuf->payload, pu8Frame, pPbuf->len);
969 pu8Frame += pPbuf->len;
970 pPbuf = pPbuf->next;
971 }
972
973 m_LwipNetIf.input(pPbufHdr, &m_LwipNetIf);
974
975 return VINF_SUCCESS;
976}
977
978
979int VBoxNetLwipNAT::processGSO(PCPDMNETWORKGSO pGso, size_t cbFrame)
980{
981 if (!PDMNetGsoIsValid(pGso, cbFrame,
982 cbFrame - sizeof(PDMNETWORKGSO)))
983 return VERR_INVALID_PARAMETER;
984
985 cbFrame -= sizeof(PDMNETWORKGSO);
986 uint8_t abHdrScratch[256];
987 uint32_t const cSegs = PDMNetGsoCalcSegmentCount(pGso,
988 cbFrame);
989 for (size_t iSeg = 0; iSeg < cSegs; iSeg++)
990 {
991 uint32_t cbSegFrame;
992 void *pvSegFrame =
993 PDMNetGsoCarveSegmentQD(pGso,
994 (uint8_t *)(pGso + 1),
995 cbFrame,
996 abHdrScratch,
997 iSeg,
998 cSegs,
999 &cbSegFrame);
1000
1001 struct pbuf *pPbuf = pbuf_alloc(PBUF_RAW, cbSegFrame, PBUF_POOL);
1002
1003 AssertMsgReturn(pPbuf, ("NAT: Can't allocate send buffer cbFrame=%u\n", cbSegFrame), VERR_INTERNAL_ERROR);
1004 AssertReturn(!pPbuf->next && pPbuf->len == cbSegFrame, VERR_INTERNAL_ERROR);
1005
1006 memcpy(pPbuf->payload, pvSegFrame, cbSegFrame);
1007 m_LwipNetIf.input(pPbuf, &g_pLwipNat->m_LwipNetIf);
1008 }
1009
1010 return VINF_SUCCESS;
1011}
1012
1013
1014int VBoxNetLwipNAT::run()
1015{
1016 /* EventQueue processing from VBoxHeadless.cpp */
1017 com::NativeEventQueue *gEventQ = NULL;
1018 gEventQ = com::NativeEventQueue::getMainEventQueue();
1019 while(true)
1020 {
1021 /* XXX:todo: graceful termination */
1022 gEventQ->processEventQueue(0);
1023 gEventQ->processEventQueue(500);
1024 }
1025
1026 vboxLwipCoreFinalize(VBoxNetLwipNAT::onLwipTcpIpFini, this);
1027
1028 m_vecPortForwardRule4.clear();
1029 m_vecPortForwardRule6.clear();
1030
1031 return VINF_SUCCESS;
1032}
1033
1034
1035/**
1036 * Entry point.
1037 */
1038extern "C" DECLEXPORT(int) TrustedMain(int argc, char **argv, char **envp)
1039{
1040 LogFlowFuncEnter();
1041
1042 NOREF(envp);
1043
1044#ifdef RT_OS_WINDOWS
1045 WSADATA wsaData;
1046 int err;
1047
1048 err = WSAStartup(MAKEWORD(2,2), &wsaData);
1049 if (err)
1050 {
1051 fprintf(stderr, "wsastartup: failed (%d)\n", err);
1052 return 1;
1053 }
1054#endif
1055
1056 SOCKET icmpsock4 = INVALID_SOCKET;
1057 SOCKET icmpsock6 = INVALID_SOCKET;
1058#ifndef RT_OS_DARWIN
1059 const int icmpstype = SOCK_RAW;
1060#else
1061 /* on OS X it's not privileged */
1062 const int icmpstype = SOCK_DGRAM;
1063#endif
1064
1065 icmpsock4 = socket(AF_INET, icmpstype, IPPROTO_ICMP);
1066 if (icmpsock4 == INVALID_SOCKET)
1067 {
1068 perror("IPPROTO_ICMP");
1069 }
1070
1071 if (icmpsock4 != INVALID_SOCKET)
1072 {
1073#ifdef ICMP_FILTER // Linux specific
1074 struct icmp_filter flt = {
1075 ~(uint32_t)(
1076 (1U << ICMP_ECHOREPLY)
1077 | (1U << ICMP_DEST_UNREACH)
1078 | (1U << ICMP_TIME_EXCEEDED)
1079 )
1080 };
1081
1082 int status = setsockopt(icmpsock4, SOL_RAW, ICMP_FILTER,
1083 &flt, sizeof(flt));
1084 if (status < 0)
1085 {
1086 perror("ICMP_FILTER");
1087 }
1088#endif
1089 }
1090
1091 icmpsock6 = socket(AF_INET6, icmpstype, IPPROTO_ICMPV6);
1092 if (icmpsock6 == INVALID_SOCKET)
1093 {
1094 perror("IPPROTO_ICMPV6");
1095 }
1096
1097 if (icmpsock6 != INVALID_SOCKET)
1098 {
1099#ifdef ICMP6_FILTER // Windows doesn't support RFC 3542 API
1100 /*
1101 * XXX: We do this here for now, not in pxping.c, to avoid
1102 * name clashes between lwIP and system headers.
1103 */
1104 struct icmp6_filter flt;
1105 ICMP6_FILTER_SETBLOCKALL(&flt);
1106
1107 ICMP6_FILTER_SETPASS(ICMP6_ECHO_REPLY, &flt);
1108
1109 ICMP6_FILTER_SETPASS(ICMP6_DST_UNREACH, &flt);
1110 ICMP6_FILTER_SETPASS(ICMP6_PACKET_TOO_BIG, &flt);
1111 ICMP6_FILTER_SETPASS(ICMP6_TIME_EXCEEDED, &flt);
1112 ICMP6_FILTER_SETPASS(ICMP6_PARAM_PROB, &flt);
1113
1114 int status = setsockopt(icmpsock6, IPPROTO_ICMPV6, ICMP6_FILTER,
1115 &flt, sizeof(flt));
1116 if (status < 0)
1117 {
1118 perror("ICMP6_FILTER");
1119 }
1120#endif
1121 }
1122
1123 HRESULT hrc = com::Initialize();
1124#ifdef VBOX_WITH_XPCOM
1125 if (hrc == NS_ERROR_FILE_ACCESS_DENIED)
1126 {
1127 char szHome[RTPATH_MAX] = "";
1128 com::GetVBoxUserHomeDirectory(szHome, sizeof(szHome));
1129 return RTMsgErrorExit(RTEXITCODE_FAILURE,
1130 "Failed to initialize COM because the global settings directory '%s' is not accessible!", szHome);
1131 }
1132#endif
1133 if (FAILED(hrc))
1134 return RTMsgErrorExit(RTEXITCODE_FAILURE, "Failed to initialize COM!");
1135
1136 g_pLwipNat = new VBoxNetLwipNAT(icmpsock4, icmpsock6);
1137
1138 Log2(("NAT: initialization\n"));
1139 int rc = g_pLwipNat->parseArgs(argc - 1, argv + 1);
1140 rc = (rc == 0) ? VINF_SUCCESS : VERR_GENERAL_FAILURE; /* XXX: FIXME */
1141
1142 if (RT_SUCCESS(rc))
1143 {
1144 rc = g_pLwipNat->init();
1145 }
1146
1147 if (RT_SUCCESS(rc))
1148 {
1149 g_pLwipNat->run();
1150 }
1151
1152 delete g_pLwipNat;
1153 return 0;
1154}
1155
1156
1157#ifndef VBOX_WITH_HARDENING
1158
1159int main(int argc, char **argv, char **envp)
1160{
1161 int rc = RTR3InitExe(argc, &argv, RTR3INIT_FLAGS_SUPLIB);
1162 if (RT_FAILURE(rc))
1163 return RTMsgInitFailure(rc);
1164
1165 return TrustedMain(argc, argv, envp);
1166}
1167
1168# if defined(RT_OS_WINDOWS)
1169
1170static LRESULT CALLBACK WindowProc(HWND hwnd,
1171 UINT uMsg,
1172 WPARAM wParam,
1173 LPARAM lParam
1174)
1175{
1176 if(uMsg == WM_DESTROY)
1177 {
1178 PostQuitMessage(0);
1179 return 0;
1180 }
1181 return DefWindowProc (hwnd, uMsg, wParam, lParam);
1182}
1183
1184static LPCWSTR g_WndClassName = L"VBoxNetNatLwipClass";
1185
1186static DWORD WINAPI MsgThreadProc(__in LPVOID lpParameter)
1187{
1188 HWND hwnd = 0;
1189 HINSTANCE hInstance = (HINSTANCE)GetModuleHandle (NULL);
1190 bool bExit = false;
1191
1192 /* Register the Window Class. */
1193 WNDCLASS wc;
1194 wc.style = 0;
1195 wc.lpfnWndProc = WindowProc;
1196 wc.cbClsExtra = 0;
1197 wc.cbWndExtra = sizeof(void *);
1198 wc.hInstance = hInstance;
1199 wc.hIcon = NULL;
1200 wc.hCursor = NULL;
1201 wc.hbrBackground = (HBRUSH)(COLOR_BACKGROUND + 1);
1202 wc.lpszMenuName = NULL;
1203 wc.lpszClassName = g_WndClassName;
1204
1205 ATOM atomWindowClass = RegisterClass(&wc);
1206
1207 if (atomWindowClass != 0)
1208 {
1209 /* Create the window. */
1210 hwnd = CreateWindowEx (WS_EX_TOOLWINDOW | WS_EX_TRANSPARENT | WS_EX_TOPMOST,
1211 g_WndClassName, g_WndClassName,
1212 WS_POPUPWINDOW,
1213 -200, -200, 100, 100, NULL, NULL, hInstance, NULL);
1214
1215 if (hwnd)
1216 {
1217 SetWindowPos(hwnd, HWND_TOPMOST, -200, -200, 0, 0,
1218 SWP_NOACTIVATE | SWP_HIDEWINDOW | SWP_NOCOPYBITS | SWP_NOREDRAW | SWP_NOSIZE);
1219
1220 MSG msg;
1221 while (GetMessage(&msg, NULL, 0, 0))
1222 {
1223 TranslateMessage(&msg);
1224 DispatchMessage(&msg);
1225 }
1226
1227 DestroyWindow (hwnd);
1228
1229 bExit = true;
1230 }
1231
1232 UnregisterClass (g_WndClassName, hInstance);
1233 }
1234
1235 if(bExit)
1236 {
1237 /* no need any accuracy here, in anyway the DHCP server usually gets terminated with TerminateProcess */
1238 exit(0);
1239 }
1240
1241 return 0;
1242}
1243
1244
1245
1246/** (We don't want a console usually.) */
1247int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
1248{
1249#if 0
1250 NOREF(hInstance); NOREF(hPrevInstance); NOREF(lpCmdLine); NOREF(nCmdShow);
1251
1252 HANDLE hThread = CreateThread(
1253 NULL, /*__in_opt LPSECURITY_ATTRIBUTES lpThreadAttributes, */
1254 0, /*__in SIZE_T dwStackSize, */
1255 MsgThreadProc, /*__in LPTHREAD_START_ROUTINE lpStartAddress,*/
1256 NULL, /*__in_opt LPVOID lpParameter,*/
1257 0, /*__in DWORD dwCreationFlags,*/
1258 NULL /*__out_opt LPDWORD lpThreadId*/
1259 );
1260
1261 if(hThread != NULL)
1262 CloseHandle(hThread);
1263
1264#endif
1265 return main(__argc, __argv, environ);
1266}
1267# endif /* RT_OS_WINDOWS */
1268
1269#endif /* !VBOX_WITH_HARDENING */
Note: See TracBrowser for help on using the repository browser.

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