summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorLinus Färnstrand <linus@mullvad.net>2017-09-26 08:50:41 +0200
committerLinus Färnstrand <linus@mullvad.net>2017-09-26 08:50:41 +0200
commit30ce3cccbba086f7a0c668e7950cb539a0eefccc (patch)
tree785203be81c3eeea98bcea2f85f8daf6be440fe1
parent9b5c05408b3589751239cf8363a2c190c7f4371e (diff)
parent66b0e0bc224b6178e39971d58cc332bff750283a (diff)
downloadmullvadvpn-30ce3cccbba086f7a0c668e7950cb539a0eefccc.tar.xz
mullvadvpn-30ce3cccbba086f7a0c668e7950cb539a0eefccc.zip
Merge branch 'log-openvpn-output'2017.1-beta1
-rw-r--r--mullvad-daemon/src/cli.rs11
-rw-r--r--mullvad-daemon/src/main.rs14
-rw-r--r--talpid-core/src/process/openvpn.rs13
-rw-r--r--talpid-core/src/tunnel/mod.rs18
4 files changed, 49 insertions, 7 deletions
diff --git a/mullvad-daemon/src/cli.rs b/mullvad-daemon/src/cli.rs
index 670a2bf28b..215783bc77 100644
--- a/mullvad-daemon/src/cli.rs
+++ b/mullvad-daemon/src/cli.rs
@@ -6,6 +6,7 @@ use std::path::PathBuf;
pub struct Config {
pub log_level: log::LogLevelFilter,
pub log_file: Option<PathBuf>,
+ pub tunnel_log_file: Option<PathBuf>,
}
pub fn get_config() -> Config {
@@ -18,10 +19,12 @@ pub fn get_config() -> Config {
_ => log::LogLevelFilter::Trace,
};
let log_file = matches.value_of_os("log_file").map(PathBuf::from);
+ let tunnel_log_file = matches.value_of_os("tunnel_log_file").map(PathBuf::from);
Config {
log_level,
log_file,
+ tunnel_log_file,
}
}
@@ -42,4 +45,12 @@ fn create_app() -> App<'static, 'static> {
.takes_value(true)
.help("Activates file logging to the given path"),
)
+ .arg(
+ Arg::with_name("tunnel_log_file")
+ .long("tunnel-log")
+ .takes_value(true)
+ .help(
+ "Save log from tunnel implementation process to this file path",
+ ),
+ )
}
diff --git a/mullvad-daemon/src/main.rs b/mullvad-daemon/src/main.rs
index 535d13c0ec..c0687026a3 100644
--- a/mullvad-daemon/src/main.rs
+++ b/mullvad-daemon/src/main.rs
@@ -178,6 +178,7 @@ struct Daemon {
firewall: FirewallProxy,
relay_endpoint: Option<Endpoint>,
tunnel_metadata: Option<TunnelMetadata>,
+ tunnel_log: Option<PathBuf>,
// Just for testing. A cyclic iterator iterating over the hardcoded relays,
// picking a new one for each retry.
@@ -185,7 +186,7 @@ struct Daemon {
}
impl Daemon {
- pub fn new() -> Result<Self> {
+ pub fn new(tunnel_log: Option<PathBuf>) -> Result<Self> {
let (tx, rx) = mpsc::channel();
let management_interface_broadcaster = Self::start_management_interface(tx.clone())?;
let state = TunnelState::NotRunning;
@@ -208,6 +209,7 @@ impl Daemon {
firewall: FirewallProxy::new().chain_err(|| ErrorKind::FirewallError)?,
relay_endpoint: None,
tunnel_metadata: None,
+ tunnel_log: tunnel_log,
relay_iter: RELAYS.iter().cloned().cycle(),
})
}
@@ -530,8 +532,12 @@ impl Daemon {
.unwrap()
.send(DaemonEvent::TunnelEvent(event));
};
- TunnelMonitor::new(relay, account_token, on_tunnel_event)
- .chain_err(|| ErrorKind::TunnelError("Unable to start tunnel monitor"))
+ TunnelMonitor::new(
+ relay,
+ account_token,
+ self.tunnel_log.as_ref().map(PathBuf::as_path),
+ on_tunnel_event,
+ ).chain_err(|| ErrorKind::TunnelError("Unable to start tunnel monitor"))
}
fn spawn_tunnel_monitor_wait_thread(&self, tunnel_monitor: TunnelMonitor) {
@@ -613,7 +619,7 @@ fn run() -> Result<()> {
init_logger(config.log_level, config.log_file.as_ref())?;
log_version();
- let daemon = Daemon::new().chain_err(|| "Unable to initialize daemon")?;
+ let daemon = Daemon::new(config.tunnel_log_file).chain_err(|| "Unable to initialize daemon")?;
let shutdown_handle = daemon.shutdown_handle();
shutdown::set_shutdown_signal_handler(move || shutdown_handle.shutdown())
diff --git a/talpid-core/src/process/openvpn.rs b/talpid-core/src/process/openvpn.rs
index 3398a9baa9..ac3e5911b1 100644
--- a/talpid-core/src/process/openvpn.rs
+++ b/talpid-core/src/process/openvpn.rs
@@ -37,6 +37,7 @@ pub struct OpenVpnCommand {
user_pass_path: Option<PathBuf>,
ca: Option<PathBuf>,
plugin: Option<(PathBuf, Vec<String>)>,
+ log: Option<PathBuf>,
}
impl OpenVpnCommand {
@@ -50,6 +51,7 @@ impl OpenVpnCommand {
user_pass_path: None,
ca: None,
plugin: None,
+ log: None,
}
}
@@ -84,6 +86,12 @@ impl OpenVpnCommand {
self
}
+ /// Sets a log file path.
+ pub fn log<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
+ self.log = Some(path.as_ref().to_path_buf());
+ self
+ }
+
/// Build a runnable expression from the current state of the command.
pub fn build(&self) -> duct::Expression {
debug!("Building expression: {}", &self);
@@ -113,6 +121,11 @@ impl OpenVpnCommand {
args.extend(plugin_args.iter().map(OsString::from));
}
+ if let Some(ref path) = self.log {
+ args.push(OsString::from("--log"));
+ args.push(OsString::from(path))
+ }
+
args.extend(Self::security_arguments().iter().map(OsString::from));
args
diff --git a/talpid-core/src/tunnel/mod.rs b/talpid-core/src/tunnel/mod.rs
index b9e8aa8fa2..6ff4c7d2b9 100644
--- a/talpid-core/src/tunnel/mod.rs
+++ b/talpid-core/src/tunnel/mod.rs
@@ -107,13 +107,18 @@ pub struct TunnelMonitor {
impl TunnelMonitor {
/// Creates a new `TunnelMonitor` that connects to the given remote and notifies `on_event`
/// on tunnel state changes.
- pub fn new<L>(remote: net::Endpoint, account_token: &str, on_event: L) -> Result<Self>
+ pub fn new<L>(
+ remote: net::Endpoint,
+ account_token: &str,
+ log: Option<&Path>,
+ on_event: L,
+ ) -> Result<Self>
where
L: Fn(TunnelEvent) + Send + Sync + 'static,
{
let user_pass_file = Self::create_user_pass_file(account_token)
.chain_err(|| ErrorKind::CredentialsWriteError)?;
- let cmd = Self::create_openvpn_cmd(remote, user_pass_file.as_ref());
+ let cmd = Self::create_openvpn_cmd(remote, user_pass_file.as_ref(), log);
let user_pass_file_path = user_pass_file.to_path_buf();
let on_openvpn_event = move |event, env| {
@@ -135,7 +140,11 @@ impl TunnelMonitor {
})
}
- fn create_openvpn_cmd(remote: net::Endpoint, user_pass_file: &Path) -> OpenVpnCommand {
+ fn create_openvpn_cmd(
+ remote: net::Endpoint,
+ user_pass_file: &Path,
+ log: Option<&Path>,
+ ) -> OpenVpnCommand {
let mut cmd = OpenVpnCommand::new(Self::get_openvpn_bin());
if let Some(config) = Self::get_config_path() {
cmd.config(config);
@@ -143,6 +152,9 @@ impl TunnelMonitor {
cmd.remote(remote)
.user_pass(user_pass_file)
.ca(Self::get_ca_path());
+ if let Some(log) = log {
+ cmd.log(log);
+ }
cmd
}