All of lore.kernel.org
 help / color / mirror / Atom feed
From: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
To: qemu devel <qemu-devel@nongnu.org>, Jason Wang <jasowang@redhat.com>
Cc: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>,
	zhanghailiang <zhang.zhanghailiang@huawei.com>,
	weifuqiang <weifuqiang@huawei.com>,
	"eddie . dong" <eddie.dong@intel.com>,
	bian naimeng <biannm@cn.fujitsu.com>,
	Li Zhijian <lizhijian@cn.fujitsu.com>
Subject: [Qemu-devel] [PATCH V3 05/10] net/net.c: Add vnet header length to SocketReadState
Date: Fri, 28 Apr 2017 17:47:15 +0800	[thread overview]
Message-ID: <1493372840-24551-6-git-send-email-zhangchen.fnst@cn.fujitsu.com> (raw)
In-Reply-To: <1493372840-24551-1-git-send-email-zhangchen.fnst@cn.fujitsu.com>

Address Jason Wang's comments add vnet header length to SocketReadState.
So we change net_fill_rstate() to read
struct  {int size; int vnet_hdr_len; const uint8_t buf[];}.

Signed-off-by: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
---
 include/net/net.h |  4 +++-
 net/net.c         | 24 ++++++++++++++++++++++--
 2 files changed, 25 insertions(+), 3 deletions(-)

diff --git a/include/net/net.h b/include/net/net.h
index 402d913..865cb98 100644
--- a/include/net/net.h
+++ b/include/net/net.h
@@ -115,9 +115,11 @@ typedef struct NICState {
 } NICState;
 
 struct SocketReadState {
-    int state; /* 0 = getting length, 1 = getting data */
+    /* 0 = getting length, 1 = getting vnet header length, 2 = getting data */
+    int state;
     uint32_t index;
     uint32_t packet_len;
+    uint32_t vnet_hdr_len;
     uint8_t buf[NET_BUFSIZE];
     SocketReadStateFinalize *finalize;
 };
diff --git a/net/net.c b/net/net.c
index f69260f..5a6b5ac 100644
--- a/net/net.c
+++ b/net/net.c
@@ -1639,8 +1639,12 @@ int net_fill_rstate(SocketReadState *rs, const uint8_t *buf, int size)
     unsigned int l;
 
     while (size > 0) {
-        /* reassemble a packet from the network */
-        switch (rs->state) { /* 0 = getting length, 1 = getting data */
+        /* Reassemble a packet from the network.
+         * 0 = getting length.
+         * 1 = getting vnet header length.
+         * 2 = getting data.
+         */
+        switch (rs->state) {
         case 0:
             l = 4 - rs->index;
             if (l > size) {
@@ -1658,6 +1662,22 @@ int net_fill_rstate(SocketReadState *rs, const uint8_t *buf, int size)
             }
             break;
         case 1:
+            l = 4 - rs->index;
+            if (l > size) {
+                l = size;
+            }
+            memcpy(rs->buf + rs->index, buf, l);
+            buf += l;
+            size -= l;
+            rs->index += l;
+            if (rs->index == 4) {
+                /* got vnet header length */
+                rs->vnet_hdr_len = ntohl(*(uint32_t *)rs->buf);
+                rs->index = 0;
+                rs->state = 2;
+            }
+            break;
+        case 2:
             l = rs->packet_len - rs->index;
             if (l > size) {
                 l = size;
-- 
2.7.4

  parent reply	other threads:[~2017-04-28  9:47 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-28  9:47 [Qemu-devel] [PATCH V3 00/10] Add COLO-proxy virtio-net support Zhang Chen
2017-04-28  9:47 ` [Qemu-devel] [PATCH V3 01/10] net: Add vnet_hdr_len related callback in NetClientInfo Zhang Chen
2017-05-02  5:46   ` Jason Wang
2017-05-03  3:08     ` Zhang Chen
2017-04-28  9:47 ` [Qemu-devel] [PATCH V3 02/10] net/tap.c: Add tap_get_vnet_hdr_len and tap_get_using_vnet_hdr function Zhang Chen
2017-04-28  9:47 ` [Qemu-devel] [PATCH V3 03/10] net/netmap.c: Add netmap_get_vnet_hdr_len function Zhang Chen
2017-04-28  9:47 ` [Qemu-devel] [PATCH V3 04/10] net/filter-mirror.c: Add filter-mirror and filter-redirector vnet support Zhang Chen
2017-05-02  5:47   ` Jason Wang
2017-05-03  3:18     ` Zhang Chen
2017-05-03 10:19       ` Jason Wang
2017-05-05  8:44         ` Zhang Chen
2017-05-05  9:25           ` Jason Wang
2017-05-05  9:43             ` Zhang Chen
2017-04-28  9:47 ` Zhang Chen [this message]
2017-05-02  5:53   ` [Qemu-devel] [PATCH V3 05/10] net/net.c: Add vnet header length to SocketReadState Jason Wang
2017-05-03  3:43     ` Zhang Chen
2017-05-03 10:42       ` Jason Wang
2017-05-08  3:47         ` Zhang Chen
2017-05-09  2:40           ` Jason Wang
2017-05-09  4:03             ` Zhang Chen
2017-05-09  5:36               ` Jason Wang
2017-05-09  6:59                 ` Zhang Chen
2017-05-09  7:36                   ` Jason Wang
2017-04-28  9:47 ` [Qemu-devel] [PATCH V3 06/10] tests/e1000e-test.c : change e1000e test case send data format Zhang Chen
2017-04-28  9:47 ` [Qemu-devel] [PATCH V3 07/10] tests/virtio-net-test.c : change virtio-net test case iov " Zhang Chen
2017-04-28  9:47 ` [Qemu-devel] [PATCH V3 08/10] net/colo-compare.c: Make colo-compare support vnet_hdr_len Zhang Chen
2017-04-28  9:47 ` [Qemu-devel] [PATCH V3 09/10] net/colo.c: Add vnet packet parse feature in colo-proxy Zhang Chen
2017-04-28  9:47 ` [Qemu-devel] [PATCH V3 10/10] net/colo-compare.c: Add vnet packet's tcp/udp/icmp compare Zhang Chen

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=1493372840-24551-6-git-send-email-zhangchen.fnst@cn.fujitsu.com \
    --to=zhangchen.fnst@cn.fujitsu.com \
    --cc=biannm@cn.fujitsu.com \
    --cc=eddie.dong@intel.com \
    --cc=jasowang@redhat.com \
    --cc=lizhijian@cn.fujitsu.com \
    --cc=qemu-devel@nongnu.org \
    --cc=weifuqiang@huawei.com \
    --cc=zhang.zhanghailiang@huawei.com \
    /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 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.