提交 bfd2de6e 编写于 作者: L Laine Stump

conf: clean up virDomainNetIPParseXML()

Rearrange this function to be better organized and more correct:

* the error codes were changed from the incorrect INVALID_ARG to
  XML_ERROR

* prefix still isn't required, but if present it must be valid or an
  error will be logged.

* don't emit a debug log just because prefix is missing - this
  is valid.

* group everything related to setting prefix in one place rather than
  scattered through the function.
上级 22a6873a
...@@ -6130,15 +6130,9 @@ virDomainNetIPParseXML(xmlNodePtr node) ...@@ -6130,15 +6130,9 @@ virDomainNetIPParseXML(xmlNodePtr node)
int family = AF_UNSPEC; int family = AF_UNSPEC;
char *address = NULL; char *address = NULL;
if (!(prefixStr = virXMLPropString(node, "prefix")) ||
(virStrToLong_ui(prefixStr, NULL, 10, &prefixValue) < 0)) {
// Don't shout, as some old config may not have a prefix
VIR_DEBUG("Missing or invalid network prefix");
}
if (!(address = virXMLPropString(node, "address"))) { if (!(address = virXMLPropString(node, "address"))) {
virReportError(VIR_ERR_INVALID_ARG, "%s", virReportError(VIR_ERR_XML_ERROR, "%s",
_("Missing network address")); _("Missing required address in <ip>"));
goto cleanup; goto cleanup;
} }
...@@ -6154,11 +6148,22 @@ virDomainNetIPParseXML(xmlNodePtr node) ...@@ -6154,11 +6148,22 @@ virDomainNetIPParseXML(xmlNodePtr node)
goto cleanup; goto cleanup;
if (virSocketAddrParse(&ip->address, address, family) < 0) { if (virSocketAddrParse(&ip->address, address, family) < 0) {
virReportError(VIR_ERR_INVALID_ARG, virReportError(VIR_ERR_XML_ERROR,
_("Failed to parse IP address: '%s'"), _("Invalid address '%s' in <ip>"),
address); address);
goto cleanup; goto cleanup;
} }
prefixStr = virXMLPropString(node, "prefix");
if (prefixStr &&
((virStrToLong_ui(prefixStr, NULL, 10, &prefixValue) < 0) ||
(family == AF_INET6 && prefixValue > 128) ||
(family == AF_INET && prefixValue > 32))) {
virReportError(VIR_ERR_XML_ERROR,
_("Invalid prefix value '%s' in <ip>"),
prefixStr);
goto cleanup;
}
ip->prefix = prefixValue; ip->prefix = prefixValue;
ret = ip; ret = ip;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册