From patchwork Thu Dec 24 01:09:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Chen X-Patchwork-Id: 11989107 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.4 required=3.0 tests=BAYES_00,FROM_WSP_TRAIL, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C4872C433E0 for ; Thu, 24 Dec 2020 01:16:17 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 6635622517 for ; Thu, 24 Dec 2020 01:16:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6635622517 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=intel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:34358 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ksFEk-0002mn-Cu for qemu-devel@archiver.kernel.org; Wed, 23 Dec 2020 20:16:15 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42362) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ksFCE-0001V6-Uk for qemu-devel@nongnu.org; Wed, 23 Dec 2020 20:13:39 -0500 Received: from mga06.intel.com ([134.134.136.31]:46595) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ksFCD-0004bX-C8 for qemu-devel@nongnu.org; Wed, 23 Dec 2020 20:13:38 -0500 IronPort-SDR: w56iw+EwSXsDCZCQAX6KJFzhcxV0JvYDdeliuw5B54cPx7HIUaRxOTfZ1XNBSImqNFmEkNI6aP PC0N8soDVdJw== X-IronPort-AV: E=McAfee;i="6000,8403,9844"; a="237652001" X-IronPort-AV: E=Sophos;i="5.78,443,1599548400"; d="scan'208";a="237652001" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Dec 2020 17:13:18 -0800 IronPort-SDR: fs3DsK8KtByJhO4tgB6lihn1b82LUlhHxBy7ufkd5rSKM2pEiGWrm0VSCKzf1JZXv61L3OCQn9 Zjx04dixQGwA== X-IronPort-AV: E=Sophos;i="5.78,443,1599548400"; d="scan'208";a="565580016" Received: from unknown (HELO localhost.localdomain) ([10.239.13.19]) by fmsmga005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Dec 2020 17:13:16 -0800 From: Zhang Chen To: Jason Wang , qemu-dev , Eric Blake , "Dr. David Alan Gilbert" , Markus Armbruster Subject: [PATCH 1/3] qapi/net: Add new QMP command for COLO passthrough Date: Thu, 24 Dec 2020 09:09:16 +0800 Message-Id: <20201224010918.19275-2-chen.zhang@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201224010918.19275-1-chen.zhang@intel.com> References: <20201224010918.19275-1-chen.zhang@intel.com> Received-SPF: pass client-ip=134.134.136.31; envelope-from=chen.zhang@intel.com; helo=mga06.intel.com X-Spam_score_int: 14 X-Spam_score: 1.4 X-Spam_bar: + X-Spam_report: (1.4 / 5.0 requ) BAYES_00=-1.9, FROM_ADDR_WS=2.999, FROM_WSP_TRAIL=2.3, HEADER_FROM_DIFFERENT_DOMAINS=0.25, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Zhang Chen Since the real user scenario does not need to monitor all traffic. Add colo-passthrough-add and colo-passthrough-del to maintain a COLO network passthrough list. Signed-off-by: Zhang Chen --- net/net.c | 12 ++++++++++++ qapi/net.json | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/net/net.c b/net/net.c index e1035f21d1..eac7a92618 100644 --- a/net/net.c +++ b/net/net.c @@ -1151,6 +1151,18 @@ void qmp_netdev_del(const char *id, Error **errp) qemu_del_net_client(nc); } +void qmp_colo_passthrough_add(const char *prot, const uint32_t port, + Error **errp) +{ + /* Setup passthrough connection */ +} + +void qmp_colo_passthrough_del(const char *prot, const uint32_t port, + 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 c31748c87f..466c29714e 100644 --- a/qapi/net.json +++ b/qapi/net.json @@ -714,3 +714,49 @@ ## { 'event': 'FAILOVER_NEGOTIATED', 'data': {'device-id': 'str'} } + +## +# @colo-passthrough-add: +# +# Add passthrough entry according to customer's needs in COLO-compare. +# +# @protocol: COLO passthrough just support TCP and UDP. +# +# @port: TCP or UDP port number. +# +# Returns: Nothing on success +# +# Since: 5.3 +# +# Example: +# +# -> { "execute": "colo-passthrough-add", +# "arguments": { "protocol": "tcp", "port": 3389 } } +# <- { "return": {} } +# +## +{ 'command': 'colo-passthrough-add', + 'data': {'protocol': 'str', 'port': 'uint32'} } + +## +# @colo-passthrough-del: +# +# Delete passthrough entry according to customer's needs in COLO-compare. +# +# @protocol: COLO passthrough just support TCP and UDP. +# +# @port: TCP or UDP port number. +# +# Returns: Nothing on success +# +# Since: 5.3 +# +# Example: +# +# -> { "execute": "colo-passthrough-del", +# "arguments": { "protocol": "tcp", "port": 3389 } } +# <- { "return": {} } +# +## +{ 'command': 'colo-passthrough-del', + 'data': {'protocol': 'str', 'port': 'uint32'} } From patchwork Thu Dec 24 01:09:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Chen X-Patchwork-Id: 11989119 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.4 required=3.0 tests=BAYES_00,FROM_WSP_TRAIL, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F3438C433E0 for ; Thu, 24 Dec 2020 01:20:01 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 7493920663 for ; Thu, 24 Dec 2020 01:20:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7493920663 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=intel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:39326 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ksFIO-0004xX-FC for qemu-devel@archiver.kernel.org; Wed, 23 Dec 2020 20:20:00 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42388) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ksFCH-0001YK-Po for qemu-devel@nongnu.org; Wed, 23 Dec 2020 20:13:41 -0500 Received: from mga06.intel.com ([134.134.136.31]:46615) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ksFCG-0004fL-4G for qemu-devel@nongnu.org; Wed, 23 Dec 2020 20:13:41 -0500 IronPort-SDR: hvk5R0i4h2p4VGNZPf2psTl0h/3d6OcDZGPlAkQ0V66kFQKc+JuNGbllFl04zM9ebigDG4sPLg 6bplRds3OLXQ== X-IronPort-AV: E=McAfee;i="6000,8403,9844"; a="237652006" X-IronPort-AV: E=Sophos;i="5.78,443,1599548400"; d="scan'208";a="237652006" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Dec 2020 17:13:20 -0800 IronPort-SDR: ATn0tyQkUGgb571GD/HTj1x7lsn5TZbRSgYjlvKhqtnLqEkgY8wjE/mBdZ2RkkKwwGMflQglJH BykC9oS7mmOg== X-IronPort-AV: E=Sophos;i="5.78,443,1599548400"; d="scan'208";a="565580039" Received: from unknown (HELO localhost.localdomain) ([10.239.13.19]) by fmsmga005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Dec 2020 17:13:18 -0800 From: Zhang Chen To: Jason Wang , qemu-dev , Eric Blake , "Dr. David Alan Gilbert" , Markus Armbruster Subject: [PATCH 2/3] hmp-commands: Add new HMP command for COLO passthrough Date: Thu, 24 Dec 2020 09:09:17 +0800 Message-Id: <20201224010918.19275-3-chen.zhang@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201224010918.19275-1-chen.zhang@intel.com> References: <20201224010918.19275-1-chen.zhang@intel.com> Received-SPF: pass client-ip=134.134.136.31; envelope-from=chen.zhang@intel.com; helo=mga06.intel.com X-Spam_score_int: 14 X-Spam_score: 1.4 X-Spam_bar: + X-Spam_report: (1.4 / 5.0 requ) BAYES_00=-1.9, FROM_ADDR_WS=2.999, FROM_WSP_TRAIL=2.3, HEADER_FROM_DIFFERENT_DOMAINS=0.25, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Zhang Chen 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 | 20 ++++++++++++++++++++ 3 files changed, 48 insertions(+) diff --git a/hmp-commands.hx b/hmp-commands.hx index 470a420c2d..f5790782d6 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,port:i", + .params = "protocol 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,port:i", + .params = "protocol 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 65d8ff4849..ab98a6b77d 100644 --- a/monitor/hmp-cmds.c +++ b/monitor/hmp-cmds.c @@ -1661,6 +1661,26 @@ 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"); + uint32_t port = qdict_get_int(qdict, "port"); + Error *err = NULL; + + qmp_colo_passthrough_add(prot, port, &err); + hmp_handle_error(mon, err); +} + +void hmp_colo_passthrough_del(Monitor *mon, const QDict *qdict) +{ + const char *prot = qdict_get_str(qdict, "protocol"); + uint32_t port = qdict_get_int(qdict, "port"); + Error *err = NULL; + + qmp_colo_passthrough_del(prot, port, &err); + hmp_handle_error(mon, err); +} + void hmp_object_add(Monitor *mon, const QDict *qdict) { Error *err = NULL; From patchwork Thu Dec 24 01:09:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Chen X-Patchwork-Id: 11989109 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.4 required=3.0 tests=BAYES_00,FROM_WSP_TRAIL, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 99826C433DB for ; Thu, 24 Dec 2020 01:16:27 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 2AE3D22517 for ; Thu, 24 Dec 2020 01:16:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2AE3D22517 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=intel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:34524 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ksFEw-0002qw-Bw for qemu-devel@archiver.kernel.org; Wed, 23 Dec 2020 20:16:26 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42382) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ksFCH-0001XA-1a for qemu-devel@nongnu.org; Wed, 23 Dec 2020 20:13:41 -0500 Received: from mga06.intel.com ([134.134.136.31]:46595) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ksFCF-0004bX-9R for qemu-devel@nongnu.org; Wed, 23 Dec 2020 20:13:40 -0500 IronPort-SDR: q2JkD8txv8gTyEtczXUFcc6UzfejFV9qnv10WDz9YtNQlau4y39rtxjSXCJR9b8vjkKN2mlsjF Dqk+Fr4RYLtA== X-IronPort-AV: E=McAfee;i="6000,8403,9844"; a="237652010" X-IronPort-AV: E=Sophos;i="5.78,443,1599548400"; d="scan'208";a="237652010" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Dec 2020 17:13:22 -0800 IronPort-SDR: 2/eLm4uw9NezWb+g5hc+pKBOfqaIUPFmlhvwsgzl0oSruMLbrwerYFd2uH1+0K/NIoDdBMLjFs mvFQNITptJHg== X-IronPort-AV: E=Sophos;i="5.78,443,1599548400"; d="scan'208";a="565580046" Received: from unknown (HELO localhost.localdomain) ([10.239.13.19]) by fmsmga005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Dec 2020 17:13:20 -0800 From: Zhang Chen To: Jason Wang , qemu-dev , Eric Blake , "Dr. David Alan Gilbert" , Markus Armbruster Subject: [PATCH 3/3] net/colo-compare: Add handler for passthrough connection Date: Thu, 24 Dec 2020 09:09:18 +0800 Message-Id: <20201224010918.19275-4-chen.zhang@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201224010918.19275-1-chen.zhang@intel.com> References: <20201224010918.19275-1-chen.zhang@intel.com> Received-SPF: pass client-ip=134.134.136.31; envelope-from=chen.zhang@intel.com; helo=mga06.intel.com X-Spam_score_int: 14 X-Spam_score: 1.4 X-Spam_bar: + X-Spam_report: (1.4 / 5.0 requ) BAYES_00=-1.9, FROM_ADDR_WS=2.999, FROM_WSP_TRAIL=2.3, HEADER_FROM_DIFFERENT_DOMAINS=0.25, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Zhang Chen Currently, we just use guest's TCP/UDP source port as the key to bypass certain network traffic. Signed-off-by: Zhang Chen --- net/colo-compare.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++ net/colo-compare.h | 2 ++ net/net.c | 27 +++++++++++++++++++++++++ 3 files changed, 78 insertions(+) diff --git a/net/colo-compare.c b/net/colo-compare.c index 337025b44f..11a32caa9b 100644 --- a/net/colo-compare.c +++ b/net/colo-compare.c @@ -46,6 +46,9 @@ static QTAILQ_HEAD(, CompareState) net_compares = static NotifierList colo_compare_notifiers = NOTIFIER_LIST_INITIALIZER(colo_compare_notifiers); +static QLIST_HEAD(, PassthroughEntry) passthroughlist = + QLIST_HEAD_INITIALIZER(passthroughlist); + #define COMPARE_READ_LEN_MAX NET_BUFSIZE #define MAX_QUEUE_SIZE 1024 @@ -103,6 +106,12 @@ typedef struct SendEntry { uint8_t *buf; } SendEntry; +typedef struct PassthroughEntry { + bool is_tcp; + uint16_t port; + QLIST_ENTRY(PassthroughEntry) node; +} PassthroughEntry; + struct CompareState { Object parent; @@ -247,6 +256,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) { @@ -264,8 +274,23 @@ static int packet_enqueue(CompareState *s, int mode, Connection **con) pkt = NULL; return -1; } + fill_connection_key(pkt, &key); + /* Check COLO passthrough connenction */ + if (!QLIST_EMPTY(&passthroughlist)) { + QLIST_FOREACH_SAFE(bypass, &passthroughlist, node, next) { + if (((key.ip_proto == IPPROTO_TCP) && bypass->is_tcp) || + ((key.ip_proto == IPPROTO_UDP) && !bypass->is_tcp)) { + if (bypass->port == key.src_port) { + packet_destroy(pkt, NULL); + pkt = NULL; + return -1; + } + } + } + } + conn = connection_get(s->connection_track_table, &key, &s->conn_list); @@ -1373,6 +1398,30 @@ static void colo_flush_packets(void *opaque, void *user_data) } } +void colo_compare_passthrough_add(bool is_tcp, const uint16_t port) +{ + PassthroughEntry *bypass = NULL; + + bypass = g_new0(PassthroughEntry, 1); + bypass->is_tcp = is_tcp; + bypass->port = port; + QLIST_INSERT_HEAD(&passthroughlist, bypass, node); +} + +void colo_compare_passthrough_del(bool is_tcp, const uint16_t port) +{ + PassthroughEntry *bypass = NULL, *next = NULL; + + if (!QLIST_EMPTY(&passthroughlist)) { + QLIST_FOREACH_SAFE(bypass, &passthroughlist, node, next) { + if ((bypass->is_tcp == is_tcp) && (bypass->port == port)) { + QLIST_REMOVE(bypass, node); + g_free(bypass); + } + } + } +} + static void colo_compare_class_init(ObjectClass *oc, void *data) { UserCreatableClass *ucc = USER_CREATABLE_CLASS(oc); diff --git a/net/colo-compare.h b/net/colo-compare.h index 22ddd512e2..1fa026c85e 100644 --- a/net/colo-compare.h +++ b/net/colo-compare.h @@ -20,5 +20,7 @@ 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); +void colo_compare_passthrough_add(bool is_tcp, const uint16_t port); +void colo_compare_passthrough_del(bool is_tcp, const uint16_t port); #endif /* QEMU_COLO_COMPARE_H */ diff --git a/net/net.c b/net/net.c index eac7a92618..1f303e8309 100644 --- a/net/net.c +++ b/net/net.c @@ -55,6 +55,7 @@ #include "sysemu/sysemu.h" #include "net/filter.h" #include "qapi/string-output-visitor.h" +#include "net/colo-compare.h" /* Net bridge is currently not supported for W32. */ #if !defined(_WIN32) @@ -1155,12 +1156,38 @@ void qmp_colo_passthrough_add(const char *prot, const uint32_t port, Error **errp) { /* Setup passthrough connection */ + if (port > 65536) { + error_setg(errp, "COLO pass through get wrong port"); + return; + } + + if (!strcmp(prot, "tcp") || !strcmp(prot, "TCP")) { + colo_compare_passthrough_add(true, (uint16_t)port); + } else if (!strcmp(prot, "udp") || !strcmp(prot, "UDP")) { + colo_compare_passthrough_add(false, (uint16_t)port); + } else { + error_setg(errp, "COLO pass through just support tcp or udp protocol"); + return; + } } void qmp_colo_passthrough_del(const char *prot, const uint32_t port, Error **errp) { /* Delete passthrough connection */ + if (port > 65536) { + error_setg(errp, "COLO pass through get wrong port"); + return; + } + + if (!strcmp(prot, "tcp") || !strcmp(prot, "TCP")) { + colo_compare_passthrough_del(true, (uint16_t)port); + } else if (!strcmp(prot, "udp") || !strcmp(prot, "UDP")) { + colo_compare_passthrough_del(false, (uint16_t)port); + } else { + error_setg(errp, "COLO pass through just support tcp or udp protocol"); + return; + } } static void netfilter_print_info(Monitor *mon, NetFilterState *nf)