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]
impl DeviceConfigBuilder
pub fn new() -> Self
[src]
pub fn new() -> Self
Creates a new DeviceConfigBuilder
that does nothing when applied.
pub fn set_keypair(self, keypair: KeyPair) -> Self
[src]
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
.
pub fn set_public_key(self, key: Key) -> Self
[src]
pub fn set_public_key(self, key: Key) -> Self
Specifies a new public key to be applied to the interface.
pub fn unset_public_key(self) -> Self
[src]
pub fn unset_public_key(self) -> Self
Specifies that the public key for this interface should be unset.
pub fn set_private_key(self, key: Key) -> Self
[src]
pub fn set_private_key(self, key: Key) -> Self
Sets a new private key to be applied to the interface.
pub fn unset_private_key(self) -> Self
[src]
pub fn unset_private_key(self) -> Self
Specifies that the private key for this interface should be unset.
pub fn set_fwmark(self, fwmark: u32) -> Self
[src]
pub fn set_fwmark(self, fwmark: u32) -> Self
Specifies the fwmark value that should be applied to packets coming from the interface.
pub fn unset_fwmark(self) -> Self
[src]
pub fn unset_fwmark(self) -> Self
Specifies that fwmark should not be set on packets from the interface.
pub fn set_listen_port(self, port: u16) -> Self
[src]
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.
pub fn randomize_listen_port(self) -> Self
[src]
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.
pub fn add_peer(self, peer: PeerConfigBuilder) -> Self
[src]
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.
pub fn add_peer_with(
self,
pubkey: &Key,
builder: impl Fn(PeerConfigBuilder) -> PeerConfigBuilder
) -> Self
[src]
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.
pub fn add_peers(self, peers: &[PeerConfigBuilder]) -> Self
[src]
pub fn add_peers(self, peers: &[PeerConfigBuilder]) -> Self
Specifies multiple peer configurations to be added to the interface.
pub fn replace_peers(self) -> Self
[src]
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.
pub fn remove_peer_by_key(self, public_key: &Key) -> Self
[src]
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.
pub fn apply(self, iface: &str) -> Result<()>
[src]
pub fn apply(self, iface: &str) -> 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
impl Debug for DeviceConfigBuilder
[src]
impl Debug for DeviceConfigBuilder
fn fmt(&self, f: &mut Formatter) -> Result
[src]
fn fmt(&self, f: &mut Formatter) -> Result
Formats the value using the given formatter. Read more
impl PartialEq for DeviceConfigBuilder
[src]
impl PartialEq for DeviceConfigBuilder
fn eq(&self, other: &DeviceConfigBuilder) -> bool
[src]
fn eq(&self, other: &DeviceConfigBuilder) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &DeviceConfigBuilder) -> bool
[src]
fn ne(&self, other: &DeviceConfigBuilder) -> bool
This method tests for !=
.
impl Eq for DeviceConfigBuilder
[src]
impl Eq for DeviceConfigBuilder
impl Clone for DeviceConfigBuilder
[src]
impl Clone for DeviceConfigBuilder
fn clone(&self) -> DeviceConfigBuilder
[src]
fn clone(&self) -> DeviceConfigBuilder
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
impl Default for DeviceConfigBuilder
[src]
impl Default for DeviceConfigBuilder
Auto Trait Implementations
impl Send for DeviceConfigBuilder
impl Send for DeviceConfigBuilder
impl Sync for DeviceConfigBuilder
impl Sync for DeviceConfigBuilder