Skip to content

udp: limit buffer depth #6895

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 10, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions libraries/ESP8266WiFi/src/include/UdpContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ class UdpContext
// ref'ing it to prevent release from the below pbuf_free(deleteme)
pbuf_ref(_rx_buf);
}
// remove the already-consumed head of the chain
pbuf_free(deleteme);

_rx_buf_offset = 0;
Expand Down Expand Up @@ -440,6 +441,19 @@ class UdpContext
const ip_addr_t *srcaddr, u16_t srcport)
{
(void) upcb;
// check receive pbuf chain depth
{
pbuf* p;
int count = 0;
for (p = _rx_buf; p && ++count < rxBufMaxDepth*2; p = p->next);
if (p)
{
// pbuf chain too deep, dropping
pbuf_free(pb);
DEBUGV(":udr\r\n");
return;
}
}

#if LWIP_VERSION_MAJOR == 1
#define TEMPDSTADDR (&current_iphdr_dest)
Expand Down Expand Up @@ -531,6 +545,10 @@ class UdpContext
srcaddr(src), dstaddr(dst), srcport(srcport) { }
};
AddrHelper _currentAddr;

// rx pbuf depth barrier (counter of buffered UDP received packets)
// keep it small
static constexpr int rxBufMaxDepth = 4;
};


Expand Down