Browse Source

feat(Linux): phase out reliance on iproute2

pull/214/head
B. Blechschmidt 12 months ago
parent
commit
584bdc17ed
  1. 2
      Cargo.toml
  2. 16
      src/general_api.rs

2
Cargo.toml

@ -49,7 +49,7 @@ socks5-impl = { version = "0.7", default-features = false, features = [
thiserror = "2"
tokio = { version = "1", features = ["full"] }
tokio-util = "0.7"
tproxy-config = { version = "6", default-features = false }
tproxy-config = { version = "7", default-features = false }
tun = { version = "0.8", features = ["async"] }
udp-stream = { version = "0.0.12", default-features = false }
unicase = "2"

16
src/general_api.rs

@ -207,11 +207,11 @@ pub async fn general_run_async(
// TproxyState implements the Drop trait to restore network configuration,
// so we need to assign it to a variable, even if it is not used.
#[cfg(any(target_os = "linux", target_os = "windows", target_os = "macos"))]
let mut _restore: Option<tproxy_config::TproxyState> = None;
let mut restore: Option<tproxy_config::TproxyState> = None;
#[cfg(any(target_os = "linux", target_os = "windows", target_os = "macos"))]
if args.setup {
_restore = Some(tproxy_config::tproxy_setup(&tproxy_args)?);
restore = Some(tproxy_config::tproxy_setup(&tproxy_args).await?);
}
#[cfg(target_os = "linux")]
@ -238,8 +238,16 @@ pub async fn general_run_async(
}
}
let join_handle = tokio::spawn(crate::run(device, tun_mtu, args, shutdown_token));
Ok(join_handle.await.map_err(std::io::Error::from)??)
let join_handle = tokio::spawn(crate::run(device, tun_mtu, args, shutdown_token.clone()));
match join_handle.await? {
Ok(sessions) => {
#[cfg(any(target_os = "linux", target_os = "windows", target_os = "macos"))]
tproxy_config::tproxy_remove(restore).await?;
Ok(sessions)
}
Err(err) => Err(std::io::Error::from(err)),
}
}
/// # Safety

Loading…
Cancel
Save