support udp proxy gateway (#22)

This commit is contained in:
Sijie.Sun
2024-03-01 21:37:45 +08:00
committed by GitHub
parent 24178bcf6e
commit c6c505f9d7
7 changed files with 448 additions and 6 deletions
+6 -2
View File
@@ -286,6 +286,10 @@ pub(crate) fn setup_sokcet2(
#[cfg(all(unix, not(target_os = "solaris"), not(target_os = "illumos")))]
socket2_socket.set_reuse_port(true)?;
if bind_addr.ip().is_unspecified() {
return Ok(());
}
// linux/mac does not use interface of bind_addr to send packet, so we need to bind device
// win can handle this with bind correctly
#[cfg(any(target_os = "ios", target_os = "macos"))]
@@ -380,7 +384,7 @@ pub mod tests {
let mut send = tunnel.pin_sink();
let mut recv = tunnel.pin_stream();
let send_data = Bytes::from("abc");
let send_data = Bytes::from("12345678abcdefg");
send.send(send_data).await.unwrap();
let ret = tokio::time::timeout(tokio::time::Duration::from_secs(1), recv.next())
.await
@@ -388,7 +392,7 @@ pub mod tests {
.unwrap()
.unwrap();
println!("echo back: {:?}", ret);
assert_eq!(ret, Bytes::from("abc"));
assert_eq!(ret, Bytes::from("12345678abcdefg"));
close_tunnel(&tunnel).await.unwrap();