minor changes

This commit is contained in:
ssrlive 2023-09-29 17:53:29 +08:00
parent 18cdfa6b06
commit 03b6e01d4a

View file

@ -194,16 +194,16 @@ impl WinTunInterface {
.iter() .iter()
.find(|addr| addr.is_ipv4()) .find(|addr| addr.is_ipv4())
.ok_or_else(|| io::Error::new(io::ErrorKind::Other, "No ipv4 gateway found"))?; .ok_or_else(|| io::Error::new(io::ErrorKind::Other, "No ipv4 gateway found"))?;
let old_gateway = old_gateway.ip();
self.old_gateway = Some(old_gateway);
// 3. route the bypass ip to the old gateway // 3. route the bypass ip to the old gateway
// command: `route add bypass_ip old_gateway metric 1` // command: `route add bypass_ip old_gateway metric 1`
let bypass_ip = bypass_ip.unwrap().to_string(); if let Some(bypass_ip) = bypass_ip {
let old_gateway = old_gateway.ip(); let args = &["add", &bypass_ip.to_string(), &old_gateway.to_string(), "metric", "1"];
let args = &["add", &bypass_ip, &old_gateway.to_string(), "metric", "1"];
run_command("route", args)?; run_command("route", args)?;
log::info!("route {:?}", args); log::info!("route {:?}", args);
}
self.old_gateway = Some(old_gateway);
Ok(()) Ok(())
} }
@ -345,8 +345,13 @@ impl event::Source for NamedPipeSource {
pub(crate) fn run_command(command: &str, args: &[&str]) -> io::Result<()> { pub(crate) fn run_command(command: &str, args: &[&str]) -> io::Result<()> {
let out = std::process::Command::new(command).args(args).output()?; let out = std::process::Command::new(command).args(args).output()?;
if !out.status.success() { if !out.status.success() {
let info = format!("{} failed: {}", command, String::from_utf8_lossy(&out.stderr)); let err = String::from_utf8_lossy(if out.stderr.is_empty() {
return Err(io::Error::new(io::ErrorKind::Other, info)); &out.stdout
} else {
&out.stderr
});
let info = format!("{} failed with: \"{}\"", command, err);
return Err(std::io::Error::new(std::io::ErrorKind::Other, info));
} }
Ok(()) Ok(())
} }