All of lore.kernel.org
 help / color / mirror / Atom feed
* [Buildroot] [PATCH v3] Allow a single DHCP configuration via the system configuration submenu
@ 2015-01-08  9:36 Jérémy Rosen
  2015-01-09 10:28 ` Károly Kasza
  0 siblings, 1 reply; 3+ messages in thread
From: Jérémy Rosen @ 2015-01-08  9:36 UTC (permalink / raw)
  To: buildroot

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>

---
v3 : - move the condition from shell logic to make logic
       (reusing the code proposed by Thomas Petazzoni)

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                       | 25 +++++++++++++++++++++++++
 3 files changed, 43 insertions(+), 4 deletions(-)
 delete mode 100644 system/skeleton/etc/network/interfaces

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..96aa342 100644
--- a/system/system.mk
+++ b/system/system.mk
@@ -38,6 +38,31 @@ ifneq ($(TARGET_GENERIC_ROOT_PASSWD),)
 TARGETS += host-mkpasswd
 endif
 
+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
+
 ifeq ($(BR2_ROOTFS_SKELETON_DEFAULT),y)
 
 define SYSTEM_ROOT_PASSWD
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [Buildroot] [PATCH v3] Allow a single DHCP configuration via the system configuration submenu
  2015-01-08  9:36 [Buildroot] [PATCH v3] Allow a single DHCP configuration via the system configuration submenu Jérémy Rosen
@ 2015-01-09 10:28 ` Károly Kasza
  2015-01-15 16:26   ` Gustavo Zacarias
  0 siblings, 1 reply; 3+ messages in thread
From: Károly Kasza @ 2015-01-09 10:28 UTC (permalink / raw)
  To: buildroot

Hi J?r?my, Thomas, Gustavo, list,

On Thu, Jan 8, 2015 at 10:36 AM, J?r?my Rosen <jeremy.rosen@openwide.fr>
wrote:

> 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>
>
> Tested-by: Karoly Kasza <kaszak@gmail.com>
Reviewed-by: Karoly Kasza <kaszak@gmail.com>

Tested with uClibc, successfully built different rootfs.ext images and
booted them.
Tested with master branch, x86_64 arch in QEMU, internal toolchain GCC
4.9.2 w/ uclibc, Linux 3.18.1.

I recommend maybe adding a dependency in Config.in later for package
ifupdown (not yet merged, proposed by Gustavo), if no Busybox is present in
the system.

Regards,
Karoly
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.busybox.net/pipermail/buildroot/attachments/20150109/1d10d023/attachment.html>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Buildroot] [PATCH v3] Allow a single DHCP configuration via the system configuration submenu
  2015-01-09 10:28 ` Károly Kasza
@ 2015-01-15 16:26   ` Gustavo Zacarias
  0 siblings, 0 replies; 3+ messages in thread
From: Gustavo Zacarias @ 2015-01-15 16:26 UTC (permalink / raw)
  To: buildroot

On 01/09/2015 07:28 AM, K?roly Kasza wrote:

Hi J?r?my, K?roly, the rest.

> Tested-by: Karoly Kasza <kaszak at gmail.com <mailto:kaszak@gmail.com>>
> Reviewed-by: Karoly Kasza <kaszak at gmail.com <mailto:kaszak@gmail.com>>
> 
> Tested with uClibc, successfully built different rootfs.ext images and
> booted them.
> Tested with master branch, x86_64 arch in QEMU, internal toolchain GCC
> 4.9.2 w/ uclibc, Linux 3.18.1.
> 
> I recommend maybe adding a dependency in Config.in later for package
> ifupdown (not yet merged, proposed by Gustavo), if no Busybox is present
> in the system.

I wouldn't go as far as selecting ifupdown, but possibly depending on
BR2_PACKAGE_BUSYBOX | BR2_PACKAGE_IFUPDOWN because the option will
always be "set" (it's a string) and you can't do that easily.
That way the option will vanish if there's no proper provider of
ifupdown which is the interpreter of /etc/network/interfaces.
Of course busybox may lack ifupdown for custom configs, but that's the
case for so many things (a shell, for example) that we can't cover weird
scenarios in a sane way, and it might just be intended.
Other than that:

Tested-by: Gustavo Zacarias <gustavo@zacarias.com.ar>
Acked-by: Gustavo Zacarias <gustavo@zacarias.com.ar>

(qemu-arm-versatile-defconfig default busybox init and systemd).
Regards.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-01-15 16:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-08  9:36 [Buildroot] [PATCH v3] Allow a single DHCP configuration via the system configuration submenu Jérémy Rosen
2015-01-09 10:28 ` Károly Kasza
2015-01-15 16:26   ` Gustavo Zacarias

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.