summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorOdd Stranne <odd@mullvad.net>2019-11-27 12:02:41 +0100
committerOdd Stranne <odd@mullvad.net>2019-12-04 13:07:57 +0100
commit80ce050ad2eee528ded8d5c1d2211534fe7485ae (patch)
treefc1e643117816cf2ebf063326b893011c96ab80a
parent4b7a7bc22d59f8d2e9e28cbec5a8168154dd801f (diff)
downloadmullvadvpn-80ce050ad2eee528ded8d5c1d2211534fe7485ae.tar.xz
mullvadvpn-80ce050ad2eee528ded8d5c1d2211534fe7485ae.zip
Update logging for winfw
-rw-r--r--talpid-core/src/firewall/windows.rs31
1 files changed, 11 insertions, 20 deletions
diff --git a/talpid-core/src/firewall/windows.rs b/talpid-core/src/firewall/windows.rs
index bee16fee3a..38e388ecbf 100644
--- a/talpid-core/src/firewall/windows.rs
+++ b/talpid-core/src/firewall/windows.rs
@@ -1,4 +1,5 @@
-use libc::{c_char, c_void};
+use crate::logging::windows::log_sink;
+
use std::{net::IpAddr, ptr};
use self::winfw::*;
@@ -46,33 +47,25 @@ 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;
fn new(args: FirewallArguments) -> Result<Self, Self::Error> {
+ let logging_context = b"WinFw\0".as_ptr();
if args.initialize_blocked {
let cfg = &WinFwSettings::new(args.allow_lan.unwrap());
unsafe {
WinFw_InitializeBlocked(
WINFW_TIMEOUT_SECONDS,
&cfg,
- Some(error_sink),
- ptr::null_mut(),
+ Some(log_sink),
+ logging_context,
)
.into_result()?
};
} else {
unsafe {
- WinFw_Initialize(WINFW_TIMEOUT_SECONDS, Some(error_sink), ptr::null_mut())
+ WinFw_Initialize(WINFW_TIMEOUT_SECONDS, Some(log_sink), logging_context)
.into_result()?
};
}
@@ -237,12 +230,10 @@ impl Firewall {
#[allow(non_snake_case)]
mod winfw {
use super::Error;
+ use crate::logging::windows::LogSink;
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,
@@ -300,16 +291,16 @@ mod winfw {
#[link_name = "WinFw_Initialize"]
pub fn WinFw_Initialize(
timeout: libc::c_uint,
- sink: Option<ErrorSink>,
- sink_context: *mut libc::c_void,
+ sink: Option<LogSink>,
+ sink_context: *const u8,
) -> InitializationResult;
#[link_name = "WinFw_InitializeBlocked"]
pub fn WinFw_InitializeBlocked(
timeout: libc::c_uint,
settings: &WinFwSettings,
- sink: Option<ErrorSink>,
- sink_context: *mut libc::c_void,
+ sink: Option<LogSink>,
+ sink_context: *const u8,
) -> InitializationResult;
#[link_name = "WinFw_Deinitialize"]