mirror of
https://git.FreeBSD.org/ports.git
synced 2024-12-25 04:43:33 +00:00
71b986b697
Obtained from: svn.redports.org/virtualbox
73 lines
2.6 KiB
C
73 lines
2.6 KiB
C
Add VLAN trunking support to vboxnetflt
|
|
|
|
See: http://lists.freebsd.org/pipermail/freebsd-emulation/2012-April/009698.html
|
|
See: http://lists.freebsd.org/pipermail/freebsd-emulation/2013-May/010605.html
|
|
Submitted by: Landon J Fuller <landonf at plausible.coop>
|
|
--- ./src/VBox/HostDrivers/VBoxNetFlt/freebsd/VBoxNetFlt-freebsd.c.orig 2013-04-12 06:38:11.000000000 -0400
|
|
+++ ./src/VBox/HostDrivers/VBoxNetFlt/freebsd/VBoxNetFlt-freebsd.c 2013-05-25 20:14:52.152180452 -0400
|
|
@@ -51,6 +51,7 @@
|
|
#include <net/if_dl.h>
|
|
#include <net/if_types.h>
|
|
#include <net/ethernet.h>
|
|
+#include <net/if_vlan_var.h>
|
|
|
|
#include <netgraph/ng_message.h>
|
|
#include <netgraph/netgraph.h>
|
|
@@ -427,6 +428,8 @@
|
|
struct ifnet *ifp = pThis->u.s.ifp;
|
|
unsigned int cSegs = 0;
|
|
bool fDropIt = false, fActive;
|
|
+ bool is_vl_tagged = false;
|
|
+ uint16_t vl_tag;
|
|
PINTNETSG pSG;
|
|
|
|
VBOXCURVNET_SET(ifp->if_vnet);
|
|
@@ -439,6 +442,19 @@
|
|
if (m == NULL)
|
|
break;
|
|
|
|
+ /* Prepend a VLAN header for consumption by the virtual switch */
|
|
+ if (m->m_flags & M_VLANTAG) {
|
|
+ vl_tag = m->m_pkthdr.ether_vtag;
|
|
+ is_vl_tagged = true;
|
|
+
|
|
+ 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++;
|
|
@@ -453,6 +469,27 @@
|
|
vboxNetFltFreeBSDMBufToSG(pThis, m, pSG, cSegs, 0);
|
|
fDropIt = pThis->pSwitchPort->pfnRecv(pThis->pSwitchPort, NULL /* pvIf */, pSG, INTNETTRUNKDIR_WIRE);
|
|
RTMemTmpFree(pSG);
|
|
+
|
|
+ /* Restore the VLAN flags before re-injecting the packet */
|
|
+ if (is_vl_tagged && !fDropIt) {
|
|
+ struct ether_vlan_header *vl_hdr;
|
|
+
|
|
+ /* This shouldn't fail, as the header was just prepended */
|
|
+ if (m->m_len < sizeof(*vl_hdr) && (m = m_pullup(m, sizeof(*vl_hdr))) == NULL) {
|
|
+ printf("vboxflt: unable to pullup VLAN header\n");
|
|
+ m_freem(m);
|
|
+ break;
|
|
+ }
|
|
+
|
|
+ /* Copy the MAC dhost/shost over the 802.1q field */
|
|
+ vl_hdr = mtod(m, struct ether_vlan_header *);
|
|
+ bcopy((char *)vl_hdr, (char *)vl_hdr + ETHER_VLAN_ENCAP_LEN, ETHER_HDR_LEN - ETHER_TYPE_LEN);
|
|
+ m_adj(m, ETHER_VLAN_ENCAP_LEN);
|
|
+
|
|
+ m->m_pkthdr.ether_vtag = vl_tag;
|
|
+ m->m_flags |= M_VLANTAG;
|
|
+ }
|
|
+
|
|
if (fDropIt)
|
|
m_freem(m);
|
|
else
|