Skip to main content

ZeroCopyPacket

Struct ZeroCopyPacket 

Source
pub struct ZeroCopyPacket { /* private fields */ }
Expand description

Zero-copy packet referencing shared memory directly.

This structure holds a pointer to packet data in guest memory without copying the actual data. The reference count enables safe deferred release after processing.

§Safety

The data pointer must remain valid for the lifetime of this packet. The caller is responsible for ensuring the underlying memory is not deallocated or modified while the packet is in use.

§Cache Line Alignment

The structure is aligned to 64 bytes to prevent false sharing when packets are processed in parallel.

Implementations§

Source§

impl ZeroCopyPacket

Source

pub const FLAG_NEEDS_CSUM: u16

Packet flag: needs checksum calculation.

Source

pub const FLAG_GSO: u16

Packet flag: is a GSO packet.

Source

pub const FLAG_FROM_GUEST: u16

Packet flag: from guest (TX direction).

Source

pub const FLAG_TO_GUEST: u16

Packet flag: to guest (RX direction).

Source

pub const fn empty() -> Self

Creates an empty packet.

Source

pub const unsafe fn from_raw_parts( data: *const u8, len: u32, desc_idx: u16, ) -> Self

Creates a new zero-copy packet from raw parts.

§Safety

The caller must ensure that:

  • data points to valid memory for at least len bytes.
  • The memory remains valid for the lifetime of the packet.
  • The memory is not modified while the packet is in use.
Source

pub const unsafe fn from_slice(data: &[u8], desc_idx: u16) -> Self

Creates a packet from a slice (for testing/non-zero-copy paths).

§Safety

The slice must remain valid for the lifetime of the packet.

Source

pub const fn is_empty(&self) -> bool

Returns true if this packet is empty.

Source

pub const fn len(&self) -> usize

Returns the packet data length.

Source

pub unsafe fn as_slice(&self) -> &[u8]

Returns the packet data as a slice.

§Safety

The caller must ensure the underlying memory is still valid.

Source

pub const fn data_ptr(&self) -> *const u8

Returns the raw data pointer.

Source

pub const fn desc_idx(&self) -> u16

Returns the descriptor index.

Source

pub const fn metadata(&self) -> &PacketMetadata

Returns a reference to the packet metadata.

Source

pub fn metadata_mut(&mut self) -> &mut PacketMetadata

Returns a mutable reference to the packet metadata.

Source

pub fn set_metadata(&mut self, metadata: PacketMetadata)

Sets the packet metadata.

Source

pub const fn flags(&self) -> u16

Returns the packet flags.

Source

pub fn set_flags(&mut self, flags: u16)

Sets packet flags.

Source

pub fn add_flag(&mut self, flag: u16)

Adds a flag.

Source

pub const fn has_flag(&self, flag: u16) -> bool

Checks if a flag is set.

Source

pub const fn timestamp(&self) -> u64

Returns the timestamp.

Source

pub fn set_timestamp(&mut self, timestamp: u64)

Sets the timestamp.

Source

pub fn add_ref(&self)

Increments the reference count.

Source

pub fn release(&self) -> bool

Decrements the reference count and returns true if it reached zero.

Source

pub fn refcount(&self) -> u32

Returns the current reference count.

Source

pub unsafe fn parse_headers(&mut self)

Parses packet headers and populates metadata.

§Safety

The packet data must be valid and accessible.

Source

pub unsafe fn src_ipv4(&self) -> Option<Ipv4Addr>

Returns the source IPv4 address, if this is an IPv4 packet.

§Safety

The packet data must be valid.

Source

pub unsafe fn dst_ipv4(&self) -> Option<Ipv4Addr>

Returns the destination IPv4 address, if this is an IPv4 packet.

§Safety

The packet data must be valid.

Source

pub unsafe fn src_ipv6(&self) -> Option<Ipv6Addr>

Returns the source IPv6 address, if this is an IPv6 packet.

§Safety

The packet data must be valid.

Source

pub unsafe fn dst_ipv6(&self) -> Option<Ipv6Addr>

Returns the destination IPv6 address, if this is an IPv6 packet.

§Safety

The packet data must be valid.

Trait Implementations§

Source§

impl Debug for ZeroCopyPacket

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ZeroCopyPacket

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Send for ZeroCopyPacket

Source§

impl Sync for ZeroCopyPacket

Auto Trait Implementations§

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.