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: Oliver Schindler
Subject: Re: [lwip-users] fixed IP and DCHP on the same net interface?
Date: Wed, 17 Dec 2008 01:05:22 +0100
User-agent: Thunderbird 2.0.0.18 (Windows/20081105)

Hi all,
i'm facing the same problem, but my solution was, to put the fallback into the dhcp-timeout. Means: Startup the dhcp with 0.0.0.0 , if it is getting an
ip , everything is o.k. , if not the static IP is used . ( see below ..)
The disadvantage of this is, that it takes 20 seconds, before the static IP is used. For me this is o.k., because the static IP is only used with
laptop and crossover-cable to configure the target.

Cheers,
Oliver



static void
dhcp_timeout(struct netif *netif)
{
struct dhcp *dhcp = netif->dhcp;

LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | 3, ("dhcp_timeout()\n"));
/* back-off period has passed, or server selection timed out */
if ((dhcp->state == DHCP_BACKING_OFF) || (dhcp->state == DHCP_SELECTING)) {
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_timeout(): No DHCP , giving up\n"));
// dhcp_release(netif);
dhcp_set_default(netif); /* Giving up */
//dhcp_discover(netif);
/* receiving the requested lease timed out */
} else if (dhcp->state == DHCP_REQUESTING) {
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("dhcp_timeout(): REQUESTING, DHCP request timed out\n"));
if (dhcp->tries <= 5) {
dhcp_select(netif);
} else {
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("dhcp_timeout(): REQUESTING, releasing, restarting\n"));
//dhcp_release(netif);
dhcp_set_default(netif); /* Giving up */
// dhcp_discover(netif);
}
--- snip ---

void dhcp_set_default(struct netif *netif){

struct ip_addr xIpAddr, xNetMast, xGateway;
struct dhcp *dhcp = netif->dhcp;

/* Timeout on first try, so set up static ip */

IP4_ADDR( &xIpAddr, cur_ip[0], cur_ip[1], cur_ip[2], cur_ip[3] );
IP4_ADDR( &xNetMast, cur_netmask[0], cur_netmask[1], cur_netmask[2], cur_netmask[3] ); IP4_ADDR( &xGateway, cur_gateway[0], cur_gateway[1], cur_gateway[2], cur_gateway[3] );
/* set the default IP address for the interface */
netif_set_ipaddr(netif, &xIpAddr);
netif_set_gw(netif, &xGateway);
netif_set_netmask(netif, &xNetMast);
/* bring the interface up */
netif_set_up(netif);
/* netif is now bound to DHCP leased address */
dhcp_set_state(dhcp, DHCP_BOUND);

}

--------------------------------------------




bill schrieb:

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 <mailto: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 <mailto:address@hidden>
http://lists.nongnu.org/mailman/listinfo/lwip-users

------------------------------------------------------------------------

_______________________________________________
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]