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
> 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
Regards
Ueli
> 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.