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.
Post Reply
ulikoehler
Posts: 71
Joined: Tue Mar 17, 2015 2:32 am
Been thanked: 3 times

DHCP client issues

Post 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
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: DHCP client issues

Post by Giovanni »

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

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

Re: DHCP client issues

Post 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
ulikoehler
Posts: 71
Joined: Tue Mar 17, 2015 2:32 am
Been thanked: 3 times

Re: DHCP client issues

Post 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
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: DHCP client issues

Post by Giovanni »

Committed.

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

Re: DHCP client issues

Post 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
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: DHCP client issues

Post by Giovanni »

Hi,

I committed the change.

Giovanni
Post Reply