From patchwork Thu Oct 22 16:43:44 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark McLoughlin X-Patchwork-Id: 36706 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 04E8DB7BB2 for ; Fri, 23 Oct 2009 04:06:51 +1100 (EST) Received: from localhost ([127.0.0.1]:48114 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N117f-00014j-GD for incoming@patchwork.ozlabs.org; Thu, 22 Oct 2009 13:06:47 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1N10nV-0007FA-GP for qemu-devel@nongnu.org; Thu, 22 Oct 2009 12:45:57 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1N10nL-00070E-Ts for qemu-devel@nongnu.org; Thu, 22 Oct 2009 12:45:52 -0400 Received: from [199.232.76.173] (port=47956 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N10nL-0006zM-7X for qemu-devel@nongnu.org; Thu, 22 Oct 2009 12:45:47 -0400 Received: from mx1.redhat.com ([209.132.183.28]:64067) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1N10nJ-0003Fa-K6 for qemu-devel@nongnu.org; Thu, 22 Oct 2009 12:45:46 -0400 Received: from int-mx08.intmail.prod.int.phx2.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n9MGji20011546 for ; Thu, 22 Oct 2009 12:45:44 -0400 Received: from blaa.localdomain (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx08.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id n9MGjhok019793; Thu, 22 Oct 2009 12:45:43 -0400 Received: by blaa.localdomain (Postfix, from userid 500) id AF02345B49; Thu, 22 Oct 2009 17:43:50 +0100 (IST) From: Mark McLoughlin To: qemu-devel@nongnu.org Date: Thu, 22 Oct 2009 17:43:44 +0100 Message-Id: <1256229830-28066-14-git-send-email-markmc@redhat.com> In-Reply-To: <1256229830-28066-1-git-send-email-markmc@redhat.com> References: <1256229830-28066-1-git-send-email-markmc@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.21 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: Mark McLoughlin Subject: [Qemu-devel] [PATCH 13/19] net: implement tap support for receive_raw() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org tap_receive_raw() always prepends a vnet header if IFF_VNET_HDR is enabled. tap_receive() only prepends when the a header is required but the NIC doesn't supply one. Signed-off-by: Mark McLoughlin --- net.c | 23 +++++++++++++++++++---- 1 files changed, 19 insertions(+), 4 deletions(-) diff --git a/net.c b/net.c index 56d9de7..b44495d 100644 --- a/net.c +++ b/net.c @@ -1377,14 +1377,14 @@ static ssize_t tap_receive_iov(VLANClientState *vc, const struct iovec *iov, return tap_write_packet(s, iovp, iovcnt); } -static ssize_t tap_receive(VLANClientState *vc, const uint8_t *buf, size_t size) +static ssize_t tap_receive_raw(VLANClientState *vc, const uint8_t *buf, size_t size) { TAPState *s = vc->opaque; struct iovec iov[2]; int iovcnt = 0; struct virtio_net_hdr hdr = { 0, }; - if (s->has_vnet_hdr && !s->using_vnet_hdr) { + if (s->has_vnet_hdr) { iov[iovcnt].iov_base = &hdr; iov[iovcnt].iov_len = sizeof(hdr); iovcnt++; @@ -1397,6 +1397,21 @@ static ssize_t tap_receive(VLANClientState *vc, const uint8_t *buf, size_t size) return tap_write_packet(s, iov, iovcnt); } +static ssize_t tap_receive(VLANClientState *vc, const uint8_t *buf, size_t size) +{ + TAPState *s = vc->opaque; + struct iovec iov[1]; + + if (s->has_vnet_hdr && !s->using_vnet_hdr) { + return tap_receive_raw(vc, buf, size); + } + + iov[0].iov_base = (char *)buf; + iov[0].iov_len = size; + + return tap_write_packet(s, iov, 1); +} + static int tap_can_send(void *opaque) { TAPState *s = opaque; @@ -1540,8 +1555,8 @@ static TAPState *net_tap_fd_init(VLANState *vlan, s->using_vnet_hdr = 0; s->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_TAP, vlan, NULL, model, name, NULL, - tap_receive, NULL, tap_receive_iov, - tap_cleanup, s); + tap_receive, tap_receive_raw, + tap_receive_iov, tap_cleanup, s); tap_read_poll(s, 1); return s; }