dns-rr: when decoding an RR from json, make class optional

The DNS RR class is a weird thing, and IRL always set to IN (i.e. 0x1).
Let's hence make it something that can be specified optionally, and
imply IN if not specified.

This makes it a bit nicer to put together suitable json resource record
keys from the command line.
This commit is contained in:
Lennart Poettering
2025-10-10 15:34:42 +02:00
parent 5751b236a5
commit 970bedb6d8
2 changed files with 6 additions and 4 deletions

View File

@@ -2205,14 +2205,16 @@ int dns_resource_key_from_json(sd_json_variant *v, DnsResourceKey **ret) {
};
static const sd_json_dispatch_field dispatch_table[] = {
{ "class", _SD_JSON_VARIANT_TYPE_INVALID, sd_json_dispatch_uint16, offsetof(struct params, class), SD_JSON_MANDATORY },
{ "class", _SD_JSON_VARIANT_TYPE_INVALID, sd_json_dispatch_uint16, offsetof(struct params, class), 0 },
{ "type", _SD_JSON_VARIANT_TYPE_INVALID, sd_json_dispatch_uint16, offsetof(struct params, type), SD_JSON_MANDATORY },
{ "name", SD_JSON_VARIANT_STRING, sd_json_dispatch_const_string, offsetof(struct params, name), SD_JSON_MANDATORY },
{}
};
_cleanup_(dns_resource_key_unrefp) DnsResourceKey *key = NULL;
struct params p;
struct params p = {
.class = DNS_CLASS_IN,
};
int r;
assert(v);

View File

@@ -4,8 +4,8 @@
SD_VARLINK_DEFINE_STRUCT_TYPE(
ResourceKey,
SD_VARLINK_FIELD_COMMENT("The RR class, almost always IN, i.e 0x01."),
SD_VARLINK_DEFINE_FIELD(class, SD_VARLINK_INT, 0),
SD_VARLINK_FIELD_COMMENT("The RR class, almost always IN, i.e 0x01. If unspecified defaults to IN."),
SD_VARLINK_DEFINE_FIELD(class, SD_VARLINK_INT, SD_VARLINK_NULLABLE),
SD_VARLINK_FIELD_COMMENT("The RR types, one of A, AAAA, PTR, …"),
SD_VARLINK_DEFINE_FIELD(type, SD_VARLINK_INT, 0),
SD_VARLINK_FIELD_COMMENT("The domain name."),