aboutsummaryrefslogtreecommitdiff
path: root/net
diff options
context:
space:
mode:
authorAlexey Kirillov <lekiravi@yandex-team.ru>2021-03-03 12:59:09 +0300
committerJason Wang <jasowang@redhat.com>2021-03-15 16:41:22 +0800
commita0724776c5a98a08fc946bb5a4ad16410ca64c0e (patch)
tree91c98dcf9fa6d9a2497e2133f4f6dcb73c4640c7 /net
parent59b5437eb732d6b103a9bc279c3482c834d1eff9 (diff)
hmp: Use QAPI NetdevInfo in hmp_info_network
Replace usage of legacy field info_str of NetClientState for backend network devices with QAPI NetdevInfo stored_config that already used in QMP query-netdev. This change increases the detail of the "info network" output and takes a more general approach to composing the output. NIC and hubports still use legacy info_str field. Signed-off-by: Alexey Kirillov <lekiravi@yandex-team.ru> Signed-off-by: Jason Wang <jasowang@redhat.com>
Diffstat (limited to 'net')
-rw-r--r--net/net.c31
1 files changed, 30 insertions, 1 deletions
diff --git a/net/net.c b/net/net.c
index 277da712eb..725a4e1450 100644
--- a/net/net.c
+++ b/net/net.c
@@ -55,6 +55,7 @@
#include "sysemu/sysemu.h"
#include "net/filter.h"
#include "qapi/string-output-visitor.h"
+#include "qapi/hmp-output-visitor.h"
/* Net bridge is currently not supported for W32. */
#if !defined(_WIN32)
@@ -1221,14 +1222,42 @@ static void netfilter_print_info(Monitor *mon, NetFilterState *nf)
monitor_printf(mon, "\n");
}
+static char *generate_info_str(NetClientState *nc)
+{
+ NetdevInfo *ni = nc->stored_config;
+ char *ret_out = NULL;
+ Visitor *v;
+
+ /* Use legacy field info_str for NIC and hubports */
+ if ((nc->info->type == NET_CLIENT_DRIVER_NIC) ||
+ (nc->info->type == NET_CLIENT_DRIVER_HUBPORT)) {
+ return g_strdup(nc->info_str ? nc->info_str : "");
+ }
+
+ if (!ni) {
+ return g_malloc0(1);
+ }
+
+ v = hmp_output_visitor_new(&ret_out);
+ if (visit_type_NetdevInfo(v, "", &ni, NULL)) {
+ visit_complete(v, &ret_out);
+ }
+ visit_free(v);
+
+ return ret_out;
+}
+
void print_net_client(Monitor *mon, NetClientState *nc)
{
NetFilterState *nf;
+ char *info_str = generate_info_str(nc);
monitor_printf(mon, "%s: index=%d,type=%s,%s\n", nc->name,
nc->queue_index,
NetClientDriver_str(nc->info->type),
- nc->info_str ? nc->info_str : "");
+ info_str);
+ g_free(info_str);
+
if (!QTAILQ_EMPTY(&nc->filters)) {
monitor_printf(mon, "filters:\n");
}