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

Allow to lookup the initial local IP address #943

Merged
merged 1 commit into from
Dec 29, 2020
Merged

Conversation

Matthias247
Copy link
Contributor

When a listener is bound to multiple network interfaces (e.g. ::0),
it is not obvious which IP the peer used to send a packet. We however
might need this information to send packets back to the peer with the
same source address.

This problem is described in #508.

This change makes the destination IP address which was used to send
the initial packet available in the Conneting and Connection types.

The information is far available only on Linux due to missing test on
other platforms.

Copy link
Collaborator

@Ralith Ralith left a comment

Choose a reason for hiding this comment

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

Nice work! Just some cosmetic thoughts + the CI issue.

quinn-proto/src/connection/mod.rs Outdated Show resolved Hide resolved
quinn-proto/src/endpoint.rs Outdated Show resolved Hide resolved
quinn/src/connection.rs Outdated Show resolved Hide resolved
@Matthias247 Matthias247 force-pushed the dest_ip branch 4 times, most recently from 7b8bc69 to be481ab Compare December 22, 2020 00:02
Ralith
Ralith previously approved these changes Dec 22, 2020
Copy link
Collaborator

@Ralith Ralith left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

Could we add coverage for this in the quinn-level unit tests, perhaps?

quinn/src/connection.rs Outdated Show resolved Hide resolved
quinn/src/connection.rs Outdated Show resolved Hide resolved
@Matthias247
Copy link
Contributor Author

Could we add coverage for this in the quinn-level unit tests, perhaps?

I added some minimal coverage by reading the field and checking that it's available on Linux, and points to the loopback client. I think this covers the most important part (reading the cmsgs). Everything else is pretty much just plumbing.

Ralith
Ralith previously approved these changes Dec 22, 2020
quinn/src/udp.rs Outdated Show resolved Hide resolved
quinn/src/platform/unix.rs Outdated Show resolved Hide resolved
/// This can be different from the address the endpoint is bound to, in case
/// the endpoint is bound to a wildcard address like `0.0.0.0` or `::`.
///
/// This will return `None` for clients, as well for servers if capturing
Copy link
Member

Choose a reason for hiding this comment

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

as well for seems a bit odd, add an extra as? I also think this docstring would be more useful if it explicitly lists supported platforms.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Alternatively, and might be a bit more concise.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I went for listing the supported platform[s]

quinn/src/connection.rs Outdated Show resolved Hide resolved
quinn/src/connection.rs Outdated Show resolved Hide resolved
Comment on lines +380 to +389
if cfg!(target_os = "linux") {
let local_ip = incoming.local_ip().expect("Local IP must be available");
assert!(local_ip.is_loopback());
} else {
assert_eq!(None, incoming.local_ip());
}
Copy link
Member

Choose a reason for hiding this comment

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

Add a note here to update the getter docs in case the platform support falls out of sync?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here, or rather to the platform files? This might be the place where people realize that more changes are necessary - because CI fails. But I somehow don't think that "update doc comments" is best kept in the tests. In the platform files - maybe. But if someone works on adding it to windows they won't look at the unix file.

Copy link
Member

Choose a reason for hiding this comment

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

I mean, it could be both, but as you say, I'm not sure someone adding support for a different platform would review the code for unix. So I think adding it here would definitely be useful, maybe do the platform files as well (I didn't see a straightforward single location where it could be added, but I could easily be wrong about that).

Ralith
Ralith previously approved these changes Dec 28, 2020
When a listener is bound to multiple network interfaces (e.g. `::0`),
it is not obvious which IP the peer used to send a packet. We however
might need this information to send packets back to the peer with the
same source address.

This problem is described in quinn-rs#508.

This change makes the destination IP address which was used to send
the initial packet available in the `Conneting` and `Connection` types.

The information is far available only on Linux due to missing test on
other platforms.
@djc djc merged commit 1bc75aa into quinn-rs:main Dec 29, 2020
@djc
Copy link
Member

djc commented Dec 29, 2020

Thanks for working through this!

Matthias247 pushed a commit to Matthias247/quinn that referenced this pull request Jan 4, 2021
This is a follow-up for quinn-rs#943. When a socket is bound to a wildcard
IP address, sending the outgoing IP might use a different source IP
address than the one the packet was received on, since the OS might
not be able to identify the necessary route. This would lead packets
not allowing to reach the client.

This change adds a setting which will set an explicit source address
in all outgoing packets. The source address which will be used is
the local IP address which was used to receive the initial incoming
packet.
Matthias247 pushed a commit to Matthias247/quinn that referenced this pull request Jan 4, 2021
This is a follow-up for quinn-rs#943. When a socket is bound to a wildcard
IP address, sending the outgoing IP might use a different source IP
address than the one the packet was received on, since the OS might
not be able to identify the necessary route. This would lead packets
not allowing to reach the client.

This change adds a setting which will set an explicit source address
in all outgoing packets. The source address which will be used is
the local IP address which was used to receive the initial incoming
packet.
Matthias247 pushed a commit to Matthias247/quinn that referenced this pull request Jan 4, 2021
This is a follow-up for quinn-rs#943. When a socket is bound to a wildcard
IP address, sending the outgoing IP might use a different source IP
address than the one the packet was received on, since the OS might
not be able to identify the necessary route. This would lead packets
not allowing to reach the client.

This change adds a setting which will set an explicit source address
in all outgoing packets. The source address which will be used is
the local IP address which was used to receive the initial incoming
packet.
djc pushed a commit to Matthias247/quinn that referenced this pull request Jan 5, 2021
This is a follow-up for quinn-rs#943. When a socket is bound to a wildcard
IP address, sending the outgoing IP might use a different source IP
address than the one the packet was received on, since the OS might
not be able to identify the necessary route. This would lead packets
not allowing to reach the client.

This change adds a setting which will set an explicit source address
in all outgoing packets. The source address which will be used is
the local IP address which was used to receive the initial incoming
packet.
djc pushed a commit to Matthias247/quinn that referenced this pull request Jan 5, 2021
This is a follow-up for quinn-rs#943. When a socket is bound to a wildcard
IP address, sending the outgoing IP might use a different source IP
address than the one the packet was received on, since the OS might
not be able to identify the necessary route. This would lead packets
not allowing to reach the client.

This change adds a setting which will set an explicit source address
in all outgoing packets. The source address which will be used is
the local IP address which was used to receive the initial incoming
packet.
Matthias247 pushed a commit to Matthias247/quinn that referenced this pull request Jan 6, 2021
This is a follow-up for quinn-rs#943. When a socket is bound to a wildcard
IP address, sending the outgoing IP might use a different source IP
address than the one the packet was received on, since the OS might
not be able to identify the necessary route. This would lead packets
not allowing to reach the client.

This change adds a setting which will set an explicit source address
in all outgoing packets. The source address which will be used is
the local IP address which was used to receive the initial incoming
packet.
Matthias247 pushed a commit to Matthias247/quinn that referenced this pull request Jan 6, 2021
This is a follow-up for quinn-rs#943. When a socket is bound to a wildcard
IP address, sending the outgoing IP might use a different source IP
address than the one the packet was received on, since the OS might
not be able to identify the necessary route. This would lead packets
not allowing to reach the client.

This change adds a setting which will set an explicit source address
in all outgoing packets. The source address which will be used is
the local IP address which was used to receive the initial incoming
packet.
djc pushed a commit that referenced this pull request Jan 6, 2021
This is a follow-up for #943. When a socket is bound to a wildcard
IP address, sending the outgoing IP might use a different source IP
address than the one the packet was received on, since the OS might
not be able to identify the necessary route. This would lead packets
not allowing to reach the client.

This change adds a setting which will set an explicit source address
in all outgoing packets. The source address which will be used is
the local IP address which was used to receive the initial incoming
packet.
@Matthias247 Matthias247 deleted the dest_ip branch January 31, 2021 04:17
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.

3 participants