From patchwork Thu Mar 18 03:04:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhang, Chen" X-Patchwork-Id: 1455053 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4F1Brc2zTvz9sWF for ; Thu, 18 Mar 2021 14:11:44 +1100 (AEDT) Received: from localhost ([::1]:49168 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lMj4Y-0004Lm-3e for incoming@patchwork.ozlabs.org; Wed, 17 Mar 2021 23:11:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55290) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lMj3f-0004Hg-To for qemu-devel@nongnu.org; Wed, 17 Mar 2021 23:10:47 -0400 Received: from mga09.intel.com ([134.134.136.24]:54698) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lMj3d-0005re-Pk for qemu-devel@nongnu.org; Wed, 17 Mar 2021 23:10:47 -0400 IronPort-SDR: wC7nD/3PcYLUne/93nlvDyGPU0IsUxT8+5HC6Ox0vajR1iYc/kOYbK/fWkeesWNAn/MpK1ton2 hUVcaZSmNqeQ== X-IronPort-AV: E=McAfee;i="6000,8403,9926"; a="189681333" X-IronPort-AV: E=Sophos;i="5.81,257,1610438400"; d="scan'208";a="189681333" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Mar 2021 20:10:39 -0700 IronPort-SDR: ata36DlWdHpFnPaX5n7HZG6RejG2k3i2JQswaxoTtQHyN0uHgbcUSOGzJ/Slwz3Kib+hxH/Nm8 gleUFsLc5IAg== X-IronPort-AV: E=Sophos;i="5.81,257,1610438400"; d="scan'208";a="412898197" Received: from unknown (HELO localhost.localdomain) ([10.239.13.19]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Mar 2021 20:10:37 -0700 From: Zhang Chen To: Jason Wang , qemu-dev , Eric Blake , "Dr. David Alan Gilbert" , Markus Armbruster , Lukas Straub Subject: [PATCH V3 1/7] qapi/net.json: Add IP_PROTOCOL definition Date: Thu, 18 Mar 2021 11:04:54 +0800 Message-Id: <20210318030500.55352-2-chen.zhang@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210318030500.55352-1-chen.zhang@intel.com> References: <20210318030500.55352-1-chen.zhang@intel.com> MIME-Version: 1.0 Received-SPF: pass client-ip=134.134.136.24; envelope-from=chen.zhang@intel.com; helo=mga09.intel.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Zhang Chen , Zhang Chen Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Add IP_PROTOCOL as enum include TCP,UDP, ICMP... for other QMP commands. Signed-off-by: Zhang Chen --- qapi/net.json | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/qapi/net.json b/qapi/net.json index c31748c87f..dc4c87dc7b 100644 --- a/qapi/net.json +++ b/qapi/net.json @@ -714,3 +714,33 @@ ## { 'event': 'FAILOVER_NEGOTIATED', 'data': {'device-id': 'str'} } + +## +# @IP_PROTOCOL: +# +# Transport layer protocol. +# +# Just for IPv4. +# +# @tcp: Transmission Control Protocol. +# +# @udp: User Datagram Protocol. +# +# @dccp: Datagram Congestion Control Protocol. +# +# @sctp: Stream Control Transmission Protocol. +# +# @udplite: Lightweight User Datagram Protocol. +# +# @icmp: Internet Control Message Protocol. +# +# @igmp: Internet Group Management Protocol. +# +# @ipv6: IPv6 Encapsulation. +# +# TODO: Need to add more transport layer protocol. +# +# Since: 6.0 +## +{ 'enum': 'IP_PROTOCOL', 'data': [ 'tcp', 'udp', 'dccp', 'sctp', 'udplite', + 'icmp', 'igmp', 'ipv6' ] } From patchwork Thu Mar 18 03:04:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhang, Chen" X-Patchwork-Id: 1455055 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4F1Btb0KPdz9sW1 for ; Thu, 18 Mar 2021 14:13:27 +1100 (AEDT) Received: from localhost ([::1]:57222 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lMj6D-0007hM-2W for incoming@patchwork.ozlabs.org; Wed, 17 Mar 2021 23:13:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55278) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lMj3f-0004Ha-7g for qemu-devel@nongnu.org; Wed, 17 Mar 2021 23:10:47 -0400 Received: from mga09.intel.com ([134.134.136.24]:54700) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lMj3d-0005sv-G2 for qemu-devel@nongnu.org; Wed, 17 Mar 2021 23:10:47 -0400 IronPort-SDR: c3R9nWlKCrpn0Up6ZR0+hXMUTobzLAZ5g2DjJGdq223P300KFTgaf2SGFKnjQ+iHzUHtd+/tOH 9RBrsIqksZwQ== X-IronPort-AV: E=McAfee;i="6000,8403,9926"; a="189681337" X-IronPort-AV: E=Sophos;i="5.81,257,1610438400"; d="scan'208";a="189681337" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Mar 2021 20:10:41 -0700 IronPort-SDR: VToqeDUO/HLPVVKLiEpM9uaE4O0aGDCyCu+pYPJAaz77fnIxLXcLQJiPrxI2weSBAPqKgTGD61 rqtfOkWsaKCg== X-IronPort-AV: E=Sophos;i="5.81,257,1610438400"; d="scan'208";a="412898213" Received: from unknown (HELO localhost.localdomain) ([10.239.13.19]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Mar 2021 20:10:39 -0700 From: Zhang Chen To: Jason Wang , qemu-dev , Eric Blake , "Dr. David Alan Gilbert" , Markus Armbruster , Lukas Straub Subject: [PATCH V3 2/7] qapi/net.json: Add L4_Connection definition Date: Thu, 18 Mar 2021 11:04:55 +0800 Message-Id: <20210318030500.55352-3-chen.zhang@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210318030500.55352-1-chen.zhang@intel.com> References: <20210318030500.55352-1-chen.zhang@intel.com> MIME-Version: 1.0 Received-SPF: pass client-ip=134.134.136.24; envelope-from=chen.zhang@intel.com; helo=mga09.intel.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Zhang Chen , Zhang Chen Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Add L4_Connection struct for other QMP commands. Except protocol field is necessary, other fields are optional. Signed-off-by: Zhang Chen --- qapi/net.json | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/qapi/net.json b/qapi/net.json index dc4c87dc7b..b4958447f2 100644 --- a/qapi/net.json +++ b/qapi/net.json @@ -744,3 +744,29 @@ ## { 'enum': 'IP_PROTOCOL', 'data': [ 'tcp', 'udp', 'dccp', 'sctp', 'udplite', 'icmp', 'igmp', 'ipv6' ] } + +## +# @L4_Connection: +# +# Layer 4 network connection. +# +# Just for IPv4. +# +# @protocol: Transport layer protocol like TCP/UDP... +# +# @id: For specific module with Qemu object ID, If there is no such part, +# it means global rules. +# +# @src_ip: Source IP. +# +# @dst_ip: Destination IP. +# +# @src_port: Source port. +# +# @dst_port: Destination port. +# +# Since: 6.0 +## +{ 'struct': 'L4_Connection', + 'data': { 'protocol': 'IP_PROTOCOL', '*id': 'str', '*src_ip': 'str', '*dst_ip': 'str', + '*src_port': 'int', '*dst_port': 'int' } } From patchwork Thu Mar 18 03:04:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhang, Chen" X-Patchwork-Id: 1455052 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4F1Brc26TKz9sW1 for ; Thu, 18 Mar 2021 14:11:43 +1100 (AEDT) Received: from localhost ([::1]:49100 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lMj4X-0004Jw-1T for incoming@patchwork.ozlabs.org; Wed, 17 Mar 2021 23:11:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55304) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lMj3g-0004Hn-P0 for qemu-devel@nongnu.org; Wed, 17 Mar 2021 23:10:48 -0400 Received: from mga09.intel.com ([134.134.136.24]:54696) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lMj3f-0005qP-2x for qemu-devel@nongnu.org; Wed, 17 Mar 2021 23:10:48 -0400 IronPort-SDR: JCTv37OkvENCUhHWH5MutSbty33hTQxPgdbbATRB5XzDm2YvigMm1gmgTiUH3nPc0r8YP3rjvG Z8xXc41kyrlg== X-IronPort-AV: E=McAfee;i="6000,8403,9926"; a="189681343" X-IronPort-AV: E=Sophos;i="5.81,257,1610438400"; d="scan'208";a="189681343" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Mar 2021 20:10:44 -0700 IronPort-SDR: GZDNlh46FIFXMFtGbVavHt4jQkwlIEIQcEjGQFScJadl9xMDFdYYaCnphlwnT18UNM0votpoDG 9XkyFZYKxIWw== X-IronPort-AV: E=Sophos;i="5.81,257,1610438400"; d="scan'208";a="412898228" Received: from unknown (HELO localhost.localdomain) ([10.239.13.19]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Mar 2021 20:10:42 -0700 From: Zhang Chen To: Jason Wang , qemu-dev , Eric Blake , "Dr. David Alan Gilbert" , Markus Armbruster , Lukas Straub Subject: [PATCH V3 3/7] qapi/net: Add new QMP command for COLO passthrough Date: Thu, 18 Mar 2021 11:04:56 +0800 Message-Id: <20210318030500.55352-4-chen.zhang@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210318030500.55352-1-chen.zhang@intel.com> References: <20210318030500.55352-1-chen.zhang@intel.com> MIME-Version: 1.0 Received-SPF: pass client-ip=134.134.136.24; envelope-from=chen.zhang@intel.com; helo=mga09.intel.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Zhang Chen , Zhang Chen Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Since the real user scenario does not need COLO to monitor all traffic. Add colo-passthrough-add and colo-passthrough-del to maintain a COLO network passthrough list. QMP demo usage: {'execute': 'colo-passthrough-add', 'arguments': {'protocol': 'tcp', 'id': 'comp0', 'src_ip':'10.239.48.105', 'dst_ip':'10.239.48.128', 'src_port':1234, 'dst_port':1235}} Signed-off-by: Zhang Chen --- net/net.c | 10 ++++++++++ qapi/net.json | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/net/net.c b/net/net.c index e1035f21d1..037dcc5973 100644 --- a/net/net.c +++ b/net/net.c @@ -1151,6 +1151,16 @@ void qmp_netdev_del(const char *id, Error **errp) qemu_del_net_client(nc); } +void qmp_colo_passthrough_add(L4_Connection *conn, Error **errp) +{ + /* Setup passthrough connection */ +} + +void qmp_colo_passthrough_del(L4_Connection *conn, Error **errp) +{ + /* Delete passthrough connection */ +} + static void netfilter_print_info(Monitor *mon, NetFilterState *nf) { char *str; diff --git a/qapi/net.json b/qapi/net.json index b4958447f2..e0c6e1d8f3 100644 --- a/qapi/net.json +++ b/qapi/net.json @@ -770,3 +770,43 @@ { 'struct': 'L4_Connection', 'data': { 'protocol': 'IP_PROTOCOL', '*id': 'str', '*src_ip': 'str', '*dst_ip': 'str', '*src_port': 'int', '*dst_port': 'int' } } + +## +# @colo-passthrough-add: +# +# Add passthrough entry according to customer's needs in COLO-compare. +# +# Returns: Nothing on success +# +# Since: 6.0 +# +# Example: +# +# -> { "execute": "colo-passthrough-add", +# "arguments": { "protocol": "tcp", "id": "object0", "src_ip": "192.168.1.1", +# "dst_ip": "192.168.1.2", "src_port": 1234, "dst_port": 4321 } } +# <- { "return": {} } +# +## +{ 'command': 'colo-passthrough-add', 'boxed': true, + 'data': 'L4_Connection' } + +## +# @colo-passthrough-del: +# +# Delete passthrough entry according to customer's needs in COLO-compare. +# +# Returns: Nothing on success +# +# Since: 6.0 +# +# Example: +# +# -> { "execute": "colo-passthrough-del", +# "arguments": { "protocol": "tcp", "id": "object0", "src_ip": "192.168.1.1", +# "dst_ip": "192.168.1.2", "src_port": 1234, "dst_port": 4321 } } +# <- { "return": {} } +# +## +{ 'command': 'colo-passthrough-del', 'boxed': true, + 'data': 'L4_Connection' } From patchwork Thu Mar 18 03:04:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhang, Chen" X-Patchwork-Id: 1455057 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4F1Bwf17tkz9sW1 for ; Thu, 18 Mar 2021 14:15:14 +1100 (AEDT) Received: from localhost ([::1]:35212 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lMj7w-0001mf-7y for incoming@patchwork.ozlabs.org; Wed, 17 Mar 2021 23:15:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55308) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lMj3h-0004IU-EK for qemu-devel@nongnu.org; Wed, 17 Mar 2021 23:10:49 -0400 Received: from mga09.intel.com ([134.134.136.24]:54700) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lMj3f-0005sv-Kt for qemu-devel@nongnu.org; Wed, 17 Mar 2021 23:10:49 -0400 IronPort-SDR: Vuvw18XOw1/BKGU1NLpDR/KcmcYQil7hlKYdDfS5jmr0gNzyaZxC/zTzZKVIa+4u/KSzNMyoOc 8AFgzeAKODwA== X-IronPort-AV: E=McAfee;i="6000,8403,9926"; a="189681347" X-IronPort-AV: E=Sophos;i="5.81,257,1610438400"; d="scan'208";a="189681347" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Mar 2021 20:10:46 -0700 IronPort-SDR: gTAU4Ib6i7UhvqhM6L1KSqTyGNB+Uyh+h2rtNueqB3WsWEm5WZu0S1UACV++TKnOUZ065+oVrT 0CF8qRQpjNYw== X-IronPort-AV: E=Sophos;i="5.81,257,1610438400"; d="scan'208";a="412898243" Received: from unknown (HELO localhost.localdomain) ([10.239.13.19]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Mar 2021 20:10:44 -0700 From: Zhang Chen To: Jason Wang , qemu-dev , Eric Blake , "Dr. David Alan Gilbert" , Markus Armbruster , Lukas Straub Subject: [PATCH V3 4/7] hmp-commands: Add new HMP command for COLO passthrough Date: Thu, 18 Mar 2021 11:04:57 +0800 Message-Id: <20210318030500.55352-5-chen.zhang@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210318030500.55352-1-chen.zhang@intel.com> References: <20210318030500.55352-1-chen.zhang@intel.com> MIME-Version: 1.0 Received-SPF: pass client-ip=134.134.136.24; envelope-from=chen.zhang@intel.com; helo=mga09.intel.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Zhang Chen , Zhang Chen Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Add hmp_colo_passthrough_add and hmp_colo_passthrough_del make user can maintain COLO network passthrough list in human monitor. Signed-off-by: Zhang Chen --- hmp-commands.hx | 26 ++++++++++++++++++++++++++ include/monitor/hmp.h | 2 ++ monitor/hmp-cmds.c | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+) diff --git a/hmp-commands.hx b/hmp-commands.hx index 73e0832ea1..c71521303c 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -1341,6 +1341,32 @@ SRST Remove host network device. ERST + { + .name = "colo_passthrough_add", + .args_type = "protocol:s,id:s?,src_ip:s?,dst_ip:s?,src_port:i?,dst_port:i?", + .params = "protocol [id] [src_ip] [dst_ip] [src_port] [dst_port]", + .help = "Add network stream to colo passthrough list", + .cmd = hmp_colo_passthrough_add, + }, + +SRST +``colo_passthrough_add`` + Add network stream to colo passthrough list. +ERST + + { + .name = "colo_passthrough_del", + .args_type = "protocol:s,id:s?,src_ip:s?,dst_ip:s?,src_port:i?,dst_port:i?", + .params = "protocol [id] [src_ip] [dst_ip] [src_port] [dst_port]", + .help = "Delete network stream from colo passthrough list", + .cmd = hmp_colo_passthrough_del, + }, + +SRST +``colo_passthrough_del`` + Delete network stream from colo passthrough list. +ERST + { .name = "object_add", .args_type = "object:O", diff --git a/include/monitor/hmp.h b/include/monitor/hmp.h index ed2913fd18..3c4943b09f 100644 --- a/include/monitor/hmp.h +++ b/include/monitor/hmp.h @@ -81,6 +81,8 @@ void hmp_device_del(Monitor *mon, const QDict *qdict); void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict); void hmp_netdev_add(Monitor *mon, const QDict *qdict); void hmp_netdev_del(Monitor *mon, const QDict *qdict); +void hmp_colo_passthrough_add(Monitor *mon, const QDict *qdict); +void hmp_colo_passthrough_del(Monitor *mon, const QDict *qdict); void hmp_getfd(Monitor *mon, const QDict *qdict); void hmp_closefd(Monitor *mon, const QDict *qdict); void hmp_sendkey(Monitor *mon, const QDict *qdict); diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c index fd4d77e246..de675d16e7 100644 --- a/monitor/hmp-cmds.c +++ b/monitor/hmp-cmds.c @@ -1660,6 +1660,40 @@ void hmp_netdev_del(Monitor *mon, const QDict *qdict) hmp_handle_error(mon, err); } +void hmp_colo_passthrough_add(Monitor *mon, const QDict *qdict) +{ + const char *prot = qdict_get_str(qdict, "protocol"); + L4_Connection *l4_conn = g_new0(L4_Connection, 1); + Error *err = NULL; + + l4_conn->id = g_strdup(qdict_get_try_str(qdict, "id")); + l4_conn->protocol = qapi_enum_parse(&IP_PROTOCOL_lookup, prot, -1, &err); + l4_conn->src_ip = g_strdup(qdict_get_try_str(qdict, "src_ip")); + l4_conn->dst_ip = g_strdup(qdict_get_try_str(qdict, "dst_ip")); + l4_conn->src_port = qdict_get_try_int(qdict, "src_port", 0); + l4_conn->dst_port = qdict_get_try_int(qdict, "dst_port", 0); + + qmp_colo_passthrough_add(l4_conn, &err); + hmp_handle_error(mon, err); +} + +void hmp_colo_passthrough_del(Monitor *mon, const QDict *qdict) +{ + const char *prot = qdict_get_str(qdict, "protocol"); + L4_Connection *l4_conn = g_new0(L4_Connection, 1); + Error *err = NULL; + + l4_conn->id = g_strdup(qdict_get_try_str(qdict, "id")); + l4_conn->protocol = qapi_enum_parse(&IP_PROTOCOL_lookup, prot, -1, &err); + l4_conn->src_ip = g_strdup(qdict_get_try_str(qdict, "src_ip")); + l4_conn->dst_ip = g_strdup(qdict_get_try_str(qdict, "dst_ip")); + l4_conn->src_port = qdict_get_try_int(qdict, "src_port", 0); + l4_conn->dst_port = qdict_get_try_int(qdict, "dst_port", 0); + + qmp_colo_passthrough_del(l4_conn, &err); + hmp_handle_error(mon, err); +} + void hmp_object_add(Monitor *mon, const QDict *qdict) { Error *err = NULL; From patchwork Thu Mar 18 03:04:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhang, Chen" X-Patchwork-Id: 1455054 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4F1Brd6j1Qz9sW1 for ; Thu, 18 Mar 2021 14:11:45 +1100 (AEDT) Received: from localhost ([::1]:49282 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lMj4Z-0004OV-Ti for incoming@patchwork.ozlabs.org; Wed, 17 Mar 2021 23:11:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55320) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lMj3j-0004Lv-TF for qemu-devel@nongnu.org; Wed, 17 Mar 2021 23:10:51 -0400 Received: from mga09.intel.com ([134.134.136.24]:54700) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lMj3h-0005sv-QL for qemu-devel@nongnu.org; Wed, 17 Mar 2021 23:10:51 -0400 IronPort-SDR: boY9I/G2h4DQRe+mY/EygCdm2e83yjfBBq56A61L1nigh77d9jiIavIyUTen7mws5ZOEdX/VzR h1Pp4S1VFhHQ== X-IronPort-AV: E=McAfee;i="6000,8403,9926"; a="189681352" X-IronPort-AV: E=Sophos;i="5.81,257,1610438400"; d="scan'208";a="189681352" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Mar 2021 20:10:49 -0700 IronPort-SDR: trFDh0fp6PurIXX5nUKbPRzLj92QiWLMMGue+NHaPYN4bG1TGa0KYVvErUOR1Ljyas3IQS1Zyq sl/yc9MSiUag== X-IronPort-AV: E=Sophos;i="5.81,257,1610438400"; d="scan'208";a="412898258" Received: from unknown (HELO localhost.localdomain) ([10.239.13.19]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Mar 2021 20:10:46 -0700 From: Zhang Chen To: Jason Wang , qemu-dev , Eric Blake , "Dr. David Alan Gilbert" , Markus Armbruster , Lukas Straub Subject: [PATCH V3 5/7] net/colo-compare: Move data structure and define to .h file. Date: Thu, 18 Mar 2021 11:04:58 +0800 Message-Id: <20210318030500.55352-6-chen.zhang@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210318030500.55352-1-chen.zhang@intel.com> References: <20210318030500.55352-1-chen.zhang@intel.com> MIME-Version: 1.0 Received-SPF: pass client-ip=134.134.136.24; envelope-from=chen.zhang@intel.com; helo=mga09.intel.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Zhang Chen , Zhang Chen Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Make other modules can reuse COLO code. Signed-off-by: Zhang Chen --- net/colo-compare.c | 106 --------------------------------------------- net/colo-compare.h | 106 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 106 insertions(+), 106 deletions(-) diff --git a/net/colo-compare.c b/net/colo-compare.c index 84db4978ac..a803f8b888 100644 --- a/net/colo-compare.c +++ b/net/colo-compare.c @@ -17,44 +17,24 @@ #include "qemu/error-report.h" #include "trace.h" #include "qapi/error.h" -#include "net/net.h" #include "net/eth.h" #include "qom/object_interfaces.h" #include "qemu/iov.h" #include "qom/object.h" #include "net/queue.h" -#include "chardev/char-fe.h" #include "qemu/sockets.h" -#include "colo.h" -#include "sysemu/iothread.h" #include "net/colo-compare.h" -#include "migration/colo.h" -#include "migration/migration.h" #include "util.h" #include "block/aio-wait.h" #include "qemu/coroutine.h" -#define TYPE_COLO_COMPARE "colo-compare" -typedef struct CompareState CompareState; -DECLARE_INSTANCE_CHECKER(CompareState, COLO_COMPARE, - TYPE_COLO_COMPARE) - static QTAILQ_HEAD(, CompareState) net_compares = QTAILQ_HEAD_INITIALIZER(net_compares); static NotifierList colo_compare_notifiers = NOTIFIER_LIST_INITIALIZER(colo_compare_notifiers); -#define COMPARE_READ_LEN_MAX NET_BUFSIZE -#define MAX_QUEUE_SIZE 1024 - -#define COLO_COMPARE_FREE_PRIMARY 0x01 -#define COLO_COMPARE_FREE_SECONDARY 0x02 - -#define REGULAR_PACKET_CHECK_MS 1000 -#define DEFAULT_TIME_OUT_MS 3000 - /* #define DEBUG_COLO_PACKETS */ static QemuMutex colo_compare_mutex; @@ -64,92 +44,6 @@ static QemuCond event_complete_cond; static int event_unhandled_count; static uint32_t max_queue_size; -/* - * + CompareState ++ - * | | - * +---------------+ +---------------+ +---------------+ - * | conn list + - > conn + ------- > conn + -- > ...... - * +---------------+ +---------------+ +---------------+ - * | | | | | | - * +---------------+ +---v----+ +---v----+ +---v----+ +---v----+ - * |primary | |secondary |primary | |secondary - * |packet | |packet + |packet | |packet + - * +--------+ +--------+ +--------+ +--------+ - * | | | | - * +---v----+ +---v----+ +---v----+ +---v----+ - * |primary | |secondary |primary | |secondary - * |packet | |packet + |packet | |packet + - * +--------+ +--------+ +--------+ +--------+ - * | | | | - * +---v----+ +---v----+ +---v----+ +---v----+ - * |primary | |secondary |primary | |secondary - * |packet | |packet + |packet | |packet + - * +--------+ +--------+ +--------+ +--------+ - */ - -typedef struct SendCo { - Coroutine *co; - struct CompareState *s; - CharBackend *chr; - GQueue send_list; - bool notify_remote_frame; - bool done; - int ret; -} SendCo; - -typedef struct SendEntry { - uint32_t size; - uint32_t vnet_hdr_len; - uint8_t *buf; -} SendEntry; - -struct CompareState { - Object parent; - - char *pri_indev; - char *sec_indev; - char *outdev; - char *notify_dev; - CharBackend chr_pri_in; - CharBackend chr_sec_in; - CharBackend chr_out; - CharBackend chr_notify_dev; - SocketReadState pri_rs; - SocketReadState sec_rs; - SocketReadState notify_rs; - SendCo out_sendco; - SendCo notify_sendco; - bool vnet_hdr; - uint64_t compare_timeout; - uint32_t expired_scan_cycle; - - /* - * Record the connection that through the NIC - * Element type: Connection - */ - GQueue conn_list; - /* Record the connection without repetition */ - GHashTable *connection_track_table; - - IOThread *iothread; - GMainContext *worker_context; - QEMUTimer *packet_check_timer; - - QEMUBH *event_bh; - enum colo_event event; - - QTAILQ_ENTRY(CompareState) next; -}; - -typedef struct CompareClass { - ObjectClass parent_class; -} CompareClass; - -enum { - PRIMARY_IN = 0, - SECONDARY_IN, -}; - static const char *colo_mode[] = { [PRIMARY_IN] = "primary", [SECONDARY_IN] = "secondary", diff --git a/net/colo-compare.h b/net/colo-compare.h index 22ddd512e2..2a9dcac0a7 100644 --- a/net/colo-compare.h +++ b/net/colo-compare.h @@ -17,6 +17,112 @@ #ifndef QEMU_COLO_COMPARE_H #define QEMU_COLO_COMPARE_H +#include "net/net.h" +#include "chardev/char-fe.h" +#include "migration/colo.h" +#include "migration/migration.h" +#include "sysemu/iothread.h" +#include "colo.h" + +#define TYPE_COLO_COMPARE "colo-compare" +typedef struct CompareState CompareState; +DECLARE_INSTANCE_CHECKER(CompareState, COLO_COMPARE, + TYPE_COLO_COMPARE) + +#define COMPARE_READ_LEN_MAX NET_BUFSIZE +#define MAX_QUEUE_SIZE 1024 + +#define COLO_COMPARE_FREE_PRIMARY 0x01 +#define COLO_COMPARE_FREE_SECONDARY 0x02 + +#define REGULAR_PACKET_CHECK_MS 1000 +#define DEFAULT_TIME_OUT_MS 3000 + +typedef struct SendCo { + Coroutine *co; + struct CompareState *s; + CharBackend *chr; + GQueue send_list; + bool notify_remote_frame; + bool done; + int ret; +} SendCo; + +typedef struct SendEntry { + uint32_t size; + uint32_t vnet_hdr_len; + uint8_t *buf; +} SendEntry; + +/* + * + CompareState ++ + * | | + * +---------------+ +---------------+ +---------------+ + * | conn list + - > conn + ------- > conn + -- > ...... + * +---------------+ +---------------+ +---------------+ + * | | | | | | + * +---------------+ +---v----+ +---v----+ +---v----+ +---v----+ + * |primary | |secondary |primary | |secondary + * |packet | |packet + |packet | |packet + + * +--------+ +--------+ +--------+ +--------+ + * | | | | + * +---v----+ +---v----+ +---v----+ +---v----+ + * |primary | |secondary |primary | |secondary + * |packet | |packet + |packet | |packet + + * +--------+ +--------+ +--------+ +--------+ + * | | | | + * +---v----+ +---v----+ +---v----+ +---v----+ + * |primary | |secondary |primary | |secondary + * |packet | |packet + |packet | |packet + + * +--------+ +--------+ +--------+ +--------+ + */ +struct CompareState { + Object parent; + + char *pri_indev; + char *sec_indev; + char *outdev; + char *notify_dev; + CharBackend chr_pri_in; + CharBackend chr_sec_in; + CharBackend chr_out; + CharBackend chr_notify_dev; + SocketReadState pri_rs; + SocketReadState sec_rs; + SocketReadState notify_rs; + SendCo out_sendco; + SendCo notify_sendco; + bool vnet_hdr; + uint64_t compare_timeout; + uint32_t expired_scan_cycle; + + /* + * Record the connection that through the NIC + * Element type: Connection + */ + GQueue conn_list; + /* Record the connection without repetition */ + GHashTable *connection_track_table; + + IOThread *iothread; + GMainContext *worker_context; + QEMUTimer *packet_check_timer; + + QEMUBH *event_bh; + enum colo_event event; + + QTAILQ_ENTRY(CompareState) next; +}; + +typedef struct CompareClass { + ObjectClass parent_class; +} CompareClass; + +enum { + PRIMARY_IN = 0, + SECONDARY_IN, +}; + void colo_notify_compares_event(void *opaque, int event, Error **errp); void colo_compare_register_notifier(Notifier *notify); void colo_compare_unregister_notifier(Notifier *notify); From patchwork Thu Mar 18 03:04:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhang, Chen" X-Patchwork-Id: 1455058 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4F1By95Yv4z9sW1 for ; Thu, 18 Mar 2021 14:16:33 +1100 (AEDT) Received: from localhost ([::1]:37822 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lMj9D-0002zP-Rg for incoming@patchwork.ozlabs.org; Wed, 17 Mar 2021 23:16:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55334) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lMj3n-0004Ob-AF for qemu-devel@nongnu.org; Wed, 17 Mar 2021 23:10:55 -0400 Received: from mga09.intel.com ([134.134.136.24]:54706) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lMj3k-0005wD-HL for qemu-devel@nongnu.org; Wed, 17 Mar 2021 23:10:55 -0400 IronPort-SDR: b2jOrDz3uzt0EagMqak6dy7g5XZnZ6Dp9DDSilRp0aoeyHyDLE6j14BN376Y1IWktk02Vu2JQg MudugLa4L6ig== X-IronPort-AV: E=McAfee;i="6000,8403,9926"; a="189681354" X-IronPort-AV: E=Sophos;i="5.81,257,1610438400"; d="scan'208";a="189681354" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Mar 2021 20:10:51 -0700 IronPort-SDR: 6tscJbnu7obPtbHWtrzlEk+HM+I3VNQcJ2bHDuZWuqyIGgR8a08DUbI3+EUAL7o2RAbhRIP48z lFAOtQEh6igA== X-IronPort-AV: E=Sophos;i="5.81,257,1610438400"; d="scan'208";a="412898271" Received: from unknown (HELO localhost.localdomain) ([10.239.13.19]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Mar 2021 20:10:49 -0700 From: Zhang Chen To: Jason Wang , qemu-dev , Eric Blake , "Dr. David Alan Gilbert" , Markus Armbruster , Lukas Straub Subject: [PATCH V3 6/7] net/colo-compare: Add passthrough list to CompareState Date: Thu, 18 Mar 2021 11:04:59 +0800 Message-Id: <20210318030500.55352-7-chen.zhang@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210318030500.55352-1-chen.zhang@intel.com> References: <20210318030500.55352-1-chen.zhang@intel.com> MIME-Version: 1.0 Received-SPF: pass client-ip=134.134.136.24; envelope-from=chen.zhang@intel.com; helo=mga09.intel.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Zhang Chen , Zhang Chen Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Add passthrough list for each CompareState. Signed-off-by: Zhang Chen --- net/colo-compare.c | 29 +++++++++++++++++++++++++++++ net/colo-compare.h | 11 +++++++++++ 2 files changed, 40 insertions(+) diff --git a/net/colo-compare.c b/net/colo-compare.c index a803f8b888..40af8cd501 100644 --- a/net/colo-compare.c +++ b/net/colo-compare.c @@ -141,6 +141,7 @@ static int packet_enqueue(CompareState *s, int mode, Connection **con) ConnectionKey key; Packet *pkt = NULL; Connection *conn; + PassthroughEntry *bypass, *next; int ret; if (mode == PRIMARY_IN) { @@ -160,6 +161,32 @@ static int packet_enqueue(CompareState *s, int mode, Connection **con) } fill_connection_key(pkt, &key); + /* Check COLO passthrough connenction */ + qemu_mutex_lock(&s->passthroughlist_mutex); + if (!QLIST_EMPTY(&s->passthroughlist)) { + QLIST_FOREACH_SAFE(bypass, &s->passthroughlist, node, next) { + if (((key.ip_proto == IPPROTO_TCP) && (bypass->l4_protocol == 0)) || + ((key.ip_proto == IPPROTO_UDP) && (bypass->l4_protocol == 1))) { + if (bypass->src_port == 0 || bypass->src_port == key.dst_port) { + if (bypass->src_ip.s_addr == 0 || + bypass->src_ip.s_addr == key.src.s_addr) { + if (bypass->dst_port == 0 || + bypass->dst_port == key.src_port) { + if (bypass->dst_ip.s_addr == 0 || + bypass->dst_ip.s_addr == key.dst.s_addr) { + packet_destroy(pkt, NULL); + pkt = NULL; + qemu_mutex_unlock(&s->passthroughlist_mutex); + return -1; + } + } + } + } + } + } + } + qemu_mutex_unlock(&s->passthroughlist_mutex); + conn = connection_get(s->connection_track_table, &key, &s->conn_list); @@ -1224,6 +1251,7 @@ static void colo_compare_complete(UserCreatable *uc, Error **errp) } g_queue_init(&s->conn_list); + QLIST_INIT(&s->passthroughlist); s->connection_track_table = g_hash_table_new_full(connection_key_hash, connection_key_equal, @@ -1236,6 +1264,7 @@ static void colo_compare_complete(UserCreatable *uc, Error **errp) if (!colo_compare_active) { qemu_mutex_init(&event_mtx); qemu_cond_init(&event_complete_cond); + qemu_mutex_init(&s->passthroughlist_mutex); colo_compare_active = true; } QTAILQ_INSERT_TAIL(&net_compares, s, next); diff --git a/net/colo-compare.h b/net/colo-compare.h index 2a9dcac0a7..2259abcd63 100644 --- a/net/colo-compare.h +++ b/net/colo-compare.h @@ -54,6 +54,15 @@ typedef struct SendEntry { uint8_t *buf; } SendEntry; +typedef struct PassthroughEntry { + int l4_protocol; + int src_port; + int dst_port; + struct in_addr src_ip; + struct in_addr dst_ip; + QLIST_ENTRY(PassthroughEntry) node; +} PassthroughEntry; + /* * + CompareState ++ * | | @@ -110,6 +119,8 @@ struct CompareState { QEMUBH *event_bh; enum colo_event event; + QLIST_HEAD(, PassthroughEntry) passthroughlist; + QemuMutex passthroughlist_mutex; QTAILQ_ENTRY(CompareState) next; }; From patchwork Thu Mar 18 03:05:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhang, Chen" X-Patchwork-Id: 1455056 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4F1Btd6LcSz9sW1 for ; Thu, 18 Mar 2021 14:13:29 +1100 (AEDT) Received: from localhost ([::1]:57500 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lMj6F-0007nv-U4 for incoming@patchwork.ozlabs.org; Wed, 17 Mar 2021 23:13:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55356) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lMj3p-0004S7-By for qemu-devel@nongnu.org; Wed, 17 Mar 2021 23:10:57 -0400 Received: from mga09.intel.com ([134.134.136.24]:54700) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lMj3n-0005sv-51 for qemu-devel@nongnu.org; Wed, 17 Mar 2021 23:10:57 -0400 IronPort-SDR: 3AvUBeMgRQIBfC+yDTA9pjocnYwyW05qs8ibBzA8j5PAq51rINxNIOB1G7NC03DzvOiJAvisn9 EXuUcPvMWPIw== X-IronPort-AV: E=McAfee;i="6000,8403,9926"; a="189681359" X-IronPort-AV: E=Sophos;i="5.81,257,1610438400"; d="scan'208";a="189681359" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Mar 2021 20:10:54 -0700 IronPort-SDR: 00vr1ULMk0fTAh7QFOV5zeBlig4BtTwwfAWaKxvTK84OBdy5VzdpVbx/lLCyt7fD2+kFcVjsUC UdzklnsLHKsw== X-IronPort-AV: E=Sophos;i="5.81,257,1610438400"; d="scan'208";a="412898313" Received: from unknown (HELO localhost.localdomain) ([10.239.13.19]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Mar 2021 20:10:51 -0700 From: Zhang Chen To: Jason Wang , qemu-dev , Eric Blake , "Dr. David Alan Gilbert" , Markus Armbruster , Lukas Straub Subject: [PATCH V3 7/7] net/net.c: Add handler for COLO passthrough connection Date: Thu, 18 Mar 2021 11:05:00 +0800 Message-Id: <20210318030500.55352-8-chen.zhang@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210318030500.55352-1-chen.zhang@intel.com> References: <20210318030500.55352-1-chen.zhang@intel.com> MIME-Version: 1.0 Received-SPF: pass client-ip=134.134.136.24; envelope-from=chen.zhang@intel.com; helo=mga09.intel.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Zhang Chen , Zhang Chen Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Use connection protocol,src port,dst port,src ip,dst ip as the key to bypass certain network traffic in COLO compare. Signed-off-by: Zhang Chen --- net/net.c | 153 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 153 insertions(+) diff --git a/net/net.c b/net/net.c index 037dcc5973..84065ec74e 100644 --- a/net/net.c +++ b/net/net.c @@ -55,6 +55,8 @@ #include "sysemu/sysemu.h" #include "net/filter.h" #include "qapi/string-output-visitor.h" +#include "net/colo-compare.h" +#include "qom/object_interfaces.h" /* Net bridge is currently not supported for W32. */ #if !defined(_WIN32) @@ -1151,14 +1153,165 @@ void qmp_netdev_del(const char *id, Error **errp) qemu_del_net_client(nc); } +static CompareState *colo_passthrough_check(L4_Connection *conn, Error **errp) +{ + Object *container; + Object *obj; + CompareState *s; + + if (!conn->id) { + error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "id", + "Need input colo-compare object id"); + return NULL; + } + + container = object_get_objects_root(); + obj = object_resolve_path_component(container, conn->id); + if (!obj) { + error_setg(errp, "colo-compare '%s' not found", conn->id); + return NULL; + } + + s = COLO_COMPARE(obj); + + if (conn->protocol == -1) { + error_setg(errp, "COLO pass through get wrong protocol"); + return NULL; + } + + if ((conn->src_ip && !qemu_isdigit(conn->src_ip[0])) || + (conn->dst_ip && !qemu_isdigit(conn->dst_ip[0]))) { + error_setg(errp, "COLO pass through get wrong IP"); + return NULL; + } + + if (conn->src_port > 65536 || conn->src_port < 0 || + conn->dst_port > 65536 || conn->dst_port < 0) { + error_setg(errp, "COLO pass through get wrong port"); + return NULL; + } + + return s; +} + +static void compare_passthrough_add(CompareState *s, + L4_Connection *conn, + Error **errp) +{ + PassthroughEntry *bypass = NULL, *next = NULL, *origin = NULL; + + bypass = g_new0(PassthroughEntry, 1); + + bypass->l4_protocol = conn->protocol; + bypass->src_port = conn->src_port; + bypass->dst_port = conn->dst_port; + + if (!inet_aton(conn->src_ip, &bypass->src_ip)) { + bypass->src_ip.s_addr = 0; + } + + if (!inet_aton(conn->dst_ip, &bypass->dst_ip)) { + bypass->dst_ip.s_addr = 0; + } + + qemu_mutex_lock(&s->passthroughlist_mutex); + if (!QLIST_EMPTY(&s->passthroughlist)) { + QLIST_FOREACH_SAFE(origin, &s->passthroughlist, node, next) { + if ((bypass->l4_protocol == origin->l4_protocol) && + (bypass->src_port == origin->src_port) && + (bypass->src_ip.s_addr == origin->src_ip.s_addr) && + (bypass->dst_ip.s_addr == origin->dst_ip.s_addr)) { + error_setg(errp, "The pass through connection already exists"); + g_free(bypass); + qemu_mutex_unlock(&s->passthroughlist_mutex); + return; + } + } + } + + QLIST_INSERT_HEAD(&s->passthroughlist, bypass, node); + qemu_mutex_unlock(&s->passthroughlist_mutex); +} + +static void compare_passthrough_del(CompareState *s, + L4_Connection *conn, + Error **errp) +{ + PassthroughEntry *bypass = NULL, *next = NULL, *origin = NULL; + + bypass = g_new0(PassthroughEntry, 1); + + bypass->l4_protocol = conn->protocol; + bypass->src_port = conn->src_port; + bypass->dst_port = conn->dst_port; + + if (!inet_aton(conn->src_ip, &bypass->src_ip)) { + bypass->src_ip.s_addr = 0; + } + + if (!inet_aton(conn->dst_ip, &bypass->dst_ip)) { + bypass->dst_ip.s_addr = 0; + } + + qemu_mutex_lock(&s->passthroughlist_mutex); + if (!QLIST_EMPTY(&s->passthroughlist)) { + QLIST_FOREACH_SAFE(origin, &s->passthroughlist, node, next) { + if ((bypass->l4_protocol == origin->l4_protocol) && + (bypass->src_port == origin->src_port) && + (bypass->src_ip.s_addr == origin->src_ip.s_addr) && + (bypass->dst_ip.s_addr == origin->dst_ip.s_addr)) { + QLIST_REMOVE(origin, node); + g_free(origin); + g_free(bypass); + qemu_mutex_unlock(&s->passthroughlist_mutex); + return; + } + } + error_setg(errp, "The pass through list can't find the connection"); + } else { + error_setg(errp, "The pass through connection list is empty"); + } + + g_free(bypass); + qemu_mutex_unlock(&s->passthroughlist_mutex); +} + void qmp_colo_passthrough_add(L4_Connection *conn, Error **errp) { /* Setup passthrough connection */ + CompareState *s; + Error *err = NULL; + + s = colo_passthrough_check(conn, &err); + if (err) { + error_propagate(errp, err); + return; + } + + compare_passthrough_add(s, conn, &err); + if (err) { + error_propagate(errp, err); + return; + } } void qmp_colo_passthrough_del(L4_Connection *conn, Error **errp) { /* Delete passthrough connection */ + CompareState *s; + Error *err = NULL; + + s = colo_passthrough_check(conn, &err); + if (err) { + error_propagate(errp, err); + return; + } + + compare_passthrough_del(s, conn, &err); + if (err) { + error_propagate(errp, err); + return; + } } static void netfilter_print_info(Monitor *mon, NetFilterState *nf)