From nobody Thu May 2 16:37:15 2024 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.zoho.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 1494553568933230.3093607793419; Thu, 11 May 2017 18:46:08 -0700 (PDT) Received: from localhost ([::1]:50911 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d8zeg-0001Mx-Fp for importer@patchew.org; Thu, 11 May 2017 21:46:06 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55984) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d8zdC-0000HG-5j for qemu-devel@nongnu.org; Thu, 11 May 2017 21:44:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d8zdA-0003ew-8T for qemu-devel@nongnu.org; Thu, 11 May 2017 21:44:34 -0400 Received: from [59.151.112.132] (port=14198 helo=heian.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d8zd9-0003YR-SM for qemu-devel@nongnu.org; Thu, 11 May 2017 21:44:32 -0400 Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 12 May 2017 09:44:28 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (unknown [10.167.33.83]) by cn.fujitsu.com (Postfix) with ESMTP id DF64347C6111; Fri, 12 May 2017 09:44:28 +0800 (CST) Received: from localhost.localdomain (10.167.226.56) by G08CNEXCHPEKD02.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.319.2; Fri, 12 May 2017 09:44:27 +0800 X-IronPort-AV: E=Sophos;i="5.22,518,1449504000"; d="scan'208";a="18766942" From: Zhang Chen To: qemu devel , Jason Wang Date: Fri, 12 May 2017 09:41:17 +0800 Message-ID: <1494553288-30764-2-git-send-email-zhangchen.fnst@cn.fujitsu.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1494553288-30764-1-git-send-email-zhangchen.fnst@cn.fujitsu.com> References: <1494553288-30764-1-git-send-email-zhangchen.fnst@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.226.56] X-yoursite-MailScanner-ID: DF64347C6111.AC9DA X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: zhangchen.fnst@cn.fujitsu.com X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 59.151.112.132 Subject: [Qemu-devel] [PATCH V4 01/12] net: Add vnet_hdr_len related arguments in NetClientState 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: zhanghailiang , Li Zhijian , weifuqiang , "eddie . dong" , Zhang Chen , bian naimeng 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" Add vnet_hdr_len and using_vnet_hdr arguments in NetClientState that make othermodule get real vnet_hdr_len easily. Signed-off-by: Zhang Chen Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- include/net/net.h | 2 ++ net/net.c | 2 ++ 2 files changed, 4 insertions(+) diff --git a/include/net/net.h b/include/net/net.h index 99b28d5..70edfc0 100644 --- a/include/net/net.h +++ b/include/net/net.h @@ -100,6 +100,8 @@ struct NetClientState { unsigned int queue_index; unsigned rxfilter_notify_enabled:1; int vring_enable; + bool using_vnet_hdr; + int vnet_hdr_len; QTAILQ_HEAD(NetFilterHead, NetFilterState) filters; }; =20 diff --git a/net/net.c b/net/net.c index 0ac3b9e..a00a0c9 100644 --- a/net/net.c +++ b/net/net.c @@ -472,6 +472,7 @@ void qemu_using_vnet_hdr(NetClientState *nc, bool enabl= e) return; } =20 + nc->using_vnet_hdr =3D enable; nc->info->using_vnet_hdr(nc, enable); } =20 @@ -491,6 +492,7 @@ void qemu_set_vnet_hdr_len(NetClientState *nc, int len) return; } =20 + nc->vnet_hdr_len =3D len; nc->info->set_vnet_hdr_len(nc, len); } =20 --=20 2.7.4 From nobody Thu May 2 16:37:15 2024 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.zoho.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 149455384932998.15416141659443; Thu, 11 May 2017 18:50:49 -0700 (PDT) Received: from localhost ([::1]:50935 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d8zjE-0005OJ-23 for importer@patchew.org; Thu, 11 May 2017 21:50:48 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56032) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d8zdG-0000JE-5T for qemu-devel@nongnu.org; Thu, 11 May 2017 21:44:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d8zdE-0003lo-PK for qemu-devel@nongnu.org; Thu, 11 May 2017 21:44:38 -0400 Received: from [59.151.112.132] (port=14198 helo=heian.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d8zdE-0003YR-D6 for qemu-devel@nongnu.org; Thu, 11 May 2017 21:44:36 -0400 Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 12 May 2017 09:44:34 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (unknown [10.167.33.83]) by cn.fujitsu.com (Postfix) with ESMTP id A4FA647C610B; Fri, 12 May 2017 09:44:30 +0800 (CST) Received: from localhost.localdomain (10.167.226.56) by G08CNEXCHPEKD02.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.319.2; Fri, 12 May 2017 09:44:28 +0800 X-IronPort-AV: E=Sophos;i="5.22,518,1449504000"; d="scan'208";a="18766947" From: Zhang Chen To: qemu devel , Jason Wang Date: Fri, 12 May 2017 09:41:18 +0800 Message-ID: <1494553288-30764-3-git-send-email-zhangchen.fnst@cn.fujitsu.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1494553288-30764-1-git-send-email-zhangchen.fnst@cn.fujitsu.com> References: <1494553288-30764-1-git-send-email-zhangchen.fnst@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.226.56] X-yoursite-MailScanner-ID: A4FA647C610B.AE876 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: zhangchen.fnst@cn.fujitsu.com X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 59.151.112.132 Subject: [Qemu-devel] [PATCH V4 02/12] net/filter-mirror.c: Add new option to enable vnet support for filter-mirror 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: zhanghailiang , Li Zhijian , weifuqiang , "eddie . dong" , Zhang Chen , bian naimeng 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" We add the vnet_hdr option for filter-mirror, default is disable. If you use virtio-net-pci net driver, please enable it. You can use it for example: -object filter-mirror,id=3Dm0,netdev=3Dhn0,queue=3Dtx,outdev=3Dmirror0,vnet= _hdr=3Don Signed-off-by: Zhang Chen --- net/filter-mirror.c | 34 ++++++++++++++++++++++++++++++++++ qemu-options.hx | 5 +++-- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/net/filter-mirror.c b/net/filter-mirror.c index 72fa7c2..3766414 100644 --- a/net/filter-mirror.c +++ b/net/filter-mirror.c @@ -38,6 +38,7 @@ typedef struct MirrorState { NetFilterState parent_obj; char *indev; char *outdev; + bool vnet_hdr; CharBackend chr_in; CharBackend chr_out; SocketReadState rs; @@ -308,6 +309,13 @@ static char *filter_mirror_get_outdev(Object *obj, Err= or **errp) return g_strdup(s->outdev); } =20 +static char *filter_mirror_get_vnet_hdr(Object *obj, Error **errp) +{ + MirrorState *s =3D FILTER_MIRROR(obj); + + return s->vnet_hdr ? g_strdup("on") : g_strdup("off"); +} + static void filter_mirror_set_outdev(Object *obj, const char *value, Error **errp) { @@ -322,6 +330,21 @@ filter_mirror_set_outdev(Object *obj, const char *valu= e, Error **errp) } } =20 +static void filter_mirror_set_vnet_hdr(Object *obj, + const char *value, + Error **errp) +{ + MirrorState *s =3D FILTER_MIRROR(obj); + + if (strcmp(value, "on") && strcmp(value, "off")) { + error_setg(errp, "Invalid value for filter-mirror vnet_hdr, " + "should be 'on' or 'off'"); + return; + } + + s->vnet_hdr =3D !strcmp(value, "on"); +} + static char *filter_redirector_get_outdev(Object *obj, Error **errp) { MirrorState *s =3D FILTER_REDIRECTOR(obj); @@ -340,8 +363,19 @@ filter_redirector_set_outdev(Object *obj, const char *= value, Error **errp) =20 static void filter_mirror_init(Object *obj) { + MirrorState *s =3D FILTER_MIRROR(obj); + object_property_add_str(obj, "outdev", filter_mirror_get_outdev, filter_mirror_set_outdev, NULL); + + /* + * The vnet_hdr is disabled by default, if you want to enable + * this option, you must enable all the option on related modules + * (like other filter or colo-compare). + */ + s->vnet_hdr =3D false; + object_property_add_str(obj, "vnet_hdr", filter_mirror_get_vnet_hdr, + filter_mirror_set_vnet_hdr, NULL); } =20 static void filter_redirector_init(Object *obj) diff --git a/qemu-options.hx b/qemu-options.hx index 70c0ded..1e08481 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -4024,10 +4024,11 @@ queue @var{all|rx|tx} is an option that can be appl= ied to any netfilter. @option{tx}: the filter is attached to the transmit queue of the netdev, where it will receive packets sent by the netdev. =20 -@item -object filter-mirror,id=3D@var{id},netdev=3D@var{netdevid},outdev= =3D@var{chardevid}[,queue=3D@var{all|rx|tx}] +@item -object filter-mirror,id=3D@var{id},netdev=3D@var{netdevid},outdev= =3D@var{chardevid},vnet_hdr=3D@var{on|off}[,queue=3D@var{all|rx|tx}] =20 filter-mirror on netdev @var{netdevid},mirror net packet to chardev -@var{chardevid} +@var{chardevid}, if vnet_hdr =3D on, filter-mirror will mirror packet +with vnet_hdr_len. =20 @item -object filter-redirector,id=3D@var{id},netdev=3D@var{netdevid},inde= v=3D@var{chardevid}, outdev=3D@var{chardevid}[,queue=3D@var{all|rx|tx}] --=20 2.7.4 From nobody Thu May 2 16:37:15 2024 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.zoho.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 1494553588277656.9357761366574; Thu, 11 May 2017 18:46:28 -0700 (PDT) Received: from localhost ([::1]:50913 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d8zf0-0001at-Qp for importer@patchew.org; Thu, 11 May 2017 21:46:26 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56053) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d8zdJ-0000LX-0w for qemu-devel@nongnu.org; Thu, 11 May 2017 21:44:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d8zdE-0003kZ-74 for qemu-devel@nongnu.org; Thu, 11 May 2017 21:44:41 -0400 Received: from [59.151.112.132] (port=45425 helo=heian.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d8zdD-0003hn-FK for qemu-devel@nongnu.org; Thu, 11 May 2017 21:44:36 -0400 Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 12 May 2017 09:44:34 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (unknown [10.167.33.83]) by cn.fujitsu.com (Postfix) with ESMTP id D4C7F47C610D; Fri, 12 May 2017 09:44:32 +0800 (CST) Received: from localhost.localdomain (10.167.226.56) by G08CNEXCHPEKD02.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.319.2; Fri, 12 May 2017 09:44:30 +0800 X-IronPort-AV: E=Sophos;i="5.22,518,1449504000"; d="scan'208";a="18766946" From: Zhang Chen To: qemu devel , Jason Wang Date: Fri, 12 May 2017 09:41:19 +0800 Message-ID: <1494553288-30764-4-git-send-email-zhangchen.fnst@cn.fujitsu.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1494553288-30764-1-git-send-email-zhangchen.fnst@cn.fujitsu.com> References: <1494553288-30764-1-git-send-email-zhangchen.fnst@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.226.56] X-yoursite-MailScanner-ID: D4C7F47C610D.AE53A X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: zhangchen.fnst@cn.fujitsu.com X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 59.151.112.132 Subject: [Qemu-devel] [PATCH V4 03/12] net/filter-mirror.c: Make filter_mirror_send support vnet support. 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: zhanghailiang , Li Zhijian , weifuqiang , "eddie . dong" , Zhang Chen , bian naimeng 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" In this patch, if vnet_hdr=3Don we change the send packet format from struct {int size; const uint8_t buf[];} to {int size; int vnet_hdr_len; con= st uint8_t buf[];}. make other module(like colo-compare) know how to parse net packet correctly. Signed-off-by: Zhang Chen --- net/filter-mirror.c | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/net/filter-mirror.c b/net/filter-mirror.c index 3766414..64323fc 100644 --- a/net/filter-mirror.c +++ b/net/filter-mirror.c @@ -44,10 +44,11 @@ typedef struct MirrorState { SocketReadState rs; } MirrorState; =20 -static int filter_mirror_send(CharBackend *chr_out, +static int filter_mirror_send(MirrorState *s, const struct iovec *iov, int iovcnt) { + NetFilterState *nf =3D NETFILTER(s); int ret =3D 0; ssize_t size =3D 0; uint32_t len =3D 0; @@ -59,14 +60,38 @@ static int filter_mirror_send(CharBackend *chr_out, } =20 len =3D htonl(size); - ret =3D qemu_chr_fe_write_all(chr_out, (uint8_t *)&len, sizeof(len)); + ret =3D qemu_chr_fe_write_all(&s->chr_out, (uint8_t *)&len, sizeof(len= )); if (ret !=3D sizeof(len)) { goto err; } =20 + if (s->vnet_hdr) { + /* + * If vnet_hdr =3D on, we send vnet header len to make other + * module(like colo-compare) know how to parse net + * packet correctly. + */ + ssize_t vnet_hdr_len; + + if (nf->netdev->using_vnet_hdr) { + vnet_hdr_len =3D nf->netdev->vnet_hdr_len; + } else if (nf->netdev->peer->using_vnet_hdr) { + vnet_hdr_len =3D nf->netdev->peer->vnet_hdr_len; + } else { + error_report("filter get vnet_hdr_len failed"); + goto err; + } + + len =3D htonl(vnet_hdr_len); + ret =3D qemu_chr_fe_write_all(&s->chr_out, (uint8_t *)&len, sizeof= (len)); + if (ret !=3D sizeof(len)) { + goto err; + } + } + buf =3D g_malloc(size); iov_to_buf(iov, iovcnt, 0, buf, size); - ret =3D qemu_chr_fe_write_all(chr_out, (uint8_t *)buf, size); + ret =3D qemu_chr_fe_write_all(&s->chr_out, (uint8_t *)buf, size); g_free(buf); if (ret !=3D size) { goto err; @@ -142,7 +167,7 @@ static ssize_t filter_mirror_receive_iov(NetFilterState= *nf, MirrorState *s =3D FILTER_MIRROR(nf); int ret; =20 - ret =3D filter_mirror_send(&s->chr_out, iov, iovcnt); + ret =3D filter_mirror_send(s, iov, iovcnt); if (ret) { error_report("filter_mirror_send failed(%s)", strerror(-ret)); } @@ -165,7 +190,7 @@ static ssize_t filter_redirector_receive_iov(NetFilterS= tate *nf, int ret; =20 if (qemu_chr_fe_get_driver(&s->chr_out)) { - ret =3D filter_mirror_send(&s->chr_out, iov, iovcnt); + ret =3D filter_mirror_send(s, iov, iovcnt); if (ret) { error_report("filter_mirror_send failed(%s)", strerror(-ret)); } --=20 2.7.4 From nobody Thu May 2 16:37:15 2024 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.zoho.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 1494553711332308.0397187845532; Thu, 11 May 2017 18:48:31 -0700 (PDT) Received: from localhost ([::1]:50920 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d8zh0-0003do-3T for importer@patchew.org; Thu, 11 May 2017 21:48:30 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56011) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d8zdE-0000Hm-Fn for qemu-devel@nongnu.org; Thu, 11 May 2017 21:44:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d8zdD-0003jk-I8 for qemu-devel@nongnu.org; Thu, 11 May 2017 21:44:36 -0400 Received: from [59.151.112.132] (port=14198 helo=heian.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d8zdC-0003YR-Ic for qemu-devel@nongnu.org; Thu, 11 May 2017 21:44:35 -0400 Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 12 May 2017 09:44:34 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (unknown [10.167.33.83]) by cn.fujitsu.com (Postfix) with ESMTP id A7A0347C6110; Fri, 12 May 2017 09:44:34 +0800 (CST) Received: from localhost.localdomain (10.167.226.56) by G08CNEXCHPEKD02.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.319.2; Fri, 12 May 2017 09:44:32 +0800 X-IronPort-AV: E=Sophos;i="5.22,518,1449504000"; d="scan'208";a="18766945" From: Zhang Chen To: qemu devel , Jason Wang Date: Fri, 12 May 2017 09:41:20 +0800 Message-ID: <1494553288-30764-5-git-send-email-zhangchen.fnst@cn.fujitsu.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1494553288-30764-1-git-send-email-zhangchen.fnst@cn.fujitsu.com> References: <1494553288-30764-1-git-send-email-zhangchen.fnst@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.226.56] X-yoursite-MailScanner-ID: A7A0347C6110.ABB32 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: zhangchen.fnst@cn.fujitsu.com X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 59.151.112.132 Subject: [Qemu-devel] [PATCH V4 04/12] net/filter-mirror.c: Add new option to enable vnet support for filter-redirector 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: zhanghailiang , Li Zhijian , weifuqiang , "eddie . dong" , Zhang Chen , bian naimeng 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" We add the vnet_hdr option for filter-redirector, default is disable. If you use virtio-net-pci net driver, please enable it. You can use it for example: -object filter-redirector,id=3Dr0,netdev=3Dhn0,queue=3Dtx,outdev=3Dred0,vne= t_hdr=3Don Signed-off-by: Zhang Chen --- net/filter-mirror.c | 33 +++++++++++++++++++++++++++++++++ qemu-options.hx | 5 +++-- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/net/filter-mirror.c b/net/filter-mirror.c index 64323fc..a65853c 100644 --- a/net/filter-mirror.c +++ b/net/filter-mirror.c @@ -377,6 +377,13 @@ static char *filter_redirector_get_outdev(Object *obj,= Error **errp) return g_strdup(s->outdev); } =20 +static char *filter_redirector_get_vnet_hdr(Object *obj, Error **errp) +{ + MirrorState *s =3D FILTER_REDIRECTOR(obj); + + return s->vnet_hdr ? g_strdup("on") : g_strdup("off"); +} + static void filter_redirector_set_outdev(Object *obj, const char *value, Error **errp) { @@ -386,6 +393,21 @@ filter_redirector_set_outdev(Object *obj, const char *= value, Error **errp) s->outdev =3D g_strdup(value); } =20 +static void filter_redirector_set_vnet_hdr(Object *obj, + const char *value, + Error **errp) +{ + MirrorState *s =3D FILTER_REDIRECTOR(obj); + + if (strcmp(value, "on") && strcmp(value, "off")) { + error_setg(errp, "Invalid value for filter-redirector vnet_hdr, " + "should be 'on' or 'off'"); + return; + } + + s->vnet_hdr =3D !strcmp(value, "on"); +} + static void filter_mirror_init(Object *obj) { MirrorState *s =3D FILTER_MIRROR(obj); @@ -405,10 +427,21 @@ static void filter_mirror_init(Object *obj) =20 static void filter_redirector_init(Object *obj) { + MirrorState *s =3D FILTER_REDIRECTOR(obj); + object_property_add_str(obj, "indev", filter_redirector_get_indev, filter_redirector_set_indev, NULL); object_property_add_str(obj, "outdev", filter_redirector_get_outdev, filter_redirector_set_outdev, NULL); + + /* + * The vnet_hdr is disabled by default, if you want to enable + * this option, you must enable all the option on related modules + * (like other filter or colo-compare). + */ + s->vnet_hdr =3D false; + object_property_add_str(obj, "vnet_hdr", filter_redirector_get_vnet_hd= r, + filter_redirector_set_vnet_hdr, NULL); } =20 static void filter_mirror_fini(Object *obj) diff --git a/qemu-options.hx b/qemu-options.hx index 1e08481..0f81c22 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -4031,10 +4031,11 @@ filter-mirror on netdev @var{netdevid},mirror net p= acket to chardev with vnet_hdr_len. =20 @item -object filter-redirector,id=3D@var{id},netdev=3D@var{netdevid},inde= v=3D@var{chardevid}, -outdev=3D@var{chardevid}[,queue=3D@var{all|rx|tx}] +outdev=3D@var{chardevid},vnet_hdr=3D@var{on|off}[,queue=3D@var{all|rx|tx}] =20 filter-redirector on netdev @var{netdevid},redirect filter's net packet to= chardev -@var{chardevid},and redirect indev's packet to filter. +@var{chardevid},and redirect indev's packet to filter.if vnet_hdr =3D on, +filter-redirector will redirect packet with vnet_hdr_len. Create a filter-redirector we need to differ outdev id from indev id, id c= an not be the same. we can just use indev or outdev, but at least one of indev or= outdev need to be specified. --=20 2.7.4 From nobody Thu May 2 16:37:15 2024 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.zoho.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 149455371343728.504064200613698; Thu, 11 May 2017 18:48:33 -0700 (PDT) Received: from localhost ([::1]:50921 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d8zh1-0003fZ-Vt for importer@patchew.org; Thu, 11 May 2017 21:48:32 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56100) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d8zdO-0000QF-Lc for qemu-devel@nongnu.org; Thu, 11 May 2017 21:44:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d8zdN-0003xm-Ge for qemu-devel@nongnu.org; Thu, 11 May 2017 21:44:46 -0400 Received: from [59.151.112.132] (port=8274 helo=heian.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d8zdM-0003ue-Gt for qemu-devel@nongnu.org; Thu, 11 May 2017 21:44:45 -0400 Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 12 May 2017 09:44:40 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (unknown [10.167.33.83]) by cn.fujitsu.com (Postfix) with ESMTP id A644947C610B; Fri, 12 May 2017 09:44:36 +0800 (CST) Received: from localhost.localdomain (10.167.226.56) by G08CNEXCHPEKD02.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.319.2; Fri, 12 May 2017 09:44:34 +0800 X-IronPort-AV: E=Sophos;i="5.22,518,1449504000"; d="scan'208";a="18766957" From: Zhang Chen To: qemu devel , Jason Wang Date: Fri, 12 May 2017 09:41:21 +0800 Message-ID: <1494553288-30764-6-git-send-email-zhangchen.fnst@cn.fujitsu.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1494553288-30764-1-git-send-email-zhangchen.fnst@cn.fujitsu.com> References: <1494553288-30764-1-git-send-email-zhangchen.fnst@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.226.56] X-yoursite-MailScanner-ID: A644947C610B.AD321 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: zhangchen.fnst@cn.fujitsu.com X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 59.151.112.132 Subject: [Qemu-devel] [PATCH V4 05/12] net/net.c: Add vnet_hdr support in SocketReadState 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: zhanghailiang , Li Zhijian , weifuqiang , "eddie . dong" , Zhang Chen , bian naimeng 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" Address Jason Wang's comments add vnet header length to SocketReadState. We add a flag to dicide whether net_fill_rstate() to read struct {int size; int vnet_hdr_len; const uint8_t buf[];} or not. Signed-off-by: Zhang Chen --- include/net/net.h | 9 +++++++-- net/colo-compare.c | 4 ++-- net/filter-mirror.c | 2 +- net/net.c | 36 ++++++++++++++++++++++++++++++++---- net/socket.c | 2 +- 5 files changed, 43 insertions(+), 10 deletions(-) diff --git a/include/net/net.h b/include/net/net.h index 70edfc0..0763636 100644 --- a/include/net/net.h +++ b/include/net/net.h @@ -113,14 +113,19 @@ typedef struct NICState { } NICState; =20 struct SocketReadState { - int state; /* 0 =3D getting length, 1 =3D getting data */ + /* 0 =3D getting length, 1 =3D getting vnet header length, 2 =3D getti= ng data */ + int state; uint32_t index; uint32_t packet_len; + uint32_t vnet_hdr_len; uint8_t buf[NET_BUFSIZE]; SocketReadStateFinalize *finalize; }; =20 -int net_fill_rstate(SocketReadState *rs, const uint8_t *buf, int size); +int net_fill_rstate(SocketReadState *rs, + const uint8_t *buf, + int size, + bool vnet_hdr); char *qemu_mac_strdup_printf(const uint8_t *macaddr); NetClientState *qemu_find_netdev(const char *id); int qemu_find_net_clients_except(const char *id, NetClientState **ncs, diff --git a/net/colo-compare.c b/net/colo-compare.c index 4ab80b1..332f57e 100644 --- a/net/colo-compare.c +++ b/net/colo-compare.c @@ -530,7 +530,7 @@ static void compare_pri_chr_in(void *opaque, const uint= 8_t *buf, int size) CompareState *s =3D COLO_COMPARE(opaque); int ret; =20 - ret =3D net_fill_rstate(&s->pri_rs, buf, size); + ret =3D net_fill_rstate(&s->pri_rs, buf, size, false); if (ret =3D=3D -1) { qemu_chr_fe_set_handlers(&s->chr_pri_in, NULL, NULL, NULL, NULL, NULL, true); @@ -547,7 +547,7 @@ static void compare_sec_chr_in(void *opaque, const uint= 8_t *buf, int size) CompareState *s =3D COLO_COMPARE(opaque); int ret; =20 - ret =3D net_fill_rstate(&s->sec_rs, buf, size); + ret =3D net_fill_rstate(&s->sec_rs, buf, size, false); if (ret =3D=3D -1) { qemu_chr_fe_set_handlers(&s->chr_sec_in, NULL, NULL, NULL, NULL, NULL, true); diff --git a/net/filter-mirror.c b/net/filter-mirror.c index a65853c..4649416 100644 --- a/net/filter-mirror.c +++ b/net/filter-mirror.c @@ -134,7 +134,7 @@ static void redirector_chr_read(void *opaque, const uin= t8_t *buf, int size) MirrorState *s =3D FILTER_REDIRECTOR(nf); int ret; =20 - ret =3D net_fill_rstate(&s->rs, buf, size); + ret =3D net_fill_rstate(&s->rs, buf, size, s->vnet_hdr); =20 if (ret =3D=3D -1) { qemu_chr_fe_set_handlers(&s->chr_in, NULL, NULL, NULL, diff --git a/net/net.c b/net/net.c index a00a0c9..a9c97cf 100644 --- a/net/net.c +++ b/net/net.c @@ -1618,13 +1618,20 @@ void net_socket_rs_init(SocketReadState *rs, * 0: success * -1: error occurs */ -int net_fill_rstate(SocketReadState *rs, const uint8_t *buf, int size) +int net_fill_rstate(SocketReadState *rs, + const uint8_t *buf, + int size, + bool vnet_hdr) { unsigned int l; =20 while (size > 0) { - /* reassemble a packet from the network */ - switch (rs->state) { /* 0 =3D getting length, 1 =3D getting data */ + /* Reassemble a packet from the network. + * 0 =3D getting length. + * 1 =3D getting vnet header length. + * 2 =3D getting data. + */ + switch (rs->state) { case 0: l =3D 4 - rs->index; if (l > size) { @@ -1638,10 +1645,31 @@ int net_fill_rstate(SocketReadState *rs, const uint= 8_t *buf, int size) /* got length */ rs->packet_len =3D ntohl(*(uint32_t *)rs->buf); rs->index =3D 0; - rs->state =3D 1; + if (vnet_hdr) { + rs->state =3D 1; + } else { + rs->state =3D 2; + rs->vnet_hdr_len =3D 0; + } } break; case 1: + l =3D 4 - rs->index; + if (l > size) { + l =3D size; + } + memcpy(rs->buf + rs->index, buf, l); + buf +=3D l; + size -=3D l; + rs->index +=3D l; + if (rs->index =3D=3D 4) { + /* got vnet header length */ + rs->vnet_hdr_len =3D ntohl(*(uint32_t *)rs->buf); + rs->index =3D 0; + rs->state =3D 2; + } + break; + case 2: l =3D rs->packet_len - rs->index; if (l > size) { l =3D size; diff --git a/net/socket.c b/net/socket.c index b8c931e..4e58eff 100644 --- a/net/socket.c +++ b/net/socket.c @@ -182,7 +182,7 @@ static void net_socket_send(void *opaque) } buf =3D buf1; =20 - ret =3D net_fill_rstate(&s->rs, buf, size); + ret =3D net_fill_rstate(&s->rs, buf, size, false); =20 if (ret =3D=3D -1) { goto eoc; --=20 2.7.4 From nobody Thu May 2 16:37:15 2024 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.zoho.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 1494553728067880.3370550823802; Thu, 11 May 2017 18:48:48 -0700 (PDT) Received: from localhost ([::1]:50922 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d8zhG-0003q9-P1 for importer@patchew.org; Thu, 11 May 2017 21:48:46 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56072) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d8zdM-0000O7-Ao for qemu-devel@nongnu.org; Thu, 11 May 2017 21:44:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d8zdK-0003tt-Qw for qemu-devel@nongnu.org; Thu, 11 May 2017 21:44:44 -0400 Received: from [59.151.112.132] (port=35788 helo=heian.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d8zdJ-0003rG-QJ for qemu-devel@nongnu.org; Thu, 11 May 2017 21:44:42 -0400 Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 12 May 2017 09:44:40 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (unknown [10.167.33.83]) by cn.fujitsu.com (Postfix) with ESMTP id 6E35D47C6111; Fri, 12 May 2017 09:44:38 +0800 (CST) Received: from localhost.localdomain (10.167.226.56) by G08CNEXCHPEKD02.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.319.2; Fri, 12 May 2017 09:44:36 +0800 X-IronPort-AV: E=Sophos;i="5.22,518,1449504000"; d="scan'208";a="18766953" From: Zhang Chen To: qemu devel , Jason Wang Date: Fri, 12 May 2017 09:41:22 +0800 Message-ID: <1494553288-30764-7-git-send-email-zhangchen.fnst@cn.fujitsu.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1494553288-30764-1-git-send-email-zhangchen.fnst@cn.fujitsu.com> References: <1494553288-30764-1-git-send-email-zhangchen.fnst@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.226.56] X-yoursite-MailScanner-ID: 6E35D47C6111.AD652 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: zhangchen.fnst@cn.fujitsu.com X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 59.151.112.132 Subject: [Qemu-devel] [PATCH V4 06/12] net/colo-compare.c: Add new option to enable vnet support for colo-compare 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: zhanghailiang , Li Zhijian , weifuqiang , "eddie . dong" , Zhang Chen , bian naimeng 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" We add the vnet_hdr option for colo-compare, default is disable. If you use virtio-net-pci net driver, please enable it. You can use it for example: -object colo-compare,id=3Dcomp0,primary_in=3Dcompare0-0,secondary_in=3Dcomp= are1,outdev=3Dcompare_out0,vnet_hdr=3Don Signed-off-by: Zhang Chen --- net/colo-compare.c | 34 +++++++++++++++++++++++++++++++++- qemu-options.hx | 3 ++- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/net/colo-compare.c b/net/colo-compare.c index 332f57e..99a6912 100644 --- a/net/colo-compare.c +++ b/net/colo-compare.c @@ -73,6 +73,7 @@ typedef struct CompareState { CharBackend chr_out; SocketReadState pri_rs; SocketReadState sec_rs; + bool vnet_hdr; =20 /* connection list: the connections belonged to this NIC could be found * in this list. @@ -642,6 +643,28 @@ static void compare_set_outdev(Object *obj, const char= *value, Error **errp) s->outdev =3D g_strdup(value); } =20 +static char *compare_get_vnet_hdr(Object *obj, Error **errp) +{ + CompareState *s =3D COLO_COMPARE(obj); + + return s->vnet_hdr ? g_strdup("on") : g_strdup("off"); +} + +static void compare_set_vnet_hdr(Object *obj, + const char *value, + Error **errp) +{ + CompareState *s =3D COLO_COMPARE(obj); + + if (strcmp(value, "on") && strcmp(value, "off")) { + error_setg(errp, "Invalid value for colo-compare vnet_hdr, " + "should be 'on' or 'off'"); + return; + } + + s->vnet_hdr =3D !strcmp(value, "on"); +} + static void compare_pri_rs_finalize(SocketReadState *pri_rs) { CompareState *s =3D container_of(pri_rs, CompareState, pri_rs); @@ -667,7 +690,6 @@ static void compare_sec_rs_finalize(SocketReadState *se= c_rs) } } =20 - /* * Return 0 is success. * Return 1 is failed. @@ -775,6 +797,8 @@ static void colo_compare_class_init(ObjectClass *oc, vo= id *data) =20 static void colo_compare_init(Object *obj) { + CompareState *s =3D COLO_COMPARE(obj); + object_property_add_str(obj, "primary_in", compare_get_pri_indev, compare_set_pri_indev, NULL); @@ -784,6 +808,14 @@ static void colo_compare_init(Object *obj) object_property_add_str(obj, "outdev", compare_get_outdev, compare_set_outdev, NULL); + /* + * The vnet_hdr is disabled by default, if you want to enable + * this option, you must enable all the option on related modules + * (like other filter or colo-compare). + */ + s->vnet_hdr =3D false; + object_property_add_str(obj, "vnet_hdr", compare_get_vnet_hdr, + compare_set_vnet_hdr, NULL); } =20 static void colo_compare_finalize(Object *obj) diff --git a/qemu-options.hx b/qemu-options.hx index 0f81c22..115b83f 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -4061,12 +4061,13 @@ The file format is libpcap, so it can be analyzed w= ith tools such as tcpdump or Wireshark. =20 @item -object colo-compare,id=3D@var{id},primary_in=3D@var{chardevid},seco= ndary_in=3D@var{chardevid}, -outdev=3D@var{chardevid} +outdev=3D@var{chardevid},vnet_hdr=3D@var{on|off} =20 Colo-compare gets packet from primary_in@var{chardevid} and secondary_in@v= ar{chardevid}, than compare primary packet with secondary packet. If the packets are same, we will output primary packet to outdev@var{chardevid}, else we will notify colo-frame do checkpoint and send primary packet to outdev@var{chardevid}. +if vnet_hdr =3D on, colo compare will send/recv packet with vnet_hdr_len. =20 we must use it with the help of filter-mirror and filter-redirector. =20 --=20 2.7.4 From nobody Thu May 2 16:37:15 2024 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.zoho.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 1494553972778108.54071245746582; Thu, 11 May 2017 18:52:52 -0700 (PDT) Received: from localhost ([::1]:50941 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d8zlD-0007N3-Cl for importer@patchew.org; Thu, 11 May 2017 21:52:51 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56102) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d8zdO-0000QT-Qv for qemu-devel@nongnu.org; Thu, 11 May 2017 21:44:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d8zdN-0003yk-Ty for qemu-devel@nongnu.org; Thu, 11 May 2017 21:44:46 -0400 Received: from [59.151.112.132] (port=35788 helo=heian.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d8zdN-0003rG-HC for qemu-devel@nongnu.org; Thu, 11 May 2017 21:44:45 -0400 Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 12 May 2017 09:44:40 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (unknown [10.167.33.83]) by cn.fujitsu.com (Postfix) with ESMTP id C563247C6117; Fri, 12 May 2017 09:44:39 +0800 (CST) Received: from localhost.localdomain (10.167.226.56) by G08CNEXCHPEKD02.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.319.2; Fri, 12 May 2017 09:44:38 +0800 X-IronPort-AV: E=Sophos;i="5.22,518,1449504000"; d="scan'208";a="18766955" From: Zhang Chen To: qemu devel , Jason Wang Date: Fri, 12 May 2017 09:41:23 +0800 Message-ID: <1494553288-30764-8-git-send-email-zhangchen.fnst@cn.fujitsu.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1494553288-30764-1-git-send-email-zhangchen.fnst@cn.fujitsu.com> References: <1494553288-30764-1-git-send-email-zhangchen.fnst@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.226.56] X-yoursite-MailScanner-ID: C563247C6117.ACE75 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: zhangchen.fnst@cn.fujitsu.com X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 59.151.112.132 Subject: [Qemu-devel] [PATCH V4 07/12] net/colo.c: Make vnet_hdr_len as packet property 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: zhanghailiang , Li Zhijian , weifuqiang , "eddie . dong" , Zhang Chen , bian naimeng 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" We can use this property flush and send packet with vnet_hdr_len. Signed-off-by: Zhang Chen --- net/colo-compare.c | 8 ++++++-- net/colo.c | 3 ++- net/colo.h | 4 +++- net/filter-rewriter.c | 2 +- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/net/colo-compare.c b/net/colo-compare.c index 99a6912..87a9529 100644 --- a/net/colo-compare.c +++ b/net/colo-compare.c @@ -122,9 +122,13 @@ static int packet_enqueue(CompareState *s, int mode) Connection *conn; =20 if (mode =3D=3D PRIMARY_IN) { - pkt =3D packet_new(s->pri_rs.buf, s->pri_rs.packet_len); + pkt =3D packet_new(s->pri_rs.buf, + s->pri_rs.packet_len, + s->pri_rs.vnet_hdr_len); } else { - pkt =3D packet_new(s->sec_rs.buf, s->sec_rs.packet_len); + pkt =3D packet_new(s->sec_rs.buf, + s->sec_rs.packet_len, + s->sec_rs.vnet_hdr_len); } =20 if (parse_packet_early(pkt)) { diff --git a/net/colo.c b/net/colo.c index 8cc166b..180eaed 100644 --- a/net/colo.c +++ b/net/colo.c @@ -153,13 +153,14 @@ void connection_destroy(void *opaque) g_slice_free(Connection, conn); } =20 -Packet *packet_new(const void *data, int size) +Packet *packet_new(const void *data, int size, int vnet_hdr_len) { Packet *pkt =3D g_slice_new(Packet); =20 pkt->data =3D g_memdup(data, size); pkt->size =3D size; pkt->creation_ms =3D qemu_clock_get_ms(QEMU_CLOCK_HOST); + pkt->vnet_hdr_len =3D vnet_hdr_len; =20 return pkt; } diff --git a/net/colo.h b/net/colo.h index 7c524f3..caedb0d 100644 --- a/net/colo.h +++ b/net/colo.h @@ -43,6 +43,8 @@ typedef struct Packet { int size; /* Time of packet creation, in wall clock ms */ int64_t creation_ms; + /* Get vnet_hdr_len from filter */ + uint32_t vnet_hdr_len; } Packet; =20 typedef struct ConnectionKey { @@ -82,7 +84,7 @@ Connection *connection_get(GHashTable *connection_track_t= able, ConnectionKey *key, GQueue *conn_list); void connection_hashtable_reset(GHashTable *connection_track_table); -Packet *packet_new(const void *data, int size); +Packet *packet_new(const void *data, int size, int vnet_hdr_len); void packet_destroy(void *opaque, void *user_data); =20 #endif /* QEMU_COLO_PROXY_H */ diff --git a/net/filter-rewriter.c b/net/filter-rewriter.c index afa06e8..63256c7 100644 --- a/net/filter-rewriter.c +++ b/net/filter-rewriter.c @@ -158,7 +158,7 @@ static ssize_t colo_rewriter_receive_iov(NetFilterState= *nf, char *buf =3D g_malloc0(size); =20 iov_to_buf(iov, iovcnt, 0, buf, size); - pkt =3D packet_new(buf, size); + pkt =3D packet_new(buf, size, 0); g_free(buf); =20 /* --=20 2.7.4 From nobody Thu May 2 16:37:15 2024 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.zoho.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 1494553591853397.5411110808159; Thu, 11 May 2017 18:46:31 -0700 (PDT) Received: from localhost ([::1]:50915 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d8zf4-0001e0-DP for importer@patchew.org; Thu, 11 May 2017 21:46:30 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56084) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d8zdN-0000PA-JW for qemu-devel@nongnu.org; Thu, 11 May 2017 21:44:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d8zdM-0003wr-Mo for qemu-devel@nongnu.org; Thu, 11 May 2017 21:44:45 -0400 Received: from [59.151.112.132] (port=35788 helo=heian.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d8zdL-0003rG-LQ for qemu-devel@nongnu.org; Thu, 11 May 2017 21:44:44 -0400 Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 12 May 2017 09:44:40 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (unknown [10.167.33.83]) by cn.fujitsu.com (Postfix) with ESMTP id 252CC47C611C; Fri, 12 May 2017 09:44:41 +0800 (CST) Received: from localhost.localdomain (10.167.226.56) by G08CNEXCHPEKD02.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.319.2; Fri, 12 May 2017 09:44:39 +0800 X-IronPort-AV: E=Sophos;i="5.22,518,1449504000"; d="scan'208";a="18766954" From: Zhang Chen To: qemu devel , Jason Wang Date: Fri, 12 May 2017 09:41:24 +0800 Message-ID: <1494553288-30764-9-git-send-email-zhangchen.fnst@cn.fujitsu.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1494553288-30764-1-git-send-email-zhangchen.fnst@cn.fujitsu.com> References: <1494553288-30764-1-git-send-email-zhangchen.fnst@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.226.56] X-yoursite-MailScanner-ID: 252CC47C611C.AD7D1 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: zhangchen.fnst@cn.fujitsu.com X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 59.151.112.132 Subject: [Qemu-devel] [PATCH V4 08/12] net/colo-compare.c: Make colo-compare support vnet_hdr_len 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: zhanghailiang , Li Zhijian , weifuqiang , "eddie . dong" , Zhang Chen , bian naimeng 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" COLO-compare can get vnet header length from filter, Add vnet_hdr_len to struct packet and output packet with the vnet_hdr_len. Signed-off-by: Zhang Chen --- net/colo-compare.c | 45 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 34 insertions(+), 11 deletions(-) diff --git a/net/colo-compare.c b/net/colo-compare.c index 87a9529..cb0b04e 100644 --- a/net/colo-compare.c +++ b/net/colo-compare.c @@ -98,9 +98,10 @@ enum { SECONDARY_IN, }; =20 -static int compare_chr_send(CharBackend *out, +static int compare_chr_send(CompareState *s, const uint8_t *buf, - uint32_t size); + uint32_t size, + uint32_t vnet_hdr_len); =20 static gint seq_sorter(Packet *a, Packet *b, gpointer data) { @@ -473,7 +474,10 @@ static void colo_compare_connection(void *opaque, void= *user_data) } =20 if (result) { - ret =3D compare_chr_send(&s->chr_out, pkt->data, pkt->size); + ret =3D compare_chr_send(s, + pkt->data, + pkt->size, + pkt->vnet_hdr_len); if (ret < 0) { error_report("colo_send_primary_packet failed"); } @@ -494,9 +498,10 @@ static void colo_compare_connection(void *opaque, void= *user_data) } } =20 -static int compare_chr_send(CharBackend *out, +static int compare_chr_send(CompareState *s, const uint8_t *buf, - uint32_t size) + uint32_t size, + uint32_t vnet_hdr_len) { int ret =3D 0; uint32_t len =3D htonl(size); @@ -505,12 +510,24 @@ static int compare_chr_send(CharBackend *out, return 0; } =20 - ret =3D qemu_chr_fe_write_all(out, (uint8_t *)&len, sizeof(len)); + ret =3D qemu_chr_fe_write_all(&s->chr_out, (uint8_t *)&len, sizeof(len= )); if (ret !=3D sizeof(len)) { goto err; } =20 - ret =3D qemu_chr_fe_write_all(out, (uint8_t *)buf, size); + if (s->vnet_hdr) { + /* + * We send vnet header len make other module(like filter-redirecto= r) + * know how to parse net packet correctly. + */ + len =3D htonl(vnet_hdr_len); + ret =3D qemu_chr_fe_write_all(&s->chr_out, (uint8_t *)&len, sizeof= (len)); + if (ret !=3D sizeof(len)) { + goto err; + } + } + + ret =3D qemu_chr_fe_write_all(&s->chr_out, (uint8_t *)buf, size); if (ret !=3D size) { goto err; } @@ -535,7 +552,7 @@ static void compare_pri_chr_in(void *opaque, const uint= 8_t *buf, int size) CompareState *s =3D COLO_COMPARE(opaque); int ret; =20 - ret =3D net_fill_rstate(&s->pri_rs, buf, size, false); + ret =3D net_fill_rstate(&s->pri_rs, buf, size, s->vnet_hdr); if (ret =3D=3D -1) { qemu_chr_fe_set_handlers(&s->chr_pri_in, NULL, NULL, NULL, NULL, NULL, true); @@ -552,7 +569,7 @@ static void compare_sec_chr_in(void *opaque, const uint= 8_t *buf, int size) CompareState *s =3D COLO_COMPARE(opaque); int ret; =20 - ret =3D net_fill_rstate(&s->sec_rs, buf, size, false); + ret =3D net_fill_rstate(&s->sec_rs, buf, size, s->vnet_hdr); if (ret =3D=3D -1) { qemu_chr_fe_set_handlers(&s->chr_sec_in, NULL, NULL, NULL, NULL, NULL, true); @@ -675,7 +692,10 @@ static void compare_pri_rs_finalize(SocketReadState *p= ri_rs) =20 if (packet_enqueue(s, PRIMARY_IN)) { trace_colo_compare_main("primary: unsupported packet in"); - compare_chr_send(&s->chr_out, pri_rs->buf, pri_rs->packet_len); + compare_chr_send(s, + pri_rs->buf, + pri_rs->packet_len, + pri_rs->vnet_hdr_len); } else { /* compare connection */ g_queue_foreach(&s->conn_list, colo_compare_connection, s); @@ -783,7 +803,10 @@ static void colo_flush_packets(void *opaque, void *use= r_data) =20 while (!g_queue_is_empty(&conn->primary_list)) { pkt =3D g_queue_pop_head(&conn->primary_list); - compare_chr_send(&s->chr_out, pkt->data, pkt->size); + compare_chr_send(s, + pkt->data, + pkt->size, + pkt->vnet_hdr_len); packet_destroy(pkt, NULL); } while (!g_queue_is_empty(&conn->secondary_list)) { --=20 2.7.4 From nobody Thu May 2 16:37:15 2024 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.zoho.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 1494553863377608.0179596877135; Thu, 11 May 2017 18:51:03 -0700 (PDT) Received: from localhost ([::1]:50936 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d8zjS-0005Ys-4X for importer@patchew.org; Thu, 11 May 2017 21:51:02 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56116) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d8zdP-0000R2-HF for qemu-devel@nongnu.org; Thu, 11 May 2017 21:44:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d8zdO-0003zp-Mq for qemu-devel@nongnu.org; Thu, 11 May 2017 21:44:47 -0400 Received: from [59.151.112.132] (port=8274 helo=heian.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d8zdO-0003ue-AZ for qemu-devel@nongnu.org; Thu, 11 May 2017 21:44:46 -0400 Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 12 May 2017 09:44:40 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (unknown [10.167.33.83]) by cn.fujitsu.com (Postfix) with ESMTP id 3403747C612D; Fri, 12 May 2017 09:44:42 +0800 (CST) Received: from localhost.localdomain (10.167.226.56) by G08CNEXCHPEKD02.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.319.2; Fri, 12 May 2017 09:44:40 +0800 X-IronPort-AV: E=Sophos;i="5.22,518,1449504000"; d="scan'208";a="18766959" From: Zhang Chen To: qemu devel , Jason Wang Date: Fri, 12 May 2017 09:41:25 +0800 Message-ID: <1494553288-30764-10-git-send-email-zhangchen.fnst@cn.fujitsu.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1494553288-30764-1-git-send-email-zhangchen.fnst@cn.fujitsu.com> References: <1494553288-30764-1-git-send-email-zhangchen.fnst@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.226.56] X-yoursite-MailScanner-ID: 3403747C612D.AB68F X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: zhangchen.fnst@cn.fujitsu.com X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 59.151.112.132 Subject: [Qemu-devel] [PATCH V4 09/12] net/colo.c: Add vnet packet parse feature in colo-proxy 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: zhanghailiang , Li Zhijian , weifuqiang , "eddie . dong" , Zhang Chen , bian naimeng 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" Make colo-compare and filter-rewriter can parse vnet packet. Signed-off-by: Zhang Chen --- net/colo.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/net/colo.c b/net/colo.c index 180eaed..28ce7c8 100644 --- a/net/colo.c +++ b/net/colo.c @@ -43,11 +43,11 @@ int parse_packet_early(Packet *pkt) { int network_length; static const uint8_t vlan[] =3D {0x81, 0x00}; - uint8_t *data =3D pkt->data; + uint8_t *data =3D pkt->data + pkt->vnet_hdr_len; uint16_t l3_proto; ssize_t l2hdr_len =3D eth_get_l2_hdr_length(data); =20 - if (pkt->size < ETH_HLEN) { + if (pkt->size < ETH_HLEN + pkt->vnet_hdr_len) { trace_colo_proxy_main("pkt->size < ETH_HLEN"); return 1; } @@ -73,7 +73,7 @@ int parse_packet_early(Packet *pkt) } =20 network_length =3D pkt->ip->ip_hl * 4; - if (pkt->size < l2hdr_len + network_length) { + if (pkt->size < l2hdr_len + network_length + pkt->vnet_hdr_len) { trace_colo_proxy_main("pkt->size < network_header + network_length= "); return 1; } --=20 2.7.4 From nobody Thu May 2 16:37:15 2024 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.zoho.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 1494554087361696.7383994912302; Thu, 11 May 2017 18:54:47 -0700 (PDT) Received: from localhost ([::1]:50947 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d8zn4-0000Lv-2F for importer@patchew.org; Thu, 11 May 2017 21:54:46 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56141) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d8zdR-0000So-1i for qemu-devel@nongnu.org; Thu, 11 May 2017 21:44:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d8zdQ-00043C-9i for qemu-devel@nongnu.org; Thu, 11 May 2017 21:44:49 -0400 Received: from [59.151.112.132] (port=32737 helo=heian.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d8zdP-0003zw-TB for qemu-devel@nongnu.org; Thu, 11 May 2017 21:44:48 -0400 Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 12 May 2017 09:44:46 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (unknown [10.167.33.83]) by cn.fujitsu.com (Postfix) with ESMTP id 425C347C610B; Fri, 12 May 2017 09:44:43 +0800 (CST) Received: from localhost.localdomain (10.167.226.56) by G08CNEXCHPEKD02.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.319.2; Fri, 12 May 2017 09:44:41 +0800 X-IronPort-AV: E=Sophos;i="5.22,518,1449504000"; d="scan'208";a="18766967" From: Zhang Chen To: qemu devel , Jason Wang Date: Fri, 12 May 2017 09:41:26 +0800 Message-ID: <1494553288-30764-11-git-send-email-zhangchen.fnst@cn.fujitsu.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1494553288-30764-1-git-send-email-zhangchen.fnst@cn.fujitsu.com> References: <1494553288-30764-1-git-send-email-zhangchen.fnst@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.226.56] X-yoursite-MailScanner-ID: 425C347C610B.AB2F5 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: zhangchen.fnst@cn.fujitsu.com X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 59.151.112.132 Subject: [Qemu-devel] [PATCH V4 10/12] net/colo-compare.c: Add vnet packet's tcp/udp/icmp compare 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: zhanghailiang , Li Zhijian , weifuqiang , "eddie . dong" , Zhang Chen , bian naimeng 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" COLO-Proxy just focus on packet payload, So we skip vnet header. Signed-off-by: Zhang Chen --- net/colo-compare.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/net/colo-compare.c b/net/colo-compare.c index cb0b04e..bf565f3 100644 --- a/net/colo-compare.c +++ b/net/colo-compare.c @@ -188,6 +188,8 @@ static int packet_enqueue(CompareState *s, int mode) */ static int colo_packet_compare_common(Packet *ppkt, Packet *spkt, int offs= et) { + int offset_all; + if (trace_event_get_state(TRACE_COLO_COMPARE_MISCOMPARE)) { char pri_ip_src[20], pri_ip_dst[20], sec_ip_src[20], sec_ip_dst[20= ]; =20 @@ -201,9 +203,12 @@ static int colo_packet_compare_common(Packet *ppkt, Pa= cket *spkt, int offset) sec_ip_src, sec_ip_dst); } =20 + offset_all =3D ppkt->vnet_hdr_len + offset; + if (ppkt->size =3D=3D spkt->size) { - return memcmp(ppkt->data + offset, spkt->data + offset, - spkt->size - offset); + return memcmp(ppkt->data + offset_all, + spkt->data + offset_all, + spkt->size - offset_all); } else { trace_colo_compare_main("Net packet size are not the same"); return -1; @@ -261,8 +266,9 @@ static int colo_packet_compare_tcp(Packet *spkt, Packet= *ppkt) */ if (ptcp->th_off > 5) { ptrdiff_t tcp_offset; + tcp_offset =3D ppkt->transport_header - (uint8_t *)ppkt->data - + (ptcp->th_off * 4); + + (ptcp->th_off * 4) - ppkt->vnet_hdr_len; res =3D colo_packet_compare_common(ppkt, spkt, tcp_offset); } else if (ptcp->th_sum =3D=3D stcp->th_sum) { res =3D colo_packet_compare_common(ppkt, spkt, ETH_HLEN); --=20 2.7.4 From nobody Thu May 2 16:37:15 2024 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.zoho.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 1494553986416981.5973070354703; Thu, 11 May 2017 18:53:06 -0700 (PDT) Received: from localhost ([::1]:50942 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d8zlR-0007YW-3E for importer@patchew.org; Thu, 11 May 2017 21:53:05 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56139) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d8zdQ-0000Se-TJ for qemu-devel@nongnu.org; Thu, 11 May 2017 21:44:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d8zdP-00041z-TH for qemu-devel@nongnu.org; Thu, 11 May 2017 21:44:48 -0400 Received: from [59.151.112.132] (port=8274 helo=heian.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d8zdP-0003ue-Go for qemu-devel@nongnu.org; Thu, 11 May 2017 21:44:47 -0400 Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 12 May 2017 09:44:46 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (unknown [10.167.33.83]) by cn.fujitsu.com (Postfix) with ESMTP id 4FA7B47C6110; Fri, 12 May 2017 09:44:44 +0800 (CST) Received: from localhost.localdomain (10.167.226.56) by G08CNEXCHPEKD02.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.319.2; Fri, 12 May 2017 09:44:42 +0800 X-IronPort-AV: E=Sophos;i="5.22,518,1449504000"; d="scan'208";a="18766966" From: Zhang Chen To: qemu devel , Jason Wang Date: Fri, 12 May 2017 09:41:27 +0800 Message-ID: <1494553288-30764-12-git-send-email-zhangchen.fnst@cn.fujitsu.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1494553288-30764-1-git-send-email-zhangchen.fnst@cn.fujitsu.com> References: <1494553288-30764-1-git-send-email-zhangchen.fnst@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.226.56] X-yoursite-MailScanner-ID: 4FA7B47C6110.AE569 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: zhangchen.fnst@cn.fujitsu.com X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 59.151.112.132 Subject: [Qemu-devel] [PATCH V4 11/12] net/filter-rewriter.c: Add new option to enable vnet support for filter-rewriter 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: zhanghailiang , Li Zhijian , weifuqiang , "eddie . dong" , Zhang Chen , bian naimeng 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" We add the vnet_hdr option for filter-rewriter, default is disable. If you use virtio-net-pci net driver, please enable it. You can use it for example: -object filter-rewriter,id=3Drew0,netdev=3Dhn0,queue=3Dall,vnet_hdr=3Don Signed-off-by: Zhang Chen --- net/filter-rewriter.c | 38 ++++++++++++++++++++++++++++++++++++++ qemu-options.hx | 4 ++-- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/net/filter-rewriter.c b/net/filter-rewriter.c index 63256c7..bc6d12a 100644 --- a/net/filter-rewriter.c +++ b/net/filter-rewriter.c @@ -33,6 +33,7 @@ typedef struct RewriterState { NetQueue *incoming_queue; /* hashtable to save connection */ GHashTable *connection_track_table; + bool vnet_hdr; } RewriterState; =20 static void filter_rewriter_flush(NetFilterState *nf) @@ -237,6 +238,42 @@ static void colo_rewriter_setup(NetFilterState *nf, Er= ror **errp) s->incoming_queue =3D qemu_new_net_queue(qemu_netfilter_pass_to_next, = nf); } =20 +static char *filter_rewriter_get_vnet_hdr(Object *obj, Error **errp) +{ + RewriterState *s =3D FILTER_COLO_REWRITER(obj); + + return s->vnet_hdr ? g_strdup("on") : g_strdup("off"); +} + +static void filter_rewriter_set_vnet_hdr(Object *obj, + const char *value, + Error **errp) +{ + RewriterState *s =3D FILTER_COLO_REWRITER(obj); + + if (strcmp(value, "on") && strcmp(value, "off")) { + error_setg(errp, "Invalid value for filter-rewriter vnet_hdr, " + "should be 'on' or 'off'"); + return; + } + + s->vnet_hdr =3D !strcmp(value, "on"); +} + +static void filter_rewriter_init(Object *obj) +{ + RewriterState *s =3D FILTER_COLO_REWRITER(obj); + + /* + * The vnet_hdr is disabled by default, if you want to enable + * this option, you must enable all the option on related modules + * (like other filter or colo-compare). + */ + s->vnet_hdr =3D false; + object_property_add_str(obj, "vnet_hdr", filter_rewriter_get_vnet_hdr, + filter_rewriter_set_vnet_hdr, NULL); +} + static void colo_rewriter_class_init(ObjectClass *oc, void *data) { NetFilterClass *nfc =3D NETFILTER_CLASS(oc); @@ -250,6 +287,7 @@ static const TypeInfo colo_rewriter_info =3D { .name =3D TYPE_FILTER_REWRITER, .parent =3D TYPE_NETFILTER, .class_init =3D colo_rewriter_class_init, + .instance_init =3D filter_rewriter_init, .instance_size =3D sizeof(RewriterState), }; =20 diff --git a/qemu-options.hx b/qemu-options.hx index 115b83f..d191050 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -4040,12 +4040,12 @@ Create a filter-redirector we need to differ outdev= id from indev id, id can not be the same. we can just use indev or outdev, but at least one of indev or= outdev need to be specified. =20 -@item -object filter-rewriter,id=3D@var{id},netdev=3D@var{netdevid},rewrit= er-mode=3D@var{mode}[,queue=3D@var{all|rx|tx}] +@item -object filter-rewriter,id=3D@var{id},netdev=3D@var{netdevid},rewrit= er-mode=3D@var{mode},vnet_hdr=3D@var{on|off}[,queue=3D@var{all|rx|tx}] =20 Filter-rewriter is a part of COLO project.It will rewrite tcp packet to secondary from primary to keep secondary tcp connection,and rewrite tcp packet to primary from secondary make tcp packet can be handled by -client. +client.if vnet_hdr =3D on, we can parse packet with vnet header. =20 usage: colo secondary: --=20 2.7.4 From nobody Thu May 2 16:37:15 2024 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.zoho.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 14945540780921000.5143704302188; Thu, 11 May 2017 18:54:38 -0700 (PDT) Received: from localhost ([::1]:50946 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d8zmu-0000De-NC for importer@patchew.org; Thu, 11 May 2017 21:54:36 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56143) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d8zdR-0000Sr-3z for qemu-devel@nongnu.org; Thu, 11 May 2017 21:44:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d8zdQ-000439-94 for qemu-devel@nongnu.org; Thu, 11 May 2017 21:44:49 -0400 Received: from [59.151.112.132] (port=61908 helo=heian.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d8zdP-0003zx-Tc for qemu-devel@nongnu.org; Thu, 11 May 2017 21:44:48 -0400 Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 12 May 2017 09:44:46 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (unknown [10.167.33.83]) by cn.fujitsu.com (Postfix) with ESMTP id 36B4947C6117; Fri, 12 May 2017 09:44:45 +0800 (CST) Received: from localhost.localdomain (10.167.226.56) by G08CNEXCHPEKD02.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.319.2; Fri, 12 May 2017 09:44:43 +0800 X-IronPort-AV: E=Sophos;i="5.22,518,1449504000"; d="scan'208";a="18766965" From: Zhang Chen To: qemu devel , Jason Wang Date: Fri, 12 May 2017 09:41:28 +0800 Message-ID: <1494553288-30764-13-git-send-email-zhangchen.fnst@cn.fujitsu.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1494553288-30764-1-git-send-email-zhangchen.fnst@cn.fujitsu.com> References: <1494553288-30764-1-git-send-email-zhangchen.fnst@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.226.56] X-yoursite-MailScanner-ID: 36B4947C6117.ABB96 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: zhangchen.fnst@cn.fujitsu.com X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 59.151.112.132 Subject: [Qemu-devel] [PATCH V4 12/12] net/filter-rewriter.c: Make filter-rewriter support vnet_hdr_len 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: zhanghailiang , Li Zhijian , weifuqiang , "eddie . dong" , Zhang Chen , bian naimeng 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" We get the vnet_hdr_len from NetClientState that make us parse net packet correctly. Signed-off-by: Zhang Chen --- net/filter-rewriter.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/net/filter-rewriter.c b/net/filter-rewriter.c index bc6d12a..be129c7 100644 --- a/net/filter-rewriter.c +++ b/net/filter-rewriter.c @@ -17,6 +17,7 @@ #include "qemu-common.h" #include "qapi/error.h" #include "qapi/qmp/qerror.h" +#include "qemu/error-report.h" #include "qapi-visit.h" #include "qom/object.h" #include "qemu/main-loop.h" @@ -156,10 +157,24 @@ static ssize_t colo_rewriter_receive_iov(NetFilterSta= te *nf, ConnectionKey key; Packet *pkt; ssize_t size =3D iov_size(iov, iovcnt); + ssize_t vnet_hdr_len =3D 0; char *buf =3D g_malloc0(size); =20 iov_to_buf(iov, iovcnt, 0, buf, size); - pkt =3D packet_new(buf, size, 0); + + if (s->vnet_hdr) { + if (nf->netdev->using_vnet_hdr) { + vnet_hdr_len =3D nf->netdev->vnet_hdr_len; + } else if (nf->netdev->peer->using_vnet_hdr) { + vnet_hdr_len =3D nf->netdev->peer->vnet_hdr_len; + } else { + error_report("filter-rewriter get vnet_hdr_len failed"); + /* When error occurred we drop the packet */ + return 1; + } + } + + pkt =3D packet_new(buf, size, vnet_hdr_len); g_free(buf); =20 /* --=20 2.7.4