VirtualBox

source: vbox/trunk/src/VBox/Devices/Network/DrvNAT.cpp@ 48947

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

Devices: Whitespace and svn:keyword cleanups by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 56.7 KB
Line 
1/* $Id: DrvNAT.cpp 48947 2013-10-07 21:41:00Z vboxsync $ */
2/** @file
3 * DrvNAT - NAT network transport driver.
4 */
5
6/*
7 * Copyright (C) 2006-2012 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
19/*******************************************************************************
20* Header Files *
21*******************************************************************************/
22#define LOG_GROUP LOG_GROUP_DRV_NAT
23#define __STDC_LIMIT_MACROS
24#define __STDC_CONSTANT_MACROS
25#include "slirp/libslirp.h"
26#include "slirp/ctl.h"
27
28#include <VBox/vmm/dbgf.h>
29#include <VBox/vmm/pdmdrv.h>
30#include <VBox/vmm/pdmnetifs.h>
31#include <VBox/vmm/pdmnetinline.h>
32
33#include <iprt/assert.h>
34#include <iprt/critsect.h>
35#include <iprt/cidr.h>
36#include <iprt/file.h>
37#include <iprt/mem.h>
38#include <iprt/pipe.h>
39#include <iprt/string.h>
40#include <iprt/stream.h>
41#include <iprt/uuid.h>
42
43#include "VBoxDD.h"
44
45#ifndef RT_OS_WINDOWS
46# include <unistd.h>
47# include <fcntl.h>
48# include <poll.h>
49# include <errno.h>
50#endif
51#ifdef RT_OS_FREEBSD
52# include <netinet/in.h>
53#endif
54#include <iprt/semaphore.h>
55#include <iprt/req.h>
56#ifdef RT_OS_DARWIN
57# include <SystemConfiguration/SystemConfiguration.h>
58# include <CoreFoundation/CoreFoundation.h>
59#endif
60
61#define COUNTERS_INIT
62#include "counters.h"
63
64
65/*******************************************************************************
66* Defined Constants And Macros *
67*******************************************************************************/
68
69#define DRVNAT_MAXFRAMESIZE (16 * 1024)
70
71/**
72 * @todo: This is a bad hack to prevent freezing the guest during high network
73 * activity. Windows host only. This needs to be fixed properly.
74 */
75#define VBOX_NAT_DELAY_HACK
76
77#define GET_EXTRADATA(pthis, node, name, rc, type, type_name, var) \
78do { \
79 (rc) = CFGMR3Query ## type((node), name, &(var)); \
80 if (RT_FAILURE((rc)) && (rc) != VERR_CFGM_VALUE_NOT_FOUND) \
81 return PDMDrvHlpVMSetError((pthis)->pDrvIns, (rc), RT_SRC_POS, N_("NAT#%d: configuration query for \""name"\" " #type_name " failed"), \
82 (pthis)->pDrvIns->iInstance); \
83} while (0)
84
85#define GET_ED_STRICT(pthis, node, name, rc, type, type_name, var) \
86do { \
87 (rc) = CFGMR3Query ## type((node), name, &(var)); \
88 if (RT_FAILURE((rc))) \
89 return PDMDrvHlpVMSetError((pthis)->pDrvIns, (rc), RT_SRC_POS, N_("NAT#%d: configuration query for \""name"\" " #type_name " failed"), \
90 (pthis)->pDrvIns->iInstance); \
91} while (0)
92
93#define GET_EXTRADATA_N(pthis, node, name, rc, type, type_name, var, var_size) \
94do { \
95 (rc) = CFGMR3Query ## type((node), name, &(var), var_size); \
96 if (RT_FAILURE((rc)) && (rc) != VERR_CFGM_VALUE_NOT_FOUND) \
97 return PDMDrvHlpVMSetError((pthis)->pDrvIns, (rc), RT_SRC_POS, N_("NAT#%d: configuration query for \""name"\" " #type_name " failed"), \
98 (pthis)->pDrvIns->iInstance); \
99} while (0)
100
101#define GET_BOOL(rc, pthis, node, name, var) \
102 GET_EXTRADATA(pthis, node, name, (rc), Bool, bolean, (var))
103#define GET_STRING(rc, pthis, node, name, var, var_size) \
104 GET_EXTRADATA_N(pthis, node, name, (rc), String, string, (var), (var_size))
105#define GET_STRING_ALLOC(rc, pthis, node, name, var) \
106 GET_EXTRADATA(pthis, node, name, (rc), StringAlloc, string, (var))
107#define GET_S32(rc, pthis, node, name, var) \
108 GET_EXTRADATA(pthis, node, name, (rc), S32, int, (var))
109#define GET_S32_STRICT(rc, pthis, node, name, var) \
110 GET_ED_STRICT(pthis, node, name, (rc), S32, int, (var))
111
112
113
114#define DO_GET_IP(rc, node, instance, status, x) \
115do { \
116 char sz##x[32]; \
117 GET_STRING((rc), (node), (instance), #x, sz ## x[0], sizeof(sz ## x)); \
118 if (rc != VERR_CFGM_VALUE_NOT_FOUND) \
119 (status) = inet_aton(sz ## x, &x); \
120} while (0)
121
122#define GETIP_DEF(rc, node, instance, x, def) \
123do \
124{ \
125 int status = 0; \
126 DO_GET_IP((rc), (node), (instance), status, x); \
127 if (status == 0 || rc == VERR_CFGM_VALUE_NOT_FOUND) \
128 x.s_addr = def; \
129} while (0)
130
131/*******************************************************************************
132* Structures and Typedefs *
133*******************************************************************************/
134/**
135 * NAT network transport driver instance data.
136 *
137 * @implements PDMINETWORKUP
138 */
139typedef struct DRVNAT
140{
141 /** The network interface. */
142 PDMINETWORKUP INetworkUp;
143 /** The network NAT Engine configureation. */
144 PDMINETWORKNATCONFIG INetworkNATCfg;
145 /** The port we're attached to. */
146 PPDMINETWORKDOWN pIAboveNet;
147 /** The network config of the port we're attached to. */
148 PPDMINETWORKCONFIG pIAboveConfig;
149 /** Pointer to the driver instance. */
150 PPDMDRVINS pDrvIns;
151 /** Link state */
152 PDMNETWORKLINKSTATE enmLinkState;
153 /** NAT state for this instance. */
154 PNATState pNATState;
155 /** TFTP directory prefix. */
156 char *pszTFTPPrefix;
157 /** Boot file name to provide in the DHCP server response. */
158 char *pszBootFile;
159 /** tftp server name to provide in the DHCP server response. */
160 char *pszNextServer;
161 /** Polling thread. */
162 PPDMTHREAD pSlirpThread;
163 /** Queue for NAT-thread-external events. */
164 RTREQQUEUE hSlirpReqQueue;
165 /** The guest IP for port-forwarding. */
166 uint32_t GuestIP;
167 /** Link state set when the VM is suspended. */
168 PDMNETWORKLINKSTATE enmLinkStateWant;
169
170#ifndef RT_OS_WINDOWS
171 /** The write end of the control pipe. */
172 RTPIPE hPipeWrite;
173 /** The read end of the control pipe. */
174 RTPIPE hPipeRead;
175#else
176 /** for external notification */
177 HANDLE hWakeupEvent;
178#endif
179
180#define DRV_PROFILE_COUNTER(name, dsc) STAMPROFILE Stat ## name
181#define DRV_COUNTING_COUNTER(name, dsc) STAMCOUNTER Stat ## name
182#include "counters.h"
183 /** thread delivering packets for receiving by the guest */
184 PPDMTHREAD pRecvThread;
185 /** thread delivering urg packets for receiving by the guest */
186 PPDMTHREAD pUrgRecvThread;
187 /** event to wakeup the guest receive thread */
188 RTSEMEVENT EventRecv;
189 /** event to wakeup the guest urgent receive thread */
190 RTSEMEVENT EventUrgRecv;
191 /** Receive Req queue (deliver packets to the guest) */
192 RTREQQUEUE hRecvReqQueue;
193 /** Receive Urgent Req queue (deliver packets to the guest). */
194 RTREQQUEUE hUrgRecvReqQueue;
195
196 /** makes access to device func RecvAvail and Recv atomical. */
197 RTCRITSECT DevAccessLock;
198 /** Number of in-flight urgent packets. */
199 volatile uint32_t cUrgPkts;
200 /** Number of in-flight regular packets. */
201 volatile uint32_t cPkts;
202
203 /** Transmit lock taken by BeginXmit and released by EndXmit. */
204 RTCRITSECT XmitLock;
205
206#ifdef RT_OS_DARWIN
207 /* Handle of the DNS watcher runloop source. */
208 CFRunLoopSourceRef hRunLoopSrcDnsWatcher;
209#endif
210} DRVNAT;
211AssertCompileMemberAlignment(DRVNAT, StatNATRecvWakeups, 8);
212/** Pointer to the NAT driver instance data. */
213typedef DRVNAT *PDRVNAT;
214
215
216/*******************************************************************************
217* Internal Functions *
218*******************************************************************************/
219static void drvNATNotifyNATThread(PDRVNAT pThis, const char *pszWho);
220
221
222static DECLCALLBACK(int) drvNATRecv(PPDMDRVINS pDrvIns, PPDMTHREAD pThread)
223{
224 PDRVNAT pThis = PDMINS_2_DATA(pDrvIns, PDRVNAT);
225
226 if (pThread->enmState == PDMTHREADSTATE_INITIALIZING)
227 return VINF_SUCCESS;
228
229 while (pThread->enmState == PDMTHREADSTATE_RUNNING)
230 {
231 RTReqQueueProcess(pThis->hRecvReqQueue, 0);
232 if (ASMAtomicReadU32(&pThis->cPkts) == 0)
233 RTSemEventWait(pThis->EventRecv, RT_INDEFINITE_WAIT);
234 }
235 return VINF_SUCCESS;
236}
237
238
239static DECLCALLBACK(int) drvNATRecvWakeup(PPDMDRVINS pDrvIns, PPDMTHREAD pThread)
240{
241 PDRVNAT pThis = PDMINS_2_DATA(pDrvIns, PDRVNAT);
242 int rc;
243 rc = RTSemEventSignal(pThis->EventRecv);
244
245 STAM_COUNTER_INC(&pThis->StatNATRecvWakeups);
246 return VINF_SUCCESS;
247}
248
249static DECLCALLBACK(int) drvNATUrgRecv(PPDMDRVINS pDrvIns, PPDMTHREAD pThread)
250{
251 PDRVNAT pThis = PDMINS_2_DATA(pDrvIns, PDRVNAT);
252
253 if (pThread->enmState == PDMTHREADSTATE_INITIALIZING)
254 return VINF_SUCCESS;
255
256 while (pThread->enmState == PDMTHREADSTATE_RUNNING)
257 {
258 RTReqQueueProcess(pThis->hUrgRecvReqQueue, 0);
259 if (ASMAtomicReadU32(&pThis->cUrgPkts) == 0)
260 {
261 int rc = RTSemEventWait(pThis->EventUrgRecv, RT_INDEFINITE_WAIT);
262 AssertRC(rc);
263 }
264 }
265 return VINF_SUCCESS;
266}
267
268static DECLCALLBACK(int) drvNATUrgRecvWakeup(PPDMDRVINS pDrvIns, PPDMTHREAD pThread)
269{
270 PDRVNAT pThis = PDMINS_2_DATA(pDrvIns, PDRVNAT);
271 int rc = RTSemEventSignal(pThis->EventUrgRecv);
272 AssertRC(rc);
273
274 return VINF_SUCCESS;
275}
276
277static DECLCALLBACK(void) drvNATUrgRecvWorker(PDRVNAT pThis, uint8_t *pu8Buf, int cb, struct mbuf *m)
278{
279 int rc = RTCritSectEnter(&pThis->DevAccessLock);
280 AssertRC(rc);
281 rc = pThis->pIAboveNet->pfnWaitReceiveAvail(pThis->pIAboveNet, RT_INDEFINITE_WAIT);
282 if (RT_SUCCESS(rc))
283 {
284 rc = pThis->pIAboveNet->pfnReceive(pThis->pIAboveNet, pu8Buf, cb);
285 AssertRC(rc);
286 }
287 else if ( rc != VERR_TIMEOUT
288 && rc != VERR_INTERRUPTED)
289 {
290 AssertRC(rc);
291 }
292
293 rc = RTCritSectLeave(&pThis->DevAccessLock);
294 AssertRC(rc);
295
296 slirp_ext_m_free(pThis->pNATState, m, pu8Buf);
297 if (ASMAtomicDecU32(&pThis->cUrgPkts) == 0)
298 {
299 drvNATRecvWakeup(pThis->pDrvIns, pThis->pRecvThread);
300 drvNATNotifyNATThread(pThis, "drvNATUrgRecvWorker");
301 }
302}
303
304
305static DECLCALLBACK(void) drvNATRecvWorker(PDRVNAT pThis, uint8_t *pu8Buf, int cb, struct mbuf *m)
306{
307 int rc;
308 STAM_PROFILE_START(&pThis->StatNATRecv, a);
309
310
311 while (ASMAtomicReadU32(&pThis->cUrgPkts) != 0)
312 {
313 rc = RTSemEventWait(pThis->EventRecv, RT_INDEFINITE_WAIT);
314 if ( RT_FAILURE(rc)
315 && ( rc == VERR_TIMEOUT
316 || rc == VERR_INTERRUPTED))
317 goto done_unlocked;
318 }
319
320 rc = RTCritSectEnter(&pThis->DevAccessLock);
321 AssertRC(rc);
322
323 STAM_PROFILE_START(&pThis->StatNATRecvWait, b);
324 rc = pThis->pIAboveNet->pfnWaitReceiveAvail(pThis->pIAboveNet, RT_INDEFINITE_WAIT);
325 STAM_PROFILE_STOP(&pThis->StatNATRecvWait, b);
326
327 if (RT_SUCCESS(rc))
328 {
329 rc = pThis->pIAboveNet->pfnReceive(pThis->pIAboveNet, pu8Buf, cb);
330 AssertRC(rc);
331 }
332 else if ( rc != VERR_TIMEOUT
333 && rc != VERR_INTERRUPTED)
334 {
335 AssertRC(rc);
336 }
337
338 rc = RTCritSectLeave(&pThis->DevAccessLock);
339 AssertRC(rc);
340
341done_unlocked:
342 slirp_ext_m_free(pThis->pNATState, m, pu8Buf);
343 ASMAtomicDecU32(&pThis->cPkts);
344
345 drvNATNotifyNATThread(pThis, "drvNATRecvWorker");
346
347 STAM_PROFILE_STOP(&pThis->StatNATRecv, a);
348}
349
350/**
351 * Frees a S/G buffer allocated by drvNATNetworkUp_AllocBuf.
352 *
353 * @param pThis Pointer to the NAT instance.
354 * @param pSgBuf The S/G buffer to free.
355 */
356static void drvNATFreeSgBuf(PDRVNAT pThis, PPDMSCATTERGATHER pSgBuf)
357{
358 Assert((pSgBuf->fFlags & PDMSCATTERGATHER_FLAGS_MAGIC_MASK) == PDMSCATTERGATHER_FLAGS_MAGIC);
359 pSgBuf->fFlags = 0;
360 if (pSgBuf->pvAllocator)
361 {
362 Assert(!pSgBuf->pvUser);
363 slirp_ext_m_free(pThis->pNATState, (struct mbuf *)pSgBuf->pvAllocator, NULL);
364 pSgBuf->pvAllocator = NULL;
365 }
366 else if (pSgBuf->pvUser)
367 {
368 RTMemFree(pSgBuf->aSegs[0].pvSeg);
369 pSgBuf->aSegs[0].pvSeg = NULL;
370 RTMemFree(pSgBuf->pvUser);
371 pSgBuf->pvUser = NULL;
372 }
373 RTMemFree(pSgBuf);
374}
375
376/**
377 * Worker function for drvNATSend().
378 *
379 * @param pThis Pointer to the NAT instance.
380 * @param pSgBuf The scatter/gather buffer.
381 * @thread NAT
382 */
383static void drvNATSendWorker(PDRVNAT pThis, PPDMSCATTERGATHER pSgBuf)
384{
385 Assert(pThis->enmLinkState == PDMNETWORKLINKSTATE_UP);
386 if (pThis->enmLinkState == PDMNETWORKLINKSTATE_UP)
387 {
388 struct mbuf *m = (struct mbuf *)pSgBuf->pvAllocator;
389 if (m)
390 {
391 /*
392 * A normal frame.
393 */
394 pSgBuf->pvAllocator = NULL;
395 slirp_input(pThis->pNATState, m, pSgBuf->cbUsed);
396 }
397 else
398 {
399 /*
400 * GSO frame, need to segment it.
401 */
402 /** @todo Make the NAT engine grok large frames? Could be more efficient... */
403#if 0 /* this is for testing PDMNetGsoCarveSegmentQD. */
404 uint8_t abHdrScratch[256];
405#endif
406 uint8_t const *pbFrame = (uint8_t const *)pSgBuf->aSegs[0].pvSeg;
407 PCPDMNETWORKGSO pGso = (PCPDMNETWORKGSO)pSgBuf->pvUser;
408 uint32_t const cSegs = PDMNetGsoCalcSegmentCount(pGso, pSgBuf->cbUsed); Assert(cSegs > 1);
409 for (size_t iSeg = 0; iSeg < cSegs; iSeg++)
410 {
411 size_t cbSeg;
412 void *pvSeg;
413 m = slirp_ext_m_get(pThis->pNATState, pGso->cbHdrsTotal + pGso->cbMaxSeg, &pvSeg, &cbSeg);
414 if (!m)
415 break;
416
417#if 1
418 uint32_t cbPayload, cbHdrs;
419 uint32_t offPayload = PDMNetGsoCarveSegment(pGso, pbFrame, pSgBuf->cbUsed,
420 iSeg, cSegs, (uint8_t *)pvSeg, &cbHdrs, &cbPayload);
421 memcpy((uint8_t *)pvSeg + cbHdrs, pbFrame + offPayload, cbPayload);
422
423 slirp_input(pThis->pNATState, m, cbPayload + cbHdrs);
424#else
425 uint32_t cbSegFrame;
426 void *pvSegFrame = PDMNetGsoCarveSegmentQD(pGso, (uint8_t *)pbFrame, pSgBuf->cbUsed, abHdrScratch,
427 iSeg, cSegs, &cbSegFrame);
428 memcpy((uint8_t *)pvSeg, pvSegFrame, cbSegFrame);
429
430 slirp_input(pThis->pNATState, m, cbSegFrame);
431#endif
432 }
433 }
434 }
435 drvNATFreeSgBuf(pThis, pSgBuf);
436
437 /** @todo Implement the VERR_TRY_AGAIN drvNATNetworkUp_AllocBuf semantics. */
438}
439
440/**
441 * @interface_method_impl{PDMINETWORKUP,pfnBeginXmit}
442 */
443static DECLCALLBACK(int) drvNATNetworkUp_BeginXmit(PPDMINETWORKUP pInterface, bool fOnWorkerThread)
444{
445 PDRVNAT pThis = RT_FROM_MEMBER(pInterface, DRVNAT, INetworkUp);
446 int rc = RTCritSectTryEnter(&pThis->XmitLock);
447 if (RT_FAILURE(rc))
448 {
449 /** @todo Kick the worker thread when we have one... */
450 rc = VERR_TRY_AGAIN;
451 }
452 return rc;
453}
454
455/**
456 * @interface_method_impl{PDMINETWORKUP,pfnAllocBuf}
457 */
458static DECLCALLBACK(int) drvNATNetworkUp_AllocBuf(PPDMINETWORKUP pInterface, size_t cbMin,
459 PCPDMNETWORKGSO pGso, PPPDMSCATTERGATHER ppSgBuf)
460{
461 PDRVNAT pThis = RT_FROM_MEMBER(pInterface, DRVNAT, INetworkUp);
462 Assert(RTCritSectIsOwner(&pThis->XmitLock));
463
464 /*
465 * Drop the incoming frame if the NAT thread isn't running.
466 */
467 if (pThis->pSlirpThread->enmState != PDMTHREADSTATE_RUNNING)
468 {
469 Log(("drvNATNetowrkUp_AllocBuf: returns VERR_NET_NO_NETWORK\n"));
470 return VERR_NET_NO_NETWORK;
471 }
472
473 /*
474 * Allocate a scatter/gather buffer and an mbuf.
475 */
476 PPDMSCATTERGATHER pSgBuf = (PPDMSCATTERGATHER)RTMemAlloc(sizeof(*pSgBuf));
477 if (!pSgBuf)
478 return VERR_NO_MEMORY;
479 if (!pGso)
480 {
481 /*
482 * Drop the frame if it is too big.
483 */
484 if (cbMin >= DRVNAT_MAXFRAMESIZE)
485 {
486 Log(("drvNATNetowrkUp_AllocBuf: drops over-sized frame (%u bytes), returns VERR_INVALID_PARAMETER\n",
487 cbMin));
488 return VERR_INVALID_PARAMETER;
489 }
490
491 pSgBuf->pvUser = NULL;
492 pSgBuf->pvAllocator = slirp_ext_m_get(pThis->pNATState, cbMin,
493 &pSgBuf->aSegs[0].pvSeg, &pSgBuf->aSegs[0].cbSeg);
494 if (!pSgBuf->pvAllocator)
495 {
496 RTMemFree(pSgBuf);
497 return VERR_TRY_AGAIN;
498 }
499 }
500 else
501 {
502 /*
503 * Drop the frame if its segment is too big.
504 */
505 if (pGso->cbHdrsTotal + pGso->cbMaxSeg >= DRVNAT_MAXFRAMESIZE)
506 {
507 Log(("drvNATNetowrkUp_AllocBuf: drops over-sized frame (%u bytes), returns VERR_INVALID_PARAMETER\n",
508 pGso->cbHdrsTotal + pGso->cbMaxSeg));
509 return VERR_INVALID_PARAMETER;
510 }
511
512 pSgBuf->pvUser = RTMemDup(pGso, sizeof(*pGso));
513 pSgBuf->pvAllocator = NULL;
514 pSgBuf->aSegs[0].cbSeg = RT_ALIGN_Z(cbMin, 16);
515 pSgBuf->aSegs[0].pvSeg = RTMemAlloc(pSgBuf->aSegs[0].cbSeg);
516 if (!pSgBuf->pvUser || !pSgBuf->aSegs[0].pvSeg)
517 {
518 RTMemFree(pSgBuf->aSegs[0].pvSeg);
519 RTMemFree(pSgBuf->pvUser);
520 RTMemFree(pSgBuf);
521 return VERR_TRY_AGAIN;
522 }
523 }
524
525 /*
526 * Initialize the S/G buffer and return.
527 */
528 pSgBuf->fFlags = PDMSCATTERGATHER_FLAGS_MAGIC | PDMSCATTERGATHER_FLAGS_OWNER_1;
529 pSgBuf->cbUsed = 0;
530 pSgBuf->cbAvailable = pSgBuf->aSegs[0].cbSeg;
531 pSgBuf->cSegs = 1;
532
533#if 0 /* poison */
534 memset(pSgBuf->aSegs[0].pvSeg, 'F', pSgBuf->aSegs[0].cbSeg);
535#endif
536 *ppSgBuf = pSgBuf;
537 return VINF_SUCCESS;
538}
539
540/**
541 * @interface_method_impl{PDMINETWORKUP,pfnFreeBuf}
542 */
543static DECLCALLBACK(int) drvNATNetworkUp_FreeBuf(PPDMINETWORKUP pInterface, PPDMSCATTERGATHER pSgBuf)
544{
545 PDRVNAT pThis = RT_FROM_MEMBER(pInterface, DRVNAT, INetworkUp);
546 Assert(RTCritSectIsOwner(&pThis->XmitLock));
547 drvNATFreeSgBuf(pThis, pSgBuf);
548 return VINF_SUCCESS;
549}
550
551/**
552 * @interface_method_impl{PDMINETWORKUP,pfnSendBuf}
553 */
554static DECLCALLBACK(int) drvNATNetworkUp_SendBuf(PPDMINETWORKUP pInterface, PPDMSCATTERGATHER pSgBuf, bool fOnWorkerThread)
555{
556 PDRVNAT pThis = RT_FROM_MEMBER(pInterface, DRVNAT, INetworkUp);
557 Assert((pSgBuf->fFlags & PDMSCATTERGATHER_FLAGS_OWNER_MASK) == PDMSCATTERGATHER_FLAGS_OWNER_1);
558 Assert(RTCritSectIsOwner(&pThis->XmitLock));
559
560 int rc;
561 if (pThis->pSlirpThread->enmState == PDMTHREADSTATE_RUNNING)
562 {
563 /* Set an FTM checkpoint as this operation changes the state permanently. */
564 PDMDrvHlpFTSetCheckpoint(pThis->pDrvIns, FTMCHECKPOINTTYPE_NETWORK);
565
566
567 RTREQQUEUE hQueue = pThis->hSlirpReqQueue;
568
569 rc = RTReqQueueCallEx(hQueue, NULL /*ppReq*/, 0 /*cMillies*/, RTREQFLAGS_VOID | RTREQFLAGS_NO_WAIT,
570 (PFNRT)drvNATSendWorker, 2, pThis, pSgBuf);
571 if (RT_SUCCESS(rc))
572 {
573 drvNATNotifyNATThread(pThis, "drvNATNetworkUp_SendBuf");
574 return VINF_SUCCESS;
575 }
576
577 rc = VERR_NET_NO_BUFFER_SPACE;
578 }
579 else
580 rc = VERR_NET_DOWN;
581 drvNATFreeSgBuf(pThis, pSgBuf);
582 return rc;
583}
584
585/**
586 * @interface_method_impl{PDMINETWORKUP,pfnEndXmit}
587 */
588static DECLCALLBACK(void) drvNATNetworkUp_EndXmit(PPDMINETWORKUP pInterface)
589{
590 PDRVNAT pThis = RT_FROM_MEMBER(pInterface, DRVNAT, INetworkUp);
591 RTCritSectLeave(&pThis->XmitLock);
592}
593
594/**
595 * Get the NAT thread out of poll/WSAWaitForMultipleEvents
596 */
597static void drvNATNotifyNATThread(PDRVNAT pThis, const char *pszWho)
598{
599 int rc;
600#ifndef RT_OS_WINDOWS
601 /* kick poll() */
602 size_t cbIgnored;
603 rc = RTPipeWrite(pThis->hPipeWrite, "", 1, &cbIgnored);
604#else
605 /* kick WSAWaitForMultipleEvents */
606 rc = WSASetEvent(pThis->hWakeupEvent);
607#endif
608 AssertRC(rc);
609}
610
611/**
612 * @interface_method_impl{PDMINETWORKUP,pfnSetPromiscuousMode}
613 */
614static DECLCALLBACK(void) drvNATNetworkUp_SetPromiscuousMode(PPDMINETWORKUP pInterface, bool fPromiscuous)
615{
616 LogFlow(("drvNATNetworkUp_SetPromiscuousMode: fPromiscuous=%d\n", fPromiscuous));
617 /* nothing to do */
618}
619
620/**
621 * Worker function for drvNATNetworkUp_NotifyLinkChanged().
622 * @thread "NAT" thread.
623 */
624static void drvNATNotifyLinkChangedWorker(PDRVNAT pThis, PDMNETWORKLINKSTATE enmLinkState)
625{
626 pThis->enmLinkState = pThis->enmLinkStateWant = enmLinkState;
627 switch (enmLinkState)
628 {
629 case PDMNETWORKLINKSTATE_UP:
630 LogRel(("NAT: link up\n"));
631 slirp_link_up(pThis->pNATState);
632 break;
633
634 case PDMNETWORKLINKSTATE_DOWN:
635 case PDMNETWORKLINKSTATE_DOWN_RESUME:
636 LogRel(("NAT: link down\n"));
637 slirp_link_down(pThis->pNATState);
638 break;
639
640 default:
641 AssertMsgFailed(("drvNATNetworkUp_NotifyLinkChanged: unexpected link state %d\n", enmLinkState));
642 }
643}
644
645/**
646 * Notification on link status changes.
647 *
648 * @param pInterface Pointer to the interface structure containing the called function pointer.
649 * @param enmLinkState The new link state.
650 * @thread EMT
651 */
652static DECLCALLBACK(void) drvNATNetworkUp_NotifyLinkChanged(PPDMINETWORKUP pInterface, PDMNETWORKLINKSTATE enmLinkState)
653{
654 PDRVNAT pThis = RT_FROM_MEMBER(pInterface, DRVNAT, INetworkUp);
655
656 LogFlow(("drvNATNetworkUp_NotifyLinkChanged: enmLinkState=%d\n", enmLinkState));
657
658 /* Don't queue new requests when the NAT thread is about to stop.
659 * But the VM could also be paused. So memorize the desired state. */
660 if (pThis->pSlirpThread->enmState != PDMTHREADSTATE_RUNNING)
661 {
662 pThis->enmLinkStateWant = enmLinkState;
663 return;
664 }
665
666 PRTREQ pReq;
667 int rc = RTReqQueueCallEx(pThis->hSlirpReqQueue, &pReq, 0 /*cMillies*/, RTREQFLAGS_VOID,
668 (PFNRT)drvNATNotifyLinkChangedWorker, 2, pThis, enmLinkState);
669 if (RT_LIKELY(rc == VERR_TIMEOUT))
670 {
671 drvNATNotifyNATThread(pThis, "drvNATNetworkUp_NotifyLinkChanged");
672 rc = RTReqWait(pReq, RT_INDEFINITE_WAIT);
673 AssertRC(rc);
674 }
675 else
676 AssertRC(rc);
677 RTReqRelease(pReq);
678}
679
680static void drvNATNotifyApplyPortForwardCommand(PDRVNAT pThis, bool fRemove,
681 bool fUdp, const char *pHostIp,
682 uint16_t u16HostPort, const char *pGuestIp, uint16_t u16GuestPort)
683{
684 RTMAC Mac;
685 RT_ZERO(Mac); /* can't get MAC here */
686 if (pThis->pIAboveConfig)
687 pThis->pIAboveConfig->pfnGetMac(pThis->pIAboveConfig, &Mac);
688
689 struct in_addr guestIp, hostIp;
690
691 if ( pHostIp == NULL
692 || inet_aton(pHostIp, &hostIp) == 0)
693 hostIp.s_addr = INADDR_ANY;
694
695 if ( pGuestIp == NULL
696 || inet_aton(pGuestIp, &guestIp) == 0)
697 guestIp.s_addr = pThis->GuestIP;
698
699 if (fRemove)
700 slirp_remove_redirect(pThis->pNATState, fUdp, hostIp, u16HostPort, guestIp, u16GuestPort);
701 else
702 slirp_add_redirect(pThis->pNATState, fUdp, hostIp, u16HostPort, guestIp, u16GuestPort, Mac.au8);
703}
704
705DECLCALLBACK(int) drvNATNetworkNatConfig_RedirectRuleCommand(PPDMINETWORKNATCONFIG pInterface, bool fRemove,
706 bool fUdp, const char *pHostIp,
707 uint16_t u16HostPort, const char *pGuestIp, uint16_t u16GuestPort)
708{
709 LogFlowFunc(("fRemove=%d, fUdp=%d, pHostIp=%s, u16HostPort=%u, pGuestIp=%s, u16GuestPort=%u\n",
710 RT_BOOL(fRemove), RT_BOOL(fUdp), pHostIp, u16HostPort, pGuestIp,
711 u16GuestPort));
712 PDRVNAT pThis = RT_FROM_MEMBER(pInterface, DRVNAT, INetworkNATCfg);
713 PRTREQ pReq;
714 int rc = RTReqQueueCallEx(pThis->hSlirpReqQueue, &pReq, 0 /*cMillies*/, RTREQFLAGS_VOID,
715 (PFNRT)drvNATNotifyApplyPortForwardCommand, 7, pThis, fRemove,
716 fUdp, pHostIp, u16HostPort, pGuestIp, u16GuestPort);
717 if (RT_LIKELY(rc == VERR_TIMEOUT))
718 {
719 drvNATNotifyNATThread(pThis, "drvNATNetworkNatConfig_RedirectRuleCommand");
720 rc = RTReqWait(pReq, RT_INDEFINITE_WAIT);
721 AssertRC(rc);
722 }
723 else
724 AssertRC(rc);
725
726 RTReqRelease(pReq);
727 port_forwarding_done:
728 return rc;
729}
730
731/**
732 * NAT thread handling the slirp stuff.
733 *
734 * The slirp implementation is single-threaded so we execute this enginre in a
735 * dedicated thread. We take care that this thread does not become the
736 * bottleneck: If the guest wants to send, a request is enqueued into the
737 * hSlirpReqQueue and handled asynchronously by this thread. If this thread
738 * wants to deliver packets to the guest, it enqueues a request into
739 * hRecvReqQueue which is later handled by the Recv thread.
740 */
741static DECLCALLBACK(int) drvNATAsyncIoThread(PPDMDRVINS pDrvIns, PPDMTHREAD pThread)
742{
743 PDRVNAT pThis = PDMINS_2_DATA(pDrvIns, PDRVNAT);
744 int nFDs = -1;
745#ifdef RT_OS_WINDOWS
746 HANDLE *phEvents = slirp_get_events(pThis->pNATState);
747 unsigned int cBreak = 0;
748#else /* RT_OS_WINDOWS */
749 unsigned int cPollNegRet = 0;
750#endif /* !RT_OS_WINDOWS */
751
752 LogFlow(("drvNATAsyncIoThread: pThis=%p\n", pThis));
753
754 if (pThread->enmState == PDMTHREADSTATE_INITIALIZING)
755 return VINF_SUCCESS;
756
757 if (pThis->enmLinkStateWant != pThis->enmLinkState)
758 drvNATNotifyLinkChangedWorker(pThis, pThis->enmLinkStateWant);
759
760 /*
761 * Polling loop.
762 */
763 while (pThread->enmState == PDMTHREADSTATE_RUNNING)
764 {
765 /*
766 * To prevent concurrent execution of sending/receiving threads
767 */
768#ifndef RT_OS_WINDOWS
769 nFDs = slirp_get_nsock(pThis->pNATState);
770 /* allocation for all sockets + Management pipe */
771 struct pollfd *polls = (struct pollfd *)RTMemAlloc((1 + nFDs) * sizeof(struct pollfd) + sizeof(uint32_t));
772 if (polls == NULL)
773 return VERR_NO_MEMORY;
774
775 /* don't pass the management pipe */
776 slirp_select_fill(pThis->pNATState, &nFDs, &polls[1]);
777
778 polls[0].fd = RTPipeToNative(pThis->hPipeRead);
779 /* POLLRDBAND usually doesn't used on Linux but seems used on Solaris */
780 polls[0].events = POLLRDNORM | POLLPRI | POLLRDBAND;
781 polls[0].revents = 0;
782
783 int cChangedFDs = poll(polls, nFDs + 1, slirp_get_timeout_ms(pThis->pNATState));
784 if (cChangedFDs < 0)
785 {
786 if (errno == EINTR)
787 {
788 Log2(("NAT: signal was caught while sleep on poll\n"));
789 /* No error, just process all outstanding requests but don't wait */
790 cChangedFDs = 0;
791 }
792 else if (cPollNegRet++ > 128)
793 {
794 LogRel(("NAT:Poll returns (%s) suppressed %d\n", strerror(errno), cPollNegRet));
795 cPollNegRet = 0;
796 }
797 }
798
799 if (cChangedFDs >= 0)
800 {
801 slirp_select_poll(pThis->pNATState, &polls[1], nFDs);
802 if (polls[0].revents & (POLLRDNORM|POLLPRI|POLLRDBAND))
803 {
804 /* drain the pipe
805 *
806 * Note! drvNATSend decoupled so we don't know how many times
807 * device's thread sends before we've entered multiplex,
808 * so to avoid false alarm drain pipe here to the very end
809 *
810 * @todo: Probably we should counter drvNATSend to count how
811 * deep pipe has been filed before drain.
812 *
813 */
814 /** @todo XXX: Make it reading exactly we need to drain the
815 * pipe.*/
816 char ch;
817 size_t cbRead;
818 RTPipeRead(pThis->hPipeRead, &ch, 1, &cbRead);
819 }
820 }
821 /* process _all_ outstanding requests but don't wait */
822 RTReqQueueProcess(pThis->hSlirpReqQueue, 0);
823 RTMemFree(polls);
824
825#else /* RT_OS_WINDOWS */
826 nFDs = -1;
827 slirp_select_fill(pThis->pNATState, &nFDs);
828 DWORD dwEvent = WSAWaitForMultipleEvents(nFDs, phEvents, FALSE,
829 slirp_get_timeout_ms(pThis->pNATState),
830 FALSE);
831 if ( (dwEvent < WSA_WAIT_EVENT_0 || dwEvent > WSA_WAIT_EVENT_0 + nFDs - 1)
832 && dwEvent != WSA_WAIT_TIMEOUT)
833 {
834 int error = WSAGetLastError();
835 LogRel(("NAT: WSAWaitForMultipleEvents returned %d (error %d)\n", dwEvent, error));
836 RTAssertPanic();
837 }
838
839 if (dwEvent == WSA_WAIT_TIMEOUT)
840 {
841 /* only check for slow/fast timers */
842 slirp_select_poll(pThis->pNATState, /* fTimeout=*/true, /*fIcmp=*/false);
843 continue;
844 }
845 /* poll the sockets in any case */
846 Log2(("%s: poll\n", __FUNCTION__));
847 slirp_select_poll(pThis->pNATState, /* fTimeout=*/false, /* fIcmp=*/(dwEvent == WSA_WAIT_EVENT_0));
848 /* process _all_ outstanding requests but don't wait */
849 RTReqQueueProcess(pThis->hSlirpReqQueue, 0);
850# ifdef VBOX_NAT_DELAY_HACK
851 if (cBreak++ > 128)
852 {
853 cBreak = 0;
854 RTThreadSleep(2);
855 }
856# endif
857#endif /* RT_OS_WINDOWS */
858 }
859
860 return VINF_SUCCESS;
861}
862
863
864/**
865 * Unblock the send thread so it can respond to a state change.
866 *
867 * @returns VBox status code.
868 * @param pDevIns The pcnet device instance.
869 * @param pThread The send thread.
870 */
871static DECLCALLBACK(int) drvNATAsyncIoWakeup(PPDMDRVINS pDrvIns, PPDMTHREAD pThread)
872{
873 PDRVNAT pThis = PDMINS_2_DATA(pDrvIns, PDRVNAT);
874
875 drvNATNotifyNATThread(pThis, "drvNATAsyncIoWakeup");
876 return VINF_SUCCESS;
877}
878
879/**
880 * Function called by slirp to check if it's possible to feed incoming data to the network port.
881 * @returns 1 if possible.
882 * @returns 0 if not possible.
883 */
884int slirp_can_output(void *pvUser)
885{
886 return 1;
887}
888
889void slirp_push_recv_thread(void *pvUser)
890{
891 PDRVNAT pThis = (PDRVNAT)pvUser;
892 Assert(pThis);
893 drvNATUrgRecvWakeup(pThis->pDrvIns, pThis->pUrgRecvThread);
894}
895
896void slirp_urg_output(void *pvUser, struct mbuf *m, const uint8_t *pu8Buf, int cb)
897{
898 PDRVNAT pThis = (PDRVNAT)pvUser;
899 Assert(pThis);
900
901 PRTREQ pReq = NULL;
902
903 /* don't queue new requests when the NAT thread is about to stop */
904 if (pThis->pSlirpThread->enmState != PDMTHREADSTATE_RUNNING)
905 return;
906
907 ASMAtomicIncU32(&pThis->cUrgPkts);
908 int rc = RTReqQueueCallEx(pThis->hUrgRecvReqQueue, NULL /*ppReq*/, 0 /*cMillies*/, RTREQFLAGS_VOID | RTREQFLAGS_NO_WAIT,
909 (PFNRT)drvNATUrgRecvWorker, 4, pThis, pu8Buf, cb, m);
910 AssertRC(rc);
911 drvNATUrgRecvWakeup(pThis->pDrvIns, pThis->pUrgRecvThread);
912}
913
914/**
915 * Function called by slirp to wake up device after VERR_TRY_AGAIN
916 */
917void slirp_output_pending(void *pvUser)
918{
919 PDRVNAT pThis = (PDRVNAT)pvUser;
920 Assert(pThis);
921 LogFlowFuncEnter();
922 pThis->pIAboveNet->pfnXmitPending(pThis->pIAboveNet);
923 LogFlowFuncLeave();
924}
925
926/**
927 * Function called by slirp to feed incoming data to the NIC.
928 */
929void slirp_output(void *pvUser, struct mbuf *m, const uint8_t *pu8Buf, int cb)
930{
931 PDRVNAT pThis = (PDRVNAT)pvUser;
932 Assert(pThis);
933
934 LogFlow(("slirp_output BEGIN %x %d\n", pu8Buf, cb));
935 Log2(("slirp_output: pu8Buf=%p cb=%#x (pThis=%p)\n%.*Rhxd\n", pu8Buf, cb, pThis, cb, pu8Buf));
936
937 PRTREQ pReq = NULL;
938
939 /* don't queue new requests when the NAT thread is about to stop */
940 if (pThis->pSlirpThread->enmState != PDMTHREADSTATE_RUNNING)
941 return;
942
943 ASMAtomicIncU32(&pThis->cPkts);
944 int rc = RTReqQueueCallEx(pThis->hRecvReqQueue, NULL /*ppReq*/, 0 /*cMillies*/, RTREQFLAGS_VOID | RTREQFLAGS_NO_WAIT,
945 (PFNRT)drvNATRecvWorker, 4, pThis, pu8Buf, cb, m);
946 AssertRC(rc);
947 drvNATRecvWakeup(pThis->pDrvIns, pThis->pRecvThread);
948 STAM_COUNTER_INC(&pThis->StatQueuePktSent);
949 LogFlowFuncLeave();
950}
951
952
953#ifdef RT_OS_DARWIN
954/**
955 * Callback for the SystemConfiguration framework to notify us whenever the DNS
956 * server changes.
957 *
958 * @returns nothing.
959 * @param hDynStor The DynamicStore handle.
960 * @param hChangedKey Array of changed keys we watch for.
961 * @param pvUser Opaque user data (NAT driver instance).
962 */
963static DECLCALLBACK(void) drvNatDnsChanged(SCDynamicStoreRef hDynStor, CFArrayRef hChangedKeys, void *pvUser)
964{
965 PDRVNAT pThis = (PDRVNAT)pvUser;
966
967 LogRel(("NAT: DNS servers changed, triggering reconnect\n"));
968
969 CFDictionaryRef hDnsDict = (CFDictionaryRef)SCDynamicStoreCopyValue(hDynStor, CFSTR("State:/Network/Global/DNS"));
970 if (hDnsDict)
971 {
972 CFArrayRef hArrAddresses = (CFArrayRef)CFDictionaryGetValue(hDnsDict, kSCPropNetDNSServerAddresses);
973 if (hArrAddresses)
974 pThis->pIAboveConfig->pfnSetLinkState(pThis->pIAboveConfig, PDMNETWORKLINKSTATE_DOWN_RESUME);
975
976 CFRelease(hDnsDict);
977 }
978}
979#endif
980
981/**
982 * @interface_method_impl{PDMIBASE,pfnQueryInterface}
983 */
984static DECLCALLBACK(void *) drvNATQueryInterface(PPDMIBASE pInterface, const char *pszIID)
985{
986 PPDMDRVINS pDrvIns = PDMIBASE_2_PDMDRV(pInterface);
987 PDRVNAT pThis = PDMINS_2_DATA(pDrvIns, PDRVNAT);
988
989 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, &pDrvIns->IBase);
990 PDMIBASE_RETURN_INTERFACE(pszIID, PDMINETWORKUP, &pThis->INetworkUp);
991 PDMIBASE_RETURN_INTERFACE(pszIID, PDMINETWORKNATCONFIG, &pThis->INetworkNATCfg);
992 return NULL;
993}
994
995
996/**
997 * Get the MAC address into the slirp stack.
998 *
999 * Called by drvNATLoadDone and drvNATPowerOn.
1000 */
1001static void drvNATSetMac(PDRVNAT pThis)
1002{
1003 if (pThis->pIAboveConfig)
1004 {
1005 RTMAC Mac;
1006 pThis->pIAboveConfig->pfnGetMac(pThis->pIAboveConfig, &Mac);
1007 /* Re-activate the port forwarding. If */
1008 slirp_set_ethaddr_and_activate_port_forwarding(pThis->pNATState, Mac.au8, pThis->GuestIP);
1009 }
1010}
1011
1012
1013/**
1014 * After loading we have to pass the MAC address of the ethernet device to the slirp stack.
1015 * Otherwise the guest is not reachable until it performs a DHCP request or an ARP request
1016 * (usually done during guest boot).
1017 */
1018static DECLCALLBACK(int) drvNATLoadDone(PPDMDRVINS pDrvIns, PSSMHANDLE pSSMHandle)
1019{
1020 PDRVNAT pThis = PDMINS_2_DATA(pDrvIns, PDRVNAT);
1021 drvNATSetMac(pThis);
1022 return VINF_SUCCESS;
1023}
1024
1025
1026/**
1027 * Some guests might not use DHCP to retrieve an IP but use a static IP.
1028 */
1029static DECLCALLBACK(void) drvNATPowerOn(PPDMDRVINS pDrvIns)
1030{
1031 PDRVNAT pThis = PDMINS_2_DATA(pDrvIns, PDRVNAT);
1032 drvNATSetMac(pThis);
1033}
1034
1035
1036/**
1037 * @interface_method_impl{PDMDEVREG,pfnResume}
1038 */
1039static DECLCALLBACK(void) drvNATResume(PPDMDRVINS pDrvIns)
1040{
1041 PDRVNAT pThis = PDMINS_2_DATA(pDrvIns, PDRVNAT);
1042 VMRESUMEREASON enmReason = PDMDrvHlpVMGetResumeReason(pDrvIns);
1043
1044 switch (enmReason)
1045 {
1046 case VMRESUMEREASON_HOST_RESUME:
1047 /*
1048 * Host resumed from a suspend and the network might have changed.
1049 * Disconnect the guest from the network temporarily to let it pick up the changes.
1050 */
1051#ifndef RT_OS_DARWIN
1052 pThis->pIAboveConfig->pfnSetLinkState(pThis->pIAboveConfig,
1053 PDMNETWORKLINKSTATE_DOWN_RESUME);
1054#endif
1055 return;
1056 default: /* Ignore every other resume reason. */
1057 /* do nothing */
1058 return;
1059 }
1060}
1061
1062
1063/**
1064 * Info handler.
1065 */
1066static DECLCALLBACK(void) drvNATInfo(PPDMDRVINS pDrvIns, PCDBGFINFOHLP pHlp, const char *pszArgs)
1067{
1068 PDRVNAT pThis = PDMINS_2_DATA(pDrvIns, PDRVNAT);
1069 slirp_info(pThis->pNATState, pHlp, pszArgs);
1070}
1071
1072#ifdef VBOX_WITH_DNSMAPPING_IN_HOSTRESOLVER
1073static int drvNATConstructDNSMappings(unsigned iInstance, PDRVNAT pThis, PCFGMNODE pMappingsCfg)
1074{
1075 int rc = VINF_SUCCESS;
1076 LogFlowFunc(("ENTER: iInstance:%d\n", iInstance));
1077 for (PCFGMNODE pNode = CFGMR3GetFirstChild(pMappingsCfg); pNode; pNode = CFGMR3GetNextChild(pNode))
1078 {
1079 if (!CFGMR3AreValuesValid(pNode, "HostName\0HostNamePattern\0HostIP\0"))
1080 return PDMDRV_SET_ERROR(pThis->pDrvIns, VERR_PDM_DRVINS_UNKNOWN_CFG_VALUES,
1081 N_("Unknown configuration in dns mapping"));
1082 char szHostNameOrPattern[255];
1083 bool fMatch = false; /* false used for equal matching, and true if wildcard pattern is used. */
1084 RT_ZERO(szHostNameOrPattern);
1085 GET_STRING(rc, pThis, pNode, "HostName", szHostNameOrPattern[0], sizeof(szHostNameOrPattern));
1086 if (rc == VERR_CFGM_VALUE_NOT_FOUND)
1087 {
1088 GET_STRING(rc, pThis, pNode, "HostNamePattern", szHostNameOrPattern[0], sizeof(szHostNameOrPattern));
1089 if (rc == VERR_CFGM_VALUE_NOT_FOUND)
1090 {
1091 char szNodeName[225];
1092 RT_ZERO(szNodeName);
1093 CFGMR3GetName(pNode, szNodeName, sizeof(szNodeName));
1094 LogRel(("NAT: Neither 'HostName' nor 'HostNamePattern' is specified for mapping %s\n", szNodeName));
1095 continue;
1096 }
1097 fMatch = true;
1098 }
1099 struct in_addr HostIP;
1100 GETIP_DEF(rc, pThis, pNode, HostIP, INADDR_ANY);
1101 if (rc == VERR_CFGM_VALUE_NOT_FOUND)
1102 {
1103 LogRel(("NAT: DNS mapping %s is ignored (address not pointed)\n", szHostNameOrPattern));
1104 continue;
1105 }
1106 slirp_add_host_resolver_mapping(pThis->pNATState, fMatch ? NULL : szHostNameOrPattern, fMatch ? szHostNameOrPattern : NULL, HostIP.s_addr);
1107 }
1108 LogFlowFunc(("LEAVE: %Rrc\n", rc));
1109 return rc;
1110}
1111#endif /* !VBOX_WITH_DNSMAPPING_IN_HOSTRESOLVER */
1112
1113
1114/**
1115 * Sets up the redirectors.
1116 *
1117 * @returns VBox status code.
1118 * @param pCfg The configuration handle.
1119 */
1120static int drvNATConstructRedir(unsigned iInstance, PDRVNAT pThis, PCFGMNODE pCfg, PRTNETADDRIPV4 pNetwork)
1121{
1122 RTMAC Mac;
1123 RT_ZERO(Mac); /* can't get MAC here */
1124
1125 /*
1126 * Enumerate redirections.
1127 */
1128 for (PCFGMNODE pNode = CFGMR3GetFirstChild(pCfg); pNode; pNode = CFGMR3GetNextChild(pNode))
1129 {
1130#ifdef VBOX_WITH_DNSMAPPING_IN_HOSTRESOLVER
1131 char szNodeName[32];
1132 CFGMR3GetName(pNode, szNodeName, 32);
1133 if ( !RTStrICmp(szNodeName, "HostResolverMappings")
1134 || !RTStrICmp(szNodeName, "AttachedDriver"))
1135 continue;
1136#endif
1137 /*
1138 * Validate the port forwarding config.
1139 */
1140 if (!CFGMR3AreValuesValid(pNode, "Protocol\0UDP\0HostPort\0GuestPort\0GuestIP\0BindIP\0"))
1141 return PDMDRV_SET_ERROR(pThis->pDrvIns, VERR_PDM_DRVINS_UNKNOWN_CFG_VALUES,
1142 N_("Unknown configuration in port forwarding"));
1143
1144 /* protocol type */
1145 bool fUDP;
1146 char szProtocol[32];
1147 int rc;
1148 GET_STRING(rc, pThis, pNode, "Protocol", szProtocol[0], sizeof(szProtocol));
1149 if (rc == VERR_CFGM_VALUE_NOT_FOUND)
1150 {
1151 fUDP = false;
1152 GET_BOOL(rc, pThis, pNode, "UDP", fUDP);
1153 }
1154 else if (RT_SUCCESS(rc))
1155 {
1156 if (!RTStrICmp(szProtocol, "TCP"))
1157 fUDP = false;
1158 else if (!RTStrICmp(szProtocol, "UDP"))
1159 fUDP = true;
1160 else
1161 return PDMDrvHlpVMSetError(pThis->pDrvIns, VERR_INVALID_PARAMETER, RT_SRC_POS,
1162 N_("NAT#%d: Invalid configuration value for \"Protocol\": \"%s\""),
1163 iInstance, szProtocol);
1164 }
1165 else
1166 return PDMDrvHlpVMSetError(pThis->pDrvIns, rc, RT_SRC_POS,
1167 N_("NAT#%d: configuration query for \"Protocol\" failed"),
1168 iInstance);
1169 /* host port */
1170 int32_t iHostPort;
1171 GET_S32_STRICT(rc, pThis, pNode, "HostPort", iHostPort);
1172
1173 /* guest port */
1174 int32_t iGuestPort;
1175 GET_S32_STRICT(rc, pThis, pNode, "GuestPort", iGuestPort);
1176
1177 /* guest address */
1178 struct in_addr GuestIP;
1179 GETIP_DEF(rc, pThis, pNode, GuestIP, RT_H2N_U32(pNetwork->u | CTL_GUEST));
1180
1181 /* Store the guest IP for re-establishing the port-forwarding rules. Note that GuestIP
1182 * is not documented. Without */
1183 if (pThis->GuestIP == INADDR_ANY)
1184 pThis->GuestIP = GuestIP.s_addr;
1185
1186 /*
1187 * Call slirp about it.
1188 */
1189 struct in_addr BindIP;
1190 GETIP_DEF(rc, pThis, pNode, BindIP, INADDR_ANY);
1191 if (slirp_add_redirect(pThis->pNATState, fUDP, BindIP, iHostPort, GuestIP, iGuestPort, Mac.au8) < 0)
1192 return PDMDrvHlpVMSetError(pThis->pDrvIns, VERR_NAT_REDIR_SETUP, RT_SRC_POS,
1193 N_("NAT#%d: configuration error: failed to set up "
1194 "redirection of %d to %d. Probably a conflict with "
1195 "existing services or other rules"), iInstance, iHostPort,
1196 iGuestPort);
1197 } /* for each redir rule */
1198
1199 return VINF_SUCCESS;
1200}
1201
1202
1203/**
1204 * Destruct a driver instance.
1205 *
1206 * Most VM resources are freed by the VM. This callback is provided so that any non-VM
1207 * resources can be freed correctly.
1208 *
1209 * @param pDrvIns The driver instance data.
1210 */
1211static DECLCALLBACK(void) drvNATDestruct(PPDMDRVINS pDrvIns)
1212{
1213 PDRVNAT pThis = PDMINS_2_DATA(pDrvIns, PDRVNAT);
1214 LogFlow(("drvNATDestruct:\n"));
1215 PDMDRV_CHECK_VERSIONS_RETURN_VOID(pDrvIns);
1216
1217 if (pThis->pNATState)
1218 {
1219 slirp_term(pThis->pNATState);
1220 slirp_deregister_statistics(pThis->pNATState, pDrvIns);
1221#ifdef VBOX_WITH_STATISTICS
1222# define DRV_PROFILE_COUNTER(name, dsc) DEREGISTER_COUNTER(name, pThis)
1223# define DRV_COUNTING_COUNTER(name, dsc) DEREGISTER_COUNTER(name, pThis)
1224# include "counters.h"
1225#endif
1226 pThis->pNATState = NULL;
1227 }
1228
1229 RTReqQueueDestroy(pThis->hSlirpReqQueue);
1230 pThis->hSlirpReqQueue = NIL_RTREQQUEUE;
1231
1232 RTReqQueueDestroy(pThis->hUrgRecvReqQueue);
1233 pThis->hUrgRecvReqQueue = NIL_RTREQQUEUE;
1234
1235 RTSemEventDestroy(pThis->EventRecv);
1236 pThis->EventRecv = NIL_RTSEMEVENT;
1237
1238 RTSemEventDestroy(pThis->EventUrgRecv);
1239 pThis->EventUrgRecv = NIL_RTSEMEVENT;
1240
1241 if (RTCritSectIsInitialized(&pThis->DevAccessLock))
1242 RTCritSectDelete(&pThis->DevAccessLock);
1243
1244 if (RTCritSectIsInitialized(&pThis->XmitLock))
1245 RTCritSectDelete(&pThis->XmitLock);
1246
1247#ifdef RT_OS_DARWIN
1248 /* Cleanup the DNS watcher. */
1249 CFRunLoopRef hRunLoopMain = CFRunLoopGetMain();
1250 CFRetain(hRunLoopMain);
1251 CFRunLoopRemoveSource(hRunLoopMain, pThis->hRunLoopSrcDnsWatcher, kCFRunLoopCommonModes);
1252 CFRelease(hRunLoopMain);
1253 CFRelease(pThis->hRunLoopSrcDnsWatcher);
1254 pThis->hRunLoopSrcDnsWatcher = NULL;
1255#endif
1256}
1257
1258
1259/**
1260 * Construct a NAT network transport driver instance.
1261 *
1262 * @copydoc FNPDMDRVCONSTRUCT
1263 */
1264static DECLCALLBACK(int) drvNATConstruct(PPDMDRVINS pDrvIns, PCFGMNODE pCfg, uint32_t fFlags)
1265{
1266 PDRVNAT pThis = PDMINS_2_DATA(pDrvIns, PDRVNAT);
1267 LogFlow(("drvNATConstruct:\n"));
1268 PDMDRV_CHECK_VERSIONS_RETURN(pDrvIns);
1269
1270 /*
1271 * Init the static parts.
1272 */
1273 pThis->pDrvIns = pDrvIns;
1274 pThis->pNATState = NULL;
1275 pThis->pszTFTPPrefix = NULL;
1276 pThis->pszBootFile = NULL;
1277 pThis->pszNextServer = NULL;
1278 pThis->hSlirpReqQueue = NIL_RTREQQUEUE;
1279 pThis->hUrgRecvReqQueue = NIL_RTREQQUEUE;
1280 pThis->EventRecv = NIL_RTSEMEVENT;
1281 pThis->EventUrgRecv = NIL_RTSEMEVENT;
1282#ifdef RT_OS_DARWIN
1283 pThis->hRunLoopSrcDnsWatcher = NULL;
1284#endif
1285
1286 /* IBase */
1287 pDrvIns->IBase.pfnQueryInterface = drvNATQueryInterface;
1288
1289 /* INetwork */
1290 pThis->INetworkUp.pfnBeginXmit = drvNATNetworkUp_BeginXmit;
1291 pThis->INetworkUp.pfnAllocBuf = drvNATNetworkUp_AllocBuf;
1292 pThis->INetworkUp.pfnFreeBuf = drvNATNetworkUp_FreeBuf;
1293 pThis->INetworkUp.pfnSendBuf = drvNATNetworkUp_SendBuf;
1294 pThis->INetworkUp.pfnEndXmit = drvNATNetworkUp_EndXmit;
1295 pThis->INetworkUp.pfnSetPromiscuousMode = drvNATNetworkUp_SetPromiscuousMode;
1296 pThis->INetworkUp.pfnNotifyLinkChanged = drvNATNetworkUp_NotifyLinkChanged;
1297
1298 /* NAT engine configuration */
1299 pThis->INetworkNATCfg.pfnRedirectRuleCommand = drvNATNetworkNatConfig_RedirectRuleCommand;
1300
1301 /*
1302 * Validate the config.
1303 */
1304 if (!CFGMR3AreValuesValid(pCfg,
1305 "PassDomain\0TFTPPrefix\0BootFile\0Network"
1306 "\0NextServer\0DNSProxy\0BindIP\0UseHostResolver\0"
1307 "SlirpMTU\0AliasMode\0"
1308 "SockRcv\0SockSnd\0TcpRcv\0TcpSnd\0"
1309 "ICMPCacheLimit\0"
1310 "SoMaxConnection\0"
1311#ifdef VBOX_WITH_DNSMAPPING_IN_HOSTRESOLVER
1312 "HostResolverMappings\0"
1313#endif
1314 ))
1315 return PDMDRV_SET_ERROR(pDrvIns, VERR_PDM_DRVINS_UNKNOWN_CFG_VALUES,
1316 N_("Unknown NAT configuration option, only supports PassDomain,"
1317 " TFTPPrefix, BootFile and Network"));
1318
1319 /*
1320 * Get the configuration settings.
1321 */
1322 int rc;
1323 bool fPassDomain = true;
1324 GET_BOOL(rc, pThis, pCfg, "PassDomain", fPassDomain);
1325
1326 GET_STRING_ALLOC(rc, pThis, pCfg, "TFTPPrefix", pThis->pszTFTPPrefix);
1327 GET_STRING_ALLOC(rc, pThis, pCfg, "BootFile", pThis->pszBootFile);
1328 GET_STRING_ALLOC(rc, pThis, pCfg, "NextServer", pThis->pszNextServer);
1329
1330 int fDNSProxy = 0;
1331 GET_S32(rc, pThis, pCfg, "DNSProxy", fDNSProxy);
1332 int fUseHostResolver = 0;
1333 GET_S32(rc, pThis, pCfg, "UseHostResolver", fUseHostResolver);
1334 int MTU = 1500;
1335 GET_S32(rc, pThis, pCfg, "SlirpMTU", MTU);
1336 int i32AliasMode = 0;
1337 int i32MainAliasMode = 0;
1338 GET_S32(rc, pThis, pCfg, "AliasMode", i32MainAliasMode);
1339 int iIcmpCacheLimit = 100;
1340 GET_S32(rc, pThis, pCfg, "ICMPCacheLimit", iIcmpCacheLimit);
1341
1342 i32AliasMode |= (i32MainAliasMode & 0x1 ? 0x1 : 0);
1343 i32AliasMode |= (i32MainAliasMode & 0x2 ? 0x40 : 0);
1344 i32AliasMode |= (i32MainAliasMode & 0x4 ? 0x4 : 0);
1345 int i32SoMaxConn = 10;
1346 GET_S32(rc, pThis, pCfg, "SoMaxConnection", i32SoMaxConn);
1347 /*
1348 * Query the network port interface.
1349 */
1350 pThis->pIAboveNet = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMINETWORKDOWN);
1351 if (!pThis->pIAboveNet)
1352 return PDMDRV_SET_ERROR(pDrvIns, VERR_PDM_MISSING_INTERFACE_ABOVE,
1353 N_("Configuration error: the above device/driver didn't "
1354 "export the network port interface"));
1355 pThis->pIAboveConfig = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMINETWORKCONFIG);
1356 if (!pThis->pIAboveConfig)
1357 return PDMDRV_SET_ERROR(pDrvIns, VERR_PDM_MISSING_INTERFACE_ABOVE,
1358 N_("Configuration error: the above device/driver didn't "
1359 "export the network config interface"));
1360
1361 /* Generate a network address for this network card. */
1362 char szNetwork[32]; /* xxx.xxx.xxx.xxx/yy */
1363 GET_STRING(rc, pThis, pCfg, "Network", szNetwork[0], sizeof(szNetwork));
1364 if (rc == VERR_CFGM_VALUE_NOT_FOUND)
1365 return PDMDrvHlpVMSetError(pDrvIns, rc, RT_SRC_POS, N_("NAT%d: Configuration error: "
1366 "missing network"),
1367 pDrvIns->iInstance, szNetwork);
1368
1369 RTNETADDRIPV4 Network, Netmask;
1370
1371 rc = RTCidrStrToIPv4(szNetwork, &Network, &Netmask);
1372 if (RT_FAILURE(rc))
1373 return PDMDrvHlpVMSetError(pDrvIns, rc, RT_SRC_POS, N_("NAT#%d: Configuration error: "
1374 "network '%s' describes not a valid IPv4 network"),
1375 pDrvIns->iInstance, szNetwork);
1376
1377 /*
1378 * Initialize slirp.
1379 */
1380 rc = slirp_init(&pThis->pNATState, RT_H2N_U32(Network.u), Netmask.u,
1381 fPassDomain, !!fUseHostResolver, i32AliasMode,
1382 iIcmpCacheLimit, pThis);
1383 if (RT_SUCCESS(rc))
1384 {
1385 slirp_set_dhcp_TFTP_prefix(pThis->pNATState, pThis->pszTFTPPrefix);
1386 slirp_set_dhcp_TFTP_bootfile(pThis->pNATState, pThis->pszBootFile);
1387 slirp_set_dhcp_next_server(pThis->pNATState, pThis->pszNextServer);
1388 slirp_set_dhcp_dns_proxy(pThis->pNATState, !!fDNSProxy);
1389 slirp_set_mtu(pThis->pNATState, MTU);
1390 slirp_set_somaxconn(pThis->pNATState, i32SoMaxConn);
1391 char *pszBindIP = NULL;
1392 GET_STRING_ALLOC(rc, pThis, pCfg, "BindIP", pszBindIP);
1393 rc = slirp_set_binding_address(pThis->pNATState, pszBindIP);
1394 if (rc != 0 && pszBindIP && *pszBindIP)
1395 LogRel(("NAT: value of BindIP has been ignored\n"));
1396
1397 if(pszBindIP != NULL)
1398 MMR3HeapFree(pszBindIP);
1399#define SLIRP_SET_TUNING_VALUE(name, setter) \
1400 do \
1401 { \
1402 int len = 0; \
1403 rc = CFGMR3QueryS32(pCfg, name, &len); \
1404 if (RT_SUCCESS(rc)) \
1405 setter(pThis->pNATState, len); \
1406 } while(0)
1407
1408 SLIRP_SET_TUNING_VALUE("SockRcv", slirp_set_rcvbuf);
1409 SLIRP_SET_TUNING_VALUE("SockSnd", slirp_set_sndbuf);
1410 SLIRP_SET_TUNING_VALUE("TcpRcv", slirp_set_tcp_rcvspace);
1411 SLIRP_SET_TUNING_VALUE("TcpSnd", slirp_set_tcp_sndspace);
1412
1413 slirp_register_statistics(pThis->pNATState, pDrvIns);
1414#ifdef VBOX_WITH_STATISTICS
1415# define DRV_PROFILE_COUNTER(name, dsc) REGISTER_COUNTER(name, pThis, STAMTYPE_PROFILE, STAMUNIT_TICKS_PER_CALL, dsc)
1416# define DRV_COUNTING_COUNTER(name, dsc) REGISTER_COUNTER(name, pThis, STAMTYPE_COUNTER, STAMUNIT_COUNT, dsc)
1417# include "counters.h"
1418#endif
1419
1420#ifdef VBOX_WITH_DNSMAPPING_IN_HOSTRESOLVER
1421 PCFGMNODE pMappingsCfg = CFGMR3GetChild(pCfg, "HostResolverMappings");
1422
1423 if (pMappingsCfg)
1424 {
1425 rc = drvNATConstructDNSMappings(pDrvIns->iInstance, pThis, pMappingsCfg);
1426 AssertRC(rc);
1427 }
1428#endif
1429 rc = drvNATConstructRedir(pDrvIns->iInstance, pThis, pCfg, &Network);
1430 if (RT_SUCCESS(rc))
1431 {
1432 /*
1433 * Register a load done notification to get the MAC address into the slirp
1434 * engine after we loaded a guest state.
1435 */
1436 rc = PDMDrvHlpSSMRegisterLoadDone(pDrvIns, drvNATLoadDone);
1437 AssertLogRelRCReturn(rc, rc);
1438
1439 rc = RTReqQueueCreate(&pThis->hSlirpReqQueue);
1440 AssertLogRelRCReturn(rc, rc);
1441
1442 rc = RTReqQueueCreate(&pThis->hRecvReqQueue);
1443 AssertLogRelRCReturn(rc, rc);
1444
1445 rc = RTReqQueueCreate(&pThis->hUrgRecvReqQueue);
1446 AssertLogRelRCReturn(rc, rc);
1447
1448 rc = PDMDrvHlpThreadCreate(pDrvIns, &pThis->pRecvThread, pThis, drvNATRecv,
1449 drvNATRecvWakeup, 128 * _1K, RTTHREADTYPE_IO, "NATRX");
1450 AssertRCReturn(rc, rc);
1451
1452 rc = RTSemEventCreate(&pThis->EventRecv);
1453 AssertRCReturn(rc, rc);
1454
1455 rc = PDMDrvHlpThreadCreate(pDrvIns, &pThis->pUrgRecvThread, pThis, drvNATUrgRecv,
1456 drvNATUrgRecvWakeup, 128 * _1K, RTTHREADTYPE_IO, "NATURGRX");
1457 AssertRCReturn(rc, rc);
1458
1459 rc = RTSemEventCreate(&pThis->EventRecv);
1460 AssertRCReturn(rc, rc);
1461
1462 rc = RTSemEventCreate(&pThis->EventUrgRecv);
1463 AssertRCReturn(rc, rc);
1464
1465 rc = RTCritSectInit(&pThis->DevAccessLock);
1466 AssertRCReturn(rc, rc);
1467
1468 rc = RTCritSectInit(&pThis->XmitLock);
1469 AssertRCReturn(rc, rc);
1470
1471 char szTmp[128];
1472 RTStrPrintf(szTmp, sizeof(szTmp), "nat%d", pDrvIns->iInstance);
1473 PDMDrvHlpDBGFInfoRegister(pDrvIns, szTmp, "NAT info.", drvNATInfo);
1474
1475#ifndef RT_OS_WINDOWS
1476 /*
1477 * Create the control pipe.
1478 */
1479 rc = RTPipeCreate(&pThis->hPipeRead, &pThis->hPipeWrite, 0 /*fFlags*/);
1480 AssertRCReturn(rc, rc);
1481#else
1482 pThis->hWakeupEvent = CreateEvent(NULL, FALSE, FALSE, NULL); /* auto-reset event */
1483 slirp_register_external_event(pThis->pNATState, pThis->hWakeupEvent,
1484 VBOX_WAKEUP_EVENT_INDEX);
1485#endif
1486
1487 rc = PDMDrvHlpThreadCreate(pDrvIns, &pThis->pSlirpThread, pThis, drvNATAsyncIoThread,
1488 drvNATAsyncIoWakeup, 128 * _1K, RTTHREADTYPE_IO, "NAT");
1489 AssertRCReturn(rc, rc);
1490
1491 pThis->enmLinkState = pThis->enmLinkStateWant = PDMNETWORKLINKSTATE_UP;
1492
1493#ifdef RT_OS_DARWIN
1494 /* Set up a watcher which notifies us everytime the DNS server changes. */
1495 int rc2 = VINF_SUCCESS;
1496 SCDynamicStoreContext SCDynStorCtx;
1497
1498 SCDynStorCtx.version = 0;
1499 SCDynStorCtx.info = pThis;
1500 SCDynStorCtx.retain = NULL;
1501 SCDynStorCtx.release = NULL;
1502 SCDynStorCtx.copyDescription = NULL;
1503
1504 SCDynamicStoreRef hDynStor = SCDynamicStoreCreate(NULL, CFSTR("org.virtualbox.drvnat"), drvNatDnsChanged, &SCDynStorCtx);
1505 if (hDynStor)
1506 {
1507 CFRunLoopSourceRef hRunLoopSrc = SCDynamicStoreCreateRunLoopSource(NULL, hDynStor, 0);
1508 if (hRunLoopSrc)
1509 {
1510 CFStringRef aWatchKeys[] =
1511 {
1512 CFSTR("State:/Network/Global/DNS")
1513 };
1514 CFArrayRef hArray = CFArrayCreate(NULL, (const void **)aWatchKeys, 1, &kCFTypeArrayCallBacks);
1515
1516 if (hArray)
1517 {
1518 if (SCDynamicStoreSetNotificationKeys(hDynStor, hArray, NULL))
1519 {
1520 CFRunLoopRef hRunLoopMain = CFRunLoopGetMain();
1521 CFRetain(hRunLoopMain);
1522 CFRunLoopAddSource(hRunLoopMain, hRunLoopSrc, kCFRunLoopCommonModes);
1523 CFRelease(hRunLoopMain);
1524 pThis->hRunLoopSrcDnsWatcher = hRunLoopSrc;
1525 }
1526 else
1527 rc2 = VERR_NO_MEMORY;
1528
1529 CFRelease(hArray);
1530 }
1531 else
1532 rc2 = VERR_NO_MEMORY;
1533
1534 if (RT_FAILURE(rc2)) /* Keep the runloop source referenced for destruction. */
1535 CFRelease(hRunLoopSrc);
1536 }
1537 CFRelease(hDynStor);
1538 }
1539 else
1540 rc2 = VERR_NO_MEMORY;
1541
1542 if (RT_FAILURE(rc2))
1543 LogRel(("NAT#%d: Failed to install DNS change notifier. The guest might loose DNS access when switching networks on the host\n",
1544 pDrvIns->iInstance));
1545#endif
1546
1547 /* might return VINF_NAT_DNS */
1548 return rc;
1549 }
1550
1551 /* failure path */
1552 slirp_term(pThis->pNATState);
1553 pThis->pNATState = NULL;
1554 }
1555 else
1556 {
1557 PDMDRV_SET_ERROR(pDrvIns, rc, N_("Unknown error during NAT networking setup: "));
1558 AssertMsgFailed(("Add error message for rc=%d (%Rrc)\n", rc, rc));
1559 }
1560
1561 return rc;
1562}
1563
1564
1565/**
1566 * NAT network transport driver registration record.
1567 */
1568const PDMDRVREG g_DrvNAT =
1569{
1570 /* u32Version */
1571 PDM_DRVREG_VERSION,
1572 /* szName */
1573 "NAT",
1574 /* szRCMod */
1575 "",
1576 /* szR0Mod */
1577 "",
1578 /* pszDescription */
1579 "NAT Network Transport Driver",
1580 /* fFlags */
1581 PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT,
1582 /* fClass. */
1583 PDM_DRVREG_CLASS_NETWORK,
1584 /* cMaxInstances */
1585 ~0U,
1586 /* cbInstance */
1587 sizeof(DRVNAT),
1588 /* pfnConstruct */
1589 drvNATConstruct,
1590 /* pfnDestruct */
1591 drvNATDestruct,
1592 /* pfnRelocate */
1593 NULL,
1594 /* pfnIOCtl */
1595 NULL,
1596 /* pfnPowerOn */
1597 drvNATPowerOn,
1598 /* pfnReset */
1599 NULL,
1600 /* pfnSuspend */
1601 NULL,
1602 /* pfnResume */
1603 drvNATResume,
1604 /* pfnAttach */
1605 NULL,
1606 /* pfnDetach */
1607 NULL,
1608 /* pfnPowerOff */
1609 NULL,
1610 /* pfnSoftReset */
1611 NULL,
1612 /* u32EndVersion */
1613 PDM_DRVREG_VERSION
1614};
1615
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