aboutsummaryrefslogtreecommitdiffstats
path: root/src/platform/mod.rs
diff options
context:
space:
mode:
authorMathias Hall-Andersen <mathias@hall-andersen.dk>2019-10-13 22:26:12 +0200
committerMathias Hall-Andersen <mathias@hall-andersen.dk>2019-10-13 22:26:12 +0200
commita08fd4002bfae92072f64f8d5e0084e6f248f139 (patch)
treea50315318549056627adb05bdd0a4f1a02f8541d /src/platform/mod.rs
parentPort timer.c from WireGuard (diff)
downloadwireguard-rs-a08fd4002bfae92072f64f8d5e0084e6f248f139.tar.xz
wireguard-rs-a08fd4002bfae92072f64f8d5e0084e6f248f139.zip
Work on Linux platform code
Diffstat (limited to 'src/platform/mod.rs')
-rw-r--r--src/platform/mod.rs36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/platform/mod.rs b/src/platform/mod.rs
new file mode 100644
index 0000000..e83384c
--- /dev/null
+++ b/src/platform/mod.rs
@@ -0,0 +1,36 @@
+use std::error::Error;
+
+use super::wireguard::bind::Bind;
+use super::wireguard::tun::Tun;
+
+#[cfg(target_os = "linux")]
+mod linux;
+
+#[cfg(target_os = "linux")]
+pub use linux::PlatformTun;
+
+/* Syntax is nasty here, due to open issue:
+ * https://github.com/rust-lang/rust/issues/38078
+ */
+pub trait UDPBind {
+ type Closer;
+ type Error: Error;
+ type Bind: Bind;
+
+ /// Bind to a new port, returning the reader/writer and
+ /// an associated instance of the Closer type, which closes the UDP socket upon "drop".
+ fn bind(
+ port: u16,
+ ) -> Result<
+ (
+ <<Self as UDPBind>::Bind as Bind>::Reader,
+ <<Self as UDPBind>::Bind as Bind>::Writer,
+ Self::Closer,
+ ),
+ Self::Error,
+ >;
+}
+
+pub trait TunBind: Tun {
+ fn create(name: &str) -> Result<(Vec<Self::Reader>, Self::Writer, Self::MTU), Self::Error>;
+}