]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
dns-rr: when decoding an RR from json, make class optional
authorLennart Poettering <lennart@poettering.net>
Fri, 10 Oct 2025 13:34:42 +0000 (15:34 +0200)
committerLennart Poettering <lennart@poettering.net>
Mon, 20 Oct 2025 08:35:23 +0000 (10:35 +0200)
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.

src/shared/dns-rr.c
src/shared/varlink-io.systemd.Resolve.c

index c86714a6076fb283798b5d5978efd3455b8cbe69..796000291436be7d416933f1d4de1ef066c66802 100644 (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);
index 12c43d33f0f17bf5c30d1c362fb6a6347edb937e..80835aef4f61d17458191c0255a40bf22b2ce918 100644 (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."),