aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock42
-rw-r--r--Cargo.toml4
-rw-r--r--benches/criterion.rs6
-rw-r--r--src/interface/config.rs4
-rw-r--r--src/interface/mod.rs4
-rw-r--r--src/interface/peer_server.rs18
-rw-r--r--src/peer.rs1
-rw-r--r--src/types.rs1
-rw-r--r--src/udp/frame.rs25
9 files changed, 70 insertions, 35 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 662c708..3505581 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -80,11 +80,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "bitflags"
-version = "0.9.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-
-[[package]]
-name = "bitflags"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -469,6 +464,11 @@ version = "0.2.37"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
+name = "libc"
+version = "0.2.39"
+source = "git+https://github.com/rust-lang/libc#837310de9a1773f74af78e2dce0f2eb881be4b78"
+
+[[package]]
name = "log"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -542,12 +542,12 @@ dependencies = [
[[package]]
name = "mio-utun"
-version = "0.6.13"
+version = "0.6.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"byteorder 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"mio 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)",
- "nix 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "nix 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@@ -593,25 +593,27 @@ dependencies = [
[[package]]
name = "nix"
-version = "0.9.0"
+version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
- "bitflags 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "bitflags 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "bytes 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"cfg-if 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "gcc 0.3.54 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.37 (registry+https://github.com/rust-lang/crates.io-index)",
"void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "nix"
-version = "0.10.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
+version = "0.11.0-pre"
+source = "git+https://github.com/mcginty/nix?branch=so_mark#3621ff61b7b2cdae1231f2eec004cbedefda3120"
dependencies = [
"bitflags 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"bytes 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"cfg-if 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"gcc 0.3.54 (registry+https://github.com/rust-lang/crates.io-index)",
- "libc 0.2.37 (registry+https://github.com/rust-lang/crates.io-index)",
+ "libc 0.2.39 (git+https://github.com/rust-lang/libc)",
"void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
@@ -1208,13 +1210,13 @@ dependencies = [
[[package]]
name = "tokio-utun"
-version = "0.1.8"
+version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"futures 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
"mio 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)",
- "mio-utun 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)",
+ "mio-utun 0.6.14 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-core 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)",
]
@@ -1300,7 +1302,7 @@ dependencies = [
"lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
"mio 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)",
- "nix 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "nix 0.11.0-pre (git+https://github.com/mcginty/nix?branch=so_mark)",
"notify 4.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
"pnet_packet 0.20.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1314,7 +1316,7 @@ dependencies = [
"tokio-signal 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-timer 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-uds 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
- "tokio-utun 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
+ "tokio-utun 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
"treebitmap 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"x25519-dalek 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
@@ -1378,7 +1380,6 @@ dependencies = [
"checksum bitflags 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8dead7461c1127cf637931a1e50934eb6eee8bff2f74433ac7909e9afcee04a3"
"checksum bitflags 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4f67931368edf3a9a51d29886d245f1c3db2f1ef0dcc9e35ff70341b78c10d23"
"checksum bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "aad18937a628ec6abcd26d1489012cc0e18c21798210f491af69ded9b881106d"
-"checksum bitflags 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4efd02e230a02e18f92fc2735f44597385ed02ad8f831e7c1c1156ee5e1ab3a5"
"checksum bitflags 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b3c30d3802dfb7281680d6285f2ccdaa8c2d8fee41f93805dba5c4cf50dc23cf"
"checksum blake2-rfc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)" = "5d6d530bdd2d52966a6d03b7a964add7ae1a288d25214066fd4b600f0f796400"
"checksum byteorder 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "652805b7e73fada9d85e9a6682a4abd490cb52d96aeecc12e33a0de34dfd0d23"
@@ -1427,6 +1428,7 @@ dependencies = [
"checksum lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c8f31047daa365f19be14b47c29df4f7c3b581832407daabe6ae77397619237d"
"checksum lazycell 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a6f08839bc70ef4a3fe1d566d5350f519c5912ea86be0df1740a7d247c7fc0ef"
"checksum libc 0.2.37 (registry+https://github.com/rust-lang/crates.io-index)" = "56aebce561378d99a0bb578f8cb15b6114d2a1814a6c7949bbe646d968bb4fa9"
+"checksum libc 0.2.39 (git+https://github.com/rust-lang/libc)" = "<none>"
"checksum log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "e19e8d5c34a3e0e2223db8e060f9e8264aeeb5c5fc64a4ee9965c062211c024b"
"checksum log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "89f010e843f2b1a31dbd316b3b8d443758bc634bed37aabade59c686d644e0a2"
"checksum memchr 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "796fba70e76612589ed2ce7f45282f5af869e0fdd7cc6199fa1aa1f1d591ba9d"
@@ -1434,13 +1436,13 @@ dependencies = [
"checksum mio 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a637d1ca14eacae06296a008fa7ad955347e34efcb5891cfd8ba05491a37907e"
"checksum mio 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)" = "7da01a5e23070d92d99b1ecd1cd0af36447c6fd44b0fe283c2db199fa136724f"
"checksum mio-uds 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)" = "1731a873077147b626d89cc6c2a0db6288d607496c5d10c0cfcf3adc697ec673"
-"checksum mio-utun 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)" = "0e504ce6f352bb5d0407354b47f13c7e36e68e987724660a63e9d10ee550eaa1"
+"checksum mio-utun 0.6.14 (registry+https://github.com/rust-lang/crates.io-index)" = "0472ddb1b3576556f2e65d66d1abfdb62364f33da4da69b3dd3a6853ef0de6de"
"checksum miow 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "3e690c5df6b2f60acd45d56378981e827ff8295562fc8d34f573deb267a59cd1"
"checksum miow 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f2f3b1cf331de6896aabf6e9d55dca90356cc9960cca7eaaf408a355ae919"
"checksum net2 0.2.32 (registry+https://github.com/rust-lang/crates.io-index)" = "9044faf1413a1057267be51b5afba8eb1090bd2231c693664aa1db716fe1eae0"
"checksum nix 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b7fd5681d13fda646462cfbd4e5f2051279a89a544d50eb98c365b507246839f"
+"checksum nix 0.11.0-pre (git+https://github.com/mcginty/nix?branch=so_mark)" = "<none>"
"checksum nix 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "bfb3ddedaa14746434a02041940495bf11325c22f6d36125d3bdd56090d50a79"
-"checksum nix 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a2c5afeb0198ec7be8569d666644b574345aad2e95a53baf3a532da3e0f3fb32"
"checksum nodrop 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)" = "9a2228dca57108069a5262f2ed8bd2e82496d2e074a06d1ccc7ce1687b6ae0a2"
"checksum notify 4.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "5c3812da3098f210a0bb440f9c008471a031aa4c1de07a264fdd75456c95a4eb"
"checksum num 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "4703ad64153382334aa8db57c637364c322d3372e097840c72000dabdcf6156e"
@@ -1509,7 +1511,7 @@ dependencies = [
"checksum tokio-signal 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "c4ef9836ecceb2583e0ddf25b7ca448fac74c1115461436f85e088a8e39e7904"
"checksum tokio-timer 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6131e780037787ff1b3f8aad9da83bca02438b72277850dd6ad0d455e0e20efc"
"checksum tokio-uds 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "65ae5d255ce739e8537221ed2942e0445f4b3b813daebac1c0050ddaaa3587f9"
-"checksum tokio-utun 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "e3c3d6da8399241b102b0591422fec1b116b5f3c8bd47c00485ab776caedcd1d"
+"checksum tokio-utun 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "c564eb0820dec975a2f4e4039900d097579c6f4eee345ddbf5fe84478a01a733"
"checksum treebitmap 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1efcc0a760c155a5eff13249f6d3339b7000278f24360db9e4c80fab798c79c5"
"checksum typenum 1.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "13a99dc6780ef33c78780b826cf9d2a78840b72cae9474de4bcaf9051e60ebbd"
"checksum unicode-width 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "bf3a113775714a22dcb774d8ea3655c53a32debae63a063acc00a91cc586245f"
diff --git a/Cargo.toml b/Cargo.toml
index 5c8ba3a..f61f898 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -41,7 +41,7 @@ log = "^0.4"
hex = "^0.3"
notify = "4.0.0"
rand = "^0.4"
-nix = "^0.10"
+nix = { git = "https://github.com/mcginty/nix", branch = "so_mark"} # TODO waiting on https://github.com/nix-rust/nix/pull/873
mio = "^0.6"
pnet_packet = "^0.20"
snow = { git = "https://github.com/mcginty/snow", features = ["ring-accelerated"], branch = "wireguard" }
@@ -50,7 +50,7 @@ subtle = "^0.5"
tokio-io = "^0.1"
tokio-core = "^0.1"
tokio-uds = "^0.1"
-tokio-utun = "^0.1"
+tokio-utun = "^0.1.9"
tokio-timer = "^0.1"
tokio-signal = "^0.1"
treebitmap = "^0.2"
diff --git a/benches/criterion.rs b/benches/criterion.rs
index 955d384..83471b8 100644
--- a/benches/criterion.rs
+++ b/benches/criterion.rs
@@ -19,8 +19,8 @@ use pnet_packet::{Packet, ipv4::MutableIpv4Packet};
use socket2::{Socket, Domain, Type, Protocol};
struct Keypair {
- pub private: [u8; 32],
- pub public: [u8; 32]
+ pub private : [u8; 32],
+ pub public : [u8; 32]
}
impl Keypair {
@@ -29,7 +29,7 @@ impl Keypair {
let private = generate_secret(&mut rng);
let public = generate_public(&private).to_bytes();
- Keypair{ private, public}
+ Keypair { private, public }
}
}
diff --git a/src/interface/config.rs b/src/interface/config.rs
index 71ca155..a80d0a5 100644
--- a/src/interface/config.rs
+++ b/src/interface/config.rs
@@ -25,6 +25,7 @@ pub enum Command {
#[allow(dead_code)]
pub enum UpdateEvent {
PrivateKey([u8; 32]),
+ Fwmark(u32),
ListenPort(u16),
UpdatePeer(PeerInfo, bool),
RemovePeer([u8; 32]),
@@ -43,6 +44,7 @@ impl UpdateEvent {
match key.as_ref() {
"private_key" => { events.push(UpdateEvent::PrivateKey(<[u8; 32]>::from_hex(&value)?)); },
"listen_port" => { events.push(UpdateEvent::ListenPort(value.parse()?)); },
+ "fwmark" => { events.push(UpdateEvent::Fwmark(value.parse()?)); },
"replace_peers" => { events.push(UpdateEvent::RemoveAllPeers); },
"preshared_key" => { info.psk = Some(<[u8; 32]>::from_hex(&value)?); },
"persistent_keepalive_interval" => { info.keepalive = Some(value.parse()?); },
@@ -71,7 +73,7 @@ impl UpdateEvent {
// "flush" the final peer if there is one
match (pending_peer, remove_pending_peer) {
- (true, true) => events.push(UpdateEvent::RemovePeer(info.pub_key)),
+ (true, true ) => events.push(UpdateEvent::RemovePeer(info.pub_key)),
(true, false) => events.push(UpdateEvent::UpdatePeer(info, replace_allowed_ips)),
_ => {}
}
diff --git a/src/interface/mod.rs b/src/interface/mod.rs
index c6b673c..e8c799c 100644
--- a/src/interface/mod.rs
+++ b/src/interface/mod.rs
@@ -188,6 +188,10 @@ impl Interface {
state.interface_info.listen_port = Some(port);
info!("set listen port: {}", port);
},
+ UpdateEvent::Fwmark(mark) => {
+ state.interface_info.fwmark = Some(mark);
+ info!("set fwmark: {}", mark);
+ }
UpdateEvent::UpdatePeer(ref info, replace_allowed_ips) => {
let existing_peer = state.pubkey_map.get(&info.pub_key).cloned();
if let Some(peer_ref) = existing_peer {
diff --git a/src/interface/peer_server.rs b/src/interface/peer_server.rs
index ca17623..6e91477 100644
--- a/src/interface/peer_server.rs
+++ b/src/interface/peer_server.rs
@@ -13,7 +13,7 @@ use byteorder::{ByteOrder, LittleEndian};
use failure::{Error, err_msg};
use futures::{Async, Future, Stream, Sink, Poll, unsync::mpsc};
use rand::{self, Rng};
-use udp::{UdpSocket, VecUdpCodec, PeerServerMessage, UdpChannel};
+use udp::{UdpSocket, PeerServerMessage, UdpChannel};
use tokio_core::reactor::Handle;
struct Channel<T> {
@@ -57,7 +57,10 @@ impl PeerServer {
}
pub fn rebind(&mut self) -> Result<(), Error> {
- let port = self.shared_state.borrow().interface_info.listen_port.unwrap_or(0);
+ let interface = &self.shared_state.borrow().interface_info;
+ let port = interface.listen_port.unwrap_or(0);
+ let fwmark = interface.fwmark.unwrap_or(0);
+
if self.port.is_some() && self.port.unwrap() == port {
debug!("skipping rebind, since we're already listening on the correct port.");
return Ok(())
@@ -66,7 +69,11 @@ impl PeerServer {
let socket = UdpSocket::bind((Ipv6Addr::unspecified(), port).into(), self.handle.clone())?;
info!("listening on {:?}", socket.local_addr()?);
- let udp = socket.framed().into();
+ let udp: UdpChannel = socket.framed().into();
+
+ if fwmark != 0 {
+ udp.set_mark(fwmark)?;
+ }
self.udp = Some(udp);
self.port = Some(port);
@@ -406,6 +413,11 @@ impl Future for PeerServer {
}
},
ListenPort(_) => self.rebind().unwrap(),
+ Fwmark(mark) => {
+ if let Some(ref udp) = self.udp {
+ udp.set_mark(mark).unwrap();
+ }
+ }
_ => {}
}
},
diff --git a/src/peer.rs b/src/peer.rs
index 3ec8aaf..e6712ed 100644
--- a/src/peer.rs
+++ b/src/peer.rs
@@ -15,7 +15,6 @@ use std::time::{SystemTime, UNIX_EPOCH};
use hex;
use time::{Tai64n, Timestamp};
use snow;
-use udp::{UdpFramed, VecUdpCodec};
use types::PeerInfo;
pub struct Peer {
diff --git a/src/types.rs b/src/types.rs
index 412d184..9f2597b 100644
--- a/src/types.rs
+++ b/src/types.rs
@@ -23,4 +23,5 @@ pub struct InterfaceInfo {
pub private_key: Option<[u8; 32]>,
pub pub_key: Option<[u8; 32]>,
pub listen_port: Option<u16>,
+ pub fwmark: Option<u32>,
}
diff --git a/src/udp/frame.rs b/src/udp/frame.rs
index 252eea4..450a75a 100644
--- a/src/udp/frame.rs
+++ b/src/udp/frame.rs
@@ -1,7 +1,10 @@
use std::io;
use std::net::{SocketAddr, Ipv4Addr, SocketAddrV4, IpAddr};
+use std::os::unix::io::{AsRawFd, RawFd};
+use failure::Error;
use futures::{Async, Future, Poll, Stream, Sink, StartSend, AsyncSink, future, stream, unsync::mpsc};
+use nix::sys::socket::{sockopt, setsockopt};
use udp::{ConnectedUdpSocket, UdpSocket};
use tokio_core::reactor::Handle;
@@ -26,10 +29,10 @@ pub struct UdpFramed {
}
impl UdpFramed {
- pub fn handle(&self) -> &Handle {
+ pub fn socket(&self) -> &UdpSocket {
match self.socket {
- Socket::Unconnected(ref socket) => &socket.handle,
- Socket::Connected(ref socket) => &socket.inner.handle,
+ Socket::Unconnected(ref socket) => &socket,
+ Socket::Connected(ref socket) => &socket.inner,
}
}
}
@@ -183,12 +186,14 @@ impl VecUdpCodec {
pub struct UdpChannel {
pub ingress : stream::SplitStream<UdpFramed>,
pub egress : mpsc::Sender<PeerServerMessage>,
+ pub fd : RawFd,
handle : Handle,
}
impl From<UdpFramed> for UdpChannel {
fn from(framed: UdpFramed) -> Self {
- let handle = framed.handle().clone();
+ let fd = framed.socket().as_raw_fd();
+ let handle = framed.socket().handle.clone();
let (udp_sink, ingress) = framed.split();
let (egress, egress_rx) = mpsc::channel(1024);
let udp_writethrough = udp_sink
@@ -202,7 +207,7 @@ impl From<UdpFramed> for UdpChannel {
handle.spawn(udp_writethrough);
- UdpChannel { egress, ingress, handle }
+ UdpChannel { egress, ingress, fd, handle }
}
}
@@ -210,4 +215,14 @@ impl UdpChannel {
pub fn send(&self, message: PeerServerMessage) {
self.handle.spawn(self.egress.clone().send(message).then(|_| Ok(())));
}
+
+ #[cfg(target_os = "linux")]
+ pub fn set_mark(&self, mark: u32) -> Result<(), Error> {
+ setsockopt(self.fd, sockopt::Mark, &mark)
+ }
+
+ #[cfg(not(target_os = "linux"))]
+ pub fn set_mark(&self, _mark: u32) -> Result<(), Error> {
+ Ok(())
+ }
}