Essential DPDK Packet Buffer Management APIs
Core Packet Buffer Operations
Allocating Packet Buffers
struct rte_mbuf *allocate_packet_buffer(struct rte_mempool *pool);
pool: Memory pool for buffer alocation
Example usage:
struct rte_mempool *buffer_pool;
struct rte_mbuf *packet = allocate_packet_buffer(buffer_pool);
if (!packet) {
printf("Buffer allocation failed\n");
return -1;
}
Releasing Packet Buffers
void release_packet_buffer(struct rte_mbuf *packet);
Buffer Cloning
struct rte_mbuf *clone_buffer(const struct rte_mbuf *original, struct rte_mempool *pool);
Advanced Buffer Manipulation
External Buffer Attachment
void attach_external_buffer(struct rte_mbuf *packet, void *data_ptr,
rte_iova_t phys_addr, uint16_t length);
Data Segment Management
struct rte_mbuf *prepend_data(struct rte_mbuf *packet, uint16_t length);
struct rte_mbuf *trim_data(struct rte_mbuf *packet, uint16_t length);
Buffer Information Queries
Packet Length Information
uint32_t get_total_packet_length(const struct rte_mbuf *packet);
uint16_t get_data_length(const struct rte_mbuf *packet);
Memory Layout Information
uint16_t get_headroom(const struct rte_mbuf *packet);
uint16_t get_tailroom(const struct rte_mbuf *packet);
Bulk Operations
Batch Allocation
unsigned int allocate_multiple_buffers(struct rte_mempool *pool,
struct rte_mbuf **buffers,
unsigned int count);
Batch Release
void release_multiple_buffers(struct rte_mbuf **buffers, unsigned int count);
Specialized Operations
Buffer Linearization
int make_buffer_contiguous(struct rte_mbuf *packet);
Physical Address Access
phys_addr_t get_physical_address(const struct rte_mbuf *packet);