diff options
| author | Odd Stranne <odd@mullvad.net> | 2019-10-11 11:38:40 +0200 |
|---|---|---|
| committer | Odd Stranne <odd@mullvad.net> | 2019-10-11 11:38:40 +0200 |
| commit | 37c95294b3d5745852c32ed419fbb96e49ad3265 (patch) | |
| tree | e5f664a73ff68832bad5401cd52bdf5740d7c4c9 | |
| parent | 7442a8f964fa61eb01e0a82fc76476f781c58cdb (diff) | |
| parent | bf385e708b70210cbe514b4c41d4163084d85834 (diff) | |
| download | mullvadvpn-37c95294b3d5745852c32ed419fbb96e49ad3265.tar.xz mullvadvpn-37c95294b3d5745852c32ed419fbb96e49ad3265.zip | |
Merge branch 'win-unbreak-winfw-logging'
| -rw-r--r-- | talpid-core/src/firewall/windows.rs | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/talpid-core/src/firewall/windows.rs b/talpid-core/src/firewall/windows.rs index 4f32013c39..73dfb8c547 100644 --- a/talpid-core/src/firewall/windows.rs +++ b/talpid-core/src/firewall/windows.rs @@ -1,3 +1,4 @@ +use libc::{c_char, c_void}; use std::{net::IpAddr, ptr}; use self::winfw::*; @@ -45,6 +46,15 @@ const WINFW_TIMEOUT_SECONDS: u32 = 2; /// The Windows implementation for the firewall and DNS. pub struct Firewall(()); +extern "system" fn error_sink(msg: *const c_char, _ctx: *mut c_void) { + use std::ffi::CStr; + if msg.is_null() { + log::error!("Log message from FFI boundary is NULL"); + } else { + log::error!("{}", unsafe { CStr::from_ptr(msg).to_string_lossy() }); + } +} + impl FirewallT for Firewall { type Error = Error; @@ -55,19 +65,15 @@ impl FirewallT for Firewall { WinFw_InitializeBlocked( WINFW_TIMEOUT_SECONDS, &cfg, - Some(winnet::log_sink), + Some(error_sink), ptr::null_mut(), ) .into_result()? }; } else { unsafe { - WinFw_Initialize( - WINFW_TIMEOUT_SECONDS, - Some(winnet::log_sink), - ptr::null_mut(), - ) - .into_result()? + WinFw_Initialize(WINFW_TIMEOUT_SECONDS, Some(error_sink), ptr::null_mut()) + .into_result()? }; } @@ -200,10 +206,12 @@ impl Firewall { #[allow(non_snake_case)] mod winfw { use super::Error; - use crate::winnet; use libc; use talpid_types::net::TransportProtocol; + /// logging callback type for use with `winfw.dll`. + pub type ErrorSink = extern "system" fn(msg: *const libc::c_char, ctx: *mut libc::c_void); + #[repr(C)] pub struct WinFwRelay { pub ip: *const libc::wchar_t, @@ -253,7 +261,7 @@ mod winfw { #[link_name = "WinFw_Initialize"] pub fn WinFw_Initialize( timeout: libc::c_uint, - sink: Option<winnet::LogSink>, + sink: Option<ErrorSink>, sink_context: *mut libc::c_void, ) -> InitializationResult; @@ -261,7 +269,7 @@ mod winfw { pub fn WinFw_InitializeBlocked( timeout: libc::c_uint, settings: &WinFwSettings, - sink: Option<winnet::LogSink>, + sink: Option<ErrorSink>, sink_context: *mut libc::c_void, ) -> InitializationResult; |
