summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorLinus Färnstrand <linus@mullvad.net>2023-08-08 10:41:24 +0200
committerLinus Färnstrand <linus@mullvad.net>2023-08-08 10:41:24 +0200
commit19c2fd3325dd0ac3dcfb30a66b9a30fc0c524e99 (patch)
treec52aa0dbd9dac787f745e7ee2be49e16927e7c8e
parent92c2dd83db7c4bc3da1f1093c730b0cbb97ca484 (diff)
parent947bb8bae0bce4be43e2a7f0b398594ac493efcc (diff)
downloadmullvadvpn-19c2fd3325dd0ac3dcfb30a66b9a30fc0c524e99.tar.xz
mullvadvpn-19c2fd3325dd0ac3dcfb30a66b9a30fc0c524e99.zip
Merge branch 'use-std-ffi-c-types'
-rw-r--r--Cargo.lock1
-rw-r--r--mullvad-daemon/src/exception_logging/unix.rs3
-rw-r--r--mullvad-daemon/src/exception_logging/win.rs5
-rw-r--r--mullvad-daemon/src/macos_launch_daemon.rs4
-rw-r--r--mullvad-daemon/src/system_service.rs3
-rw-r--r--talpid-core/src/firewall/windows.rs9
-rw-r--r--talpid-routing/src/unix/macos/data.rs51
-rw-r--r--talpid-windows-net/Cargo.toml1
-rw-r--r--talpid-windows-net/src/net.rs3
-rw-r--r--talpid-wireguard/src/logging.rs5
-rw-r--r--talpid-wireguard/src/wireguard_go.rs24
11 files changed, 51 insertions, 58 deletions
diff --git a/Cargo.lock b/Cargo.lock
index eb7309d0db..6bc9b89fc1 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -3772,7 +3772,6 @@ version = "0.0.0"
dependencies = [
"err-derive",
"futures",
- "libc",
"socket2 0.4.9",
"talpid-types",
"winapi",
diff --git a/mullvad-daemon/src/exception_logging/unix.rs b/mullvad-daemon/src/exception_logging/unix.rs
index 430fedb74f..4cb3a35ac5 100644
--- a/mullvad-daemon/src/exception_logging/unix.rs
+++ b/mullvad-daemon/src/exception_logging/unix.rs
@@ -1,8 +1,9 @@
//! Installs signal handlers to catch critical program faults and logs them.
-use libc::{c_int, c_void, siginfo_t};
+use libc::siginfo_t;
use nix::sys::signal::{sigaction, SaFlags, SigAction, SigHandler, SigSet, Signal};
+use std::ffi::{c_int, c_void};
use std::{convert::TryFrom, sync::Once};
static INIT_ONCE: Once = Once::new();
diff --git a/mullvad-daemon/src/exception_logging/win.rs b/mullvad-daemon/src/exception_logging/win.rs
index 343b04a59c..906a8533fc 100644
--- a/mullvad-daemon/src/exception_logging/win.rs
+++ b/mullvad-daemon/src/exception_logging/win.rs
@@ -1,11 +1,10 @@
-use libc::c_void;
use mullvad_paths::log_dir;
use std::{
borrow::Cow,
- ffi::CStr,
+ ffi::{c_char, c_void, CStr},
fmt::Write,
fs, io, mem,
- os::{raw::c_char, windows::io::AsRawHandle},
+ os::windows::io::AsRawHandle,
path::{Path, PathBuf},
ptr,
};
diff --git a/mullvad-daemon/src/macos_launch_daemon.rs b/mullvad-daemon/src/macos_launch_daemon.rs
index 04a562e9a1..d71e4b49bb 100644
--- a/mullvad-daemon/src/macos_launch_daemon.rs
+++ b/mullvad-daemon/src/macos_launch_daemon.rs
@@ -80,7 +80,7 @@ fn daemon_plist_url() -> Object {
let nsurl_inst: Id = unsafe { msg_send![class!(NSURL), alloc] };
let nsurl_inst: Id = unsafe { msg_send![nsurl_inst, initWithString: nsstr_inst] };
- let _: libc::c_void = unsafe { msg_send![nsstr_inst, release] };
+ let _: () = unsafe { msg_send![nsstr_inst, release] };
assert!(!nsurl_inst.is_null());
@@ -92,6 +92,6 @@ struct Object(Id);
impl Drop for Object {
fn drop(&mut self) {
- let _: libc::c_void = unsafe { msg_send![self.0, release] };
+ let _: () = unsafe { msg_send![self.0, release] };
}
}
diff --git a/mullvad-daemon/src/system_service.rs b/mullvad-daemon/src/system_service.rs
index 11b3e88eac..07eb791584 100644
--- a/mullvad-daemon/src/system_service.rs
+++ b/mullvad-daemon/src/system_service.rs
@@ -1,10 +1,9 @@
use crate::cli;
-use libc::c_void;
use mullvad_daemon::{runtime::new_runtime_builder, DaemonShutdownHandle};
use once_cell::sync::Lazy;
use std::{
env,
- ffi::OsString,
+ ffi::{c_void, OsString},
ptr, slice,
sync::{
atomic::{AtomicBool, AtomicUsize, Ordering},
diff --git a/talpid-core/src/firewall/windows.rs b/talpid-core/src/firewall/windows.rs
index b7b4ac39f6..ed3e0a19fe 100644
--- a/talpid-core/src/firewall/windows.rs
+++ b/talpid-core/src/firewall/windows.rs
@@ -334,8 +334,8 @@ fn widestring_ip(ip: IpAddr) -> WideCString {
/// Logging callback implementation.
pub extern "system" fn log_sink(
level: log::Level,
- msg: *const libc::c_char,
- context: *mut libc::c_void,
+ msg: *const std::ffi::c_char,
+ context: *mut std::ffi::c_void,
) {
if msg.is_null() {
log::error!("Log message from FFI boundary is NULL");
@@ -409,11 +409,10 @@ fn multibyte_to_wide(mb_string: &CStr, codepage: u32) -> Result<Vec<u16>, io::Er
#[allow(non_snake_case)]
mod winfw {
use super::{widestring_ip, AllowedEndpoint, AllowedTunnelTraffic, Error, WideCString};
- use libc;
+ use std::ffi::{c_char, c_void};
use talpid_types::net::TransportProtocol;
- type LogSink =
- extern "system" fn(level: log::Level, msg: *const libc::c_char, context: *mut libc::c_void);
+ type LogSink = extern "system" fn(level: log::Level, msg: *const c_char, context: *mut c_void);
pub struct WinFwAllowedEndpointContainer {
_clients: Box<[WideCString]>,
diff --git a/talpid-routing/src/unix/macos/data.rs b/talpid-routing/src/unix/macos/data.rs
index 1e955c5fa0..16981ee5f6 100644
--- a/talpid-routing/src/unix/macos/data.rs
+++ b/talpid-routing/src/unix/macos/data.rs
@@ -5,6 +5,7 @@ use nix::{
};
use std::{
collections::BTreeMap,
+ ffi::{c_int, c_uchar, c_ushort},
net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6},
};
@@ -385,13 +386,13 @@ impl RouteMessage {
#[derive(Debug)]
#[repr(C)]
struct ifa_msghdr {
- ifam_msglen: libc::c_ushort,
- ifam_version: libc::c_uchar,
- ifam_type: libc::c_uchar,
- ifam_addrs: libc::c_int,
- ifam_flags: libc::c_int,
- ifam_index: libc::c_ushort,
- ifam_metric: libc::c_int,
+ ifam_msglen: c_ushort,
+ ifam_version: c_uchar,
+ ifam_type: c_uchar,
+ ifam_addrs: c_int,
+ ifam_flags: c_int,
+ ifam_index: c_ushort,
+ ifam_metric: c_int,
}
#[derive(Debug)]
@@ -529,7 +530,7 @@ pub enum Error {
/// Unrecognized message
UnknownMessageType(u8),
/// Unrecognized address flag
- UnknownAddressFlag(libc::c_int),
+ UnknownAddressFlag(c_int),
/// Mismatched socket address type
MismatchedSocketAddress(AddressFlag, Box<SockaddrStorage>),
/// Link socket address contains no identifier
@@ -1003,16 +1004,16 @@ impl<'a> Iterator for RouteSockAddrIterator<'a> {
#[derive(Debug, Clone)]
#[repr(C)]
pub struct rt_msghdr {
- pub rtm_msglen: libc::c_ushort,
- pub rtm_version: libc::c_uchar,
- pub rtm_type: libc::c_uchar,
- pub rtm_index: libc::c_ushort,
- pub rtm_flags: libc::c_int,
- pub rtm_addrs: libc::c_int,
+ pub rtm_msglen: c_ushort,
+ pub rtm_version: c_uchar,
+ pub rtm_type: c_uchar,
+ pub rtm_index: c_ushort,
+ pub rtm_flags: c_int,
+ pub rtm_addrs: c_int,
pub rtm_pid: libc::pid_t,
- pub rtm_seq: libc::c_int,
- pub rtm_errno: libc::c_int,
- pub rtm_use: libc::c_int,
+ pub rtm_seq: c_int,
+ pub rtm_errno: c_int,
+ pub rtm_use: c_int,
pub rtm_inits: u32,
pub rtm_rmx: rt_metrics,
}
@@ -1049,15 +1050,15 @@ impl rt_msghdr {
#[derive(Debug)]
#[repr(C)]
pub struct rt_msghdr_short {
- pub rtm_msglen: libc::c_ushort,
- pub rtm_version: libc::c_uchar,
- pub rtm_type: libc::c_uchar,
- pub rtm_index: libc::c_ushort,
- pub rtm_flags: libc::c_int,
- pub rtm_addrs: libc::c_int,
+ pub rtm_msglen: c_ushort,
+ pub rtm_version: c_uchar,
+ pub rtm_type: c_uchar,
+ pub rtm_index: c_ushort,
+ pub rtm_flags: c_int,
+ pub rtm_addrs: c_int,
pub rtm_pid: libc::pid_t,
- pub rtm_seq: libc::c_int,
- pub rtm_errno: libc::c_int,
+ pub rtm_seq: c_int,
+ pub rtm_errno: c_int,
}
const ROUTE_MESSAGE_HEADER_SHORT_SIZE: usize = std::mem::size_of::<rt_msghdr_short>();
diff --git a/talpid-windows-net/Cargo.toml b/talpid-windows-net/Cargo.toml
index 351bc539ea..f3a6f7046f 100644
--- a/talpid-windows-net/Cargo.toml
+++ b/talpid-windows-net/Cargo.toml
@@ -10,7 +10,6 @@ publish.workspace = true
[target.'cfg(windows)'.dependencies]
err-derive = "0.3.1"
-libc = "0.2"
socket2 = { version = "0.4.2", features = ["all"] }
futures = "0.3.15"
winapi = { version = "0.3.6", features = ["ws2def"] }
diff --git a/talpid-windows-net/src/net.rs b/talpid-windows-net/src/net.rs
index ec146a5c72..92e8e97969 100644
--- a/talpid-windows-net/src/net.rs
+++ b/talpid-windows-net/src/net.rs
@@ -1,4 +1,3 @@
-use libc::c_void;
use socket2::SockAddr;
use std::{
ffi::{OsStr, OsString},
@@ -153,7 +152,7 @@ impl<'a> Drop for IpNotifierHandle<'a> {
}
unsafe extern "system" fn inner_callback(
- context: *const c_void,
+ context: *const std::ffi::c_void,
row: *const MIB_IPINTERFACE_ROW,
notify_type: i32,
) {
diff --git a/talpid-wireguard/src/logging.rs b/talpid-wireguard/src/logging.rs
index bf91840644..5f006d418c 100644
--- a/talpid-wireguard/src/logging.rs
+++ b/talpid-wireguard/src/logging.rs
@@ -1,5 +1,6 @@
use once_cell::sync::Lazy;
use parking_lot::Mutex;
+use std::ffi::{c_char, c_void};
use std::{collections::HashMap, fmt, fs, io::Write, path::Path};
static LOG_MUTEX: Lazy<Mutex<HashMap<u32, fs::File>>> = Lazy::new(|| Mutex::new(HashMap::new()));
@@ -91,8 +92,8 @@ fn log_inner(logfile: &mut fs::File, level: LogLevel, tag: &str, msg: &str) {
// Callback that receives messages from WireGuard
pub unsafe extern "system" fn wg_go_logging_callback(
level: WgLogLevel,
- msg: *const libc::c_char,
- context: *mut libc::c_void,
+ msg: *const c_char,
+ context: *mut c_void,
) {
let mut map = LOG_MUTEX.lock();
if let Some(logfile) = map.get_mut(&(context as u32)) {
diff --git a/talpid-wireguard/src/wireguard_go.rs b/talpid-wireguard/src/wireguard_go.rs
index d12753258b..fff8416064 100644
--- a/talpid-wireguard/src/wireguard_go.rs
+++ b/talpid-wireguard/src/wireguard_go.rs
@@ -6,9 +6,8 @@ use crate::logging::{clean_up_logging, initialize_logging, wg_go_logging_callbac
#[cfg(windows)]
use futures::SinkExt;
use std::{
- ffi::{c_void, CStr},
+ ffi::{c_char, c_void, CStr},
future::Future,
- os::raw::c_char,
path::Path,
pin::Pin,
};
@@ -95,7 +94,7 @@ impl WgGoTunnel {
wg_config_str.as_ptr() as *const i8,
tunnel_fd,
Some(wg_go_logging_callback),
- logging_context.0 as *mut libc::c_void,
+ logging_context.0 as *mut c_void,
)
};
check_wg_status(handle)?;
@@ -154,7 +153,7 @@ impl WgGoTunnel {
&mut alias_ptr,
&mut interface_luid,
Some(wg_go_logging_callback),
- logging_context.0 as *mut libc::c_void,
+ logging_context.0 as *mut c_void,
)
};
check_wg_status(handle)?;
@@ -424,11 +423,8 @@ fn check_wg_status(wg_code: i32) -> Result<()> {
#[cfg(unix)]
pub type Fd = std::os::unix::io::RawFd;
-pub type LoggingCallback = unsafe extern "system" fn(
- level: WgLogLevel,
- msg: *const libc::c_char,
- context: *mut libc::c_void,
-);
+pub type LoggingCallback =
+ unsafe extern "system" fn(level: WgLogLevel, msg: *const c_char, context: *mut c_void);
const ERROR_GENERAL_FAILURE: i32 = -1;
const ERROR_INTERMITTENT_FAILURE: i32 = -2;
@@ -445,7 +441,7 @@ extern "C" {
settings: *const i8,
fd: Fd,
logging_callback: Option<LoggingCallback>,
- logging_context: *mut libc::c_void,
+ logging_context: *mut c_void,
) -> i32;
// Android
@@ -454,7 +450,7 @@ extern "C" {
settings: *const i8,
fd: Fd,
logging_callback: Option<LoggingCallback>,
- logging_context: *mut libc::c_void,
+ logging_context: *mut c_void,
) -> i32;
// Windows
@@ -463,17 +459,17 @@ extern "C" {
iface_name: *const i8,
mtu: i64,
settings: *const i8,
- iface_name_out: *mut *mut std::os::raw::c_char,
+ iface_name_out: *mut *mut c_char,
iface_luid_out: *mut u64,
logging_callback: Option<LoggingCallback>,
- logging_context: *mut libc::c_void,
+ logging_context: *mut c_void,
) -> i32;
// Pass a handle that was created by wgTurnOn to stop a wireguard tunnel.
fn wgTurnOff(handle: i32) -> i32;
// Returns the file descriptor of the tunnel IPv4 socket.
- fn wgGetConfig(handle: i32) -> *mut std::os::raw::c_char;
+ fn wgGetConfig(handle: i32) -> *mut c_char;
// Sets the config of the WireGuard interface.
fn wgSetConfig(handle: i32, settings: *const i8) -> i32;