Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LwM5D-0006h5-QI for qemu-devel@nongnu.org; Tue, 21 Apr 2009 15:56:43 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LwM5D-0006gi-6w for qemu-devel@nongnu.org; Tue, 21 Apr 2009 15:56:43 -0400 Received: from [199.232.76.173] (port=39677 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LwM5D-0006gb-1Q for qemu-devel@nongnu.org; Tue, 21 Apr 2009 15:56:43 -0400 Received: from savannah.gnu.org ([199.232.41.3]:35690 helo=sv.gnu.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1LwM5C-00028V-Fp for qemu-devel@nongnu.org; Tue, 21 Apr 2009 15:56:42 -0400 Received: from cvs.savannah.gnu.org ([199.232.41.69]) by sv.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1LwM5B-0007wW-KC for qemu-devel@nongnu.org; Tue, 21 Apr 2009 19:56:41 +0000 Received: from aliguori by cvs.savannah.gnu.org with local (Exim 4.69) (envelope-from ) id 1LwM5B-0007wS-C1 for qemu-devel@nongnu.org; Tue, 21 Apr 2009 19:56:41 +0000 MIME-Version: 1.0 Errors-To: aliguori Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Anthony Liguori Message-Id: Date: Tue, 21 Apr 2009 19:56:41 +0000 Subject: [Qemu-devel] [7203] net: Untangle nested qemu_send_packet (Jan Kiszka) List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Revision: 7203 http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=7203 Author: aliguori Date: 2009-04-21 19:56:41 +0000 (Tue, 21 Apr 2009) Log Message: ----------- net: Untangle nested qemu_send_packet (Jan Kiszka) 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 Signed-off-by: Anthony Liguori Modified Paths: -------------- trunk/net.c trunk/net.h Modified: trunk/net.c =================================================================== --- trunk/net.c 2009-04-21 19:56:36 UTC (rev 7202) +++ trunk/net.c 2009-04-21 19:56:41 UTC (rev 7203) @@ -403,22 +403,46 @@ 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; } } Modified: trunk/net.h =================================================================== --- trunk/net.h 2009-04-21 19:56:36 UTC (rev 7202) +++ trunk/net.h 2009-04-21 19:56:41 UTC (rev 7203) @@ -29,11 +29,22 @@ 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);