From 4ca7f6b82489f07177c69e236092996524997af3 Mon Sep 17 00:00:00 2001 From: Markus Pettersson Date: Thu, 2 Jan 2025 13:21:47 +0100 Subject: [PATCH] Clean up API for setting tunnel device name --- talpid-tunnel/src/tun_provider/mod.rs | 2 ++ talpid-tunnel/src/tun_provider/unix.rs | 10 ++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/talpid-tunnel/src/tun_provider/mod.rs b/talpid-tunnel/src/tun_provider/mod.rs index 94a82735d183..1bf4e1abb483 100644 --- a/talpid-tunnel/src/tun_provider/mod.rs +++ b/talpid-tunnel/src/tun_provider/mod.rs @@ -35,6 +35,7 @@ cfg_if! { #[derive(Clone, Debug, Eq, PartialEq)] pub struct TunConfig { /// Interface name to use. + #[cfg(target_os = "linux")] pub name: Option, /// IP addresses for the tunnel interface. @@ -80,6 +81,7 @@ impl TunConfig { /// Android to route all traffic inside the tunnel. pub fn blocking_config() -> TunConfig { TunConfig { + #[cfg(target_os = "linux")] name: None, addresses: vec![IpAddr::V4(Ipv4Addr::new(10, 0, 0, 1))], mtu: 1380, diff --git a/talpid-tunnel/src/tun_provider/unix.rs b/talpid-tunnel/src/tun_provider/unix.rs index 71b988f59b54..588cb7a35929 100644 --- a/talpid-tunnel/src/tun_provider/unix.rs +++ b/talpid-tunnel/src/tun_provider/unix.rs @@ -70,10 +70,11 @@ impl UnixTunProvider { #[allow(unused_mut)] let mut builder = TunnelDeviceBuilder::default(); #[cfg(target_os = "linux")] - builder.enable_packet_information(); - #[cfg(target_os = "linux")] - if let Some(ref name) = self.config.name { - builder.name(name); + { + builder.enable_packet_information(); + if let Some(ref name) = self.config.name { + builder.name(name); + } } builder.create()? }; @@ -137,6 +138,7 @@ impl TunnelDeviceBuilder { } /// Set a custom name for this tunnel device. + #[cfg(target_os = "linux")] pub fn name(&mut self, name: &str) -> &mut Self { self.config.tun_name(name); self