[vbox-dev] [PATCH] demonstration patch for host-only networking packet direction

Ed Maste emaste at freebsd.org
Tue Sep 4 13:34:14 GMT 2012


On 30 August 2012 14:54, Ed Maste <emaste at freebsd.org> wrote:
> ...
> It appears that VirtualBox calls vboxNetFltPortOsXmit with fDst set to
> INTNETTRUNKDIR_HOST if the MAC address matches that of the vboxnet
> interface, or INTNETTRUNKDIR_WIRE otherwise.  To me this seems
> undesirable in the case of a host-only network, where there really is
> no 'wire' and all packets ought to be destined to/from the host.
>
> I could implement something in the FreeBSD VBoxNetFlt and VBoxNetAdp
> drivers for this, but it seems like it's a general issue.  Should
> VirtualBox always set fDst to INTNETTRUNKDIR_HOST for host-only
> interfaces?

Here's a quick hacky patch that demonstrates the change in behaviour.
It does fix the issue I originally encountered.



diff --git a/src/VBox/HostDrivers/VBoxNetFlt/VBoxNetFltInternal.h
b/src/VBox/HostDrivers/VBoxNetFlt/VBoxNetFltInternal.h
index 90182a9..a01e060 100644
--- a/src/VBox/HostDrivers/VBoxNetFlt/VBoxNetFltInternal.h
+++ b/src/VBox/HostDrivers/VBoxNetFlt/VBoxNetFltInternal.h
@@ -237,6 +237,8 @@ typedef struct VBOXNETFLTINS
             struct task tskout;
             /** The MAC address of the interface. */
             RTMAC MacAddr;
+            /** Host-only flag. */
+            int host_only;
             /** @} */
 # elif defined(RT_OS_WINDOWS)
             /** @name Windows instance data.
diff --git a/src/VBox/HostDrivers/VBoxNetFlt/freebsd/VBoxNetFlt-freebsd.c
b/src/VBox/HostDrivers/VBoxNetFlt/freebsd/VBoxNetFlt-freebsd.c
index 2912d76..b100bb4 100644
--- a/src/VBox/HostDrivers/VBoxNetFlt/freebsd/VBoxNetFlt-freebsd.c
+++ b/src/VBox/HostDrivers/VBoxNetFlt/freebsd/VBoxNetFlt-freebsd.c
@@ -524,6 +524,14 @@ int vboxNetFltPortOsXmit(PVBOXNETFLTINS pThis,
void *pvIfData, PINTNETSG pSG, ui
     ifp = ASMAtomicUoReadPtrT(&pThis->u.s.ifp, struct ifnet *);
     VBOXCURVNET_SET(ifp->if_vnet);

+    /* XXX Don't send to wire for host-only interface - see the thread at
+     * https://www.virtualbox.org/pipermail/vbox-dev/2012-August/005316.html
+     */
+    if ((fDst & INTNETTRUNKDIR_WIRE) && pThis->u.s.host_only)
+    {
+        fDst = INTNETTRUNKDIR_HOST;
+    }
+
     if (fDst & INTNETTRUNKDIR_WIRE)
     {
         m = vboxNetFltFreeBSDSGMBufFromSG(pThis, pSG);
@@ -587,6 +595,7 @@ int vboxNetFltOsInitInstance(PVBOXNETFLTINS pThis,
void *pvContext)
     ifp = ifunit(pThis->szName);
     if (ifp == NULL)
         return VERR_INTNET_FLT_IF_NOT_FOUND;
+    pThis->u.s.host_only = !strncmp(pThis->szName, "vboxnet", 7);

     /* Create a new netgraph node for this instance */
     if (ng_make_node_common(&ng_vboxnetflt_typestruct, &node) != 0)




More information about the vbox-dev mailing list