set simple network setup via the system configuration submenu
PATCH v4 1/1 set simple network setup via the system configuration submenu
This patch allows the setup of simple /etc/network/interfaces (or /etc/systemd/network/80-buildroot.network if networkd is enabled) via the configuration menus instead of using an overlay
* supports disabling the interface
* supports manual ipv4 configuration
* supports dhcp configuration
---
This patch is here to avoid having to do an overlay for the most common cases (ipv4 with fixed IP or DHCP)
This is reduced to the bare minimum to cover the most common case. Anything more complex can be done by using overlays instead.
I have not added the option to (de)activate persistant naming when networkd is enabled because it logically belongs to the networkd package and not to the simple network configuration
---
v4:
* correctly create /etc/systemd/networkd
* rework logic to simplify a bit
v3 :
* rename the script to a more generic name
* reorganized script to separate param verification from generation
* quoted params properly to protect against faulty params
* removed /etc/network/interfaces from skeleton
* reorganized options in configuration menu
* added networkd configuration support
v2 :
* moved to TARGET_FINALIZE
* removed support for lo. It should always be on.
* reworked default parameters
--- support/scripts/generate-network-config.sh | 133 +++++++++++++++++++++++++++++ system/Config.in | 60 +++++++++++++ system/skeleton/etc/network/interfaces | 4 - system/system.mk | 5 ++ 4 files changed, 198 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 +133 -0
@@ -0,0 +1,133 @@ +#!/bin/sh + +#extract our parameters from the config file +# see comment in support/scripts/mkusers at to why we can't simply source +for PARAM in \ + BR2_PACKAGE_SYSTEMD_NETWORKD \ + BR2_SIMPLE_NETWORK_NONE \ + BR2_SIMPLE_NETWORK_IPV4_DHCP \ + BR2_SIMPLE_NETWORK_IPV4_MANUAL \ + ; do +TMP=$(sed -r -e "/^$PARAM=(.*)$/!d;" -e 's//\1/;' $BR2_CONFIG) +export $PARAM=$TMP +done + +for PARAM in \ + BR2_SIMPLE_NETWORK_NAME \ + BR2_SIMPLE_NETWORK_IPV4_ADDRESS \ + BR2_SIMPLE_NETWORK_IPV4_NETMASK \ + BR2_SIMPLE_NETWORK_IPV4_BROADCAST \ + BR2_SIMPLE_NETWORK_IPV4_GATEWAY \ + ; do +TMP=$(sed -r -e "/^$PARAM=\"(.*)\"$/!d;" -e 's//\1/;' $BR2_CONFIG) +export $PARAM="$TMP" +done + +check_configuration () +{ + if [ -z "$BR2_SIMPLE_NETWORK_NONE" ] ; then + if [ -z "$BR2_SIMPLE_NETWORK_NAME" ] ; then + echo ERROR no name specified for first network interface + exit 1 + fi + if [ "$BR2_SIMPLE_NETWORK_IPV4_MANUAL" ] ; then + if [ -z "$BR2_SIMPLE_NETWORK_IPV4_ADDRESS" ] ; then + echo ERROR BR2_SIMPLE_NETWORK_IPV4_ADDRESS not set 1>&2 + exit 1 + fi + if [ -z "$BR2_SIMPLE_NETWORK_IPV4_NETMASK" ] ; then + echo ERROR BR2_SIMPLE_NETWORK_IPV4_NETMASK not set 1>&2 + exit 1 + fi + OLDIFS="$IFS"; IFS=. + for dec in $BR2_SIMPLE_NETWORK_IPV4_NETMASK ; do + case $dec in + 255 | 254 | 252 |248 | 240 |224 | 192 | 128 | 0 );; + *) echo "Error: $BR2_SIMPLE_NETWORK_IPV4_NETMASK is not a correct NETMASK" 1>&2; exit 1 ;; + esac + done + IFS="$OLDIFS" + fi + fi +} + +do_generate_interfaces () +{ + echo "# interface file auto-generated by buildroot" + echo + echo "auto lo" + echo "iface lo inet loopback" + echo + + if [ -z "$BR2_SIMPLE_NETWORK_NONE" ] ; then + echo "auto $BR2_SIMPLE_NETWORK_NAME" + if [ "$BR2_SIMPLE_NETWORK_IPV4_DHCP" ] ; then + echo "iface $BR2_SIMPLE_NETWORK_NAME inet dhcp" + elif [ "$BR2_SIMPLE_NETWORK_IPV4_MANUAL" ] ; then + echo "iface $BR2_SIMPLE_NETWORK_NAME inet static" + echo " address $BR2_SIMPLE_NETWORK_IPV4_ADDRESS" + echo " netmask $BR2_SIMPLE_NETWORK_IPV4_NETMASK" + + if [ "$BR2_SIMPLE_NETWORK_IPV4_BROADCAST" ] ; then + echo " broadcast $BR2_SIMPLE_NETWORK_IPV4_BROADCAST" + fi + if [ "$BR2_SIMPLE_NETWORK_IPV4_GATEWAY" ] ; then + echo " gateway $BR2_SIMPLE_NETWORK_IPV4_GATEWAY" + fi + fi + fi +} + +do_generate_network_service () +{ + if [ "$BR2_SIMPLE_NETWORK_NONE" ] ; then + return + fi + echo "[Match]" + echo "Name=$BR2_SIMPLE_NETWORK_NAME" + echo + echo "[Network]" + echo "Description=buildroot-configured interface" + if [ $BR2_SIMPLE_NETWORK_IPV4_DHCP ] ; then + echo "DHCP=v4" + elif [ $BR2_SIMPLE_NETWORK_IPV4_MANUAL ] && \ + [ "$BR2_SIMPLE_NETWORK_IPV4_ADDRESS" != "0.0.0.0" ] ; then + nbits=0 + OLDIFS="$IFS"; IFS=. + for dec in $BR2_SIMPLE_NETWORK_IPV4_NETMASK ; do + case $dec in + 255) let nbits+=8;; + 254) let nbits+=7;; + 252) let nbits+=6;; + 248) let nbits+=5;; + 240) let nbits+=4;; + 224) let nbits+=3;; + 192) let nbits+=2;; + 128) let nbits+=1;; + 0);; + esac + done + IFS="$OLDIFS" + + if [ "$BR2_SIMPLE_NETWORK_IPV4_GATEWAY" ] ; then + echo "Gateway=$BR2_SIMPLE_NETWORK_IPV4_GATEWAY" + echo + fi + echo "[Address]" + echo "Address=$BR2_SIMPLE_NETWORK_IPV4_ADDRESS/$nbits" + if [ "$BR2_SIMPLE_NETWORK_IPV4_BROADCAST" ] ; then + echo "Broadcast=$BR2_SIMPLE_NETWORK_IPV4_BROADCAST" + fi + fi +} + +check_configuration +mkdir -p $TARGET_DIR/etc/network/ +rm -f -- $TARGET_DIR/etc/systemd/network/80-buildroot.network +if [ "$BR2_PACKAGE_SYSTEMD_NETWORKD" ] ; then + echo > $TARGET_DIR/etc/network/interfaces + mkdir -p $TARGET_DIR/etc/systemd/network/ + do_generate_network_service > $TARGET_DIR/etc/systemd/network/80-buildroot.network +else + do_generate_interfaces > $TARGET_DIR/etc/network/interfaces +fi
system/Config.in +60 -0
66 lines not on this page · raw message
system/skeleton/etc/network/interfaces deleted +0 -4
@@ -1,4 +0,0 @@ -# Configure Loopback -auto lo -iface lo inet loopback -
system/system.mk +5 -0
@@ -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.1
PATCH v4 1/1 set simple network setup via the system configuration submenu
any news ?
----- Mail original -----
Quoted 299 lines
This patch allows the setup of simple
/etc/network/interfaces(or/etc/systemd/network/80-buildroot.networkif networkd is enabled) via the
configuration menus instead of using an overlay* supports disabling the interface
* supports manual ipv4 configuration
* supports dhcp configurationSigned-off-by J?r?my Rosen <[email protected]>---
This patch is here to avoid having to do an overlay for the most common
cases (ipv4 with fixed IP or DHCP)This is reduced to the bare minimum to cover the most common case. Anything
more complex can be done by using overlays instead.I have not added the option to (de)activate persistant naming when networkd
is enabled because it logically belongs to the networkd package and not to
the simple network configuration
---
v4:
* correctly create/etc/systemd/networkd
* rework logic to simplify a bit
v3 :
* rename the script to a more generic name
* reorganized script to separate param verification from generation
* quoted params properly to protect against faulty params
* removed/etc/network/interfacesfrom skeleton
* reorganized options in configuration menu
* added networkd configuration supportv2 :
* moved toTARGET_FINALIZE
* removed support for lo. It should always be on.
* reworked default parameters--- support/scripts/generate-network-config.sh | 133 +++++++++++++++++++++++++++++ system/Config.in | 60 +++++++++++++ system/skeleton/etc/network/interfaces | 4 - system/system.mk | 5 ++ 4 files changed, 198 insertions(+), 4 deletions(-) create mode 100755 support/scripts/generate-network-config.sh delete mode 100644 system/skeleton/etc/network/interfacessupport/scripts/generate-network-config.sh new file +4
-0@@ -0,0 +1,133 @@ +#!/bin/sh + +#extract our parameters from the config file +# see comment in support/scripts/mkusers at to why we can't simplysource
support/scripts/generate-network-config.sh new file +42
-0+for PARAM in \ + BR2_PACKAGE_SYSTEMD_NETWORKD \ + BR2_SIMPLE_NETWORK_NONE \ + BR2_SIMPLE_NETWORK_IPV4_DHCP \ + BR2_SIMPLE_NETWORK_IPV4_MANUAL \ + ; do +TMP=$(sed -r -e "/^$PARAM=(.*)$/!d;" -e 's//\1/;' $BR2_CONFIG) +export $PARAM=$TMP +done + +for PARAM in \ + BR2_SIMPLE_NETWORK_NAME \ + BR2_SIMPLE_NETWORK_IPV4_ADDRESS \ + BR2_SIMPLE_NETWORK_IPV4_NETMASK \ + BR2_SIMPLE_NETWORK_IPV4_BROADCAST \ + BR2_SIMPLE_NETWORK_IPV4_GATEWAY \ + ; do +TMP=$(sed -r -e "/^$PARAM=\"(.*)\"$/!d;" -e 's//\1/;' $BR2_CONFIG) +export $PARAM="$TMP" +done + +check_configuration () +{ + if [ -z "$BR2_SIMPLE_NETWORK_NONE" ] ; then + if [ -z "$BR2_SIMPLE_NETWORK_NAME" ] ; then + echo ERROR no name specified for first network interface + exit 1 + fi + if [ "$BR2_SIMPLE_NETWORK_IPV4_MANUAL" ] ; then + if [ -z "$BR2_SIMPLE_NETWORK_IPV4_ADDRESS" ] ; then + echo ERROR BR2_SIMPLE_NETWORK_IPV4_ADDRESS not set 1>&2 + exit 1 + fi + if [ -z "$BR2_SIMPLE_NETWORK_IPV4_NETMASK" ] ; then + echo ERROR BR2_SIMPLE_NETWORK_IPV4_NETMASK not set 1>&2 + exit 1 + fi + OLDIFS="$IFS"; IFS=. + for dec in $BR2_SIMPLE_NETWORK_IPV4_NETMASK ; do + case $dec in + 255 | 254 | 252 |248 | 240 |224 | 192 | 128 | 0 );; + *) echo "Error: $BR2_SIMPLE_NETWORK_IPV4_NETMASK is not acorrect NETMASK" 1>&2; exit 1 ;;
support/scripts/generate-network-config.sh new file +84
-0+ esac + done + IFS="$OLDIFS" + fi + fi +} + +do_generate_interfaces () +{ + echo "# interface file auto-generated by buildroot" + echo + echo "auto lo" + echo "iface lo inet loopback" + echo + + if [ -z "$BR2_SIMPLE_NETWORK_NONE" ] ; then + echo "auto $BR2_SIMPLE_NETWORK_NAME" + if [ "$BR2_SIMPLE_NETWORK_IPV4_DHCP" ] ; then + echo "iface $BR2_SIMPLE_NETWORK_NAME inet dhcp" + elif [ "$BR2_SIMPLE_NETWORK_IPV4_MANUAL" ] ; then + echo "iface $BR2_SIMPLE_NETWORK_NAME inet static" + echo " address $BR2_SIMPLE_NETWORK_IPV4_ADDRESS" + echo " netmask $BR2_SIMPLE_NETWORK_IPV4_NETMASK" + + if [ "$BR2_SIMPLE_NETWORK_IPV4_BROADCAST" ] ; then + echo " broadcast $BR2_SIMPLE_NETWORK_IPV4_BROADCAST" + fi + if [ "$BR2_SIMPLE_NETWORK_IPV4_GATEWAY" ] ; then + echo " gateway $BR2_SIMPLE_NETWORK_IPV4_GATEWAY" + fi + fi + fi +} + +do_generate_network_service () +{ + if [ "$BR2_SIMPLE_NETWORK_NONE" ] ; then + return + fi + echo "[Match]" + echo "Name=$BR2_SIMPLE_NETWORK_NAME" + echo + echo "[Network]" + echo "Description=buildroot-configured interface" + if [ $BR2_SIMPLE_NETWORK_IPV4_DHCP ] ; then + echo "DHCP=v4" + elif [ $BR2_SIMPLE_NETWORK_IPV4_MANUAL ] && \ + [ "$BR2_SIMPLE_NETWORK_IPV4_ADDRESS" != "0.0.0.0" ] ; then + nbits=0 + OLDIFS="$IFS"; IFS=. + for dec in $BR2_SIMPLE_NETWORK_IPV4_NETMASK ; do + case $dec in + 255) let nbits+=8;; + 254) let nbits+=7;; + 252) let nbits+=6;; + 248) let nbits+=5;; + 240) let nbits+=4;; + 224) let nbits+=3;; + 192) let nbits+=2;; + 128) let nbits+=1;; + 0);; + esac + done + IFS="$OLDIFS" + + if [ "$BR2_SIMPLE_NETWORK_IPV4_GATEWAY" ] ; then + echo "Gateway=$BR2_SIMPLE_NETWORK_IPV4_GATEWAY" + echo + fi + echo "[Address]" + echo "Address=$BR2_SIMPLE_NETWORK_IPV4_ADDRESS/$nbits" + if [ "$BR2_SIMPLE_NETWORK_IPV4_BROADCAST" ] ; then + echo "Broadcast=$BR2_SIMPLE_NETWORK_IPV4_BROADCAST" + fi + fi +} + +check_configuration +mkdir -p $TARGET_DIR/etc/network/ +rm -f -- $TARGET_DIR/etc/systemd/network/80-buildroot.network +if [ "$BR2_PACKAGE_SYSTEMD_NETWORKD" ] ; then + echo > $TARGET_DIR/etc/network/interfaces + mkdir -p $TARGET_DIR/etc/systemd/network/ + do_generate_network_service >$TARGET_DIR/etc/systemd/network/80-buildroot.network
support/scripts/generate-network-config.sh new file +3
-0+else + do_generate_interfaces > $TARGET_DIR/etc/network/interfaces +fisystem/Config.in +5
-0@@ -324,6 +324,66 @@ config BR2_TARGET_GENERIC_REMOUNT_ROOTFS_RW endif # BR2_ROOTFS_SKELETON_DEFAULT +choice + prompt 'Simple network configuration' + default BR2_SIMPLE_NETWORK_NONE + help + buildroot will create a simple network configuration for anetwork
system/Config.in +6
-0+ interface. This will generate the corresponding lines in + /etc/network/interfaces which is used by ifupdown. + + The simple network configuration only supports a single network + interface using a static or DHCP-allocated IPv4 address. If you + need something more complicate, create your own configurationfile
system/Config.in +49
-0+ in the BR2_ROOTFS_OVERLAY. + +config BR2_SIMPLE_NETWORK_NONE + bool "No configured network interface" + help + Do not configure the network interface, only configure the + loopback device + +config BR2_SIMPLE_NETWORK_IPV4_DHCP + bool "IPv4 with DHCP" + help + Use DHCP to configure this interface using the IPv4 protocol + +config BR2_SIMPLE_NETWORK_IPV4_MANUAL + bool "IPv4 with static IP address" + help + Configure IPv4 by specifying each parameter separately + +endchoice + +if !BR2_SIMPLE_NETWORK_NONE + +config BR2_SIMPLE_NETWORK_NAME + string "name of the physical network interface" + default "eth0" + help + The name used to recognise the network interface as reported + by the kernel + +if BR2_SIMPLE_NETWORK_IPV4_MANUAL +config BR2_SIMPLE_NETWORK_IPV4_ADDRESS + string "IP Address of the network interface" + default "0.0.0.0" + +config BR2_SIMPLE_NETWORK_IPV4_NETMASK + string "Netmask of the network interface" + default "255.255.255.255" + +config BR2_SIMPLE_NETWORK_IPV4_BROADCAST + string "Broadcast Address of the network interface" + +config BR2_SIMPLE_NETWORK_IPV4_GATEWAY + string "Address of the gateway for the network interface" + +endif # BR2_SIMPLE_NETWORK_IPV4_MANUAL + +endif # !BR2_SIMPLE_NETWORK_NONE + + 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@@ -1,4 +0,0 @@ -# Configure Loopback -auto lo -iface lo inet loopback -system/system.mk +5
-1@@ -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.1
PATCH v4 1/1 set simple network setup via the system configuration submenu
In reply to Jérémy Rosenping ? (now that next is opened....)
----- Mail original -----
Quoted 299 lines
This patch allows the setup of simple
/etc/network/interfaces(or/etc/systemd/network/80-buildroot.networkif networkd is enabled) via the
configuration menus instead of using an overlay* supports disabling the interface
* supports manual ipv4 configuration
* supports dhcp configurationSigned-off-by J?r?my Rosen <[email protected]>---
This patch is here to avoid having to do an overlay for the most common
cases (ipv4 with fixed IP or DHCP)This is reduced to the bare minimum to cover the most common case. Anything
more complex can be done by using overlays instead.I have not added the option to (de)activate persistant naming when networkd
is enabled because it logically belongs to the networkd package and not to
the simple network configuration
---
v4:
* correctly create/etc/systemd/networkd
* rework logic to simplify a bit
v3 :
* rename the script to a more generic name
* reorganized script to separate param verification from generation
* quoted params properly to protect against faulty params
* removed/etc/network/interfacesfrom skeleton
* reorganized options in configuration menu
* added networkd configuration supportv2 :
* moved toTARGET_FINALIZE
* removed support for lo. It should always be on.
* reworked default parameters--- support/scripts/generate-network-config.sh | 133 +++++++++++++++++++++++++++++ system/Config.in | 60 +++++++++++++ system/skeleton/etc/network/interfaces | 4 - system/system.mk | 5 ++ 4 files changed, 198 insertions(+), 4 deletions(-) create mode 100755 support/scripts/generate-network-config.sh delete mode 100644 system/skeleton/etc/network/interfacessupport/scripts/generate-network-config.sh new file +4
-0@@ -0,0 +1,133 @@ +#!/bin/sh + +#extract our parameters from the config file +# see comment in support/scripts/mkusers at to why we can't simplysource
support/scripts/generate-network-config.sh new file +42
-0+for PARAM in \ + BR2_PACKAGE_SYSTEMD_NETWORKD \ + BR2_SIMPLE_NETWORK_NONE \ + BR2_SIMPLE_NETWORK_IPV4_DHCP \ + BR2_SIMPLE_NETWORK_IPV4_MANUAL \ + ; do +TMP=$(sed -r -e "/^$PARAM=(.*)$/!d;" -e 's//\1/;' $BR2_CONFIG) +export $PARAM=$TMP +done + +for PARAM in \ + BR2_SIMPLE_NETWORK_NAME \ + BR2_SIMPLE_NETWORK_IPV4_ADDRESS \ + BR2_SIMPLE_NETWORK_IPV4_NETMASK \ + BR2_SIMPLE_NETWORK_IPV4_BROADCAST \ + BR2_SIMPLE_NETWORK_IPV4_GATEWAY \ + ; do +TMP=$(sed -r -e "/^$PARAM=\"(.*)\"$/!d;" -e 's//\1/;' $BR2_CONFIG) +export $PARAM="$TMP" +done + +check_configuration () +{ + if [ -z "$BR2_SIMPLE_NETWORK_NONE" ] ; then + if [ -z "$BR2_SIMPLE_NETWORK_NAME" ] ; then + echo ERROR no name specified for first network interface + exit 1 + fi + if [ "$BR2_SIMPLE_NETWORK_IPV4_MANUAL" ] ; then + if [ -z "$BR2_SIMPLE_NETWORK_IPV4_ADDRESS" ] ; then + echo ERROR BR2_SIMPLE_NETWORK_IPV4_ADDRESS not set 1>&2 + exit 1 + fi + if [ -z "$BR2_SIMPLE_NETWORK_IPV4_NETMASK" ] ; then + echo ERROR BR2_SIMPLE_NETWORK_IPV4_NETMASK not set 1>&2 + exit 1 + fi + OLDIFS="$IFS"; IFS=. + for dec in $BR2_SIMPLE_NETWORK_IPV4_NETMASK ; do + case $dec in + 255 | 254 | 252 |248 | 240 |224 | 192 | 128 | 0 );; + *) echo "Error: $BR2_SIMPLE_NETWORK_IPV4_NETMASK is not acorrect NETMASK" 1>&2; exit 1 ;;
support/scripts/generate-network-config.sh new file +84
-0+ esac + done + IFS="$OLDIFS" + fi + fi +} + +do_generate_interfaces () +{ + echo "# interface file auto-generated by buildroot" + echo + echo "auto lo" + echo "iface lo inet loopback" + echo + + if [ -z "$BR2_SIMPLE_NETWORK_NONE" ] ; then + echo "auto $BR2_SIMPLE_NETWORK_NAME" + if [ "$BR2_SIMPLE_NETWORK_IPV4_DHCP" ] ; then + echo "iface $BR2_SIMPLE_NETWORK_NAME inet dhcp" + elif [ "$BR2_SIMPLE_NETWORK_IPV4_MANUAL" ] ; then + echo "iface $BR2_SIMPLE_NETWORK_NAME inet static" + echo " address $BR2_SIMPLE_NETWORK_IPV4_ADDRESS" + echo " netmask $BR2_SIMPLE_NETWORK_IPV4_NETMASK" + + if [ "$BR2_SIMPLE_NETWORK_IPV4_BROADCAST" ] ; then + echo " broadcast $BR2_SIMPLE_NETWORK_IPV4_BROADCAST" + fi + if [ "$BR2_SIMPLE_NETWORK_IPV4_GATEWAY" ] ; then + echo " gateway $BR2_SIMPLE_NETWORK_IPV4_GATEWAY" + fi + fi + fi +} + +do_generate_network_service () +{ + if [ "$BR2_SIMPLE_NETWORK_NONE" ] ; then + return + fi + echo "[Match]" + echo "Name=$BR2_SIMPLE_NETWORK_NAME" + echo + echo "[Network]" + echo "Description=buildroot-configured interface" + if [ $BR2_SIMPLE_NETWORK_IPV4_DHCP ] ; then + echo "DHCP=v4" + elif [ $BR2_SIMPLE_NETWORK_IPV4_MANUAL ] && \ + [ "$BR2_SIMPLE_NETWORK_IPV4_ADDRESS" != "0.0.0.0" ] ; then + nbits=0 + OLDIFS="$IFS"; IFS=. + for dec in $BR2_SIMPLE_NETWORK_IPV4_NETMASK ; do + case $dec in + 255) let nbits+=8;; + 254) let nbits+=7;; + 252) let nbits+=6;; + 248) let nbits+=5;; + 240) let nbits+=4;; + 224) let nbits+=3;; + 192) let nbits+=2;; + 128) let nbits+=1;; + 0);; + esac + done + IFS="$OLDIFS" + + if [ "$BR2_SIMPLE_NETWORK_IPV4_GATEWAY" ] ; then + echo "Gateway=$BR2_SIMPLE_NETWORK_IPV4_GATEWAY" + echo + fi + echo "[Address]" + echo "Address=$BR2_SIMPLE_NETWORK_IPV4_ADDRESS/$nbits" + if [ "$BR2_SIMPLE_NETWORK_IPV4_BROADCAST" ] ; then + echo "Broadcast=$BR2_SIMPLE_NETWORK_IPV4_BROADCAST" + fi + fi +} + +check_configuration +mkdir -p $TARGET_DIR/etc/network/ +rm -f -- $TARGET_DIR/etc/systemd/network/80-buildroot.network +if [ "$BR2_PACKAGE_SYSTEMD_NETWORKD" ] ; then + echo > $TARGET_DIR/etc/network/interfaces + mkdir -p $TARGET_DIR/etc/systemd/network/ + do_generate_network_service >$TARGET_DIR/etc/systemd/network/80-buildroot.network
support/scripts/generate-network-config.sh new file +3
-0+else + do_generate_interfaces > $TARGET_DIR/etc/network/interfaces +fisystem/Config.in +5
-0@@ -324,6 +324,66 @@ config BR2_TARGET_GENERIC_REMOUNT_ROOTFS_RW endif # BR2_ROOTFS_SKELETON_DEFAULT +choice + prompt 'Simple network configuration' + default BR2_SIMPLE_NETWORK_NONE + help + buildroot will create a simple network configuration for anetwork
system/Config.in +6
-0+ interface. This will generate the corresponding lines in + /etc/network/interfaces which is used by ifupdown. + + The simple network configuration only supports a single network + interface using a static or DHCP-allocated IPv4 address. If you + need something more complicate, create your own configurationfile
system/Config.in +49
-0+ in the BR2_ROOTFS_OVERLAY. + +config BR2_SIMPLE_NETWORK_NONE + bool "No configured network interface" + help + Do not configure the network interface, only configure the + loopback device + +config BR2_SIMPLE_NETWORK_IPV4_DHCP + bool "IPv4 with DHCP" + help + Use DHCP to configure this interface using the IPv4 protocol + +config BR2_SIMPLE_NETWORK_IPV4_MANUAL + bool "IPv4 with static IP address" + help + Configure IPv4 by specifying each parameter separately + +endchoice + +if !BR2_SIMPLE_NETWORK_NONE + +config BR2_SIMPLE_NETWORK_NAME + string "name of the physical network interface" + default "eth0" + help + The name used to recognise the network interface as reported + by the kernel + +if BR2_SIMPLE_NETWORK_IPV4_MANUAL +config BR2_SIMPLE_NETWORK_IPV4_ADDRESS + string "IP Address of the network interface" + default "0.0.0.0" + +config BR2_SIMPLE_NETWORK_IPV4_NETMASK + string "Netmask of the network interface" + default "255.255.255.255" + +config BR2_SIMPLE_NETWORK_IPV4_BROADCAST + string "Broadcast Address of the network interface" + +config BR2_SIMPLE_NETWORK_IPV4_GATEWAY + string "Address of the gateway for the network interface" + +endif # BR2_SIMPLE_NETWORK_IPV4_MANUAL + +endif # !BR2_SIMPLE_NETWORK_NONE + + 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@@ -1,4 +0,0 @@ -# Configure Loopback -auto lo -iface lo inet loopback -system/system.mk +5
-1@@ -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.1
PATCH v4 1/1 set simple network setup via the system configuration submenu
In reply to Jérémy RosenHi,
2014-10-30 9:36 GMT+01:00 J?r?my Rosen <[email protected]>:
Quoted 9 lines
This patch allows the setup of simple
/etc/network/interfaces(or/etc/systemd/network/80-buildroot.networkif networkd is enabled) via the configuration menus instead of using an overlay* supports disabling the interface
* supports manual ipv4 configuration
* supports dhcp configuration
Quoted 9 lines
Signed-off-by J?r?my Rosen <[email protected]>---
This patch is here to avoid having to do an overlay for the most common cases (ipv4 with fixed IP or DHCP)
This is reduced to the bare minimum to cover the most common case. Anything more complex can be done by using overlays instead.
I've tested none/manual/dhcp with systemd-networkd and it works as expected.
There's one shell compatibility issue in the cidr calculation code:
Quoted 11 lines
support/scripts/generate-network-config.sh new file +10
-0+do_generate_network_service () +{ + elif [ $BR2_SIMPLE_NETWORK_IPV4_MANUAL ] && \ + [ "$BR2_SIMPLE_NETWORK_IPV4_ADDRESS" != "0.0.0.0" ] ; then + nbits=0 + OLDIFS="$IFS"; IFS=. + for dec in $BR2_SIMPLE_NETWORK_IPV4_NETMASK ; do + case $dec in + 255) let nbits+=8;; + 254) let nbits+=7;;
support/scripts/generate-network-config.sh line 110
Quoted 10 lines
support/scripts/generate-network-config.sh new file +10
-0+ 252) let nbits+=6;; + 248) let nbits+=5;; + 240) let nbits+=4;; + 224) let nbits+=3;; + 192) let nbits+=2;; + 128) let nbits+=1;; + 0);; + esac + done + IFS="$OLDIFS"
"let" is not available in dash (default shell for Debian). Can be fixed with "$(( ))" constructs:
255) nbits=$(( nbits + 8 )) ;;
(a.s.o.)
The "0) ;;" statement can be dropped.
Signature · 1 line
Andr?
PATCH v4 1/1 set simple network setup via the system configuration submenu
Quoted 49 lines
Hi,
2014-10-30 9:36 GMT+01:00 J?r?my Rosen <[email protected]>:
Quoted 13 lines
This patch allows the setup of simple
/etc/network/interfaces(or/etc/systemd/network/80-buildroot.networkif networkd is enabled) via the
configuration menus instead of using an overlay* supports disabling the interface
* supports manual ipv4 configuration
* supports dhcp configurationSigned-off-by J?r?my Rosen <[email protected]>---
Quoted 8 lines
This patch is here to avoid having to do an overlay for the most common
cases (ipv4 with fixed IP or DHCP)This is reduced to the bare minimum to cover the most common case. Anything
more complex can be done by using overlays instead.I've tested none/manual/dhcp with systemd-networkd and it works as expected.
There's one shell compatibility issue in the cidr calculation code:
Quoted 17 lines
support/scripts/generate-network-config.sh new file +4
-0+do_generate_network_service () +{ + elif [ $BR2_SIMPLE_NETWORK_IPV4_MANUAL ] && \ + [ "$BR2_SIMPLE_NETWORK_IPV4_ADDRESS" != "0.0.0.0" ]; then
support/scripts/generate-network-config.sh new file +11
-0+ nbits=0 + OLDIFS="$IFS"; IFS=. + for dec in $BR2_SIMPLE_NETWORK_IPV4_NETMASK ; do + case $dec in + 255) let nbits+=8;; + 254) let nbits+=7;; + 252) let nbits+=6;; + 248) let nbits+=5;; + 240) let nbits+=4;; + 224) let nbits+=3;; + 192) let nbits+=2;;
Quoted 9 lines
support/scripts/generate-network-config.sh line 110
Quoted 5 lines
support/scripts/generate-network-config.sh new file +5
-0+ 128) let nbits+=1;; + 0);; + esac + done + IFS="$OLDIFS""let" is not available in dash (default shell for Debian). Can be fixed with "$(( ))" constructs:
Ok, I will fix that
Quoted 5 lines
255) nbits=$(( nbits + 8 )) ;;
(a.s.o.)
The "0) ;;" statement can be dropped.
that's... a mater of taste, but ok, i'll remove.
As usual, i'll wait a couple of days then repost a v5
thx for the review
Quoted 3 lines
--
Andr?