diff mbox

[COLO-Frame,v14,36/40] net/filter: Add a helper to traverse all the filters

Message ID 1454750932-7556-37-git-send-email-zhang.zhanghailiang@huawei.com (mailing list archive)
State New, archived
Headers show

Commit Message

Zhanghailiang Feb. 6, 2016, 9:28 a.m. UTC
Add a new API qemu_foreach_netfilter(), it will traverse
all the filters, and call the callback function.

Signed-off-by: zhanghailiang <zhang.zhanghailiang@huawei.com>
Cc: Jason Wang <jasowang@redhat.com>
Cc: Yang Hongyang <hongyang.yang@easystack.cn>
---
v14:
 - New patch split from previous version.
---
 include/net/net.h |  4 ++++
 net/net.c         | 24 ++++++++++++++++++++++++
 2 files changed, 28 insertions(+)
diff mbox

Patch

diff --git a/include/net/net.h b/include/net/net.h
index f6f0194..d4e5100 100644
--- a/include/net/net.h
+++ b/include/net/net.h
@@ -125,6 +125,10 @@  NetClientState *qemu_find_vlan_client_by_name(Monitor *mon, int vlan_id,
                                               const char *client_str);
 typedef void (*qemu_nic_foreach)(NICState *nic, void *opaque);
 void qemu_foreach_nic(qemu_nic_foreach func, void *opaque);
+typedef void (*qemu_netfilter_foreach)(NetFilterState *nf, void *opaque,
+                                       Error **errp);
+void qemu_foreach_netfilter(qemu_netfilter_foreach func, void *opaque,
+                            Error **errp);
 int qemu_can_send_packet(NetClientState *nc);
 ssize_t qemu_sendv_packet(NetClientState *nc, const struct iovec *iov,
                           int iovcnt);
diff --git a/net/net.c b/net/net.c
index 36f8345..f5007e5 100644
--- a/net/net.c
+++ b/net/net.c
@@ -268,6 +268,30 @@  static char *assign_name(NetClientState *nc1, const char *model)
     return g_strdup_printf("%s.%d", model, id);
 }
 
+void qemu_foreach_netfilter(qemu_netfilter_foreach func, void *opaque,
+                            Error **errp)
+{
+    NetClientState *nc;
+    NetFilterState *nf;
+
+    QTAILQ_FOREACH(nc, &net_clients, next) {
+        if (nc->info->type == NET_CLIENT_OPTIONS_KIND_NIC) {
+            continue;
+        }
+
+        QTAILQ_FOREACH(nf, &nc->filters, next) {
+            if (func) {
+                Error *local_err = NULL;
+
+                func(nf, opaque, &local_err);
+                if (local_err) {
+                    error_propagate(errp, local_err);
+                    return;
+                }
+            }
+        }
+    }
+}
 static void qemu_net_client_destructor(NetClientState *nc)
 {
     g_free(nc);