From 44b7c0f55e2866600c3f305cf6432a4279541284 Mon Sep 17 00:00:00 2001 From: Datong Sun Date: Thu, 16 Sep 2021 22:17:47 -0700 Subject: [PATCH] fix(fake_tcp) fixed incorrect RST SEQ/ACK --- src/bin/client.rs | 12 +++++++++--- src/fake_tcp/mod.rs | 4 ++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/bin/client.rs b/src/bin/client.rs index 630f25a..5142042 100644 --- a/src/bin/client.rs +++ b/src/bin/client.rs @@ -64,8 +64,8 @@ async fn main() { info!("Created TUN device {}", tun.name()); let udp_sock = Arc::new(UdpSocket::bind(local_addr).await.unwrap()); - let connections = Mutex::new(LruCache::>::with_expiry_duration( - UDP_TTL, + let connections = Arc::new(Mutex::new( + LruCache::>::with_expiry_duration(UDP_TTL), )); let mut stack = Stack::new(tun); @@ -96,8 +96,10 @@ async fn main() { } assert!(connections.lock().await.insert(addr, sock.clone()).is_none()); + debug!("inserted fake TCP socket into LruCache"); let udp_sock = udp_sock.clone(); + let connections = connections.clone(); tokio::spawn(async move { loop { let mut buf_r = [0u8; MAX_PACKET_LEN]; @@ -105,7 +107,11 @@ async fn main() { Some(size) => { udp_sock.send_to(&buf_r[..size], addr).await.unwrap(); }, - None => { return; }, + None => { + connections.lock().await.remove(&addr); + debug!("removed fake TCP socket from LruCache"); + return; + }, } } }); diff --git a/src/fake_tcp/mod.rs b/src/fake_tcp/mod.rs index 6658810..f743e77 100644 --- a/src/fake_tcp/mod.rs +++ b/src/fake_tcp/mod.rs @@ -399,7 +399,7 @@ impl Stack { local_addr, remote_addr, 0, - tcp_packet.get_acknowledgement() + 1, + tcp_packet.get_sequence() + 1, tcp::TcpFlags::RST, None, ); @@ -410,8 +410,8 @@ impl Stack { let buf = build_tcp_packet( local_addr, remote_addr, + tcp_packet.get_acknowledgement(), 0, - tcp_packet.get_acknowledgement() + 1, tcp::TcpFlags::RST, None, );