]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
lxc conf2xml: convert lxc.network.ipv[46].gateway
authorCédric Bosdonnat <cbosdonnat@suse.com>
Thu, 24 Jul 2014 11:40:32 +0000 (13:40 +0200)
committerCédric Bosdonnat <cbosdonnat@suse.com>
Mon, 5 Jan 2015 19:24:17 +0000 (20:24 +0100)
src/lxc/lxc_native.c
tests/lxcconf2xmldata/lxcconf2xml-physnetwork.config
tests/lxcconf2xmldata/lxcconf2xml-physnetwork.xml
tests/lxcconf2xmldata/lxcconf2xml-simple.config
tests/lxcconf2xmldata/lxcconf2xml-simple.xml

index edc56820b9d192b6d6d1cdefcb54a4c1b0e0d2db..d7cd1d5308e56df51f694f777880e6868866a889 100644 (file)
@@ -424,10 +424,36 @@ typedef struct {
     char *name;
     virDomainNetIpDefPtr *ips;
     size_t nips;
+    char *gateway_ipv4;
+    char *gateway_ipv6;
     bool privnet;
     size_t networks;
 } lxcNetworkParseData;
 
+static int
+lxcAddNetworkRouteDefinition(const char *address,
+                             int family,
+                             virDomainNetRouteDefPtr **routes,
+                             size_t *nroutes)
+{
+    virDomainNetRouteDefPtr route = NULL;
+
+    if (VIR_ALLOC(route) < 0)
+        goto error;
+
+    if (virSocketAddrParse(&route->via, address, family) < 0)
+        goto error;
+
+    if (VIR_APPEND_ELEMENT(*routes, *nroutes, route) < 0)
+        goto error;
+
+    return 0;
+
+ error:
+    VIR_FREE(route);
+    return -1;
+}
+
 static int
 lxcAddNetworkDefinition(lxcNetworkParseData *data)
 {
@@ -465,6 +491,18 @@ lxcAddNetworkDefinition(lxcNetworkParseData *data)
         hostdev->source.caps.u.net.ips = data->ips;
         hostdev->source.caps.u.net.nips = data->nips;
 
+        if (data->gateway_ipv4 &&
+            lxcAddNetworkRouteDefinition(data->gateway_ipv4, AF_INET,
+                                         &hostdev->source.caps.u.net.routes,
+                                         &hostdev->source.caps.u.net.nroutes) < 0)
+                goto error;
+
+        if (data->gateway_ipv6 &&
+            lxcAddNetworkRouteDefinition(data->gateway_ipv6, AF_INET6,
+                                         &hostdev->source.caps.u.net.routes,
+                                         &hostdev->source.caps.u.net.nroutes) < 0)
+                goto error;
+
         if (VIR_EXPAND_N(data->def->hostdevs, data->def->nhostdevs, 1) < 0)
             goto error;
         data->def->hostdevs[data->def->nhostdevs - 1] = hostdev;
@@ -477,6 +515,18 @@ lxcAddNetworkDefinition(lxcNetworkParseData *data)
         net->ips = data->ips;
         net->nips = data->nips;
 
+        if (data->gateway_ipv4 &&
+            lxcAddNetworkRouteDefinition(data->gateway_ipv4, AF_INET,
+                                         &net->routes,
+                                         &net->nroutes) < 0)
+                goto error;
+
+        if (data->gateway_ipv6 &&
+            lxcAddNetworkRouteDefinition(data->gateway_ipv6, AF_INET6,
+                                         &net->routes,
+                                         &net->nroutes) < 0)
+                goto error;
+
         if (VIR_EXPAND_N(data->def->nets, data->def->nnets, 1) < 0)
             goto error;
         data->def->nets[data->def->nnets - 1] = net;
@@ -568,6 +618,10 @@ lxcNetworkWalkCallback(const char *name, virConfValuePtr value, void *data)
             VIR_FREE(ip);
             return -1;
         }
+    } else if (STREQ(name, "lxc.network.ipv4.gateway")) {
+        parseData->gateway_ipv4 = value->str;
+    } else if (STREQ(name, "lxc.network.ipv6.gateway")) {
+        parseData->gateway_ipv6 = value->str;
     } else if (STRPREFIX(name, "lxc.network")) {
         VIR_WARN("Unhandled network property: %s = %s",
                  name,
@@ -584,7 +638,8 @@ lxcConvertNetworkSettings(virDomainDefPtr def, virConfPtr properties)
     int result = -1;
     size_t i;
     lxcNetworkParseData data = {def, NULL, NULL, NULL, NULL,
-                                NULL, NULL, NULL, NULL, 0, true, 0};
+                                NULL, NULL, NULL, NULL, 0,
+                                NULL, NULL, true, 0};
 
     if (virConfWalk(properties, lxcNetworkWalkCallback, &data) < 0)
         goto error;
index 94f7c61af79d13c15e6c5ae9de53e15c9f6bf83c..779dac2b1cfc5e95b0c8d95a48f2bbf16bbb4c60 100644 (file)
@@ -2,7 +2,9 @@ lxc.network.type = phys
 lxc.network.link = eth0
 lxc.network.name = eth1
 lxc.network.ipv4 = 192.168.122.2/24
+lxc.network.ipv4.gateway = 192.168.122.1
 lxc.network.ipv6 = 2003:db8:1:0:214:1234:fe0b:3596/64
+lxc.network.ipv6.gateway = 2003:db8:1:0:214:1234:fe0b:3595
 
 lxc.rootfs = /var/lib/lxc/migrate_test/rootfs
 lxc.utsname = migrate_test
index e0008161041f0b8398ca672340dbf8442ac37a6c..d2cec8f2d7164b109360c289273f9e8e259fd6c3 100644 (file)
@@ -27,6 +27,8 @@
       </source>
       <ip address='192.168.122.2' family='ipv4' prefix='24'/>
       <ip address='2003:db8:1:0:214:1234:fe0b:3596' family='ipv6' prefix='64'/>
+      <route family='ipv4' via='192.168.122.1'/>
+      <route family='ipv6' via='2003:db8:1:0:214:1234:fe0b:3595'/>
     </hostdev>
   </devices>
 </domain>
index d417ba0492e8cab84d3fcf9129b18de401f305ea..50a44bba9583574c3181eff8112d7048d0e5db1a 100644 (file)
@@ -7,7 +7,9 @@ lxc.network.link = virbr0
 lxc.network.hwaddr = 02:00:15:8f:05:c1
 lxc.network.name = eth0
 lxc.network.ipv4 = 192.168.122.2/24
+lxc.network.ipv4.gateway = 192.168.122.1
 lxc.network.ipv6 = 2003:db8:1:0:214:1234:fe0b:3596/64
+lxc.network.ipv6.gateway = 2003:db8:1:0:214:1234:fe0b:3595
 
 #remove next line if host DNS configuration should not be available to container
 lxc.mount.entry = proc proc proc nodev,noexec,nosuid 0 0
index 0dbbc71d14ac1b73d4840d183cdbc2f6056f88cb..b1210e5f80e94f8af363ba343861bbb0c3bb471e 100644 (file)
@@ -39,6 +39,8 @@
       <source bridge='virbr0'/>
       <ip address='192.168.122.2' family='ipv4' prefix='24'/>
       <ip address='2003:db8:1:0:214:1234:fe0b:3596' family='ipv6' prefix='64'/>
+      <route family='ipv4' via='192.168.122.1'/>
+      <route family='ipv6' via='2003:db8:1:0:214:1234:fe0b:3595'/>
       <guest dev='eth0'/>
       <link state='up'/>
     </interface>