mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-24 22:55:23 +00:00
Don't expose 'vnet%d' to the user
https://bugzilla.redhat.com/517371 Matt Booth points out that if you use a non-existent bridge name when start a guest you get a weird error message: Failed to add tap interface 'vnet%d' to bridge 'virbr0' and dev='vnet%d' appears in the dumpxml output. Fix that by not including 'vnet%d' in the error message and freeing the 'vnet%d' string if adding the tap device to the bridge fails. * src/qemu_conf.c, src/uml_conf.c: fix qemudNetworkIfaceConnect() and umlConnectTapDevice() to not expose 'vnet%d' to the user
This commit is contained in:
parent
e8ad339312
commit
2b1f67d418
@ -1038,6 +1038,7 @@ qemudNetworkIfaceConnect(virConnectPtr conn,
|
||||
int err;
|
||||
int tapfd = -1;
|
||||
int vnet_hdr = 0;
|
||||
int template_ifname = 0;
|
||||
|
||||
if (net->type == VIR_DOMAIN_NET_TYPE_NETWORK) {
|
||||
virNetworkPtr network = virNetworkLookupByName(conn,
|
||||
@ -1059,6 +1060,14 @@ qemudNetworkIfaceConnect(virConnectPtr conn,
|
||||
return -1;
|
||||
}
|
||||
|
||||
char ebuf[1024];
|
||||
if (!driver->brctl && (err = brInit(&driver->brctl))) {
|
||||
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
||||
_("cannot initialize bridge support: %s"),
|
||||
virStrerror(err, ebuf, sizeof ebuf));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!net->ifname ||
|
||||
STRPREFIX(net->ifname, "vnet") ||
|
||||
strchr(net->ifname, '%')) {
|
||||
@ -1067,14 +1076,8 @@ qemudNetworkIfaceConnect(virConnectPtr conn,
|
||||
virReportOOMError(conn);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
char ebuf[1024];
|
||||
if (!driver->brctl && (err = brInit(&driver->brctl))) {
|
||||
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
||||
_("cannot initialize bridge support: %s"),
|
||||
virStrerror(err, ebuf, sizeof ebuf));
|
||||
return -1;
|
||||
/* avoid exposing vnet%d in dumpxml or error outputs */
|
||||
template_ifname = 1;
|
||||
}
|
||||
|
||||
if (qemuCmdFlags & QEMUD_CMD_FLAG_VNET_HDR &&
|
||||
@ -1088,12 +1091,18 @@ qemudNetworkIfaceConnect(virConnectPtr conn,
|
||||
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
||||
_("Failed to add tap interface to bridge. "
|
||||
"%s is not a bridge device"), brname);
|
||||
} else if (template_ifname) {
|
||||
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
||||
_("Failed to add tap interface to bridge '%s' : %s"),
|
||||
brname, virStrerror(err, ebuf, sizeof ebuf));
|
||||
} else {
|
||||
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
||||
_("Failed to add tap interface '%s' "
|
||||
"to bridge '%s' : %s"),
|
||||
net->ifname, brname, virStrerror(err, ebuf, sizeof ebuf));
|
||||
}
|
||||
if (template_ifname)
|
||||
VIR_FREE(net->ifname);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -104,17 +104,10 @@ umlConnectTapDevice(virConnectPtr conn,
|
||||
virDomainNetDefPtr net,
|
||||
const char *bridge)
|
||||
{
|
||||
int tapfd = -1;
|
||||
int err;
|
||||
brControl *brctl = NULL;
|
||||
|
||||
if (!net->ifname ||
|
||||
STRPREFIX(net->ifname, "vnet") ||
|
||||
strchr(net->ifname, '%')) {
|
||||
VIR_FREE(net->ifname);
|
||||
if (!(net->ifname = strdup("vnet%d")))
|
||||
goto no_memory;
|
||||
}
|
||||
int tapfd = -1;
|
||||
int template_ifname = 0;
|
||||
int err;
|
||||
|
||||
if ((err = brInit(&brctl))) {
|
||||
char ebuf[1024];
|
||||
@ -124,6 +117,16 @@ umlConnectTapDevice(virConnectPtr conn,
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (!net->ifname ||
|
||||
STRPREFIX(net->ifname, "vnet") ||
|
||||
strchr(net->ifname, '%')) {
|
||||
VIR_FREE(net->ifname);
|
||||
if (!(net->ifname = strdup("vnet%d")))
|
||||
goto no_memory;
|
||||
/* avoid exposing vnet%d in dumpxml or error outputs */
|
||||
template_ifname = 1;
|
||||
}
|
||||
|
||||
if ((err = brAddTap(brctl, bridge,
|
||||
&net->ifname, BR_TAP_PERSIST, &tapfd))) {
|
||||
if (errno == ENOTSUP) {
|
||||
@ -131,6 +134,11 @@ umlConnectTapDevice(virConnectPtr conn,
|
||||
umlReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
||||
_("Failed to add tap interface to bridge. "
|
||||
"%s is not a bridge device"), bridge);
|
||||
} else if (template_ifname) {
|
||||
char ebuf[1024];
|
||||
umlReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
||||
_("Failed to add tap interface to bridge '%s' : %s"),
|
||||
bridge, virStrerror(err, ebuf, sizeof ebuf));
|
||||
} else {
|
||||
char ebuf[1024];
|
||||
umlReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
||||
@ -138,6 +146,8 @@ umlConnectTapDevice(virConnectPtr conn,
|
||||
"to bridge '%s' : %s"),
|
||||
net->ifname, bridge, virStrerror(err, ebuf, sizeof ebuf));
|
||||
}
|
||||
if (template_ifname)
|
||||
VIR_FREE(net->ifname);
|
||||
goto error;
|
||||
}
|
||||
close(tapfd);
|
||||
|
Loading…
Reference in New Issue
Block a user