Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 13 Apr 2012 14:51:49 -0400
From:      Landon J Fuller <landonf@plausible.coop>
To:        freebsd-emulation@freebsd.org
Subject:   [PATCH] VLAN trunking support in VirtualBox vboxnetflt
Message-ID:  <6BCC0BDE-C9FD-47F0-96AE-88F797EFB074@plausible.coop>

index | next in thread | raw e-mail

[-- Attachment #1 --]
Howdy,

I was looking into trunking VLANs into a virtual machine via bridging, and noted that transmit of 802.1q tagged packets worked from the guest VM, but upon reception, the VLAN tag seemed to be stripped before the packets hit the guest's interface.

Taking a look at the netgraph-based bridging implementation, it looks like the VLAN tag is not being re-inserted at the head of the ethernet frame prior to handing off the to VirtualBox, and VBox doesn't seem to have an equivalent 'ether_vtag' field in its INTNETSG struct to handle this.

Thus, to preserve the VLAN tag, I modified vboxNetFltFreeBSDMBufToSG() to ether_vlanencap() to insert the VLAN tag before handing off to VBox. With this in place, I was able to successfully trunk VLANs to a virtual machine. 

Some caveats:
	- If using virtio-kmod's if_vtnet, you must set vlanhwfilter (or promisc) flags on the guest interface before virtualbox will pass the VLAN tagged packets through. Otherwise, the VBox virtio-net device implementation will filter out the incoming packets before handing them to the VM hardware.
	- VBox's em(4) host implementation does not appear to support 'hardware' VLAN tagging, but it does declare it. If using a em(4) virtualized NIC, you must set -vlanhwtag on the guest interface.

I welcome someone(s) with more experience than I eyeballing the (tiny) attached patch. I'm also especially concerned as to whether this should be considered supported functionality in VBox, or I'm just getting lucky with the virtio-net code path.

Thanks,
Landon


[-- Attachment #2 --]
--- src/VBox/./HostDrivers/VBoxNetFlt/freebsd/VBoxNetFlt-freebsd.c.orig	2012-04-12 17:27:56.035382846 -0400
+++ src/VBox/./HostDrivers/VBoxNetFlt/freebsd/VBoxNetFlt-freebsd.c	2012-04-12 17:30:13.038601065 -0400
@@ -439,6 +439,16 @@
         if (m == NULL)
             break;
 
+        /* Preprend a VLAN header for consumption by the virtual switch */
+        if (m->m_flags & M_VLANTAG) {
+            m = ether_vlanencap(m, m->m_pkthdr.ether_vtag);
+            if (m == NULL) {
+                printf("vboxflt: unable to prepend VLAN header\n");
+                break;
+            }
+            m->m_flags &= ~M_VLANTAG;
+        }
+
         for (m0 = m; m0 != NULL; m0 = m0->m_next)
             if (m0->m_len > 0)
                 cSegs++;
help

Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?6BCC0BDE-C9FD-47F0-96AE-88F797EFB074>