[lxc-devel] [lxd/master] network: Spawn dnsmasq on FAN bridges

stgraber on Github lxc-bot at linuxcontainers.org
Thu Oct 27 21:39:31 UTC 2016


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 354 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20161027/e9a0ee84/attachment.bin>
-------------- next part --------------
From c7485426a8b42a98998a12548e6db3ac57daedf8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Thu, 27 Oct 2016 17:21:23 -0400
Subject: [PATCH] network: Spawn dnsmasq on FAN bridges
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 lxd/networks.go | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/lxd/networks.go b/lxd/networks.go
index f13f023..1bdb021 100644
--- a/lxd/networks.go
+++ b/lxd/networks.go
@@ -916,8 +916,15 @@ func (n *network) Start() error {
 			return err
 		}
 
+		addr := strings.Split(fanAddress, "/")
 		if n.config["fan.type"] == "ipip" {
-			fanAddress = strings.Replace(fanAddress, "/8", "/24", 1)
+			fanAddress = fmt.Sprintf("%s/24", addr[0])
+		}
+
+		// Parse the host subnet
+		_, hostSubnet, err := net.ParseCIDR(fmt.Sprintf("%s/24", addr[0]))
+		if err != nil {
+			return err
 		}
 
 		// Add the address
@@ -926,6 +933,14 @@ func (n *network) Start() error {
 			return err
 		}
 
+		// Update the dnsmasq config
+		dnsmasqCmd = append(dnsmasqCmd, []string{
+			fmt.Sprintf("--listen-address=%s", addr[0]),
+			"--dhcp-no-override", "--dhcp-authoritative",
+			fmt.Sprintf("--dhcp-leasefile=%s", shared.VarPath("networks", n.name, "dnsmasq.leases")),
+			fmt.Sprintf("--dhcp-hostsfile=%s", shared.VarPath("networks", n.name, "dnsmasq.hosts")),
+			"--dhcp-range", fmt.Sprintf("%s,%s", networkGetIP(hostSubnet, 2).String(), networkGetIP(hostSubnet, -2).String())}...)
+
 		// Setup the tunnel
 		if n.config["fan.type"] == "ipip" {
 			err = shared.RunCommand("ip", "-4", "route", "flush", "dev", "tunl0")
@@ -941,8 +956,6 @@ func (n *network) Start() error {
 			// Fails if the map is already set
 			shared.RunCommand("ip", "link", "change", "tunl0", "type", "ipip", "fan-map", fmt.Sprintf("%s:%s", overlay, underlay))
 
-			addr := strings.Split(fanAddress, "/")
-
 			err = shared.RunCommand("ip", "route", "add", overlay, "dev", "tunl0", "src", addr[0])
 			if err != nil {
 				return err
@@ -1066,7 +1079,7 @@ func (n *network) Start() error {
 	}
 
 	// Configure dnsmasq
-	if !shared.StringInSlice(n.config["ipv4.address"], []string{"", "none"}) || !shared.StringInSlice(n.config["ipv6.address"], []string{"", "none"}) {
+	if n.config["bridge.mode"] == "fan" || !shared.StringInSlice(n.config["ipv4.address"], []string{"", "none"}) || !shared.StringInSlice(n.config["ipv6.address"], []string{"", "none"}) {
 		dnsDomain := n.config["dns.domain"]
 		if dnsDomain == "" {
 			dnsDomain = "lxd"


More information about the lxc-devel mailing list