qemu-process: prepare slirp-helper

When the network interface is of "user" type, and QEMU has the "-net
socket,fd=" datagram support, call qemuInterfacePrepareSlirp() to
probe and associate a slirp-helper with the interface.

The usage of automated slirp-helper can be prevented with
disableSlirp (in particular when resuming a
VM that didn't start with slirp-helper before).

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Marc-André Lureau 2019-08-08 18:55:12 +04:00 committed by Michal Privoznik
parent 03a2e2edad
commit 9145b3f1cc
3 changed files with 44 additions and 3 deletions

View File

@ -612,6 +612,33 @@ qemuInterfaceBridgeConnect(virDomainDefPtr def,
} }
qemuSlirpPtr
qemuInterfacePrepareSlirp(virQEMUDriverPtr driver,
virDomainNetDefPtr net)
{
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
VIR_AUTOPTR(qemuSlirp) slirp = NULL;
size_t i;
if (!(slirp = qemuSlirpNewForHelper(cfg->slirpHelperName)))
return NULL;
for (i = 0; i < net->guestIP.nips; i++) {
const virNetDevIPAddr *ip = net->guestIP.ips[i];
if (VIR_SOCKET_ADDR_IS_FAMILY(&ip->address, AF_INET) &&
!qemuSlirpHasFeature(slirp, QEMU_SLIRP_FEATURE_IPV4))
return NULL;
if (VIR_SOCKET_ADDR_IS_FAMILY(&ip->address, AF_INET6) &&
!qemuSlirpHasFeature(slirp, QEMU_SLIRP_FEATURE_IPV6))
return NULL;
}
VIR_RETURN_PTR(slirp);
}
/** /**
* qemuInterfaceOpenVhostNet: * qemuInterfaceOpenVhostNet:
* @def: domain definition * @def: domain definition

View File

@ -24,6 +24,7 @@
#include "domain_conf.h" #include "domain_conf.h"
#include "qemu_conf.h" #include "qemu_conf.h"
#include "qemu_domain.h" #include "qemu_domain.h"
#include "qemu_slirp.h"
int qemuInterfaceStartDevice(virDomainNetDefPtr net); int qemuInterfaceStartDevice(virDomainNetDefPtr net);
int qemuInterfaceStartDevices(virDomainDefPtr def); int qemuInterfaceStartDevices(virDomainDefPtr def);
@ -54,3 +55,6 @@ int qemuInterfaceOpenVhostNet(virDomainDefPtr def,
virDomainNetDefPtr net, virDomainNetDefPtr net,
int *vhostfd, int *vhostfd,
size_t *vhostfdSize); size_t *vhostfdSize);
qemuSlirpPtr qemuInterfacePrepareSlirp(virQEMUDriverPtr driver,
virDomainNetDefPtr net);

View File

@ -5705,8 +5705,11 @@ qemuProcessInit(virQEMUDriverPtr driver,
* qemuProcessNetworkPrepareDevices * qemuProcessNetworkPrepareDevices
*/ */
static int static int
qemuProcessNetworkPrepareDevices(virDomainDefPtr def) qemuProcessNetworkPrepareDevices(virQEMUDriverPtr driver,
virDomainObjPtr vm)
{ {
virDomainDefPtr def = vm->def;
qemuDomainObjPrivatePtr priv = vm->privateData;
int ret = -1; int ret = -1;
size_t i; size_t i;
virConnectPtr conn = NULL; virConnectPtr conn = NULL;
@ -5751,7 +5754,14 @@ qemuProcessNetworkPrepareDevices(virDomainDefPtr def)
} }
if (virDomainHostdevInsert(def, hostdev) < 0) if (virDomainHostdevInsert(def, hostdev) < 0)
goto cleanup; goto cleanup;
} } else if (actualType == VIR_DOMAIN_NET_TYPE_USER &&
!priv->disableSlirp &&
virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_NET_SOCKET_DGRAM)) {
qemuSlirpPtr slirp = qemuInterfacePrepareSlirp(driver, net);
QEMU_DOMAIN_NETWORK_PRIVATE(net)->slirp = slirp;
}
} }
ret = 0; ret = 0;
cleanup: cleanup:
@ -6552,7 +6562,7 @@ qemuProcessPrepareHost(virQEMUDriverPtr driver,
* will need to be setup. * will need to be setup.
*/ */
VIR_DEBUG("Preparing network devices"); VIR_DEBUG("Preparing network devices");
if (qemuProcessNetworkPrepareDevices(vm->def) < 0) if (qemuProcessNetworkPrepareDevices(driver, vm) < 0)
goto cleanup; goto cleanup;
/* Must be run before security labelling */ /* Must be run before security labelling */