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
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.

Copy link
Contributor

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?

Sorry for the late reply. I am trying to debug this issue further. Below is a part of the log showing how the system should respond (with our current patch).
Especially the last line is relevant where the net context is bound to UDP 5353.

[00:00:00.056,000] <dbg> net_sock_svc: socket_service_thread: (net_socket_service): Service WEST_TOPDIR/zephyr/subsys/net/lib/dns/mdns_responder.c:47 has 2 pollable sockets
[00:00:00.074,000] <dbg> net_sock_svc: socket_service_thread: (net_socket_service): Monitoring 2 socket entries
[00:00:00.086,000] <inf> net_mdns_responder: REGISTER DISPATCHER STARTS HERE
[00:00:00.094,000] <dbg> net_sock: zsock_socket_internal: (main): socket: ctx=0x2000740c, fd=5
[00:00:00.105,000] <dbg> net_ctx: net_context_bind: (main): Context 0x2000740c binding to UDP 224.0.0.251:5353 iface 2 (0x200018b8)

However, with the current (unpatched) code this never happens and incoming mDNS requests are not being forwarded to the responder.

As discussed above, comparing addresses and ports is not sufficient in this case.
Using the sockets to distinguish the entries works (although it might not be that clean).
I will try to use the network interfaces for that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jukkar do you think comparing sockets will be sufficient? Those should be interface, protocol and port specific so the distinction can be made as required. Might there be a reason why we shouldn't just compare the fds of the two sockets in question?

Copy link
Member

Choose a reason for hiding this comment

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

Socket numbers are unique, how could that help here as mentioned in #79588 (comment)

@jukkar
Copy link
Member

jukkar commented Oct 16, 2024

@kica-z I have alternate implementation proposal at #79917. I did not test it much but verified that it can now listen to multiple network interfaces. If possible please try it and report if it works for you.

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.

5 participants