mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-10 14:57:42 +00:00
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:
parent
03a2e2edad
commit
9145b3f1cc
@ -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:
|
||||
* @def: domain definition
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include "domain_conf.h"
|
||||
#include "qemu_conf.h"
|
||||
#include "qemu_domain.h"
|
||||
#include "qemu_slirp.h"
|
||||
|
||||
int qemuInterfaceStartDevice(virDomainNetDefPtr net);
|
||||
int qemuInterfaceStartDevices(virDomainDefPtr def);
|
||||
@ -54,3 +55,6 @@ int qemuInterfaceOpenVhostNet(virDomainDefPtr def,
|
||||
virDomainNetDefPtr net,
|
||||
int *vhostfd,
|
||||
size_t *vhostfdSize);
|
||||
|
||||
qemuSlirpPtr qemuInterfacePrepareSlirp(virQEMUDriverPtr driver,
|
||||
virDomainNetDefPtr net);
|
||||
|
@ -5705,8 +5705,11 @@ qemuProcessInit(virQEMUDriverPtr driver,
|
||||
* qemuProcessNetworkPrepareDevices
|
||||
*/
|
||||
static int
|
||||
qemuProcessNetworkPrepareDevices(virDomainDefPtr def)
|
||||
qemuProcessNetworkPrepareDevices(virQEMUDriverPtr driver,
|
||||
virDomainObjPtr vm)
|
||||
{
|
||||
virDomainDefPtr def = vm->def;
|
||||
qemuDomainObjPrivatePtr priv = vm->privateData;
|
||||
int ret = -1;
|
||||
size_t i;
|
||||
virConnectPtr conn = NULL;
|
||||
@ -5751,7 +5754,14 @@ qemuProcessNetworkPrepareDevices(virDomainDefPtr def)
|
||||
}
|
||||
if (virDomainHostdevInsert(def, hostdev) < 0)
|
||||
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;
|
||||
cleanup:
|
||||
@ -6552,7 +6562,7 @@ qemuProcessPrepareHost(virQEMUDriverPtr driver,
|
||||
* will need to be setup.
|
||||
*/
|
||||
VIR_DEBUG("Preparing network devices");
|
||||
if (qemuProcessNetworkPrepareDevices(vm->def) < 0)
|
||||
if (qemuProcessNetworkPrepareDevices(driver, vm) < 0)
|
||||
goto cleanup;
|
||||
|
||||
/* Must be run before security labelling */
|
||||
|
Loading…
Reference in New Issue
Block a user