Page 1 of 1

DHCP client issues

Posted: Sun Mar 29, 2015 7:24 pm
by ulikoehler
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

Re: DHCP client issues

Posted: Sun Mar 29, 2015 8:34 pm
by Giovanni
Are those supposed to be there even if DHCP is not used?

Giovanni

Re: DHCP client issues

Posted: Sun Mar 29, 2015 9:45 pm
by ulikoehler
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

Re: DHCP client issues

Posted: Tue Mar 31, 2015 3:13 am
by ulikoehler
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

Re: DHCP client issues

Posted: Sun Apr 05, 2015 11:13 am
by Giovanni
Committed.

Giovanni

Re: DHCP client issues

Posted: Wed Apr 08, 2015 12:13 am
by ulikoehler
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

Re: DHCP client issues

Posted: Wed Apr 08, 2015 8:36 am
by Giovanni
Hi,

I committed the change.

Giovanni