mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-03 15:53:54 -06:00
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>
This commit is contained in:
parent
3aa1b7af0f
commit
d32ad10a14
12 changed files with 477 additions and 9 deletions
30
net/net.c
30
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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue