render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
9119d9
From c245c3ae639f702cfc1f8cdb0b0272600bc4ad1e Mon Sep 17 00:00:00 2001
9119d9
Message-Id: <c245c3ae639f702cfc1f8cdb0b0272600bc4ad1e@dist-git>
9119d9
From: Laine Stump <laine@laine.org>
9119d9
Date: Mon, 15 Dec 2014 10:51:30 -0500
9119d9
Subject: [PATCH] network: setup bridge devices for macTableManager='libvirt'
9119d9
9119d9
This is part of the fix for:
9119d9
9119d9
  https://bugzilla.redhat.com/show_bug.cgi?id=1099210
9119d9
9119d9
When the bridge device for a network has macTableManager='libvirt' the
9119d9
intent is that all kernel management of the bridge's MAC table
9119d9
(Forwarding Database, or fdb, in the case of a Linux Host Bridge) be
9119d9
disabled, with libvirt handling updates to the table instead. The
9119d9
setup required for the bridge itself is:
9119d9
9119d9
1) set the "vlan_filtering" property of the bridge device to 1.
9119d9
9119d9
2) If the bridge has a "Dummy" tap device used to set a fixed MAC
9119d9
address on the bridge (which is always the case for a bridge created
9119d9
by libvirt, and never the case for a bridge created by the host system
9119d9
network config), turn off learning and unicast_flood on this tap (this
9119d9
is needed even though this tap is never IFF_UP, because the kernel
9119d9
ignores the IFF_UP flag of devices when using their settings to
9119d9
automatically decide whether or not to turn off promiscuous mode for
9119d9
any attached device).
9119d9
9119d9
(1) is done both for libvirt-created/managed bridges, and for bridges
9119d9
that are created by the host system config, while (2) is done only for
9119d9
bridges created by libvirt (i.e. for forward modes of nat, routed, and
9119d9
isolated bridges)
9119d9
9119d9
There is no attempt to turn vlan_filtering off when destroying the
9119d9
network because in the case of a libvirt-created bridge, the bridge is
9119d9
about to be destroyed anyway, and in the case of a system bridge, if
9119d9
the other devices attached to the bridge could operate properly before
9119d9
destroying libvirt's network object, they will continue to operate
9119d9
properly (this is similar to the way that libvirt will enable
9119d9
ip_forwarding whenever a routed/natted network is started, but will
9119d9
never attempt to disable it if they are stopped).
9119d9
9119d9
(cherry picked from commit 8a144c90457a8699fb35fbefe8974a2530980eaa)
9119d9
9119d9
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
9119d9
---
9119d9
 src/network/bridge_driver.c | 54 +++++++++++++++++++++++++++++++++++++++++++++
9119d9
 1 file changed, 54 insertions(+)
9119d9
9119d9
diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
9119d9
index 361029f..3e3e4de 100644
9119d9
--- a/src/network/bridge_driver.c
9119d9
+++ b/src/network/bridge_driver.c
9119d9
@@ -1928,6 +1928,29 @@ networkAddAddrToBridge(virNetworkObjPtr network,
9119d9
     return 0;
9119d9
 }
9119d9
 
9119d9
+
9119d9
+static int
9119d9
+networkStartHandleMACTableManagerMode(virNetworkObjPtr network,
9119d9
+                                      const char *macTapIfName)
9119d9
+{
9119d9
+    const char *brname = network->def->bridge;
9119d9
+
9119d9
+    if (brname &&
9119d9
+        network->def->macTableManager
9119d9
+        == VIR_NETWORK_BRIDGE_MAC_TABLE_MANAGER_LIBVIRT) {
9119d9
+        if (virNetDevBridgeSetVlanFiltering(brname, true) < 0)
9119d9
+            return -1;
9119d9
+        if (macTapIfName) {
9119d9
+            if (virNetDevBridgePortSetLearning(brname, macTapIfName, false) < 0)
9119d9
+                return -1;
9119d9
+            if (virNetDevBridgePortSetUnicastFlood(brname, macTapIfName, false) < 0)
9119d9
+                return -1;
9119d9
+        }
9119d9
+    }
9119d9
+    return 0;
9119d9
+}
9119d9
+
9119d9
+
9119d9
 /* add an IP (static) route to a bridge */
9119d9
 static int
9119d9
 networkAddRouteToBridge(virNetworkObjPtr network,
9119d9
@@ -2056,6 +2079,9 @@ networkStartNetworkVirtual(virNetworkDriverStatePtr driver,
9119d9
         }
9119d9
     }
9119d9
 
9119d9
+    if (networkStartHandleMACTableManagerMode(network, macTapIfName) < 0)
9119d9
+        goto err2;
9119d9
+
9119d9
     /* Bring up the bridge interface */
9119d9
     if (virNetDevSetOnline(network->def->bridge, 1) < 0)
9119d9
         goto err2;
9119d9
@@ -2201,6 +2227,27 @@ static int networkShutdownNetworkVirtual(virNetworkDriverStatePtr driver ATTRIBU
9119d9
 }
9119d9
 
9119d9
 
9119d9
+static int
9119d9
+networkStartNetworkBridge(virNetworkObjPtr network)
9119d9
+{
9119d9
+    /* put anything here that needs to be done each time a network of
9119d9
+     * type BRIDGE, is started. On failure, undo anything you've done,
9119d9
+     * and return -1. On success return 0.
9119d9
+     */
9119d9
+    return networkStartHandleMACTableManagerMode(network, NULL);
9119d9
+}
9119d9
+
9119d9
+static int
9119d9
+networkShutdownNetworkBridge(virNetworkObjPtr network ATTRIBUTE_UNUSED)
9119d9
+{
9119d9
+    /* put anything here that needs to be done each time a network of
9119d9
+     * type BRIDGE is shutdown. On failure, undo anything you've done,
9119d9
+     * and return -1. On success return 0.
9119d9
+     */
9119d9
+    return 0;
9119d9
+}
9119d9
+
9119d9
+
9119d9
 /* networkCreateInterfacePool:
9119d9
  * @netdef: the original NetDef from the network
9119d9
  *
9119d9
@@ -2367,6 +2414,10 @@ networkStartNetwork(virNetworkDriverStatePtr driver,
9119d9
         break;
9119d9
 
9119d9
     case VIR_NETWORK_FORWARD_BRIDGE:
9119d9
+       if (networkStartNetworkBridge(network) < 0)
9119d9
+          goto cleanup;
9119d9
+       break;
9119d9
+
9119d9
     case VIR_NETWORK_FORWARD_PRIVATE:
9119d9
     case VIR_NETWORK_FORWARD_VEPA:
9119d9
     case VIR_NETWORK_FORWARD_PASSTHROUGH:
9119d9
@@ -2434,6 +2485,9 @@ static int networkShutdownNetwork(virNetworkDriverStatePtr driver,
9119d9
         break;
9119d9
 
9119d9
     case VIR_NETWORK_FORWARD_BRIDGE:
9119d9
+        ret = networkShutdownNetworkBridge(network);
9119d9
+        break;
9119d9
+
9119d9
     case VIR_NETWORK_FORWARD_PRIVATE:
9119d9
     case VIR_NETWORK_FORWARD_VEPA:
9119d9
     case VIR_NETWORK_FORWARD_PASSTHROUGH:
9119d9
-- 
9119d9
2.2.0
9119d9