[lxc-devel] [lxd/master] NIC IPVlan: Adds support for multiple NIC devices

tomponline on Github lxc-bot at linuxcontainers.org
Fri Mar 27 16:13:43 UTC 2020


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 464 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20200327/9e2671d9/attachment.bin>
-------------- next part --------------
From f84ef68c3fcd3d2a6b3423151551467a84347f3e Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Fri, 27 Mar 2020 16:05:50 +0000
Subject: [PATCH 1/3] lxd/device/nic/ipvlan: Adds ipv4.gateway and ipv6.gateway
 support

Fixes #6852

Signed-off-by: Thomas Parrott <thomas.parrott at canonical.com>
---
 lxd/device/nic_ipvlan.go | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/lxd/device/nic_ipvlan.go b/lxd/device/nic_ipvlan.go
index 74a0f8c345..e51af7d96f 100644
--- a/lxd/device/nic_ipvlan.go
+++ b/lxd/device/nic_ipvlan.go
@@ -32,6 +32,8 @@ func (d *nicIPVLAN) validateConfig(instConf instance.ConfigReader) error {
 		"mtu",
 		"hwaddr",
 		"vlan",
+		"ipv4.gateway",
+		"ipv6.gateway",
 	}
 
 	rules := nicValidationRules(requiredFields, optionalFields)
@@ -167,7 +169,9 @@ func (d *nicIPVLAN) Start() (*deviceConfig.RunConfig, error) {
 			nic = append(nic, deviceConfig.RunConfigItem{Key: "ipv4.address", Value: fmt.Sprintf("%s/32", addr)})
 		}
 
-		nic = append(nic, deviceConfig.RunConfigItem{Key: "ipv4.gateway", Value: "dev"})
+		if nicHasAutoGateway(d.config["ipv4.gateway"]) {
+			nic = append(nic, deviceConfig.RunConfigItem{Key: "ipv4.gateway", Value: "dev"})
+		}
 	}
 
 	if d.config["ipv6.address"] != "" {
@@ -176,7 +180,9 @@ func (d *nicIPVLAN) Start() (*deviceConfig.RunConfig, error) {
 			nic = append(nic, deviceConfig.RunConfigItem{Key: "ipv6.address", Value: fmt.Sprintf("%s/128", addr)})
 		}
 
-		nic = append(nic, deviceConfig.RunConfigItem{Key: "ipv6.gateway", Value: "dev"})
+		if nicHasAutoGateway(d.config["ipv6.gateway"]) {
+			nic = append(nic, deviceConfig.RunConfigItem{Key: "ipv6.gateway", Value: "dev"})
+		}
 	}
 
 	runConf.NetworkInterface = nic

From cbaee898136a6619d8500c9609369c3a4b6fff26 Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Fri, 27 Mar 2020 16:07:43 +0000
Subject: [PATCH 2/3] api: Adds container_nic_ipvlan_gateway API extension

Signed-off-by: Thomas Parrott <thomas.parrott at canonical.com>
---
 doc/api-extensions.md | 7 +++++++
 shared/version/api.go | 1 +
 2 files changed, 8 insertions(+)

diff --git a/doc/api-extensions.md b/doc/api-extensions.md
index 3fc67bccf3..930c254829 100644
--- a/doc/api-extensions.md
+++ b/doc/api-extensions.md
@@ -975,3 +975,10 @@ This adds a new `size` field to the output of `/1.0/instances/<name>/snapshots/<
 
 ## clustering\_edit\_roles
 This adds a writable endpoint for cluster members, allowing the editing of their roles.
+
+## container\_nic\_ipvlan\_gateway
+This introduces the `ipv4.gateway` and `ipv6.gateway` NIC config keys that can take a value of either "auto" or
+"none". The default value for the key if unspecified is "auto". This will cause the current behaviour of a default
+gateway being added inside the container and the same gateway address being added to the host-side interface.
+If the value is set to "none" then no default gateway nor will the address be added to the host-side interface.
+This allows multiple ipvlan NIC devices to be added to a container.
diff --git a/shared/version/api.go b/shared/version/api.go
index cfa20e71f6..4534d9769f 100644
--- a/shared/version/api.go
+++ b/shared/version/api.go
@@ -199,6 +199,7 @@ var APIExtensions = []string{
 	"trust_ca_certificates",
 	"snapshot_disk_usage",
 	"clustering_edit_roles",
+	"container_nic_ipvlan_gateway",
 }
 
 // APIExtensionsCount returns the number of available API extensions.

From 1a78e998afdd727921f9e9d323c247c6837000b6 Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Fri, 27 Mar 2020 16:08:48 +0000
Subject: [PATCH 3/3] doc/instances: Adds ipvlan ipv4.gateway and ipv6.gateway
 docs

Signed-off-by: Thomas Parrott <thomas.parrott at canonical.com>
---
 doc/instances.md | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/doc/instances.md b/doc/instances.md
index c569b94784..cc512febfd 100644
--- a/doc/instances.md
+++ b/doc/instances.md
@@ -370,7 +370,9 @@ name                    | string    | kernel assigned   | no        | The name o
 mtu                     | integer   | parent MTU        | no        | The MTU of the new interface
 hwaddr                  | string    | randomly assigned | no        | The MAC address of the new interface
 ipv4.address            | string    | -                 | no        | Comma delimited list of IPv4 static addresses to add to the instance
+ipv4.gateway            | string    | auto              | no        | Whether to add an automatic default IPv4 gateway, can be "auto" or "none"
 ipv6.address            | string    | -                 | no        | Comma delimited list of IPv6 static addresses to add to the instance
+ipv6.gateway            | string    | auto              | no        | Whether to add an automatic default IPv6 gateway, can be "auto" or "none"
 vlan                    | integer   | -                 | no        | The VLAN ID to attach to
 
 #### nictype: p2p


More information about the lxc-devel mailing list