Skip to content

Commit

Permalink
Fix routing issues described in #104
Browse files Browse the repository at this point in the history
  • Loading branch information
blechschmidt committed Apr 9, 2024
1 parent 7bee2e0 commit 3eb2a34
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 35 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ socks5-impl = { version = "0.5" }
thiserror = "1.0"
tokio = { version = "1.36", features = ["full"] }
tokio-util = "0.7"
tproxy-config = { version = ">=3.0.2", features = ["log"] }
tproxy-config = { version = "4.0", features = ["log"] }
trust-dns-proto = "0.23"
tun2 = { version = "1.2", features = ["async"] }
udp-stream = { version = "0.0", default-features = false }
Expand Down
36 changes: 2 additions & 34 deletions src/desktop_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ pub async fn desktop_run_async(args: Args, shutdown_token: tokio_util::sync::Can
let mut tproxy_args = TproxyArgs::new()
.tun_dns(args.dns_addr)
.proxy_addr(args.proxy.addr)
.bypass_ips(&bypass_ips);
.bypass_ips(&bypass_ips)
.ipv6_default_route(args.ipv6_enabled);

#[allow(unused_mut, unused_assignments, unused_variables)]
let mut setup = true;
Expand All @@ -135,39 +136,6 @@ pub async fn desktop_run_async(args: Args, shutdown_token: tokio_util::sync::Can

#[cfg(target_os = "linux")]
{
let run_ip_util = |args: String| {
tokio::process::Command::new("ip")
.args(args.split(' '))
.stdout(std::process::Stdio::null())
.stderr(std::process::Stdio::null())
.spawn()
.ok();
};

if setup && !args.ipv6_enabled {
// Remove ipv6 connectivity if not explicitly required
// TODO: remove this when upstream will get updated
run_ip_util(format!("-6 route delete ::/1 dev {}", tproxy_args.tun_name));
run_ip_util(format!("-6 route delete 80::/1 dev {}", tproxy_args.tun_name));
}

#[cfg(target_os = "linux")]
if setup && args.unshare {
// New namespace doesn't have any other routing device by default
// So our `tun` device should act as such to make space for other proxies.
run_ip_util(format!("route delete 0.0.0.0/1 dev {}", tproxy_args.tun_name));
run_ip_util(format!("route delete 128.0.0.0/1 dev {}", tproxy_args.tun_name));

run_ip_util(format!("route add 0.0.0.0/0 dev {}", tproxy_args.tun_name));

if args.ipv6_enabled {
run_ip_util(format!("-6 route delete ::/1 dev {}", tproxy_args.tun_name));
run_ip_util(format!("-6 route delete 80::/1 dev {}", tproxy_args.tun_name));

run_ip_util(format!("-6 route add ::/0 dev {}", tproxy_args.tun_name));
}
}

let mut admin_command_args = args.admin_command.iter();
if let Some(command) = admin_command_args.next() {
let child = tokio::process::Command::new(command)
Expand Down

0 comments on commit 3eb2a34

Please sign in to comment.