+TCP buffers exhausted after a while (ENC28J60)

Very good that you found this, great. This subject is a bit complicated. Because of the zero-copy method, packets are translated to payload buffers, and back to network packets. This was a simple conversion, but since IPv6 the IP-headers have a variable length.

You are not the only developer who wants to use the space before pucEthernetBuffer for your own driver, and that is surely possible.

However, please increase the size of ipconfigBUFFER_PADDING from 10 to 14 or more, because the IPv6 library already uses the other bytes.

Here is a layout of the bytes before pucEthernetBuffer[0] :

pucEthernetBuffer -14  : for your your driver, or more if you want to
pucEthernetBuffer -10  : a pointer to the containing `NetworkBufferDescriptor_t`
                         On a 64-bit platform, the pointer will be 8-bytes long.
pucEthernetBuffer  -6  : For IPv6 : store the frame type
pucEthernetBuffer  -2  : ipconfigPACKET_FILLER_SIZE ( 2 )
                         I think it is OK to use the bytes at -1 and -2 for your driver.

From here the normal packet data:

pucEthernetBuffer  0   : MACAddress_t xDestinationAddress;
pucEthernetBuffer  6   : MACAddress_t xSourceAddress;
pucEthernetBuffer  10  : uint16_t usFrameType;

From here on, the fields are 4-byte aligned:

pucEthernetBuffer  12  : uint8_t ucVersionHeaderLength;

See also this comment in FreeRTOS_IP.c :

/* For an IPv4 packet, pucIPType points to 6 bytes before the pucEthernetBuffer,
 * for a IPv6 packet, pucIPType will point to the first byte of the IP-header:
 * 'ucVersionTrafficClass'. */

I hope this all works for you! When I’m not clear, please ask more.