Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend loopback workaround #140

Merged
merged 3 commits into from
Oct 17, 2023
Merged

Extend loopback workaround #140

merged 3 commits into from
Oct 17, 2023

Conversation

jeremymill
Copy link
Contributor

This should resolve #135.

Current workaround for loopback from #118 does not allow connecting to the same host when using the public ip. This change extends the workaround to allow for that, unblocking additional use cases pending a larger rework to fully support multiple interfaces (see #132)

Current workaround for loopback does not allow connecting to the same
host when using the public ip. This change extends the workaround to
allow for that, unblocking additional use cases pending a larger rework
to fully support multiple interfaces.
@@ -74,7 +74,7 @@ impl TcpStream {
let rx = host.tcp.new_stream(pair);

let syn = Protocol::Tcp(Segment::Syn(Syn { ack }));
if !dst.ip().is_loopback() {
if !dst.ip().is_loopback() && dst.ip() != local_addr.ip() {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe introduce a function that can compare the host for 2 IPs.

src/host.rs Outdated
@@ -417,6 +417,11 @@ pub fn matches(bind: SocketAddr, dst: SocketAddr) -> bool {
bind == dst
}

/// Returns whether loopback is supported from src to dst
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically this is not a loopback. It ends up behaving like loopback because of how turmoil is routing to the local IP address. Mayeb is_same?

Copy link
Contributor

@mcches mcches left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for picking up this issue. I left one comment.

fn loopback_wildcard_public_v4() -> Result {
let bind_addr = SocketAddr::new(Ipv4Addr::UNSPECIFIED.into(), 1234);
let connect_addr = SocketAddr::from((Ipv4Addr::new(192, 168, 0, 1), 1234));
run_localhost_test(IpVersion::V4, bind_addr, connect_addr)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this verify the stream's addrs are set the same as what tokio::net types return? These need to behave the same way.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

run_localhost_test asserts:

assert_eq!(socket.local_addr()?.ip(), connect_addr.ip());
assert_eq!(socket.peer_addr()?.ip(), connect_addr.ip());

on both server and client.

@mcches mcches merged commit 9f56e96 into tokio-rs:main Oct 17, 2023
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Loopback is incomplete
4 participants