]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
resolve: add delegate info to DNSConfiguration
authorNick Rosbrook <enr0n@ubuntu.com>
Fri, 10 Oct 2025 19:56:33 +0000 (15:56 -0400)
committerNick Rosbrook <enr0n@ubuntu.com>
Thu, 6 Nov 2025 10:17:58 +0000 (05:17 -0500)
This is one of several commits to expand the DNSConfiguration varlink
type to include the necessary information for resolvectl status output.

src/resolve/resolved-manager.c
src/shared/varlink-io.systemd.Resolve.Monitor.c

index ba9402e926348b987c8970727eddb3ae985898a8..d88102ac83304d1a9946ca59e682726f3c935d90 100644 (file)
@@ -2043,6 +2043,7 @@ void dns_manager_reset_statistics(Manager *m) {
 static int dns_configuration_json_append(
                 const char *ifname,
                 int ifindex,
+                const char *delegate,
                 int default_route,
                 DnsServer *current_dns_server,
                 DnsServer *dns_servers,
@@ -2106,7 +2107,10 @@ static int dns_configuration_json_append(
                         configuration,
                         JSON_BUILD_PAIR_STRING_NON_EMPTY("ifname", ifname),
                         SD_JSON_BUILD_PAIR_CONDITION(ifindex > 0, "ifindex", SD_JSON_BUILD_UNSIGNED(ifindex)),
-                        SD_JSON_BUILD_PAIR_CONDITION(ifindex > 0, "defaultRoute", SD_JSON_BUILD_BOOLEAN(default_route > 0)),
+                        JSON_BUILD_PAIR_STRING_NON_EMPTY("delegate", delegate),
+                        JSON_BUILD_PAIR_CONDITION_BOOLEAN(ifindex > 0 || !!delegate,
+                                                          "defaultRoute",
+                                                          default_route > 0),
                         JSON_BUILD_PAIR_VARIANT_NON_NULL("currentServer", current_dns_server_json),
                         JSON_BUILD_PAIR_VARIANT_NON_NULL("servers", dns_servers_json),
                         JSON_BUILD_PAIR_VARIANT_NON_NULL("searchDomains", search_domains_json));
@@ -2119,6 +2123,7 @@ static int global_dns_configuration_json_append(Manager *m, sd_json_variant **co
         return dns_configuration_json_append(
                         /* ifname = */ NULL,
                         /* ifindex = */ 0,
+                        /* delegate = */ NULL,
                         /* default_route = */ 0,
                         manager_get_dns_server(m),
                         m->dns_servers,
@@ -2133,6 +2138,7 @@ static int link_dns_configuration_json_append(Link *l, sd_json_variant **configu
         return dns_configuration_json_append(
                         l->ifname,
                         l->ifindex,
+                        /* delegate = */ NULL,
                         link_get_default_route(l),
                         link_get_dns_server(l),
                         l->dns_servers,
@@ -2140,9 +2146,25 @@ static int link_dns_configuration_json_append(Link *l, sd_json_variant **configu
                         configuration);
 }
 
+static int delegate_dns_configuration_json_append(DnsDelegate *d, sd_json_variant **configuration) {
+        assert(d);
+        assert(configuration);
+
+        return dns_configuration_json_append(
+                        /* ifname = */ NULL,
+                        /* ifindex = */ 0,
+                        d->id,
+                        d->default_route,
+                        dns_delegate_get_dns_server(d),
+                        d->dns_servers,
+                        d->search_domains,
+                        configuration);
+}
+
 int manager_dump_dns_configuration_json(Manager *m, sd_json_variant **ret) {
         _cleanup_(sd_json_variant_unrefp) sd_json_variant *configuration = NULL;
         Link *l;
+        DnsDelegate *d;
         int r;
 
         assert(m);
@@ -2160,6 +2182,13 @@ int manager_dump_dns_configuration_json(Manager *m, sd_json_variant **ret) {
                         return r;
         }
 
+        /* Append configuration for each delegate */
+        HASHMAP_FOREACH(d, m->delegates) {
+                r = delegate_dns_configuration_json_append(d, &configuration);
+                if (r < 0)
+                        return r;
+        }
+
         return sd_json_buildo(ret, SD_JSON_BUILD_PAIR_VARIANT("configuration", configuration));
 }
 
index 2861368a45fc04f06cba65f9555a8f672a3ceefb..d78ea7bb9725577c6c05feda8a9bd69e57e5639d 100644 (file)
@@ -144,6 +144,8 @@ static SD_VARLINK_DEFINE_STRUCT_TYPE(
                 SD_VARLINK_DEFINE_FIELD(ifname, SD_VARLINK_STRING, SD_VARLINK_NULLABLE),
                 SD_VARLINK_FIELD_COMMENT("Interface index, if any, associated with this configuration. Empty for global configuration."),
                 SD_VARLINK_DEFINE_FIELD(ifindex, SD_VARLINK_INT, SD_VARLINK_NULLABLE),
+                SD_VARLINK_FIELD_COMMENT("Delegate name, if any, associated with this configuration. Empty for global or link configurations."),
+                SD_VARLINK_DEFINE_FIELD(delegate, SD_VARLINK_STRING, SD_VARLINK_NULLABLE),
                 SD_VARLINK_FIELD_COMMENT("Indicates whether or not this link's DNS servers will be used for resolving domain names that do not match any link's configured domains."),
                 SD_VARLINK_DEFINE_FIELD(defaultRoute, SD_VARLINK_BOOL, SD_VARLINK_NULLABLE),
                 SD_VARLINK_FIELD_COMMENT("DNS server currently selected to use for lookups."),