-
Notifications
You must be signed in to change notification settings - Fork 50
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
Conversation
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.
src/net/tcp/stream.rs
Outdated
@@ -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() { |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
?
There was a problem hiding this 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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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)