Skip to content

Conversation

@dignifiedquire
Copy link
Contributor

@dignifiedquire dignifiedquire commented Nov 22, 2025

Description

This allows for multiple interfaces to be bound, and be actually used.

You can now use this by passing

let endpoint = Endpoint::builder()
  .bind_addr_v4_default("127.0.0.1", 1234)
  .bind_addr_v4("192.168.1.2/24".parse()?, 1234) // bind to prefix_len of 24
  .bind()
  .await?

The selection of the interface is done internally by first looking at all specific bindings, and then fallbing back to the default version for this family.

Breaking Changes

  • iroh
    • changed
      • Endpoint::bind_addr_v4 to Endpoint::bind_addr_v4_default
      • Endpoint::bind_addr_v6 to Endpoint::bind_addr_v6_default
    • added
      • Endpoint::bind_addr_v4
      • Endpoint::bind_addr_v6
    • endpoint::Ipv4Net
    • endpoint::Ipv6Net

@github-actions
Copy link

github-actions bot commented Nov 22, 2025

Documentation for this PR has been generated and is available at: https://n0-computer.github.io/iroh/pr/3692/docs/iroh/

Last updated: 2025-12-19T10:41:21Z

@github-actions
Copy link

github-actions bot commented Nov 22, 2025

Netsim report & logs for this PR have been generated and is available at: LOGS
This report will remain available for 3 days.

Last updated for commit: 73a4b9b

@n0bot n0bot bot added this to iroh Nov 22, 2025
@github-project-automation github-project-automation bot moved this to 🏗 In progress in iroh Nov 22, 2025
@dignifiedquire dignifiedquire marked this pull request as ready for review November 22, 2025 13:46
@dignifiedquire dignifiedquire changed the title feat(iroh): allow IP transports to bind to multiple interfaces feat(iroh)!: allow IP transports to bind to multiple interfaces Nov 22, 2025
@dignifiedquire dignifiedquire changed the title feat(iroh)!: allow IP transports to bind to multiple interfaces feat(iroh)!: allow multiple IP transports, including filtering by interface Nov 22, 2025
@dignifiedquire dignifiedquire force-pushed the feat-bind-interfaces branch 2 times, most recently from 6726f3c to 479652f Compare November 25, 2025 10:13
@dignifiedquire dignifiedquire changed the base branch from feat-multipath to main December 19, 2025 10:39
@Frando
Copy link
Member

Frando commented Dec 19, 2025

We could remove the _default API I think, if you set a netmask of 0 it will apply to everything. And instead return an error if you bind conflicting networks.

@dignifiedquire
Copy link
Contributor Author

We could remove the _default API I think, if you set a netmask of 0 it will apply to everything. And instead return an error if you bind conflicting networks.

well currently they are treated differently internally as an explicit fallback, thats why the difference in configuration exists

if sender.is_valid_send_addr(addr) {
Addr::Ip(addr) => match addr {
SocketAddr::V4(_) => {
for sender in self.ip.v4_iter_mut().filter(|s| s.is_valid_send_addr(addr)) {
Copy link
Member

Choose a reason for hiding this comment

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

It probably makes sense to pass in src: Option<IpAddr> now that we populate that value.
After all, is the value that should first and foremost tell you which interface to use.

Copy link
Member

@matheus23 matheus23 left a comment

Choose a reason for hiding this comment

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

I'm not super convinced this is the right API 🤔

Looking at your example:

let endpoint = Endpoint::builder()
  .bind_addr_v4_default("127.0.0.1", 1234)
  .bind_addr_v4("192.168.1.2/24".parse()?, 1234) // bind to prefix_len of 24
  .bind()
  .await?

It looks like the configuration for an endpoint that will only send traffic in the local network and localhost.
So let's say quinn produces a datagram that's meant to be sent to 192.168.1.101:1234.
Iroh will then first check this against your 192.168.1.2/24 and find a match. However, it turns out that interface is actually busy, so it continues.
Then it'll see the "default" 127.0.0.1 interface and try to send on that. But obviously it can't send outside localhost, so ideally that should just fail sending, but I think it won't? I'm not actually sure what will happen.

Also another thing about the default socket: What if someone wants to bind a dual-stack socket with [::]? I think that should match against an IPv4 address, but IIUC currently it doesn't?

Minor note: I'm not sure what should happen if you bind multiple sockets to the same port, but different IP addrs. What happens in these cases? I'm not sure.

Comment on lines +79 to +107
/// Does this configuration match to send to the given `dst` address.
pub(crate) fn is_valid_send_addr(&self, dst: SocketAddr) -> bool {
match self {
Self::V4Default { .. } => matches!(dst, SocketAddr::V4(_)),
Self::V6Default { .. } => matches!(dst, SocketAddr::V6(_)),
Self::V4 { ip_addr, .. } => match dst {
SocketAddr::V4(dst_v4) => ip_addr.contains(dst_v4.ip()),
SocketAddr::V6(_) => false,
},
Self::V6 {
ip_addr, scope_id, ..
} => match dst {
SocketAddr::V6(dst_v6) => {
if ip_addr.contains(dst_v6.ip()) {
return true;
}
if dst_v6.ip().is_unicast_link_local() {
// If we have a link local interface, use the scope id
if *scope_id == dst_v6.scope_id() {
return true;
}
}
false
}
SocketAddr::V4(_) => false,
},
}
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Yeah I agree with Frando here I think: I'm not sure if it's that useful to have the default cases here.
What's the use case for having these be a special case? Make sure they're tried last?

@flub flub added this to the iroh: v1.0.0-rc.0 milestone Dec 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: 🏗 In progress

Development

Successfully merging this pull request may close these issues.

6 participants