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, 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 unsafe fn advance(&mut self, l: i16)
pub unsafe fn advance(&mut self, l: i16)
Advance the current data pointer by l bytes
§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.
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.