Sophie

Sophie

distrib > Scientific%20Linux > 5x > x86_64 > by-pkgid > 340e01248478ba8b78a6d4d1809b1eff > files > 70

kvm-83-270.el5_11.src.rpm

From 58033f158c24b2eceddfeb759d77b16e38086270 Mon Sep 17 00:00:00 2001
From: Gleb Natapov <gleb@redhat.com>
Date: Tue, 26 May 2009 16:32:05 +0300
Subject: [PATCH 11/14] Add qemu_send_raw() to vlan.

Updated version from upstream.

It gets packet without virtio header and adds it if needed.

Signed-off-by: Gleb Natapov <gleb@redhat.com>
Message-ID: <20090526133205.GV3948@redhat.com>
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
RH-Upstream-status: submitted
Obsoletes: <1243256573-9056-2-git-send-email-gleb@redhat.com>
Acked-by: Mark McLoughlin <markmc@redhat.com>
Acked-by: Dor Laor <dlaor@redhat.com>
Acked-by: Juan Quintela <quintela@redhat.com>
Bugzilla: 503793
---
 qemu/hw/virtio-net.c |   23 +++++++++++++++++++----
 qemu/net.c           |   49 +++++++++++++++++++++++++++++++++++++++++++++++++
 qemu/net.h           |    2 ++
 3 files changed, 70 insertions(+), 4 deletions(-)

diff --git a/qemu/hw/virtio-net.c b/qemu/hw/virtio-net.c
index 07c7f76..a505c83 100644
--- a/qemu/hw/virtio-net.c
+++ b/qemu/hw/virtio-net.c
@@ -210,7 +210,7 @@ static int iov_fill(struct iovec *iov, int iovcnt, const void *buf, int count)
 }
 
 static int receive_header(VirtIONet *n, struct iovec *iov, int iovcnt,
-                          const void *buf, size_t size, size_t hdr_len)
+                          const void *buf, size_t size, size_t hdr_len, int raw)
 {
     struct virtio_net_hdr *hdr = iov[0].iov_base;
     int offset = 0;
@@ -220,7 +220,11 @@ static int receive_header(VirtIONet *n, struct iovec *iov, int iovcnt,
 
 #ifdef TAP_VNET_HDR
     if (tap_has_vnet_hdr(n->vc->vlan->first_client)) {
-        memcpy(hdr, buf, sizeof(*hdr));
+        if (!raw) {
+            memcpy(hdr, buf, sizeof(*hdr));
+        } else {
+            memset(hdr, 0, sizeof(*hdr));
+        }
         offset = sizeof(*hdr);
         work_around_broken_dhclient(hdr, buf + offset, size - offset);
     }
@@ -235,7 +239,7 @@ static int receive_header(VirtIONet *n, struct iovec *iov, int iovcnt,
     return offset;
 }
 
-static void virtio_net_receive(void *opaque, const uint8_t *buf, int size)
+static void virtio_net_receive2(void *opaque, const uint8_t *buf, int size, int raw)
 {
     VirtIONet *n = opaque;
     struct virtio_net_hdr_mrg_rxbuf *mhdr = NULL;
@@ -282,7 +286,7 @@ static void virtio_net_receive(void *opaque, const uint8_t *buf, int size)
                 mhdr = (struct virtio_net_hdr_mrg_rxbuf *)sg[0].iov_base;
 
             offset += receive_header(n, sg, elem.in_num,
-                                     buf + offset, size - offset, hdr_len);
+                                     buf + offset, size - offset, hdr_len, raw);
             total += hdr_len;
         }
 
@@ -304,6 +308,16 @@ static void virtio_net_receive(void *opaque, const uint8_t *buf, int size)
     virtio_notify(&n->vdev, n->rx_vq);
 }
 
+static void virtio_net_receive(void *opaque, const uint8_t *buf, int size)
+{
+    virtio_net_receive2(opaque, buf, size, 0);
+}
+
+static void virtio_net_receive_raw(void *opaque, const uint8_t *buf, int size)
+{
+    virtio_net_receive2(opaque, buf, size, 1);
+}
+
 /* TX */
 static void virtio_net_flush_tx(VirtIONet *n, VirtQueue *vq)
 {
@@ -464,6 +478,7 @@ PCIDevice *virtio_net_init(PCIBus *bus, NICInfo *nd, int devfn)
                                  virtio_net_receive, virtio_net_can_receive, n);
     n->vc->cleanup = virtio_net_cleanup;
     n->vc->link_status_changed = virtio_net_set_link_status;
+    n->vc->fd_read_raw = virtio_net_receive_raw;
 
     qemu_format_nic_info_str(n->vc, n->mac);
 
diff --git a/qemu/net.c b/qemu/net.c
index 76628be..6cc9bc5 100644
--- a/qemu/net.c
+++ b/qemu/net.c
@@ -436,6 +436,31 @@ int qemu_send_packet(VLANClientState *vc1, const uint8_t *buf, int size)
     return ret;
 }
 
+void qemu_send_packet_raw(VLANClientState *sender, const uint8_t *buf, int size)
+{
+    VLANState *vlan = sender->vlan;
+    VLANClientState *vc;
+
+    if (sender->link_down)
+        return;
+
+#ifdef DEBUG_NET
+    printf("vlan %d send raw:\n", vlan->id);
+    hex_dump(stdout, buf, size);
+#endif
+    for(vc = vlan->first_client; vc != NULL; vc = vc->next) {
+        if (vc == sender || vc->link_down) {
+            continue;
+        }
+        if (vc->fd_read_raw) {
+            vc->fd_read_raw(vc->opaque, buf, size);
+        } else {
+            vc->fd_read(vc->opaque, buf, size);
+        }
+    }
+    return;
+}
+
 static ssize_t vc_sendv_compat(VLANClientState *vc, const struct iovec *iov,
                                int iovcnt)
 {
@@ -767,6 +792,29 @@ static void tap_receive(void *opaque, const uint8_t *buf, int size)
     tap_receive_iov(opaque, iov, i);
 }
 
+static void tap_receive_raw(void *opaque, const uint8_t *buf, int size)
+{
+    struct iovec iov[2];
+    int i = 0;
+
+#ifdef IFF_VNET_HDR
+    TAPState *s = opaque;
+    struct virtio_net_hdr hdr = { 0, };
+
+    if (s->has_vnet_hdr && s->using_vnet_hdr) {
+        iov[i].iov_base = &hdr;
+        iov[i].iov_len  = sizeof(hdr);
+        i++;
+    }
+#endif
+
+    iov[i].iov_base = (char *) buf;
+    iov[i].iov_len  = size;
+    i++;
+
+    tap_receive_iov(opaque, iov, i);
+}
+
 static int tap_can_send(void *opaque)
 {
     TAPState *s = opaque;
@@ -942,6 +990,7 @@ static TAPState *net_tap_fd_init(VLANState *vlan,
 #ifdef HAVE_IOVEC
     s->vc->fd_readv = tap_receive_iov;
 #endif
+    s->vc->fd_read_raw = tap_receive_raw;
 #ifdef TUNSETOFFLOAD
     s->vc->set_offload = tap_set_offload;
 #endif
diff --git a/qemu/net.h b/qemu/net.h
index 028878b..f4806c0 100644
--- a/qemu/net.h
+++ b/qemu/net.h
@@ -15,6 +15,7 @@ typedef void (SetOffload)(VLANClientState *, int, int, int, int);
 
 struct VLANClientState {
     IOReadHandler *fd_read;
+    IOReadHandler *fd_read_raw;
     IOReadvHandler *fd_readv;
     /* Packets may still be sent if this returns zero.  It's used to
        rate-limit the slirp code.  */
@@ -51,6 +52,7 @@ int qemu_can_send_packet(VLANClientState *vc);
 ssize_t qemu_sendv_packet(VLANClientState *vc, const struct iovec *iov,
                           int iovcnt);
 int qemu_send_packet(VLANClientState *vc, const uint8_t *buf, int size);
+void qemu_send_packet_raw(VLANClientState *vc, const uint8_t *buf, int size);
 void qemu_format_nic_info_str(VLANClientState *vc, uint8_t macaddr[6]);
 void qemu_check_nic_model(NICInfo *nd, const char *model);
 void qemu_check_nic_model_list(NICInfo *nd, const char * const *models,
-- 
1.6.3.rc4.29.g8146