File bbf1eafa-lxc-honour-nic-state.patch of Package libvirt.11695

From bbf1eafa5758f723b3d354e76c559d0baf6447b8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?C=C3=A9dric=20Bosdonnat?= <cbosdonnat@suse.com>
Date: Fri, 25 Jul 2014 15:24:29 +0200
Subject: [PATCH 15/17] LXC: honour network devices link state

Don't activate LXC network device if <link state='down'/> has been set
in its configuration.
---
 src/lxc/lxc_container.c | 46 ++++++++++++++++++++++++----------------------
 1 file changed, 24 insertions(+), 22 deletions(-)

Index: libvirt-1.2.5/src/lxc/lxc_container.c
===================================================================
--- libvirt-1.2.5.orig/src/lxc/lxc_container.c
+++ libvirt-1.2.5/src/lxc/lxc_container.c
@@ -536,31 +536,33 @@ static int lxcContainerRenameAndEnableIn
             VIR_FREE(ipStr);
         }
 
-        VIR_DEBUG("Enabling %s", newname);
-        rc = virNetDevSetOnline(newname, true);
-        if (rc < 0)
-            goto error_out;
+        if (netDef->linkstate != VIR_DOMAIN_NET_INTERFACE_LINK_STATE_DOWN) {
+            VIR_DEBUG("Enabling %s", newname);
+            rc = virNetDevSetOnline(newname, true);
+            if (rc < 0)
+                goto error_out;
 
-        /* Set the routes */
-        for (j = 0; j < netDef->nroutes; j++) {
-            virDomainNetRouteDefPtr route = netDef->routes[j];
-            if (VIR_SOCKET_ADDR_VALID(&route->to))
-                toStr = virSocketAddrFormat(&route->to);
-            else
-                if (VIR_STRDUP(toStr, "default") < 0)
-                    goto error_out;
-            viaStr = virSocketAddrFormat(&route->via);
-            VIR_DEBUG("Adding route %s/%d via %s", toStr, route->prefix, viaStr);
+            /* Set the routes */
+            for (j = 0; j < netDef->nroutes; j++) {
+                virDomainNetRouteDefPtr route = netDef->routes[j];
+                if (VIR_SOCKET_ADDR_VALID(&route->to))
+                    toStr = virSocketAddrFormat(&route->to);
+                else
+                    if (VIR_STRDUP(toStr, "default") < 0)
+                        goto error_out;
+                viaStr = virSocketAddrFormat(&route->via);
+                VIR_DEBUG("Adding route %s/%d via %s", toStr, route->prefix, viaStr);
 
-            if (virNetDevAddRoute(newname, &route->to, route->prefix,
-                                  &route->via, 0) < 0) {
-                virReportError(VIR_ERR_SYSTEM_ERROR,
-                               _("Failed to add route %s/%d via %s"),
-                               toStr, route->prefix, viaStr);
-                goto error_out;
+                if (virNetDevAddRoute(newname, &route->to, route->prefix,
+                                      &route->via, 0) < 0) {
+                    virReportError(VIR_ERR_SYSTEM_ERROR,
+                                   _("Failed to add route %s/%d via %s"),
+                                   toStr, route->prefix, viaStr);
+                    goto error_out;
+                }
+                VIR_FREE(toStr);
+                VIR_FREE(viaStr);
             }
-            VIR_FREE(toStr);
-            VIR_FREE(viaStr);
         }
 
         VIR_FREE(newname);