summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorLinus Färnstrand <linus@mullvad.net>2017-09-06 15:26:39 +0200
committerLinus Färnstrand <linus@mullvad.net>2017-09-06 19:46:25 +0200
commit3e65f6b6e435ed562a417a7f962fc5e167aa7f51 (patch)
tree63461ea07d0bbd2ca246035fcba47eee85c6cab1
parenta4dad7cb03b9bb9e91775c7058df7fe8a13971f5 (diff)
downloadmullvadvpn-3e65f6b6e435ed562a417a7f962fc5e167aa7f51.tar.xz
mullvadvpn-3e65f6b6e435ed562a417a7f962fc5e167aa7f51.zip
Add dev field to tunnel up event variant
-rw-r--r--talpid-core/src/tunnel/mod.rs21
1 files changed, 15 insertions, 6 deletions
diff --git a/talpid-core/src/tunnel/mod.rs b/talpid-core/src/tunnel/mod.rs
index 489fdc8a94..49d1d7dd44 100644
--- a/talpid-core/src/tunnel/mod.rs
+++ b/talpid-core/src/tunnel/mod.rs
@@ -5,6 +5,7 @@ use openvpn_plugin::types::OpenVpnPluginEvent;
use process::openvpn::OpenVpnCommand;
+use std::collections::HashMap;
use std::env;
use std::ffi::{OsStr, OsString};
use std::fs;
@@ -42,10 +43,13 @@ pub use self::errors::*;
/// Possible events from the VPN tunnel and the child process managing it.
-#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
+#[derive(Debug, Clone, Eq, PartialEq, Hash)]
pub enum TunnelEvent {
/// Sent when the tunnel comes up and is ready for traffic.
- Up,
+ Up {
+ /// The name of the device which the tunnel is running on.
+ dev: String,
+ },
/// Sent when the tunnel goes down.
Down,
}
@@ -53,9 +57,14 @@ pub enum TunnelEvent {
impl TunnelEvent {
/// Converts an `OpenVpnPluginEvent` to a `TunnelEvent`.
/// Returns `None` if there is no corresponding `TunnelEvent`.
- fn from_openvpn_event(event: &OpenVpnPluginEvent) -> Option<TunnelEvent> {
+ fn from_openvpn_event(event: &OpenVpnPluginEvent,
+ env: &HashMap<String, String>)
+ -> Option<TunnelEvent> {
match *event {
- OpenVpnPluginEvent::Up => Some(TunnelEvent::Up),
+ OpenVpnPluginEvent::Up => {
+ let dev = env.get("dev").expect("No \"dev\" in tunnel up event").to_owned();
+ Some(TunnelEvent::Up { dev })
+ }
OpenVpnPluginEvent::RoutePredown => Some(TunnelEvent::Down),
_ => None,
}
@@ -81,12 +90,12 @@ impl TunnelMonitor {
let cmd = Self::create_openvpn_cmd(remote, user_pass_file.as_ref());
let user_pass_file_path = user_pass_file.to_path_buf();
- let on_openvpn_event = move |event, _env| {
+ let on_openvpn_event = move |event, env| {
if event == OpenVpnPluginEvent::Up {
// The user-pass file has been read. Try to delete it early.
let _ = fs::remove_file(&user_pass_file_path);
}
- match TunnelEvent::from_openvpn_event(&event) {
+ match TunnelEvent::from_openvpn_event(&event, &env) {
Some(tunnel_event) => on_event(tunnel_event),
None => debug!("Ignoring OpenVpnEvent {:?}", event),
}