Patchwork [38/44] net: add qemu_foreach_nic()

login
register
mail settings
Submitter Mark McLoughlin
Date Nov. 25, 2009, 6:49 p.m.
Message ID <1259174977-26212-39-git-send-email-markmc@redhat.com>
Download mbox | patch
Permalink /patch/39439/
State New
Headers show

Comments

Mark McLoughlin - Nov. 25, 2009, 6:49 p.m.
Signed-off-by: Mark McLoughlin <markmc@redhat.com>
---
 net.c |   20 ++++++++++++++++++++
 net.h |    2 ++
 2 files changed, 22 insertions(+), 0 deletions(-)

Patch

diff --git a/net.c b/net.c
index a1ec243..c71699d 100644
--- a/net.c
+++ b/net.c
@@ -326,6 +326,26 @@  qemu_find_vlan_client_by_name(Monitor *mon, int vlan_id,
     return vc;
 }
 
+void qemu_foreach_nic(qemu_nic_foreach func, void *opaque)
+{
+    VLANClientState *nc;
+    VLANState *vlan;
+
+    QTAILQ_FOREACH(nc, &non_vlan_clients, next) {
+        if (nc->info->type == NET_CLIENT_TYPE_NIC) {
+            func(DO_UPCAST(NICState, nc, nc), opaque);
+        }
+    }
+
+    QTAILQ_FOREACH(vlan, &vlans, next) {
+        QTAILQ_FOREACH(nc, &vlan->clients, next) {
+            if (nc->info->type == NET_CLIENT_TYPE_NIC) {
+                func(DO_UPCAST(NICState, nc, nc), opaque);
+            }
+        }
+    }
+}
+
 int qemu_can_send_packet(VLANClientState *sender)
 {
     VLANState *vlan = sender->vlan;
diff --git a/net.h b/net.h
index 497a737..d583d59 100644
--- a/net.h
+++ b/net.h
@@ -95,6 +95,8 @@  NICState *qemu_new_nic(NetClientInfo *info,
 void qemu_del_vlan_client(VLANClientState *vc);
 VLANClientState *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);
 int qemu_can_send_packet(VLANClientState *vc);
 ssize_t qemu_sendv_packet(VLANClientState *vc, const struct iovec *iov,
                           int iovcnt);