From nobody Wed Apr 16 03:54:05 2025 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 1504836950025390.41276711822354; Thu, 7 Sep 2017 19:15:50 -0700 (PDT) Received: from localhost ([::1]:42988 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dq8ph-0003V7-1R for importer@patchew.org; Thu, 07 Sep 2017 22:15:49 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:32840) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dq8gj-0003em-Tc for qemu-devel@nongnu.org; Thu, 07 Sep 2017 22:06:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dq8ge-0002VI-UU for qemu-devel@nongnu.org; Thu, 07 Sep 2017 22:06:33 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37100) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dq8ge-0002UY-Mf for qemu-devel@nongnu.org; Thu, 07 Sep 2017 22:06:28 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C8937356D9; Fri, 8 Sep 2017 02:06:27 +0000 (UTC) Received: from jason-ThinkPad-T450s.redhat.com (ovpn-12-98.pek2.redhat.com [10.72.12.98]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4D6BA600C2; Fri, 8 Sep 2017 02:06:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com C8937356D9 Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=jasowang@redhat.com From: Jason Wang To: peter.maydell@linaro.org, qemu-devel@nongnu.org Date: Fri, 8 Sep 2017 10:05:19 +0800 Message-Id: <1504836324-4871-14-git-send-email-jasowang@redhat.com> In-Reply-To: <1504836324-4871-1-git-send-email-jasowang@redhat.com> References: <1504836324-4871-1-git-send-email-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 08 Sep 2017 02:06:27 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 13/18] net/colo-compare.c: Optimize unpredictable tcp options comparison 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 , 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 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Zhang Chen When network is busy, some tcp options(like sack) will unpredictable occur in primary side or secondary side. it will make packet size not same, but the two packet's payload is identical. colo just care about packet payload, so we skip the option field. Signed-off-by: Zhang Chen Signed-off-by: Jason Wang --- net/colo-compare.c | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/net/colo-compare.c b/net/colo-compare.c index 5fe8e3f..612fbac 100644 --- a/net/colo-compare.c +++ b/net/colo-compare.c @@ -186,7 +186,10 @@ static int packet_enqueue(CompareState *s, int mode) * return: 0 means packet same * > 0 || < 0 means packet different */ -static int colo_packet_compare_common(Packet *ppkt, Packet *spkt, int offs= et) +static int colo_packet_compare_common(Packet *ppkt, + Packet *spkt, + int poffset, + int soffset) { 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= ]; @@ -201,12 +204,13 @@ static int colo_packet_compare_common(Packet *ppkt, P= acket *spkt, int offset) sec_ip_src, sec_ip_dst); } =20 - offset =3D ppkt->vnet_hdr_len + offset; + poffset =3D ppkt->vnet_hdr_len + poffset; + soffset =3D ppkt->vnet_hdr_len + soffset; =20 - if (ppkt->size =3D=3D spkt->size) { - return memcmp(ppkt->data + offset, - spkt->data + offset, - spkt->size - offset); + 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; @@ -263,13 +267,22 @@ static int colo_packet_compare_tcp(Packet *spkt, Pack= et *ppkt) * so we just need skip this field. */ if (ptcp->th_off > 5) { - ptrdiff_t tcp_offset; + ptrdiff_t ptcp_offset, stcp_offset; =20 - tcp_offset =3D ppkt->transport_header - (uint8_t *)ppkt->data - + (ptcp->th_off * 4) - ppkt->vnet_hdr_len; - res =3D colo_packet_compare_common(ppkt, spkt, tcp_offset); + 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; + + /* + * 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); + res =3D colo_packet_compare_common(ppkt, spkt, ETH_HLEN, ETH_HLEN); } else { res =3D -1; } @@ -330,6 +343,7 @@ static int colo_packet_compare_udp(Packet *spkt, Packet= *ppkt) * the ip payload here. */ ret =3D colo_packet_compare_common(ppkt, spkt, + network_header_length + ETH_HLEN, network_header_length + ETH_HLEN); =20 if (ret) { @@ -367,6 +381,7 @@ static int colo_packet_compare_icmp(Packet *spkt, Packe= t *ppkt) * the ip payload here. */ if (colo_packet_compare_common(ppkt, spkt, + network_header_length + ETH_HLEN, network_header_length + ETH_HLEN)) { trace_colo_compare_icmp_miscompare("primary pkt size", ppkt->size); @@ -404,7 +419,7 @@ static int colo_packet_compare_other(Packet *spkt, Pack= et *ppkt) sec_ip_src, sec_ip_dst); } =20 - return colo_packet_compare_common(ppkt, spkt, 0); + return colo_packet_compare_common(ppkt, spkt, 0, 0); } =20 static int colo_old_packet_check_one(Packet *pkt, int64_t *check_time) --=20 2.7.4