aboutsummaryrefslogtreecommitdiffstats
path: root/src/types/tun.rs
diff options
context:
space:
mode:
authorMathias Hall-Andersen <mathias@hall-andersen.dk>2019-10-09 15:08:26 +0200
committerMathias Hall-Andersen <mathias@hall-andersen.dk>2019-10-09 15:08:26 +0200
commit761c46064d7510303f08cde27c9e13b07293f3af (patch)
tree7b914169725952e557223972b3f0b611c54e6829 /src/types/tun.rs
parentRestructure dummy implementations (diff)
downloadwireguard-rs-761c46064d7510303f08cde27c9e13b07293f3af.tar.xz
wireguard-rs-761c46064d7510303f08cde27c9e13b07293f3af.zip
Restructure IO traits.
Diffstat (limited to 'src/types/tun.rs')
-rw-r--r--src/types/tun.rs43
1 files changed, 28 insertions, 15 deletions
diff --git a/src/types/tun.rs b/src/types/tun.rs
index fc8044a..2ba16ff 100644
--- a/src/types/tun.rs
+++ b/src/types/tun.rs
@@ -1,18 +1,22 @@
-use std::error;
+use std::error::Error;
-pub trait Tun: Send + Sync + Clone + 'static {
- type Error: error::Error;
+pub trait Writer: Send + Sync + 'static {
+ type Error: Error;
- /// Returns the MTU of the device
+ /// Receive a cryptkey routed IP packet
///
- /// This function needs to be efficient (called for every read).
- /// The goto implementation strategy is to .load an atomic variable,
- /// then use e.g. netlink to update the variable in a separate thread.
+ /// # Arguments
+ ///
+ /// - src: Buffer containing the IP packet to be written
///
/// # Returns
///
- /// The MTU of the interface in bytes
- fn mtu(&self) -> usize;
+ /// Unit type or an error
+ fn write(&self, src: &[u8]) -> Result<(), Self::Error>;
+}
+
+pub trait Reader: Send + 'static {
+ type Error: Error;
/// Reads an IP packet into dst[offset:] from the tunnel device
///
@@ -29,15 +33,24 @@ pub trait Tun: Send + Sync + Clone + 'static {
///
/// The size of the IP packet (ignoring the header) or an std::error::Error instance:
fn read(&self, buf: &mut [u8], offset: usize) -> Result<usize, Self::Error>;
+}
- /// Writes an IP packet to the tunnel device
- ///
- /// # Arguments
+pub trait MTU: Send + Sync + Clone + 'static {
+ /// Returns the MTU of the device
///
- /// - src: Buffer containing the IP packet to be written
+ /// This function needs to be efficient (called for every read).
+ /// The goto implementation strategy is to .load an atomic variable,
+ /// then use e.g. netlink to update the variable in a separate thread.
///
/// # Returns
///
- /// Unit type or an error
- fn write(&self, src: &[u8]) -> Result<(), Self::Error>;
+ /// The MTU of the interface in bytes
+ fn mtu(&self) -> usize;
+}
+
+pub trait Tun: Send + Sync + 'static {
+ type Writer: Writer;
+ type Reader: Reader;
+ type MTU: MTU;
+ type Error: Error;
}