Skip to content

Use IPV6_HDRINCL in set_header_included_v6() on Linux#563

Merged
Thomasdezeeuw merged 1 commit into
rust-lang:masterfrom
kntyskw:master
Mar 16, 2025
Merged

Use IPV6_HDRINCL in set_header_included_v6() on Linux#563
Thomasdezeeuw merged 1 commit into
rust-lang:masterfrom
kntyskw:master

Conversation

@kntyskw

@kntyskw kntyskw commented Mar 12, 2025

Copy link
Copy Markdown
Contributor

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()

@Thomasdezeeuw Thomasdezeeuw left a comment

Copy link
Copy Markdown
Collaborator

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
@kntyskw

kntyskw commented Apr 1, 2025

Copy link
Copy Markdown
Contributor Author

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