Skip to content

Commit

Permalink
Fix dropping datagrams from unknown connections on the client endpoint (
Browse files Browse the repository at this point in the history
  • Loading branch information
iyangsj authored May 16, 2024
1 parent 7cf54a5 commit 16ccb9f
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions src/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,10 @@ impl Endpoint {
}

// Drop the datagram for unrecognized connection for client
if !self.is_server && self.config.stateless_reset {
self.send_stateless_reset(buf.len(), &hdr.dcid, local, remote)?;
if !self.is_server {
if self.config.stateless_reset {
self.send_stateless_reset(buf.len(), &hdr.dcid, local, remote)?;
}
return Ok(());
}

Expand Down Expand Up @@ -2297,6 +2299,31 @@ mod tests {
Ok(())
}

#[test]
fn endpoint_client_recv_invalid_initial() -> Result<()> {
let sock = Rc::new(MockSocket::new());
let mut conf = TestPair::new_test_config(false)?;
conf.enable_stateless_reset(false);

let mut e = Endpoint::new(
Box::new(conf),
false,
Box::new(ClientHandler::new(
CaseConf::default(),
Arc::new(AtomicBool::new(false)),
)),
sock.clone(),
);
let info = TestTool::new_test_packet_info(false);

// Client recv an Initial with ClientHello message
let mut initial = TEST_INITIAL.clone();
e.recv(&mut initial, &info)?;
assert_eq!(e.conns.len(), 0);

Ok(())
}

#[test]
fn endpoint_conn_raw_pointer_stability() -> Result<()> {
let cli_addr: SocketAddr = "127.8.8.8:8888".parse().unwrap();
Expand Down

0 comments on commit 16ccb9f

Please sign in to comment.