From 5306976db126f2855b25c88d240804a5dc4bed1f Mon Sep 17 00:00:00 2001 From: david gauchard Date: Wed, 26 Jun 2019 21:35:43 +0200 Subject: [PATCH] udp remote pbuf helper: honor fragmented packets (#6222) fix for #5960 didn't take fragmented packets into account fixes #6218 --- .../ESP8266WiFi/src/include/UdpContext.h | 29 +++++++++++-------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/libraries/ESP8266WiFi/src/include/UdpContext.h b/libraries/ESP8266WiFi/src/include/UdpContext.h index 8198ccea6..540217d2f 100644 --- a/libraries/ESP8266WiFi/src/include/UdpContext.h +++ b/libraries/ESP8266WiFi/src/include/UdpContext.h @@ -34,6 +34,7 @@ void esp_schedule(); #define PBUF_ALIGNER_ADJUST 4 #define PBUF_ALIGNER(x) ((void*)((((intptr_t)(x))+3)&~3)) +#define PBUF_HELPER_FLAG 0xff // lwIP pbuf flag: u8_t class UdpContext { @@ -243,21 +244,24 @@ public: if (_rx_buf) { - // 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) -> ... + if (_rx_buf->flags == PBUF_HELPER_FLAG) + { + // 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, - // copy it to "current address" - auto helper = (AddrHelper*)PBUF_ALIGNER(_rx_buf->payload); - _currentAddr = *helper; + // so the first rx_buf contains an address helper, + // copy it to "current address" + auto helper = (AddrHelper*)PBUF_ALIGNER(_rx_buf->payload); + _currentAddr = *helper; - // destroy the helper in the about-to-be-released pbuf - helper->~AddrHelper(); + // destroy the helper in the about-to-be-released pbuf + helper->~AddrHelper(); - // forward in rx_buf list, next one is effective data - // current (not ref'ed) one will be pbuf_free'd with deleteme - _rx_buf = _rx_buf->next; + // forward in rx_buf list, next one is effective data + // current (not ref'ed) one will be pbuf_free'd with deleteme + _rx_buf = _rx_buf->next; + } // this rx_buf is not nullptr by construction, // ref'ing it to prevent release from the below pbuf_free(deleteme) @@ -471,6 +475,7 @@ private: } // construct in place new(PBUF_ALIGNER(pb_helper->payload)) AddrHelper(srcaddr, TEMPDSTADDR, srcport); + pb->flags = PBUF_HELPER_FLAG; // mark helper pbuf // chain it pbuf_cat(_rx_buf, pb_helper);