-
Notifications
You must be signed in to change notification settings - Fork 6.9k
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: dns-sd: support dns service discovery #29179
net: dns: dns-sd: support dns service discovery #29179
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some initial notes.
Just "transposed" my test suite over from gtest, which had 100% coverage. There are likely still some issues to sort out here (e.g. currently there are pointer comparisons where there were previously vector comparisons). |
Close - running into random faults, but otherwise, I'm able to get responses: $ avahi-browse -t -r _zephyr._tcp
+ lowpan0 IPv6 Zephyr RTOS _zephyr._tcp local
= lowpan0 IPv6 Zephyr RTOS _zephyr._tcp local
hostname = [Zephyr\032RTOS.local]
address = [2001:db8::1]
port = [4242]
txt = [] There is a similar UDP service that can be queried as well. I'm currently testing with the It can be tested with the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you could add here the changes you have to mdns_responder sample, that way it is easier to see how the thing is being used.
One thing I noticed, that we should do also changes to socket layer as we should only start to advertise the service after there is a local socket bound to the said service. So the application etc can register a service using the macros, but it should be only enabled at runtime after there is really a service running.
Currently there is a stack overflow on |
I was thinking about creating a separate ticket for that but just including it here as a PR since they are pretty tightly coupled; do we have a non-multicast DNS service as well?
Hmm... would make sense. I also considered adding some callbacks to the REGISTER() macro. what do you think of
Could possibly use flags instead of individual functions too. That might actually facilitate dynamic TXT 😳 |
We could introduce DNS-SD to other samples too if they enable DNS. For example echo-server is not enabling DNS by default, but we could have an overlay there which could enable DNS-SD so that the app can start to advertise the service. |
Callbacks are not really possible if the application is running in usermode as the kernel mode component cannot pass any data in a safe way to the application. If possible, lets try to avoid callbacks unless really mandatory. In #29200 I did a bit similar functionality. In that PR, when application binds to a local address, the code in So for DNS-SD, we could do it similar way. If application has registered DNS-SD service (using the macro, we could allow runtime configuration in the future too, this was what I suggested earlier), the bind code will call some dns-sd API function to let it know that a local port was bound, dns-sd could then verify that this port is indeed an already registered service and enable advertisements. When the said socket is closed, the advertisements are disabled. |
That might be a lot of pressure on one ticket - can we limit this one to "support" and then "enable" in samples later? |
The problem with this "early" support is that it is not possible to see example how the DNS-SD would work if we not have sample that uses it properly (with also changes in socket bind()). I am hesitant to have code merged if the usage of it is not clear. |
That said, we could have another PR that adds sample etc if you do not want to add extra commits to this one. |
Sorry for the confusion - I will definitely add DNS-SD to the mDNS responder application, I just mean that it might be a bit much to add DNS-SD support to every networked sample application. As long as we can limit the sample changes to mDNS responder, that is ok with me. You? |
Agreed, I did not mean that we need to add DNS-SD support to every network samp app either. |
Since all of the DNS-SD records are const, it might be better to query the network subsystem from DNS_SD to see whether or not any sockets are open on a given address / port. I mean, a simple way to do it would be to try and open a socket / port and immediately close it afterward, but that gets a bit racey. I like the idea though. Another item that ties into this idea is the simple fact that DNS-SD was designed so that ports did not need to be preassigned. A service should be able to bind to 0 and get an ephemeral port number and have DNS-SD advertise that randomly assigned port number as easily as if it were preassigned. In particular, I think that would make for a good "next ticket" item, as I think it would solve both of our concerns, @jukkar. E.g. if the port number is 0, that means the service has not yet started and DNS-SD should not advertise it. However, using a |
OK - I think I'm basically done now, as long as everything is green. Please have a look over at your earliest convenience. |
@jukkar, I believe that the last commit should address your change request. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since all of the DNS-SD records are const, it might be better to query the network subsystem from DNS_SD to see whether or not any sockets are open on a given address / port. I mean, a simple way to do it would be to try and open a socket / port and immediately close it afterward, but that gets a bit racey.
I do not think we need to do those kind of kludges like open a socket and then immediately close it. We can just implement a function (could be kept private) in socket lib, that checks whether a given port is opened or not, and then call that from DNS_SD to check whether the service should be advertised or not.
; | ||
} | ||
|
||
int add_a_record(const struct dns_sd_rec *inst, uint32_t ttl, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had I been able to, I would have just included the .c file in the test.
Including the .c file could be a nice solution here, what was the issue preventing that?
Same - I was just using it as a bad example.
Should the function be added in this PR? |
I am fine with that, in a separate commit of course. |
Update - added ephemeral port support in this PR as well. So that would allow a service to just use any available port that was returned by |
I think I will need to create a small network service in mdns_responder and bind it to a port, because obviously with the additional change where it only advertises bound services, mdns_responder no longer responds to PTR queries. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, pretty neat 👍
Some last minute changes - sorry. As it turns out, the Just tested with Ephemeral Port:
Fixed Port:
|
This change adds net_context_port_in_use(), which is a simple wrapper around net_context_check_port() and is used to check if a particular socket is bound to a given IP address. Fixes #29649 Signed-off-by: Christopher Friedt <[email protected]>
This change adds support for DNS Service Discovery (DNS-SD) as described in RFC 6763. Fixes #29099 Signed-off-by: Christopher Friedt <[email protected]>
Tests for DNS-SD (RFC 6763) Fixes #29099 Signed-off-by: Christopher Friedt <[email protected]>
This change enables support for DNS service discovery (RFC 6763) in the mdns_responder service and sample app. Fixes #29429 Signed-off-by: Christopher Friedt <[email protected]>
Thanks - yeah, I think it's a relatively small change that should enable a lot of functionality :-) Especially judging by how some of the existing smart home devices use DNS-SD, I think it could really enable a lot of products to come out of Zephyr. |
This change adds support for DNS Service Discovery (DNS-SD) as described in RFC 6763. It also adds DNS-SD support to the
mdns_responder
service and sample application as well as a function callnet_context_port_in_use()
.Fixes #29099
Fixes #29429
Fixes #29649