pub struct Mbuf { /* private fields */ }Expand description
A memory buffer for packet data
Mbufs are the basic unit for carrying packet data in DPDK. They are allocated from memory pools and contain both metadata and actual packet data.
Implementations§
Source§impl Mbuf
impl Mbuf
Sourcepub unsafe fn from_raw(ptr: *mut rte_mbuf) -> Option<Self>
pub unsafe fn from_raw(ptr: *mut rte_mbuf) -> Option<Self>
Create a new Mbuf from a raw pointer
§Safety
The caller must ensure:
- The pointer is valid and properly aligned
- The mbuf was allocated from a valid mempool
- Ownership is being transferred (the raw pointer should not be freed elsewhere)
Sourcepub fn into_raw(self) -> *mut rte_mbuf
pub fn into_raw(self) -> *mut rte_mbuf
Consume self and return the raw pointer
After calling this, the caller is responsible for freeing the mbuf
Sourcepub fn data_offset(&self) -> u16
pub fn data_offset(&self) -> u16
Get the data offset within the buffer
Sourcepub fn packet_len(&self) -> u32
pub fn packet_len(&self) -> u32
Get the total packet length
Sourcepub fn data(&self) -> Option<&[u8]>
pub fn data(&self) -> Option<&[u8]>
Get a slice to the packet data
Returns None if the buffer address is null
Sourcepub fn data_mut(&mut self) -> Option<&mut [u8]>
pub fn data_mut(&mut self) -> Option<&mut [u8]>
Get a mutable slice to the packet data
Returns None if the buffer address is null
Sourcepub fn set_data_len(&mut self, len: u16)
pub fn set_data_len(&mut self, len: u16)
Set the data length
Sourcepub fn set_packet_len(&mut self, len: u32)
pub fn set_packet_len(&mut self, len: u32)
Set the packet length
Sourcepub fn set_ol_flags(&mut self, flags: u64)
pub fn set_ol_flags(&mut self, flags: u64)
Set the ol_flags field (offload flags)
Sourcepub fn vlan_tci(&self) -> u16
pub fn vlan_tci(&self) -> u16
Get the VLAN Tag Control Information (TCI) field.
On RX, the NIC populates this when RTE_MBUF_F_RX_VLAN_STRIPPED is set
in ol_flags. On TX, the application sets this and the NIC inserts the
VLAN tag when RTE_MBUF_F_TX_VLAN is set.
Sourcepub fn set_vlan_tci(&mut self, tci: u16)
pub fn set_vlan_tci(&mut self, tci: u16)
Set the VLAN TCI field for hardware VLAN insertion on TX.
Must be combined with set_ol_flags(RTE_MBUF_F_TX_VLAN) for the NIC
to actually insert the VLAN tag.
Sourcepub fn set_tx_offload(&mut self, l2_len: u8, l3_len: u16, l4_len: u8)
pub fn set_tx_offload(&mut self, l2_len: u8, l3_len: u16, l4_len: u8)
Set TX offload lengths (l2_len, l3_len, l4_len) in the tx_offload bitfield.
DPDK encodes these as: l2_len (bits 0-6, 7 bits), l3_len (bits 7-15, 9 bits), l4_len (bits 16-23, 8 bits).
Uses a C shim wrapper because tx_offload lives inside an anonymous union
in the real DPDK rte_mbuf struct, which bindgen represents as
__bindgen_anon_N.tx_offload rather than a direct field.