diff options
| author | Emīls <emils@mullvad.net> | 2018-06-12 23:35:43 +0100 |
|---|---|---|
| committer | Emīls <emils@mullvad.net> | 2018-06-27 11:42:41 +0100 |
| commit | 3bb3c719ffffcf41dcfd20cedf60cc9d9cc17434 (patch) | |
| tree | f19c72f1349185c609b6b71bffd639b564b656e3 | |
| parent | c35ed12fa10886b17b5f6a71be51870eb482d898 (diff) | |
| download | mullvadvpn-3bb3c719ffffcf41dcfd20cedf60cc9d9cc17434.tar.xz mullvadvpn-3bb3c719ffffcf41dcfd20cedf60cc9d9cc17434.zip | |
Add route.rs to talpid-core/src/firewall/windows/
| -rw-r--r-- | talpid-core/src/firewall/windows/mod.rs | 1 | ||||
| -rw-r--r-- | talpid-core/src/firewall/windows/route.rs | 43 |
2 files changed, 44 insertions, 0 deletions
diff --git a/talpid-core/src/firewall/windows/mod.rs b/talpid-core/src/firewall/windows/mod.rs index 01c6dd4c53..64fe32191f 100644 --- a/talpid-core/src/firewall/windows/mod.rs +++ b/talpid-core/src/firewall/windows/mod.rs @@ -15,6 +15,7 @@ use self::widestring::WideCString; mod ffi; mod dns; mod system_state; +mod route; use self::dns::WinDns; diff --git a/talpid-core/src/firewall/windows/route.rs b/talpid-core/src/firewall/windows/route.rs new file mode 100644 index 0000000000..c66dfbfabd --- /dev/null +++ b/talpid-core/src/firewall/windows/route.rs @@ -0,0 +1,43 @@ +use super::ffi; +use super::widestring::WideCString; +use libc; +use std::ptr; + +error_chain!{ + errors{ + /// Failure to set metrics of network interfaces + MetricApplication{ + description("Failed to set the metrics for a network interface") + } + } +} + +// Returns true if metrics were changed, false otherwise +pub fn ensure_top_metric_for_interface(interface_alias: &str) -> Result<bool> { + let interface_alias_ws = + WideCString::new(interface_alias.encode_utf16().collect::<Vec<_>>()).unwrap(); + match unsafe { + WinRoute_EnsureTopMetric( + interface_alias_ws.as_wide_c_str().as_ptr(), + Some(ffi::error_sink), + ptr::null_mut(), + ) + } { + 0 => Ok(false), + 1 => Ok(true), + -1 => Err(Error::from(ErrorKind::MetricApplication)), + _ => { + error!("Unexpected return code from WinRoute_EnsureTopMetric"); + Err(Error::from(ErrorKind::MetricApplication)) + } + } +} + +extern "system" { + #[link_name(WinRoute_EnsureTopMetric)] + pub fn WinRoute_EnsureTopMetric( + tunnel_interface_alias: *const libc::wchar_t, + sink: Option<ffi::ErrorSink>, + sink_context: *mut libc::c_void, + ) -> i32; +} |
