提交 3023ec5e 编写于 作者: M Matthew Booth 提交者: Daniel Veillard

Ensure guestfwd address is IPv4 and various cleanups

* include/libvirt/virterror.h src/util/virterror.c: add a new error
  VIR_ERR_CONFIG_UNSUPPORTED for valid but unsupported configuration options
* src/conf/domain_conf.c: Throw an error if guestfwd address isn't IPv4
  and cleanup a number of parsing return error values.
上级 bea92f96
...@@ -170,6 +170,7 @@ typedef enum { ...@@ -170,6 +170,7 @@ typedef enum {
VIR_WAR_NO_SECRET, /* failed to start secret storage */ VIR_WAR_NO_SECRET, /* failed to start secret storage */
VIR_ERR_INVALID_SECRET, /* invalid secret */ VIR_ERR_INVALID_SECRET, /* invalid secret */
VIR_ERR_NO_SECRET, /* secret not found */ VIR_ERR_NO_SECRET, /* secret not found */
VIR_ERR_CONFIG_UNSUPPORTED, /* unsupported configuration construct */
} virErrorNumber; } virErrorNumber;
/** /**
......
...@@ -1365,8 +1365,8 @@ virDomainChrDefParseXML(virConnectPtr conn, ...@@ -1365,8 +1365,8 @@ virDomainChrDefParseXML(virConnectPtr conn,
nodeName = (const char *) node->name; nodeName = (const char *) node->name;
if ((def->targetType = virDomainChrTargetTypeFromString(nodeName)) < 0) { if ((def->targetType = virDomainChrTargetTypeFromString(nodeName)) < 0) {
/* channel is handled below */ /* channel is handled below */
if(STRNEQ(nodeName, "channel")) { if (STRNEQ(nodeName, "channel")) {
virDomainReportError(conn, VIR_ERR_INVALID_DOMAIN, virDomainReportError(conn, VIR_ERR_XML_ERROR,
_("unknown target type for character device: %s"), _("unknown target type for character device: %s"),
nodeName); nodeName);
return NULL; return NULL;
...@@ -1421,10 +1421,10 @@ virDomainChrDefParseXML(virConnectPtr conn, ...@@ -1421,10 +1421,10 @@ virDomainChrDefParseXML(virConnectPtr conn,
protocol = virXMLPropString(cur, "type"); protocol = virXMLPropString(cur, "type");
} else if (xmlStrEqual(cur->name, BAD_CAST "target")) { } else if (xmlStrEqual(cur->name, BAD_CAST "target")) {
/* If target type isn't set yet, expect it to be set here */ /* If target type isn't set yet, expect it to be set here */
if(def->targetType == VIR_DOMAIN_CHR_TARGET_TYPE_NULL) { if (def->targetType == VIR_DOMAIN_CHR_TARGET_TYPE_NULL) {
targetType = virXMLPropString(cur, "type"); targetType = virXMLPropString(cur, "type");
if(targetType == NULL) { if (targetType == NULL) {
virDomainReportError(conn, VIR_ERR_INVALID_DOMAIN, "%s", virDomainReportError(conn, VIR_ERR_XML_ERROR, "%s",
_("character device target does " _("character device target does "
"not define a type")); "not define a type"));
goto error; goto error;
...@@ -1432,7 +1432,7 @@ virDomainChrDefParseXML(virConnectPtr conn, ...@@ -1432,7 +1432,7 @@ virDomainChrDefParseXML(virConnectPtr conn,
if ((def->targetType = if ((def->targetType =
virDomainChrTargetTypeFromString(targetType)) < 0) virDomainChrTargetTypeFromString(targetType)) < 0)
{ {
virDomainReportError(conn, VIR_ERR_INVALID_DOMAIN, virDomainReportError(conn, VIR_ERR_XML_ERROR,
_("unknown target type for " _("unknown target type for "
"character device: %s"), "character device: %s"),
targetType); targetType);
...@@ -1446,14 +1446,14 @@ virDomainChrDefParseXML(virConnectPtr conn, ...@@ -1446,14 +1446,14 @@ virDomainChrDefParseXML(virConnectPtr conn,
case VIR_DOMAIN_CHR_TARGET_TYPE_SERIAL: case VIR_DOMAIN_CHR_TARGET_TYPE_SERIAL:
case VIR_DOMAIN_CHR_TARGET_TYPE_CONSOLE: case VIR_DOMAIN_CHR_TARGET_TYPE_CONSOLE:
portStr = virXMLPropString(cur, "port"); portStr = virXMLPropString(cur, "port");
if(portStr == NULL) { if (portStr == NULL) {
/* Not required. It will be assigned automatically /* Not required. It will be assigned automatically
* later */ * later */
break; break;
} }
if(virStrToLong_ui(portStr, NULL, 10, &port) < 0) { if (virStrToLong_ui(portStr, NULL, 10, &port) < 0) {
virDomainReportError(conn, VIR_ERR_INVALID_DOMAIN, virDomainReportError(conn, VIR_ERR_XML_ERROR,
_("Invalid port number: %s"), _("Invalid port number: %s"),
portStr); portStr);
goto error; goto error;
...@@ -1464,32 +1464,39 @@ virDomainChrDefParseXML(virConnectPtr conn, ...@@ -1464,32 +1464,39 @@ virDomainChrDefParseXML(virConnectPtr conn,
addrStr = virXMLPropString(cur, "address"); addrStr = virXMLPropString(cur, "address");
portStr = virXMLPropString(cur, "port"); portStr = virXMLPropString(cur, "port");
if(addrStr == NULL) { if (addrStr == NULL) {
virDomainReportError(conn, VIR_ERR_INVALID_DOMAIN, "%s", virDomainReportError(conn, VIR_ERR_XML_ERROR, "%s",
_("guestfwd channel does not " _("guestfwd channel does not "
"define a target address")); "define a target address"));
goto error; goto error;
} }
if(VIR_ALLOC(def->target.addr) < 0) { if (VIR_ALLOC(def->target.addr) < 0) {
virReportOOMError(conn); virReportOOMError(conn);
goto error; goto error;
} }
if(virSocketParseAddr(addrStr, def->target.addr, 0) < 0) if (virSocketParseAddr(addrStr, def->target.addr, 0) < 0)
{ {
virDomainReportError(conn, VIR_ERR_INVALID_DOMAIN, virDomainReportError(conn, VIR_ERR_XML_ERROR,
_("%s is not a valid address"), _("%s is not a valid address"),
addrStr); addrStr);
goto error; goto error;
} }
if(portStr == NULL) { if (def->target.addr->stor.ss_family != AF_INET) {
virDomainReportError(conn, VIR_ERR_INVALID_DOMAIN, "%s", virDomainReportError(conn, VIR_ERR_CONFIG_UNSUPPORTED,
"%s", _("guestfwd channel only supports "
"IPv4 addresses"));
goto error;
}
if (portStr == NULL) {
virDomainReportError(conn, VIR_ERR_XML_ERROR, "%s",
_("guestfwd channel does " _("guestfwd channel does "
"not define a target port")); "not define a target port"));
goto error; goto error;
} }
if(virStrToLong_ui(portStr, NULL, 10, &port) < 0) { if (virStrToLong_ui(portStr, NULL, 10, &port) < 0) {
virDomainReportError(conn, VIR_ERR_INVALID_DOMAIN, virDomainReportError(conn, VIR_ERR_XML_ERROR,
_("Invalid port number: %s"), _("Invalid port number: %s"),
portStr); portStr);
goto error; goto error;
...@@ -1498,7 +1505,7 @@ virDomainChrDefParseXML(virConnectPtr conn, ...@@ -1498,7 +1505,7 @@ virDomainChrDefParseXML(virConnectPtr conn,
break; break;
default: default:
virDomainReportError(conn, VIR_ERR_INVALID_DOMAIN, virDomainReportError(conn, VIR_ERR_XML_ERROR,
_("unexpected target type type %u"), _("unexpected target type type %u"),
def->targetType); def->targetType);
} }
...@@ -2732,7 +2739,7 @@ static virDomainDefPtr virDomainDefParseXML(virConnectPtr conn, ...@@ -2732,7 +2739,7 @@ static virDomainDefPtr virDomainDefParseXML(virConnectPtr conn,
} }
if (!(flags & VIR_DOMAIN_XML_INACTIVE)) if (!(flags & VIR_DOMAIN_XML_INACTIVE))
if((virXPathLong(conn, "string(./@id)", ctxt, &id)) < 0) if ((virXPathLong(conn, "string(./@id)", ctxt, &id)) < 0)
id = -1; id = -1;
def->id = (int)id; def->id = (int)id;
......
...@@ -1089,6 +1089,12 @@ virErrorMsg(virErrorNumber error, const char *info) ...@@ -1089,6 +1089,12 @@ virErrorMsg(virErrorNumber error, const char *info)
else else
errmsg = _("Secret not found: %s"); errmsg = _("Secret not found: %s");
break; break;
case VIR_ERR_CONFIG_UNSUPPORTED:
if (info == NULL)
errmsg = _("unsupported configuration");
else
errmsg = _("unsupported configuration: %s");
break;
} }
return (errmsg); return (errmsg);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册