diff mbox

[v2] Allow a single DHCP configuration via the system configuration submenu

Message ID 1420211162-9189-1-git-send-email-jeremy.rosen@openwide.fr
State Superseded
Headers show

Commit Message

Jeremy Rosen Jan. 2, 2015, 3:06 p.m. UTC
This patch allows the setup of simple a single interface to be
automatically brought up and configured via DHCP on system startup.

The interface name can be set via a configuration option. This patch
does not support systemd-networkd, any complex network configuration should
be done via overlay of /etc/network/interfaces or the relevant networkd
configuration file

Signed-off-by: Jérémy Rosen <jeremy.rosen@openwide.fr>

---

v2 : - inline shell section instead of providing a script
     - add one Config.in option instead of two
---
 system/Config.in                       | 18 ++++++++++++++++++
 system/skeleton/etc/network/interfaces |  4 ----
 system/system.mk                       | 17 +++++++++++++++++
 3 files changed, 35 insertions(+), 4 deletions(-)
 delete mode 100644 system/skeleton/etc/network/interfaces

Comments

Thomas Petazzoni Jan. 2, 2015, 3:24 p.m. UTC | #1
Dear Jérémy Rosen,

On Fri,  2 Jan 2015 16:06:02 +0100, Jérémy Rosen wrote:

> +define SIMPLE_NETWORK
> +	mkdir -p $(TARGET_DIR)/etc/network/
> +
> +	echo "# interface file auto-generated by buildroot" >  $(TARGET_DIR)/etc/network/interfaces
> +	echo                                                >> $(TARGET_DIR)/etc/network/interfaces
> +	echo "auto lo"                                      >> $(TARGET_DIR)/etc/network/interfaces
> +	echo "iface lo inet loopback"                       >> $(TARGET_DIR)/etc/network/interfaces
> +	echo                                                >> $(TARGET_DIR)/etc/network/interfaces
> +
> +	if [ -n "$(BR2_SIMPLE_DHCP)" ] ; then \
> +		echo "auto $(BR2_SIMPLE_DHCP)"              >> $(TARGET_DIR)/etc/network/interfaces ; \
> +		echo "iface $(BR2_SIMPLE_DHCP) inet dhcp"   >> $(TARGET_DIR)/etc/network/interfaces ; \
> +	fi

Can we use make instead of the shell for this condition? Also,
BR_SIMPLE_DHCP has some double quotes, so you probably want to use
qstrip. Something like:

define SET_NETWORK_LOCALHOST
	echo "# interface file auto-generated by buildroot" >  $(TARGET_DIR)/etc/network/interfaces
	echo                                                >> $(TARGET_DIR)/etc/network/interfaces
	echo "auto lo"                                      >> $(TARGET_DIR)/etc/network/interfaces
	echo "iface lo inet loopback"                       >> $(TARGET_DIR)/etc/network/interfaces
	echo                                                >> $(TARGET_DIR)/etc/network/interfaces
endef

NETWORK_DHCP_IFACE = $(call qstrip,$(BR2_SIMPLE_DHCP))

ifneq ($(NETWORK_DHCP_IFACE),)
define SET_NETWORK_DHCP
	echo "auto $(NETWORK_DHCP_IFACE)" >> $(TARGET_DIR)/etc/network/interfaces
	echo "iface $(NETWORK_DHCP_IFACE) inet dhcp" >> $(TARGET_DIR)/etc/network/interfaces
endef
endif

define SET_NETWORK
	mkdir -p $(TARGET_DIR)/etc/network/
	$(SET_NETWORK_LOCALHOST)
	$(SET_NETWORK_DHCP)
endef

TARGET_FINALIZE_HOOKS += SET_NETWORK

It would be good to avoid the repeated redirects to
$(TARGET_DIR)/etc/network/interfaces, but I don't immediately see an
elegant way of doing that.

Thanks,

Thomas
diff mbox

Patch

diff --git a/system/Config.in b/system/Config.in
index a3b7aff..71ba7ab 100644
--- a/system/Config.in
+++ b/system/Config.in
@@ -324,6 +324,24 @@  config BR2_TARGET_GENERIC_REMOUNT_ROOTFS_RW
 
 endif # BR2_ROOTFS_SKELETON_DEFAULT
 
+
+config BR2_SIMPLE_DHCP
+	string "Name of the physical network interface to run DHCP on"
+	default ""
+	depends on !BR2_PACKAGE_SYSTEMD_NETWORKD
+	help
+	  The name of the network interface to configure automatically.
+	  A DHCP request will automatically happen on startup on the selected
+	  interface.
+
+	  If left empty, no automatic DHCP requests will take place.
+
+	  For more complicated network setups use an overlay to overwrite
+	  /etc/network/interfaces or add a networkd configuration file.
+
+comment "automatic network configuration via DHCP is not compatible with networkd"
+	depends on BR2_PACKAGE_SYSTEMD_NETWORKD
+
 config BR2_TARGET_TZ_INFO
 	bool "Install timezone info"
 	# No timezone for musl; only for uClibc or (e)glibc.
diff --git a/system/skeleton/etc/network/interfaces b/system/skeleton/etc/network/interfaces
deleted file mode 100644
index 218b82c..0000000
--- a/system/skeleton/etc/network/interfaces
+++ /dev/null
@@ -1,4 +0,0 @@ 
-# Configure Loopback
-auto lo
-iface lo inet loopback
-
diff --git a/system/system.mk b/system/system.mk
index e4a3160..b070919 100644
--- a/system/system.mk
+++ b/system/system.mk
@@ -38,6 +38,23 @@  ifneq ($(TARGET_GENERIC_ROOT_PASSWD),)
 TARGETS += host-mkpasswd
 endif
 
+define SIMPLE_NETWORK
+	mkdir -p $(TARGET_DIR)/etc/network/
+
+	echo "# interface file auto-generated by buildroot" >  $(TARGET_DIR)/etc/network/interfaces
+	echo                                                >> $(TARGET_DIR)/etc/network/interfaces
+	echo "auto lo"                                      >> $(TARGET_DIR)/etc/network/interfaces
+	echo "iface lo inet loopback"                       >> $(TARGET_DIR)/etc/network/interfaces
+	echo                                                >> $(TARGET_DIR)/etc/network/interfaces
+
+	if [ -n "$(BR2_SIMPLE_DHCP)" ] ; then \
+		echo "auto $(BR2_SIMPLE_DHCP)"              >> $(TARGET_DIR)/etc/network/interfaces ; \
+		echo "iface $(BR2_SIMPLE_DHCP) inet dhcp"   >> $(TARGET_DIR)/etc/network/interfaces ; \
+	fi
+
+endef
+TARGET_FINALIZE_HOOKS += SIMPLE_NETWORK
+
 ifeq ($(BR2_ROOTFS_SKELETON_DEFAULT),y)
 
 define SYSTEM_ROOT_PASSWD