From: Jan Kiszka <jan.kiszka@siemens.com>
To: qemu-devel@nongnu.org
Cc: Mark McLoughlin <markmc@redhat.com>
Subject: [Qemu-devel] [PATCH v2 08/11] net: Untangle nested qemu_send_packet
Date: Sun, 19 Apr 2009 12:04:26 +0200	[thread overview]
Message-ID: <20090419100426.24240.70663.stgit@mchn012c.ww002.siemens.net> (raw)
In-Reply-To: <20090419100424.24240.51439.stgit@mchn012c.ww002.siemens.net>
Queue packets that are send during an ongoing packet delivery. This
ensures that packets will always arrive in their logical order at each
client of a VLAN. Currently, slirp generates such immediate relies, and
e.g. packet-sniffing clients on the same VLAN may get confused.
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
 net.c |   36 ++++++++++++++++++++++++++++++------
 net.h |   11 +++++++++++
 2 files changed, 41 insertions(+), 6 deletions(-)
diff --git a/net.c b/net.c
index 1ee7504..5156cc1 100644
--- a/net.c
+++ b/net.c
@@ -402,22 +402,46 @@ int qemu_can_send_packet(VLANClientState *vc1)
     return 0;
 }
 
-void qemu_send_packet(VLANClientState *vc1, const uint8_t *buf, int size)
+static void
+qemu_deliver_packet(VLANClientState *sender, const uint8_t *buf, int size)
 {
-    VLANState *vlan = vc1->vlan;
     VLANClientState *vc;
 
-    if (vc1->link_down)
+    for (vc = sender->vlan->first_client; vc != NULL; vc = vc->next) {
+        if (vc != sender && !vc->link_down) {
+            vc->fd_read(vc->opaque, buf, size);
+        }
+    }
+}
+
+void qemu_send_packet(VLANClientState *vc, const uint8_t *buf, int size)
+{
+    VLANState *vlan = vc->vlan;
+    VLANPacket *packet;
+
+    if (vc->link_down)
         return;
 
 #ifdef DEBUG_NET
     printf("vlan %d send:\n", vlan->id);
     hex_dump(stdout, buf, size);
 #endif
-    for(vc = vlan->first_client; vc != NULL; vc = vc->next) {
-        if (vc != vc1 && !vc->link_down) {
-            vc->fd_read(vc->opaque, buf, size);
+    if (vlan->delivering) {
+        packet = qemu_malloc(sizeof(VLANPacket) + size);
+        packet->next = vlan->send_queue;
+        packet->sender = vc;
+        packet->size = size;
+        memcpy(packet->data, buf, size);
+        vlan->send_queue = packet;
+    } else {
+        vlan->delivering = 1;
+        qemu_deliver_packet(vc, buf, size);
+        while ((packet = vlan->send_queue) != NULL) {
+            qemu_deliver_packet(packet->sender, packet->data, packet->size);
+            vlan->send_queue = packet->next;
+            qemu_free(packet);
         }
+        vlan->delivering = 0;
     }
 }
 
diff --git a/net.h b/net.h
index 413f705..fe5ece7 100644
--- a/net.h
+++ b/net.h
@@ -29,11 +29,22 @@ struct VLANClientState {
     char info_str[256];
 };
 
+typedef struct VLANPacket VLANPacket;
+
+struct VLANPacket {
+    struct VLANPacket *next;
+    VLANClientState *sender;
+    int size;
+    uint8_t data[0];
+};
+
 struct VLANState {
     int id;
     VLANClientState *first_client;
     struct VLANState *next;
     unsigned int nb_guest_devs, nb_host_devs;
+    VLANPacket *send_queue;
+    int delivering;
 };
 
 VLANState *qemu_find_vlan(int id);
next prev parent reply	other threads:[~2009-04-19 10:36 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-04-19 10:04 [Qemu-devel] [PATCH v2 00/11] Various small networking improvements Jan Kiszka
2009-04-19 10:04 ` [Qemu-devel] [PATCH v2 03/11] net: Prevent multiple slirp instances Jan Kiszka
2009-04-19 10:37   ` Blue Swirl
2009-04-19 11:51     ` [Qemu-devel] " Jan Kiszka
2009-04-19 10:04 ` [Qemu-devel] [PATCH v2 01/11] net: Fix -net socket,listen Jan Kiszka
2009-04-19 10:04 ` [Qemu-devel] [PATCH v2 06/11] Allow empty params for check_params Jan Kiszka
2009-04-19 10:04 ` [Qemu-devel] [PATCH v2 02/11] net: Check device passed to host_net_remove Jan Kiszka
2009-04-19 10:04 ` [Qemu-devel] [PATCH v2 05/11] monitor: Allow host_net_add/remove for all targets Jan Kiszka
2009-04-19 10:04 ` [Qemu-devel] [PATCH v2 04/11] monitor: Improve host_net_add Jan Kiszka
2009-04-28 15:08   ` Krumme, Chris
2009-04-28 19:25     ` [Qemu-devel] [PATCH] net: Avoid gcc'ism in net_host_device_add Jan Kiszka
2009-04-19 10:04 ` [Qemu-devel] [PATCH v2 07/11] net: Add parameter checks for VLAN clients Jan Kiszka
2009-04-19 10:04 ` Jan Kiszka [this message]
2009-04-19 10:04 ` [Qemu-devel] [PATCH v2 10/11] slirp: Handle DHCP requests for specific IP Jan Kiszka
2009-04-19 10:04 ` [Qemu-devel] [PATCH v2 11/11] slirp: Enhance host-guest redirection setup Jan Kiszka
2009-04-19 10:04 ` [Qemu-devel] [PATCH v2 09/11] net: Add support for capturing VLANs Jan Kiszka
2009-04-21 20:55 ` [Qemu-devel] [PATCH v2 00/11] Various small networking improvements Anthony Liguori
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox
  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):
  git send-email \
    --in-reply-to=20090419100426.24240.70663.stgit@mchn012c.ww002.siemens.net \
    --to=jan.kiszka@siemens.com \
    --cc=markmc@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY
  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
  Be sure your reply has a Subject: header at the top and a blank line
  before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).