Allow a single DHCP configuration via the system configuration submenu
PATCH v4 1/1 Allow a single DHCP configuration via the system configuration submenu
This patch allows the setup of simple a single interface to be automatically brought up and configured via DHCP on system startup.
The interface name can be set via a configuration option. This patch does not support systemd-networkd, any complex network configuration should be done via overlay of /etc/network/interfaces or the relevant networkd configuration file
---
v4 : - changed condition to also depend on ifupdown or busybox
suggestion by Gustavo Zacarias
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 | 21 +++++++++++++++++++++ system/skeleton/etc/network/interfaces | 4 ---- system/system.mk | 25 +++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 4 deletions(-) delete mode 100644 system/skeleton/etc/network/interfaces
system/Config.in +21 -0
@@ -324,6 +324,27 @@ 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 && (BR2_PACKAGE_BUSYBOX || BR2_PACKAGE_IFUPDOWN) + 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 + +comment "automatic network configuration via DHCP needs ifupdown or busybox" + depends on !(BR2_PACKAGE_BUSYBOX || BR2_PACKAGE_IFUPDOWN) + 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 +25 -0
@@ -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
Signature · 1 line
2.1.4
PATCH v4 1/1 Allow a single DHCP configuration via the system configuration submenu
Dear J?r?my Rosen,
Quoted 9 lines · J?r?my Rosen
system/Config.in +9
-0+config BR2_SIMPLE_DHCP + string "Name of the physical network interface to run DHCP on" + default "" + depends on !BR2_PACKAGE_SYSTEMD_NETWORKD && (BR2_PACKAGE_BUSYBOX || BR2_PACKAGE_IFUPDOWN) + help + The name of the network interface to configure automatically. + A DHCP request will automatically happen on startup on the selected + interface. +
system/Config.in config BR2_TARGET_GENERIC_REMOUNT_ROOTFS_RW · line 346
Quoted 10 lines
system/Config.in +10
-0+ 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 + +comment "automatic network configuration via DHCP needs ifupdown or busybox" + depends on !(BR2_PACKAGE_BUSYBOX || BR2_PACKAGE_IFUPDOWN)
I'm still not really happy with this. It's
really /etc/network/interfaces as a whole that doesn't make sense in a context where you don't have Busybox ifupdown, or the full blown ifupdown, no? Not just the DHCP part of it.
Thomas
Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons Embedded Linux, Kernel and Android engineering http://free-electrons.com
PATCH v4 1/1 Allow a single DHCP configuration via the system configuration submenu
Quoted 25 lines
Dear J?r?my Rosen,
Quoted 21 lines · J?r?my Rosen
system/Config.in +4
-0+config BR2_SIMPLE_DHCP + string "Name of the physical network interface to run DHCP on" + default "" + depends on !BR2_PACKAGE_SYSTEMD_NETWORKD && (BR2_PACKAGE_BUSYBOX||
BR2_PACKAGE_IFUPDOWN)system/Config.in +3
-0+ help + The name of the network interface to configure automatically. + A DHCP request will automatically happen on startup on theselected
system/Config.in +8
-0+ 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 notcompatible with networkd"
system/Config.in +3
-0+ depends on BR2_PACKAGE_SYSTEMD_NETWORKD + +comment "automatic network configuration via DHCP needs ifupdown
Quoted 9 lines
system/Config.in config BR2_TARGET_GENERIC_REMOUNT_ROOTFS_RW · line 346
Quoted 2 lines
or busybox"
system/Config.in +1
-0+ depends on !(BR2_PACKAGE_BUSYBOX || BR2_PACKAGE_IFUPDOWN)I'm still not really happy with this. It's
really/etc/network/interfacesas a whole that doesn't make sense in a
context where you don't have Busybox ifupdown, or the full blown ifupdown, no? Not just the DHCP part of it.
i'm not sure how you want me to correct that...
* not generate network/interfaces at all if ifupdown is not available
* correct the comment sections "generation of /etc/network/interfaces needs ifupdown" (but that does not reflect what the option is when it is available)
* something else
please tell me and i'll send a new patch
Quoted 6 lines
Thomas
--
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
PATCH v4 1/1 Allow a single DHCP configuration via the system configuration submenu
In reply to Jérémy RosenQuoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"J?r?my" == J?r?my Rosen <[email protected]> writes:
Hi,
Quoted 8 lines
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/interfacesor the relevant networkd configuration file
Quoted 5 lines
Signed-off-by J?r?my Rosen <[email protected]>---
v4 : - changed condition to also depend on ifupdown or busybox
suggestion by Gustavo Zacarias
Sorry for the slow response. We have discussed this during the dev days and agreed to include it. Committed with some changes, see below.
Thanks!
Quoted 1 line
+config
BR2_SIMPLE_DHCP
We're not completely consist with this, but the new system options are called BR2_SYSTEM_*, so I've renamed to the option.
system/Config.in config BR2_TARGET_GENERIC_REMOUNT_ROOTFS_RW · line 329
Quoted 1 line
system/Config.in +1
-0+ string "Name of the physical network interface to run DHCP on"
This is quite long, so I reworded it to:
"Network interface to configure through DHCP"
system/Config.in config BR2_TARGET_GENERIC_REMOUNT_ROOTFS_RW · line 335
Quoted 6 lines
system/Config.in +6
-0+ default "" + depends on !BR2_PACKAGE_SYSTEMD_NETWORKD && (BR2_PACKAGE_BUSYBOX || BR2_PACKAGE_IFUPDOWN) + help + The name of the network interface to configure automatically. + A DHCP request will automatically happen on startup on the selected + interface.
And here I reworded it a bit and mentioned an example (eth0).
system/system.mk ifneq ($(TARGET_GENERIC_ROOT_PASSWD),) · line 47
Quoted 7 lines
system/system.mk +7
-0+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
Elsewhere in BR we use syntax like:
( \
echo foo ; \
echo bar ; \
) > file
Which is a bit less verbose, so I've changed it to that.
Signature · 1 line
Bye, Peter Korsgaard
PATCH v4 1/1 Allow a single DHCP configuration via the system configuration submenu
Quoted 7 lines
Sorry for the slow response. We have discussed this during the dev days
and agreed to include it. Committed with some changes, see below.Thanks!
Thanks a lot, really appreciated :)
Quoted 50 lines
Quoted 2 lines
+config
BR2_SIMPLE_DHCPWe're not completely consist with this, but the new system options are
called BR2_SYSTEM_*, so I've renamed to the option.system/Config.in config BR2_TARGET_GENERIC_REMOUNT_ROOTFS_RW · line 329
Quoted 1 line
system/Config.in +1
-0+ string "Name of the physical network interface to run DHCP on"This is quite long, so I reworded it to:
"Network interface to configure through DHCP"
system/Config.in config BR2_TARGET_GENERIC_REMOUNT_ROOTFS_RW · line 335
Quoted 8 lines
(quoted diff) +2
-0+ default "" + depends on !BR2_PACKAGE_SYSTEMD_NETWORKD && (BR2_PACKAGE_BUSYBOX||
BR2_PACKAGE_IFUPDOWN)system/Config.in +3
-0+ help + The name of the network interface to configure automatically. + A DHCP request will automatically happen on startup on theselected
system/Config.in +1
-0+ interface.And here I reworded it a bit and mentioned an example (eth0).
Quoted 4 lines
(quoted diff) +3
-0+define SET_NETWORK_LOCALHOST + echo "# interface file auto-generated by buildroot" > $(TARGET_DIR)/etc/network/interfaces + echo >>Quoted 8 lines
$(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
+endefElsewhere in BR we use syntax like:
( \
echo foo ; \
echo bar ; \
) > fileWhich is a bit less verbose, so I've changed it to that.
--
Bye, Peter Korsgaard
PATCH v4 1/1 Allow a single DHCP configuration via the system configuration submenu
Quoted 7 lines
Quoted 7 lines
Quoted 2 lines
+config
BR2_SIMPLE_DHCPWe're not completely consist with this, but the new system options are
called BR2_SYSTEM_*, so I've renamed to the option.
On this topic, what about the following idea?
If the interface name is blank do not perform DHCP as currently If the interface name is "*" then run something like this script to automatically find and use the first network interface for DHCP I'd like to be able to use the same BR config on slightly different boards that may sometimes have different network interface names/orders The kernel handles that OK with modules so maybe buildroot could to?
Steve
#!/bin/bash
interfaces="/tmp/interfaces" # The on-the-fly generated interfaces file # This is only used for the BR2_SYSTEM_DHCP "simple single interface dhcp" option. # Many systems only have a single network interface, so auto-find/use it by default. # If there are in fact multiple network interfaces the first non-loop interface
# listed in /sys/class/net will be used as the default DHCP configured interface. # As an aid to debugging on new systems all other interfaces found are added to the # generated $interfaces file with DHCP enabled but only the first one is brought up. # Run "ifup -a -i $interfaces" as an alternate to the default /etc/network/interfaces # if [ $# -gt 0 ]; then # be our own mapping script echo "default" # will always be the first interface exit 0 fi
first=""
echo "# Auto-generated by $(readlink -f $0)" > $interfaces
echo "auto lo" >> $interfaces
echo "iface lo inet loopback" >> $interfaces
echo "" >> $interfaces
for interface in $(ls --hide=lo* /sys/class/net); do
if [ "$first" == "" ]; then first=$interface echo "auto $first" >> $interfaces else # This is only used to help troubleshoot any additional network interfaces later on echo "iface $interface inet dhcp" >> $interfaces fi echo "" >> $interfaces done # This is the only network interface that needs to be brought up for the simple case # The mapping to default instead of using the physical inteface name is intentional # so that all modifications and documentation will refer to the constant name "default" echo "iface default inet dhcp" >> $interfaces echo "" >> $interfaces # Map the first physical network interface to the logical default interface echo "mapping $first" >> $interfaces echo " script $(readlink -f $0)" >> $interfaces # We don't need any map statements since it's always going to be "default"
PATCH v4 1/1 Allow a single DHCP configuration via the system configuration submenu
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 4 lines
Quoted 1 line
"Steve" == Steve Kenton <[email protected]> writes:
+config
BR2_SIMPLE_DHCPWe're not completely consist with this, but the new system options are
called BR2_SYSTEM_*, so I've renamed to the option.
Quoted 8 lines
On this topic, what about the following idea?
If the interface name is blank do not perform DHCP as currently If the interface name is "*" then run something like this script to automatically find and use the first network interface for DHCP I'd like to be able to use the same BR config on slightly different boards that may sometimes have different network interface names/orders The kernel handles that OK with modules so maybe buildroot could to?
So those boards have network interfaces not using eth%d names? That sounds pretty uncommon to me. Another approach would simply be add an init script to rename those to eth0 with nameif.
Signature · 1 line
Bye, Peter Korsgaard
PATCH v4 1/1 Allow a single DHCP configuration via the system configuration submenu
Quoted 17 lines · Peter Korsgaard
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
"Steve" == Steve Kenton<[email protected]> writes:
+config
BR2_SIMPLE_DHCPWe're not completely consist with this, but the new system options are
called BR2_SYSTEM_*, so I've renamed to the option.Quoted 8 lines
On this topic, what about the following idea?
If the interface name is blank do not perform DHCP as currently If the interface name is "*" then run something like this script to automatically find and use the first network interface for DHCP I'd like to be able to use the same BR config on slightly different boards that may sometimes have different network interface names/orders The kernel handles that OK with modules so maybe buildroot could to?
Quoted 3 lines
So those boards have network interfaces not using eth%d names? That sounds pretty uncommon to me. Another approach would simply be add an init script to rename those to eth0 with nameif.
Yes, two I have to test right now are an Asrock and an ECS mini-ITX and on both
the kernel built with buildroot 2015.02-rc1 calls the network interface "sit0"
Given that the name(s) are available why not just use it/them instead of requiring the
entering of a configuration value for an interface name to use BR2_SIMPLE_DHCP?
Steve
Quoted 1 line
PATCH v4 1/1 Allow a single DHCP configuration via the system configuration submenu
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"Steve" == Steve Kenton <[email protected]> writes:
Hi,
Quoted 8 lines
Quoted 3 lines
So those boards have network interfaces not using eth%d names? That sounds pretty uncommon to me. Another approach would simply be add an init script to rename those to eth0 with nameif.
Yes, two I have to test right now are an Asrock and an ECS mini-ITX and on both
the kernel built with buildroot 2015.02-rc1 calls the network interface "sit0"
Really? sit%d is normally for point-to-point tunnels, not for real hw devices:
http://www.deepspace6.net/docs/iproute2tunnel-en.html
Signature · 1 line
Bye, Peter Korsgaard
PATCH v4 1/1 Allow a single DHCP configuration via the system configuration submenu
Quoted 13 lines · Peter Korsgaard
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"Steve" == Steve Kenton <[email protected]> writes:
Hi,
Quoted 8 lines
Quoted 3 lines
So those boards have network interfaces not using eth%d names? That sounds pretty uncommon to me. Another approach would simply be add an init script to rename those to eth0 with nameif.
Yes, two I have to test right now are an Asrock and an ECS mini-ITX and on both
the kernel built with buildroot 2015.02-rc1 calls the network interface "sit0"
Quoted 5 lines
Really? sit%d is normally for point-to-point tunnels, not for real hw devices:
I was not aware of that, but it certainly set off alarm bells in my mind. I'm just now getting to the networking and I thought my problem was the names being wrong. I guess I wrote a clever script to solve a problem that does not exist :-)
I don't know where "sit0" comes from but I see I'm missing a driver for my ethernet - oops! I didn't look closely enough and just assumed they were the same two devices.
Sorry for the noise.
Steve
Here is what buildroot-2015.02-rc2 shows me with lspci -k and ifconfig -a:
03:00.0 Class 0200: 10ec:8168
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
sit0 Link encap:IPv6-in-IPv4
NOARP MTU:1480 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
And here is what Ubuntu 14.04 on the same hardware show me:
03:00.0 Ethernet controller: Realtek Semiconductor Co., Ltd. RTL8111/8168/8411 PCI Express Gigabit Ethernet Controller (rev 06)
Subsystem: ASRock Incorporation Motherboard (one of many)
Kernel driver in use: r8169
eth1 Link encap:Ethernet HWaddr bc:5f:f4:cb:1e:f6
inet addr:192.168.1.2 Bcast:192.168.1.255 Mask:255.255.255.0 inet6 addr: fe80::be5f:f4ff:fecb:1ef6/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:1288 errors:0 dropped:0 overruns:0 frame:0 TX packets:783 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000
RX bytes:1472508 (1.4 MB) TX bytes:67242 (67.2 KB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:286 errors:0 dropped:0 overruns:0 frame:0 TX packets:286 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0
RX bytes:23049 (23.0 KB) TX bytes:23049 (23.0 KB)
PATCH v4 1/1 Allow a single DHCP configuration via the system configuration submenu
In reply to Peter Korsgaard----- Mail original -----
Quoted 22 lines
Quoted 12 lines
Quoted 10 lines
Quoted 10 lines
Quoted 4 lines
Quoted 1 line
"Steve" == Steve Kenton <[email protected]> writes:
+config
BR2_SIMPLE_DHCPWe're not completely consist with this, but the new system options
are
called BR2_SYSTEM_*, so I've renamed to the option.On this topic, what about the following idea?
Quoted 9 lines
If the interface name is blank do not perform DHCP as currently If the interface name is "*" then run something like this script to automatically find and use the first network interface for DHCP I'd like to be able to use the same BR config on slightly different
boards that may sometimes have different network interface names/orders
The kernel handles that OK with modules so maybe buildroot could to?
Quoted 4 lines
So those boards have network interfaces not using eth%d names? That sounds pretty uncommon to me. Another approach would simply be add an init script to rename those to eth0 with nameif.
there is the (still pretty uncommon) case of networkd that does interface naming based on the physical layout and not the module loading order
interfaces are never named eth* in that case.
Regards
Jeremy Rosen