diff options
| author | David Lönnhager <david.l@mullvad.net> | 2025-06-12 15:07:28 +0200 |
|---|---|---|
| committer | David Lönnhager <david.l@mullvad.net> | 2025-06-12 15:07:28 +0200 |
| commit | f0efcc68cfc310f6965443c28fbbf59455187165 (patch) | |
| tree | bdd9c5c90fa3de5940792c8c8a62b8ac5ee4d1d9 | |
| parent | d1e7c795be9a67db5d73539154b37a4a871a6009 (diff) | |
| parent | 98c86b21ec58a5e136b30a6039ddf4bfff8fa602 (diff) | |
| download | mullvadvpn-f0efcc68cfc310f6965443c28fbbf59455187165.tar.xz mullvadvpn-f0efcc68cfc310f6965443c28fbbf59455187165.zip | |
Merge branch 'win-add-ipv6-boringtun'
| -rw-r--r-- | talpid-tunnel/src/tun_provider/windows.rs | 39 |
1 files changed, 23 insertions, 16 deletions
diff --git a/talpid-tunnel/src/tun_provider/windows.rs b/talpid-tunnel/src/tun_provider/windows.rs index 646cf70125..eb60655cc3 100644 --- a/talpid-tunnel/src/tun_provider/windows.rs +++ b/talpid-tunnel/src/tun_provider/windows.rs @@ -7,12 +7,8 @@ use tun07::{AbstractDevice, AsyncDevice, Configuration}; #[derive(Debug, thiserror::Error)] pub enum Error { /// Failed to set IP address - #[error("Failed to set IPv4 address")] - SetIpv4(#[source] tun::Error), - - /// Failed to set IP address #[error("Failed to set IPv6 address")] - SetIpv6(#[source] io::Error), + SetIp(#[source] talpid_windows::net::Error), /// Unable to open a tunnel device #[error("Unable to open a tunnel device")] @@ -22,6 +18,10 @@ pub enum Error { #[error("Failed to enable/disable link device")] ToggleDevice(#[source] tun::Error), + /// Failed to get device luid + #[error("Failed to get tunnel device luid")] + GetDeviceLuid(#[source] io::Error), + /// Failed to get device name #[error("Failed to get tunnel device name")] GetDeviceName(#[source] tun::Error), @@ -49,17 +49,26 @@ impl WindowsTunProvider { /// Open a tunnel using the current tunnel config. pub fn open_tun(&mut self) -> Result<WindowsTun, Error> { + let (first_addr, remaining_addrs) = self + .config + .addresses + .split_first() + .map(|(first, rest)| (Some(first), rest)) + .unwrap_or((None, &[])); + let mut tunnel_device = { #[allow(unused_mut)] let mut builder = TunnelDeviceBuilder::default(); - #[cfg(target_os = "linux")] - if let Some(ref name) = self.config.name { - builder.name(name); + // TODO: set alias + // TODO: have tun either not use netsh or not set any default address at all + // TODO: tun can only set a single address + if let Some(addr) = first_addr { + builder.config.address(*addr); } builder.create()? }; - for ip in self.config.addresses.iter() { + for ip in remaining_addrs { tunnel_device.set_ip(*ip)?; } @@ -122,13 +131,11 @@ impl Default for TunnelDeviceBuilder { impl TunnelDevice { fn set_ip(&mut self, ip: IpAddr) -> Result<(), Error> { - match ip { - IpAddr::V4(ipv4) => self.dev.set_address(ipv4.into()).map_err(Error::SetIpv4), - IpAddr::V6(_ipv6) => { - // TODO - todo!("ipv6 not implemented"); - } - } + // TODO: Expose luid from wintun-bindings. + // Also, maybe, update wintun-bindings to use Windows APIs instead of netsh + let name = self.get_name()?; + let luid = talpid_windows::net::luid_from_alias(&name).map_err(Error::GetDeviceLuid)?; + talpid_windows::net::add_ip_address_for_interface(luid, ip).map_err(Error::SetIp) } fn set_up(&mut self, up: bool) -> Result<(), Error> { |
