Skip to main content

Mbuf

Struct Mbuf 

Source
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

Source

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)
Source

pub fn as_raw(&self) -> *mut rte_mbuf

Get the raw pointer to the underlying mbuf

Source

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

Source

pub fn data_offset(&self) -> u16

Get the data offset within the buffer

Source

pub fn packet_len(&self) -> u32

Get the total packet length

Source

pub fn data_len(&self) -> u16

Get the data length in this segment

Source

pub fn buf_len(&self) -> u16

Get the buffer length (total available space)

Source

pub fn data(&self) -> Option<&[u8]>

Get a slice to the packet data

Returns None if the buffer address is null

Source

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

Source

pub fn set_data_len(&mut self, len: u16)

Set the data length

Source

pub fn set_packet_len(&mut self, len: u32)

Set the packet length

Source

pub fn ol_flags(&self) -> u64

Get the ol_flags field (offload flags)

Source

pub fn set_ol_flags(&mut self, flags: u64)

Set the ol_flags field (offload flags)

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Drop for Mbuf

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Send for Mbuf

Auto Trait Implementations§

§

impl Freeze for Mbuf

§

impl RefUnwindSafe for Mbuf

§

impl !Sync for Mbuf

§

impl Unpin for Mbuf

§

impl UnsafeUnpin for Mbuf

§

impl UnwindSafe for Mbuf

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.