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>,
"eddie . dong" <eddie.dong@intel.com>,
bian naimeng <biannm@cn.fujitsu.com>,
Li Zhijian <lizhijian@cn.fujitsu.com>
Subject: [Qemu-devel] [PATCH V2 2/6] net/net.c: Add vnet header length to SocketReadState
Date: Thu, 20 Apr 2017 14:39:02 +0800 [thread overview]
Message-ID: <1492670346-18004-3-git-send-email-zhangchen.fnst@cn.fujitsu.com> (raw)
In-Reply-To: <1492670346-18004-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 99b28d5..1204fe5 100644
--- a/include/net/net.h
+++ b/include/net/net.h
@@ -111,9 +111,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 0ac3b9e..d467452 100644
--- a/net/net.c
+++ b/net/net.c
@@ -1621,8 +1621,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) {
@@ -1640,6 +1644,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
next prev parent reply other threads:[~2017-04-20 6:38 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-04-20 6:39 [Qemu-devel] [PATCH V2 0/6] Add COLO-proxy virtio-net support Zhang Chen
2017-04-20 6:39 ` [Qemu-devel] [PATCH V2 1/6] net/filter-mirror.c: Add filter-mirror and filter-redirector vnet support Zhang Chen
2017-04-20 6:39 ` Zhang Chen [this message]
2017-04-20 6:39 ` [Qemu-devel] [PATCH V2 3/6] net/colo-compare.c: Make colo-compare support vnet_hdr_len Zhang Chen
2017-04-20 6:39 ` [Qemu-devel] [PATCH V2 4/6] net/socket.c: Add vnet packet support in net_socket_receive() Zhang Chen
2017-04-20 6:39 ` [Qemu-devel] [PATCH V2 5/6] net/colo.c: Add vnet packet parse feature in colo-proxy Zhang Chen
2017-04-20 6:39 ` [Qemu-devel] [PATCH V2 6/6] net/colo-compare.c: Add vnet packet's tcp/udp/icmp compare Zhang Chen
2017-04-24 3:48 ` [Qemu-devel] [PATCH V2 0/6] Add COLO-proxy virtio-net support Jason Wang
2017-04-24 6:42 ` Zhang Chen
2017-04-24 12:02 ` Zhang Chen
2017-04-25 3:54 ` Jason Wang
2017-04-25 6:17 ` 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=1492670346-18004-3-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=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 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).