mirror of https://github.com/xemu-project/xemu.git
net: Fix handling of id in netdev_add and netdev_del
CLI -netdev accumulates in option group "netdev". Before commit08712fcb85
"net: Track netdevs in NetClientState rather than QemuOpt", netdev_add added to the option group, and netdev_del removed from it, both HMP and QMP. Thus, every netdev had a corresponding QemuOpts in this option group. Commit08712fcb85
dropped this for QMP netdev_add and both netdev_del. Now a netdev has a corresponding QemuOpts only when it was created with CLI or HMP. Two issues: * QMP and HMP netdev_del can leave QemuOpts behind, breaking HMP netdev_add. Reproducer: $ qemu-system-x86_64 -S -display none -nodefaults -monitor stdio QEMU 5.1.92 monitor - type 'help' for more information (qemu) netdev_add user,id=net0 (qemu) info network net0: index=0,type=user,net=10.0.2.0,restrict=off (qemu) netdev_del net0 (qemu) info network (qemu) netdev_add user,id=net0 upstream-qemu: Duplicate ID 'net0' for netdev Try "help netdev_add" for more information Fix by restoring the QemuOpts deletion in qmp_netdev_del(), but with a guard, because the QemuOpts need not exist. * QMP netdev_add loses its "no duplicate ID" check. Reproducer: $ qemu-system-x86_64 -S -display none -qmp stdio {"QMP": {"version": {"qemu": {"micro": 92, "minor": 1, "major": 5}, "package": "v5.2.0-rc2-1-g02c1f0142c"}, "capabilities": ["oob"]}} {"execute": "qmp_capabilities"} {"return": {}} {"execute": "netdev_add", "arguments": {"type": "user", "id":"net0"}} {"return": {}} {"execute": "netdev_add", "arguments": {"type": "user", "id":"net0"}} {"return": {}} Fix by adding a duplicate ID check to net_client_init1() to replace the lost one. The check is redundant for callers where QemuOpts still checks, i.e. for CLI and HMP. Reported-by: Andrew Melnichenko <andrew@daynix.com> Fixes:08712fcb85
Cc: qemu-stable@nongnu.org Signed-off-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Signed-off-by: Jason Wang <jasowang@redhat.com>
This commit is contained in:
parent
e81eb5e6d1
commit
831734cce6
20
net/net.c
20
net/net.c
|
@ -983,6 +983,7 @@ static int (* const net_client_init_fun[NET_CLIENT_DRIVER__MAX])(
|
||||||
static int net_client_init1(const Netdev *netdev, bool is_netdev, Error **errp)
|
static int net_client_init1(const Netdev *netdev, bool is_netdev, Error **errp)
|
||||||
{
|
{
|
||||||
NetClientState *peer = NULL;
|
NetClientState *peer = NULL;
|
||||||
|
NetClientState *nc;
|
||||||
|
|
||||||
if (is_netdev) {
|
if (is_netdev) {
|
||||||
if (netdev->type == NET_CLIENT_DRIVER_NIC ||
|
if (netdev->type == NET_CLIENT_DRIVER_NIC ||
|
||||||
|
@ -1010,6 +1011,12 @@ static int net_client_init1(const Netdev *netdev, bool is_netdev, Error **errp)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nc = qemu_find_netdev(netdev->id);
|
||||||
|
if (nc) {
|
||||||
|
error_setg(errp, "Duplicate ID '%s'", netdev->id);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
if (net_client_init_fun[netdev->type](netdev, netdev->id, peer, errp) < 0) {
|
if (net_client_init_fun[netdev->type](netdev, netdev->id, peer, errp) < 0) {
|
||||||
/* FIXME drop when all init functions store an Error */
|
/* FIXME drop when all init functions store an Error */
|
||||||
if (errp && !*errp) {
|
if (errp && !*errp) {
|
||||||
|
@ -1020,8 +1027,6 @@ static int net_client_init1(const Netdev *netdev, bool is_netdev, Error **errp)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_netdev) {
|
if (is_netdev) {
|
||||||
NetClientState *nc;
|
|
||||||
|
|
||||||
nc = qemu_find_netdev(netdev->id);
|
nc = qemu_find_netdev(netdev->id);
|
||||||
assert(nc);
|
assert(nc);
|
||||||
nc->is_netdev = true;
|
nc->is_netdev = true;
|
||||||
|
@ -1135,6 +1140,7 @@ void qmp_netdev_add(Netdev *netdev, Error **errp)
|
||||||
void qmp_netdev_del(const char *id, Error **errp)
|
void qmp_netdev_del(const char *id, Error **errp)
|
||||||
{
|
{
|
||||||
NetClientState *nc;
|
NetClientState *nc;
|
||||||
|
QemuOpts *opts;
|
||||||
|
|
||||||
nc = qemu_find_netdev(id);
|
nc = qemu_find_netdev(id);
|
||||||
if (!nc) {
|
if (!nc) {
|
||||||
|
@ -1149,6 +1155,16 @@ void qmp_netdev_del(const char *id, Error **errp)
|
||||||
}
|
}
|
||||||
|
|
||||||
qemu_del_net_client(nc);
|
qemu_del_net_client(nc);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Wart: we need to delete the QemuOpts associated with netdevs
|
||||||
|
* created via CLI or HMP, to avoid bogus "Duplicate ID" errors in
|
||||||
|
* HMP netdev_add.
|
||||||
|
*/
|
||||||
|
opts = qemu_opts_find(qemu_find_opts("netdev"), id);
|
||||||
|
if (opts) {
|
||||||
|
qemu_opts_del(opts);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void netfilter_print_info(Monitor *mon, NetFilterState *nf)
|
static void netfilter_print_info(Monitor *mon, NetFilterState *nf)
|
||||||
|
|
Loading…
Reference in New Issue