[En-Nut-Discussion] Problem with NutDhcpClient thread (\pro\dhcpc.c)

Arlind Cela arlind.cela at gmail.com
Thu May 8 17:24:30 CEST 2008


Hello group,

While tracing the dhcp traffic, we realized a problem related to
NutDhcpClient thread. The situation is as follows:

We start this thread with NutDhcpIfConfig(). The device gets the IP settings
from the DHCP server, with a lease of 30 minutes. After 15 minutes (50%
lease), we are supposed to send a request for renewal, but it goes wrong…

 -debug-

[1.DHCP-BOUND 900]
[1.DHCP-ERROR 1]

- -

After taking a look into it, we realized that the problem was caused from
the following peace of code:

/*

 * Keep track of the API timeout.

 */

if (dhcpState != DHCPST_IDLE && dhcpApiTimeout != NUT_WAIT_INFINITE) {

    u_long tt = NutGetMillis() - dhcpApiStart;

    if (dhcpApiTimeout <= tt) {

        dhcpError = DHCPERR_TIMEOUT;

        dhcpState = DHCPST_IDLE;

        continue;

    }

    if ((tt = dhcpApiTimeout - tt) < tmo) {

        tmo = tt;

    }

}



dhcpApiTimeout (we use 20000) is always smaller than tt, because
dhcpApiStart only gets the value of NutGetMillis() when the thread is
started (@DhcpKick); in the meanwhile the value of NutGetMillis() has
increased by 15 minutes...

We figured that a workaround would be to update the value of dhcpApiStart
every time we enter the DHCPST_BOUND state

 if (dhcpState == DHCPST_BOUND) {

    dhcpApiStart = NutGetMillis();

}

Has anyone come accross this problem, or does anyone have a better
implementation?

Thank you in advance,


-Arlind Cela



More information about the En-Nut-Discussion mailing list