pub trait WireguardInterfaceApi {
// Required methods
fn create_interface(&self) -> Result<(), WireguardInterfaceError>;
fn assign_address(
&self,
address: &IpAddrMask
) -> Result<(), WireguardInterfaceError>;
fn configure_peer_routing(
&self,
peers: &[Peer]
) -> Result<(), WireguardInterfaceError>;
fn configure_interface(
&self,
config: &InterfaceConfiguration
) -> Result<(), WireguardInterfaceError>;
fn remove_interface(&self) -> Result<(), WireguardInterfaceError>;
fn configure_peer(&self, peer: &Peer) -> Result<(), WireguardInterfaceError>;
fn remove_peer(
&self,
peer_pubkey: &Key
) -> Result<(), WireguardInterfaceError>;
fn read_interface_data(&self) -> Result<Host, WireguardInterfaceError>;
fn configure_dns(
&self,
dns: &[IpAddr]
) -> Result<(), WireguardInterfaceError>;
}
Expand description
API for managing a WireGuard interface.
Specific interface being managed is identified by name.
Required Methods§
sourcefn create_interface(&self) -> Result<(), WireguardInterfaceError>
fn create_interface(&self) -> Result<(), WireguardInterfaceError>
Creates a new WireGuard interface.
sourcefn assign_address(
&self,
address: &IpAddrMask
) -> Result<(), WireguardInterfaceError>
fn assign_address( &self, address: &IpAddrMask ) -> Result<(), WireguardInterfaceError>
Assigns IP address to an existing interface.
sourcefn configure_peer_routing(
&self,
peers: &[Peer]
) -> Result<(), WireguardInterfaceError>
fn configure_peer_routing( &self, peers: &[Peer] ) -> Result<(), WireguardInterfaceError>
Add peer routing, basically a copy of wg-quick up <if_name>
routing.
Extracts all uniques allowed ips from Peer slice and add routing for every
address.
sourcefn configure_interface(
&self,
config: &InterfaceConfiguration
) -> Result<(), WireguardInterfaceError>
fn configure_interface( &self, config: &InterfaceConfiguration ) -> Result<(), WireguardInterfaceError>
Updates configuration of an existing WireGuard interface.
sourcefn remove_interface(&self) -> Result<(), WireguardInterfaceError>
fn remove_interface(&self) -> Result<(), WireguardInterfaceError>
Removes the WireGuard interface being managed.
Meant to be used in drop
method for a given API struct.
sourcefn configure_peer(&self, peer: &Peer) -> Result<(), WireguardInterfaceError>
fn configure_peer(&self, peer: &Peer) -> Result<(), WireguardInterfaceError>
Adds a peer or updates peer configuration.
sourcefn remove_peer(&self, peer_pubkey: &Key) -> Result<(), WireguardInterfaceError>
fn remove_peer(&self, peer_pubkey: &Key) -> Result<(), WireguardInterfaceError>
Removes a configured peer with a given pubkey.
sourcefn read_interface_data(&self) -> Result<Host, WireguardInterfaceError>
fn read_interface_data(&self) -> Result<Host, WireguardInterfaceError>
Reads current WireGuard interface configuration and stats.
Similar to wg show <if_name>
command.
sourcefn configure_dns(&self, dns: &[IpAddr]) -> Result<(), WireguardInterfaceError>
fn configure_dns(&self, dns: &[IpAddr]) -> Result<(), WireguardInterfaceError>
Sets the DNS configuration for the WireGuard interface.
This function takes a vector of DNS server addresses (dns
) and configures the
WireGuard interface to use these DNS servers. It is equivalent to specifying the
DNS section in a WireGuard configuration file and using wg-quick
to apply the
configuration.
§Arguments
dns
- A vector of `IpAddr`` representing the DNS server addresses to be set for the WireGuard interface.
§Returns
Returns Ok(())
if the DNS configuration is successfully set, or an
Err(WireguardInterfaceError)
if there is an error during the configuration process.