Skip to content

resolved: add "static RRs" concept#41213

Open
poettering wants to merge 6 commits intosystemd:mainfrom
poettering:resolved-static-rrs
Open

resolved: add "static RRs" concept#41213
poettering wants to merge 6 commits intosystemd:mainfrom
poettering:resolved-static-rrs

Conversation

@poettering
Copy link
Member

split out of #40980

@keszybz
Copy link
Member

keszybz commented Mar 20, 2026

Please see the comments in #40980 (review).

@keszybz keszybz added reviewed/needs-rework 🔨 PR has been reviewed and needs another round of reworks and removed please-review PR is ready for (re-)review by a maintainer labels Mar 20, 2026
let's ensure the name is actually a valid DNS name.
This only parses a small subset of RR types for now, but we can add more
later.

Covered are the most important RR types: A, AAAA, PTR.
When we are told to reload our configuration also flush out /etc/hosts
explicitly. This is particularly relevant since we suppress too frequent
reloads, and hence a synchronous way to force a reload is very useful.
This is an extension of the /etc/hosts concept, but can provide any kind
of RRs (well, actually, we only parse A/AAAA/PTR for now, but the
concept is open for more).

Fixes: systemd#17791
@poettering poettering force-pushed the resolved-static-rrs branch from c80680e to f868062 Compare March 20, 2026 15:08
@poettering
Copy link
Member Author

I addressed all earlier claude and human reviews now. ptal

@poettering poettering added please-review PR is ready for (re-)review by a maintainer claude-review and removed reviewed/needs-rework 🔨 PR has been reviewed and needs another round of reworks labels Mar 20, 2026
@github-actions
Copy link

github-actions bot commented Mar 20, 2026

Claude review of PR #41213 (f868062)

<!-- claude-pr-review -->

Must fix

  • IPv4 string dispatch test checks wrong variablesrc/test/test-json.c:1708 — The string-based dispatch test dispatches to &dummy but asserts on data.addr.s_addr (which still holds the value from the earlier test). Should check dummy.s_addr instead.
  • IPv6 string dispatch test checks wrong variablesrc/test/test-json.c:1824 — Same issue: dispatches to &dummy but asserts on data.addr.s6_addr instead of dummy.s6_addr.
  • Missing resolved.conf.xml docs for ReadStaticRecords=src/resolve/resolved-gperf.gperf:34 — The new config option is registered in gperf and conf.in but has no <varlistentry> in man/resolved.conf.xml. Every other Resolve.* option has a man page entry.

Suggestions

  • Static records vs /etc/hosts precedence undocumentedsrc/resolve/resolved-dns-query.c:1069 — Static records are checked before /etc/hosts in query resolution. This priority isn't documented in the systemd.rr(5) man page and could surprise users.
  • Man page missing /usr/local/lib/ pathman/systemd.rr.xml:31 — The synopsis lists /etc/, /run/, /usr/lib/ paths but omits /usr/local/lib/systemd/resolve/static.d/*.rr. The code uses CONF_PATHS_NULSTR() which includes it, and other man pages (e.g. resolved.conf.xml) consistently list all four paths.

Nits

  • Missing assert(stats) in load_static_record_filesrc/resolve/resolved-static-records.c:82 — The function asserts cf and records but not stats, which is also required non-NULL.
  • See Also missing resolved.conf(5)man/systemd.rr.xml:86 — The ReadStaticRecords= option to enable/disable this feature lives in resolved.conf(5), but it's not referenced.
  • Log message uses raw type numbersrc/shared/dns-rr.c:2612 — The "Decoding DNS type %i" message could include the symbolic name via dns_type_to_string() for easier debugging.

Workflow run

},
/* flags= */ 0,
&dummy));
ASSERT_EQ(be32toh(data.addr.s_addr), 0xC0A80101U);

Choose a reason for hiding this comment

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

Claude: must-fix: This assertion checks data.addr.s_addr, but the string dispatch above writes to &dummy (at offset 0). Since data.addr still holds 0xC0A80101U from the earlier array-based test, this assertion always passes regardless of whether string dispatch works correctly.

Should be:

ASSERT_EQ(be32toh(dummy.s_addr), 0xC0A80101U);

/* flags= */ 0,
&dummy));

ASSERT_EQ(data.addr.s6_addr[15], 1);

Choose a reason for hiding this comment

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

Claude: must-fix: Same issue as the IPv4 test: the string dispatch writes to &dummy, but these assertions check data.addr.s6_addr (which still holds ::1 from the earlier array-based test). The string dispatch result in dummy is never verified.

Should be:

ASSERT_EQ(dummy.s6_addr[15], 1);
for (size_t i = 0; i < 15; i++)
        ASSERT_EQ(dummy.s6_addr[i], 0);

Resolve.Cache, config_parse_dns_cache_mode, DNS_CACHE_MODE_YES, offsetof(Manager, enable_cache)
Resolve.DNSStubListener, config_parse_dns_stub_listener_mode, 0, offsetof(Manager, dns_stub_listener_mode)
Resolve.ReadEtcHosts, config_parse_bool, 0, offsetof(Manager, read_etc_hosts)
Resolve.ReadStaticRecords, config_parse_bool, 0, offsetof(Manager, read_static_records)

Choose a reason for hiding this comment

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

Claude: must-fix: The new Resolve.ReadStaticRecords= configuration option is registered here and in resolved.conf.in, but there is no corresponding <varlistentry> documentation in man/resolved.conf.xml. Every other Resolve.* option (e.g., ReadEtcHosts=) has a man page entry describing its behavior and default value.

q->state != DNS_TRANSACTION_NULL)
return 0;

r = dns_query_try_static_records(q);

Choose a reason for hiding this comment

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

Claude: suggestion: Static records are checked before /etc/hosts in the query resolution order, meaning .rr drop-in files silently take priority over /etc/hosts entries for the same name. This seems intentional, but the systemd.rr(5) man page doesn't mention this precedence relationship. A brief note in the Description section (and/or a comment here analogous to the one above dns_query_try_etc_hosts) would help users understand the resolution order.

<member><filename>/run/systemd/resolve/static.d/*.rr</filename></member>
<member><filename>/usr/lib/systemd/resolve/static.d/*.rr</filename></member>
</simplelist></para>
</refsynopsisdiv>

Choose a reason for hiding this comment

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

Claude: suggestion: The synopsis lists /etc/, /run/, and /usr/lib/ paths but omits /usr/local/lib/systemd/resolve/static.d/*.rr. The code uses CONF_PATHS_NULSTR() which includes /usr/local/lib/ as well. Other systemd man pages (e.g., resolved.conf.xml) consistently list all four paths.


assert(cf);
assert(records);

Choose a reason for hiding this comment

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

Claude: nit: Missing assert(stats) -- the function asserts cf and records but not the stats double-pointer parameter, which is dereferenced unconditionally on the next line.

<title>See Also</title>
<para><simplelist type="inline">
<member><citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry></member>
<member><citerefentry><refentrytitle>systemd-resolved.service</refentrytitle><manvolnum>8</manvolnum></citerefentry></member>

Choose a reason for hiding this comment

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

Claude: nit: The See Also section references systemd-resolved.service(8) and hosts(5) but does not reference resolved.conf(5), which is where the ReadStaticRecords= option to enable/disable this feature lives.

*ret = TAKE_PTR(rr);
return 0;
}

Choose a reason for hiding this comment

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

Claude: nit: The log message "Decoding DNS type %i is currently not supported." outputs just the raw numeric type. Consider including the symbolic name via dns_type_to_string() for easier debugging, similar to the pattern in resolvectl.c which uses both the name and number.

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

Development

Successfully merging this pull request may close these issues.

2 participants