Skip to content

Commit

Permalink
Clean up API for setting tunnel device name
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkusPettersson98 committed Jan 2, 2025
1 parent d4a8c92 commit 4ca7f6b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 2 additions & 0 deletions talpid-tunnel/src/tun_provider/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,

/// IP addresses for the tunnel interface.
Expand Down Expand Up @@ -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,
Expand Down
10 changes: 6 additions & 4 deletions talpid-tunnel/src/tun_provider/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()?
};
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 4ca7f6b

Please sign in to comment.