From patchwork Tue Sep 1 09:06:20 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Hongyang X-Patchwork-Id: 512742 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 825FB14076A for ; Tue, 1 Sep 2015 19:09:54 +1000 (AEST) Received: from localhost ([::1]:51702 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZWhZg-0001jB-Nf for incoming@patchwork.ozlabs.org; Tue, 01 Sep 2015 05:09:52 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45068) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZWhWl-0005CC-Ue for qemu-devel@nongnu.org; Tue, 01 Sep 2015 05:06:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZWhWk-0000bt-QB for qemu-devel@nongnu.org; Tue, 01 Sep 2015 05:06:51 -0400 Received: from [59.151.112.132] (port=7111 helo=heian.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZWhWk-0000W8-E5 for qemu-devel@nongnu.org; Tue, 01 Sep 2015 05:06:50 -0400 X-IronPort-AV: E=Sophos;i="5.15,520,1432569600"; d="scan'208";a="100234399" Received: from bogon (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 01 Sep 2015 17:09:47 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (localhost.localdomain [127.0.0.1]) by edo.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id t8196Xsr028917; Tue, 1 Sep 2015 17:06:33 +0800 Received: from localhost (10.167.226.223) by G08CNEXCHPEKD02.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.181.6; Tue, 1 Sep 2015 17:06:41 +0800 From: Yang Hongyang To: Date: Tue, 1 Sep 2015 17:06:20 +0800 Message-ID: <1441098383-22585-8-git-send-email-yanghy@cn.fujitsu.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1441098383-22585-1-git-send-email-yanghy@cn.fujitsu.com> References: <1441098383-22585-1-git-send-email-yanghy@cn.fujitsu.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 59.151.112.132 Cc: thuth@redhat.com, zhang.zhanghailiang@huawei.com, lizhijian@cn.fujitsu.com, jasowang@redhat.com, armbru@redhat.com, mrhines@linux.vnet.ibm.com, Yang Hongyang , stefanha@redhat.com, Yang Hongyang Subject: [Qemu-devel] [PATCH v9 07/10] netfilter: print filter info associate with the 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Yang Hongyang When execute "info network", print filter info also. current info printed is simple, can add more info later. Signed-off-by: Yang Hongyang --- v9: tiny cleanup according to Tomas's comment. v7: initial patch --- include/net/filter.h | 1 + net/filter.c | 22 ++++++++++++++++++++++ net/net.c | 11 +++++++++++ 3 files changed, 34 insertions(+) diff --git a/include/net/filter.h b/include/net/filter.h index d1aafbe..e29c8a4 100644 --- a/include/net/filter.h +++ b/include/net/filter.h @@ -55,6 +55,7 @@ NetFilterState *qemu_new_net_filter(NetFilterInfo *info, int chain); void qemu_del_net_filter(NetFilterState *nf); void netfilter_add(QemuOpts *opts, Error **errp); +const char *qemu_netfilter_get_chain_str(int chain); /* pass the packet to the next filter */ ssize_t qemu_netfilter_pass_to_next(NetFilterState *nf, NetPacket *packet); diff --git a/net/filter.c b/net/filter.c index 53bb8c4..570813c 100644 --- a/net/filter.c +++ b/net/filter.c @@ -24,6 +24,28 @@ static QTAILQ_HEAD(, NetFilterState) net_filters; +const char *qemu_netfilter_get_chain_str(int chain) +{ + const char *str; + + switch (chain) { + case NET_FILTER_IN: + str = "in"; + break; + case NET_FILTER_OUT: + str = "out"; + break; + case NET_FILTER_ALL: + str = "all"; + break; + default: + str = "unknown"; + break; + } + + return str; +} + NetFilterState *qemu_new_net_filter(NetFilterInfo *info, NetClientState *netdev, const char *name, diff --git a/net/net.c b/net/net.c index 00cca83..06f2cce 100644 --- a/net/net.c +++ b/net/net.c @@ -1199,10 +1199,21 @@ void qmp_netdev_del(const char *id, Error **errp) void print_net_client(Monitor *mon, NetClientState *nc) { + NetFilterState *nf; + monitor_printf(mon, "%s: index=%d,type=%s,%s\n", nc->name, nc->queue_index, NetClientOptionsKind_lookup[nc->info->type], nc->info_str); + if (!QTAILQ_EMPTY(&nc->filters)) { + monitor_printf(mon, "filters:\n"); + } + QTAILQ_FOREACH(nf, &nc->filters, next) { + monitor_printf(mon, " - %s: type=%s,netdev=%s,chain=%s\n", nf->name, + NetFilterType_lookup[nf->info->type], + nf->netdev->name, + qemu_netfilter_get_chain_str(nf->chain)); + } } RxFilterInfoList *qmp_query_rx_filter(bool has_name, const char *name,