Skip to content

Commit

Permalink
Move talpid-windows-net into talpid-windows
Browse files Browse the repository at this point in the history
  • Loading branch information
dlon committed Oct 20, 2023
1 parent ca98809 commit ba120a2
Show file tree
Hide file tree
Showing 25 changed files with 63 additions and 106 deletions.
16 changes: 4 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 0 additions & 1 deletion talpid-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion talpid-core/src/dns/windows/iphlpapi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion talpid-core/src/dns/windows/netsh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down
2 changes: 1 addition & 1 deletion talpid-core/src/dns/windows/tcpip.rs
Original file line number Diff line number Diff line change
@@ -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},
Expand Down
2 changes: 1 addition & 1 deletion talpid-core/src/offline/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
30 changes: 13 additions & 17 deletions talpid-core/src/split_tunnel/windows/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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")]
Expand Down Expand Up @@ -105,7 +109,7 @@ pub struct SplitTunnel {
runtime: tokio::runtime::Handle,
request_tx: RequestTx,
event_thread: Option<std::thread::JoinHandle<()>>,
quit_event: Arc<talpid_windows::sync::Event>,
quit_event: Arc<Event>,
excluded_processes: Arc<RwLock<HashMap<usize, ExcludedProcess>>>,
_route_change_callback: Option<CallbackHandle>,
daemon_tx: Weak<mpsc::UnboundedSender<TunnelCommand>>,
Expand Down Expand Up @@ -191,21 +195,13 @@ impl SplitTunnel {
fn spawn_event_listener(
handle: Arc<driver::DeviceHandle>,
excluded_processes: Arc<RwLock<HashMap<usize, ExcludedProcess>>>,
) -> Result<
(
std::thread::JoinHandle<()>,
Arc<talpid_windows::sync::Event>,
),
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<Event>), 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 || {
Expand Down Expand Up @@ -244,8 +240,8 @@ impl SplitTunnel {

fn fetch_next_event(
device: &Arc<driver::DeviceHandle>,
quit_event: &talpid_windows::sync::Event,
overlapped: &mut talpid_windows::io::Overlapped,
quit_event: &Event,
overlapped: &mut Overlapped,
data_buffer: &mut Vec<u8>,
) -> io::Result<EventResult> {
if unsafe { driver::wait_for_single_object(quit_event.as_raw(), Some(Duration::ZERO)) }
Expand Down
2 changes: 1 addition & 1 deletion talpid-openvpn/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 7 additions & 6 deletions talpid-openvpn/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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!(
Expand Down
2 changes: 1 addition & 1 deletion talpid-routing/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion talpid-routing/src/windows/default_route_monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use windows_sys::Win32::{
},
};

use talpid_windows_net::AddressFamily;
use talpid_windows::net::AddressFamily;

const WIN_FALSE: BOOLEAN = 0;

Expand Down
2 changes: 1 addition & 1 deletion talpid-routing/src/windows/get_best_default_route.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down
12 changes: 5 additions & 7 deletions talpid-routing/src/windows/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -284,12 +284,10 @@ fn get_mtu_for_route(addr_family: AddressFamily) -> Result<Option<u16>> {
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))
Expand Down
6 changes: 3 additions & 3 deletions talpid-routing/src/windows/route_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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(),
Expand All @@ -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`
Expand Down
2 changes: 1 addition & 1 deletion talpid-tunnel/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion talpid-tunnel/src/windows.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
28 changes: 0 additions & 28 deletions talpid-windows-net/Cargo.toml

This file was deleted.

10 changes: 0 additions & 10 deletions talpid-windows-net/src/lib.rs

This file was deleted.

7 changes: 7 additions & 0 deletions talpid-windows/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
12 changes: 7 additions & 5 deletions talpid-windows/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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;
File renamed without changes.
2 changes: 1 addition & 1 deletion talpid-wireguard/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit ba120a2

Please sign in to comment.