FreeRTOS+TCP: Problem with DHCP renewal on runtime, dhcp offer ignored or lost

Hi,

I work with a board using ATSAM4E16E microcontroller. I use DHCP to obtain an IP address. The DHCP process works fine at start up and gives me an IP address. The problem is that, after the lease time of the first given IP address, the new attempt of DHCP fails and the application switchs to static addressing.
I have used Wireshark to check the network exchanges during the new attempt and I have seen that the server does respond with a dhcp offer but it seems that the client ignores it, or maybe it is lost.
Currently, my only solution is to reboot the card but I would like to avoid it.

Do you have any idea what the problem is ?

Clémentin, thanks for reporting this. I must admit that this feature hasn’t received attention for many years.

I just tested DHCP renewal by forcing a very short lease time of 60 seconds. On my STM32F4 the DHCP renewal process seems to work well.

I forced a 1-minute expiry:

FreeRTOS_printf( ( "Setting DHCP renewal to %lu\n", dhcpMINIMUM_LEASE_TIME ) );
xDHCPData.ulLeaseTime = dhcpMINIMUM_LEASE_TIME;

Also I enabled +TCP debug logging in FreeRTOSIPConfig.h:

#define ipconfigHAS_DEBUG_PRINTF	1
#define FreeRTOS_debug_printf(X)	( void ) vLoggingPrintf X

and I added one extra logging around line 491:

    case eLeasedAddress :
        FreeRTOS_debug_printf( ( "vDHCPProcess: discover\n" ) );

It gave me the following logging:


  1.901.824 [IP-task   ] DHCP Discover address 192.168.2.114
  1.901.949 [IP-task   ] prvInitialiseDHCP: start after 250 ticks
  1.902.049 [IP-task   ] vDHCPProcess: discover
  3.838.803 [IP-task   ] vDHCPProcess: offer 192.168.2.12
  3.838.913 [IP-task   ] DHCP Request address 192.168.2.12
  3.839.041 [IP-task   ] vDHCPProcess: reply 192.168.2.12
  3.861.772 [IP-task   ] vDHCPProcess: offer 192.168.2.12
  3.861.881 [IP-task   ] vDHCPProcess: acked 192.168.2.12
  3.862.050 [IP-task   ] IP Address: 192.168.2.12
  3.862.446 [IP-task   ] Setting DHCP renewal to 60000

 63.862.238 [IP-task   ] vDHCPProcess: discover
 63.862.326 [IP-task   ] vDHCPProcess: reply 192.168.2.12
 63.881.311 [IP-task   ] vDHCPProcess: offer 192.168.2.12
 63.881.423 [IP-task   ] vDHCPProcess: acked 192.168.2.12
 63.881.558 [IP-task   ] IP Address: 192.168.2.12
 63.881.949 [IP-task   ] Setting DHCP renewal to 60000

123.881.238 [IP-task   ] vDHCPProcess: discover
123.881.326 [IP-task   ] vDHCPProcess: reply 192.168.2.12
123.899.759 [IP-task   ] vDHCPProcess: offer 192.168.2.12
123.899.872 [IP-task   ] vDHCPProcess: acked 192.168.2.12
123.900.006 [IP-task   ] IP Address: 192.168.2.12
123.900.403 [IP-task   ] Setting DHCP renewal to 60000

Could you do the same and show some logging?

Thanks for your reply,

I just modified the code as you’ve suggested and it gave me the following logging:

 DHCP offer: use = 1: Cont 100.0.0.0
 prvInitialiseDHCP: start after 250 ticks
 vDHCPProcess: discover                                                                 
 vDHCPProcess: offer c0a80015ip
 DHCP request: use = 1: Cont 192.168.0.21
 vDHCPProcess: reply c0a80015ip
 vDHCPProcess: offer c0a80015ip
 vDHCPProcess: acked c0a80015ip
 Setting DHCP renewal to 60000

 vDHCPProcess: discover
 vDHCPProcess: reply c0a80015ip
 vDHCPProcess: offer c0a80015ip            
 vDHCPProcess: acked c0a80015ip
 Setting DHCP renewal to 60000

 vDHCPProcess: discover
 vDHCPProcess: reply c0a80015ip
 vDHCPProcess: offer c0a80015ip
 vDHCPProcess: acked c0a80015ip
 Setting DHCP renewal to 60000

It seems that’s the DHCP renewal is actually working here, so the problem must be different.

I don’t know what your network setup looks like, but it is difficult to investigate the traffic between a board and a router.

What I often do is run a DHCP server on my laptop. Then I can also run WireShark and follow the DHCP and other conversations.

I use the open source Dual DHCP DNS Server. If necessary, disable other DHCP servers.

If you want, you can attach a zipped PCAP file to your post.