From nobody Thu Apr 25 11:59:52 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 1495549529436930.5597024591054; Tue, 23 May 2017 07:25:29 -0700 (PDT) Received: from localhost ([::1]:49293 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dDAkY-000699-04 for importer@patchew.org; Tue, 23 May 2017 10:25:26 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42259) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dDAgL-0002gX-1j for qemu-devel@nongnu.org; Tue, 23 May 2017 10:21:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dDAgG-000307-BY for qemu-devel@nongnu.org; Tue, 23 May 2017 10:21:04 -0400 Received: from [59.151.112.132] (port=29446 helo=heian.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dDAgF-0002zZ-NH for qemu-devel@nongnu.org; Tue, 23 May 2017 10:21:00 -0400 Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 23 May 2017 22:20:56 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (unknown [10.167.33.83]) by cn.fujitsu.com (Postfix) with ESMTP id 8AB1247C7C8C; Tue, 23 May 2017 22:20:52 +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; Tue, 23 May 2017 22:20:51 +0800 X-IronPort-AV: E=Sophos;i="5.22,518,1449504000"; d="scan'208";a="19208525" From: Zhang Chen To: qemu devel , Jason Wang Date: Tue, 23 May 2017 22:20:33 +0800 Message-ID: <1495549241-23380-2-git-send-email-zhangchen.fnst@cn.fujitsu.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1495549241-23380-1-git-send-email-zhangchen.fnst@cn.fujitsu.com> References: <1495549241-23380-1-git-send-email-zhangchen.fnst@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.226.56] X-yoursite-MailScanner-ID: 8AB1247C7C8C.AFA49 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 V5 1/9] 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 Apr 25 11:59:52 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 1495549811976454.31771506528526; Tue, 23 May 2017 07:30:11 -0700 (PDT) Received: from localhost ([::1]:49324 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dDAp2-00019J-N4 for importer@patchew.org; Tue, 23 May 2017 10:30:04 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42296) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dDAgM-0002hI-AK for qemu-devel@nongnu.org; Tue, 23 May 2017 10:21:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dDAgH-00030K-6v for qemu-devel@nongnu.org; Tue, 23 May 2017 10:21:06 -0400 Received: from [59.151.112.132] (port=32707 helo=heian.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dDAgG-0002zE-LL for qemu-devel@nongnu.org; Tue, 23 May 2017 10:21:01 -0400 Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 23 May 2017 22:20:56 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (unknown [10.167.33.83]) by cn.fujitsu.com (Postfix) with ESMTP id E6CCB47CA8C4; Tue, 23 May 2017 22:20:53 +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; Tue, 23 May 2017 22:20:52 +0800 X-IronPort-AV: E=Sophos;i="5.22,518,1449504000"; d="scan'208";a="19208527" From: Zhang Chen To: qemu devel , Jason Wang Date: Tue, 23 May 2017 22:20:34 +0800 Message-ID: <1495549241-23380-3-git-send-email-zhangchen.fnst@cn.fujitsu.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1495549241-23380-1-git-send-email-zhangchen.fnst@cn.fujitsu.com> References: <1495549241-23380-1-git-send-email-zhangchen.fnst@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.226.56] X-yoursite-MailScanner-ID: E6CCB47CA8C4.A1EB0 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 V5 2/9] net/filter-mirror.c: Make filter mirror 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" 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 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 | 73 +++++++++++++++++++++++++++++++++++++++++++++++++= ---- qemu-options.hx | 5 ++-- 2 files changed, 70 insertions(+), 8 deletions(-) diff --git a/net/filter-mirror.c b/net/filter-mirror.c index 72fa7c2..8df0be6 100644 --- a/net/filter-mirror.c +++ b/net/filter-mirror.c @@ -38,15 +38,17 @@ typedef struct MirrorState { NetFilterState parent_obj; char *indev; char *outdev; + bool vnet_hdr; CharBackend chr_in; CharBackend chr_out; 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; @@ -58,14 +60,42 @@ 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; + + /* + * In anytime, nf->netdev and nf->netdev->peer both have a vnet_hd= r_len, + * Here we just find out which is we need. When filter set RX or TX + * that the real vnet_hdr_len are different. + */ + 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 { + return 0; + } + + 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; @@ -141,7 +171,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)); } @@ -164,7 +194,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)); } @@ -308,6 +338,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 +359,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 +392,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..81fb96b 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -4024,10 +4024,9 @@ queue @var{all|rx|tx} is an option that can be appli= ed 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} +filter-mirror on netdev @var{netdevid},mirror net packet to chardev@var{ch= ardevid}, if vnet_hdr =3D on, filter-mirror will mirror packet with vnet_hd= r_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 Apr 25 11:59:52 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 1495549379246689.5704376292431; Tue, 23 May 2017 07:22:59 -0700 (PDT) Received: from localhost ([::1]:49284 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dDAi7-0003qy-4I for importer@patchew.org; Tue, 23 May 2017 10:22:55 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42258) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dDAgL-0002gW-1I for qemu-devel@nongnu.org; Tue, 23 May 2017 10:21:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dDAgH-00030P-7g for qemu-devel@nongnu.org; Tue, 23 May 2017 10:21:04 -0400 Received: from [59.151.112.132] (port=60354 helo=heian.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dDAgG-0002xH-Kd for qemu-devel@nongnu.org; Tue, 23 May 2017 10:21:01 -0400 Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 23 May 2017 22:20:56 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (unknown [10.167.33.83]) by cn.fujitsu.com (Postfix) with ESMTP id CFEBC47CA8CC; Tue, 23 May 2017 22:20:54 +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; Tue, 23 May 2017 22:20:54 +0800 X-IronPort-AV: E=Sophos;i="5.22,518,1449504000"; d="scan'208";a="19208524" From: Zhang Chen To: qemu devel , Jason Wang Date: Tue, 23 May 2017 22:20:35 +0800 Message-ID: <1495549241-23380-4-git-send-email-zhangchen.fnst@cn.fujitsu.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1495549241-23380-1-git-send-email-zhangchen.fnst@cn.fujitsu.com> References: <1495549241-23380-1-git-send-email-zhangchen.fnst@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.226.56] X-yoursite-MailScanner-ID: CFEBC47CA8CC.A3803 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 V5 3/9] 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. Because colo-compare or other modules needs the vnet_hdr_len to parse packet, so we add this new option send the len to others. 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 | 6 +++--- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/net/filter-mirror.c b/net/filter-mirror.c index 8df0be6..6c8579f 100644 --- a/net/filter-mirror.c +++ b/net/filter-mirror.c @@ -381,6 +381,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) { @@ -390,6 +397,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); @@ -409,10 +431,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 81fb96b..a3c4688 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -4028,11 +4028,11 @@ queue @var{all|rx|tx} is an option that can be appl= ied to any netfilter. =20 filter-mirror on netdev @var{netdevid},mirror net packet to chardev@var{ch= ardevid}, if vnet_hdr =3D on, filter-mirror will mirror packet with vnet_hd= r_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}] +@item -object filter-redirector,id=3D@var{id},netdev=3D@var{netdevid},inde= v=3D@var{chardevid},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 Apr 25 11:59:52 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 1495549532265135.8189495975223; Tue, 23 May 2017 07:25:32 -0700 (PDT) Received: from localhost ([::1]:49294 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dDAkb-0006BX-Q5 for importer@patchew.org; Tue, 23 May 2017 10:25:29 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42323) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dDAgS-0002nD-CC for qemu-devel@nongnu.org; Tue, 23 May 2017 10:21:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dDAgI-000312-Hy for qemu-devel@nongnu.org; Tue, 23 May 2017 10:21:12 -0400 Received: from [59.151.112.132] (port=29446 helo=heian.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dDAgH-0002zZ-5J for qemu-devel@nongnu.org; Tue, 23 May 2017 10:21:02 -0400 Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 23 May 2017 22:20:56 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (unknown [10.167.33.83]) by cn.fujitsu.com (Postfix) with ESMTP id BD26347CA8E2; Tue, 23 May 2017 22:20:55 +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; Tue, 23 May 2017 22:20:55 +0800 X-IronPort-AV: E=Sophos;i="5.22,518,1449504000"; d="scan'208";a="19208526" From: Zhang Chen To: qemu devel , Jason Wang Date: Tue, 23 May 2017 22:20:36 +0800 Message-ID: <1495549241-23380-5-git-send-email-zhangchen.fnst@cn.fujitsu.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1495549241-23380-1-git-send-email-zhangchen.fnst@cn.fujitsu.com> References: <1495549241-23380-1-git-send-email-zhangchen.fnst@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.226.56] X-yoursite-MailScanner-ID: BD26347CA8E2.AFC6C 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 V5 4/9] 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" We add a flag to dicide whether net_fill_rstate() to read the vnet_hdr_len or not. Signed-off-by: Zhang Chen Suggested-by: Jason Wang --- include/net/net.h | 6 +++++- net/filter-mirror.c | 1 + net/net.c | 33 ++++++++++++++++++++++++++++++--- 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/include/net/net.h b/include/net/net.h index 70edfc0..6846b91 100644 --- a/include/net/net.h +++ b/include/net/net.h @@ -113,9 +113,13 @@ 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; + /* This flag decide whether to read the vnet_hdr_len field */ + bool vnet_hdr; uint32_t index; uint32_t packet_len; + uint32_t vnet_hdr_len; uint8_t buf[NET_BUFSIZE]; SocketReadStateFinalize *finalize; }; diff --git a/net/filter-mirror.c b/net/filter-mirror.c index 6c8579f..18992e9 100644 --- a/net/filter-mirror.c +++ b/net/filter-mirror.c @@ -266,6 +266,7 @@ static void filter_redirector_setup(NetFilterState *nf,= Error **errp) } =20 net_socket_rs_init(&s->rs, redirector_rs_finalize); + s->rs.vnet_hdr =3D s->vnet_hdr; =20 if (s->indev) { chr =3D qemu_chr_find(s->indev); diff --git a/net/net.c b/net/net.c index a00a0c9..031cbb5 100644 --- a/net/net.c +++ b/net/net.c @@ -1607,8 +1607,10 @@ void net_socket_rs_init(SocketReadState *rs, SocketReadStateFinalize *finalize) { rs->state =3D 0; + rs->vnet_hdr =3D false; rs->index =3D 0; rs->packet_len =3D 0; + rs->vnet_hdr_len =3D 0; memset(rs->buf, 0, sizeof(rs->buf)); rs->finalize =3D finalize; } @@ -1623,8 +1625,12 @@ int net_fill_rstate(SocketReadState *rs, const uint8= _t *buf, int size) 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 +1644,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 (rs->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; --=20 2.7.4 From nobody Thu Apr 25 11:59:52 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 1495549380182300.80870200750905; Tue, 23 May 2017 07:23:00 -0700 (PDT) Received: from localhost ([::1]:49285 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dDAi9-0003zk-FA for importer@patchew.org; Tue, 23 May 2017 10:22:57 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42252) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dDAgK-0002gI-IY for qemu-devel@nongnu.org; Tue, 23 May 2017 10:21:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dDAgF-0002zt-R6 for qemu-devel@nongnu.org; Tue, 23 May 2017 10:21:04 -0400 Received: from [59.151.112.132] (port=32707 helo=heian.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dDAgF-0002zE-AX for qemu-devel@nongnu.org; Tue, 23 May 2017 10:20:59 -0400 Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 23 May 2017 22:20:56 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (unknown [10.167.33.83]) by cn.fujitsu.com (Postfix) with ESMTP id 36D2C47CA8F8; Tue, 23 May 2017 22:20:57 +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; Tue, 23 May 2017 22:20:56 +0800 X-IronPort-AV: E=Sophos;i="5.22,518,1449504000"; d="scan'208";a="19208523" From: Zhang Chen To: qemu devel , Jason Wang Date: Tue, 23 May 2017 22:20:37 +0800 Message-ID: <1495549241-23380-6-git-send-email-zhangchen.fnst@cn.fujitsu.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1495549241-23380-1-git-send-email-zhangchen.fnst@cn.fujitsu.com> References: <1495549241-23380-1-git-send-email-zhangchen.fnst@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.226.56] X-yoursite-MailScanner-ID: 36D2C47CA8F8.AFFF3 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 V5 5/9] 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 4ab80b1..bf0b856 100644 --- a/net/colo-compare.c +++ b/net/colo-compare.c @@ -121,9 +121,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 Apr 25 11:59:52 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 149554968092820.728366705043186; Tue, 23 May 2017 07:28:00 -0700 (PDT) Received: from localhost ([::1]:49313 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dDAn0-0008St-7W for importer@patchew.org; Tue, 23 May 2017 10:27:58 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42263) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dDAgL-0002gZ-2J for qemu-devel@nongnu.org; Tue, 23 May 2017 10:21:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dDAgI-00031A-Na for qemu-devel@nongnu.org; Tue, 23 May 2017 10:21:04 -0400 Received: from [59.151.112.132] (port=32707 helo=heian.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dDAgH-0002zE-V3 for qemu-devel@nongnu.org; Tue, 23 May 2017 10:21:02 -0400 Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 23 May 2017 22:20:58 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (unknown [10.167.33.83]) by cn.fujitsu.com (Postfix) with ESMTP id 20AD047C7C8C; Tue, 23 May 2017 22:20:58 +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; Tue, 23 May 2017 22:20:57 +0800 X-IronPort-AV: E=Sophos;i="5.22,518,1449504000"; d="scan'208";a="19208529" From: Zhang Chen To: qemu devel , Jason Wang Date: Tue, 23 May 2017 22:20:38 +0800 Message-ID: <1495549241-23380-7-git-send-email-zhangchen.fnst@cn.fujitsu.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1495549241-23380-1-git-send-email-zhangchen.fnst@cn.fujitsu.com> References: <1495549241-23380-1-git-send-email-zhangchen.fnst@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.226.56] X-yoursite-MailScanner-ID: 20AD047C7C8C.AEE3A 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 V5 6/9] 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" 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 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 | 76 +++++++++++++++++++++++++++++++++++++++++++++++---= ---- qemu-options.hx | 4 +-- 2 files changed, 69 insertions(+), 11 deletions(-) diff --git a/net/colo-compare.c b/net/colo-compare.c index bf0b856..f89b380 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. @@ -97,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) { @@ -472,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"); } @@ -493,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); @@ -504,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; } @@ -646,13 +664,38 @@ static void compare_set_outdev(Object *obj, const cha= r *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); =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); @@ -735,7 +778,9 @@ static void colo_compare_complete(UserCreatable *uc, Er= ror **errp) } =20 net_socket_rs_init(&s->pri_rs, compare_pri_rs_finalize); + s->pri_rs.vnet_hdr =3D s->vnet_hdr; net_socket_rs_init(&s->sec_rs, compare_sec_rs_finalize); + s->sec_rs.vnet_hdr =3D s->vnet_hdr; =20 g_queue_init(&s->conn_list); =20 @@ -761,7 +806,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)) { @@ -779,6 +827,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); @@ -788,6 +838,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 a3c4688..bb3f400 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -4057,13 +4057,13 @@ Dump the network traffic on netdev @var{dev} to the= file specified by The file format is libpcap, so it can be analyzed with tools such as tcpdu= mp 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} +@item -object colo-compare,id=3D@var{id},primary_in=3D@var{chardevid},seco= ndary_in=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 Apr 25 11:59:52 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 1495549744202859.3007285831096; Tue, 23 May 2017 07:29:04 -0700 (PDT) Received: from localhost ([::1]:49320 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dDAo1-0000bc-Tt for importer@patchew.org; Tue, 23 May 2017 10:29:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42298) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dDAgM-0002hY-Hn for qemu-devel@nongnu.org; Tue, 23 May 2017 10:21:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dDAgL-00032U-ES for qemu-devel@nongnu.org; Tue, 23 May 2017 10:21:06 -0400 Received: from [59.151.112.132] (port=32707 helo=heian.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dDAgL-0002zE-0L for qemu-devel@nongnu.org; Tue, 23 May 2017 10:21:05 -0400 Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 23 May 2017 22:21:03 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (unknown [10.167.33.83]) by cn.fujitsu.com (Postfix) with ESMTP id 0975847C7C8C; Tue, 23 May 2017 22:20:59 +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; Tue, 23 May 2017 22:20:58 +0800 X-IronPort-AV: E=Sophos;i="5.22,518,1449504000"; d="scan'208";a="19208538" From: Zhang Chen To: qemu devel , Jason Wang Date: Tue, 23 May 2017 22:20:39 +0800 Message-ID: <1495549241-23380-8-git-send-email-zhangchen.fnst@cn.fujitsu.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1495549241-23380-1-git-send-email-zhangchen.fnst@cn.fujitsu.com> References: <1495549241-23380-1-git-send-email-zhangchen.fnst@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.226.56] X-yoursite-MailScanner-ID: 0975847C7C8C.AE718 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 V5 7/9] 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 Apr 25 11:59:52 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 1495549583808770.8782306574435; Tue, 23 May 2017 07:26:23 -0700 (PDT) Received: from localhost ([::1]:49300 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dDAlS-00071W-ID for importer@patchew.org; Tue, 23 May 2017 10:26:22 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42271) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dDAgL-0002gg-BA for qemu-devel@nongnu.org; Tue, 23 May 2017 10:21:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dDAgK-00031g-4x for qemu-devel@nongnu.org; Tue, 23 May 2017 10:21:05 -0400 Received: from [59.151.112.132] (port=32707 helo=heian.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dDAgJ-0002zE-Of for qemu-devel@nongnu.org; Tue, 23 May 2017 10:21:04 -0400 Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 23 May 2017 22:21:03 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (unknown [10.167.33.83]) by cn.fujitsu.com (Postfix) with ESMTP id EC80047CA8C3; Tue, 23 May 2017 22:20:59 +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; Tue, 23 May 2017 22:20:59 +0800 X-IronPort-AV: E=Sophos;i="5.22,518,1449504000"; d="scan'208";a="19208536" From: Zhang Chen To: qemu devel , Jason Wang Date: Tue, 23 May 2017 22:20:40 +0800 Message-ID: <1495549241-23380-9-git-send-email-zhangchen.fnst@cn.fujitsu.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1495549241-23380-1-git-send-email-zhangchen.fnst@cn.fujitsu.com> References: <1495549241-23380-1-git-send-email-zhangchen.fnst@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.226.56] X-yoursite-MailScanner-ID: EC80047CA8C3.A02B0 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 V5 8/9] 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 | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/net/colo-compare.c b/net/colo-compare.c index f89b380..0d7fe2b 100644 --- a/net/colo-compare.c +++ b/net/colo-compare.c @@ -201,8 +201,11 @@ static int colo_packet_compare_common(Packet *ppkt, Pa= cket *spkt, int offset) sec_ip_src, sec_ip_dst); } =20 + offset =3D ppkt->vnet_hdr_len + offset; + if (ppkt->size =3D=3D spkt->size) { - return memcmp(ppkt->data + offset, spkt->data + offset, + return memcmp(ppkt->data + offset, + spkt->data + offset, spkt->size - offset); } else { trace_colo_compare_main("Net packet size are not the same"); @@ -261,8 +264,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 Apr 25 11:59:52 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 1495549536707160.90899352408667; Tue, 23 May 2017 07:25:36 -0700 (PDT) Received: from localhost ([::1]:49295 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dDAkd-0006CL-Ay for importer@patchew.org; Tue, 23 May 2017 10:25:31 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42310) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dDAgN-0002i7-M5 for qemu-devel@nongnu.org; Tue, 23 May 2017 10:21:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dDAgM-00032u-0U for qemu-devel@nongnu.org; Tue, 23 May 2017 10:21:07 -0400 Received: from [59.151.112.132] (port=60669 helo=heian.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dDAgK-00031S-Oj for qemu-devel@nongnu.org; Tue, 23 May 2017 10:21:05 -0400 Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 23 May 2017 22:21:03 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (unknown [10.167.33.83]) by cn.fujitsu.com (Postfix) with ESMTP id D64AE47CA8CC; Tue, 23 May 2017 22:21:00 +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; Tue, 23 May 2017 22:21:00 +0800 X-IronPort-AV: E=Sophos;i="5.22,518,1449504000"; d="scan'208";a="19208537" From: Zhang Chen To: qemu devel , Jason Wang Date: Tue, 23 May 2017 22:20:41 +0800 Message-ID: <1495549241-23380-10-git-send-email-zhangchen.fnst@cn.fujitsu.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1495549241-23380-1-git-send-email-zhangchen.fnst@cn.fujitsu.com> References: <1495549241-23380-1-git-send-email-zhangchen.fnst@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.226.56] X-yoursite-MailScanner-ID: D64AE47CA8CC.A13C6 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 V5 9/9] 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 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 We get the vnet_hdr_len from NetClientState that make us parse net packet correctly. Signed-off-by: Zhang Chen --- net/filter-rewriter.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++= +++- qemu-options.hx | 4 ++-- 2 files changed, 56 insertions(+), 3 deletions(-) diff --git a/net/filter-rewriter.c b/net/filter-rewriter.c index 63256c7..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" @@ -33,6 +34,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) @@ -155,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 /* @@ -237,6 +253,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 +302,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 bb3f400..59cbdd9 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -4037,12 +4037,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