[lxc-devel] [lxd/master] Tweak fan bridge handling
stgraber on Github
lxc-bot at linuxcontainers.org
Wed Jul 25 03:54:48 UTC 2018
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 301 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20180725/82e85a4c/attachment.bin>
-------------- next part --------------
From 5083383d5527cb6738a0adfac67be6e059e76a3f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Tue, 24 Jul 2018 23:13:16 -0400
Subject: [PATCH 1/3] lxd/init: Allow selecting custom Fan underlay
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/main_init_interactive.go | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)
diff --git a/lxd/main_init_interactive.go b/lxd/main_init_interactive.go
index 6c6b85f03..fc594208b 100644
--- a/lxd/main_init_interactive.go
+++ b/lxd/main_init_interactive.go
@@ -332,6 +332,32 @@ func (c *cmdInit) askNetworking(config *cmdInitData, d lxd.ContainerServer) erro
"bridge.mode": "fan",
}
+ // Select the underlay
+ network.Config["fan.underlay_subnet"] = cli.AskString("What subnet should be used as the Fan underlay? [default=auto]: ", "auto", func(value string) error {
+ var err error
+ var subnet *net.IPNet
+
+ // Handle auto
+ if value == "auto" {
+ subnet, _, err = networkDefaultGatewaySubnetV4()
+ if err != nil {
+ return err
+ }
+ } else {
+ _, subnet, err = net.ParseCIDR(value)
+ if err != nil {
+ return err
+ }
+ }
+
+ size, _ := subnet.Mask.Size()
+ if size != 16 && size != 24 {
+ return fmt.Errorf("The underlay subnet must be a /16 or a /24")
+ }
+
+ return nil
+ })
+
// Add the new network
config.Node.Networks = append(config.Node.Networks, network)
From e7847e4168054da68207f256317677a45bd26949 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Tue, 24 Jul 2018 23:47:27 -0400
Subject: [PATCH 2/3] lxd/init: Fix typo in Fan question
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/main_init_interactive.go | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lxd/main_init_interactive.go b/lxd/main_init_interactive.go
index fc594208b..5bdcc5b95 100644
--- a/lxd/main_init_interactive.go
+++ b/lxd/main_init_interactive.go
@@ -324,7 +324,7 @@ func (c *cmdInit) askNetworking(config *cmdInitData, d lxd.ContainerServer) erro
break
}
- } else if config.Cluster != nil && fanKernel && cli.AskBool("Would you like to create a new Fan overlay network? (yes/no) [default=yes]", "yes") {
+ } else if config.Cluster != nil && fanKernel && cli.AskBool("Would you like to create a new Fan overlay network? (yes/no) [default=yes]: ", "yes") {
// Define the network
network := api.NetworksPost{}
network.Name = "lxdfan0"
From afdaa9be2dbb9177a5ac845a845f19bcb87eaa1d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Tue, 24 Jul 2018 23:47:46 -0400
Subject: [PATCH 3/3] lxd/networks: Calculate Fan MTU based on parent
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 | 35 +++++++++++++++++++++++++++++++++++
1 file changed, 35 insertions(+)
diff --git a/lxd/networks.go b/lxd/networks.go
index b81963be4..26d3e4442 100644
--- a/lxd/networks.go
+++ b/lxd/networks.go
@@ -9,6 +9,7 @@ import (
"net/http"
"os"
"os/exec"
+ "strconv"
"strings"
"sync"
@@ -1439,6 +1440,40 @@ func (n *network) Start() error {
fanAddress = fmt.Sprintf("%s/24", addr[0])
}
+ // Update the MTU based on overlay device (if available)
+ content, err := ioutil.ReadFile(fmt.Sprintf("/sys/class/net/%s/mtu", devName))
+ if err == nil {
+ // Parse value
+ fanMtuInt, err := strconv.ParseInt(strings.TrimSpace(string(content)), 10, 32)
+ if err != nil {
+ return err
+ }
+
+ // Apply overhead
+ if n.config["fan.type"] == "ipip" {
+ fanMtuInt = fanMtuInt - 20
+ } else {
+ fanMtuInt = fanMtuInt - 50
+ }
+
+ // Apply changes
+ fanMtu := fmt.Sprintf("%d", fanMtuInt)
+ if fanMtu != mtu {
+ mtu = fanMtu
+ if n.config["bridge.driver"] != "openvswitch" {
+ _, err = shared.RunCommand("ip", "link", "set", "dev", fmt.Sprintf("%s-mtu", n.name), "mtu", mtu)
+ if err != nil {
+ return err
+ }
+ }
+
+ _, err = shared.RunCommand("ip", "link", "set", "dev", n.name, "mtu", mtu)
+ if err != nil {
+ return err
+ }
+ }
+ }
+
// Parse the host subnet
_, hostSubnet, err := net.ParseCIDR(fmt.Sprintf("%s/24", addr[0]))
if err != nil {
More information about the lxc-devel
mailing list