From patchwork Fri Jan 22 08:36:50 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhanghailiang X-Patchwork-Id: 8088331 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id A688B9F1CC for ; Fri, 22 Jan 2016 08:41:21 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id EF4DB20434 for ; Fri, 22 Jan 2016 08:41:20 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 295F7202B8 for ; Fri, 22 Jan 2016 08:41:20 +0000 (UTC) Received: from localhost ([::1]:51327 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aMXHT-0007OF-Jl for patchwork-qemu-devel@patchwork.kernel.org; Fri, 22 Jan 2016 03:41:19 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56902) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aMXFs-0005Ih-Be for qemu-devel@nongnu.org; Fri, 22 Jan 2016 03:39:41 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aMXFr-0003Ui-AA for qemu-devel@nongnu.org; Fri, 22 Jan 2016 03:39:40 -0500 Received: from szxga03-in.huawei.com ([119.145.14.66]:3134) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aMXFq-0002xW-Og for qemu-devel@nongnu.org; Fri, 22 Jan 2016 03:39:39 -0500 Received: from 172.24.1.47 (EHLO szxeml432-hub.china.huawei.com) ([172.24.1.47]) by szxrg03-dlp.huawei.com (MOS 4.4.3-GA FastPath queued) with ESMTP id BVC00644; Fri, 22 Jan 2016 16:37:27 +0800 (CST) Received: from localhost (10.177.24.212) by szxeml432-hub.china.huawei.com (10.82.67.209) with Microsoft SMTP Server id 14.3.235.1; Fri, 22 Jan 2016 16:37:09 +0800 From: zhanghailiang To: Date: Fri, 22 Jan 2016 16:36:50 +0800 Message-ID: <1453451811-11860-7-git-send-email-zhang.zhanghailiang@huawei.com> X-Mailer: git-send-email 1.9.0.msysgit.0 In-Reply-To: <1453451811-11860-1-git-send-email-zhang.zhanghailiang@huawei.com> References: <1453451811-11860-1-git-send-email-zhang.zhanghailiang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.177.24.212] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020201.56A1EA47.0157, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2013-05-26 15:14:31, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 8262336c98033a9e7fc1a9be330a1225 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 119.145.14.66 Cc: zhanghailiang , jasowang@redhat.com, zhangchen.fnst@cn.fujitsu.com, hongyang.yang@easystack.cn Subject: [Qemu-devel] [PATCH RFC 6/7] net/filter: Add a default filter to each netdev X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP We add each netdev a default buffer filter, which the name is 'nop', and the default buffer filter is disabled, so it has no side effect for packets delivering in qemu net layer. The default buffer filter can be used by COLO or Micro-checkpoint, The reason we add the default filter is we hope to support hot add network during COLO state in future. Signed-off-by: zhanghailiang --- include/net/filter.h | 11 +++++++++++ net/dump.c | 2 -- net/filter.c | 15 ++++++++++++++- net/net.c | 18 ++++++++++++++++++ 4 files changed, 43 insertions(+), 3 deletions(-) diff --git a/include/net/filter.h b/include/net/filter.h index c7bd8f9..2043609 100644 --- a/include/net/filter.h +++ b/include/net/filter.h @@ -22,6 +22,16 @@ #define NETFILTER_CLASS(klass) \ OBJECT_CLASS_CHECK(NetFilterClass, (klass), TYPE_NETFILTER) +#define DEFAULT_FILTER_NAME "nop" + +#define TYPE_FILTER_BUFFER "filter-buffer" +#define TYPE_FILTER_DUMP "filter-dump" + +#define NETFILTER_ID_BUFFER 1 +#define NETFILTER_ID_DUMP 2 + +extern const char *const netfilter_type_lookup[]; + typedef void (FilterSetup) (NetFilterState *nf, Error **errp); typedef void (FilterCleanup) (NetFilterState *nf); /* @@ -55,6 +65,7 @@ struct NetFilterState { char *netdev_id; NetClientState *netdev; NetFilterDirection direction; + bool is_default; bool enabled; QTAILQ_ENTRY(NetFilterState) next; }; diff --git a/net/dump.c b/net/dump.c index 88d9582..82727a6 100644 --- a/net/dump.c +++ b/net/dump.c @@ -229,8 +229,6 @@ int net_init_dump(const NetClientOptions *opts, const char *name, /* Dumping via filter */ -#define TYPE_FILTER_DUMP "filter-dump" - #define FILTER_DUMP(obj) \ OBJECT_CHECK(NetFilterDumpState, (obj), TYPE_FILTER_DUMP) diff --git a/net/filter.c b/net/filter.c index 4d96301..a126a3b 100644 --- a/net/filter.c +++ b/net/filter.c @@ -21,6 +21,11 @@ #include "qapi/qmp-input-visitor.h" #include "monitor/monitor.h" +const char *const netfilter_type_lookup[] = { + [NETFILTER_ID_BUFFER] = TYPE_FILTER_BUFFER, + [NETFILTER_ID_DUMP] = TYPE_FILTER_DUMP, +}; + ssize_t qemu_netfilter_receive(NetFilterState *nf, NetFilterDirection direction, NetClientState *sender, @@ -200,7 +205,7 @@ static void netfilter_complete(UserCreatable *uc, Error **errp) NetFilterClass *nfc = NETFILTER_GET_CLASS(uc); int queues; Error *local_err = NULL; - + char *path = object_get_canonical_path_component(OBJECT(nf)); if (!nf->netdev_id) { error_setg(errp, "Parameter 'netdev' is required"); @@ -225,6 +230,14 @@ static void netfilter_complete(UserCreatable *uc, Error **errp) } nf->netdev = ncs[0]; + nf->is_default = !strcmp(path, DEFAULT_FILTER_NAME); + /* + * For the default buffer filter, it will be disabled by default, + * So it will not buffer any packets. + */ + if (nf->is_default) { + nf->enabled = false; + } if (nfc->setup) { nfc->setup(nf, &local_err); diff --git a/net/net.c b/net/net.c index ec43105..9630234 100644 --- a/net/net.c +++ b/net/net.c @@ -76,6 +76,12 @@ const char *host_net_devices[] = { int default_net = 1; +/* + * FIXME: Export this with an option for users to control + * this with comand line ? + */ +int default_netfilter = NETFILTER_ID_BUFFER; + /***********************************************************/ /* network device redirectors */ @@ -1032,6 +1038,18 @@ static int net_client_init1(const void *object, int is_netdev, Error **errp) } return -1; } + + if (is_netdev) { + const Netdev *netdev = object; + /* + * Here we add each netdev a default filter whose name is 'nop', + * it will disabled by default, Users can enable it when necessary. + */ + netdev_add_filter(netdev->id, + netfilter_type_lookup[default_netfilter], + DEFAULT_FILTER_NAME, + errp); + } return 0; }