summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2021-11-26 19:57:51 +0900
committerYu Watanabe <watanabe.yu+github@gmail.com>2021-11-26 20:20:06 +0900
commitb707e43d33b9cd2b00ba30945b05868cda6674d2 (patch)
tree626807596020141e76cb8be012c01bce2eeafc08
parent46c31852f19f0ed9fd191d9ee9f6ddcea3426870 (diff)
downloadsystemd-b707e43d33b9cd2b00ba30945b05868cda6674d2.tar.gz
network: json: append DNS misc settings
-rw-r--r--src/network/networkd-json.c107
1 files changed, 107 insertions, 0 deletions
diff --git a/src/network/networkd-json.c b/src/network/networkd-json.c
index 315d06a091..894badd6f9 100644
--- a/src/network/networkd-json.c
+++ b/src/network/networkd-json.c
@@ -1054,6 +1054,103 @@ finalize:
return r;
}
+static int dns_misc_build_json(Link *link, JsonVariant **ret) {
+ JsonVariant **elements = NULL;
+ ResolveSupport resolve_support;
+ NetworkConfigSource source;
+ DnsOverTlsMode mode;
+ size_t n = 0;
+ int t, r;
+
+ assert(link);
+ assert(ret);
+
+ if (!link->network) {
+ *ret = NULL;
+ return 0;
+ }
+
+ resolve_support = link->llmnr >= 0 ? link->llmnr : link->network->llmnr;
+ if (resolve_support >= 0) {
+ source = link->llmnr >= 0 ? NETWORK_CONFIG_SOURCE_RUNTIME : NETWORK_CONFIG_SOURCE_STATIC;
+
+ if (!GREEDY_REALLOC(elements, n + 1)) {
+ r = -ENOMEM;
+ goto finalize;
+ }
+
+ r = json_build(elements + n, JSON_BUILD_OBJECT(
+ JSON_BUILD_PAIR_STRING("LLMNR", resolve_support_to_string(resolve_support)),
+ JSON_BUILD_PAIR_STRING("ConfigSource", network_config_source_to_string(source))));
+ if (r < 0)
+ goto finalize;
+
+ n++;
+ }
+
+ resolve_support = link->mdns >= 0 ? link->mdns : link->network->mdns;
+ if (resolve_support >= 0) {
+ source = link->mdns >= 0 ? NETWORK_CONFIG_SOURCE_RUNTIME : NETWORK_CONFIG_SOURCE_STATIC;
+
+ if (!GREEDY_REALLOC(elements, n + 1)) {
+ r = -ENOMEM;
+ goto finalize;
+ }
+
+ r = json_build(elements + n, JSON_BUILD_OBJECT(
+ JSON_BUILD_PAIR_STRING("MDNS", resolve_support_to_string(resolve_support)),
+ JSON_BUILD_PAIR_STRING("ConfigSource", network_config_source_to_string(source))));
+ if (r < 0)
+ goto finalize;
+
+ n++;
+ }
+
+ t = link->dns_default_route >= 0 ? link->dns_default_route : link->network->dns_default_route;
+ if (t >= 0) {
+ source = link->dns_default_route >= 0 ? NETWORK_CONFIG_SOURCE_RUNTIME : NETWORK_CONFIG_SOURCE_STATIC;
+
+ if (!GREEDY_REALLOC(elements, n + 1)) {
+ r = -ENOMEM;
+ goto finalize;
+ }
+
+ r = json_build(elements + n, JSON_BUILD_OBJECT(
+ JSON_BUILD_PAIR_BOOLEAN("DNSDefaultRoute", t),
+ JSON_BUILD_PAIR_STRING("ConfigSource", network_config_source_to_string(source))));
+ if (r < 0)
+ goto finalize;
+
+ n++;
+ }
+
+ mode = link->dns_over_tls_mode >= 0 ? link->dns_over_tls_mode : link->network->dns_over_tls_mode;
+ if (mode >= 0) {
+ source = link->dns_over_tls_mode >= 0 ? NETWORK_CONFIG_SOURCE_RUNTIME : NETWORK_CONFIG_SOURCE_STATIC;
+
+ if (!GREEDY_REALLOC(elements, n + 1)) {
+ r = -ENOMEM;
+ goto finalize;
+ }
+
+ r = json_build(elements + n, JSON_BUILD_OBJECT(
+ JSON_BUILD_PAIR_STRING("DNSOverTLS", dns_over_tls_mode_to_string(mode)),
+ JSON_BUILD_PAIR_STRING("ConfigSource", network_config_source_to_string(source))));
+ if (r < 0)
+ goto finalize;
+
+ n++;
+ }
+
+ r = json_build(ret, JSON_BUILD_OBJECT(JSON_BUILD_PAIR("DNSSettings",
+ JSON_BUILD_VARIANT_ARRAY(elements, n))));
+
+finalize:
+ json_variant_unref_many(elements, n);
+ free(elements);
+ return r;
+}
+
int link_build_json(Link *link, JsonVariant **ret) {
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL, *w = NULL;
_cleanup_free_ char *type = NULL, *flags = NULL;
@@ -1189,6 +1286,16 @@ int link_build_json(Link *link, JsonVariant **ret) {
w = json_variant_unref(w);
+ r = dns_misc_build_json(link, &w);
+ if (r < 0)
+ return r;
+
+ r = json_variant_merge(&v, w);
+ if (r < 0)
+ return r;
+
+ w = json_variant_unref(w);
+
r = addresses_build_json(link->addresses, &w);
if (r < 0)
return r;