From de0b97861a3f24b6291b5cc9e9640ca79f5bedf1 Mon Sep 17 00:00:00 2001 From: Thomas Kindler Date: Fri, 28 May 2021 10:34:21 +0200 Subject: [PATCH] Fix bug #60681: Initialize custom data in pbuf struct Add a #define that users can use to initialize LWIP_PBUF_CUSTOM_DATA fields. see patch #10072 idea by Thomas Kindler --- src/core/pbuf.c | 2 ++ src/include/lwip/opt.h | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/src/core/pbuf.c b/src/core/pbuf.c index 9c7c9ba9..ad3995b1 100644 --- a/src/core/pbuf.c +++ b/src/core/pbuf.c @@ -186,6 +186,8 @@ pbuf_init_alloced_pbuf(struct pbuf *p, void *payload, u16_t tot_len, u16_t len, p->flags = flags; p->ref = 1; p->if_idx = NETIF_NO_INDEX; + + LWIP_PBUF_CUSTOM_DATA_INIT(p); } /** diff --git a/src/include/lwip/opt.h b/src/include/lwip/opt.h index 27958405..2573285f 100644 --- a/src/include/lwip/opt.h +++ b/src/include/lwip/opt.h @@ -1628,10 +1628,22 @@ /** * LWIP_PBUF_CUSTOM_DATA: Store private data on pbufs (e.g. timestamps) * This extends struct pbuf so user can store custom data on every pbuf. + * e.g.: + * \#define LWIP_PBUF_CUSTOM_DATA u32_t myref; */ #if !defined LWIP_PBUF_CUSTOM_DATA || defined __DOXYGEN__ #define LWIP_PBUF_CUSTOM_DATA #endif + +/** + * LWIP_PBUF_CUSTOM_DATA_INIT: Initialize private data on pbufs. + * e.g. for the above example definition: + * \#define LWIP_PBUF_CUSTOM_DATA(p) (p)->myref = 0 + */ +#if !defined LWIP_PBUF_CUSTOM_DATA_INIT || defined __DOXYGEN__ +#define LWIP_PBUF_CUSTOM_DATA_INIT(p) +#endif + /** * @} */