Signed-off-by: Miguel Di Ciurcio Filho <miguel.fi...@gmail.com> --- monitor.c | 8 +++++ net.c | 96 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ net.h | 2 + 3 files changed, 106 insertions(+), 0 deletions(-)
diff --git a/monitor.c b/monitor.c index 15b53b9..0038214 100644 --- a/monitor.c +++ b/monitor.c @@ -2425,6 +2425,14 @@ static const mon_cmd_t info_cmds[] = { .mhandler.info = do_info_network, }, { + .name = "netdev", + .args_type = "", + .params = "", + .help = "show information about network backend devices", + .user_print = do_info_netdev_print, + .mhandler.info_new = do_info_netdev, + }, + { .name = "chardev", .args_type = "", .params = "", diff --git a/net.c b/net.c index 4cb93ed..ed68b61 100644 --- a/net.c +++ b/net.c @@ -36,6 +36,8 @@ #include "qemu-common.h" #include "qemu_socket.h" #include "hw/qdev.h" +#include "qdict.h" +#include "qjson.h" static QTAILQ_HEAD(, VLANState) vlans; static QTAILQ_HEAD(, VLANClientState) non_vlan_clients; @@ -1252,6 +1254,100 @@ void do_info_network(Monitor *mon) } } +static void netdev_iter(QObject *obj, void *opaque) +{ + + Monitor *mon = opaque; + QDict *net_device = qobject_to_qdict(obj); + + monitor_printf(mon, "%s: ", qdict_get_str(net_device, "id")); + + monitor_printf(mon, "type=%s,", qdict_get_str(net_device, "type")); + + if (qdict_haskey(net_device, "vlan")) { + monitor_printf(mon, "vlan=%d,", (int)qdict_get_int(net_device, "vlan")); + } + + if (qdict_haskey(net_device, "peer")) { + monitor_printf(mon, "peer=%s,", qdict_get_str(net_device, "peer")); + } + + monitor_printf(mon, + qstring_get_str(qdict_to_qstring(qdict_get_qdict(net_device, +"info"), ","))); + + monitor_printf(mon, "\n"); + +} + +void do_info_netdev_print(Monitor *mon, const QObject *ret_data) +{ + + QList *net_devices; + + net_devices = qobject_to_qlist(ret_data); + + qlist_iter(net_devices, netdev_iter, mon); + +} + +void do_info_netdev(Monitor *mon, QObject **ret_data) +{ + VLANState *vlan; + VLANClientState *vc; + QDict *net_device; + QList *device_list; + device_list = qlist_new(); + QObject *obj; + + QTAILQ_FOREACH(vlan, &vlans, next) { + + QTAILQ_FOREACH(vc, &vlan->clients, next) { + + if (vc->info->type == NET_CLIENT_TYPE_NONE || + vc->info->type == NET_CLIENT_TYPE_NIC || + vc->info->type == NET_CLIENT_TYPE_DUMP) { + continue; + } + + obj = qobject_from_jsonf("{ 'vlan': %d, 'id': %s, 'type': %s}", vlan->id, + vc->name, vc->model); + + net_device = qobject_to_qdict(obj); + + QINCREF(vc->info_dict); + qdict_put(net_device, "info", vc->info_dict); + + qlist_append(device_list, net_device); + } + } + + QTAILQ_FOREACH(vc, &non_vlan_clients, next) { + + if (vc->info->type == NET_CLIENT_TYPE_NONE || + vc->info->type == NET_CLIENT_TYPE_NIC || + vc->info->type == NET_CLIENT_TYPE_DUMP) { + continue; + } + + obj = qobject_from_jsonf("{'id': %s, 'type': %s}", + vc->name, vc->model); + + net_device = qobject_to_qdict(obj); + + QINCREF(vc->info_dict); + qdict_put(net_device, "info", vc->info_dict); + + if (vc->peer) { + qdict_put(net_device, "peer", qstring_from_str(vc->peer->name)); + } + + qlist_append(device_list, net_device); + } + + *ret_data = QOBJECT(device_list); +} + int do_set_link(Monitor *mon, const QDict *qdict, QObject **ret_data) { VLANState *vlan; diff --git a/net.h b/net.h index acc1645..65bbf27 100644 --- a/net.h +++ b/net.h @@ -119,6 +119,8 @@ int qemu_find_nic_model(NICInfo *nd, const char * const *models, const char *default_model); void do_info_network(Monitor *mon); +void do_info_netdev_print(Monitor *mon, const QObject *ret_data); +void do_info_netdev(Monitor *mon, QObject **ret_data); int do_set_link(Monitor *mon, const QDict *qdict, QObject **ret_data); /* NIC info */ -- 1.7.1