conf: make 'vnet' prefix a macro

Using a macro ensures that all the code is looking for the same
prefix.

* src/conf/domain_conf.h (VIR_NET_GENERATED_PREFIX): New macro.
* src/conf/domain_conf.c (virDomainNetDefParseXML): Use it.
* src/uml/uml_conf.c (umlConnectTapDevice): Likewise.
* src/qemu/qemu_command.c (qemuNetworkIfaceConnect): Likewise.
Suggested by Laine Stump.
This commit is contained in:
Eric Blake 2011-07-29 09:36:17 -06:00
parent 513122ae93
commit dd20328fbb
4 changed files with 13 additions and 9 deletions

View File

@ -2819,7 +2819,7 @@ virDomainNetDefParseXML(virCapsPtr caps,
ifname = virXMLPropString(cur, "dev"); ifname = virXMLPropString(cur, "dev");
if ((ifname != NULL) && if ((ifname != NULL) &&
((flags & VIR_DOMAIN_XML_INACTIVE) && ((flags & VIR_DOMAIN_XML_INACTIVE) &&
(STRPREFIX((const char*)ifname, "vnet")))) { (STRPREFIX(ifname, VIR_NET_GENERATED_PREFIX)))) {
/* An auto-generated target name, blank it out */ /* An auto-generated target name, blank it out */
VIR_FREE(ifname); VIR_FREE(ifname);
} }

View File

@ -429,6 +429,10 @@ struct _virDomainNetDef {
virBandwidthPtr bandwidth; virBandwidthPtr bandwidth;
}; };
/* Used for prefix of ifname of any network name generated dynamically
* by libvirt, and cannot be used for a persistent network name. */
# define VIR_NET_GENERATED_PREFIX "vnet"
enum virDomainChrDeviceType { enum virDomainChrDeviceType {
VIR_DOMAIN_CHR_DEVICE_TYPE_PARALLEL = 0, VIR_DOMAIN_CHR_DEVICE_TYPE_PARALLEL = 0,
VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL, VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL,

View File

@ -188,7 +188,7 @@ qemuNetworkIfaceConnect(virDomainDefPtr def,
int err; int err;
int tapfd = -1; int tapfd = -1;
int vnet_hdr = 0; int vnet_hdr = 0;
int template_ifname = 0; bool template_ifname = false;
unsigned char tapmac[VIR_MAC_BUFLEN]; unsigned char tapmac[VIR_MAC_BUFLEN];
int actualType = virDomainNetGetActualType(net); int actualType = virDomainNetGetActualType(net);
@ -244,15 +244,15 @@ qemuNetworkIfaceConnect(virDomainDefPtr def,
} }
if (!net->ifname || if (!net->ifname ||
STRPREFIX(net->ifname, "vnet") || STRPREFIX(net->ifname, VIR_NET_GENERATED_PREFIX) ||
strchr(net->ifname, '%')) { strchr(net->ifname, '%')) {
VIR_FREE(net->ifname); VIR_FREE(net->ifname);
if (!(net->ifname = strdup("vnet%d"))) { if (!(net->ifname = strdup(VIR_NET_GENERATED_PREFIX "%d"))) {
virReportOOMError(); virReportOOMError();
goto cleanup; goto cleanup;
} }
/* avoid exposing vnet%d in getXMLDesc or error outputs */ /* avoid exposing vnet%d in getXMLDesc or error outputs */
template_ifname = 1; template_ifname = true;
} }
if (qemuCapsGet(qemuCaps, QEMU_CAPS_VNET_HDR) && if (qemuCapsGet(qemuCaps, QEMU_CAPS_VNET_HDR) &&

View File

@ -115,7 +115,7 @@ umlConnectTapDevice(virConnectPtr conn,
const char *bridge) const char *bridge)
{ {
brControl *brctl = NULL; brControl *brctl = NULL;
int template_ifname = 0; bool template_ifname = false;
int err; int err;
unsigned char tapmac[VIR_MAC_BUFLEN]; unsigned char tapmac[VIR_MAC_BUFLEN];
@ -126,13 +126,13 @@ umlConnectTapDevice(virConnectPtr conn,
} }
if (!net->ifname || if (!net->ifname ||
STRPREFIX(net->ifname, "vnet") || STRPREFIX(net->ifname, VIR_NET_GENERATED_PREFIX) ||
strchr(net->ifname, '%')) { strchr(net->ifname, '%')) {
VIR_FREE(net->ifname); VIR_FREE(net->ifname);
if (!(net->ifname = strdup("vnet%d"))) if (!(net->ifname = strdup(VIR_NET_GENERATED_PREFIX "%d")))
goto no_memory; goto no_memory;
/* avoid exposing vnet%d in getXMLDesc or error outputs */ /* avoid exposing vnet%d in getXMLDesc or error outputs */
template_ifname = 1; template_ifname = true;
} }
memcpy(tapmac, net->mac, VIR_MAC_BUFLEN); memcpy(tapmac, net->mac, VIR_MAC_BUFLEN);