Skip to content

Commit f926625

Browse files
committed
ESP8266: Make copies of incoming packets if under buffer pressure
SDK maintains a pool of 5 buffers. If getting close to the limit, we start making copies to avoid pressure.
1 parent a4e5219 commit f926625

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

src/esp8266/sdk_lwip/src/netif/etharp.c

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1299,6 +1299,12 @@ etharp_request(struct netif *netif, ip_addr_t *ipaddr)
12991299
}
13001300
#endif /* LWIP_ARP */
13011301

1302+
struct wdevctl {
1303+
uint16_t num_free_bufs;
1304+
};
1305+
1306+
extern struct wdevctl wDevCtrl;
1307+
13021308
/**
13031309
* Process received ethernet frames. Using this function instead of directly
13041310
* calling ip_input and passing ARP frames through etharp in ethernetif_input,
@@ -1373,11 +1379,27 @@ ethernet_input(struct pbuf *p, struct netif *netif)
13731379
LWIP_ASSERT("Can't move over header in packet", 0);
13741380
goto free_and_return;
13751381
} else {
1382+
/*
1383+
* SDK maintains a pool of 5 buffers. The number of free + 1
1384+
* is the first field in the wDevCtrl struct. When it gets down to 1
1385+
* the SDK prints "LmacRxBlk:1" and drops incoming packets.
1386+
* If getting close to the limit, we start making copies to avoid pressure.
1387+
*/
1388+
if (wDevCtrl.num_free_bufs <= 3) {
1389+
struct pbuf *p2 = pbuf_alloc(PBUF_RAW, p->tot_len, PBUF_RAM);
1390+
if (p2 != NULL) {
1391+
pbuf_copy(p2, p);
1392+
pbuf_free(p);
1393+
p = p2;
1394+
} else {
1395+
goto free_and_return;
1396+
}
1397+
}
13761398
/* pass to IP layer */
13771399
ip_input(p, netif);
13781400
}
13791401
break;
1380-
1402+
13811403
case PP_HTONS(ETHTYPE_ARP):
13821404
if (!(netif->flags & NETIF_FLAG_ETHARP)) {
13831405
goto free_and_return;

0 commit comments

Comments
 (0)