LWIP multiple netif

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderator: RoccoMarco

Post Reply
dhq
Posts: 5
Joined: Sun Jun 12, 2016 9:55 pm
Has thanked: 1 time

LWIP multiple netif

Post 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
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: LWIP multiple netif

Post by Giovanni »

Hi,

The scenario has never been considered, most likely lwipthread requires customizations for this.

Giovanni
dhq
Posts: 5
Joined: Sun Jun 12, 2016 9:55 pm
Has thanked: 1 time

Re: LWIP multiple netif

Post 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.
Post Reply