Repository navigation
resolved: Implement continuous mDNS querying as per RFC6762 5.2 - #22532
Conversation
|
Looks like a couple of autopkgtest checks are failing due to timeouts. Possibly unrelated to the content of the PR. |
|
Ubuntu CIs are quite unstable. Please simply ignore the failures if they seem unrelated. |
|
@poettering Any feedback regarding this implementation would be appreciated. |
|
@vchillara could you rebase this one? |
3d16555 to
8e1ddd2
Compare
rebased. Also, reduced the scope of this pull request to include just the feature. |
|
@bluca branch has been rebased. could you please remove the "needs-rebase" label? |
24c8e2f to
dfac3a5
Compare
|
Added cache maintenance (issuing queries at 80, 85, 90, 95% of the TTL for services with actively interested clients, and updating records) as per RFC 6762. |
dfac3a5 to
403f3bc
Compare
evverx
left a comment
There was a problem hiding this comment.
Looking at #23750 (comment) it appears the idea is to provide the methods so that clients implemented elsewhere can interact with resolved. I think it generally makes sense (after all that's what the API is for) but I think it should also be possible to browse services using resolvectl browse or something like that.
Other than that with this patch applied resolved can be crashed by sending malformed packets:
Program received signal SIGABRT, Aborted.
0x00007fe46f6a1aec in __pthread_kill_implementation () from target:/lib64/libc.so.6
(gdb) bt
#0 0x00007fe46f6a1aec in __pthread_kill_implementation () from target:/lib64/libc.so.6
#1 0x00007fe46f6552a6 in raise () from target:/lib64/libc.so.6
#2 0x00007fe46f6287f3 in abort () from target:/lib64/libc.so.6
#3 0x00007fe47180cebf in log_assert_failed (text=0x65a4c0 "answer", file=0x659b23 "src/resolve/resolved-mdns-browse-services.c", line=371,
func=0x65a920 <__PRETTY_FUNCTION__.13> "mdns_notify_subscribers_unsolicited_updates") at ../src/basic/log.c:856
#4 0x00000000005c3370 in mdns_notify_subscribers_unsolicited_updates (m=0x618000000080, answer=0x0, owner_family=2) at ../src/resolve/resolved-mdns-browse-services.c:371
#5 0x000000000053960a in on_mdns_packet (s=0x612000002140, fd=15, revents=1, userdata=0x618000000080) at ../src/resolve/resolved-mdns.c:428
#6 0x00007fe471ba938e in source_dispatch (s=0x612000002140) at ../src/libsystemd/sd-event/sd-event.c:3591
#7 0x00007fe471bb1ba5 in sd_event_dispatch (e=0x617000000080) at ../src/libsystemd/sd-event/sd-event.c:4175
#8 0x00007fe471bb2d09 in sd_event_run (e=0x617000000080, timeout=18446744073709551615) at ../src/libsystemd/sd-event/sd-event.c:4236
#9 0x00007fe471bb308a in sd_event_loop (e=0x617000000080) at ../src/libsystemd/sd-event/sd-event.c:4257
#10 0x0000000000553a13 in run (argc=1, argv=0x7ffc7834b908) at ../src/resolve/resolved.c:92
#11 0x0000000000553cad in main (argc=1, argv=0x7ffc7834b908) at ../src/resolve/resolved.c:99
403f3bc to
97d884a
Compare
|
@daandemeyer fixed now @evverx |
Good to know. Thanks!
I'm not sure at this point the testsuite run with
I create a local network where a VM can send packets to a container and vice versa. It isn't ideal because due to I presume some kernel bugs Ideally I think new features should be put on hold until resolved gets to a point where new heap-use-after-frees like #23894 and #23843 no longer pop up every day and at least basic tests are introduced. |
|
btw, please always mark the review items you think are addressed as "resolved". |
| item->flags, | ||
| item->rrsig); | ||
| item->rrsig, | ||
| USEC_INFINITY); |
There was a problem hiding this comment.
please prefix with /* until= */
(we do that these days in func calls where the passed parameter gives no hint what it is)
There was a problem hiding this comment.
Where? It's not visible here, so maybe it ended up in some other commit.
Hi, we have fixed the review comments and marked them as 'resolved', except for a few that need clarification #22532 (comment) Regards |
|
Hi, Could you please review and provide your valuable feedback? |
keszybz
left a comment
There was a problem hiding this comment.
I don't see anything unreasonable. Still a bit of style issues. It's confusing that the whitespace fixes are applied in commit 5/6, instead of squashed into the original commits.
| return dns_answer_add_extend_full(a, rr, ifindex, flags, rrsig, USEC_INFINITY); | ||
| } | ||
|
|
||
| static inline int dns_answer_add(DnsAnswer *a, DnsResourceRecord *rr, | ||
| int ifindex, DnsAnswerFlags flags, DnsResourceRecord *rrsig) { | ||
| return dns_answer_add_full(a, rr, ifindex, flags, rrsig, USEC_INFINITY); |
There was a problem hiding this comment.
Also here, please add /* until= */ for completeness.
| * To adhere to these timing requirements for continuous queries, | ||
| * the maximum number of attempts should be set to 1. | ||
| */ | ||
| #define MDNS_TRANSACTION_CONTINUOUS_QUERY_MAX 1 |
There was a problem hiding this comment.
Hmm, also here I don't see this changed. (I think that the change is completely pointless too, but let's ignore that.)
I guess I'm dense, but I don't see how the two rules mean that the number is 1. "Continuous" is explicitly about sending a stream of queries infinitely…
| switch (p) { | ||
|
|
||
| case DNS_PROTOCOL_LLMNR: | ||
| return LLMNR_TRANSACTION_ATTEMPTS_MAX; |
| * 60 minutes, perform subsequent queries at a steady-state rate of one | ||
| * query per hour */ | ||
| usec_t mdns_calculate_next_query_delay(usec_t current_delay) { | ||
| assert(current_delay <= (3600 * USEC_PER_SEC)); |
There was a problem hiding this comment.
No need to wrap the multiplication in parens.
There was a problem hiding this comment.
Removed the multiplication that was inside the parentheses
| "Failed to match answer key with " | ||
| "service browser's key: %m"); |
| if (r < 0) { | ||
| log_error_errno(r, | ||
| "Failed to match answer key with service " | ||
| "browser's key: %m"); | ||
| return; | ||
| } |
There was a problem hiding this comment.
if (r < 0)
return (void) log_error_errno(r, …);and below too.
|
|
||
| sb = dns_service_browser_ref(userdata); | ||
| if (!sb) | ||
| return log_error_errno(0, "Failed to reference service browser: %m"); |
There was a problem hiding this comment.
0 is not a valid value, it'd cause an assertion failure.
assert_se(sb = dns_service_browser_ref(userdata));Prepare for upcoming mDNS browse services. Distinguish between registered and discovered services to avoid confusion. Co-authored-by: Vishwanath Chandapur <[email protected]>
Prepare for mDNS browse services to facilitate scheduled cache maintenance queries when browsing for services. Introduce dns_answer_add_full() and dns_answer_add_extend_full() to explicitly handle the 'until' argument, enabling fine-grained control over the time property of DNS answers. Ensure backward compatibility while providing the flexibility to specify 'until' for specific cases when needed Co-authored-by: Vishwanath Chandapur <[email protected]>
Prepare for upcoming mDNS browse services. Prevent continuous queries from being attempted thrice. Co-authored-by: Vishwanath Chandapur <[email protected]>
| case DNS_RECORD_TTL_STATE_100_PERCENT: | ||
| return 100; | ||
| default: | ||
| return -1; |
There was a problem hiding this comment.
maybe return -EINVAL here, that would be more in-line with our usual schemes.
(doesn't matter, but I would probably have implemented this via a table, i.e.
static const int ttl_percent_table[_DNS_RECORD_TTL_STATE_MAX] = {
[DNS_RECORD_TTL_STATE_80_PERCENT] = 80,
…
};
return ttl_percent_table[ttl_state];you get the idea. but doesn't really matter, the switch is fine too, and i have the suspicion, that good compilers generate the same code from both these days
There was a problem hiding this comment.
Done, Converted the switch cases into a table and added returning -EINVAL.
| assert(percent > 0); | ||
|
|
||
| return usec_sub_unsigned(until, (100 - percent) * ttl * USEC_PER_SEC / 100); | ||
| } |
There was a problem hiding this comment.
hmm, is this function used outside of this .c file? if so please do not export it. (same for all other funcs defind here). i.e. add static wherever you can.
There was a problem hiding this comment.
We added a few unit tests to verify these timings. Hence, we removed the static, now we have added it back.
We will try to find another way to unit test later.
|
|
||
| r = dns_answer_match_key(query->answer, sb->key, NULL); | ||
| if (r < 0) | ||
| return (void) log_error_errno(r, "mDNS answer does not match service browser key: %m"); |
There was a problem hiding this comment.
hmm, this error conditoin, how can this ever happen? if this is impossible, it should be an assert(). If it can happen but is nothing too concerning and we can go on, then it should be a warning level thing, and it should be saying ", ignoring" at the end of the msg. Or if it can happen and means the query has to fail, then we need to do more than just error log at error level, and somehow fail the query. or, in the case this actually is ok this way it deserves a comment, why it is.
There was a problem hiding this comment.
This logic is redundant and has been removed.
Allow for mDNS service/domain/types browsing. A client can connect to the backend via varlink and receive updates as the requested service becomes available. The interval between the first two queries MUST be at least one second, the intervals between successive queries MUST increase by at least a factor of two. When the interval between queries reaches or exceeds 60 minutes, a querier MAY cap the interval to a maximum of 60 minutes, and perform subsequent queries at a steady-state rate of one query per hour. Delete expired cache entries one second after goodbye packet received as per RFC6762 Section 10.1 Cache maintenance: The querier should plan to issue a query at 80% of the record lifetime, and then if no answer is received, at 85%, 90%, and 95%. If an answer is received, then the remaining TTL is reset to the value given in the answer, and this process repeats for as long as the Multicast DNS querier has an ongoing interest in the record. If no answer is received after four queries, the record is deleted when it reaches 100% of its lifetime. TODO: Improve the DNS transaction logic when multiple clients subscribe to the same service, ensuring that continuous queries are optimized. Co-authored-by: Vishwanath Chandapur <[email protected]>
|
|
||
| systemctl unmask systemd-resolved.service systemd-networkd.{service,socket} systemd-machined.service | ||
| systemctl enable --now systemd-resolved.service systemd-networkd.{socket,service} systemd-machined.service | ||
| ln -svrf /run/systemd/resolved.conf.d/99-mdns-llmnr.conf /etc/resolv.conf |
There was a problem hiding this comment.
I don't understand this here. /etc/resolv.conf is a completely different format than the ini .conf files used by systemd. This line effectively just disables resolv.conf.
There was a problem hiding this comment.
Since the tests are very specific to mDNS, want to make sure the global mDNS is ON
There was a problem hiding this comment.
/etc/resolv.conf uses a format like this:
nameserver 127.0.0.53
options edns0 trust-ad
search home
but /run/systemd/resolved.conf and /run/systemd/resolved.conf.d/99-mdns-llmnr.conf are ini files with a [Resolve] section and key=value settings. Those formats are incompatible.
commented
Jul 17, 2025
|
OK, I think we should merge this. I looked at the test, and there's one confused file and a few style tweaks needed, but otherwise it seems to make sense. @poettering, since you reviewed this in the past, good to go? |
Co-authored-by: Frantisek Sumsal <[email protected]> Co-authored-by: Vishwanath Chandapur <[email protected]>
commented
Jul 18, 2025
|
Thank you for your patience ;) |
Allow for mDNS service/domain/types browsing.
A client can connect to the backend via varlink and receive updates as the requested service becomes available.
The interval between the first two queries MUST be at least one second, the intervals between successive queries MUST increase by at least a factor of two.
When the interval between queries reaches or exceeds 60 minutes, a querier MAY cap the interval to a maximum of 60 minutes, and perform subsequent queries at a steady-state rate of one query per hour.
Cache maintenance performed by issuing queries at 80, 85, 90, 95% of the TTL, and updating/removing the records depending on replies.
TODO:
Improve the DNS transaction logic when multiple clients subscribe to the same service, ensuring that continuous queries are optimized.