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

Steve Kenton skenton at ou.edu
Sat Feb 14 16:18:47 UTC 2015

>>> +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.
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?


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

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
		echo "auto $first" >>			$interfaces
# This is only used to help troubleshoot any additional network interfaces later on
		echo "iface $interface inet dhcp" >>	$interfaces
	echo "" >>					$interfaces
# 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"

More information about the buildroot mailing list