DHCP client

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

DHCP client

9,497 Views
niklasmolin
Senior Contributor I

Hi.

I'm trying to configure the DHCP client (udhcpc), but can't find where it is initialized.

Right now I can see that I have following udhcpc command running:

udhcpc -R -n -p /var/run/udhcpc.eth0.pid -i eth0

But it looks like it won't continue to try requesting an IP address if it failed.

In our case we will always have a link but it could be that it might not be able to access the DHCP server right after boot up.

We want the DHCP client to continue to request for an IP address, until it succeeded.

What I can see from the description of udhcpc I should use following command:

udhcpc -R -A -p /var/run/udhcpc.eth0.pid -i eth

But I can't find where this command is initialized during boot up (using Yocto)

Thanks,

Niklas

Labels (2)
3 Replies

3,179 Views
michaeldoswald
Contributor III

Hi,

I know it's too late for an answer, but maybe somebody finds this question while googling...

I have the same problem on my side. What I found out is, that the 'udhcpc' command is issued by busybox itself, not from within a startup script. Looking at the source from busybox/networking/ifupdown.c, I can see a method named 'dhcp_up'. This method will execute the dhcp client command after the interface is up. The method has actually four different methods of acquiring a dhcp address, depending on which tool is installed on the system (as of version 1.22.1-r0 of busybox). The tools are checked in the order listed below

  1. dhcpcd[[ -h %hostname%]][[ -i %vendor%]][[ -I %client%]][[ -l %leasetime%]] %iface%
  2. dhclient -pf /var/run/dhclient.%iface%.pid %iface%
  3. pump -i %iface%[[ -h %hostname%]][[ -l %leasehours%]]
  4. udhcpc UDHCPC_CMD_OPTIONS -p /var/run/udhcpc.%iface%.pid -i %iface%[[ -H %hostname%]][[ -c %client%]] [[ -s %script%]][[ %udhcpc_opts%]]

Given this information, I see two possible options to solve the problem:

  1. Install another dhcp client supported by busybox (e.g. dhcpcd) and configure it accordingly
  2. As seen in the fourth command, the udhcpc command is constructed with a define in it. This define can be changed with the 'defconfig' file of the busybox sources. The config option is named CONFIG_IFUPDOWN_UDHCPC_CMD_OPTIONS and the default value is set to "-R -n" (which is exactly what you see in your installation). One could recompile the busybox binary with the changed configuration.

I think the second option is preferrable. I'm not yet used to the Yocto build system, but I guess it would be possible to create a .bbappend file in your own meta-layer to add a patch for the default 'defconfig' file of the busybox package.

According to Yocto busybox menuconfig you can configure the busybox package and build the binary with your yocto installation using the following commands:

bitbake -c menuconfig busybox 

bitbake busybox 

As Otavio Salvador wrote in the same thread: It's good to add it in a project specific layer and save it there with a busybox_<version>.bbappend instructing bitbake to check the layer's path for overrides. This allow for later reuse of the changed configuration and also store of it under a SCM system (as GIT, for example).

3,179 Views
niklasmolin
Senior Contributor I

Hi Michael.

Have you had any luck with this yet?

We just ran into it again (after putting it on hold for some time).

But I'll try to dig into this again.

0 Kudos

3,179 Views
michaeldoswald
Contributor III

Hi Niklas,

I couldn't get it to run with busybox alone either. After a lot of trial and error and banging my head onto the desk, I gave up on the udhcpc idea. Since I use yocto, I found that the 'connman' utility is available as a recipe. Connman is a tool that handles network connections for ethernet, wifi, bluetooth, cellular etc. and seems to be under active development.

I've added the 'connman' package to my yocto image definition and stripped the information in the /etc/network/interfaces configuration file to only contain the loopback (otherwise busybox may interfer with the network configuration, it may also be possible to disable all network functions of busybox, I didnt' try that):

/etc/network/interfaces

auto lo

iface lo inet loopback

Connman will automatically configure your ethernet port as soon as the cable is connected and get an IP address via DHCP. This is the default behaviour if no explicit configuration is done. If you need to configure IP addresses or other settings explicitly, the config files for connman are located at /var/lib/connman. The documentation in the git repo at http://git.kernel.org/cgit/network/connman/connman.git/tree/doc contains a lot of information.

There is also a command line configuration utility called connmanctl which allows to configure a lot of stuff interactively. The corresponding yocto package would be 'connman-client'.

On another note: Connman is plugin based, which means that configuration abilities for the different network technologies is handled within plugins. The ethernet plugin is compiled in by default in the yocto recipe. If you also need the wifi plugin, you need to specify the following setting in your yocto 'local.conf':

# Enable wifi support for connman

PACKAGECONFIG_append_pn-connman = " wifi"

I'm sorry that I cant give you a solution that works with the udhcp client from busybox. But connman seems to be pretty lightweight too and the configuration is a lot easier, especially if you also need wifi. In that case connman is handling all the wpa_supplicant stuff for you, you only need to add a small config file in the connman directory.

Best Regards,

Michael