lwip-users
[Top][All Lists]
Advanced

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

RE: [lwip-users] fixed IP and DCHP on the same net interface?


From: bill
Subject: RE: [lwip-users] fixed IP and DCHP on the same net interface?
Date: Tue, 16 Dec 2008 11:55:13 -0500

Piero,

 

In my Ethernet driver, I’ve done the following to allow an attempt at DHCP with a fallback to a static IP.

 

                int dhcpFallbackTimer = GetmSTimer() + 5000;                   //            5 seconds

                while( ! netif_is_up( netif_default ) )

                                {

                                //            Waiting for fallback

                                if( (int) GetmSTimer() - dhcpFallbackTimer > 0 )

                                                {

                                                struct ip_addr sn_mask, gw_addr;

                                               

                                                netif_set_down( netif_default );

                                                netif_set_addr( netif_default, &ip, &netmask, &gateway );                        //            Fallback address

                                                netif_set_up( netif_default );

                                                break;

                                                }

                                }

 

The fallback address is something the user can configure, but it starts out as a 169.254 address with the last 2 bytes formed from the MAC address (so the installer knows what the fallback address is).

 

Hope this helps,

Bill

 

From: address@hidden [mailto:address@hidden On Behalf Of Piero 74
Sent: Tuesday, December 16, 2008 11:09 AM
To: Mailing list for lwIP users
Subject: Re: [lwip-users] fixed IP and DCHP on the same net interface?

 

i found a solution... but i "forced" stack implementation guidelines...

 

I did a post to lwip_dev with this idea... because i need a feedback... here a copy.

 

"

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??

"

2008/12/16 Alain M. <address@hidden>

The real question is: do you really want to do that? what if you connect 2 cameras, what happens? plus the problem on another message...

IMHO, this would work better:
try DHCP for some time, withou any ip, then use autoip...

Alain

Piero 74 escreveu:

 

Hi all

I tested a network camera, which seems work in this way:

it has a DHCP client inside, which starts on power on. But until an IP from DHCP server is available, it answers on fixed ip (i.e. 192.168.1.3)

Can i do the same using lwip?

I tried to bring up an interface with fixed IP and after start DHCP, but it doesn't work: i didn't receive a new ip address from DHCP server.

I saw DHCP traffic using wireshark: in normal situation, DHCP client sends packet from 0.0.0.0 to broadcast, and the server answers, in my situation i have DHCP request from 192.168.1.3 to broadcast...
i suppose this could be the problem

Any idea??

Thanks,
Piero

 

_______________________________________________
lwip-users mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/lwip-users

 


reply via email to

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