Skip to main content

L2tpBuilder

Struct L2tpBuilder 

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

Builder for L2TPv2 packets.

The builder encodes the header flags and optional fields according to RFC 2661. Fields:

  • T bit (message type): cleared for data, set for control
  • L bit: when set a 2-byte Length field appears after the flags word
  • S bit: when set Ns and Nr (2 bytes each) appear after Session ID
  • O bit: when set Offset Size + Offset Pad appear after Nr (or Session ID)
  • Ver nibble: always 2 for L2TPv2

Implementations§

Source§

impl L2tpBuilder

Source

pub fn new() -> Self

Create a new L2TP data message builder with minimal defaults. Produces a 6-byte header: \x00\x02\x00\x00\x00\x00 (ver=2, tid=0, sid=0).

Source

pub fn control(self) -> Self

Set the T bit — makes this a control message.

Source

pub fn data(self) -> Self

Set the T bit to 0 — data message (default).

Source

pub fn with_length(self) -> Self

Set the L (length) bit so a Length field will be included in the header.

Source

pub fn with_sequence(self) -> Self

Set the S (sequence) bit so Ns and Nr will be included.

Source

pub fn with_offset(self) -> Self

Set the O (offset) bit so Offset Size + Offset Pad will be included.

Source

pub fn priority(self) -> Self

Set the P (priority) bit for data messages.

Source

pub fn tunnel_id(self, id: u16) -> Self

Set the Tunnel ID.

Source

pub fn session_id(self, id: u16) -> Self

Set the Session ID.

Source

pub fn ns(self, ns: u16) -> Self

Set the Ns (send sequence number) field. Automatically enables the S bit.

Source

pub fn nr(self, nr: u16) -> Self

Set the Nr (receive sequence number) field. Automatically enables the S bit.

Source

pub fn offset_size(self, size: u16) -> Self

Set the Offset Size field. Automatically enables the O bit.

Source

pub fn payload<T: Into<Vec<u8>>>(self, data: T) -> Self

Set the payload (data after the L2TP header).

Source

pub fn control_length() -> Self

Create a control message with the Length bit set (matching Scapy’s L2TP(hdr="control+length") default).

Source

pub fn header_size(&self) -> usize

Compute the header length in bytes.

Source

pub fn packet_size(&self) -> usize

Compute the total packet size (header + payload).

Source

pub fn build(&self) -> Vec<u8>

Serialize the L2TP header (and payload if any) into bytes.

Source

pub fn build_into(&self, buf: &mut Vec<u8>)

Serialize into an existing buffer (must be at least packet_size() bytes).

Trait Implementations§

Source§

impl Clone for L2tpBuilder

Source§

fn clone(&self) -> L2tpBuilder

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for L2tpBuilder

Source§

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

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

impl Default for L2tpBuilder

Source§

fn default() -> L2tpBuilder

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

impl IntoLayerStackEntry for L2tpBuilder

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V