Wednesday 1 July 2015

First (failed) attempt to route IP packets with ESP8266

In every other comment on my previous projects, someone brought up the topic of mesh networking with ESP8266 modules. Gooooogling the topic, I couldn't find a project that had made into a stable release. (Drop me a line in the comments if you found/have one)

Taking things nice & slow, I started with the following setup:

Ping connectivity table
PING n/a n/a n/a n/a YES n/a n/a n/a YES n/a n/a YES NO n/a n/a n/a

So as expected, the ESP8266/NodeMCU does not forward IP packets. I had a peek at the NodeMCU sources and made the following change to /app/include/lwip/opt.h:

  * IP_FORWARD==1: Enables the ability to forward IP packets across network  
  * interfaces. If you are going to run lwIP on a device with only one network  
  * interface, define this to 0.  
 #ifndef IP_FORWARD  
 // #define IP_FORWARD           0  
 #define IP_FORWARD           1  

I rebuilt the firmware, flashed it to a ESP Module and:

FAILED. No changes to the module's routing behaviour.

If anyone is more familiar with the code, don't hesitate to leave a comment.

Next Steps:

  • Get packet forwarding to work
  • Routes? What routes? (There is a hook for those in later versions of LWIP. Backporting possible?)

Another search of the source code shows that there is another place that sets IP_FORWARD: /app/include/lwipopts.h - I'll try that next.

1 comment:

  1. 1) lwipopts.h, opt.h ===> IP_FORWARD 1
    2) xtensa-lx106-elf-ar x liblwip.a ==> extract LIB
    3) MODIFY /core/ipv4/ip.c

    //icmp_time_exceeded(p, ICMP_TE_TTL); ==> COMMENT

    and COMMENT !!!

    //if (netif == inp) {
    // LWIP_DEBUGF(IP_DEBUG, ("ip_forward: not bouncing packets back on incoming interface.\n"));
    // goto return_noroute;
    // }
    --> ip.o

    xtensa-lx106-elf-ar cr liblwip.a api_lib.o ... (new)ip.o .. udp.o

    and replace the old liblwip.a with the new one that support IP FORWARDING :):)