esp_netif_receive eating all my ram (SLIP protocol) (IDFGH-4141)

fpena_inusual
Posts: 9
Joined: Tue Oct 20, 2020 8:58 am

Re: esp_netif_receive eating all my ram (SLIP protocol) (IDFGH-4141)

Postby fpena_inusual » Thu Oct 29, 2020 8:09 am

Hello again,

More info on the issue.

I've attached two log files, one contains the captured packets in wireshark and the other the output log from the esp32.
As you can see, the packet #25 is lost somewhere. For whatever reason it's received from the slip interface but it's not accepted on the ip4 layers, and my guess is that this packet is held in memory forever.

Code: Select all

slipif_input: alloc
slipif: Got packet (40 bytes) <-- Here comes the lost packet
slipif_input: alloc
slipif: Got packet (40 bytes) <-- This is the retransmitted packet
ip_input: iphdr->dest 0x2f0a8c0 netif->ip_addr 0x2f0a8c0 (0xf0a8c0, 0xf0a8c0, 0x2000000)
ip4_input: packet accepted on interface sl
ip4_input: 
IP header:
+-------------------------------+
| 4 | 5 |  0x00 |        40     | (v, hl, tos, len)
+-------------------------------+
|    19789      |010|       0   | (id, flags, offset)
+-------------------------------+
|   64  |    6  |    0x8c2d     | (ttl, proto, chksum)
+-------------------------------+
|  192  |  168  |  240  |    1  | (src)
+-------------------------------+
|  192  |  168  |  240  |    2  | (dest)
+-------------------------------+
ip4_input: p->len 40 p->tot_len 40
And it seems to happen on ever problematic packet.

I'll keep digging on it...
Attachments
wireshark_capture_2.txt
(49.3 KiB) Downloaded 16 times
console_capture_2.log
(21.24 KiB) Downloaded 15 times

fpena_inusual
Posts: 9
Joined: Tue Oct 20, 2020 8:58 am

Re: esp_netif_receive eating all my ram (SLIP protocol) (IDFGH-4141)

Postby fpena_inusual » Thu Oct 29, 2020 9:36 am

Ok, I think I've solved the isue :D

I traced back the problem to the slipif_proccess_rxqueue function in components/lwip/lwip/src/netif/slipif.c file of the esp-idf.
I actually didn't fix anything. I simply compared the function with the one used in the esp8266 SDK (that I used before as slip gateway) and made the same changes to it... and it worked flawlessly.

Here is the patch to this file:

Code: Select all

--- a/components/lwip/lwip/src/netif/slipif.c	2020-10-29 09:39:59.444559678 +0100
+++ b/components/lwip/lwip/src/netif/slipif.c	2020-10-29 10:18:44.963390416 +0100
@@ -461,12 +461,8 @@
     struct pbuf *p = priv->rxpackets;
 #if SLIP_RX_QUEUE
     /* dequeue packet */
-    struct pbuf *q = p;
-    while ((q->len != q->tot_len) && (q->next != NULL)) {
-      q = q->next;
-    }
-    priv->rxpackets = q->next;
-    q->next = NULL;
+    priv->rxpackets = p->next;
+    p->next = NULL;
 #else /* SLIP_RX_QUEUE */
     priv->rxpackets = NULL;
 #endif /* SLIP_RX_QUEUE */
@@ -497,7 +493,7 @@
     if (priv->rxpackets != NULL) {
 #if SLIP_RX_QUEUE
       /* queue multiple pbufs */
-      struct pbuf *q = p;
+      struct pbuf *q = priv->rxpackets;
       while (q->next != NULL) {
         q = q->next;
       }
P.S.: I've also attached the patch file to this post.
Attachments
slipif.patch.zip
(526 Bytes) Downloaded 15 times

Who is online

Users browsing this forum: Bing [Bot] and 35 guests