lwip-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lwip-devel] pbuf_header for PBUF_REF/ROM in lwip-1.3.1


From: rh_maillist
Subject: [lwip-devel] pbuf_header for PBUF_REF/ROM in lwip-1.3.1
Date: Fri, 10 May 2013 10:21:18 +0100

We' just moving our comms protocol to run over UDP from RS232 using STM32F1 and 
F2 chips.  The current ST ethernetif_input port allocates a PBUF_POOL and 
memcpy's the data from the DMA buffer in to it before passing it on to 
netif->input to process.

We've got quite a bit of RAM and not much traffic and are looking to get away 
from the memcpy.  I've changed this to allocate a PBUF_REF and then set the 
payload to point to the DMA buffer directly to save copying as the processing 
of these packets is very quick.

This works for UDP traffic but fails for ICMP (echo requests).  The reason is 
that LWIP does a couple of pbuf_header calls with -ve values while processing 
the header but when ICMP wants to send the reply (in icml.c line 143), it 
readjusts the header backwards using pbuf_header with a positive value.

This doesn't work for PBUF_REF/ROM types as it can't safely check for 
underflow.  The underflow for PBUF_RAM/POOL is checked for by comparing the new 
payload pointer to the pbuf pointer + sizeof(pbuf) which can't be done as they 
aren't allocated in a single block.

One solution is to LWIP_ICMP_ECHO_CHECK_INPUT_PBUF_LEN but this looks like it 
has a bug in it in lwip-1.3.1 as it doesn't adjust the payload pointer if it's 
not defined and it needs adjusting.  Do I understand this correctly and if so, 
has it been fixed in a later version?

A solution we've implemented here to add an extra member to pbuf which is 
original_payload.  When pbufs are allocated from POOL/RAM then this is set to 
payload - offset in pbuf_alloc.  For code using REF/ROM pbufs, they set the 
original_payload to payload when setting up the pbuf.  Then in pbuf_header, we 
just check payload >= original_payload when adjusting backwards to check for 
underflow.

I'm new to LWIP so just wondered what people thought of this as a solution.  
I've attached the new pbuf.c and .h for reference.  #define 
PBUF_HEADER_ADJUST_ALL for the new behaviour.

Cheers

Russell

Attachment: pbuf.h
Description: Binary data

Attachment: pbuf.c
Description: Binary data



reply via email to

[Prev in Thread] Current Thread [Next in Thread]