All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 00/15] Some networking code re-organization
@ 2009-10-22 16:49 Mark McLoughlin
  2009-10-22 16:49 ` [Qemu-devel] [PATCH 01/15] net: move net-queue.[ch] under net/ Mark McLoughlin
                   ` (16 more replies)
  0 siblings, 17 replies; 22+ messages in thread
From: Mark McLoughlin @ 2009-10-22 16:49 UTC (permalink / raw)
  To: qemu-devel

Hey,
        We've been meaning to split net.c up for quite a while now,
so here goes with a first cut at.

        There shouldn't be anything too controversial here, apart
from CONFIG_LINUX maybe.

        I've build tested this on F11, F12 and mingw and also done
some basic runtime testing.

        Building on e.g. *BSD, Solaris and AIX hasn't been tested.
I wouldn't be surprised if I've broken the build there despite all
my efforts but, if I have, it should be trivial to fix back up.

        This isn't the end of the cleanups; obviously the other
backends could be split out too, we could use module construtors, etc.

Cheers,
Mark.

^ permalink raw reply	[flat|nested] 22+ messages in thread

* [Qemu-devel] [PATCH 01/15] net: move net-queue.[ch] under net/
  2009-10-22 16:49 [Qemu-devel] [PATCH 00/15] Some networking code re-organization Mark McLoughlin
@ 2009-10-22 16:49 ` Mark McLoughlin
  2009-10-23 16:52   ` [Qemu-devel] [PATCH 01/15 v2] " Mark McLoughlin
  2009-10-22 16:49 ` [Qemu-devel] [PATCH 02/15] net: move net-checksum.c " Mark McLoughlin
                   ` (15 subsequent siblings)
  16 siblings, 1 reply; 22+ messages in thread
From: Mark McLoughlin @ 2009-10-22 16:49 UTC (permalink / raw)
  To: qemu-devel; +Cc: Mark McLoughlin

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
---
 Makefile    |    6 +-
 net-queue.c |  260 -----------------------------------------------------------
 net-queue.h |   71 ----------------
 net.h       |    2 +-
 net/queue.c |  260 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 net/queue.h |   71 ++++++++++++++++
 6 files changed, 337 insertions(+), 333 deletions(-)
 delete mode 100644 net-queue.c
 delete mode 100644 net-queue.h
 create mode 100644 net/queue.c
 create mode 100644 net/queue.h

diff --git a/Makefile b/Makefile
index e78a3d0..6fb89fb 100644
--- a/Makefile
+++ b/Makefile
@@ -86,6 +86,10 @@ block-nested-$(CONFIG_CURL) += curl.o
 
 block-obj-y +=  $(addprefix block/, $(block-nested-y))
 
+net-obj-y = net.o
+net-nested-y = queue.o
+net-obj-y += $(addprefix net/, $(net-nested-y))
+
 ######################################################################
 # libqemu_common.a: Target independent part of system emulation. The
 # long term path is to suppress *all* target specific code in case of
@@ -93,6 +97,7 @@ block-obj-y +=  $(addprefix block/, $(block-nested-y))
 # CPUs and machines.
 
 obj-y = $(block-obj-y)
+obj-y += $(net-obj-y)
 obj-y += readline.o console.o
 
 obj-y += tcg-runtime.o host-utils.o
@@ -121,7 +126,6 @@ obj-$(CONFIG_SD) += sd.o
 obj-y += bt.o bt-host.o bt-vhci.o bt-l2cap.o bt-sdp.o bt-hci.o bt-hid.o usb-bt.o
 obj-y += bt-hci-csr.o
 obj-y += buffered_file.o migration.o migration-tcp.o qemu-sockets.o
-obj-y += net.o net-queue.o
 obj-y += qemu-char.o aio.o net-checksum.o savevm.o
 obj-y += msmouse.o ps2.o
 obj-y += qdev.o qdev-properties.o
diff --git a/net-queue.c b/net-queue.c
deleted file mode 100644
index f6b01e9..0000000
--- a/net-queue.c
+++ /dev/null
@@ -1,260 +0,0 @@
-/*
- * Copyright (c) 2003-2008 Fabrice Bellard
- * Copyright (c) 2009 Red Hat, Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-#include "net-queue.h"
-#include "qemu-queue.h"
-
-/* The delivery handler may only return zero if it will call
- * qemu_net_queue_flush() when it determines that it is once again able
- * to deliver packets. It must also call qemu_net_queue_purge() in its
- * cleanup path.
- *
- * If a sent callback is provided to send(), the caller must handle a
- * zero return from the delivery handler by not sending any more packets
- * until we have invoked the callback. Only in that case will we queue
- * the packet.
- *
- * If a sent callback isn't provided, we just drop the packet to avoid
- * unbounded queueing.
- */
-
-struct NetPacket {
-    QTAILQ_ENTRY(NetPacket) entry;
-    VLANClientState *sender;
-    unsigned flags;
-    int size;
-    NetPacketSent *sent_cb;
-    uint8_t data[0];
-};
-
-struct NetQueue {
-    NetPacketDeliver *deliver;
-    NetPacketDeliverIOV *deliver_iov;
-    void *opaque;
-
-    QTAILQ_HEAD(packets, NetPacket) packets;
-
-    unsigned delivering : 1;
-};
-
-NetQueue *qemu_new_net_queue(NetPacketDeliver *deliver,
-                             NetPacketDeliverIOV *deliver_iov,
-                             void *opaque)
-{
-    NetQueue *queue;
-
-    queue = qemu_mallocz(sizeof(NetQueue));
-
-    queue->deliver = deliver;
-    queue->deliver_iov = deliver_iov;
-    queue->opaque = opaque;
-
-    QTAILQ_INIT(&queue->packets);
-
-    queue->delivering = 0;
-
-    return queue;
-}
-
-void qemu_del_net_queue(NetQueue *queue)
-{
-    NetPacket *packet, *next;
-
-    QTAILQ_FOREACH_SAFE(packet, &queue->packets, entry, next) {
-        QTAILQ_REMOVE(&queue->packets, packet, entry);
-        qemu_free(packet);
-    }
-
-    qemu_free(queue);
-}
-
-static ssize_t qemu_net_queue_append(NetQueue *queue,
-                                     VLANClientState *sender,
-                                     unsigned flags,
-                                     const uint8_t *buf,
-                                     size_t size,
-                                     NetPacketSent *sent_cb)
-{
-    NetPacket *packet;
-
-    packet = qemu_malloc(sizeof(NetPacket) + size);
-    packet->sender = sender;
-    packet->flags = flags;
-    packet->size = size;
-    packet->sent_cb = sent_cb;
-    memcpy(packet->data, buf, size);
-
-    QTAILQ_INSERT_TAIL(&queue->packets, packet, entry);
-
-    return size;
-}
-
-static ssize_t qemu_net_queue_append_iov(NetQueue *queue,
-                                         VLANClientState *sender,
-                                         unsigned flags,
-                                         const struct iovec *iov,
-                                         int iovcnt,
-                                         NetPacketSent *sent_cb)
-{
-    NetPacket *packet;
-    size_t max_len = 0;
-    int i;
-
-    for (i = 0; i < iovcnt; i++) {
-        max_len += iov[i].iov_len;
-    }
-
-    packet = qemu_malloc(sizeof(NetPacket) + max_len);
-    packet->sender = sender;
-    packet->sent_cb = sent_cb;
-    packet->flags = flags;
-    packet->size = 0;
-
-    for (i = 0; i < iovcnt; i++) {
-        size_t len = iov[i].iov_len;
-
-        memcpy(packet->data + packet->size, iov[i].iov_base, len);
-        packet->size += len;
-    }
-
-    QTAILQ_INSERT_TAIL(&queue->packets, packet, entry);
-
-    return packet->size;
-}
-
-static ssize_t qemu_net_queue_deliver(NetQueue *queue,
-                                      VLANClientState *sender,
-                                      unsigned flags,
-                                      const uint8_t *data,
-                                      size_t size)
-{
-    ssize_t ret = -1;
-
-    queue->delivering = 1;
-    ret = queue->deliver(sender, flags, data, size, queue->opaque);
-    queue->delivering = 0;
-
-    return ret;
-}
-
-static ssize_t qemu_net_queue_deliver_iov(NetQueue *queue,
-                                          VLANClientState *sender,
-                                          unsigned flags,
-                                          const struct iovec *iov,
-                                          int iovcnt)
-{
-    ssize_t ret = -1;
-
-    queue->delivering = 1;
-    ret = queue->deliver_iov(sender, flags, iov, iovcnt, queue->opaque);
-    queue->delivering = 0;
-
-    return ret;
-}
-
-ssize_t qemu_net_queue_send(NetQueue *queue,
-                            VLANClientState *sender,
-                            unsigned flags,
-                            const uint8_t *data,
-                            size_t size,
-                            NetPacketSent *sent_cb)
-{
-    ssize_t ret;
-
-    if (queue->delivering) {
-        return qemu_net_queue_append(queue, sender, flags, data, size, NULL);
-    }
-
-    ret = qemu_net_queue_deliver(queue, sender, flags, data, size);
-    if (ret == 0 && sent_cb != NULL) {
-        qemu_net_queue_append(queue, sender, flags, data, size, sent_cb);
-        return 0;
-    }
-
-    qemu_net_queue_flush(queue);
-
-    return ret;
-}
-
-ssize_t qemu_net_queue_send_iov(NetQueue *queue,
-                                VLANClientState *sender,
-                                unsigned flags,
-                                const struct iovec *iov,
-                                int iovcnt,
-                                NetPacketSent *sent_cb)
-{
-    ssize_t ret;
-
-    if (queue->delivering) {
-        return qemu_net_queue_append_iov(queue, sender, flags, iov, iovcnt, NULL);
-    }
-
-    ret = qemu_net_queue_deliver_iov(queue, sender, flags, iov, iovcnt);
-    if (ret == 0 && sent_cb != NULL) {
-        qemu_net_queue_append_iov(queue, sender, flags, iov, iovcnt, sent_cb);
-        return 0;
-    }
-
-    qemu_net_queue_flush(queue);
-
-    return ret;
-}
-
-void qemu_net_queue_purge(NetQueue *queue, VLANClientState *from)
-{
-    NetPacket *packet, *next;
-
-    QTAILQ_FOREACH_SAFE(packet, &queue->packets, entry, next) {
-        if (packet->sender == from) {
-            QTAILQ_REMOVE(&queue->packets, packet, entry);
-            qemu_free(packet);
-        }
-    }
-}
-
-void qemu_net_queue_flush(NetQueue *queue)
-{
-    while (!QTAILQ_EMPTY(&queue->packets)) {
-        NetPacket *packet;
-        int ret;
-
-        packet = QTAILQ_FIRST(&queue->packets);
-        QTAILQ_REMOVE(&queue->packets, packet, entry);
-
-        ret = qemu_net_queue_deliver(queue,
-                                     packet->sender,
-                                     packet->flags,
-                                     packet->data,
-                                     packet->size);
-        if (ret == 0 && packet->sent_cb != NULL) {
-            QTAILQ_INSERT_HEAD(&queue->packets, packet, entry);
-            break;
-        }
-
-        if (packet->sent_cb) {
-            packet->sent_cb(packet->sender, ret);
-        }
-
-        qemu_free(packet);
-    }
-}
diff --git a/net-queue.h b/net-queue.h
deleted file mode 100644
index a31958e..0000000
--- a/net-queue.h
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Copyright (c) 2003-2008 Fabrice Bellard
- * Copyright (c) 2009 Red Hat, Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-#ifndef QEMU_NET_QUEUE_H
-#define QEMU_NET_QUEUE_H
-
-#include "qemu-common.h"
-
-typedef struct NetPacket NetPacket;
-typedef struct NetQueue NetQueue;
-
-typedef void (NetPacketSent) (VLANClientState *sender, ssize_t ret);
-
-typedef ssize_t (NetPacketDeliver) (VLANClientState *sender,
-                                    unsigned flags,
-                                    const uint8_t *buf,
-                                    size_t size,
-                                    void *opaque);
-
-typedef ssize_t (NetPacketDeliverIOV) (VLANClientState *sender,
-                                       unsigned flags,
-                                       const struct iovec *iov,
-                                       int iovcnt,
-                                       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,
-                             void *opaque);
-void qemu_del_net_queue(NetQueue *queue);
-
-ssize_t qemu_net_queue_send(NetQueue *queue,
-                            VLANClientState *sender,
-                            unsigned flags,
-                            const uint8_t *data,
-                            size_t size,
-                            NetPacketSent *sent_cb);
-
-ssize_t qemu_net_queue_send_iov(NetQueue *queue,
-                                VLANClientState *sender,
-                                unsigned flags,
-                                const struct iovec *iov,
-                                int iovcnt,
-                                NetPacketSent *sent_cb);
-
-void qemu_net_queue_purge(NetQueue *queue, VLANClientState *from);
-void qemu_net_queue_flush(NetQueue *queue);
-
-#endif /* QEMU_NET_QUEUE_H */
diff --git a/net.h b/net.h
index 7e6cbf4..9ebb978 100644
--- a/net.h
+++ b/net.h
@@ -5,7 +5,7 @@
 #include "qemu-common.h"
 #include "qdict.h"
 #include "qemu-option.h"
-#include "net-queue.h"
+#include "net/queue.h"
 
 /* VLANs support */
 
diff --git a/net/queue.c b/net/queue.c
new file mode 100644
index 0000000..e91a9a5
--- /dev/null
+++ b/net/queue.c
@@ -0,0 +1,260 @@
+/*
+ * Copyright (c) 2003-2008 Fabrice Bellard
+ * Copyright (c) 2009 Red Hat, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "net/queue.h"
+#include "qemu-queue.h"
+
+/* The delivery handler may only return zero if it will call
+ * qemu_net_queue_flush() when it determines that it is once again able
+ * to deliver packets. It must also call qemu_net_queue_purge() in its
+ * cleanup path.
+ *
+ * If a sent callback is provided to send(), the caller must handle a
+ * zero return from the delivery handler by not sending any more packets
+ * until we have invoked the callback. Only in that case will we queue
+ * the packet.
+ *
+ * If a sent callback isn't provided, we just drop the packet to avoid
+ * unbounded queueing.
+ */
+
+struct NetPacket {
+    QTAILQ_ENTRY(NetPacket) entry;
+    VLANClientState *sender;
+    unsigned flags;
+    int size;
+    NetPacketSent *sent_cb;
+    uint8_t data[0];
+};
+
+struct NetQueue {
+    NetPacketDeliver *deliver;
+    NetPacketDeliverIOV *deliver_iov;
+    void *opaque;
+
+    QTAILQ_HEAD(packets, NetPacket) packets;
+
+    unsigned delivering : 1;
+};
+
+NetQueue *qemu_new_net_queue(NetPacketDeliver *deliver,
+                             NetPacketDeliverIOV *deliver_iov,
+                             void *opaque)
+{
+    NetQueue *queue;
+
+    queue = qemu_mallocz(sizeof(NetQueue));
+
+    queue->deliver = deliver;
+    queue->deliver_iov = deliver_iov;
+    queue->opaque = opaque;
+
+    QTAILQ_INIT(&queue->packets);
+
+    queue->delivering = 0;
+
+    return queue;
+}
+
+void qemu_del_net_queue(NetQueue *queue)
+{
+    NetPacket *packet, *next;
+
+    QTAILQ_FOREACH_SAFE(packet, &queue->packets, entry, next) {
+        QTAILQ_REMOVE(&queue->packets, packet, entry);
+        qemu_free(packet);
+    }
+
+    qemu_free(queue);
+}
+
+static ssize_t qemu_net_queue_append(NetQueue *queue,
+                                     VLANClientState *sender,
+                                     unsigned flags,
+                                     const uint8_t *buf,
+                                     size_t size,
+                                     NetPacketSent *sent_cb)
+{
+    NetPacket *packet;
+
+    packet = qemu_malloc(sizeof(NetPacket) + size);
+    packet->sender = sender;
+    packet->flags = flags;
+    packet->size = size;
+    packet->sent_cb = sent_cb;
+    memcpy(packet->data, buf, size);
+
+    QTAILQ_INSERT_TAIL(&queue->packets, packet, entry);
+
+    return size;
+}
+
+static ssize_t qemu_net_queue_append_iov(NetQueue *queue,
+                                         VLANClientState *sender,
+                                         unsigned flags,
+                                         const struct iovec *iov,
+                                         int iovcnt,
+                                         NetPacketSent *sent_cb)
+{
+    NetPacket *packet;
+    size_t max_len = 0;
+    int i;
+
+    for (i = 0; i < iovcnt; i++) {
+        max_len += iov[i].iov_len;
+    }
+
+    packet = qemu_malloc(sizeof(NetPacket) + max_len);
+    packet->sender = sender;
+    packet->sent_cb = sent_cb;
+    packet->flags = flags;
+    packet->size = 0;
+
+    for (i = 0; i < iovcnt; i++) {
+        size_t len = iov[i].iov_len;
+
+        memcpy(packet->data + packet->size, iov[i].iov_base, len);
+        packet->size += len;
+    }
+
+    QTAILQ_INSERT_TAIL(&queue->packets, packet, entry);
+
+    return packet->size;
+}
+
+static ssize_t qemu_net_queue_deliver(NetQueue *queue,
+                                      VLANClientState *sender,
+                                      unsigned flags,
+                                      const uint8_t *data,
+                                      size_t size)
+{
+    ssize_t ret = -1;
+
+    queue->delivering = 1;
+    ret = queue->deliver(sender, flags, data, size, queue->opaque);
+    queue->delivering = 0;
+
+    return ret;
+}
+
+static ssize_t qemu_net_queue_deliver_iov(NetQueue *queue,
+                                          VLANClientState *sender,
+                                          unsigned flags,
+                                          const struct iovec *iov,
+                                          int iovcnt)
+{
+    ssize_t ret = -1;
+
+    queue->delivering = 1;
+    ret = queue->deliver_iov(sender, flags, iov, iovcnt, queue->opaque);
+    queue->delivering = 0;
+
+    return ret;
+}
+
+ssize_t qemu_net_queue_send(NetQueue *queue,
+                            VLANClientState *sender,
+                            unsigned flags,
+                            const uint8_t *data,
+                            size_t size,
+                            NetPacketSent *sent_cb)
+{
+    ssize_t ret;
+
+    if (queue->delivering) {
+        return qemu_net_queue_append(queue, sender, flags, data, size, NULL);
+    }
+
+    ret = qemu_net_queue_deliver(queue, sender, flags, data, size);
+    if (ret == 0 && sent_cb != NULL) {
+        qemu_net_queue_append(queue, sender, flags, data, size, sent_cb);
+        return 0;
+    }
+
+    qemu_net_queue_flush(queue);
+
+    return ret;
+}
+
+ssize_t qemu_net_queue_send_iov(NetQueue *queue,
+                                VLANClientState *sender,
+                                unsigned flags,
+                                const struct iovec *iov,
+                                int iovcnt,
+                                NetPacketSent *sent_cb)
+{
+    ssize_t ret;
+
+    if (queue->delivering) {
+        return qemu_net_queue_append_iov(queue, sender, flags, iov, iovcnt, NULL);
+    }
+
+    ret = qemu_net_queue_deliver_iov(queue, sender, flags, iov, iovcnt);
+    if (ret == 0 && sent_cb != NULL) {
+        qemu_net_queue_append_iov(queue, sender, flags, iov, iovcnt, sent_cb);
+        return 0;
+    }
+
+    qemu_net_queue_flush(queue);
+
+    return ret;
+}
+
+void qemu_net_queue_purge(NetQueue *queue, VLANClientState *from)
+{
+    NetPacket *packet, *next;
+
+    QTAILQ_FOREACH_SAFE(packet, &queue->packets, entry, next) {
+        if (packet->sender == from) {
+            QTAILQ_REMOVE(&queue->packets, packet, entry);
+            qemu_free(packet);
+        }
+    }
+}
+
+void qemu_net_queue_flush(NetQueue *queue)
+{
+    while (!QTAILQ_EMPTY(&queue->packets)) {
+        NetPacket *packet;
+        int ret;
+
+        packet = QTAILQ_FIRST(&queue->packets);
+        QTAILQ_REMOVE(&queue->packets, packet, entry);
+
+        ret = qemu_net_queue_deliver(queue,
+                                     packet->sender,
+                                     packet->flags,
+                                     packet->data,
+                                     packet->size);
+        if (ret == 0 && packet->sent_cb != NULL) {
+            QTAILQ_INSERT_HEAD(&queue->packets, packet, entry);
+            break;
+        }
+
+        if (packet->sent_cb) {
+            packet->sent_cb(packet->sender, ret);
+        }
+
+        qemu_free(packet);
+    }
+}
diff --git a/net/queue.h b/net/queue.h
new file mode 100644
index 0000000..a31958e
--- /dev/null
+++ b/net/queue.h
@@ -0,0 +1,71 @@
+/*
+ * Copyright (c) 2003-2008 Fabrice Bellard
+ * Copyright (c) 2009 Red Hat, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#ifndef QEMU_NET_QUEUE_H
+#define QEMU_NET_QUEUE_H
+
+#include "qemu-common.h"
+
+typedef struct NetPacket NetPacket;
+typedef struct NetQueue NetQueue;
+
+typedef void (NetPacketSent) (VLANClientState *sender, ssize_t ret);
+
+typedef ssize_t (NetPacketDeliver) (VLANClientState *sender,
+                                    unsigned flags,
+                                    const uint8_t *buf,
+                                    size_t size,
+                                    void *opaque);
+
+typedef ssize_t (NetPacketDeliverIOV) (VLANClientState *sender,
+                                       unsigned flags,
+                                       const struct iovec *iov,
+                                       int iovcnt,
+                                       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,
+                             void *opaque);
+void qemu_del_net_queue(NetQueue *queue);
+
+ssize_t qemu_net_queue_send(NetQueue *queue,
+                            VLANClientState *sender,
+                            unsigned flags,
+                            const uint8_t *data,
+                            size_t size,
+                            NetPacketSent *sent_cb);
+
+ssize_t qemu_net_queue_send_iov(NetQueue *queue,
+                                VLANClientState *sender,
+                                unsigned flags,
+                                const struct iovec *iov,
+                                int iovcnt,
+                                NetPacketSent *sent_cb);
+
+void qemu_net_queue_purge(NetQueue *queue, VLANClientState *from);
+void qemu_net_queue_flush(NetQueue *queue);
+
+#endif /* QEMU_NET_QUEUE_H */
-- 
1.6.2.5

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [Qemu-devel] [PATCH 02/15] net: move net-checksum.c under net/
  2009-10-22 16:49 [Qemu-devel] [PATCH 00/15] Some networking code re-organization Mark McLoughlin
  2009-10-22 16:49 ` [Qemu-devel] [PATCH 01/15] net: move net-queue.[ch] under net/ Mark McLoughlin
@ 2009-10-22 16:49 ` Mark McLoughlin
  2009-10-22 16:49 ` [Qemu-devel] [PATCH 03/15] net: move tap-win32.c " Mark McLoughlin
                   ` (14 subsequent siblings)
  16 siblings, 0 replies; 22+ messages in thread
From: Mark McLoughlin @ 2009-10-22 16:49 UTC (permalink / raw)
  To: qemu-devel; +Cc: Mark McLoughlin

Also add a new net/checksum.h header

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
---
 Makefile        |    4 +-
 hw/e1000.c      |    1 +
 hw/virtio-net.c |    1 +
 hw/xen_nic.c    |    1 +
 net-checksum.c  |   86 -------------------------------------------------------
 net.h           |    7 ----
 net/checksum.c  |   85 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 net/checksum.h  |   29 ++++++++++++++++++
 8 files changed, 119 insertions(+), 95 deletions(-)
 delete mode 100644 net-checksum.c
 create mode 100644 net/checksum.c
 create mode 100644 net/checksum.h

diff --git a/Makefile b/Makefile
index 6fb89fb..c8c0b18 100644
--- a/Makefile
+++ b/Makefile
@@ -87,7 +87,7 @@ block-nested-$(CONFIG_CURL) += curl.o
 block-obj-y +=  $(addprefix block/, $(block-nested-y))
 
 net-obj-y = net.o
-net-nested-y = queue.o
+net-nested-y = queue.o checksum.o
 net-obj-y += $(addprefix net/, $(net-nested-y))
 
 ######################################################################
@@ -126,7 +126,7 @@ obj-$(CONFIG_SD) += sd.o
 obj-y += bt.o bt-host.o bt-vhci.o bt-l2cap.o bt-sdp.o bt-hci.o bt-hid.o usb-bt.o
 obj-y += bt-hci-csr.o
 obj-y += buffered_file.o migration.o migration-tcp.o qemu-sockets.o
-obj-y += qemu-char.o aio.o net-checksum.o savevm.o
+obj-y += qemu-char.o aio.o savevm.o
 obj-y += msmouse.o ps2.o
 obj-y += qdev.o qdev-properties.o
 obj-y += qint.o qstring.o qdict.o qlist.o qemu-config.o
diff --git a/hw/e1000.c b/hw/e1000.c
index f123bda..bf753f2 100644
--- a/hw/e1000.c
+++ b/hw/e1000.c
@@ -25,6 +25,7 @@
 #include "hw.h"
 #include "pci.h"
 #include "net.h"
+#include "net/checksum.h"
 
 #include "e1000_hw.h"
 
diff --git a/hw/virtio-net.c b/hw/virtio-net.c
index 15b6f45..9e0acaf 100644
--- a/hw/virtio-net.c
+++ b/hw/virtio-net.c
@@ -13,6 +13,7 @@
 
 #include "virtio.h"
 #include "net.h"
+#include "net/checksum.h"
 #include "qemu-timer.h"
 #include "virtio-net.h"
 
diff --git a/hw/xen_nic.c b/hw/xen_nic.c
index 75599d6..bcf161c 100644
--- a/hw/xen_nic.c
+++ b/hw/xen_nic.c
@@ -40,6 +40,7 @@
 
 #include "hw.h"
 #include "net.h"
+#include "net/checksum.h"
 #include "qemu-char.h"
 #include "xen_backend.h"
 
diff --git a/net-checksum.c b/net-checksum.c
deleted file mode 100644
index 4956c5c..0000000
--- a/net-checksum.c
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- *  IP checksumming functions.
- *  (c) 2008 Gerd Hoffmann <kraxel@redhat.com>
- *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; under version 2 of the License.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "hw/hw.h"
-#include "net.h"
-
-#define PROTO_TCP  6
-#define PROTO_UDP 17
-
-uint32_t net_checksum_add(int len, uint8_t *buf)
-{
-    uint32_t sum = 0;
-    int i;
-
-    for (i = 0; i < len; i++) {
-	if (i & 1)
-	    sum += (uint32_t)buf[i];
-	else
-	    sum += (uint32_t)buf[i] << 8;
-    }
-    return sum;
-}
-
-uint16_t net_checksum_finish(uint32_t sum)
-{
-    while (sum>>16)
-	sum = (sum & 0xFFFF)+(sum >> 16);
-    return ~sum;
-}
-
-uint16_t net_checksum_tcpudp(uint16_t length, uint16_t proto,
-                             uint8_t *addrs, uint8_t *buf)
-{
-    uint32_t sum = 0;
-
-    sum += net_checksum_add(length, buf);         // payload
-    sum += net_checksum_add(8, addrs);            // src + dst address
-    sum += proto + length;                        // protocol & length
-    return net_checksum_finish(sum);
-}
-
-void net_checksum_calculate(uint8_t *data, int length)
-{
-    int hlen, plen, proto, csum_offset;
-    uint16_t csum;
-
-    if ((data[14] & 0xf0) != 0x40)
-	return; /* not IPv4 */
-    hlen  = (data[14] & 0x0f) * 4;
-    plen  = (data[16] << 8 | data[17]) - hlen;
-    proto = data[23];
-
-    switch (proto) {
-    case PROTO_TCP:
-	csum_offset = 16;
-	break;
-    case PROTO_UDP:
-	csum_offset = 6;
-	break;
-    default:
-	return;
-    }
-
-    if (plen < csum_offset+2)
-	return;
-
-    data[14+hlen+csum_offset]   = 0;
-    data[14+hlen+csum_offset+1] = 0;
-    csum = net_checksum_tcpudp(plen, proto, data+14+12, data+14+hlen);
-    data[14+hlen+csum_offset]   = csum >> 8;
-    data[14+hlen+csum_offset+1] = csum & 0xff;
-}
diff --git a/net.h b/net.h
index 9ebb978..86eb200 100644
--- a/net.h
+++ b/net.h
@@ -128,13 +128,6 @@ struct HCIInfo {
 
 struct HCIInfo *qemu_next_hci(void);
 
-/* checksumming functions (net-checksum.c) */
-uint32_t net_checksum_add(int len, uint8_t *buf);
-uint16_t net_checksum_finish(uint32_t sum);
-uint16_t net_checksum_tcpudp(uint16_t length, uint16_t proto,
-                             uint8_t *addrs, uint8_t *buf);
-void net_checksum_calculate(uint8_t *data, int length);
-
 /* from net.c */
 extern const char *legacy_tftp_prefix;
 extern const char *legacy_bootp_filename;
diff --git a/net/checksum.c b/net/checksum.c
new file mode 100644
index 0000000..4046932
--- /dev/null
+++ b/net/checksum.c
@@ -0,0 +1,85 @@
+/*
+ *  IP checksumming functions.
+ *  (c) 2008 Gerd Hoffmann <kraxel@redhat.com>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; under version 2 of the License.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "net/checksum.h"
+
+#define PROTO_TCP  6
+#define PROTO_UDP 17
+
+uint32_t net_checksum_add(int len, uint8_t *buf)
+{
+    uint32_t sum = 0;
+    int i;
+
+    for (i = 0; i < len; i++) {
+	if (i & 1)
+	    sum += (uint32_t)buf[i];
+	else
+	    sum += (uint32_t)buf[i] << 8;
+    }
+    return sum;
+}
+
+uint16_t net_checksum_finish(uint32_t sum)
+{
+    while (sum>>16)
+	sum = (sum & 0xFFFF)+(sum >> 16);
+    return ~sum;
+}
+
+uint16_t net_checksum_tcpudp(uint16_t length, uint16_t proto,
+                             uint8_t *addrs, uint8_t *buf)
+{
+    uint32_t sum = 0;
+
+    sum += net_checksum_add(length, buf);         // payload
+    sum += net_checksum_add(8, addrs);            // src + dst address
+    sum += proto + length;                        // protocol & length
+    return net_checksum_finish(sum);
+}
+
+void net_checksum_calculate(uint8_t *data, int length)
+{
+    int hlen, plen, proto, csum_offset;
+    uint16_t csum;
+
+    if ((data[14] & 0xf0) != 0x40)
+	return; /* not IPv4 */
+    hlen  = (data[14] & 0x0f) * 4;
+    plen  = (data[16] << 8 | data[17]) - hlen;
+    proto = data[23];
+
+    switch (proto) {
+    case PROTO_TCP:
+	csum_offset = 16;
+	break;
+    case PROTO_UDP:
+	csum_offset = 6;
+	break;
+    default:
+	return;
+    }
+
+    if (plen < csum_offset+2)
+	return;
+
+    data[14+hlen+csum_offset]   = 0;
+    data[14+hlen+csum_offset+1] = 0;
+    csum = net_checksum_tcpudp(plen, proto, data+14+12, data+14+hlen);
+    data[14+hlen+csum_offset]   = csum >> 8;
+    data[14+hlen+csum_offset+1] = csum & 0xff;
+}
diff --git a/net/checksum.h b/net/checksum.h
new file mode 100644
index 0000000..1f05298
--- /dev/null
+++ b/net/checksum.h
@@ -0,0 +1,29 @@
+/*
+ *  IP checksumming functions.
+ *  (c) 2008 Gerd Hoffmann <kraxel@redhat.com>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; under version 2 of the License.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef QEMU_NET_CHECKSUM_H
+#define QEMU_NET_CHECKSUM_H
+
+#include <stdint.h>
+
+uint32_t net_checksum_add(int len, uint8_t *buf);
+uint16_t net_checksum_finish(uint32_t sum);
+uint16_t net_checksum_tcpudp(uint16_t length, uint16_t proto,
+                             uint8_t *addrs, uint8_t *buf);
+void net_checksum_calculate(uint8_t *data, int length);
+
+#endif /* QEMU_NET_CHECKSUM_H */
-- 
1.6.2.5

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [Qemu-devel] [PATCH 03/15] net: move tap-win32.c under net/
  2009-10-22 16:49 [Qemu-devel] [PATCH 00/15] Some networking code re-organization Mark McLoughlin
  2009-10-22 16:49 ` [Qemu-devel] [PATCH 01/15] net: move net-queue.[ch] under net/ Mark McLoughlin
  2009-10-22 16:49 ` [Qemu-devel] [PATCH 02/15] net: move net-checksum.c " Mark McLoughlin
@ 2009-10-22 16:49 ` Mark McLoughlin
  2009-10-22 16:49 ` [Qemu-devel] [PATCH 04/15] net: move more stuff into net/tap-win32.c, add net/tap.h Mark McLoughlin
                   ` (13 subsequent siblings)
  16 siblings, 0 replies; 22+ messages in thread
From: Mark McLoughlin @ 2009-10-22 16:49 UTC (permalink / raw)
  To: qemu-devel; +Cc: Mark McLoughlin

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
---
 Makefile        |    2 +-
 net/tap-win32.c |  690 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 tap-win32.c     |  690 -------------------------------------------------------
 3 files changed, 691 insertions(+), 691 deletions(-)
 create mode 100644 net/tap-win32.c
 delete mode 100644 tap-win32.c

diff --git a/Makefile b/Makefile
index c8c0b18..a49177f 100644
--- a/Makefile
+++ b/Makefile
@@ -88,6 +88,7 @@ block-obj-y +=  $(addprefix block/, $(block-nested-y))
 
 net-obj-y = net.o
 net-nested-y = queue.o checksum.o
+net-nested-$(CONFIG_WIN32) += tap-win32.o
 net-obj-y += $(addprefix net/, $(net-nested-y))
 
 ######################################################################
@@ -132,7 +133,6 @@ obj-y += qdev.o qdev-properties.o
 obj-y += qint.o qstring.o qdict.o qlist.o qemu-config.o
 
 obj-$(CONFIG_BRLAPI) += baum.o
-obj-$(CONFIG_WIN32) += tap-win32.o
 obj-$(CONFIG_POSIX) += migration-exec.o migration-unix.o migration-fd.o
 
 audio/audio.o audio/fmodaudio.o: QEMU_CFLAGS += $(FMOD_CFLAGS)
diff --git a/net/tap-win32.c b/net/tap-win32.c
new file mode 100644
index 0000000..7d92df2
--- /dev/null
+++ b/net/tap-win32.c
@@ -0,0 +1,690 @@
+/*
+ *  TAP-Win32 -- A kernel driver to provide virtual tap device functionality
+ *               on Windows.  Originally derived from the CIPE-Win32
+ *               project by Damion K. Wilson, with extensive modifications by
+ *               James Yonan.
+ *
+ *  All source code which derives from the CIPE-Win32 project is
+ *  Copyright (C) Damion K. Wilson, 2003, and is released under the
+ *  GPL version 2 (see below).
+ *
+ *  All other source code is Copyright (C) James Yonan, 2003-2004,
+ *  and is released under the GPL version 2 (see below).
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program (see the file COPYING included with this
+ *  distribution); if not, see <http://www.gnu.org/licenses/>.
+ */
+#include "qemu-common.h"
+#include "net.h"
+#include "sysemu.h"
+#include <stdio.h>
+#include <windows.h>
+#include <winioctl.h>
+
+//=============
+// TAP IOCTLs
+//=============
+
+#define TAP_CONTROL_CODE(request,method) \
+  CTL_CODE (FILE_DEVICE_UNKNOWN, request, method, FILE_ANY_ACCESS)
+
+#define TAP_IOCTL_GET_MAC               TAP_CONTROL_CODE (1, METHOD_BUFFERED)
+#define TAP_IOCTL_GET_VERSION           TAP_CONTROL_CODE (2, METHOD_BUFFERED)
+#define TAP_IOCTL_GET_MTU               TAP_CONTROL_CODE (3, METHOD_BUFFERED)
+#define TAP_IOCTL_GET_INFO              TAP_CONTROL_CODE (4, METHOD_BUFFERED)
+#define TAP_IOCTL_CONFIG_POINT_TO_POINT TAP_CONTROL_CODE (5, METHOD_BUFFERED)
+#define TAP_IOCTL_SET_MEDIA_STATUS      TAP_CONTROL_CODE (6, METHOD_BUFFERED)
+#define TAP_IOCTL_CONFIG_DHCP_MASQ      TAP_CONTROL_CODE (7, METHOD_BUFFERED)
+#define TAP_IOCTL_GET_LOG_LINE          TAP_CONTROL_CODE (8, METHOD_BUFFERED)
+#define TAP_IOCTL_CONFIG_DHCP_SET_OPT   TAP_CONTROL_CODE (9, METHOD_BUFFERED)
+
+//=================
+// Registry keys
+//=================
+
+#define ADAPTER_KEY "SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002BE10318}"
+
+#define NETWORK_CONNECTIONS_KEY "SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}"
+
+//======================
+// Filesystem prefixes
+//======================
+
+#define USERMODEDEVICEDIR "\\\\.\\Global\\"
+#define TAPSUFFIX         ".tap"
+
+
+//======================
+// Compile time configuration
+//======================
+
+//#define DEBUG_TAP_WIN32
+
+#define TUN_ASYNCHRONOUS_WRITES 1
+
+#define TUN_BUFFER_SIZE 1560
+#define TUN_MAX_BUFFER_COUNT 32
+
+/*
+ * The data member "buffer" must be the first element in the tun_buffer
+ * structure. See the function, tap_win32_free_buffer.
+ */
+typedef struct tun_buffer_s {
+    unsigned char buffer [TUN_BUFFER_SIZE];
+    unsigned long read_size;
+    struct tun_buffer_s* next;
+} tun_buffer_t;
+
+typedef struct tap_win32_overlapped {
+    HANDLE handle;
+    HANDLE read_event;
+    HANDLE write_event;
+    HANDLE output_queue_semaphore;
+    HANDLE free_list_semaphore;
+    HANDLE tap_semaphore;
+    CRITICAL_SECTION output_queue_cs;
+    CRITICAL_SECTION free_list_cs;
+    OVERLAPPED read_overlapped;
+    OVERLAPPED write_overlapped;
+    tun_buffer_t buffers[TUN_MAX_BUFFER_COUNT];
+    tun_buffer_t* free_list;
+    tun_buffer_t* output_queue_front;
+    tun_buffer_t* output_queue_back;
+} tap_win32_overlapped_t;
+
+static tap_win32_overlapped_t tap_overlapped;
+
+static tun_buffer_t* get_buffer_from_free_list(tap_win32_overlapped_t* const overlapped)
+{
+    tun_buffer_t* buffer = NULL;
+    WaitForSingleObject(overlapped->free_list_semaphore, INFINITE);
+    EnterCriticalSection(&overlapped->free_list_cs);
+    buffer = overlapped->free_list;
+//    assert(buffer != NULL);
+    overlapped->free_list = buffer->next;
+    LeaveCriticalSection(&overlapped->free_list_cs);
+    buffer->next = NULL;
+    return buffer;
+}
+
+static void put_buffer_on_free_list(tap_win32_overlapped_t* const overlapped, tun_buffer_t* const buffer)
+{
+    EnterCriticalSection(&overlapped->free_list_cs);
+    buffer->next = overlapped->free_list;
+    overlapped->free_list = buffer;
+    LeaveCriticalSection(&overlapped->free_list_cs);
+    ReleaseSemaphore(overlapped->free_list_semaphore, 1, NULL);
+}
+
+static tun_buffer_t* get_buffer_from_output_queue(tap_win32_overlapped_t* const overlapped, const int block)
+{
+    tun_buffer_t* buffer = NULL;
+    DWORD result, timeout = block ? INFINITE : 0L;
+
+    // Non-blocking call
+    result = WaitForSingleObject(overlapped->output_queue_semaphore, timeout);
+
+    switch (result)
+    {
+        // The semaphore object was signaled.
+        case WAIT_OBJECT_0:
+            EnterCriticalSection(&overlapped->output_queue_cs);
+
+            buffer = overlapped->output_queue_front;
+            overlapped->output_queue_front = buffer->next;
+
+            if(overlapped->output_queue_front == NULL) {
+                overlapped->output_queue_back = NULL;
+            }
+
+            LeaveCriticalSection(&overlapped->output_queue_cs);
+            break;
+
+        // Semaphore was nonsignaled, so a time-out occurred.
+        case WAIT_TIMEOUT:
+            // Cannot open another window.
+            break;
+    }
+
+    return buffer;
+}
+
+static tun_buffer_t* get_buffer_from_output_queue_immediate (tap_win32_overlapped_t* const overlapped)
+{
+    return get_buffer_from_output_queue(overlapped, 0);
+}
+
+static void put_buffer_on_output_queue(tap_win32_overlapped_t* const overlapped, tun_buffer_t* const buffer)
+{
+    EnterCriticalSection(&overlapped->output_queue_cs);
+
+    if(overlapped->output_queue_front == NULL && overlapped->output_queue_back == NULL) {
+        overlapped->output_queue_front = overlapped->output_queue_back = buffer;
+    } else {
+        buffer->next = NULL;
+        overlapped->output_queue_back->next = buffer;
+        overlapped->output_queue_back = buffer;
+    }
+
+    LeaveCriticalSection(&overlapped->output_queue_cs);
+
+    ReleaseSemaphore(overlapped->output_queue_semaphore, 1, NULL);
+}
+
+
+static int is_tap_win32_dev(const char *guid)
+{
+    HKEY netcard_key;
+    LONG status;
+    DWORD len;
+    int i = 0;
+
+    status = RegOpenKeyEx(
+        HKEY_LOCAL_MACHINE,
+        ADAPTER_KEY,
+        0,
+        KEY_READ,
+        &netcard_key);
+
+    if (status != ERROR_SUCCESS) {
+        return FALSE;
+    }
+
+    for (;;) {
+        char enum_name[256];
+        char unit_string[256];
+        HKEY unit_key;
+        char component_id_string[] = "ComponentId";
+        char component_id[256];
+        char net_cfg_instance_id_string[] = "NetCfgInstanceId";
+        char net_cfg_instance_id[256];
+        DWORD data_type;
+
+        len = sizeof (enum_name);
+        status = RegEnumKeyEx(
+            netcard_key,
+            i,
+            enum_name,
+            &len,
+            NULL,
+            NULL,
+            NULL,
+            NULL);
+
+        if (status == ERROR_NO_MORE_ITEMS)
+            break;
+        else if (status != ERROR_SUCCESS) {
+            return FALSE;
+        }
+
+        snprintf (unit_string, sizeof(unit_string), "%s\\%s",
+                  ADAPTER_KEY, enum_name);
+
+        status = RegOpenKeyEx(
+            HKEY_LOCAL_MACHINE,
+            unit_string,
+            0,
+            KEY_READ,
+            &unit_key);
+
+        if (status != ERROR_SUCCESS) {
+            return FALSE;
+        } else {
+            len = sizeof (component_id);
+            status = RegQueryValueEx(
+                unit_key,
+                component_id_string,
+                NULL,
+                &data_type,
+                (LPBYTE)component_id,
+                &len);
+
+            if (!(status != ERROR_SUCCESS || data_type != REG_SZ)) {
+                len = sizeof (net_cfg_instance_id);
+                status = RegQueryValueEx(
+                    unit_key,
+                    net_cfg_instance_id_string,
+                    NULL,
+                    &data_type,
+                    (LPBYTE)net_cfg_instance_id,
+                    &len);
+
+                if (status == ERROR_SUCCESS && data_type == REG_SZ) {
+                    if (/* !strcmp (component_id, TAP_COMPONENT_ID) &&*/
+                        !strcmp (net_cfg_instance_id, guid)) {
+                        RegCloseKey (unit_key);
+                        RegCloseKey (netcard_key);
+                        return TRUE;
+                    }
+                }
+            }
+            RegCloseKey (unit_key);
+        }
+        ++i;
+    }
+
+    RegCloseKey (netcard_key);
+    return FALSE;
+}
+
+static int get_device_guid(
+    char *name,
+    int name_size,
+    char *actual_name,
+    int actual_name_size)
+{
+    LONG status;
+    HKEY control_net_key;
+    DWORD len;
+    int i = 0;
+    int stop = 0;
+
+    status = RegOpenKeyEx(
+        HKEY_LOCAL_MACHINE,
+        NETWORK_CONNECTIONS_KEY,
+        0,
+        KEY_READ,
+        &control_net_key);
+
+    if (status != ERROR_SUCCESS) {
+        return -1;
+    }
+
+    while (!stop)
+    {
+        char enum_name[256];
+        char connection_string[256];
+        HKEY connection_key;
+        char name_data[256];
+        DWORD name_type;
+        const char name_string[] = "Name";
+
+        len = sizeof (enum_name);
+        status = RegEnumKeyEx(
+            control_net_key,
+            i,
+            enum_name,
+            &len,
+            NULL,
+            NULL,
+            NULL,
+            NULL);
+
+        if (status == ERROR_NO_MORE_ITEMS)
+            break;
+        else if (status != ERROR_SUCCESS) {
+            return -1;
+        }
+
+        snprintf(connection_string,
+             sizeof(connection_string),
+             "%s\\%s\\Connection",
+             NETWORK_CONNECTIONS_KEY, enum_name);
+
+        status = RegOpenKeyEx(
+            HKEY_LOCAL_MACHINE,
+            connection_string,
+            0,
+            KEY_READ,
+            &connection_key);
+
+        if (status == ERROR_SUCCESS) {
+            len = sizeof (name_data);
+            status = RegQueryValueEx(
+                connection_key,
+                name_string,
+                NULL,
+                &name_type,
+                (LPBYTE)name_data,
+                &len);
+
+            if (status != ERROR_SUCCESS || name_type != REG_SZ) {
+                    return -1;
+            }
+            else {
+                if (is_tap_win32_dev(enum_name)) {
+                    snprintf(name, name_size, "%s", enum_name);
+                    if (actual_name) {
+                        if (strcmp(actual_name, "") != 0) {
+                            if (strcmp(name_data, actual_name) != 0) {
+                                RegCloseKey (connection_key);
+                                ++i;
+                                continue;
+                            }
+                        }
+                        else {
+                            snprintf(actual_name, actual_name_size, "%s", name_data);
+                        }
+                    }
+                    stop = 1;
+                }
+            }
+
+            RegCloseKey (connection_key);
+        }
+        ++i;
+    }
+
+    RegCloseKey (control_net_key);
+
+    if (stop == 0)
+        return -1;
+
+    return 0;
+}
+
+static int tap_win32_set_status(HANDLE handle, int status)
+{
+    unsigned long len = 0;
+
+    return DeviceIoControl(handle, TAP_IOCTL_SET_MEDIA_STATUS,
+                &status, sizeof (status),
+                &status, sizeof (status), &len, NULL);
+}
+
+static void tap_win32_overlapped_init(tap_win32_overlapped_t* const overlapped, const HANDLE handle)
+{
+    overlapped->handle = handle;
+
+    overlapped->read_event = CreateEvent(NULL, FALSE, FALSE, NULL);
+    overlapped->write_event = CreateEvent(NULL, FALSE, FALSE, NULL);
+
+    overlapped->read_overlapped.Offset = 0;
+    overlapped->read_overlapped.OffsetHigh = 0;
+    overlapped->read_overlapped.hEvent = overlapped->read_event;
+
+    overlapped->write_overlapped.Offset = 0;
+    overlapped->write_overlapped.OffsetHigh = 0;
+    overlapped->write_overlapped.hEvent = overlapped->write_event;
+
+    InitializeCriticalSection(&overlapped->output_queue_cs);
+    InitializeCriticalSection(&overlapped->free_list_cs);
+
+    overlapped->output_queue_semaphore = CreateSemaphore(
+        NULL,   // default security attributes
+        0,   // initial count
+        TUN_MAX_BUFFER_COUNT,   // maximum count
+        NULL);  // unnamed semaphore
+
+    if(!overlapped->output_queue_semaphore)  {
+        fprintf(stderr, "error creating output queue semaphore!\n");
+    }
+
+    overlapped->free_list_semaphore = CreateSemaphore(
+        NULL,   // default security attributes
+        TUN_MAX_BUFFER_COUNT,   // initial count
+        TUN_MAX_BUFFER_COUNT,   // maximum count
+        NULL);  // unnamed semaphore
+
+    if(!overlapped->free_list_semaphore)  {
+        fprintf(stderr, "error creating free list semaphore!\n");
+    }
+
+    overlapped->free_list = overlapped->output_queue_front = overlapped->output_queue_back = NULL;
+
+    {
+        unsigned index;
+        for(index = 0; index < TUN_MAX_BUFFER_COUNT; index++) {
+            tun_buffer_t* element = &overlapped->buffers[index];
+            element->next = overlapped->free_list;
+            overlapped->free_list = element;
+        }
+    }
+    /* To count buffers, initially no-signal. */
+    overlapped->tap_semaphore = CreateSemaphore(NULL, 0, TUN_MAX_BUFFER_COUNT, NULL);
+    if(!overlapped->tap_semaphore)
+        fprintf(stderr, "error creating tap_semaphore.\n");
+}
+
+static int tap_win32_write(tap_win32_overlapped_t *overlapped,
+                           const void *buffer, unsigned long size)
+{
+    unsigned long write_size;
+    BOOL result;
+    DWORD error;
+
+    result = GetOverlappedResult( overlapped->handle, &overlapped->write_overlapped,
+                                  &write_size, FALSE);
+
+    if (!result && GetLastError() == ERROR_IO_INCOMPLETE)
+        WaitForSingleObject(overlapped->write_event, INFINITE);
+
+    result = WriteFile(overlapped->handle, buffer, size,
+                       &write_size, &overlapped->write_overlapped);
+
+    if (!result) {
+        switch (error = GetLastError())
+        {
+        case ERROR_IO_PENDING:
+#ifndef TUN_ASYNCHRONOUS_WRITES
+            WaitForSingleObject(overlapped->write_event, INFINITE);
+#endif
+            break;
+        default:
+            return -1;
+        }
+    }
+
+    return 0;
+}
+
+static DWORD WINAPI tap_win32_thread_entry(LPVOID param)
+{
+    tap_win32_overlapped_t *overlapped = (tap_win32_overlapped_t*)param;
+    unsigned long read_size;
+    BOOL result;
+    DWORD dwError;
+    tun_buffer_t* buffer = get_buffer_from_free_list(overlapped);
+
+
+    for (;;) {
+        result = ReadFile(overlapped->handle,
+                          buffer->buffer,
+                          sizeof(buffer->buffer),
+                          &read_size,
+                          &overlapped->read_overlapped);
+        if (!result) {
+            dwError = GetLastError();
+            if (dwError == ERROR_IO_PENDING) {
+                WaitForSingleObject(overlapped->read_event, INFINITE);
+                result = GetOverlappedResult( overlapped->handle, &overlapped->read_overlapped,
+                                              &read_size, FALSE);
+                if (!result) {
+#ifdef DEBUG_TAP_WIN32
+                    LPVOID lpBuffer;
+                    dwError = GetLastError();
+                    FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
+                                   NULL, dwError, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
+                                   (LPTSTR) & lpBuffer, 0, NULL );
+                    fprintf(stderr, "Tap-Win32: Error GetOverlappedResult %d - %s\n", dwError, lpBuffer);
+                    LocalFree( lpBuffer );
+#endif
+                }
+            } else {
+#ifdef DEBUG_TAP_WIN32
+                LPVOID lpBuffer;
+                FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
+                               NULL, dwError, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
+                               (LPTSTR) & lpBuffer, 0, NULL );
+                fprintf(stderr, "Tap-Win32: Error ReadFile %d - %s\n", dwError, lpBuffer);
+                LocalFree( lpBuffer );
+#endif
+            }
+        }
+
+        if(read_size > 0) {
+            buffer->read_size = read_size;
+            put_buffer_on_output_queue(overlapped, buffer);
+            ReleaseSemaphore(overlapped->tap_semaphore, 1, NULL);
+            buffer = get_buffer_from_free_list(overlapped);
+        }
+    }
+
+    return 0;
+}
+
+static int tap_win32_read(tap_win32_overlapped_t *overlapped,
+                          uint8_t **pbuf, int max_size)
+{
+    int size = 0;
+
+    tun_buffer_t* buffer = get_buffer_from_output_queue_immediate(overlapped);
+
+    if(buffer != NULL) {
+        *pbuf = buffer->buffer;
+        size = (int)buffer->read_size;
+        if(size > max_size) {
+            size = max_size;
+        }
+    }
+
+    return size;
+}
+
+static void tap_win32_free_buffer(tap_win32_overlapped_t *overlapped,
+                                  uint8_t *pbuf)
+{
+    tun_buffer_t* buffer = (tun_buffer_t*)pbuf;
+    put_buffer_on_free_list(overlapped, buffer);
+}
+
+static int tap_win32_open(tap_win32_overlapped_t **phandle,
+                          const char *prefered_name)
+{
+    char device_path[256];
+    char device_guid[0x100];
+    int rc;
+    HANDLE handle;
+    BOOL bret;
+    char name_buffer[0x100] = {0, };
+    struct {
+        unsigned long major;
+        unsigned long minor;
+        unsigned long debug;
+    } version;
+    DWORD version_len;
+    DWORD idThread;
+    HANDLE hThread;
+
+    if (prefered_name != NULL)
+        snprintf(name_buffer, sizeof(name_buffer), "%s", prefered_name);
+
+    rc = get_device_guid(device_guid, sizeof(device_guid), name_buffer, sizeof(name_buffer));
+    if (rc)
+        return -1;
+
+    snprintf (device_path, sizeof(device_path), "%s%s%s",
+              USERMODEDEVICEDIR,
+              device_guid,
+              TAPSUFFIX);
+
+    handle = CreateFile (
+        device_path,
+        GENERIC_READ | GENERIC_WRITE,
+        0,
+        0,
+        OPEN_EXISTING,
+        FILE_ATTRIBUTE_SYSTEM | FILE_FLAG_OVERLAPPED,
+        0 );
+
+    if (handle == INVALID_HANDLE_VALUE) {
+        return -1;
+    }
+
+    bret = DeviceIoControl(handle, TAP_IOCTL_GET_VERSION,
+                           &version, sizeof (version),
+                           &version, sizeof (version), &version_len, NULL);
+
+    if (bret == FALSE) {
+        CloseHandle(handle);
+        return -1;
+    }
+
+    if (!tap_win32_set_status(handle, TRUE)) {
+        return -1;
+    }
+
+    tap_win32_overlapped_init(&tap_overlapped, handle);
+
+    *phandle = &tap_overlapped;
+
+    hThread = CreateThread(NULL, 0, tap_win32_thread_entry,
+                           (LPVOID)&tap_overlapped, 0, &idThread);
+    return 0;
+}
+
+/********************************************/
+
+ typedef struct TAPState {
+     VLANClientState *vc;
+     tap_win32_overlapped_t *handle;
+ } TAPState;
+
+static void tap_cleanup(VLANClientState *vc)
+{
+    TAPState *s = vc->opaque;
+
+    qemu_del_wait_object(s->handle->tap_semaphore, NULL, NULL);
+
+    /* FIXME: need to kill thread and close file handle:
+       tap_win32_close(s);
+    */
+    qemu_free(s);
+}
+
+static ssize_t tap_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
+{
+    TAPState *s = vc->opaque;
+
+    return tap_win32_write(s->handle, buf, size);
+}
+
+static void tap_win32_send(void *opaque)
+{
+    TAPState *s = opaque;
+    uint8_t *buf;
+    int max_size = 4096;
+    int size;
+
+    size = tap_win32_read(s->handle, &buf, max_size);
+    if (size > 0) {
+        qemu_send_packet(s->vc, buf, size);
+        tap_win32_free_buffer(s->handle, buf);
+    }
+}
+
+int tap_win32_init(VLANState *vlan, const char *model,
+                   const char *name, const char *ifname)
+{
+    TAPState *s;
+
+    s = qemu_mallocz(sizeof(TAPState));
+    if (!s)
+        return -1;
+    if (tap_win32_open(&s->handle, ifname) < 0) {
+        printf("tap: Could not open '%s'\n", ifname);
+        return -1;
+    }
+
+    s->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_TAP,
+                                 vlan, NULL, model, name,
+                                 NULL, tap_receive,
+                                 NULL, NULL, tap_cleanup, s);
+
+    snprintf(s->vc->info_str, sizeof(s->vc->info_str),
+             "tap: ifname=%s", ifname);
+
+    qemu_add_wait_object(s->handle->tap_semaphore, tap_win32_send, s);
+    return 0;
+}
diff --git a/tap-win32.c b/tap-win32.c
deleted file mode 100644
index 7d92df2..0000000
--- a/tap-win32.c
+++ /dev/null
@@ -1,690 +0,0 @@
-/*
- *  TAP-Win32 -- A kernel driver to provide virtual tap device functionality
- *               on Windows.  Originally derived from the CIPE-Win32
- *               project by Damion K. Wilson, with extensive modifications by
- *               James Yonan.
- *
- *  All source code which derives from the CIPE-Win32 project is
- *  Copyright (C) Damion K. Wilson, 2003, and is released under the
- *  GPL version 2 (see below).
- *
- *  All other source code is Copyright (C) James Yonan, 2003-2004,
- *  and is released under the GPL version 2 (see below).
- *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with this program (see the file COPYING included with this
- *  distribution); if not, see <http://www.gnu.org/licenses/>.
- */
-#include "qemu-common.h"
-#include "net.h"
-#include "sysemu.h"
-#include <stdio.h>
-#include <windows.h>
-#include <winioctl.h>
-
-//=============
-// TAP IOCTLs
-//=============
-
-#define TAP_CONTROL_CODE(request,method) \
-  CTL_CODE (FILE_DEVICE_UNKNOWN, request, method, FILE_ANY_ACCESS)
-
-#define TAP_IOCTL_GET_MAC               TAP_CONTROL_CODE (1, METHOD_BUFFERED)
-#define TAP_IOCTL_GET_VERSION           TAP_CONTROL_CODE (2, METHOD_BUFFERED)
-#define TAP_IOCTL_GET_MTU               TAP_CONTROL_CODE (3, METHOD_BUFFERED)
-#define TAP_IOCTL_GET_INFO              TAP_CONTROL_CODE (4, METHOD_BUFFERED)
-#define TAP_IOCTL_CONFIG_POINT_TO_POINT TAP_CONTROL_CODE (5, METHOD_BUFFERED)
-#define TAP_IOCTL_SET_MEDIA_STATUS      TAP_CONTROL_CODE (6, METHOD_BUFFERED)
-#define TAP_IOCTL_CONFIG_DHCP_MASQ      TAP_CONTROL_CODE (7, METHOD_BUFFERED)
-#define TAP_IOCTL_GET_LOG_LINE          TAP_CONTROL_CODE (8, METHOD_BUFFERED)
-#define TAP_IOCTL_CONFIG_DHCP_SET_OPT   TAP_CONTROL_CODE (9, METHOD_BUFFERED)
-
-//=================
-// Registry keys
-//=================
-
-#define ADAPTER_KEY "SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002BE10318}"
-
-#define NETWORK_CONNECTIONS_KEY "SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}"
-
-//======================
-// Filesystem prefixes
-//======================
-
-#define USERMODEDEVICEDIR "\\\\.\\Global\\"
-#define TAPSUFFIX         ".tap"
-
-
-//======================
-// Compile time configuration
-//======================
-
-//#define DEBUG_TAP_WIN32
-
-#define TUN_ASYNCHRONOUS_WRITES 1
-
-#define TUN_BUFFER_SIZE 1560
-#define TUN_MAX_BUFFER_COUNT 32
-
-/*
- * The data member "buffer" must be the first element in the tun_buffer
- * structure. See the function, tap_win32_free_buffer.
- */
-typedef struct tun_buffer_s {
-    unsigned char buffer [TUN_BUFFER_SIZE];
-    unsigned long read_size;
-    struct tun_buffer_s* next;
-} tun_buffer_t;
-
-typedef struct tap_win32_overlapped {
-    HANDLE handle;
-    HANDLE read_event;
-    HANDLE write_event;
-    HANDLE output_queue_semaphore;
-    HANDLE free_list_semaphore;
-    HANDLE tap_semaphore;
-    CRITICAL_SECTION output_queue_cs;
-    CRITICAL_SECTION free_list_cs;
-    OVERLAPPED read_overlapped;
-    OVERLAPPED write_overlapped;
-    tun_buffer_t buffers[TUN_MAX_BUFFER_COUNT];
-    tun_buffer_t* free_list;
-    tun_buffer_t* output_queue_front;
-    tun_buffer_t* output_queue_back;
-} tap_win32_overlapped_t;
-
-static tap_win32_overlapped_t tap_overlapped;
-
-static tun_buffer_t* get_buffer_from_free_list(tap_win32_overlapped_t* const overlapped)
-{
-    tun_buffer_t* buffer = NULL;
-    WaitForSingleObject(overlapped->free_list_semaphore, INFINITE);
-    EnterCriticalSection(&overlapped->free_list_cs);
-    buffer = overlapped->free_list;
-//    assert(buffer != NULL);
-    overlapped->free_list = buffer->next;
-    LeaveCriticalSection(&overlapped->free_list_cs);
-    buffer->next = NULL;
-    return buffer;
-}
-
-static void put_buffer_on_free_list(tap_win32_overlapped_t* const overlapped, tun_buffer_t* const buffer)
-{
-    EnterCriticalSection(&overlapped->free_list_cs);
-    buffer->next = overlapped->free_list;
-    overlapped->free_list = buffer;
-    LeaveCriticalSection(&overlapped->free_list_cs);
-    ReleaseSemaphore(overlapped->free_list_semaphore, 1, NULL);
-}
-
-static tun_buffer_t* get_buffer_from_output_queue(tap_win32_overlapped_t* const overlapped, const int block)
-{
-    tun_buffer_t* buffer = NULL;
-    DWORD result, timeout = block ? INFINITE : 0L;
-
-    // Non-blocking call
-    result = WaitForSingleObject(overlapped->output_queue_semaphore, timeout);
-
-    switch (result)
-    {
-        // The semaphore object was signaled.
-        case WAIT_OBJECT_0:
-            EnterCriticalSection(&overlapped->output_queue_cs);
-
-            buffer = overlapped->output_queue_front;
-            overlapped->output_queue_front = buffer->next;
-
-            if(overlapped->output_queue_front == NULL) {
-                overlapped->output_queue_back = NULL;
-            }
-
-            LeaveCriticalSection(&overlapped->output_queue_cs);
-            break;
-
-        // Semaphore was nonsignaled, so a time-out occurred.
-        case WAIT_TIMEOUT:
-            // Cannot open another window.
-            break;
-    }
-
-    return buffer;
-}
-
-static tun_buffer_t* get_buffer_from_output_queue_immediate (tap_win32_overlapped_t* const overlapped)
-{
-    return get_buffer_from_output_queue(overlapped, 0);
-}
-
-static void put_buffer_on_output_queue(tap_win32_overlapped_t* const overlapped, tun_buffer_t* const buffer)
-{
-    EnterCriticalSection(&overlapped->output_queue_cs);
-
-    if(overlapped->output_queue_front == NULL && overlapped->output_queue_back == NULL) {
-        overlapped->output_queue_front = overlapped->output_queue_back = buffer;
-    } else {
-        buffer->next = NULL;
-        overlapped->output_queue_back->next = buffer;
-        overlapped->output_queue_back = buffer;
-    }
-
-    LeaveCriticalSection(&overlapped->output_queue_cs);
-
-    ReleaseSemaphore(overlapped->output_queue_semaphore, 1, NULL);
-}
-
-
-static int is_tap_win32_dev(const char *guid)
-{
-    HKEY netcard_key;
-    LONG status;
-    DWORD len;
-    int i = 0;
-
-    status = RegOpenKeyEx(
-        HKEY_LOCAL_MACHINE,
-        ADAPTER_KEY,
-        0,
-        KEY_READ,
-        &netcard_key);
-
-    if (status != ERROR_SUCCESS) {
-        return FALSE;
-    }
-
-    for (;;) {
-        char enum_name[256];
-        char unit_string[256];
-        HKEY unit_key;
-        char component_id_string[] = "ComponentId";
-        char component_id[256];
-        char net_cfg_instance_id_string[] = "NetCfgInstanceId";
-        char net_cfg_instance_id[256];
-        DWORD data_type;
-
-        len = sizeof (enum_name);
-        status = RegEnumKeyEx(
-            netcard_key,
-            i,
-            enum_name,
-            &len,
-            NULL,
-            NULL,
-            NULL,
-            NULL);
-
-        if (status == ERROR_NO_MORE_ITEMS)
-            break;
-        else if (status != ERROR_SUCCESS) {
-            return FALSE;
-        }
-
-        snprintf (unit_string, sizeof(unit_string), "%s\\%s",
-                  ADAPTER_KEY, enum_name);
-
-        status = RegOpenKeyEx(
-            HKEY_LOCAL_MACHINE,
-            unit_string,
-            0,
-            KEY_READ,
-            &unit_key);
-
-        if (status != ERROR_SUCCESS) {
-            return FALSE;
-        } else {
-            len = sizeof (component_id);
-            status = RegQueryValueEx(
-                unit_key,
-                component_id_string,
-                NULL,
-                &data_type,
-                (LPBYTE)component_id,
-                &len);
-
-            if (!(status != ERROR_SUCCESS || data_type != REG_SZ)) {
-                len = sizeof (net_cfg_instance_id);
-                status = RegQueryValueEx(
-                    unit_key,
-                    net_cfg_instance_id_string,
-                    NULL,
-                    &data_type,
-                    (LPBYTE)net_cfg_instance_id,
-                    &len);
-
-                if (status == ERROR_SUCCESS && data_type == REG_SZ) {
-                    if (/* !strcmp (component_id, TAP_COMPONENT_ID) &&*/
-                        !strcmp (net_cfg_instance_id, guid)) {
-                        RegCloseKey (unit_key);
-                        RegCloseKey (netcard_key);
-                        return TRUE;
-                    }
-                }
-            }
-            RegCloseKey (unit_key);
-        }
-        ++i;
-    }
-
-    RegCloseKey (netcard_key);
-    return FALSE;
-}
-
-static int get_device_guid(
-    char *name,
-    int name_size,
-    char *actual_name,
-    int actual_name_size)
-{
-    LONG status;
-    HKEY control_net_key;
-    DWORD len;
-    int i = 0;
-    int stop = 0;
-
-    status = RegOpenKeyEx(
-        HKEY_LOCAL_MACHINE,
-        NETWORK_CONNECTIONS_KEY,
-        0,
-        KEY_READ,
-        &control_net_key);
-
-    if (status != ERROR_SUCCESS) {
-        return -1;
-    }
-
-    while (!stop)
-    {
-        char enum_name[256];
-        char connection_string[256];
-        HKEY connection_key;
-        char name_data[256];
-        DWORD name_type;
-        const char name_string[] = "Name";
-
-        len = sizeof (enum_name);
-        status = RegEnumKeyEx(
-            control_net_key,
-            i,
-            enum_name,
-            &len,
-            NULL,
-            NULL,
-            NULL,
-            NULL);
-
-        if (status == ERROR_NO_MORE_ITEMS)
-            break;
-        else if (status != ERROR_SUCCESS) {
-            return -1;
-        }
-
-        snprintf(connection_string,
-             sizeof(connection_string),
-             "%s\\%s\\Connection",
-             NETWORK_CONNECTIONS_KEY, enum_name);
-
-        status = RegOpenKeyEx(
-            HKEY_LOCAL_MACHINE,
-            connection_string,
-            0,
-            KEY_READ,
-            &connection_key);
-
-        if (status == ERROR_SUCCESS) {
-            len = sizeof (name_data);
-            status = RegQueryValueEx(
-                connection_key,
-                name_string,
-                NULL,
-                &name_type,
-                (LPBYTE)name_data,
-                &len);
-
-            if (status != ERROR_SUCCESS || name_type != REG_SZ) {
-                    return -1;
-            }
-            else {
-                if (is_tap_win32_dev(enum_name)) {
-                    snprintf(name, name_size, "%s", enum_name);
-                    if (actual_name) {
-                        if (strcmp(actual_name, "") != 0) {
-                            if (strcmp(name_data, actual_name) != 0) {
-                                RegCloseKey (connection_key);
-                                ++i;
-                                continue;
-                            }
-                        }
-                        else {
-                            snprintf(actual_name, actual_name_size, "%s", name_data);
-                        }
-                    }
-                    stop = 1;
-                }
-            }
-
-            RegCloseKey (connection_key);
-        }
-        ++i;
-    }
-
-    RegCloseKey (control_net_key);
-
-    if (stop == 0)
-        return -1;
-
-    return 0;
-}
-
-static int tap_win32_set_status(HANDLE handle, int status)
-{
-    unsigned long len = 0;
-
-    return DeviceIoControl(handle, TAP_IOCTL_SET_MEDIA_STATUS,
-                &status, sizeof (status),
-                &status, sizeof (status), &len, NULL);
-}
-
-static void tap_win32_overlapped_init(tap_win32_overlapped_t* const overlapped, const HANDLE handle)
-{
-    overlapped->handle = handle;
-
-    overlapped->read_event = CreateEvent(NULL, FALSE, FALSE, NULL);
-    overlapped->write_event = CreateEvent(NULL, FALSE, FALSE, NULL);
-
-    overlapped->read_overlapped.Offset = 0;
-    overlapped->read_overlapped.OffsetHigh = 0;
-    overlapped->read_overlapped.hEvent = overlapped->read_event;
-
-    overlapped->write_overlapped.Offset = 0;
-    overlapped->write_overlapped.OffsetHigh = 0;
-    overlapped->write_overlapped.hEvent = overlapped->write_event;
-
-    InitializeCriticalSection(&overlapped->output_queue_cs);
-    InitializeCriticalSection(&overlapped->free_list_cs);
-
-    overlapped->output_queue_semaphore = CreateSemaphore(
-        NULL,   // default security attributes
-        0,   // initial count
-        TUN_MAX_BUFFER_COUNT,   // maximum count
-        NULL);  // unnamed semaphore
-
-    if(!overlapped->output_queue_semaphore)  {
-        fprintf(stderr, "error creating output queue semaphore!\n");
-    }
-
-    overlapped->free_list_semaphore = CreateSemaphore(
-        NULL,   // default security attributes
-        TUN_MAX_BUFFER_COUNT,   // initial count
-        TUN_MAX_BUFFER_COUNT,   // maximum count
-        NULL);  // unnamed semaphore
-
-    if(!overlapped->free_list_semaphore)  {
-        fprintf(stderr, "error creating free list semaphore!\n");
-    }
-
-    overlapped->free_list = overlapped->output_queue_front = overlapped->output_queue_back = NULL;
-
-    {
-        unsigned index;
-        for(index = 0; index < TUN_MAX_BUFFER_COUNT; index++) {
-            tun_buffer_t* element = &overlapped->buffers[index];
-            element->next = overlapped->free_list;
-            overlapped->free_list = element;
-        }
-    }
-    /* To count buffers, initially no-signal. */
-    overlapped->tap_semaphore = CreateSemaphore(NULL, 0, TUN_MAX_BUFFER_COUNT, NULL);
-    if(!overlapped->tap_semaphore)
-        fprintf(stderr, "error creating tap_semaphore.\n");
-}
-
-static int tap_win32_write(tap_win32_overlapped_t *overlapped,
-                           const void *buffer, unsigned long size)
-{
-    unsigned long write_size;
-    BOOL result;
-    DWORD error;
-
-    result = GetOverlappedResult( overlapped->handle, &overlapped->write_overlapped,
-                                  &write_size, FALSE);
-
-    if (!result && GetLastError() == ERROR_IO_INCOMPLETE)
-        WaitForSingleObject(overlapped->write_event, INFINITE);
-
-    result = WriteFile(overlapped->handle, buffer, size,
-                       &write_size, &overlapped->write_overlapped);
-
-    if (!result) {
-        switch (error = GetLastError())
-        {
-        case ERROR_IO_PENDING:
-#ifndef TUN_ASYNCHRONOUS_WRITES
-            WaitForSingleObject(overlapped->write_event, INFINITE);
-#endif
-            break;
-        default:
-            return -1;
-        }
-    }
-
-    return 0;
-}
-
-static DWORD WINAPI tap_win32_thread_entry(LPVOID param)
-{
-    tap_win32_overlapped_t *overlapped = (tap_win32_overlapped_t*)param;
-    unsigned long read_size;
-    BOOL result;
-    DWORD dwError;
-    tun_buffer_t* buffer = get_buffer_from_free_list(overlapped);
-
-
-    for (;;) {
-        result = ReadFile(overlapped->handle,
-                          buffer->buffer,
-                          sizeof(buffer->buffer),
-                          &read_size,
-                          &overlapped->read_overlapped);
-        if (!result) {
-            dwError = GetLastError();
-            if (dwError == ERROR_IO_PENDING) {
-                WaitForSingleObject(overlapped->read_event, INFINITE);
-                result = GetOverlappedResult( overlapped->handle, &overlapped->read_overlapped,
-                                              &read_size, FALSE);
-                if (!result) {
-#ifdef DEBUG_TAP_WIN32
-                    LPVOID lpBuffer;
-                    dwError = GetLastError();
-                    FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
-                                   NULL, dwError, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
-                                   (LPTSTR) & lpBuffer, 0, NULL );
-                    fprintf(stderr, "Tap-Win32: Error GetOverlappedResult %d - %s\n", dwError, lpBuffer);
-                    LocalFree( lpBuffer );
-#endif
-                }
-            } else {
-#ifdef DEBUG_TAP_WIN32
-                LPVOID lpBuffer;
-                FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
-                               NULL, dwError, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
-                               (LPTSTR) & lpBuffer, 0, NULL );
-                fprintf(stderr, "Tap-Win32: Error ReadFile %d - %s\n", dwError, lpBuffer);
-                LocalFree( lpBuffer );
-#endif
-            }
-        }
-
-        if(read_size > 0) {
-            buffer->read_size = read_size;
-            put_buffer_on_output_queue(overlapped, buffer);
-            ReleaseSemaphore(overlapped->tap_semaphore, 1, NULL);
-            buffer = get_buffer_from_free_list(overlapped);
-        }
-    }
-
-    return 0;
-}
-
-static int tap_win32_read(tap_win32_overlapped_t *overlapped,
-                          uint8_t **pbuf, int max_size)
-{
-    int size = 0;
-
-    tun_buffer_t* buffer = get_buffer_from_output_queue_immediate(overlapped);
-
-    if(buffer != NULL) {
-        *pbuf = buffer->buffer;
-        size = (int)buffer->read_size;
-        if(size > max_size) {
-            size = max_size;
-        }
-    }
-
-    return size;
-}
-
-static void tap_win32_free_buffer(tap_win32_overlapped_t *overlapped,
-                                  uint8_t *pbuf)
-{
-    tun_buffer_t* buffer = (tun_buffer_t*)pbuf;
-    put_buffer_on_free_list(overlapped, buffer);
-}
-
-static int tap_win32_open(tap_win32_overlapped_t **phandle,
-                          const char *prefered_name)
-{
-    char device_path[256];
-    char device_guid[0x100];
-    int rc;
-    HANDLE handle;
-    BOOL bret;
-    char name_buffer[0x100] = {0, };
-    struct {
-        unsigned long major;
-        unsigned long minor;
-        unsigned long debug;
-    } version;
-    DWORD version_len;
-    DWORD idThread;
-    HANDLE hThread;
-
-    if (prefered_name != NULL)
-        snprintf(name_buffer, sizeof(name_buffer), "%s", prefered_name);
-
-    rc = get_device_guid(device_guid, sizeof(device_guid), name_buffer, sizeof(name_buffer));
-    if (rc)
-        return -1;
-
-    snprintf (device_path, sizeof(device_path), "%s%s%s",
-              USERMODEDEVICEDIR,
-              device_guid,
-              TAPSUFFIX);
-
-    handle = CreateFile (
-        device_path,
-        GENERIC_READ | GENERIC_WRITE,
-        0,
-        0,
-        OPEN_EXISTING,
-        FILE_ATTRIBUTE_SYSTEM | FILE_FLAG_OVERLAPPED,
-        0 );
-
-    if (handle == INVALID_HANDLE_VALUE) {
-        return -1;
-    }
-
-    bret = DeviceIoControl(handle, TAP_IOCTL_GET_VERSION,
-                           &version, sizeof (version),
-                           &version, sizeof (version), &version_len, NULL);
-
-    if (bret == FALSE) {
-        CloseHandle(handle);
-        return -1;
-    }
-
-    if (!tap_win32_set_status(handle, TRUE)) {
-        return -1;
-    }
-
-    tap_win32_overlapped_init(&tap_overlapped, handle);
-
-    *phandle = &tap_overlapped;
-
-    hThread = CreateThread(NULL, 0, tap_win32_thread_entry,
-                           (LPVOID)&tap_overlapped, 0, &idThread);
-    return 0;
-}
-
-/********************************************/
-
- typedef struct TAPState {
-     VLANClientState *vc;
-     tap_win32_overlapped_t *handle;
- } TAPState;
-
-static void tap_cleanup(VLANClientState *vc)
-{
-    TAPState *s = vc->opaque;
-
-    qemu_del_wait_object(s->handle->tap_semaphore, NULL, NULL);
-
-    /* FIXME: need to kill thread and close file handle:
-       tap_win32_close(s);
-    */
-    qemu_free(s);
-}
-
-static ssize_t tap_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
-{
-    TAPState *s = vc->opaque;
-
-    return tap_win32_write(s->handle, buf, size);
-}
-
-static void tap_win32_send(void *opaque)
-{
-    TAPState *s = opaque;
-    uint8_t *buf;
-    int max_size = 4096;
-    int size;
-
-    size = tap_win32_read(s->handle, &buf, max_size);
-    if (size > 0) {
-        qemu_send_packet(s->vc, buf, size);
-        tap_win32_free_buffer(s->handle, buf);
-    }
-}
-
-int tap_win32_init(VLANState *vlan, const char *model,
-                   const char *name, const char *ifname)
-{
-    TAPState *s;
-
-    s = qemu_mallocz(sizeof(TAPState));
-    if (!s)
-        return -1;
-    if (tap_win32_open(&s->handle, ifname) < 0) {
-        printf("tap: Could not open '%s'\n", ifname);
-        return -1;
-    }
-
-    s->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_TAP,
-                                 vlan, NULL, model, name,
-                                 NULL, tap_receive,
-                                 NULL, NULL, tap_cleanup, s);
-
-    snprintf(s->vc->info_str, sizeof(s->vc->info_str),
-             "tap: ifname=%s", ifname);
-
-    qemu_add_wait_object(s->handle->tap_semaphore, tap_win32_send, s);
-    return 0;
-}
-- 
1.6.2.5

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [Qemu-devel] [PATCH 04/15] net: move more stuff into net/tap-win32.c, add net/tap.h
  2009-10-22 16:49 [Qemu-devel] [PATCH 00/15] Some networking code re-organization Mark McLoughlin
                   ` (2 preceding siblings ...)
  2009-10-22 16:49 ` [Qemu-devel] [PATCH 03/15] net: move tap-win32.c " Mark McLoughlin
@ 2009-10-22 16:49 ` Mark McLoughlin
  2009-10-22 16:49 ` [Qemu-devel] [PATCH 05/15] net: move tap-linux.h under net/ Mark McLoughlin
                   ` (12 subsequent siblings)
  16 siblings, 0 replies; 22+ messages in thread
From: Mark McLoughlin @ 2009-10-22 16:49 UTC (permalink / raw)
  To: qemu-devel; +Cc: Mark McLoughlin

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
---
 hw/virtio-net.c |    1 +
 net.c           |   75 ++++++++----------------------------------------------
 net.h           |    5 ---
 net/tap-win32.c |   48 +++++++++++++++++++++++++++++++++-
 net/tap.h       |   42 ++++++++++++++++++++++++++++++
 sysemu.h        |    4 ---
 6 files changed, 100 insertions(+), 75 deletions(-)
 create mode 100644 net/tap.h

diff --git a/hw/virtio-net.c b/hw/virtio-net.c
index 9e0acaf..7ee393b 100644
--- a/hw/virtio-net.c
+++ b/hw/virtio-net.c
@@ -14,6 +14,7 @@
 #include "virtio.h"
 #include "net.h"
 #include "net/checksum.h"
+#include "net/tap.h"
 #include "qemu-timer.h"
 #include "virtio-net.h"
 
diff --git a/net.c b/net.c
index 3e54c53..2f31562 100644
--- a/net.c
+++ b/net.c
@@ -103,6 +103,7 @@
 
 #include "qemu-common.h"
 #include "net.h"
+#include "net/tap.h"
 #include "monitor.h"
 #include "sysemu.h"
 #include "qemu-timer.h"
@@ -1279,23 +1280,7 @@ void do_info_usernet(Monitor *mon)
 
 #endif /* CONFIG_SLIRP */
 
-#if defined(_WIN32)
-int tap_has_ufo(VLANClientState *vc)
-{
-    return 0;
-}
-int tap_has_vnet_hdr(VLANClientState *vc)
-{
-    return 0;
-}
-void tap_using_vnet_hdr(VLANClientState *vc, int using_vnet_hdr)
-{
-}
-void tap_set_offload(VLANClientState *vc, int csum, int tso4,
-                     int tso6, int ecn, int ufo)
-{
-}
-#else /* !defined(_WIN32) */
+#if !defined(_WIN32) && !defined(_AIX)
 
 /* Maximum GSO packet size (64k) plus plenty of room for
  * the ethernet and virtio_net headers
@@ -1905,7 +1890,7 @@ static int net_tap_init(QemuOpts *opts, int *vnet_hdr)
     return fd;
 }
 
-#endif /* !_WIN32 */
+#endif /* !defined(_WIN32) && !defined(_AIX) */
 
 #if defined(CONFIG_VDE)
 typedef struct VDEState {
@@ -2802,36 +2787,8 @@ static int net_init_slirp(QemuOpts *opts,
 }
 #endif /* CONFIG_SLIRP */
 
-#ifdef _WIN32
-static int net_init_tap_win32(QemuOpts *opts,
-                              Monitor *mon,
-                              const char *name,
-                              VLANState *vlan)
-{
-    const char *ifname;
-
-    ifname = qemu_opt_get(opts, "ifname");
-
-    if (!ifname) {
-        qemu_error("tap: no interface name\n");
-        return -1;
-    }
-
-    if (tap_win32_init(vlan, "tap", name, ifname) == -1) {
-        return -1;
-    }
-
-    if (vlan) {
-        vlan->nb_host_devs++;
-    }
-
-    return 0;
-}
-#elif !defined(_AIX)
-static int net_init_tap(QemuOpts *opts,
-                        Monitor *mon,
-                        const char *name,
-                        VLANState *vlan)
+#if !defined(_WIN32) && !defined(_AIX)
+int net_init_tap(QemuOpts *opts, Monitor *mon, const char *name, VLANState *vlan)
 {
     TAPState *s;
     int fd, vnet_hdr;
@@ -2900,7 +2857,7 @@ static int net_init_tap(QemuOpts *opts,
 
     return 0;
 }
-#endif
+#endif /* !defined(_WIN32) && !defined(_AIX) */
 
 static int net_init_socket(QemuOpts *opts,
                            Monitor *mon,
@@ -3158,10 +3115,10 @@ static struct {
             { /* end of list */ }
         },
 #endif
-#ifdef _WIN32
+#ifndef _AIX
     }, {
         .type = "tap",
-        .init = net_init_tap_win32,
+        .init = net_init_tap,
         .desc = {
             NET_COMMON_PARAMS_DESC,
             {
@@ -3169,23 +3126,12 @@ static struct {
                 .type = QEMU_OPT_STRING,
                 .help = "interface name",
             },
-            { /* end of list */ }
-        },
-#elif !defined(_AIX)
-    }, {
-        .type = "tap",
-        .init = net_init_tap,
-        .desc = {
-            NET_COMMON_PARAMS_DESC,
+#ifndef _WIN32
             {
                 .name = "fd",
                 .type = QEMU_OPT_STRING,
                 .help = "file descriptor of an already opened tap",
             }, {
-                .name = "ifname",
-                .type = QEMU_OPT_STRING,
-                .help = "interface name",
-            }, {
                 .name = "script",
                 .type = QEMU_OPT_STRING,
                 .help = "script to initialize the interface",
@@ -3202,9 +3148,10 @@ static struct {
                 .type = QEMU_OPT_BOOL,
                 .help = "enable the IFF_VNET_HDR flag on the tap interface"
             },
+#endif /* _WIN32 */
             { /* end of list */ }
         },
-#endif
+#endif /* _AIX */
     }, {
         .type = "socket",
         .init = net_init_socket,
diff --git a/net.h b/net.h
index 86eb200..1a907c7 100644
--- a/net.h
+++ b/net.h
@@ -161,9 +161,4 @@ VLANClientState *qdev_get_vlan_client(DeviceState *dev,
                                       NetCleanup *cleanup,
                                       void *opaque);
 
-int tap_has_ufo(VLANClientState *vc);
-int tap_has_vnet_hdr(VLANClientState *vc);
-void tap_using_vnet_hdr(VLANClientState *vc, int using_vnet_hdr);
-void tap_set_offload(VLANClientState *vc, int csum, int tso4, int tso6, int ecn, int ufo);
-
 #endif
diff --git a/net/tap-win32.c b/net/tap-win32.c
index 7d92df2..ea66471 100644
--- a/net/tap-win32.c
+++ b/net/tap-win32.c
@@ -25,6 +25,9 @@
  *  along with this program (see the file COPYING included with this
  *  distribution); if not, see <http://www.gnu.org/licenses/>.
  */
+
+#include "net/tap.h"
+
 #include "qemu-common.h"
 #include "net.h"
 #include "sysemu.h"
@@ -664,8 +667,8 @@ static void tap_win32_send(void *opaque)
     }
 }
 
-int tap_win32_init(VLANState *vlan, const char *model,
-                   const char *name, const char *ifname)
+static int tap_win32_init(VLANState *vlan, const char *model,
+                          const char *name, const char *ifname)
 {
     TAPState *s;
 
@@ -688,3 +691,44 @@ int tap_win32_init(VLANState *vlan, const char *model,
     qemu_add_wait_object(s->handle->tap_semaphore, tap_win32_send, s);
     return 0;
 }
+
+int net_init_tap(QemuOpts *opts, Monitor *mon, const char *name, VLANState *vlan)
+{
+    const char *ifname;
+
+    ifname = qemu_opt_get(opts, "ifname");
+
+    if (!ifname) {
+        qemu_error("tap: no interface name\n");
+        return -1;
+    }
+
+    if (tap_win32_init(vlan, "tap", name, ifname) == -1) {
+        return -1;
+    }
+
+    if (vlan) {
+        vlan->nb_host_devs++;
+    }
+
+    return 0;
+}
+
+int tap_has_ufo(VLANClientState *vc)
+{
+    return 0;
+}
+
+int tap_has_vnet_hdr(VLANClientState *vc)
+{
+    return 0;
+}
+
+void tap_using_vnet_hdr(VLANClientState *vc, int using_vnet_hdr)
+{
+}
+
+void tap_set_offload(VLANClientState *vc, int csum, int tso4,
+                     int tso6, int ecn, int ufo)
+{
+}
diff --git a/net/tap.h b/net/tap.h
new file mode 100644
index 0000000..53952a1
--- /dev/null
+++ b/net/tap.h
@@ -0,0 +1,42 @@
+/*
+ * QEMU System Emulator
+ *
+ * Copyright (c) 2003-2008 Fabrice Bellard
+ * Copyright (c) 2009 Red Hat, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#ifndef QEMU_NET_TAP_H
+#define QEMU_NET_TAP_H
+
+#include "qemu-common.h"
+#include "qemu-option.h"
+
+#define DEFAULT_NETWORK_SCRIPT "/etc/qemu-ifup"
+#define DEFAULT_NETWORK_DOWN_SCRIPT "/etc/qemu-ifdown"
+
+int net_init_tap(QemuOpts *opts, Monitor *mon, const char *name, VLANState *vlan);
+
+int tap_has_ufo(VLANClientState *vc);
+int tap_has_vnet_hdr(VLANClientState *vc);
+void tap_using_vnet_hdr(VLANClientState *vc, int using_vnet_hdr);
+void tap_set_offload(VLANClientState *vc, int csum, int tso4, int tso6, int ecn, int ufo);
+
+#endif /* QEMU_NET_TAP_H */
diff --git a/sysemu.h b/sysemu.h
index 763861d..05822dc 100644
--- a/sysemu.h
+++ b/sysemu.h
@@ -88,10 +88,6 @@ int qemu_add_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque);
 void qemu_del_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque);
 #endif
 
-/* TAP win32 */
-int tap_win32_init(VLANState *vlan, const char *model,
-                   const char *name, const char *ifname);
-
 /* SLIRP */
 void do_info_slirp(Monitor *mon);
 
-- 
1.6.2.5

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [Qemu-devel] [PATCH 05/15] net: move tap-linux.h under net/
  2009-10-22 16:49 [Qemu-devel] [PATCH 00/15] Some networking code re-organization Mark McLoughlin
                   ` (3 preceding siblings ...)
  2009-10-22 16:49 ` [Qemu-devel] [PATCH 04/15] net: move more stuff into net/tap-win32.c, add net/tap.h Mark McLoughlin
@ 2009-10-22 16:49 ` Mark McLoughlin
  2009-10-22 16:49 ` [Qemu-devel] [PATCH 06/15] net: split all the tap code out into net/tap.c Mark McLoughlin
                   ` (11 subsequent siblings)
  16 siblings, 0 replies; 22+ messages in thread
From: Mark McLoughlin @ 2009-10-22 16:49 UTC (permalink / raw)
  To: qemu-devel; +Cc: Mark McLoughlin

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
---
 net.c           |    2 +-
 net/tap-linux.h |   51 +++++++++++++++++++++++++++++++++++++++++++++++++++
 tap-linux.h     |   51 ---------------------------------------------------
 3 files changed, 52 insertions(+), 52 deletions(-)
 create mode 100644 net/tap-linux.h
 delete mode 100644 tap-linux.h

diff --git a/net.c b/net.c
index 2f31562..3225dcd 100644
--- a/net.c
+++ b/net.c
@@ -46,7 +46,7 @@
 #include <net/if_tap.h>
 #endif
 #ifdef __linux__
-#include "tap-linux.h"
+#include "net/tap-linux.h"
 #endif
 #include <arpa/inet.h>
 #include <dirent.h>
diff --git a/net/tap-linux.h b/net/tap-linux.h
new file mode 100644
index 0000000..d81c650
--- /dev/null
+++ b/net/tap-linux.h
@@ -0,0 +1,51 @@
+/*
+ *  Universal TUN/TAP device driver.
+ *  Copyright (C) 1999-2000 Maxim Krasnyansky <max_mk@yahoo.com>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ *  GNU General Public License for more details.
+ */
+
+#ifndef QEMU_TAP_H
+#define QEMU_TAP_H
+
+#include <stdint.h>
+#include <linux/ioctl.h>
+
+/* Ioctl defines */
+#define TUNSETIFF     _IOW('T', 202, int)
+#define TUNGETFEATURES _IOR('T', 207, unsigned int)
+#define TUNSETOFFLOAD  _IOW('T', 208, unsigned int)
+#define TUNGETIFF      _IOR('T', 210, unsigned int)
+#define TUNSETSNDBUF   _IOW('T', 212, int)
+
+/* TUNSETIFF ifr flags */
+#define IFF_TAP		0x0002
+#define IFF_NO_PI	0x1000
+#define IFF_VNET_HDR	0x4000
+
+/* Features for GSO (TUNSETOFFLOAD). */
+#define TUN_F_CSUM	0x01	/* You can hand me unchecksummed packets. */
+#define TUN_F_TSO4	0x02	/* I can handle TSO for IPv4 packets */
+#define TUN_F_TSO6	0x04	/* I can handle TSO for IPv6 packets */
+#define TUN_F_TSO_ECN	0x08	/* I can handle TSO with ECN bits. */
+#define TUN_F_UFO	0x10	/* I can handle UFO packets */
+
+struct virtio_net_hdr
+{
+    uint8_t flags;
+    uint8_t gso_type;
+    uint16_t hdr_len;
+    uint16_t gso_size;
+    uint16_t csum_start;
+    uint16_t csum_offset;
+};
+
+#endif /* QEMU_TAP_H */
diff --git a/tap-linux.h b/tap-linux.h
deleted file mode 100644
index d81c650..0000000
--- a/tap-linux.h
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- *  Universal TUN/TAP device driver.
- *  Copyright (C) 1999-2000 Maxim Krasnyansky <max_mk@yahoo.com>
- *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- *  GNU General Public License for more details.
- */
-
-#ifndef QEMU_TAP_H
-#define QEMU_TAP_H
-
-#include <stdint.h>
-#include <linux/ioctl.h>
-
-/* Ioctl defines */
-#define TUNSETIFF     _IOW('T', 202, int)
-#define TUNGETFEATURES _IOR('T', 207, unsigned int)
-#define TUNSETOFFLOAD  _IOW('T', 208, unsigned int)
-#define TUNGETIFF      _IOR('T', 210, unsigned int)
-#define TUNSETSNDBUF   _IOW('T', 212, int)
-
-/* TUNSETIFF ifr flags */
-#define IFF_TAP		0x0002
-#define IFF_NO_PI	0x1000
-#define IFF_VNET_HDR	0x4000
-
-/* Features for GSO (TUNSETOFFLOAD). */
-#define TUN_F_CSUM	0x01	/* You can hand me unchecksummed packets. */
-#define TUN_F_TSO4	0x02	/* I can handle TSO for IPv4 packets */
-#define TUN_F_TSO6	0x04	/* I can handle TSO for IPv6 packets */
-#define TUN_F_TSO_ECN	0x08	/* I can handle TSO with ECN bits. */
-#define TUN_F_UFO	0x10	/* I can handle UFO packets */
-
-struct virtio_net_hdr
-{
-    uint8_t flags;
-    uint8_t gso_type;
-    uint16_t hdr_len;
-    uint16_t gso_size;
-    uint16_t csum_start;
-    uint16_t csum_offset;
-};
-
-#endif /* QEMU_TAP_H */
-- 
1.6.2.5

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [Qemu-devel] [PATCH 06/15] net: split all the tap code out into net/tap.c
  2009-10-22 16:49 [Qemu-devel] [PATCH 00/15] Some networking code re-organization Mark McLoughlin
                   ` (4 preceding siblings ...)
  2009-10-22 16:49 ` [Qemu-devel] [PATCH 05/15] net: move tap-linux.h under net/ Mark McLoughlin
@ 2009-10-22 16:49 ` Mark McLoughlin
  2009-10-22 16:49 ` [Qemu-devel] [PATCH 07/15] net: split BSD tap_open() out into net/tap-bsd.c Mark McLoughlin
                   ` (10 subsequent siblings)
  16 siblings, 0 replies; 22+ messages in thread
From: Mark McLoughlin @ 2009-10-22 16:49 UTC (permalink / raw)
  To: qemu-devel; +Cc: Mark McLoughlin

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
---
 Makefile  |    1 +
 net.c     |  692 +-------------------------------------------------------
 net.h     |    2 +
 net/tap.c |  759 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 763 insertions(+), 691 deletions(-)
 create mode 100644 net/tap.c

diff --git a/Makefile b/Makefile
index a49177f..69ead10 100644
--- a/Makefile
+++ b/Makefile
@@ -88,6 +88,7 @@ block-obj-y +=  $(addprefix block/, $(block-nested-y))
 
 net-obj-y = net.o
 net-nested-y = queue.o checksum.o
+net-nested-$(CONFIG_POSIX) += tap.o
 net-nested-$(CONFIG_WIN32) += tap-win32.o
 net-obj-y += $(addprefix net/, $(net-nested-y))
 
diff --git a/net.c b/net.c
index 3225dcd..365305a 100644
--- a/net.c
+++ b/net.c
@@ -42,12 +42,6 @@
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <net/if.h>
-#ifdef __NetBSD__
-#include <net/if_tap.h>
-#endif
-#ifdef __linux__
-#include "net/tap-linux.h"
-#endif
 #include <arpa/inet.h>
 #include <dirent.h>
 #include <netdb.h>
@@ -1280,618 +1274,6 @@ void do_info_usernet(Monitor *mon)
 
 #endif /* CONFIG_SLIRP */
 
-#if !defined(_WIN32) && !defined(_AIX)
-
-/* Maximum GSO packet size (64k) plus plenty of room for
- * the ethernet and virtio_net headers
- */
-#define TAP_BUFSIZE (4096 + 65536)
-
-typedef struct TAPState {
-    VLANClientState *vc;
-    int fd;
-    char down_script[1024];
-    char down_script_arg[128];
-    uint8_t buf[TAP_BUFSIZE];
-    unsigned int read_poll : 1;
-    unsigned int write_poll : 1;
-    unsigned int has_vnet_hdr : 1;
-    unsigned int using_vnet_hdr : 1;
-    unsigned int has_ufo: 1;
-} TAPState;
-
-static int launch_script(const char *setup_script, const char *ifname, int fd);
-
-static int tap_can_send(void *opaque);
-static void tap_send(void *opaque);
-static void tap_writable(void *opaque);
-
-static void tap_update_fd_handler(TAPState *s)
-{
-    qemu_set_fd_handler2(s->fd,
-                         s->read_poll  ? tap_can_send : NULL,
-                         s->read_poll  ? tap_send     : NULL,
-                         s->write_poll ? tap_writable : NULL,
-                         s);
-}
-
-static void tap_read_poll(TAPState *s, int enable)
-{
-    s->read_poll = !!enable;
-    tap_update_fd_handler(s);
-}
-
-static void tap_write_poll(TAPState *s, int enable)
-{
-    s->write_poll = !!enable;
-    tap_update_fd_handler(s);
-}
-
-static void tap_writable(void *opaque)
-{
-    TAPState *s = opaque;
-
-    tap_write_poll(s, 0);
-
-    qemu_flush_queued_packets(s->vc);
-}
-
-static ssize_t tap_write_packet(TAPState *s, const struct iovec *iov, int iovcnt)
-{
-    ssize_t len;
-
-    do {
-        len = writev(s->fd, iov, iovcnt);
-    } while (len == -1 && errno == EINTR);
-
-    if (len == -1 && errno == EAGAIN) {
-        tap_write_poll(s, 1);
-        return 0;
-    }
-
-    return len;
-}
-
-static ssize_t tap_receive_iov(VLANClientState *vc, const struct iovec *iov,
-                               int iovcnt)
-{
-    TAPState *s = vc->opaque;
-    const struct iovec *iovp = iov;
-    struct iovec iov_copy[iovcnt + 1];
-    struct virtio_net_hdr hdr = { 0, };
-
-    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));
-        iovp = iov_copy;
-        iovcnt++;
-    }
-
-    return tap_write_packet(s, iovp, iovcnt);
-}
-
-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) {
-        iov[iovcnt].iov_base = &hdr;
-        iov[iovcnt].iov_len  = sizeof(hdr);
-        iovcnt++;
-    }
-
-    iov[iovcnt].iov_base = (char *)buf;
-    iov[iovcnt].iov_len  = size;
-    iovcnt++;
-
-    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;
-
-    return qemu_can_send_packet(s->vc);
-}
-
-#ifdef __sun__
-static ssize_t tap_read_packet(int tapfd, uint8_t *buf, int maxlen)
-{
-    struct strbuf sbuf;
-    int f = 0;
-
-    sbuf.maxlen = maxlen;
-    sbuf.buf = (char *)buf;
-
-    return getmsg(tapfd, NULL, &sbuf, &f) >= 0 ? sbuf.len : -1;
-}
-#else
-static ssize_t tap_read_packet(int tapfd, uint8_t *buf, int maxlen)
-{
-    return read(tapfd, buf, maxlen);
-}
-#endif
-
-static void tap_send_completed(VLANClientState *vc, ssize_t len)
-{
-    TAPState *s = vc->opaque;
-    tap_read_poll(s, 1);
-}
-
-static void tap_send(void *opaque)
-{
-    TAPState *s = opaque;
-    int size;
-
-    do {
-        uint8_t *buf = s->buf;
-
-        size = tap_read_packet(s->fd, s->buf, sizeof(s->buf));
-        if (size <= 0) {
-            break;
-        }
-
-        if (s->has_vnet_hdr && !s->using_vnet_hdr) {
-            buf  += sizeof(struct virtio_net_hdr);
-            size -= sizeof(struct virtio_net_hdr);
-        }
-
-        size = qemu_send_packet_async(s->vc, buf, size, tap_send_completed);
-        if (size == 0) {
-            tap_read_poll(s, 0);
-        }
-    } while (size > 0);
-}
-
-/* sndbuf should be set to a value lower than the tx queue
- * capacity of any destination network interface.
- * Ethernet NICs generally have txqueuelen=1000, so 1Mb is
- * a good default, given a 1500 byte MTU.
- */
-#define TAP_DEFAULT_SNDBUF 1024*1024
-
-static int tap_set_sndbuf(TAPState *s, QemuOpts *opts)
-{
-    int sndbuf;
-
-    sndbuf = qemu_opt_get_size(opts, "sndbuf", TAP_DEFAULT_SNDBUF);
-    if (!sndbuf) {
-        sndbuf = INT_MAX;
-    }
-
-    if (ioctl(s->fd, TUNSETSNDBUF, &sndbuf) == -1 && qemu_opt_get(opts, "sndbuf")) {
-        qemu_error("TUNSETSNDBUF ioctl failed: %s\n", strerror(errno));
-        return -1;
-    }
-    return 0;
-}
-
-int tap_has_ufo(VLANClientState *vc)
-{
-    TAPState *s = vc->opaque;
-
-    assert(vc->type == NET_CLIENT_TYPE_TAP);
-
-    return s->has_ufo;
-}
-
-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;
-
-    if (ioctl(fd, TUNGETIFF, &ifr) != 0) {
-        qemu_error("TUNGETIFF ioctl() failed: %s\n", strerror(errno));
-        return 0;
-    }
-
-    return ifr.ifr_flags & IFF_VNET_HDR;
-}
-
-void tap_set_offload(VLANClientState *vc, int csum, int tso4,
-                     int tso6, int ecn, int ufo)
-{
-    TAPState *s = vc->opaque;
-    unsigned int offload = 0;
-
-    if (csum) {
-        offload |= TUN_F_CSUM;
-        if (tso4)
-            offload |= TUN_F_TSO4;
-        if (tso6)
-            offload |= TUN_F_TSO6;
-        if ((tso4 || tso6) && ecn)
-            offload |= TUN_F_TSO_ECN;
-        if (ufo)
-            offload |= TUN_F_UFO;
-    }
-
-    if (ioctl(s->fd, TUNSETOFFLOAD, offload) != 0) {
-        offload &= ~TUN_F_UFO;
-        if (ioctl(s->fd, TUNSETOFFLOAD, offload) != 0) {
-            fprintf(stderr, "TUNSETOFFLOAD ioctl() failed: %s\n",
-                    strerror(errno));
-        }
-    }
-}
-
-static void tap_cleanup(VLANClientState *vc)
-{
-    TAPState *s = vc->opaque;
-
-    qemu_purge_queued_packets(vc);
-
-    if (s->down_script[0])
-        launch_script(s->down_script, s->down_script_arg, s->fd);
-
-    tap_read_poll(s, 0);
-    tap_write_poll(s, 0);
-    close(s->fd);
-    qemu_free(s);
-}
-
-/* fd support */
-
-static TAPState *net_tap_fd_init(VLANState *vlan,
-                                 const char *model,
-                                 const char *name,
-                                 int fd,
-                                 int vnet_hdr)
-{
-    TAPState *s;
-    unsigned int offload;
-
-    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_raw,
-                                 tap_receive_iov, tap_cleanup, s);
-    s->has_ufo = 0;
-    /* Check if tap supports UFO */
-    offload = TUN_F_CSUM | TUN_F_UFO;
-    if (ioctl(s->fd, TUNSETOFFLOAD, offload) == 0)
-       s->has_ufo = 1;
-    tap_set_offload(s->vc, 0, 0, 0, 0, 0);
-    tap_read_poll(s, 1);
-    return s;
-}
-
-#if defined (CONFIG_BSD) || defined (__FreeBSD_kernel__)
-static int tap_open(char *ifname, int ifname_size,
-                    int *vnet_hdr, int vnet_hdr_required)
-{
-    int fd;
-    char *dev;
-    struct stat s;
-
-    TFR(fd = open("/dev/tap", O_RDWR));
-    if (fd < 0) {
-        fprintf(stderr, "warning: could not open /dev/tap: no virtual network emulation\n");
-        return -1;
-    }
-
-    fstat(fd, &s);
-    dev = devname(s.st_rdev, S_IFCHR);
-    pstrcpy(ifname, ifname_size, dev);
-
-    fcntl(fd, F_SETFL, O_NONBLOCK);
-    return fd;
-}
-#elif defined(__sun__)
-#define TUNNEWPPA       (('T'<<16) | 0x0001)
-/*
- * Allocate TAP device, returns opened fd.
- * Stores dev name in the first arg(must be large enough).
- */
-static int tap_alloc(char *dev, size_t dev_size)
-{
-    int tap_fd, if_fd, ppa = -1;
-    static int ip_fd = 0;
-    char *ptr;
-
-    static int arp_fd = 0;
-    int ip_muxid, arp_muxid;
-    struct strioctl  strioc_if, strioc_ppa;
-    int link_type = I_PLINK;;
-    struct lifreq ifr;
-    char actual_name[32] = "";
-
-    memset(&ifr, 0x0, sizeof(ifr));
-
-    if( *dev ){
-       ptr = dev;
-       while( *ptr && !qemu_isdigit((int)*ptr) ) ptr++;
-       ppa = atoi(ptr);
-    }
-
-    /* Check if IP device was opened */
-    if( ip_fd )
-       close(ip_fd);
-
-    TFR(ip_fd = open("/dev/udp", O_RDWR, 0));
-    if (ip_fd < 0) {
-       syslog(LOG_ERR, "Can't open /dev/ip (actually /dev/udp)");
-       return -1;
-    }
-
-    TFR(tap_fd = open("/dev/tap", O_RDWR, 0));
-    if (tap_fd < 0) {
-       syslog(LOG_ERR, "Can't open /dev/tap");
-       return -1;
-    }
-
-    /* Assign a new PPA and get its unit number. */
-    strioc_ppa.ic_cmd = TUNNEWPPA;
-    strioc_ppa.ic_timout = 0;
-    strioc_ppa.ic_len = sizeof(ppa);
-    strioc_ppa.ic_dp = (char *)&ppa;
-    if ((ppa = ioctl (tap_fd, I_STR, &strioc_ppa)) < 0)
-       syslog (LOG_ERR, "Can't assign new interface");
-
-    TFR(if_fd = open("/dev/tap", O_RDWR, 0));
-    if (if_fd < 0) {
-       syslog(LOG_ERR, "Can't open /dev/tap (2)");
-       return -1;
-    }
-    if(ioctl(if_fd, I_PUSH, "ip") < 0){
-       syslog(LOG_ERR, "Can't push IP module");
-       return -1;
-    }
-
-    if (ioctl(if_fd, SIOCGLIFFLAGS, &ifr) < 0)
-	syslog(LOG_ERR, "Can't get flags\n");
-
-    snprintf (actual_name, 32, "tap%d", ppa);
-    pstrcpy(ifr.lifr_name, sizeof(ifr.lifr_name), actual_name);
-
-    ifr.lifr_ppa = ppa;
-    /* Assign ppa according to the unit number returned by tun device */
-
-    if (ioctl (if_fd, SIOCSLIFNAME, &ifr) < 0)
-        syslog (LOG_ERR, "Can't set PPA %d", ppa);
-    if (ioctl(if_fd, SIOCGLIFFLAGS, &ifr) <0)
-        syslog (LOG_ERR, "Can't get flags\n");
-    /* Push arp module to if_fd */
-    if (ioctl (if_fd, I_PUSH, "arp") < 0)
-        syslog (LOG_ERR, "Can't push ARP module (2)");
-
-    /* Push arp module to ip_fd */
-    if (ioctl (ip_fd, I_POP, NULL) < 0)
-        syslog (LOG_ERR, "I_POP failed\n");
-    if (ioctl (ip_fd, I_PUSH, "arp") < 0)
-        syslog (LOG_ERR, "Can't push ARP module (3)\n");
-    /* Open arp_fd */
-    TFR(arp_fd = open ("/dev/tap", O_RDWR, 0));
-    if (arp_fd < 0)
-       syslog (LOG_ERR, "Can't open %s\n", "/dev/tap");
-
-    /* Set ifname to arp */
-    strioc_if.ic_cmd = SIOCSLIFNAME;
-    strioc_if.ic_timout = 0;
-    strioc_if.ic_len = sizeof(ifr);
-    strioc_if.ic_dp = (char *)&ifr;
-    if (ioctl(arp_fd, I_STR, &strioc_if) < 0){
-        syslog (LOG_ERR, "Can't set ifname to arp\n");
-    }
-
-    if((ip_muxid = ioctl(ip_fd, I_LINK, if_fd)) < 0){
-       syslog(LOG_ERR, "Can't link TAP device to IP");
-       return -1;
-    }
-
-    if ((arp_muxid = ioctl (ip_fd, link_type, arp_fd)) < 0)
-        syslog (LOG_ERR, "Can't link TAP device to ARP");
-
-    close (if_fd);
-
-    memset(&ifr, 0x0, sizeof(ifr));
-    pstrcpy(ifr.lifr_name, sizeof(ifr.lifr_name), actual_name);
-    ifr.lifr_ip_muxid  = ip_muxid;
-    ifr.lifr_arp_muxid = arp_muxid;
-
-    if (ioctl (ip_fd, SIOCSLIFMUXID, &ifr) < 0)
-    {
-      ioctl (ip_fd, I_PUNLINK , arp_muxid);
-      ioctl (ip_fd, I_PUNLINK, ip_muxid);
-      syslog (LOG_ERR, "Can't set multiplexor id");
-    }
-
-    snprintf(dev, dev_size, "tap%d", ppa);
-    return tap_fd;
-}
-
-static int tap_open(char *ifname, int ifname_size,
-                    int *vnet_hdr, int vnet_hdr_required)
-{
-    char  dev[10]="";
-    int fd;
-    if( (fd = tap_alloc(dev, sizeof(dev))) < 0 ){
-       fprintf(stderr, "Cannot allocate TAP device\n");
-       return -1;
-    }
-    pstrcpy(ifname, ifname_size, dev);
-    fcntl(fd, F_SETFL, O_NONBLOCK);
-    return fd;
-}
-#elif defined (_AIX)
-static int tap_open(char *ifname, int ifname_size,
-                    int *vnet_hdr, int vnet_hdr_required)
-{
-    fprintf (stderr, "no tap on AIX\n");
-    return -1;
-}
-#else
-static int tap_open(char *ifname, int ifname_size,
-                    int *vnet_hdr, int vnet_hdr_required)
-{
-    struct ifreq ifr;
-    int fd, ret;
-
-    TFR(fd = open("/dev/net/tun", O_RDWR));
-    if (fd < 0) {
-        fprintf(stderr, "warning: could not open /dev/net/tun: no virtual network emulation\n");
-        return -1;
-    }
-    memset(&ifr, 0, sizeof(ifr));
-    ifr.ifr_flags = IFF_TAP | IFF_NO_PI;
-
-    if (*vnet_hdr) {
-        unsigned int features;
-
-        if (ioctl(fd, TUNGETFEATURES, &features) == 0 &&
-            features & IFF_VNET_HDR) {
-            *vnet_hdr = 1;
-            ifr.ifr_flags |= IFF_VNET_HDR;
-        }
-
-        if (vnet_hdr_required && !*vnet_hdr) {
-            qemu_error("vnet_hdr=1 requested, but no kernel "
-                       "support for IFF_VNET_HDR available");
-            close(fd);
-            return -1;
-        }
-    }
-
-    if (ifname[0] != '\0')
-        pstrcpy(ifr.ifr_name, IFNAMSIZ, ifname);
-    else
-        pstrcpy(ifr.ifr_name, IFNAMSIZ, "tap%d");
-    ret = ioctl(fd, TUNSETIFF, (void *) &ifr);
-    if (ret != 0) {
-        fprintf(stderr, "warning: could not configure /dev/net/tun: no virtual network emulation\n");
-        close(fd);
-        return -1;
-    }
-    pstrcpy(ifname, ifname_size, ifr.ifr_name);
-    fcntl(fd, F_SETFL, O_NONBLOCK);
-    return fd;
-}
-#endif
-
-static int launch_script(const char *setup_script, const char *ifname, int fd)
-{
-    sigset_t oldmask, mask;
-    int pid, status;
-    char *args[3];
-    char **parg;
-
-    sigemptyset(&mask);
-    sigaddset(&mask, SIGCHLD);
-    sigprocmask(SIG_BLOCK, &mask, &oldmask);
-
-    /* try to launch network script */
-    pid = fork();
-    if (pid == 0) {
-        int open_max = sysconf(_SC_OPEN_MAX), i;
-
-        for (i = 0; i < open_max; i++) {
-            if (i != STDIN_FILENO &&
-                i != STDOUT_FILENO &&
-                i != STDERR_FILENO &&
-                i != fd) {
-                close(i);
-            }
-        }
-        parg = args;
-        *parg++ = (char *)setup_script;
-        *parg++ = (char *)ifname;
-        *parg++ = NULL;
-        execv(setup_script, args);
-        _exit(1);
-    } else if (pid > 0) {
-        while (waitpid(pid, &status, 0) != pid) {
-            /* loop */
-        }
-        sigprocmask(SIG_SETMASK, &oldmask, NULL);
-
-        if (WIFEXITED(status) && WEXITSTATUS(status) == 0) {
-            return 0;
-        }
-    }
-    fprintf(stderr, "%s: could not launch network script\n", setup_script);
-    return -1;
-}
-
-static int net_tap_init(QemuOpts *opts, int *vnet_hdr)
-{
-    int fd, vnet_hdr_required;
-    char ifname[128] = {0,};
-    const char *setup_script;
-
-    if (qemu_opt_get(opts, "ifname")) {
-        pstrcpy(ifname, sizeof(ifname), qemu_opt_get(opts, "ifname"));
-    }
-
-    *vnet_hdr = qemu_opt_get_bool(opts, "vnet_hdr", 1);
-    if (qemu_opt_get(opts, "vnet_hdr")) {
-        vnet_hdr_required = *vnet_hdr;
-    } else {
-        vnet_hdr_required = 0;
-    }
-
-    TFR(fd = tap_open(ifname, sizeof(ifname), vnet_hdr, vnet_hdr_required));
-    if (fd < 0) {
-        return -1;
-    }
-
-    setup_script = qemu_opt_get(opts, "script");
-    if (setup_script &&
-        setup_script[0] != '\0' &&
-        strcmp(setup_script, "no") != 0 &&
-        launch_script(setup_script, ifname, fd)) {
-        close(fd);
-        return -1;
-    }
-
-    qemu_opt_set(opts, "ifname", ifname);
-
-    return fd;
-}
-
-#endif /* !defined(_WIN32) && !defined(_AIX) */
-
 #if defined(CONFIG_VDE)
 typedef struct VDEState {
     VLANClientState *vc;
@@ -2607,7 +1989,7 @@ int qemu_find_nic_model(NICInfo *nd, const char * const *models,
     return -1;
 }
 
-static int net_handle_fd_param(Monitor *mon, const char *param)
+int net_handle_fd_param(Monitor *mon, const char *param)
 {
     if (!qemu_isdigit(param[0])) {
         int fd;
@@ -2787,78 +2169,6 @@ static int net_init_slirp(QemuOpts *opts,
 }
 #endif /* CONFIG_SLIRP */
 
-#if !defined(_WIN32) && !defined(_AIX)
-int net_init_tap(QemuOpts *opts, Monitor *mon, const char *name, VLANState *vlan)
-{
-    TAPState *s;
-    int fd, vnet_hdr;
-
-    if (qemu_opt_get(opts, "fd")) {
-        if (qemu_opt_get(opts, "ifname") ||
-            qemu_opt_get(opts, "script") ||
-            qemu_opt_get(opts, "downscript") ||
-            qemu_opt_get(opts, "vnet_hdr")) {
-            qemu_error("ifname=, script=, downscript= and vnet_hdr= is invalid with fd=\n");
-            return -1;
-        }
-
-        fd = net_handle_fd_param(mon, qemu_opt_get(opts, "fd"));
-        if (fd == -1) {
-            return -1;
-        }
-
-        fcntl(fd, F_SETFL, O_NONBLOCK);
-
-        vnet_hdr = tap_probe_vnet_hdr(fd);
-    } else {
-        if (!qemu_opt_get(opts, "script")) {
-            qemu_opt_set(opts, "script", DEFAULT_NETWORK_SCRIPT);
-        }
-
-        if (!qemu_opt_get(opts, "downscript")) {
-            qemu_opt_set(opts, "downscript", DEFAULT_NETWORK_DOWN_SCRIPT);
-        }
-
-        fd = net_tap_init(opts, &vnet_hdr);
-    }
-
-    s = net_tap_fd_init(vlan, "tap", name, fd, vnet_hdr);
-    if (!s) {
-        close(fd);
-        return -1;
-    }
-
-    if (tap_set_sndbuf(s, opts) < 0) {
-        return -1;
-    }
-
-    if (qemu_opt_get(opts, "fd")) {
-        snprintf(s->vc->info_str, sizeof(s->vc->info_str), "fd=%d", fd);
-    } else {
-        const char *ifname, *script, *downscript;
-
-        ifname     = qemu_opt_get(opts, "ifname");
-        script     = qemu_opt_get(opts, "script");
-        downscript = qemu_opt_get(opts, "downscript");
-
-        snprintf(s->vc->info_str, sizeof(s->vc->info_str),
-                 "ifname=%s,script=%s,downscript=%s",
-                 ifname, script, downscript);
-
-        if (strcmp(downscript, "no") != 0) {
-            snprintf(s->down_script, sizeof(s->down_script), "%s", downscript);
-            snprintf(s->down_script_arg, sizeof(s->down_script_arg), "%s", ifname);
-        }
-    }
-
-    if (vlan) {
-        vlan->nb_host_devs++;
-    }
-
-    return 0;
-}
-#endif /* !defined(_WIN32) && !defined(_AIX) */
-
 static int net_init_socket(QemuOpts *opts,
                            Monitor *mon,
                            const char *name,
diff --git a/net.h b/net.h
index 1a907c7..8074c66 100644
--- a/net.h
+++ b/net.h
@@ -161,4 +161,6 @@ VLANClientState *qdev_get_vlan_client(DeviceState *dev,
                                       NetCleanup *cleanup,
                                       void *opaque);
 
+int net_handle_fd_param(Monitor *mon, const char *param);
+
 #endif
diff --git a/net/tap.c b/net/tap.c
new file mode 100644
index 0000000..6b43d80
--- /dev/null
+++ b/net/tap.c
@@ -0,0 +1,759 @@
+/*
+ * QEMU System Emulator
+ *
+ * Copyright (c) 2003-2008 Fabrice Bellard
+ * Copyright (c) 2009 Red Hat, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "net/tap.h"
+
+#include "config-host.h"
+
+#include <signal.h>
+#include <sys/ioctl.h>
+#include <sys/stat.h>
+#include <sys/wait.h>
+#include <net/if.h>
+
+#include "net.h"
+#include "sysemu.h"
+#include "qemu-char.h"
+#include "qemu-common.h"
+
+#ifdef __linux__
+#include "net/tap-linux.h"
+#endif
+
+#ifdef __NetBSD__
+#include <net/if_tap.h>
+#endif
+
+#ifdef CONFIG_BSD
+#if defined(__FreeBSD__) || defined(__DragonFly__)
+#include <libutil.h>
+#else
+#include <util.h>
+#endif
+#elif defined (__GLIBC__) && defined (__FreeBSD_kernel__)
+#include <freebsd/stdlib.h>
+#endif
+
+#if defined(__OpenBSD__)
+#include <util.h>
+#endif
+
+#ifdef __sun__
+#include <sys/stat.h>
+#include <sys/ethernet.h>
+#include <sys/sockio.h>
+#include <netinet/arp.h>
+#include <netinet/in.h>
+#include <netinet/in_systm.h>
+#include <netinet/ip.h>
+#include <netinet/ip_icmp.h> // must come after ip.h
+#include <netinet/udp.h>
+#include <netinet/tcp.h>
+#include <net/if.h>
+#include <syslog.h>
+#include <stropts.h>
+#endif
+
+#if !defined(_AIX)
+
+/* Maximum GSO packet size (64k) plus plenty of room for
+ * the ethernet and virtio_net headers
+ */
+#define TAP_BUFSIZE (4096 + 65536)
+
+typedef struct TAPState {
+    VLANClientState *vc;
+    int fd;
+    char down_script[1024];
+    char down_script_arg[128];
+    uint8_t buf[TAP_BUFSIZE];
+    unsigned int read_poll : 1;
+    unsigned int write_poll : 1;
+    unsigned int has_vnet_hdr : 1;
+    unsigned int using_vnet_hdr : 1;
+    unsigned int has_ufo: 1;
+} TAPState;
+
+static int launch_script(const char *setup_script, const char *ifname, int fd);
+
+static int tap_can_send(void *opaque);
+static void tap_send(void *opaque);
+static void tap_writable(void *opaque);
+
+static void tap_update_fd_handler(TAPState *s)
+{
+    qemu_set_fd_handler2(s->fd,
+                         s->read_poll  ? tap_can_send : NULL,
+                         s->read_poll  ? tap_send     : NULL,
+                         s->write_poll ? tap_writable : NULL,
+                         s);
+}
+
+static void tap_read_poll(TAPState *s, int enable)
+{
+    s->read_poll = !!enable;
+    tap_update_fd_handler(s);
+}
+
+static void tap_write_poll(TAPState *s, int enable)
+{
+    s->write_poll = !!enable;
+    tap_update_fd_handler(s);
+}
+
+static void tap_writable(void *opaque)
+{
+    TAPState *s = opaque;
+
+    tap_write_poll(s, 0);
+
+    qemu_flush_queued_packets(s->vc);
+}
+
+static ssize_t tap_write_packet(TAPState *s, const struct iovec *iov, int iovcnt)
+{
+    ssize_t len;
+
+    do {
+        len = writev(s->fd, iov, iovcnt);
+    } while (len == -1 && errno == EINTR);
+
+    if (len == -1 && errno == EAGAIN) {
+        tap_write_poll(s, 1);
+        return 0;
+    }
+
+    return len;
+}
+
+static ssize_t tap_receive_iov(VLANClientState *vc, const struct iovec *iov,
+                               int iovcnt)
+{
+    TAPState *s = vc->opaque;
+    const struct iovec *iovp = iov;
+    struct iovec iov_copy[iovcnt + 1];
+    struct virtio_net_hdr hdr = { 0, };
+
+    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));
+        iovp = iov_copy;
+        iovcnt++;
+    }
+
+    return tap_write_packet(s, iovp, iovcnt);
+}
+
+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) {
+        iov[iovcnt].iov_base = &hdr;
+        iov[iovcnt].iov_len  = sizeof(hdr);
+        iovcnt++;
+    }
+
+    iov[iovcnt].iov_base = (char *)buf;
+    iov[iovcnt].iov_len  = size;
+    iovcnt++;
+
+    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;
+
+    return qemu_can_send_packet(s->vc);
+}
+
+#ifdef __sun__
+static ssize_t tap_read_packet(int tapfd, uint8_t *buf, int maxlen)
+{
+    struct strbuf sbuf;
+    int f = 0;
+
+    sbuf.maxlen = maxlen;
+    sbuf.buf = (char *)buf;
+
+    return getmsg(tapfd, NULL, &sbuf, &f) >= 0 ? sbuf.len : -1;
+}
+#else
+static ssize_t tap_read_packet(int tapfd, uint8_t *buf, int maxlen)
+{
+    return read(tapfd, buf, maxlen);
+}
+#endif
+
+static void tap_send_completed(VLANClientState *vc, ssize_t len)
+{
+    TAPState *s = vc->opaque;
+    tap_read_poll(s, 1);
+}
+
+static void tap_send(void *opaque)
+{
+    TAPState *s = opaque;
+    int size;
+
+    do {
+        uint8_t *buf = s->buf;
+
+        size = tap_read_packet(s->fd, s->buf, sizeof(s->buf));
+        if (size <= 0) {
+            break;
+        }
+
+        if (s->has_vnet_hdr && !s->using_vnet_hdr) {
+            buf  += sizeof(struct virtio_net_hdr);
+            size -= sizeof(struct virtio_net_hdr);
+        }
+
+        size = qemu_send_packet_async(s->vc, buf, size, tap_send_completed);
+        if (size == 0) {
+            tap_read_poll(s, 0);
+        }
+    } while (size > 0);
+}
+
+/* sndbuf should be set to a value lower than the tx queue
+ * capacity of any destination network interface.
+ * Ethernet NICs generally have txqueuelen=1000, so 1Mb is
+ * a good default, given a 1500 byte MTU.
+ */
+#define TAP_DEFAULT_SNDBUF 1024*1024
+
+static int tap_set_sndbuf(TAPState *s, QemuOpts *opts)
+{
+    int sndbuf;
+
+    sndbuf = qemu_opt_get_size(opts, "sndbuf", TAP_DEFAULT_SNDBUF);
+    if (!sndbuf) {
+        sndbuf = INT_MAX;
+    }
+
+    if (ioctl(s->fd, TUNSETSNDBUF, &sndbuf) == -1 && qemu_opt_get(opts, "sndbuf")) {
+        qemu_error("TUNSETSNDBUF ioctl failed: %s\n", strerror(errno));
+        return -1;
+    }
+    return 0;
+}
+
+int tap_has_ufo(VLANClientState *vc)
+{
+    TAPState *s = vc->opaque;
+
+    assert(vc->type == NET_CLIENT_TYPE_TAP);
+
+    return s->has_ufo;
+}
+
+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;
+
+    if (ioctl(fd, TUNGETIFF, &ifr) != 0) {
+        qemu_error("TUNGETIFF ioctl() failed: %s\n", strerror(errno));
+        return 0;
+    }
+
+    return ifr.ifr_flags & IFF_VNET_HDR;
+}
+
+void tap_set_offload(VLANClientState *vc, int csum, int tso4,
+                     int tso6, int ecn, int ufo)
+{
+    TAPState *s = vc->opaque;
+    unsigned int offload = 0;
+
+    if (csum) {
+        offload |= TUN_F_CSUM;
+        if (tso4)
+            offload |= TUN_F_TSO4;
+        if (tso6)
+            offload |= TUN_F_TSO6;
+        if ((tso4 || tso6) && ecn)
+            offload |= TUN_F_TSO_ECN;
+        if (ufo)
+            offload |= TUN_F_UFO;
+    }
+
+    if (ioctl(s->fd, TUNSETOFFLOAD, offload) != 0) {
+        offload &= ~TUN_F_UFO;
+        if (ioctl(s->fd, TUNSETOFFLOAD, offload) != 0) {
+            fprintf(stderr, "TUNSETOFFLOAD ioctl() failed: %s\n",
+                    strerror(errno));
+        }
+    }
+}
+
+static void tap_cleanup(VLANClientState *vc)
+{
+    TAPState *s = vc->opaque;
+
+    qemu_purge_queued_packets(vc);
+
+    if (s->down_script[0])
+        launch_script(s->down_script, s->down_script_arg, s->fd);
+
+    tap_read_poll(s, 0);
+    tap_write_poll(s, 0);
+    close(s->fd);
+    qemu_free(s);
+}
+
+/* fd support */
+
+static TAPState *net_tap_fd_init(VLANState *vlan,
+                                 const char *model,
+                                 const char *name,
+                                 int fd,
+                                 int vnet_hdr)
+{
+    TAPState *s;
+    unsigned int offload;
+
+    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_raw,
+                                 tap_receive_iov, tap_cleanup, s);
+    s->has_ufo = 0;
+    /* Check if tap supports UFO */
+    offload = TUN_F_CSUM | TUN_F_UFO;
+    if (ioctl(s->fd, TUNSETOFFLOAD, offload) == 0)
+       s->has_ufo = 1;
+    tap_set_offload(s->vc, 0, 0, 0, 0, 0);
+    tap_read_poll(s, 1);
+    return s;
+}
+
+#if defined (CONFIG_BSD) || defined (__FreeBSD_kernel__)
+static int tap_open(char *ifname, int ifname_size,
+                    int *vnet_hdr, int vnet_hdr_required)
+{
+    int fd;
+    char *dev;
+    struct stat s;
+
+    TFR(fd = open("/dev/tap", O_RDWR));
+    if (fd < 0) {
+        fprintf(stderr, "warning: could not open /dev/tap: no virtual network emulation\n");
+        return -1;
+    }
+
+    fstat(fd, &s);
+    dev = devname(s.st_rdev, S_IFCHR);
+    pstrcpy(ifname, ifname_size, dev);
+
+    fcntl(fd, F_SETFL, O_NONBLOCK);
+    return fd;
+}
+#elif defined(__sun__)
+#define TUNNEWPPA       (('T'<<16) | 0x0001)
+/*
+ * Allocate TAP device, returns opened fd.
+ * Stores dev name in the first arg(must be large enough).
+ */
+static int tap_alloc(char *dev, size_t dev_size)
+{
+    int tap_fd, if_fd, ppa = -1;
+    static int ip_fd = 0;
+    char *ptr;
+
+    static int arp_fd = 0;
+    int ip_muxid, arp_muxid;
+    struct strioctl  strioc_if, strioc_ppa;
+    int link_type = I_PLINK;;
+    struct lifreq ifr;
+    char actual_name[32] = "";
+
+    memset(&ifr, 0x0, sizeof(ifr));
+
+    if( *dev ){
+       ptr = dev;
+       while( *ptr && !qemu_isdigit((int)*ptr) ) ptr++;
+       ppa = atoi(ptr);
+    }
+
+    /* Check if IP device was opened */
+    if( ip_fd )
+       close(ip_fd);
+
+    TFR(ip_fd = open("/dev/udp", O_RDWR, 0));
+    if (ip_fd < 0) {
+       syslog(LOG_ERR, "Can't open /dev/ip (actually /dev/udp)");
+       return -1;
+    }
+
+    TFR(tap_fd = open("/dev/tap", O_RDWR, 0));
+    if (tap_fd < 0) {
+       syslog(LOG_ERR, "Can't open /dev/tap");
+       return -1;
+    }
+
+    /* Assign a new PPA and get its unit number. */
+    strioc_ppa.ic_cmd = TUNNEWPPA;
+    strioc_ppa.ic_timout = 0;
+    strioc_ppa.ic_len = sizeof(ppa);
+    strioc_ppa.ic_dp = (char *)&ppa;
+    if ((ppa = ioctl (tap_fd, I_STR, &strioc_ppa)) < 0)
+       syslog (LOG_ERR, "Can't assign new interface");
+
+    TFR(if_fd = open("/dev/tap", O_RDWR, 0));
+    if (if_fd < 0) {
+       syslog(LOG_ERR, "Can't open /dev/tap (2)");
+       return -1;
+    }
+    if(ioctl(if_fd, I_PUSH, "ip") < 0){
+       syslog(LOG_ERR, "Can't push IP module");
+       return -1;
+    }
+
+    if (ioctl(if_fd, SIOCGLIFFLAGS, &ifr) < 0)
+	syslog(LOG_ERR, "Can't get flags\n");
+
+    snprintf (actual_name, 32, "tap%d", ppa);
+    pstrcpy(ifr.lifr_name, sizeof(ifr.lifr_name), actual_name);
+
+    ifr.lifr_ppa = ppa;
+    /* Assign ppa according to the unit number returned by tun device */
+
+    if (ioctl (if_fd, SIOCSLIFNAME, &ifr) < 0)
+        syslog (LOG_ERR, "Can't set PPA %d", ppa);
+    if (ioctl(if_fd, SIOCGLIFFLAGS, &ifr) <0)
+        syslog (LOG_ERR, "Can't get flags\n");
+    /* Push arp module to if_fd */
+    if (ioctl (if_fd, I_PUSH, "arp") < 0)
+        syslog (LOG_ERR, "Can't push ARP module (2)");
+
+    /* Push arp module to ip_fd */
+    if (ioctl (ip_fd, I_POP, NULL) < 0)
+        syslog (LOG_ERR, "I_POP failed\n");
+    if (ioctl (ip_fd, I_PUSH, "arp") < 0)
+        syslog (LOG_ERR, "Can't push ARP module (3)\n");
+    /* Open arp_fd */
+    TFR(arp_fd = open ("/dev/tap", O_RDWR, 0));
+    if (arp_fd < 0)
+       syslog (LOG_ERR, "Can't open %s\n", "/dev/tap");
+
+    /* Set ifname to arp */
+    strioc_if.ic_cmd = SIOCSLIFNAME;
+    strioc_if.ic_timout = 0;
+    strioc_if.ic_len = sizeof(ifr);
+    strioc_if.ic_dp = (char *)&ifr;
+    if (ioctl(arp_fd, I_STR, &strioc_if) < 0){
+        syslog (LOG_ERR, "Can't set ifname to arp\n");
+    }
+
+    if((ip_muxid = ioctl(ip_fd, I_LINK, if_fd)) < 0){
+       syslog(LOG_ERR, "Can't link TAP device to IP");
+       return -1;
+    }
+
+    if ((arp_muxid = ioctl (ip_fd, link_type, arp_fd)) < 0)
+        syslog (LOG_ERR, "Can't link TAP device to ARP");
+
+    close (if_fd);
+
+    memset(&ifr, 0x0, sizeof(ifr));
+    pstrcpy(ifr.lifr_name, sizeof(ifr.lifr_name), actual_name);
+    ifr.lifr_ip_muxid  = ip_muxid;
+    ifr.lifr_arp_muxid = arp_muxid;
+
+    if (ioctl (ip_fd, SIOCSLIFMUXID, &ifr) < 0)
+    {
+      ioctl (ip_fd, I_PUNLINK , arp_muxid);
+      ioctl (ip_fd, I_PUNLINK, ip_muxid);
+      syslog (LOG_ERR, "Can't set multiplexor id");
+    }
+
+    snprintf(dev, dev_size, "tap%d", ppa);
+    return tap_fd;
+}
+
+static int tap_open(char *ifname, int ifname_size,
+                    int *vnet_hdr, int vnet_hdr_required)
+{
+    char  dev[10]="";
+    int fd;
+    if( (fd = tap_alloc(dev, sizeof(dev))) < 0 ){
+       fprintf(stderr, "Cannot allocate TAP device\n");
+       return -1;
+    }
+    pstrcpy(ifname, ifname_size, dev);
+    fcntl(fd, F_SETFL, O_NONBLOCK);
+    return fd;
+}
+#elif defined (_AIX)
+static int tap_open(char *ifname, int ifname_size,
+                    int *vnet_hdr, int vnet_hdr_required)
+{
+    fprintf (stderr, "no tap on AIX\n");
+    return -1;
+}
+#else
+static int tap_open(char *ifname, int ifname_size,
+                    int *vnet_hdr, int vnet_hdr_required)
+{
+    struct ifreq ifr;
+    int fd, ret;
+
+    TFR(fd = open("/dev/net/tun", O_RDWR));
+    if (fd < 0) {
+        fprintf(stderr, "warning: could not open /dev/net/tun: no virtual network emulation\n");
+        return -1;
+    }
+    memset(&ifr, 0, sizeof(ifr));
+    ifr.ifr_flags = IFF_TAP | IFF_NO_PI;
+
+    if (*vnet_hdr) {
+        unsigned int features;
+
+        if (ioctl(fd, TUNGETFEATURES, &features) == 0 &&
+            features & IFF_VNET_HDR) {
+            *vnet_hdr = 1;
+            ifr.ifr_flags |= IFF_VNET_HDR;
+        }
+
+        if (vnet_hdr_required && !*vnet_hdr) {
+            qemu_error("vnet_hdr=1 requested, but no kernel "
+                       "support for IFF_VNET_HDR available");
+            close(fd);
+            return -1;
+        }
+    }
+
+    if (ifname[0] != '\0')
+        pstrcpy(ifr.ifr_name, IFNAMSIZ, ifname);
+    else
+        pstrcpy(ifr.ifr_name, IFNAMSIZ, "tap%d");
+    ret = ioctl(fd, TUNSETIFF, (void *) &ifr);
+    if (ret != 0) {
+        fprintf(stderr, "warning: could not configure /dev/net/tun: no virtual network emulation\n");
+        close(fd);
+        return -1;
+    }
+    pstrcpy(ifname, ifname_size, ifr.ifr_name);
+    fcntl(fd, F_SETFL, O_NONBLOCK);
+    return fd;
+}
+#endif
+
+static int launch_script(const char *setup_script, const char *ifname, int fd)
+{
+    sigset_t oldmask, mask;
+    int pid, status;
+    char *args[3];
+    char **parg;
+
+    sigemptyset(&mask);
+    sigaddset(&mask, SIGCHLD);
+    sigprocmask(SIG_BLOCK, &mask, &oldmask);
+
+    /* try to launch network script */
+    pid = fork();
+    if (pid == 0) {
+        int open_max = sysconf(_SC_OPEN_MAX), i;
+
+        for (i = 0; i < open_max; i++) {
+            if (i != STDIN_FILENO &&
+                i != STDOUT_FILENO &&
+                i != STDERR_FILENO &&
+                i != fd) {
+                close(i);
+            }
+        }
+        parg = args;
+        *parg++ = (char *)setup_script;
+        *parg++ = (char *)ifname;
+        *parg++ = NULL;
+        execv(setup_script, args);
+        _exit(1);
+    } else if (pid > 0) {
+        while (waitpid(pid, &status, 0) != pid) {
+            /* loop */
+        }
+        sigprocmask(SIG_SETMASK, &oldmask, NULL);
+
+        if (WIFEXITED(status) && WEXITSTATUS(status) == 0) {
+            return 0;
+        }
+    }
+    fprintf(stderr, "%s: could not launch network script\n", setup_script);
+    return -1;
+}
+
+static int net_tap_init(QemuOpts *opts, int *vnet_hdr)
+{
+    int fd, vnet_hdr_required;
+    char ifname[128] = {0,};
+    const char *setup_script;
+
+    if (qemu_opt_get(opts, "ifname")) {
+        pstrcpy(ifname, sizeof(ifname), qemu_opt_get(opts, "ifname"));
+    }
+
+    *vnet_hdr = qemu_opt_get_bool(opts, "vnet_hdr", 1);
+    if (qemu_opt_get(opts, "vnet_hdr")) {
+        vnet_hdr_required = *vnet_hdr;
+    } else {
+        vnet_hdr_required = 0;
+    }
+
+    TFR(fd = tap_open(ifname, sizeof(ifname), vnet_hdr, vnet_hdr_required));
+    if (fd < 0) {
+        return -1;
+    }
+
+    setup_script = qemu_opt_get(opts, "script");
+    if (setup_script &&
+        setup_script[0] != '\0' &&
+        strcmp(setup_script, "no") != 0 &&
+        launch_script(setup_script, ifname, fd)) {
+        close(fd);
+        return -1;
+    }
+
+    qemu_opt_set(opts, "ifname", ifname);
+
+    return fd;
+}
+
+int net_init_tap(QemuOpts *opts, Monitor *mon, const char *name, VLANState *vlan)
+{
+    TAPState *s;
+    int fd, vnet_hdr;
+
+    if (qemu_opt_get(opts, "fd")) {
+        if (qemu_opt_get(opts, "ifname") ||
+            qemu_opt_get(opts, "script") ||
+            qemu_opt_get(opts, "downscript") ||
+            qemu_opt_get(opts, "vnet_hdr")) {
+            qemu_error("ifname=, script=, downscript= and vnet_hdr= is invalid with fd=\n");
+            return -1;
+        }
+
+        fd = net_handle_fd_param(mon, qemu_opt_get(opts, "fd"));
+        if (fd == -1) {
+            return -1;
+        }
+
+        fcntl(fd, F_SETFL, O_NONBLOCK);
+
+        vnet_hdr = tap_probe_vnet_hdr(fd);
+    } else {
+        if (!qemu_opt_get(opts, "script")) {
+            qemu_opt_set(opts, "script", DEFAULT_NETWORK_SCRIPT);
+        }
+
+        if (!qemu_opt_get(opts, "downscript")) {
+            qemu_opt_set(opts, "downscript", DEFAULT_NETWORK_DOWN_SCRIPT);
+        }
+
+        fd = net_tap_init(opts, &vnet_hdr);
+    }
+
+    s = net_tap_fd_init(vlan, "tap", name, fd, vnet_hdr);
+    if (!s) {
+        close(fd);
+        return -1;
+    }
+
+    if (tap_set_sndbuf(s, opts) < 0) {
+        return -1;
+    }
+
+    if (qemu_opt_get(opts, "fd")) {
+        snprintf(s->vc->info_str, sizeof(s->vc->info_str), "fd=%d", fd);
+    } else {
+        const char *ifname, *script, *downscript;
+
+        ifname     = qemu_opt_get(opts, "ifname");
+        script     = qemu_opt_get(opts, "script");
+        downscript = qemu_opt_get(opts, "downscript");
+
+        snprintf(s->vc->info_str, sizeof(s->vc->info_str),
+                 "ifname=%s,script=%s,downscript=%s",
+                 ifname, script, downscript);
+
+        if (strcmp(downscript, "no") != 0) {
+            snprintf(s->down_script, sizeof(s->down_script), "%s", downscript);
+            snprintf(s->down_script_arg, sizeof(s->down_script_arg), "%s", ifname);
+        }
+    }
+
+    if (vlan) {
+        vlan->nb_host_devs++;
+    }
+
+    return 0;
+}
+
+#endif /* !defined(_AIX) */
-- 
1.6.2.5

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [Qemu-devel] [PATCH 07/15] net: split BSD tap_open() out into net/tap-bsd.c
  2009-10-22 16:49 [Qemu-devel] [PATCH 00/15] Some networking code re-organization Mark McLoughlin
                   ` (5 preceding siblings ...)
  2009-10-22 16:49 ` [Qemu-devel] [PATCH 06/15] net: split all the tap code out into net/tap.c Mark McLoughlin
@ 2009-10-22 16:49 ` Mark McLoughlin
  2009-10-22 16:49 ` [Qemu-devel] [PATCH 08/15] net: move solaris code to net/tap-solaris.c Mark McLoughlin
                   ` (9 subsequent siblings)
  16 siblings, 0 replies; 22+ messages in thread
From: Mark McLoughlin @ 2009-10-22 16:49 UTC (permalink / raw)
  To: qemu-devel; +Cc: Mark McLoughlin

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
---
 Makefile      |    1 +
 net/tap-bsd.c |   62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 net/tap.c     |   50 +++------------------------------------------
 net/tap.h     |    2 +
 4 files changed, 69 insertions(+), 46 deletions(-)
 create mode 100644 net/tap-bsd.c

diff --git a/Makefile b/Makefile
index 69ead10..a29c486 100644
--- a/Makefile
+++ b/Makefile
@@ -90,6 +90,7 @@ net-obj-y = net.o
 net-nested-y = queue.o checksum.o
 net-nested-$(CONFIG_POSIX) += tap.o
 net-nested-$(CONFIG_WIN32) += tap-win32.o
+net-nested-$(CONFIG_BSD) += tap-bsd.o
 net-obj-y += $(addprefix net/, $(net-nested-y))
 
 ######################################################################
diff --git a/net/tap-bsd.c b/net/tap-bsd.c
new file mode 100644
index 0000000..6940434
--- /dev/null
+++ b/net/tap-bsd.c
@@ -0,0 +1,62 @@
+/*
+ * QEMU System Emulator
+ *
+ * Copyright (c) 2003-2008 Fabrice Bellard
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "net/tap.h"
+#incude "qemu-common.h"
+
+#ifdef __NetBSD__
+#include <net/if_tap.h>
+#endif
+
+#if defined(__FreeBSD__) || defined(__DragonFly__)
+#include <libutil.h>
+#else
+#include <util.h>
+#endif
+#elif defined (__GLIBC__) && defined (__FreeBSD_kernel__)
+#include <freebsd/stdlib.h>
+
+#if defined(__OpenBSD__)
+#include <util.h>
+#endif
+
+int tap_open(char *ifname, int ifname_size, int *vnet_hdr, int vnet_hdr_required)
+{
+    int fd;
+    char *dev;
+    struct stat s;
+
+    TFR(fd = open("/dev/tap", O_RDWR));
+    if (fd < 0) {
+        fprintf(stderr, "warning: could not open /dev/tap: no virtual network emulation\n");
+        return -1;
+    }
+
+    fstat(fd, &s);
+    dev = devname(s.st_rdev, S_IFCHR);
+    pstrcpy(ifname, ifname_size, dev);
+
+    fcntl(fd, F_SETFL, O_NONBLOCK);
+    return fd;
+}
diff --git a/net/tap.c b/net/tap.c
index 6b43d80..64553ab 100644
--- a/net/tap.c
+++ b/net/tap.c
@@ -42,24 +42,6 @@
 #include "net/tap-linux.h"
 #endif
 
-#ifdef __NetBSD__
-#include <net/if_tap.h>
-#endif
-
-#ifdef CONFIG_BSD
-#if defined(__FreeBSD__) || defined(__DragonFly__)
-#include <libutil.h>
-#else
-#include <util.h>
-#endif
-#elif defined (__GLIBC__) && defined (__FreeBSD_kernel__)
-#include <freebsd/stdlib.h>
-#endif
-
-#if defined(__OpenBSD__)
-#include <util.h>
-#endif
-
 #ifdef __sun__
 #include <sys/stat.h>
 #include <sys/ethernet.h>
@@ -394,28 +376,7 @@ static TAPState *net_tap_fd_init(VLANState *vlan,
     return s;
 }
 
-#if defined (CONFIG_BSD) || defined (__FreeBSD_kernel__)
-static int tap_open(char *ifname, int ifname_size,
-                    int *vnet_hdr, int vnet_hdr_required)
-{
-    int fd;
-    char *dev;
-    struct stat s;
-
-    TFR(fd = open("/dev/tap", O_RDWR));
-    if (fd < 0) {
-        fprintf(stderr, "warning: could not open /dev/tap: no virtual network emulation\n");
-        return -1;
-    }
-
-    fstat(fd, &s);
-    dev = devname(s.st_rdev, S_IFCHR);
-    pstrcpy(ifname, ifname_size, dev);
-
-    fcntl(fd, F_SETFL, O_NONBLOCK);
-    return fd;
-}
-#elif defined(__sun__)
+#ifdef __sun__
 #define TUNNEWPPA       (('T'<<16) | 0x0001)
 /*
  * Allocate TAP device, returns opened fd.
@@ -538,8 +499,7 @@ static int tap_alloc(char *dev, size_t dev_size)
     return tap_fd;
 }
 
-static int tap_open(char *ifname, int ifname_size,
-                    int *vnet_hdr, int vnet_hdr_required)
+int tap_open(char *ifname, int ifname_size, int *vnet_hdr, int vnet_hdr_required)
 {
     char  dev[10]="";
     int fd;
@@ -552,15 +512,13 @@ static int tap_open(char *ifname, int ifname_size,
     return fd;
 }
 #elif defined (_AIX)
-static int tap_open(char *ifname, int ifname_size,
-                    int *vnet_hdr, int vnet_hdr_required)
+int tap_open(char *ifname, int ifname_size, int *vnet_hdr, int vnet_hdr_required)
 {
     fprintf (stderr, "no tap on AIX\n");
     return -1;
 }
 #else
-static int tap_open(char *ifname, int ifname_size,
-                    int *vnet_hdr, int vnet_hdr_required)
+int tap_open(char *ifname, int ifname_size, int *vnet_hdr, int vnet_hdr_required)
 {
     struct ifreq ifr;
     int fd, ret;
diff --git a/net/tap.h b/net/tap.h
index 53952a1..5d32de5 100644
--- a/net/tap.h
+++ b/net/tap.h
@@ -34,6 +34,8 @@
 
 int net_init_tap(QemuOpts *opts, Monitor *mon, const char *name, VLANState *vlan);
 
+int tap_open(char *ifname, int ifname_size, int *vnet_hdr, int vnet_hdr_required);
+
 int tap_has_ufo(VLANClientState *vc);
 int tap_has_vnet_hdr(VLANClientState *vc);
 void tap_using_vnet_hdr(VLANClientState *vc, int using_vnet_hdr);
-- 
1.6.2.5

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [Qemu-devel] [PATCH 08/15] net: move solaris code to net/tap-solaris.c
  2009-10-22 16:49 [Qemu-devel] [PATCH 00/15] Some networking code re-organization Mark McLoughlin
                   ` (6 preceding siblings ...)
  2009-10-22 16:49 ` [Qemu-devel] [PATCH 07/15] net: split BSD tap_open() out into net/tap-bsd.c Mark McLoughlin
@ 2009-10-22 16:49 ` Mark McLoughlin
  2009-10-22 16:49 ` [Qemu-devel] [PATCH 09/15] net: move AIX code into net/tap-aix.c Mark McLoughlin
                   ` (8 subsequent siblings)
  16 siblings, 0 replies; 22+ messages in thread
From: Mark McLoughlin @ 2009-10-22 16:49 UTC (permalink / raw)
  To: qemu-devel; +Cc: Mark McLoughlin

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
---
 Makefile          |    1 +
 net/tap-solaris.c |  185 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 net/tap.c         |  168 +-----------------------------------------------
 net/tap.h         |    2 +
 4 files changed, 191 insertions(+), 165 deletions(-)
 create mode 100644 net/tap-solaris.c

diff --git a/Makefile b/Makefile
index a29c486..5918213 100644
--- a/Makefile
+++ b/Makefile
@@ -91,6 +91,7 @@ net-nested-y = queue.o checksum.o
 net-nested-$(CONFIG_POSIX) += tap.o
 net-nested-$(CONFIG_WIN32) += tap-win32.o
 net-nested-$(CONFIG_BSD) += tap-bsd.o
+net-nested-$(CONFIG_SOLARIS) += tap-solaris.o
 net-obj-y += $(addprefix net/, $(net-nested-y))
 
 ######################################################################
diff --git a/net/tap-solaris.c b/net/tap-solaris.c
new file mode 100644
index 0000000..0dd5b68
--- /dev/null
+++ b/net/tap-solaris.c
@@ -0,0 +1,185 @@
+/*
+ * QEMU System Emulator
+ *
+ * Copyright (c) 2003-2008 Fabrice Bellard
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "net/tap.h"
+
+#include <sys/stat.h>
+#include <sys/ethernet.h>
+#include <sys/sockio.h>
+#include <netinet/arp.h>
+#include <netinet/in.h>
+#include <netinet/in_systm.h>
+#include <netinet/ip.h>
+#include <netinet/ip_icmp.h> // must come after ip.h
+#include <netinet/udp.h>
+#include <netinet/tcp.h>
+#include <net/if.h>
+#include <syslog.h>
+#include <stropts.h>
+
+ssize_t tap_read_packet(int tapfd, uint8_t *buf, int maxlen)
+{
+    struct strbuf sbuf;
+    int f = 0;
+
+    sbuf.maxlen = maxlen;
+    sbuf.buf = (char *)buf;
+
+    return getmsg(tapfd, NULL, &sbuf, &f) >= 0 ? sbuf.len : -1;
+}
+
+#define TUNNEWPPA       (('T'<<16) | 0x0001)
+/*
+ * Allocate TAP device, returns opened fd.
+ * Stores dev name in the first arg(must be large enough).
+ */
+static int tap_alloc(char *dev, size_t dev_size)
+{
+    int tap_fd, if_fd, ppa = -1;
+    static int ip_fd = 0;
+    char *ptr;
+
+    static int arp_fd = 0;
+    int ip_muxid, arp_muxid;
+    struct strioctl  strioc_if, strioc_ppa;
+    int link_type = I_PLINK;;
+    struct lifreq ifr;
+    char actual_name[32] = "";
+
+    memset(&ifr, 0x0, sizeof(ifr));
+
+    if( *dev ){
+       ptr = dev;
+       while( *ptr && !qemu_isdigit((int)*ptr) ) ptr++;
+       ppa = atoi(ptr);
+    }
+
+    /* Check if IP device was opened */
+    if( ip_fd )
+       close(ip_fd);
+
+    TFR(ip_fd = open("/dev/udp", O_RDWR, 0));
+    if (ip_fd < 0) {
+       syslog(LOG_ERR, "Can't open /dev/ip (actually /dev/udp)");
+       return -1;
+    }
+
+    TFR(tap_fd = open("/dev/tap", O_RDWR, 0));
+    if (tap_fd < 0) {
+       syslog(LOG_ERR, "Can't open /dev/tap");
+       return -1;
+    }
+
+    /* Assign a new PPA and get its unit number. */
+    strioc_ppa.ic_cmd = TUNNEWPPA;
+    strioc_ppa.ic_timout = 0;
+    strioc_ppa.ic_len = sizeof(ppa);
+    strioc_ppa.ic_dp = (char *)&ppa;
+    if ((ppa = ioctl (tap_fd, I_STR, &strioc_ppa)) < 0)
+       syslog (LOG_ERR, "Can't assign new interface");
+
+    TFR(if_fd = open("/dev/tap", O_RDWR, 0));
+    if (if_fd < 0) {
+       syslog(LOG_ERR, "Can't open /dev/tap (2)");
+       return -1;
+    }
+    if(ioctl(if_fd, I_PUSH, "ip") < 0){
+       syslog(LOG_ERR, "Can't push IP module");
+       return -1;
+    }
+
+    if (ioctl(if_fd, SIOCGLIFFLAGS, &ifr) < 0)
+	syslog(LOG_ERR, "Can't get flags\n");
+
+    snprintf (actual_name, 32, "tap%d", ppa);
+    pstrcpy(ifr.lifr_name, sizeof(ifr.lifr_name), actual_name);
+
+    ifr.lifr_ppa = ppa;
+    /* Assign ppa according to the unit number returned by tun device */
+
+    if (ioctl (if_fd, SIOCSLIFNAME, &ifr) < 0)
+        syslog (LOG_ERR, "Can't set PPA %d", ppa);
+    if (ioctl(if_fd, SIOCGLIFFLAGS, &ifr) <0)
+        syslog (LOG_ERR, "Can't get flags\n");
+    /* Push arp module to if_fd */
+    if (ioctl (if_fd, I_PUSH, "arp") < 0)
+        syslog (LOG_ERR, "Can't push ARP module (2)");
+
+    /* Push arp module to ip_fd */
+    if (ioctl (ip_fd, I_POP, NULL) < 0)
+        syslog (LOG_ERR, "I_POP failed\n");
+    if (ioctl (ip_fd, I_PUSH, "arp") < 0)
+        syslog (LOG_ERR, "Can't push ARP module (3)\n");
+    /* Open arp_fd */
+    TFR(arp_fd = open ("/dev/tap", O_RDWR, 0));
+    if (arp_fd < 0)
+       syslog (LOG_ERR, "Can't open %s\n", "/dev/tap");
+
+    /* Set ifname to arp */
+    strioc_if.ic_cmd = SIOCSLIFNAME;
+    strioc_if.ic_timout = 0;
+    strioc_if.ic_len = sizeof(ifr);
+    strioc_if.ic_dp = (char *)&ifr;
+    if (ioctl(arp_fd, I_STR, &strioc_if) < 0){
+        syslog (LOG_ERR, "Can't set ifname to arp\n");
+    }
+
+    if((ip_muxid = ioctl(ip_fd, I_LINK, if_fd)) < 0){
+       syslog(LOG_ERR, "Can't link TAP device to IP");
+       return -1;
+    }
+
+    if ((arp_muxid = ioctl (ip_fd, link_type, arp_fd)) < 0)
+        syslog (LOG_ERR, "Can't link TAP device to ARP");
+
+    close (if_fd);
+
+    memset(&ifr, 0x0, sizeof(ifr));
+    pstrcpy(ifr.lifr_name, sizeof(ifr.lifr_name), actual_name);
+    ifr.lifr_ip_muxid  = ip_muxid;
+    ifr.lifr_arp_muxid = arp_muxid;
+
+    if (ioctl (ip_fd, SIOCSLIFMUXID, &ifr) < 0)
+    {
+      ioctl (ip_fd, I_PUNLINK , arp_muxid);
+      ioctl (ip_fd, I_PUNLINK, ip_muxid);
+      syslog (LOG_ERR, "Can't set multiplexor id");
+    }
+
+    snprintf(dev, dev_size, "tap%d", ppa);
+    return tap_fd;
+}
+
+int tap_open(char *ifname, int ifname_size, int *vnet_hdr, int vnet_hdr_required)
+{
+    char  dev[10]="";
+    int fd;
+    if( (fd = tap_alloc(dev, sizeof(dev))) < 0 ){
+       fprintf(stderr, "Cannot allocate TAP device\n");
+       return -1;
+    }
+    pstrcpy(ifname, ifname_size, dev);
+    fcntl(fd, F_SETFL, O_NONBLOCK);
+    return fd;
+}
diff --git a/net/tap.c b/net/tap.c
index 64553ab..056fefe 100644
--- a/net/tap.c
+++ b/net/tap.c
@@ -42,22 +42,6 @@
 #include "net/tap-linux.h"
 #endif
 
-#ifdef __sun__
-#include <sys/stat.h>
-#include <sys/ethernet.h>
-#include <sys/sockio.h>
-#include <netinet/arp.h>
-#include <netinet/in.h>
-#include <netinet/in_systm.h>
-#include <netinet/ip.h>
-#include <netinet/ip_icmp.h> // must come after ip.h
-#include <netinet/udp.h>
-#include <netinet/tcp.h>
-#include <net/if.h>
-#include <syslog.h>
-#include <stropts.h>
-#endif
-
 #if !defined(_AIX)
 
 /* Maximum GSO packet size (64k) plus plenty of room for
@@ -191,19 +175,8 @@ static int tap_can_send(void *opaque)
     return qemu_can_send_packet(s->vc);
 }
 
-#ifdef __sun__
-static ssize_t tap_read_packet(int tapfd, uint8_t *buf, int maxlen)
-{
-    struct strbuf sbuf;
-    int f = 0;
-
-    sbuf.maxlen = maxlen;
-    sbuf.buf = (char *)buf;
-
-    return getmsg(tapfd, NULL, &sbuf, &f) >= 0 ? sbuf.len : -1;
-}
-#else
-static ssize_t tap_read_packet(int tapfd, uint8_t *buf, int maxlen)
+#ifndef __sun__
+ssize_t tap_read_packet(int tapfd, uint8_t *buf, int maxlen)
 {
     return read(tapfd, buf, maxlen);
 }
@@ -376,142 +349,7 @@ static TAPState *net_tap_fd_init(VLANState *vlan,
     return s;
 }
 
-#ifdef __sun__
-#define TUNNEWPPA       (('T'<<16) | 0x0001)
-/*
- * Allocate TAP device, returns opened fd.
- * Stores dev name in the first arg(must be large enough).
- */
-static int tap_alloc(char *dev, size_t dev_size)
-{
-    int tap_fd, if_fd, ppa = -1;
-    static int ip_fd = 0;
-    char *ptr;
-
-    static int arp_fd = 0;
-    int ip_muxid, arp_muxid;
-    struct strioctl  strioc_if, strioc_ppa;
-    int link_type = I_PLINK;;
-    struct lifreq ifr;
-    char actual_name[32] = "";
-
-    memset(&ifr, 0x0, sizeof(ifr));
-
-    if( *dev ){
-       ptr = dev;
-       while( *ptr && !qemu_isdigit((int)*ptr) ) ptr++;
-       ppa = atoi(ptr);
-    }
-
-    /* Check if IP device was opened */
-    if( ip_fd )
-       close(ip_fd);
-
-    TFR(ip_fd = open("/dev/udp", O_RDWR, 0));
-    if (ip_fd < 0) {
-       syslog(LOG_ERR, "Can't open /dev/ip (actually /dev/udp)");
-       return -1;
-    }
-
-    TFR(tap_fd = open("/dev/tap", O_RDWR, 0));
-    if (tap_fd < 0) {
-       syslog(LOG_ERR, "Can't open /dev/tap");
-       return -1;
-    }
-
-    /* Assign a new PPA and get its unit number. */
-    strioc_ppa.ic_cmd = TUNNEWPPA;
-    strioc_ppa.ic_timout = 0;
-    strioc_ppa.ic_len = sizeof(ppa);
-    strioc_ppa.ic_dp = (char *)&ppa;
-    if ((ppa = ioctl (tap_fd, I_STR, &strioc_ppa)) < 0)
-       syslog (LOG_ERR, "Can't assign new interface");
-
-    TFR(if_fd = open("/dev/tap", O_RDWR, 0));
-    if (if_fd < 0) {
-       syslog(LOG_ERR, "Can't open /dev/tap (2)");
-       return -1;
-    }
-    if(ioctl(if_fd, I_PUSH, "ip") < 0){
-       syslog(LOG_ERR, "Can't push IP module");
-       return -1;
-    }
-
-    if (ioctl(if_fd, SIOCGLIFFLAGS, &ifr) < 0)
-	syslog(LOG_ERR, "Can't get flags\n");
-
-    snprintf (actual_name, 32, "tap%d", ppa);
-    pstrcpy(ifr.lifr_name, sizeof(ifr.lifr_name), actual_name);
-
-    ifr.lifr_ppa = ppa;
-    /* Assign ppa according to the unit number returned by tun device */
-
-    if (ioctl (if_fd, SIOCSLIFNAME, &ifr) < 0)
-        syslog (LOG_ERR, "Can't set PPA %d", ppa);
-    if (ioctl(if_fd, SIOCGLIFFLAGS, &ifr) <0)
-        syslog (LOG_ERR, "Can't get flags\n");
-    /* Push arp module to if_fd */
-    if (ioctl (if_fd, I_PUSH, "arp") < 0)
-        syslog (LOG_ERR, "Can't push ARP module (2)");
-
-    /* Push arp module to ip_fd */
-    if (ioctl (ip_fd, I_POP, NULL) < 0)
-        syslog (LOG_ERR, "I_POP failed\n");
-    if (ioctl (ip_fd, I_PUSH, "arp") < 0)
-        syslog (LOG_ERR, "Can't push ARP module (3)\n");
-    /* Open arp_fd */
-    TFR(arp_fd = open ("/dev/tap", O_RDWR, 0));
-    if (arp_fd < 0)
-       syslog (LOG_ERR, "Can't open %s\n", "/dev/tap");
-
-    /* Set ifname to arp */
-    strioc_if.ic_cmd = SIOCSLIFNAME;
-    strioc_if.ic_timout = 0;
-    strioc_if.ic_len = sizeof(ifr);
-    strioc_if.ic_dp = (char *)&ifr;
-    if (ioctl(arp_fd, I_STR, &strioc_if) < 0){
-        syslog (LOG_ERR, "Can't set ifname to arp\n");
-    }
-
-    if((ip_muxid = ioctl(ip_fd, I_LINK, if_fd)) < 0){
-       syslog(LOG_ERR, "Can't link TAP device to IP");
-       return -1;
-    }
-
-    if ((arp_muxid = ioctl (ip_fd, link_type, arp_fd)) < 0)
-        syslog (LOG_ERR, "Can't link TAP device to ARP");
-
-    close (if_fd);
-
-    memset(&ifr, 0x0, sizeof(ifr));
-    pstrcpy(ifr.lifr_name, sizeof(ifr.lifr_name), actual_name);
-    ifr.lifr_ip_muxid  = ip_muxid;
-    ifr.lifr_arp_muxid = arp_muxid;
-
-    if (ioctl (ip_fd, SIOCSLIFMUXID, &ifr) < 0)
-    {
-      ioctl (ip_fd, I_PUNLINK , arp_muxid);
-      ioctl (ip_fd, I_PUNLINK, ip_muxid);
-      syslog (LOG_ERR, "Can't set multiplexor id");
-    }
-
-    snprintf(dev, dev_size, "tap%d", ppa);
-    return tap_fd;
-}
-
-int tap_open(char *ifname, int ifname_size, int *vnet_hdr, int vnet_hdr_required)
-{
-    char  dev[10]="";
-    int fd;
-    if( (fd = tap_alloc(dev, sizeof(dev))) < 0 ){
-       fprintf(stderr, "Cannot allocate TAP device\n");
-       return -1;
-    }
-    pstrcpy(ifname, ifname_size, dev);
-    fcntl(fd, F_SETFL, O_NONBLOCK);
-    return fd;
-}
-#elif defined (_AIX)
+#ifdef _AIX
 int tap_open(char *ifname, int ifname_size, int *vnet_hdr, int vnet_hdr_required)
 {
     fprintf (stderr, "no tap on AIX\n");
diff --git a/net/tap.h b/net/tap.h
index 5d32de5..5648ddd 100644
--- a/net/tap.h
+++ b/net/tap.h
@@ -36,6 +36,8 @@ int net_init_tap(QemuOpts *opts, Monitor *mon, const char *name, VLANState *vlan
 
 int tap_open(char *ifname, int ifname_size, int *vnet_hdr, int vnet_hdr_required);
 
+ssize_t tap_read_packet(int tapfd, uint8_t *buf, int maxlen);
+
 int tap_has_ufo(VLANClientState *vc);
 int tap_has_vnet_hdr(VLANClientState *vc);
 void tap_using_vnet_hdr(VLANClientState *vc, int using_vnet_hdr);
-- 
1.6.2.5

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [Qemu-devel] [PATCH 09/15] net: move AIX code into net/tap-aix.c
  2009-10-22 16:49 [Qemu-devel] [PATCH 00/15] Some networking code re-organization Mark McLoughlin
                   ` (7 preceding siblings ...)
  2009-10-22 16:49 ` [Qemu-devel] [PATCH 08/15] net: move solaris code to net/tap-solaris.c Mark McLoughlin
@ 2009-10-22 16:49 ` Mark McLoughlin
  2009-10-22 16:49 ` [Qemu-devel] [PATCH 10/15] build: add CONFIG_LINUX Mark McLoughlin
                   ` (7 subsequent siblings)
  16 siblings, 0 replies; 22+ messages in thread
From: Mark McLoughlin @ 2009-10-22 16:49 UTC (permalink / raw)
  To: qemu-devel; +Cc: Mark McLoughlin

Okay, this makes the tap options available on AIX even though there's
no support, but if we want to do it right we should have not compile
the tap code at all on AIX using e.g. CONFIG_TAP.

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
---
 Makefile      |    1 +
 net.c         |    2 --
 net/tap-aix.c |   32 ++++++++++++++++++++++++++++++++
 net/tap.c     |   12 ------------
 4 files changed, 33 insertions(+), 14 deletions(-)
 create mode 100644 net/tap-aix.c

diff --git a/Makefile b/Makefile
index 5918213..b9ff2eb 100644
--- a/Makefile
+++ b/Makefile
@@ -92,6 +92,7 @@ net-nested-$(CONFIG_POSIX) += tap.o
 net-nested-$(CONFIG_WIN32) += tap-win32.o
 net-nested-$(CONFIG_BSD) += tap-bsd.o
 net-nested-$(CONFIG_SOLARIS) += tap-solaris.o
+net-nested-$(CONFIG_AIX) += tap-aix.o
 net-obj-y += $(addprefix net/, $(net-nested-y))
 
 ######################################################################
diff --git a/net.c b/net.c
index 365305a..661bbc1 100644
--- a/net.c
+++ b/net.c
@@ -2425,7 +2425,6 @@ static struct {
             { /* end of list */ }
         },
 #endif
-#ifndef _AIX
     }, {
         .type = "tap",
         .init = net_init_tap,
@@ -2461,7 +2460,6 @@ static struct {
 #endif /* _WIN32 */
             { /* end of list */ }
         },
-#endif /* _AIX */
     }, {
         .type = "socket",
         .init = net_init_socket,
diff --git a/net/tap-aix.c b/net/tap-aix.c
new file mode 100644
index 0000000..5ec3b2c
--- /dev/null
+++ b/net/tap-aix.c
@@ -0,0 +1,32 @@
+/*
+ * QEMU System Emulator
+ *
+ * Copyright (c) 2003-2008 Fabrice Bellard
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "net/tap.h"
+#include <stdio.h>
+
+int tap_open(char *ifname, int ifname_size, int *vnet_hdr, int vnet_hdr_required)
+{
+    fprintf(stderr, "no tap on AIX\n");
+    return -1;
+}
diff --git a/net/tap.c b/net/tap.c
index 056fefe..560e0e4 100644
--- a/net/tap.c
+++ b/net/tap.c
@@ -42,8 +42,6 @@
 #include "net/tap-linux.h"
 #endif
 
-#if !defined(_AIX)
-
 /* Maximum GSO packet size (64k) plus plenty of room for
  * the ethernet and virtio_net headers
  */
@@ -349,13 +347,6 @@ static TAPState *net_tap_fd_init(VLANState *vlan,
     return s;
 }
 
-#ifdef _AIX
-int tap_open(char *ifname, int ifname_size, int *vnet_hdr, int vnet_hdr_required)
-{
-    fprintf (stderr, "no tap on AIX\n");
-    return -1;
-}
-#else
 int tap_open(char *ifname, int ifname_size, int *vnet_hdr, int vnet_hdr_required)
 {
     struct ifreq ifr;
@@ -400,7 +391,6 @@ int tap_open(char *ifname, int ifname_size, int *vnet_hdr, int vnet_hdr_required
     fcntl(fd, F_SETFL, O_NONBLOCK);
     return fd;
 }
-#endif
 
 static int launch_script(const char *setup_script, const char *ifname, int fd)
 {
@@ -551,5 +541,3 @@ int net_init_tap(QemuOpts *opts, Monitor *mon, const char *name, VLANState *vlan
 
     return 0;
 }
-
-#endif /* !defined(_AIX) */
-- 
1.6.2.5

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [Qemu-devel] [PATCH 10/15] build: add CONFIG_LINUX
  2009-10-22 16:49 [Qemu-devel] [PATCH 00/15] Some networking code re-organization Mark McLoughlin
                   ` (8 preceding siblings ...)
  2009-10-22 16:49 ` [Qemu-devel] [PATCH 09/15] net: move AIX code into net/tap-aix.c Mark McLoughlin
@ 2009-10-22 16:49 ` Mark McLoughlin
  2009-10-22 16:49 ` [Qemu-devel] [PATCH 11/15] net: move linux code into net/tap-linux.c Mark McLoughlin
                   ` (6 subsequent siblings)
  16 siblings, 0 replies; 22+ messages in thread
From: Mark McLoughlin @ 2009-10-22 16:49 UTC (permalink / raw)
  To: qemu-devel; +Cc: Mark McLoughlin

So I can add a tap-linux.c and use CONFIG_LINUX to pull it in
in Makefile

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
---
 configure |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/configure b/configure
index 43d87c5..4ccdebe 100755
--- a/configure
+++ b/configure
@@ -1897,6 +1897,10 @@ else
   echo "CONFIG_POSIX=y" >> $config_host_mak
 fi
 
+if test "$linux" = "yes" ; then
+  echo "CONFIG_LINUX=y" >> $config_host_mak
+fi
+
 if test "$darwin" = "yes" ; then
   echo "CONFIG_DARWIN=y" >> $config_host_mak
 fi
-- 
1.6.2.5

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [Qemu-devel] [PATCH 11/15] net: move linux code into net/tap-linux.c
  2009-10-22 16:49 [Qemu-devel] [PATCH 00/15] Some networking code re-organization Mark McLoughlin
                   ` (9 preceding siblings ...)
  2009-10-22 16:49 ` [Qemu-devel] [PATCH 10/15] build: add CONFIG_LINUX Mark McLoughlin
@ 2009-10-22 16:49 ` Mark McLoughlin
  2009-10-22 16:49 ` [Qemu-devel] [PATCH 12/15] net: move tap_set_sndbuf() to tap-linux.c Mark McLoughlin
                   ` (5 subsequent siblings)
  16 siblings, 0 replies; 22+ messages in thread
From: Mark McLoughlin @ 2009-10-22 16:49 UTC (permalink / raw)
  To: qemu-devel; +Cc: Mark McLoughlin

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
---
 Makefile        |    1 +
 net/tap-linux.c |   78 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 net/tap.c       |   47 ---------------------------------
 3 files changed, 79 insertions(+), 47 deletions(-)
 create mode 100644 net/tap-linux.c

diff --git a/Makefile b/Makefile
index b9ff2eb..44bd7ef 100644
--- a/Makefile
+++ b/Makefile
@@ -89,6 +89,7 @@ block-obj-y +=  $(addprefix block/, $(block-nested-y))
 net-obj-y = net.o
 net-nested-y = queue.o checksum.o
 net-nested-$(CONFIG_POSIX) += tap.o
+net-nested-$(CONFIG_LINUX) += tap-linux.o
 net-nested-$(CONFIG_WIN32) += tap-win32.o
 net-nested-$(CONFIG_BSD) += tap-bsd.o
 net-nested-$(CONFIG_SOLARIS) += tap-solaris.o
diff --git a/net/tap-linux.c b/net/tap-linux.c
new file mode 100644
index 0000000..c6f751e
--- /dev/null
+++ b/net/tap-linux.c
@@ -0,0 +1,78 @@
+/*
+ * QEMU System Emulator
+ *
+ * Copyright (c) 2003-2008 Fabrice Bellard
+ * Copyright (c) 2009 Red Hat, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "net/tap.h"
+#include "net/tap-linux.h"
+
+#include <net/if.h>
+#include <sys/ioctl.h>
+
+#include "sysemu.h"
+#include "qemu-common.h"
+
+int tap_open(char *ifname, int ifname_size, int *vnet_hdr, int vnet_hdr_required)
+{
+    struct ifreq ifr;
+    int fd, ret;
+
+    TFR(fd = open("/dev/net/tun", O_RDWR));
+    if (fd < 0) {
+        fprintf(stderr, "warning: could not open /dev/net/tun: no virtual network emulation\n");
+        return -1;
+    }
+    memset(&ifr, 0, sizeof(ifr));
+    ifr.ifr_flags = IFF_TAP | IFF_NO_PI;
+
+    if (*vnet_hdr) {
+        unsigned int features;
+
+        if (ioctl(fd, TUNGETFEATURES, &features) == 0 &&
+            features & IFF_VNET_HDR) {
+            *vnet_hdr = 1;
+            ifr.ifr_flags |= IFF_VNET_HDR;
+        }
+
+        if (vnet_hdr_required && !*vnet_hdr) {
+            qemu_error("vnet_hdr=1 requested, but no kernel "
+                       "support for IFF_VNET_HDR available");
+            close(fd);
+            return -1;
+        }
+    }
+
+    if (ifname[0] != '\0')
+        pstrcpy(ifr.ifr_name, IFNAMSIZ, ifname);
+    else
+        pstrcpy(ifr.ifr_name, IFNAMSIZ, "tap%d");
+    ret = ioctl(fd, TUNSETIFF, (void *) &ifr);
+    if (ret != 0) {
+        fprintf(stderr, "warning: could not configure /dev/net/tun: no virtual network emulation\n");
+        close(fd);
+        return -1;
+    }
+    pstrcpy(ifname, ifname_size, ifr.ifr_name);
+    fcntl(fd, F_SETFL, O_NONBLOCK);
+    return fd;
+}
diff --git a/net/tap.c b/net/tap.c
index 560e0e4..5392937 100644
--- a/net/tap.c
+++ b/net/tap.c
@@ -38,9 +38,7 @@
 #include "qemu-char.h"
 #include "qemu-common.h"
 
-#ifdef __linux__
 #include "net/tap-linux.h"
-#endif
 
 /* Maximum GSO packet size (64k) plus plenty of room for
  * the ethernet and virtio_net headers
@@ -347,51 +345,6 @@ static TAPState *net_tap_fd_init(VLANState *vlan,
     return s;
 }
 
-int tap_open(char *ifname, int ifname_size, int *vnet_hdr, int vnet_hdr_required)
-{
-    struct ifreq ifr;
-    int fd, ret;
-
-    TFR(fd = open("/dev/net/tun", O_RDWR));
-    if (fd < 0) {
-        fprintf(stderr, "warning: could not open /dev/net/tun: no virtual network emulation\n");
-        return -1;
-    }
-    memset(&ifr, 0, sizeof(ifr));
-    ifr.ifr_flags = IFF_TAP | IFF_NO_PI;
-
-    if (*vnet_hdr) {
-        unsigned int features;
-
-        if (ioctl(fd, TUNGETFEATURES, &features) == 0 &&
-            features & IFF_VNET_HDR) {
-            *vnet_hdr = 1;
-            ifr.ifr_flags |= IFF_VNET_HDR;
-        }
-
-        if (vnet_hdr_required && !*vnet_hdr) {
-            qemu_error("vnet_hdr=1 requested, but no kernel "
-                       "support for IFF_VNET_HDR available");
-            close(fd);
-            return -1;
-        }
-    }
-
-    if (ifname[0] != '\0')
-        pstrcpy(ifr.ifr_name, IFNAMSIZ, ifname);
-    else
-        pstrcpy(ifr.ifr_name, IFNAMSIZ, "tap%d");
-    ret = ioctl(fd, TUNSETIFF, (void *) &ifr);
-    if (ret != 0) {
-        fprintf(stderr, "warning: could not configure /dev/net/tun: no virtual network emulation\n");
-        close(fd);
-        return -1;
-    }
-    pstrcpy(ifname, ifname_size, ifr.ifr_name);
-    fcntl(fd, F_SETFL, O_NONBLOCK);
-    return fd;
-}
-
 static int launch_script(const char *setup_script, const char *ifname, int fd)
 {
     sigset_t oldmask, mask;
-- 
1.6.2.5

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [Qemu-devel] [PATCH 12/15] net: move tap_set_sndbuf() to tap-linux.c
  2009-10-22 16:49 [Qemu-devel] [PATCH 00/15] Some networking code re-organization Mark McLoughlin
                   ` (10 preceding siblings ...)
  2009-10-22 16:49 ` [Qemu-devel] [PATCH 11/15] net: move linux code into net/tap-linux.c Mark McLoughlin
@ 2009-10-22 16:49 ` Mark McLoughlin
  2009-10-22 16:49 ` [Qemu-devel] [PATCH 13/15] net: move tap_probe_vnet_hdr() " Mark McLoughlin
                   ` (4 subsequent siblings)
  16 siblings, 0 replies; 22+ messages in thread
From: Mark McLoughlin @ 2009-10-22 16:49 UTC (permalink / raw)
  To: qemu-devel; +Cc: Mark McLoughlin

TUNSETSNDBUF is only available on linux

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
---
 net/tap-aix.c     |    6 ++++++
 net/tap-bsd.c     |    5 +++++
 net/tap-linux.c   |   23 +++++++++++++++++++++++
 net/tap-solaris.c |    5 +++++
 net/tap.c         |   25 +------------------------
 net/tap.h         |    2 ++
 6 files changed, 42 insertions(+), 24 deletions(-)

diff --git a/net/tap-aix.c b/net/tap-aix.c
index 5ec3b2c..3f9ccdd 100644
--- a/net/tap-aix.c
+++ b/net/tap-aix.c
@@ -30,3 +30,9 @@ int tap_open(char *ifname, int ifname_size, int *vnet_hdr, int vnet_hdr_required
     fprintf(stderr, "no tap on AIX\n");
     return -1;
 }
+
+int tap_set_sndbuf(int fd, QemuOpts *opts)
+{
+    return 0;
+}
+
diff --git a/net/tap-bsd.c b/net/tap-bsd.c
index 6940434..e28615f 100644
--- a/net/tap-bsd.c
+++ b/net/tap-bsd.c
@@ -60,3 +60,8 @@ int tap_open(char *ifname, int ifname_size, int *vnet_hdr, int vnet_hdr_required
     fcntl(fd, F_SETFL, O_NONBLOCK);
     return fd;
 }
+
+int tap_set_sndbuf(int fd, QemuOpts *opts)
+{
+    return 0;
+}
diff --git a/net/tap-linux.c b/net/tap-linux.c
index c6f751e..6c3b6e3 100644
--- a/net/tap-linux.c
+++ b/net/tap-linux.c
@@ -76,3 +76,26 @@ int tap_open(char *ifname, int ifname_size, int *vnet_hdr, int vnet_hdr_required
     fcntl(fd, F_SETFL, O_NONBLOCK);
     return fd;
 }
+
+/* sndbuf should be set to a value lower than the tx queue
+ * capacity of any destination network interface.
+ * Ethernet NICs generally have txqueuelen=1000, so 1Mb is
+ * a good default, given a 1500 byte MTU.
+ */
+#define TAP_DEFAULT_SNDBUF 1024*1024
+
+int tap_set_sndbuf(int fd, QemuOpts *opts)
+{
+    int sndbuf;
+
+    sndbuf = qemu_opt_get_size(opts, "sndbuf", TAP_DEFAULT_SNDBUF);
+    if (!sndbuf) {
+        sndbuf = INT_MAX;
+    }
+
+    if (ioctl(fd, TUNSETSNDBUF, &sndbuf) == -1 && qemu_opt_get(opts, "sndbuf")) {
+        qemu_error("TUNSETSNDBUF ioctl failed: %s\n", strerror(errno));
+        return -1;
+    }
+    return 0;
+}
diff --git a/net/tap-solaris.c b/net/tap-solaris.c
index 0dd5b68..de5855a 100644
--- a/net/tap-solaris.c
+++ b/net/tap-solaris.c
@@ -183,3 +183,8 @@ int tap_open(char *ifname, int ifname_size, int *vnet_hdr, int vnet_hdr_required
     fcntl(fd, F_SETFL, O_NONBLOCK);
     return fd;
 }
+
+int tap_set_sndbuf(int fd, QemuOpts *opts)
+{
+    return 0;
+}
diff --git a/net/tap.c b/net/tap.c
index 5392937..df2cfbe 100644
--- a/net/tap.c
+++ b/net/tap.c
@@ -209,29 +209,6 @@ static void tap_send(void *opaque)
     } while (size > 0);
 }
 
-/* sndbuf should be set to a value lower than the tx queue
- * capacity of any destination network interface.
- * Ethernet NICs generally have txqueuelen=1000, so 1Mb is
- * a good default, given a 1500 byte MTU.
- */
-#define TAP_DEFAULT_SNDBUF 1024*1024
-
-static int tap_set_sndbuf(TAPState *s, QemuOpts *opts)
-{
-    int sndbuf;
-
-    sndbuf = qemu_opt_get_size(opts, "sndbuf", TAP_DEFAULT_SNDBUF);
-    if (!sndbuf) {
-        sndbuf = INT_MAX;
-    }
-
-    if (ioctl(s->fd, TUNSETSNDBUF, &sndbuf) == -1 && qemu_opt_get(opts, "sndbuf")) {
-        qemu_error("TUNSETSNDBUF ioctl failed: %s\n", strerror(errno));
-        return -1;
-    }
-    return 0;
-}
-
 int tap_has_ufo(VLANClientState *vc)
 {
     TAPState *s = vc->opaque;
@@ -465,7 +442,7 @@ int net_init_tap(QemuOpts *opts, Monitor *mon, const char *name, VLANState *vlan
         return -1;
     }
 
-    if (tap_set_sndbuf(s, opts) < 0) {
+    if (tap_set_sndbuf(s->fd, opts) < 0) {
         return -1;
     }
 
diff --git a/net/tap.h b/net/tap.h
index 5648ddd..0d67c24 100644
--- a/net/tap.h
+++ b/net/tap.h
@@ -43,4 +43,6 @@ int tap_has_vnet_hdr(VLANClientState *vc);
 void tap_using_vnet_hdr(VLANClientState *vc, int using_vnet_hdr);
 void tap_set_offload(VLANClientState *vc, int csum, int tso4, int tso6, int ecn, int ufo);
 
+int tap_set_sndbuf(int fd, QemuOpts *opts);
+
 #endif /* QEMU_NET_TAP_H */
-- 
1.6.2.5

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [Qemu-devel] [PATCH 13/15] net: move tap_probe_vnet_hdr() to tap-linux.c
  2009-10-22 16:49 [Qemu-devel] [PATCH 00/15] Some networking code re-organization Mark McLoughlin
                   ` (11 preceding siblings ...)
  2009-10-22 16:49 ` [Qemu-devel] [PATCH 12/15] net: move tap_set_sndbuf() to tap-linux.c Mark McLoughlin
@ 2009-10-22 16:49 ` Mark McLoughlin
  2009-10-22 16:49 ` [Qemu-devel] [PATCH 14/15] net: move tap_set_offload() code into tap-linux.c Mark McLoughlin
                   ` (3 subsequent siblings)
  16 siblings, 0 replies; 22+ messages in thread
From: Mark McLoughlin @ 2009-10-22 16:49 UTC (permalink / raw)
  To: qemu-devel; +Cc: Mark McLoughlin

Only Linux has support for IFF_VNET_HDR

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
---
 net/tap-aix.c     |    4 ++++
 net/tap-bsd.c     |    5 +++++
 net/tap-linux.c   |   12 ++++++++++++
 net/tap-solaris.c |    5 +++++
 net/tap.c         |   12 ------------
 net/tap.h         |    1 +
 6 files changed, 27 insertions(+), 12 deletions(-)

diff --git a/net/tap-aix.c b/net/tap-aix.c
index 3f9ccdd..27143ff 100644
--- a/net/tap-aix.c
+++ b/net/tap-aix.c
@@ -36,3 +36,7 @@ int tap_set_sndbuf(int fd, QemuOpts *opts)
     return 0;
 }
 
+int tap_probe_vnet_hdr(int fd)
+{
+    return 0;
+}
diff --git a/net/tap-bsd.c b/net/tap-bsd.c
index e28615f..1cdde90 100644
--- a/net/tap-bsd.c
+++ b/net/tap-bsd.c
@@ -65,3 +65,8 @@ int tap_set_sndbuf(int fd, QemuOpts *opts)
 {
     return 0;
 }
+
+int tap_probe_vnet_hdr(int fd)
+{
+    return 0;
+}
diff --git a/net/tap-linux.c b/net/tap-linux.c
index 6c3b6e3..0059404 100644
--- a/net/tap-linux.c
+++ b/net/tap-linux.c
@@ -99,3 +99,15 @@ int tap_set_sndbuf(int fd, QemuOpts *opts)
     }
     return 0;
 }
+
+int tap_probe_vnet_hdr(int fd)
+{
+    struct ifreq ifr;
+
+    if (ioctl(fd, TUNGETIFF, &ifr) != 0) {
+        qemu_error("TUNGETIFF ioctl() failed: %s\n", strerror(errno));
+        return 0;
+    }
+
+    return ifr.ifr_flags & IFF_VNET_HDR;
+}
diff --git a/net/tap-solaris.c b/net/tap-solaris.c
index de5855a..3f48e57 100644
--- a/net/tap-solaris.c
+++ b/net/tap-solaris.c
@@ -188,3 +188,8 @@ int tap_set_sndbuf(int fd, QemuOpts *opts)
 {
     return 0;
 }
+
+int tap_probe_vnet_hdr(int fd)
+{
+    return 0;
+}
diff --git a/net/tap.c b/net/tap.c
index df2cfbe..3f6722e 100644
--- a/net/tap.c
+++ b/net/tap.c
@@ -239,18 +239,6 @@ void tap_using_vnet_hdr(VLANClientState *vc, int using_vnet_hdr)
     s->using_vnet_hdr = using_vnet_hdr;
 }
 
-static int tap_probe_vnet_hdr(int fd)
-{
-    struct ifreq ifr;
-
-    if (ioctl(fd, TUNGETIFF, &ifr) != 0) {
-        qemu_error("TUNGETIFF ioctl() failed: %s\n", strerror(errno));
-        return 0;
-    }
-
-    return ifr.ifr_flags & IFF_VNET_HDR;
-}
-
 void tap_set_offload(VLANClientState *vc, int csum, int tso4,
                      int tso6, int ecn, int ufo)
 {
diff --git a/net/tap.h b/net/tap.h
index 0d67c24..de729a7 100644
--- a/net/tap.h
+++ b/net/tap.h
@@ -44,5 +44,6 @@ void tap_using_vnet_hdr(VLANClientState *vc, int using_vnet_hdr);
 void tap_set_offload(VLANClientState *vc, int csum, int tso4, int tso6, int ecn, int ufo);
 
 int tap_set_sndbuf(int fd, QemuOpts *opts);
+int tap_probe_vnet_hdr(int fd);
 
 #endif /* QEMU_NET_TAP_H */
-- 
1.6.2.5

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [Qemu-devel] [PATCH 14/15] net: move tap_set_offload() code into tap-linux.c
  2009-10-22 16:49 [Qemu-devel] [PATCH 00/15] Some networking code re-organization Mark McLoughlin
                   ` (12 preceding siblings ...)
  2009-10-22 16:49 ` [Qemu-devel] [PATCH 13/15] net: move tap_probe_vnet_hdr() " Mark McLoughlin
@ 2009-10-22 16:49 ` Mark McLoughlin
  2009-10-22 16:49 ` [Qemu-devel] [PATCH 15/15] net: move UFO support detection to tap-linux.c Mark McLoughlin
                   ` (2 subsequent siblings)
  16 siblings, 0 replies; 22+ messages in thread
From: Mark McLoughlin @ 2009-10-22 16:49 UTC (permalink / raw)
  To: qemu-devel; +Cc: Mark McLoughlin

TUNSETOFFLOAD is only available on Linux

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
---
 net/tap-aix.c     |    5 +++++
 net/tap-bsd.c     |    5 +++++
 net/tap-linux.c   |   26 ++++++++++++++++++++++++++
 net/tap-solaris.c |    5 +++++
 net/tap.c         |   21 +--------------------
 net/tap.h         |    1 +
 6 files changed, 43 insertions(+), 20 deletions(-)

diff --git a/net/tap-aix.c b/net/tap-aix.c
index 27143ff..0de3dd9 100644
--- a/net/tap-aix.c
+++ b/net/tap-aix.c
@@ -40,3 +40,8 @@ int tap_probe_vnet_hdr(int fd)
 {
     return 0;
 }
+
+void tap_fd_set_offload(int fd, int csum, int tso4,
+                        int tso6, int ecn, int ufo)
+{
+}
diff --git a/net/tap-bsd.c b/net/tap-bsd.c
index 1cdde90..1e85a3c 100644
--- a/net/tap-bsd.c
+++ b/net/tap-bsd.c
@@ -70,3 +70,8 @@ int tap_probe_vnet_hdr(int fd)
 {
     return 0;
 }
+
+void tap_fd_set_offload(int fd, int csum, int tso4,
+                        int tso6, int ecn, int ufo)
+{
+}
diff --git a/net/tap-linux.c b/net/tap-linux.c
index 0059404..b6f1fad 100644
--- a/net/tap-linux.c
+++ b/net/tap-linux.c
@@ -111,3 +111,29 @@ int tap_probe_vnet_hdr(int fd)
 
     return ifr.ifr_flags & IFF_VNET_HDR;
 }
+
+void tap_fd_set_offload(int fd, int csum, int tso4,
+                        int tso6, int ecn, int ufo)
+{
+    unsigned int offload = 0;
+
+    if (csum) {
+        offload |= TUN_F_CSUM;
+        if (tso4)
+            offload |= TUN_F_TSO4;
+        if (tso6)
+            offload |= TUN_F_TSO6;
+        if ((tso4 || tso6) && ecn)
+            offload |= TUN_F_TSO_ECN;
+        if (ufo)
+            offload |= TUN_F_UFO;
+    }
+
+    if (ioctl(fd, TUNSETOFFLOAD, offload) != 0) {
+        offload &= ~TUN_F_UFO;
+        if (ioctl(fd, TUNSETOFFLOAD, offload) != 0) {
+            fprintf(stderr, "TUNSETOFFLOAD ioctl() failed: %s\n",
+                    strerror(errno));
+        }
+    }
+}
diff --git a/net/tap-solaris.c b/net/tap-solaris.c
index 3f48e57..614df01 100644
--- a/net/tap-solaris.c
+++ b/net/tap-solaris.c
@@ -193,3 +193,8 @@ int tap_probe_vnet_hdr(int fd)
 {
     return 0;
 }
+
+void tap_fd_set_offload(int fd, int csum, int tso4,
+                        int tso6, int ecn, int ufo)
+{
+}
diff --git a/net/tap.c b/net/tap.c
index 3f6722e..9b11071 100644
--- a/net/tap.c
+++ b/net/tap.c
@@ -243,27 +243,8 @@ void tap_set_offload(VLANClientState *vc, int csum, int tso4,
                      int tso6, int ecn, int ufo)
 {
     TAPState *s = vc->opaque;
-    unsigned int offload = 0;
-
-    if (csum) {
-        offload |= TUN_F_CSUM;
-        if (tso4)
-            offload |= TUN_F_TSO4;
-        if (tso6)
-            offload |= TUN_F_TSO6;
-        if ((tso4 || tso6) && ecn)
-            offload |= TUN_F_TSO_ECN;
-        if (ufo)
-            offload |= TUN_F_UFO;
-    }
 
-    if (ioctl(s->fd, TUNSETOFFLOAD, offload) != 0) {
-        offload &= ~TUN_F_UFO;
-        if (ioctl(s->fd, TUNSETOFFLOAD, offload) != 0) {
-            fprintf(stderr, "TUNSETOFFLOAD ioctl() failed: %s\n",
-                    strerror(errno));
-        }
-    }
+    return tap_fd_set_offload(s->fd, csum, tso4, tso6, ecn, ufo);
 }
 
 static void tap_cleanup(VLANClientState *vc)
diff --git a/net/tap.h b/net/tap.h
index de729a7..16398b5 100644
--- a/net/tap.h
+++ b/net/tap.h
@@ -45,5 +45,6 @@ void tap_set_offload(VLANClientState *vc, int csum, int tso4, int tso6, int ecn,
 
 int tap_set_sndbuf(int fd, QemuOpts *opts);
 int tap_probe_vnet_hdr(int fd);
+void tap_fd_set_offload(int fd, int csum, int tso4, int tso6, int ecn, int ufo);
 
 #endif /* QEMU_NET_TAP_H */
-- 
1.6.2.5

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [Qemu-devel] [PATCH 15/15] net: move UFO support detection to tap-linux.c
  2009-10-22 16:49 [Qemu-devel] [PATCH 00/15] Some networking code re-organization Mark McLoughlin
                   ` (13 preceding siblings ...)
  2009-10-22 16:49 ` [Qemu-devel] [PATCH 14/15] net: move tap_set_offload() code into tap-linux.c Mark McLoughlin
@ 2009-10-22 16:49 ` Mark McLoughlin
  2009-10-22 20:34 ` [Qemu-devel] [PATCH 00/15] Some networking code re-organization Anthony Liguori
       [not found] ` <m37hunntts.fsf@neno.mitica>
  16 siblings, 0 replies; 22+ messages in thread
From: Mark McLoughlin @ 2009-10-22 16:49 UTC (permalink / raw)
  To: qemu-devel; +Cc: Mark McLoughlin

Only supported on Linux

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
---
 net/tap-aix.c     |    5 +++++
 net/tap-bsd.c     |    5 +++++
 net/tap-linux.c   |   12 ++++++++++++
 net/tap-solaris.c |    5 +++++
 net/tap.c         |    7 +------
 net/tap.h         |    1 +
 6 files changed, 29 insertions(+), 6 deletions(-)

diff --git a/net/tap-aix.c b/net/tap-aix.c
index 0de3dd9..4bc9f2f 100644
--- a/net/tap-aix.c
+++ b/net/tap-aix.c
@@ -41,6 +41,11 @@ int tap_probe_vnet_hdr(int fd)
     return 0;
 }
 
+int tap_probe_has_ufo(int fd)
+{
+    return 0;
+}
+
 void tap_fd_set_offload(int fd, int csum, int tso4,
                         int tso6, int ecn, int ufo)
 {
diff --git a/net/tap-bsd.c b/net/tap-bsd.c
index 1e85a3c..3ad14bb 100644
--- a/net/tap-bsd.c
+++ b/net/tap-bsd.c
@@ -71,6 +71,11 @@ int tap_probe_vnet_hdr(int fd)
     return 0;
 }
 
+int tap_probe_has_ufo(int fd)
+{
+    return 0;
+}
+
 void tap_fd_set_offload(int fd, int csum, int tso4,
                         int tso6, int ecn, int ufo)
 {
diff --git a/net/tap-linux.c b/net/tap-linux.c
index b6f1fad..0f621a2 100644
--- a/net/tap-linux.c
+++ b/net/tap-linux.c
@@ -112,6 +112,18 @@ int tap_probe_vnet_hdr(int fd)
     return ifr.ifr_flags & IFF_VNET_HDR;
 }
 
+int tap_probe_has_ufo(int fd)
+{
+    unsigned offload;
+
+    offload = TUN_F_CSUM | TUN_F_UFO;
+
+    if (ioctl(fd, TUNSETOFFLOAD, offload) < 0)
+        return 0;
+
+    return 1;
+}
+
 void tap_fd_set_offload(int fd, int csum, int tso4,
                         int tso6, int ecn, int ufo)
 {
diff --git a/net/tap-solaris.c b/net/tap-solaris.c
index 614df01..ef4e60c 100644
--- a/net/tap-solaris.c
+++ b/net/tap-solaris.c
@@ -194,6 +194,11 @@ int tap_probe_vnet_hdr(int fd)
     return 0;
 }
 
+int tap_probe_has_ufo(int fd)
+{
+    return 0;
+}
+
 void tap_fd_set_offload(int fd, int csum, int tso4,
                         int tso6, int ecn, int ufo)
 {
diff --git a/net/tap.c b/net/tap.c
index 9b11071..60354e4 100644
--- a/net/tap.c
+++ b/net/tap.c
@@ -271,7 +271,6 @@ static TAPState *net_tap_fd_init(VLANState *vlan,
                                  int vnet_hdr)
 {
     TAPState *s;
-    unsigned int offload;
 
     s = qemu_mallocz(sizeof(TAPState));
     s->fd = fd;
@@ -281,11 +280,7 @@ static TAPState *net_tap_fd_init(VLANState *vlan,
                                  vlan, NULL, model, name, NULL,
                                  tap_receive, tap_receive_raw,
                                  tap_receive_iov, tap_cleanup, s);
-    s->has_ufo = 0;
-    /* Check if tap supports UFO */
-    offload = TUN_F_CSUM | TUN_F_UFO;
-    if (ioctl(s->fd, TUNSETOFFLOAD, offload) == 0)
-       s->has_ufo = 1;
+    s->has_ufo = tap_probe_has_ufo(s->fd);
     tap_set_offload(s->vc, 0, 0, 0, 0, 0);
     tap_read_poll(s, 1);
     return s;
diff --git a/net/tap.h b/net/tap.h
index 16398b5..538a562 100644
--- a/net/tap.h
+++ b/net/tap.h
@@ -45,6 +45,7 @@ void tap_set_offload(VLANClientState *vc, int csum, int tso4, int tso6, int ecn,
 
 int tap_set_sndbuf(int fd, QemuOpts *opts);
 int tap_probe_vnet_hdr(int fd);
+int tap_probe_has_ufo(int fd);
 void tap_fd_set_offload(int fd, int csum, int tso4, int tso6, int ecn, int ufo);
 
 #endif /* QEMU_NET_TAP_H */
-- 
1.6.2.5

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* Re: [Qemu-devel] [PATCH 00/15] Some networking code re-organization
  2009-10-22 16:49 [Qemu-devel] [PATCH 00/15] Some networking code re-organization Mark McLoughlin
                   ` (14 preceding siblings ...)
  2009-10-22 16:49 ` [Qemu-devel] [PATCH 15/15] net: move UFO support detection to tap-linux.c Mark McLoughlin
@ 2009-10-22 20:34 ` Anthony Liguori
  2009-10-23  9:59   ` Mark McLoughlin
       [not found] ` <m37hunntts.fsf@neno.mitica>
  16 siblings, 1 reply; 22+ messages in thread
From: Anthony Liguori @ 2009-10-22 20:34 UTC (permalink / raw)
  To: Mark McLoughlin; +Cc: qemu-devel

Mark McLoughlin wrote:
> Hey,
>         We've been meaning to split net.c up for quite a while now,
> so here goes with a first cut at.
>
>         There shouldn't be anything too controversial here, apart
> from CONFIG_LINUX maybe.
>
>         I've build tested this on F11, F12 and mingw and also done
> some basic runtime testing.
>
>         Building on e.g. *BSD, Solaris and AIX hasn't been tested.
> I wouldn't be surprised if I've broken the build there despite all
> my efforts but, if I have, it should be trivial to fix back up.
>
>         This isn't the end of the cleanups; obviously the other
> backends could be split out too, we could use module construtors, etc.
>   

This series doesn't build for me.  I get dependency errors even after a 
full rebuild.  I'm building from a separate directory fwiw.

Regards,

Anthony Liguori

> Cheers,
> Mark.
>
>
>
>   

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [Qemu-devel] [PATCH 00/15] Some networking code re-organization
  2009-10-22 20:34 ` [Qemu-devel] [PATCH 00/15] Some networking code re-organization Anthony Liguori
@ 2009-10-23  9:59   ` Mark McLoughlin
  2009-10-23 13:44     ` Anthony Liguori
  0 siblings, 1 reply; 22+ messages in thread
From: Mark McLoughlin @ 2009-10-23  9:59 UTC (permalink / raw)
  To: Anthony Liguori; +Cc: qemu-devel

On Thu, 2009-10-22 at 15:34 -0500, Anthony Liguori wrote:
> Mark McLoughlin wrote:
> > Hey,
> >         We've been meaning to split net.c up for quite a while now,
> > so here goes with a first cut at.
> >
> >         There shouldn't be anything too controversial here, apart
> > from CONFIG_LINUX maybe.
> >
> >         I've build tested this on F11, F12 and mingw and also done
> > some basic runtime testing.
> >
> >         Building on e.g. *BSD, Solaris and AIX hasn't been tested.
> > I wouldn't be surprised if I've broken the build there despite all
> > my efforts but, if I have, it should be trivial to fix back up.
> >
> >         This isn't the end of the cleanups; obviously the other
> > backends could be split out too, we could use module construtors, etc.
> >   
> 
> This series doesn't build for me.  I get dependency errors even after a 
> full rebuild.  I'm building from a separate directory fwiw.

Don't see it here, I'm afraid - any more details?

Btw, it's all pushed to http://repo.or.cz/w/qemu/markmc.git if that
helps

Cheers,
Mark.

^ permalink raw reply	[flat|nested] 22+ messages in thread

* [Qemu-devel] Re: [PATCH 00/15] Some networking code re-organization
       [not found] ` <m37hunntts.fsf@neno.mitica>
@ 2009-10-23 10:00   ` Mark McLoughlin
  0 siblings, 0 replies; 22+ messages in thread
From: Mark McLoughlin @ 2009-10-23 10:00 UTC (permalink / raw)
  To: Juan Quintela; +Cc: qemu-devel

On Thu, 2009-10-22 at 20:53 +0200, Juan Quintela wrote:
> Mark McLoughlin <markmc@redhat.com> wrote:
> > Hey,
> >         We've been meaning to split net.c up for quite a while now,
> > so here goes with a first cut at.
> 
> If you have to respin this series, please use
> 
> git mv foo.c net/foo.c

I did, looks like I needed to use 'git format-patch -M'

Cheers,
Mark.

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [Qemu-devel] [PATCH 00/15] Some networking code re-organization
  2009-10-23  9:59   ` Mark McLoughlin
@ 2009-10-23 13:44     ` Anthony Liguori
  2009-10-23 16:49       ` Mark McLoughlin
  0 siblings, 1 reply; 22+ messages in thread
From: Anthony Liguori @ 2009-10-23 13:44 UTC (permalink / raw)
  To: Mark McLoughlin; +Cc: qemu-devel

[-- Attachment #1: Type: text/plain, Size: 664 bytes --]

Mark McLoughlin wrote:
> On Thu, 2009-10-22 at 15:34 -0500, Anthony Liguori wrote:
>   
>> This series doesn't build for me.  I get dependency errors even after a 
>> full rebuild.  I'm building from a separate directory fwiw.
>>     
>
> Don't see it here, I'm afraid - any more details?
>
> Btw, it's all pushed to http://repo.or.cz/w/qemu/markmc.git if that
> helps
>   

Building master of that tree.  Source code is in 
/home/anthony/git/qemu.  Build dir is /home/anthony/obj/qemu-tmp.  
Configure line is ~/git/qemu/configure 
--kerneldir=/home/anthony/git/kvm-userspace/kernel.

Attached the make V=1 output and configure output.

Regards,

Anthony Liguori

[-- Attachment #2: build.log --]
[-- Type: text/plain, Size: 29972 bytes --]

Install prefix    /usr/local
BIOS directory    /usr/local/share/qemu
binary directory  /usr/local/bin
Manual directory  /usr/local/share/man
ELF interp prefix /usr/gnemul/qemu-%M
Source path       /home/anthony/git/qemu
C compiler        gcc
Host C compiler   gcc
CFLAGS            -O2 -g 
QEMU_CFLAGS       -Werror -Wold-style-definition -Wold-style-declaration -I. -I$(SRC_PATH) -U_FORTIFY_SOURCE -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wendif-labels -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -m64 
LDFLAGS           -Wl,--warn-common -g -m64 
make              make
install           install
host CPU          x86_64
host big endian   no
target list       i386-softmmu x86_64-softmmu arm-softmmu cris-softmmu m68k-softmmu microblaze-softmmu mips-softmmu mipsel-softmmu mips64-softmmu mips64el-softmmu ppc-softmmu ppcemb-softmmu ppc64-softmmu sh4-softmmu sh4eb-softmmu sparc-softmmu sparc64-softmmu i386-linux-user x86_64-linux-user alpha-linux-user arm-linux-user armeb-linux-user cris-linux-user m68k-linux-user microblaze-linux-user mips-linux-user mipsel-linux-user ppc-linux-user ppc64-linux-user ppc64abi32-linux-user sh4-linux-user sh4eb-linux-user sparc-linux-user sparc64-linux-user sparc32plus-linux-user 
tcg debug enabled no
gprof enabled     no
sparse enabled    no
strip binaries    yes
profiler          no
static build      no
-Werror enabled   yes
SDL support       yes
curses support    yes
curl support      yes
check support     no
mingw32 support   no
Audio drivers     oss
Extra audio cards ac97 es1370 sb16
Mixer emulation   no
VNC TLS support   yes
VNC SASL support  yes
xen support       no
brlapi support    yes
bluez  support    no
Documentation     yes
NPTL support      yes
GUEST_BASE        yes
PIE user targets  no
vde support       yes
IO thread         no
Linux AIO support yes
Install blobs     yes
KVM support       yes
fdt support       no
preadv support    no
fdatasync         yes
uuid support      yes
cat  i386-softmmu/config-devices.mak  x86_64-softmmu/config-devices.mak  arm-softmmu/config-devices.mak  cris-softmmu/config-devices.mak  m68k-softmmu/config-devices.mak  microblaze-softmmu/config-devices.mak  mips-softmmu/config-devices.mak  mipsel-softmmu/config-devices.mak  mips64-softmmu/config-devices.mak  mips64el-softmmu/config-devices.mak  ppc-softmmu/config-devices.mak  ppcemb-softmmu/config-devices.mak  ppc64-softmmu/config-devices.mak  sh4-softmmu/config-devices.mak  sh4eb-softmmu/config-devices.mak  sparc-softmmu/config-devices.mak  sparc64-softmmu/config-devices.mak  i386-linux-user/config-devices.mak  x86_64-linux-user/config-devices.mak  alpha-linux-user/config-devices.mak  arm-linux-user/config-devices.mak  armeb-linux-user/config-devices.mak  cris-linux-user/config-devices.mak  m68k-linux-user/config-devices.mak  microblaze-linux-user/config-devices.mak  mips-linux-user/config-devices.mak  mipsel-linux-user/config-devices.mak  ppc-linux-user/config-devices.mak  ppc64-linux-user/config-devices.mak  ppc64abi32-linux-user/config-devices.mak  sh4-linux-user/config-devices.mak  sh4eb-linux-user/config-devices.mak  sparc-linux-user/config-devices.mak  sparc64-linux-user/config-devices.mak  sparc32plus-linux-user/config-devices.mak | grep "=y$" | sort -u > config-all-devices.mak
/home/anthony/git/qemu/create_config < config-host.mak > config-host.h-timestamp
/home/anthony/git/qemu/create_config < config-all-devices.mak > config-all-devices.h-timestamp
make  qemu-nbd qemu-io qemu-img  qemu-doc.html qemu-tech.html qemu.1 qemu-img.1 qemu-nbd.8 recurse-all
make[1]: Entering directory `/home/anthony/obj/qemu-tmp'
gcc -I/home/anthony/git/qemu/slirp -Werror -Wold-style-definition -Wold-style-declaration -I. -I/home/anthony/git/qemu -U_FORTIFY_SOURCE -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wendif-labels -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -m64  -MMD -MP -MT qemu-nbd.o  -O2 -g  -c -o qemu-nbd.o /home/anthony/git/qemu/qemu-nbd.c
gcc -I/home/anthony/git/qemu/slirp -Werror -Wold-style-definition -Wold-style-declaration -I. -I/home/anthony/git/qemu -U_FORTIFY_SOURCE -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wendif-labels -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -m64  -MMD -MP -MT qemu-tool.o  -O2 -g  -c -o qemu-tool.o /home/anthony/git/qemu/qemu-tool.c
gcc -I/home/anthony/git/qemu/slirp -Werror -Wold-style-definition -Wold-style-declaration -I. -I/home/anthony/git/qemu -U_FORTIFY_SOURCE -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wendif-labels -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -m64  -MMD -MP -MT cutils.o  -O2 -g  -c -o cutils.o /home/anthony/git/qemu/cutils.c
gcc -I/home/anthony/git/qemu/slirp -Werror -Wold-style-definition -Wold-style-declaration -I. -I/home/anthony/git/qemu -U_FORTIFY_SOURCE -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wendif-labels -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -m64  -MMD -MP -MT cache-utils.o  -O2 -g  -c -o cache-utils.o /home/anthony/git/qemu/cache-utils.c
gcc -I/home/anthony/git/qemu/slirp -Werror -Wold-style-definition -Wold-style-declaration -I. -I/home/anthony/git/qemu -U_FORTIFY_SOURCE -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wendif-labels -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -m64  -MMD -MP -MT qemu-malloc.o  -O2 -g  -c -o qemu-malloc.o /home/anthony/git/qemu/qemu-malloc.c
gcc -I/home/anthony/git/qemu/slirp -Werror -Wold-style-definition -Wold-style-declaration -I. -I/home/anthony/git/qemu -U_FORTIFY_SOURCE -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wendif-labels -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -m64  -MMD -MP -MT qemu-option.o  -O2 -g  -c -o qemu-option.o /home/anthony/git/qemu/qemu-option.c
gcc -I/home/anthony/git/qemu/slirp -Werror -Wold-style-definition -Wold-style-declaration -I. -I/home/anthony/git/qemu -U_FORTIFY_SOURCE -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wendif-labels -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -m64  -MMD -MP -MT module.o  -O2 -g  -c -o module.o /home/anthony/git/qemu/module.c
gcc -I/home/anthony/git/qemu/slirp -Werror -Wold-style-definition -Wold-style-declaration -I. -I/home/anthony/git/qemu -U_FORTIFY_SOURCE -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wendif-labels -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -m64  -MMD -MP -MT nbd.o  -O2 -g  -c -o nbd.o /home/anthony/git/qemu/nbd.c
gcc -I/home/anthony/git/qemu/slirp -Werror -Wold-style-definition -Wold-style-declaration -I. -I/home/anthony/git/qemu -U_FORTIFY_SOURCE -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wendif-labels -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -m64  -MMD -MP -MT block.o  -O2 -g  -c -o block.o /home/anthony/git/qemu/block.c
gcc -I/home/anthony/git/qemu/slirp -Werror -Wold-style-definition -Wold-style-declaration -I. -I/home/anthony/git/qemu -U_FORTIFY_SOURCE -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wendif-labels -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -m64  -MMD -MP -MT aio.o  -O2 -g  -c -o aio.o /home/anthony/git/qemu/aio.c
gcc -I/home/anthony/git/qemu/slirp -Werror -Wold-style-definition -Wold-style-declaration -I. -I/home/anthony/git/qemu -U_FORTIFY_SOURCE -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wendif-labels -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -m64  -MMD -MP -MT aes.o  -O2 -g  -c -o aes.o /home/anthony/git/qemu/aes.c
gcc -I/home/anthony/git/qemu/slirp -Werror -Wold-style-definition -Wold-style-declaration -I. -I/home/anthony/git/qemu -U_FORTIFY_SOURCE -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wendif-labels -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -m64  -MMD -MP -MT osdep.o  -O2 -g  -c -o osdep.o /home/anthony/git/qemu/osdep.c
gcc -I/home/anthony/git/qemu/slirp -Werror -Wold-style-definition -Wold-style-declaration -I. -I/home/anthony/git/qemu -U_FORTIFY_SOURCE -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wendif-labels -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -m64  -MMD -MP -MT posix-aio-compat.o  -O2 -g  -c -o posix-aio-compat.o /home/anthony/git/qemu/posix-aio-compat.c
gcc -I/home/anthony/git/qemu/slirp -Werror -Wold-style-definition -Wold-style-declaration -I. -I/home/anthony/git/qemu -U_FORTIFY_SOURCE -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wendif-labels -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -m64  -MMD -MP -MT linux-aio.o  -O2 -g  -c -o linux-aio.o /home/anthony/git/qemu/linux-aio.c
gcc -I/home/anthony/git/qemu/slirp -Werror -Wold-style-definition -Wold-style-declaration -I. -I/home/anthony/git/qemu -U_FORTIFY_SOURCE -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wendif-labels -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -m64  -MMD -MP -MT block/cow.o  -O2 -g  -c -o block/cow.o /home/anthony/git/qemu/block/cow.c
gcc -I/home/anthony/git/qemu/slirp -Werror -Wold-style-definition -Wold-style-declaration -I. -I/home/anthony/git/qemu -U_FORTIFY_SOURCE -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wendif-labels -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -m64  -MMD -MP -MT block/qcow.o  -O2 -g  -c -o block/qcow.o /home/anthony/git/qemu/block/qcow.c
gcc -I/home/anthony/git/qemu/slirp -Werror -Wold-style-definition -Wold-style-declaration -I. -I/home/anthony/git/qemu -U_FORTIFY_SOURCE -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wendif-labels -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -m64  -MMD -MP -MT block/vdi.o  -O2 -g  -c -o block/vdi.o /home/anthony/git/qemu/block/vdi.c
gcc -I/home/anthony/git/qemu/slirp -Werror -Wold-style-definition -Wold-style-declaration -I. -I/home/anthony/git/qemu -U_FORTIFY_SOURCE -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wendif-labels -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -m64  -MMD -MP -MT block/vmdk.o  -O2 -g  -c -o block/vmdk.o /home/anthony/git/qemu/block/vmdk.c
gcc -I/home/anthony/git/qemu/slirp -Werror -Wold-style-definition -Wold-style-declaration -I. -I/home/anthony/git/qemu -U_FORTIFY_SOURCE -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wendif-labels -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -m64  -MMD -MP -MT block/cloop.o  -O2 -g  -c -o block/cloop.o /home/anthony/git/qemu/block/cloop.c
gcc -I/home/anthony/git/qemu/slirp -Werror -Wold-style-definition -Wold-style-declaration -I. -I/home/anthony/git/qemu -U_FORTIFY_SOURCE -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wendif-labels -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -m64  -MMD -MP -MT block/dmg.o  -O2 -g  -c -o block/dmg.o /home/anthony/git/qemu/block/dmg.c
gcc -I/home/anthony/git/qemu/slirp -Werror -Wold-style-definition -Wold-style-declaration -I. -I/home/anthony/git/qemu -U_FORTIFY_SOURCE -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wendif-labels -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -m64  -MMD -MP -MT block/bochs.o  -O2 -g  -c -o block/bochs.o /home/anthony/git/qemu/block/bochs.c
gcc -I/home/anthony/git/qemu/slirp -Werror -Wold-style-definition -Wold-style-declaration -I. -I/home/anthony/git/qemu -U_FORTIFY_SOURCE -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wendif-labels -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -m64  -MMD -MP -MT block/vpc.o  -O2 -g  -c -o block/vpc.o /home/anthony/git/qemu/block/vpc.c
gcc -I/home/anthony/git/qemu/slirp -Werror -Wold-style-definition -Wold-style-declaration -I. -I/home/anthony/git/qemu -U_FORTIFY_SOURCE -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wendif-labels -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -m64  -MMD -MP -MT block/vvfat.o  -O2 -g  -c -o block/vvfat.o /home/anthony/git/qemu/block/vvfat.c
gcc -I/home/anthony/git/qemu/slirp -Werror -Wold-style-definition -Wold-style-declaration -I. -I/home/anthony/git/qemu -U_FORTIFY_SOURCE -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wendif-labels -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -m64  -MMD -MP -MT block/qcow2.o  -O2 -g  -c -o block/qcow2.o /home/anthony/git/qemu/block/qcow2.c
gcc -I/home/anthony/git/qemu/slirp -Werror -Wold-style-definition -Wold-style-declaration -I. -I/home/anthony/git/qemu -U_FORTIFY_SOURCE -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wendif-labels -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -m64  -MMD -MP -MT block/qcow2-refcount.o  -O2 -g  -c -o block/qcow2-refcount.o /home/anthony/git/qemu/block/qcow2-refcount.c
gcc -I/home/anthony/git/qemu/slirp -Werror -Wold-style-definition -Wold-style-declaration -I. -I/home/anthony/git/qemu -U_FORTIFY_SOURCE -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wendif-labels -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -m64  -MMD -MP -MT block/qcow2-cluster.o  -O2 -g  -c -o block/qcow2-cluster.o /home/anthony/git/qemu/block/qcow2-cluster.c
gcc -I/home/anthony/git/qemu/slirp -Werror -Wold-style-definition -Wold-style-declaration -I. -I/home/anthony/git/qemu -U_FORTIFY_SOURCE -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wendif-labels -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -m64  -MMD -MP -MT block/qcow2-snapshot.o  -O2 -g  -c -o block/qcow2-snapshot.o /home/anthony/git/qemu/block/qcow2-snapshot.c
gcc -I/home/anthony/git/qemu/slirp -Werror -Wold-style-definition -Wold-style-declaration -I. -I/home/anthony/git/qemu -U_FORTIFY_SOURCE -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wendif-labels -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -m64  -MMD -MP -MT block/parallels.o  -O2 -g  -c -o block/parallels.o /home/anthony/git/qemu/block/parallels.c
gcc -I/home/anthony/git/qemu/slirp -Werror -Wold-style-definition -Wold-style-declaration -I. -I/home/anthony/git/qemu -U_FORTIFY_SOURCE -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wendif-labels -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -m64  -MMD -MP -MT block/nbd.o  -O2 -g  -c -o block/nbd.o /home/anthony/git/qemu/block/nbd.c
gcc -I/home/anthony/git/qemu/slirp -Werror -Wold-style-definition -Wold-style-declaration -I. -I/home/anthony/git/qemu -U_FORTIFY_SOURCE -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wendif-labels -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -m64  -MMD -MP -MT block/raw-posix.o  -O2 -g  -c -o block/raw-posix.o /home/anthony/git/qemu/block/raw-posix.c
gcc -I/home/anthony/git/qemu/slirp -Werror -Wold-style-definition -Wold-style-declaration -I. -I/home/anthony/git/qemu -U_FORTIFY_SOURCE -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wendif-labels -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -m64  -MMD -MP -MT block/curl.o  -O2 -g  -c -o block/curl.o /home/anthony/git/qemu/block/curl.c
gcc -Wl,--warn-common -g -m64  -o qemu-nbd qemu-nbd.o qemu-tool.o cutils.o cache-utils.o qemu-malloc.o qemu-option.o module.o nbd.o block.o aio.o aes.o osdep.o posix-aio-compat.o linux-aio.o block/cow.o block/qcow.o block/vdi.o block/vmdk.o block/cloop.o block/dmg.o block/bochs.o block/vpc.o block/vvfat.o block/qcow2.o block/qcow2-refcount.o block/qcow2-cluster.o block/qcow2-snapshot.o block/parallels.o block/nbd.o block/raw-posix.o block/curl.o -Wl,--whole-archive  -Wl,--no-whole-archive -lrt -lpthread  -laio -lz -lcurl   -lvdeplug -luuid 
gcc -I/home/anthony/git/qemu/slirp -Werror -Wold-style-definition -Wold-style-declaration -I. -I/home/anthony/git/qemu -U_FORTIFY_SOURCE -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wendif-labels -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -m64  -MMD -MP -MT qemu-io.o  -O2 -g  -c -o qemu-io.o /home/anthony/git/qemu/qemu-io.c
gcc -I/home/anthony/git/qemu/slirp -Werror -Wold-style-definition -Wold-style-declaration -I. -I/home/anthony/git/qemu -U_FORTIFY_SOURCE -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wendif-labels -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -m64  -MMD -MP -MT cmd.o  -O2 -g  -c -o cmd.o /home/anthony/git/qemu/cmd.c
gcc -Wl,--warn-common -g -m64  -o qemu-io qemu-io.o qemu-tool.o cmd.o cutils.o cache-utils.o qemu-malloc.o qemu-option.o module.o nbd.o block.o aio.o aes.o osdep.o posix-aio-compat.o linux-aio.o block/cow.o block/qcow.o block/vdi.o block/vmdk.o block/cloop.o block/dmg.o block/bochs.o block/vpc.o block/vvfat.o block/qcow2.o block/qcow2-refcount.o block/qcow2-cluster.o block/qcow2-snapshot.o block/parallels.o block/nbd.o block/raw-posix.o block/curl.o -Wl,--whole-archive  -Wl,--no-whole-archive -lrt -lpthread  -laio -lz -lcurl   -lvdeplug -luuid 
sh /home/anthony/git/qemu/hxtool -h < /home/anthony/git/qemu/qemu-img-cmds.hx > qemu-img-cmds.h
gcc -I/home/anthony/git/qemu/slirp -Werror -Wold-style-definition -Wold-style-declaration -I. -I/home/anthony/git/qemu -U_FORTIFY_SOURCE -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wendif-labels -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -m64  -MMD -MP -MT qemu-img.o  -O2 -g  -c -o qemu-img.o /home/anthony/git/qemu/qemu-img.c
gcc -Wl,--warn-common -g -m64  -o qemu-img qemu-img.o qemu-tool.o cutils.o cache-utils.o qemu-malloc.o qemu-option.o module.o nbd.o block.o aio.o aes.o osdep.o posix-aio-compat.o linux-aio.o block/cow.o block/qcow.o block/vdi.o block/vmdk.o block/cloop.o block/dmg.o block/bochs.o block/vpc.o block/vvfat.o block/qcow2.o block/qcow2-refcount.o block/qcow2-cluster.o block/qcow2-snapshot.o block/parallels.o block/nbd.o block/raw-posix.o block/curl.o -Wl,--whole-archive  -Wl,--no-whole-archive -lrt -lpthread  -laio -lz -lcurl   -lvdeplug -luuid 
sh /home/anthony/git/qemu/hxtool -t < /home/anthony/git/qemu/qemu-options.hx > qemu-options.texi
sh /home/anthony/git/qemu/hxtool -t < /home/anthony/git/qemu/qemu-monitor.hx > qemu-monitor.texi
sh /home/anthony/git/qemu/hxtool -t < /home/anthony/git/qemu/qemu-img-cmds.hx > qemu-img-cmds.texi
texi2html -I=. -monolithic -number /home/anthony/git/qemu/qemu-doc.texi
texi2html -I=. -monolithic -number /home/anthony/git/qemu/qemu-tech.texi
perl -Ww -- /home/anthony/git/qemu/texi2pod.pl /home/anthony/git/qemu/qemu-doc.texi qemu.pod && pod2man --section=1 --center=" " --release=" " qemu.pod > qemu.1
perl -Ww -- /home/anthony/git/qemu/texi2pod.pl /home/anthony/git/qemu/qemu-img.texi qemu-img.pod && pod2man --section=1 --center=" " --release=" " qemu-img.pod > qemu-img.1
perl -Ww -- /home/anthony/git/qemu/texi2pod.pl /home/anthony/git/qemu/qemu-nbd.texi qemu-nbd.pod && pod2man --section=8 --center=" " --release=" " qemu-nbd.pod > qemu-nbd.8
make  -C libhw64 V="1" TARGET_DIR="libhw64/" all
make[2]: Entering directory `/home/anthony/obj/qemu-tmp/libhw64'
gcc -I/home/anthony/git/qemu/slirp -Werror -Wold-style-definition -Wold-style-declaration -I. -I/home/anthony/git/qemu -U_FORTIFY_SOURCE -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wendif-labels -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -m64  -DTARGET_PHYS_ADDR_BITS=64 -MMD -MP -MT loader.o -I.. -I/home/anthony/git/qemu/fpu -O2 -g  -c -o loader.o /home/anthony/git/qemu/hw/loader.c
gcc -I/home/anthony/git/qemu/slirp -Werror -Wold-style-definition -Wold-style-declaration -I. -I/home/anthony/git/qemu -U_FORTIFY_SOURCE -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wendif-labels -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -m64  -DTARGET_PHYS_ADDR_BITS=64 -MMD -MP -MT virtio.o -I.. -I/home/anthony/git/qemu/fpu -O2 -g  -c -o virtio.o /home/anthony/git/qemu/hw/virtio.c
gcc -I/home/anthony/git/qemu/slirp -Werror -Wold-style-definition -Wold-style-declaration -I. -I/home/anthony/git/qemu -U_FORTIFY_SOURCE -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wendif-labels -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -m64  -DTARGET_PHYS_ADDR_BITS=64 -MMD -MP -MT fw_cfg.o -I.. -I/home/anthony/git/qemu/fpu -O2 -g  -c -o fw_cfg.o /home/anthony/git/qemu/hw/fw_cfg.c
gcc -I/home/anthony/git/qemu/slirp -Werror -Wold-style-definition -Wold-style-declaration -I. -I/home/anthony/git/qemu -U_FORTIFY_SOURCE -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wendif-labels -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -m64  -DTARGET_PHYS_ADDR_BITS=64 -MMD -MP -MT watchdog.o -I.. -I/home/anthony/git/qemu/fpu -O2 -g  -c -o watchdog.o /home/anthony/git/qemu/hw/watchdog.c
gcc -I/home/anthony/git/qemu/slirp -Werror -Wold-style-definition -Wold-style-declaration -I. -I/home/anthony/git/qemu -U_FORTIFY_SOURCE -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wendif-labels -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -m64  -DTARGET_PHYS_ADDR_BITS=64 -MMD -MP -MT ecc.o -I.. -I/home/anthony/git/qemu/fpu -O2 -g  -c -o ecc.o /home/anthony/git/qemu/hw/ecc.c
gcc -I/home/anthony/git/qemu/slirp -Werror -Wold-style-definition -Wold-style-declaration -I. -I/home/anthony/git/qemu -U_FORTIFY_SOURCE -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wendif-labels -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -m64  -DTARGET_PHYS_ADDR_BITS=64 -MMD -MP -MT nand.o -I.. -I/home/anthony/git/qemu/fpu -O2 -g  -c -o nand.o /home/anthony/git/qemu/hw/nand.c
gcc -I/home/anthony/git/qemu/slirp -Werror -Wold-style-definition -Wold-style-declaration -I. -I/home/anthony/git/qemu -U_FORTIFY_SOURCE -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wendif-labels -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -m64  -DTARGET_PHYS_ADDR_BITS=64 -MMD -MP -MT m48t59.o -I.. -I/home/anthony/git/qemu/fpu -O2 -g  -c -o m48t59.o /home/anthony/git/qemu/hw/m48t59.c
gcc -I/home/anthony/git/qemu/slirp -Werror -Wold-style-definition -Wold-style-declaration -I. -I/home/anthony/git/qemu -U_FORTIFY_SOURCE -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wendif-labels -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -m64  -DTARGET_PHYS_ADDR_BITS=64 -MMD -MP -MT escc.o -I.. -I/home/anthony/git/qemu/fpu -O2 -g  -c -o escc.o /home/anthony/git/qemu/hw/escc.c
gcc -I/home/anthony/git/qemu/slirp -Werror -Wold-style-definition -Wold-style-declaration -I. -I/home/anthony/git/qemu -U_FORTIFY_SOURCE -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wendif-labels -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -m64  -DTARGET_PHYS_ADDR_BITS=64 -MMD -MP -MT wdt_i6300esb.o -I.. -I/home/anthony/git/qemu/fpu -O2 -g  -c -o wdt_i6300esb.o /home/anthony/git/qemu/hw/wdt_i6300esb.c
gcc -I/home/anthony/git/qemu/slirp -Werror -Wold-style-definition -Wold-style-declaration -I. -I/home/anthony/git/qemu -U_FORTIFY_SOURCE -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wendif-labels -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -m64  -DTARGET_PHYS_ADDR_BITS=64 -MMD -MP -MT msix.o -I.. -I/home/anthony/git/qemu/fpu -O2 -g  -c -o msix.o /home/anthony/git/qemu/hw/msix.c
gcc -I/home/anthony/git/qemu/slirp -Werror -Wold-style-definition -Wold-style-declaration -I. -I/home/anthony/git/qemu -U_FORTIFY_SOURCE -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wendif-labels -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -m64  -DTARGET_PHYS_ADDR_BITS=64 -MMD -MP -MT ne2000.o -I.. -I/home/anthony/git/qemu/fpu -O2 -g  -c -o ne2000.o /home/anthony/git/qemu/hw/ne2000.c
gcc -I/home/anthony/git/qemu/slirp -Werror -Wold-style-definition -Wold-style-declaration -I. -I/home/anthony/git/qemu -U_FORTIFY_SOURCE -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wendif-labels -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -m64  -DTARGET_PHYS_ADDR_BITS=64 -MMD -MP -MT lsi53c895a.o -I.. -I/home/anthony/git/qemu/fpu -O2 -g  -c -o lsi53c895a.o /home/anthony/git/qemu/hw/lsi53c895a.c
gcc -I/home/anthony/git/qemu/slirp -Werror -Wold-style-definition -Wold-style-declaration -I. -I/home/anthony/git/qemu -U_FORTIFY_SOURCE -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wendif-labels -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -m64  -DTARGET_PHYS_ADDR_BITS=64 -MMD -MP -MT esp.o -I.. -I/home/anthony/git/qemu/fpu -O2 -g  -c -o esp.o /home/anthony/git/qemu/hw/esp.c
gcc -I/home/anthony/git/qemu/slirp -Werror -Wold-style-definition -Wold-style-declaration -I. -I/home/anthony/git/qemu -U_FORTIFY_SOURCE -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wendif-labels -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -m64  -DTARGET_PHYS_ADDR_BITS=64 -MMD -MP -MT dma-helpers.o -I.. -I/home/anthony/git/qemu/fpu -O2 -g  -c -o dma-helpers.o /home/anthony/git/qemu/dma-helpers.c
gcc -I/home/anthony/git/qemu/slirp -Werror -Wold-style-definition -Wold-style-declaration -I. -I/home/anthony/git/qemu -U_FORTIFY_SOURCE -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wendif-labels -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -m64  -DTARGET_PHYS_ADDR_BITS=64 -MMD -MP -MT sysbus.o -I.. -I/home/anthony/git/qemu/fpu -O2 -g  -c -o sysbus.o /home/anthony/git/qemu/hw/sysbus.c
gcc -I/home/anthony/git/qemu/slirp -Werror -Wold-style-definition -Wold-style-declaration -I. -I/home/anthony/git/qemu -U_FORTIFY_SOURCE -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wendif-labels -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -m64  -DTARGET_PHYS_ADDR_BITS=64 -MMD -MP -MT isa-bus.o -I.. -I/home/anthony/git/qemu/fpu -O2 -g  -c -o isa-bus.o /home/anthony/git/qemu/hw/isa-bus.c
gcc -I/home/anthony/git/qemu/slirp -Werror -Wold-style-definition -Wold-style-declaration -I. -I/home/anthony/git/qemu -U_FORTIFY_SOURCE -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wendif-labels -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -m64  -DTARGET_PHYS_ADDR_BITS=64 -MMD -MP -MT qdev-addr.o -I.. -I/home/anthony/git/qemu/fpu -O2 -g  -c -o qdev-addr.o /home/anthony/git/qemu/hw/qdev-addr.c
rm -f libqemuhw64.a && ar rcs libqemuhw64.a loader.o virtio.o fw_cfg.o watchdog.o ecc.o nand.o m48t59.o escc.o wdt_i6300esb.o msix.o ne2000.o lsi53c895a.o esp.o dma-helpers.o sysbus.o isa-bus.o qdev-addr.o
make[2]: Leaving directory `/home/anthony/obj/qemu-tmp/libhw64'
gcc -I/home/anthony/git/qemu/slirp -Werror -Wold-style-definition -Wold-style-declaration -I. -I/home/anthony/git/qemu -U_FORTIFY_SOURCE -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wendif-labels -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -m64  -MMD -MP -MT net.o  -O2 -g  -c -o net.o /home/anthony/git/qemu/net.c
gcc -I/home/anthony/git/qemu/slirp -Werror -Wold-style-definition -Wold-style-declaration -I. -I/home/anthony/git/qemu -U_FORTIFY_SOURCE -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wendif-labels -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -m64  -MMD -MP -MT net/queue.o  -O2 -g  -c -o net/queue.o /home/anthony/git/qemu/net/queue.c
/home/anthony/git/qemu/net/queue.c:260: fatal error: opening dependency file net/queue.d: No such file or directory
compilation terminated.
make[1]: *** [net/queue.o] Error 1
make[1]: Leaving directory `/home/anthony/obj/qemu-tmp'
make: *** [build-all] Error 2

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [Qemu-devel] [PATCH 00/15] Some networking code re-organization
  2009-10-23 13:44     ` Anthony Liguori
@ 2009-10-23 16:49       ` Mark McLoughlin
  0 siblings, 0 replies; 22+ messages in thread
From: Mark McLoughlin @ 2009-10-23 16:49 UTC (permalink / raw)
  To: Anthony Liguori; +Cc: qemu-devel

On Fri, 2009-10-23 at 08:44 -0500, Anthony Liguori wrote:
> Mark McLoughlin wrote:
> > On Thu, 2009-10-22 at 15:34 -0500, Anthony Liguori wrote:
> >   
> >> This series doesn't build for me.  I get dependency errors even after a 
> >> full rebuild.  I'm building from a separate directory fwiw.
> >>     
> >
> > Don't see it here, I'm afraid - any more details?
> >
> > Btw, it's all pushed to http://repo.or.cz/w/qemu/markmc.git if that
> > helps
> >   
> 
> Building master of that tree.  Source code is in 
> /home/anthony/git/qemu.  Build dir is /home/anthony/obj/qemu-tmp.  
> Configure line is ~/git/qemu/configure 
> --kerneldir=/home/anthony/git/kvm-userspace/kernel.
> 
> Attached the make V=1 output and configure output.

Thanks, I'll add using a separate build dir to my test matrix :)

Incremental patch below, will post a v2 of 01/15, also pushed to
net-cleanup.v2 branch

Thanks,
Mark.

diff --git a/Makefile b/Makefile
index 44bd7ef..41107a5 100644
--- a/Makefile
+++ b/Makefile
@@ -229,7 +229,7 @@ clean:
 # avoid old build problems by removing potentially incorrect old files
 	rm -f config.mak op-i386.h opc-i386.h gen-op-i386.h op-arm.h opc-arm.h gen-op-arm.h
 	rm -f *.o *.d *.a $(TOOLS) TAGS cscope.* *.pod *~ */*~
-	rm -f slirp/*.o slirp/*.d audio/*.o audio/*.d block/*.o block/*.d
+	rm -f slirp/*.o slirp/*.d audio/*.o audio/*.d block/*.o block/*.d net/*.o net/*.d
 	rm -f qemu-img-cmds.h
 	$(MAKE) -C tests clean
 	for d in $(ALL_SUBDIRS) libhw32 libhw64 libuser; do \
@@ -413,4 +413,4 @@ tarbin:
 	$(mandir)/man8/qemu-nbd.8
 
 # Include automatically generated dependency files
--include $(wildcard *.d audio/*.d slirp/*.d block/*.d)
+-include $(wildcard *.d audio/*.d slirp/*.d block/*.d net/*.d)
diff --git a/configure b/configure
index 4ccdebe..b9fc32b 100755
--- a/configure
+++ b/configure
@@ -2533,7 +2533,7 @@ done # for target in $targets
 
 # build tree in object directory if source path is different from current one
 if test "$source_path_used" = "yes" ; then
-    DIRS="tests tests/cris slirp audio block pc-bios/optionrom"
+    DIRS="tests tests/cris slirp audio block net pc-bios/optionrom"
     DIRS="$DIRS roms/pcbios roms/seabios roms/vgabios"
     FILES="Makefile tests/Makefile"
     FILES="$FILES tests/cris/Makefile tests/cris/.gdbinit"

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [Qemu-devel] [PATCH 01/15 v2] net: move net-queue.[ch] under net/
  2009-10-22 16:49 ` [Qemu-devel] [PATCH 01/15] net: move net-queue.[ch] under net/ Mark McLoughlin
@ 2009-10-23 16:52   ` Mark McLoughlin
  0 siblings, 0 replies; 22+ messages in thread
From: Mark McLoughlin @ 2009-10-23 16:52 UTC (permalink / raw)
  To: qemu-devel; +Cc: Mark McLoughlin

[v2: handle building in a separate dir]

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
---
 Makefile                   |   10 +++++++---
 configure                  |    2 +-
 net.h                      |    2 +-
 net-queue.c => net/queue.c |    2 +-
 net-queue.h => net/queue.h |    0
 5 files changed, 10 insertions(+), 6 deletions(-)
 rename net-queue.c => net/queue.c (99%)
 rename net-queue.h => net/queue.h (100%)

diff --git a/Makefile b/Makefile
index e78a3d0..aea7756 100644
--- a/Makefile
+++ b/Makefile
@@ -86,6 +86,10 @@ block-nested-$(CONFIG_CURL) += curl.o
 
 block-obj-y +=  $(addprefix block/, $(block-nested-y))
 
+net-obj-y = net.o
+net-nested-y = queue.o
+net-obj-y += $(addprefix net/, $(net-nested-y))
+
 ######################################################################
 # libqemu_common.a: Target independent part of system emulation. The
 # long term path is to suppress *all* target specific code in case of
@@ -93,6 +97,7 @@ block-obj-y +=  $(addprefix block/, $(block-nested-y))
 # CPUs and machines.
 
 obj-y = $(block-obj-y)
+obj-y += $(net-obj-y)
 obj-y += readline.o console.o
 
 obj-y += tcg-runtime.o host-utils.o
@@ -121,7 +126,6 @@ obj-$(CONFIG_SD) += sd.o
 obj-y += bt.o bt-host.o bt-vhci.o bt-l2cap.o bt-sdp.o bt-hci.o bt-hid.o usb-bt.o
 obj-y += bt-hci-csr.o
 obj-y += buffered_file.o migration.o migration-tcp.o qemu-sockets.o
-obj-y += net.o net-queue.o
 obj-y += qemu-char.o aio.o net-checksum.o savevm.o
 obj-y += msmouse.o ps2.o
 obj-y += qdev.o qdev-properties.o
@@ -220,7 +224,7 @@ clean:
 # avoid old build problems by removing potentially incorrect old files
 	rm -f config.mak op-i386.h opc-i386.h gen-op-i386.h op-arm.h opc-arm.h gen-op-arm.h
 	rm -f *.o *.d *.a $(TOOLS) TAGS cscope.* *.pod *~ */*~
-	rm -f slirp/*.o slirp/*.d audio/*.o audio/*.d block/*.o block/*.d
+	rm -f slirp/*.o slirp/*.d audio/*.o audio/*.d block/*.o block/*.d net/*.o net/*.d
 	rm -f qemu-img-cmds.h
 	$(MAKE) -C tests clean
 	for d in $(ALL_SUBDIRS) libhw32 libhw64 libuser; do \
@@ -404,4 +408,4 @@ tarbin:
 	$(mandir)/man8/qemu-nbd.8
 
 # Include automatically generated dependency files
--include $(wildcard *.d audio/*.d slirp/*.d block/*.d)
+-include $(wildcard *.d audio/*.d slirp/*.d block/*.d net/*.d)
diff --git a/configure b/configure
index 43d87c5..6b4faf6 100755
--- a/configure
+++ b/configure
@@ -2529,7 +2529,7 @@ done # for target in $targets
 
 # build tree in object directory if source path is different from current one
 if test "$source_path_used" = "yes" ; then
-    DIRS="tests tests/cris slirp audio block pc-bios/optionrom"
+    DIRS="tests tests/cris slirp audio block net pc-bios/optionrom"
     DIRS="$DIRS roms/pcbios roms/seabios roms/vgabios"
     FILES="Makefile tests/Makefile"
     FILES="$FILES tests/cris/Makefile tests/cris/.gdbinit"
diff --git a/net.h b/net.h
index 7e6cbf4..9ebb978 100644
--- a/net.h
+++ b/net.h
@@ -5,7 +5,7 @@
 #include "qemu-common.h"
 #include "qdict.h"
 #include "qemu-option.h"
-#include "net-queue.h"
+#include "net/queue.h"
 
 /* VLANs support */
 
diff --git a/net-queue.c b/net/queue.c
similarity index 99%
rename from net-queue.c
rename to net/queue.c
index f6b01e9..e91a9a5 100644
--- a/net-queue.c
+++ b/net/queue.c
@@ -21,7 +21,7 @@
  * THE SOFTWARE.
  */
 
-#include "net-queue.h"
+#include "net/queue.h"
 #include "qemu-queue.h"
 
 /* The delivery handler may only return zero if it will call
diff --git a/net-queue.h b/net/queue.h
similarity index 100%
rename from net-queue.h
rename to net/queue.h
-- 
1.6.2.5

^ permalink raw reply related	[flat|nested] 22+ messages in thread

end of thread, other threads:[~2009-10-23 16:54 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-10-22 16:49 [Qemu-devel] [PATCH 00/15] Some networking code re-organization Mark McLoughlin
2009-10-22 16:49 ` [Qemu-devel] [PATCH 01/15] net: move net-queue.[ch] under net/ Mark McLoughlin
2009-10-23 16:52   ` [Qemu-devel] [PATCH 01/15 v2] " Mark McLoughlin
2009-10-22 16:49 ` [Qemu-devel] [PATCH 02/15] net: move net-checksum.c " Mark McLoughlin
2009-10-22 16:49 ` [Qemu-devel] [PATCH 03/15] net: move tap-win32.c " Mark McLoughlin
2009-10-22 16:49 ` [Qemu-devel] [PATCH 04/15] net: move more stuff into net/tap-win32.c, add net/tap.h Mark McLoughlin
2009-10-22 16:49 ` [Qemu-devel] [PATCH 05/15] net: move tap-linux.h under net/ Mark McLoughlin
2009-10-22 16:49 ` [Qemu-devel] [PATCH 06/15] net: split all the tap code out into net/tap.c Mark McLoughlin
2009-10-22 16:49 ` [Qemu-devel] [PATCH 07/15] net: split BSD tap_open() out into net/tap-bsd.c Mark McLoughlin
2009-10-22 16:49 ` [Qemu-devel] [PATCH 08/15] net: move solaris code to net/tap-solaris.c Mark McLoughlin
2009-10-22 16:49 ` [Qemu-devel] [PATCH 09/15] net: move AIX code into net/tap-aix.c Mark McLoughlin
2009-10-22 16:49 ` [Qemu-devel] [PATCH 10/15] build: add CONFIG_LINUX Mark McLoughlin
2009-10-22 16:49 ` [Qemu-devel] [PATCH 11/15] net: move linux code into net/tap-linux.c Mark McLoughlin
2009-10-22 16:49 ` [Qemu-devel] [PATCH 12/15] net: move tap_set_sndbuf() to tap-linux.c Mark McLoughlin
2009-10-22 16:49 ` [Qemu-devel] [PATCH 13/15] net: move tap_probe_vnet_hdr() " Mark McLoughlin
2009-10-22 16:49 ` [Qemu-devel] [PATCH 14/15] net: move tap_set_offload() code into tap-linux.c Mark McLoughlin
2009-10-22 16:49 ` [Qemu-devel] [PATCH 15/15] net: move UFO support detection to tap-linux.c Mark McLoughlin
2009-10-22 20:34 ` [Qemu-devel] [PATCH 00/15] Some networking code re-organization Anthony Liguori
2009-10-23  9:59   ` Mark McLoughlin
2009-10-23 13:44     ` Anthony Liguori
2009-10-23 16:49       ` Mark McLoughlin
     [not found] ` <m37hunntts.fsf@neno.mitica>
2009-10-23 10:00   ` [Qemu-devel] " Mark McLoughlin

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.