From patchwork Wed Oct 21 11:27:47 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark McLoughlin X-Patchwork-Id: 36533 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 2746FB7B7C for ; Wed, 21 Oct 2009 23:35:10 +1100 (EST) Received: from localhost ([127.0.0.1]:59521 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N0aPD-0005Cb-2u for incoming@patchwork.ozlabs.org; Wed, 21 Oct 2009 08:35:07 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1N0ZOB-0006k5-GC for qemu-devel@nongnu.org; Wed, 21 Oct 2009 07:29:59 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1N0ZO4-0006fc-Fv for qemu-devel@nongnu.org; Wed, 21 Oct 2009 07:29:57 -0400 Received: from [199.232.76.173] (port=57334 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N0ZO3-0006eX-Dw for qemu-devel@nongnu.org; Wed, 21 Oct 2009 07:29:51 -0400 Received: from mx1.redhat.com ([209.132.183.28]:30669) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1N0ZO2-0002xZ-Ht for qemu-devel@nongnu.org; Wed, 21 Oct 2009 07:29:50 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n9LBTnGr028384 for ; Wed, 21 Oct 2009 07:29:49 -0400 Received: from blaa.localdomain (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id n9LBTmSR025676; Wed, 21 Oct 2009 07:29:49 -0400 Received: by blaa.localdomain (Postfix, from userid 500) id 09958462C5; Wed, 21 Oct 2009 12:27:59 +0100 (IST) From: Mark McLoughlin To: qemu-devel@nongnu.org Date: Wed, 21 Oct 2009 12:27:47 +0100 Message-Id: <1256124478-2988-9-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.11 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: Mark McLoughlin Subject: [Qemu-devel] [PATCH 08/19] net: add tap_has_vnet_hdr() and tap_using_vnet_hdr() APIs 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 These lamely named functions allow virtio-net to query whether IFF_VNET_HDR is enabled on a tap interface and inform the tap code that virtio-net will supply packets with a vnet header. Signed-off-by: Mark McLoughlin --- net.c | 39 +++++++++++++++++++++++++++++++++++---- net.h | 3 +++ 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/net.c b/net.c index 638ba36..56d979b 100644 --- a/net.c +++ b/net.c @@ -1246,7 +1246,15 @@ void do_info_usernet(Monitor *mon) #endif /* CONFIG_SLIRP */ -#if !defined(_WIN32) +#if defined(_WIN32) +int tap_has_vnet_hdr(VLANClientState *vc) +{ + return 0; +} +void tap_using_vnet_hdr(VLANClientState *vc, int using_vnet_hdr) +{ +} +#else /* !defined(_WIN32) */ /* Maximum GSO packet size (64k) plus plenty of room for * the ethernet and virtio_net headers @@ -1262,6 +1270,7 @@ typedef struct TAPState { unsigned int read_poll : 1; unsigned int write_poll : 1; unsigned int has_vnet_hdr : 1; + unsigned int using_vnet_hdr : 1; } TAPState; static int launch_script(const char *setup_script, const char *ifname, int fd); @@ -1324,7 +1333,7 @@ static ssize_t tap_receive_iov(VLANClientState *vc, const struct iovec *iov, struct iovec iov_copy[iovcnt + 1]; struct virtio_net_hdr hdr = { 0, }; - if (s->has_vnet_hdr) { + if (s->has_vnet_hdr && !s->using_vnet_hdr) { iov_copy[0].iov_base = &hdr; iov_copy[0].iov_len = sizeof(hdr); memcpy(&iov_copy[1], iov, iovcnt * sizeof(*iov)); @@ -1342,7 +1351,7 @@ static ssize_t tap_receive(VLANClientState *vc, const uint8_t *buf, size_t size) int iovcnt = 0; struct virtio_net_hdr hdr = { 0, }; - if (s->has_vnet_hdr) { + if (s->has_vnet_hdr && !s->using_vnet_hdr) { iov[iovcnt].iov_base = &hdr; iov[iovcnt].iov_len = sizeof(hdr); iovcnt++; @@ -1399,7 +1408,7 @@ static void tap_send(void *opaque) break; } - if (s->has_vnet_hdr) { + if (s->has_vnet_hdr && !s->using_vnet_hdr) { buf += sizeof(struct virtio_net_hdr); size -= sizeof(struct virtio_net_hdr); } @@ -1434,6 +1443,27 @@ static int tap_set_sndbuf(TAPState *s, QemuOpts *opts) return 0; } +int tap_has_vnet_hdr(VLANClientState *vc) +{ + TAPState *s = vc->opaque; + + assert(vc->type == NET_CLIENT_TYPE_TAP); + + return s->has_vnet_hdr; +} + +void tap_using_vnet_hdr(VLANClientState *vc, int using_vnet_hdr) +{ + TAPState *s = vc->opaque; + + using_vnet_hdr = using_vnet_hdr != 0; + + assert(vc->type == NET_CLIENT_TYPE_TAP); + assert(s->has_vnet_hdr == using_vnet_hdr); + + s->using_vnet_hdr = using_vnet_hdr; +} + static int tap_probe_vnet_hdr(int fd) { struct ifreq ifr; @@ -1474,6 +1504,7 @@ static TAPState *net_tap_fd_init(VLANState *vlan, s = qemu_mallocz(sizeof(TAPState)); s->fd = fd; s->has_vnet_hdr = vnet_hdr != 0; + s->using_vnet_hdr = 0; s->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_TAP, vlan, NULL, model, name, NULL, tap_receive, tap_receive_iov, diff --git a/net.h b/net.h index aefeef4..5f28860 100644 --- a/net.h +++ b/net.h @@ -165,4 +165,7 @@ VLANClientState *qdev_get_vlan_client(DeviceState *dev, NetCleanup *cleanup, void *opaque); +int tap_has_vnet_hdr(VLANClientState *vc); +void tap_using_vnet_hdr(VLANClientState *vc, int using_vnet_hdr); + #endif