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: mdns: add capability of providing records in runtime #60271
net: mdns: add capability of providing records in runtime #60271
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.
Hello @konradderda, and thank you very much for your first pull request to the Zephyr project!
A project maintainer just triggered our CI pipeline to run it against your PR and ensure it's compliant and doesn't cause any issues. You might want to take this opportunity to review the project's Contributor Expectations and make any updates to your pull request if necessary. 😊
Technically, that's not exactly the case, it only requires the pointers to memory for DNS records to be set at compile time (and subsequently the number of records).
The memory that each record points to can be runtime modifiable today. In any case though, dns_sd is definitely ripe for improvement. |
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.
Looks good to me, with a couple of minor modifications.
Please fix the compliance issues and ensure the build is green.
If you have interest in this area, I would recommend checking out some of the items on the TODO list here #38846
subsys/net/lib/dns/mdns_responder.c
Outdated
DNS_SD_FOREACH(record) { | ||
DNS_SD_COUNT(&rec_num); | ||
|
||
while (rec_num || ext_rec_num) { |
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.
Please use integer comparisons here instead of treating the integers as bools
cc @pdgendt |
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.
Please check the compliance results, it reported some nits as well. Otherwise looks good.
include/zephyr/net/mdns_responder.h
Outdated
|
||
#include <stddef.h> | ||
|
||
#include "dns_sd.h" |
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.
#include <zephyr/net/dns_sd.h>
include/zephyr/net/mdns_responder.h
Outdated
* @ref DNS_SD_REGISTER_SERVICE (if any) and then go over external records. | ||
* | ||
* @param records An array of mDNS records | ||
* @param count The number of elemnts |
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.
* @param count The number of elemnts | |
* @param count The number of elements |
include/zephyr/net/mdns_responder.h
Outdated
* | ||
* @param records An array of mDNS records | ||
* @param count The number of elemnts | ||
* @return int 0 for OK; -EINVAL for invalid parameters. |
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.
@return
doesn't need type
731b176
to
9132a20
Compare
Hello @cfriedt,
That was my first idea. However, it's not possible because the zephyr/include/zephyr/net/dns_sd.h Line 233 in e544bdb
Moreover, such approach would be enough for a small number of records. With this approach the user can provide a pointer to a static array, memory slab, heap allocated memory, etc. |
261f0fc
to
b8c69a8
Compare
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.
b8c69a8
to
ebef21e
Compare
@cfriedt @ssharks @tbursztyka, sorry for bothering you but it seems that this PR could be closed with an additional approval, could you please look at it? Thanks in advance. |
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.
The only thing I observe: Is it clear to the users that the mdns_responder_set_ext_records knows it have to make the data stay at that location instead of providing a stack variable?
@ssharks, Thank you for the question, I think that providing a stack variable is perfectly fine as long as the scope is prolonged - e.g. we can have an array of |
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 changes needed
ebef21e
to
7c707ec
Compare
This pull request has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this pull request will automatically be closed in 14 days. Note, that you can always re-open a closed pull request at any time. |
ping @konradderda, just wondering if you would have some time to address the latest comments? |
@jukkar I am sorry for the delay. There is no problem with addressing the comments regarding the code. However, I had tried to write a test case for my change and I found that with the current implementation it's quite hard to do. Unfortunately, at the moment I will not be able to provide a proper test implementation. |
@konradderda will you return to this before the 3.6 merge window closes this week? |
ping @konradderda, are you able to continue with this? The needed changes look rather small and it would be nice to get this merged as this has been pending for a long time. It would be also nicer to get this in at the beginning of the 3.7 release cycle than at the end. |
Hmm, I missed the fact that unit tests would need changes too so the amount of work is bigger. |
705f986
to
ca4fa5c
Compare
ca4fa5c
to
795cbfd
Compare
@jukkar @MaureenHelm I had finally got some time and prepared a test for this change with a foundations for implementation of new test cases in the futute. Also, I have applied last remarks from @cfriedt . |
795cbfd
to
1d4de57
Compare
342c82a
to
9d681cb
Compare
if (!ifaddr) { | ||
zassert_not_null(ifaddr, "Failed to add LL-addr"); | ||
} else { | ||
/* we need to set the addresses preferred */ | ||
ifaddr->addr_state = NET_ADDR_PREFERRED; | ||
} |
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.
We can simplify this to:
zassert_not_null(ifaddr, "Failed to add LL-addr");
/* we need to set the addresses preferred */
ifaddr->addr_state = NET_ADDR_PREFERRED;
because if the zassert fails, then the program stops so there is no need to have the if() else() branches.
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.
Done
subsys/net/lib/dns/mdns_responder.c
Outdated
*/ | ||
if (rec_num > 0) { | ||
DNS_SD_GET(rec_num - 1, &record); | ||
rec_num -= 1; |
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.
That is perfectly valid code but usually -1 is done via rec_num--;
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.
Done
subsys/net/lib/dns/mdns_responder.c
Outdated
rec_num -= 1; | ||
} else { | ||
record = &external_records[ext_rec_num - 1]; | ||
ext_rec_num -= 1; |
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.
and ext_rec_num--;
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.
Done
9d681cb
to
4b19cdb
Compare
Current implementation of mDNS responder does makes it mandatory to have all the records set at compile time. It is not suited well for applications that have to publish/unpublish or change records in runtime, e.g. data received from the network. Signed-off-by: Konrad Derda <konrad.derda@nordicsemi.no>
This commit adds a test for externally stored mDNS records for mDNS responder. Signed-off-by: Konrad Derda <konrad.derda@nordicsemi.no>
4b19cdb
to
9ed5102
Compare
Current implementation of mDNS responder does makes it mandatory to have all the records set at compile time. It is not suited well for applications that have to publish/unpublish or change records in runtime, e.g. data received from the network.