lwip-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lwip-users] DHCP server offer timing


From: Leon Woestenberg
Subject: Re: [lwip-users] DHCP server offer timing
Date: Thu, 11 Mar 2004 19:17:32 +0100
User-agent: Mozilla Thunderbird 0.5 (Windows/20040207)

Hello,

thanks for this report. Lets walk through this one...

address@hidden wrote:
I am using lwIP 0.7.1 and found a situation that seems to be related
to DHCP server offer timing.

The following is the excerpt from dhcp_discover().

    /* set receive callback function with netif as user data */
    udp_recv(dhcp->pcb, dhcp_recv, netif);

    udp_bind(dhcp->pcb, IP_ADDR_ANY, DHCP_CLIENT_PORT);
    udp_connect(dhcp->pcb, IP_ADDR_BROADCAST, DHCP_SERVER_PORT);
    LWIP_DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_discover: send()ing\n"));
    udp_send(dhcp->pcb, dhcp->p_out);     /* 1 */

At this point, the DISCOVER message is on its way to a DHCP server.
We must now listen to any DHCP server for an OFFER message. However,
the PCB is still "connected" to remote address IP_ADDR_BROADCAST, which
is 255.255.255.255.

    LWIP_DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_discover: bind()ing\n"));
    udp_bind(dhcp->pcb, IP_ADDR_ANY, DHCP_CLIENT_PORT);
    LWIP_DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_discover: connect()ing\n"));
    udp_connect(dhcp->pcb, IP_ADDR_ANY, DHCP_SERVER_PORT);   /* 2 */

Only after the connect, we accept packets from ANY address (0.0.0.0).

So yes, you have found a race condition.

I am considering to introduce another UDP-PCB which will receive DHCP
offer.  But that is thought to be DHCP server's fast response.......
>
No, I would suggest introducing a scope-local PCB for dhcp_discover() for the _outgoing_ DISCOVER message. This way, we keep dhcp->pcb for
globally listening on replies.

We might have this race condition as well in the next pair of messages,
which are the REQUEST and ACK message, to resp. from the server.

This makes a nice case for udp_sendto(), although I would not want to
introduce more code footprint or overhead by having udp_send() call
udp_sendto().

I will review the code.

Regards,

Leon Woestenberg.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]