Skip to content

Commit f4f62a3

Browse files
Jeremy Rosenjacmet
Jeremy Rosen
authored andcommitted
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 [Peter: rename to BR2_SYSTEM_DHCP, tweak help text & implementation] Signed-off-by: Jérémy Rosen <[email protected]> Signed-off-by: Peter Korsgaard <[email protected]>
1 parent d538b8b commit f4f62a3

File tree

3 files changed

+49
-4
lines changed

3 files changed

+49
-4
lines changed

system/Config.in

+20
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,26 @@ config BR2_TARGET_GENERIC_REMOUNT_ROOTFS_RW
326326

327327
endif # BR2_ROOTFS_SKELETON_DEFAULT
328328

329+
330+
config BR2_SYSTEM_DHCP
331+
string "Network interface to configure through DHCP"
332+
default ""
333+
depends on !BR2_PACKAGE_SYSTEMD_NETWORKD && (BR2_PACKAGE_BUSYBOX || BR2_PACKAGE_IFUPDOWN)
334+
help
335+
Enter here the name of the network interface (E.G. eth0) to
336+
automatically configure through DHCP at bootup.
337+
338+
If left empty, no automatic DHCP requests will take place.
339+
340+
For more complicated network setups use an overlay to overwrite
341+
/etc/network/interfaces or add a networkd configuration file.
342+
343+
comment "automatic network configuration via DHCP is not compatible with networkd"
344+
depends on BR2_PACKAGE_SYSTEMD_NETWORKD
345+
346+
comment "automatic network configuration via DHCP needs ifupdown or busybox"
347+
depends on !(BR2_PACKAGE_BUSYBOX || BR2_PACKAGE_IFUPDOWN)
348+
329349
config BR2_TARGET_TZ_INFO
330350
bool "Install timezone info"
331351
# No timezone for musl; only for uClibc or (e)glibc.

system/skeleton/etc/network/interfaces

-4
This file was deleted.

system/system.mk

+29
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,35 @@ ifneq ($(TARGET_GENERIC_ROOT_PASSWD),)
3838
TARGETS += host-mkpasswd
3939
endif
4040

41+
define SET_NETWORK_LOCALHOST
42+
( \
43+
echo "# interface file auto-generated by buildroot"; \
44+
echo ; \
45+
echo "auto lo"; \
46+
echo "iface lo inet loopback"; \
47+
) > $(TARGET_DIR)/etc/network/interfaces
48+
endef
49+
50+
NETWORK_DHCP_IFACE = $(call qstrip,$(BR2_SYSTEM_DHCP))
51+
52+
ifneq ($(NETWORK_DHCP_IFACE),)
53+
define SET_NETWORK_DHCP
54+
( \
55+
echo ; \
56+
echo "auto $(NETWORK_DHCP_IFACE)"; \
57+
echo "iface $(NETWORK_DHCP_IFACE) inet dhcp"; \
58+
) >> $(TARGET_DIR)/etc/network/interfaces
59+
endef
60+
endif
61+
62+
define SET_NETWORK
63+
mkdir -p $(TARGET_DIR)/etc/network/
64+
$(SET_NETWORK_LOCALHOST)
65+
$(SET_NETWORK_DHCP)
66+
endef
67+
68+
TARGET_FINALIZE_HOOKS += SET_NETWORK
69+
4170
ifeq ($(BR2_ROOTFS_SKELETON_DEFAULT),y)
4271

4372
define SYSTEM_ROOT_PASSWD

0 commit comments

Comments
 (0)