From nobody Tue Feb 10 06:08:35 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1513935358630854.9438252988133; Fri, 22 Dec 2017 01:35:58 -0800 (PST) Received: from localhost ([::1]:41818 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eSJkD-0000yq-AW for importer@patchew.org; Fri, 22 Dec 2017 04:35:57 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56309) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eSJig-0000DN-FJ for qemu-devel@nongnu.org; Fri, 22 Dec 2017 04:34:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eSJid-0004HL-QU for qemu-devel@nongnu.org; Fri, 22 Dec 2017 04:34:22 -0500 Received: from mail.cn.fujitsu.com ([183.91.158.132]:57188 helo=heian.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eSJic-0004GR-VM for qemu-devel@nongnu.org; Fri, 22 Dec 2017 04:34:19 -0500 Received: from bogon (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 22 Dec 2017 17:34:17 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (unknown [10.167.33.83]) by cn.fujitsu.com (Postfix) with ESMTP id C5C5A486A791; Fri, 22 Dec 2017 17:34:17 +0800 (CST) Received: from localhost.localdomain (10.167.226.123) by G08CNEXCHPEKD02.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.361.1; Fri, 22 Dec 2017 17:34:16 +0800 X-IronPort-AV: E=Sophos;i="5.43,368,1503331200"; d="scan'208";a="32205960" From: Mao Zhongyi To: Date: Fri, 22 Dec 2017 17:28:55 +0800 Message-ID: <733fdfcb43ac149d8914014cd5eb4416077e3eae.1513933605.git.maozy.fnst@cn.fujitsu.com> X-Mailer: git-send-email 2.9.4 In-Reply-To: References: MIME-Version: 1.0 X-Originating-IP: [10.167.226.123] X-yoursite-MailScanner-ID: C5C5A486A791.A1DAC X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: maozy.fnst@cn.fujitsu.com X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 183.91.158.132 Subject: [Qemu-devel] [PATCH v3 1/2] colo: modified the payload compare function X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jason Wang , Li Zhijian , Zhang Chen Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Modified the function colo_packet_compare_common to prepare for the tcp packet comparison in the next patch. Cc: Zhang Chen Cc: Li Zhijian Cc: Jason Wang Signed-off-by: Mao Zhongyi Signed-off-by: Li Zhijian Signed-off-by: Zhang Chen Reviewed-by: Zhang Chen --- net/colo-compare.c | 88 +++++++++++++++++++++++++++-----------------------= ---- 1 file changed, 44 insertions(+), 44 deletions(-) diff --git a/net/colo-compare.c b/net/colo-compare.c index 0ebdec9..f39ca02 100644 --- a/net/colo-compare.c +++ b/net/colo-compare.c @@ -190,10 +190,12 @@ static int packet_enqueue(CompareState *s, int mode, = Connection **con) * return: 0 means packet same * > 0 || < 0 means packet different */ -static int colo_packet_compare_common(Packet *ppkt, - Packet *spkt, - int poffset, - int soffset) +static int colo_compare_packet_payload(Packet *ppkt, + Packet *spkt, + uint16_t poffset, + uint16_t soffset, + uint16_t len) + { if (trace_event_get_state_backends(TRACE_COLO_COMPARE_MISCOMPARE)) { char pri_ip_src[20], pri_ip_dst[20], sec_ip_src[20], sec_ip_dst[20= ]; @@ -208,17 +210,7 @@ static int colo_packet_compare_common(Packet *ppkt, sec_ip_src, sec_ip_dst); } =20 - poffset =3D ppkt->vnet_hdr_len + poffset; - soffset =3D ppkt->vnet_hdr_len + soffset; - - if (ppkt->size - poffset =3D=3D spkt->size - soffset) { - return memcmp(ppkt->data + poffset, - spkt->data + soffset, - spkt->size - soffset); - } else { - trace_colo_compare_main("Net packet size are not the same"); - return -1; - } + return memcmp(ppkt->data + poffset, spkt->data + soffset, len); } =20 /* @@ -270,24 +262,19 @@ static int colo_packet_compare_tcp(Packet *spkt, Pack= et *ppkt) * the secondary guest's timestamp. COLO just focus on payload, * so we just need skip this field. */ - if (ptcp->th_off > 5) { - ptrdiff_t ptcp_offset, stcp_offset; =20 - ptcp_offset =3D ppkt->transport_header - (uint8_t *)ppkt->data - + (ptcp->th_off * 4) - ppkt->vnet_hdr_len; - stcp_offset =3D spkt->transport_header - (uint8_t *)spkt->data - + (stcp->th_off * 4) - spkt->vnet_hdr_len; + ptrdiff_t ptcp_offset, stcp_offset; =20 - /* - * When network is busy, some tcp options(like sack) will unpredic= table - * occur in primary side or secondary side. it will make packet si= ze - * not same, but the two packet's payload is identical. colo just - * care about packet payload, so we skip the option field. - */ - res =3D colo_packet_compare_common(ppkt, spkt, ptcp_offset, stcp_o= ffset); - } else if (ptcp->th_sum =3D=3D stcp->th_sum) { - res =3D colo_packet_compare_common(ppkt, spkt, ETH_HLEN, ETH_HLEN); + ptcp_offset =3D ppkt->transport_header - (uint8_t *)ppkt->data + + (ptcp->th_off << 2) - ppkt->vnet_hdr_len; + stcp_offset =3D spkt->transport_header - (uint8_t *)spkt->data + + (stcp->th_off << 2) - spkt->vnet_hdr_len; + if (ppkt->size - ptcp_offset =3D=3D spkt->size - stcp_offset) { + res =3D colo_compare_packet_payload(ppkt, spkt, + ptcp_offset, stcp_offset, + ppkt->size - ptcp_offset); } else { + trace_colo_compare_main("TCP: payload size of packets are differen= t"); res =3D -1; } =20 @@ -331,8 +318,8 @@ static int colo_packet_compare_tcp(Packet *spkt, Packet= *ppkt) */ static int colo_packet_compare_udp(Packet *spkt, Packet *ppkt) { - int ret; - int network_header_length =3D ppkt->ip->ip_hl * 4; + uint16_t network_header_length =3D ppkt->ip->ip_hl << 2; + uint16_t offset =3D network_header_length + ETH_HLEN + ppkt->vnet_hdr_= len; =20 trace_colo_compare_main("compare udp"); =20 @@ -346,11 +333,12 @@ static int colo_packet_compare_udp(Packet *spkt, Pack= et *ppkt) * other field like TOS,TTL,IP Checksum. we only need to compare * the ip payload here. */ - ret =3D colo_packet_compare_common(ppkt, spkt, - network_header_length + ETH_HLEN, - network_header_length + ETH_HLEN); - - if (ret) { + if (ppkt->size !=3D spkt->size) { + trace_colo_compare_main("UDP: payload size of packets are differen= t"); + return -1; + } + if (colo_compare_packet_payload(ppkt, spkt, offset, offset, + ppkt->size - offset)) { trace_colo_compare_udp_miscompare("primary pkt size", ppkt->size); trace_colo_compare_udp_miscompare("Secondary pkt size", spkt->size= ); if (trace_event_get_state_backends(TRACE_COLO_COMPARE_MISCOMPARE))= { @@ -359,9 +347,10 @@ static int colo_packet_compare_udp(Packet *spkt, Packe= t *ppkt) qemu_hexdump((char *)spkt->data, stderr, "colo-compare sec pkt= ", spkt->size); } + return -1; + } else { + return 0; } - - return ret; } =20 /* @@ -370,7 +359,8 @@ static int colo_packet_compare_udp(Packet *spkt, Packet= *ppkt) */ static int colo_packet_compare_icmp(Packet *spkt, Packet *ppkt) { - int network_header_length =3D ppkt->ip->ip_hl * 4; + uint16_t network_header_length =3D ppkt->ip->ip_hl << 2; + uint16_t offset =3D network_header_length + ETH_HLEN + ppkt->vnet_hdr_= len; =20 trace_colo_compare_main("compare icmp"); =20 @@ -384,9 +374,12 @@ static int colo_packet_compare_icmp(Packet *spkt, Pack= et *ppkt) * other field like TOS,TTL,IP Checksum. we only need to compare * the ip payload here. */ - if (colo_packet_compare_common(ppkt, spkt, - network_header_length + ETH_HLEN, - network_header_length + ETH_HLEN)) { + if (ppkt->size !=3D spkt->size) { + trace_colo_compare_main("ICMP: payload size of packets are differe= nt"); + return -1; + } + if (colo_compare_packet_payload(ppkt, spkt, offset, offset, + ppkt->size - offset)) { trace_colo_compare_icmp_miscompare("primary pkt size", ppkt->size); trace_colo_compare_icmp_miscompare("Secondary pkt size", @@ -409,6 +402,8 @@ static int colo_packet_compare_icmp(Packet *spkt, Packe= t *ppkt) */ static int colo_packet_compare_other(Packet *spkt, Packet *ppkt) { + uint16_t offset =3D ppkt->vnet_hdr_len; + trace_colo_compare_main("compare other"); if (trace_event_get_state_backends(TRACE_COLO_COMPARE_MISCOMPARE)) { char pri_ip_src[20], pri_ip_dst[20], sec_ip_src[20], sec_ip_dst[20= ]; @@ -423,7 +418,12 @@ static int colo_packet_compare_other(Packet *spkt, Pac= ket *ppkt) sec_ip_src, sec_ip_dst); } =20 - return colo_packet_compare_common(ppkt, spkt, 0, 0); + if (ppkt->size !=3D spkt->size) { + trace_colo_compare_main("Other: payload size of packets are differ= ent"); + return -1; + } + return colo_compare_packet_payload(ppkt, spkt, offset, offset, + ppkt->size - offset); } =20 static int colo_old_packet_check_one(Packet *pkt, int64_t *check_time) --=20 2.9.4