even if the interface is down, and we can't get any addresses from the
device itself.
---
src/drv_initscripts.c | 15 +++++++--------
src/dutil.c | 28 +++++++++++++++-------------
2 files changed, 22 insertions(+), 21 deletions(-)
diff --git a/src/drv_initscripts.c b/src/drv_initscripts.c
index e8c4698..6034698 100644
--- a/src/drv_initscripts.c
+++ b/src/drv_initscripts.c
@@ -764,16 +764,15 @@ char *drv_xml_state(struct netcf_if *nif) {
ncf_xml = apply_stylesheet(ncf, ncf->driver->put, aug_xml);
ERR_BAIL(ncf);
- /* get the current IP address. If it's non-zero, also get the
- * current prefix, and add both to the document */
+ /* get the current IP address and prefix, and add both to the
+ * document.
+ */
ipv4 = if_ipv4_address(ncf, nif->name);
ERR_BAIL(ncf);
- if (ipv4 != 0) {
- prefix = if_ipv4_prefix(ncf, nif->name);
- ERR_BAIL(ncf);
- add_state_to_xml_doc(ncf_xml, ncf, ipv4, prefix);
- ERR_BAIL(ncf);
- }
+ prefix = if_ipv4_prefix(ncf, nif->name);
+ ERR_BAIL(ncf);
+ add_state_to_xml_doc(ncf_xml, ncf, ipv4, prefix);
+ ERR_BAIL(ncf);
r = xsltSaveResultToString((xmlChar **)&result, &result_len,
ncf_xml, ncf->driver->put);
diff --git a/src/dutil.c b/src/dutil.c
index dd75768..d2090a7 100644
--- a/src/dutil.c
+++ b/src/dutil.c
@@ -600,19 +600,21 @@ void add_state_to_xml_doc(xmlDocPtr doc, struct netcf *ncf
ATTRIBUTE_UNUSED,
cur = next;
}
- ip = xmlNewDocNode(doc, NULL, BAD_CAST "ip", NULL);
- ERR_NOMEM((ip == NULL), ncf);
- cur = xmlAddChild(proto, ip);
- ERR_NOMEM((cur == NULL), ncf);
-
- inet_ntop(AF_INET, (struct in_addr *)&ipv4, ip_str, sizeof(ip_str));
- prop = xmlSetProp(ip, BAD_CAST "address", BAD_CAST ip_str);
- ERR_NOMEM((prop == NULL), ncf);
- snprintf(prefix_str, sizeof(prefix_str), "%d", prefix);
- prop = xmlSetProp(ip, BAD_CAST "prefix", BAD_CAST prefix_str);
- ERR_NOMEM((prop == NULL), ncf);
- prop = xmlSetProp(ip, BAD_CAST "source", BAD_CAST "device");
- ERR_NOMEM((prop == NULL), ncf);
+ if (ipv4 != 0) {
+ ip = xmlNewDocNode(doc, NULL, BAD_CAST "ip", NULL);
+ ERR_NOMEM((ip == NULL), ncf);
+ cur = xmlAddChild(proto, ip);
+ ERR_NOMEM((cur == NULL), ncf);
+
+ inet_ntop(AF_INET, (struct in_addr *)&ipv4, ip_str, sizeof(ip_str));
+ prop = xmlSetProp(ip, BAD_CAST "address", BAD_CAST ip_str);
+ ERR_NOMEM((prop == NULL), ncf);
+ snprintf(prefix_str, sizeof(prefix_str), "%d", prefix);
+ prop = xmlSetProp(ip, BAD_CAST "prefix", BAD_CAST prefix_str);
+ ERR_NOMEM((prop == NULL), ncf);
+ prop = xmlSetProp(ip, BAD_CAST "source", BAD_CAST "device");
+ ERR_NOMEM((prop == NULL), ncf);
+ }
error:
return;
--
1.6.2.5