Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
authors = ['Narrowlink <opensource@narrowlink.com>']
description = 'Asynchronous lightweight userspace implementation of TCP/IP stack for Tun device'
name = "ipstack"
version = "1.0.0"
version = "1.0.1"
edition = "2024"
license = "Apache-2.0"
repository = 'https://github.com/narrowlink/ipstack'
Expand All @@ -11,11 +11,11 @@ readme = "README.md"

[dependencies]
ahash = { version = "0.8", default-features = false, features = ["std"] }
etherparse = { version = "0.19", default-features = false, features = ["std"] }
etherparse = { version = "0.20", default-features = false, features = ["std"] }
log = { version = "0.4", default-features = false }
rand = { version = "0.9", default-features = false, features = ["thread_rng"] }
rand = { version = "0.10", default-features = false, features = ["thread_rng"] }
thiserror = { version = "2.0", default-features = false }
tokio = { version = "1.48", default-features = false, features = [
tokio = { version = "1.52", default-features = false, features = [
"sync",
"rt",
"time",
Expand All @@ -25,11 +25,11 @@ tokio = { version = "1.48", default-features = false, features = [
] }

[dev-dependencies]
clap = { version = "4.5", default-features = false, features = ["derive"] }
clap = { version = "4.6", default-features = false, features = ["derive"] }
criterion = { version = "0.8" } # Benchmarks
dotenvy = "0.15"
env_logger = "0.11"
tokio = { version = "1.48", default-features = false, features = [
tokio = { version = "1.52", default-features = false, features = [
"rt-multi-thread",
] }
tun = { version = "0.8", default-features = false, features = ["async"] }
Expand Down
42 changes: 18 additions & 24 deletions src/stream/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -695,14 +695,12 @@ async fn tcp_main_logic_loop(
}

match state {
TcpState::SynReceived => {
if flags & ACK == ACK {
if len > 0 {
tcb.add_unordered_packet(incoming_seq, payload);
extract_data_n_write_upstream(&up_packet_sender, &mut tcb, network_tuple, &data_tx, &read_notify)?;
}
tcb.change_state(TcpState::Established);
TcpState::SynReceived if flags & ACK == ACK => {
if len > 0 {
tcb.add_unordered_packet(incoming_seq, payload);
extract_data_n_write_upstream(&up_packet_sender, &mut tcb, network_tuple, &data_tx, &read_notify)?;
}
tcb.change_state(TcpState::Established);
}
TcpState::Established => {
if flags == ACK {
Expand Down Expand Up @@ -818,17 +816,15 @@ async fn tcp_main_logic_loop(
write_notify.lock().unwrap().take().map(|w| w.wake_by_ref()).unwrap_or(());
}
}
TcpState::LastAck => {
if flags & ACK == ACK {
tcb.change_state(TcpState::Closed);
tokio::spawn(async move {
if let Err(e) = exit_notifier.send(()).await {
log::debug!("exit_notifier send failed: {e}");
}
});
let new_state = tcb.get_state();
log::trace!("{network_tuple} {state:?}: Received final ACK, transitioned to {new_state:?}");
}
TcpState::LastAck if flags & ACK == ACK => {
tcb.change_state(TcpState::Closed);
tokio::spawn(async move {
if let Err(e) = exit_notifier.send(()).await {
log::debug!("exit_notifier send failed: {e}");
}
});
let new_state = tcb.get_state();
log::trace!("{network_tuple} {state:?}: Received final ACK, transitioned to {new_state:?}");
}
TcpState::FinWait1 => {
if flags & (ACK | FIN) == (ACK | FIN) && len == 0 {
Expand Down Expand Up @@ -889,12 +885,10 @@ async fn tcp_main_logic_loop(
log::trace!("{network_tuple} {state:?}: Some unnormal case, we do nothing here");
}
}
TcpState::TimeWait => {
if flags & (ACK | FIN) == (ACK | FIN) {
write_packet_to_device(&up_packet_sender, network_tuple, &tcb, None, ACK, None, None)?;
// wait to timeout, can't call `tcb.change_state(TcpState::Closed);` to change state here
// now we need to wait for the timeout to reach...
}
TcpState::TimeWait if flags & (ACK | FIN) == (ACK | FIN) => {
write_packet_to_device(&up_packet_sender, network_tuple, &tcb, None, ACK, None, None)?;
// wait to timeout, can't call `tcb.change_state(TcpState::Closed);` to change state here
// now we need to wait for the timeout to reach...
}
_ => {}
} // end of match state
Expand Down
Loading