frawau / aiozeroconf

An asyncio/pure python implementation of multicast DNS service discovery
GNU Lesser General Public License v2.1
25 stars 6 forks source link

Align membership registration code between ipv4 and ipv6 #3

Closed RouquinBlanc closed 5 years ago

RouquinBlanc commented 5 years ago

There was an inconsistency between the multicast registration code.

On top of being misaligned, this prevents working on MacOS when specifying an interface. With this change I can now use the lib in both Ubuntu 18.04 and Mac OS Mojave (Could only test those 2).

RouquinBlanc commented 5 years ago

Well in fact it was very much incomplete, even on IPv6. It seems that the convention of binding on idx 0 in IPv6 is only for linux; on Mac OS it does not work!

So this is an attempt to:

Tested with all combination of:

frawau commented 5 years ago

Thanks for the PR. Will release soon.

frawau commented 5 years ago

Hi,

I am having a problem with your mods.

I am using Ubuntu 18.10 and for my main.py program to work I must specify an interface for IPv4 to work whereas before it was working fine.

For instance with the new version

mycomputer ==> python3 -m aiozeroconf

Browsing services, press Ctrl-C to exit...

Service MyComputer._http._tcp.local. of type _http._tcp.local. state changed: ServiceStateChange.Added Address: 172.17.0.1:8080 Weight: 0, priority: 0 Server: MyComputer.local. No properties

Old version

fw@MyComputer ==> python3 -m aiozeroconf

Browsing services, press Ctrl-C to exit...

Service MyComputer._http._tcp.local. of type _http._tcp.local. state changed: ServiceStateChange.Added Address: 10.10.10.1:8080 Weight: 0, priority: 0 Server: MyComputer.local. No properties

Service Hollywood._http._tcp.local. of type _http._tcp.local. state changed: ServiceStateChange.Added Service Hollywood #2._http._tcp.local. of type _http._tcp.local. state changed: ServiceStateChange.Added Address: 10.10.10.10:9981 Weight: 0, priority: 0 Server: Hollywood.local. Properties are: b'path': b'/'

Service Colour._http._tcp.local. of type _http._tcp.local. state changed: ServiceStateChange.Added Address: 10.10.10.15:80 Weight: 0, priority: 0 Server: Paris.local. No properties

Service sonoff-9EE161-0353._http._tcp.local. of type _http._tcp.local. state changed: ServiceStateChange.Added Address: 10.10.10.41:80 Weight: 0, priority: 0 Server: sonoff-9ee161-0353.local. No properties

Service sonoff-AB0C18-3096._http._tcp.local. of type _http._tcp.local. state changed: ServiceStateChange.Added Service sonoff-43A00C-0012._http._tcp.local. of type _http._tcp.local. state changed: ServiceStateChange.Added Service sonoff-4600C7-0199._http._tcp.local. of type _http._tcp.local. state changed: ServiceStateChange.Added Service sonoff-86721B-4635._http._tcp.local. of type _http._tcp.local. state changed: ServiceStateChange.Added Address: 10.10.10.10:8080 Weight: 0, priority: 0 Server: Hollywood.local. No properties

Address: 10.10.10.47:80 Weight: 0, priority: 0 Server: sonoff-ab0c18-3096.local. No properties

Address: 10.10.10.45:80 Weight: 0, priority: 0 Server: sonoff-4600c7-0199.local. No properties

Address: 10.10.10.40:80 Weight: 0, priority: 0 Server: sonoff-86721b-4635.local. No properties

Address: 10.10.10.48:80 Weight: 0, priority: 0 Server: sonoff-43a00c-0012.local. No properties

I have a bunch of interfaces ['lo', 'enp3s0', 'br0', 'virbr0', 'virbr0-nic', 'docker0']

"br0" is a bridge with 'enp3s0' and 'virbr0-nic'. Addr 10.10.10.1 'docker0' has address 172.17.0.1 'virbr0' has address 192.168.122.1

No VM is running

Any idea?

RouquinBlanc commented 5 years ago

Hum... Then I guess it comes from the fact that the DNS request is not sent to the right interface... A socket can be bound for sending to only one interface. This is why in the original zeroconf project one socket is created for each interface, in to of the one listening on all interfaces... Looking at the original zeroconf code on which this project is based, many things are done pretty differently now...

Ideally I should try to add the extra code to open sending sockets for every interface, but then the changes required are much bigger... I will see if I can find time for this as originally it was supposed to be a quick fix :-)

Le jeu. 1 nov. 2018 à 15:43, François Wautier notifications@github.com a écrit :

Hi,

I am having a problem with your mods.

I am using Ubuntu 18.10 and for my main.py program to work I must specify an interface for IPv4 to work whereas before it was working fine. For instance with the new version

mycomputer ==> python3 -m aiozeroconf

Browsing services, press Ctrl-C to exit... Service MyComputer._http._tcp.local. of type _http._tcp.local. state changed: ServiceStateChange.Added Address: 172.17.0.1:8080 Weight: 0, priority: 0 Server: MyComputer.local. No properties Old version

fw@MyComputer ==> python3 -m aiozeroconf

Browsing services, press Ctrl-C to exit...

Service MyComputer._http._tcp.local. of type _http._tcp.local. state changed: ServiceStateChange.Added Address: 10.10.10.1:8080 Weight: 0, priority: 0 Server: MyComputer.local. No properties

Service Hollywood._http._tcp.local. of type _http._tcp.local. state changed: ServiceStateChange.Added Service Hollywood #2 https://github.com/frawau/aiozeroconf/pull/2._http._tcp.local. of type _http._tcp.local. state changed: ServiceStateChange.Added Address: 10.10.10.10:9981 Weight: 0, priority: 0 Server: Hollywood.local. Properties are: b'path': b'/'

Service Colour._http._tcp.local. of type _http._tcp.local. state changed: ServiceStateChange.Added Address: 10.10.10.15:80 Weight: 0, priority: 0 Server: Paris.local. No properties

Service sonoff-9EE161-0353._http._tcp.local. of type _http._tcp.local. state changed: ServiceStateChange.Added Address: 10.10.10.41:80 Weight: 0, priority: 0 Server: sonoff-9ee161-0353.local. No properties

Service sonoff-AB0C18-3096._http._tcp.local. of type _http._tcp.local. state changed: ServiceStateChange.Added Service sonoff-43A00C-0012._http._tcp.local. of type _http._tcp.local. state changed: ServiceStateChange.Added Service sonoff-4600C7-0199._http._tcp.local. of type _http._tcp.local. state changed: ServiceStateChange.Added Service sonoff-86721B-4635._http._tcp.local. of type _http._tcp.local. state changed: ServiceStateChange.Added Address: 10.10.10.10:8080 Weight: 0, priority: 0 Server: Hollywood.local. No properties

Address: 10.10.10.47:80 Weight: 0, priority: 0 Server: sonoff-ab0c18-3096.local. No properties

Address: 10.10.10.45:80 Weight: 0, priority: 0 Server: sonoff-4600c7-0199.local. No properties

Address: 10.10.10.40:80 Weight: 0, priority: 0 Server: sonoff-86721b-4635.local. No properties Address: 10.10.10.48:80 Weight: 0, priority: 0 Server: sonoff-43a00c-0012.local. No properties

I have a bunch of interfaces ['lo', 'enp3s0', 'br0', 'virbr0', 'virbr0-nic', 'docker0']

"br0" is a bridge with 'enp3s0' and 'virbr0-nic'. Addr 10.10.10.1 'docker0' has address 172.17.0.1 'virbr0' has address 192.168.122.1

No VM is running

Any idea?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/frawau/aiozeroconf/pull/3#issuecomment-435055318, or mute the thread https://github.com/notifications/unsubscribe-auth/AL7y-E6ODNz2RAKfBGurYr1PymzIg8S7ks5uqwisgaJpZM4YCA5x .

RouquinBlanc commented 5 years ago

By the way, the code works as I would expect in this case: as it bound the socket to docker interface last, that's the only interface on which the DNS request was sent.

In the old situation though, it was probably only sending on enp3s0, which is different but not much better! We will get to a good state when we get both!

RouquinBlanc commented 5 years ago

I've made several extra changes for:

Will submit another PR