From patchwork Fri Aug 21 04:30:08 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Hongyang X-Patchwork-Id: 509283 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 D0B61140129 for ; Fri, 21 Aug 2015 14:35:13 +1000 (AEST) Received: from localhost ([::1]:39674 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZSe2p-00037k-Nc for incoming@patchwork.ozlabs.org; Fri, 21 Aug 2015 00:35:11 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37370) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZSdzo-0006XU-Az for qemu-devel@nongnu.org; Fri, 21 Aug 2015 00:32:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZSdzm-00042O-VQ for qemu-devel@nongnu.org; Fri, 21 Aug 2015 00:32:04 -0400 Received: from [59.151.112.132] (port=5740 helo=heian.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZSdzm-0003xh-IB for qemu-devel@nongnu.org; Fri, 21 Aug 2015 00:32:02 -0400 X-IronPort-AV: E=Sophos;i="5.15,520,1432569600"; d="scan'208";a="99873543" Received: from unknown (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 21 Aug 2015 12:35:14 +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 t7L4VtCP013005; Fri, 21 Aug 2015 12:31:55 +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; Fri, 21 Aug 2015 12:31:59 +0800 From: Yang Hongyang To: Date: Fri, 21 Aug 2015 12:30:08 +0800 Message-ID: <1440131412-7330-8-git-send-email-yanghy@cn.fujitsu.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1440131412-7330-1-git-send-email-yanghy@cn.fujitsu.com> References: <1440131412-7330-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, mrhines@linux.vnet.ibm.com, Yang Hongyang , stefanha@redhat.com Subject: [Qemu-devel] [PATCH v7 07/11] 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. Signed-off-by: Yang Hongyang --- 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 9278d40..188ecb1 100644 --- a/include/net/filter.h +++ b/include/net/filter.h @@ -56,6 +56,7 @@ NetFilterState *qemu_new_net_filter(NetFilterInfo *info, void qemu_del_net_filter(NetFilterState *nf); void netfilter_add(QemuOpts *opts, Error **errp); void qmp_netfilter_add(QDict *qdict, QObject **ret, 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 24d2d62..f790774 100644 --- a/net/filter.c +++ b/net/filter.c @@ -22,6 +22,28 @@ static QTAILQ_HEAD(, NetFilterState) net_filters; +const char *qemu_netfilter_get_chain_str(int chain) +{ + const char *str = NULL; + + 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..99f0e87 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, + NetFilterOptionsKind_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,