diff --git a/src/qemu/qemu_interface.c b/src/qemu/qemu_interface.c index 72ed51cb1f8beb1bda76e6759e6c141894277bda..0e82831676ccded59c1642a40dd929bfa84e1403 100644 --- a/src/qemu/qemu_interface.c +++ b/src/qemu/qemu_interface.c @@ -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 diff --git a/src/qemu/qemu_interface.h b/src/qemu/qemu_interface.h index 5a2f87e53201b42ace29c91325cfbf6897729a7f..0464b903d79edf1a6c862d0aa3f9b0311ba6ba22 100644 --- a/src/qemu/qemu_interface.h +++ b/src/qemu/qemu_interface.h @@ -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); diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 1dd67902635bc80b28f99e3692e91aa46653e620..1960f534665d49c7460ed5aa51f103c97c39ce2b 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -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 */