From 51ab80181450256475f082f513a6ab9373b898dd Mon Sep 17 00:00:00 2001 From: Trinity Pointard Date: Tue, 17 Mar 2020 13:29:05 +0100 Subject: [PATCH 1/2] use provided ip for TcpSocket::connect instead of 0.0.0.0 --- src/socket/tcp.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/socket/tcp.rs b/src/socket/tcp.rs index 09c47fefd..0c358a52b 100644 --- a/src/socket/tcp.rs +++ b/src/socket/tcp.rs @@ -483,9 +483,9 @@ impl<'a> TcpSocket<'a> { // If local address is not provided, use an unspecified address but a specified protocol. // This lets us lower IpRepr later to determine IP header size and calculate MSS, // but without committing to a specific address right away. - let local_addr = match remote_endpoint.addr { - IpAddress::Unspecified => return Err(Error::Unaddressable), - _ => remote_endpoint.addr.to_unspecified(), + let local_addr = match local_endpoint.addr { + IpAddress::Unspecified => remote_endpoint.addr.to_unspecified(), + ip => ip, }; let local_endpoint = IpEndpoint { addr: local_addr, ..local_endpoint }; From 7bceb9bb287e12ee0062aea6ff2cba73d19a7e0f Mon Sep 17 00:00:00 2001 From: Trinity Pointard Date: Tue, 17 Mar 2020 20:15:13 +0100 Subject: [PATCH 2/2] update tests add non regression test to test_connect_validation fix test_syn_sent_sanity to accept socket with set local ip --- src/socket/tcp.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/socket/tcp.rs b/src/socket/tcp.rs index 0c358a52b..b88d58391 100644 --- a/src/socket/tcp.rs +++ b/src/socket/tcp.rs @@ -1894,6 +1894,16 @@ mod test { s } + fn socket_syn_sent_with_local_ipendpoint(local: IpEndpoint) -> TcpSocket<'static> { + let mut s = socket(); + s.state = State::SynSent; + s.local_endpoint = local; + s.remote_endpoint = REMOTE_END; + s.local_seq_no = LOCAL_SEQ; + s.remote_last_seq = LOCAL_SEQ; + s + } + fn socket_established_with_buffer_sizes(tx_len: usize, rx_len: usize) -> TcpSocket<'static> { let mut s = socket_syn_received_with_buffer_sizes(tx_len, rx_len); s.state = State::Established; @@ -2318,6 +2328,9 @@ mod test { Err(Error::Unaddressable)); assert_eq!(s.connect((IpAddress::Unspecified, 80), LOCAL_END), Err(Error::Unaddressable)); + s.connect(REMOTE_END, LOCAL_END).expect("Connect failed with valid parameters"); + assert_eq!(s.local_endpoint(), LOCAL_END); + assert_eq!(s.remote_endpoint(), REMOTE_END); } #[test] @@ -2378,7 +2391,7 @@ mod test { let mut s = socket(); s.local_seq_no = LOCAL_SEQ; s.connect(REMOTE_END, LOCAL_END).unwrap(); - sanity!(s, socket_syn_sent()); + sanity!(s, socket_syn_sent_with_local_ipendpoint(LOCAL_END)); } #[test]