-
-
Notifications
You must be signed in to change notification settings - Fork 495
feat(ip_recverr): ADD IP_RECVERR and IPV6_RECVERR support for linux #2421
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
base: main
Are you sure you want to change the base?
Conversation
5338a62 to
aa6bf63
Compare
mxinden
left a comment
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.
Good work. I will take a more in-depth look.
2addc3c to
125a041
Compare
thomaseizinger
left a comment
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.
Gave this a first pass.
quinn-udp/src/unix.rs
Outdated
| if is_ip_err || is_ipv6_err { | ||
| let err_data = unsafe { cmsg::decode::<SockExtendedErr, libc::cmsghdr>(cmsg) }; | ||
|
|
||
| let addr = unsafe { |
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.
Do we not have this code somewhere already in the codebase? Perhaps extracting a small utility function could make this a bit more concise.
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.
I considered factoring it out, but this logic is fairly localized and only used here. so I’ll keep it inline for clarity.
032a179 to
a9e7e2a
Compare
|
This is my first open-source contribution, so I understand there may be several mistakes. Thank you for taking the time to review my work and provide guidance—I really appreciate it. |
a9e7e2a to
c21cbe6
Compare
thomaseizinger
left a comment
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.
Great progress. One big item to discuss.
| recv_err(socket.0) | ||
| } | ||
|
|
||
| #[cfg(not(target_os = "linux"))] |
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.
I think we should aim for a unified API across all platforms, even if they currently don't return a value. Otherwise code that uses this also needs to use a cfg to compile on multiple platforms.
|
|
||
| let mut control = cmsg::Aligned([0u8; CMSG_LEN]); | ||
|
|
||
| // We don't need actual data, just the error info |
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.
Oh! I understand now. So to receive error info, we pass a flag to recvmsg but otherwise it is the same syscall. An alternative design would be to do this as part of the other recv flow and store the received ICMP messages in a (bounded) queue. That would be more efficient in terms of syscall usage, especially because most of the time, this syscall here is not going to return anything. Yet, an application wanting to handle this still needs to call this in a loop with the other recv, taking up CPU usage of the recv hot path.
Curious to hear what other people think about this.
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.
Your suggestion makes sense to me.
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.
Interesting. In case someone here knows, what is the intended use, or asked differently, how do other applications use it?
quinn-udp/src/lib.rs
Outdated
| struct SockExtendedErr { | ||
| ee_errno: u32, | ||
| ee_origin: u8, | ||
| ee_type: u8, | ||
| ee_code: u8, | ||
| ee_pad: u8, | ||
| ee_info: u32, | ||
| ee_data: u32, |
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.
Nit: without any compelling reason to the contrary (like shared standardization with other APIs), suggest naming this SocketExtendedError and dropping the common ee_ prefix on fields (which is a kind of stuttering).
Also, since these only seem relevant on Unix, suggest that these should live in the unix module?
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.
Also, since these only seem relevant on Unix, suggest that these should live in the
unixmodule?
I don't think you addressed this.
Also, please keep it these types near the bottom of the module to maintain the top-down ordering of items.
| HostUnreachable, | ||
| PortUnreachable, | ||
| PacketTooBig, | ||
| Other { icmp_type: u8, icmp_code: u8 }, |
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.
Nit: drop the icmp_ prefix, which is pretty obvious for a type named IcmpErrorKind.
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.
Since type is a reserved keyword in Rust, it can’t be used directly as a field name, We can use raw identifier instead r#type. Can i do that?
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.
Seems okay to me.
quinn-udp/src/lib.rs
Outdated
|
|
||
| #[cfg(target_os = "linux")] | ||
| impl IcmpErrorKind { | ||
| fn from_extended_err(err: &SockExtendedErr) -> Self { |
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.
It feels like this should be SocketExtendedError::kind().
Can we name the magic constants for type and code here with their common libc or whatever names?
|
Please squash all your changes before pushing. |
4333346 to
fd00c2e
Compare
chore(ip_recverr): Testing with socket setup similar to cmsg in recv feat(ip_recverr): Initialised socket options for IPV4 and V6 feat(ip_recverr): Add error read queue function chore(ip_recverr): Add error handling after recieving normal packets test(ip_recverr): Start the test cases for IP_RECVERR test(ip_recverr): Complete the test cases for ip_recverr and ipv6 test(ip_recverr): handle expected send failure instead of panicking style: Format the files using rustfmt style(recv_err): Change the name of the unused function refactor(ip_recverr): change the ICMPErr to enum kind refactor(ip_recverr): COnversion from SockExtendedErr to ICMPErrKind refactor(ip_recverr): Remove ICMPErr from recv and add seperate recv_icmp_err test(ip_recverr): Change the test files following new method Apply suggestions from code review Co-authored-by: Thomas Eizinger <[email protected]> refactor: address code review feedback - Use early returns to reduce nesting - Replace match with unwrap in tests - Add non-Linux fallback implementation fix(ip_recverr): Continue to next control message instead of return test(ip_recverr): Fix the socket binding error from OS, now sends proper network error fix(ip_recverr): rename IcmpError for non linux platforms fix(pacing): allow ±0ns tolerance in computes_pause_correctly test on i386 -Used Duration::abs_diff() instead of manual difference for cleaner and more robust duration comparison. -added inline formatting as required. build(deps): bump rustls-platform-verifier from 0.6.1 to 0.6.2 Bumps [rustls-platform-verifier](https://github.com/rustls/rustls-platform-verifier) from 0.6.1 to 0.6.2. - [Release notes](https://github.com/rustls/rustls-platform-verifier/releases) - [Changelog](https://github.com/rustls/rustls-platform-verifier/blob/main/CHANGELOG) - [Commits](rustls/rustls-platform-verifier@v/0.6.1...v/0.6.2) --- updated-dependencies: - dependency-name: rustls-platform-verifier dependency-version: 0.6.2 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <[email protected]> refactor(ip_recverr): Change SockExtendedError as suggested fix(ip_recverr): Add IcmpError for non linux platforms refactor(ip_recverr): Change to SockExtendedError Kind
fd00c2e to
7278847
Compare
Including merges. |
5252988 to
7278847
Compare
On Linux, enables
IP_RECVERRandIPV6_RECVERRsocket optionsThis allows the socket to receive ICMP errors via the error queue, enabling faster detection of network unreachability instead of waiting for connection timeouts.
Features Implemented
Closes #2052