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.
---
v4: new patch
src/conf/domain_conf.c | 2 +-
src/conf/domain_conf.h | 4 ++++
src/qemu/qemu_command.c | 8 ++++----
src/uml/uml_conf.c | 8 ++++----
4 files changed, 13 insertions(+), 9 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 257a1ea..72eccde 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -2819,7 +2819,7 @@ virDomainNetDefParseXML(virCapsPtr caps,
ifname = virXMLPropString(cur, "dev");
if ((ifname != NULL) &&
((flags & VIR_DOMAIN_XML_INACTIVE) &&
- (STRPREFIX((const char*)ifname, "vnet")))) {
+ (STRPREFIX(ifname, VIR_NET_GENERATED_PREFIX)))) {
/* An auto-generated target name, blank it out */
VIR_FREE(ifname);
}
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index c748f52..dd33eb0 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -429,6 +429,10 @@ struct _virDomainNetDef {
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 {
VIR_DOMAIN_CHR_DEVICE_TYPE_PARALLEL = 0,
VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL,
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index ee42f1d..6a2e2ae 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -188,7 +188,7 @@ qemuNetworkIfaceConnect(virDomainDefPtr def,
int err;
int tapfd = -1;
int vnet_hdr = 0;
- int template_ifname = 0;
+ bool template_ifname = false;
unsigned char tapmac[VIR_MAC_BUFLEN];
int actualType = virDomainNetGetActualType(net);
@@ -244,15 +244,15 @@ qemuNetworkIfaceConnect(virDomainDefPtr def,
}
if (!net->ifname ||
- STRPREFIX(net->ifname, "vnet") ||
+ STRPREFIX(net->ifname, VIR_NET_GENERATED_PREFIX) ||
strchr(net->ifname, '%')) {
VIR_FREE(net->ifname);
- if (!(net->ifname = strdup("vnet%d"))) {
+ if (!(net->ifname = strdup(VIR_NET_GENERATED_PREFIX "%d"))) {
virReportOOMError();
goto cleanup;
}
/* avoid exposing vnet%d in getXMLDesc or error outputs */
- template_ifname = 1;
+ template_ifname = true;
}
if (qemuCapsGet(qemuCaps, QEMU_CAPS_VNET_HDR) &&
diff --git a/src/uml/uml_conf.c b/src/uml/uml_conf.c
index 417271e..7b5e094 100644
--- a/src/uml/uml_conf.c
+++ b/src/uml/uml_conf.c
@@ -115,7 +115,7 @@ umlConnectTapDevice(virConnectPtr conn,
const char *bridge)
{
brControl *brctl = NULL;
- int template_ifname = 0;
+ bool template_ifname = false;
int err;
unsigned char tapmac[VIR_MAC_BUFLEN];
@@ -126,13 +126,13 @@ umlConnectTapDevice(virConnectPtr conn,
}
if (!net->ifname ||
- STRPREFIX(net->ifname, "vnet") ||
+ STRPREFIX(net->ifname, VIR_NET_GENERATED_PREFIX) ||
strchr(net->ifname, '%')) {
VIR_FREE(net->ifname);
- if (!(net->ifname = strdup("vnet%d")))
+ if (!(net->ifname = strdup(VIR_NET_GENERATED_PREFIX "%d")))
goto no_memory;
/* avoid exposing vnet%d in getXMLDesc or error outputs */
- template_ifname = 1;
+ template_ifname = true;
}
memcpy(tapmac, net->mac, VIR_MAC_BUFLEN);
--
1.7.4.4