qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH v4 02/10] net: introduce qemu_nic_format_info_dict a


From: Miguel Di Ciurcio Filho
Subject: [Qemu-devel] [PATCH v4 02/10] net: introduce qemu_nic_format_info_dict and VLANClientState->info_dict
Date: Tue, 18 May 2010 14:07:41 -0300

There is no standard format when formatting VLANClientState.info_str,
so it is difficult to extract information and transmit it over QMP.

This patch adds info_dict, a QDict to better handle the information
of a NIC.

Signed-off-by: Miguel Di Ciurcio Filho <address@hidden>
---
 net.c |   17 +++++++++++++++++
 net.h |    2 ++
 2 files changed, 19 insertions(+), 0 deletions(-)

diff --git a/net.c b/net.c
index efa8b3d..9e8a8ab 100644
--- a/net.c
+++ b/net.c
@@ -173,6 +173,22 @@ void qemu_format_nic_info_str(VLANClientState *vc, uint8_t 
macaddr[6])
              macaddr[3], macaddr[4], macaddr[5]);
 }
 
+void qemu_format_nic_info_dict(VLANClientState *vc, uint8_t macaddr[6])
+{
+    char mac[18];
+
+    if (vc->info_dict == NULL) {
+        vc->info_dict = qdict_new();
+    }
+
+    snprintf(mac, sizeof(mac), "%02x:%02x:%02x:%02x:%02x:%02x",
+             macaddr[0], macaddr[1], macaddr[2],
+             macaddr[3], macaddr[4], macaddr[5]);
+
+    qdict_put(vc->info_dict, "macaddr", qstring_from_str(mac));
+    qdict_put(vc->info_dict, "model", qstring_from_str(vc->model));
+}
+
 void qemu_macaddr_default_if_unset(MACAddr *macaddr)
 {
     static int index = 0;
@@ -301,6 +317,7 @@ void qemu_del_vlan_client(VLANClientState *vc)
 
     qemu_free(vc->name);
     qemu_free(vc->model);
+    QDECREF(vc->info_dict);
     qemu_free(vc);
 }
 
diff --git a/net.h b/net.h
index b83f615..4566f7d 100644
--- a/net.h
+++ b/net.h
@@ -66,6 +66,7 @@ struct VLANClientState {
     char *model;
     char *name;
     char info_str[256];
+    QDict *info_dict;
     unsigned receive_disabled : 1;
 };
 
@@ -111,6 +112,7 @@ ssize_t qemu_send_packet_async(VLANClientState *vc, const 
uint8_t *buf,
 void qemu_purge_queued_packets(VLANClientState *vc);
 void qemu_flush_queued_packets(VLANClientState *vc);
 void qemu_format_nic_info_str(VLANClientState *vc, uint8_t macaddr[6]);
+void qemu_format_nic_info_dict(VLANClientState *vc, uint8_t macaddr[6]);
 void qemu_macaddr_default_if_unset(MACAddr *macaddr);
 int qemu_show_nic_models(const char *arg, const char *const *models);
 void qemu_check_nic_model(NICInfo *nd, const char *model);
-- 
1.7.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]