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
impl ZeroCopyPacket
Sourcepub const FLAG_NEEDS_CSUM: u16
pub const FLAG_NEEDS_CSUM: u16
Packet flag: needs checksum calculation.
Sourcepub const FLAG_FROM_GUEST: u16
pub const FLAG_FROM_GUEST: u16
Packet flag: from guest (TX direction).
Sourcepub const FLAG_TO_GUEST: u16
pub const FLAG_TO_GUEST: u16
Packet flag: to guest (RX direction).
Sourcepub const unsafe fn from_raw_parts(
data: *const u8,
len: u32,
desc_idx: u16,
) -> Self
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:
datapoints to valid memory for at leastlenbytes.- The memory remains valid for the lifetime of the packet.
- The memory is not modified while the packet is in use.
Sourcepub const unsafe fn from_slice(data: &[u8], desc_idx: u16) -> Self
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.
Sourcepub unsafe fn as_slice(&self) -> &[u8] ⓘ
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.
Sourcepub const fn metadata(&self) -> &PacketMetadata
pub const fn metadata(&self) -> &PacketMetadata
Returns a reference to the packet metadata.
Sourcepub fn metadata_mut(&mut self) -> &mut PacketMetadata
pub fn metadata_mut(&mut self) -> &mut PacketMetadata
Returns a mutable reference to the packet metadata.
Sourcepub fn set_metadata(&mut self, metadata: PacketMetadata)
pub fn set_metadata(&mut self, metadata: PacketMetadata)
Sets the packet metadata.
Sourcepub fn set_timestamp(&mut self, timestamp: u64)
pub fn set_timestamp(&mut self, timestamp: u64)
Sets the timestamp.
Sourcepub fn release(&self) -> bool
pub fn release(&self) -> bool
Decrements the reference count and returns true if it reached zero.
Sourcepub unsafe fn parse_headers(&mut self)
pub unsafe fn parse_headers(&mut self)
Sourcepub unsafe fn dst_ipv4(&self) -> Option<Ipv4Addr>
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.