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

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) ===
Adds support for multiple interfaces by allowing the disabling of the automatic default gateway being added using the NIC config keys `ipv4.gateway=none` and `ipv6.gateway=none` respectively.

 
From 8f7f45b72373cc9cf4a75b7a30fad442529af704 Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parr...@canonical.com>
Date: Mon, 9 Mar 2020 16:14:20 +0000
Subject: [PATCH 1/5] doc/instances: Adds missing host_name key on routed nic
 device

Signed-off-by: Thomas Parrott <thomas.parr...@canonical.com>
---
 doc/instances.md | 1 +
 1 file changed, 1 insertion(+)

diff --git a/doc/instances.md b/doc/instances.md
index e217700ab9..c01e6a1f58 100644
--- a/doc/instances.md
+++ b/doc/instances.md
@@ -462,6 +462,7 @@ Key                     | Type      | Default           | 
Required  | Descriptio
 :--                     | :--       | :--               | :--       | :--
 parent                  | string    | -                 | no        | The name 
of the host device to join the instance to
 name                    | string    | kernel assigned   | no        | The name 
of the interface inside the instance
+host\_name              | string    | randomly assigned | no        | The name 
of the interface inside the host
 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

From ce03803313e2f7548a392f5983dac7be8ec1cb90 Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parr...@canonical.com>
Date: Mon, 9 Mar 2020 16:16:17 +0000
Subject: [PATCH 2/5] doc/instances: Documents ipv4.gateway and ipv6.gateway
 routed NIC keys

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

diff --git a/doc/instances.md b/doc/instances.md
index c01e6a1f58..c569b94784 100644
--- a/doc/instances.md
+++ b/doc/instances.md
@@ -466,7 +466,9 @@ host\_name              | string    | randomly 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
 
 #### bridged, macvlan or ipvlan for connection to physical network

From 41e4b48e73aaf54e10dcf1c8d1ea7e1cea907bf1 Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parr...@canonical.com>
Date: Mon, 9 Mar 2020 16:16:40 +0000
Subject: [PATCH 3/5] lxd/device/device/utils/network: Adds NetworkValidGateway
 helper

Signed-off-by: Thomas Parrott <thomas.parr...@canonical.com>
---
 lxd/device/device_utils_network.go | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/lxd/device/device_utils_network.go 
b/lxd/device/device_utils_network.go
index a8850aa5c8..2a57e1be84 100644
--- a/lxd/device/device_utils_network.go
+++ b/lxd/device/device_utils_network.go
@@ -683,6 +683,15 @@ func NetworkValidNetworkV6List(value string) error {
        return nil
 }
 
+// NetworkValidGateway validates the gateway value.
+func NetworkValidGateway(value string) error {
+       if shared.StringInSlice(value, []string{"none", "auto"}) {
+               return nil
+       }
+
+       return fmt.Errorf("Invalid gateway: %s")
+}
+
 // networkParsePortRange validates a port range in the form n-n.
 func networkParsePortRange(r string) (int64, int64, error) {
        entries := strings.Split(r, "-")

From 8b94d9b0b2bf7398bf95c2e7f2d54738e50855b6 Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parr...@canonical.com>
Date: Mon, 9 Mar 2020 16:17:32 +0000
Subject: [PATCH 4/5] lxd/device/nic: Adds ipv4.gateway and ipv6.gateway
 validation

Signed-off-by: Thomas Parrott <thomas.parr...@canonical.com>
---
 lxd/device/nic.go | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/lxd/device/nic.go b/lxd/device/nic.go
index d33a8820a3..5cd0f70c5a 100644
--- a/lxd/device/nic.go
+++ b/lxd/device/nic.go
@@ -27,6 +27,7 @@ func nicLoadByType(c deviceConfig.Device) device {
 
 // nicValidationRules returns config validation rules for nic devices.
 func nicValidationRules(requiredFields []string, optionalFields []string) 
map[string]func(value string) error {
+
        // Define a set of default validators for each field name.
        defaultValidators := map[string]func(value string) error{
                "name":                    shared.IsAny,
@@ -49,6 +50,8 @@ func nicValidationRules(requiredFields []string, 
optionalFields []string) map[st
                "ipv4.routes":             NetworkValidNetworkV4List,
                "ipv6.routes":             NetworkValidNetworkV6List,
                "boot.priority":           shared.IsUint32,
+               "ipv4.gateway":            NetworkValidGateway,
+               "ipv6.gateway":            NetworkValidGateway,
        }
 
        validators := map[string]func(value string) error{}
@@ -94,3 +97,13 @@ func nicValidationRules(requiredFields []string, 
optionalFields []string) map[st
 
        return validators
 }
+
+// nicHasAutoGateway takes the value of the "ipv4.gateway" or "ipv6.gateway" 
config keys and returns whether they
+// specify whether the gateway mode is automatic or not
+func nicHasAutoGateway(value string) bool {
+       if value == "" || value == "auto" {
+               return true
+       }
+
+       return false
+}

From 60eebc31e9d6b59f91fa5509f6c32cfafac7a2cd Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parr...@canonical.com>
Date: Mon, 9 Mar 2020 16:18:02 +0000
Subject: [PATCH 5/5] lxd/device/nic/routed: Adds support for not adding
 automatic default gateway

Uses ipv4.gateway=none or ipv6.gateway=none option respectively.

Signed-off-by: Thomas Parrott <thomas.parr...@canonical.com>
---
 lxd/device/nic_routed.go | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/lxd/device/nic_routed.go b/lxd/device/nic_routed.go
index 8cca5851d9..e6ef7f50c7 100644
--- a/lxd/device/nic_routed.go
+++ b/lxd/device/nic_routed.go
@@ -37,6 +37,8 @@ func (d *nicRouted) validateConfig(instConf 
instance.ConfigReader) error {
                "hwaddr",
                "host_name",
                "vlan",
+               "ipv4.gateway",
+               "ipv6.gateway",
        }
 
        rules := nicValidationRules(requiredFields, optionalFields)
@@ -214,8 +216,10 @@ func (d *nicRouted) Start() (*deviceConfig.RunConfig, 
error) {
                        nic = append(nic, deviceConfig.RunConfigItem{Key: 
"ipv4.address", Value: fmt.Sprintf("%s/32", addr)})
                }
 
-               // Use a fixed link-local address as the next-hop default 
gateway.
-               nic = append(nic, deviceConfig.RunConfigItem{Key: 
"ipv4.gateway", Value: nicRoutedIPv4GW})
+               if nicHasAutoGateway(d.config["ipv4.gateway"]) {
+                       // Use a fixed link-local address as the next-hop 
default gateway.
+                       nic = append(nic, deviceConfig.RunConfigItem{Key: 
"ipv4.gateway", Value: nicRoutedIPv4GW})
+               }
        }
 
        if d.config["ipv6.address"] != "" {
@@ -224,8 +228,10 @@ func (d *nicRouted) Start() (*deviceConfig.RunConfig, 
error) {
                        nic = append(nic, deviceConfig.RunConfigItem{Key: 
"ipv6.address", Value: fmt.Sprintf("%s/128", addr)})
                }
 
-               // Use a fixed link-local address as the next-hop default 
gateway.
-               nic = append(nic, deviceConfig.RunConfigItem{Key: 
"ipv6.gateway", Value: nicRoutedIPv6GW})
+               if nicHasAutoGateway(d.config["ipv6.gateway"]) {
+                       // Use a fixed link-local address as the next-hop 
default gateway.
+                       nic = append(nic, deviceConfig.RunConfigItem{Key: 
"ipv6.gateway", Value: nicRoutedIPv6GW})
+               }
        }
 
        runConf.NetworkInterface = nic
@@ -273,14 +279,14 @@ func (d *nicRouted) postStart() error {
        // inside the instance work and ensure that traffic doesn't 
periodically halt whilst ARP/NDP
        // is re-detected.
        if v["host_name"] != "" {
-               if d.config["ipv4.address"] != "" {
+               if d.config["ipv4.address"] != "" && 
nicHasAutoGateway(d.config["ipv4.gateway"]) {
                        _, err := shared.RunCommand("ip", "-4", "addr", "add", 
fmt.Sprintf("%s/32", nicRoutedIPv4GW), "dev", v["host_name"])
                        if err != nil {
                                return err
                        }
                }
 
-               if d.config["ipv6.address"] != "" {
+               if d.config["ipv6.address"] != "" && 
nicHasAutoGateway(d.config["ipv6.gateway"]) {
                        _, err := shared.RunCommand("ip", "-6", "addr", "add", 
fmt.Sprintf("%s/128", nicRoutedIPv6GW), "dev", v["host_name"])
                        if err != nil {
                                return err
_______________________________________________
lxc-devel mailing list
lxc-devel@lists.linuxcontainers.org
http://lists.linuxcontainers.org/listinfo/lxc-devel

Reply via email to