From owner-freebsd-emulation@FreeBSD.ORG Fri Apr 13 18:52:01 2012 Return-Path: Delivered-To: freebsd-emulation@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 9A66F1065673 for ; Fri, 13 Apr 2012 18:52:01 +0000 (UTC) (envelope-from landonf@plausible.coop) Received: from web1.plausible.coop (web1.plausible.coop [173.45.236.101]) by mx1.freebsd.org (Postfix) with ESMTP id 69F1E8FC0A for ; Fri, 13 Apr 2012 18:52:01 +0000 (UTC) Received: from smtp.office.plausible.coop (c-24-5-85-69.hsd1.ca.comcast.net [24.5.85.69]) by web1.plausible.coop (Postfix) with ESMTP id 679D4C6C335 for ; Fri, 13 Apr 2012 11:52:36 -0700 (PDT) Received: by smtp.office.plausible.coop (Postfix, from userid 65534) id 1FC777B4409; Fri, 13 Apr 2012 11:51:55 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail1.office.plausiblelabs.com X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED autolearn=unavailable version=3.3.1 Received: from [192.168.1.176] (rrcs-50-74-162-234.nyc.biz.rr.com [50.74.162.234]) by smtp.office.plausible.coop (Postfix) with ESMTPSA id AA0307B4401 for ; Fri, 13 Apr 2012 11:51:52 -0700 (PDT) From: Landon J Fuller Content-Type: multipart/mixed; boundary="Apple-Mail=_6B83BA87-1108-4832-B016-1EF6DA3DFC93" Date: Fri, 13 Apr 2012 14:51:49 -0400 Message-Id: <6BCC0BDE-C9FD-47F0-96AE-88F797EFB074@plausible.coop> To: freebsd-emulation@freebsd.org Mime-Version: 1.0 (Apple Message framework v1257) X-Mailer: Apple Mail (2.1257) Subject: [PATCH] VLAN trunking support in VirtualBox vboxnetflt X-BeenThere: freebsd-emulation@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Development of Emulators of other operating systems List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 13 Apr 2012 18:52:01 -0000 --Apple-Mail=_6B83BA87-1108-4832-B016-1EF6DA3DFC93 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii 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.=20 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 --Apple-Mail=_6B83BA87-1108-4832-B016-1EF6DA3DFC93 Content-Disposition: attachment; filename*0=patch-src-VBox-HostDrivers-VBoxNetFlt-freebsd-VBoxNetFlt-freebsd; filename*1=.c Content-Type: application/octet-stream; name="patch-src-VBox-HostDrivers-VBoxNetFlt-freebsd-VBoxNetFlt-freebsd.c" Content-Transfer-Encoding: 7bit --- 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++; --Apple-Mail=_6B83BA87-1108-4832-B016-1EF6DA3DFC93--