summaryrefslogtreecommitdiffstats
path: root/src/configuration
diff options
context:
space:
mode:
authorMathias Hall-Andersen <mathias@hall-andersen.dk>2019-10-23 12:08:35 +0200
committerMathias Hall-Andersen <mathias@hall-andersen.dk>2019-10-23 12:08:35 +0200
commitee3599d5507ceee23ef3382dbda9de8e73c54a00 (patch)
treed681a3f8a5a2d5e7bea779acecd1fc0798285d9e /src/configuration
parentWork on platform specific code (Linux) (diff)
downloadwireguard-rs-ee3599d5507ceee23ef3382dbda9de8e73c54a00.tar.xz
wireguard-rs-ee3599d5507ceee23ef3382dbda9de8e73c54a00.zip
Moved IO traits into platform module
Diffstat (limited to 'src/configuration')
-rw-r--r--src/configuration/config.rs25
-rw-r--r--src/configuration/mod.rs6
2 files changed, 20 insertions, 11 deletions
diff --git a/src/configuration/config.rs b/src/configuration/config.rs
index 24b1349..f42b53b 100644
--- a/src/configuration/config.rs
+++ b/src/configuration/config.rs
@@ -2,10 +2,8 @@ use spin::Mutex;
use std::net::{IpAddr, SocketAddr};
use x25519_dalek::{PublicKey, StaticSecret};
-use super::BindOwner;
-use super::PlatformBind;
-use super::Tun;
-use super::Wireguard;
+use super::*;
+use bind::Owner;
/// The goal of the configuration interface is, among others,
/// to hide the IO implementations (over which the WG device is generic),
@@ -21,17 +19,26 @@ pub struct PeerState {
allowed_ips: Vec<(IpAddr, u32)>,
}
-struct UDPState<O: BindOwner> {
+struct UDPState<O: bind::Owner> {
fwmark: Option<u32>,
owner: O,
port: u16,
}
-pub struct WireguardConfig<T: Tun, B: PlatformBind> {
+pub struct WireguardConfig<T: tun::Tun, B: bind::Platform> {
wireguard: Wireguard<T, B>,
network: Mutex<Option<UDPState<B::Owner>>>,
}
+impl<T: tun::Tun, B: bind::Platform> WireguardConfig<T, B> {
+ fn new(wg: Wireguard<T, B>) -> WireguardConfig<T, B> {
+ WireguardConfig {
+ wireguard: wg,
+ network: Mutex::new(None),
+ }
+ }
+}
+
pub enum ConfigError {
NoSuchPeer,
NotListening,
@@ -41,8 +48,8 @@ impl ConfigError {
fn errno(&self) -> i32 {
// TODO: obtain the correct error values
match self {
- NoSuchPeer => 1,
- NotListening => 2,
+ ConfigError::NoSuchPeer => 1,
+ ConfigError::NotListening => 2,
}
}
}
@@ -180,7 +187,7 @@ pub trait Configuration {
fn get_peers(&self) -> Vec<PeerState>;
}
-impl<T: Tun, B: PlatformBind> Configuration for WireguardConfig<T, B> {
+impl<T: tun::Tun, B: bind::Platform> Configuration for WireguardConfig<T, B> {
fn set_private_key(&self, sk: Option<StaticSecret>) {
self.wireguard.set_key(sk)
}
diff --git a/src/configuration/mod.rs b/src/configuration/mod.rs
index 56a83e2..520b397 100644
--- a/src/configuration/mod.rs
+++ b/src/configuration/mod.rs
@@ -1,5 +1,7 @@
mod config;
-use super::platform::{BindOwner, PlatformBind};
-use super::wireguard::tun::Tun;
+use super::platform::{bind, tun};
use super::wireguard::Wireguard;
+
+pub use config::Configuration;
+pub use config::WireguardConfig;