Struct wgctrl_rs::DeviceConfigBuilder[][src]

pub struct DeviceConfigBuilder { /* fields omitted */ }

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".parse()?;

DeviceConfigBuilder::new()
    .set_keypair(our_keypair)
    .replace_peers()
    .add_peer_with(&peer_keypair.public, |peer| {
        peer.set_endpoint(server_addr, 51820)
            .replace_allowed_ips()
            .allow_all_ips()
    }).apply("wg-example");

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

Methods

impl DeviceConfigBuilder
[src]

Creates a new DeviceConfigBuilder that does nothing when applied.

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.

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

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

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

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

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

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

Specifies the port to listen for incoming packets on.

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

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

This is probably what you want in client configurations.

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.

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.

Specifies multiple peer configurations to be added to the interface.

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

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

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

impl Debug for DeviceConfigBuilder
[src]

Formats the value using the given formatter. Read more

impl PartialEq for DeviceConfigBuilder
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl Eq for DeviceConfigBuilder
[src]

impl Clone for DeviceConfigBuilder
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl Default for DeviceConfigBuilder
[src]

Returns the "default value" for a type. Read more

Auto Trait Implementations