[libvirt] [PATCH] Parse ipaddr for bridge network types

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

 



# HG changeset patch
# User john.levon@xxxxxxx
# Date 1232054247 28800
# Node ID 2b8a53968637c1ba806a1cdd94a24f4d15f8072a
# Parent  04139c088854c23dc548c0f9f4abf54c4ed07e0d
Parse ipaddr for bridge network types

As well as supporting round-tripping of the IP address, this fixes a
leak if ipaddr was specified in the Xen domain config.

Signed-off-by: John Levon <john.levon@xxxxxxx>

diff --git a/src/domain_conf.c b/src/domain_conf.c
--- a/src/domain_conf.c
+++ b/src/domain_conf.c
@@ -277,6 +277,7 @@ void virDomainNetDefFree(virDomainNetDef
     case VIR_DOMAIN_NET_TYPE_BRIDGE:
         VIR_FREE(def->data.bridge.brname);
         VIR_FREE(def->data.bridge.script);
+        VIR_FREE(def->data.bridge.ipaddr);
         break;
     }
 
@@ -867,7 +868,8 @@ virDomainNetDefParseXML(virConnectPtr co
                 address = virXMLPropString(cur, "address");
                 port = virXMLPropString(cur, "port");
             } else if ((address == NULL) &&
-                       (def->type == VIR_DOMAIN_NET_TYPE_ETHERNET) &&
+                       (def->type == VIR_DOMAIN_NET_TYPE_ETHERNET ||
+                        def->type == VIR_DOMAIN_NET_TYPE_BRIDGE) &&
                        (xmlStrEqual(cur->name, BAD_CAST "ip"))) {
                 address = virXMLPropString(cur, "address");
             } else if ((ifname == NULL) &&
@@ -933,6 +935,10 @@ virDomainNetDefParseXML(virConnectPtr co
         if (script != NULL) {
             def->data.bridge.script = script;
             script = NULL;
+        }
+        if (address != NULL) {
+            def->data.bridge.ipaddr = address;
+            address = NULL;
         }
         break;
 
@@ -2870,6 +2876,9 @@ virDomainNetDefFormat(virConnectPtr conn
     case VIR_DOMAIN_NET_TYPE_BRIDGE:
         virBufferEscapeString(buf, "      <source bridge='%s'/>\n",
                               def->data.bridge.brname);
+        if (def->data.bridge.ipaddr)
+            virBufferVSprintf(buf, "      <ip address='%s'/>\n",
+                              def->data.bridge.ipaddr);
         if (def->data.bridge.script)
             virBufferEscapeString(buf, "      <script path='%s'/>\n",
                                   def->data.bridge.script);
diff --git a/src/domain_conf.h b/src/domain_conf.h
--- a/src/domain_conf.h
+++ b/src/domain_conf.h
@@ -154,6 +154,7 @@ struct _virDomainNetDef {
         struct {
             char *brname;
             char *script;
+            char *ipaddr;
         } bridge;
     } data;
     char *ifname;
diff --git a/src/xend_internal.c b/src/xend_internal.c
--- a/src/xend_internal.c
+++ b/src/xend_internal.c
@@ -1792,10 +1792,18 @@ xenDaemonParseSxprNets(virConnectPtr con
                     net->type == VIR_DOMAIN_NET_TYPE_BRIDGE &&
                     !(net->data.bridge.script = strdup(tmp2)))
                     goto no_memory;
+                tmp = sexpr_node(node, "device/vif/ip");
+                if (tmp &&
+                    !(net->data.bridge.ipaddr = strdup(tmp)))
+                    goto no_memory;
             } else {
                 net->type = VIR_DOMAIN_NET_TYPE_ETHERNET;
                 if (tmp2 &&
                     !(net->data.ethernet.script = strdup(tmp2)))
+                    goto no_memory;
+                tmp = sexpr_node(node, "device/vif/ip");
+                if (tmp &&
+                    !(net->data.ethernet.ipaddr = strdup(tmp)))
                     goto no_memory;
             }
 
@@ -1829,11 +1837,6 @@ xenDaemonParseSxprNets(virConnectPtr con
                 net->mac[4] = mac[4];
                 net->mac[5] = mac[5];
             }
-
-            tmp = sexpr_node(node, "device/vif/ip");
-            if (tmp &&
-                !(net->data.ethernet.ipaddr = strdup(tmp)))
-                goto no_memory;
 
             if (model &&
                 !(net->model = strdup(model)))
@@ -5128,6 +5131,8 @@ xenDaemonFormatSxprNet(virConnectPtr con
             script = def->data.bridge.script;
 
         virBufferVSprintf(buf, "(script '%s')", script);
+        if (def->data.bridge.ipaddr != NULL)
+            virBufferVSprintf(buf, "(ip '%s')", def->data.bridge.ipaddr);
         break;
 
     case VIR_DOMAIN_NET_TYPE_NETWORK:
diff --git a/src/xm_internal.c b/src/xm_internal.c
--- a/src/xm_internal.c
+++ b/src/xm_internal.c
@@ -1086,6 +1086,9 @@ xenXMDomainConfigParse(virConnectPtr con
                 if (script[0] &&
                     !(net->data.bridge.script = strdup(script)))
                     goto no_memory;
+                if (ip[0] &&
+                    !(net->data.bridge.ipaddr = strdup(ip)))
+                    goto no_memory;
             } else {
                 if (script[0] &&
                     !(net->data.ethernet.script = strdup(script)))
@@ -1822,6 +1825,8 @@ static int xenXMDomainConfigFormatNet(vi
     switch (net->type) {
     case VIR_DOMAIN_NET_TYPE_BRIDGE:
         virBufferVSprintf(&buf, ",bridge=%s", net->data.bridge.brname);
+        if (net->data.bridge.ipaddr)
+            virBufferVSprintf(&buf, ",ip=%s", net->data.bridge.ipaddr);
         break;
 
     case VIR_DOMAIN_NET_TYPE_ETHERNET:

--
Libvir-list mailing list
Libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]