diff --git a/Cargo.lock b/Cargo.lock index 63031c21c64d..a60c97063935 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3457,7 +3457,6 @@ dependencies = [ "talpid-tunnel-config-client", "talpid-types", "talpid-windows", - "talpid-windows-net", "talpid-wireguard", "tokio", "tonic-build", @@ -3499,7 +3498,7 @@ dependencies = [ "talpid-routing", "talpid-tunnel", "talpid-types", - "talpid-windows-net", + "talpid-windows", "tokio", "tonic", "tonic-build", @@ -3556,7 +3555,7 @@ dependencies = [ "rtnetlink", "system-configuration", "talpid-types", - "talpid-windows-net", + "talpid-windows", "tokio", "widestring", "windows-sys 0.48.0", @@ -3584,7 +3583,7 @@ dependencies = [ "nix 0.23.2", "talpid-routing", "talpid-types", - "talpid-windows-net", + "talpid-windows", "tokio", "tun", "windows-sys 0.48.0", @@ -3625,13 +3624,6 @@ dependencies = [ [[package]] name = "talpid-windows" version = "0.0.0" -dependencies = [ - "windows-sys 0.48.0", -] - -[[package]] -name = "talpid-windows-net" -version = "0.0.0" dependencies = [ "err-derive", "futures", @@ -3670,7 +3662,7 @@ dependencies = [ "talpid-tunnel", "talpid-tunnel-config-client", "talpid-types", - "talpid-windows-net", + "talpid-windows", "tokio", "tokio-stream", "tunnel-obfuscation", diff --git a/Cargo.toml b/Cargo.toml index f68e491d9fb5..a94e5514b7bc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -34,7 +34,7 @@ members = [ "talpid-time", "talpid-tunnel", "talpid-tunnel-config-client", - "talpid-windows-net", + "talpid-windows", "talpid-wireguard", "mullvad-management-interface", "tunnel-obfuscation", diff --git a/talpid-core/Cargo.toml b/talpid-core/Cargo.toml index 40dae6b27b7e..eecc07e388cb 100644 --- a/talpid-core/Cargo.toml +++ b/talpid-core/Cargo.toml @@ -60,7 +60,6 @@ widestring = "1.0" winreg = { version = "0.51", features = ["transactions"] } memoffset = "0.6" windows-service = "0.6.0" -talpid-windows-net = { path = "../talpid-windows-net" } talpid-windows = { path = "../talpid-windows" } [target.'cfg(windows)'.dependencies.windows-sys] diff --git a/talpid-core/src/dns/windows/iphlpapi.rs b/talpid-core/src/dns/windows/iphlpapi.rs index 2d62e1860e19..f9aba7006564 100644 --- a/talpid-core/src/dns/windows/iphlpapi.rs +++ b/talpid-core/src/dns/windows/iphlpapi.rs @@ -13,7 +13,7 @@ use std::{ ptr, }; use talpid_types::win32_err; -use talpid_windows_net::{guid_from_luid, luid_from_alias}; +use talpid_windows::net::{guid_from_luid, luid_from_alias}; use windows_sys::{ core::GUID, s, w, diff --git a/talpid-core/src/dns/windows/netsh.rs b/talpid-core/src/dns/windows/netsh.rs index 17cf551b1feb..7de3fe790013 100644 --- a/talpid-core/src/dns/windows/netsh.rs +++ b/talpid-core/src/dns/windows/netsh.rs @@ -9,7 +9,7 @@ use std::{ time::Duration, }; use talpid_types::{net::IpVersion, ErrorExt}; -use talpid_windows_net::{index_from_luid, luid_from_alias}; +use talpid_windows::net::{index_from_luid, luid_from_alias}; use windows_sys::Win32::{ Foundation::{MAX_PATH, WAIT_OBJECT_0, WAIT_TIMEOUT}, System::{ diff --git a/talpid-core/src/dns/windows/tcpip.rs b/talpid-core/src/dns/windows/tcpip.rs index c1d577f5fe30..244417e119ca 100644 --- a/talpid-core/src/dns/windows/tcpip.rs +++ b/talpid-core/src/dns/windows/tcpip.rs @@ -1,7 +1,7 @@ use crate::dns::DnsMonitorT; use std::{io, net::IpAddr}; use talpid_types::ErrorExt; -use talpid_windows_net::{guid_from_luid, luid_from_alias}; +use talpid_windows::net::{guid_from_luid, luid_from_alias}; use windows_sys::{core::GUID, Win32::System::Com::StringFromGUID2}; use winreg::{ enums::{HKEY_LOCAL_MACHINE, KEY_SET_VALUE}, diff --git a/talpid-core/src/offline/windows.rs b/talpid-core/src/offline/windows.rs index 2756f9c6900b..6539e6e256b5 100644 --- a/talpid-core/src/offline/windows.rs +++ b/talpid-core/src/offline/windows.rs @@ -9,7 +9,7 @@ use std::{ time::Duration, }; use talpid_types::ErrorExt; -use talpid_windows_net::AddressFamily; +use talpid_windows::net::AddressFamily; #[derive(err_derive::Error, Debug)] pub enum Error { diff --git a/talpid-core/src/split_tunnel/windows/mod.rs b/talpid-core/src/split_tunnel/windows/mod.rs index dcabda7c8e68..e168ad38aecf 100644 --- a/talpid-core/src/split_tunnel/windows/mod.rs +++ b/talpid-core/src/split_tunnel/windows/mod.rs @@ -21,7 +21,11 @@ use std::{ }; use talpid_routing::{get_best_default_route, CallbackHandle, EventType, RouteManagerHandle}; use talpid_types::{split_tunnel::ExcludedProcess, tunnel::ErrorStateCause, ErrorExt}; -use talpid_windows_net::{get_ip_address_for_interface, AddressFamily}; +use talpid_windows::{ + io::Overlapped, + net::{get_ip_address_for_interface, AddressFamily}, + sync::Event, +}; use windows_sys::Win32::Foundation::ERROR_OPERATION_ABORTED; const DRIVER_EVENT_BUFFER_SIZE: usize = 2048; @@ -69,7 +73,7 @@ pub enum Error { /// Failed to obtain an IP address given a network interface LUID #[error(display = "Failed to obtain IP address for interface LUID")] - LuidToIp(#[error(source)] talpid_windows_net::Error), + LuidToIp(#[error(source)] talpid_windows::net::Error), /// Failed to set up callback for monitoring default route changes #[error(display = "Failed to register default route change callback")] @@ -105,7 +109,7 @@ pub struct SplitTunnel { runtime: tokio::runtime::Handle, request_tx: RequestTx, event_thread: Option>, - quit_event: Arc, + quit_event: Arc, excluded_processes: Arc>>, _route_change_callback: Option, daemon_tx: Weak>, @@ -191,21 +195,13 @@ impl SplitTunnel { fn spawn_event_listener( handle: Arc, excluded_processes: Arc>>, - ) -> Result< - ( - std::thread::JoinHandle<()>, - Arc, - ), - Error, - > { - let mut event_overlapped = talpid_windows::io::Overlapped::new(Some( - talpid_windows::sync::Event::new(true, false).map_err(Error::EventThreadError)?, + ) -> Result<(std::thread::JoinHandle<()>, Arc), Error> { + let mut event_overlapped = Overlapped::new(Some( + Event::new(true, false).map_err(Error::EventThreadError)?, )) .map_err(Error::EventThreadError)?; - let quit_event = Arc::new( - talpid_windows::sync::Event::new(true, false).map_err(Error::EventThreadError)?, - ); + let quit_event = Arc::new(Event::new(true, false).map_err(Error::EventThreadError)?); let quit_event_copy = quit_event.clone(); let event_thread = std::thread::spawn(move || { @@ -244,8 +240,8 @@ impl SplitTunnel { fn fetch_next_event( device: &Arc, - quit_event: &talpid_windows::sync::Event, - overlapped: &mut talpid_windows::io::Overlapped, + quit_event: &Event, + overlapped: &mut Overlapped, data_buffer: &mut Vec, ) -> io::Result { if unsafe { driver::wait_for_single_object(quit_event.as_raw(), Some(Duration::ZERO)) } diff --git a/talpid-openvpn/Cargo.toml b/talpid-openvpn/Cargo.toml index 6bfdb0c57741..a348ea748634 100644 --- a/talpid-openvpn/Cargo.toml +++ b/talpid-openvpn/Cargo.toml @@ -32,7 +32,7 @@ prost = { workspace = true } [target.'cfg(windows)'.dependencies] widestring = "1.0" winreg = { version = "0.51", features = ["transactions"] } -talpid-windows-net = { path = "../talpid-windows-net" } +talpid-windows = { path = "../talpid-windows" } [target.'cfg(windows)'.dependencies.windows-sys] workspace = true diff --git a/talpid-openvpn/src/lib.rs b/talpid-openvpn/src/lib.rs index 48e3b20b20ea..9fd0c317efe7 100644 --- a/talpid-openvpn/src/lib.rs +++ b/talpid-openvpn/src/lib.rs @@ -203,7 +203,7 @@ impl WintunContext for WintunContextImpl { async fn wait_for_interfaces(&self) -> io::Result<()> { let luid = self.adapter.luid(); - talpid_windows_net::wait_for_interfaces(luid, true, self.wait_v6_interface).await + talpid_windows::net::wait_for_interfaces(luid, true, self.wait_v6_interface).await } fn prepare_interface(&self) { @@ -867,11 +867,12 @@ mod event_server { #[cfg(windows)] { let tunnel_device = metadata.interface.clone(); - let luid = talpid_windows_net::luid_from_alias(tunnel_device).map_err(|error| { - log::error!("{}", error.display_chain_with_msg("luid_from_alias failed")); - tonic::Status::unavailable("failed to obtain interface luid") - })?; - talpid_windows_net::wait_for_addresses(luid) + let luid = + talpid_windows::net::luid_from_alias(tunnel_device).map_err(|error| { + log::error!("{}", error.display_chain_with_msg("luid_from_alias failed")); + tonic::Status::unavailable("failed to obtain interface luid") + })?; + talpid_windows::net::wait_for_addresses(luid) .await .map_err(|error| { log::error!( diff --git a/talpid-routing/Cargo.toml b/talpid-routing/Cargo.toml index 56fb12b13c31..e5cfb9d9f904 100644 --- a/talpid-routing/Cargo.toml +++ b/talpid-routing/Cargo.toml @@ -36,7 +36,7 @@ system-configuration = "0.5.1" [target.'cfg(windows)'.dependencies] libc = "0.2" -talpid-windows-net = { path = "../talpid-windows-net" } +talpid-windows = { path = "../talpid-windows" } widestring = "1.0" [target.'cfg(windows)'.dependencies.windows-sys] diff --git a/talpid-routing/src/windows/default_route_monitor.rs b/talpid-routing/src/windows/default_route_monitor.rs index 0f7d64e3a892..4e452ef31911 100644 --- a/talpid-routing/src/windows/default_route_monitor.rs +++ b/talpid-routing/src/windows/default_route_monitor.rs @@ -22,7 +22,7 @@ use windows_sys::Win32::{ }, }; -use talpid_windows_net::AddressFamily; +use talpid_windows::net::AddressFamily; const WIN_FALSE: BOOLEAN = 0; diff --git a/talpid-routing/src/windows/get_best_default_route.rs b/talpid-routing/src/windows/get_best_default_route.rs index 4a1f254a79ac..f51313034895 100644 --- a/talpid-routing/src/windows/get_best_default_route.rs +++ b/talpid-routing/src/windows/get_best_default_route.rs @@ -1,7 +1,7 @@ use super::{Error, Result}; use std::{net::SocketAddr, slice}; use talpid_types::win32_err; -use talpid_windows_net::{ +use talpid_windows::net::{ get_ip_interface_entry, try_socketaddr_from_inet_sockaddr, AddressFamily, }; use widestring::{widecstr, WideCStr}; diff --git a/talpid-routing/src/windows/mod.rs b/talpid-routing/src/windows/mod.rs index 51ac345f82c5..7924d4c7abf4 100644 --- a/talpid-routing/src/windows/mod.rs +++ b/talpid-routing/src/windows/mod.rs @@ -12,7 +12,7 @@ use net::AddressFamily; pub use route_manager::{Callback, CallbackHandle, Route, RouteManagerInternal}; use std::{collections::HashSet, io, net::IpAddr}; use talpid_types::ErrorExt; -use talpid_windows_net as net; +use talpid_windows::net; mod default_route_monitor; mod get_best_default_route; @@ -284,12 +284,10 @@ fn get_mtu_for_route(addr_family: AddressFamily) -> Result> { match get_best_default_route(addr_family) { Ok(Some(route)) => { let interface_row = - talpid_windows_net::get_ip_interface_entry(addr_family, &route.iface).map_err( - |e| { - log::error!("Could not get ip interface entry: {}", e); - Error::GetMtu - }, - )?; + net::get_ip_interface_entry(addr_family, &route.iface).map_err(|e| { + log::error!("Could not get ip interface entry: {}", e); + Error::GetMtu + })?; let mtu = interface_row.NlMtu; let mtu = u16::try_from(mtu).map_err(|_| Error::GetMtu)?; Ok(Some(mtu)) diff --git a/talpid-routing/src/windows/route_manager.rs b/talpid-routing/src/windows/route_manager.rs index 277832eaa94a..a122a29003ce 100644 --- a/talpid-routing/src/windows/route_manager.rs +++ b/talpid-routing/src/windows/route_manager.rs @@ -11,7 +11,7 @@ use std::{ sync::{Arc, Mutex}, }; use talpid_types::win32_err; -use talpid_windows_net::{ +use talpid_windows::net::{ inet_sockaddr_from_socketaddr, try_socketaddr_from_inet_sockaddr, AddressFamily, }; use widestring::{WideCStr, WideCString}; @@ -824,7 +824,7 @@ impl<'a> Iterator for AdaptersIterator<'a> { pub fn win_ip_address_prefix_from_ipnetwork_port_zero(from: IpNetwork) -> IP_ADDRESS_PREFIX { // Port should not matter so we set it to 0 let prefix = - talpid_windows_net::inet_sockaddr_from_socketaddr(std::net::SocketAddr::new(from.ip(), 0)); + talpid_windows::net::inet_sockaddr_from_socketaddr(std::net::SocketAddr::new(from.ip(), 0)); IP_ADDRESS_PREFIX { Prefix: prefix, PrefixLength: from.prefix(), @@ -834,7 +834,7 @@ pub fn win_ip_address_prefix_from_ipnetwork_port_zero(from: IpNetwork) -> IP_ADD /// Convert to a windows defined `SOCKADDR_INET` from a `IpAddr` but set the port to 0 pub fn inet_sockaddr_from_ipaddr(from: IpAddr) -> SOCKADDR_INET { // Port should not matter so we set it to 0 - talpid_windows_net::inet_sockaddr_from_socketaddr(std::net::SocketAddr::new(from, 0)) + talpid_windows::net::inet_sockaddr_from_socketaddr(std::net::SocketAddr::new(from, 0)) } /// Convert to a `AddressFamily` from a `ipnetwork::IpNetwork` diff --git a/talpid-tunnel/Cargo.toml b/talpid-tunnel/Cargo.toml index 1e8bbd939537..1f5ef36a1a6f 100644 --- a/talpid-tunnel/Cargo.toml +++ b/talpid-tunnel/Cargo.toml @@ -32,7 +32,7 @@ tun = "0.5.1" tun = "0.5.1" [target.'cfg(windows)'.dependencies] -talpid-windows-net = { path = "../talpid-windows-net" } +talpid-windows = { path = "../talpid-windows" } [target.'cfg(windows)'.dependencies.windows-sys] workspace = true diff --git a/talpid-tunnel/src/windows.rs b/talpid-tunnel/src/windows.rs index d9c54f69408e..bc5fffb3f0ec 100644 --- a/talpid-tunnel/src/windows.rs +++ b/talpid-tunnel/src/windows.rs @@ -1,5 +1,5 @@ use std::io; -use talpid_windows_net::{get_ip_interface_entry, set_ip_interface_entry, AddressFamily}; +use talpid_windows::net::{get_ip_interface_entry, set_ip_interface_entry, AddressFamily}; use windows_sys::Win32::{ Foundation::ERROR_NOT_FOUND, NetworkManagement::Ndis::NET_LUID_LH, Networking::WinSock::RouterDiscoveryDisabled, diff --git a/talpid-windows-net/Cargo.toml b/talpid-windows-net/Cargo.toml deleted file mode 100644 index 1c6fc02d9ab8..000000000000 --- a/talpid-windows-net/Cargo.toml +++ /dev/null @@ -1,28 +0,0 @@ -[package] -name = "talpid-windows-net" -description = "Work with Windows network interfaces and their configuration" -version.workspace = true -authors.workspace = true -repository.workspace = true -license.workspace = true -edition.workspace = true -publish.workspace = true - -[target.'cfg(windows)'.dependencies] -err-derive = { workspace = true } -socket2 = { version = "0.5.3" } -futures = "0.3.15" - -talpid-types = { path = "../talpid-types" } - -[target.'cfg(windows)'.dependencies.windows-sys] -workspace = true -features = [ - "Win32_Foundation", - "Win32_Globalization", - "Win32_System_Com", - "Win32_System_IO", - "Win32_Networking_WinSock", - "Win32_NetworkManagement_IpHelper", - "Win32_NetworkManagement_Ndis", -] diff --git a/talpid-windows-net/src/lib.rs b/talpid-windows-net/src/lib.rs deleted file mode 100644 index 48dc8062ee4a..000000000000 --- a/talpid-windows-net/src/lib.rs +++ /dev/null @@ -1,10 +0,0 @@ -//! Interface with low-level windows specific bits. - -#![deny(missing_docs)] -#![deny(rust_2018_idioms)] - -/// Nicer interfaces with Windows networking code. -#[cfg(windows)] -pub mod net; -#[cfg(windows)] -pub use net::*; diff --git a/talpid-windows/Cargo.toml b/talpid-windows/Cargo.toml index 20a4d1ae3e4b..0765a1376b70 100644 --- a/talpid-windows/Cargo.toml +++ b/talpid-windows/Cargo.toml @@ -8,6 +8,13 @@ license.workspace = true edition.workspace = true publish.workspace = true +[target.'cfg(windows)'.dependencies] +err-derive = { workspace = true } +socket2 = { version = "0.5.3" } +futures = "0.3.15" + +talpid-types = { path = "../talpid-types" } + [target.'cfg(windows)'.dependencies.windows-sys] workspace = true features = [ diff --git a/talpid-windows/src/lib.rs b/talpid-windows/src/lib.rs index edc471aa3353..865c3e8a8132 100644 --- a/talpid-windows/src/lib.rs +++ b/talpid-windows/src/lib.rs @@ -1,12 +1,14 @@ -//! Interface with low-level windows specific bits. +//! Interface with low-level Windows-specific bits. #![deny(missing_docs)] #![deny(rust_2018_idioms)] +#![cfg(windows)] -/// Windows I/O -#[cfg(windows)] +/// I/O pub mod io; -/// Synchronization (event objects, etc.) -#[cfg(windows)] +/// Networking +pub mod net; + +/// Synchronization pub mod sync; diff --git a/talpid-windows-net/src/net.rs b/talpid-windows/src/net.rs similarity index 100% rename from talpid-windows-net/src/net.rs rename to talpid-windows/src/net.rs diff --git a/talpid-wireguard/Cargo.toml b/talpid-wireguard/Cargo.toml index f8e854a7c56f..f9a446a700d7 100644 --- a/talpid-wireguard/Cargo.toml +++ b/talpid-wireguard/Cargo.toml @@ -50,7 +50,7 @@ tokio-stream = { version = "0.1", features = ["io-util"] } [target.'cfg(windows)'.dependencies] bitflags = "1.2" -talpid-windows-net = { path = "../talpid-windows-net" } +talpid-windows = { path = "../talpid-windows" } widestring = "1.0" # TODO: Figure out which features are needed and which are not diff --git a/talpid-wireguard/src/lib.rs b/talpid-wireguard/src/lib.rs index cdc09224ef4b..c95a5d371b67 100644 --- a/talpid-wireguard/src/lib.rs +++ b/talpid-wireguard/src/lib.rs @@ -105,7 +105,7 @@ pub enum Error { /// Failed to set IP addresses on WireGuard interface #[cfg(target_os = "windows")] #[error(display = "Failed to set IP addresses on WireGuard interface")] - SetIpAddressesError(#[error(source)] talpid_windows_net::Error), + SetIpAddressesError(#[error(source)] talpid_windows::net::Error), } /// Spawns and monitors a wireguard tunnel @@ -643,12 +643,12 @@ impl WireguardMonitor { })?; // TODO: The LUID can be obtained directly. - let luid = talpid_windows_net::luid_from_alias(iface_name).map_err(|error| { + let luid = talpid_windows::net::luid_from_alias(iface_name).map_err(|error| { log::error!("Failed to obtain tunnel interface LUID: {}", error); CloseMsg::SetupError(Error::IpInterfacesError) })?; for address in addresses { - talpid_windows_net::add_ip_address_for_interface(luid, *address) + talpid_windows::net::add_ip_address_for_interface(luid, *address) .map_err(|error| CloseMsg::SetupError(Error::SetIpAddressesError(error)))?; } Ok(()) diff --git a/talpid-wireguard/src/wireguard_nt.rs b/talpid-wireguard/src/wireguard_nt.rs index c3fb12de1eba..daa7da65c86c 100644 --- a/talpid-wireguard/src/wireguard_nt.rs +++ b/talpid-wireguard/src/wireguard_nt.rs @@ -22,7 +22,7 @@ use std::{ sync::{Arc, Mutex}, }; use talpid_types::{BoxedError, ErrorExt}; -use talpid_windows_net as net; +use talpid_windows::net; use widestring::{U16CStr, U16CString}; use windows_sys::{ core::GUID, @@ -1031,7 +1031,7 @@ mod tests { public_key: *WG_PUBLIC_KEY.as_bytes(), preshared_key: [0; WIREGUARD_KEY_LENGTH], persistent_keepalive: 0, - endpoint: talpid_windows_net::inet_sockaddr_from_socketaddr( + endpoint: talpid_windows::net::inet_sockaddr_from_socketaddr( "1.2.3.4:1234".parse().unwrap(), ) .into(),