tagging vde-2 version 2.3.2
[vde.git] / 2.3.2 / doc / VirtualBox-3.1.6_OSE_VDE.patch
blobd393db05389af7c92dad9a5416bb5adeee32b934
1 diff -Naur VirtualBox-3.1.6_OSE/src/VBox/Devices/Builtins.cpp VirtualBox-3.1.6_OSE_VDE/src/VBox/Devices/Builtins.cpp
2 --- VirtualBox-3.1.6_OSE/src/VBox/Devices/Builtins.cpp 2010-03-25 20:55:45.000000000 +0100
3 +++ VirtualBox-3.1.6_OSE_VDE/src/VBox/Devices/Builtins.cpp 2010-04-04 10:18:29.000000000 +0200
4 @@ -237,6 +237,13 @@
5 if (RT_FAILURE(rc))
6 return rc;
7 #endif
8 + /* ENABLE VDE */
9 +#if defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD)
10 + rc = pCallbacks->pfnRegister(pCallbacks, &g_DrvVDE);
11 + if (RT_FAILURE(rc))
12 + return rc;
13 +#endif
14 + /* /ENABLE VDE */
15 rc = pCallbacks->pfnRegister(pCallbacks, &g_DrvIntNet);
16 if (RT_FAILURE(rc))
17 return rc;
18 diff -Naur VirtualBox-3.1.6_OSE/src/VBox/Devices/Builtins.h VirtualBox-3.1.6_OSE_VDE/src/VBox/Devices/Builtins.h
19 --- VirtualBox-3.1.6_OSE/src/VBox/Devices/Builtins.h 2010-03-25 20:55:45.000000000 +0100
20 +++ VirtualBox-3.1.6_OSE_VDE/src/VBox/Devices/Builtins.h 2010-04-04 10:18:29.000000000 +0200
21 @@ -106,6 +106,9 @@
22 #if defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD)
23 extern const PDMDRVREG g_DrvHostInterface;
24 #endif
25 +#if defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD)
26 +extern const PDMDRVREG g_DrvVDE;
27 +#endif
28 extern const PDMDRVREG g_DrvIntNet;
29 extern const PDMDRVREG g_DrvNAT;
30 extern const PDMDRVREG g_DrvNetSniffer;
31 diff -Naur VirtualBox-3.1.6_OSE/src/VBox/Devices/Makefile.kmk VirtualBox-3.1.6_OSE_VDE/src/VBox/Devices/Makefile.kmk
32 --- VirtualBox-3.1.6_OSE/src/VBox/Devices/Makefile.kmk 2010-03-25 20:55:47.000000000 +0100
33 +++ VirtualBox-3.1.6_OSE_VDE/src/VBox/Devices/Makefile.kmk 2010-04-04 10:18:29.000000000 +0200
34 @@ -909,8 +909,10 @@
35 Audio/ossaudio.c
36 endif # l4
38 +# ENABLE VDE: Network/DrvVDE.cpp added
39 Drivers_SOURCES.linux = \
40 Network/DrvTAP.cpp \
41 + Network/DrvVDE.cpp \
42 Audio/ossaudio.c \
43 Parallel/DrvHostParallel.cpp \
44 Serial/DrvHostSerial.cpp
45 diff -Naur VirtualBox-3.1.6_OSE/src/VBox/Devices/Network/DrvVDE.cpp VirtualBox-3.1.6_OSE_VDE/src/VBox/Devices/Network/DrvVDE.cpp
46 --- VirtualBox-3.1.6_OSE/src/VBox/Devices/Network/DrvVDE.cpp 1970-01-01 01:00:00.000000000 +0100
47 +++ VirtualBox-3.1.6_OSE_VDE/src/VBox/Devices/Network/DrvVDE.cpp 2010-04-04 10:34:46.000000000 +0200
48 @@ -0,0 +1,561 @@
49 +/** $Id: DrvVDE.cpp $ */
50 +/** @file
51 + * VDE network transport driver.
52 + */
54 +/*
55 + * Copyright (C) 2010 Renzo Davoli. VirtualSquare. University of Bologna.
56 + * Copyright (C) 2006-2007 Sun Microsystems, Inc.
57 + *
58 + * This file is part of VirtualBox Open Source Edition (OSE), as
59 + * available from http://www.virtualbox.org. This file is free software;
60 + * you can redistribute it and/or modify it under the terms of the GNU
61 + * General Public License (GPL) as published by the Free Software
62 + * Foundation, in version 2 as it comes in the "COPYING" file of the
63 + * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
64 + * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
65 + *
66 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
67 + * Clara, CA 95054 USA or visit http://www.sun.com if you need
68 + * additional information or have any questions.
69 + */
71 +/*******************************************************************************
72 +* Header Files *
73 +*******************************************************************************/
74 +#define LOG_GROUP LOG_GROUP_DRV_TUN
75 +#include <VBox/log.h>
76 +#include <VBox/pdmdrv.h>
78 +#include <iprt/assert.h>
79 +#include <iprt/ctype.h>
80 +#include <iprt/file.h>
81 +#include <iprt/string.h>
82 +#include <iprt/path.h>
83 +#include <iprt/thread.h>
84 +#include <iprt/asm.h>
85 +#include <iprt/semaphore.h>
87 +#include <sys/ioctl.h>
88 +#include <sys/poll.h>
89 +#include <sys/fcntl.h>
90 +#include <errno.h>
91 +#include <unistd.h>
92 +#include <limits.h>
94 +#include "Builtins.h"
95 +#include "libvdeplug_dyn.h"
97 +struct vdepluglib vdeplughdl;
99 +/*******************************************************************************
100 +* Structures and Typedefs *
101 +*******************************************************************************/
102 +/**
103 + * Block driver instance data.
104 + */
105 +typedef struct DRVVDE
107 + /** The network interface. */
108 + PDMINETWORKCONNECTOR INetworkConnector;
109 + /** The network interface. */
110 + PPDMINETWORKPORT pPort;
111 + /** Pointer to the driver instance. */
112 + PPDMDRVINS pDrvIns;
113 + /** VDE device file handle. */
114 + RTFILE FileDevice;
115 + /** The configured VDE device name. */
116 + char *pszDeviceName;
117 + /** VDE setup application. */
118 + char *pszSetupApplication;
119 + /** VDE terminate application. */
120 + char *pszTerminateApplication;
121 + /** The write end of the control pipe. */
122 + RTFILE PipeWrite;
123 + /** The read end of the control pipe. */
124 + RTFILE PipeRead;
125 + /** Reader thread. */
126 + PPDMTHREAD pThread;
128 + VDECONN *vdeconn;
129 +#ifdef VBOX_WITH_STATISTICS
130 + /** Number of sent packets. */
131 + STAMCOUNTER StatPktSent;
132 + /** Number of sent bytes. */
133 + STAMCOUNTER StatPktSentBytes;
134 + /** Number of received packets. */
135 + STAMCOUNTER StatPktRecv;
136 + /** Number of received bytes. */
137 + STAMCOUNTER StatPktRecvBytes;
138 + /** Profiling packet transmit runs. */
139 + STAMPROFILE StatTransmit;
140 + /** Profiling packet receive runs. */
141 + STAMPROFILEADV StatReceive;
142 +#endif /* VBOX_WITH_STATISTICS */
144 +#ifdef LOG_ENABLED
145 + /** The nano ts of the last transfer. */
146 + uint64_t u64LastTransferTS;
147 + /** The nano ts of the last receive. */
148 + uint64_t u64LastReceiveTS;
149 +#endif
150 +} DRVVDE, *PDRVVDE;
153 +/** Converts a pointer to VDE::INetworkConnector to a PRDVVDE. */
154 +#define PDMINETWORKCONNECTOR_2_DRVVDE(pInterface) ( (PDRVVDE)((uintptr_t)pInterface - RT_OFFSETOF(DRVVDE, INetworkConnector)) )
157 +/*******************************************************************************
158 +* Internal Functions *
159 +*******************************************************************************/
161 +/**
162 + * Send data to the network.
164 + * @returns VBox status code.
165 + * @param pInterface Pointer to the interface structure containing the called function pointer.
166 + * @param pvBuf Data to send.
167 + * @param cb Number of bytes to send.
168 + * @thread EMT
169 + */
170 +static DECLCALLBACK(int) drvVDESend(PPDMINETWORKCONNECTOR pInterface, const void *pvBuf, size_t cb)
172 + PDRVVDE pThis = PDMINETWORKCONNECTOR_2_DRVVDE(pInterface);
173 + STAM_COUNTER_INC(&pThis->StatPktSent);
174 + STAM_COUNTER_ADD(&pThis->StatPktSentBytes, cb);
175 + STAM_PROFILE_START(&pThis->StatTransmit, a);
177 +#ifdef LOG_ENABLED
178 + uint64_t u64Now = RTTimeProgramNanoTS();
179 + LogFlow(("drvVDESend: %-4d bytes at %llu ns deltas: r=%llu t=%llu\n",
180 + cb, u64Now, u64Now - pThis->u64LastReceiveTS, u64Now - pThis->u64LastTransferTS));
181 + pThis->u64LastTransferTS = u64Now;
182 +#endif
183 + Log2(("drvVDESend: pvBuf=%p cb=%#x\n"
184 + "%.*Rhxd\n",
185 + pvBuf, cb, cb, pvBuf));
187 + int rc = vdeplughdl.vde_send(pThis->vdeconn, pvBuf, cb, 0);
189 + STAM_PROFILE_STOP(&pThis->StatTransmit, a);
190 + AssertRC(rc);
191 + return rc;
195 +/**
196 + * Set promiscuous mode.
198 + * This is called when the promiscuous mode is set. This means that there doesn't have
199 + * to be a mode change when it's called.
201 + * @param pInterface Pointer to the interface structure containing the called function pointer.
202 + * @param fPromiscuous Set if the adaptor is now in promiscuous mode. Clear if it is not.
203 + * @thread EMT
204 + */
205 +static DECLCALLBACK(void) drvVDESetPromiscuousMode(PPDMINETWORKCONNECTOR pInterface, bool fPromiscuous)
207 + LogFlow(("drvVDESetPromiscuousMode: fPromiscuous=%d\n", fPromiscuous));
208 + /* nothing to do */
212 +/**
213 + * Notification on link status changes.
215 + * @param pInterface Pointer to the interface structure containing the called function pointer.
216 + * @param enmLinkState The new link state.
217 + * @thread EMT
218 + */
219 +static DECLCALLBACK(void) drvVDENotifyLinkChanged(PPDMINETWORKCONNECTOR pInterface, PDMNETWORKLINKSTATE enmLinkState)
221 + LogFlow(("drvNATNotifyLinkChanged: enmLinkState=%d\n", enmLinkState));
222 + /** @todo take action on link down and up. Stop the polling and such like. */
226 +/**
227 + * Asynchronous I/O thread for handling receive.
229 + * @returns VINF_SUCCESS (ignored).
230 + * @param Thread Thread handle.
231 + * @param pvUser Pointer to a DRVVDE structure.
232 + */
233 +static DECLCALLBACK(int) drvVDEAsyncIoThread(PPDMDRVINS pDrvIns, PPDMTHREAD pThread)
235 + PDRVVDE pThis = PDMINS_2_DATA(pDrvIns, PDRVVDE);
236 + LogFlow(("drvVDEAsyncIoThread: pThis=%p\n", pThis));
238 + if (pThread->enmState == PDMTHREADSTATE_INITIALIZING)
239 + return VINF_SUCCESS;
241 + STAM_PROFILE_ADV_START(&pThis->StatReceive, a);
243 + /*
244 + * Polling loop.
245 + */
246 + while (pThread->enmState == PDMTHREADSTATE_RUNNING)
248 + /*
249 + * Wait for something to become available.
250 + */
251 + struct pollfd aFDs[2];
252 + aFDs[0].fd = vdeplughdl.vde_datafd(pThis->vdeconn);
253 + aFDs[0].events = POLLIN | POLLPRI;
254 + aFDs[0].revents = 0;
255 + aFDs[1].fd = pThis->PipeRead;
256 + aFDs[1].events = POLLIN | POLLPRI | POLLERR | POLLHUP;
257 + aFDs[1].revents = 0;
258 + STAM_PROFILE_ADV_STOP(&pThis->StatReceive, a);
259 + errno=0;
260 + int rc = poll(&aFDs[0], RT_ELEMENTS(aFDs), -1 /* infinite */);
262 + /* this might have changed in the meantime */
263 + if (pThread->enmState != PDMTHREADSTATE_RUNNING)
264 + break;
266 + STAM_PROFILE_ADV_START(&pThis->StatReceive, a);
267 + if ( rc > 0
268 + && (aFDs[0].revents & (POLLIN | POLLPRI))
269 + && !aFDs[1].revents)
271 + /*
272 + * Read the frame.
273 + */
274 + char achBuf[16384];
275 + ssize_t cbRead = 0;
276 + cbRead = vdeplughdl.vde_recv(pThis->vdeconn, achBuf, sizeof(achBuf), 0);
277 + if (cbRead >= 0)
279 + /*
280 + * Wait for the device to have space for this frame.
281 + * Most guests use frame-sized receive buffers, hence non-zero cbMax
282 + * automatically means there is enough room for entire frame. Some
283 + * guests (eg. Solaris) use large chains of small receive buffers
284 + * (each 128 or so bytes large). We will still start receiving as soon
285 + * as cbMax is non-zero because:
286 + * - it would be quite expensive for pfnCanReceive to accurately
287 + * determine free receive buffer space
288 + * - if we were waiting for enough free buffers, there is a risk
289 + * of deadlocking because the guest could be waiting for a receive
290 + * overflow error to allocate more receive buffers
291 + */
292 + STAM_PROFILE_ADV_STOP(&pThis->StatReceive, a);
293 + int rc = pThis->pPort->pfnWaitReceiveAvail(pThis->pPort, RT_INDEFINITE_WAIT);
295 + STAM_PROFILE_ADV_START(&pThis->StatReceive, a);
297 + /*
298 + * A return code != VINF_SUCCESS means that we were woken up during a VM
299 + * state transistion. Drop the packet and wait for the next one.
300 + */
301 + if (RT_FAILURE(rc))
302 + continue;
304 + /*
305 + * Pass the data up.
306 + */
307 +#ifdef LOG_ENABLED
308 + uint64_t u64Now = RTTimeProgramNanoTS();
309 + LogFlow(("drvVDEAsyncIoThread: %-4d bytes at %llu ns deltas: r=%llu t=%llu\n",
310 + cbRead, u64Now, u64Now - pThis->u64LastReceiveTS, u64Now - pThis->u64LastTransferTS));
311 + pThis->u64LastReceiveTS = u64Now;
312 +#endif
313 + Log2(("drvVDEAsyncIoThread: cbRead=%#x\n" "%.*Rhxd\n", cbRead, cbRead, achBuf));
314 + STAM_COUNTER_INC(&pThis->StatPktRecv);
315 + STAM_COUNTER_ADD(&pThis->StatPktRecvBytes, cbRead);
316 + rc = pThis->pPort->pfnReceive(pThis->pPort, achBuf, cbRead);
317 + AssertRC(rc);
319 + else
321 + LogFlow(("drvVDEAsyncIoThread: RTFileRead -> %Rrc\n", rc));
322 + if (rc == VERR_INVALID_HANDLE)
323 + break;
324 + RTThreadYield();
327 + else if ( rc > 0
328 + && aFDs[1].revents)
330 + LogFlow(("drvVDEAsyncIoThread: Control message: enmState=%d revents=%#x\n", pThread->enmState, aFDs[1].revents));
331 + if (aFDs[1].revents & (POLLHUP | POLLERR | POLLNVAL))
332 + break;
334 + /* drain the pipe */
335 + char ch;
336 + size_t cbRead;
337 + RTFileRead(pThis->PipeRead, &ch, 1, &cbRead);
339 + else
341 + /*
342 + * poll() failed for some reason. Yield to avoid eating too much CPU.
344 + * EINTR errors have been seen frequently. They should be harmless, even
345 + * if they are not supposed to occur in our setup.
346 + */
347 + if (errno == EINTR)
348 + Log(("rc=%d revents=%#x,%#x errno=%p %s\n", rc, aFDs[0].revents, aFDs[1].revents, errno, strerror(errno)));
349 + else
350 + AssertMsgFailed(("rc=%d revents=%#x,%#x errno=%p %s\n", rc, aFDs[0].revents, aFDs[1].revents, errno, strerror(errno)));
351 + RTThreadYield();
356 + LogFlow(("drvVDEAsyncIoThread: returns %Rrc\n", VINF_SUCCESS));
357 + STAM_PROFILE_ADV_STOP(&pThis->StatReceive, a);
358 + return VINF_SUCCESS;
362 +/**
363 + * Unblock the send thread so it can respond to a state change.
365 + * @returns VBox status code.
366 + * @param pDevIns The pcnet device instance.
367 + * @param pThread The send thread.
368 + */
369 +static DECLCALLBACK(int) drvVDEAsyncIoWakeup(PPDMDRVINS pDrvIns, PPDMTHREAD pThread)
371 + PDRVVDE pThis = PDMINS_2_DATA(pDrvIns, PDRVVDE);
373 + int rc = RTFileWrite(pThis->PipeWrite, "", 1, NULL);
374 + AssertRC(rc);
376 + return VINF_SUCCESS;
380 +/**
381 + * Queries an interface to the driver.
383 + * @returns Pointer to interface.
384 + * @returns NULL if the interface was not supported by the driver.
385 + * @param pInterface Pointer to this interface structure.
386 + * @param enmInterface The requested interface identification.
387 + * @thread Any thread.
388 + */
389 +static DECLCALLBACK(void *) drvVDEQueryInterface(PPDMIBASE pInterface, PDMINTERFACE enmInterface)
391 + PPDMDRVINS pDrvIns = PDMIBASE_2_PDMDRV(pInterface);
392 + PDRVVDE pThis = PDMINS_2_DATA(pDrvIns, PDRVVDE);
393 + switch (enmInterface)
395 + case PDMINTERFACE_BASE:
396 + return &pDrvIns->IBase;
397 + case PDMINTERFACE_NETWORK_CONNECTOR:
398 + return &pThis->INetworkConnector;
399 + default:
400 + return NULL;
405 +/**
406 + * Destruct a driver instance.
408 + * Most VM resources are freed by the VM. This callback is provided so that any non-VM
409 + * resources can be freed correctly.
411 + * @param pDrvIns The driver instance data.
412 + */
413 +static DECLCALLBACK(void) drvVDEDestruct(PPDMDRVINS pDrvIns)
415 + LogFlow(("drvVDEDestruct\n"));
416 + PDRVVDE pThis = PDMINS_2_DATA(pDrvIns, PDRVVDE);
418 + /*
419 + * Terminate the control pipe.
420 + */
421 + if (pThis->PipeWrite != NIL_RTFILE)
423 + int rc = RTFileClose(pThis->PipeWrite);
424 + AssertRC(rc);
425 + pThis->PipeWrite = NIL_RTFILE;
427 + if (pThis->PipeRead != NIL_RTFILE)
429 + int rc = RTFileClose(pThis->PipeRead);
430 + AssertRC(rc);
431 + pThis->PipeRead = NIL_RTFILE;
434 + MMR3HeapFree(pThis->pszDeviceName);
435 + MMR3HeapFree(pThis->pszSetupApplication);
436 + MMR3HeapFree(pThis->pszTerminateApplication);
438 +#ifdef VBOX_WITH_STATISTICS
439 + /*
440 + * Deregister statistics.
441 + */
442 + PDMDrvHlpSTAMDeregister(pDrvIns, &pThis->StatPktSent);
443 + PDMDrvHlpSTAMDeregister(pDrvIns, &pThis->StatPktSentBytes);
444 + PDMDrvHlpSTAMDeregister(pDrvIns, &pThis->StatPktRecv);
445 + PDMDrvHlpSTAMDeregister(pDrvIns, &pThis->StatPktRecvBytes);
446 + PDMDrvHlpSTAMDeregister(pDrvIns, &pThis->StatTransmit);
447 + PDMDrvHlpSTAMDeregister(pDrvIns, &pThis->StatReceive);
448 +#endif /* VBOX_WITH_STATISTICS */
452 +/**
453 + * Construct a VDE network transport driver instance.
455 + * @copydoc FNPDMDRVCONSTRUCT
456 + */
457 +static DECLCALLBACK(int) drvVDEConstruct(PPDMDRVINS pDrvIns, PCFGMNODE pCfgHandle, uint32_t fFlags)
459 + PDRVVDE pThis = PDMINS_2_DATA(pDrvIns, PDRVVDE);
461 + /*
462 + * Init the static parts.
463 + */
464 + pThis->pDrvIns = pDrvIns;
465 + pThis->pszDeviceName = NULL;
466 + pThis->pszSetupApplication = NULL;
467 + pThis->pszTerminateApplication = NULL;
469 + /* IBase */
470 + pDrvIns->IBase.pfnQueryInterface = drvVDEQueryInterface;
471 + /* INetwork */
472 + pThis->INetworkConnector.pfnSend = drvVDESend;
473 + pThis->INetworkConnector.pfnSetPromiscuousMode = drvVDESetPromiscuousMode;
474 + pThis->INetworkConnector.pfnNotifyLinkChanged = drvVDENotifyLinkChanged;
476 + if (!CFGMR3AreValuesValid(pCfgHandle,
477 + "Network\0"
478 + "Trunk\0"
479 + "TrunkType\0"
480 + "ReceiveBufferSize\0"
481 + "SendBufferSize\0"
482 + "RestrictAccess\0"
483 + "SharedMacOnWire\0"
484 + "IgnoreAllPromisc\0"
485 + "QuietlyIgnoreAllPromisc\0"
486 + "IgnoreClientPromisc\0"
487 + "QuietlyIgnoreClientPromisc\0"
488 + "IgnoreTrunkWirePromisc\0"
489 + "QuietlyIgnoreTrunkWirePromisc\0"
490 + "IgnoreTrunkHostPromisc\0"
491 + "QuietlyIgnoreTrunkHostPromisc\0"
492 + "IsService\0"))
493 + return VERR_PDM_DRVINS_UNKNOWN_CFG_VALUES;
495 + /*
496 + * Query the network port interface.
497 + */
498 + pThis->pPort = (PPDMINETWORKPORT)pDrvIns->pUpBase->pfnQueryInterface(pDrvIns->pUpBase, PDMINTERFACE_NETWORK_PORT);
499 + if (!pThis->pPort)
501 + AssertMsgFailed(("Configuration error: the above device/driver didn't export the network port interface!\n"));
502 + return VERR_PDM_MISSING_INTERFACE_ABOVE;
505 + char szNetwork[PATH_MAX]; /* PATH_MAX */
506 + int rc = CFGMR3QueryString(pCfgHandle, "Network", szNetwork, sizeof(szNetwork));
507 + if (RT_FAILURE(rc))
508 + *szNetwork=0;
510 + /* LogRel(("VDEXXXXXX %s\n",szNetwork));*/
512 + /*
513 + * Read the configuration.
514 + */
515 + if (vdeplughdl.dl_handle == NULL)
516 + libvdeplug_dynopen(vdeplughdl);
517 + if (vdeplughdl.dl_handle == NULL) {
518 + return PDMDrvHlpVMSetError(pThis->pDrvIns, VERR_PDM_HIF_OPEN_FAILED, RT_SRC_POS,
519 + N_("VDEplug library: not found"));
521 + pThis->vdeconn=vdeplughdl.vde_open(szNetwork,"VirtualBOX",NULL);
522 + if (pThis->vdeconn == NULL) {
523 + return PDMDrvHlpVMSetError(pThis->pDrvIns, VERR_PDM_HIF_OPEN_FAILED, RT_SRC_POS,
524 + N_("Failed to connect to the VDE SWITCH"));
528 + rc = VINF_SUCCESS;
530 + /*
531 + * Create the control pipe.
532 + */
533 + int fds[2];
534 + if (pipe(&fds[0]) != 0) /** @todo RTPipeCreate() or something... */
536 + int rc = RTErrConvertFromErrno(errno);
537 + AssertRC(rc);
538 + return rc;
540 + pThis->PipeRead = fds[0];
541 + pThis->PipeWrite = fds[1];
543 + /*
544 + * Create the async I/O thread.
545 + */
546 + rc = PDMDrvHlpPDMThreadCreate(pDrvIns, &pThis->pThread, pThis, drvVDEAsyncIoThread, drvVDEAsyncIoWakeup, 128 * _1K, RTTHREADTYPE_IO, "VDE");
547 + AssertRCReturn(rc, rc);
549 +#ifdef VBOX_WITH_STATISTICS
550 + /*
551 + * Statistics.
552 + */
553 + PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->StatPktSent, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES, "Number of sent packets.", "/Drivers/VDE%d/Packets/Sent", pDrvIns->iInstance);
554 + PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->StatPktSentBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Number of sent bytes.", "/Drivers/VDE%d/Bytes/Sent", pDrvIns->iInstance);
555 + PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->StatPktRecv, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES, "Number of received packets.", "/Drivers/VDE%d/Packets/Received", pDrvIns->iInstance);
556 + PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->StatPktRecvBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Number of received bytes.", "/Drivers/VDE%d/Bytes/Received", pDrvIns->iInstance);
557 + PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->StatTransmit, STAMTYPE_PROFILE, STAMVISIBILITY_ALWAYS, STAMUNIT_TICKS_PER_CALL, "Profiling packet transmit runs.", "/Drivers/VDE%d/Transmit", pDrvIns->iInstance);
558 + PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->StatReceive, STAMTYPE_PROFILE, STAMVISIBILITY_ALWAYS, STAMUNIT_TICKS_PER_CALL, "Profiling packet receive runs.", "/Drivers/VDE%d/Receive", pDrvIns->iInstance);
559 +#endif /* VBOX_WITH_STATISTICS */
561 + return rc;
565 +/**
566 + * VDE network transport driver registration record.
567 + */
568 +const PDMDRVREG g_DrvVDE =
570 + /* u32Version */
571 + PDM_DRVREG_VERSION,
572 + /* szDriverName */
573 + "VDE",
574 + /* pszDescription */
575 + "VDE Network Transport Driver",
576 + /* fFlags */
577 + PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT,
578 + /* fClass. */
579 + PDM_DRVREG_CLASS_NETWORK,
580 + /* cMaxInstances */
581 + ~0,
582 + /* cbInstance */
583 + sizeof(DRVVDE),
584 + /* pfnConstruct */
585 + drvVDEConstruct,
586 + /* pfnDestruct */
587 + drvVDEDestruct,
588 + /* pfnIOCtl */
589 + NULL,
590 + /* pfnPowerOn */
591 + NULL,
592 + /* pfnReset */
593 + NULL,
594 + /* pfnSuspend */
595 + NULL, /** @todo Do power on, suspend and resume handlers! */
596 + /* pfnResume */
597 + NULL,
598 + /* pfnAttach */
599 + NULL,
600 + /* pfnDetach */
601 + NULL,
602 + /* pfnPowerOff */
603 + NULL,
604 + /* pfnSoftReset */
605 + NULL,
606 + /* u32EndVersion */
607 + PDM_DRVREG_VERSION
610 diff -Naur VirtualBox-3.1.6_OSE/src/VBox/Devices/Network/libvdeplug_dyn.h VirtualBox-3.1.6_OSE_VDE/src/VBox/Devices/Network/libvdeplug_dyn.h
611 --- VirtualBox-3.1.6_OSE/src/VBox/Devices/Network/libvdeplug_dyn.h 1970-01-01 01:00:00.000000000 +0100
612 +++ VirtualBox-3.1.6_OSE_VDE/src/VBox/Devices/Network/libvdeplug_dyn.h 2010-04-04 10:34:54.000000000 +0200
613 @@ -0,0 +1,119 @@
615 + * libvdeplug - A library to connect to a VDE Switch.
616 + * dynamic loading version (requires libdl).
618 + * Copyright (C) 2006,2007,2010 Renzo Davoli, University of Bologna
620 + * This library is free software; you can redistribute it and/or modify it
621 + * under the terms of the GNU Lesser General Public License as published by
622 + * the Free Software Foundation version 2.1 of the License, or (at
623 + * your option) any later version.
625 + * This library is distributed in the hope that it will be useful, but
626 + * WITHOUT ANY WARRANTY; without even the implied warranty of
627 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
628 + * General Public License for more details.
630 + * You should have received a copy of the GNU Lesser General Public
631 + * License along with this library; if not, write to the Free Software
632 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
633 + */
635 +/* Use this include file when you need to write an application that can
636 + * benefit from vde when available.
637 + * Linking libvdeplug to your programs you force your application users
638 + * to have the library installed (otherway the dynamic linker complies
639 + * and the program does not start).
641 + *
642 + * usage:
643 + * define a struct vdepluglib variable;
644 + * eg:
645 + * struct vdepluglib vdeplug;
647 + * test the availability of the library and load it:
649 + * libvdeplug_dynopen(vdeplug);
650 + * if vdeplug.dl_handle is not NULL the library is ready otherwise it is
651 + * not available in the target system.
653 + * if libvdeplug does exist the library function can be called
654 + * in this way:
655 + * vdeplug.vde_open(....)
656 + * vdeplug.vde_read(....)
657 + * vdeplug.vde_open(....)
658 + * vdeplug.vde_recv(....)
659 + * vdeplug.vde_send(....)
660 + * vdeplug.vde_datafd(....)
661 + * vdeplug.vde_ctlfd(....)
662 + * vdeplug.vde_close(....)
663 + * libvdeplug_dynclose(vdeplug) can be used to deallocate the dynamic library
664 + * when needed.
665 + *************************************************/
667 +#ifndef _VDEDYNLIB_H
668 +#define _VDEDYNLIB_H
669 +#include <sys/types.h>
670 +#include <dlfcn.h>
671 +#define LIBVDEPLUG_INTERFACE_VERSION 1
673 +struct vdeconn;
675 +typedef struct vdeconn VDECONN;
677 +/* Open a VDE connection.
678 + * vde_open_options:
679 + * port: connect to a specific port of the switch (0=any)
680 + * group: change the ownership of the communication port to a specific group
681 + * (NULL=no change)
682 + * mode: set communication port mode (if 0 standard socket mode applies)
683 + */
684 +struct vde_open_args {
685 + int port;
686 + char *group;
687 + mode_t mode;
690 +/* vde_open args:
691 + * vde_switch: switch id (path)
692 + * descr: description (it will appear in the port description on the switch)
693 + */
694 +#define vde_open(vde_switch,descr,open_args) \
695 + vde_open_real((vde_switch),(descr),LIBVDEPLUG_INTERFACE_VERSION,(open_args))
697 +struct vdepluglib {
698 + void *dl_handle;
699 + VDECONN * (*vde_open_real)(const char *vde_switch,char *descr,int interface_version, struct vde_open_args *open_args);
700 + size_t (* vde_recv)(VDECONN *conn,void *buf,size_t len,int flags);
701 + size_t (* vde_send)(VDECONN *conn,const void *buf,size_t len,int flags);
702 + int (* vde_datafd)(VDECONN *conn);
703 + int (* vde_ctlfd)(VDECONN *conn);
704 + int (* vde_close)(VDECONN *conn);
707 +typedef VDECONN * (* VDE_OPEN_REAL_T)(const char *vde_switch,char *descr,int interface_version, struct vde_open_args *open_args);
708 +typedef size_t (* VDE_RECV_T)(VDECONN *conn,void *buf,size_t len,int flags);
709 +typedef size_t (* VDE_SEND_T)(VDECONN *conn,const void *buf,size_t len,int flags);
710 +typedef int (* VDE_INT_FUN)(VDECONN *conn);
711 +#define libvdeplug_dynopen(x) do { \
712 + (x).dl_handle=dlopen("libvdeplug.so",RTLD_NOW); \
713 + if ((x).dl_handle) { \
714 + (x).vde_open_real=(VDE_OPEN_REAL_T) dlsym((x).dl_handle,"vde_open_real"); \
715 + (x).vde_recv=(VDE_RECV_T) dlsym((x).dl_handle,"vde_recv"); \
716 + (x).vde_send=(VDE_SEND_T) dlsym((x).dl_handle,"vde_send"); \
717 + (x).vde_datafd=(VDE_INT_FUN) dlsym((x).dl_handle,"vde_datafd"); \
718 + (x).vde_ctlfd=(VDE_INT_FUN) dlsym((x).dl_handle,"vde_ctlfd"); \
719 + (x).vde_close=(VDE_INT_FUN) dlsym((x).dl_handle,"vde_close"); \
720 + } else { \
721 + (x).vde_open_real=NULL; \
722 + (x).vde_send= NULL; \
723 + (x).vde_recv= NULL; \
724 + (x).vde_datafd= (x).vde_ctlfd= (x).vde_close= NULL; \
725 + }\
726 + } while (0)
728 +#define libvdeplug_dynclose(x) do { \
729 + dlclose((x).dl_handle); \
730 + } while (0)
732 +#endif
733 diff -Naur VirtualBox-3.1.6_OSE/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.cpp VirtualBox-3.1.6_OSE_VDE/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.cpp
734 --- VirtualBox-3.1.6_OSE/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.cpp 2010-03-25 20:56:15.000000000 +0100
735 +++ VirtualBox-3.1.6_OSE_VDE/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.cpp 2010-04-04 10:18:34.000000000 +0200
736 @@ -1849,6 +1849,11 @@
737 else if (type == KNetworkAttachmentType_HostOnly)
738 attType = attType.arg (tr ("Host-only adapter, '%1'",
739 "details report (network)").arg (adapter.GetHostInterface()));
740 + /* ENABLE VDE */
741 + else if (type == KNetworkAttachmentType_VDE)
742 + attType = attType.arg (tr ("VDE network, '%1'",
743 + "details report (network)").arg (adapter.GetVDENetwork()));
744 + /* /ENABLE VDE */
745 else
746 attType = attType.arg (vboxGlobal().toString (type));
748 @@ -2796,6 +2801,10 @@
749 tr ("Internal Network", "NetworkAttachmentType");
750 mNetworkAttachmentTypes [KNetworkAttachmentType_HostOnly] =
751 tr ("Host-only Adapter", "NetworkAttachmentType");
752 + /* ENABLE VDE */
753 + mNetworkAttachmentTypes [KNetworkAttachmentType_VDE] =
754 + tr ("VDE Adapter", "NetworkAttachmentType");
755 + /* /ENABLE VDE */
757 mClipboardTypes [KClipboardMode_Disabled] =
758 tr ("Disabled", "ClipboardType");
759 diff -Naur VirtualBox-3.1.6_OSE/src/VBox/Frontends/VirtualBox/src/settings/vm/VBoxVMSettingsNetwork.cpp VirtualBox-3.1.6_OSE_VDE/src/VBox/Frontends/VirtualBox/src/settings/vm/VBoxVMSettingsNetwork.cpp
760 --- VirtualBox-3.1.6_OSE/src/VBox/Frontends/VirtualBox/src/settings/vm/VBoxVMSettingsNetwork.cpp 2010-03-25 20:56:16.000000000 +0100
761 +++ VirtualBox-3.1.6_OSE_VDE/src/VBox/Frontends/VirtualBox/src/settings/vm/VBoxVMSettingsNetwork.cpp 2010-04-04 10:18:34.000000000 +0200
762 @@ -103,6 +103,12 @@
763 mHoiName = mAdapter.GetHostInterface();
764 if (mHoiName.isEmpty()) mHoiName = QString::null;
765 break;
766 + /* ENABLE VDE */
767 + case KNetworkAttachmentType_VDE:
768 + mVDEName = mAdapter.GetVDENetwork();
769 + if (mVDEName.isEmpty()) mVDEName = QString::null;
770 + break;
771 + /* /ENABLE VDE */
772 default:
773 break;
775 @@ -143,6 +149,12 @@
776 mAdapter.SetHostInterface (alternativeName());
777 mAdapter.AttachToHostOnlyInterface();
778 break;
779 + /* ENABLE VDE */
780 + case KNetworkAttachmentType_VDE:
781 + mAdapter.SetVDENetwork (alternativeName());
782 + mAdapter.AttachToVDE();
783 + break;
784 + /* /ENABLE VDE */
785 default:
786 break;
788 @@ -255,6 +267,11 @@
789 case KNetworkAttachmentType_HostOnly:
790 result = mHoiName;
791 break;
792 + /* ENABLE VDE*/
793 + case KNetworkAttachmentType_VDE:
794 + result = mVDEName;
795 + break;
796 + /* /ENABLE VDE*/
797 default:
798 break;
800 @@ -331,6 +348,13 @@
801 mCbAdapterName->insertItems (0, mParent->hoiList());
802 mCbAdapterName->setEditable (false);
803 break;
804 + /* ENABLE VDE */
805 + case KNetworkAttachmentType_VDE:
806 + mCbAdapterName->insertItem(0, alternativeName());
807 + mCbAdapterName->setEditable (true);
808 + mCbAdapterName->setCompleter (0);
809 + break;
810 + /* /ENABLE VDE */
811 default:
812 break;
814 @@ -430,6 +454,20 @@
815 mHoiName = newName;
816 break;
818 + /* ENABLE VDE */
819 + case KNetworkAttachmentType_VDE:
821 + QString newName ((mCbAdapterName->itemData (mCbAdapterName->currentIndex()).toString() ==
822 + QString (emptyItemCode) &&
823 + mCbAdapterName->currentText() ==
824 + mCbAdapterName->itemText (mCbAdapterName->currentIndex())) ||
825 + mCbAdapterName->currentText().isEmpty() ?
826 + QString::null : mCbAdapterName->currentText());
827 + if (mVDEName != newName)
828 + mVDEName = newName;
829 + break;
831 + /* /ENABLE VDE */
832 default:
833 break;
835 @@ -546,6 +584,14 @@
836 KNetworkAttachmentType_HostOnly);
837 mCbAttachmentType->setItemData (4,
838 mCbAttachmentType->itemText (4), Qt::ToolTipRole);
839 + /* ENABLE VDE */
840 + mCbAttachmentType->insertItem (5,
841 + vboxGlobal().toString (KNetworkAttachmentType_VDE));
842 + mCbAttachmentType->setItemData (5,
843 + KNetworkAttachmentType_VDE);
844 + mCbAttachmentType->setItemData (5,
845 + mCbAttachmentType->itemText (5), Qt::ToolTipRole);
846 + /* /ENABLE VDE */
848 /* Set the old value */
849 mCbAttachmentType->setCurrentIndex (currentAttachment);
850 diff -Naur VirtualBox-3.1.6_OSE/src/VBox/Frontends/VirtualBox/src/settings/vm/VBoxVMSettingsNetwork.h VirtualBox-3.1.6_OSE_VDE/src/VBox/Frontends/VirtualBox/src/settings/vm/VBoxVMSettingsNetwork.h
851 --- VirtualBox-3.1.6_OSE/src/VBox/Frontends/VirtualBox/src/settings/vm/VBoxVMSettingsNetwork.h 2010-03-25 20:56:16.000000000 +0100
852 +++ VirtualBox-3.1.6_OSE_VDE/src/VBox/Frontends/VirtualBox/src/settings/vm/VBoxVMSettingsNetwork.h 2010-04-04 10:18:34.000000000 +0200
853 @@ -76,6 +76,9 @@
854 QString mBrgName;
855 QString mIntName;
856 QString mHoiName;
857 + /* ENABLE VDE */
858 + QString mVDEName;
859 + /* /ENABLE VDE */
861 bool mPolished;
862 bool mDisableStaticControls;
863 @@ -92,6 +95,7 @@
864 QStringList brgList (bool aRefresh = false);
865 QStringList intList (bool aRefresh = false);
866 QStringList hoiList (bool aRefresh = false);
867 + QStringList vdeList (bool aRefresh = false);
869 protected:
871 diff -Naur VirtualBox-3.1.6_OSE/src/VBox/Frontends/VirtualBox/src/settings/vm/VBoxVMSettingsNetwork.ui VirtualBox-3.1.6_OSE_VDE/src/VBox/Frontends/VirtualBox/src/settings/vm/VBoxVMSettingsNetwork.ui
872 --- VirtualBox-3.1.6_OSE/src/VBox/Frontends/VirtualBox/src/settings/vm/VBoxVMSettingsNetwork.ui 2010-03-25 20:56:16.000000000 +0100
873 +++ VirtualBox-3.1.6_OSE_VDE/src/VBox/Frontends/VirtualBox/src/settings/vm/VBoxVMSettingsNetwork.ui 2010-04-04 10:18:34.000000000 +0200
874 @@ -110,7 +110,7 @@
875 </sizepolicy>
876 </property>
877 <property name="whatsThis" >
878 - <string>Selects the name of the network adapter for &lt;b&gt;Bridged Adapter&lt;/b&gt; or &lt;b&gt;Host-only Adapter&lt;/b&gt; attachments and the name of the network &lt;b&gt;Internal Network&lt;/b&gt; attachments.</string>
879 + <string>Selects the name of the network adapter for &lt;b&gt;Bridged Adapter&lt;/b&gt; or &lt;b&gt;Host-only Adapter&lt;/b&gt; attachments and the name of the network &lt;b&gt;Internal Network&lt;/b&gt; or the switch for &lt;b&gt;VDE&lt;/b&gt; attachments.</string>
880 </property>
881 </widget>
882 </item>
883 diff -Naur VirtualBox-3.1.6_OSE/src/VBox/Main/cbinding/VBoxCAPI_v3_0.h VirtualBox-3.1.6_OSE_VDE/src/VBox/Main/cbinding/VBoxCAPI_v3_0.h
884 --- VirtualBox-3.1.6_OSE/src/VBox/Main/cbinding/VBoxCAPI_v3_0.h 2010-03-25 20:56:39.000000000 +0100
885 +++ VirtualBox-3.1.6_OSE_VDE/src/VBox/Main/cbinding/VBoxCAPI_v3_0.h 2010-04-04 10:18:33.000000000 +0200
886 @@ -1657,6 +1657,7 @@
887 NetworkAttachmentType_Bridged = 2,
888 NetworkAttachmentType_Internal = 3,
889 NetworkAttachmentType_HostOnly = 4
890 + NetworkAttachmentType_VDE = 5
892 /* End of enum NetworkAttachmentType Declaration */
894 @@ -4500,6 +4501,11 @@
895 nsresult (*GetNATNetwork)(INetworkAdapter *pThis, PRUnichar * *NATNetwork);
896 nsresult (*SetNATNetwork)(INetworkAdapter *pThis, PRUnichar * NATNetwork);
898 + /* ENABLE VDE */
899 + nsresult (*GetVDENetwork)(INetworkAdapter *pThis, PRUnichar * *NATNetwork);
900 + nsresult (*SetVDENetwork)(INetworkAdapter *pThis, PRUnichar * NATNetwork);
901 + /* /ENABLE VDE */
903 nsresult (*GetCableConnected)(INetworkAdapter *pThis, PRBool *cableConnected);
904 nsresult (*SetCableConnected)(INetworkAdapter *pThis, PRBool cableConnected);
906 diff -Naur VirtualBox-3.1.6_OSE/src/VBox/Main/ConsoleImpl2.cpp VirtualBox-3.1.6_OSE_VDE/src/VBox/Main/ConsoleImpl2.cpp
907 --- VirtualBox-3.1.6_OSE/src/VBox/Main/ConsoleImpl2.cpp 2010-03-25 20:56:37.000000000 +0100
908 +++ VirtualBox-3.1.6_OSE_VDE/src/VBox/Main/ConsoleImpl2.cpp 2010-04-04 10:18:32.000000000 +0200
909 @@ -2798,6 +2798,29 @@
910 break;
913 + /* ENABLE VDE */
914 + case NetworkAttachmentType_VDE:
916 + hrc = aNetworkAdapter->COMGETTER(VDENetwork)(&str); H();
917 +#if 0
918 + if (str) {
919 + Utf8Str strUtf8 = str;
920 + LogRel(("VDE Network %s\n",(char *)strUtf8.raw()));
922 +#endif
923 + rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
924 + rc = CFGMR3InsertString(pLunL0, "Driver", "VDE"); RC_CHECK();
925 + rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
926 + if (str && *str) {
927 + rc = CFGMR3InsertStringW(pCfg, "Network", str); RC_CHECK();
928 + networkName = str;
930 + rc = CFGMR3InsertInteger(pCfg, "TrunkType", kIntNetTrunkType_WhateverNone); RC_CHECK();
931 + STR_FREE();
932 + break;
934 + /* /ENABLE VDE */
936 default:
937 AssertMsgFailed(("should not get here!\n"));
938 break;
939 diff -Naur VirtualBox-3.1.6_OSE/src/VBox/Main/idl/VirtualBox.xidl VirtualBox-3.1.6_OSE_VDE/src/VBox/Main/idl/VirtualBox.xidl
940 --- VirtualBox-3.1.6_OSE/src/VBox/Main/idl/VirtualBox.xidl 2010-03-25 20:56:40.000000000 +0100
941 +++ VirtualBox-3.1.6_OSE_VDE/src/VBox/Main/idl/VirtualBox.xidl 2010-04-04 10:18:33.000000000 +0200
942 @@ -11240,6 +11240,9 @@
943 <const name="Bridged" value="2"/>
944 <const name="Internal" value="3"/>
945 <const name="HostOnly" value="4"/>
946 + <!-- ENABLE VDE -->
947 + <const name="VDE" value="5"/>
948 + <!-- /ENABLE VDE -->
949 </enum>
951 <enum
952 @@ -11342,6 +11345,14 @@
953 </desc>
954 </attribute>
956 + <!-- ENABLE VDE -->
957 + <attribute name="VDENetwork" type="wstring">
958 + <desc>
959 + Name of the VDE switch the VM is attached to.
960 + </desc>
961 + </attribute>
962 + <!-- /ENABLE VDE -->
964 <attribute name="cableConnected" type="boolean">
965 <desc>
966 Flag whether the adapter reports the cable as connected or not.
967 @@ -11393,6 +11404,14 @@
968 </desc>
969 </method>
971 + <!-- ENABLE VDE -->
972 + <method name="attachToVDE">
973 + <desc>
974 + Attach the network adapter to a VDE network.
975 + </desc>
976 + </method>
977 + <!-- /ENABLE VDE -->
979 <method name="detach">
980 <desc>
981 Detach the network adapter
982 diff -Naur VirtualBox-3.1.6_OSE/src/VBox/Main/include/NetworkAdapterImpl.h VirtualBox-3.1.6_OSE_VDE/src/VBox/Main/include/NetworkAdapterImpl.h
983 --- VirtualBox-3.1.6_OSE/src/VBox/Main/include/NetworkAdapterImpl.h 2010-03-25 20:56:41.000000000 +0100
984 +++ VirtualBox-3.1.6_OSE_VDE/src/VBox/Main/include/NetworkAdapterImpl.h 2010-04-04 10:18:33.000000000 +0200
985 @@ -49,6 +49,9 @@
986 mCableConnected(TRUE), mLineSpeed(0), mTraceEnabled(FALSE),
987 mHostInterface("") /* cannot be null */,
988 mNATNetwork("") /* cannot be null */
989 + /* ENABLE VDE */
990 + , mVDENetwork("") /* can be null */
991 + /* /ENABLE VDE */
994 bool operator== (const Data &that) const
995 @@ -63,6 +66,9 @@
996 mTraceEnabled == that.mTraceEnabled &&
997 mHostInterface == that.mHostInterface &&
998 mInternalNetwork == that.mInternalNetwork &&
999 + /* ENABLE VDE */
1000 + mVDENetwork == that.mVDENetwork &&
1001 + /* /ENABLE VDE */
1002 mNATNetwork == that.mNATNetwork);
1005 @@ -78,6 +84,9 @@
1006 Bstr mHostInterface;
1007 Bstr mInternalNetwork;
1008 Bstr mNATNetwork;
1009 + /* ENABLE VDE */
1010 + Bstr mVDENetwork;
1011 + /* /ENABLE VDE */
1014 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT (NetworkAdapter)
1015 @@ -118,6 +127,10 @@
1016 STDMETHOD(COMSETTER(InternalNetwork)) (IN_BSTR aInternalNetwork);
1017 STDMETHOD(COMGETTER(NATNetwork)) (BSTR *aNATNetwork);
1018 STDMETHOD(COMSETTER(NATNetwork)) (IN_BSTR aNATNetwork);
1019 + /* ENABLE VDE */
1020 + STDMETHOD(COMGETTER(VDENetwork)) (BSTR *aVDENetwork);
1021 + STDMETHOD(COMSETTER(VDENetwork)) (IN_BSTR aVDENetwork);
1022 + /* /ENABLE VDE */
1023 STDMETHOD(COMGETTER(CableConnected)) (BOOL *aConnected);
1024 STDMETHOD(COMSETTER(CableConnected)) (BOOL aConnected);
1025 STDMETHOD(COMGETTER(TraceEnabled)) (BOOL *aEnabled);
1026 @@ -132,6 +145,9 @@
1027 STDMETHOD(AttachToBridgedInterface)();
1028 STDMETHOD(AttachToInternalNetwork)();
1029 STDMETHOD(AttachToHostOnlyInterface)();
1030 + /* ENABLE VDE */
1031 + STDMETHOD(AttachToVDE)();
1032 + /* /ENABLE VDE */
1033 STDMETHOD(Detach)();
1035 // public methods only for internal purposes
1036 diff -Naur VirtualBox-3.1.6_OSE/src/VBox/Main/NetworkAdapterImpl.cpp VirtualBox-3.1.6_OSE_VDE/src/VBox/Main/NetworkAdapterImpl.cpp
1037 --- VirtualBox-3.1.6_OSE/src/VBox/Main/NetworkAdapterImpl.cpp 2010-03-25 20:56:38.000000000 +0100
1038 +++ VirtualBox-3.1.6_OSE_VDE/src/VBox/Main/NetworkAdapterImpl.cpp 2010-04-04 10:18:33.000000000 +0200
1039 @@ -532,6 +532,52 @@
1040 return S_OK;
1043 +/* ENABLE VDE */
1044 +STDMETHODIMP NetworkAdapter::COMGETTER(VDENetwork) (BSTR *aVDENetwork)
1046 + CheckComArgOutPointerValid(aVDENetwork);
1048 + AutoCaller autoCaller(this);
1049 + CheckComRCReturnRC(autoCaller.rc());
1051 + AutoReadLock alock(this);
1053 + mData->mVDENetwork.cloneTo(aVDENetwork);
1055 + return S_OK;
1058 +STDMETHODIMP NetworkAdapter::COMSETTER(VDENetwork) (IN_BSTR aVDENetwork)
1060 + Bstr bstrEmpty("");
1061 + if (!aVDENetwork)
1062 + aVDENetwork = bstrEmpty;
1064 + AutoCaller autoCaller(this);
1065 + CheckComRCReturnRC(autoCaller.rc());
1067 + /* the machine needs to be mutable */
1068 + Machine::AutoMutableStateDependency adep (mParent);
1069 + CheckComRCReturnRC(adep.rc());
1071 + AutoWriteLock alock(this);
1073 + if (mData->mVDENetwork != aVDENetwork)
1075 + mData.backup();
1076 + mData->mVDENetwork = aVDENetwork;
1078 + /* leave the lock before informing callbacks */
1079 + alock.unlock();
1081 + mParent->onNetworkAdapterChange (this, FALSE);
1084 + return S_OK;
1087 +/* /ENABLE VDE */
1089 STDMETHODIMP NetworkAdapter::COMGETTER(CableConnected) (BOOL *aConnected)
1091 CheckComArgOutPointerValid(aConnected);
1092 @@ -864,6 +910,51 @@
1093 return S_OK;
1096 +/* ENABLE VDE */
1097 +STDMETHODIMP NetworkAdapter::AttachToVDE()
1099 + AutoCaller autoCaller(this);
1100 + CheckComRCReturnRC(autoCaller.rc());
1102 + /* the machine needs to be mutable */
1103 + Machine::AutoMutableStateDependency adep (mParent);
1104 + CheckComRCReturnRC(adep.rc());
1106 + AutoWriteLock alock(this);
1108 + /* don't do anything if we're already host interface attached */
1109 + if (mData->mAttachmentType != NetworkAttachmentType_VDE)
1111 + mData.backup();
1113 + /* first detach the current attachment */
1114 + // Commented this for now as it reset the parameter mData->mHostInterface
1115 + // which is essential while changing the Attachment dynamically.
1116 + //detach();
1118 + mData->mAttachmentType = NetworkAttachmentType_VDE;
1120 + /* leave the lock before informing callbacks */
1121 + alock.unlock();
1123 + HRESULT rc = mParent->onNetworkAdapterChange (this, TRUE);
1124 + if (FAILED (rc))
1126 + /* If changing the attachment failed then we can't assume
1127 + * that the previous attachment will attach correctly
1128 + * and thus return error along with dettaching all
1129 + * attachments.
1130 + */
1131 + Detach();
1132 + return rc;
1136 + return S_OK;
1139 +/* /ENABLE VDE */
1141 STDMETHODIMP NetworkAdapter::Detach()
1143 AutoCaller autoCaller(this);
1144 @@ -966,6 +1057,15 @@
1145 CheckComRCReturnRC(rc);
1146 break;
1148 + /* ENABLE VDE */
1149 + case NetworkAttachmentType_VDE:
1150 + mData->mVDENetwork = data.strName;
1151 + rc = AttachToVDE();
1152 + CheckComRCReturnRC(rc);
1153 + break;
1154 + /* ENABLE VDE */
1157 case NetworkAttachmentType_Null:
1158 rc = Detach();
1159 CheckComRCReturnRC(rc);
1160 @@ -1024,6 +1124,10 @@
1161 case NetworkAttachmentType_HostOnly:
1162 data.strName = mData->mHostInterface;
1163 break;
1165 + case NetworkAttachmentType_VDE:
1166 + data.strName = mData->mVDENetwork;
1167 + break;
1170 return S_OK;
1171 diff -Naur VirtualBox-3.1.6_OSE/src/VBox/Main/xml/Settings.cpp VirtualBox-3.1.6_OSE_VDE/src/VBox/Main/xml/Settings.cpp
1172 --- VirtualBox-3.1.6_OSE/src/VBox/Main/xml/Settings.cpp 2010-03-25 20:56:45.000000000 +0100
1173 +++ VirtualBox-3.1.6_OSE_VDE/src/VBox/Main/xml/Settings.cpp 2010-04-04 10:18:33.000000000 +0200
1174 @@ -1371,6 +1371,13 @@
1175 if (!pelmAdapterChild->getAttributeValue("name", nic.strName)) // required network name
1176 throw ConfigFileError(this, pelmAdapterChild, N_("Required HostOnlyInterface/@name element is missing"));
1178 + /* ENABLE VDE */
1179 + else if ((pelmAdapterChild = pelmAdapter->findChildElement("VDE")))
1181 + nic.mode = NetworkAttachmentType_VDE;
1182 + pelmAdapterChild->getAttributeValue("network", nic.strName); // optional network name
1184 + /* /ENABLE VDE */
1185 // else: default is NetworkAttachmentType_Null
1187 ll.push_back(nic);
1188 @@ -2701,6 +2708,13 @@
1189 pelmAdapter->createChild("HostOnlyInterface")->setAttribute("name", nic.strName);
1190 break;
1192 + /* ENABLE VDE */
1193 + case NetworkAttachmentType_VDE:
1194 + pelmNAT = pelmAdapter->createChild("VDE");
1195 + if (nic.strName.length())
1196 + pelmNAT->setAttribute("network", nic.strName);
1197 + /* /ENABLE VDE */
1199 default: /*case NetworkAttachmentType_Null:*/
1200 break;