Skip to content

Commit

Permalink
fixup! Refactor open_tunnel
Browse files Browse the repository at this point in the history
  • Loading branch information
Serock3 committed Jan 23, 2025
1 parent 0943253 commit 9f3dab1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
17 changes: 10 additions & 7 deletions talpid-wireguard/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -691,13 +691,13 @@ impl WireguardMonitor {
} else {
#[cfg(target_os = "linux")]
{
let res = if will_nm_manage_dns() {
let res: Option<TunnelType> = if will_nm_manage_dns() {
match wireguard_kernel::NetworkManagerTunnel::new(runtime, config) {
Ok(tunnel) => {
log::debug!(
"Using NetworkManager to use kernel WireGuard implementation"
);
Ok(Box::new(tunnel))
Some(Box::new(tunnel))
}
Err(err) => {
log::error!(
Expand All @@ -706,13 +706,14 @@ impl WireguardMonitor {
"Failed to initialize WireGuard tunnel via NetworkManager"
)
);
None
}
};
}
} else {
match wireguard_kernel::NetlinkTunnel::new(runtime, config) {
Ok(tunnel) => {
log::debug!("Using kernel WireGuard implementation");
Ok(Box::new(tunnel))
Some(Box::new(tunnel))
}
Err(error) => {
log::error!(
Expand All @@ -721,12 +722,14 @@ impl WireguardMonitor {
"Failed to setup kernel WireGuard device, falling back to the userspace implementation"
)
);
None
}
};
}
};

match res {
Ok(tunnel) => Ok(tunnel),
Err(_) => {
Some(tunnel) => Ok(tunnel),
None => {
log::warn!("Falling back to userspace WireGuard implementation");
let tunnel = Self::open_wireguard_go_tunnel(config, log_path, tun_provider)
.map(Box::new)?;
Expand Down
2 changes: 1 addition & 1 deletion talpid-wireguard/src/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ pub fn clean_up_logging(ordinal: u64) {
state.map.remove(&ordinal);
}

#[allow(dead_code)]
pub enum LogLevel {
#[cfg_attr(windows, allow(dead_code))]
Verbose,
Info,
Warning,
Expand Down

0 comments on commit 9f3dab1

Please sign in to comment.