-
Notifications
You must be signed in to change notification settings - Fork 234
allow binding to an interface instead of an IP address #3218
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
Comments
I'm not sure we'd want to provide an API where you can use interface names directly. I think the querying of interface->IP may be better to stay in the application code. To be fair, my opinion here is mostly based on precedent: I don't think I've seen any network lib providing such an API. But yes, we should allow biding to any number of sockets, IPv4 and IPv6. Maybe we can even provide an API where you can pass in bound sockets, but I'm not sure about that. |
Just saw this API in reqwest: /// Bind to an interface by `SO_BINDTODEVICE`.
pub fn interface(self, interface: &str) -> ClientBuilder https://docs.rs/reqwest/latest/reqwest/struct.ClientBuilder.html#method.interface |
which seems to be limited to
|
A great starting point that should cover most people's use cases is to allow binding to multiple IPv4 and IPv6 addresses, yeah! I can always enumerate the IPs on my desired interfaces myself. |
That will not be possible easily, as we would have to maintain a socket per IP address. So the solution is to proxy through to the OS allowed abilities to bind a (UDP) socket to an interface by name. |
I'm not sure why this shouldn't be possible. I was expecting that this would be long-term where we need to end up. We already have two sockets, one for IPv4 and one for IPv6. Adding more sockets means that you have to solve routing on the outbound path somehow though. Or maybe there are OS-mechanisms which allow you to bind more fine-grained, in that case maybe we could allow passing in exactly one IPv4 and one IPv6 socket with the application being able to bind in whichever way they would like. |
We will be able to add this feature once we introduce transport abstractions, allowing multiple IP based transports, each bound to a different interface. So it is planned, but will take a moment to get there. |
Relevant issue: #2228 |
Magicsock::listen
currently supports either listening on a specific ipv4 and/or ipv6 address.However, binding to 0.0.0.0, either via
None
or passing that explicitly, will cause it to bind across multiple interfaces.I have a use-case where I want to force Iroh connections through one or more specific network interface(s).
My only option right now is to first query those interface(s) for their IP address(es), and then pass one of them to Magicsock.
Therefore, I currently cannot bind on two interfaces (both v4 or v6) while avoiding a third.
I would love the ability to bind to an arbitrary list of interfaces, each on v4, v6, or both.
The text was updated successfully, but these errors were encountered: