Propogate stack errors to handle callers

This commit is contained in:
Jackson Coxson
2025-08-15 20:25:03 -06:00
parent ef7811b3a6
commit 5cbdb2505a
3 changed files with 22 additions and 3 deletions

View File

@@ -581,7 +581,7 @@ impl Adapter {
} }
if res.flags.fin { if res.flags.fin {
ack_me = Some(res.destination_port); ack_me = Some(res.destination_port);
state.status = ConnectionStatus::Error(ErrorKind::ConnectionReset); state.status = ConnectionStatus::Error(ErrorKind::UnexpectedEof);
} }
if res.flags.syn && res.flags.ack { if res.flags.syn && res.flags.ack {
ack_me = Some(res.destination_port); ack_me = Some(res.destination_port);

View File

@@ -14,6 +14,8 @@ use tokio::{
sync::oneshot, sync::oneshot,
}; };
use crate::tcp::adapter::ConnectionStatus;
pub type ConnectToPortRes = pub type ConnectToPortRes =
oneshot::Sender<Result<(u16, AsyncRx<Result<Vec<u8>, std::io::Error>>), std::io::Error>>; oneshot::Sender<Result<(u16, AsyncRx<Result<Vec<u8>, std::io::Error>>), std::io::Error>>;
@@ -124,6 +126,23 @@ impl AdapterHandle {
handles.remove(&hp); handles.remove(&hp);
let _ = adapter.close(hp).await; let _ = adapter.close(hp).await;
} }
let mut to_close = Vec::new();
for (&hp, tx) in &handles {
if let Ok(ConnectionStatus::Error(kind)) = adapter.get_status(hp) {
if kind == std::io::ErrorKind::UnexpectedEof {
to_close.push(hp);
} else {
let _ = tx.send(Err(std::io::Error::from(kind)));
to_close.push(hp);
}
}
}
for hp in to_close {
handles.remove(&hp);
// Best-effort close. For RST this just tidies state on our side
let _ = adapter.close(hp).await;
}
} }
_ = tick.tick() => { _ = tick.tick() => {

View File

@@ -5,7 +5,7 @@ use std::{
time::{SystemTime, UNIX_EPOCH}, time::{SystemTime, UNIX_EPOCH},
}; };
use log::debug; use log::trace;
use tokio::io::AsyncWriteExt; use tokio::io::AsyncWriteExt;
use crate::{ReadWrite, provider::RsdProvider}; use crate::{ReadWrite, provider::RsdProvider};
@@ -16,7 +16,7 @@ pub mod packets;
pub mod stream; pub mod stream;
pub(crate) fn log_packet(file: &Arc<tokio::sync::Mutex<tokio::fs::File>>, packet: &[u8]) { pub(crate) fn log_packet(file: &Arc<tokio::sync::Mutex<tokio::fs::File>>, packet: &[u8]) {
debug!("Logging {} byte packet", packet.len()); trace!("Logging {} byte packet", packet.len());
let packet = packet.to_vec(); let packet = packet.to_vec();
let file = file.to_owned(); let file = file.to_owned();
let now = SystemTime::now(); let now = SystemTime::now();