From patchwork Wed Oct 21 11:27:52 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark McLoughlin X-Patchwork-Id: 36538 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 8A2F8B7B88 for ; Wed, 21 Oct 2009 23:44:42 +1100 (EST) Received: from localhost ([127.0.0.1]:32939 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N0aYR-00012W-HJ for incoming@patchwork.ozlabs.org; Wed, 21 Oct 2009 08:44:39 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1N0ZOD-0006mJ-QQ for qemu-devel@nongnu.org; Wed, 21 Oct 2009 07:30:02 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1N0ZO5-0006go-Ov for qemu-devel@nongnu.org; Wed, 21 Oct 2009 07:29:59 -0400 Received: from [199.232.76.173] (port=57337 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N0ZO3-0006f8-PC for qemu-devel@nongnu.org; Wed, 21 Oct 2009 07:29:51 -0400 Received: from mx1.redhat.com ([209.132.183.28]:9290) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1N0ZO2-0002xq-Od for qemu-devel@nongnu.org; Wed, 21 Oct 2009 07:29:51 -0400 Received: from int-mx03.intmail.prod.int.phx2.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n9LBTnQH019656 for ; Wed, 21 Oct 2009 07:29:50 -0400 Received: from blaa.localdomain (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx03.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id n9LBTnKN002044; Wed, 21 Oct 2009 07:29:49 -0400 Received: by blaa.localdomain (Postfix, from userid 500) id 3C32B463B3; Wed, 21 Oct 2009 12:27:59 +0100 (IST) From: Mark McLoughlin To: qemu-devel@nongnu.org Date: Wed, 21 Oct 2009 12:27:52 +0100 Message-Id: <1256124478-2988-14-git-send-email-markmc@redhat.com> In-Reply-To: <1256124478-2988-1-git-send-email-markmc@redhat.com> References: <1256124478-2988-1-git-send-email-markmc@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.16 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; }