mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-25 15:15:25 +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 err;
|
||||||
int tapfd = -1;
|
int tapfd = -1;
|
||||||
int vnet_hdr = 0;
|
int vnet_hdr = 0;
|
||||||
|
int template_ifname = 0;
|
||||||
|
|
||||||
if (net->type == VIR_DOMAIN_NET_TYPE_NETWORK) {
|
if (net->type == VIR_DOMAIN_NET_TYPE_NETWORK) {
|
||||||
virNetworkPtr network = virNetworkLookupByName(conn,
|
virNetworkPtr network = virNetworkLookupByName(conn,
|
||||||
@ -1059,6 +1060,14 @@ qemudNetworkIfaceConnect(virConnectPtr conn,
|
|||||||
return -1;
|
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 ||
|
if (!net->ifname ||
|
||||||
STRPREFIX(net->ifname, "vnet") ||
|
STRPREFIX(net->ifname, "vnet") ||
|
||||||
strchr(net->ifname, '%')) {
|
strchr(net->ifname, '%')) {
|
||||||
@ -1067,14 +1076,8 @@ qemudNetworkIfaceConnect(virConnectPtr conn,
|
|||||||
virReportOOMError(conn);
|
virReportOOMError(conn);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
/* avoid exposing vnet%d in dumpxml or error outputs */
|
||||||
|
template_ifname = 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 (qemuCmdFlags & QEMUD_CMD_FLAG_VNET_HDR &&
|
if (qemuCmdFlags & QEMUD_CMD_FLAG_VNET_HDR &&
|
||||||
@ -1088,12 +1091,18 @@ qemudNetworkIfaceConnect(virConnectPtr conn,
|
|||||||
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
||||||
_("Failed to add tap interface to bridge. "
|
_("Failed to add tap interface to bridge. "
|
||||||
"%s is not a bridge device"), brname);
|
"%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 {
|
} else {
|
||||||
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
||||||
_("Failed to add tap interface '%s' "
|
_("Failed to add tap interface '%s' "
|
||||||
"to bridge '%s' : %s"),
|
"to bridge '%s' : %s"),
|
||||||
net->ifname, brname, virStrerror(err, ebuf, sizeof ebuf));
|
net->ifname, brname, virStrerror(err, ebuf, sizeof ebuf));
|
||||||
}
|
}
|
||||||
|
if (template_ifname)
|
||||||
|
VIR_FREE(net->ifname);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,17 +104,10 @@ umlConnectTapDevice(virConnectPtr conn,
|
|||||||
virDomainNetDefPtr net,
|
virDomainNetDefPtr net,
|
||||||
const char *bridge)
|
const char *bridge)
|
||||||
{
|
{
|
||||||
int tapfd = -1;
|
|
||||||
int err;
|
|
||||||
brControl *brctl = NULL;
|
brControl *brctl = NULL;
|
||||||
|
int tapfd = -1;
|
||||||
if (!net->ifname ||
|
int template_ifname = 0;
|
||||||
STRPREFIX(net->ifname, "vnet") ||
|
int err;
|
||||||
strchr(net->ifname, '%')) {
|
|
||||||
VIR_FREE(net->ifname);
|
|
||||||
if (!(net->ifname = strdup("vnet%d")))
|
|
||||||
goto no_memory;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((err = brInit(&brctl))) {
|
if ((err = brInit(&brctl))) {
|
||||||
char ebuf[1024];
|
char ebuf[1024];
|
||||||
@ -124,6 +117,16 @@ umlConnectTapDevice(virConnectPtr conn,
|
|||||||
goto error;
|
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,
|
if ((err = brAddTap(brctl, bridge,
|
||||||
&net->ifname, BR_TAP_PERSIST, &tapfd))) {
|
&net->ifname, BR_TAP_PERSIST, &tapfd))) {
|
||||||
if (errno == ENOTSUP) {
|
if (errno == ENOTSUP) {
|
||||||
@ -131,6 +134,11 @@ umlConnectTapDevice(virConnectPtr conn,
|
|||||||
umlReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
umlReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
||||||
_("Failed to add tap interface to bridge. "
|
_("Failed to add tap interface to bridge. "
|
||||||
"%s is not a bridge device"), 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 {
|
} else {
|
||||||
char ebuf[1024];
|
char ebuf[1024];
|
||||||
umlReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
umlReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
||||||
@ -138,6 +146,8 @@ umlConnectTapDevice(virConnectPtr conn,
|
|||||||
"to bridge '%s' : %s"),
|
"to bridge '%s' : %s"),
|
||||||
net->ifname, bridge, virStrerror(err, ebuf, sizeof ebuf));
|
net->ifname, bridge, virStrerror(err, ebuf, sizeof ebuf));
|
||||||
}
|
}
|
||||||
|
if (template_ifname)
|
||||||
|
VIR_FREE(net->ifname);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
close(tapfd);
|
close(tapfd);
|
||||||
|
Loading…
Reference in New Issue
Block a user