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
impl DeviceUpdate
Sourcepub fn set_keypair(self, keypair: KeyPair) -> Self
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
.
Sourcepub fn set_public_key(self, key: Key) -> Self
pub fn set_public_key(self, key: Key) -> Self
Specifies a new public key to be applied to the interface.
Sourcepub fn unset_public_key(self) -> Self
pub fn unset_public_key(self) -> Self
Specifies that the public key for this interface should be unset.
Sourcepub fn set_private_key(self, key: Key) -> Self
pub fn set_private_key(self, key: Key) -> Self
Sets a new private key to be applied to the interface.
Sourcepub fn unset_private_key(self) -> Self
pub fn unset_private_key(self) -> Self
Specifies that the private key for this interface should be unset.
Sourcepub fn set_fwmark(self, fwmark: u32) -> Self
pub fn set_fwmark(self, fwmark: u32) -> Self
Specifies the fwmark value that should be applied to packets coming from the interface.
Sourcepub fn unset_fwmark(self) -> Self
pub fn unset_fwmark(self) -> Self
Specifies that fwmark should not be set on packets from the interface.
Sourcepub fn set_listen_port(self, port: u16) -> Self
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.
Sourcepub fn randomize_listen_port(self) -> Self
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.
Sourcepub fn add_peer(self, peer: PeerConfigBuilder) -> Self
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.
Sourcepub fn add_peer_with(
self,
pubkey: &Key,
builder: impl Fn(PeerConfigBuilder) -> PeerConfigBuilder,
) -> Self
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.
Sourcepub fn add_peers(self, peers: &[PeerConfigBuilder]) -> Self
pub fn add_peers(self, peers: &[PeerConfigBuilder]) -> Self
Specifies multiple peer configurations to be added to the interface.
Sourcepub fn replace_peers(self) -> Self
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.
Sourcepub fn remove_peer_by_key(self, public_key: &Key) -> Self
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.
Trait Implementations§
Source§impl Clone for DeviceUpdate
impl Clone for DeviceUpdate
Source§fn clone(&self) -> DeviceUpdate
fn clone(&self) -> DeviceUpdate
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more