summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorOdd Stranne <odd@mullvad.net>2020-02-01 18:21:02 +0100
committerOdd Stranne <odd@mullvad.net>2020-02-03 13:42:46 +0100
commit09cba9098a0349c102339db85e49d1f0be7ef6c3 (patch)
tree2c8453a1ffdb94757aa65ae4ac70cee04c7587f3
parent0c2d0c1221c0bcb4523ce5458c2771e8e6dd34e9 (diff)
downloadmullvadvpn-09cba9098a0349c102339db85e49d1f0be7ef6c3.tar.xz
mullvadvpn-09cba9098a0349c102339db85e49d1f0be7ef6c3.zip
Adjust talpid-core for changes in winnet
-rw-r--r--talpid-core/src/tunnel/wireguard/wireguard_go.rs2
-rw-r--r--talpid-core/src/winnet.rs85
2 files changed, 32 insertions, 55 deletions
diff --git a/talpid-core/src/tunnel/wireguard/wireguard_go.rs b/talpid-core/src/tunnel/wireguard/wireguard_go.rs
index 91af5aa7a2..c569c8727e 100644
--- a/talpid-core/src/tunnel/wireguard/wireguard_go.rs
+++ b/talpid-core/src/tunnel/wireguard/wireguard_go.rs
@@ -160,7 +160,7 @@ impl WgGoTunnel {
#[cfg(target_os = "windows")]
pub unsafe extern "system" fn default_route_changed_callback(
event_type: winnet::WinNetDefaultRouteChangeEventType,
- address_family: winnet::WinNetIpFamily,
+ address_family: winnet::WinNetAddrFamily,
interface_luid: u64,
_ctx: *mut libc::c_void,
) {
diff --git a/talpid-core/src/winnet.rs b/talpid-core/src/winnet.rs
index 08a4937b3c..2eee4b205a 100644
--- a/talpid-core/src/winnet.rs
+++ b/talpid-core/src/winnet.rs
@@ -105,45 +105,25 @@ pub fn get_tap_interface_alias() -> Result<OsString, Error> {
Ok(alias.to_os_string())
}
-#[repr(C)]
-struct WinNetIpType(u32);
-
-const WINNET_IPV4: u32 = 0;
-const WINNET_IPV6: u32 = 1;
-
-impl WinNetIpType {
- pub fn v4() -> Self {
- WinNetIpType(WINNET_IPV4)
- }
-
- pub fn v6() -> Self {
- WinNetIpType(WINNET_IPV6)
- }
-}
-
-
-#[repr(C)]
-pub struct WinNetIpNetwork {
- ip_type: WinNetIpType,
- ip_bytes: [u8; 16],
- prefix: u8,
+#[allow(dead_code)]
+#[repr(u32)]
+pub enum WinNetAddrFamily {
+ IPV4 = 0,
+ IPV6 = 1,
}
-impl From<IpNetwork> for WinNetIpNetwork {
- fn from(network: IpNetwork) -> WinNetIpNetwork {
- let WinNetIp { ip_type, ip_bytes } = WinNetIp::from(network.ip());
- let prefix = network.prefix();
- WinNetIpNetwork {
- ip_type,
- ip_bytes,
- prefix,
+impl WinNetAddrFamily {
+ pub fn to_windows_proto_enum(&self) -> u16 {
+ match self {
+ Self::IPV4 => 2,
+ Self::IPV6 => 23,
}
}
}
#[repr(C)]
pub struct WinNetIp {
- ip_type: WinNetIpType,
+ addr_family: WinNetAddrFamily,
ip_bytes: [u8; 16],
}
@@ -154,7 +134,7 @@ impl From<IpAddr> for WinNetIp {
IpAddr::V4(v4_addr) => {
bytes[..4].copy_from_slice(&v4_addr.octets());
WinNetIp {
- ip_type: WinNetIpType::v4(),
+ addr_family: WinNetAddrFamily::IPV4,
ip_bytes: bytes,
}
}
@@ -162,7 +142,7 @@ impl From<IpAddr> for WinNetIp {
bytes.copy_from_slice(&v6_addr.octets());
WinNetIp {
- ip_type: WinNetIpType::v6(),
+ addr_family: WinNetAddrFamily::IPV6,
ip_bytes: bytes,
}
}
@@ -171,6 +151,21 @@ impl From<IpAddr> for WinNetIp {
}
#[repr(C)]
+pub struct WinNetIpNetwork {
+ prefix: u8,
+ ip: WinNetIp,
+}
+
+impl From<IpNetwork> for WinNetIpNetwork {
+ fn from(network: IpNetwork) -> WinNetIpNetwork {
+ WinNetIpNetwork {
+ prefix: network.prefix(),
+ ip: WinNetIp::from(network.ip()),
+ }
+ }
+}
+
+#[repr(C)]
pub struct WinNetNode {
gateway: *mut WinNetIp,
device_name: *mut u16,
@@ -196,7 +191,6 @@ impl WinNetNode {
}
}
-
fn from_device(name: &str) -> Self {
let device_name = WideCString::from_str(name)
.expect("Failed to convert UTF-8 string to null terminated UCS string")
@@ -234,7 +228,6 @@ impl Drop for WinNetNode {
}
}
-
#[repr(C)]
pub struct WinNetRoute {
gateway: WinNetIpNetwork,
@@ -251,7 +244,7 @@ impl WinNetRoute {
pub fn new(node: WinNetNode, gateway: WinNetIpNetwork) -> Self {
let node = Box::into_raw(Box::new(node));
- WinNetRoute { gateway, node }
+ Self { gateway, node }
}
}
@@ -273,7 +266,7 @@ pub fn activate_routing_manager(routes: &[WinNetRoute]) -> bool {
pub struct WinNetCallbackHandle {
handle: *mut libc::c_void,
- // allows us to keep the context pointer allive.
+ // Allows us to keep the context pointer alive.
_context: Box<dyn std::any::Any>,
}
@@ -292,25 +285,9 @@ pub enum WinNetDefaultRouteChangeEventType {
DefaultRouteRemoved = 1,
}
-#[allow(dead_code)]
-#[repr(u16)]
-pub enum WinNetIpFamily {
- V4 = 0,
- V6 = 1,
-}
-
-impl WinNetIpFamily {
- pub fn to_windows_proto_enum(&self) -> u16 {
- match self {
- Self::V4 => 2,
- Self::V6 => 23,
- }
- }
-}
-
pub type DefaultRouteChangedCallback = unsafe extern "system" fn(
event_type: WinNetDefaultRouteChangeEventType,
- ip_family: WinNetIpFamily,
+ addr_family: WinNetAddrFamily,
interface_luid: u64,
ctx: *mut c_void,
);