[Buildroot] [PATCH] Allow a single DHCP configuration via the system configuration submenu

Samuel Martin s.martin49 at gmail.com
Wed Dec 17 16:30:29 UTC 2014


Hi Jeremy,

On Wed, Dec 17, 2014 at 5:15 PM, Jérémy Rosen <jeremy.rosen at 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 at openwide.fr>
> ---
>  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
>
> diff --git a/support/scripts/generate-network-config.sh b/support/scripts/generate-network-config.sh
> new file mode 100755
> index 0000000..92f8d16
> --- /dev/null
> +++ b/support/scripts/generate-network-config.sh
> @@ -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
> diff --git a/system/Config.in b/system/Config.in
> index a3b7aff..10a81e9 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
> +       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 ;-)

> +
> +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.
> 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..bb933f6 100644
> --- a/system/system.mk
> +++ b/system/system.mk
> @@ -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
>
> _______________________________________________
> buildroot mailing list
> buildroot at busybox.net
> http://lists.busybox.net/mailman/listinfo/buildroot

Regards,

-- 
Samuel



More information about the buildroot mailing list