⚠️ VeridianOS Kernel Documentation - This is low-level kernel code. All functions are unsafe unless explicitly marked otherwise. no_std

WireGuardInterface

Struct WireGuardInterface 

Source
pub struct WireGuardInterface {
    pub name: [u8; 16],
    pub static_key: X25519KeyPair,
    pub listen_port: u16,
    pub tunnel_address: Option<IpAddress>,
    pub tunnel_prefix: u8,
    pub peers: BTreeMap<u64, WireGuardPeer>,
    pub mtu: u16,
    pub is_up: bool,
    pub packets_in: u64,
    pub packets_out: u64,
    /* private fields */
}
Expand description

WireGuard virtual network interface (wg0)

Fields§

§name: [u8; 16]

Interface name

§static_key: X25519KeyPair

Local static key pair

§listen_port: u16

Listening UDP port

§tunnel_address: Option<IpAddress>

Tunnel IP address

§tunnel_prefix: u8

Tunnel subnet prefix length

§peers: BTreeMap<u64, WireGuardPeer>

Peer table: hash of public key -> peer

§mtu: u16

Interface MTU

§is_up: bool

Whether the interface is up

§packets_in: u64

Packet counter for statistics

§packets_out: u64

Implementations§

Source§

impl WireGuardInterface

Source

pub fn new(name: &[u8], static_key: X25519KeyPair, listen_port: u16) -> Self

Create a new WireGuard interface

Source

pub fn set_address(&mut self, addr: IpAddress, prefix: u8)

Set tunnel IP address

Source

pub fn calculate_mtu(outer_mtu: u16, is_ipv6: bool) -> u16

Calculate effective MTU based on outer transport.

  • IPv4 outer: outer_mtu - 20 (IP) - 8 (UDP) - 32 (WG overhead) = outer_mtu - 60
  • IPv6 outer: outer_mtu - 40 (IP) - 8 (UDP) - 32 (WG overhead) = outer_mtu - 80
Source

pub fn add_peer(&mut self, peer: WireGuardPeer) -> Result<(), WireGuardError>

Add a peer

Source

pub fn remove_peer( &mut self, public_key: &[u8; 32], ) -> Result<(), WireGuardError>

Remove a peer by public key

Source

pub fn get_peer(&self, public_key: &[u8; 32]) -> Option<&WireGuardPeer>

Look up a peer by public key

Source

pub fn get_peer_mut( &mut self, public_key: &[u8; 32], ) -> Option<&mut WireGuardPeer>

Look up a peer mutably by public key

Source

pub fn find_peer_for_ip(&self, dst: &Ipv4Address) -> Option<&WireGuardPeer>

Find a peer that handles a given destination IP

Source

pub fn up(&mut self) -> Result<(), WireGuardError>

Bring the interface up

Source

pub fn down(&mut self)

Bring the interface down

Source

pub fn alloc_sender_index(&mut self) -> u32

Allocate a new sender index

Source

pub fn peer_count(&self) -> usize

Get peer count

Auto Trait Implementations§

§

impl Freeze for WireGuardInterface

§

impl RefUnwindSafe for WireGuardInterface

§

impl Send for WireGuardInterface

§

impl Sync for WireGuardInterface

§

impl Unpin for WireGuardInterface

§

impl UnwindSafe for WireGuardInterface

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.