summaryrefslogtreecommitdiffhomepage
path: root/talpid-core/src
diff options
context:
space:
mode:
authorDavid Lönnhager <david.l@mullvad.net>2020-09-11 19:21:39 +0200
committerDavid Lönnhager <david.l@mullvad.net>2020-11-09 14:54:58 +0100
commit8781e5909ff418cb9fc97918b7da328ad148b643 (patch)
treead5c986bbba97a9bc1aa2a44900274329360907c /talpid-core/src
parentc3921b60fd92e114368e1df07b977ec7178a5e65 (diff)
downloadmullvadvpn-8781e5909ff418cb9fc97918b7da328ad148b643.tar.xz
mullvadvpn-8781e5909ff418cb9fc97918b7da328ad148b643.zip
Add winnet function for obtaining the IP address given an interface luid
Diffstat (limited to 'talpid-core/src')
-rw-r--r--talpid-core/src/winnet.rs38
1 files changed, 38 insertions, 0 deletions
diff --git a/talpid-core/src/winnet.rs b/talpid-core/src/winnet.rs
index a648aad982..3015369282 100644
--- a/talpid-core/src/winnet.rs
+++ b/talpid-core/src/winnet.rs
@@ -33,6 +33,10 @@ pub enum Error {
#[error(display = "Failed to obtain default route")]
GetDefaultRoute,
+ /// Failed to obtain an IP address given a LUID.
+ #[error(display = "Failed to obtain IP address for the given interface")]
+ GetIpAddressFromLuid,
+
/// Failed to read IPv6 status on the TAP network interface.
#[error(display = "Failed to read IPv6 status on the TAP network interface")]
GetIpv6Status,
@@ -410,6 +414,28 @@ pub fn get_best_default_route(
}
}
+// TODO: Remove attribute once this is in use.
+#[allow(dead_code)]
+pub fn interface_luid_to_ip(
+ family: WinNetAddrFamily,
+ luid: u64,
+) -> Result<Option<WinNetIp>, Error> {
+ let mut ip = WinNetIp::default();
+ match unsafe {
+ WinNet_InterfaceLuidToIpAddress(
+ family,
+ luid,
+ &mut ip as *mut _,
+ Some(log_sink),
+ logging_context(),
+ )
+ } {
+ InterfaceLuidToIpAddressStatus::Success => Ok(Some(ip)),
+ InterfaceLuidToIpAddressStatus::NotFound => Ok(None),
+ InterfaceLuidToIpAddressStatus::Failure => Err(Error::GetIpAddressFromLuid),
+ }
+}
+
pub fn add_device_ip_addresses(iface: &String, addresses: &Vec<IpAddr>) -> bool {
let raw_iface = WideCString::from_str(iface)
.expect("Failed to convert UTF-8 string to null terminated UCS string")
@@ -438,6 +464,7 @@ mod api {
Failure = 2,
}
pub type GetBestDefaultRouteStatus = FailableOptionalStatus;
+ pub type InterfaceLuidToIpAddressStatus = FailableOptionalStatus;
extern "system" {
#[link_name = "WinNet_ActivateRouteManager"]
@@ -485,6 +512,17 @@ mod api {
sink_context: *const u8,
) -> GetBestDefaultRouteStatus;
+ // TODO: Remove "allow(dead_code)" this is in use.
+ #[allow(dead_code)]
+ #[link_name = "WinNet_InterfaceLuidToIpAddress"]
+ pub fn WinNet_InterfaceLuidToIpAddress(
+ family: super::WinNetAddrFamily,
+ luid: u64,
+ ip: *mut super::WinNetIp,
+ sink: Option<LogSink>,
+ sink_context: *const u8,
+ ) -> InterfaceLuidToIpAddressStatus;
+
#[link_name = "WinNet_GetTapInterfaceAlias"]
pub fn WinNet_GetTapInterfaceAlias(
tunnel_interface_alias: *mut *mut wchar_t,