summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--talpid-core/src/winnet.rs37
1 files changed, 36 insertions, 1 deletions
diff --git a/talpid-core/src/winnet.rs b/talpid-core/src/winnet.rs
index 21b5bb3ae7..3e7a52bf75 100644
--- a/talpid-core/src/winnet.rs
+++ b/talpid-core/src/winnet.rs
@@ -3,7 +3,11 @@ pub use self::api::{WinNet_ActivateConnectivityMonitor, WinNet_DeactivateConnect
use crate::{logging::windows::log_sink, routing::Node};
use ipnetwork::IpNetwork;
use libc::{c_void, wchar_t};
-use std::{ffi::OsString, net::IpAddr, ptr};
+use std::{
+ ffi::{OsStr, OsString},
+ net::IpAddr,
+ ptr,
+};
use widestring::WideCString;
/// Errors that this module may produce.
@@ -17,6 +21,10 @@ pub enum Error {
#[error(display = "Supplied interface alias is invalid")]
InvalidInterfaceAlias(#[error(source)] widestring::NulError<u16>),
+ /// Failed to enable IPv6 on the network interface.
+ #[error(display = "Failed to enable IPv6 on the network interface")]
+ EnableIpv6,
+
/// Failed to read IPv6 status on the TAP network interface.
#[error(display = "Failed to read IPv6 status on the TAP network interface")]
GetIpv6Status,
@@ -62,6 +70,26 @@ pub fn ensure_best_metric_for_interface(interface_alias: &str) -> Result<bool, E
}
}
+/// Enables IPv6 for a given interface.
+pub fn enable_ipv6_for_adapter(interface_alias: &OsStr) -> Result<(), Error> {
+ let interface_alias_ws =
+ WideCString::from_os_str(interface_alias).map_err(Error::InvalidInterfaceAlias)?;
+
+ let result = unsafe {
+ WinNet_EnableIpv6ForAdapter(
+ interface_alias_ws.as_ptr(),
+ Some(log_sink),
+ logging_context(),
+ )
+ };
+
+ if result {
+ Ok(())
+ } else {
+ Err(Error::EnableIpv6)
+ }
+}
+
/// Checks if IPv6 is enabled for the TAP interface
pub fn get_tap_interface_ipv6_status() -> Result<bool, Error> {
// WinNet_GetTapInterfaceIpv6Status() will fail if the alias cannot be retrieved.
@@ -380,6 +408,13 @@ mod api {
sink_context: *const u8,
) -> u32;
+ #[link_name = "WinNet_EnableIpv6ForAdapter"]
+ pub fn WinNet_EnableIpv6ForAdapter(
+ tunnel_interface_alias: *const wchar_t,
+ sink: Option<LogSink>,
+ sink_context: *const u8,
+ ) -> bool;
+
#[link_name = "WinNet_GetTapInterfaceIpv6Status"]
pub fn WinNet_GetTapInterfaceIpv6Status(
sink: Option<LogSink>,