AnsweredAssumed Answered

Strange behavior in RTCS ipcfg.c when using LWDNS

Question asked by Travis Hidlay on Jul 22, 2011
Latest reply on May 9, 2012 by Jari Vanhakylä

Hello,

 

I've been working on using DHCP to automatically configure a K60 using a TWR-K60 + TWR-SER development setup. 

 

The OS is MQX 3.7.  I tried using the code below:

 

error = ipcfg_bind_dhcp_wait(IPCFG_default_enet_device, 0, NULL);

 

This was followed by checking the error for the result, and printing out the resulting ip information

using the same code that's in the Security_Network.c file (lines 98-101).

 

The scenario was this:

 

I plugged in the TWR-SER board to an isolated switch connected only to a DHCP server.  The configuration worked, and I was able to see the correct IP Address, Netmask, Gateway, and DNS address.  The lease time on the DHCP server was set to 5 minutes.  After about 1 minute, I plugged the TWR-SER board into another network with a different DHCP server.  The lease was renewed after a few minutes, and I was able to see the correct IP, Gateway, and NetMask, but the DNS server address was the same as before.

 

After digging through some of the RTCS code, I found the relevant section called during a renew of the DHCP lease, starting at line 949 in ipcfg.c, and it looks like (with RTCSCFG_ENABLE_LWDNS set) the only update to the DNS address happens by:

 

ipcfg_data[device].dns = ntohl (optptr);

 

The global LWDNS_server_ipaddr is never updated when the lease is renewed.  Is there any reason for this?  I added the following line:

 

ipcfg_add_dns_ip (device, ipcfg_data[device].dns);

 

This seems to do the trick, the DNS address is now included in the new DHCP lease.

 

Outcomes