Skip to content

Add support for AWDL interface on macOS #207

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

Merged
merged 1 commit into from
Dec 17, 2019
Merged

Add support for AWDL interface on macOS #207

merged 1 commit into from
Dec 17, 2019

Conversation

schmittner
Copy link

The API is inspired by Apple's NetService.includesPeerToPeer
(see https://developer.apple.com/documentation/foundation/netservice/1414086-includespeertopeer)

@schmittner
Copy link
Author

@jstasiak not sure why build for pypy3.5 fails. My changes should not have any effects by default.

@jstasiak
Copy link
Collaborator

Hey, thanks for the patch, it's actually shorter than I expected after a quick look some time ago, nice!

not sure why build for pypy3.5 fails. My changes should not have any effects by default.

One or two of the tests fail intermittently on PyPy for some reason, yet to be figured out.

Regarding the patch – I'm wondering about the API. Wouldn't it be better if we got rid of the apple_p2p public constructor parameter and instead detected internally if one of the interfaces addresses belongs to awdl0? It sounds like it should work, I can do it myself later. Here I'd at least change the apple_p2p behavior to crash on non-mac platforms and remove the if platform.system() == 'Darwin' check – the parameter says it's macOS-only already.

@schmittner
Copy link
Author

schmittner commented Dec 17, 2019

Regarding the API: enabling AWDL automatically is a security risk. Services could get unintentionally advertised over AWDL which is an unauthenticated interface and anybody within range could overhear the announcements. I believe this is the reason why Apple implements its API like this.

That's why I would want to keep the flag. What we could do, however, is automatically set apple_p2p to True when the user selects awdl0 as the only interface in which case we assume that the user knows what they're doing.

Regarding the platform check: isn't ignoring the setting on non-Apple platforms more graceful? Actually, I think it would make sense to check if the interface name is awdl0 even on macOS before trying to set the option. yes, we can do this. I'll update the pull request.

@jstasiak
Copy link
Collaborator

What we could do, however, is automatically set apple_p2p to True when the user selects awdl0 as the only interface in which case we assume that the user knows what they're doing.

This is what I had in mind, I should've been more explicit, sorry. I'd only enable it by default if the client code explicitly selects that one interface.

Actually, I think it would make sense to check if the interface name is awdl0 even on macOS before trying to set the option.

Agreed. The way I'd expect it to work:

interfaces apple_p2p (Optional[bool]) behavior
multiple interfaces None or False no SO_RECV_ANYIF set on any socket
multiple interfaces True SO_RECV_ANYIF set on a socket(s) corresponding to AWDL interface (if any)
AWDL interface None or True SO_RECV_ANYIF set
AWDL interface False ?

Is this tenable security-wise?

@jstasiak
Copy link
Collaborator

Alternatively maybe let's stick to the explicit way of enabling this (I'm kind of leaning this way, but I'll leave the decision to you):

interfaces apple_p2p (bool, default False) behavior
multiple interfaces False no SO_RECV_ANYIF set on any socket
multiple interfaces True SO_RECV_ANYIF set on a socket(s) corresponding to AWDL interface (if any)
AWDL interface True SO_RECV_ANYIF set
AWDL interface False no SO_RECV_ANYIF set

@schmittner
Copy link
Author

I also like the explicit way better. So, let's stick with that.

Unfortunately, it is currently not possible to set SO_RECV_ANYIF only on the AWDL interface since we are always binding to ('', port) (see issue #193). If that is resolved (e.g., via #180), we can add such a check.

@jstasiak have you figured out the pypy3.5 problem?

@jstasiak
Copy link
Collaborator

It usually just goes away when another build is triggered, someone needs to investigate it further to get to the bottom of it – restarting CI is a workaround for now.

As to setting SO_RECV_ANYIF – fair enough, let's merge as is now once the linter is happy.

@jstasiak jstasiak merged commit fcafdc1 into python-zeroconf:master Dec 17, 2019
@jstasiak
Copy link
Collaborator

jstasiak commented Dec 17, 2019

Edit: This whole comment is wrong. Ignore. :>

@jstasiak not sure why build for pypy3.5 fails. My changes should not have any effects by default.

So the funny thing is the test that sometimes fails in Travis on PyPy should never pass and I'm trying to figure out why. This line won't work because zeroconf variable is not there https://github.com/jstasiak/python-zeroconf/blob/fcafdc1e285cc5c3c1f2c413ac9309d3426179f4/zeroconf/test.py#L883 and the whole test should collapse.

@jstasiak
Copy link
Collaborator

Ugh, sorry, I actually made myself believe the above – I renamed the variable locally while debugging and forgot about it. Ignore me.

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

Successfully merging this pull request may close these issues.

2 participants