From patchwork Wed Oct 21 11:27:49 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark McLoughlin X-Patchwork-Id: 36546 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 51B8EB7BAA for ; Wed, 21 Oct 2009 23:54:22 +1100 (EST) Received: from localhost ([127.0.0.1]:55880 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N0ahn-0006nW-Em for incoming@patchwork.ozlabs.org; Wed, 21 Oct 2009 08:54:19 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1N0ZOE-0006mX-5X for qemu-devel@nongnu.org; Wed, 21 Oct 2009 07:30:03 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1N0ZO6-0006hU-PD for qemu-devel@nongnu.org; Wed, 21 Oct 2009 07:29:59 -0400 Received: from [199.232.76.173] (port=57338 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N0ZO3-0006fA-Px for qemu-devel@nongnu.org; Wed, 21 Oct 2009 07:29:52 -0400 Received: from mx1.redhat.com ([209.132.183.28]:52359) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1N0ZO2-0002xo-MR for qemu-devel@nongnu.org; Wed, 21 Oct 2009 07:29:51 -0400 Received: from int-mx05.intmail.prod.int.phx2.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.18]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n9LBTnWf011645 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-mx05.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id n9LBTnNo023702; Wed, 21 Oct 2009 07:29:49 -0400 Received: by blaa.localdomain (Postfix, from userid 500) id 209E346309; Wed, 21 Oct 2009 12:27:59 +0100 (IST) From: Mark McLoughlin To: qemu-devel@nongnu.org Date: Wed, 21 Oct 2009 12:27:49 +0100 Message-Id: <1256124478-2988-11-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.18 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: Mark McLoughlin Subject: [Qemu-devel] [PATCH 10/19] net: add an API for 'raw' packets 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 In the case where a NIC and backend agree on a packet header format, this API allows injecting packets which lack the agreed upon header. We need this for sending our gratuitous ARP. Signed-off-by: Mark McLoughlin --- net-queue.h | 1 + net.c | 37 +++++++++++++++++++++++++++++-------- net.h | 2 ++ 3 files changed, 32 insertions(+), 8 deletions(-) diff --git a/net-queue.h b/net-queue.h index 343760e..a31958e 100644 --- a/net-queue.h +++ b/net-queue.h @@ -44,6 +44,7 @@ typedef ssize_t (NetPacketDeliverIOV) (VLANClientState *sender, void *opaque); #define QEMU_NET_PACKET_FLAG_NONE 0 +#define QEMU_NET_PACKET_FLAG_RAW (1<<0) NetQueue *qemu_new_net_queue(NetPacketDeliver *deliver, NetPacketDeliverIOV *deliver_iov, diff --git a/net.c b/net.c index 30dc402..50d2f83 100644 --- a/net.c +++ b/net.c @@ -463,7 +463,10 @@ static ssize_t qemu_deliver_packet(VLANClientState *sender, return size; } - return vc->receive(vc, data, size); + if (flags & QEMU_NET_PACKET_FLAG_RAW && vc->receive_raw) + return vc->receive_raw(vc, data, size); + else + return vc->receive(vc, data, size); } static ssize_t qemu_vlan_deliver_packet(VLANClientState *sender, @@ -488,7 +491,10 @@ static ssize_t qemu_vlan_deliver_packet(VLANClientState *sender, continue; } - len = vc->receive(vc, buf, size); + if (flags & QEMU_NET_PACKET_FLAG_RAW && vc->receive_raw) + len = vc->receive_raw(vc, buf, size); + else + len = vc->receive(vc, buf, size); ret = (ret >= 0) ? ret : len; } @@ -526,9 +532,10 @@ void qemu_flush_queued_packets(VLANClientState *vc) qemu_net_queue_flush(queue); } -ssize_t qemu_send_packet_async(VLANClientState *sender, - const uint8_t *buf, int size, - NetPacketSent *sent_cb) +static ssize_t qemu_send_packet_async_with_flags(VLANClientState *sender, + unsigned flags, + const uint8_t *buf, int size, + NetPacketSent *sent_cb) { NetQueue *queue; @@ -547,9 +554,15 @@ ssize_t qemu_send_packet_async(VLANClientState *sender, queue = sender->vlan->send_queue; } - return qemu_net_queue_send(queue, sender, - QEMU_NET_PACKET_FLAG_NONE, - buf, size, sent_cb); + return qemu_net_queue_send(queue, sender, flags, buf, size, sent_cb); +} + +ssize_t qemu_send_packet_async(VLANClientState *sender, + const uint8_t *buf, int size, + NetPacketSent *sent_cb) +{ + return qemu_send_packet_async_with_flags(sender, QEMU_NET_PACKET_FLAG_NONE, + buf, size, sent_cb); } void qemu_send_packet(VLANClientState *vc, const uint8_t *buf, int size) @@ -557,6 +570,12 @@ void qemu_send_packet(VLANClientState *vc, const uint8_t *buf, int size) qemu_send_packet_async(vc, buf, size, NULL); } +ssize_t qemu_send_packet_raw(VLANClientState *vc, const uint8_t *buf, int size) +{ + return qemu_send_packet_async_with_flags(vc, QEMU_NET_PACKET_FLAG_RAW, + buf, size, NULL); +} + static ssize_t vc_sendv_compat(VLANClientState *vc, const struct iovec *iov, int iovcnt) { @@ -626,6 +645,8 @@ static ssize_t qemu_vlan_deliver_packet_iov(VLANClientState *sender, continue; } + assert(!(flags & QEMU_NET_PACKET_FLAG_RAW)); + if (vc->receive_iov) { len = vc->receive_iov(vc, iov, iovcnt); } else { diff --git a/net.h b/net.h index 5f28860..53d813c 100644 --- a/net.h +++ b/net.h @@ -28,6 +28,7 @@ typedef void (LinkStatusChanged)(VLANClientState *); struct VLANClientState { net_client_type type; NetReceive *receive; + NetReceive *receive_raw; NetReceiveIOV *receive_iov; /* Packets may still be sent if this returns zero. It's used to rate-limit the slirp code. */ @@ -72,6 +73,7 @@ ssize_t qemu_sendv_packet(VLANClientState *vc, const struct iovec *iov, ssize_t qemu_sendv_packet_async(VLANClientState *vc, const struct iovec *iov, int iovcnt, NetPacketSent *sent_cb); void qemu_send_packet(VLANClientState *vc, const uint8_t *buf, int size); +ssize_t qemu_send_packet_raw(VLANClientState *vc, const uint8_t *buf, int size); ssize_t qemu_send_packet_async(VLANClientState *vc, const uint8_t *buf, int size, NetPacketSent *sent_cb); void qemu_purge_queued_packets(VLANClientState *vc);