Repository navigation
resolvectl: use more varlink - #41840
Conversation
| 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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
|
test placeholder |
b4024a5 to
5054161
Compare
| 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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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.
1f06172 to
b4f7917
Compare
|
LGTM. But please address the suggestions by Claude (or comment something if a suggestion is ignored). |
b4f7917 to
de2f438
Compare
@yuwata Thanks! I addressed Claude's most recent suggestions, and left comments on the ones I chose not to address. |
|
lgtm |
The punctuation is not strictly important for the error.
Re-factor using the shared code introduced for resolvectl.
|
Okay, hopefully claude is happy now. |
There are already varlink methods for
ResolveHostname,ResolveAddress, andResolveRecord. Use those inresolvectlinstead of the dbus equivalents.