1 | /* $Id: DrvIntNet.cpp 93652 2022-02-08 11:26:14Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * DrvIntNet - Internal network transport driver.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2022 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_INTNET
|
---|
23 | #include <VBox/vmm/pdmdrv.h>
|
---|
24 | #include <VBox/vmm/pdmnetinline.h>
|
---|
25 | #include <VBox/vmm/pdmnetifs.h>
|
---|
26 | #include <VBox/vmm/cfgm.h>
|
---|
27 | #include <VBox/intnet.h>
|
---|
28 | #include <VBox/intnetinline.h>
|
---|
29 | #include <VBox/vmm/vmm.h>
|
---|
30 | #include <VBox/sup.h>
|
---|
31 | #include <VBox/err.h>
|
---|
32 |
|
---|
33 | #include <VBox/param.h>
|
---|
34 | #include <VBox/log.h>
|
---|
35 | #include <iprt/asm.h>
|
---|
36 | #include <iprt/assert.h>
|
---|
37 | #include <iprt/ctype.h>
|
---|
38 | #include <iprt/memcache.h>
|
---|
39 | #include <iprt/net.h>
|
---|
40 | #include <iprt/semaphore.h>
|
---|
41 | #include <iprt/string.h>
|
---|
42 | #include <iprt/time.h>
|
---|
43 | #include <iprt/thread.h>
|
---|
44 | #include <iprt/uuid.h>
|
---|
45 | #if defined(RT_OS_DARWIN) && defined(IN_RING3)
|
---|
46 | # include <iprt/system.h>
|
---|
47 | #endif
|
---|
48 |
|
---|
49 | #include "VBoxDD.h"
|
---|
50 |
|
---|
51 |
|
---|
52 | /*********************************************************************************************************************************
|
---|
53 | * Defined Constants And Macros *
|
---|
54 | *********************************************************************************************************************************/
|
---|
55 | #if 0
|
---|
56 | /** Enables the ring-0 part. */
|
---|
57 | #define VBOX_WITH_DRVINTNET_IN_R0
|
---|
58 | #endif
|
---|
59 |
|
---|
60 |
|
---|
61 | /*********************************************************************************************************************************
|
---|
62 | * Structures and Typedefs *
|
---|
63 | *********************************************************************************************************************************/
|
---|
64 | /**
|
---|
65 | * The state of the asynchronous thread.
|
---|
66 | */
|
---|
67 | typedef enum RECVSTATE
|
---|
68 | {
|
---|
69 | /** The thread is suspended. */
|
---|
70 | RECVSTATE_SUSPENDED = 1,
|
---|
71 | /** The thread is running. */
|
---|
72 | RECVSTATE_RUNNING,
|
---|
73 | /** The thread must (/has) terminate. */
|
---|
74 | RECVSTATE_TERMINATE,
|
---|
75 | /** The usual 32-bit type blowup. */
|
---|
76 | RECVSTATE_32BIT_HACK = 0x7fffffff
|
---|
77 | } RECVSTATE;
|
---|
78 |
|
---|
79 | /**
|
---|
80 | * Internal networking driver instance data.
|
---|
81 | *
|
---|
82 | * @implements PDMINETWORKUP
|
---|
83 | */
|
---|
84 | typedef struct DRVINTNET
|
---|
85 | {
|
---|
86 | /** The network interface. */
|
---|
87 | PDMINETWORKUP INetworkUpR3;
|
---|
88 | /** The network interface. */
|
---|
89 | R3PTRTYPE(PPDMINETWORKDOWN) pIAboveNet;
|
---|
90 | /** The network config interface.
|
---|
91 | * Can (in theory at least) be NULL. */
|
---|
92 | R3PTRTYPE(PPDMINETWORKCONFIG) pIAboveConfigR3;
|
---|
93 | /** Pointer to the driver instance (ring-3). */
|
---|
94 | PPDMDRVINSR3 pDrvInsR3;
|
---|
95 | /** Pointer to the communication buffer (ring-3). */
|
---|
96 | R3PTRTYPE(PINTNETBUF) pBufR3;
|
---|
97 | #ifdef VBOX_WITH_DRVINTNET_IN_R0
|
---|
98 | /** Ring-3 base interface for the ring-0 context. */
|
---|
99 | PDMIBASER0 IBaseR0;
|
---|
100 | /** Ring-3 base interface for the raw-mode context. */
|
---|
101 | PDMIBASERC IBaseRC;
|
---|
102 | RTR3PTR R3PtrAlignment;
|
---|
103 |
|
---|
104 | /** The network interface for the ring-0 context. */
|
---|
105 | PDMINETWORKUPR0 INetworkUpR0;
|
---|
106 | /** Pointer to the driver instance (ring-0). */
|
---|
107 | PPDMDRVINSR0 pDrvInsR0;
|
---|
108 | /** Pointer to the communication buffer (ring-0). */
|
---|
109 | R0PTRTYPE(PINTNETBUF) pBufR0;
|
---|
110 |
|
---|
111 | /** The network interface for the raw-mode context. */
|
---|
112 | PDMINETWORKUPRC INetworkUpRC;
|
---|
113 | /** Pointer to the driver instance. */
|
---|
114 | PPDMDRVINSRC pDrvInsRC;
|
---|
115 | RTRCPTR RCPtrAlignment;
|
---|
116 | #endif
|
---|
117 |
|
---|
118 | /** The transmit lock. */
|
---|
119 | PDMCRITSECT XmitLock;
|
---|
120 | /** Interface handle. */
|
---|
121 | INTNETIFHANDLE hIf;
|
---|
122 | /** The receive thread state. */
|
---|
123 | RECVSTATE volatile enmRecvState;
|
---|
124 | /** The receive thread. */
|
---|
125 | RTTHREAD hRecvThread;
|
---|
126 | /** The event semaphore that the receive thread waits on. */
|
---|
127 | RTSEMEVENT hRecvEvt;
|
---|
128 | /** The transmit thread. */
|
---|
129 | PPDMTHREAD pXmitThread;
|
---|
130 | /** The event semaphore that the transmit thread waits on. */
|
---|
131 | SUPSEMEVENT hXmitEvt;
|
---|
132 | /** The support driver session handle. */
|
---|
133 | PSUPDRVSESSION pSupDrvSession;
|
---|
134 | /** Scatter/gather descriptor cache. */
|
---|
135 | RTMEMCACHE hSgCache;
|
---|
136 | /** Set if the link is down.
|
---|
137 | * When the link is down all incoming packets will be dropped. */
|
---|
138 | bool volatile fLinkDown;
|
---|
139 | /** Set when the xmit thread has been signalled. (atomic) */
|
---|
140 | bool volatile fXmitSignalled;
|
---|
141 | /** Set if the transmit thread the one busy transmitting. */
|
---|
142 | bool volatile fXmitOnXmitThread;
|
---|
143 | /** The xmit thread should process the ring ASAP. */
|
---|
144 | bool fXmitProcessRing;
|
---|
145 | /** Set if data transmission should start immediately and deactivate
|
---|
146 | * as late as possible. */
|
---|
147 | bool fActivateEarlyDeactivateLate;
|
---|
148 | /** Padding. */
|
---|
149 | bool afReserved[HC_ARCH_BITS == 64 ? 3 : 3];
|
---|
150 | /** Scratch space for holding the ring-0 scatter / gather descriptor.
|
---|
151 | * The PDMSCATTERGATHER::fFlags member is used to indicate whether it is in
|
---|
152 | * use or not. Always accessed while owning the XmitLock. */
|
---|
153 | union
|
---|
154 | {
|
---|
155 | PDMSCATTERGATHER Sg;
|
---|
156 | uint8_t padding[8 * sizeof(RTUINTPTR)];
|
---|
157 | } u;
|
---|
158 | /** The network name. */
|
---|
159 | char szNetwork[INTNET_MAX_NETWORK_NAME];
|
---|
160 |
|
---|
161 | /** Number of GSO packets sent. */
|
---|
162 | STAMCOUNTER StatSentGso;
|
---|
163 | /** Number of GSO packets received. */
|
---|
164 | STAMCOUNTER StatReceivedGso;
|
---|
165 | /** Number of packets send from ring-0. */
|
---|
166 | STAMCOUNTER StatSentR0;
|
---|
167 | /** The number of times we've had to wake up the xmit thread to continue the
|
---|
168 | * ring-0 job. */
|
---|
169 | STAMCOUNTER StatXmitWakeupR0;
|
---|
170 | /** The number of times we've had to wake up the xmit thread to continue the
|
---|
171 | * ring-3 job. */
|
---|
172 | STAMCOUNTER StatXmitWakeupR3;
|
---|
173 | /** The times the xmit thread has been told to process the ring. */
|
---|
174 | STAMCOUNTER StatXmitProcessRing;
|
---|
175 | #ifdef VBOX_WITH_STATISTICS
|
---|
176 | /** Profiling packet transmit runs. */
|
---|
177 | STAMPROFILE StatTransmit;
|
---|
178 | /** Profiling packet receive runs. */
|
---|
179 | STAMPROFILEADV StatReceive;
|
---|
180 | #endif /* VBOX_WITH_STATISTICS */
|
---|
181 | #ifdef LOG_ENABLED
|
---|
182 | /** The nano ts of the last transfer. */
|
---|
183 | uint64_t u64LastTransferTS;
|
---|
184 | /** The nano ts of the last receive. */
|
---|
185 | uint64_t u64LastReceiveTS;
|
---|
186 | #endif
|
---|
187 | } DRVINTNET;
|
---|
188 | AssertCompileMemberAlignment(DRVINTNET, XmitLock, 8);
|
---|
189 | AssertCompileMemberAlignment(DRVINTNET, StatSentGso, 8);
|
---|
190 | /** Pointer to instance data of the internal networking driver. */
|
---|
191 | typedef DRVINTNET *PDRVINTNET;
|
---|
192 |
|
---|
193 | /**
|
---|
194 | * Config value to flag translation structure.
|
---|
195 | */
|
---|
196 | typedef struct DRVINTNETFLAG
|
---|
197 | {
|
---|
198 | /** The value. */
|
---|
199 | const char *pszChoice;
|
---|
200 | /** The corresponding flag. */
|
---|
201 | uint32_t fFlag;
|
---|
202 | } DRVINTNETFLAG;
|
---|
203 | /** Pointer to a const flag value translation. */
|
---|
204 | typedef DRVINTNETFLAG const *PCDRVINTNETFLAG;
|
---|
205 |
|
---|
206 |
|
---|
207 | #ifdef IN_RING3
|
---|
208 |
|
---|
209 |
|
---|
210 | /**
|
---|
211 | * Updates the MAC address on the kernel side.
|
---|
212 | *
|
---|
213 | * @returns VBox status code.
|
---|
214 | * @param pThis The driver instance.
|
---|
215 | */
|
---|
216 | static int drvR3IntNetUpdateMacAddress(PDRVINTNET pThis)
|
---|
217 | {
|
---|
218 | if (!pThis->pIAboveConfigR3)
|
---|
219 | return VINF_SUCCESS;
|
---|
220 |
|
---|
221 | INTNETIFSETMACADDRESSREQ SetMacAddressReq;
|
---|
222 | SetMacAddressReq.Hdr.u32Magic = SUPVMMR0REQHDR_MAGIC;
|
---|
223 | SetMacAddressReq.Hdr.cbReq = sizeof(SetMacAddressReq);
|
---|
224 | SetMacAddressReq.pSession = NIL_RTR0PTR;
|
---|
225 | SetMacAddressReq.hIf = pThis->hIf;
|
---|
226 | int rc = pThis->pIAboveConfigR3->pfnGetMac(pThis->pIAboveConfigR3, &SetMacAddressReq.Mac);
|
---|
227 | if (RT_SUCCESS(rc))
|
---|
228 | rc = PDMDrvHlpSUPCallVMMR0Ex(pThis->pDrvInsR3, VMMR0_DO_INTNET_IF_SET_MAC_ADDRESS,
|
---|
229 | &SetMacAddressReq, sizeof(SetMacAddressReq));
|
---|
230 |
|
---|
231 | Log(("drvR3IntNetUpdateMacAddress: %.*Rhxs rc=%Rrc\n", sizeof(SetMacAddressReq.Mac), &SetMacAddressReq.Mac, rc));
|
---|
232 | return rc;
|
---|
233 | }
|
---|
234 |
|
---|
235 |
|
---|
236 | /**
|
---|
237 | * Sets the kernel interface active or inactive.
|
---|
238 | *
|
---|
239 | * Worker for poweron, poweroff, suspend and resume.
|
---|
240 | *
|
---|
241 | * @returns VBox status code.
|
---|
242 | * @param pThis The driver instance.
|
---|
243 | * @param fActive The new state.
|
---|
244 | */
|
---|
245 | static int drvR3IntNetSetActive(PDRVINTNET pThis, bool fActive)
|
---|
246 | {
|
---|
247 | if (!pThis->pIAboveConfigR3)
|
---|
248 | return VINF_SUCCESS;
|
---|
249 |
|
---|
250 | INTNETIFSETACTIVEREQ SetActiveReq;
|
---|
251 | SetActiveReq.Hdr.u32Magic = SUPVMMR0REQHDR_MAGIC;
|
---|
252 | SetActiveReq.Hdr.cbReq = sizeof(SetActiveReq);
|
---|
253 | SetActiveReq.pSession = NIL_RTR0PTR;
|
---|
254 | SetActiveReq.hIf = pThis->hIf;
|
---|
255 | SetActiveReq.fActive = fActive;
|
---|
256 | int rc = PDMDrvHlpSUPCallVMMR0Ex(pThis->pDrvInsR3, VMMR0_DO_INTNET_IF_SET_ACTIVE,
|
---|
257 | &SetActiveReq, sizeof(SetActiveReq));
|
---|
258 |
|
---|
259 | Log(("drvR3IntNetSetActive: fActive=%d rc=%Rrc\n", fActive, rc));
|
---|
260 | AssertRC(rc);
|
---|
261 | return rc;
|
---|
262 | }
|
---|
263 |
|
---|
264 | #endif /* IN_RING3 */
|
---|
265 |
|
---|
266 | /* -=-=-=-=- PDMINETWORKUP -=-=-=-=- */
|
---|
267 |
|
---|
268 | #ifndef IN_RING3
|
---|
269 | /**
|
---|
270 | * Helper for signalling the xmit thread.
|
---|
271 | *
|
---|
272 | * @returns VERR_TRY_AGAIN (convenience).
|
---|
273 | * @param pThis The instance data..
|
---|
274 | */
|
---|
275 | DECLINLINE(int) drvR0IntNetSignalXmit(PDRVINTNET pThis)
|
---|
276 | {
|
---|
277 | /// @todo if (!ASMAtomicXchgBool(&pThis->fXmitSignalled, true)) - needs careful optimizing.
|
---|
278 | {
|
---|
279 | int rc = SUPSemEventSignal(pThis->pSupDrvSession, pThis->hXmitEvt);
|
---|
280 | AssertRC(rc);
|
---|
281 | STAM_REL_COUNTER_INC(&pThis->CTX_SUFF(StatXmitWakeup));
|
---|
282 | }
|
---|
283 | return VERR_TRY_AGAIN;
|
---|
284 | }
|
---|
285 | #endif /* !IN_RING3 */
|
---|
286 |
|
---|
287 |
|
---|
288 | /**
|
---|
289 | * Helper for processing the ring-0 consumer side of the xmit ring.
|
---|
290 | *
|
---|
291 | * The caller MUST own the xmit lock.
|
---|
292 | *
|
---|
293 | * @returns Status code from IntNetR0IfSend, except for VERR_TRY_AGAIN.
|
---|
294 | * @param pThis The instance data..
|
---|
295 | */
|
---|
296 | DECLINLINE(int) drvIntNetProcessXmit(PDRVINTNET pThis)
|
---|
297 | {
|
---|
298 | Assert(PDMDrvHlpCritSectIsOwner(pThis->CTX_SUFF(pDrvIns), &pThis->XmitLock));
|
---|
299 |
|
---|
300 | #ifdef IN_RING3
|
---|
301 | INTNETIFSENDREQ SendReq;
|
---|
302 | SendReq.Hdr.u32Magic = SUPVMMR0REQHDR_MAGIC;
|
---|
303 | SendReq.Hdr.cbReq = sizeof(SendReq);
|
---|
304 | SendReq.pSession = NIL_RTR0PTR;
|
---|
305 | SendReq.hIf = pThis->hIf;
|
---|
306 | int rc = PDMDrvHlpSUPCallVMMR0Ex(pThis->pDrvInsR3, VMMR0_DO_INTNET_IF_SEND, &SendReq, sizeof(SendReq));
|
---|
307 | #else
|
---|
308 | int rc = IntNetR0IfSend(pThis->hIf, pThis->pSupDrvSession);
|
---|
309 | if (rc == VERR_TRY_AGAIN)
|
---|
310 | {
|
---|
311 | ASMAtomicUoWriteBool(&pThis->fXmitProcessRing, true);
|
---|
312 | drvR0IntNetSignalXmit(pThis);
|
---|
313 | rc = VINF_SUCCESS;
|
---|
314 | }
|
---|
315 | #endif
|
---|
316 | return rc;
|
---|
317 | }
|
---|
318 |
|
---|
319 |
|
---|
320 |
|
---|
321 | /**
|
---|
322 | * @interface_method_impl{PDMINETWORKUP,pfnBeginXmit}
|
---|
323 | */
|
---|
324 | PDMBOTHCBDECL(int) drvIntNetUp_BeginXmit(PPDMINETWORKUP pInterface, bool fOnWorkerThread)
|
---|
325 | {
|
---|
326 | PDRVINTNET pThis = RT_FROM_MEMBER(pInterface, DRVINTNET, CTX_SUFF(INetworkUp));
|
---|
327 | #ifndef IN_RING3
|
---|
328 | Assert(!fOnWorkerThread);
|
---|
329 | #endif
|
---|
330 |
|
---|
331 | int rc = PDMDrvHlpCritSectTryEnter(pThis->CTX_SUFF(pDrvIns), &pThis->XmitLock);
|
---|
332 | if (RT_SUCCESS(rc))
|
---|
333 | {
|
---|
334 | if (fOnWorkerThread)
|
---|
335 | {
|
---|
336 | ASMAtomicUoWriteBool(&pThis->fXmitOnXmitThread, true);
|
---|
337 | ASMAtomicWriteBool(&pThis->fXmitSignalled, false);
|
---|
338 | }
|
---|
339 | }
|
---|
340 | else if (rc == VERR_SEM_BUSY)
|
---|
341 | {
|
---|
342 | /** @todo Does this actually make sense if the other dude is an EMT and so
|
---|
343 | * forth? I seriously think this is ring-0 only...
|
---|
344 | * We might end up waking up the xmit thread unnecessarily here, even when in
|
---|
345 | * ring-0... This needs some more thought and optimizations when the ring-0 bits
|
---|
346 | * are working. */
|
---|
347 | #ifdef IN_RING3
|
---|
348 | if ( !fOnWorkerThread
|
---|
349 | /*&& !ASMAtomicUoReadBool(&pThis->fXmitOnXmitThread)
|
---|
350 | && ASMAtomicCmpXchgBool(&pThis->fXmitSignalled, true, false)*/)
|
---|
351 | {
|
---|
352 | rc = SUPSemEventSignal(pThis->pSupDrvSession, pThis->hXmitEvt);
|
---|
353 | AssertRC(rc);
|
---|
354 | }
|
---|
355 | rc = VERR_TRY_AGAIN;
|
---|
356 | #else /* IN_RING0 */
|
---|
357 | rc = drvR0IntNetSignalXmit(pThis);
|
---|
358 | #endif /* IN_RING0 */
|
---|
359 | }
|
---|
360 | return rc;
|
---|
361 | }
|
---|
362 |
|
---|
363 |
|
---|
364 | /**
|
---|
365 | * @interface_method_impl{PDMINETWORKUP,pfnAllocBuf}
|
---|
366 | */
|
---|
367 | PDMBOTHCBDECL(int) drvIntNetUp_AllocBuf(PPDMINETWORKUP pInterface, size_t cbMin,
|
---|
368 | PCPDMNETWORKGSO pGso, PPPDMSCATTERGATHER ppSgBuf)
|
---|
369 | {
|
---|
370 | PDRVINTNET pThis = RT_FROM_MEMBER(pInterface, DRVINTNET, CTX_SUFF(INetworkUp));
|
---|
371 | int rc = VINF_SUCCESS;
|
---|
372 | Assert(cbMin < UINT32_MAX / 2);
|
---|
373 | Assert(PDMDrvHlpCritSectIsOwner(pThis->CTX_SUFF(pDrvIns), &pThis->XmitLock));
|
---|
374 |
|
---|
375 | /*
|
---|
376 | * Allocate a S/G descriptor.
|
---|
377 | * This shouldn't normally fail as the NICs usually won't allocate more
|
---|
378 | * than one buffer at a time and the SG gets freed on sending.
|
---|
379 | */
|
---|
380 | #ifdef IN_RING3
|
---|
381 | PPDMSCATTERGATHER pSgBuf = (PPDMSCATTERGATHER)RTMemCacheAlloc(pThis->hSgCache);
|
---|
382 | if (!pSgBuf)
|
---|
383 | return VERR_NO_MEMORY;
|
---|
384 | #else
|
---|
385 | PPDMSCATTERGATHER pSgBuf = &pThis->u.Sg;
|
---|
386 | if (RT_UNLIKELY(pSgBuf->fFlags != 0))
|
---|
387 | return drvR0IntNetSignalXmit(pThis);
|
---|
388 | #endif
|
---|
389 |
|
---|
390 | /*
|
---|
391 | * Allocate room in the ring buffer.
|
---|
392 | *
|
---|
393 | * In ring-3 we may have to process the xmit ring before there is
|
---|
394 | * sufficient buffer space since we might have stacked up a few frames to the
|
---|
395 | * trunk while in ring-0. (There is not point of doing this in ring-0.)
|
---|
396 | */
|
---|
397 | PINTNETHDR pHdr = NULL; /* gcc silliness */
|
---|
398 | if (pGso)
|
---|
399 | rc = IntNetRingAllocateGsoFrame(&pThis->CTX_SUFF(pBuf)->Send, (uint32_t)cbMin, pGso,
|
---|
400 | &pHdr, &pSgBuf->aSegs[0].pvSeg);
|
---|
401 | else
|
---|
402 | rc = IntNetRingAllocateFrame(&pThis->CTX_SUFF(pBuf)->Send, (uint32_t)cbMin,
|
---|
403 | &pHdr, &pSgBuf->aSegs[0].pvSeg);
|
---|
404 | #ifdef IN_RING3
|
---|
405 | if ( RT_FAILURE(rc)
|
---|
406 | && pThis->CTX_SUFF(pBuf)->cbSend >= cbMin * 2 + sizeof(INTNETHDR))
|
---|
407 | {
|
---|
408 | drvIntNetProcessXmit(pThis);
|
---|
409 | if (pGso)
|
---|
410 | rc = IntNetRingAllocateGsoFrame(&pThis->CTX_SUFF(pBuf)->Send, (uint32_t)cbMin, pGso,
|
---|
411 | &pHdr, &pSgBuf->aSegs[0].pvSeg);
|
---|
412 | else
|
---|
413 | rc = IntNetRingAllocateFrame(&pThis->CTX_SUFF(pBuf)->Send, (uint32_t)cbMin,
|
---|
414 | &pHdr, &pSgBuf->aSegs[0].pvSeg);
|
---|
415 | }
|
---|
416 | #endif
|
---|
417 | if (RT_SUCCESS(rc))
|
---|
418 | {
|
---|
419 | /*
|
---|
420 | * Set up the S/G descriptor and return successfully.
|
---|
421 | */
|
---|
422 | pSgBuf->fFlags = PDMSCATTERGATHER_FLAGS_MAGIC | PDMSCATTERGATHER_FLAGS_OWNER_1;
|
---|
423 | pSgBuf->cbUsed = 0;
|
---|
424 | pSgBuf->cbAvailable = cbMin;
|
---|
425 | pSgBuf->pvAllocator = pHdr;
|
---|
426 | pSgBuf->pvUser = pGso ? (PPDMNETWORKGSO)pSgBuf->aSegs[0].pvSeg - 1 : NULL;
|
---|
427 | pSgBuf->cSegs = 1;
|
---|
428 | pSgBuf->aSegs[0].cbSeg = cbMin;
|
---|
429 |
|
---|
430 | *ppSgBuf = pSgBuf;
|
---|
431 | return VINF_SUCCESS;
|
---|
432 | }
|
---|
433 |
|
---|
434 | #ifdef IN_RING3
|
---|
435 | /*
|
---|
436 | * If the above fails, then we're really out of space. There are nobody
|
---|
437 | * competing with us here because of the xmit lock.
|
---|
438 | */
|
---|
439 | rc = VERR_NO_MEMORY;
|
---|
440 | RTMemCacheFree(pThis->hSgCache, pSgBuf);
|
---|
441 |
|
---|
442 | #else /* IN_RING0 */
|
---|
443 | /*
|
---|
444 | * If the request is reasonable, kick the xmit thread and tell it to
|
---|
445 | * process the xmit ring ASAP.
|
---|
446 | */
|
---|
447 | if (pThis->CTX_SUFF(pBuf)->cbSend >= cbMin * 2 + sizeof(INTNETHDR))
|
---|
448 | {
|
---|
449 | pThis->fXmitProcessRing = true;
|
---|
450 | rc = drvR0IntNetSignalXmit(pThis);
|
---|
451 | }
|
---|
452 | else
|
---|
453 | rc = VERR_NO_MEMORY;
|
---|
454 | pSgBuf->fFlags = 0;
|
---|
455 | #endif /* IN_RING0 */
|
---|
456 | return rc;
|
---|
457 | }
|
---|
458 |
|
---|
459 |
|
---|
460 | /**
|
---|
461 | * @interface_method_impl{PDMINETWORKUP,pfnFreeBuf}
|
---|
462 | */
|
---|
463 | PDMBOTHCBDECL(int) drvIntNetUp_FreeBuf(PPDMINETWORKUP pInterface, PPDMSCATTERGATHER pSgBuf)
|
---|
464 | {
|
---|
465 | PDRVINTNET pThis = RT_FROM_MEMBER(pInterface, DRVINTNET, CTX_SUFF(INetworkUp));
|
---|
466 | PINTNETHDR pHdr = (PINTNETHDR)pSgBuf->pvAllocator;
|
---|
467 | #ifdef IN_RING0
|
---|
468 | Assert(pSgBuf == &pThis->u.Sg);
|
---|
469 | #endif
|
---|
470 | Assert(pSgBuf->fFlags == (PDMSCATTERGATHER_FLAGS_MAGIC | PDMSCATTERGATHER_FLAGS_OWNER_1));
|
---|
471 | Assert(pSgBuf->cbUsed <= pSgBuf->cbAvailable);
|
---|
472 | Assert( pHdr->u8Type == INTNETHDR_TYPE_FRAME
|
---|
473 | || pHdr->u8Type == INTNETHDR_TYPE_GSO);
|
---|
474 | Assert(PDMDrvHlpCritSectIsOwner(pThis->CTX_SUFF(pDrvIns), &pThis->XmitLock));
|
---|
475 |
|
---|
476 | /** @todo LATER: try unalloc the frame. */
|
---|
477 | pHdr->u8Type = INTNETHDR_TYPE_PADDING;
|
---|
478 | IntNetRingCommitFrame(&pThis->CTX_SUFF(pBuf)->Send, pHdr);
|
---|
479 |
|
---|
480 | #ifdef IN_RING3
|
---|
481 | RTMemCacheFree(pThis->hSgCache, pSgBuf);
|
---|
482 | #else
|
---|
483 | pSgBuf->fFlags = 0;
|
---|
484 | #endif
|
---|
485 | return VINF_SUCCESS;
|
---|
486 | }
|
---|
487 |
|
---|
488 |
|
---|
489 | /**
|
---|
490 | * @interface_method_impl{PDMINETWORKUP,pfnSendBuf}
|
---|
491 | */
|
---|
492 | PDMBOTHCBDECL(int) drvIntNetUp_SendBuf(PPDMINETWORKUP pInterface, PPDMSCATTERGATHER pSgBuf, bool fOnWorkerThread)
|
---|
493 | {
|
---|
494 | PDRVINTNET pThis = RT_FROM_MEMBER(pInterface, DRVINTNET, CTX_SUFF(INetworkUp));
|
---|
495 | STAM_PROFILE_START(&pThis->StatTransmit, a);
|
---|
496 | RT_NOREF_PV(fOnWorkerThread);
|
---|
497 |
|
---|
498 | AssertPtr(pSgBuf);
|
---|
499 | Assert(pSgBuf->fFlags == (PDMSCATTERGATHER_FLAGS_MAGIC | PDMSCATTERGATHER_FLAGS_OWNER_1));
|
---|
500 | Assert(pSgBuf->cbUsed <= pSgBuf->cbAvailable);
|
---|
501 | Assert(PDMDrvHlpCritSectIsOwner(pThis->CTX_SUFF(pDrvIns), &pThis->XmitLock));
|
---|
502 |
|
---|
503 | if (pSgBuf->pvUser)
|
---|
504 | STAM_COUNTER_INC(&pThis->StatSentGso);
|
---|
505 |
|
---|
506 | /*
|
---|
507 | * Commit the frame and push it thru the switch.
|
---|
508 | */
|
---|
509 | PINTNETHDR pHdr = (PINTNETHDR)pSgBuf->pvAllocator;
|
---|
510 | IntNetRingCommitFrameEx(&pThis->CTX_SUFF(pBuf)->Send, pHdr, pSgBuf->cbUsed);
|
---|
511 | int rc = drvIntNetProcessXmit(pThis);
|
---|
512 | STAM_PROFILE_STOP(&pThis->StatTransmit, a);
|
---|
513 |
|
---|
514 | /*
|
---|
515 | * Free the descriptor and return.
|
---|
516 | */
|
---|
517 | #ifdef IN_RING3
|
---|
518 | RTMemCacheFree(pThis->hSgCache, pSgBuf);
|
---|
519 | #else
|
---|
520 | STAM_REL_COUNTER_INC(&pThis->StatSentR0);
|
---|
521 | pSgBuf->fFlags = 0;
|
---|
522 | #endif
|
---|
523 | return rc;
|
---|
524 | }
|
---|
525 |
|
---|
526 |
|
---|
527 | /**
|
---|
528 | * @interface_method_impl{PDMINETWORKUP,pfnEndXmit}
|
---|
529 | */
|
---|
530 | PDMBOTHCBDECL(void) drvIntNetUp_EndXmit(PPDMINETWORKUP pInterface)
|
---|
531 | {
|
---|
532 | PDRVINTNET pThis = RT_FROM_MEMBER(pInterface, DRVINTNET, CTX_SUFF(INetworkUp));
|
---|
533 | ASMAtomicUoWriteBool(&pThis->fXmitOnXmitThread, false);
|
---|
534 | PDMDrvHlpCritSectLeave(pThis->CTX_SUFF(pDrvIns), &pThis->XmitLock);
|
---|
535 | }
|
---|
536 |
|
---|
537 |
|
---|
538 | /**
|
---|
539 | * @interface_method_impl{PDMINETWORKUP,pfnSetPromiscuousMode}
|
---|
540 | */
|
---|
541 | PDMBOTHCBDECL(void) drvIntNetUp_SetPromiscuousMode(PPDMINETWORKUP pInterface, bool fPromiscuous)
|
---|
542 | {
|
---|
543 | PDRVINTNET pThis = RT_FROM_MEMBER(pInterface, DRVINTNET, CTX_SUFF(INetworkUp));
|
---|
544 |
|
---|
545 | #ifdef IN_RING3
|
---|
546 | INTNETIFSETPROMISCUOUSMODEREQ Req;
|
---|
547 | Req.Hdr.u32Magic = SUPVMMR0REQHDR_MAGIC;
|
---|
548 | Req.Hdr.cbReq = sizeof(Req);
|
---|
549 | Req.pSession = NIL_RTR0PTR;
|
---|
550 | Req.hIf = pThis->hIf;
|
---|
551 | Req.fPromiscuous = fPromiscuous;
|
---|
552 | int rc = PDMDrvHlpSUPCallVMMR0Ex(pThis->pDrvInsR3, VMMR0_DO_INTNET_IF_SET_PROMISCUOUS_MODE, &Req, sizeof(Req));
|
---|
553 | #else /* IN_RING0 */
|
---|
554 | int rc = IntNetR0IfSetPromiscuousMode(pThis->hIf, pThis->pSupDrvSession, fPromiscuous);
|
---|
555 | #endif /* IN_RING0 */
|
---|
556 |
|
---|
557 | LogFlow(("drvIntNetUp_SetPromiscuousMode: fPromiscuous=%RTbool\n", fPromiscuous));
|
---|
558 | AssertRC(rc);
|
---|
559 | }
|
---|
560 |
|
---|
561 | #ifdef IN_RING3
|
---|
562 |
|
---|
563 | /**
|
---|
564 | * @interface_method_impl{PDMINETWORKUP,pfnNotifyLinkChanged}
|
---|
565 | */
|
---|
566 | static DECLCALLBACK(void) drvR3IntNetUp_NotifyLinkChanged(PPDMINETWORKUP pInterface, PDMNETWORKLINKSTATE enmLinkState)
|
---|
567 | {
|
---|
568 | PDRVINTNET pThis = RT_FROM_MEMBER(pInterface, DRVINTNET, CTX_SUFF(INetworkUp));
|
---|
569 | bool fLinkDown;
|
---|
570 | switch (enmLinkState)
|
---|
571 | {
|
---|
572 | case PDMNETWORKLINKSTATE_DOWN:
|
---|
573 | case PDMNETWORKLINKSTATE_DOWN_RESUME:
|
---|
574 | fLinkDown = true;
|
---|
575 | break;
|
---|
576 | default:
|
---|
577 | AssertMsgFailed(("enmLinkState=%d\n", enmLinkState));
|
---|
578 | RT_FALL_THRU();
|
---|
579 | case PDMNETWORKLINKSTATE_UP:
|
---|
580 | fLinkDown = false;
|
---|
581 | break;
|
---|
582 | }
|
---|
583 | LogFlow(("drvR3IntNetUp_NotifyLinkChanged: enmLinkState=%d %d->%d\n", enmLinkState, pThis->fLinkDown, fLinkDown));
|
---|
584 | ASMAtomicXchgSize(&pThis->fLinkDown, fLinkDown);
|
---|
585 | }
|
---|
586 |
|
---|
587 |
|
---|
588 | /* -=-=-=-=- Transmit Thread -=-=-=-=- */
|
---|
589 |
|
---|
590 | /**
|
---|
591 | * Async I/O thread for deferred packet transmission.
|
---|
592 | *
|
---|
593 | * @returns VBox status code. Returning failure will naturally terminate the thread.
|
---|
594 | * @param pDrvIns The internal networking driver instance.
|
---|
595 | * @param pThread The thread.
|
---|
596 | */
|
---|
597 | static DECLCALLBACK(int) drvR3IntNetXmitThread(PPDMDRVINS pDrvIns, PPDMTHREAD pThread)
|
---|
598 | {
|
---|
599 | PDRVINTNET pThis = PDMINS_2_DATA(pDrvIns, PDRVINTNET);
|
---|
600 |
|
---|
601 | while (pThread->enmState == PDMTHREADSTATE_RUNNING)
|
---|
602 | {
|
---|
603 | /*
|
---|
604 | * Transmit any pending packets.
|
---|
605 | */
|
---|
606 | /** @todo Optimize this. We shouldn't call pfnXmitPending unless asked for.
|
---|
607 | * Also there is no need to call drvIntNetProcessXmit if we also
|
---|
608 | * called pfnXmitPending and send one or more frames. */
|
---|
609 | if (ASMAtomicXchgBool(&pThis->fXmitProcessRing, false))
|
---|
610 | {
|
---|
611 | STAM_REL_COUNTER_INC(&pThis->StatXmitProcessRing);
|
---|
612 | PDMDrvHlpCritSectEnter(pDrvIns, &pThis->XmitLock, VERR_IGNORED);
|
---|
613 | drvIntNetProcessXmit(pThis);
|
---|
614 | PDMDrvHlpCritSectLeave(pDrvIns, &pThis->XmitLock);
|
---|
615 | }
|
---|
616 |
|
---|
617 | pThis->pIAboveNet->pfnXmitPending(pThis->pIAboveNet);
|
---|
618 |
|
---|
619 | if (ASMAtomicXchgBool(&pThis->fXmitProcessRing, false))
|
---|
620 | {
|
---|
621 | STAM_REL_COUNTER_INC(&pThis->StatXmitProcessRing);
|
---|
622 | PDMDrvHlpCritSectEnter(pDrvIns, &pThis->XmitLock, VERR_IGNORED);
|
---|
623 | drvIntNetProcessXmit(pThis);
|
---|
624 | PDMDrvHlpCritSectLeave(pDrvIns, &pThis->XmitLock);
|
---|
625 | }
|
---|
626 |
|
---|
627 | /*
|
---|
628 | * Block until we've got something to send or is supposed
|
---|
629 | * to leave the running state.
|
---|
630 | */
|
---|
631 | int rc = SUPSemEventWaitNoResume(pThis->pSupDrvSession, pThis->hXmitEvt, RT_INDEFINITE_WAIT);
|
---|
632 | AssertLogRelMsgReturn(RT_SUCCESS(rc) || rc == VERR_INTERRUPTED, ("%Rrc\n", rc), rc);
|
---|
633 | if (RT_UNLIKELY(pThread->enmState != PDMTHREADSTATE_RUNNING))
|
---|
634 | break;
|
---|
635 |
|
---|
636 | }
|
---|
637 |
|
---|
638 | /* The thread is being initialized, suspended or terminated. */
|
---|
639 | return VINF_SUCCESS;
|
---|
640 | }
|
---|
641 |
|
---|
642 |
|
---|
643 | /**
|
---|
644 | * @copydoc FNPDMTHREADWAKEUPDRV
|
---|
645 | */
|
---|
646 | static DECLCALLBACK(int) drvR3IntNetXmitWakeUp(PPDMDRVINS pDrvIns, PPDMTHREAD pThread)
|
---|
647 | {
|
---|
648 | RT_NOREF(pThread);
|
---|
649 | PDRVINTNET pThis = PDMINS_2_DATA(pDrvIns, PDRVINTNET);
|
---|
650 | return SUPSemEventSignal(pThis->pSupDrvSession, pThis->hXmitEvt);
|
---|
651 | }
|
---|
652 |
|
---|
653 |
|
---|
654 | /* -=-=-=-=- Receive Thread -=-=-=-=- */
|
---|
655 |
|
---|
656 | /**
|
---|
657 | * Wait for space to become available up the driver/device chain.
|
---|
658 | *
|
---|
659 | * @returns VINF_SUCCESS if space is available.
|
---|
660 | * @returns VERR_STATE_CHANGED if the state changed.
|
---|
661 | * @returns VBox status code on other errors.
|
---|
662 | * @param pThis Pointer to the instance data.
|
---|
663 | */
|
---|
664 | static int drvR3IntNetRecvWaitForSpace(PDRVINTNET pThis)
|
---|
665 | {
|
---|
666 | LogFlow(("drvR3IntNetRecvWaitForSpace:\n"));
|
---|
667 | STAM_PROFILE_ADV_STOP(&pThis->StatReceive, a);
|
---|
668 | int rc = pThis->pIAboveNet->pfnWaitReceiveAvail(pThis->pIAboveNet, RT_INDEFINITE_WAIT);
|
---|
669 | STAM_PROFILE_ADV_START(&pThis->StatReceive, a);
|
---|
670 | LogFlow(("drvR3IntNetRecvWaitForSpace: returns %Rrc\n", rc));
|
---|
671 | return rc;
|
---|
672 | }
|
---|
673 |
|
---|
674 |
|
---|
675 | /**
|
---|
676 | * Executes async I/O (RUNNING mode).
|
---|
677 | *
|
---|
678 | * @returns VERR_STATE_CHANGED if the state changed.
|
---|
679 | * @returns Appropriate VBox status code (error) on fatal error.
|
---|
680 | * @param pThis The driver instance data.
|
---|
681 | */
|
---|
682 | static int drvR3IntNetRecvRun(PDRVINTNET pThis)
|
---|
683 | {
|
---|
684 | PPDMDRVINS pDrvIns = pThis->pDrvInsR3;
|
---|
685 | LogFlow(("drvR3IntNetRecvRun: pThis=%p\n", pThis));
|
---|
686 |
|
---|
687 | /*
|
---|
688 | * The running loop - processing received data and waiting for more to arrive.
|
---|
689 | */
|
---|
690 | STAM_PROFILE_ADV_START(&pThis->StatReceive, a);
|
---|
691 | PINTNETBUF pBuf = pThis->CTX_SUFF(pBuf);
|
---|
692 | PINTNETRINGBUF pRingBuf = &pBuf->Recv;
|
---|
693 | for (;;)
|
---|
694 | {
|
---|
695 | /*
|
---|
696 | * Process the receive buffer.
|
---|
697 | */
|
---|
698 | PINTNETHDR pHdr;
|
---|
699 | while ((pHdr = IntNetRingGetNextFrameToRead(pRingBuf)) != NULL)
|
---|
700 | {
|
---|
701 | /*
|
---|
702 | * Check the state and then inspect the packet.
|
---|
703 | */
|
---|
704 | if (pThis->enmRecvState != RECVSTATE_RUNNING)
|
---|
705 | {
|
---|
706 | STAM_PROFILE_ADV_STOP(&pThis->StatReceive, a);
|
---|
707 | LogFlow(("drvR3IntNetRecvRun: returns VERR_STATE_CHANGED (state changed - #0)\n"));
|
---|
708 | return VERR_STATE_CHANGED;
|
---|
709 | }
|
---|
710 |
|
---|
711 | Log2(("pHdr=%p offRead=%#x: %.8Rhxs\n", pHdr, pRingBuf->offReadX, pHdr));
|
---|
712 | uint8_t u8Type = pHdr->u8Type;
|
---|
713 | if ( ( u8Type == INTNETHDR_TYPE_FRAME
|
---|
714 | || u8Type == INTNETHDR_TYPE_GSO)
|
---|
715 | && !pThis->fLinkDown)
|
---|
716 | {
|
---|
717 | /*
|
---|
718 | * Check if there is room for the frame and pass it up.
|
---|
719 | */
|
---|
720 | size_t cbFrame = pHdr->cbFrame;
|
---|
721 | int rc = pThis->pIAboveNet->pfnWaitReceiveAvail(pThis->pIAboveNet, 0);
|
---|
722 | if (rc == VINF_SUCCESS)
|
---|
723 | {
|
---|
724 | if (u8Type == INTNETHDR_TYPE_FRAME)
|
---|
725 | {
|
---|
726 | /*
|
---|
727 | * Normal frame.
|
---|
728 | */
|
---|
729 | #ifdef LOG_ENABLED
|
---|
730 | if (LogIsEnabled())
|
---|
731 | {
|
---|
732 | uint64_t u64Now = RTTimeProgramNanoTS();
|
---|
733 | LogFlow(("drvR3IntNetRecvRun: %-4d bytes at %llu ns deltas: r=%llu t=%llu\n",
|
---|
734 | cbFrame, u64Now, u64Now - pThis->u64LastReceiveTS, u64Now - pThis->u64LastTransferTS));
|
---|
735 | pThis->u64LastReceiveTS = u64Now;
|
---|
736 | Log2(("drvR3IntNetRecvRun: cbFrame=%#x\n"
|
---|
737 | "%.*Rhxd\n",
|
---|
738 | cbFrame, cbFrame, IntNetHdrGetFramePtr(pHdr, pBuf)));
|
---|
739 | }
|
---|
740 | #endif
|
---|
741 | rc = pThis->pIAboveNet->pfnReceive(pThis->pIAboveNet, IntNetHdrGetFramePtr(pHdr, pBuf), cbFrame);
|
---|
742 | AssertRC(rc);
|
---|
743 |
|
---|
744 | /* skip to the next frame. */
|
---|
745 | IntNetRingSkipFrame(pRingBuf);
|
---|
746 | }
|
---|
747 | else
|
---|
748 | {
|
---|
749 | /*
|
---|
750 | * Generic segment offload frame (INTNETHDR_TYPE_GSO).
|
---|
751 | */
|
---|
752 | STAM_COUNTER_INC(&pThis->StatReceivedGso);
|
---|
753 | PCPDMNETWORKGSO pGso = IntNetHdrGetGsoContext(pHdr, pBuf);
|
---|
754 | if (PDMNetGsoIsValid(pGso, cbFrame, cbFrame - sizeof(PDMNETWORKGSO)))
|
---|
755 | {
|
---|
756 | if ( !pThis->pIAboveNet->pfnReceiveGso
|
---|
757 | || RT_FAILURE(pThis->pIAboveNet->pfnReceiveGso(pThis->pIAboveNet,
|
---|
758 | (uint8_t *)(pGso + 1),
|
---|
759 | pHdr->cbFrame - sizeof(PDMNETWORKGSO),
|
---|
760 | pGso)))
|
---|
761 | {
|
---|
762 | /*
|
---|
763 | * This is where we do the offloading since this NIC
|
---|
764 | * does not support large receive offload (LRO).
|
---|
765 | */
|
---|
766 | cbFrame -= sizeof(PDMNETWORKGSO);
|
---|
767 |
|
---|
768 | uint8_t abHdrScratch[256];
|
---|
769 | uint32_t const cSegs = PDMNetGsoCalcSegmentCount(pGso, cbFrame);
|
---|
770 | #ifdef LOG_ENABLED
|
---|
771 | if (LogIsEnabled())
|
---|
772 | {
|
---|
773 | uint64_t u64Now = RTTimeProgramNanoTS();
|
---|
774 | LogFlow(("drvR3IntNetRecvRun: %-4d bytes at %llu ns deltas: r=%llu t=%llu; GSO - %u segs\n",
|
---|
775 | cbFrame, u64Now, u64Now - pThis->u64LastReceiveTS, u64Now - pThis->u64LastTransferTS, cSegs));
|
---|
776 | pThis->u64LastReceiveTS = u64Now;
|
---|
777 | Log2(("drvR3IntNetRecvRun: cbFrame=%#x type=%d cbHdrsTotal=%#x cbHdrsSeg=%#x Hdr1=%#x Hdr2=%#x MMS=%#x\n"
|
---|
778 | "%.*Rhxd\n",
|
---|
779 | cbFrame, pGso->u8Type, pGso->cbHdrsTotal, pGso->cbHdrsSeg, pGso->offHdr1, pGso->offHdr2, pGso->cbMaxSeg,
|
---|
780 | cbFrame - sizeof(*pGso), pGso + 1));
|
---|
781 | }
|
---|
782 | #endif
|
---|
783 | for (uint32_t iSeg = 0; iSeg < cSegs; iSeg++)
|
---|
784 | {
|
---|
785 | uint32_t cbSegFrame;
|
---|
786 | void *pvSegFrame = PDMNetGsoCarveSegmentQD(pGso, (uint8_t *)(pGso + 1), cbFrame,
|
---|
787 | abHdrScratch, iSeg, cSegs, &cbSegFrame);
|
---|
788 | rc = drvR3IntNetRecvWaitForSpace(pThis);
|
---|
789 | if (RT_FAILURE(rc))
|
---|
790 | {
|
---|
791 | Log(("drvR3IntNetRecvRun: drvR3IntNetRecvWaitForSpace -> %Rrc; iSeg=%u cSegs=%u\n", rc, iSeg, cSegs));
|
---|
792 | break; /* we drop the rest. */
|
---|
793 | }
|
---|
794 | rc = pThis->pIAboveNet->pfnReceive(pThis->pIAboveNet, pvSegFrame, cbSegFrame);
|
---|
795 | AssertRC(rc);
|
---|
796 | }
|
---|
797 | }
|
---|
798 | }
|
---|
799 | else
|
---|
800 | {
|
---|
801 | AssertMsgFailed(("cbFrame=%#x type=%d cbHdrsTotal=%#x cbHdrsSeg=%#x Hdr1=%#x Hdr2=%#x MMS=%#x\n",
|
---|
802 | cbFrame, pGso->u8Type, pGso->cbHdrsTotal, pGso->cbHdrsSeg, pGso->offHdr1, pGso->offHdr2, pGso->cbMaxSeg));
|
---|
803 | STAM_REL_COUNTER_INC(&pBuf->cStatBadFrames);
|
---|
804 | }
|
---|
805 |
|
---|
806 | IntNetRingSkipFrame(pRingBuf);
|
---|
807 | }
|
---|
808 | }
|
---|
809 | else
|
---|
810 | {
|
---|
811 | /*
|
---|
812 | * Wait for sufficient space to become available and then retry.
|
---|
813 | */
|
---|
814 | rc = drvR3IntNetRecvWaitForSpace(pThis);
|
---|
815 | if (RT_FAILURE(rc))
|
---|
816 | {
|
---|
817 | if (rc == VERR_INTERRUPTED)
|
---|
818 | {
|
---|
819 | /*
|
---|
820 | * NIC is going down, likely because the VM is being reset. Skip the frame.
|
---|
821 | */
|
---|
822 | AssertMsg(IntNetIsValidFrameType(pHdr->u8Type), ("Unknown frame type %RX16! offRead=%#x\n", pHdr->u8Type, pRingBuf->offReadX));
|
---|
823 | IntNetRingSkipFrame(pRingBuf);
|
---|
824 | }
|
---|
825 | else
|
---|
826 | {
|
---|
827 | STAM_PROFILE_ADV_STOP(&pThis->StatReceive, a);
|
---|
828 | LogFlow(("drvR3IntNetRecvRun: returns %Rrc (wait-for-space)\n", rc));
|
---|
829 | return rc;
|
---|
830 | }
|
---|
831 | }
|
---|
832 | }
|
---|
833 | }
|
---|
834 | else
|
---|
835 | {
|
---|
836 | /*
|
---|
837 | * Link down or unknown frame - skip to the next frame.
|
---|
838 | */
|
---|
839 | AssertMsg(IntNetIsValidFrameType(pHdr->u8Type), ("Unknown frame type %RX16! offRead=%#x\n", pHdr->u8Type, pRingBuf->offReadX));
|
---|
840 | IntNetRingSkipFrame(pRingBuf);
|
---|
841 | STAM_REL_COUNTER_INC(&pBuf->cStatBadFrames);
|
---|
842 | }
|
---|
843 | } /* while more received data */
|
---|
844 |
|
---|
845 | /*
|
---|
846 | * Wait for data, checking the state before we block.
|
---|
847 | */
|
---|
848 | if (pThis->enmRecvState != RECVSTATE_RUNNING)
|
---|
849 | {
|
---|
850 | STAM_PROFILE_ADV_STOP(&pThis->StatReceive, a);
|
---|
851 | LogFlow(("drvR3IntNetRecvRun: returns VINF_SUCCESS (state changed - #1)\n"));
|
---|
852 | return VERR_STATE_CHANGED;
|
---|
853 | }
|
---|
854 | INTNETIFWAITREQ WaitReq;
|
---|
855 | WaitReq.Hdr.u32Magic = SUPVMMR0REQHDR_MAGIC;
|
---|
856 | WaitReq.Hdr.cbReq = sizeof(WaitReq);
|
---|
857 | WaitReq.pSession = NIL_RTR0PTR;
|
---|
858 | WaitReq.hIf = pThis->hIf;
|
---|
859 | WaitReq.cMillies = 30000; /* 30s - don't wait forever, timeout now and then. */
|
---|
860 | STAM_PROFILE_ADV_STOP(&pThis->StatReceive, a);
|
---|
861 | int rc = PDMDrvHlpSUPCallVMMR0Ex(pDrvIns, VMMR0_DO_INTNET_IF_WAIT, &WaitReq, sizeof(WaitReq));
|
---|
862 | if ( RT_FAILURE(rc)
|
---|
863 | && rc != VERR_TIMEOUT
|
---|
864 | && rc != VERR_INTERRUPTED)
|
---|
865 | {
|
---|
866 | LogFlow(("drvR3IntNetRecvRun: returns %Rrc\n", rc));
|
---|
867 | return rc;
|
---|
868 | }
|
---|
869 | STAM_PROFILE_ADV_START(&pThis->StatReceive, a);
|
---|
870 | }
|
---|
871 | }
|
---|
872 |
|
---|
873 |
|
---|
874 | /**
|
---|
875 | * Asynchronous I/O thread for handling receive.
|
---|
876 | *
|
---|
877 | * @returns VINF_SUCCESS (ignored).
|
---|
878 | * @param hThreadSelf Thread handle.
|
---|
879 | * @param pvUser Pointer to a DRVINTNET structure.
|
---|
880 | */
|
---|
881 | static DECLCALLBACK(int) drvR3IntNetRecvThread(RTTHREAD hThreadSelf, void *pvUser)
|
---|
882 | {
|
---|
883 | RT_NOREF(hThreadSelf);
|
---|
884 | PDRVINTNET pThis = (PDRVINTNET)pvUser;
|
---|
885 | LogFlow(("drvR3IntNetRecvThread: pThis=%p\n", pThis));
|
---|
886 | STAM_PROFILE_ADV_START(&pThis->StatReceive, a);
|
---|
887 |
|
---|
888 | /*
|
---|
889 | * The main loop - acting on state.
|
---|
890 | */
|
---|
891 | for (;;)
|
---|
892 | {
|
---|
893 | RECVSTATE enmRecvState = pThis->enmRecvState;
|
---|
894 | switch (enmRecvState)
|
---|
895 | {
|
---|
896 | case RECVSTATE_SUSPENDED:
|
---|
897 | {
|
---|
898 | int rc = RTSemEventWait(pThis->hRecvEvt, 30000);
|
---|
899 | if ( RT_FAILURE(rc)
|
---|
900 | && rc != VERR_TIMEOUT)
|
---|
901 | {
|
---|
902 | LogFlow(("drvR3IntNetRecvThread: returns %Rrc\n", rc));
|
---|
903 | return rc;
|
---|
904 | }
|
---|
905 | break;
|
---|
906 | }
|
---|
907 |
|
---|
908 | case RECVSTATE_RUNNING:
|
---|
909 | {
|
---|
910 | int rc = drvR3IntNetRecvRun(pThis);
|
---|
911 | if ( rc != VERR_STATE_CHANGED
|
---|
912 | && RT_FAILURE(rc))
|
---|
913 | {
|
---|
914 | LogFlow(("drvR3IntNetRecvThread: returns %Rrc\n", rc));
|
---|
915 | return rc;
|
---|
916 | }
|
---|
917 | break;
|
---|
918 | }
|
---|
919 |
|
---|
920 | default:
|
---|
921 | AssertMsgFailed(("Invalid state %d\n", enmRecvState));
|
---|
922 | RT_FALL_THRU();
|
---|
923 | case RECVSTATE_TERMINATE:
|
---|
924 | LogFlow(("drvR3IntNetRecvThread: returns VINF_SUCCESS\n"));
|
---|
925 | return VINF_SUCCESS;
|
---|
926 | }
|
---|
927 | }
|
---|
928 | }
|
---|
929 |
|
---|
930 |
|
---|
931 | #ifdef VBOX_WITH_DRVINTNET_IN_R0
|
---|
932 |
|
---|
933 | /* -=-=-=-=- PDMIBASERC -=-=-=-=- */
|
---|
934 |
|
---|
935 | /**
|
---|
936 | * @interface_method_impl{PDMIBASERC,pfnQueryInterface}
|
---|
937 | */
|
---|
938 | static DECLCALLBACK(RTRCPTR) drvR3IntNetIBaseRC_QueryInterface(PPDMIBASERC pInterface, const char *pszIID)
|
---|
939 | {
|
---|
940 | PDRVINTNET pThis = RT_FROM_MEMBER(pInterface, DRVINTNET, IBaseRC);
|
---|
941 | #if 0
|
---|
942 | PDMIBASERC_RETURN_INTERFACE(pThis->pDrvInsR3, pszIID, PDMINETWORKUP, &pThis->INetworkUpRC);
|
---|
943 | #else
|
---|
944 | RT_NOREF(pThis, pszIID);
|
---|
945 | #endif
|
---|
946 | return NIL_RTRCPTR;
|
---|
947 | }
|
---|
948 |
|
---|
949 |
|
---|
950 | /* -=-=-=-=- PDMIBASER0 -=-=-=-=- */
|
---|
951 |
|
---|
952 | /**
|
---|
953 | * @interface_method_impl{PDMIBASER0,pfnQueryInterface}
|
---|
954 | */
|
---|
955 | static DECLCALLBACK(RTR0PTR) drvR3IntNetIBaseR0_QueryInterface(PPDMIBASER0 pInterface, const char *pszIID)
|
---|
956 | {
|
---|
957 | PDRVINTNET pThis = RT_FROM_MEMBER(pInterface, DRVINTNET, IBaseR0);
|
---|
958 | PDMIBASER0_RETURN_INTERFACE(pThis->pDrvInsR3, pszIID, PDMINETWORKUP, &pThis->INetworkUpR0);
|
---|
959 | return NIL_RTR0PTR;
|
---|
960 | }
|
---|
961 |
|
---|
962 | #endif /* VBOX_WITH_DRVINTNET_IN_R0 */
|
---|
963 |
|
---|
964 | /* -=-=-=-=- PDMIBASE -=-=-=-=- */
|
---|
965 |
|
---|
966 |
|
---|
967 | /**
|
---|
968 | * @interface_method_impl{PDMIBASE,pfnQueryInterface}
|
---|
969 | */
|
---|
970 | static DECLCALLBACK(void *) drvR3IntNetIBase_QueryInterface(PPDMIBASE pInterface, const char *pszIID)
|
---|
971 | {
|
---|
972 | PPDMDRVINS pDrvIns = PDMIBASE_2_PDMDRV(pInterface);
|
---|
973 | PDRVINTNET pThis = PDMINS_2_DATA(pDrvIns, PDRVINTNET);
|
---|
974 |
|
---|
975 | PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, &pDrvIns->IBase);
|
---|
976 | #ifdef VBOX_WITH_DRVINTNET_IN_R0
|
---|
977 | PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASER0, &pThis->IBaseR0);
|
---|
978 | PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASERC, &pThis->IBaseRC);
|
---|
979 | #endif
|
---|
980 | PDMIBASE_RETURN_INTERFACE(pszIID, PDMINETWORKUP, &pThis->INetworkUpR3);
|
---|
981 | return NULL;
|
---|
982 | }
|
---|
983 |
|
---|
984 |
|
---|
985 | /* -=-=-=-=- PDMDRVREG -=-=-=-=- */
|
---|
986 |
|
---|
987 | /**
|
---|
988 | * Power Off notification.
|
---|
989 | *
|
---|
990 | * @param pDrvIns The driver instance.
|
---|
991 | */
|
---|
992 | static DECLCALLBACK(void) drvR3IntNetPowerOff(PPDMDRVINS pDrvIns)
|
---|
993 | {
|
---|
994 | LogFlow(("drvR3IntNetPowerOff\n"));
|
---|
995 | PDRVINTNET pThis = PDMINS_2_DATA(pDrvIns, PDRVINTNET);
|
---|
996 | if (!pThis->fActivateEarlyDeactivateLate)
|
---|
997 | {
|
---|
998 | ASMAtomicXchgSize(&pThis->enmRecvState, RECVSTATE_SUSPENDED);
|
---|
999 | drvR3IntNetSetActive(pThis, false /* fActive */);
|
---|
1000 | }
|
---|
1001 | }
|
---|
1002 |
|
---|
1003 |
|
---|
1004 | /**
|
---|
1005 | * drvR3IntNetResume helper.
|
---|
1006 | */
|
---|
1007 | static int drvR3IntNetResumeSend(PDRVINTNET pThis, const void *pvBuf, size_t cb)
|
---|
1008 | {
|
---|
1009 | /*
|
---|
1010 | * Add the frame to the send buffer and push it onto the network.
|
---|
1011 | */
|
---|
1012 | int rc = IntNetRingWriteFrame(&pThis->pBufR3->Send, pvBuf, (uint32_t)cb);
|
---|
1013 | if ( rc == VERR_BUFFER_OVERFLOW
|
---|
1014 | && pThis->pBufR3->cbSend < cb)
|
---|
1015 | {
|
---|
1016 | INTNETIFSENDREQ SendReq;
|
---|
1017 | SendReq.Hdr.u32Magic = SUPVMMR0REQHDR_MAGIC;
|
---|
1018 | SendReq.Hdr.cbReq = sizeof(SendReq);
|
---|
1019 | SendReq.pSession = NIL_RTR0PTR;
|
---|
1020 | SendReq.hIf = pThis->hIf;
|
---|
1021 | PDMDrvHlpSUPCallVMMR0Ex(pThis->pDrvInsR3, VMMR0_DO_INTNET_IF_SEND, &SendReq, sizeof(SendReq));
|
---|
1022 |
|
---|
1023 | rc = IntNetRingWriteFrame(&pThis->pBufR3->Send, pvBuf, (uint32_t)cb);
|
---|
1024 | }
|
---|
1025 |
|
---|
1026 | if (RT_SUCCESS(rc))
|
---|
1027 | {
|
---|
1028 | INTNETIFSENDREQ SendReq;
|
---|
1029 | SendReq.Hdr.u32Magic = SUPVMMR0REQHDR_MAGIC;
|
---|
1030 | SendReq.Hdr.cbReq = sizeof(SendReq);
|
---|
1031 | SendReq.pSession = NIL_RTR0PTR;
|
---|
1032 | SendReq.hIf = pThis->hIf;
|
---|
1033 | rc = PDMDrvHlpSUPCallVMMR0Ex(pThis->pDrvInsR3, VMMR0_DO_INTNET_IF_SEND, &SendReq, sizeof(SendReq));
|
---|
1034 | }
|
---|
1035 |
|
---|
1036 | AssertRC(rc);
|
---|
1037 | return rc;
|
---|
1038 | }
|
---|
1039 |
|
---|
1040 |
|
---|
1041 | /**
|
---|
1042 | * Resume notification.
|
---|
1043 | *
|
---|
1044 | * @param pDrvIns The driver instance.
|
---|
1045 | */
|
---|
1046 | static DECLCALLBACK(void) drvR3IntNetResume(PPDMDRVINS pDrvIns)
|
---|
1047 | {
|
---|
1048 | LogFlow(("drvR3IntNetPowerResume\n"));
|
---|
1049 | PDRVINTNET pThis = PDMINS_2_DATA(pDrvIns, PDRVINTNET);
|
---|
1050 | VMRESUMEREASON enmReason = PDMDrvHlpVMGetResumeReason(pDrvIns);
|
---|
1051 |
|
---|
1052 | if (!pThis->fActivateEarlyDeactivateLate)
|
---|
1053 | {
|
---|
1054 | ASMAtomicXchgSize(&pThis->enmRecvState, RECVSTATE_RUNNING);
|
---|
1055 | RTSemEventSignal(pThis->hRecvEvt);
|
---|
1056 | drvR3IntNetUpdateMacAddress(pThis); /* (could be a state restore) */
|
---|
1057 | drvR3IntNetSetActive(pThis, true /* fActive */);
|
---|
1058 | }
|
---|
1059 |
|
---|
1060 | switch (enmReason)
|
---|
1061 | {
|
---|
1062 | case VMRESUMEREASON_HOST_RESUME:
|
---|
1063 | {
|
---|
1064 | uint32_t u32TrunkType;
|
---|
1065 | int rc = pDrvIns->pHlpR3->pfnCFGMQueryU32(pDrvIns->pCfg, "TrunkType", &u32TrunkType);
|
---|
1066 | AssertRC(rc);
|
---|
1067 |
|
---|
1068 | /*
|
---|
1069 | * Only do the disconnect for bridged networking. Host-only and
|
---|
1070 | * internal networks are not affected by a host resume.
|
---|
1071 | */
|
---|
1072 | if ( RT_SUCCESS(rc)
|
---|
1073 | && u32TrunkType == kIntNetTrunkType_NetFlt)
|
---|
1074 | {
|
---|
1075 | rc = pThis->pIAboveConfigR3->pfnSetLinkState(pThis->pIAboveConfigR3,
|
---|
1076 | PDMNETWORKLINKSTATE_DOWN_RESUME);
|
---|
1077 | AssertRC(rc);
|
---|
1078 | }
|
---|
1079 | break;
|
---|
1080 | }
|
---|
1081 | case VMRESUMEREASON_TELEPORTED:
|
---|
1082 | case VMRESUMEREASON_TELEPORT_FAILED:
|
---|
1083 | {
|
---|
1084 | if ( PDMDrvHlpVMTeleportedAndNotFullyResumedYet(pDrvIns)
|
---|
1085 | && pThis->pIAboveConfigR3)
|
---|
1086 | {
|
---|
1087 | /*
|
---|
1088 | * We've just been teleported and need to drop a hint to the switch
|
---|
1089 | * since we're likely to have changed to a different port. We just
|
---|
1090 | * push out some ethernet frame that doesn't mean anything to anyone.
|
---|
1091 | * For this purpose ethertype 0x801e was chosen since it was registered
|
---|
1092 | * to Sun (dunno what it is/was used for though).
|
---|
1093 | */
|
---|
1094 | union
|
---|
1095 | {
|
---|
1096 | RTNETETHERHDR Hdr;
|
---|
1097 | uint8_t ab[128];
|
---|
1098 | } Frame;
|
---|
1099 | RT_ZERO(Frame);
|
---|
1100 | Frame.Hdr.DstMac.au16[0] = 0xffff;
|
---|
1101 | Frame.Hdr.DstMac.au16[1] = 0xffff;
|
---|
1102 | Frame.Hdr.DstMac.au16[2] = 0xffff;
|
---|
1103 | Frame.Hdr.EtherType = RT_H2BE_U16_C(0x801e);
|
---|
1104 | int rc = pThis->pIAboveConfigR3->pfnGetMac(pThis->pIAboveConfigR3,
|
---|
1105 | &Frame.Hdr.SrcMac);
|
---|
1106 | if (RT_SUCCESS(rc))
|
---|
1107 | rc = drvR3IntNetResumeSend(pThis, &Frame, sizeof(Frame));
|
---|
1108 | if (RT_FAILURE(rc))
|
---|
1109 | LogRel(("IntNet#%u: Sending dummy frame failed: %Rrc\n",
|
---|
1110 | pDrvIns->iInstance, rc));
|
---|
1111 | }
|
---|
1112 | break;
|
---|
1113 | }
|
---|
1114 | default: /* ignore every other resume reason else */
|
---|
1115 | break;
|
---|
1116 | } /* end of switch(enmReason) */
|
---|
1117 | }
|
---|
1118 |
|
---|
1119 |
|
---|
1120 | /**
|
---|
1121 | * Suspend notification.
|
---|
1122 | *
|
---|
1123 | * @param pDrvIns The driver instance.
|
---|
1124 | */
|
---|
1125 | static DECLCALLBACK(void) drvR3IntNetSuspend(PPDMDRVINS pDrvIns)
|
---|
1126 | {
|
---|
1127 | LogFlow(("drvR3IntNetPowerSuspend\n"));
|
---|
1128 | PDRVINTNET pThis = PDMINS_2_DATA(pDrvIns, PDRVINTNET);
|
---|
1129 | if (!pThis->fActivateEarlyDeactivateLate)
|
---|
1130 | {
|
---|
1131 | ASMAtomicXchgSize(&pThis->enmRecvState, RECVSTATE_SUSPENDED);
|
---|
1132 | drvR3IntNetSetActive(pThis, false /* fActive */);
|
---|
1133 | }
|
---|
1134 | }
|
---|
1135 |
|
---|
1136 |
|
---|
1137 | /**
|
---|
1138 | * Power On notification.
|
---|
1139 | *
|
---|
1140 | * @param pDrvIns The driver instance.
|
---|
1141 | */
|
---|
1142 | static DECLCALLBACK(void) drvR3IntNetPowerOn(PPDMDRVINS pDrvIns)
|
---|
1143 | {
|
---|
1144 | LogFlow(("drvR3IntNetPowerOn\n"));
|
---|
1145 | PDRVINTNET pThis = PDMINS_2_DATA(pDrvIns, PDRVINTNET);
|
---|
1146 | if (!pThis->fActivateEarlyDeactivateLate)
|
---|
1147 | {
|
---|
1148 | ASMAtomicXchgSize(&pThis->enmRecvState, RECVSTATE_RUNNING);
|
---|
1149 | RTSemEventSignal(pThis->hRecvEvt);
|
---|
1150 | drvR3IntNetUpdateMacAddress(pThis);
|
---|
1151 | drvR3IntNetSetActive(pThis, true /* fActive */);
|
---|
1152 | }
|
---|
1153 | }
|
---|
1154 |
|
---|
1155 |
|
---|
1156 | /**
|
---|
1157 | * @interface_method_impl{PDMDRVREG,pfnRelocate}
|
---|
1158 | */
|
---|
1159 | static DECLCALLBACK(void) drvR3IntNetRelocate(PPDMDRVINS pDrvIns, RTGCINTPTR offDelta)
|
---|
1160 | {
|
---|
1161 | /* nothing to do here yet */
|
---|
1162 | RT_NOREF(pDrvIns, offDelta);
|
---|
1163 | }
|
---|
1164 |
|
---|
1165 |
|
---|
1166 | /**
|
---|
1167 | * Destruct a driver instance.
|
---|
1168 | *
|
---|
1169 | * Most VM resources are freed by the VM. This callback is provided so that any non-VM
|
---|
1170 | * resources can be freed correctly.
|
---|
1171 | *
|
---|
1172 | * @param pDrvIns The driver instance data.
|
---|
1173 | */
|
---|
1174 | static DECLCALLBACK(void) drvR3IntNetDestruct(PPDMDRVINS pDrvIns)
|
---|
1175 | {
|
---|
1176 | LogFlow(("drvR3IntNetDestruct\n"));
|
---|
1177 | PDRVINTNET pThis = PDMINS_2_DATA(pDrvIns, PDRVINTNET);
|
---|
1178 | PDMDRV_CHECK_VERSIONS_RETURN_VOID(pDrvIns);
|
---|
1179 |
|
---|
1180 | /*
|
---|
1181 | * Indicate to the receive thread that it's time to quit.
|
---|
1182 | */
|
---|
1183 | ASMAtomicXchgSize(&pThis->enmRecvState, RECVSTATE_TERMINATE);
|
---|
1184 | ASMAtomicXchgSize(&pThis->fLinkDown, true);
|
---|
1185 | RTSEMEVENT hRecvEvt = pThis->hRecvEvt;
|
---|
1186 | pThis->hRecvEvt = NIL_RTSEMEVENT;
|
---|
1187 |
|
---|
1188 | if (hRecvEvt != NIL_RTSEMEVENT)
|
---|
1189 | RTSemEventSignal(hRecvEvt);
|
---|
1190 |
|
---|
1191 | if (pThis->hIf != INTNET_HANDLE_INVALID)
|
---|
1192 | {
|
---|
1193 | INTNETIFABORTWAITREQ AbortWaitReq;
|
---|
1194 | AbortWaitReq.Hdr.u32Magic = SUPVMMR0REQHDR_MAGIC;
|
---|
1195 | AbortWaitReq.Hdr.cbReq = sizeof(AbortWaitReq);
|
---|
1196 | AbortWaitReq.pSession = NIL_RTR0PTR;
|
---|
1197 | AbortWaitReq.hIf = pThis->hIf;
|
---|
1198 | AbortWaitReq.fNoMoreWaits = true;
|
---|
1199 | int rc = PDMDrvHlpSUPCallVMMR0Ex(pDrvIns, VMMR0_DO_INTNET_IF_ABORT_WAIT, &AbortWaitReq, sizeof(AbortWaitReq));
|
---|
1200 | AssertMsg(RT_SUCCESS(rc) || rc == VERR_SEM_DESTROYED, ("%Rrc\n", rc)); RT_NOREF_PV(rc);
|
---|
1201 | }
|
---|
1202 |
|
---|
1203 | /*
|
---|
1204 | * Wait for the threads to terminate.
|
---|
1205 | */
|
---|
1206 | if (pThis->pXmitThread)
|
---|
1207 | {
|
---|
1208 | int rc = PDMDrvHlpThreadDestroy(pDrvIns, pThis->pXmitThread, NULL);
|
---|
1209 | AssertRC(rc);
|
---|
1210 | pThis->pXmitThread = NULL;
|
---|
1211 | }
|
---|
1212 |
|
---|
1213 | if (pThis->hRecvThread != NIL_RTTHREAD)
|
---|
1214 | {
|
---|
1215 | int rc = RTThreadWait(pThis->hRecvThread, 5000, NULL);
|
---|
1216 | AssertRC(rc);
|
---|
1217 | pThis->hRecvThread = NIL_RTTHREAD;
|
---|
1218 | }
|
---|
1219 |
|
---|
1220 | /*
|
---|
1221 | * Deregister statistics in case we're being detached.
|
---|
1222 | */
|
---|
1223 | if (pThis->pBufR3)
|
---|
1224 | {
|
---|
1225 | PDMDrvHlpSTAMDeregister(pDrvIns, &pThis->pBufR3->Recv.cStatFrames);
|
---|
1226 | PDMDrvHlpSTAMDeregister(pDrvIns, &pThis->pBufR3->Recv.cbStatWritten);
|
---|
1227 | PDMDrvHlpSTAMDeregister(pDrvIns, &pThis->pBufR3->Recv.cOverflows);
|
---|
1228 | PDMDrvHlpSTAMDeregister(pDrvIns, &pThis->pBufR3->Send.cStatFrames);
|
---|
1229 | PDMDrvHlpSTAMDeregister(pDrvIns, &pThis->pBufR3->Send.cbStatWritten);
|
---|
1230 | PDMDrvHlpSTAMDeregister(pDrvIns, &pThis->pBufR3->Send.cOverflows);
|
---|
1231 | PDMDrvHlpSTAMDeregister(pDrvIns, &pThis->pBufR3->cStatYieldsOk);
|
---|
1232 | PDMDrvHlpSTAMDeregister(pDrvIns, &pThis->pBufR3->cStatYieldsNok);
|
---|
1233 | PDMDrvHlpSTAMDeregister(pDrvIns, &pThis->pBufR3->cStatLost);
|
---|
1234 | PDMDrvHlpSTAMDeregister(pDrvIns, &pThis->pBufR3->cStatBadFrames);
|
---|
1235 | PDMDrvHlpSTAMDeregister(pDrvIns, &pThis->pBufR3->StatSend1);
|
---|
1236 | PDMDrvHlpSTAMDeregister(pDrvIns, &pThis->pBufR3->StatSend2);
|
---|
1237 | PDMDrvHlpSTAMDeregister(pDrvIns, &pThis->pBufR3->StatRecv1);
|
---|
1238 | PDMDrvHlpSTAMDeregister(pDrvIns, &pThis->pBufR3->StatRecv2);
|
---|
1239 | PDMDrvHlpSTAMDeregister(pDrvIns, &pThis->pBufR3->StatReserved);
|
---|
1240 | PDMDrvHlpSTAMDeregister(pDrvIns, &pThis->StatReceivedGso);
|
---|
1241 | PDMDrvHlpSTAMDeregister(pDrvIns, &pThis->StatSentGso);
|
---|
1242 | #ifdef VBOX_WITH_STATISTICS
|
---|
1243 | PDMDrvHlpSTAMDeregister(pDrvIns, &pThis->StatReceive);
|
---|
1244 | PDMDrvHlpSTAMDeregister(pDrvIns, &pThis->StatTransmit);
|
---|
1245 | #endif
|
---|
1246 | PDMDrvHlpSTAMDeregister(pDrvIns, &pThis->StatXmitWakeupR0);
|
---|
1247 | PDMDrvHlpSTAMDeregister(pDrvIns, &pThis->StatXmitWakeupR3);
|
---|
1248 | PDMDrvHlpSTAMDeregister(pDrvIns, &pThis->StatXmitProcessRing);
|
---|
1249 | }
|
---|
1250 |
|
---|
1251 | /*
|
---|
1252 | * Close the interface
|
---|
1253 | */
|
---|
1254 | if (pThis->hIf != INTNET_HANDLE_INVALID)
|
---|
1255 | {
|
---|
1256 | INTNETIFCLOSEREQ CloseReq;
|
---|
1257 | CloseReq.Hdr.u32Magic = SUPVMMR0REQHDR_MAGIC;
|
---|
1258 | CloseReq.Hdr.cbReq = sizeof(CloseReq);
|
---|
1259 | CloseReq.pSession = NIL_RTR0PTR;
|
---|
1260 | CloseReq.hIf = pThis->hIf;
|
---|
1261 | pThis->hIf = INTNET_HANDLE_INVALID;
|
---|
1262 | int rc = PDMDrvHlpSUPCallVMMR0Ex(pDrvIns, VMMR0_DO_INTNET_IF_CLOSE, &CloseReq, sizeof(CloseReq));
|
---|
1263 | AssertRC(rc);
|
---|
1264 | }
|
---|
1265 |
|
---|
1266 |
|
---|
1267 | /*
|
---|
1268 | * Destroy the semaphores, S/G cache and xmit lock.
|
---|
1269 | */
|
---|
1270 | if (hRecvEvt != NIL_RTSEMEVENT)
|
---|
1271 | RTSemEventDestroy(hRecvEvt);
|
---|
1272 |
|
---|
1273 | if (pThis->hXmitEvt != NIL_SUPSEMEVENT)
|
---|
1274 | {
|
---|
1275 | SUPSemEventClose(pThis->pSupDrvSession, pThis->hXmitEvt);
|
---|
1276 | pThis->hXmitEvt = NIL_SUPSEMEVENT;
|
---|
1277 | }
|
---|
1278 |
|
---|
1279 | RTMemCacheDestroy(pThis->hSgCache);
|
---|
1280 | pThis->hSgCache = NIL_RTMEMCACHE;
|
---|
1281 |
|
---|
1282 | if (PDMDrvHlpCritSectIsInitialized(pDrvIns, &pThis->XmitLock))
|
---|
1283 | PDMDrvHlpCritSectDelete(pDrvIns, &pThis->XmitLock);
|
---|
1284 | }
|
---|
1285 |
|
---|
1286 |
|
---|
1287 | /**
|
---|
1288 | * Queries a policy config value and translates it into open network flag.
|
---|
1289 | *
|
---|
1290 | * @returns VBox status code (error set on failure).
|
---|
1291 | * @param pDrvIns The driver instance.
|
---|
1292 | * @param pszName The value name.
|
---|
1293 | * @param paFlags The open network flag descriptors.
|
---|
1294 | * @param cFlags The number of descriptors.
|
---|
1295 | * @param fFlags The fixed flag.
|
---|
1296 | * @param pfFlags The flags variable to update.
|
---|
1297 | */
|
---|
1298 | static int drvIntNetR3CfgGetPolicy(PPDMDRVINS pDrvIns, const char *pszName, PCDRVINTNETFLAG paFlags, size_t cFlags,
|
---|
1299 | uint32_t fFixedFlag, uint32_t *pfFlags)
|
---|
1300 | {
|
---|
1301 | PCPDMDRVHLPR3 pHlp = pDrvIns->pHlpR3;
|
---|
1302 |
|
---|
1303 | char szValue[64];
|
---|
1304 | int rc = pHlp->pfnCFGMQueryString(pDrvIns->pCfg, pszName, szValue, sizeof(szValue));
|
---|
1305 | if (RT_FAILURE(rc))
|
---|
1306 | {
|
---|
1307 | if (rc == VERR_CFGM_VALUE_NOT_FOUND)
|
---|
1308 | return VINF_SUCCESS;
|
---|
1309 | return PDMDrvHlpVMSetError(pDrvIns, rc, RT_SRC_POS,
|
---|
1310 | N_("Configuration error: Failed to query value of \"%s\""), pszName);
|
---|
1311 | }
|
---|
1312 |
|
---|
1313 | /*
|
---|
1314 | * Check for +fixed first, so it can be stripped off.
|
---|
1315 | */
|
---|
1316 | char *pszSep = strpbrk(szValue, "+,;");
|
---|
1317 | if (pszSep)
|
---|
1318 | {
|
---|
1319 | *pszSep++ = '\0';
|
---|
1320 | const char *pszFixed = RTStrStripL(pszSep);
|
---|
1321 | if (strcmp(pszFixed, "fixed"))
|
---|
1322 | {
|
---|
1323 | *pszSep = '+';
|
---|
1324 | return PDMDrvHlpVMSetError(pDrvIns, VERR_INVALID_PARAMETER, RT_SRC_POS,
|
---|
1325 | N_("Configuration error: The value of \"%s\" is unknown: \"%s\""), pszName, szValue);
|
---|
1326 | }
|
---|
1327 | *pfFlags |= fFixedFlag;
|
---|
1328 | RTStrStripR(szValue);
|
---|
1329 | }
|
---|
1330 |
|
---|
1331 | /*
|
---|
1332 | * Match against the flag values.
|
---|
1333 | */
|
---|
1334 | size_t i = cFlags;
|
---|
1335 | while (i-- > 0)
|
---|
1336 | if (!strcmp(paFlags[i].pszChoice, szValue))
|
---|
1337 | {
|
---|
1338 | *pfFlags |= paFlags[i].fFlag;
|
---|
1339 | return VINF_SUCCESS;
|
---|
1340 | }
|
---|
1341 |
|
---|
1342 | if (!strcmp(szValue, "none"))
|
---|
1343 | return VINF_SUCCESS;
|
---|
1344 |
|
---|
1345 | if (!strcmp(szValue, "fixed"))
|
---|
1346 | {
|
---|
1347 | *pfFlags |= fFixedFlag;
|
---|
1348 | return VINF_SUCCESS;
|
---|
1349 | }
|
---|
1350 |
|
---|
1351 | return PDMDrvHlpVMSetError(pDrvIns, VERR_INVALID_PARAMETER, RT_SRC_POS,
|
---|
1352 | N_("Configuration error: The value of \"%s\" is unknown: \"%s\""), pszName, szValue);
|
---|
1353 | }
|
---|
1354 |
|
---|
1355 |
|
---|
1356 | /**
|
---|
1357 | * Construct a TAP network transport driver instance.
|
---|
1358 | *
|
---|
1359 | * @copydoc FNPDMDRVCONSTRUCT
|
---|
1360 | */
|
---|
1361 | static DECLCALLBACK(int) drvR3IntNetConstruct(PPDMDRVINS pDrvIns, PCFGMNODE pCfg, uint32_t fFlags)
|
---|
1362 | {
|
---|
1363 | RT_NOREF(fFlags);
|
---|
1364 | PDMDRV_CHECK_VERSIONS_RETURN(pDrvIns);
|
---|
1365 | PDRVINTNET pThis = PDMINS_2_DATA(pDrvIns, PDRVINTNET);
|
---|
1366 | PCPDMDRVHLPR3 pHlp = pDrvIns->pHlpR3;
|
---|
1367 | bool f;
|
---|
1368 |
|
---|
1369 | /*
|
---|
1370 | * Init the static parts.
|
---|
1371 | */
|
---|
1372 | pThis->pDrvInsR3 = pDrvIns;
|
---|
1373 | #ifdef VBOX_WITH_DRVINTNET_IN_R0
|
---|
1374 | pThis->pDrvInsR0 = PDMDRVINS_2_R0PTR(pDrvIns);
|
---|
1375 | #endif
|
---|
1376 | pThis->hIf = INTNET_HANDLE_INVALID;
|
---|
1377 | pThis->hRecvThread = NIL_RTTHREAD;
|
---|
1378 | pThis->hRecvEvt = NIL_RTSEMEVENT;
|
---|
1379 | pThis->pXmitThread = NULL;
|
---|
1380 | pThis->hXmitEvt = NIL_SUPSEMEVENT;
|
---|
1381 | pThis->pSupDrvSession = PDMDrvHlpGetSupDrvSession(pDrvIns);
|
---|
1382 | pThis->hSgCache = NIL_RTMEMCACHE;
|
---|
1383 | pThis->enmRecvState = RECVSTATE_SUSPENDED;
|
---|
1384 | pThis->fActivateEarlyDeactivateLate = false;
|
---|
1385 | /* IBase* */
|
---|
1386 | pDrvIns->IBase.pfnQueryInterface = drvR3IntNetIBase_QueryInterface;
|
---|
1387 | #ifdef VBOX_WITH_DRVINTNET_IN_R0
|
---|
1388 | pThis->IBaseR0.pfnQueryInterface = drvR3IntNetIBaseR0_QueryInterface;
|
---|
1389 | pThis->IBaseRC.pfnQueryInterface = drvR3IntNetIBaseRC_QueryInterface;
|
---|
1390 | #endif
|
---|
1391 | /* INetworkUp */
|
---|
1392 | pThis->INetworkUpR3.pfnBeginXmit = drvIntNetUp_BeginXmit;
|
---|
1393 | pThis->INetworkUpR3.pfnAllocBuf = drvIntNetUp_AllocBuf;
|
---|
1394 | pThis->INetworkUpR3.pfnFreeBuf = drvIntNetUp_FreeBuf;
|
---|
1395 | pThis->INetworkUpR3.pfnSendBuf = drvIntNetUp_SendBuf;
|
---|
1396 | pThis->INetworkUpR3.pfnEndXmit = drvIntNetUp_EndXmit;
|
---|
1397 | pThis->INetworkUpR3.pfnSetPromiscuousMode = drvIntNetUp_SetPromiscuousMode;
|
---|
1398 | pThis->INetworkUpR3.pfnNotifyLinkChanged = drvR3IntNetUp_NotifyLinkChanged;
|
---|
1399 |
|
---|
1400 | /*
|
---|
1401 | * Validate the config.
|
---|
1402 | */
|
---|
1403 | PDMDRV_VALIDATE_CONFIG_RETURN(pDrvIns,
|
---|
1404 | "Network"
|
---|
1405 | "|Trunk"
|
---|
1406 | "|TrunkType"
|
---|
1407 | "|ReceiveBufferSize"
|
---|
1408 | "|SendBufferSize"
|
---|
1409 | "|SharedMacOnWire"
|
---|
1410 | "|RestrictAccess"
|
---|
1411 | "|RequireExactPolicyMatch"
|
---|
1412 | "|RequireAsRestrictivePolicy"
|
---|
1413 | "|AccessPolicy"
|
---|
1414 | "|PromiscPolicyClients"
|
---|
1415 | "|PromiscPolicyHost"
|
---|
1416 | "|PromiscPolicyWire"
|
---|
1417 | "|IfPolicyPromisc"
|
---|
1418 | "|TrunkPolicyHost"
|
---|
1419 | "|TrunkPolicyWire"
|
---|
1420 | "|IsService"
|
---|
1421 | "|IgnoreConnectFailure"
|
---|
1422 | "|Workaround1",
|
---|
1423 | "");
|
---|
1424 |
|
---|
1425 | /*
|
---|
1426 | * Check that no-one is attached to us.
|
---|
1427 | */
|
---|
1428 | AssertMsgReturn(PDMDrvHlpNoAttach(pDrvIns) == VERR_PDM_NO_ATTACHED_DRIVER,
|
---|
1429 | ("Configuration error: Not possible to attach anything to this driver!\n"),
|
---|
1430 | VERR_PDM_DRVINS_NO_ATTACH);
|
---|
1431 |
|
---|
1432 | /*
|
---|
1433 | * Query the network port interface.
|
---|
1434 | */
|
---|
1435 | pThis->pIAboveNet = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMINETWORKDOWN);
|
---|
1436 | if (!pThis->pIAboveNet)
|
---|
1437 | {
|
---|
1438 | AssertMsgFailed(("Configuration error: the above device/driver didn't export the network port interface!\n"));
|
---|
1439 | return VERR_PDM_MISSING_INTERFACE_ABOVE;
|
---|
1440 | }
|
---|
1441 | pThis->pIAboveConfigR3 = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMINETWORKCONFIG);
|
---|
1442 |
|
---|
1443 | /*
|
---|
1444 | * Read the configuration.
|
---|
1445 | */
|
---|
1446 | INTNETOPENREQ OpenReq;
|
---|
1447 | RT_ZERO(OpenReq);
|
---|
1448 | OpenReq.Hdr.cbReq = sizeof(OpenReq);
|
---|
1449 | OpenReq.Hdr.u32Magic = SUPVMMR0REQHDR_MAGIC;
|
---|
1450 | OpenReq.pSession = NIL_RTR0PTR;
|
---|
1451 |
|
---|
1452 | /** @cfgm{Network, string}
|
---|
1453 | * The name of the internal network to connect to.
|
---|
1454 | */
|
---|
1455 | int rc = pHlp->pfnCFGMQueryString(pCfg, "Network", OpenReq.szNetwork, sizeof(OpenReq.szNetwork));
|
---|
1456 | if (RT_FAILURE(rc))
|
---|
1457 | return PDMDRV_SET_ERROR(pDrvIns, rc,
|
---|
1458 | N_("Configuration error: Failed to get the \"Network\" value"));
|
---|
1459 | strcpy(pThis->szNetwork, OpenReq.szNetwork);
|
---|
1460 |
|
---|
1461 | /** @cfgm{TrunkType, uint32_t, kIntNetTrunkType_None}
|
---|
1462 | * The trunk connection type see INTNETTRUNKTYPE.
|
---|
1463 | */
|
---|
1464 | uint32_t u32TrunkType;
|
---|
1465 | rc = pHlp->pfnCFGMQueryU32(pCfg, "TrunkType", &u32TrunkType);
|
---|
1466 | if (rc == VERR_CFGM_VALUE_NOT_FOUND)
|
---|
1467 | u32TrunkType = kIntNetTrunkType_None;
|
---|
1468 | else if (RT_FAILURE(rc))
|
---|
1469 | return PDMDRV_SET_ERROR(pDrvIns, rc,
|
---|
1470 | N_("Configuration error: Failed to get the \"TrunkType\" value"));
|
---|
1471 | OpenReq.enmTrunkType = (INTNETTRUNKTYPE)u32TrunkType;
|
---|
1472 |
|
---|
1473 | /** @cfgm{Trunk, string, ""}
|
---|
1474 | * The name of the trunk connection.
|
---|
1475 | */
|
---|
1476 | rc = pHlp->pfnCFGMQueryString(pCfg, "Trunk", OpenReq.szTrunk, sizeof(OpenReq.szTrunk));
|
---|
1477 | if (rc == VERR_CFGM_VALUE_NOT_FOUND)
|
---|
1478 | OpenReq.szTrunk[0] = '\0';
|
---|
1479 | else if (RT_FAILURE(rc))
|
---|
1480 | return PDMDRV_SET_ERROR(pDrvIns, rc,
|
---|
1481 | N_("Configuration error: Failed to get the \"Trunk\" value"));
|
---|
1482 |
|
---|
1483 | OpenReq.fFlags = 0;
|
---|
1484 |
|
---|
1485 | /** @cfgm{SharedMacOnWire, boolean, false}
|
---|
1486 | * Whether to shared the MAC address of the host interface when using the wire. When
|
---|
1487 | * attaching to a wireless NIC this option is usually a requirement.
|
---|
1488 | */
|
---|
1489 | bool fSharedMacOnWire;
|
---|
1490 | rc = pHlp->pfnCFGMQueryBoolDef(pCfg, "SharedMacOnWire", &fSharedMacOnWire, false);
|
---|
1491 | if (RT_FAILURE(rc))
|
---|
1492 | return PDMDRV_SET_ERROR(pDrvIns, rc,
|
---|
1493 | N_("Configuration error: Failed to get the \"SharedMacOnWire\" value"));
|
---|
1494 | if (fSharedMacOnWire)
|
---|
1495 | OpenReq.fFlags |= INTNET_OPEN_FLAGS_SHARED_MAC_ON_WIRE;
|
---|
1496 |
|
---|
1497 | /** @cfgm{RestrictAccess, boolean, true}
|
---|
1498 | * Whether to restrict the access to the network or if it should be public.
|
---|
1499 | * Everyone on the computer can connect to a public network.
|
---|
1500 | * @deprecated Use AccessPolicy instead.
|
---|
1501 | */
|
---|
1502 | rc = pHlp->pfnCFGMQueryBool(pCfg, "RestrictAccess", &f);
|
---|
1503 | if (RT_SUCCESS(rc))
|
---|
1504 | {
|
---|
1505 | if (f)
|
---|
1506 | OpenReq.fFlags |= INTNET_OPEN_FLAGS_ACCESS_RESTRICTED;
|
---|
1507 | else
|
---|
1508 | OpenReq.fFlags |= INTNET_OPEN_FLAGS_ACCESS_PUBLIC;
|
---|
1509 | OpenReq.fFlags |= INTNET_OPEN_FLAGS_ACCESS_FIXED;
|
---|
1510 | }
|
---|
1511 | else if (rc != VERR_CFGM_VALUE_NOT_FOUND)
|
---|
1512 | return PDMDRV_SET_ERROR(pDrvIns, rc,
|
---|
1513 | N_("Configuration error: Failed to get the \"RestrictAccess\" value"));
|
---|
1514 |
|
---|
1515 | /** @cfgm{RequireExactPolicyMatch, boolean, false}
|
---|
1516 | * Whether to require that the current security and promiscuous policies of
|
---|
1517 | * the network is exactly as the ones specified in this open network
|
---|
1518 | * request. Use this with RequireAsRestrictivePolicy to prevent
|
---|
1519 | * restrictions from being lifted. If no further policy changes are
|
---|
1520 | * desired, apply the relevant fixed flags. */
|
---|
1521 | rc = pHlp->pfnCFGMQueryBoolDef(pCfg, "RequireExactPolicyMatch", &f, false);
|
---|
1522 | if (RT_FAILURE(rc))
|
---|
1523 | return PDMDRV_SET_ERROR(pDrvIns, rc,
|
---|
1524 | N_("Configuration error: Failed to get the \"RequireExactPolicyMatch\" value"));
|
---|
1525 | if (f)
|
---|
1526 | OpenReq.fFlags |= INTNET_OPEN_FLAGS_REQUIRE_EXACT;
|
---|
1527 |
|
---|
1528 | /** @cfgm{RequireAsRestrictivePolicy, boolean, false}
|
---|
1529 | * Whether to require that the security and promiscuous policies of the
|
---|
1530 | * network is at least as restrictive as specified this request specifies
|
---|
1531 | * and prevent them being lifted later on.
|
---|
1532 | */
|
---|
1533 | rc = pHlp->pfnCFGMQueryBoolDef(pCfg, "RequireAsRestrictivePolicy", &f, false);
|
---|
1534 | if (RT_FAILURE(rc))
|
---|
1535 | return PDMDRV_SET_ERROR(pDrvIns, rc,
|
---|
1536 | N_("Configuration error: Failed to get the \"RequireAsRestrictivePolicy\" value"));
|
---|
1537 | if (f)
|
---|
1538 | OpenReq.fFlags |= INTNET_OPEN_FLAGS_REQUIRE_AS_RESTRICTIVE_POLICIES;
|
---|
1539 |
|
---|
1540 | /** @cfgm{AccessPolicy, string, "none"}
|
---|
1541 | * The access policy of the network:
|
---|
1542 | * public, public+fixed, restricted, restricted+fixed, none or fixed.
|
---|
1543 | *
|
---|
1544 | * A "public" network is accessible to everyone on the same host, while a
|
---|
1545 | * "restricted" one is only accessible to VMs & services started by the
|
---|
1546 | * same user. The "none" policy, which is the default, means no policy
|
---|
1547 | * change or choice is made and that the current (existing network) or
|
---|
1548 | * default (new) policy should be used. */
|
---|
1549 | static const DRVINTNETFLAG s_aAccessPolicyFlags[] =
|
---|
1550 | {
|
---|
1551 | { "public", INTNET_OPEN_FLAGS_ACCESS_PUBLIC },
|
---|
1552 | { "restricted", INTNET_OPEN_FLAGS_ACCESS_RESTRICTED }
|
---|
1553 | };
|
---|
1554 | rc = drvIntNetR3CfgGetPolicy(pDrvIns, "AccessPolicy", &s_aAccessPolicyFlags[0], RT_ELEMENTS(s_aAccessPolicyFlags),
|
---|
1555 | INTNET_OPEN_FLAGS_ACCESS_FIXED, &OpenReq.fFlags);
|
---|
1556 | AssertRCReturn(rc, rc);
|
---|
1557 |
|
---|
1558 | /** @cfgm{PromiscPolicyClients, string, "none"}
|
---|
1559 | * The network wide promiscuous mode policy for client (non-trunk)
|
---|
1560 | * interfaces: allow, allow+fixed, deny, deny+fixed, none or fixed. */
|
---|
1561 | static const DRVINTNETFLAG s_aPromiscPolicyClient[] =
|
---|
1562 | {
|
---|
1563 | { "allow", INTNET_OPEN_FLAGS_PROMISC_ALLOW_CLIENTS },
|
---|
1564 | { "deny", INTNET_OPEN_FLAGS_PROMISC_DENY_CLIENTS }
|
---|
1565 | };
|
---|
1566 | rc = drvIntNetR3CfgGetPolicy(pDrvIns, "PromiscPolicyClients", &s_aPromiscPolicyClient[0], RT_ELEMENTS(s_aPromiscPolicyClient),
|
---|
1567 | INTNET_OPEN_FLAGS_PROMISC_FIXED, &OpenReq.fFlags);
|
---|
1568 | AssertRCReturn(rc, rc);
|
---|
1569 | /** @cfgm{PromiscPolicyHost, string, "none"}
|
---|
1570 | * The promiscuous mode policy for the trunk-host
|
---|
1571 | * connection: allow, allow+fixed, deny, deny+fixed, none or fixed. */
|
---|
1572 | static const DRVINTNETFLAG s_aPromiscPolicyHost[] =
|
---|
1573 | {
|
---|
1574 | { "allow", INTNET_OPEN_FLAGS_PROMISC_ALLOW_TRUNK_HOST },
|
---|
1575 | { "deny", INTNET_OPEN_FLAGS_PROMISC_DENY_TRUNK_HOST }
|
---|
1576 | };
|
---|
1577 | rc = drvIntNetR3CfgGetPolicy(pDrvIns, "PromiscPolicyHost", &s_aPromiscPolicyHost[0], RT_ELEMENTS(s_aPromiscPolicyHost),
|
---|
1578 | INTNET_OPEN_FLAGS_PROMISC_FIXED, &OpenReq.fFlags);
|
---|
1579 | AssertRCReturn(rc, rc);
|
---|
1580 | /** @cfgm{PromiscPolicyWire, string, "none"}
|
---|
1581 | * The promiscuous mode policy for the trunk-host
|
---|
1582 | * connection: allow, allow+fixed, deny, deny+fixed, none or fixed. */
|
---|
1583 | static const DRVINTNETFLAG s_aPromiscPolicyWire[] =
|
---|
1584 | {
|
---|
1585 | { "allow", INTNET_OPEN_FLAGS_PROMISC_ALLOW_TRUNK_WIRE },
|
---|
1586 | { "deny", INTNET_OPEN_FLAGS_PROMISC_DENY_TRUNK_WIRE }
|
---|
1587 | };
|
---|
1588 | rc = drvIntNetR3CfgGetPolicy(pDrvIns, "PromiscPolicyWire", &s_aPromiscPolicyWire[0], RT_ELEMENTS(s_aPromiscPolicyWire),
|
---|
1589 | INTNET_OPEN_FLAGS_PROMISC_FIXED, &OpenReq.fFlags);
|
---|
1590 | AssertRCReturn(rc, rc);
|
---|
1591 |
|
---|
1592 |
|
---|
1593 | /** @cfgm{IfPolicyPromisc, string, "none"}
|
---|
1594 | * The promiscuous mode policy for this
|
---|
1595 | * interface: deny, deny+fixed, allow-all, allow-all+fixed, allow-network,
|
---|
1596 | * allow-network+fixed, none or fixed. */
|
---|
1597 | static const DRVINTNETFLAG s_aIfPolicyPromisc[] =
|
---|
1598 | {
|
---|
1599 | { "allow-all", INTNET_OPEN_FLAGS_IF_PROMISC_ALLOW | INTNET_OPEN_FLAGS_IF_PROMISC_SEE_TRUNK },
|
---|
1600 | { "allow-network", INTNET_OPEN_FLAGS_IF_PROMISC_ALLOW | INTNET_OPEN_FLAGS_IF_PROMISC_NO_TRUNK },
|
---|
1601 | { "deny", INTNET_OPEN_FLAGS_IF_PROMISC_DENY }
|
---|
1602 | };
|
---|
1603 | rc = drvIntNetR3CfgGetPolicy(pDrvIns, "IfPolicyPromisc", &s_aIfPolicyPromisc[0], RT_ELEMENTS(s_aIfPolicyPromisc),
|
---|
1604 | INTNET_OPEN_FLAGS_IF_FIXED, &OpenReq.fFlags);
|
---|
1605 | AssertRCReturn(rc, rc);
|
---|
1606 |
|
---|
1607 |
|
---|
1608 | /** @cfgm{TrunkPolicyHost, string, "none"}
|
---|
1609 | * The trunk-host policy: promisc, promisc+fixed, enabled, enabled+fixed,
|
---|
1610 | * disabled, disabled+fixed, none or fixed
|
---|
1611 | *
|
---|
1612 | * This can be used to prevent packages to be routed to the host. */
|
---|
1613 | static const DRVINTNETFLAG s_aTrunkPolicyHost[] =
|
---|
1614 | {
|
---|
1615 | { "promisc", INTNET_OPEN_FLAGS_TRUNK_HOST_ENABLED | INTNET_OPEN_FLAGS_TRUNK_HOST_PROMISC_MODE },
|
---|
1616 | { "enabled", INTNET_OPEN_FLAGS_TRUNK_HOST_ENABLED },
|
---|
1617 | { "disabled", INTNET_OPEN_FLAGS_TRUNK_HOST_DISABLED }
|
---|
1618 | };
|
---|
1619 | rc = drvIntNetR3CfgGetPolicy(pDrvIns, "TrunkPolicyHost", &s_aTrunkPolicyHost[0], RT_ELEMENTS(s_aTrunkPolicyHost),
|
---|
1620 | INTNET_OPEN_FLAGS_TRUNK_FIXED, &OpenReq.fFlags);
|
---|
1621 | AssertRCReturn(rc, rc);
|
---|
1622 | /** @cfgm{TrunkPolicyWire, string, "none"}
|
---|
1623 | * The trunk-host policy: promisc, promisc+fixed, enabled, enabled+fixed,
|
---|
1624 | * disabled, disabled+fixed, none or fixed.
|
---|
1625 | *
|
---|
1626 | * This can be used to prevent packages to be routed to the wire. */
|
---|
1627 | static const DRVINTNETFLAG s_aTrunkPolicyWire[] =
|
---|
1628 | {
|
---|
1629 | { "promisc", INTNET_OPEN_FLAGS_TRUNK_WIRE_ENABLED | INTNET_OPEN_FLAGS_TRUNK_WIRE_PROMISC_MODE },
|
---|
1630 | { "enabled", INTNET_OPEN_FLAGS_TRUNK_WIRE_ENABLED },
|
---|
1631 | { "disabled", INTNET_OPEN_FLAGS_TRUNK_WIRE_DISABLED }
|
---|
1632 | };
|
---|
1633 | rc = drvIntNetR3CfgGetPolicy(pDrvIns, "TrunkPolicyWire", &s_aTrunkPolicyWire[0], RT_ELEMENTS(s_aTrunkPolicyWire),
|
---|
1634 | INTNET_OPEN_FLAGS_TRUNK_FIXED, &OpenReq.fFlags);
|
---|
1635 | AssertRCReturn(rc, rc);
|
---|
1636 |
|
---|
1637 |
|
---|
1638 | /** @cfgm{ReceiveBufferSize, uint32_t, 318 KB}
|
---|
1639 | * The size of the receive buffer.
|
---|
1640 | */
|
---|
1641 | rc = pHlp->pfnCFGMQueryU32(pCfg, "ReceiveBufferSize", &OpenReq.cbRecv);
|
---|
1642 | if (rc == VERR_CFGM_VALUE_NOT_FOUND)
|
---|
1643 | OpenReq.cbRecv = 318 * _1K ;
|
---|
1644 | else if (RT_FAILURE(rc))
|
---|
1645 | return PDMDRV_SET_ERROR(pDrvIns, rc,
|
---|
1646 | N_("Configuration error: Failed to get the \"ReceiveBufferSize\" value"));
|
---|
1647 |
|
---|
1648 | /** @cfgm{SendBufferSize, uint32_t, 196 KB}
|
---|
1649 | * The size of the send (transmit) buffer.
|
---|
1650 | * This should be more than twice the size of the larges frame size because
|
---|
1651 | * the ring buffer is very simple and doesn't support splitting up frames
|
---|
1652 | * nor inserting padding. So, if this is too close to the frame size the
|
---|
1653 | * header will fragment the buffer such that the frame won't fit on either
|
---|
1654 | * side of it and the code will get very upset about it all.
|
---|
1655 | */
|
---|
1656 | rc = pHlp->pfnCFGMQueryU32(pCfg, "SendBufferSize", &OpenReq.cbSend);
|
---|
1657 | if (rc == VERR_CFGM_VALUE_NOT_FOUND)
|
---|
1658 | OpenReq.cbSend = RT_ALIGN_Z(VBOX_MAX_GSO_SIZE * 3, _1K);
|
---|
1659 | else if (RT_FAILURE(rc))
|
---|
1660 | return PDMDRV_SET_ERROR(pDrvIns, rc,
|
---|
1661 | N_("Configuration error: Failed to get the \"SendBufferSize\" value"));
|
---|
1662 | if (OpenReq.cbSend < 128)
|
---|
1663 | return PDMDRV_SET_ERROR(pDrvIns, rc,
|
---|
1664 | N_("Configuration error: The \"SendBufferSize\" value is too small"));
|
---|
1665 | if (OpenReq.cbSend < VBOX_MAX_GSO_SIZE * 3)
|
---|
1666 | LogRel(("DrvIntNet: Warning! SendBufferSize=%u, Recommended minimum size %u butes.\n", OpenReq.cbSend, VBOX_MAX_GSO_SIZE * 4));
|
---|
1667 |
|
---|
1668 | /** @cfgm{IsService, boolean, true}
|
---|
1669 | * This alterns the way the thread is suspended and resumed. When it's being used by
|
---|
1670 | * a service such as LWIP/iSCSI it shouldn't suspend immediately like for a NIC.
|
---|
1671 | */
|
---|
1672 | rc = pHlp->pfnCFGMQueryBool(pCfg, "IsService", &pThis->fActivateEarlyDeactivateLate);
|
---|
1673 | if (rc == VERR_CFGM_VALUE_NOT_FOUND)
|
---|
1674 | pThis->fActivateEarlyDeactivateLate = false;
|
---|
1675 | else if (RT_FAILURE(rc))
|
---|
1676 | return PDMDRV_SET_ERROR(pDrvIns, rc,
|
---|
1677 | N_("Configuration error: Failed to get the \"IsService\" value"));
|
---|
1678 |
|
---|
1679 |
|
---|
1680 | /** @cfgm{IgnoreConnectFailure, boolean, false}
|
---|
1681 | * When set only raise a runtime error if we cannot connect to the internal
|
---|
1682 | * network. */
|
---|
1683 | bool fIgnoreConnectFailure;
|
---|
1684 | rc = pHlp->pfnCFGMQueryBoolDef(pCfg, "IgnoreConnectFailure", &fIgnoreConnectFailure, false);
|
---|
1685 | if (RT_FAILURE(rc))
|
---|
1686 | return PDMDRV_SET_ERROR(pDrvIns, rc,
|
---|
1687 | N_("Configuration error: Failed to get the \"IgnoreConnectFailure\" value"));
|
---|
1688 |
|
---|
1689 | /** @cfgm{Workaround1, boolean, depends}
|
---|
1690 | * Enables host specific workarounds, the default is depends on the whether
|
---|
1691 | * we think the host requires it or not.
|
---|
1692 | */
|
---|
1693 | bool fWorkaround1 = false;
|
---|
1694 | #ifdef RT_OS_DARWIN
|
---|
1695 | if (OpenReq.fFlags & INTNET_OPEN_FLAGS_SHARED_MAC_ON_WIRE)
|
---|
1696 | {
|
---|
1697 | char szKrnlVer[256];
|
---|
1698 | RTSystemQueryOSInfo(RTSYSOSINFO_RELEASE, szKrnlVer, sizeof(szKrnlVer));
|
---|
1699 | if (strcmp(szKrnlVer, "10.7.0") >= 0)
|
---|
1700 | {
|
---|
1701 | LogRel(("IntNet#%u: Enables the workaround (ip_tos=0) for the little endian ip header checksum problem\n"));
|
---|
1702 | fWorkaround1 = true;
|
---|
1703 | }
|
---|
1704 | }
|
---|
1705 | #endif
|
---|
1706 | rc = pHlp->pfnCFGMQueryBoolDef(pCfg, "Workaround1", &fWorkaround1, fWorkaround1);
|
---|
1707 | if (RT_FAILURE(rc))
|
---|
1708 | return PDMDRV_SET_ERROR(pDrvIns, rc,
|
---|
1709 | N_("Configuration error: Failed to get the \"Workaround1\" value"));
|
---|
1710 | if (fWorkaround1)
|
---|
1711 | OpenReq.fFlags |= INTNET_OPEN_FLAGS_WORKAROUND_1;
|
---|
1712 |
|
---|
1713 | LogRel(("IntNet#%u: szNetwork={%s} enmTrunkType=%d szTrunk={%s} fFlags=%#x cbRecv=%u cbSend=%u fIgnoreConnectFailure=%RTbool\n",
|
---|
1714 | pDrvIns->iInstance, OpenReq.szNetwork, OpenReq.enmTrunkType, OpenReq.szTrunk, OpenReq.fFlags,
|
---|
1715 | OpenReq.cbRecv, OpenReq.cbSend, fIgnoreConnectFailure));
|
---|
1716 |
|
---|
1717 | #ifdef RT_OS_DARWIN
|
---|
1718 | /* Temporary hack: attach to a network with the name 'if=en0' and you're hitting the wire. */
|
---|
1719 | if ( !OpenReq.szTrunk[0]
|
---|
1720 | && OpenReq.enmTrunkType == kIntNetTrunkType_None
|
---|
1721 | && !strncmp(pThis->szNetwork, RT_STR_TUPLE("if=en"))
|
---|
1722 | && RT_C_IS_DIGIT(pThis->szNetwork[sizeof("if=en") - 1])
|
---|
1723 | && !pThis->szNetwork[sizeof("if=en")])
|
---|
1724 | {
|
---|
1725 | OpenReq.enmTrunkType = kIntNetTrunkType_NetFlt;
|
---|
1726 | strcpy(OpenReq.szTrunk, &pThis->szNetwork[sizeof("if=") - 1]);
|
---|
1727 | }
|
---|
1728 | /* Temporary hack: attach to a network with the name 'wif=en0' and you're on the air. */
|
---|
1729 | if ( !OpenReq.szTrunk[0]
|
---|
1730 | && OpenReq.enmTrunkType == kIntNetTrunkType_None
|
---|
1731 | && !strncmp(pThis->szNetwork, RT_STR_TUPLE("wif=en"))
|
---|
1732 | && RT_C_IS_DIGIT(pThis->szNetwork[sizeof("wif=en") - 1])
|
---|
1733 | && !pThis->szNetwork[sizeof("wif=en")])
|
---|
1734 | {
|
---|
1735 | OpenReq.enmTrunkType = kIntNetTrunkType_NetFlt;
|
---|
1736 | OpenReq.fFlags |= INTNET_OPEN_FLAGS_SHARED_MAC_ON_WIRE;
|
---|
1737 | strcpy(OpenReq.szTrunk, &pThis->szNetwork[sizeof("wif=") - 1]);
|
---|
1738 | }
|
---|
1739 | #endif /* DARWIN */
|
---|
1740 |
|
---|
1741 | /*
|
---|
1742 | * Create the event semaphore, S/G cache and xmit critsect.
|
---|
1743 | */
|
---|
1744 | rc = RTSemEventCreate(&pThis->hRecvEvt);
|
---|
1745 | if (RT_FAILURE(rc))
|
---|
1746 | return rc;
|
---|
1747 | rc = RTMemCacheCreate(&pThis->hSgCache, sizeof(PDMSCATTERGATHER), 0, UINT32_MAX, NULL, NULL, pThis, 0);
|
---|
1748 | if (RT_FAILURE(rc))
|
---|
1749 | return rc;
|
---|
1750 | rc = PDMDrvHlpCritSectInit(pDrvIns, &pThis->XmitLock, RT_SRC_POS, "IntNetXmit");
|
---|
1751 | if (RT_FAILURE(rc))
|
---|
1752 | return rc;
|
---|
1753 |
|
---|
1754 | /*
|
---|
1755 | * Create the interface.
|
---|
1756 | */
|
---|
1757 | if (SUPR3IsDriverless()) /** @todo This is probably not good enough for doing fuzz testing, but later... */
|
---|
1758 | return PDMDrvHlpVMSetError(pDrvIns, VERR_SUP_DRIVERLESS, RT_SRC_POS,
|
---|
1759 | N_("Cannot attach to '%s' in driverless mode"), pThis->szNetwork);
|
---|
1760 | OpenReq.hIf = INTNET_HANDLE_INVALID;
|
---|
1761 | rc = PDMDrvHlpSUPCallVMMR0Ex(pDrvIns, VMMR0_DO_INTNET_OPEN, &OpenReq, sizeof(OpenReq));
|
---|
1762 | if (RT_FAILURE(rc))
|
---|
1763 | {
|
---|
1764 | if (fIgnoreConnectFailure)
|
---|
1765 | {
|
---|
1766 | /*
|
---|
1767 | * During VM restore it is fatal if the network is not available because the
|
---|
1768 | * VM settings are locked and the user has no chance to fix network settings.
|
---|
1769 | * Therefore don't abort but just raise a runtime warning.
|
---|
1770 | */
|
---|
1771 | PDMDrvHlpVMSetRuntimeError(pDrvIns, 0 /*fFlags*/, "HostIfNotConnecting",
|
---|
1772 | N_ ("Cannot connect to the network interface '%s'. The virtual "
|
---|
1773 | "network card will appear to work but the guest will not "
|
---|
1774 | "be able to connect. Please choose a different network in the "
|
---|
1775 | "network settings"), OpenReq.szTrunk);
|
---|
1776 |
|
---|
1777 | return VERR_PDM_NO_ATTACHED_DRIVER;
|
---|
1778 | }
|
---|
1779 | return PDMDrvHlpVMSetError(pDrvIns, rc, RT_SRC_POS,
|
---|
1780 | N_("Failed to open/create the internal network '%s'"), pThis->szNetwork);
|
---|
1781 | }
|
---|
1782 |
|
---|
1783 | AssertRelease(OpenReq.hIf != INTNET_HANDLE_INVALID);
|
---|
1784 | pThis->hIf = OpenReq.hIf;
|
---|
1785 | Log(("IntNet%d: hIf=%RX32 '%s'\n", pDrvIns->iInstance, pThis->hIf, pThis->szNetwork));
|
---|
1786 |
|
---|
1787 | /*
|
---|
1788 | * Get default buffer.
|
---|
1789 | */
|
---|
1790 | INTNETIFGETBUFFERPTRSREQ GetBufferPtrsReq;
|
---|
1791 | GetBufferPtrsReq.Hdr.u32Magic = SUPVMMR0REQHDR_MAGIC;
|
---|
1792 | GetBufferPtrsReq.Hdr.cbReq = sizeof(GetBufferPtrsReq);
|
---|
1793 | GetBufferPtrsReq.pSession = NIL_RTR0PTR;
|
---|
1794 | GetBufferPtrsReq.hIf = pThis->hIf;
|
---|
1795 | GetBufferPtrsReq.pRing3Buf = NULL;
|
---|
1796 | GetBufferPtrsReq.pRing0Buf = NIL_RTR0PTR;
|
---|
1797 | rc = PDMDrvHlpSUPCallVMMR0Ex(pDrvIns, VMMR0_DO_INTNET_IF_GET_BUFFER_PTRS, &GetBufferPtrsReq, sizeof(GetBufferPtrsReq));
|
---|
1798 | if (RT_FAILURE(rc))
|
---|
1799 | return PDMDrvHlpVMSetError(pDrvIns, rc, RT_SRC_POS,
|
---|
1800 | N_("Failed to get ring-3 buffer for the newly created interface to '%s'"), pThis->szNetwork);
|
---|
1801 | AssertRelease(RT_VALID_PTR(GetBufferPtrsReq.pRing3Buf));
|
---|
1802 | pThis->pBufR3 = GetBufferPtrsReq.pRing3Buf;
|
---|
1803 | #ifdef VBOX_WITH_DRVINTNET_IN_R0
|
---|
1804 | pThis->pBufR0 = GetBufferPtrsReq.pRing0Buf;
|
---|
1805 | #endif
|
---|
1806 |
|
---|
1807 | /*
|
---|
1808 | * Register statistics.
|
---|
1809 | */
|
---|
1810 | PDMDrvHlpSTAMRegCounterEx(pDrvIns, &pThis->pBufR3->Recv.cbStatWritten, "Bytes/Received", STAMUNIT_BYTES, "Number of received bytes.");
|
---|
1811 | PDMDrvHlpSTAMRegCounterEx(pDrvIns, &pThis->pBufR3->Send.cbStatWritten, "Bytes/Sent", STAMUNIT_BYTES, "Number of sent bytes.");
|
---|
1812 | PDMDrvHlpSTAMRegCounter(pDrvIns, &pThis->pBufR3->Recv.cOverflows, "Overflows/Recv", "Number overflows.");
|
---|
1813 | PDMDrvHlpSTAMRegCounter(pDrvIns, &pThis->pBufR3->Send.cOverflows, "Overflows/Sent", "Number overflows.");
|
---|
1814 | PDMDrvHlpSTAMRegCounter(pDrvIns, &pThis->pBufR3->Recv.cStatFrames, "Packets/Received", "Number of received packets.");
|
---|
1815 | PDMDrvHlpSTAMRegCounter(pDrvIns, &pThis->pBufR3->Send.cStatFrames, "Packets/Sent", "Number of sent packets.");
|
---|
1816 | PDMDrvHlpSTAMRegCounter(pDrvIns, &pThis->StatReceivedGso, "Packets/Received-Gso", "The GSO portion of the received packets.");
|
---|
1817 | PDMDrvHlpSTAMRegCounter(pDrvIns, &pThis->StatSentGso, "Packets/Sent-Gso", "The GSO portion of the sent packets.");
|
---|
1818 | PDMDrvHlpSTAMRegCounter(pDrvIns, &pThis->StatSentR0, "Packets/Sent-R0", "The ring-0 portion of the sent packets.");
|
---|
1819 |
|
---|
1820 | PDMDrvHlpSTAMRegCounter(pDrvIns, &pThis->pBufR3->cStatLost, "Packets/Lost", "Number of lost packets.");
|
---|
1821 | PDMDrvHlpSTAMRegCounter(pDrvIns, &pThis->pBufR3->cStatYieldsNok, "YieldOk", "Number of times yielding helped fix an overflow.");
|
---|
1822 | PDMDrvHlpSTAMRegCounter(pDrvIns, &pThis->pBufR3->cStatYieldsOk, "YieldNok", "Number of times yielding didn't help fix an overflow.");
|
---|
1823 | PDMDrvHlpSTAMRegCounter(pDrvIns, &pThis->pBufR3->cStatBadFrames, "BadFrames", "Number of bad frames seed by the consumers.");
|
---|
1824 | PDMDrvHlpSTAMRegProfile(pDrvIns, &pThis->pBufR3->StatSend1, "Send1", "Profiling IntNetR0IfSend.");
|
---|
1825 | PDMDrvHlpSTAMRegProfile(pDrvIns, &pThis->pBufR3->StatSend2, "Send2", "Profiling sending to the trunk.");
|
---|
1826 | PDMDrvHlpSTAMRegProfile(pDrvIns, &pThis->pBufR3->StatRecv1, "Recv1", "Reserved for future receive profiling.");
|
---|
1827 | PDMDrvHlpSTAMRegProfile(pDrvIns, &pThis->pBufR3->StatRecv2, "Recv2", "Reserved for future receive profiling.");
|
---|
1828 | PDMDrvHlpSTAMRegProfile(pDrvIns, &pThis->pBufR3->StatReserved, "Reserved", "Reserved for future use.");
|
---|
1829 | #ifdef VBOX_WITH_STATISTICS
|
---|
1830 | PDMDrvHlpSTAMRegProfileAdv(pDrvIns, &pThis->StatReceive, "Receive", "Profiling packet receive runs.");
|
---|
1831 | PDMDrvHlpSTAMRegProfile(pDrvIns, &pThis->StatTransmit, "Transmit", "Profiling packet transmit runs.");
|
---|
1832 | #endif
|
---|
1833 | PDMDrvHlpSTAMRegCounter(pDrvIns, &pThis->StatXmitWakeupR0, "XmitWakeup-R0", "Xmit thread wakeups from ring-0.");
|
---|
1834 | PDMDrvHlpSTAMRegCounter(pDrvIns, &pThis->StatXmitWakeupR3, "XmitWakeup-R3", "Xmit thread wakeups from ring-3.");
|
---|
1835 | PDMDrvHlpSTAMRegCounter(pDrvIns, &pThis->StatXmitProcessRing, "XmitProcessRing", "Time xmit thread was told to process the ring.");
|
---|
1836 |
|
---|
1837 | /*
|
---|
1838 | * Create the async I/O threads.
|
---|
1839 | * Note! Using a PDM thread here doesn't fit with the IsService=true operation.
|
---|
1840 | */
|
---|
1841 | rc = RTThreadCreate(&pThis->hRecvThread, drvR3IntNetRecvThread, pThis, 0,
|
---|
1842 | RTTHREADTYPE_IO, RTTHREADFLAGS_WAITABLE, "INTNET-RECV");
|
---|
1843 | if (RT_FAILURE(rc))
|
---|
1844 | {
|
---|
1845 | AssertRC(rc);
|
---|
1846 | return rc;
|
---|
1847 | }
|
---|
1848 |
|
---|
1849 | rc = SUPSemEventCreate(pThis->pSupDrvSession, &pThis->hXmitEvt);
|
---|
1850 | AssertRCReturn(rc, rc);
|
---|
1851 |
|
---|
1852 | rc = PDMDrvHlpThreadCreate(pDrvIns, &pThis->pXmitThread, pThis,
|
---|
1853 | drvR3IntNetXmitThread, drvR3IntNetXmitWakeUp, 0, RTTHREADTYPE_IO, "INTNET-XMIT");
|
---|
1854 | AssertRCReturn(rc, rc);
|
---|
1855 |
|
---|
1856 | #ifdef VBOX_WITH_DRVINTNET_IN_R0
|
---|
1857 | /*
|
---|
1858 | * Resolve the ring-0 context interface addresses.
|
---|
1859 | */
|
---|
1860 | rc = pDrvIns->pHlpR3->pfnLdrGetR0InterfaceSymbols(pDrvIns, &pThis->INetworkUpR0, sizeof(pThis->INetworkUpR0),
|
---|
1861 | "drvIntNetUp_", PDMINETWORKUP_SYM_LIST);
|
---|
1862 | AssertLogRelRCReturn(rc, rc);
|
---|
1863 | #endif
|
---|
1864 |
|
---|
1865 | /*
|
---|
1866 | * Activate data transmission as early as possible
|
---|
1867 | */
|
---|
1868 | if (pThis->fActivateEarlyDeactivateLate)
|
---|
1869 | {
|
---|
1870 | ASMAtomicXchgSize(&pThis->enmRecvState, RECVSTATE_RUNNING);
|
---|
1871 | RTSemEventSignal(pThis->hRecvEvt);
|
---|
1872 |
|
---|
1873 | drvR3IntNetUpdateMacAddress(pThis);
|
---|
1874 | drvR3IntNetSetActive(pThis, true /* fActive */);
|
---|
1875 | }
|
---|
1876 |
|
---|
1877 | return rc;
|
---|
1878 | }
|
---|
1879 |
|
---|
1880 |
|
---|
1881 |
|
---|
1882 | /**
|
---|
1883 | * Internal networking transport driver registration record.
|
---|
1884 | */
|
---|
1885 | const PDMDRVREG g_DrvIntNet =
|
---|
1886 | {
|
---|
1887 | /* u32Version */
|
---|
1888 | PDM_DRVREG_VERSION,
|
---|
1889 | /* szName */
|
---|
1890 | "IntNet",
|
---|
1891 | /* szRCMod */
|
---|
1892 | "VBoxDDRC.rc",
|
---|
1893 | /* szR0Mod */
|
---|
1894 | "VBoxDDR0.r0",
|
---|
1895 | /* pszDescription */
|
---|
1896 | "Internal Networking Transport Driver",
|
---|
1897 | /* fFlags */
|
---|
1898 | #ifdef VBOX_WITH_DRVINTNET_IN_R0
|
---|
1899 | PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT | PDM_DRVREG_FLAGS_R0,
|
---|
1900 | #else
|
---|
1901 | PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT,
|
---|
1902 | #endif
|
---|
1903 | /* fClass. */
|
---|
1904 | PDM_DRVREG_CLASS_NETWORK,
|
---|
1905 | /* cMaxInstances */
|
---|
1906 | ~0U,
|
---|
1907 | /* cbInstance */
|
---|
1908 | sizeof(DRVINTNET),
|
---|
1909 | /* pfnConstruct */
|
---|
1910 | drvR3IntNetConstruct,
|
---|
1911 | /* pfnDestruct */
|
---|
1912 | drvR3IntNetDestruct,
|
---|
1913 | /* pfnRelocate */
|
---|
1914 | drvR3IntNetRelocate,
|
---|
1915 | /* pfnIOCtl */
|
---|
1916 | NULL,
|
---|
1917 | /* pfnPowerOn */
|
---|
1918 | drvR3IntNetPowerOn,
|
---|
1919 | /* pfnReset */
|
---|
1920 | NULL,
|
---|
1921 | /* pfnSuspend */
|
---|
1922 | drvR3IntNetSuspend,
|
---|
1923 | /* pfnResume */
|
---|
1924 | drvR3IntNetResume,
|
---|
1925 | /* pfnAttach */
|
---|
1926 | NULL,
|
---|
1927 | /* pfnDetach */
|
---|
1928 | NULL,
|
---|
1929 | /* pfnPowerOff */
|
---|
1930 | drvR3IntNetPowerOff,
|
---|
1931 | /* pfnSoftReset */
|
---|
1932 | NULL,
|
---|
1933 | /* u32EndVersion */
|
---|
1934 | PDM_DRVREG_VERSION
|
---|
1935 | };
|
---|
1936 |
|
---|
1937 | #endif /* IN_RING3 */
|
---|
1938 |
|
---|