1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-04-22 21:23:07 +03:00

udp remote pbuf helper: honor fragmented packets (#6222)

fix for #5960 didn't take fragmented packets into account
fixes #6218
This commit is contained in:
david gauchard 2019-06-26 21:35:43 +02:00 committed by GitHub
parent 961b558a91
commit 5306976db1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -34,6 +34,7 @@ void esp_schedule();
#define PBUF_ALIGNER_ADJUST 4 #define PBUF_ALIGNER_ADJUST 4
#define PBUF_ALIGNER(x) ((void*)((((intptr_t)(x))+3)&~3)) #define PBUF_ALIGNER(x) ((void*)((((intptr_t)(x))+3)&~3))
#define PBUF_HELPER_FLAG 0xff // lwIP pbuf flag: u8_t
class UdpContext class UdpContext
{ {
@ -243,21 +244,24 @@ public:
if (_rx_buf) if (_rx_buf)
{ {
// we have interleaved informations on addresses within reception pbuf chain: if (_rx_buf->flags == PBUF_HELPER_FLAG)
// before: (data-pbuf) -> (data-pbuf) -> (data-pbuf) -> ... in the receiving order {
// now: (address-info-pbuf -> data-pbuf) -> (address-info-pbuf -> data-pbuf) -> ... // we have interleaved informations on addresses within reception pbuf chain:
// before: (data-pbuf) -> (data-pbuf) -> (data-pbuf) -> ... in the receiving order
// now: (address-info-pbuf -> data-pbuf) -> (address-info-pbuf -> data-pbuf) -> ...
// so the first rx_buf contains an address helper, // so the first rx_buf contains an address helper,
// copy it to "current address" // copy it to "current address"
auto helper = (AddrHelper*)PBUF_ALIGNER(_rx_buf->payload); auto helper = (AddrHelper*)PBUF_ALIGNER(_rx_buf->payload);
_currentAddr = *helper; _currentAddr = *helper;
// destroy the helper in the about-to-be-released pbuf // destroy the helper in the about-to-be-released pbuf
helper->~AddrHelper(); helper->~AddrHelper();
// forward in rx_buf list, next one is effective data // forward in rx_buf list, next one is effective data
// current (not ref'ed) one will be pbuf_free'd with deleteme // current (not ref'ed) one will be pbuf_free'd with deleteme
_rx_buf = _rx_buf->next; _rx_buf = _rx_buf->next;
}
// this rx_buf is not nullptr by construction, // this rx_buf is not nullptr by construction,
// ref'ing it to prevent release from the below pbuf_free(deleteme) // ref'ing it to prevent release from the below pbuf_free(deleteme)
@ -471,6 +475,7 @@ private:
} }
// construct in place // construct in place
new(PBUF_ALIGNER(pb_helper->payload)) AddrHelper(srcaddr, TEMPDSTADDR, srcport); new(PBUF_ALIGNER(pb_helper->payload)) AddrHelper(srcaddr, TEMPDSTADDR, srcport);
pb->flags = PBUF_HELPER_FLAG; // mark helper pbuf
// chain it // chain it
pbuf_cat(_rx_buf, pb_helper); pbuf_cat(_rx_buf, pb_helper);