Page 1 of 1
LWIP multiple netif
Posted: Sun Jul 03, 2016 12:18 am
by dhq
Hi,
I am trying to set up LWIP so that it uses two netif simultaneously.
One is used for a static IP and the other one starts a DHCP client.
I already set up a simple webserver demo.
The DHCP would have all ip, netmask ,gateway set to zero.
The issue is , after I poked around a bit , I see that ChibiOS always sets up a deafult netif on the lwip thread.
Does ChibiOS supports multiple netifs or do I have to modify the lwip thread?
PS: not sure if this is the correct sub-forum.
Best,
Demeter
Re: LWIP multiple netif
Posted: Sun Jul 03, 2016 9:41 am
by Giovanni
Hi,
The scenario has never been considered, most likely lwipthread requires customizations for this.
Giovanni
Re: LWIP multiple netif
Posted: Sun Jul 03, 2016 4:47 pm
by dhq
I looked a bit further and here's what I found:
1. LWIP does not seem to have any internal interface routing algorithm unless I am missing something
2. I created two interfaces inside the lwip thread and the last interface is the one that always gets the packets.
Code: Select all
IP4_ADDR(&dhcp_ip, 0, 0, 0, 0);
IP4_ADDR(&dhcp_gateway, 0, 0, 0, 0);
IP4_ADDR(&dhcp_netmask, 0, 0, 0 ,0);
netif_add(&dhcpif, &dhcp_ip, &dhcp_netmask, &dhcp_gateway, NULL, ethernetif2_init, tcpip_input);
netif_set_default(&thisif);
netif_set_up(&thisif);
netif_set_up(&dhcpif);
3. Different interfaces need different MAC addresses.
4. I tried to duplicate the ARP packets to each interface but this does not work at present.
Code: Select all
case ETHTYPE_ARP:
// create a copy of pbuf for each netif. ONLY for ARP packet
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 (thisif.input(ptemp, &thisif)!=ERR_OK)
{
LWIP_DEBUGF(NETIF_DEBUG, ("ethernetif_input: ARP input error\n"));
pbuf_free(ptemp);
ptemp = NULL;
}
if (dhcpif.input(ptemp, &dhcpif)!=ERR_OK)
{
LWIP_DEBUGF(NETIF_DEBUG, ("ethernetif_input: ARP input error\n"));
pbuf_free(ptemp);
ptemp = NULL;
}
}
pbuf_free(p); // free original pbuf
I'll give it another try but I was under the impression that this had been done since multiple netif are a perfect match for RTOS'ses.