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

net: dns: Fix DNS dispatcher for multiple network interfaces #79588

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

kica-z
Copy link
Contributor

@kica-z kica-z commented Oct 9, 2024

When having multiple interfaces the dns dispatcher falsely flags interfaces with the same port and address_family as duplicates. This leads to problems when for example using MDNS.

@NilsRuf-EH thanks for pointing that out.

When having multiple interfaces the dns dispatcher falsely flags
interfaces with the same port and address_family as duplicates.
This leads to problems when for example using MDNS.

Signed-off-by: Carlo Kirchmeier <carlo.kirchmeier@zuehlke.com>
Co-authored-by: Nils Ruf <nils.ruf@endress.com>
@kica-z kica-z force-pushed the bugfix/mdns-multi-interface branch from 4a1491b to 7e586e2 Compare October 9, 2024 08:15
net_sin(&ctx->local_addr)->sin_port) {
dup = true;
continue;
if (ctx->sock == entry->sock) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't explicit check for socket FD make other checks kind of pointless? It's not that you can have a socket that is bound to two different ports...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably check the addresses instead of socket descriptor values.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rlubos i think you are right.

@jukkar so we would compare net_sin(&ctx->local_addr)->sin_addr.s_addr == net_sin(&entry->local_addr)->sin_addr.s_addr as well as the port right? And since no two interfaces should have the same IP assigned this would also solve the issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this also be called for interfaces that are down or have no address assigned?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we would compare net_sin(&ctx->local_addr)->sin_addr.s_addr == net_sin(&entry->local_addr)->sin_addr.s_addr as well as the port right? And since no two interfaces should have the same IP assigned this would also solve the issue.

It needs to be a bit more complicated as IPv6 needs to be checked too. Your example address check only validates IPv4 address.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this also be called for interfaces that are down or have no address assigned?

Please elaborate what you mean, I do not understand your question.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this also be called for interfaces that are down or have no address assigned?

Please elaborate what you mean, I do not understand your question.

^ was a misconception of mine and can be ignored

But as far as i can see in the MDNS responder the function register_dispatcher and subsequently dns_dispatcher_register is called for each interface twice (once IPv4 and IPv6) and the local_addr is the same for both interfaces since it is the multicast 224.0.0.251 respectively ff02::fb. So both interfaces would have the same IP during the dispatch_register and the comparison would detect a false duplicate again right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, the addresses would be the same in this case.

Hmm, I am trying to understand the actual issue. So you see the problem when having two network interfaces, what exactly is printed (if you enable debugging) error / warning etc. in this case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In short: The second interface was detected as a duplicate by the dispatcher since it had the same address family and port as the first interface (due to MDNS multicast).

@NilsRuf-EH as I will be absent the next few days could you have a look again at what the log output was in detail?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we have ports and family the same, then to separate them, the network interface is the only left thing that we can use.

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

Successfully merging this pull request may close these issues.

4 participants