cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gabr...@apache.org
Subject [cloudstack] 01/09: kvm/bridge: Allow Link Local Cidr (cloud0 interface) to be configured
Date Tue, 16 Jul 2019 14:17:20 GMT
This is an automated email from the ASF dual-hosted git repository.

gabriel pushed a commit to branch cloud0-cidr-412
in repository https://gitbox.apache.org/repos/asf/cloudstack.git

commit f2d38daee1f4cf9820b1e939d80afdb74f50bbe3
Author: Wido den Hollander <wido@widodh.nl>
AuthorDate: Fri Jul 12 10:54:41 2019 +0200

    kvm/bridge: Allow Link Local Cidr (cloud0 interface) to be configured
    
    There are certain scenarios where the 169.254.0.0/16 subnet is used for different
    purposes then CloudStack on a hypervisor.
    
    Once of such scenarios is a BGP+EVPN+VXLAN setup using BGP Unnumbered where the
    169.254.0.1 address is used by Frr/Zebra BGP routing to send traffic to the
    neighboring router.
    
    The following settings can be changed in the agent.properties (default values added):
    
    network.linklocal.cidr=169.254.0.0/16
    network.linklink.address=169.254.0.1/16
    network.linklocal.gateway=169.254.0.1
    network.linklocal.netmask=255.255.255.0
    
    Make sure the global setting 'control.cidr' matches the values defined in the agent.propeties!
    
    Signed-off-by: Wido den Hollander <wido@widodh.nl>
---
 .../hypervisor/kvm/resource/BridgeVifDriver.java   | 35 ++++++++++++++++++----
 1 file changed, 30 insertions(+), 5 deletions(-)

diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/BridgeVifDriver.java
b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/BridgeVifDriver.java
index ebaf23f..0aef2c5 100644
--- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/BridgeVifDriver.java
+++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/BridgeVifDriver.java
@@ -28,6 +28,7 @@ import java.util.regex.Pattern;
 
 import javax.naming.ConfigurationException;
 
+import com.cloud.utils.StringUtils;
 import org.apache.log4j.Logger;
 import org.libvirt.LibvirtException;
 
@@ -49,6 +50,10 @@ public class BridgeVifDriver extends VifDriverBase {
     private final Object _vnetBridgeMonitor = new Object();
     private String _modifyVlanPath;
     private String _modifyVxlanPath;
+    private String _linkLocalCidr = "169.254.0.0/16";
+    private String _linkLocalAddress = "169.254.0.1/16";
+    private String _linkLocalGateway = NetUtils.getLinkLocalGateway();
+    private String _linkLocalNetmask = NetUtils.getLinkLocalNetMask();
     private String bridgeNameSchema;
     private Long libvirtVersion;
 
@@ -69,6 +74,26 @@ public class BridgeVifDriver extends VifDriverBase {
 
         bridgeNameSchema = (String)params.get("network.bridge.name.schema");
 
+        String linkLocalCidr = (String)params.get("network.linklocal.cidr");
+        if (StringUtils.isNotBlank(linkLocalCidr)) {
+            _linkLocalCidr = linkLocalCidr;
+        }
+
+        String linkLocalAddress = (String)params.get("network.linklocal.address");
+        if (StringUtils.isNotBlank(linkLocalAddress)) {
+            _linkLocalAddress = linkLocalAddress;
+        }
+
+        String linkLocalGateway = (String)params.get("network.linklocal.gateway");
+        if (StringUtils.isNotBlank(linkLocalGateway)) {
+            _linkLocalGateway = linkLocalGateway;
+        }
+
+        String linkLocalNetmask = (String)params.get("network.linklocal.netmask");
+        if (StringUtils.isNotBlank(linkLocalNetmask)) {
+            _linkLocalNetmask = _linkLocalNetmask;
+        }
+
         String value = (String)params.get("scripts.timeout");
         _timeout = NumbersUtil.parseInt(value, 30 * 60) * 1000;
 
@@ -384,7 +409,7 @@ public class BridgeVifDriver extends VifDriverBase {
     private void deleteExistingLinkLocalRouteTable(String linkLocalBr) {
         Script command = new Script("/bin/bash", _timeout);
         command.add("-c");
-        command.add("ip route | grep " + NetUtils.getLinkLocalCIDR());
+        command.add("ip route | grep " + _linkLocalCidr);
         OutputInterpreter.AllLinesParser parser = new OutputInterpreter.AllLinesParser();
         String result = command.execute(parser);
         boolean foundLinkLocalBr = false;
@@ -397,15 +422,15 @@ public class BridgeVifDriver extends VifDriverBase {
                 }
                 final String device = tokens[2];
                 if (!Strings.isNullOrEmpty(device) && !device.equalsIgnoreCase(linkLocalBr))
{
-                    Script.runSimpleBashScript("ip route del " + NetUtils.getLinkLocalCIDR()
+ " dev " + tokens[2]);
+                    Script.runSimpleBashScript("ip route del " + _linkLocalCidr + " dev "
+ tokens[2]);
                 } else {
                     foundLinkLocalBr = true;
                 }
             }
         }
         if (!foundLinkLocalBr) {
-            Script.runSimpleBashScript("ip address add 169.254.0.1/16 dev " + linkLocalBr
+ ";" + "ip route add " + NetUtils.getLinkLocalCIDR() + " dev " + linkLocalBr + " src " +
-                    NetUtils.getLinkLocalGateway());
+            Script.runSimpleBashScript("ip address add " + _linkLocalAddress + " dev " +
linkLocalBr + ";" + "ip route add " + _linkLocalCidr + " dev " + linkLocalBr + " src " +
+                    _linkLocalGateway;
         }
     }
 
@@ -417,7 +442,7 @@ public class BridgeVifDriver extends VifDriverBase {
     public void createControlNetwork(String privBrName)  {
         deleteExistingLinkLocalRouteTable(privBrName);
         if (!isExistingBridge(privBrName)) {
-            Script.runSimpleBashScript("brctl addbr " + privBrName + "; ip link set " + privBrName
+ " up; ip address add 169.254.0.1/16 dev " + privBrName, _timeout);
+            Script.runSimpleBashScript("brctl addbr " + privBrName + "; ip link set " + privBrName
+ " up; ip address add " + _linkLocalAddress + " dev " + privBrName, _timeout);
         }
     }
 


Mime
View raw message