You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The ServiceInfo struct returned in ServiceEvent::ServiceResolved can include link-local IPv6 addresses without any scope/zone ID information, making them useless. IPv6 requires link-local addresses, so you are pretty much guaranteed to receive these when the service browser daemon is active.
In #242, the daemon itself was fixed to allow link-local addresses to be reachable by the daemon. The problem here is that, as a client, I need the same information to be able to create a valid socket with these link-local addresses. The behavior and some background details were mentioned in this comment when IPv6 support was initially being added: #130 (comment)
My current workaround is ignoring IPv6 link-local addresses. But I would be able to use them if the interface number that the addresses were discovered on was included in the event.
A similar issue was discussed recently in #342 , and we got a basic (internal) struct committed to include the interface number, while left the full solution not decided yet.
It seems now it's a good time to come back and work out a full solution ;-). Early one of my concerns was: only a client (i.e. querier) would use the interface number inside an address, and that would conflict with the usage of ServiceInfo on the server side. But now I think probably even the server side can benefit from specifying interface number / scope id for publishing its service on IPv6.
And it's likely be a breaking change in API, but I think we can make it as minimum as possible.
I'm indifferent to any changes that might be necessary for this. I know, for instance, that the ServiceInfo is used in two places: 1. to register the service and 2. to receive service update events from the daemon. It absolutely makes sense to include the interface index in the latter. Splitting these into different structs would be acceptable to me, but I understand if others feel differently.
Additionally, I don't know how useful it is to include the interface index in the service registration. The interface information is local to the host that is registering the service, and it cannot be used by any remote peers.
Additionally, I don't know how useful it is to include the interface index in the service registration. The interface information is local to the host that is registering the service, and it cannot be used by any remote peers.
I imagine, if the host has two interfaces with the same link-local IPv6 address, and the user wants to publish the service only on one of the IPv6 links, then an interface index would be needed.
Currently, such service will be published by mdns-sd on both IPv6 links as long as they have the same address. The user cannot pick only one of them.
That is true. The service registration should probably require a scope/zone ID for link-local IPv6 addresses to associate the interface. My comment was that the interface should not be included in any packets delivered over the network. From the other perspective, recipients should not be told which interface was used for that address. It would be irrelevant and confusing.
Sorry about my delay. I think I wanted to focus on the client (query) side and use the currently under-used ResolvedService to get the interface / scope id for addresses. In the long term, I hope the client side uses ResolvedService to replace ServiceInfo. Please checkout PR #362 for details, and let me know if this patch would work for you. Thanks!
@keepsimple1 I've toyed around a bit more and updated the query example to use the new proposed API.
I've noticed something weird, which may come surprising to consumers:
When running with cargo run --example=query _mass._tcp
What's a bit weird from a consumers point of view, we now get IPv6 link addresses scoped to interfaces which actually don't have a link-loca IPv6 addr:
Output of ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host proto kernel_lo
valid_lft forever preferred_lft forever
2: enp12s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether d8:43:ae:b3:ea:97 brd ff:ff:ff:ff:ff:ff
inet 192.168.178.53/24 brd 192.168.178.255 scope global dynamic noprefixroute enp12s0
valid_lft 856400sec preferred_lft 856400sec
inet6 2003:e8:bf13:1300:a491:e24f:acbf:68c3/64 scope global dynamic noprefixroute
valid_lft 6837sec preferred_lft 1437sec
inet6 fe80::b7a:957b:f7e1:9b0e/64 scope link noprefixroute
valid_lft forever preferred_lft forever
3: wlp13s0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
link/ether 56:e7:b9:88:9d:ad brd ff:ff:ff:ff:ff:ff permaddr 58:cd:c9:86:54:1f
4: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000
link/ether 52:54:00:cb:66:f6 brd ff:ff:ff:ff:ff:ff
inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
valid_lft forever preferred_lft forever
5: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default
link/ether c2:3d:2f:ed:eb:a1 brd ff:ff:ff:ff:ff:ff
inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0
valid_lft forever preferred_lft forever
6: br-966d8702ceaa: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default
link/ether ca:46:88:da:1f:8e brd ff:ff:ff:ff:ff:ff
inet 172.18.0.1/16 brd 172.18.255.255 scope global br-966d8702ceaa
valid_lft forever preferred_lft forever
So in the example above we get the IPv6 link local scoped to
I agree that the link-local addresses need to include only the interface index where it is reachable. And IPv4 and non-link-local IPv6 does not need the interface information. The addition of these creates confusion.
Understood that such confusion is not good. Thanks a lot for your testing @hrzlgnm! I expected such observation with localhost service loop-back seen by all interfaces, but didn't expect such for a non-localhost service. I didn't see it in a basic manual testing. Let me look into more.
I didn't see it in a basic manual testing. Let me look into more.
@hrzlgnm I think it's because in your case, other interfaces virbr0, docker0, br-966d8702ceaa are bridges, which forwards multicast. Hence the published service address was seen by multiple interfaces.
Perhaps we need to add some kind of filtering for interfaces not having ipv6 link local addresses or no ipv6 addresses at all?
I agree that the link-local addresses need to include only the interface index where it is reachable. And IPv4 and non-link-local IPv6 does not need the interface information. The addition of these creates confusion.
I've changed ResolvedService.addresses to be a HashMap<IpAddr, Vec<InterfaceId>>. i.e. for each service address, there is a list of interfaces on which the address was seen. This change is partially inspired by Apple's NWBrowser.Result.interfaces. I also updated the query example to use that.
I didn't see it in a basic manual testing. Let me look into more.
@hrzlgnm I think it's because in your case, other interfaces virbr0, docker0, br-966d8702ceaa are bridges, which forwards multicast. Hence the published service address was seen by multiple interfaces.
Yes that's what it looks like. But those bridges are not bridged anywhere.
brctl show
bridge name bridge id STP enabled interfaces
br-966d8702ceaa 8000.6e177a64a807 no
docker0 8000.aac82ee40b7c no
virbr0 8000.525400cb66f6 yes
So maybe there is an other circumstance leading to receiving replies also on those sockets.
Perhaps we need to add some kind of filtering for interfaces not having ipv6 link local addresses or no ipv6 addresses at all?
I agree that the link-local addresses need to include only the interface index where it is reachable. And IPv4 and non-link-local IPv6 does not need the interface information. The addition of these creates confusion.
I've changed ResolvedService.addresses to be a HashMap<IpAddr, Vec<InterfaceId>>. i.e. for each service address, there is a list of interfaces on which the address was seen. This change is partially inspired by Apple's NWBrowser.Result.interfaces. I also updated the query example to use that.
What do you think?
I've checked the changes, those would also work for me.
To avoid having those interfaces that have their link DOWN to also show up, I'll add disabling those using ServiceDaemon::disable_interface on my side.
What I also noticed all interfaces except enp12s0 were actually down...maybe it's a good idea to treat those as disabled?
I agree, however I've not found an API in ip-addrs crate to detect the operational state of these interfaces (They are configured to be UP, and are operational DOWN). Will check around.
Thanks! I hope if-addrs crate can be enhanced to support checking interface UP or not. I've asked over there and also created a PR: messense/if-addrs#49 . But that's of course not in our control, so probably I will treat this as a separate issue and won't block this original issue.
@parasyte Just want to check, would the updated diff work for your use case? Or is it still confusing? The key change is the addresses field in ResolvedService:
/// Addresses of the service.
/// Each address maps to the list of interfaces on which the address is found.
/// The interface list is particularly useful for link-local IPv6 addresses,
/// where the same address can be found on multiple interfaces.
pub addresses: HashMap<IpAddr, Vec<InterfaceId>>,
(Btw, we will use a separate PR to filter out interfaces are "down" operationally).
I went through this PR again and I updated the design after more of thinking: add InterfaceId info only for IPv6 address, not for IPv4 address.
Instead of HashMap<IpAddr, Vec<InterfaceId>>, now ResolvedService.addresses is HashSet<HostIp>. Its change is simply that the new HostIp replaces the existing IpAddr and supports scope_id for IPv6.
Hope this make the change of ResolvedService easier to understand, and remove confusions.
A separate PR #369 opened to exclude the operational down interfaces. @hrzlgnm let me know if it helps in your setup.
Thanks, tried it out and the change and indeed helps a lot in my setup and probably others, too.
Now I have:
At 338.13µs: SearchStarted("_http._tcp.local. on 3 interfaces [192.168.178.53 (enp12s0), 2003:e8:bf13:1300:a491:e24f:acbf:68c3 (enp12s0), fe80::b7a:957b:f7e1:9b0e (enp12s0)]")
At 76.603204ms: ServiceFound("_http._tcp.local.", "Denon AVR-X1400H._http._tcp.local.")
At 76.658144ms: Resolved a new service: Denon AVR-X1400H._http._tcp.local.
host: Denon-AVR-X1400H.local.
port: 80
Address: fe80::205:cdff:fea5:86b0%2
Address: 2003:e8:bf13:1300:205:cdff:fea5:86b0%2
Address: 192.168.178.21
Property: path=/settings/
At 150.030533ms: ServiceFound("_http._tcp.local.", "Tibber Bridge Web Server._http._tcp.local.")
At 150.059793ms: Resolved a new service: Tibber Bridge Web Server._http._tcp.local.
host: Bridge20c228000.local.
port: 80
Address: 192.168.178.33
Instead of:
At 466.759µs: SearchStarted("_http._tcp.local. on 5 interfaces [172.17.0.1 (docker0), fe80::b7a:957b:f7e1:9b0e (enp12s0), 192.168.178.53 (enp12s0), 192.168.122.1 (virbr0), 2003:e8:bf13:1300:a491:e24f:acbf:68c3 (enp12s0)]")
At 96.23125ms: ServiceFound("_http._tcp.local.", "Denon AVR-X1400H._http._tcp.local.")
At 96.30142ms: Resolved a new service: Denon AVR-X1400H._http._tcp.local.
host: Denon-AVR-X1400H.local.
port: 80
Address: fe80::205:cdff:fea5:86b0%3
Address: 2003:e8:bf13:1300:205:cdff:fea5:86b0%3
Address: 192.168.178.21
Property: path=/settings/
At 96.38964ms: Resolved a new service: Denon AVR-X1400H._http._tcp.local.
host: Denon-AVR-X1400H.local.
port: 80
Address: 192.168.178.21
Address: fe80::205:cdff:fea5:86b0%2
Address: 2003:e8:bf13:1300:205:cdff:fea5:86b0%2
Address: 2003:e8:bf13:1300:205:cdff:fea5:86b0%3
Address: fe80::205:cdff:fea5:86b0%3
Property: path=/settings/
At 96.47697ms: Resolved a new service: Denon AVR-X1400H._http._tcp.local.
host: Denon-AVR-X1400H.local.
port: 80
Address: fe80::205:cdff:fea5:86b0%2
Address: 2003:e8:bf13:1300:205:cdff:fea5:86b0%3
Address: 2003:e8:bf13:1300:205:cdff:fea5:86b0%5
Address: 192.168.178.21
Address: fe80::205:cdff:fea5:86b0%3
Address: 2003:e8:bf13:1300:205:cdff:fea5:86b0%2
Address: fe80::205:cdff:fea5:86b0%5
Property: path=/settings/
At 212.425841ms: ServiceFound("_http._tcp.local.", "Tibber Bridge Web Server._http._tcp.local.")
At 212.447611ms: Resolved a new service: Tibber Bridge Web Server._http._tcp.local.
host: Bridge20c228000.local.
port: 80
Address: 192.168.178.33
At 212.491661ms: Resolved a new service: Tibber Bridge Web Server._http._tcp.local.
host: Bridge20c228000.local.
port: 80
Address: 192.168.178.33
At 212.525411ms: Resolved a new service: Tibber Bridge Web Server._http._tcp.local.
host: Bridge20c228000.local.
port: 80
Address: 192.168.178.33
@keepsimple1 Can we have public access to the field HostIpV6::scope_id, otherwise it's not possible to use the scope_id in other means than .to_string()
Can we have public access to the field HostIpV6::scope_id, otherwise it's not possible to use the scope_id in other means than .to_string()
Surely we can add that. Is it easier for you to use a method of HostIpv6 or of HostIp enum, as following?
implHostIpV6{/// Returns the scope_id for this IPv6 address.pubconstfnscope_id(&self) -> InterfaceId{self.scope_id}}
or this:
implHostIp{/// Returns the scope_id for IPv6 addresses, or None for IPv4 addresses.pubconstfnscope_id(&self) -> Option<InterfaceId>{matchself{HostIp::V4(_) => None,HostIp::V6(v6) => Some(v6.scope_id),}}}
(Apologies for my recent silence on this. My client decided that we needed to skip local resolution and go straight for public WAN resolution in the project we are working on, so this kind of got back-burnered for me.)
I'm going to try to find some time to give this a try.
I can't speak for @hrzlgnm, but I would personally lean toward the method on HostIPv6, if the choice is between those two. This info only needs to be queried for IPv6 address, but only for link-local addresses. I.e., only when Ipv6Addr::is_unicast_link_local() returns true.
Thanks @parasyte@hrzlgnm I've added the access methods in PR #369 and updated test cases.
This info only needs to be queried for IPv6 address, but only for link-local addresses. I.e., only when Ipv6Addr::is_unicast_link_local() returns true.
Understood. Currently I'm always returning &InterfaceId for IPv6, instead of Option<&InterfaceId> as I think the ergonomic benefit overweights the "only needed for link local addrs". Besides, in mDNS cases, the relevant IPv6 addrs are always link local. (And, the client can always check is_unicast_link_local() , which is a recent stable API btw).
Activity
keepsimple1 commentedon May 19, 2025
A similar issue was discussed recently in #342 , and we got a basic (internal) struct committed to include the interface number, while left the full solution not decided yet.
It seems now it's a good time to come back and work out a full solution ;-). Early one of my concerns was: only a client (i.e. querier) would use the interface number inside an address, and that would conflict with the usage of
ServiceInfoon the server side. But now I think probably even the server side can benefit from specifying interface number / scope id for publishing its service on IPv6.And it's likely be a breaking change in API, but I think we can make it as minimum as possible.
parasyte commentedon May 19, 2025
Thanks! I hadn't seen #342 yet. I'm going over it, now.
BTW, here are a few related conversations:
I'm indifferent to any changes that might be necessary for this. I know, for instance, that the
ServiceInfois used in two places: 1. to register the service and 2. to receive service update events from the daemon. It absolutely makes sense to include the interface index in the latter. Splitting these into different structs would be acceptable to me, but I understand if others feel differently.Additionally, I don't know how useful it is to include the interface index in the service registration. The interface information is local to the host that is registering the service, and it cannot be used by any remote peers.
keepsimple1 commentedon May 20, 2025
I imagine, if the host has two interfaces with the same link-local IPv6 address, and the user wants to publish the service only on one of the IPv6 links, then an interface index would be needed.
Currently, such service will be published by mdns-sd on both IPv6 links as long as they have the same address. The user cannot pick only one of them.
parasyte commentedon May 20, 2025
That is true. The service registration should probably require a scope/zone ID for link-local IPv6 addresses to associate the interface. My comment was that the interface should not be included in any packets delivered over the network. From the other perspective, recipients should not be told which interface was used for that address. It would be irrelevant and confusing.
keepsimple1 commentedon Jun 9, 2025
Sorry about my delay. I think I wanted to focus on the client (query) side and use the currently under-used
ResolvedServiceto get the interface / scope id for addresses. In the long term, I hope the client side usesResolvedServiceto replaceServiceInfo. Please checkout PR #362 for details, and let me know if this patch would work for you. Thanks!CC @hrzlgnm as issue #339 is related.
hrzlgnm commentedon Jun 9, 2025
@keepsimple1 I had a look at #339. It works for me.
hrzlgnm commentedon Jun 9, 2025
@keepsimple1 I've toyed around a bit more and updated the query example to use the new proposed API.
I've noticed something weird, which may come surprising to consumers:
When running with cargo run --example=query _mass._tcp
We get multiple entries for the same IPv4 address but with every interface which could see it.
Or another example with a service also having IPv6 support: cargo run --example=query _raop._tcp
What's a bit weird from a consumers point of view, we now get IPv6 link addresses scoped to interfaces which actually don't have a link-loca IPv6 addr:
Output of
ip addrSo in the example above we get the IPv6 link local scoped to
But the actual only interface having a ipv6 link local address is (2: enp12s0) in this case.
Similarly for the non link local IPv6 address, where only (2: enp12s0) can actually connect to, having an actuall IPv6 address.
Perhaps we need to add some kind of filtering for interfaces not having ipv6 link local addresses or no ipv6 addresses at all?
parasyte commentedon Jun 9, 2025
I agree that the link-local addresses need to include only the interface index where it is reachable. And IPv4 and non-link-local IPv6 does not need the interface information. The addition of these creates confusion.
keepsimple1 commentedon Jun 10, 2025
Understood that such confusion is not good. Thanks a lot for your testing @hrzlgnm! I expected such observation with localhost service loop-back seen by all interfaces, but didn't expect such for a non-localhost service. I didn't see it in a basic manual testing. Let me look into more.
hrzlgnm commentedon Jun 12, 2025
What I also noticed all interfaces except enp12s0 were actually down...maybe it's a good idea to treat those as disabled?
keepsimple1 commentedon Jun 13, 2025
@hrzlgnm I think it's because in your case, other interfaces
virbr0,docker0,br-966d8702ceaaare bridges, which forwards multicast. Hence the published service address was seen by multiple interfaces.I've changed
ResolvedService.addressesto be aHashMap<IpAddr, Vec<InterfaceId>>. i.e. for each service address, there is a list of interfaces on which the address was seen. This change is partially inspired by Apple'sNWBrowser.Result.interfaces. I also updated the query example to use that.What do you think?
hrzlgnm commentedon Jun 13, 2025
Yes that's what it looks like. But those bridges are not bridged anywhere.
So maybe there is an other circumstance leading to receiving replies also on those sockets.
I've checked the changes, those would also work for me.
To avoid having those interfaces that have their link
DOWNto also show up, I'll add disabling those usingServiceDaemon::disable_interfaceon my side.keepsimple1 commentedon Jun 13, 2025
I agree, however I've not found an API in
ip-addrscrate to detect the operational state of these interfaces (They are configured to be UP, and are operational DOWN). Will check around.hrzlgnm commentedon Jun 13, 2025
I'm using the crate pnet on Linux and macOS and ifconfig for windows to support that case:
https://github.com/hrzlgnm/mdns-browser/blob/4d45c597a7dd65014c76e1d2dad2b5590e472f72/src-tauri/src/lib.rs#L263
keepsimple1 commentedon Jun 15, 2025
Thanks! I hope
if-addrscrate can be enhanced to support checking interface UP or not. I've asked over there and also created a PR: messense/if-addrs#49 . But that's of course not in our control, so probably I will treat this as a separate issue and won't block this original issue.keepsimple1 commentedon Jun 26, 2025
@parasyte Just want to check, would the updated diff work for your use case? Or is it still confusing? The key change is the
addressesfield inResolvedService:(Btw, we will use a separate PR to filter out interfaces are "down" operationally).
keepsimple1 commentedon Jun 30, 2025
I went through this PR again and I updated the design after more of thinking: add
InterfaceIdinfo only for IPv6 address, not for IPv4 address.Instead of
HashMap<IpAddr, Vec<InterfaceId>>, nowResolvedService.addressesisHashSet<HostIp>. Its change is simply that the newHostIpreplaces the existingIpAddrand supportsscope_idfor IPv6.Hope this make the change of
ResolvedServiceeasier to understand, and remove confusions.keepsimple1 commentedon Jul 9, 2025
PR merged finally ;-). Opened a new issue to track the filter for
Downinterfaces. If any questions, please raise them. Thanks!keepsimple1 commentedon Jul 10, 2025
A separate PR #369 opened to exclude the operational down interfaces. @hrzlgnm let me know if it helps in your setup.
hrzlgnm commentedon Jul 10, 2025
Thanks, tried it out and the change and indeed helps a lot in my setup and probably others, too.
Now I have:
Instead of:
hrzlgnm commentedon Jul 10, 2025
@keepsimple1 Can we have public access to the field
HostIpV6::scope_id, otherwise it's not possible to use thescope_idin other means than.to_string()keepsimple1 commentedon Jul 11, 2025
Surely we can add that. Is it easier for you to use a method of
HostIpv6or ofHostIpenum, as following?or this:
parasyte commentedon Jul 11, 2025
(Apologies for my recent silence on this. My client decided that we needed to skip local resolution and go straight for public WAN resolution in the project we are working on, so this kind of got back-burnered for me.)
I'm going to try to find some time to give this a try.
I can't speak for @hrzlgnm, but I would personally lean toward the method on
HostIPv6, if the choice is between those two. This info only needs to be queried for IPv6 address, but only for link-local addresses. I.e., only whenIpv6Addr::is_unicast_link_local()returnstrue.hrzlgnm commentedon Jul 11, 2025
I'm with @parasyte here, we should go with a method of HostIpV6.
keepsimple1 commentedon Jul 11, 2025
Thanks @parasyte @hrzlgnm I've added the access methods in PR #369 and updated test cases.
Understood. Currently I'm always returning
&InterfaceIdfor IPv6, instead ofOption<&InterfaceId>as I think the ergonomic benefit overweights the "only needed for link local addrs". Besides, in mDNS cases, the relevant IPv6 addrs are always link local. (And, the client can always checkis_unicast_link_local(), which is a recent stable API btw).keepsimple1 commentedon Jul 13, 2025
PRs merged.