Skip to main content

BufferRef

Struct BufferRef 

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

Source

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

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

pub fn as_ptr(&self) -> *mut vlib_buffer_t

Returns the raw pointer to the underlying vlib_buffer_t

Source

pub fn current_length(&self) -> u16

Current length

Typically, this is the amount of packet data remaining from Self::current_ptr_mut.

Source

pub fn flags(&self) -> BufferFlags

Buffer flags

Source

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.

Source

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.

Source

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 l is positive, the buffer must have at least l bytes of data remaining.
  • If l is negative, the current data offset must be at least -l bytes from the start of the buffer’s data area (including pre-data).
Source

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.

Source

pub fn add_trace<N: Node>( &mut self, vm: &MainRef, node: &NodeRuntimeRef<N>, ) -> &mut MaybeUninit<N::TraceData>

Add trace data to this buffer

Source

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

pub fn total_length_not_including_first_buffer(&self) -> u32

Get the total length of the buffer chain not including the first buffer

Source

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.

Source

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.

Source

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.

Source

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.

Source

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>

Source

pub fn vnet_buffer(&self) -> &BufferRef

Source

pub fn vnet_buffer_mut(&mut self) -> &mut BufferRef

Source§

impl<FeatureData: Copy> BufferRef<FeatureData>

Source

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.

Auto Trait Implementations§

§

impl<FeatureData> Freeze for BufferRef<FeatureData>

§

impl<FeatureData> !RefUnwindSafe for BufferRef<FeatureData>

§

impl<FeatureData> !Send for BufferRef<FeatureData>

§

impl<FeatureData> !Sync for BufferRef<FeatureData>

§

impl<FeatureData> Unpin for BufferRef<FeatureData>
where FeatureData: Unpin,

§

impl<FeatureData> UnsafeUnpin for BufferRef<FeatureData>

§

impl<FeatureData> UnwindSafe for BufferRef<FeatureData>
where FeatureData: UnwindSafe,

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.