set simple network setup via the system configuration submenu
PATCH 1/1 set simple network setup via the system configuration submenu
This patch allows the setup of simple /etc/network/interfaces via the configuration menus instead of using an overlay
* supports the loopback interface
* supports one normal interface (renamable)
* 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)
I can make it more complex (second network if, support ipv6) depending on what people want/need, but I want to keep it simple. The point is to avoid having to tweak overlays to change stuff that everybody needs to change for prototyping
With regards to systemd, as far as I could figure it still uses /etc/network/interfaces but with different names. AFAIU there is no sane default to replace the "eth0" name so I did not put a different default when systemd is used
--- Makefile | 1 + support/scripts/generate-interfaces.sh | 75 ++++++++++++++++++++++++++++++++ system/Config.in | 78 ++++++++++++++++++++++++++++++++++ 3 files changed, 154 insertions(+) create mode 100755 support/scripts/generate-interfaces.sh
Makefile +1 -0
@@ -477,6 +477,7 @@ $(BUILD_DIR)/.root: @ln -snf lib $(TARGET_DIR)/$(LIB_SYMLINK) @mkdir -p $(TARGET_DIR)/usr @ln -snf lib $(TARGET_DIR)/usr/$(LIB_SYMLINK) + ./support/scripts/generate-interfaces.sh $(TARGET_DIR) touch $@ $(TARGET_DIR): $(BUILD_DIR)/.root
support/scripts/generate-interfaces.sh new file +75 -0
75 lines not on this page · raw message
system/Config.in +78 -0
82 lines not on this page · raw message
Signature · 1 line
2.1.0
PATCH 1/1 set simple network setup via the system configuration submenu
bump ?
I can rebase if need be, but I'm pretty sure there are some comments to be done on that...
----- Mail original -----
Quoted 231 lines
This patch allows the setup of simple
/etc/network/interfacesvia the configuration menus instead of using an overlay* supports the loopback interface
* supports one normal interface (renamable)
* 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)I can make it more complex (second network if, support ipv6) depending on
what people want/need, but I want to keep it simple. The point is to avoid
having to tweak overlays to change stuff that everybody needs to change for
prototypingWith regards to systemd, as far as I could figure it still uses
/etc/network/interfacesbut with different names. AFAIU there is no sane
default to replace the "eth0" name so I did not put a different default
when systemd is used--- Makefile | 1 + support/scripts/generate-interfaces.sh | 75 ++++++++++++++++++++++++++++++++ system/Config.in | 78 ++++++++++++++++++++++++++++++++++ 3 files changed, 154 insertions(+) create mode 100755 support/scripts/generate-interfaces.shMakefile +1
-0@@ -477,6 +477,7 @@ $(BUILD_DIR)/.root: @ln -snf lib $(TARGET_DIR)/$(LIB_SYMLINK) @mkdir -p $(TARGET_DIR)/usr @ln -snf lib $(TARGET_DIR)/usr/$(LIB_SYMLINK) + ./support/scripts/generate-interfaces.sh $(TARGET_DIR) touch $@ $(TARGET_DIR): $(BUILD_DIR)/.rootsupport/scripts/generate-interfaces.sh new file +68
-0@@ -0,0 +1,75 @@ +#!/bin/sh + + +#extract our parameters from the config file +for PARAM in \ + BR2_SIMPLE_NETWORK_LO_ENABLE \ + BR2_SIMPLE_NETWORK_LO_AUTO \ + \ + BR2_SIMPLE_NETWORK_1_ENABLE \ + BR2_SIMPLE_NETWORK_1_AUTO \ + BR2_SIMPLE_NETWORK_1_IPV4_DHCP \ + BR2_SIMPLE_NETWORK_1_IPV4_MANUAL \ + ; do +TMP=$(sed -r -e "/^$PARAM=(.*)$/!d;" -e 's//\1/;' $BR2_CONFIG) + export $PARAM=$TMP +done + +for PARAM in \ + BR2_SIMPLE_NETWORK_1_NAME \ + BR2_SIMPLE_NETWORK_1_IPV4_ADDRESS \ + BR2_SIMPLE_NETWORK_1_IPV4_NETMASK \ + BR2_SIMPLE_NETWORK_1_IPV4_BROADCAST \ + BR2_SIMPLE_NETWORK_1_IPV4_GATEWAY \ + ; do +TMP=$(sed -r -e "/^$PARAM=\"(.*)\"$/!d;" -e 's//\1/;' $BR2_CONFIG) + export $PARAM=$TMP +done + + + +IFACE_FILE=$TARGET_DIR/etc/network/interfaces +echo -n > $IFACE_FILE # empty the file + +if [ $BR2_SIMPLE_NETWORK_LO_ENABLE ] ; then + if [ $BR2_SIMPLE_NETWORK_LO_AUTO ] ; then + echo "auto lo">> $IFACE_FILE + fi + echo "iface lo inet loopback">> $IFACE_FILE + echo >>$IFACE_FILE +fi + +if [ $BR2_SIMPLE_NETWORK_1_ENABLE ] ; then + if [ -z $BR2_SIMPLE_NETWORK_1_NAME ] ; then + echo ERROR no name specified for first network interface + exit 1 + fi + if [ $BR2_SIMPLE_NETWORK_1_AUTO ] ; then + echo "auto $BR2_SIMPLE_NETWORK_1_NAME">> $IFACE_FILE + fi + if [ $BR2_SIMPLE_NETWORK_1_IPV4_DHCP ] ; then + echo "iface $BR2_SIMPLE_NETWORK_1_NAME inet dhcp">> $IFACE_FILE + elif [ $BR2_SIMPLE_NETWORK_1_IPV4_MANUAL ] ; then + for PARAM in \ + BR2_SIMPLE_NETWORK_1_IPV4_ADDRESS \ + BR2_SIMPLE_NETWORK_1_IPV4_NETMASK \ + BR2_SIMPLE_NETWORK_1_IPV4_BROADCAST \ + BR2_SIMPLE_NETWORK_1_IPV4_GATEWAY \ + ; do + eval VALUE=\$$PARAM + if [ -z $VALUE ] ; then + echo ERROR $PARAM not set + exit 1 + fi + done + echo "iface $BR2_SIMPLE_NETWORK_1_NAME inet static">> $IFACE_FILE + echo " address $BR2_SIMPLE_NETWORK_1_IPV4_ADDRESS">> $IFACE_FILE + echo " netmask $BR2_SIMPLE_NETWORK_1_IPV4_NETMASK">> $IFACE_FILE + echo " broadcast $BR2_SIMPLE_NETWORK_1_IPV4_BROADCAST">>$IFACE_FILE
support/scripts/generate-interfaces.sh new file +7
-0+ echo " gateway $BR2_SIMPLE_NETWORK_1_IPV4_GATEWAY">> $IFACE_FILE + else + echo Incorrect buildroot configuration + exit 1 + fi + echo >>$IFACE_FILE +fisystem/Config.in +5
-0@@ -389,4 +389,82 @@ config BR2_ROOTFS_POST_SCRIPT_ARGS directory / images directory. The arguments in this option will be passed *after* those. +menuconfig BR2_SIMPLE_NETWORK + bool "Generate simple network configuration" + default n + help + Use buildroot to set network configuration during the buildprocess
system/Config.in +14
-0+ +if BR2_SIMPLE_NETWORK +menuconfig BR2_SIMPLE_NETWORK_LO_ENABLE + bool "enable loopback device" + default y + help + Enables the loopback interface at startup + +if BR2_SIMPLE_NETWORK_LO_ENABLE +config BR2_SIMPLE_NETWORK_LO_AUTO + bool "enable loopback interface at startup" + default y + help + Should the loopback inteface be brought up automatically atstartup
system/Config.in +15
-0+ +endif + +menuconfig BR2_SIMPLE_NETWORK_1_ENABLE + bool "enable first network interface" + default y + help + Enable the first network interface + +if BR2_SIMPLE_NETWORK_1_ENABLE +config BR2_SIMPLE_NETWORK_1_AUTO + bool "enable first network interface at startup" + default y + help + Should the first network inteface be brought up automatically atstartup
system/Config.in +6
-0+ +config BR2_SIMPLE_NETWORK_1_NAME + string "name of the first physical network interface" + default "eth0" + help + The name used to recognise the first network interface asreported by the kernel
system/Config.in +6
-0+ +choice + prompt "Configuration type" + default BR2_SIMPLE_NETWORK_1_DHCP + help + The type of configuration to use for the first physicalinterface
system/Config.in +32
-1+ +config BR2_SIMPLE_NETWORK_1_IPV4_DHCP + bool "IPv4 with DHCP" + help + Use DHCP to configure this interface + using the IPv4 protocol + +config BR2_SIMPLE_NETWORK_1_IPV4_MANUAL + bool "IPv4 with parameters manually specified" + help + Configure IPv4 by specifying each parameter separately +endchoice + +if BR2_SIMPLE_NETWORK_1_IPV4_MANUAL +config BR2_SIMPLE_NETWORK_1_IPV4_ADDRESS + string "IP Address of the first network interface" + +config BR2_SIMPLE_NETWORK_1_IPV4_NETMASK + string "Netmask of the first network interface" + +config BR2_SIMPLE_NETWORK_1_IPV4_BROADCAST + string "Broadcast Address of the first network interface" + +config BR2_SIMPLE_NETWORK_1_IPV4_GATEWAY + string "Address of the gateway for the first network interface" +endif + +endif + +endif + + endmenu --2.1.0
PATCH 1/1 set simple network setup via the system configuration submenu
In reply to Jérémy RosenHiJ?r?my,
Le 08/09/2014 14:13, J?r?my Rosen a ?crit :
Quoted 12 lines
This patch allows the setup of simple
/etc/network/interfacesvia the configuration menus instead of using an overlay* supports the loopback interface
* supports one normal interface (renamable)
* supports manual ipv4 configuration
* supports dhcp configurationSigned-off-by J?r?my Rosen <[email protected]>---
Quoted 7 lines
This patch is here to avoid having to do an overlay for the most common cases (ipv4 with fixed IP or DHCP)
I can make it more complex (second network if, support ipv6) depending on what people want/need, but I want to keep it simple. The point is to avoid having to tweak overlays to change stuff that everybody needs to change for prototyping
The idea is good, some comments below.
Quoted 5 lines
With regards to systemd, as far as I could figure it still uses
/etc/network/interfacesbut with different names. AFAIU there is no sane default to replace the "eth0" name so I did not put a different default when systemd is used
I checked on my Fedora machine that use systemd and there is no directory /etc/network.
Instead there is a /etc/networks file.
But I don't know systemd so much...
Quoted 12 lines
--- Makefile | 1 + support/scripts/generate-interfaces.sh | 75 ++++++++++++++++++++++++++++++++ system/Config.in | 78 ++++++++++++++++++++++++++++++++++ 3 files changed, 154 insertions(+)create mode 100755
support/scripts/generate-interfaces.shMakefile +0
-0
Makefile $(BUILD_DIR)/.root: · line 480
Quoted 4 lines
Makefile +1
-0@@ -477,6 +477,7 @@ $(BUILD_DIR)/.root: @ln -snf lib $(TARGET_DIR)/$(LIB_SYMLINK) @mkdir -p $(TARGET_DIR)/usr @ln -snf lib $(TARGET_DIR)/usr/$(LIB_SYMLINK) + ./support/scripts/generate-interfaces.sh $(TARGET_DIR)
generate-interfaces.sh is only called when the target directory is created. What happen if the Buildroot's configuration is modified ? What's about calling this script from target-finalize ?
If unlikely another interfaces file exist on the overlay directory which network configuration must be used ?
Also, $(TOPDIR) must be used here instead of '.'
Quoted 154 lines
Makefile +0
-0touch $@ $(TARGET_DIR): $(BUILD_DIR)/.rootsupport/scripts/generate-interfaces.sh new file +75
-0@@ -0,0 +1,75 @@ +#!/bin/sh + + +#extract our parameters from the config file +for PARAM in \ + BR2_SIMPLE_NETWORK_LO_ENABLE \ + BR2_SIMPLE_NETWORK_LO_AUTO \ + \ + BR2_SIMPLE_NETWORK_1_ENABLE \ + BR2_SIMPLE_NETWORK_1_AUTO \ + BR2_SIMPLE_NETWORK_1_IPV4_DHCP \ + BR2_SIMPLE_NETWORK_1_IPV4_MANUAL \ + ; do +TMP=$(sed -r -e "/^$PARAM=(.*)$/!d;" -e 's//\1/;' $BR2_CONFIG) + export $PARAM=$TMP +done + +for PARAM in \ + BR2_SIMPLE_NETWORK_1_NAME \ + BR2_SIMPLE_NETWORK_1_IPV4_ADDRESS \ + BR2_SIMPLE_NETWORK_1_IPV4_NETMASK \ + BR2_SIMPLE_NETWORK_1_IPV4_BROADCAST \ + BR2_SIMPLE_NETWORK_1_IPV4_GATEWAY \ + ; do +TMP=$(sed -r -e "/^$PARAM=\"(.*)\"$/!d;" -e 's//\1/;' $BR2_CONFIG) + export $PARAM=$TMP +done + + + +IFACE_FILE=$TARGET_DIR/etc/network/interfaces +echo -n > $IFACE_FILE # empty the file + +if [ $BR2_SIMPLE_NETWORK_LO_ENABLE ] ; then + if [ $BR2_SIMPLE_NETWORK_LO_AUTO ] ; then + echo "auto lo">> $IFACE_FILE + fi + echo "iface lo inet loopback">> $IFACE_FILE + echo >>$IFACE_FILE +fi + +if [ $BR2_SIMPLE_NETWORK_1_ENABLE ] ; then + if [ -z $BR2_SIMPLE_NETWORK_1_NAME ] ; then + echo ERROR no name specified for first network interface + exit 1 + fi + if [ $BR2_SIMPLE_NETWORK_1_AUTO ] ; then + echo "auto $BR2_SIMPLE_NETWORK_1_NAME">> $IFACE_FILE + fi + if [ $BR2_SIMPLE_NETWORK_1_IPV4_DHCP ] ; then + echo "iface $BR2_SIMPLE_NETWORK_1_NAME inet dhcp">> $IFACE_FILE + elif [ $BR2_SIMPLE_NETWORK_1_IPV4_MANUAL ] ; then + for PARAM in \ + BR2_SIMPLE_NETWORK_1_IPV4_ADDRESS \ + BR2_SIMPLE_NETWORK_1_IPV4_NETMASK \ + BR2_SIMPLE_NETWORK_1_IPV4_BROADCAST \ + BR2_SIMPLE_NETWORK_1_IPV4_GATEWAY \ + ; do + eval VALUE=\$$PARAM + if [ -z $VALUE ] ; then + echo ERROR $PARAM not set + exit 1 + fi + done + echo "iface $BR2_SIMPLE_NETWORK_1_NAME inet static">> $IFACE_FILE + echo " address $BR2_SIMPLE_NETWORK_1_IPV4_ADDRESS">> $IFACE_FILE + echo " netmask $BR2_SIMPLE_NETWORK_1_IPV4_NETMASK">> $IFACE_FILE + echo " broadcast $BR2_SIMPLE_NETWORK_1_IPV4_BROADCAST">> $IFACE_FILE + echo " gateway $BR2_SIMPLE_NETWORK_1_IPV4_GATEWAY">> $IFACE_FILE + else + echo Incorrect buildroot configuration + exit 1 + fi + echo >>$IFACE_FILE +fisystem/Config.in +62
-0@@ -389,4 +389,82 @@ config BR2_ROOTFS_POST_SCRIPT_ARGS directory / images directory. The arguments in this option will be passed *after* those. +menuconfig BR2_SIMPLE_NETWORK + bool "Generate simple network configuration" + default n + help + Use buildroot to set network configuration during the build process + +if BR2_SIMPLE_NETWORK +menuconfig BR2_SIMPLE_NETWORK_LO_ENABLE + bool "enable loopback device" + default y + help + Enables the loopback interface at startup + +if BR2_SIMPLE_NETWORK_LO_ENABLE +config BR2_SIMPLE_NETWORK_LO_AUTO + bool "enable loopback interface at startup" + default y + help + Should the loopback inteface be brought up automatically at startup + +endif + +menuconfig BR2_SIMPLE_NETWORK_1_ENABLE + bool "enable first network interface" + default y + help + Enable the first network interface + +if BR2_SIMPLE_NETWORK_1_ENABLE +config BR2_SIMPLE_NETWORK_1_AUTO + bool "enable first network interface at startup" + default y + help + Should the first network inteface be brought up automatically at startup + +config BR2_SIMPLE_NETWORK_1_NAME + string "name of the first physical network interface" + default "eth0" + help + The name used to recognise the first network interface as reported by the kernel + +choice + prompt "Configuration type" + default BR2_SIMPLE_NETWORK_1_DHCP + help + The type of configuration to use for the first physical interface + +config BR2_SIMPLE_NETWORK_1_IPV4_DHCP + bool "IPv4 with DHCP" + help + Use DHCP to configure this interface + using the IPv4 protocol + +config BR2_SIMPLE_NETWORK_1_IPV4_MANUAL + bool "IPv4 with parameters manually specified" + help + Configure IPv4 by specifying each parameter separately +endchoice + +if BR2_SIMPLE_NETWORK_1_IPV4_MANUAL +config BR2_SIMPLE_NETWORK_1_IPV4_ADDRESS + string "IP Address of the first network interface"
system/Config.in config BR2_ROOTFS_POST_SCRIPT_ARGS · line 463
Quoted 10 lines
system/Config.in +10
-0+ +config BR2_SIMPLE_NETWORK_1_IPV4_NETMASK + string "Netmask of the first network interface" + +config BR2_SIMPLE_NETWORK_1_IPV4_BROADCAST + string "Broadcast Address of the first network interface" + +config BR2_SIMPLE_NETWORK_1_IPV4_GATEWAY + string "Address of the gateway for the first network interface" +endif
These configs settings needs a default value (like for the interface name) otherwise the script generate-interface will failif only BR2_SIMPLE_NETWORK_1_IPV4_MANUAL has been selected.
system/Config.in config BR2_ROOTFS_POST_SCRIPT_ARGS · line 470
Quoted 7 lines
system/Config.in +6
-0+ +endif + +endif + + endmenu
Best regards,
Romain
PATCH 1/1 set simple network setup via the system configuration submenu
----- Mail original -----
Quoted 2 lines
HiJ?r?my,
<...>
Quoted 11 lines
Quoted 7 lines
With regards to systemd, as far as I could figure it still uses
/etc/network/interfacesbut with different names. AFAIU there is no sane
default to replace the "eth0" name so I did not put a different default
when systemd is usedI checked on my Fedora machine that use systemd and there is no directory
/etc/network.
Instead there is a/etc/networksfile.
But I don't know systemd so much...
* systemv init
configuration is done by net-utils (or busybox) via /etc/network/*
inittab calls /etc/rc.d/S40network which calls ifup -a
(this file is part of skeleton/ so is always here)
this is the well known configuration infrastructure we all know and love.
* systemd without networkd
buildroot will automatically add a network.service which will do the equivalent of S40network (i.e : call "ifup -a") The same infrastructue is used, so the script still works
* systemd with networkd
systemd-networkd is in charge of setting up the network using systemd rules it will find throughout the filesystem (/etc/systemd/network /usr/lib/systemd/network)
I don't generate a networkd rule in this case. I don't know if this is a wanted feature. I'll have a look at how complicated this is...
Quoted 23 lines
Quoted 14 lines
--- Makefile | 1 + support/scripts/generate-interfaces.sh | 75 ++++++++++++++++++++++++++++++++ system/Config.in | 78 ++++++++++++++++++++++++++++++++++ 3 files changed, 154 insertions(+)create mode 100755
support/scripts/generate-interfaces.shMakefile +0
-0Makefile $(BUILD_DIR)/.root: · line 480
Quoted 4 lines
Makefile +1
-0@@ -477,6 +477,7 @@ $(BUILD_DIR)/.root: @ln -snf lib $(TARGET_DIR)/$(LIB_SYMLINK) @mkdir -p $(TARGET_DIR)/usr @ln -snf lib $(TARGET_DIR)/usr/$(LIB_SYMLINK) + ./support/scripts/generate-interfaces.sh $(TARGET_DIR)
generate-interfaces.shis only called when the target directory is created.
What happen if the Buildroot's configuration is modified ? What's about calling this script from target-finalize ?
Quoted 4 lines
If unlikely another interfaces file exist on the overlay directory which
network configuration must be used ?
I have moved this to system/system.mk which is where most of the system submenu stuff is added. These are all added to TARGET_FINALIZE which works for me. If a user adds an overlay, the overlay is applied after TARGET_FINALIZE so the user's version of the file would be use, which seems to me like the correct behaviour
Quoted 1 line
Also, $(TOPDIR) must be used here instead of '.'
fixed, will respin
Quoted 169 lines
Quoted 169 lines
Makefile +0
-0touch $@ $(TARGET_DIR): $(BUILD_DIR)/.rootsupport/scripts/generate-interfaces.sh new file +65
-0@@ -0,0 +1,75 @@ +#!/bin/sh + + +#extract our parameters from the config file +for PARAM in \ + BR2_SIMPLE_NETWORK_LO_ENABLE \ + BR2_SIMPLE_NETWORK_LO_AUTO \ + \ + BR2_SIMPLE_NETWORK_1_ENABLE \ + BR2_SIMPLE_NETWORK_1_AUTO \ + BR2_SIMPLE_NETWORK_1_IPV4_DHCP \ + BR2_SIMPLE_NETWORK_1_IPV4_MANUAL \ + ; do +TMP=$(sed -r -e "/^$PARAM=(.*)$/!d;" -e 's//\1/;' $BR2_CONFIG) + export $PARAM=$TMP +done + +for PARAM in \ + BR2_SIMPLE_NETWORK_1_NAME \ + BR2_SIMPLE_NETWORK_1_IPV4_ADDRESS \ + BR2_SIMPLE_NETWORK_1_IPV4_NETMASK \ + BR2_SIMPLE_NETWORK_1_IPV4_BROADCAST \ + BR2_SIMPLE_NETWORK_1_IPV4_GATEWAY \ + ; do +TMP=$(sed -r -e "/^$PARAM=\"(.*)\"$/!d;" -e 's//\1/;' $BR2_CONFIG) + export $PARAM=$TMP +done + + + +IFACE_FILE=$TARGET_DIR/etc/network/interfaces +echo -n > $IFACE_FILE # empty the file + +if [ $BR2_SIMPLE_NETWORK_LO_ENABLE ] ; then + if [ $BR2_SIMPLE_NETWORK_LO_AUTO ] ; then + echo "auto lo">> $IFACE_FILE + fi + echo "iface lo inet loopback">> $IFACE_FILE + echo >>$IFACE_FILE +fi + +if [ $BR2_SIMPLE_NETWORK_1_ENABLE ] ; then + if [ -z $BR2_SIMPLE_NETWORK_1_NAME ] ; then + echo ERROR no name specified for first network interface + exit 1 + fi + if [ $BR2_SIMPLE_NETWORK_1_AUTO ] ; then + echo "auto $BR2_SIMPLE_NETWORK_1_NAME">> $IFACE_FILE + fi + if [ $BR2_SIMPLE_NETWORK_1_IPV4_DHCP ] ; then + echo "iface $BR2_SIMPLE_NETWORK_1_NAME inet dhcp">> $IFACE_FILE + elif [ $BR2_SIMPLE_NETWORK_1_IPV4_MANUAL ] ; then + for PARAM in \ + BR2_SIMPLE_NETWORK_1_IPV4_ADDRESS \ + BR2_SIMPLE_NETWORK_1_IPV4_NETMASK \ + BR2_SIMPLE_NETWORK_1_IPV4_BROADCAST \ + BR2_SIMPLE_NETWORK_1_IPV4_GATEWAY \ + ; do + eval VALUE=\$$PARAM + if [ -z $VALUE ] ; then + echo ERROR $PARAM not set + exit 1 + fi + done + echo "iface $BR2_SIMPLE_NETWORK_1_NAME inet static">>$IFACE_FILE
support/scripts/generate-interfaces.sh new file +3
-0+ echo " address $BR2_SIMPLE_NETWORK_1_IPV4_ADDRESS">> $IFACE_FILE + echo " netmask $BR2_SIMPLE_NETWORK_1_IPV4_NETMASK">> $IFACE_FILE + echo " broadcast $BR2_SIMPLE_NETWORK_1_IPV4_BROADCAST">>$IFACE_FILE
support/scripts/generate-interfaces.sh new file +7
-0+ echo " gateway $BR2_SIMPLE_NETWORK_1_IPV4_GATEWAY">> $IFACE_FILE + else + echo Incorrect buildroot configuration + exit 1 + fi + echo >>$IFACE_FILE +fisystem/Config.in +5
-0@@ -389,4 +389,82 @@ config BR2_ROOTFS_POST_SCRIPT_ARGS directory / images directory. The arguments in this option will be passed *after* those. +menuconfig BR2_SIMPLE_NETWORK + bool "Generate simple network configuration" + default n + help + Use buildroot to set network configuration during the buildprocess
system/Config.in +14
-0+ +if BR2_SIMPLE_NETWORK +menuconfig BR2_SIMPLE_NETWORK_LO_ENABLE + bool "enable loopback device" + default y + help + Enables the loopback interface at startup + +if BR2_SIMPLE_NETWORK_LO_ENABLE +config BR2_SIMPLE_NETWORK_LO_AUTO + bool "enable loopback interface at startup" + default y + help + Should the loopback inteface be brought up automatically atstartup
system/Config.in +15
-0+ +endif + +menuconfig BR2_SIMPLE_NETWORK_1_ENABLE + bool "enable first network interface" + default y + help + Enable the first network interface + +if BR2_SIMPLE_NETWORK_1_ENABLE +config BR2_SIMPLE_NETWORK_1_AUTO + bool "enable first network interface at startup" + default y + help + Should the first network inteface be brought up automaticallyat startup
system/Config.in +6
-0+ +config BR2_SIMPLE_NETWORK_1_NAME + string "name of the first physical network interface" + default "eth0" + help + The name used to recognise the first network interface asreported by the kernel
system/Config.in +6
-0+ +choice + prompt "Configuration type" + default BR2_SIMPLE_NETWORK_1_DHCP + help + The type of configuration to use for the first physicalinterface
system/Config.in +22
-0+ +config BR2_SIMPLE_NETWORK_1_IPV4_DHCP + bool "IPv4 with DHCP" + help + Use DHCP to configure this interface + using the IPv4 protocol + +config BR2_SIMPLE_NETWORK_1_IPV4_MANUAL + bool "IPv4 with parameters manually specified" + help + Configure IPv4 by specifying each parameter separately +endchoice + +if BR2_SIMPLE_NETWORK_1_IPV4_MANUAL +config BR2_SIMPLE_NETWORK_1_IPV4_ADDRESS + string "IP Address of the first network interface" + +config BR2_SIMPLE_NETWORK_1_IPV4_NETMASK + string "Netmask of the first network interface" + +config BR2_SIMPLE_NETWORK_1_IPV4_BROADCAST + string "Broadcast Address of the first network interface"
Quoted 8 lines
system/Config.in config BR2_ROOTFS_POST_SCRIPT_ARGS · line 463
Quoted 4 lines
system/Config.in +4
-0+ +config BR2_SIMPLE_NETWORK_1_IPV4_GATEWAY + string "Address of the gateway for the first network interface" +endifThese configs settings needs a default value (like for the interface name)
otherwise the script generate-interface will fail if onlyBR2_SIMPLE_NETWORK_1_IPV4_MANUALhas been selected.
Yes, that's on purpose... There is no sane default afaik for IP address when nothing is known on about the intranet topology...
I am opened to any suggestion on default values but I think it's safer to consider this an incorrect setup and refuse to build
At this point i'll wait a couple of days for extra comments and i'll look into networkd generation.
After that I will respin the patch...
Quoted 11 lines
system/Config.in config BR2_ROOTFS_POST_SCRIPT_ARGS · line 470
Quoted 7 lines
system/Config.in +6
-0+ +endif + +endif + + endmenuBest regards,
Romain
PATCH 1/1 set simple network setup via the system configuration submenu
Hi J?r?my,
Quoted 31 lines
Quoted 10 lines
Quoted 6 lines
With regards to systemd, as far as I could figure it still uses
/etc/network/interfacesbut with different names. AFAIU there is no sane
default to replace the "eth0" name so I did not put a different default
when systemd is usedI checked on my Fedora machine that use systemd and there is no directory
/etc/network.
Instead there is a/etc/networksfile.
But I don't know systemd so much...* systemv init
configuration is done by net-utils (or busybox) via
/etc/network/*inittab calls
/etc/rc.d/S40networkwhich calls ifup -a(this file is part of skeleton/ so is always here)
this is the well known configuration infrastructure we all know and love.
* systemd without networkd
buildroot will automatically add a network.service which will do the equivalent of S40network (i.e : call "ifup -a") The same infrastructue is used, so the script still works
* systemd with networkd
Quoted 7 lines
systemd-networkd is in charge of setting up the network using systemd rules it will find throughout the filesystem (
/etc/systemd/network/usr/lib/systemd/network)I don't generate a networkd rule in this case. I don't know if this is a wanted feature. I'll have a look at how complicated this is...
ok
Quoted 27 lines
Quoted 23 lines
Quoted 14 lines
--- Makefile | 1 + support/scripts/generate-interfaces.sh | 75 ++++++++++++++++++++++++++++++++ system/Config.in | 78 ++++++++++++++++++++++++++++++++++ 3 files changed, 154 insertions(+)create mode 100755
support/scripts/generate-interfaces.shMakefile +0
-0Makefile $(BUILD_DIR)/.root: · line 480
Quoted 4 lines
Makefile +1
-0@@ -477,6 +477,7 @@ $(BUILD_DIR)/.root: @ln -snf lib $(TARGET_DIR)/$(LIB_SYMLINK) @mkdir -p $(TARGET_DIR)/usr @ln -snf lib $(TARGET_DIR)/usr/$(LIB_SYMLINK) + ./support/scripts/generate-interfaces.sh $(TARGET_DIR)
generate-interfaces.shis only called when the target directory is created.
What happen if the Buildroot's configuration is modified ? What's about calling this script from target-finalize ?Quoted 4 lines
If unlikely another interfaces file exist on the overlay directory which
network configuration must be used ?
Quoted 6 lines
I have moved this to
system/system.mkwhich is where most of the system submenu stuff is added. These are all added toTARGET_FINALIZEwhich works for me. If a user adds an overlay, the overlay is applied afterTARGET_FINALIZEso the user's version of the file would be use, which seems to me like the correct behaviour
I'm agree with you.
Quoted 2 lines
Quoted 1 line
Also, $(TOPDIR) must be used here instead of '.'
fixed, will respin
[snip]
Quoted 24 lines
Quoted 16 lines
Quoted 16 lines
Makefile +16
-0+ +config BR2_SIMPLE_NETWORK_1_IPV4_MANUAL + bool "IPv4 with parameters manually specified" + help + Configure IPv4 by specifying each parameter separately +endchoice + +if BR2_SIMPLE_NETWORK_1_IPV4_MANUAL +config BR2_SIMPLE_NETWORK_1_IPV4_ADDRESS + string "IP Address of the first network interface" + +config BR2_SIMPLE_NETWORK_1_IPV4_NETMASK + string "Netmask of the first network interface" + +config BR2_SIMPLE_NETWORK_1_IPV4_BROADCAST + string "Broadcast Address of the first network interface"Quoted 8 lines
Makefile
Quoted 4 lines
Makefile +4
-0+ +config BR2_SIMPLE_NETWORK_1_IPV4_GATEWAY + string "Address of the gateway for the first network interface" +endifThese configs settings needs a default value (like for the interface name)
otherwise the script generate-interface will fail if onlyBR2_SIMPLE_NETWORK_1_IPV4_MANUALhas been selected.
Quoted 2 lines
Yes, that's on purpose... There is no sane default afaik for IP address when nothing is known on about the intranet topology...
I understand but I'm thinking about autobuilders here.
The autobuilder will randomly enable BR2_SIMPLE_NETWORK_1_IPV4_MANUAL in the configuration without set any value in other BR2_SIMPLE_NETWORK_1_IPV4_.
Quoted 2 lines
I am opened to any suggestion on default values but I think it's safer to consider this an incorrect setup and refuse to build
An exception may be added in autobuilders to prevent to build with BR2_SIMPLE_NETWORK_1_IPV4_MANUAL set ? Through ?
Quoted 6 lines
At this point i'll wait a couple of days for extra comments and i'll look into networkd generation.
After that I will respin the patch...
Ok, thanks.
Best regards,
Romain
PATCH 1/1 set simple network setup via the system configuration submenu
In reply to Jérémy RosenQuoted 2 lines · J?r?my Rosen
This patch allows the setup of simple
/etc/network/interfacesvia the configuration menus instead of using an overlay
I definitely like the idea of that!
I think that this is where buildroot can still grow a little: simple system
configuration through the Kconfig interface.
Quoted 10 lines
* supports the loopback interface
* supports one normal interface (renamable)
* supports manual ipv4 configuration
* supports dhcp configurationSigned-off-by J?r?my Rosen <[email protected]>---
Quoted 7 lines
This patch is here to avoid having to do an overlay for the most common cases (ipv4 with fixed IP or DHCP)
I can make it more complex (second network if, support ipv6) depending on what people want/need, but I want to keep it simple. The point is to avoid having to tweak overlays to change stuff that everybody needs to change for prototyping
Anyway that could be done in later patches. Better first let this functionality
be tested for a while and then extend it.
Quoted 5 lines
With regards to systemd, as far as I could figure it still uses
/etc/network/interfacesbut with different names. AFAIU there is no sane default to replace the "eth0" name so I did not put a different default when systemd is used
In the meantime you know better :-). If you don't implement the
systemd-networkd support in the end, then I suggest you mention it in comments in generate-interfaces.sh
Quoted 12 lines
--- Makefile | 1 + support/scripts/generate-interfaces.sh | 75 ++++++++++++++++++++++++++++++++ system/Config.in | 78 ++++++++++++++++++++++++++++++++++ 3 files changed, 154 insertions(+) create mode 100755 support/scripts/generate-interfaces.shMakefile +0
-0
Makefile $(BUILD_DIR)/.root: · line 480
Quoted 4 lines
Makefile +1
-0@@ -477,6 +477,7 @@ $(BUILD_DIR)/.root: @ln -snf lib $(TARGET_DIR)/$(LIB_SYMLINK) @mkdir -p $(TARGET_DIR)/usr @ln -snf lib $(TARGET_DIR)/usr/$(LIB_SYMLINK) + ./support/scripts/generate-interfaces.sh $(TARGET_DIR)
+1 for moving it to TARGET_FINALIZE_HOOKS.
But I think it should be conditional on BR2_SIMPLE_NETWORK=y.
Quoted 27 lines
Makefile +0
-0touch $@ $(TARGET_DIR): $(BUILD_DIR)/.rootsupport/scripts/generate-interfaces.sh new file +18
-0@@ -0,0 +1,75 @@ +#!/bin/sh + + +#extract our parameters from the config file +for PARAM in \ + BR2_SIMPLE_NETWORK_LO_ENABLE \ + BR2_SIMPLE_NETWORK_LO_AUTO \ + \ + BR2_SIMPLE_NETWORK_1_ENABLE \ + BR2_SIMPLE_NETWORK_1_AUTO \ + BR2_SIMPLE_NETWORK_1_IPV4_DHCP \ + BR2_SIMPLE_NETWORK_1_IPV4_MANUAL \ + ; do +TMP=$(sed -r -e "/^$PARAM=(.*)$/!d;" -e 's//\1/;' $BR2_CONFIG) + export $PARAM=$TMP +done + +for PARAM in \
support/scripts/generate-interfaces.sh line 28
Quoted 10 lines
support/scripts/generate-interfaces.sh new file +10
-0+ BR2_SIMPLE_NETWORK_1_NAME \ + BR2_SIMPLE_NETWORK_1_IPV4_ADDRESS \ + BR2_SIMPLE_NETWORK_1_IPV4_NETMASK \ + BR2_SIMPLE_NETWORK_1_IPV4_BROADCAST \ + BR2_SIMPLE_NETWORK_1_IPV4_GATEWAY \ + ; do +TMP=$(sed -r -e "/^$PARAM=\"(.*)\"$/!d;" -e 's//\1/;' $BR2_CONFIG) + export $PARAM=$TMP +done +
You can just source the config, that's a lot simpler than all this magic. If
you really want you could grep out the BR2_SIMPLE_NETWORK part but really I don't see the point.
support/scripts/generate-interfaces.sh line 32
Quoted 4 lines
support/scripts/generate-interfaces.sh new file +4
-0+ + +IFACE_FILE=$TARGET_DIR/etc/network/interfaces +echo -n > $IFACE_FILE # empty the file
Perhaps, just to be sure, an mkdir -p of /etc/network ?
Just a minor nit, but wouldn't it be simpler to put all of the below in a
function which you then call with
do_generate_interfaces > $TARGET_DIR/etc/network/interfaces
? Then you don't have to redirect all the time. Or you could also just do
exec > $TARGET_DIR/etc/network/interfaces
support/scripts/generate-interfaces.sh line 34
Quoted 2 lines
support/scripts/generate-interfaces.sh new file +2
-0+ +if [ $BR2_SIMPLE_NETWORK_LO_ENABLE ] ; then
I didn't know that this worked... I always thought you had to put quotes to
protect against an empty string, but it turns out that [ ] works perfectly. Thanks for teaching me!
support/scripts/generate-interfaces.sh line 44
Quoted 10 lines
support/scripts/generate-interfaces.sh new file +10
-0+ if [ $BR2_SIMPLE_NETWORK_LO_AUTO ] ; then + echo "auto lo">> $IFACE_FILE + fi + echo "iface lo inet loopback">> $IFACE_FILE + echo >>$IFACE_FILE +fi + +if [ $BR2_SIMPLE_NETWORK_1_ENABLE ] ; then + if [ -z $BR2_SIMPLE_NETWORK_1_NAME ] ; then + echo ERROR no name specified for first network interface
If you follow my suggestion of redirecting once, then this should of course be
1>&2 (which would be a good idea anyway).
I would actually prefer to check things like this in the .mk file, so you see
the error earlier. However, in this case, that would make things way to complicated I'm afraid.
support/scripts/generate-interfaces.sh line 57
Quoted 13 lines
support/scripts/generate-interfaces.sh new file +13
-0+ exit 1 + fi + if [ $BR2_SIMPLE_NETWORK_1_AUTO ] ; then + echo "auto $BR2_SIMPLE_NETWORK_1_NAME">> $IFACE_FILE + fi + if [ $BR2_SIMPLE_NETWORK_1_IPV4_DHCP ] ; then + echo "iface $BR2_SIMPLE_NETWORK_1_NAME inet dhcp">> $IFACE_FILE + elif [ $BR2_SIMPLE_NETWORK_1_IPV4_MANUAL ] ; then + for PARAM in \ + BR2_SIMPLE_NETWORK_1_IPV4_ADDRESS \ + BR2_SIMPLE_NETWORK_1_IPV4_NETMASK \ + BR2_SIMPLE_NETWORK_1_IPV4_BROADCAST \ + BR2_SIMPLE_NETWORK_1_IPV4_GATEWAY \
Only address is really required. ifconfig will derive the netmask from the
address (though in practice that usually doesn't work anymore nowadays, because of CIDR and because we use network-local IP addresses with a much smaller range than the default 192.168.0.0/16). Broadcast is derived from the netmask, and the gateway is only needed if you want non-local access.
support/scripts/generate-interfaces.sh line 69
Quoted 12 lines
support/scripts/generate-interfaces.sh new file +12
-0+ ; do + eval VALUE=\$$PARAM + if [ -z $VALUE ] ; then + echo ERROR $PARAM not set + exit 1 + fi + done + echo "iface $BR2_SIMPLE_NETWORK_1_NAME inet static">> $IFACE_FILE + echo " address $BR2_SIMPLE_NETWORK_1_IPV4_ADDRESS">> $IFACE_FILE + echo " netmask $BR2_SIMPLE_NETWORK_1_IPV4_NETMASK">> $IFACE_FILE + echo " broadcast $BR2_SIMPLE_NETWORK_1_IPV4_BROADCAST">> $IFACE_FILE + echo " gateway $BR2_SIMPLE_NETWORK_1_IPV4_GATEWAY">> $IFACE_FILE
So the last three should be conditional on whether it is defined.
Quoted 11 lines
support/scripts/generate-interfaces.sh new file +6
-0+ else + echo Incorrect buildroot configuration + exit 1 + fi + echo >>$IFACE_FILE +fisystem/Config.in +0
-0
system/Config.in config BR2_ROOTFS_POST_SCRIPT_ARGS · line 394
Quoted 6 lines
system/Config.in +3
-0@@ -389,4 +389,82 @@ config BR2_ROOTFS_POST_SCRIPT_ARGS directory / images directory. The arguments in this option will be passed *after* those. +menuconfig BR2_SIMPLE_NETWORK + bool "Generate simple network configuration" + default n
Since we currently do generate this, I think it should default to y.
Also, I think this menu should go before the rootfs overlay option, so it
corresponds to the order in which we do things. Maybe even just after the remount option.
system/Config.in config BR2_ROOTFS_POST_SCRIPT_ARGS · line 396
Quoted 2 lines
system/Config.in +2
-0+ help + Use buildroot to set network configuration during the build process
Suggested more complete help text:
Let buildroot create the network configuration file during the build process. This is /etc/network/interfaces when using ifupdown, and /etc/systemd/network/<iface>.network when using systemd-networkd.
The simple network configuration only supports the loopback interface and a single other network interface using a static or DHCP-allocated IPv4 address. If you need something more complicate, create your own configuration file in the BR2_ROOTFS_OVERLAY.
Quoted 4 lines
system/Config.in +4
-0+ +if BR2_SIMPLE_NETWORK +menuconfig BR2_SIMPLE_NETWORK_LO_ENABLE + bool "enable loopback device"
system/Config.in config BR2_ROOTFS_POST_SCRIPT_ARGS · line 410
Quoted 10 lines
system/Config.in +10
-0+ default y + help + Enables the loopback interface at startup + +if BR2_SIMPLE_NETWORK_LO_ENABLE +config BR2_SIMPLE_NETWORK_LO_AUTO + bool "enable loopback interface at startup" + default y + help + Should the loopback inteface be brought up automatically at startup
I wonder if these auto things really make sense. Why would you ever want it
non-auto? I mean, I can imagine a lot of situations, but then you anyway don't want to use the simple network management.
Actually, I even doubt it makes sense to leave out the loopback interface.
Without loopback, things tend to be pretty fragile, so I wouldn't put that option in a _simple_ network configuration. Too much ammo to shoot yourself in the foot, and you can make your own /etc/network/interfaces if you really want to.
system/Config.in config BR2_ROOTFS_POST_SCRIPT_ARGS · line 418
Quoted 8 lines
system/Config.in +8
-0+ +endif + +menuconfig BR2_SIMPLE_NETWORK_1_ENABLE + bool "enable first network interface" + default y + help + Enable the first network interface
As long as we support only one interface, calling it the first one doesn't make
much sense.
Also, if the loopback option is removed, then nesting it another level doesn't
make much sense. And even if the loopback stays, I would do the second-level nesting with indentation (i.e. config instead of menuconfig and rely on the condition to indent it).
system/Config.in config BR2_ROOTFS_POST_SCRIPT_ARGS · line 425
Quoted 7 lines
system/Config.in +7
-0+ +if BR2_SIMPLE_NETWORK_1_ENABLE +config BR2_SIMPLE_NETWORK_1_AUTO + bool "enable first network interface at startup" + default y + help + Should the first network inteface be brought up automatically at startup
Again, I don't think it's useful to have this option.
system/Config.in config BR2_ROOTFS_POST_SCRIPT_ARGS · line 428
Quoted 3 lines
system/Config.in +3
-0+ +config BR2_SIMPLE_NETWORK_1_NAME + string "name of the first physical network interface"
Since this is already in the 'first network interface' menu, there is no point
in repeating 'first physical network interface' everywhere. Same story if it is indented.
Quoted 8 lines
system/Config.in +8
-0+ default "eth0" + help + The name used to recognise the first network interface as reported by the kernel + +choice + prompt "Configuration type" + default BR2_SIMPLE_NETWORK_1_DHCP + help
system/Config.in config BR2_ROOTFS_POST_SCRIPT_ARGS · line 446
Quoted 10 lines
system/Config.in +10
-0+ The type of configuration to use for the first physical interface + +config BR2_SIMPLE_NETWORK_1_IPV4_DHCP + bool "IPv4 with DHCP" + help + Use DHCP to configure this interface + using the IPv4 protocol + +config BR2_SIMPLE_NETWORK_1_IPV4_MANUAL + bool "IPv4 with parameters manually specified"
Call this "IPv4 with static IP address"
system/Config.in config BR2_ROOTFS_POST_SCRIPT_ARGS · line 459
Quoted 13 lines
system/Config.in +13
-0+ help + Configure IPv4 by specifying each parameter separately +endchoice + +if BR2_SIMPLE_NETWORK_1_IPV4_MANUAL +config BR2_SIMPLE_NETWORK_1_IPV4_ADDRESS + string "IP Address of the first network interface" + +config BR2_SIMPLE_NETWORK_1_IPV4_NETMASK + string "Netmask of the first network interface" + +config BR2_SIMPLE_NETWORK_1_IPV4_BROADCAST + string "Broadcast Address of the first network interface"
Actually, does it make sense to specify a broadcast address? When is it ever
different from default?
Bottom line: I'd limit the configurability to the minimum useful set, and leave
the rest for a rootfs overlay.
Regards,
Arnout
Quoted 12 lines
system/Config.in +10
-0+ +config BR2_SIMPLE_NETWORK_1_IPV4_GATEWAY + string "Address of the gateway for the first network interface" +endif + +endif + +endif + + endmenu
Signature · 6 lines
Arnout Vandecappelle arnout at mind be Senior Embedded Software Architect +32-16-286500 Essensium/Mind http://www.mind.be G.Geenslaan 9, 3001 Leuven, Belgium BE 872 984 063 RPR Leuven LinkedIn profile: http://www.linkedin.com/in/arnoutvandecappelle GPG fingerprint: 7CB5 E4CC 6C2E EFD4 6E3D A754 F963 ECAB 2450 2F1F
PATCH 1/1 set simple network setup via the system configuration submenu
Hello Arnout
I've read all your comments and it boils down to the following philosophy
* don't plan for having more complicated stuff : one interface, simple cases only
* lo should always be enabled
* backward compatibility
I agree with this approch, see my remarks below for specific answers to your comments, I'll respin the patch when it's ready.
----- Mail original -----
Quoted 45 lines · J?r?my Rosen
Quoted 3 lines
This patch allows the setup of simple
/etc/network/interfacesvia the
configuration menus instead of using an overlayI definitely like the idea of that!
I think that this is where buildroot can still grow a little: simple system
configuration through theKconfiginterface.Quoted 14 lines
* supports the loopback interface
* supports one normal interface (renamable)
* 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)Quoted 7 lines
I can make it more complex (second network if, support ipv6) depending on
what people want/need, but I want to keep it simple. The point is to avoid
having to tweak overlays to change stuff that everybody needs to change for
prototypingAnyway that could be done in later patches. Better first let this functionality
be tested for a while and then extend it.Quoted 7 lines
With regards to systemd, as far as I could figure it still uses
/etc/network/interfacesbut with different names. AFAIU there is no sane
default to replace the "eth0" name so I did not put a different default
when systemd is used
Quoted 5 lines
In the meantime you know better :-). If you don't implement the
systemd-networkd support in the end, then I suggest you mention it in comments
ingenerate-interfaces.sh
I've looked into it, it's doable but complicated so i'll disable network setup when networkd is enabled and let people write their own service for the time being. networkd enables lo when it is not configured so all should be fine.
Quoted 22 lines
Quoted 15 lines
--- Makefile | 1 + support/scripts/generate-interfaces.sh | 75 ++++++++++++++++++++++++++++++++ system/Config.in | 78 ++++++++++++++++++++++++++++++++++ 3 files changed, 154 insertions(+) create mode 100755 support/scripts/generate-interfaces.shMakefile +0
-0Makefile $(BUILD_DIR)/.root: · line 480
Quoted 4 lines
Makefile +1
-0@@ -477,6 +477,7 @@ $(BUILD_DIR)/.root: @ln -snf lib $(TARGET_DIR)/$(LIB_SYMLINK) @mkdir -p $(TARGET_DIR)/usr @ln -snf lib $(TARGET_DIR)/usr/$(LIB_SYMLINK) + ./support/scripts/generate-interfaces.sh $(TARGET_DIR)+1 for moving it to
TARGET_FINALIZE_HOOKS.
Quoted 2 lines
But I think it should be conditional on BR2_SIMPLE_NETWORK=y.
I moved it to TARGET_FINALIZE but did not make it conditional. it is needed for enabling lo, even when ethO is not configured
Quoted 37 lines
Quoted 37 lines
Makefile +0
-0touch $@ $(TARGET_DIR): $(BUILD_DIR)/.rootsupport/scripts/generate-interfaces.sh new file +27
-0@@ -0,0 +1,75 @@ +#!/bin/sh + + +#extract our parameters from the config file +for PARAM in \ + BR2_SIMPLE_NETWORK_LO_ENABLE \ + BR2_SIMPLE_NETWORK_LO_AUTO \ + \ + BR2_SIMPLE_NETWORK_1_ENABLE \ + BR2_SIMPLE_NETWORK_1_AUTO \ + BR2_SIMPLE_NETWORK_1_IPV4_DHCP \ + BR2_SIMPLE_NETWORK_1_IPV4_MANUAL \ + ; do +TMP=$(sed -r -e "/^$PARAM=(.*)$/!d;" -e 's//\1/;' $BR2_CONFIG) + export $PARAM=$TMP +done + +for PARAM in \ + BR2_SIMPLE_NETWORK_1_NAME \ + BR2_SIMPLE_NETWORK_1_IPV4_ADDRESS \ + BR2_SIMPLE_NETWORK_1_IPV4_NETMASK \ + BR2_SIMPLE_NETWORK_1_IPV4_BROADCAST \ + BR2_SIMPLE_NETWORK_1_IPV4_GATEWAY \ + ; do +TMP=$(sed -r -e "/^$PARAM=\"(.*)\"$/!d;" -e 's//\1/;' $BR2_CONFIG) + export $PARAM=$TMP +done
Quoted 9 lines
support/scripts/generate-interfaces.sh line 28
Quoted 1 line
support/scripts/generate-interfaces.sh new file +1
-0+You can just source the config, that's a lot simpler than all this magic. If
you really want you could grep out theBR2_SIMPLE_NETWORKpart but really I
don't see the point.
unfortunately that doesnt work because of lines like the following
BR2_HOST_DIR="$(BASE_DIR)/host"
I've copied the logic from mkusers and yeah... it's a bit ugly.
Quoted 7 lines
support/scripts/generate-interfaces.sh line 32
Quoted 4 lines
support/scripts/generate-interfaces.sh new file +4
-0+ + +IFACE_FILE=$TARGET_DIR/etc/network/interfaces +echo -n > $IFACE_FILE # empty the filePerhaps, just to be sure, an mkdir -p of
/etc/network?
will do
Quoted 11 lines
Just a minor nit, but wouldn't it be simpler to put all of the below in a
function which you then call with
do_generate_interfaces> $TARGET_DIR/etc/network/interfaces? Then you don't have to redirect all the time. Or you could also just do
exec > $TARGET_DIR/etc/network/interfaces
will do
Quoted 9 lines
support/scripts/generate-interfaces.sh line 34
Quoted 2 lines
support/scripts/generate-interfaces.sh new file +2
-0+ +if [ $BR2_SIMPLE_NETWORK_LO_ENABLE ] ; thenI didn't know that this worked... I always thought you had to put quotes to
protect against an empty string, but it turns out that [ ] works perfectly.
Thanks for teaching me!
Quoted 15 lines
support/scripts/generate-interfaces.sh line 44
Quoted 10 lines
support/scripts/generate-interfaces.sh new file +10
-0+ if [ $BR2_SIMPLE_NETWORK_LO_AUTO ] ; then + echo "auto lo">> $IFACE_FILE + fi + echo "iface lo inet loopback">> $IFACE_FILE + echo >>$IFACE_FILE +fi + +if [ $BR2_SIMPLE_NETWORK_1_ENABLE ] ; then + if [ -z $BR2_SIMPLE_NETWORK_1_NAME ] ; then + echo ERROR no name specified for first network interfaceIf you follow my suggestion of redirecting once, then this should of course be
1>&2 (which would be a good idea anyway).
indeed, will do
Quoted 6 lines
I would actually prefer to check things like this in the .mk file, so you see
the error earlier. However, in this case, that would make things way to
complicated I'm afraid.
my Makefile-fu is even worse than my shell-fu, I'm not sure I could handle this properly...
Quoted 14 lines
support/scripts/generate-interfaces.sh line 57
Quoted 13 lines
support/scripts/generate-interfaces.sh new file +13
-0+ exit 1 + fi + if [ $BR2_SIMPLE_NETWORK_1_AUTO ] ; then + echo "auto $BR2_SIMPLE_NETWORK_1_NAME">> $IFACE_FILE + fi + if [ $BR2_SIMPLE_NETWORK_1_IPV4_DHCP ] ; then + echo "iface $BR2_SIMPLE_NETWORK_1_NAME inet dhcp">> $IFACE_FILE + elif [ $BR2_SIMPLE_NETWORK_1_IPV4_MANUAL ] ; then + for PARAM in \ + BR2_SIMPLE_NETWORK_1_IPV4_ADDRESS \ + BR2_SIMPLE_NETWORK_1_IPV4_NETMASK \ + BR2_SIMPLE_NETWORK_1_IPV4_BROADCAST \ + BR2_SIMPLE_NETWORK_1_IPV4_GATEWAY \
Quoted 7 lines
Only address is really required. ifconfig will derive the netmask from the
address (though in practice that usually doesn't work anymore nowadays, because
of CIDR and because we use network-local IP addresses with a much smaller range
than the default 192.168.0.0/16).
the busybox ifup seems to need both address and netmask to bring an interface up (I havn't tested with the real net-utils) so i'll have to make both mandatory.
I have settled to a default address of 0.0.0.0 and a netmask of 255.255.255.255 which is accepted by ifconfig to bring the interface up with no IP address (so not dangerous on a network) and should allow the autobuilder to correctly work.
Broadcast and gateway are indeed optional and can default to empty
I am still open to suggestions on exactly what default to provide, but I think this is the best we can do without a way to tell the autobuilder to only generate for DHCP or something like that...
Quoted 4 lines
Broadcast is derived from the
netmask, and the
gateway is only needed if you want non-local access.
Quoted 17 lines
Quoted 13 lines
support/scripts/generate-interfaces.sh new file +8
-0+ ; do + eval VALUE=\$$PARAM + if [ -z $VALUE ] ; then + echo ERROR $PARAM not set + exit 1 + fi + done + echo "iface $BR2_SIMPLE_NETWORK_1_NAME inet static">>$IFACE_FILE
support/scripts/generate-interfaces.sh new file +3
-0+ echo " address $BR2_SIMPLE_NETWORK_1_IPV4_ADDRESS">> $IFACE_FILE + echo " netmask $BR2_SIMPLE_NETWORK_1_IPV4_NETMASK">> $IFACE_FILE + echo " broadcast $BR2_SIMPLE_NETWORK_1_IPV4_BROADCAST">>$IFACE_FILE
support/scripts/generate-interfaces.sh line 69
Quoted 1 line
support/scripts/generate-interfaces.sh new file +1
-0+ echo " gateway $BR2_SIMPLE_NETWORK_1_IPV4_GATEWAY">> $IFACE_FILESo the last three should be conditional on whether it is defined.
will fix all that
Quoted 15 lines
Quoted 15 lines
support/scripts/generate-interfaces.sh new file +6
-0+ else + echo Incorrect buildroot configuration + exit 1 + fi + echo >>$IFACE_FILE +fisystem/Config.in +0
-0@@ -389,4 +389,82 @@ config BR2_ROOTFS_POST_SCRIPT_ARGS directory / images directory. The arguments in this option will be passed *after* those.
Quoted 6 lines
system/Config.in config BR2_ROOTFS_POST_SCRIPT_ARGS · line 394
Quoted 3 lines
system/Config.in +3
-0+menuconfig BR2_SIMPLE_NETWORK + bool "Generate simple network configuration" + default nSince we currently do generate this, I think it should default to y.
I slightly changed the logic, the option is only about eth0, so should default to n for backward compatibility, the script is always called to generate the lo part.
Quoted 6 lines
Also, I think this menu should go before the rootfs overlay option, so it
corresponds to the order in which we do things. Maybe even just after the
remount option.
makes sense, will do
Quoted 11 lines
Quoted 3 lines
system/Config.in +2
-0+ help + Use buildroot to set network configuration during the buildprocess
Suggested more complete help text:
Let buildroot create the network configuration file during the build
process. This is/etc/network/interfaceswhen using ifupdown, and /etc/systemd/network/<iface>.network when using systemd-networkd.
Quoted 8 lines
The simple network configuration only supports the loopback interface
and a single other network interface using a static or DHCP-allocated
IPv4 address. If you need something more complicate, create your own
configuration file in theBR2_ROOTFS_OVERLAY.
much better, I will use that (slight reword because the option is not about generating the file, but including a default eth0 in the file)
Quoted 13 lines
Quoted 13 lines
system/Config.in +13
-0+ +if BR2_SIMPLE_NETWORK +menuconfig BR2_SIMPLE_NETWORK_LO_ENABLE + bool "enable loopback device" + default y + help + Enables the loopback interface at startup + +if BR2_SIMPLE_NETWORK_LO_ENABLE +config BR2_SIMPLE_NETWORK_LO_AUTO + bool "enable loopback interface at startup" + default y + help
Quoted 9 lines
Quoted 2 lines
system/Config.in +1
-0+ Should the loopback inteface be brought up automatically atstartup
I wonder if these auto things really make sense. Why would you ever want it
non-auto? I mean, I can imagine a lot of situations, but then you anyway don't
want to use the simple network management.
makes sense, option removed
Quoted 9 lines
Actually, I even doubt it makes sense to leave out the loopback interface.
Without loopback, things tend to be pretty fragile, so I wouldn't put that
option in a _simple_ network configuration. Too much ammo to shoot yourself in
the foot, and you can make your own/etc/network/interfacesif you really want to.
agreed
Quoted 4 lines
Quoted 4 lines
system/Config.in +4
-0+ +endif + +menuconfig BR2_SIMPLE_NETWORK_1_ENABLE
Quoted 9 lines
system/Config.in config BR2_ROOTFS_POST_SCRIPT_ARGS · line 418
Quoted 4 lines
system/Config.in +4
-0+ bool "enable first network interface" + default y + help + Enable the first network interfaceAs long as we support only one interface, calling it the first one doesn't make
much sense.
ok, will rename the options
Quoted 8 lines
Also, if the loopback option is removed, then nesting it another level doesn't
make much sense. And even if the loopback stays, I would do the second-level
nesting with indentation (i.e. config instead of menuconfig and rely on the
condition to indent it).
will do
Quoted 11 lines
Quoted 8 lines
system/Config.in +7
-0+ +if BR2_SIMPLE_NETWORK_1_ENABLE +config BR2_SIMPLE_NETWORK_1_AUTO + bool "enable first network interface at startup" + default y + help + Should the first network inteface be brought up automaticallyat startup
Again, I don't think it's useful to have this option.
Quoted 10 lines
system/Config.in config BR2_ROOTFS_POST_SCRIPT_ARGS · line 428
Quoted 3 lines
system/Config.in +3
-0+ +config BR2_SIMPLE_NETWORK_1_NAME + string "name of the first physical network interface"Since this is already in the 'first network interface' menu, there is no point
in repeating 'first physical network interface' everywhere. Same story if it is
indented.
ok
Quoted 15 lines
Quoted 15 lines
system/Config.in +3
-0+ default "eth0" + help + The name used to recognise the first network interface asreported by the kernel
system/Config.in +6
-0+ +choice + prompt "Configuration type" + default BR2_SIMPLE_NETWORK_1_DHCP + help + The type of configuration to use for the first physicalinterface
system/Config.in +3
-0+ +config BR2_SIMPLE_NETWORK_1_IPV4_DHCP + bool "IPv4 with DHCP"
Quoted 9 lines
system/Config.in config BR2_ROOTFS_POST_SCRIPT_ARGS · line 446
Quoted 6 lines
system/Config.in +6
-0+ help + Use DHCP to configure this interface + using the IPv4 protocol + +config BR2_SIMPLE_NETWORK_1_IPV4_MANUAL + bool "IPv4 with parameters manually specified"Call this "IPv4 with static IP address"
better indeed
Quoted 9 lines
Quoted 9 lines
system/Config.in +9
-0+ help + Configure IPv4 by specifying each parameter separately +endchoice + +if BR2_SIMPLE_NETWORK_1_IPV4_MANUAL +config BR2_SIMPLE_NETWORK_1_IPV4_ADDRESS + string "IP Address of the first network interface" + +config BR2_SIMPLE_NETWORK_1_IPV4_NETMASK
Quoted 9 lines
system/Config.in config BR2_ROOTFS_POST_SCRIPT_ARGS · line 459
Quoted 4 lines
system/Config.in +4
-0+ string "Netmask of the first network interface" + +config BR2_SIMPLE_NETWORK_1_IPV4_BROADCAST + string "Broadcast Address of the first network interface"Actually, does it make sense to specify a broadcast address? When is it ever
different from default?
I don't know how to guess it, pretty standard, easy to add and can be left empty. I think it makes sense to leave it as is...
Quoted 8 lines
Bottom line: I'd limit the configurability to the minimum useful set, and leave
the rest for a rootfs overlay.Regards,
Arnout
Thx for the review i'll respin this soon
Quoted 23 lines
system/Config.in config BR2_ROOTFS_POST_SCRIPT_ARGS · line 470
Quoted 12 lines
system/Config.in +10
-0+ +config BR2_SIMPLE_NETWORK_1_IPV4_GATEWAY + string "Address of the gateway for the first network interface" +endif + +endif + +endif + + endmenu--
Arnout Vandecappelle arnout at mind be Senior Embedded Software Architect +32-16-286500 Essensium/Mind http://www.mind.be G.Geenslaan 9, 3001 Leuven, Belgium BE 872 984 063 RPR Leuven LinkedIn profile: http://www.linkedin.com/in/arnoutvandecappelle GPG fingerprint: 7CB5 E4CC 6C2E EFD4 6E3D A754 F963 ECAB 2450 2F1F