aboutsummaryrefslogtreecommitdiff
path: root/net/net.c
diff options
context:
space:
mode:
authorAlexey Kirillov <lekiravi@yandex-team.ru>2021-03-03 12:59:06 +0300
committerJason Wang <jasowang@redhat.com>2021-03-15 16:41:22 +0800
commitd32ad10a14d46dfe9304e3ed5858a11dcd5c71a0 (patch)
treee56aaddf5e86dd29209ce958e94c0d91ad950778 /net/net.c
parent3aa1b7af0f5fbfdf1b4759658e1445bda680b40d (diff)
qapi: net: Add query-netdev command
The query-netdev command is used to get the configuration of the current network device backends (netdevs). This is the QMP analog of the HMP command "info network" but only for netdevs (i.e. excluding NIC and hubports). The query-netdev command returns an array of objects of the NetdevInfo type, which are an extension of Netdev type. It means that response can be used for netdev-add after small modification. This can be useful for recreate the same netdev configuration. Information about the network device is filled in when it is created or modified and is available through the NetClientState->stored_config. Signed-off-by: Alexey Kirillov <lekiravi@yandex-team.ru> Acked-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Jason Wang <jasowang@redhat.com>
Diffstat (limited to 'net/net.c')
-rw-r--r--net/net.c30
1 files changed, 29 insertions, 1 deletions
diff --git a/net/net.c b/net/net.c
index edf9b95418..9a2a6ab155 100644
--- a/net/net.c
+++ b/net/net.c
@@ -36,7 +36,6 @@
#include "monitor/monitor.h"
#include "qemu/help_option.h"
#include "qapi/qapi-commands-net.h"
-#include "qapi/qapi-visit-net.h"
#include "qapi/qmp/qdict.h"
#include "qapi/qmp/qerror.h"
#include "qemu/error-report.h"
@@ -353,6 +352,7 @@ static void qemu_free_net_client(NetClientState *nc)
}
g_free(nc->name);
g_free(nc->model);
+ qapi_free_NetdevInfo(nc->stored_config);
if (nc->destructor) {
nc->destructor(nc);
}
@@ -1289,6 +1289,34 @@ RxFilterInfoList *qmp_query_rx_filter(bool has_name, const char *name,
return filter_list;
}
+NetdevInfoList *qmp_query_netdev(Error **errp)
+{
+ NetdevInfoList *list = NULL;
+ NetClientState *nc;
+
+ QTAILQ_FOREACH(nc, &net_clients, next) {
+ /*
+ * Only look at netdevs (backend network devices), not for each queue
+ * or NIC / hubport
+ */
+ if (nc->stored_config) {
+ NetdevInfo *element = QAPI_CLONE(NetdevInfo, nc->stored_config);
+
+ g_free(element->id); /* Need to dealloc empty id after clone */
+ element->id = g_strdup(nc->name);
+
+ element->has_peer_id = nc->peer != NULL;
+ if (element->has_peer_id) {
+ element->peer_id = g_strdup(nc->peer->name);
+ }
+
+ QAPI_LIST_PREPEND(list, element);
+ }
+ }
+
+ return list;
+}
+
void hmp_info_network(Monitor *mon, const QDict *qdict)
{
NetClientState *nc, *peer;