The following pull request was submitted through Github.
It can be accessed and reviewed at: https://github.com/lxc/lxd/pull/5736

This e-mail was sent by the LXC bot, direct replies will not reach the author
unless they happen to be subscribed to this list.

=== Description (from pull-request) ===
Signed-off-by: Thomas Parrott <[email protected]>
From 547b17c81b32bb96b1ca8428b4f63cca1f9c26b5 Mon Sep 17 00:00:00 2001
From: Thomas Parrott <[email protected]>
Date: Wed, 8 May 2019 11:13:53 +0100
Subject: [PATCH] network: Fixes custom MTU not being applied

Signed-off-by: Thomas Parrott <[email protected]>
---
 lxd/container_lxc.go             |  9 +++++++
 test/suites/container_devices.sh | 43 +++++++++++++++++++++++++++++---
 2 files changed, 48 insertions(+), 4 deletions(-)

diff --git a/lxd/container_lxc.go b/lxd/container_lxc.go
index 508a8db697..f99b9e1475 100644
--- a/lxd/container_lxc.go
+++ b/lxd/container_lxc.go
@@ -7626,6 +7626,15 @@ func (c *containerLXC) createNetworkDevice(name string, 
m types.Device) (string,
                }
        }
 
+       // Set the MAC address
+       if m["mtu"] != "" {
+               _, err := shared.RunCommand("ip", "link", "set", "dev", dev, 
"mtu", m["mtu"])
+               if err != nil {
+                       deviceRemoveInterface(dev)
+                       return "", fmt.Errorf("Failed to set the MTU: %s", err)
+               }
+       }
+
        // Bring the interface up
        _, err := shared.RunCommand("ip", "link", "set", "dev", dev, "up")
        if err != nil {
diff --git a/test/suites/container_devices.sh b/test/suites/container_devices.sh
index 9cb5f958c8..56265a8e7f 100644
--- a/test/suites/container_devices.sh
+++ b/test/suites/container_devices.sh
@@ -24,6 +24,7 @@ test_container_devices_nic() {
   lxc profile device set ${ct_name} eth0 limits.ingress 1Mbit
   lxc profile device set ${ct_name} eth0 limits.egress 2Mbit
   lxc profile device set ${ct_name} eth0 host_name "${veth_host_name}"
+  lxc profile device set ${ct_name} eth0 mtu "1400"
   lxc launch testimage "${ct_name}" -p ${ct_name}
   if ! ip -4 r list dev "${veth_host_name}" | grep "192.0.2.1${ipRand}" ; then
     echo "ipv4.routes invalid"
@@ -42,6 +43,12 @@ test_container_devices_nic() {
     false
   fi
 
+  # Check custom MTU is applied.
+  if ! lxc exec "${ct_name}" -- ip link show eth0 | grep "mtu 1400" ; then
+    echo "mtu invalid"
+    false
+  fi
+
   # Test hot plugging a container nic with different settings to profile with 
the same name.
   lxc config device add "${ct_name}" eth0 nic \
     nictype=bridged \
@@ -50,7 +57,9 @@ test_container_devices_nic() {
     ipv6.routes="2001:db8::2${ipRand}/128" \
     limits.ingress=3Mbit \
     limits.egress=4Mbit \
-    host_name="${veth_host_name}"
+    host_name="${veth_host_name}" \
+    name=eth0 \
+    mtu=1401
 
   if ! ip -4 r list dev "${veth_host_name}" | grep "192.0.2.2${ipRand}" ; then
     echo "ipv4.routes invalid"
@@ -69,6 +78,12 @@ test_container_devices_nic() {
     false
   fi
 
+  # Check custom MTU is applied.
+  if ! lxc exec "${ct_name}" -- ip link show eth0 | grep "mtu 1401" ; then
+    echo "mtu invalid"
+    false
+  fi
+
   # Test removing hot plugged device and check profile nic is restored.
   lxc config device remove "${ct_name}" eth0
   if ! ip -4 r list dev "${veth_host_name}" | grep "192.0.2.1${ipRand}" ; then
@@ -88,16 +103,23 @@ test_container_devices_nic() {
     false
   fi
 
+  # Check custom MTU is applied.
+  if ! lxc exec "${ct_name}" -- ip link show eth0 | grep "mtu 1400" ; then
+    echo "mtu invalid"
+    false
+  fi
+
   # Test hot plugging a container nic then updating it.
   lxc config device add "${ct_name}" eth0 nic \
     nictype=bridged \
     parent=${brName} \
-    host_name="${veth_host_name}"
+    host_name="${veth_host_name}" \
+    name=eth0
   lxc config device set "${ct_name}" eth0 ipv4.routes "192.0.2.2${ipRand}/32"
   lxc config device set "${ct_name}" eth0 ipv6.routes 
"2001:db8::2${ipRand}/128"
   lxc config device set "${ct_name}" eth0 limits.ingress 3Mbit
   lxc config device set "${ct_name}" eth0 limits.egress 4Mbit
-
+  lxc config device set "${ct_name}" eth0 mtu 1403
   if ! ip -4 r list dev "${veth_host_name}" | grep "192.0.2.2${ipRand}" ; then
     echo "ipv4.routes invalid"
     false
@@ -115,6 +137,12 @@ test_container_devices_nic() {
     false
   fi
 
+  # Check custom MTU is applied.
+  if ! lxc exec "${ct_name}" -- ip link show eth0 | grep "mtu 1403" ; then
+    echo "mtu invalid"
+    false
+  fi
+
   # Test adding p2p veth to running container.
   lxc config device add "${ct_name}" eth1 nic \
     nictype=p2p \
@@ -122,7 +150,8 @@ test_container_devices_nic() {
     ipv6.routes="2001:db8::3${ipRand}/128" \
     limits.ingress=3Mbit \
     limits.egress=4Mbit \
-    host_name="${veth_host_name}p2p"
+    host_name="${veth_host_name}p2p" \
+    mtu=1400
 
   if ! ip -4 r list dev "${veth_host_name}p2p" | grep "192.0.2.3${ipRand}" ; 
then
     echo "ipv4.routes invalid"
@@ -141,6 +170,12 @@ test_container_devices_nic() {
     false
   fi
 
+  # Check custom MTU is applied.
+  if ! lxc exec "${ct_name}" -- ip link show eth1 | grep "mtu 1400" ; then
+    echo "mtu invalid"
+    false
+  fi
+
   # Cleanup.
   lxc config device remove "${ct_name}" eth1
   lxc delete "${ct_name}" -f
_______________________________________________
lxc-devel mailing list
[email protected]
http://lists.linuxcontainers.org/listinfo/lxc-devel

Reply via email to