From: Jason Wang <jasowang@redhat.com>
To: peter.maydell@linaro.org
Cc: qemu-devel@nongnu.org, Zhang Chen <zhangchen.fnst@cn.fujitsu.com>,
Li Zhijian <lizhijian@cn.fujitsu.com>,
Wen Congyang <wency@cn.fujitsu.com>,
Jason Wang <jasowang@redhat.com>
Subject: [Qemu-devel] [PULL 09/27] colo-compare: add TCP, UDP, ICMP packet comparison
Date: Mon, 26 Sep 2016 16:59:17 +0800 [thread overview]
Message-ID: <1474880375-22946-10-git-send-email-jasowang@redhat.com> (raw)
In-Reply-To: <1474880375-22946-1-git-send-email-jasowang@redhat.com>
From: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
We add TCP,UDP,ICMP packet comparison to replace
IP packet comparison. This can increase the
accuracy of the package comparison.
Less checkpoint more efficiency.
Signed-off-by: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
Signed-off-by: Li Zhijian <lizhijian@cn.fujitsu.com>
Signed-off-by: Wen Congyang <wency@cn.fujitsu.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
---
net/colo-compare.c | 147 +++++++++++++++++++++++++++++++++++++++++++++++++++--
trace-events | 3 ++
2 files changed, 146 insertions(+), 4 deletions(-)
diff --git a/net/colo-compare.c b/net/colo-compare.c
index 645126e..3328515 100644
--- a/net/colo-compare.c
+++ b/net/colo-compare.c
@@ -19,6 +19,7 @@
#include "qapi/qmp/qerror.h"
#include "qapi/error.h"
#include "net/net.h"
+#include "net/eth.h"
#include "qom/object_interfaces.h"
#include "qemu/iov.h"
#include "qom/object.h"
@@ -178,9 +179,131 @@ static int colo_packet_compare(Packet *ppkt, Packet *spkt)
}
}
-static int colo_packet_compare_all(Packet *spkt, Packet *ppkt)
+/*
+ * Called from the compare thread on the primary
+ * for compare tcp packet
+ * compare_tcp copied from Dr. David Alan Gilbert's branch
+ */
+static int colo_packet_compare_tcp(Packet *spkt, Packet *ppkt)
+{
+ struct tcphdr *ptcp, *stcp;
+ int res;
+ char *sdebug, *ddebug;
+
+ trace_colo_compare_main("compare tcp");
+ if (ppkt->size != spkt->size) {
+ if (trace_event_get_state(TRACE_COLO_COMPARE_MISCOMPARE)) {
+ trace_colo_compare_main("pkt size not same");
+ }
+ return -1;
+ }
+
+ ptcp = (struct tcphdr *)ppkt->transport_header;
+ stcp = (struct tcphdr *)spkt->transport_header;
+
+ /*
+ * The 'identification' field in the IP header is *very* random
+ * it almost never matches. Fudge this by ignoring differences in
+ * unfragmented packets; they'll normally sort themselves out if different
+ * anyway, and it should recover at the TCP level.
+ * An alternative would be to get both the primary and secondary to rewrite
+ * somehow; but that would need some sync traffic to sync the state
+ */
+ if (ntohs(ppkt->ip->ip_off) & IP_DF) {
+ spkt->ip->ip_id = ppkt->ip->ip_id;
+ /* and the sum will be different if the IDs were different */
+ spkt->ip->ip_sum = ppkt->ip->ip_sum;
+ }
+
+ res = memcmp(ppkt->data + ETH_HLEN, spkt->data + ETH_HLEN,
+ (spkt->size - ETH_HLEN));
+
+ if (res != 0 && trace_event_get_state(TRACE_COLO_COMPARE_MISCOMPARE)) {
+ sdebug = strdup(inet_ntoa(ppkt->ip->ip_src));
+ ddebug = strdup(inet_ntoa(ppkt->ip->ip_dst));
+ fprintf(stderr, "%s: src/dst: %s/%s p: seq/ack=%u/%u"
+ " s: seq/ack=%u/%u res=%d flags=%x/%x\n",
+ __func__, sdebug, ddebug,
+ (unsigned int)ntohl(ptcp->th_seq),
+ (unsigned int)ntohl(ptcp->th_ack),
+ (unsigned int)ntohl(stcp->th_seq),
+ (unsigned int)ntohl(stcp->th_ack),
+ res, ptcp->th_flags, stcp->th_flags);
+
+ fprintf(stderr, "Primary len = %d\n", ppkt->size);
+ qemu_hexdump((char *)ppkt->data, stderr, "colo-compare", ppkt->size);
+ fprintf(stderr, "Secondary len = %d\n", spkt->size);
+ qemu_hexdump((char *)spkt->data, stderr, "colo-compare", spkt->size);
+
+ g_free(sdebug);
+ g_free(ddebug);
+ }
+
+ return res;
+}
+
+/*
+ * Called from the compare thread on the primary
+ * for compare udp packet
+ */
+static int colo_packet_compare_udp(Packet *spkt, Packet *ppkt)
+{
+ int ret;
+
+ trace_colo_compare_main("compare udp");
+ ret = colo_packet_compare(ppkt, spkt);
+
+ if (ret) {
+ trace_colo_compare_udp_miscompare("primary pkt size", ppkt->size);
+ qemu_hexdump((char *)ppkt->data, stderr, "colo-compare", ppkt->size);
+ trace_colo_compare_udp_miscompare("Secondary pkt size", spkt->size);
+ qemu_hexdump((char *)spkt->data, stderr, "colo-compare", spkt->size);
+ }
+
+ return ret;
+}
+
+/*
+ * Called from the compare thread on the primary
+ * for compare icmp packet
+ */
+static int colo_packet_compare_icmp(Packet *spkt, Packet *ppkt)
{
- trace_colo_compare_main("compare all");
+ int network_length;
+
+ trace_colo_compare_main("compare icmp");
+ network_length = ppkt->ip->ip_hl * 4;
+ if (ppkt->size != spkt->size ||
+ ppkt->size < network_length + ETH_HLEN) {
+ return -1;
+ }
+
+ if (colo_packet_compare(ppkt, spkt)) {
+ trace_colo_compare_icmp_miscompare("primary pkt size",
+ ppkt->size);
+ qemu_hexdump((char *)ppkt->data, stderr, "colo-compare",
+ ppkt->size);
+ trace_colo_compare_icmp_miscompare("Secondary pkt size",
+ spkt->size);
+ qemu_hexdump((char *)spkt->data, stderr, "colo-compare",
+ spkt->size);
+ return -1;
+ } else {
+ return 0;
+ }
+}
+
+/*
+ * Called from the compare thread on the primary
+ * for compare other packet
+ */
+static int colo_packet_compare_other(Packet *spkt, Packet *ppkt)
+{
+ trace_colo_compare_main("compare other");
+ trace_colo_compare_ip_info(ppkt->size, inet_ntoa(ppkt->ip->ip_src),
+ inet_ntoa(ppkt->ip->ip_dst), spkt->size,
+ inet_ntoa(spkt->ip->ip_src),
+ inet_ntoa(spkt->ip->ip_dst));
return colo_packet_compare(ppkt, spkt);
}
@@ -242,8 +365,24 @@ static void colo_compare_connection(void *opaque, void *user_data)
qemu_mutex_lock(&s->timer_check_lock);
pkt = g_queue_pop_tail(&conn->primary_list);
qemu_mutex_unlock(&s->timer_check_lock);
- result = g_queue_find_custom(&conn->secondary_list,
- pkt, (GCompareFunc)colo_packet_compare_all);
+ switch (conn->ip_proto) {
+ case IPPROTO_TCP:
+ result = g_queue_find_custom(&conn->secondary_list,
+ pkt, (GCompareFunc)colo_packet_compare_tcp);
+ break;
+ case IPPROTO_UDP:
+ result = g_queue_find_custom(&conn->secondary_list,
+ pkt, (GCompareFunc)colo_packet_compare_udp);
+ break;
+ case IPPROTO_ICMP:
+ result = g_queue_find_custom(&conn->secondary_list,
+ pkt, (GCompareFunc)colo_packet_compare_icmp);
+ break;
+ default:
+ result = g_queue_find_custom(&conn->secondary_list,
+ pkt, (GCompareFunc)colo_packet_compare_other);
+ break;
+ }
if (result) {
ret = compare_chr_send(s->chr_out, pkt->data, pkt->size);
diff --git a/trace-events b/trace-events
index 81de82c..b395368 100644
--- a/trace-events
+++ b/trace-events
@@ -144,8 +144,11 @@ colo_proxy_main(const char *chr) ": %s"
# net/colo-compare.c
colo_compare_main(const char *chr) ": %s"
+colo_compare_udp_miscompare(const char *sta, int size) ": %s = %d"
+colo_compare_icmp_miscompare(const char *sta, int size) ": %s = %d"
colo_compare_ip_info(int psize, const char *sta, const char *stb, int ssize, const char *stc, const char *std) "ppkt size = %d, ip_src = %s, ip_dst = %s, spkt size = %d, ip_src = %s, ip_dst = %s"
colo_old_packet_check_found(int64_t old_time) "%" PRId64
+colo_compare_miscompare(void) ""
### Guest events, keep at bottom
--
2.7.4
next prev parent reply other threads:[~2016-09-26 9:00 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-26 8:59 [Qemu-devel] [PULL 00/27] Net patches Jason Wang
2016-09-26 8:59 ` [Qemu-devel] [PULL 01/27] virtio-net: allow increasing rx queue size Jason Wang
2016-09-26 8:59 ` [Qemu-devel] [PULL 02/27] net: hmp_host_net_remove: Del the -net option of the removed host_net Jason Wang
2016-09-26 8:59 ` [Qemu-devel] [PULL 03/27] qemu-char: Add qemu_chr_add_handlers_full() for GMaincontext Jason Wang
2016-09-26 8:59 ` [Qemu-devel] [PULL 04/27] colo-compare: introduce colo compare initialization Jason Wang
2016-09-26 8:59 ` [Qemu-devel] [PULL 05/27] net/colo.c: add colo.c to define and handle packet Jason Wang
2016-09-26 8:59 ` [Qemu-devel] [PULL 06/27] Jhash: add linux kernel jhashtable in qemu Jason Wang
2016-09-26 8:59 ` [Qemu-devel] [PULL 07/27] colo-compare: track connection and enqueue packet Jason Wang
2016-09-26 8:59 ` [Qemu-devel] [PULL 08/27] colo-compare: introduce packet comparison thread Jason Wang
2016-09-26 8:59 ` Jason Wang [this message]
2016-09-26 8:59 ` [Qemu-devel] [PULL 10/27] filter-rewriter: introduce filter-rewriter initialization Jason Wang
2016-09-26 8:59 ` [Qemu-devel] [PULL 11/27] filter-rewriter: track connection and parse packet Jason Wang
2016-09-26 8:59 ` [Qemu-devel] [PULL 12/27] filter-rewriter: rewrite tcp packet to keep secondary connection Jason Wang
2016-09-26 8:59 ` [Qemu-devel] [PULL 13/27] MAINTAINERS: add maintainer for COLO-proxy Jason Wang
2016-09-26 8:59 ` [Qemu-devel] [PULL 14/27] docs: Add documentation " Jason Wang
2016-09-26 8:59 ` [Qemu-devel] [PULL 15/27] e1000: fix buliding complaint Jason Wang
2016-09-26 8:59 ` [Qemu-devel] [PULL 16/27] tap: Allow specifying a bridge Jason Wang
2016-09-26 8:59 ` [Qemu-devel] [PULL 17/27] net: limit allocation in nc_sendv_compat Jason Wang
2016-09-26 8:59 ` [Qemu-devel] [PULL 18/27] e1000e: Flush all receive queues on receive enable Jason Wang
2016-09-26 8:59 ` [Qemu-devel] [PULL 19/27] e1000e: Flush receive queues on link up Jason Wang
2016-09-26 8:59 ` [Qemu-devel] [PULL 20/27] e1000e: Fix CTRL_EXT.EIAME behavior Jason Wang
2016-09-26 8:59 ` [Qemu-devel] [PULL 21/27] e1000e: Fix PBACLR implementation Jason Wang
2016-09-26 8:59 ` [Qemu-devel] [PULL 22/27] e1000e: Fix OTHER interrupts processing for MSI-X Jason Wang
2016-09-26 8:59 ` [Qemu-devel] [PULL 23/27] e1000e: Fix spurious RX TCP ACK interrupts Jason Wang
2016-09-26 8:59 ` [Qemu-devel] [PULL 24/27] e1000e: Fix EIAC register implementation Jason Wang
2016-09-26 8:59 ` [Qemu-devel] [PULL 25/27] net: mcf: limit buffer descriptor count Jason Wang
2016-09-26 8:59 ` [Qemu-devel] [PULL 26/27] mcf_fec: fix error in qemu_send_packet argument Jason Wang
2016-09-26 8:59 ` [Qemu-devel] [PULL 27/27] imx_fec: " Jason Wang
2016-09-26 21:04 ` [Qemu-devel] [PULL 00/27] Net patches Peter Maydell
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=1474880375-22946-10-git-send-email-jasowang@redhat.com \
--to=jasowang@redhat.com \
--cc=lizhijian@cn.fujitsu.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=wency@cn.fujitsu.com \
--cc=zhangchen.fnst@cn.fujitsu.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).