[En-Nut-Discussion] Attempting to fix network config API.

Henrik Maier hmnews at proconx.com
Wed Aug 20 02:34:16 CEST 2014

Hi Thiago,

On 20/08/2014 6:28 AM, Thiago A. Corrêa wrote:
> Hi,
>      Our functions for network configuration have more responsabilities
> than they should. They make assumptions that that simplify a sample
> application but actually makes it harder for a finished product that
> would usually let the user say he wants DHCP or he wants fixed IP
> settings.
>      I propose we introduce alternative functions that does what they
> advertise and let the caller decide what to do if it fails, or if he

I had exactly the very same issue.

We have overridden the auto-magic saving of IP configuration using a 
void function, as our application takes care of saving a device 
configuration in a different way. I also never liked that a DHCP 
acquired IP address suddenly becomes permanent.

int NutNetSaveConfig(void)
    return 0;

With disabled auto-magic IP configuration saving, we then use below code 
to somehow allow transition from DHCP to static IP and vice versa. 
Depending on the user selection globConfig.dhcpEnabled we pre-set some 
Nut/OS global variables to make NutDhcpIfConfig behave in a certain way. 
It works but surely is not a clean API but it allows nice transitions 
from DHCP to non-DHCP without any requirement for rebooting the device

       nif->if_local_ip = 0; // Make sure we don't think in DHCP that we 
are configured externally
       NutIpRouteDelAll(&devEth0); // Remove route table, all entries 
have become invalid

       if (globConfig.dhcpEnabled)
          confnet.cdn_cip_addr = 0;
          confnet.cdn_ip_mask = 0x00FFFFFF;
          confnet.cdn_gateway = 0;
          confnet.cdn_cip_addr = globConfig.localIpAddr.val;
          confnet.cdn_ip_mask = globConfig.localNetMask.val;
          confnet.cdn_gateway = globConfig.localGateway.val;
       result = NutDhcpIfConfig(DEV_ETHER_NAME, confnet.cdn_mac, 60000);

So I certainly would support a clean API to perform these steps. I 
suggest to separate saving of the config from applying them and also 
have a clear option to enable and disable DHCP again.


More information about the En-Nut-Discussion mailing list