Skip to content
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

Return IP address in the same subnet first when resolving host name #1375

Open
shuangye opened this issue May 11, 2024 · 0 comments
Open

Return IP address in the same subnet first when resolving host name #1375

shuangye opened this issue May 11, 2024 · 0 comments

Comments

@shuangye
Copy link

I register a service with multiple IP addresses on a host named "a.local".

host = 'a.local'
addresses = ['169.254.221.201', 'fe80::b899:e0f5:4425:b0d3', '172.27.224.1', 'fe80::70b:21f5:ed6c:b3d7', '10.0.0.17', 'fe80::ea97:b49:2a41:3a7c', '169.254.145.196', 'fe80::fbbd:c6c3:9671:28a6', '169.254.8.134', 'fe80::dc87:290:5b75:f12e', '169.254.10.51', 'fe80::2f53:e6a8:83bb:849b']
service = ServiceInfo("_http._tcp.local.",
                        f"dummy server._http._tcp.local.",
                        port=port,
                        parsed_addresses=addresses,
                        server=f"{host}.")

Then I run avahi-resolve to resolve the host name from a client 10.0.0.201. Seems zeroconf returns IP addresses in unpredictable order. The result may change between different runs:

$ avahi-resolve -n a.local
a.local 172.27.224.1
$ avahi-resolve -n a.local
a.local 10.0.0.17
$ avahi-resolve -n a.local
a.local fe80::70b:21f5:ed6c:b3d7  # sometimes even IPv6 address, but client uses IPv4

Capture the traffic using tcpdump:

15:12:38.102579 IP (tos 0x0, ttl 255, id 16597, offset 0, flags [DF], proto UDP (17), length 59)
    10.0.0.201.5353 > 224.0.0.251.5353: [bad udp cksum 0xebfc -> 0xe6aa!] 0 [2q] A (QM)? a.local. AAAA (QM)? a.local. (31)
15:12:38.214380 IP (tos 0x0, ttl 255, id 19923, offset 0, flags [none], proto UDP (17), length 311)
    10.0.0.17.5353 > 224.0.0.251.5353: [udp sum ok] 0*- [0q] 12/0/0 a.local. (Cache flush) [2m] A 172.27.224.1, a.local. (Cache flush) [2m] A 169.254.10.51, a.local. (Cache flush) [2m] A 169.254.221.201, a.local. (Cache flush) [2m] AAAA fe80::ea97:b49:2a41:3a7c, a.local. (Cache flush) [2m] AAAA fe80::fbbd:c6c3:9671:28a6, a.local. (Cache flush) [2m] A 169.254.8.134, a.local. (Cache flush) [2m] AAAA fe80::70b:21f5:ed6c:b3d7, a.local. (Cache flush) [2m] AAAA fe80::2f53:e6a8:83bb:849b, a.local. (Cache flush) [2m] A 169.254.145.196, a.local. (Cache flush) [2m] AAAA fe80::b899:e0f5:4425:b0d3, a.local. (Cache flush) [2m] AAAA fe80::dc87:290:5b75:f12e, a.local. (Cache flush) [2m] A 10.0.0.17 (283)

I think it could be better if zeroconf can prioritize the IP address which is in the same subnet as the client.
In this example, client IP address is 10.0.0.201, so it could be better to return 10.0.0.17 first, since avahi-resolve uses the first IP address only.

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

No branches or pull requests

1 participant