mirror of
https://github.com/tun2proxy/tun2proxy.git
synced 2025-06-05 14:20:21 +00:00
Use destructor to restore network config
This commit is contained in:
parent
0239a225a1
commit
ebbe939f85
2 changed files with 5 additions and 10 deletions
|
@ -30,7 +30,7 @@ socks5-impl = { version = "0.5" }
|
||||||
thiserror = "1.0"
|
thiserror = "1.0"
|
||||||
tokio = { version = "1.36", features = ["full"] }
|
tokio = { version = "1.36", features = ["full"] }
|
||||||
tokio-util = "0.7"
|
tokio-util = "0.7"
|
||||||
tproxy-config = { version = "3.0", features = ["log"] }
|
tproxy-config = { version = ">=3.0.2", features = ["log"] }
|
||||||
trust-dns-proto = "0.23"
|
trust-dns-proto = "0.23"
|
||||||
tun2 = { version = "1.2", features = ["async"] }
|
tun2 = { version = "1.2", features = ["async"] }
|
||||||
udp-stream = { version = "0.0", default-features = false }
|
udp-stream = { version = "0.0", default-features = false }
|
||||||
|
|
|
@ -119,7 +119,9 @@ pub async fn desktop_run_async(args: Args, shutdown_token: tokio_util::sync::Can
|
||||||
tproxy_args = tproxy_args.tun_name(&tun_name);
|
tproxy_args = tproxy_args.tun_name(&tun_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut restore: Option<tproxy_config::TproxyState> = None;
|
// TproxyState implements the Drop trait to restore network configuration,
|
||||||
|
// so we we need to assign it to a variable, even if it is not used.
|
||||||
|
let mut _restore: Option<tproxy_config::TproxyState> = None;
|
||||||
|
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
{
|
{
|
||||||
|
@ -128,7 +130,7 @@ pub async fn desktop_run_async(args: Args, shutdown_token: tokio_util::sync::Can
|
||||||
|
|
||||||
#[cfg(any(target_os = "linux", target_os = "windows", target_os = "macos"))]
|
#[cfg(any(target_os = "linux", target_os = "windows", target_os = "macos"))]
|
||||||
if setup {
|
if setup {
|
||||||
restore = Some(tproxy_config::tproxy_setup(&tproxy_args)?);
|
_restore = Some(tproxy_config::tproxy_setup(&tproxy_args)?);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
|
@ -191,13 +193,6 @@ pub async fn desktop_run_async(args: Args, shutdown_token: tokio_util::sync::Can
|
||||||
let join_handle = tokio::spawn(crate::run(device, MTU, args, shutdown_token));
|
let join_handle = tokio::spawn(crate::run(device, MTU, args, shutdown_token));
|
||||||
join_handle.await.map_err(std::io::Error::from)??;
|
join_handle.await.map_err(std::io::Error::from)??;
|
||||||
|
|
||||||
#[cfg(any(target_os = "linux", target_os = "windows", target_os = "macos"))]
|
|
||||||
if setup {
|
|
||||||
// TODO: This probably should be handled by a destructor
|
|
||||||
// since otherwise removal is not guaranteed if anything above returns early.
|
|
||||||
tproxy_config::tproxy_remove(restore)?;
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok::<(), std::io::Error>(())
|
Ok::<(), std::io::Error>(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue