Skip to contentSkip to conversation

Allow a single DHCP configuration via the system configuration submenu

PATCH New Jérémy Rosen 3 participants 5 messages Dec 17, 2014 – Dec 18, 2014

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Allow a single DHCP configuration via the system configuration submenu

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

---
 support/scripts/generate-network-config.sh | 24 ++++++++++++++++++++++++
 system/Config.in                           | 18 ++++++++++++++++++
 system/skeleton/etc/network/interfaces     |  4 ----
 system/system.mk                           |  5 +++++
 4 files changed, 47 insertions(+), 4 deletions(-)
 create mode 100755 support/scripts/generate-network-config.sh
 delete mode 100644 system/skeleton/etc/network/interfaces
support/scripts/generate-network-config.sh new file +24 -0
new file mode 100755
index 0000000..92f8d16
@@ -0,0 +1,24 @@
+#!/bin/sh
+
+export BR2_SIMPLE_DHCP=$(sed -r -e "/^BR2_SIMPLE_DHCP=(.*)$/!d;" -e 's//\1/;' $BR2_CONFIG)
+
+export BR2_SIMPLE_DHCP_INTERFACE="$(sed -r -e "/^BR2_SIMPLE_DHCP_INTERFACE=\"(.*)\"$/!d;" -e 's//\1/;' $BR2_CONFIG)"
+
+do_generate_interfaces ()
+{
+	echo "# interface file auto-generated by buildroot"
+	echo
+	echo "auto lo"
+	echo "iface lo inet loopback"
+	echo
+
+	if [ -z "$BR2_SIMPLE_DHCP" ] ; then
+		return
+        fi
+
+	echo "auto $BR2_SIMPLE_DHCP_INTERFACE"
+	echo "iface $BR2_SIMPLE_DHCP_INTERFACE inet dhcp"
+}
+
+mkdir -p $TARGET_DIR/etc/network/
+do_generate_interfaces > $TARGET_DIR/etc/network/interfaces
system/Config.in +18 -0
index a3b7aff..10a81e9 100644
@@ -324,6 +324,24 @@ config BR2_TARGET_GENERIC_REMOUNT_ROOTFS_RW
 
 endif # BR2_ROOTFS_SKELETON_DEFAULT
 
+config BR2_SIMPLE_DHCP
+	bool "automatic network configuration via DHCP"
+	default n
+	depends on !BR2_PACKAGE_SYSTEMD_NETWORKD
+	help
+	  Automatically do a DHCP request on startup on selected interface at 
+	  startup. For more complicated setups use an overlay.
+
+comment "automatic network configuration via DHCP is not compatible with networkd"
+	depends on BR2_PACKAGE_SYSTEMD_NETWORKD
+
+config BR2_SIMPLE_DHCP_INTERFACE
+	string "name of the physical network interface to run DHCP on"
+	depends on BR2_SIMPLE_DHCP
+	default eth0
+	help
+	  The name of the network interface to configure automatically
+
 config BR2_TARGET_TZ_INFO
 	bool "Install timezone info"
 	# No timezone for musl; only for uClibc or (e)glibc.
system/skeleton/etc/network/interfaces deleted +0 -4
deleted file mode 100644
index 218b82c..0000000
@@ -1,4 +0,0 @@
-# Configure Loopback
-auto lo
-iface lo inet loopback
-
system/system.mk +5 -0
index e4a3160..bb933f6 100644
@@ -38,6 +38,11 @@ ifneq ($(TARGET_GENERIC_ROOT_PASSWD),)
 TARGETS += host-mkpasswd
 endif
 
+define SIMPLE_NETWORK
+	$(TOPDIR)/support/scripts/generate-network-config.sh $(TARGET_DIR)
+endef
+TARGET_FINALIZE_HOOKS += SIMPLE_NETWORK
+
 ifeq ($(BR2_ROOTFS_SKELETON_DEFAULT),y)
 
 define SYSTEM_ROOT_PASSWD
Signature · 1 line
2.1.3
#1 lore raw

PATCH 1/1 Allow a single DHCP configuration via the system configuration submenu

Hi Jeremy,

Quoted 56 lines · J?r?my Rosen

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

---
 support/scripts/generate-network-config.sh | 24 ++++++++++++++++++++++++
 system/Config.in                           | 18 ++++++++++++++++++
 system/skeleton/etc/network/interfaces     |  4 ----
 system/system.mk                           |  5 +++++
 4 files changed, 47 insertions(+), 4 deletions(-)
 create mode 100755 support/scripts/generate-network-config.sh
 delete mode 100644 system/skeleton/etc/network/interfaces
support/scripts/generate-network-config.sh new file +24 -0
new file mode 100755
index 0000000..92f8d16
@@ -0,0 +1,24 @@
+#!/bin/sh
+
+export BR2_SIMPLE_DHCP=$(sed -r -e "/^BR2_SIMPLE_DHCP=(.*)$/!d;" -e 's//\1/;' $BR2_CONFIG)
+
+export BR2_SIMPLE_DHCP_INTERFACE="$(sed -r -e "/^BR2_SIMPLE_DHCP_INTERFACE=\"(.*)\"$/!d;" -e 's//\1/;' $BR2_CONFIG)"
+
+do_generate_interfaces ()
+{
+       echo "# interface file auto-generated by buildroot"
+       echo
+       echo "auto lo"
+       echo "iface lo inet loopback"
+       echo
+
+       if [ -z "$BR2_SIMPLE_DHCP" ] ; then
+               return
+        fi
+
+       echo "auto $BR2_SIMPLE_DHCP_INTERFACE"
+       echo "iface $BR2_SIMPLE_DHCP_INTERFACE inet dhcp"
+}
+
+mkdir -p $TARGET_DIR/etc/network/
+do_generate_interfaces > $TARGET_DIR/etc/network/interfaces
system/Config.in +0 -0
index a3b7aff..10a81e9 100644
@@ -324,6 +324,24 @@ config BR2_TARGET_GENERIC_REMOUNT_ROOTFS_RW
 
 endif # BR2_ROOTFS_SKELETON_DEFAULT
 

system/Config.in config BR2_TARGET_GENERIC_REMOUNT_ROOTFS_RW · line 336

Quoted 10 lines
system/Config.in +10 -0
+config BR2_SIMPLE_DHCP
+       bool "automatic network configuration via DHCP"
+       default n
+       depends on !BR2_PACKAGE_SYSTEMD_NETWORKD
+       help
+         Automatically do a DHCP request on startup on selected interface at
+         startup. For more complicated setups use an overlay.
+
+comment "automatic network configuration via DHCP is not compatible with networkd"
+       depends on BR2_PACKAGE_SYSTEMD_NETWORKD

IIRC, comment does not support help message, but it could be worthwhile to document somewhere how to do this in the systemd case, without needing reading the git log ;-)

Quoted 40 lines
system/Config.in +8 -0
+
+config BR2_SIMPLE_DHCP_INTERFACE
+       string "name of the physical network interface to run DHCP on"
+       depends on BR2_SIMPLE_DHCP
+       default eth0
+       help
+         The name of the network interface to configure automatically
+
 config BR2_TARGET_TZ_INFO
        bool "Install timezone info"
        # No timezone for musl; only for uClibc or (e)glibc.
system/skeleton/etc/network/interfaces deleted +0 -4
deleted file mode 100644
index 218b82c..0000000
@@ -1,4 +0,0 @@
-# Configure Loopback
-auto lo
-iface lo inet loopback
-
system/system.mk +5 -1
index e4a3160..bb933f6 100644
@@ -38,6 +38,11 @@ ifneq ($(TARGET_GENERIC_ROOT_PASSWD),)
 TARGETS += host-mkpasswd
 endif
 
+define SIMPLE_NETWORK
+       $(TOPDIR)/support/scripts/generate-network-config.sh $(TARGET_DIR)
+endef
+TARGET_FINALIZE_HOOKS += SIMPLE_NETWORK
+
 ifeq ($(BR2_ROOTFS_SKELETON_DEFAULT),y)
 
 define SYSTEM_ROOT_PASSWD
--

2.1.3

Quoted 4 lines

_______________________________________________
buildroot mailing list
buildroot at busybox.net
http://lists.busybox.net/mailman/listinfo/buildroot

Regards,

Signature · 1 line
Samuel
#2 lore raw

PATCH 1/1 Allow a single DHCP configuration via the system configuration submenu

Hey Samuel

----- Mail original -----

Quoted 68 lines

Hi Jeremy,

Quoted 64 lines · J?r?my Rosen

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

---
 support/scripts/generate-network-config.sh | 24
 ++++++++++++++++++++++++
 system/Config.in                           | 18 ++++++++++++++++++
 system/skeleton/etc/network/interfaces     |  4 ----
 system/system.mk                           |  5 +++++
 4 files changed, 47 insertions(+), 4 deletions(-)
 create mode 100755 support/scripts/generate-network-config.sh
 delete mode 100644 system/skeleton/etc/network/interfaces
support/scripts/generate-network-config.sh new file +5 -1
new file mode 100755
index 0000000..92f8d16
@@ -0,0 +1,24 @@
+#!/bin/sh
+
+export BR2_SIMPLE_DHCP=$(sed -r -e "/^BR2_SIMPLE_DHCP=(.*)$/!d;"
-e 's//\1/;' $BR2_CONFIG)
+
+export BR2_SIMPLE_DHCP_INTERFACE="$(sed -r -e

"/^BR2_SIMPLE_DHCP_INTERFACE=\"(.*)\"$/!d;" -e 's//\1/;' $BR2_CONFIG)"

support/scripts/generate-network-config.sh new file +19 -0
+
+do_generate_interfaces ()
+{
+       echo "# interface file auto-generated by buildroot"
+       echo
+       echo "auto lo"
+       echo "iface lo inet loopback"
+       echo
+
+       if [ -z "$BR2_SIMPLE_DHCP" ] ; then
+               return
+        fi
+
+       echo "auto $BR2_SIMPLE_DHCP_INTERFACE"
+       echo "iface $BR2_SIMPLE_DHCP_INTERFACE inet dhcp"
+}
+
+mkdir -p $TARGET_DIR/etc/network/
+do_generate_interfaces > $TARGET_DIR/etc/network/interfaces
system/Config.in +0 -0
index a3b7aff..10a81e9 100644
@@ -324,6 +324,24 @@ config BR2_TARGET_GENERIC_REMOUNT_ROOTFS_RW
 
 endif # BR2_ROOTFS_SKELETON_DEFAULT
 
Quoted 17 lines
Quoted 10 lines
system/Config.in +6 -0
+config BR2_SIMPLE_DHCP
+       bool "automatic network configuration via DHCP"
+       default n
+       depends on !BR2_PACKAGE_SYSTEMD_NETWORKD
+       help
+         Automatically do a DHCP request on startup on selected

interface at

system/Config.in +3 -0
+         startup. For more complicated setups use an overlay.
+
+comment "automatic network configuration via DHCP is not
Quoted 2 lines

compatible with networkd"
+ depends on BR2_PACKAGE_SYSTEMD_NETWORKD

IIRC, comment does not support help message, but it could be worthwhile to document somewhere how to do this in the systemd case, without needing reading the git log ;-)

well, the answer is "the usual way, use overlays" and "read the man page for networkd".

systemd in general has pretty good set of docs, and we don't document most of the ways to customize your image. BR users are supposed to know system configuration (we don't document /etc/network/interfaces)

so I personally think it's not really needed, but if you think it's really necessary and you tell me where to add a note, I can write something... I have a good understanding of networkd with my previous attempt at network configuration

Quoted 54 lines
Quoted 44 lines
system/Config.in +3 -0
+
+config BR2_SIMPLE_DHCP_INTERFACE
+       string "name of the physical network interface to run DHCP

on"

system/Config.in +4 -0
+       depends on BR2_SIMPLE_DHCP
+       default eth0
+       help
+         The name of the network interface to configure

automatically

system/Config.in +1 -0
+
 config BR2_TARGET_TZ_INFO
        bool "Install timezone info"
        # No timezone for musl; only for uClibc or (e)glibc.
system/skeleton/etc/network/interfaces deleted +0 -4
deleted file mode 100644
index 218b82c..0000000
@@ -1,4 +0,0 @@
-# Configure Loopback
-auto lo
-iface lo inet loopback
-
system/system.mk +5 -0
index e4a3160..bb933f6 100644
@@ -38,6 +38,11 @@ ifneq ($(TARGET_GENERIC_ROOT_PASSWD),)
 TARGETS += host-mkpasswd
 endif
 
+define SIMPLE_NETWORK
+       $(TOPDIR)/support/scripts/generate-network-config.sh
 $(TARGET_DIR)
+endef
+TARGET_FINALIZE_HOOKS += SIMPLE_NETWORK
+
 ifeq ($(BR2_ROOTFS_SKELETON_DEFAULT),y)
 

define SYSTEM_ROOT_PASSWD
--
2.1.3

Quoted 4 lines

_______________________________________________
buildroot mailing list
buildroot at busybox.net
http://lists.busybox.net/mailman/listinfo/buildroot

Regards,

--
Samuel

#3 lore raw

PATCH 1/1 Allow a single DHCP configuration via the system configuration submenu

In reply to Jérémy Rosen

Dear J?r?my Rosen,

Quoted 1 line · J?r?my Rosen
 support/scripts/generate-network-config.sh | 24 ++++++++++++++++++++++++

Do we really need a helper script to do this?

NETWORK_IFACES = $(TARGET_DIR)/etc/network/interfaces NETWORK_DHCP_IFACE = $(call qstrip,$(BR2_SIMPLE_DHCP_INTERFACE))

define NETWORK_ADD_DHCP_INTERFACE

	echo "auto $(NETWORK_DHCP_IFACE)" >> $(NETWORK_IFACES)
	echo "iface $(NETWORK_DHCP_IFACE) inet dhcp" >> $(NETWORK_IFACES)

endef

define NETWORK_CREATE_IFACES_FILE

	rm -f $(NETWORK_IFACES)
	echo "auto lo" >> $(NETWORK_IFACES)
	echo "iface lo inet loopback" >> $(NETWORK_IFACES)
	$(NETWORK_ADD_DHCP_INTERFACE)

endef

TARGET_FINALIZE_HOOKS += NETWORK_CREATE_IFACES_FILE

Quoted 7 lines
system/Config.in +7 -0
+config BR2_SIMPLE_DHCP
+	bool "automatic network configuration via DHCP"
+	default n
+	depends on !BR2_PACKAGE_SYSTEMD_NETWORKD
+	help
+	  Automatically do a DHCP request on startup on selected interface at 
+	  startup. For more complicated setups use an overlay.

system/Config.in config BR2_TARGET_GENERIC_REMOUNT_ROOTFS_RW · line 343

Quoted 10 lines
system/Config.in +10 -0
+
+comment "automatic network configuration via DHCP is not compatible with networkd"
+	depends on BR2_PACKAGE_SYSTEMD_NETWORKD
+
+config BR2_SIMPLE_DHCP_INTERFACE
+	string "name of the physical network interface to run DHCP on"
+	depends on BR2_SIMPLE_DHCP
+	default eth0
+	help
+	  The name of the network interface to configure automatically

Why two options? Just make the BR2_SIMPLE_DHCP_INTERFACE empty by default (does nothing), and when non-empty, used as the DHCP network interface.

Best regards,

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
#4 lore raw

PATCH 1/1 Allow a single DHCP configuration via the system configuration submenu

----- Mail original -----

Quoted 9 lines

Dear J?r?my Rosen,

Quoted 2 lines · J?r?my Rosen
 support/scripts/generate-network-config.sh | 24

++++++++++++++++++++++++

Do we really need a helper script to do this?

That's... debatable. I think it's a bit long for inline, but it's a matter of taste. I'll inline in simplify it (do everythin without functions to shorten a bit)

Quoted 32 lines

NETWORK_IFACES = $(TARGET_DIR)/etc/network/interfaces NETWORK_DHCP_IFACE = $(call qstrip,$(BR2_SIMPLE_DHCP_INTERFACE))

define NETWORK_ADD_DHCP_INTERFACE

	echo "auto $(NETWORK_DHCP_IFACE)" >> $(NETWORK_IFACES)
	echo "iface $(NETWORK_DHCP_IFACE) inet dhcp" >> $(NETWORK_IFACES)

endef

define NETWORK_CREATE_IFACES_FILE

	rm -f $(NETWORK_IFACES)
	echo "auto lo" >> $(NETWORK_IFACES)
	echo "iface lo inet loopback" >> $(NETWORK_IFACES)
	$(NETWORK_ADD_DHCP_INTERFACE)

endef

TARGET_FINALIZE_HOOKS += NETWORK_CREATE_IFACES_FILE

Quoted 15 lines
system/Config.in +6 -0
+config BR2_SIMPLE_DHCP
+	bool "automatic network configuration via DHCP"
+	default n
+	depends on !BR2_PACKAGE_SYSTEMD_NETWORKD
+	help
+	  Automatically do a DHCP request on startup on selected

interface at

system/Config.in +3 -0
+	  startup. For more complicated setups use an overlay.
+
+comment "automatic network configuration via DHCP is not

compatible with networkd"

system/Config.in +4 -0
+	depends on BR2_PACKAGE_SYSTEMD_NETWORKD
+
+config BR2_SIMPLE_DHCP_INTERFACE
+	string "name of the physical network interface to run DHCP on"
Quoted 9 lines

system/Config.in config BR2_TARGET_GENERIC_REMOUNT_ROOTFS_RW · line 343

Quoted 4 lines
system/Config.in +4 -0
+	depends on BR2_SIMPLE_DHCP
+	default eth0
+	help
+	  The name of the network interface to configure automatically

Why two options? Just make the BR2_SIMPLE_DHCP_INTERFACE empty by default (does nothing), and when non-empty, used as the DHCP network interface.

I did it for better presentation in the menuconfig menu, I thought one option to activate and then another one to set, rather than an empty-by-default one was cleaner... but if you think a single one is better it's easy to change...

I'll wait for more comments and submit a v2 when I have more feedback

Quoted 8 lines

Best regards,

Thomas
--
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com