From patchwork Wed Oct 7 03:52:19 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Hongyang X-Patchwork-Id: 527101 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 08E37140DA4 for ; Wed, 7 Oct 2015 14:56:55 +1100 (AEDT) Received: from localhost ([::1]:55112 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZjfqW-0003vT-Nb for incoming@patchwork.ozlabs.org; Tue, 06 Oct 2015 23:56:52 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40855) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zjfml-0005uf-LO for qemu-devel@nongnu.org; Tue, 06 Oct 2015 23:53:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zjfmk-0003xC-D7 for qemu-devel@nongnu.org; Tue, 06 Oct 2015 23:52:59 -0400 Received: from [59.151.112.132] (port=13189 helo=heian.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zjfmj-0003tn-G7 for qemu-devel@nongnu.org; Tue, 06 Oct 2015 23:52:58 -0400 X-IronPort-AV: E=Sophos;i="5.15,520,1432569600"; d="scan'208";a="101428749" Received: from unknown (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 07 Oct 2015 11:55:28 +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 t973qVus023503; Wed, 7 Oct 2015 11:52:31 +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; Wed, 7 Oct 2015 11:52:55 +0800 From: Yang Hongyang To: Date: Wed, 7 Oct 2015 11:52:19 +0800 Message-ID: <1444189942-21787-8-git-send-email-yanghy@cn.fujitsu.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1444189942-21787-1-git-send-email-yanghy@cn.fujitsu.com> References: <1444189942-21787-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, Yang Hongyang , stefanha@redhat.com, Yang Hongyang Subject: [Qemu-devel] [PATCH v13 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. add a info_str member to NetFilterState, store specific filters info. Signed-off-by: Yang Hongyang Signed-off-by: Jason Wang --- include/net/filter.h | 1 + net/filter.c | 20 ++++++++++++++++++++ net/net.c | 11 +++++++++++ 3 files changed, 32 insertions(+) diff --git a/include/net/filter.h b/include/net/filter.h index 5639976..2deda36 100644 --- a/include/net/filter.h +++ b/include/net/filter.h @@ -55,6 +55,7 @@ struct NetFilterState { char *netdev_id; NetClientState *netdev; NetFilterDirection direction; + char info_str[256]; QTAILQ_ENTRY(NetFilterState) next; }; diff --git a/net/filter.c b/net/filter.c index 5d5022f..326f2b5 100644 --- a/net/filter.c +++ b/net/filter.c @@ -15,6 +15,7 @@ #include "net/vhost_net.h" #include "qom/object_interfaces.h" #include "qemu/iov.h" +#include "qapi/string-output-visitor.h" ssize_t qemu_netfilter_receive(NetFilterState *nf, NetFilterDirection direction, @@ -134,6 +135,9 @@ static void netfilter_complete(UserCreatable *uc, Error **errp) NetFilterClass *nfc = NETFILTER_GET_CLASS(uc); int queues; Error *local_err = NULL; + char *str, *info; + ObjectProperty *prop; + StringOutputVisitor *ov; if (!nf->netdev_id) { error_setg(errp, "Parameter 'netdev' is required"); @@ -167,6 +171,22 @@ static void netfilter_complete(UserCreatable *uc, Error **errp) } } QTAILQ_INSERT_TAIL(&nf->netdev->filters, nf, next); + + /* generate info str */ + QTAILQ_FOREACH(prop, &OBJECT(nf)->properties, node) { + if (!strcmp(prop->name, "type")) { + continue; + } + ov = string_output_visitor_new(false); + object_property_get(OBJECT(nf), string_output_get_visitor(ov), + prop->name, errp); + str = string_output_get_string(ov); + string_output_visitor_cleanup(ov); + info = g_strdup_printf(",%s=%s", prop->name, str); + g_strlcat(nf->info_str, info, sizeof(nf->info_str)); + g_free(str); + g_free(info); + } } static void netfilter_finalize(Object *obj) diff --git a/net/net.c b/net/net.c index c0ebb13..39af893 100644 --- a/net/net.c +++ b/net/net.c @@ -1179,10 +1179,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%s\n", + object_get_canonical_path_component(OBJECT(nf)), + object_get_typename(OBJECT(nf)), + nf->info_str); + } } RxFilterInfoList *qmp_query_rx_filter(bool has_name, const char *name,