summaryrefslogtreecommitdiffstats
path: root/src/network/networkd-json.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/network/networkd-json.c')
-rw-r--r--src/network/networkd-json.c115
1 files changed, 115 insertions, 0 deletions
diff --git a/src/network/networkd-json.c b/src/network/networkd-json.c
index 452df9a17f..7ccf653f74 100644
--- a/src/network/networkd-json.c
+++ b/src/network/networkd-json.c
@@ -503,6 +503,117 @@ static int dns_append_json(Link *link, sd_json_variant **v) {
return json_variant_set_field_non_null(v, "DNS", array);
}
+static int dnr_append_json_one(Link *link, const struct sd_dns_resolver *res, NetworkConfigSource s, const union in_addr_union *p, sd_json_variant **array) {
+ _cleanup_(sd_json_variant_unrefp) sd_json_variant *addrs_array = NULL;
+ _cleanup_strv_free_ char **transports = NULL;
+ int r;
+
+ assert(link);
+ assert(res);
+ assert(array);
+
+ FOREACH_ARRAY(addr, res->addrs, res->n_addrs) {
+ r = sd_json_variant_append_arrayb(
+ &addrs_array,
+ JSON_BUILD_IN_ADDR(addr, res->family));
+ if (r < 0)
+ return r;
+ }
+
+ r = dns_resolver_transports_to_strv(res->transports, &transports);
+ if (r < 0)
+ return r;
+
+ //FIXME ifindex?
+ return sd_json_variant_append_arrayb(
+ array,
+ SD_JSON_BUILD_OBJECT(
+ SD_JSON_BUILD_PAIR_INTEGER("Family", res->family),
+ SD_JSON_BUILD_PAIR_INTEGER("Priority", res->priority),
+ JSON_BUILD_PAIR_VARIANT_NON_NULL("Addresses", addrs_array),
+ JSON_BUILD_PAIR_UNSIGNED_NON_ZERO("Port", res->port),
+ JSON_BUILD_PAIR_STRING_NON_EMPTY("ServerName", res->auth_name),
+ JSON_BUILD_PAIR_STRING_NON_EMPTY("DoHPath", res->dohpath),
+ JSON_BUILD_PAIR_STRV_NON_EMPTY("Transports", transports),
+ SD_JSON_BUILD_PAIR_STRING("ConfigSource", network_config_source_to_string(s)),
+ JSON_BUILD_PAIR_IN_ADDR_NON_NULL("ConfigProvider", p, res->family)));
+}
+
+static int dnr_append_json(Link *link, sd_json_variant **v) {
+ _cleanup_(sd_json_variant_unrefp) sd_json_variant *array = NULL;
+ int r;
+
+ assert(link);
+ assert(v);
+
+ if (!link->network)
+ return 0;
+
+ if (link->dhcp_lease && link_get_use_dnr(link, NETWORK_CONFIG_SOURCE_DHCP4)) {
+ struct sd_dns_resolver *dnr;
+ union in_addr_union s;
+ int n_dnr;
+
+ r = sd_dhcp_lease_get_server_identifier(link->dhcp_lease, &s.in);
+ if (r < 0)
+ return r;
+
+ n_dnr = sd_dhcp_lease_get_dnr(link->dhcp_lease, &dnr);
+ if (n_dnr < 0)
+ return 0;
+
+ FOREACH_ARRAY(res, dnr, n_dnr) {
+ r = dnr_append_json_one(link,
+ res,
+ NETWORK_CONFIG_SOURCE_DHCP4,
+ &s,
+ &array);
+ if (r < 0)
+ return r;
+ }
+ }
+
+ if (link->dhcp6_lease && link_get_use_dnr(link, NETWORK_CONFIG_SOURCE_DHCP6)) {
+ struct sd_dns_resolver *dnr;
+ union in_addr_union s;
+ int n_dnr;
+
+ r = sd_dhcp6_lease_get_server_address(link->dhcp6_lease, &s.in6);
+ if (r < 0)
+ return r;
+
+ n_dnr = sd_dhcp6_lease_get_dnr(link->dhcp6_lease, &dnr);
+ if (n_dnr < 0)
+ return 0;
+
+ FOREACH_ARRAY(res, dnr, n_dnr) {
+ r = dnr_append_json_one(link,
+ res,
+ NETWORK_CONFIG_SOURCE_DHCP6,
+ &s,
+ &array);
+ if (r < 0)
+ return r;
+ }
+ }
+
+ if (link_get_use_dnr(link, NETWORK_CONFIG_SOURCE_NDISC)) {
+ NDiscDNR *a;
+
+ SET_FOREACH(a, link->ndisc_dnr) {
+ r = dnr_append_json_one(link,
+ &a->resolver,
+ NETWORK_CONFIG_SOURCE_NDISC,
+ &(union in_addr_union) { .in6 = a->router },
+ &array);
+ if (r < 0)
+ return r;
+ }
+ }
+
+ return json_variant_set_field_non_null(v, "DNR", array);
+}
+
static int server_append_json_one_addr(int family, const union in_addr_union *a, NetworkConfigSource s, const union in_addr_union *p, sd_json_variant **array) {
assert(IN_SET(family, AF_INET, AF_INET6));
assert(a);
@@ -1268,6 +1379,10 @@ int link_build_json(Link *link, sd_json_variant **ret) {
if (r < 0)
return r;
+ r = dnr_append_json(link, &v);
+ if (r < 0)
+ return r;
+
r = ntp_append_json(link, &v);
if (r < 0)
return r;