[lxc-devel] [lxd/master] vlan property added to physical nictype (issue #3375)

Orange-OpenSource on Github lxc-bot at linuxcontainers.org
Mon Jul 3 14:51:25 UTC 2017


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 358 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20170703/582a9655/attachment.bin>
-------------- next part --------------
From 8ada776b8fba15d3df47a6d1f91cde0b7667d882 Mon Sep 17 00:00:00 2001
From: Vincent Catros <vincent.catros at orange.com>
Date: Mon, 3 Jul 2017 16:47:52 +0200
Subject: [PATCH] vlan property added to physical nictype (issue #3375)

Signed-off-by: Vincent Catros <vincent.catros at orange.com>
---
 doc/api-extensions.md |  4 ++--
 doc/containers.md     |  2 +-
 lxd/container_lxc.go  | 31 +++++++++++++++++--------------
 lxd/networks_utils.go |  2 +-
 4 files changed, 21 insertions(+), 18 deletions(-)

diff --git a/doc/api-extensions.md b/doc/api-extensions.md
index bc3dd2d61..df7b64400 100644
--- a/doc/api-extensions.md
+++ b/doc/api-extensions.md
@@ -219,12 +219,12 @@ Introduces the ability to rename a volume group by setting "storage.lvm.vg\_name
 Introduces the ability to rename a thinpool name by setting "storage.thinpool\_name".
 
 ## network\_vlan
-This adds a new "vlan" property to "macvlan" network devices.
+This adds a new "vlan" property to "macvlan" and "physical" network devices.
 
 When set, this will instruct LXD to attach to the specified VLAN. LXD
 will look for an existing interface for that VLAN on the host. If one
 can't be found it will create one itself and then use that as the
-macvlan parent.
+macvlan parent if "macvlan" nictype is selected or as it if "physical" nictype is selected.
 
 ## image\_create\_aliases
 Adds a new "aliases" field to POST /1.0/images allowing for aliases to
diff --git a/doc/containers.md b/doc/containers.md
index 025dff5e5..21cce3c73 100644
--- a/doc/containers.md
+++ b/doc/containers.md
@@ -172,7 +172,7 @@ host\_name              | string    | randomly assigned | no        | bridged, p
 hwaddr                  | string    | randomly assigned | no        | all                           | -             | The MAC address of the new interface
 mtu                     | integer   | parent MTU        | no        | all                           | -             | The MTU of the new interface
 parent                  | string    | -                 | yes       | physical, bridged, macvlan    | -             | The name of the host device or bridge
-vlan                    | integer   | -                 | no        | macvlan                       | network\_vlan | The VLAN ID to attach to
+vlan                    | integer   | -                 | no        | macvlan, physical             | network\_vlan | The VLAN ID to attach to
 ipv4.address            | string    | -                 | no        | bridged                       | network       | An IPv4 address to assign to the container through DHCP
 ipv6.address            | string    | -                 | no        | bridged                       | network       | An IPv6 address to assign to the container through DHCP
 security.mac\_filtering | boolean   | false             | no        | bridged                       | network       | Prevent the container from spoofing another's MAC address
diff --git a/lxd/container_lxc.go b/lxd/container_lxc.go
index c94bd3b1e..b9df5887d 100644
--- a/lxd/container_lxc.go
+++ b/lxd/container_lxc.go
@@ -1266,12 +1266,12 @@ func (c *containerLXC) initLXC() error {
 				return err
 			}
 
-			if shared.StringInSlice(m["nictype"], []string{"bridged", "physical"}) {
+			if m["nictype"] == "bridged" {
 				err = lxcSetConfigItem(cc, fmt.Sprintf("%s.%d.link", networkKeyPrefix, networkidx), m["parent"])
 				if err != nil {
 					return err
 				}
-			} else if m["nictype"] == "macvlan" {
+			} else if shared.StringInSlice(m["nictype"], []string{"macvlan", "physical"}) {
 				err = lxcSetConfigItem(cc, fmt.Sprintf("%s.%d.link", networkKeyPrefix, networkidx), networkGetHostDevice(m["parent"], m["vlan"]))
 				if err != nil {
 					return err
@@ -1837,7 +1837,7 @@ func (c *containerLXC) startCommon() (string, error) {
 			}
 
 			// Create VLAN devices
-			if m["nictype"] == "macvlan" && m["vlan"] != "" {
+			if shared.StringInSlice(m["nictype"], []string{"macvlan", "physical"}) && m["vlan"] != "" {
 				device := networkGetHostDevice(m["parent"], m["vlan"])
 				if !shared.PathExists(fmt.Sprintf("/sys/class/net/%s", device)) {
 					_, err := shared.RunCommand("ip", "link", "add", "link", m["parent"], "name", device, "up", "type", "vlan", "id", m["vlan"])
@@ -5748,13 +5748,8 @@ func (c *containerLXC) createNetworkDevice(name string, m types.Device) (string,
 		dev = n2
 	}
 
-	// Handle physical
-	if m["nictype"] == "physical" {
-		dev = m["parent"]
-	}
-
-	// Handle macvlan
-	if m["nictype"] == "macvlan" {
+	// Handle physical and macvlan
+	if shared.StringInSlice(m["nictype"], []string{"physical", "macvlan"}) {
 		// Deal with VLAN
 		device := m["parent"]
 		if m["vlan"] != "" {
@@ -5770,12 +5765,20 @@ func (c *containerLXC) createNetworkDevice(name string, m types.Device) (string,
 			}
 		}
 
-		_, err := shared.RunCommand("ip", "link", "add", n1, "link", device, "type", "macvlan", "mode", "bridge")
-		if err != nil {
-			return "", fmt.Errorf("Failed to create the new macvlan interface: %s", err)
+		// Handle physical
+		if m["nictype"] == "physical" {
+			dev = device
 		}
 
-		dev = n1
+		// Handle macvlan
+		if m["nictype"] == "macvlan" {
+			_, err := shared.RunCommand("ip", "link", "add", n1, "link", device, "type", "macvlan", "mode", "bridge")
+			if err != nil {
+				return "", fmt.Errorf("Failed to create the new macvlan interface: %s", err)
+			}
+
+			dev = n1
+		}
 	}
 
 	// Set the MAC address
diff --git a/lxd/networks_utils.go b/lxd/networks_utils.go
index 098487cc3..e87f79e71 100644
--- a/lxd/networks_utils.go
+++ b/lxd/networks_utils.go
@@ -96,7 +96,7 @@ func networkIsInUse(c container, name string) bool {
 			continue
 		}
 
-		if !shared.StringInSlice(d["nictype"], []string{"bridged", "macvlan"}) {
+		if !shared.StringInSlice(d["nictype"], []string{"bridged", "macvlan", "physical"}) {
 			continue
 		}
 


More information about the lxc-devel mailing list