Skip to content

Use IPV6_HDRINCL in set_header_included_v6() on Linux #563

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

Merged
merged 1 commit into from
Mar 16, 2025

Conversation

kntyskw
Copy link
Contributor

@kntyskw kntyskw commented Mar 12, 2025

This pull request introduces a platform-specific configuration to use IPV6_HDRINCL in set_header_included_v6() on Linux.

Background: Linux has defined IPv6 specific constant IPV6_HDRINCL (36) that needs to be used when setting HDRINCL socket option instead of IP_HDRINCL (2). Without it, set_header_included_v6() function does not work as expected and a kernel provided header is added to packets sent even if set_header_included_v6(true) is called on a raw socket.

  • src/socket.rs: Added conditional compilation for IPV6_HDRINCL on Linux and IP_HDRINCL on non-Linux systems to the setsockopt function.
  • src/sys/unix.rs: Added conditional use of libc::IPV6_HDRINCL for Linux systems.

@kntyskw kntyskw force-pushed the master branch 2 times, most recently from f26a032 to ba422c8 Compare March 13, 2025 21:34
…INCL. This patch adds a configuration that alters the value to set in set_header_included_v6()
Copy link
Collaborator

@Thomasdezeeuw Thomasdezeeuw left a comment

Choose a reason for hiding this comment

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

I can't find any mentions of this in the manual or on kernel.org, only in the source: https://github.com/torvalds/linux/blob/cb82ca153949c6204af793de24b18a04236e79fd/net/ipv6/raw.c#L1001

But, I think the patch is correct.

@Thomasdezeeuw Thomasdezeeuw merged commit d35ef30 into rust-lang:master Mar 16, 2025
43 checks passed
@kntyskw
Copy link
Contributor Author

kntyskw commented Apr 1, 2025

Thank you @Thomasdezeeuw for reviewing and approving! Yeah, I didn't find it anywhere either and it took time for me to find out why it didn't work as expected. I found it finally when I greped Linux header files. I'm glad no one else will have to dig into it again in the future!

Hasan6979 pushed a commit to NordSecurity/socket2 that referenced this pull request May 15, 2025
Instead of IP_HDRINCL in Socket:: set_header_included_v6.
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.

2 participants