diff options
| -rw-r--r-- | Cargo.lock | 23 | ||||
| -rw-r--r-- | mullvad-daemon/Cargo.toml | 1 | ||||
| -rw-r--r-- | mullvad-daemon/src/main.rs | 22 | ||||
| -rw-r--r-- | mullvad-types/Cargo.toml | 2 | ||||
| -rw-r--r-- | mullvad-types/src/lib.rs | 2 | ||||
| -rw-r--r-- | mullvad-types/src/relay_endpoint.rs | 5 | ||||
| -rw-r--r-- | talpid-core/Cargo.toml | 1 | ||||
| -rw-r--r-- | talpid-core/src/firewall/macos.rs | 33 | ||||
| -rw-r--r-- | talpid-core/src/firewall/mod.rs | 2 | ||||
| -rw-r--r-- | talpid-core/src/lib.rs | 4 | ||||
| -rw-r--r-- | talpid-core/src/process/openvpn.rs | 6 | ||||
| -rw-r--r-- | talpid-core/src/tunnel/mod.rs | 2 | ||||
| -rw-r--r-- | talpid-types/Cargo.toml | 9 | ||||
| -rw-r--r-- | talpid-types/src/lib.rs | 13 | ||||
| -rw-r--r-- | talpid-types/src/net.rs (renamed from talpid-core/src/net.rs) | 15 |
15 files changed, 85 insertions, 55 deletions
diff --git a/Cargo.lock b/Cargo.lock index 91b97a1db7..4ea00f8d59 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,12 +1,9 @@ [root] -name = "talpid-openvpn-plugin" +name = "talpid-types" version = "0.1.0" dependencies = [ - "env_logger 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", - "error-chain 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", - "openvpn-plugin 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "talpid-ipc 0.1.0", + "serde 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -673,6 +670,7 @@ dependencies = [ "simple-signal 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "talpid-core 0.1.0", "talpid-ipc 0.1.0", + "talpid-types 0.1.0", "toml 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "uuid 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -684,6 +682,7 @@ dependencies = [ "chrono 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)", + "talpid-types 0.1.0", ] [[package]] @@ -1184,6 +1183,7 @@ dependencies = [ "openvpn-plugin 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "pfctl 0.1.0 (git+https://github.com/mullvad/pfctl-rs.git)", "talpid-ipc 0.1.0", + "talpid-types 0.1.0", "uuid 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1205,6 +1205,17 @@ dependencies = [ ] [[package]] +name = "talpid-openvpn-plugin" +version = "0.1.0" +dependencies = [ + "env_logger 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", + "error-chain 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "openvpn-plugin 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "talpid-ipc 0.1.0", +] + +[[package]] name = "tempdir" version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" diff --git a/mullvad-daemon/Cargo.toml b/mullvad-daemon/Cargo.toml index 786baac7a3..b355c4bf53 100644 --- a/mullvad-daemon/Cargo.toml +++ b/mullvad-daemon/Cargo.toml @@ -32,6 +32,7 @@ toml = "0.4" mullvad-types = { path = "../mullvad-types" } talpid-core = { path = "../talpid-core" } talpid-ipc = { path = "../talpid-ipc" } +talpid-types = { path = "../talpid-types" } [target.'cfg(unix)'.dependencies] simple-signal = "1.1" diff --git a/mullvad-daemon/src/main.rs b/mullvad-daemon/src/main.rs index 17b6df06d5..d548eb3e03 100644 --- a/mullvad-daemon/src/main.rs +++ b/mullvad-daemon/src/main.rs @@ -35,6 +35,7 @@ extern crate lazy_static; extern crate mullvad_types; extern crate talpid_core; extern crate talpid_ipc; +extern crate talpid_types; mod cli; mod management_interface; @@ -57,14 +58,13 @@ use mullvad_types::states::{DaemonState, SecurityState, TargetState}; use std::io; use std::net::{Ipv4Addr, SocketAddr, ToSocketAddrs}; use std::path::PathBuf; -use std::str::FromStr; use std::sync::{Arc, Mutex, mpsc}; use std::thread; use talpid_core::firewall::{Firewall, FirewallProxy, SecurityPolicy}; use talpid_core::mpsc::IntoSender; -use talpid_core::net::{Endpoint, TransportProtocol}; use talpid_core::tunnel::{self, TunnelEvent, TunnelMonitor}; +use talpid_types::net::{Endpoint, TransportProtocol}; error_chain!{ errors { @@ -544,17 +544,13 @@ impl Daemon { ) } - let protocol = TransportProtocol::from_str(&relay_endpoint.protocol) - .map_err( - |_| { - format!( - "Invalid custom server protocol: {}", - relay_endpoint.protocol - ) - }, - )?; - - Ok(Endpoint::new(socket_addr.ip(), socket_addr.port(), protocol),) + Ok( + Endpoint::new( + socket_addr.ip(), + socket_addr.port(), + relay_endpoint.protocol, + ), + ) } } diff --git a/mullvad-types/Cargo.toml b/mullvad-types/Cargo.toml index 148970e428..3f6c13f0dc 100644 --- a/mullvad-types/Cargo.toml +++ b/mullvad-types/Cargo.toml @@ -8,3 +8,5 @@ license = "GPL-3.0" chrono = { version = "0.4", features = ["serde"] } serde_derive = "1.0" serde = "1.0" + +talpid-types = { path = "../talpid-types" } diff --git a/mullvad-types/src/lib.rs b/mullvad-types/src/lib.rs index cc4f035c93..2801efefad 100644 --- a/mullvad-types/src/lib.rs +++ b/mullvad-types/src/lib.rs @@ -11,6 +11,8 @@ extern crate chrono; extern crate serde_derive; extern crate serde; +extern crate talpid_types; + pub mod account; pub mod location; pub mod states; diff --git a/mullvad-types/src/relay_endpoint.rs b/mullvad-types/src/relay_endpoint.rs index d02f9d9d56..d5a80a5879 100644 --- a/mullvad-types/src/relay_endpoint.rs +++ b/mullvad-types/src/relay_endpoint.rs @@ -1,14 +1,15 @@ use std::fmt; +use talpid_types::net::TransportProtocol; #[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)] pub struct RelayEndpoint { pub host: String, pub port: u16, - pub protocol: String, + pub protocol: TransportProtocol, } impl fmt::Display for RelayEndpoint { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { - write!(fmt, "{}:{} - {}", self.host, self.port, self.protocol) + write!(fmt, "{}:{} - {:?}", self.host, self.port, self.protocol) } } diff --git a/talpid-core/Cargo.toml b/talpid-core/Cargo.toml index 9b9cada258..ba70f49071 100644 --- a/talpid-core/Cargo.toml +++ b/talpid-core/Cargo.toml @@ -16,6 +16,7 @@ uuid = { version = "0.5", features = ["v4"] } openvpn-plugin = { version = "0.2", features = ["serialize"] } talpid-ipc = { path = "../talpid-ipc" } +talpid-types = { path = "../talpid-types" } [target.'cfg(unix)'.dependencies] libc = "0.2.20" diff --git a/talpid-core/src/firewall/macos.rs b/talpid-core/src/firewall/macos.rs index 5be5d4764e..8f0ba7a897 100644 --- a/talpid-core/src/firewall/macos.rs +++ b/talpid-core/src/firewall/macos.rs @@ -1,7 +1,7 @@ use super::{Firewall, SecurityPolicy}; -use net; use pfctl; use std::net::Ipv4Addr; +use talpid_types::net; // alias used to instantiate firewall implementation pub type ConcreteFirewall = PacketFilter; @@ -9,15 +9,6 @@ pub use pfctl::{Error, ErrorKind, Result}; const ANCHOR_NAME: &'static str = "talpid_core"; -impl From<net::TransportProtocol> for pfctl::Proto { - fn from(protocol: net::TransportProtocol) -> Self { - match protocol { - net::TransportProtocol::Udp => pfctl::Proto::Udp, - net::TransportProtocol::Tcp => pfctl::Proto::Tcp, - } - } -} - pub struct PacketFilter { pf: pfctl::PfCtl, pf_was_enabled: Option<bool>, @@ -85,11 +76,14 @@ impl PacketFilter { } fn get_relay_rule(relay_endpoint: net::Endpoint) -> Result<pfctl::FilterRule> { + let pfctl_endpoint = as_pfctl_endpoint(relay_endpoint); + let pfctl_proto = as_pfctl_proto(relay_endpoint.protocol); + pfctl::FilterRuleBuilder::default() .action(pfctl::FilterRuleAction::Pass) .direction(pfctl::Direction::Out) - .to(relay_endpoint.address) - .proto(relay_endpoint.protocol) + .to(pfctl_endpoint) + .proto(pfctl_proto) .keep_state(pfctl::StatePolicy::Keep) .tcp_flags(Self::get_tcp_flags()) .quick(true) @@ -174,3 +168,18 @@ impl PacketFilter { self.pf.try_remove_anchor(ANCHOR_NAME, pfctl::AnchorKind::Filter) } } + +fn as_pfctl_endpoint(relay_endpoint: net::Endpoint) -> pfctl::Endpoint { + pfctl::Endpoint::new( + pfctl::Ip::from(relay_endpoint.address.ip()), + pfctl::Port::from(relay_endpoint.address.port()) + ) +} + +fn as_pfctl_proto(protocol: net::TransportProtocol) -> pfctl::Proto { + match protocol { + net::TransportProtocol::Udp => pfctl::Proto::Udp, + net::TransportProtocol::Tcp => pfctl::Proto::Tcp, + } +} + diff --git a/talpid-core/src/firewall/mod.rs b/talpid-core/src/firewall/mod.rs index 16b8139453..acc0f21792 100644 --- a/talpid-core/src/firewall/mod.rs +++ b/talpid-core/src/firewall/mod.rs @@ -1,4 +1,4 @@ -use net::Endpoint; +use talpid_types::net::Endpoint; #[cfg(target_os = "macos")] #[path = "macos.rs"] diff --git a/talpid-core/src/lib.rs b/talpid-core/src/lib.rs index 271553c10c..c4cff6ebfc 100644 --- a/talpid-core/src/lib.rs +++ b/talpid-core/src/lib.rs @@ -30,6 +30,7 @@ extern crate jsonrpc_macros; extern crate uuid; extern crate talpid_ipc; +extern crate talpid_types; extern crate openvpn_plugin; #[cfg(target_os = "macos")] @@ -38,9 +39,6 @@ extern crate pfctl; /// Working with processes. pub mod process; -/// Network primitives. -pub mod net; - /// Abstracts over different VPN tunnel technologies pub mod tunnel; diff --git a/talpid-core/src/process/openvpn.rs b/talpid-core/src/process/openvpn.rs index ce663809ce..c756757a75 100644 --- a/talpid-core/src/process/openvpn.rs +++ b/talpid-core/src/process/openvpn.rs @@ -1,11 +1,11 @@ use duct; -use net; - use std::ffi::{OsStr, OsString}; use std::fmt; use std::path::{Path, PathBuf}; +use talpid_types::net; + static BASE_ARGUMENTS: &[&[&str]] = &[ &["--client"], &["--nobind"], @@ -190,9 +190,9 @@ fn write_argument(fmt: &mut fmt::Formatter, arg: &str) -> fmt::Result { #[cfg(test)] mod tests { use super::OpenVpnCommand; - use net::{Endpoint, TransportProtocol}; use std::ffi::OsString; use std::net::Ipv4Addr; + use talpid_types::net::{Endpoint, TransportProtocol}; #[test] fn passes_one_remote() { diff --git a/talpid-core/src/tunnel/mod.rs b/talpid-core/src/tunnel/mod.rs index a2ab25a487..83212e6874 100644 --- a/talpid-core/src/tunnel/mod.rs +++ b/talpid-core/src/tunnel/mod.rs @@ -1,5 +1,4 @@ use mktemp; -use net; use openvpn_plugin::types::OpenVpnPluginEvent; @@ -11,6 +10,7 @@ use std::ffi::{OsStr, OsString}; use std::fs; use std::io::{self, Write}; use std::path::{Path, PathBuf}; +use talpid_types::net; /// A module for all OpenVPN related tunnel management. pub mod openvpn; diff --git a/talpid-types/Cargo.toml b/talpid-types/Cargo.toml new file mode 100644 index 0000000000..4e1e7f9171 --- /dev/null +++ b/talpid-types/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "talpid-types" +version = "0.1.0" +authors = ["Linus Färnstrand <linus@mullvad.net>"] +license = "GPL-3.0" + +[dependencies] +serde_derive = "1.0" +serde = "1.0" diff --git a/talpid-types/src/lib.rs b/talpid-types/src/lib.rs new file mode 100644 index 0000000000..c32daa26d3 --- /dev/null +++ b/talpid-types/src/lib.rs @@ -0,0 +1,13 @@ +//! # License +//! +//! Copyright (C) 2017 Amagicom AB +//! +//! This program is free software: you can redistribute it and/or modify it under the terms of the +//! GNU General Public License as published by the Free Software Foundation, either version 3 of +//! the License, or (at your option) any later version. + +#[macro_use] +extern crate serde_derive; +extern crate serde; + +pub mod net; diff --git a/talpid-core/src/net.rs b/talpid-types/src/net.rs index 9a75859d61..e1052d0571 100644 --- a/talpid-core/src/net.rs +++ b/talpid-types/src/net.rs @@ -1,5 +1,4 @@ use std::net::{IpAddr, SocketAddr}; -use std::str::FromStr; /// Represents a network layer IP address together with the transport layer protocol and port. #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] @@ -21,22 +20,10 @@ impl Endpoint { } /// Representation of a transport protocol, either UDP or TCP. -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)] pub enum TransportProtocol { /// Represents the UDP transport protocol. Udp, /// Represents the TCP transport protocol. Tcp, } - -impl FromStr for TransportProtocol { - type Err = (); - - fn from_str(s: &str) -> ::std::result::Result<TransportProtocol, Self::Err> { - match s { - "udp" => Ok(TransportProtocol::Udp), - "tcp" => Ok(TransportProtocol::Tcp), - _ => Err(()), - } - } -} |
