From: Yang Hongyang <bur...@gmail.com>

When execute "info network", print filter info also.
current info printed is simple, can add more info later.

Signed-off-by: Yang Hongyang <yan...@cn.fujitsu.com>
---
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 2504bf8..d29a7ea 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,
-- 
1.9.1


Reply via email to