[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH 04/10] conf: Network - keep track of active DHCP stanza in virNetworkDef



From: TJ <linux iam tj>

To avoid iterating all virNetworkIpDef entries when determining
DHCP state keep track of the first enabled DHCP stanza in the
network definition itself, for both IPv4 and IPv6.

A by-product of this change is it allows the XML to contain more
than one IP->DHCP stanza. The active DHCP stanza is the first enabled
DHCP stanza.
All other stanzas are retained which adds flexibility when multiple
interfaces and routes might come and go since an alternative DHCP
stanza can be selected and a refresh operation performed without
needing to destroy/edit/start the network.

Signed-off-by: TJ <linux iam tj>
---
 src/conf/network_conf.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c
index 259de0a..c5eab01 100644
--- a/src/conf/network_conf.c
+++ b/src/conf/network_conf.c
@@ -1882,6 +1882,13 @@ virNetworkDefParseXML(xmlXPathContextPtr ctxt)
             if (ret < 0)
                 goto error;
             def->nips++;
+	    /* use only the first enabled DHCP definition */
+	    if (!def->ipv4_dhcp && def->ips[ii].dhcp_enabled &&
+		VIR_SOCKET_ADDR_IS_FAMILY(&def->ips[ii].address, AF_INET))
+		def->ipv4_dhcp = &def->ips[ii];
+	    if (!def->ipv6_dhcp && def->ips[ii].dhcp_enabled &&
+		VIR_SOCKET_ADDR_IS_FAMILY(&def->ips[ii].address, AF_INET6))
+		def->ipv6_dhcp = &def->ips[ii];
         }
     }
     VIR_FREE(ipNodes);
-- 
1.8.1.2.433.g9808ce0.dirty


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]