Skip to content

Add ability to specify multicast groups with addresses #1520

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

Open
gabearro opened this issue Feb 13, 2025 · 10 comments
Open

Add ability to specify multicast groups with addresses #1520

gabearro opened this issue Feb 13, 2025 · 10 comments

Comments

@gabearro
Copy link

Zeroconf assumes that all of the interfaces passed into the library via Zeroconf(interfaces=[<address_0>, <address_1>,...] are able to be bound to. This isn't always the case, for example in a sandboxed environment such as iOS.

In iOS, you are able to bind a socket to 127.0.0.1:5353 but you aren't able to bind to the en0 and pdp_ip0 interfaces on port 5353 because the system daemon is already bound to that. There needs to be a way to configure which addresses are apart of the multicast group that zeroconf builds in.

@bdraco
Copy link
Member

bdraco commented Feb 13, 2025

Check the example in the Home Assistant zeroconf integration on how to specify

@gabearro
Copy link
Author

https://github.com/home-assistant/core/blob/81cac25bd01c26b8076c938a40a3677d9baf58b0/homeassistant/components/zeroconf/__init__.py#L196

@bdraco this specifies the interfaces the zeroconf tries to bind to. For the use case that I have I need to add two interfaces to the multicast group while only binding to one of the two.

@bdraco
Copy link
Member

bdraco commented Feb 13, 2025

While I'm still not 100% sure what you are asking for, InterfacesType does allow specifying a list of ip addresses:

InterfacesType = Union[Sequence[Union[str, int, tuple[tuple[str, int, int], int]]], InterfaceChoice]

The code to normalize the choices is at

def normalize_interface_choice(

If you need something more complex we could accept a PR to expand the options.

@bdraco bdraco changed the title Unable to specify multicast group addresses Add ability to specify multicast groups with addresses Feb 13, 2025
@gabearro
Copy link
Author

gabearro commented Feb 13, 2025

Apologies about the lack of information, I opened this issue while being on mobile. I will provide more details tomorrow when I have more time :)

I think the best way to articulate the issue is as follows:

On iOS, multicast messages sent to and from the device may not be received unless the device explicitly joins a multicast group on both its local IP and 127.0.0.1. Currently(assume interfaces=[localhost, local_ip]), Zeroconf attempts to bind to port 5353 on both those interfaces which will fail because of iOS sandboxing.

Ideally zeroconf's implementation should support the following:

  • binding to a specific interface
  • creating a multicast group for the bound socket consisting of explicitly defined addresses/interfaces

I will likely create the PR for this tomorrow assuming I have time. Are there any contribution guidelines for this project?

@bdraco
Copy link
Member

bdraco commented Feb 13, 2025

Thanks for the additional details. That makes a lot more sense now. It would be helpful if you could also post the log of the exceptions/errors that happen for additional context.

I will likely create the PR for this tomorrow assuming I have time. Are there any contribution guidelines for this project?

Commit messages should follow https://www.conventionalcommits.org/en/v1.0.0/ to keep the CI happy, however as long as the title of the PR does it will get squashed in the end anyways.

@bdraco
Copy link
Member

bdraco commented Feb 13, 2025

Also keep in mind we eventually need to implement run time reloads to solve home-assistant/core#59553 so any changes should think about that a bit

@gabearro
Copy link
Author

Also keep in mind we eventually need to implement run time reloads to solve home-assistant/core#59553 so any changes should think about that a bit

Is zeroconf technically a home-assistant project or are they just tightly intertwined? Just so I know what to look out for

@gabearro
Copy link
Author

Thanks for the additional details. That makes a lot more sense now. It would be helpful if you could also post the log of the exceptions/errors that happen for additional context.

I will likely create the PR for this tomorrow assuming I have time. Are there any contribution guidelines for this project?

Commit messages should follow https://www.conventionalcommits.org/en/v1.0.0/ to keep the CI happy, however as long as the title of the PR does it will get squashed in the end anyways.

I will provide some logs later today, it isn't obvious to be honest that something is wrong. When you bind to all addresses it configures a correct multicast group but wont actually broadcast because of using two unique interfaces(seems to be a posix issue but honestly not sure. I think the kernel doesn't know which interface to use for multicast and decides on neither) while actively using those two interfaces. When you bind to just localhost you wont have any issues other than not receiving anything!

@bdraco
Copy link
Member

bdraco commented Feb 13, 2025

Also keep in mind we eventually need to implement run time reloads to solve home-assistant/core#59553 so any changes should think about that a bit

Is zeroconf technically a home-assistant project or are they just tightly intertwined? Just so I know what to look out for

zeroconf is not a Home Assistant project. It is the largest known user base for this project though and the source of most issue reports. ie. this project's largest customer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants