Skip to content

Enable IP_BOUND_IF on illumos and Solaris #561

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 6 commits into from
Mar 11, 2025

Conversation

hawkw
Copy link
Contributor

@hawkw hawkw commented Feb 26, 2025

The IP_BOUND_IF socket option, which is wrapped by the
Socket::bind_device_by_index_{v4,v6} and
Socket::device_index_{v4,v6} is available on SunOS-like systems, such
as illumos and Solaris, as well as macOS-like systems. However, these
APIs are currently cfg-flagged to only be available on macOS-like
systems.

This commit changes the cfg attributes to also enable these APIs on
illumos and Solaris.

Fixes #560

The `IP_BOUND_IF` socket option, which is wrapped by the
`Socket::bind_device_by_index_{v4,v6}` and
`Socket::device_index_{v4,v6}` is available on SunOS-like systems, such
as illumos and Solaris, as well as macOS-like systems. However, these
APIs are currently cfg-flagged to only be available on macOS-like
systems.

This commit changes the cfg attributes to also enable these APIs on
illumos and Solaris.

Fixes rust-lang#560
@hawkw
Copy link
Contributor Author

hawkw commented Feb 26, 2025

Ugh, it looks like libc also doesn't expose these socket options on illumos or Solaris. That's annoying...

`libc` [v0.2.171] was just released, and it includes definitions of
`IP_BOUND_IF` for Solarish operating systems. Thus, we can now remove
the temporary local definitions.

[v0.2.171]: https://github.com/rust-lang/libc/releases/tag/0.2.171
@hawkw hawkw requested a review from Thomasdezeeuw March 11, 2025 17:33
@Thomasdezeeuw Thomasdezeeuw merged commit 5c1f3b0 into rust-lang:master Mar 11, 2025
43 checks passed
@Thomasdezeeuw
Copy link
Collaborator

Thanks @hawkw

@hawkw
Copy link
Contributor Author

hawkw commented Mar 13, 2025

@Thomasdezeeuw would it be possible to get a patch release of socket2 0.5.x with this change? I see that the master branch has breaking changes for v0.6 (as of 0cb5119), but I'd be happy to fork v0.5.x from the prior commit and do a backport, if that's helpful.

@hawkw hawkw mentioned this pull request Mar 13, 2025
7 tasks
@Thomasdezeeuw
Copy link
Collaborator

@hawkw yes, if you can create a pr to target 0.5.x that would be helpful 👍

hawkw added a commit to hawkw/socket2-rs that referenced this pull request Mar 17, 2025
The `IP_BOUND_IF` socket option, which is wrapped by the
`Socket::bind_device_by_index_{v4,v6}` and
`Socket::device_index_{v4,v6}` is available on SunOS-like systems, such
as illumos and Solaris, as well as macOS-like systems. However, these
APIs are currently cfg-flagged to only be available on macOS-like
systems.

This commit changes the cfg attributes to also enable these APIs on
illumos and Solaris.

Fixes rust-lang#560
@hawkw
Copy link
Contributor Author

hawkw commented Mar 17, 2025

@hawkw yes, if you can create a pr to target 0.5.x that would be helpful 👍

Opened #565 targeting v0.5.x!

Thomasdezeeuw pushed a commit that referenced this pull request Mar 20, 2025
The `IP_BOUND_IF` socket option, which is wrapped by the
`Socket::bind_device_by_index_{v4,v6}` and
`Socket::device_index_{v4,v6}` is available on SunOS-like systems, such
as illumos and Solaris, as well as macOS-like systems. However, these
APIs are currently cfg-flagged to only be available on macOS-like
systems.

This commit changes the cfg attributes to also enable these APIs on
illumos and Solaris.

Fixes #560
hawkw added a commit to hawkw/reqwest that referenced this pull request Mar 31, 2025
The `ClientBuilder` type has an `interface` method that sets the name of
a specific network interface to bind TCP connections on. This method is
currently only enabled on Linux, Android, and Fuchsia, as it uses the
`SO_BINDTODEVICE` socket option, which only exists on those systems.
Upstream changes to `socket2` (rust-lang/socket2#561) and `hyper-util`
(hyperium/hyper-util#176) have added support for similar functionality
on macOS (and other Apple operating systems, such as iOS, watchOS, tvOS,
and visionOS), and Solaris and Solaris-like systems like illumos, using
the `IP_BOUND_IF`/`IPV6_BOUND_IF` socket options on those systems.

This branch enables the `ClientBuilder::interface` API on these
additional target OSes.

Note that this presently requires a Cargo patch to take a Git dependency
on hyperium/hyper-util@5831ace. Once
that commit is published, the patch can be removed. This PR should not be
merged until then.

Fixes seanmonstar#2571
seanmonstar pushed a commit to seanmonstar/reqwest that referenced this pull request Apr 9, 2025
The `ClientBuilder` type has an `interface` method that sets the name of
a specific network interface to bind TCP connections on. This method is
currently only enabled on Linux, Android, and Fuchsia, as it uses the
`SO_BINDTODEVICE` socket option, which only exists on those systems.
Upstream changes to `socket2` (rust-lang/socket2#561) and `hyper-util`
(hyperium/hyper-util#176) have added support for similar functionality
on macOS (and other Apple operating systems, such as iOS, watchOS, tvOS,
and visionOS), and Solaris and Solaris-like systems like illumos, using
the `IP_BOUND_IF`/`IPV6_BOUND_IF` socket options on those systems.

This branch enables the `ClientBuilder::interface` API on these
additional target OSes.

Fixes #2571
Hasan6979 pushed a commit to NordSecurity/socket2 that referenced this pull request May 15, 2025
The `IP_BOUND_IF` socket option, which is wrapped by the
`Socket::bind_device_by_index_{v4,v6}` and
`Socket::device_index_{v4,v6}` is available on SunOS-like systems, such
as illumos and Solaris, as well as macOS-like systems. However, these
APIs are currently cfg-flagged to only be available on macOS-like
systems.

This commit changes the cfg attributes to also enable these APIs on
illumos and Solaris.

Fixes rust-lang#560
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.

Socket::bind_device_by_index_{v4,v6} should be available on illumos/Solaris
2 participants