[lwip-users] Defining the default route

60 views
Skip to first unread message

Mason

unread,
Mar 19, 2012, 12:11:33 PM3/19/12
to Mailing list for lwIP users
Hello,

I'm using lwip 1.4.1

Below is the code I use to initialize the network stack.

static void do_lwip_init(void *arg)
{
struct netif *netif = malloc(sizeof *netif);
memset(netif, 0, sizeof *netif);
#if USE_DHCP
netif_add(netif, NULL, NULL, NULL, NULL, ethernetif_init, tcpip_input);
dhcp_start(netif);
#else
ip_addr_t addr, mask;
IP4_ADDR(&addr, 192, 168, 1, 42);
IP4_ADDR(&mask, 255, 255, 255, 0);
netif_add(netif, &addr, &mask, NULL, NULL, ethernetif_init, tcpip_input);
netif_set_up(netif);
#endif
}

void eth_init(void)
{
tcpip_init(do_lwip_init, NULL);
}

When I try to connect to an address outside the LAN, I get an
ERR_RTE error (Routing problem).

Looking at struct netif *ip_route(ip_addr_t *dest)
IIUC, ip_route will check if the address is local,
otherwise, it will send via netif_default when it
is set.

Several questions:

1) The correct function to use is netif_set_default, right?

2) If I use static addressing, I have to declare the
default route myself, using netif_set_default?

3) When using DHCP, does the DHCP code take care of
declaring the default route, or do I have to do it
myself, like point 2?

--
Regards.

_______________________________________________
lwip-users mailing list
lwip-...@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users

Simon Goldschmidt

unread,
Mar 19, 2012, 2:03:09 PM3/19/12
to Mailing list for lwIP users
Mason <mpeg...@free.fr> wrote:

> 1) The correct function to use is netif_set_default, right?
>
> 2) If I use static addressing, I have to declare the
> default route myself, using netif_set_default?
>
> 3) When using DHCP, does the DHCP code take care of
> declaring the default route, or do I have to do it
> myself, like point 2?

1) is always right. DHCP or AutoIP cannot change routing: you can have multiple netifs with DHCP or AutoIP enabled.
>

Simon

Ueli Niederer

unread,
Mar 20, 2012, 3:35:11 AM3/20/12
to Mailing list for lwIP users
> Below is the code I use to initialize the network stack.
> <snip>

> ip_addr_t addr, mask;
> IP4_ADDR(&addr, 192, 168, 1, 42);
> IP4_ADDR(&mask, 255, 255, 255, 0);
> netif_add(netif, &addr, &mask, NULL, NULL, ethernetif_init, tcpip_input);
A possible cause cause you can't connect outside the lan might be that
you didn't specify a gateway (3rd parameter). The gateway becomes
necessary if you want to communicate outside your subnet.

Regards
Ueli

Mason

unread,
Mar 20, 2012, 4:35:58 AM3/20/12
to Mailing list for lwIP users
Simon Goldschmidt wrote:

> Mason wrote:
>
>> 1) The correct function to use is netif_set_default, right?
>>
>> 2) If I use static addressing, I have to declare the
>> default route myself, using netif_set_default?
>>
>> 3) When using DHCP, does the DHCP code take care of
>> declaring the default route, or do I have to do it
>> myself, like point 2?
>
> 1) is always right. DHCP or AutoIP cannot change routing:
> you can have multiple netifs with DHCP or AutoIP enabled.

I thought lwip didn't support multi-homing very well?

Anyway, if I understand correctly, my init code should be:

static void do_lwip_init(void *arg)
{
struct netif *netif = malloc(sizeof *netif);
memset(netif, 0, sizeof *netif);
#if USE_DHCP
netif_add(netif, NULL, NULL, NULL, NULL, ethernetif_init, tcpip_input);
dhcp_start(netif);
#else
ip_addr_t addr, mask;
IP4_ADDR(&addr, 192, 168, 1, 42);
IP4_ADDR(&mask, 255, 255, 255, 0);
netif_add(netif, &addr, &mask, NULL, NULL, ethernetif_init, tcpip_input);
netif_set_up(netif);
#endif

netif_set_default(netif);
}

(And, as Ueli has pointed out, I must provide the address of a
gateway in the static addressing case.)

--
Regards.

Reply all
Reply to author
Forward
0 new messages