aboutsummaryrefslogtreecommitdiffstats
path: root/src/platform/linux
diff options
context:
space:
mode:
Diffstat (limited to 'src/platform/linux')
-rw-r--r--src/platform/linux/mod.rs2
-rw-r--r--src/platform/linux/tun.rs42
-rw-r--r--src/platform/linux/udp.rs24
3 files changed, 39 insertions, 29 deletions
diff --git a/src/platform/linux/mod.rs b/src/platform/linux/mod.rs
index 82731de..d28391e 100644
--- a/src/platform/linux/mod.rs
+++ b/src/platform/linux/mod.rs
@@ -4,4 +4,4 @@ mod udp;
pub use tun::LinuxTun as Tun;
pub use uapi::LinuxUAPI as UAPI;
-pub use udp::LinuxBind as Bind;
+pub use udp::LinuxUDP as UDP;
diff --git a/src/platform/linux/tun.rs b/src/platform/linux/tun.rs
index 0bbae81..604fad9 100644
--- a/src/platform/linux/tun.rs
+++ b/src/platform/linux/tun.rs
@@ -6,8 +6,8 @@ use std::error::Error;
use std::fmt;
use std::os::raw::c_short;
use std::os::unix::io::RawFd;
-use std::sync::atomic::{AtomicUsize, Ordering};
-use std::sync::Arc;
+use std::thread;
+use std::time::Duration;
const IFNAMSIZ: usize = 16;
const TUNSETIFF: u64 = 0x4004_54ca;
@@ -30,7 +30,9 @@ struct Ifreq {
_pad: [u8; 64],
}
-pub struct LinuxTun {}
+pub struct LinuxTun {
+ events: Vec<TunEvent>,
+}
pub struct LinuxTunReader {
fd: RawFd,
@@ -44,8 +46,8 @@ pub struct LinuxTunWriter {
* announcing an MTU update for the interface
*/
#[derive(Clone)]
-pub struct LinuxTunMTU {
- value: Arc<AtomicUsize>,
+pub struct LinuxTunStatus {
+ first: bool,
}
#[derive(Debug)]
@@ -81,13 +83,6 @@ impl Error for LinuxTunError {
}
}
-impl MTU for LinuxTunMTU {
- #[inline(always)]
- fn mtu(&self) -> usize {
- self.value.load(Ordering::Relaxed)
- }
-}
-
impl Reader for LinuxTunReader {
type Error = LinuxTunError;
@@ -118,15 +113,30 @@ impl Writer for LinuxTunWriter {
}
}
+impl Status for LinuxTunStatus {
+ type Error = LinuxTunError;
+
+ fn event(&mut self) -> Result<TunEvent, Self::Error> {
+ if self.first {
+ self.first = false;
+ return Ok(TunEvent::Up(1420));
+ }
+
+ loop {
+ thread::sleep(Duration::from_secs(60 * 60));
+ }
+ }
+}
+
impl Tun for LinuxTun {
type Error = LinuxTunError;
type Reader = LinuxTunReader;
type Writer = LinuxTunWriter;
- type MTU = LinuxTunMTU;
+ type Status = LinuxTunStatus;
}
impl PlatformTun for LinuxTun {
- fn create(name: &str) -> Result<(Vec<Self::Reader>, Self::Writer, Self::MTU), Self::Error> {
+ fn create(name: &str) -> Result<(Vec<Self::Reader>, Self::Writer, Self::Status), Self::Error> {
// construct request struct
let mut req = Ifreq {
name: [0u8; libc::IFNAMSIZ],
@@ -157,9 +167,7 @@ impl PlatformTun for LinuxTun {
Ok((
vec![LinuxTunReader { fd }], // TODO: enable multi-queue for Linux
LinuxTunWriter { fd },
- LinuxTunMTU {
- value: Arc::new(AtomicUsize::new(1500)), // TODO: fetch and update
- },
+ LinuxTunStatus { first: true },
))
}
}
diff --git a/src/platform/linux/udp.rs b/src/platform/linux/udp.rs
index a291d1a..f871bce 100644
--- a/src/platform/linux/udp.rs
+++ b/src/platform/linux/udp.rs
@@ -1,4 +1,4 @@
-use super::super::bind::*;
+use super::super::udp::*;
use super::super::Endpoint;
use std::io;
@@ -6,7 +6,7 @@ use std::net::{SocketAddr, UdpSocket};
use std::sync::Arc;
#[derive(Clone)]
-pub struct LinuxBind(Arc<UdpSocket>);
+pub struct LinuxUDP(Arc<UdpSocket>);
pub struct LinuxOwner(Arc<UdpSocket>);
@@ -22,7 +22,7 @@ impl Endpoint for SocketAddr {
}
}
-impl Reader<SocketAddr> for LinuxBind {
+impl Reader<SocketAddr> for LinuxUDP {
type Error = io::Error;
fn read(&self, buf: &mut [u8]) -> Result<(usize, SocketAddr), Self::Error> {
@@ -30,7 +30,7 @@ impl Reader<SocketAddr> for LinuxBind {
}
}
-impl Writer<SocketAddr> for LinuxBind {
+impl Writer<SocketAddr> for LinuxUDP {
type Error = io::Error;
fn write(&self, buf: &[u8], dst: &SocketAddr) -> Result<(), Self::Error> {
@@ -56,17 +56,19 @@ impl Owner for LinuxOwner {
}
impl Drop for LinuxOwner {
- fn drop(&mut self) {}
+ fn drop(&mut self) {
+ // TODO: close udp bind
+ }
}
-impl Bind for LinuxBind {
+impl UDP for LinuxUDP {
type Error = io::Error;
type Endpoint = SocketAddr;
- type Reader = LinuxBind;
- type Writer = LinuxBind;
+ type Reader = Self;
+ type Writer = Self;
}
-impl PlatformBind for LinuxBind {
+impl PlatformUDP for LinuxUDP {
type Owner = LinuxOwner;
fn bind(port: u16) -> Result<(Vec<Self::Reader>, Self::Writer, Self::Owner), Self::Error> {
@@ -74,8 +76,8 @@ impl PlatformBind for LinuxBind {
let socket = Arc::new(socket);
Ok((
- vec![LinuxBind(socket.clone())],
- LinuxBind(socket.clone()),
+ vec![LinuxUDP(socket.clone())],
+ LinuxUDP(socket.clone()),
LinuxOwner(socket),
))
}