Skip to content

resolvectl: use more varlink - #41840

Merged
yuwata merged 9 commits into
systemd:mainfrom
enr0n:resolvectl-varlink
Jun 27, 2026
Merged

yuwata merged 9 commits into
systemd:mainfrom
enr0n:resolvectl-varlink

Conversation

@enr0n

@enr0n enr0n commented Apr 27, 2026

Copy link
Copy Markdown
Member

There are already varlink methods for ResolveHostname, ResolveAddress, and ResolveRecord. Use those in resolvectl instead of the dbus equivalents.

@github-actions github-actions Bot added resolve please-review PR is ready for (re-)review by a maintainer labels Apr 27, 2026
Comment thread src/resolve/resolvectl.c Outdated
static int resolve_host_error(const char *name, int r, const sd_bus_error *error) {
if (sd_bus_error_has_name(error, BUS_ERROR_DNS_NXDOMAIN))
return log_error_errno(r, "%s: %s", name, bus_error_message(error, r));
static int varlink_resolve_check_error(const char *error_id, sd_json_variant *reply, char **ret_errstr) {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

One difference this PR creates is the error message output. E.g.:

$ resolvectl query --type=A example.invalid
example.invalid: resolve call failed: NXDOMAIN

vs.

$ resolvectl query --type=A example.invalid
example.invalid: resolve call failed: Name 'example.invalid' not found

because the string in the latter example is set in the dbus reply directly, whereas the varlink code just gives error ID, and maybe rcode. I am wondering if the varlink code should just set the same "human readable" error strings in another field on error.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think showing the low-level string NXDOMAIN too would make sense, this is a relatively low-level tool after all, and NXDOMAIN a relatively well-known concept. otherwsie the new msg looks good to me

@bluca bluca added ci-fails/needs-rework 🔥 Please rework this, the CI noticed an issue with the PR claude-review and removed please-review PR is ready for (re-)review by a maintainer labels Apr 28, 2026
@github-actions

github-actions Bot commented Apr 28, 2026 •

Copy link
Copy Markdown

test placeholder

Workflow run

Comment thread src/resolve/resolvectl.c Resolved
Comment thread src/resolve/resolvectl.c Resolved
Comment thread src/resolve/resolvectl.c Resolved
Comment thread src/resolve/resolvectl.c Resolved
Comment thread src/resolve/resolvectl.c Resolved
Comment thread src/resolve/resolvectl.c Resolved
Comment thread src/resolve/resolvectl.c Resolved
Comment thread src/resolve/resolvectl.c Resolved
Comment thread src/resolve/resolvectl.c Resolved
Comment thread src/resolve/resolvectl.c Resolved
Comment thread src/resolve/resolvectl.c Resolved
@enr0n
enr0n force-pushed the resolvectl-varlink branch from b4024a5 to 5054161 Compare April 28, 2026 20:33
@github-actions github-actions Bot added network util-lib please-review PR is ready for (re-)review by a maintainer and removed ci-fails/needs-rework 🔥 Please rework this, the CI noticed an issue with the PR labels Apr 28, 2026
Comment thread src/resolve/resolvectl.c Resolved
Comment thread src/resolve/resolvectl.c Resolved
Comment thread src/resolve/resolvectl.c Resolved
@bluca bluca added ci-fails/needs-rework 🔥 Please rework this, the CI noticed an issue with the PR and removed please-review PR is ready for (re-)review by a maintainer labels Apr 29, 2026
@enr0n
enr0n force-pushed the resolvectl-varlink branch from 5054161 to 6a9ab04 Compare May 1, 2026 19:37
@github-actions github-actions Bot removed the ci-fails/needs-rework 🔥 Please rework this, the CI noticed an issue with the PR label May 1, 2026
@github-actions github-actions Bot added please-review PR is ready for (re-)review by a maintainer and removed reviewed/needs-rework 🔨 PR has been reviewed and needs another round of reworks labels Jun 25, 2026
Comment thread src/shared/resolve-varlink-util.c Resolved
Comment thread src/resolve/resolvectl.c
bool needs_authentication = false;
FOREACH_ARRAY(record, reply.records, reply.n_records) {
_cleanup_(dns_resource_record_unrefp) DnsResourceRecord *rr = NULL;
r = dns_resource_record_new_from_raw(&rr, record->raw.iov_base, record->raw.iov_len);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Claude: suggestion: dns_resource_record_new_from_raw() is now called unconditionally for every record before the arg_raw == RAW_PACKET branch, and a parse failure aborts the whole query via log_error_errno(). The old code dumped the raw wire bytes verbatim in RAW_PACKET mode without parsing (only the non-RAW_PACKET path parsed, and dns_type_needs_authentication() used the type read straight from the wire message). With this change a single unparseable record makes resolvectl --raw=packet fail instead of emitting the raw packet, a behavior regression. Consider parsing lazily: skip the parse in RAW_PACKET mode and only parse when the RR is actually needed for formatted output / authentication tracking.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

If the parsing fails, presumably the packet is invalid somehow, so it seems fine not to output. I would also expect callers of this to assume failure when this returns a non-zero exit code anyways.

Comment thread src/nss-resolve/nss-resolve.c Resolved
enr0n added 3 commits June 26, 2026 09:12
There are several places where address family is dispatched from JSON,
so take json_dispatch_address_family from networkd and put it in
json-util.c.

Update the all instances in the tree to use this new function, adding
SD_JSON_RELAX to the dispatch flags if AF_UNSPEC should be allowed
in that case.
Generalize json_dispatch_address from nss-resolve, and add support for
strings to be compatible with the existing json_dispatch_{in,in6}_addr
helpers. This will be used in a later commit.
This is preparation for using varlink methods more in resolvectl. In
particular, this is helpful for proving more accurate error messages,
and maintaining compatibility with existing error messages from the
DBus API.
@enr0n
enr0n force-pushed the resolvectl-varlink branch from 1f06172 to b4f7917 Compare June 26, 2026 13:15
Comment thread src/shared/resolve-varlink-util.c Resolved
Comment thread src/shared/resolve-varlink-util.c Resolved
Comment thread src/resolve/resolvectl.c Resolved
@yuwata

yuwata commented Jun 26, 2026

Copy link
Copy Markdown
Member

LGTM. But please address the suggestions by Claude (or comment something if a suggestion is ignored).

@enr0n
enr0n force-pushed the resolvectl-varlink branch from b4f7917 to de2f438 Compare June 26, 2026 14:44
@enr0n

enr0n commented Jun 26, 2026

Copy link
Copy Markdown
Member Author

LGTM. But please address the suggestions by Claude (or comment something if a suggestion is ignored).

@yuwata Thanks! I addressed Claude's most recent suggestions, and left comments on the ones I chose not to address.

@yuwata yuwata added good-to-merge/waiting-for-ci 👍 PR is good to merge, but CI hasn't passed at time of review. Please merge if you see CI has passed and removed please-review PR is ready for (re-)review by a maintainer labels Jun 26, 2026
@poettering

Copy link
Copy Markdown
Member

lgtm

Comment thread src/resolve/resolvectl.c Resolved
Comment thread src/shared/resolve-varlink-util.h Resolved
@yuwata yuwata removed the good-to-merge/waiting-for-ci 👍 PR is good to merge, but CI hasn't passed at time of review. Please merge if you see CI has passed label Jun 26, 2026
@enr0n

enr0n commented Jun 26, 2026

Copy link
Copy Markdown
Member Author

Okay, hopefully claude is happy now.

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.

7 participants