Getting mbuf pointer from buf_addr pointer
Dmitry Kozlyuk
dmitry.kozliuk at gmail.com
Tue Jul 12 13:22:09 CEST 2022
2022-07-12 12:30 (UTC+0200), Antonio Di Bacco:
> I was asked to reproduce the exact same behaviour of a library that
> used VMDQ queues without DPDK.
> Now this library offered an API to allocate a buffer for a packet and
> returned an address where the application could write its data.
>
> void* vmdqNew (vmdqUidPOOLt* p);
>
> I implemented the same API to allocate an MBUF from a pool and I also
> return the right address as a void* but then to transmit the packet I
> need the address of the MBUF for the tx_burst API and I don't have it.
Since you create mbufs and send them, the approach I mentioned is viable.
See rte_mbuf_buf_addr() and do the reverse to calculate the pointer to mbuf.
There is no API because it cannot work for any mbuf, but you case is limited
(there are chained mbufs, externally-attached mbufs, etc).
BTW, in general you could save a back-reference to the mbuf
just before the buffer you return from vmdqNew(), in pktmbuf private data.
But direct calculation is more efficient.
More information about the users
mailing list