From 8a659e31866a260111f6c93edbba62f593aea7f4 Mon Sep 17 00:00:00 2001 From: Daniel Veillard Date: Fri, 6 Nov 2009 17:50:54 +0100 Subject: [PATCH] Store the range size when adding a DHCP range * src/conf/network_conf.h: extend the structure to store the range * src/conf/network_conf.c: before adding a range parse the IP addresses do some checking and keep the size --- src/conf/network_conf.c | 40 +++++++++++++++++++++++++++++++++++++--- src/conf/network_conf.h | 1 + 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c index 9ecfc1d22c..62b3007c25 100644 --- a/src/conf/network_conf.c +++ b/src/conf/network_conf.c @@ -36,6 +36,7 @@ #include "virterror_internal.h" #include "datatypes.h" #include "network_conf.h" +#include "network.h" #include "memory.h" #include "xml.h" #include "uuid.h" @@ -230,15 +231,47 @@ virNetworkDHCPRangeDefParseXML(virConnectPtr conn, while (cur != NULL) { if (cur->type == XML_ELEMENT_NODE && xmlStrEqual(cur->name, BAD_CAST "range")) { - xmlChar *start, *end; + char *start, *end; + virSocketAddr saddr, eaddr; + int range; - if (!(start = xmlGetProp(cur, BAD_CAST "start"))) { + if (!(start = (char *) xmlGetProp(cur, BAD_CAST "start"))) { cur = cur->next; continue; } - if (!(end = xmlGetProp(cur, BAD_CAST "end"))) { + if (!(end = (char *) xmlGetProp(cur, BAD_CAST "end"))) { + xmlFree(start); cur = cur->next; + continue; + } + + if (virSocketParseAddr(start, &saddr, 0) < 0) { + virNetworkReportError(conn, VIR_ERR_XML_ERROR, + _("cannot parse dhcp start address '%s'"), + start); + xmlFree(start); + xmlFree(end); + cur = cur->next; + continue; + } + if (virSocketParseAddr(end, &eaddr, 0) < 0) { + virNetworkReportError(conn, VIR_ERR_XML_ERROR, + _("cannot parse dhcp end address '%s'"), + end); xmlFree(start); + xmlFree(end); + cur = cur->next; + continue; + } + + range = virSocketGetRange(&saddr, &eaddr); + if (range < 0) { + virNetworkReportError(conn, VIR_ERR_XML_ERROR, + _("dhcp range '%s' to '%s' invalid"), + start, end); + xmlFree(start); + xmlFree(end); + cur = cur->next; continue; } @@ -250,6 +283,7 @@ virNetworkDHCPRangeDefParseXML(virConnectPtr conn, } def->ranges[def->nranges].start = (char *)start; def->ranges[def->nranges].end = (char *)end; + def->ranges[def->nranges].size = range; def->nranges++; } else if (cur->type == XML_ELEMENT_NODE && xmlStrEqual(cur->name, BAD_CAST "host")) { diff --git a/src/conf/network_conf.h b/src/conf/network_conf.h index d5dfaebec1..0214d1a283 100644 --- a/src/conf/network_conf.h +++ b/src/conf/network_conf.h @@ -45,6 +45,7 @@ typedef virNetworkDHCPRangeDef *virNetworkDHCPRangeDefPtr; struct _virNetworkDHCPRangeDef { char *start; char *end; + int size; }; typedef struct _virNetworkDHCPHostDef virNetworkDHCPHostDef; -- GitLab