qemu-devel.nongnu.org archive mirror
 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>,
	"eddie . dong" <eddie.dong@intel.com>,
	bian naimeng <biannm@cn.fujitsu.com>,
	Li Zhijian <lizhijian@cn.fujitsu.com>
Subject: [Qemu-devel] [PATCH 1/3] COLO-proxy: Add virtio-net packet parse function
Date: Thu, 16 Mar 2017 17:52:06 +0800	[thread overview]
Message-ID: <1489657928-14919-2-git-send-email-zhangchen.fnst@cn.fujitsu.com> (raw)
In-Reply-To: <1489657928-14919-1-git-send-email-zhangchen.fnst@cn.fujitsu.com>

Change parse_packet_early(Packet *pkt) to parse_packet_early(Packet *pkt, int offset)
that we can skip virtio-net header.

Signed-off-by: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
---
 net/colo-compare.c    | 11 +++++++----
 net/colo.c            |  8 ++++----
 net/colo.h            |  5 ++++-
 net/filter-rewriter.c | 15 ++++++++++-----
 4 files changed, 25 insertions(+), 14 deletions(-)

diff --git a/net/colo-compare.c b/net/colo-compare.c
index 54e6d40..ce0cd12 100644
--- a/net/colo-compare.c
+++ b/net/colo-compare.c
@@ -126,10 +126,13 @@ static int packet_enqueue(CompareState *s, int mode)
         pkt = packet_new(s->sec_rs.buf, s->sec_rs.packet_len);
     }
 
-    if (parse_packet_early(pkt)) {
-        packet_destroy(pkt, NULL);
-        pkt = NULL;
-        return -1;
+    /* Try to parse the virtio-net-pci packet */
+    if (parse_packet_early(pkt, VIRTIO_NET_HEADER)) {
+        if (parse_packet_early(pkt, 0)) {
+            packet_destroy(pkt, NULL);
+            pkt = NULL;
+            return -1;
+        }
     }
     fill_connection_key(pkt, &key);
 
diff --git a/net/colo.c b/net/colo.c
index 8cc166b..060e822 100644
--- a/net/colo.c
+++ b/net/colo.c
@@ -39,15 +39,15 @@ int connection_key_equal(const void *key1, const void *key2)
     return memcmp(key1, key2, sizeof(ConnectionKey)) == 0;
 }
 
-int parse_packet_early(Packet *pkt)
+int parse_packet_early(Packet *pkt, int offset)
 {
     int network_length;
     static const uint8_t vlan[] = {0x81, 0x00};
-    uint8_t *data = pkt->data;
+    uint8_t *data = pkt->data + offset;
     uint16_t l3_proto;
     ssize_t l2hdr_len = eth_get_l2_hdr_length(data);
 
-    if (pkt->size < ETH_HLEN) {
+    if (pkt->size < ETH_HLEN + offset) {
         trace_colo_proxy_main("pkt->size < ETH_HLEN");
         return 1;
     }
@@ -73,7 +73,7 @@ int parse_packet_early(Packet *pkt)
     }
 
     network_length = pkt->ip->ip_hl * 4;
-    if (pkt->size < l2hdr_len + network_length) {
+    if (pkt->size < l2hdr_len + network_length + offset) {
         trace_colo_proxy_main("pkt->size < network_header + network_length");
         return 1;
     }
diff --git a/net/colo.h b/net/colo.h
index 7c524f3..b713f87 100644
--- a/net/colo.h
+++ b/net/colo.h
@@ -33,6 +33,9 @@
 #define IPPROTO_UDPLITE 136
 #endif
 
+/* virtio-net header length */
+#define VIRTIO_NET_HEADER 12
+
 typedef struct Packet {
     void *data;
     union {
@@ -73,7 +76,7 @@ typedef struct Connection {
 
 uint32_t connection_key_hash(const void *opaque);
 int connection_key_equal(const void *opaque1, const void *opaque2);
-int parse_packet_early(Packet *pkt);
+int parse_packet_early(Packet *pkt, int offset);
 void fill_connection_key(Packet *pkt, ConnectionKey *key);
 void reverse_connection_key(ConnectionKey *key);
 Connection *connection_new(ConnectionKey *key);
diff --git a/net/filter-rewriter.c b/net/filter-rewriter.c
index afa06e8..c3f0261 100644
--- a/net/filter-rewriter.c
+++ b/net/filter-rewriter.c
@@ -51,12 +51,17 @@ static void filter_rewriter_flush(NetFilterState *nf)
  */
 static int is_tcp_packet(Packet *pkt)
 {
-    if (!parse_packet_early(pkt) &&
-        pkt->ip->ip_p == IPPROTO_TCP) {
-        return 1;
-    } else {
-        return 0;
+    if (!parse_packet_early(pkt, VIRTIO_NET_HEADER) ||
+        !parse_packet_early(pkt, 0)) {
+        if (pkt->ip->ip_p == IPPROTO_TCP) {
+            return 1;
+        } else {
+            goto out;
+        }
     }
+
+out:
+    return 0;
 }
 
 /* handle tcp packet from primary guest */
-- 
2.7.4

  reply	other threads:[~2017-03-16  9:53 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-16  9:52 [Qemu-devel] [PATCH 0/3] Add COLO-proxy virtio-net support Zhang Chen
2017-03-16  9:52 ` Zhang Chen [this message]
2017-03-16  9:52 ` [Qemu-devel] [PATCH 2/3] COLO-proxy: Add a tag to mark virtio-net packet Zhang Chen
2017-03-16  9:52 ` [Qemu-devel] [PATCH 3/3] COLO-compare: Add virtio-net packet compare support Zhang Chen
2017-03-21  3:39 ` [Qemu-devel] [PATCH 0/3] Add COLO-proxy virtio-net support Jason Wang
2017-03-21  5:47   ` Zhang Chen
2017-03-21  6:10     ` Jason Wang
2017-03-21  6:16       ` Zhang Chen
2017-03-21  6:30         ` Jason Wang
2017-03-21  7:08           ` Zhang Chen
2017-03-21  9:15             ` Jason Wang
2017-03-22  1:50               ` Zhang Chen
2017-03-22  3:13                 ` Jason Wang
2017-03-22  3:37                   ` 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=1489657928-14919-2-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).