aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJake McGinty <me@jake.su>2018-04-30 01:08:37 -0700
committerJake McGinty <me@jake.su>2018-04-30 01:08:37 -0700
commit14952477345591163da987bd922ff2c4d4a3a601 (patch)
treebdf07ff541c0ff09e21aeaae9aecbf604a9419d6 /src
parentconsts: fix typo in MAX_PEERS_PER_DEVICE (diff)
downloadwireguard-rs-14952477345591163da987bd922ff2c4d4a3a601.tar.xz
wireguard-rs-14952477345591163da987bd922ff2c4d4a3a601.zip
initial commit on netlink listener. not working.jm/netlink-listener
Diffstat (limited to 'src')
-rw-r--r--src/consts.rs1
-rw-r--r--src/lib.rs4
-rw-r--r--src/main.rs4
-rw-r--r--src/route_monitor/linux.rs34
-rw-r--r--src/route_monitor/mod.rs5
5 files changed, 46 insertions, 2 deletions
diff --git a/src/consts.rs b/src/consts.rs
index 0aa644d..3425469 100644
--- a/src/consts.rs
+++ b/src/consts.rs
@@ -30,5 +30,6 @@ pub const MAX_CONTENT_SIZE : usize = MAX_SEGMENT_SIZE - TRANSPORT_OVERHEAD;
pub const PADDING_MULTIPLE : usize = 16;
pub const MAX_QUEUED_INCOMING_HANDSHAKES : usize = 4096;
+pub const UNDER_LOAD_QUEUE_SIZE : usize = 512;
pub const MAX_QUEUED_PACKETS : usize = 1024;
pub const MAX_PEERS_PER_DEVICE : usize = 1 << 20;
diff --git a/src/lib.rs b/src/lib.rs
index 5302f19..e80b6ab 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -38,6 +38,9 @@ extern crate tokio_signal;
extern crate treebitmap;
extern crate x25519_dalek;
+#[cfg(any(target_os = "android", target_os = "linux"))]
+extern crate pnetlink;
+
pub mod interface;
pub mod peer;
pub mod noise;
@@ -50,6 +53,7 @@ mod cookie;
mod error;
mod ip_packet;
mod message;
+mod route_monitor;
mod router;
mod timer;
mod udp;
diff --git a/src/main.rs b/src/main.rs
index 183503c..79fecf8 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -60,8 +60,8 @@ fn main() {
message,
))
})
- .level(log::LevelFilter::Info)
- .level_for("wireguard", log::LevelFilter::Debug)
+ .level(log::LevelFilter::Warn)
+ // .level_for("wireguard", log::LevelFilter::Debug)
.chain(std::io::stdout())
.apply().unwrap();
diff --git a/src/route_monitor/linux.rs b/src/route_monitor/linux.rs
new file mode 100644
index 0000000..a08cff2
--- /dev/null
+++ b/src/route_monitor/linux.rs
@@ -0,0 +1,34 @@
+use failure::Error;
+use futures::stream::Stream;
+use futures::{Async, Poll};
+use pnetlink::socket::NetlinkProtocol;
+use pnetlink::packet::route::RtMsgPacket;
+use pnetlink::tokio::{NetlinkSocket, NetlinkCodec};
+use tokio_core::reactor::Handle;
+use tokio_io::{AsyncRead, codec::Framed};
+use std::io;
+
+pub struct RouteListener {
+ inner: Framed<NetlinkSocket, NetlinkCodec>,
+}
+
+impl RouteListener {
+ pub fn bind(handle: &Handle) -> io::Result<Self> {
+ let sock = NetlinkSocket::bind(NetlinkProtocol::Route, 0, handle)?;
+
+ Ok(RouteListener {
+ inner: AsyncRead::framed(sock, NetlinkCodec {});
+ })
+ }
+}
+
+impl Stream for RouteListener {
+ type Item = ();
+ type Error = Error;
+
+ fn poll(&mut self) -> Poll<Option<Self::Item>, Self::Error> {
+ match self.inner.poll() {
+ Ok(Async::Ready(Some(packet)))
+ }
+ }
+} \ No newline at end of file
diff --git a/src/route_monitor/mod.rs b/src/route_monitor/mod.rs
new file mode 100644
index 0000000..db74130
--- /dev/null
+++ b/src/route_monitor/mod.rs
@@ -0,0 +1,5 @@
+#[cfg(any(target_os = "android", target_os = "linux"))]
+mod linux;
+
+#[cfg(any(target_os = "android", target_os = "linux"))]
+pub use self::linux::RouteListener; \ No newline at end of file