Skip to content

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

Open
arilotter opened this issue Mar 7, 2025 · 8 comments
Open

allow binding to an interface instead of an IP address #3218

arilotter opened this issue Mar 7, 2025 · 8 comments
Labels
c-iroh feat New feature or request

Comments

@arilotter
Copy link

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.

@n0bot n0bot bot added this to iroh Mar 7, 2025
@flub flub added feat New feature or request c-iroh labels Mar 10, 2025
@flub
Copy link
Contributor

flub commented Mar 10, 2025

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.

@matheus23
Copy link
Member

matheus23 commented Mar 16, 2025

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

@dignifiedquire
Copy link
Contributor

which seems to be limited to

 #[cfg(any(
    target_os = "android",
    target_os = "fuchsia",
    target_os = "linux"
))]

@arilotter
Copy link
Author

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.

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.

@dignifiedquire
Copy link
Contributor

A great starting point that should cover most people's use cases is to allow binding to multiple IPv4 and IPv6 addresses, yeah!

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.

@flub
Copy link
Contributor

flub commented Mar 20, 2025

A great starting point that should cover most people's use cases is to allow binding to multiple IPv4 and IPv6 addresses, yeah!

That will not be possible easily, as we would have to maintain a socket per IP address.

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.

@dignifiedquire
Copy link
Contributor

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.

@matheus23
Copy link
Member

Relevant issue: #2228

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c-iroh feat New feature or request
Projects
Status: No status
Development

No branches or pull requests

4 participants