[lxc-devel] [lxd/master] network: Add ipv4.dhcp.gateway

stgraber on Github lxc-bot at linuxcontainers.org
Fri Feb 9 01:44:47 UTC 2018


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 370 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20180209/26bb349d/attachment.bin>
-------------- next part --------------
From 1248c68210ac614f1845e50657a9ba37258a3bff Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Thu, 8 Feb 2018 20:42:57 -0500
Subject: [PATCH] network: Add ipv4.dhcp.gateway
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Closes #4202

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 config/bash/lxd-client |  2 +-
 doc/api-extensions.md  |  3 +++
 doc/networks.md        |  1 +
 lxd/networks.go        |  4 ++++
 lxd/networks_config.go | 15 ++++++++-------
 shared/version/api.go  |  1 +
 6 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/config/bash/lxd-client b/config/bash/lxd-client
index fbbefbcd7..43e058383 100644
--- a/config/bash/lxd-client
+++ b/config/bash/lxd-client
@@ -92,7 +92,7 @@ _have lxc && {
 
     networks_keys="bridge.driver bridge.external_interfaces bridge.mode \
       bridge.mtu dns.domain dns.mode fan.overlay_subnet fan.type \
-      fan.underlay_subnet ipv4.address ipv4.dhcp ipv4.dhcp.expiry \
+      fan.underlay_subnet ipv4.address ipv4.dhcp ipv4.dhcp.expiry ipv4.dhcp.gateway \
       ipv4.dhcp.ranges ipv4.firewall ipv4.nat ipv4.routes ipv4.routing \
       ipv6.address ipv6.dhcp ipv6.dhcp.expiry ipv6.dhcp.ranges \
       ipv6.dhcp.stateful ipv6.firewall ipv6.nat ipv6.routes ipv6.routing \
diff --git a/doc/api-extensions.md b/doc/api-extensions.md
index 1ba3db34d..ca278d160 100644
--- a/doc/api-extensions.md
+++ b/doc/api-extensions.md
@@ -395,3 +395,6 @@ getting a stream of events over websocket.
 ## proxy
 This adds a new `proxy` device type to containers, allowing forwarding
 of connections between the host and container.
+
+## network\_dhcp\_gateway
+Introduces a new ipv4.dhcp.gateway network config key to set an alternate gateway.
diff --git a/doc/networks.md b/doc/networks.md
index 54b01ae4f..2b29b7a0c 100644
--- a/doc/networks.md
+++ b/doc/networks.md
@@ -33,6 +33,7 @@ fan.underlay\_subnet            | string    | fan mode              | default ga
 ipv4.address                    | string    | standard mode         | random unused subnet      | IPv4 address for the bridge (CIDR notation). Use "none" to turn off IPv4 or "auto" to generate a new one
 ipv4.dhcp                       | boolean   | ipv4 address          | true                      | Whether to allocate addresses using DHCP
 ipv4.dhcp.expiry                | string    | ipv4 dhcp             | 1h                        | When to expire DHCP leases
+ipv4.dhcp.gateway               | string    | ipv4 dhcp             | ipv4.address              | Address of the gateway for the subnet
 ipv4.dhcp.ranges                | string    | ipv4 dhcp             | all addresses             | Comma separated list of IP ranges to use for DHCP (FIRST-LAST format)
 ipv4.firewall                   | boolean   | ipv4 address          | true                      | Whether to generate filtering firewall rules for this network
 ipv4.nat                        | boolean   | ipv4 address          | false                     | Whether to NAT (will default to true if unset and a random ipv4.address is generated)
diff --git a/lxd/networks.go b/lxd/networks.go
index 9bab7a1fe..50dcb12c8 100644
--- a/lxd/networks.go
+++ b/lxd/networks.go
@@ -811,6 +811,10 @@ func (n *network) Start() error {
 				dnsmasqCmd = append(dnsmasqCmd, []string{"--dhcp-no-override", "--dhcp-authoritative", fmt.Sprintf("--dhcp-leasefile=%s", shared.VarPath("networks", n.name, "dnsmasq.leases")), fmt.Sprintf("--dhcp-hostsfile=%s", shared.VarPath("networks", n.name, "dnsmasq.hosts"))}...)
 			}
 
+			if n.config["ipv4.dhcp.gateway"] != "" {
+				dnsmasqCmd = append(dnsmasqCmd, fmt.Sprintf("--dhcp-option=3,%s", n.config["ipv4.dhcp.gateway"]))
+			}
+
 			expiry := "1h"
 			if n.config["ipv4.dhcp.expiry"] != "" {
 				expiry = n.config["ipv4.dhcp.expiry"]
diff --git a/lxd/networks_config.go b/lxd/networks_config.go
index 91e15d795..5c79a9d86 100644
--- a/lxd/networks_config.go
+++ b/lxd/networks_config.go
@@ -60,13 +60,14 @@ var networkConfigKeys = map[string]func(value string) error{
 
 		return networkValidAddressCIDRV4(value)
 	},
-	"ipv4.firewall":    shared.IsBool,
-	"ipv4.nat":         shared.IsBool,
-	"ipv4.dhcp":        shared.IsBool,
-	"ipv4.dhcp.expiry": shared.IsAny,
-	"ipv4.dhcp.ranges": shared.IsAny,
-	"ipv4.routes":      shared.IsAny,
-	"ipv4.routing":     shared.IsBool,
+	"ipv4.firewall":     shared.IsBool,
+	"ipv4.nat":          shared.IsBool,
+	"ipv4.dhcp":         shared.IsBool,
+	"ipv4.dhcp.gateway": networkValidAddressV4,
+	"ipv4.dhcp.expiry":  shared.IsAny,
+	"ipv4.dhcp.ranges":  shared.IsAny,
+	"ipv4.routes":       shared.IsAny,
+	"ipv4.routing":      shared.IsBool,
 
 	"ipv6.address": func(value string) error {
 		if shared.IsOneOf(value, []string{"none", "auto"}) == nil {
diff --git a/shared/version/api.go b/shared/version/api.go
index feb31aab8..e75ed6056 100644
--- a/shared/version/api.go
+++ b/shared/version/api.go
@@ -87,4 +87,5 @@ var APIExtensions = []string{
 	"maas_network",
 	"devlxd_events",
 	"proxy",
+	"network_dhcp_gateway",
 }


More information about the lxc-devel mailing list