tasklwIP - A Lightweight TCP/IP stack - Tasks: task #11472, Support a PBUF_REF type for RX


You are not allowed to post comments on this tracker with your current authentication level.

task #11472: Support a PBUF_REF type for RX

Submitted by:  Simon Goldschmidt <goldsimon>
Submitted on:  Fri 21 Oct 2011 07:43:01 PM UTC  
Category:  None Should Start On:  Fri 21 Oct 2011 12:00:00 AM UTC
Should be Finished on:  Fri 21 Oct 2011 12:00:00 AM UTC Priority:  5 - Normal
Status:  Done Privacy:  Public
Percent Complete:  100% Assigned to:  Simon Goldschmidt <goldsimon>
Open/Closed:  Closed Planned Release:  1.5.0 beta1
Effort:  0.00

Mon 31 Aug 2015 06:29:47 AM UTC, comment #4: 

PBUF_REF with "custom" pbufs is now supported for RX pbufs (see pcapif in contrib for an example, LWIP_SUPPORT_CUSTOM_PBUF is required)

Simon Goldschmidt <goldsimon>
Project AdministratorIn charge of this item.
Mon 08 Dec 2014 02:30:02 PM UTC, comment #3: 

IPv4 reassembly works, so "only" IPv6 is remaining... (there are a couple of pbuf_header() calls with a positive offset that seem suspicious)

Simon Goldschmidt <goldsimon>
Project AdministratorIn charge of this item.
Mon 08 Dec 2014 02:03:46 PM UTC, comment #2: 

This should work for IPv4 now.

IPv6 and IP reassemly (IPv4 + IPv6) remains to be checked...

Simon Goldschmidt <goldsimon>
Project AdministratorIn charge of this item.
Fri 07 Feb 2014 12:46:48 PM UTC, comment #1: 

Some (unchecked) input on this from lwip-devel on 2013-05-10 (also see attached files):
"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.



(file #30478, file #30479)

Simon Goldschmidt <goldsimon>
Project AdministratorIn charge of this item.
Fri 21 Oct 2011 07:43:01 PM UTC, original submission:  

Currently, PBUF_REF is not fully supported for RX data, as pbuf_header() only works in one direction.

This could/should be extended to allow some kind of REF type for targets where the location of RX data is fixed (e.g. use an extended struct pbuf that includes the original size of the payload plus a 'freed' callback like for custom pbufs).

Simon Goldschmidt <goldsimon>
Project AdministratorIn charge of this item.


Attached Files
file #30478:  pbuf.h added by goldsimon (4KiB - application/octet-stream)
file #30479:  pbuf.c added by goldsimon (31KiB - application/octet-stream)


Depends on the following items: None found

Items that depend on this one: None found


Carbon-Copy List
  • -email is unavailable- added by goldsimon (Submitted the item)

    Do you think this task is very important?
    If so, you can add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.




    Follow 8 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2015-08-31 goldsimon StatusNone => Done
        Percent Complete50% => 100%
        Open/ClosedOpen => Closed
    2014-12-08 goldsimon Percent Complete0% => 50%
        Assigned toNone => goldsimon
        Planned ReleaseNone => 1.5.0 beta1
    2014-02-07 goldsimon Attached File- => Added pbuf.h, #30478
        Attached File- => Added pbuf.c, #30479

    Back to the top

    Powered by Savane 3.5