mirror of
https://github.com/dndx/phantun.git
synced 2025-01-31 12:19:30 +08:00
fix(fake_tcp) fixed incorrect RST SEQ/ACK
This commit is contained in:
parent
9251775856
commit
44b7c0f55e
@ -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::<SocketAddrV4, Arc<Socket>>::with_expiry_duration(
|
||||
UDP_TTL,
|
||||
let connections = Arc::new(Mutex::new(
|
||||
LruCache::<SocketAddrV4, Arc<Socket>>::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;
|
||||
},
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -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,
|
||||
);
|
||||
|
Loading…
x
Reference in New Issue
Block a user