Skip to content

Commit

Permalink
Bump version 6.0.5
Browse files Browse the repository at this point in the history
  • Loading branch information
ssrlive committed Oct 3, 2024
1 parent afdbb86 commit b931489
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "tproxy-config"
version = "6.0.4"
version = "6.0.5"
edition = "2021"
description = "Transparent proxy configuration"
license = "MIT"
Expand Down
13 changes: 11 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,19 @@ pub(crate) const ETC_RESOLV_CONF_FILE: &str = "/etc/resolv.conf";

#[allow(dead_code)]
pub(crate) fn run_command(command: &str, args: &[&str]) -> std::io::Result<Vec<u8>> {
let out = std::process::Command::new(command).args(args).output()?;
let full_cmd = format!("{} {}", command, args.join(" "));
log::trace!("Running command: \"{full_cmd}\"...");
let out = match std::process::Command::new(command).args(args).output() {
Ok(out) => out,
Err(e) => {
log::trace!("Run command: \"{full_cmd}\" failed with: {e}");
return Err(e);
}
};
if !out.status.success() {
let err = String::from_utf8_lossy(if out.stderr.is_empty() { &out.stdout } else { &out.stderr });
let info = format!("{} failed with: \"{}\"", command, err);
let info = format!("Run command: \"{full_cmd}\" failed with {err}");
log::trace!("{}", info);
return Err(std::io::Error::new(std::io::ErrorKind::Other, info));
}
Ok(out.stdout)
Expand Down
3 changes: 0 additions & 3 deletions src/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ pub fn tproxy_setup(tproxy_args: &TproxyArgs) -> std::io::Result<TproxyState> {
};
let gateway = tproxy_args.tun_gateway.to_string();
let args = &["add", &unspecified, "mask", &unspecified, &gateway, "metric", "6"];
log::info!("route {:?}", args);
run_command("route", args)?;

let (original_gateway, _) = get_default_gateway()?;
Expand All @@ -32,7 +31,6 @@ pub fn tproxy_setup(tproxy_args: &TproxyArgs) -> std::io::Result<TproxyState> {
// command: `netsh interface ip set dns "utun3" static 10.0.0.1`
let tun_name = format!("\"{}\"", tproxy_args.tun_name);
let args = &["interface", "ip", "set", "dns", &tun_name, "static", &gateway];
log::info!("netsh {:?}", args);
run_command("netsh", args)?;

let state = TproxyState {
Expand All @@ -54,7 +52,6 @@ fn do_bypass_ip(bypass_ip: cidr::IpCidr, original_gateway: IpAddr) -> std::io::R
// route the bypass ip to the original gateway
// command: `route add bypass_ip/24 original_gateway metric 1`
let args = &["add", &bypass_ip.to_string(), &original_gateway.to_string(), "metric", "1"];
log::info!("route {:?}", args);
run_command("route", args)?;
Ok(())
}
Expand Down

0 comments on commit b931489

Please sign in to comment.