Struct DeviceUpdate

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

Builds and represents a configuration that can be applied to a WireGuard interface.

This is the primary way of changing the settings of an interface.

Note that if an interface exists, the configuration is applied on top of the existing settings, and missing parts are not overwritten or set to defaults.

If this is not what you want, use delete_interface to remove the interface entirely before applying the new configuration.

§Example

let our_keypair = KeyPair::generate();
let peer_keypair = KeyPair::generate();
let server_addr = "192.168.1.1:51820".parse()?;

DeviceUpdate::new()
    .set_keypair(our_keypair)
    .replace_peers()
    .add_peer_with(&peer_keypair.public, |peer| {
        peer.set_endpoint(server_addr)
            .replace_allowed_ips()
            .allow_all_ips()
    }).apply(&"wg-example".parse().unwrap(), Backend::Userspace);

println!("Send these keys to your peer: {:#?}", peer_keypair);

Implementations§

Source§

impl DeviceUpdate

Source

pub fn new() -> Self

Creates a new DeviceConfigBuilder that does nothing when applied.

Source

pub fn set_keypair(self, keypair: KeyPair) -> Self

Sets a new keypair to be applied to the interface.

This is a convenience method that simply wraps set_public_key and set_private_key.

Source

pub fn set_public_key(self, key: Key) -> Self

Specifies a new public key to be applied to the interface.

Source

pub fn unset_public_key(self) -> Self

Specifies that the public key for this interface should be unset.

Source

pub fn set_private_key(self, key: Key) -> Self

Sets a new private key to be applied to the interface.

Source

pub fn unset_private_key(self) -> Self

Specifies that the private key for this interface should be unset.

Source

pub fn set_fwmark(self, fwmark: u32) -> Self

Specifies the fwmark value that should be applied to packets coming from the interface.

Source

pub fn unset_fwmark(self) -> Self

Specifies that fwmark should not be set on packets from the interface.

Source

pub fn set_listen_port(self, port: u16) -> Self

Specifies the port to listen for incoming packets on.

This is useful for a server configuration that listens on a fixed endpoint.

Source

pub fn randomize_listen_port(self) -> Self

Specifies that a random port should be used for incoming packets.

This is probably what you want in client configurations.

Source

pub fn add_peer(self, peer: PeerConfigBuilder) -> Self

Specifies a new peer configuration to be added to the interface.

See PeerConfigBuilder for details on building peer configurations. This method can be called more than once, and all peers will be added to the configuration.

Source

pub fn add_peer_with( self, pubkey: &Key, builder: impl Fn(PeerConfigBuilder) -> PeerConfigBuilder, ) -> Self

Specifies a new peer configuration using a builder function.

This is simply a convenience method to make adding peers more fluent. This method can be called more than once, and all peers will be added to the configuration.

Source

pub fn add_peers(self, peers: &[PeerConfigBuilder]) -> Self

Specifies multiple peer configurations to be added to the interface.

Source

pub fn replace_peers(self) -> Self

Specifies that the peer configurations in this DeviceConfigBuilder should replace the existing configurations on the interface, not modify or append to them.

Source

pub fn remove_peer_by_key(self, public_key: &Key) -> Self

Specifies that the peer with this public key should be removed from the interface.

Source

pub fn apply(self, iface: &InterfaceName, backend: Backend) -> Result<()>

Build and apply the configuration to a WireGuard interface by name.

An interface with the provided name will be created if one does not exist already.

Trait Implementations§

Source§

impl Clone for DeviceUpdate

Source§

fn clone(&self) -> DeviceUpdate

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 DeviceUpdate

Source§

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

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

impl Default for DeviceUpdate

Source§

fn default() -> Self

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

impl PartialEq for DeviceUpdate

Source§

fn eq(&self, other: &DeviceUpdate) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for DeviceUpdate

Source§

impl StructuralPartialEq for DeviceUpdate

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