mirror of
https://github.com/morgan9e/systemd
synced 2026-04-14 08:25:20 +09:00
resolve: add delegate info to DNSConfiguration
This is one of several commits to expand the DNSConfiguration varlink type to include the necessary information for resolvectl status output.
This commit is contained in:
@@ -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));
|
||||
}
|
||||
|
||||
|
||||
@@ -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."),
|
||||
|
||||
Reference in New Issue
Block a user