diff options
| author | Emīls Piņķis <emils@mullvad.net> | 2019-03-13 11:49:28 +0000 |
|---|---|---|
| committer | Emīls Piņķis <emils@mullvad.net> | 2019-03-13 11:49:28 +0000 |
| commit | 50d3d18d4710949179e19372bdcd7cbe93fbb260 (patch) | |
| tree | af07f053f433b2eb34492a3833c949990fe7fc16 | |
| parent | 0a68c13474728660b936f37abc283c1d1aeb1780 (diff) | |
| parent | db408ea051da355307a4ba57c01f5cc64320b009 (diff) | |
| download | mullvadvpn-50d3d18d4710949179e19372bdcd7cbe93fbb260.tar.xz mullvadvpn-50d3d18d4710949179e19372bdcd7cbe93fbb260.zip | |
Merge branch 'wg-rework-ping'
| -rw-r--r-- | talpid-core/src/tunnel/wireguard/mod.rs | 5 | ||||
| -rw-r--r-- | talpid-core/src/tunnel/wireguard/ping_monitor.rs | 43 | ||||
| -rw-r--r-- | talpid-core/src/tunnel_state_machine/connecting_state.rs | 1 |
3 files changed, 34 insertions, 15 deletions
diff --git a/talpid-core/src/tunnel/wireguard/mod.rs b/talpid-core/src/tunnel/wireguard/mod.rs index 65897d9d23..5bcaff847f 100644 --- a/talpid-core/src/tunnel/wireguard/mod.rs +++ b/talpid-core/src/tunnel/wireguard/mod.rs @@ -11,7 +11,7 @@ pub mod wireguard_go; pub use self::wireguard_go::WgGoTunnel; // amount of seconds to run `ping` until it returns. -const PING_TIMEOUT: u16 = 5; +const PING_TIMEOUT: u16 = 7; error_chain! { errors { @@ -76,15 +76,16 @@ impl WireguardMonitor { close_msg_receiver, }; monitor.setup_routing(&config)?; - monitor.start_pinger(&config); monitor.tunnel_up(&config); ping_monitor::ping( config.ipv4_gateway.into(), PING_TIMEOUT, &monitor.tunnel.get_interface_name().to_string(), + true, ) .chain_err(|| ErrorKind::PingTimeoutError)?; + monitor.start_pinger(&config); Ok(monitor) } diff --git a/talpid-core/src/tunnel/wireguard/ping_monitor.rs b/talpid-core/src/tunnel/wireguard/ping_monitor.rs index 58f2904c88..e6cdd1b033 100644 --- a/talpid-core/src/tunnel/wireguard/ping_monitor.rs +++ b/talpid-core/src/tunnel/wireguard/ping_monitor.rs @@ -20,7 +20,7 @@ pub fn spawn_ping_monitor<F: FnOnce() + Send + 'static>( ) { thread::spawn(move || loop { let start = time::Instant::now(); - if let Err(e) = ping(ip, timeout_secs, &interface) { + if let Err(e) = ping(ip, timeout_secs, &interface, false) { log::debug!("ping failed - {}", e); on_fail(); return; @@ -33,8 +33,13 @@ pub fn spawn_ping_monitor<F: FnOnce() + Send + 'static>( }); } -pub fn ping(ip: IpAddr, timeout_secs: u16, interface: &str) -> Result<()> { - let output = ping_cmd(ip, timeout_secs, interface) +pub fn ping( + ip: IpAddr, + timeout_secs: u16, + interface: &str, + exit_on_first_reply: bool, +) -> Result<()> { + let output = ping_cmd(ip, timeout_secs, interface, exit_on_first_reply) .run() .chain_err(|| ErrorKind::PingError)?; if !output.status.success() { @@ -43,7 +48,12 @@ pub fn ping(ip: IpAddr, timeout_secs: u16, interface: &str) -> Result<()> { Ok(()) } -fn ping_cmd(ip: IpAddr, timeout_secs: u16, interface: &str) -> duct::Expression { +fn ping_cmd( + ip: IpAddr, + timeout_secs: u16, + interface: &str, + exit_on_first_reply: bool, +) -> duct::Expression { let interface_flag = if cfg!(target_os = "linux") { "-I" } else { @@ -54,18 +64,25 @@ fn ping_cmd(ip: IpAddr, timeout_secs: u16, interface: &str) -> duct::Expression } else { "-t" }; - duct::cmd!( - "ping", + + let timeout_secs = timeout_secs.to_string(); + let ip = ip.to_string(); + + let mut args = vec![ "-n", - "-c", + "-i", "1", &interface_flag, &interface, timeout_flag, - &timeout_secs.to_string(), - ip.to_string() - ) - .stdin_null() - .stdout_null() - .unchecked() + &timeout_secs, + &ip, + ]; + if exit_on_first_reply { + args.push("-o"); + } + duct::cmd("ping", args) + .stdin_null() + .stdout_null() + .unchecked() } diff --git a/talpid-core/src/tunnel_state_machine/connecting_state.rs b/talpid-core/src/tunnel_state_machine/connecting_state.rs index 1588648e4e..78c6deee6b 100644 --- a/talpid-core/src/tunnel_state_machine/connecting_state.rs +++ b/talpid-core/src/tunnel_state_machine/connecting_state.rs @@ -343,6 +343,7 @@ impl TunnelState for ConnectingState { ) } Err(error) => { + log::error!("Failed to start tunnel: {}", error); let block_reason = match *error.kind() { tunnel::ErrorKind::EnableIpv6Error => BlockReason::Ipv6Unavailable, |
