pub struct BufferRef<FeatureData>(/* private fields */);Expand description
Reference to a VPP buffer
A &mut BufferRef<FeatureData> is equivalent to a vlib_buffer_t * in C (a *mut vlib_buffer_t in Rust).
Implementations§
Source§impl<FeatureData> BufferRef<FeatureData>
impl<FeatureData> BufferRef<FeatureData>
Sourcepub unsafe fn from_ptr<'a>(ptr: *mut vlib_buffer_t) -> &'a Self
pub unsafe fn from_ptr<'a>(ptr: *mut vlib_buffer_t) -> &'a Self
Create a &BufferRef from a raw pointer
§Safety
- The pointer must be a valid and properly initialised
vlib_buffer_t. - The pointer must stay valid and the contents must not be mutated for the duration of the lifetime of the returned object.
Sourcepub unsafe fn from_ptr_mut<'a>(ptr: *mut vlib_buffer_t) -> &'a mut Self
pub unsafe fn from_ptr_mut<'a>(ptr: *mut vlib_buffer_t) -> &'a mut Self
Create a &mut BufferRef from a raw pointer
§Safety
- The pointer must be a valid and properly initialised
vlib_buffer_t. - The pointer must stay valid and the contents must not be mutated for the duration of the lifetime of the returned object.
Sourcepub fn as_ptr(&self) -> *mut vlib_buffer_t
pub fn as_ptr(&self) -> *mut vlib_buffer_t
Returns the raw pointer to the underlying vlib_buffer_t
Sourcepub fn current_length(&self) -> u16
pub fn current_length(&self) -> u16
Current length
Typically, this is the amount of packet data remaining from Self::current_ptr_mut.
Sourcepub fn flags(&self) -> BufferFlags
pub fn flags(&self) -> BufferFlags
Buffer flags
Sourcepub fn current_ptr_mut(&mut self) -> *mut u8
pub fn current_ptr_mut(&mut self) -> *mut u8
Get a pointer to the current data
This corresponds to the VPP C API vlib_buffer_get_current.
§Usage guidance
Note that the pointer returned may point to uninitialised data depending on the context. In addition, depending on the context, the remaining data the amount is expected. Finally, if remaining data is sufficent and it’s initialised it may not have been validated so care must be taken in determining whether or not lengths in the headers can be trusted.
Sourcepub fn has_space(&self, l: i16) -> bool
pub fn has_space(&self, l: i16) -> bool
Check if the buffer has space for l more bytes
This corresponds to the VPP C API vlib_buffer_has_space.
Sourcepub unsafe fn advance(&mut self, l: i16)
pub unsafe fn advance(&mut self, l: i16)
Advance the current data pointer by l bytes
This corresponds to the VPP C API vlib_buffer_advance.
§Safety
- If
lis positive, the buffer must have at leastlbytes of data remaining. - If
lis negative, the current data offset must be at least-lbytes from the start of the buffer’s data area (including pre-data).
Sourcepub fn tail_mut(&mut self) -> *mut u8
pub fn tail_mut(&mut self) -> *mut u8
Get a pointer to the end of the current data
This corresponds to the VPP C function vlib_buffer_get_tail.
Sourcepub fn add_trace<N: Node>(
&mut self,
vm: &MainRef,
node: &NodeRuntimeRef<N>,
) -> &mut MaybeUninit<N::TraceData>
pub fn add_trace<N: Node>( &mut self, vm: &MainRef, node: &NodeRuntimeRef<N>, ) -> &mut MaybeUninit<N::TraceData>
Add trace data to this buffer
Sourcepub fn set_error<N: Node>(&mut self, node: &NodeRuntimeRef<N>, error: N::Errors)
pub fn set_error<N: Node>(&mut self, node: &NodeRuntimeRef<N>, error: N::Errors)
Set an error reason
This is typically done before sending the packet to the drop node, where it use the
value to display the reason in traces and automatically increment the per-node, per-error
counter for the error.
Sourcepub fn total_length_not_including_first_buffer(&self) -> u32
pub fn total_length_not_including_first_buffer(&self) -> u32
Get the total length of the buffer chain not including the first buffer
Sourcepub fn length_in_chain(&self, vm: &MainRef) -> u64
pub fn length_in_chain(&self, vm: &MainRef) -> u64
Get the total length of the buffer chain from the current offset
Note that this doesn’t take into account any bytes that have been Self::advance()d
over.
Sourcepub fn prefetch_header_load(&self)
pub fn prefetch_header_load(&self)
Hint to the CPU to prefetch the buffer header for read access.
This is a performance hint that attempts to bring the buffer header into the CPU cache prior to reading fields from it. It does not affect program semantics and may be a no-op on some platforms. Use this when you will shortly read header fields and want to reduce cache miss latency.
Sourcepub fn prefetch_header_store(&self)
pub fn prefetch_header_store(&self)
Hint to the CPU to prefetch the buffer header for write access.
Similar to prefetch_header_load but indicates imminent writes to the header. This is a
performance optimization only and does not change observable behaviour other than timing.
Sourcepub fn prefetch_data_load(&self)
pub fn prefetch_data_load(&self)
Hint to the CPU to prefetch the buffer data area for read access.
This brings the buffer’s data into cache in preparation for reading the packet payload. It is a non-semantic performance hint and may be ignored on some architectures. Use this when you will shortly read packet data and want to reduce cache miss latency.
Sourcepub fn prefetch_data_store(&self)
pub fn prefetch_data_store(&self)
Hint to the CPU to prefetch the buffer data area for write access.
Similar to prefetch_data_load but indicates the caller will write into the data area.
This is a cache-warming hint to reduce latency on subsequent stores.
Source§impl<FeatureData> BufferRef<FeatureData>
impl<FeatureData> BufferRef<FeatureData>
pub fn vnet_buffer(&self) -> &BufferRef
pub fn vnet_buffer_mut(&mut self) -> &mut BufferRef
Source§impl<FeatureData: Copy> BufferRef<FeatureData>
impl<FeatureData: Copy> BufferRef<FeatureData>
Sourcepub unsafe fn vnet_feature_next(&mut self) -> (u32, FeatureData)
pub unsafe fn vnet_feature_next(&mut self) -> (u32, FeatureData)
Get the next feature node and feature data for this buffer
Used when continuing to the next feature node in a node invoked from a feature arc.
§Safety
Must only be used from nodes when invoked from a feature arc.