minor fixed (#120)

1. fix mtu, always set by ourselves and use smaller value
2. wireguard connector should return tunnel after receive packet
This commit is contained in:
Sijie.Sun
2024-05-18 18:04:06 +08:00
committed by GitHub
parent 0ead308392
commit 6efbb5cb3d
4 changed files with 79 additions and 58 deletions
+1 -1
View File
@@ -151,7 +151,7 @@ pub struct Flags {
pub enable_encryption: bool,
#[derivative(Default(value = "true"))]
pub enable_ipv6: bool,
#[derivative(Default(value = "1420"))]
#[derivative(Default(value = "1380"))]
pub mtu: u16,
#[derivative(Default(value = "true"))]
pub latency_first: bool,
+17 -3
View File
@@ -30,6 +30,7 @@ pub trait IfConfiguerTrait: Send + Sync {
async fn wait_interface_show(&self, _name: &str) -> Result<(), Error> {
return Ok(());
}
async fn set_mtu(&self, _name: &str, _mtu: u32) -> Result<(), Error>;
}
fn cidr_to_subnet_mask(prefix_length: u8) -> Ipv4Addr {
@@ -77,9 +78,7 @@ async fn run_shell_cmd(cmd: &str) -> Result<(), Error> {
tracing::info!(?cmd, ?ec, ?succ, ?stdout, ?stderr, "run shell cmd");
if !cmd_out.status.success() {
return Err(Error::ShellCommandError(
stdout + &stderr,
));
return Err(Error::ShellCommandError(stdout + &stderr));
}
Ok(())
}
@@ -154,6 +153,10 @@ impl IfConfiguerTrait for MacIfConfiger {
.await
}
}
async fn set_mtu(&self, name: &str, mtu: u32) -> Result<(), Error> {
run_shell_cmd(format!("ifconfig {} mtu {}", name, mtu).as_str()).await
}
}
pub struct LinuxIfConfiger {}
@@ -210,6 +213,10 @@ impl IfConfiguerTrait for LinuxIfConfiger {
.await
}
}
async fn set_mtu(&self, name: &str, mtu: u32) -> Result<(), Error> {
run_shell_cmd(format!("ip link set dev {} mtu {}", name, mtu).as_str()).await
}
}
#[cfg(target_os = "windows")]
@@ -362,6 +369,13 @@ impl IfConfiguerTrait for WindowsIfConfiger {
.await??,
)
}
async fn set_mtu(&self, name: &str, mtu: u32) -> Result<(), Error> {
run_shell_cmd(
format!("netsh interface ipv4 set subinterface {} mtu={}", name, mtu).as_str(),
)
.await
}
}
#[cfg(target_os = "macos")]