InterfaceBuilder

Struct InterfaceBuilder 

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

Builder for Interface.

Implementations§

Source§

impl InterfaceBuilder

Source

pub fn address<VALUE: Into<Vec<IpNet>>>(&mut self, value: VALUE) -> &mut Self

Interface’s address.

/32 and /128 IP networks will be generated as regular ips (f.e. 1.2.3.4/32 -> 1.2.3.4)

You can also use InterfaceBuilder::add_network() to add a single network and InterfaceBuilder::add_address() to add a single address.

Wireguard docs

Source

pub fn listen_port(&mut self, value: u16) -> &mut Self

Port to listen for incoming VPN connections.

Wireguard conf

Source

pub fn private_key(&mut self, value: PrivateKey) -> &mut Self

Node’s private key.

Wireguard conf

Source

pub fn dns<VALUE: Into<Vec<String>>>(&mut self, value: VALUE) -> &mut Self

The DNS servers to announce to VPN clients via DHCP.

Wireguard docs

Source

pub fn endpoint<VALUE: Into<String>>(&mut self, value: VALUE) -> &mut Self

Endpoint.

  • [Interface] section will have # Name = <endpoint> comment at the top.
  • Exported Peer (via Interface::to_peer) will have this endpoint.

Wireguard Docs for # Name; Wireguard Docs for endpoint

Source

pub fn table(&mut self, value: Table) -> &mut Self

Routing table to use for the WireGuard routes.

See Table for special values.

Wireguard docs

Source

pub fn mtu(&mut self, value: usize) -> &mut Self

Maximum Transmission Unit (MTU, aka packet/frame size) to use when connecting to the peer.

Wireguard docs

Source

pub fn amnezia_settings(&mut self, value: AmneziaSettings) -> &mut Self

Available on crate feature amneziawg only.

AmneziaWG obfuscation values.

AmneziaWG Docs

Source

pub fn pre_up<VALUE: Into<Vec<String>>>(&mut self, value: VALUE) -> &mut Self

Commands, that will be executed before the interface is brought up

Wireguard docs

Source

pub fn pre_down<VALUE: Into<Vec<String>>>(&mut self, value: VALUE) -> &mut Self

Commands, that will be executed before the interface is brought down

Wireguard docs

Source

pub fn post_up<VALUE: Into<Vec<String>>>(&mut self, value: VALUE) -> &mut Self

Commands, that will be executed after the interface is brought up

Wireguard docs

Source

pub fn post_down<VALUE: Into<Vec<String>>>(&mut self, value: VALUE) -> &mut Self

Commands, that will be executed after the interface is brought down

Wireguard docs

Source

pub fn peers<VALUE: Into<Vec<Peer>>>(&mut self, value: VALUE) -> &mut Self

Peers.

Create them using PeerBuilder or Interface::to_peer method.

Wireguard docs

Source§

impl InterfaceBuilder

Source

pub fn new() -> Self

Create new InterfaceBuilder.

let interface = InterfaceBuilder::new()
    .address([as_ipnet!("10.0.0.1/24")])
    // <snip>
    .build();
Source

pub fn add_network<T: Into<IpNet>>(&mut self, value: T) -> &mut Self

Adds IP Network to Address = ... field.

value is Into<IpNet>, which means that it can be either ipnet::IpNet or std::net::IpAddr.

§Example
use wireguard_conf::{as_ipnet, prelude::*};

let interface = InterfaceBuilder::new()
    .add_network(as_ipnet!("1.2.3.4/16"))
    .add_network(as_ipnet!("fd00:DEAD:BEEF::1/48"))
    .build();

assert_eq!(
    interface.address,
    vec![
        as_ipnet!("1.2.3.4/16"),
        as_ipnet!("fd00:DEAD:BEEF::1/48")
    ]
);
Source

pub fn add_address<T: Into<IpAddr>>(&mut self, value: T) -> &mut Self

Adds IP address to Address = ... field.

value is Into<IpAddr>, which means that it can be either std::net::Ipv4Addr or std::net::Ipv6Addr.

§Example
use wireguard_conf::{as_ipaddr, as_ipnet, prelude::*};

let interface = InterfaceBuilder::new()
    .add_address(as_ipaddr!("1.2.3.4"))
    .add_address(as_ipaddr!("fd00::1"))
    .build();

// /32 and /128 are added automatically
assert_eq!(
    interface.address,
    vec![
        as_ipnet!("1.2.3.4/32"),
        as_ipnet!("fd00::1/128"),
    ]
);
Source

pub fn build(&self) -> Interface

Builds an Interface.

Trait Implementations§

Source§

impl Clone for InterfaceBuilder

Source§

fn clone(&self) -> InterfaceBuilder

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 Default for InterfaceBuilder

Source§

fn default() -> Self

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

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