DHCP client issues

This forum is about you. Feel free to discuss anything is related to embedded and electronics, your awesome projects, your ideas, your announcements, not necessarily related to ChibiOS but to embedded in general. This forum is NOT for support.
ulikoehler
Posts: 71
Joined: Tue Mar 17, 2015 2:32 am
Location: Munich, Germany
Been thanked: 3 times

DHCP client issues

Postby ulikoehler » Sun Mar 29, 2015 7:24 pm

Since ChibiOS 2.6 I have had issues with the lwIP DHCP client not working properly. I believe this is the case because the lwip functions dhcp_start() and dhcp_stop() are never called in the lwIP binding thread.

I have written a patch that calls them when an interface comes up / down. I have tested them successfully on an Olimex E407 and used this code in multiple projects, however I'd like to hear your comments about it.

Change: In lwipthread.c, replace

Code: Select all

        if (current_link_status)
          tcpip_callback_with_block((tcpip_callback_fn) netif_set_link_up,
                                     &thisif, 0);
        else
          tcpip_callback_with_block((tcpip_callback_fn) netif_set_link_down,
                                     &thisif, 0);

by

Code: Select all

        if (current_link_status) {
          tcpip_callback_with_block((tcpip_callback_fn) netif_set_link_up,
                                     &thisif, 0);
          dhcp_start(&thisif);
        } else {
          tcpip_callback_with_block((tcpip_callback_fn) netif_set_link_down,
                                     &thisif, 0);
          dhcp_stop(&thisif);
        }


Best regards, Uli

User avatar
Giovanni
Site Admin
Posts: 13008
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 742 times
Been thanked: 620 times
Contact:

Re: DHCP client issues

Postby Giovanni » Sun Mar 29, 2015 8:34 pm

Are those supposed to be there even if DHCP is not used?

Giovanni

ulikoehler
Posts: 71
Joined: Tue Mar 17, 2015 2:32 am
Location: Munich, Germany
Been thanked: 3 times

Re: DHCP client issues

Postby ulikoehler » Sun Mar 29, 2015 9:45 pm

Thanks Giovanni - you are right, they should not be active in that case. Here's the fixed version:

Code: Select all

        if (current_link_status) {
          tcpip_callback_with_block((tcpip_callback_fn) netif_set_link_up,
                                     &thisif, 0);
#ifdef LWIP_DHCP
          dhcp_start(&thisif);
#endif
        } else {
          tcpip_callback_with_block((tcpip_callback_fn) netif_set_link_down,
                                     &thisif, 0);
#ifdef LWIP_DHCP
          dhcp_stop(&thisif);
#endif
        }


Best regards

ulikoehler
Posts: 71
Joined: Tue Mar 17, 2015 2:32 am
Location: Munich, Germany
Been thanked: 3 times

Re: DHCP client issues

Postby ulikoehler » Tue Mar 31, 2015 3:13 am

Correction: It should be this way because LWIP_DHCP is defined as 1 or 0 and not undefined:

Code: Select all

        if (current_link_status) {
          tcpip_callback_with_block((tcpip_callback_fn) netif_set_link_up,
                                     &thisif, 0);
#if LWIP_DHCP
          dhcp_start(&thisif);
#endif
        } else {
          tcpip_callback_with_block((tcpip_callback_fn) netif_set_link_down,
                                     &thisif, 0);
#if LWIP_DHCP
          dhcp_stop(&thisif);
#endif
        }


Best regards

User avatar
Giovanni
Site Admin
Posts: 13008
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 742 times
Been thanked: 620 times
Contact:

Re: DHCP client issues

Postby Giovanni » Sun Apr 05, 2015 11:13 am

Committed.

Giovanni

ulikoehler
Posts: 71
Joined: Tue Mar 17, 2015 2:32 am
Location: Munich, Germany
Been thanked: 3 times

Re: DHCP client issues

Postby ulikoehler » Wed Apr 08, 2015 12:13 am

Thanks for merging, Giovanni!

DHCP works perfectly for me now. I noticed, however, that GCC shows a warning that dhcp_start and dhcp_stop are not defined. I might have patched a #include into my lwIP at some point which hid the error from me.

Although it is not functionally required unless someone uses -Werror like flags, I think we should add

Code: Select all

#if LWIP_DHCP
#include <lwip/dhcp.h>
#endif


somewhere in the include section of lwipthread.c

Best regards, Uli

User avatar
Giovanni
Site Admin
Posts: 13008
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 742 times
Been thanked: 620 times
Contact:

Re: DHCP client issues

Postby Giovanni » Wed Apr 08, 2015 8:36 am

Hi,

I committed the change.

Giovanni


Return to “User Projects”

Who is online

Users browsing this forum: No registered users and 2 guests