lwip-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lwip-devel] two netif on the same HW - DHCP and fixed ip toghether


From: Piero 74
Subject: [lwip-devel] two netif on the same HW - DHCP and fixed ip toghether
Date: Tue, 16 Dec 2008 17:08:36 +0100

Hi all.

I found a solution for my problem, but i need community feedback.

The problem is:

I have my ip board, and i need to simplify the installer work.
So, in a business LAN with a DHCP server, the idea is to have FW which starts, as default, with DHCP client enabled, get an IP to himself, and the installer can read the IP using
'ping <nomeHOST>'  (i used code found in forum for NBNS.. very good code!!! Thanks Alain!)
After this, a professional installer could decide tho disable DHCP client and use a fixed IP, through our SW which  changes IP board setting.

Ok... but the problem happens if the installer put the board in a small LAN without DHCP or try to connect it directly to his pc using eth cable.
In this case i need a fixed IP.


I tried to use a net interface with fixed IP, and after start DHCP client... in my company LAN DHCP server doesn't answer (or routers block broadcast packet with src IP different than 0.0.0.0)

So, my solution, is:

- create TWO interfaces on the same HW, one with fixed IP and one with DHCP on and ip = 0.0.0.0
- i changed code in ethernetif scheleton, in function ethernetif_input() in this way:

...
  switch (htons(ethhdr->type)) {

#if PPPOE_SUPPORT
    /* PPPoE packet? */
  case ETHTYPE_PPPOEDISC:
    // not implemented additional code
  case ETHTYPE_PPPOE:
    // not implemented additional code
#endif /* PPPOE_SUPPORT */

    /* IP or ARP packet? */
  case ETHTYPE_ARP:
/* test*/
    // create a copy of pbuf for each netif. ONLY for ARP packet
    for( netifCurr = netifLocal; netifCurr != NULL; netifCurr = netifCurr->next )
    {
      ptemp = pbuf_alloc(PBUF_RAW, p->tot_len, PBUF_POOL);
      if (ptemp != NULL)
      {

#if ETH_PAD_SIZE
          pbuf_header(ptemp, -ETH_PAD_SIZE); // drop the padding word
#endif

        pbuf_copy(ptemp, p);
        // full packet send to tcpip_thread to process
        if (netifCurr->input(ptemp, netifCurr)!=ERR_OK)
        {
          LWIP_DEBUGF(NETIF_DEBUG, ("ethernetif_input: ARP input error\n"));
          pbuf_free(ptemp);
          ptemp = NULL;
        }
      }
    }
    pbuf_free(p); // free original pbuf
    break;
//
  case ETHTYPE_IP:
    /* full packet send to tcpip_thread to process */
    // if there are multiple interface on the same emac hw, send to first interface
    // ip layer will route packets to correct netif
    if (netifLocal->input(p, netifLocal)!=ERR_OK)
    {
      LWIP_DEBUGF(NETIF_DEBUG, ("ethernetif_input: IP input error\n"));
      pbuf_free(p);
      p = NULL;
    }
    ret = TRUE;
    break;
  default:
    pbuf_free(p);
    p = NULL;
    break;
  }
  return(ret);
...

so.. now i duplicate ARP packets and send a copy of each interface, and use always the first interface for IP packet, because IP layer route packet between interfaces

In this way, until board gets IP from DHCP, it answers using fixed IP, after it answers using dynamic IP


Any comment??

Bye 
Piero

reply via email to

[Prev in Thread] Current Thread [Next in Thread]