diff options
author | Zhang Chen <zhangchen.fnst@cn.fujitsu.com> | 2017-03-02 17:54:16 +0800 |
---|---|---|
committer | Jason Wang <jasowang@redhat.com> | 2017-03-06 11:46:02 +0800 |
commit | 2ad7ca4c81733cba5c5c464078a643aba61044f8 (patch) | |
tree | 00d9cb562f16e89140e35c2fc5d65d30e542959c /net/colo-compare.c | |
parent | db0a762e4be965b8976abe9df82c6d47c57336fc (diff) | |
download | qemu-2ad7ca4c81733cba5c5c464078a643aba61044f8.zip qemu-2ad7ca4c81733cba5c5c464078a643aba61044f8.tar.gz qemu-2ad7ca4c81733cba5c5c464078a643aba61044f8.tar.bz2 |
COLO-compare: Rename compare function and remove duplicate codes
Rename colo_packet_compare() to colo_packet_compare_common() that
make tcp_compare udp_compare icmp_compare reuse this function.
Remove minimum packet size check in icmp_compare, because we have
check this in parse_packet_early().
Signed-off-by: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
Diffstat (limited to 'net/colo-compare.c')
-rw-r--r-- | net/colo-compare.c | 18 |
1 files changed, 7 insertions, 11 deletions
diff --git a/net/colo-compare.c b/net/colo-compare.c index 300f017..602a758 100644 --- a/net/colo-compare.c +++ b/net/colo-compare.c @@ -180,7 +180,7 @@ static int packet_enqueue(CompareState *s, int mode) * return: 0 means packet same * > 0 || < 0 means packet different */ -static int colo_packet_compare(Packet *ppkt, Packet *spkt) +static int colo_packet_compare_common(Packet *ppkt, Packet *spkt) { trace_colo_compare_ip_info(ppkt->size, inet_ntoa(ppkt->ip->ip_src), inet_ntoa(ppkt->ip->ip_dst), spkt->size, @@ -190,6 +190,7 @@ static int colo_packet_compare(Packet *ppkt, Packet *spkt) if (ppkt->size == spkt->size) { return memcmp(ppkt->data, spkt->data, spkt->size); } else { + trace_colo_compare_main("Net packet size are not the same"); return -1; } } @@ -205,6 +206,7 @@ static int colo_packet_compare_tcp(Packet *spkt, Packet *ppkt) int res; 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"); @@ -263,7 +265,8 @@ static int colo_packet_compare_udp(Packet *spkt, Packet *ppkt) int ret; trace_colo_compare_main("compare udp"); - ret = colo_packet_compare(ppkt, spkt); + + ret = colo_packet_compare_common(ppkt, spkt); if (ret) { trace_colo_compare_udp_miscompare("primary pkt size", ppkt->size); @@ -281,16 +284,9 @@ static int colo_packet_compare_udp(Packet *spkt, Packet *ppkt) */ static int colo_packet_compare_icmp(Packet *spkt, Packet *ppkt) { - 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)) { + if (colo_packet_compare_common(ppkt, spkt)) { trace_colo_compare_icmp_miscompare("primary pkt size", ppkt->size); qemu_hexdump((char *)ppkt->data, stderr, "colo-compare", @@ -316,7 +312,7 @@ static int colo_packet_compare_other(Packet *spkt, Packet *ppkt) 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); + return colo_packet_compare_common(ppkt, spkt); } static int colo_old_packet_check_one(Packet *pkt, int64_t *check_time) |