diff --git a/src/core/devices/wifi/nm-wifi-utils.c b/src/core/devices/wifi/nm-wifi-utils.c index 8a8d062f3a..332352ab06 100644 --- a/src/core/devices/wifi/nm-wifi-utils.c +++ b/src/core/devices/wifi/nm-wifi-utils.c @@ -1577,19 +1577,17 @@ ip_config_to_iwd_config(int addr_family, GKeyFile *file, NMSettingIPConfig *s_ip if (num) { nm_str_buf_reset(&strbuf); for (i = 0; i < num; i++) { - char sbuf[NM_INET_ADDRSTRLEN]; - NMIPAddr a; + char addrstr[NM_INET_ADDRSTRLEN]; - if (!nm_utils_dnsname_parse_assert(addr_family, - nm_setting_ip_config_get_dns(s_ip, i), - NULL, - &a, - NULL)) + if (!nm_dns_uri_parse_plain(addr_family, + nm_setting_ip_config_get_dns(s_ip, i), + addrstr, + NULL)) continue; if (strbuf.len > 0) nm_str_buf_append_c(&strbuf, ' '); - nm_str_buf_append(&strbuf, nm_inet_ntop(addr_family, &a, sbuf)); + nm_str_buf_append(&strbuf, addrstr); } /* It doesn't matter whether we add the DNS under [IPv4] or [IPv6] * except that with method=auto the list will override the diff --git a/src/core/dns/nm-dns-dnsmasq.c b/src/core/dns/nm-dns-dnsmasq.c index c0983afcdf..8e3c10c98c 100644 --- a/src/core/dns/nm-dns-dnsmasq.c +++ b/src/core/dns/nm-dns-dnsmasq.c @@ -884,7 +884,7 @@ add_ip_config(NMDnsDnsmasq *self, GVariantBuilder *servers, const NMDnsConfigIPD for (i = 0; i < num; i++) { NMIPAddr a; - if (!nm_utils_dnsname_parse_assert(ip_data->addr_family, strarr[i], NULL, &a, NULL)) + if (!nm_dns_uri_parse_plain(ip_data->addr_family, strarr[i], NULL, &a)) continue; ip_addr_to_string(ip_data->addr_family, &a, iface, ip_addr_to_string_buf); diff --git a/src/core/dns/nm-dns-manager.c b/src/core/dns/nm-dns-manager.c index 0fd3439490..704d030bbe 100644 --- a/src/core/dns/nm-dns-manager.c +++ b/src/core/dns/nm-dns-manager.c @@ -600,7 +600,7 @@ merge_one_l3cd(NMResolvConfData *rc, int addr_family, int ifindex, const NML3Con for (i = 0; i < num_nameservers; i++) { NMIPAddr a; - if (!nm_utils_dnsname_parse_assert(addr_family, strarr[i], NULL, &a, NULL)) + if (!nm_dns_uri_parse_plain(addr_family, strarr[i], NULL, &a)) continue; if (addr_family == AF_INET) @@ -1307,7 +1307,6 @@ merge_global_dns_config(NMResolvConfData *rc, NMGlobalDnsConfig *global_conf) static const char * get_nameserver_list(int addr_family, const NML3ConfigData *l3cd, NMStrBuf *tmp_strbuf) { - char buf[NM_INET_ADDRSTRLEN]; guint num; guint i; const char *const *strarr; @@ -1316,15 +1315,9 @@ get_nameserver_list(int addr_family, const NML3ConfigData *l3cd, NMStrBuf *tmp_s strarr = nm_l3_config_data_get_nameservers(l3cd, addr_family, &num); for (i = 0; i < num; i++) { - NMIPAddr a; - - if (!nm_utils_dnsname_parse_assert(addr_family, strarr[i], NULL, &a, NULL)) - continue; - - nm_inet_ntop(addr_family, &a, buf); if (i > 0) nm_str_buf_append_c(tmp_strbuf, ' '); - nm_str_buf_append(tmp_strbuf, buf); + nm_str_buf_append(tmp_strbuf, strarr[i]); } nm_str_buf_maybe_expand(tmp_strbuf, 1, FALSE); @@ -2737,7 +2730,6 @@ _get_config_variant(NMDnsManager *self) guint num_domains; guint num_searches; guint i; - char buf[NM_INET_ADDRSTRLEN]; const char *ifname; const char *const *strarr; @@ -2749,12 +2741,7 @@ _get_config_variant(NMDnsManager *self) g_variant_builder_init(&strv_builder, G_VARIANT_TYPE("as")); for (i = 0; i < num; i++) { - NMIPAddr a; - - if (!nm_utils_dnsname_parse_assert(ip_data->addr_family, strarr[i], NULL, &a, NULL)) - continue; - - g_variant_builder_add(&strv_builder, "s", nm_inet_ntop(ip_data->addr_family, &a, buf)); + g_variant_builder_add(&strv_builder, "s", strarr[i]); } g_variant_builder_add(&entry_builder, "{sv}", diff --git a/src/core/dns/nm-dns-systemd-resolved.c b/src/core/dns/nm-dns-systemd-resolved.c index 49c1094de5..0701a1dcb5 100644 --- a/src/core/dns/nm-dns-systemd-resolved.c +++ b/src/core/dns/nm-dns-systemd-resolved.c @@ -396,13 +396,24 @@ update_add_ip_config(NMDnsSystemdResolved *self, strarr = nm_l3_config_data_get_nameservers(ip_data->l3cd, ip_data->addr_family, &n); for (i = 0; i < n; i++) { - const char *server_name; - NMIPAddr a; + NMDnsServer dns_server; - if (!nm_utils_dnsname_parse_assert(ip_data->addr_family, strarr[i], NULL, &a, &server_name)) + if (!nm_dns_uri_parse(ip_data->addr_family, strarr[i], &dns_server)) continue; - if (server_name) { + if (!NM_IN_SET(dns_server.scheme, + NM_DNS_URI_SCHEME_TLS, + NM_DNS_URI_SCHEME_NONE, + NM_DNS_URI_SCHEME_UDP)) { + /* In systemd-resolved, the use of DNS-over-TLS can't be controlled + * for each name server; it is controlled via a per-link knob. + * Therefore, we pass all the addresses we know about and then let + * systemd-resolved decide whether to use DoT, based on the + * "connection.dns-over-tls" property. */ + continue; + } + + if (dns_server.servername) { NM_SET_OUT(out_require_dns_ex, TRUE); if (priv->has_set_link_dns_ex == FALSE) { /* The caller won't care about this result anymore. We can skip setting it. */ @@ -413,15 +424,19 @@ update_add_ip_config(NMDnsSystemdResolved *self, if (dns_ex) { g_variant_builder_open(dns_ex, G_VARIANT_TYPE("(iayqs)")); g_variant_builder_add(dns_ex, "i", ip_data->addr_family); - g_variant_builder_add_value(dns_ex, nm_g_variant_new_ay((gconstpointer) &a, addr_size)); + g_variant_builder_add_value( + dns_ex, + nm_g_variant_new_ay((gconstpointer) &dns_server.addr, addr_size)); g_variant_builder_add(dns_ex, "q", 0); - g_variant_builder_add(dns_ex, "s", server_name ?: ""); + g_variant_builder_add(dns_ex, "s", dns_server.servername ?: ""); g_variant_builder_close(dns_ex); } if (dns) { g_variant_builder_open(dns, G_VARIANT_TYPE("(iay)")); g_variant_builder_add(dns, "i", ip_data->addr_family); - g_variant_builder_add_value(dns, nm_g_variant_new_ay((gconstpointer) &a, addr_size)); + g_variant_builder_add_value( + dns, + nm_g_variant_new_ay((gconstpointer) &dns_server.addr, addr_size)); g_variant_builder_close(dns); } has_config = TRUE; diff --git a/src/core/dnsmasq/nm-dnsmasq-manager.c b/src/core/dnsmasq/nm-dnsmasq-manager.c index 3566b62480..030a8e28e1 100644 --- a/src/core/dnsmasq/nm-dnsmasq-manager.c +++ b/src/core/dnsmasq/nm-dnsmasq-manager.c @@ -102,7 +102,6 @@ create_dm_cmd_line(const char *iface, char first[INET_ADDRSTRLEN]; char last[INET_ADDRSTRLEN]; char listen_address_s[INET_ADDRSTRLEN]; - char sbuf_addr[INET_ADDRSTRLEN]; gs_free char *error_desc = NULL; const char *dm_binary; const NMPlatformIP4Address *listen_address; @@ -191,13 +190,13 @@ create_dm_cmd_line(const char *iface, nm_gstring_prepare(&s); g_string_append(s, "--dhcp-option=option:dns-server"); for (i = 0; i < n; i++) { - in_addr_t a; + char addrstr[NM_INET_ADDRSTRLEN]; - if (!nm_utils_dnsname_parse_assert(AF_INET, strarr[i], NULL, &a, NULL)) + if (!nm_dns_uri_parse_plain(AF_INET, strarr[i], addrstr, NULL)) continue; g_string_append_c(s, ','); - g_string_append(s, nm_inet4_ntop(a, sbuf_addr)); + g_string_append(s, addrstr); } nm_strv_ptrarray_take_gstring(cmd, &s); } diff --git a/src/core/ndisc/nm-ndisc.c b/src/core/ndisc/nm-ndisc.c index acbd36c4dc..962058d66d 100644 --- a/src/core/ndisc/nm-ndisc.c +++ b/src/core/ndisc/nm-ndisc.c @@ -1103,14 +1103,14 @@ nm_ndisc_set_config(NMNDisc *ndisc, const NML3ConfigData *l3cd) if (l3cd) strvarr = nm_l3_config_data_get_nameservers(l3cd, AF_INET6, &len); for (i = 0; i < len; i++) { - struct in6_addr a; + NMIPAddr a; NMNDiscDNSServer n; - if (!nm_utils_dnsname_parse_assert(AF_INET6, strvarr[i], NULL, &a, NULL)) + if (!nm_dns_uri_parse_plain(AF_INET6, strvarr[i], NULL, &a)) continue; n = (NMNDiscDNSServer) { - .address = a, + .address = a.addr6, .expiry_msec = _nm_ndisc_lifetime_to_expiry(NM_NDISC_EXPIRY_BASE_TIMESTAMP, NM_NDISC_ROUTER_LIFETIME), }; diff --git a/src/core/nm-dispatcher.c b/src/core/nm-dispatcher.c index 4f442c685a..0abbca73a4 100644 --- a/src/core/nm-dispatcher.c +++ b/src/core/nm-dispatcher.c @@ -255,7 +255,7 @@ dump_ip_to_props(const NML3ConfigData *l3cd, int addr_family, GVariantBuilder *b for (i = 0; i < n; i++) { NMIPAddr a; - if (!nm_utils_dnsname_parse_assert(addr_family, strarr[i], NULL, &a, NULL)) + if (!nm_dns_uri_parse_plain(addr_family, strarr[i], NULL, &a)) continue; if (IS_IPv4) diff --git a/src/core/nm-ip-config.c b/src/core/nm-ip-config.c index 8cd27ac4f7..eb0ec9aa03 100644 --- a/src/core/nm-ip-config.c +++ b/src/core/nm-ip-config.c @@ -449,22 +449,27 @@ get_property_ip4(GObject *object, guint prop_id, GValue *value, GParamSpec *pspe else g_variant_builder_init(&builder, G_VARIANT_TYPE("aa{sv}")); for (i = 0; i < len; i++) { - in_addr_t a; + NMIPAddr a; - if (!nm_utils_dnsname_parse_assert(AF_INET, strarr[i], NULL, &a, NULL)) - continue; - - if (prop_id == PROP_IP4_NAMESERVERS) + if (prop_id == PROP_IP4_NAMESERVERS) { + if (!nm_dns_uri_parse_plain(AF_INET, strarr[i], NULL, &a)) + continue; g_variant_builder_add(&builder, "u", a); - else { + } else { GVariantBuilder nested_builder; + char addrstr[NM_INET_ADDRSTRLEN]; - nm_inet4_ntop(a, addr_str); g_variant_builder_init(&nested_builder, G_VARIANT_TYPE("a{sv}")); + if (nm_dns_uri_parse_plain(AF_INET, strarr[i], addrstr, NULL)) { + g_variant_builder_add(&nested_builder, + "{sv}", + "address", + g_variant_new_string(addrstr)); + } g_variant_builder_add(&nested_builder, "{sv}", - "address", - g_variant_new_string(addr_str)); + "uri", + g_variant_new_string(strarr[i])); g_variant_builder_add(&builder, "a{sv}", &nested_builder); } } @@ -692,12 +697,13 @@ get_property_ip6(GObject *object, guint prop_id, GValue *value, GParamSpec *pspe else { g_variant_builder_init(&builder, G_VARIANT_TYPE("aay")); for (i = 0; i < len; i++) { - struct in6_addr a; + NMIPAddr a; - if (!nm_utils_dnsname_parse_assert(AF_INET6, strarr[i], NULL, &a, NULL)) + /* TODO: expose the full URI as well */ + if (!nm_dns_uri_parse_plain(AF_INET6, strarr[i], NULL, &a)) continue; - g_variant_builder_add(&builder, "@ay", nm_g_variant_new_ay_in6addr(&a)); + g_variant_builder_add(&builder, "@ay", nm_g_variant_new_ay_in6addr(&a.addr6)); } g_value_take_variant(value, g_variant_builder_end(&builder)); } diff --git a/src/core/nm-l3-config-data.c b/src/core/nm-l3-config-data.c index 7afac1d7d6..70867ff70e 100644 --- a/src/core/nm-l3-config-data.c +++ b/src/core/nm-l3-config-data.c @@ -1460,8 +1460,7 @@ nm_l3_config_data_add_nameserver(NML3ConfigData *self, int addr_family, const ch if (NM_MORE_ASSERTS > 5) { gs_free char *s_free = NULL; - nm_assert( - nm_streq0(nm_utils_dnsname_normalize(addr_family, nameserver, &s_free), nameserver)); + nm_assert(nm_streq0(nm_dns_uri_normalize(addr_family, nameserver, &s_free), nameserver)); } p_arr = &self->nameservers_x[NM_IS_IPv4(addr_family)]; diff --git a/src/core/nm-l3cfg.c b/src/core/nm-l3cfg.c index 48a50a5998..c7ab976187 100644 --- a/src/core/nm-l3cfg.c +++ b/src/core/nm-l3cfg.c @@ -3938,10 +3938,10 @@ _l3cfg_routed_dns(NML3Cfg *self, NML3ConfigData *l3cd) NMPlatformIPXRoute route_new; char addr_buf[INET6_ADDRSTRLEN]; char route_buf[128]; - NMIPAddr addr; + NMDnsServer dns; int r; - if (!nm_utils_dnsname_parse_assert(addr_family, nameservers[i], NULL, &addr, NULL)) + if (!nm_dns_uri_parse(addr_family, nameservers[i], &dns)) continue; /* Find the gateway to the DNS over the current interface. When @@ -3950,13 +3950,13 @@ _l3cfg_routed_dns(NML3Cfg *self, NML3ConfigData *l3cd) * the table containing DNS routes. */ r = nm_platform_ip_route_get(self->priv.platform, addr_family, - &addr, + &dns.addr, DNS_ROUTES_FWMARK_TABLE_PRIO, self->priv.ifindex, &obj); if (r < 0) { _LOGT("could not get route to DNS %s", - nm_inet_ntop(addr_family, addr.addr_ptr, addr_buf)); + nm_inet_ntop(addr_family, dns.addr.addr_ptr, addr_buf)); continue; } @@ -3964,7 +3964,7 @@ _l3cfg_routed_dns(NML3Cfg *self, NML3ConfigData *l3cd) if (IS_IPv4) { route_new.r4 = (NMPlatformIP4Route) { - .network = addr.addr4, + .network = dns.addr.addr4, .plen = 32, .table_any = FALSE, .metric_any = TRUE, @@ -3976,7 +3976,7 @@ _l3cfg_routed_dns(NML3Cfg *self, NML3ConfigData *l3cd) nm_platform_ip_route_normalize(addr_family, &route_new.rx); _LOGT("route to %s: %s", - nm_inet4_ntop(addr.addr4, addr_buf), + nm_inet4_ntop(dns.addr.addr4, addr_buf), nm_platform_ip4_route_to_string(&route_new.r4, route_buf, sizeof(route_buf))); nm_l3_config_data_add_route_4(l3cd, &route_new.r4); @@ -3987,7 +3987,7 @@ _l3cfg_routed_dns(NML3Cfg *self, NML3ConfigData *l3cd) route_added = TRUE; } else { route_new.r6 = (NMPlatformIP6Route) { - .network = addr.addr6, + .network = dns.addr.addr6, .plen = 128, .table_any = FALSE, .metric_any = TRUE, @@ -3999,7 +3999,7 @@ _l3cfg_routed_dns(NML3Cfg *self, NML3ConfigData *l3cd) nm_platform_ip_route_normalize(addr_family, &route_new.rx); _LOGT("route to %s: %s", - nm_inet6_ntop(&addr.addr6, addr_buf), + nm_inet6_ntop(&dns.addr.addr6, addr_buf), nm_platform_ip6_route_to_string(&route_new.r6, route_buf, sizeof(route_buf))); nm_l3_config_data_add_route_6(l3cd, &route_new.r6); diff --git a/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c b/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c index 81964de6c3..d64052cbde 100644 --- a/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c +++ b/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c @@ -2056,9 +2056,8 @@ make_ip4_setting(shvarFile *ifcfg, * Pick up just IPv4 addresses (IPv6 addresses are taken by make_ip6_setting()) */ for (i = 1; i < 10000; i++) { - int af; - NMIPAddr ip; - char tag[256]; + NMDnsServer dns; + char tag[256]; numbered_tag(tag, "DNS", i); nm_clear_g_free(&value); @@ -2066,14 +2065,16 @@ make_ip4_setting(shvarFile *ifcfg, if (!v) break; - if (!nm_utils_dnsname_parse(AF_UNSPEC, v, &af, &ip, NULL)) { + if (!nm_dns_uri_parse(AF_UNSPEC, v, &dns)) { g_set_error(error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Invalid DNS server address '%s'", v); return NULL; - } else if (af == AF_INET) { + } + + if (dns.addr_family == AF_INET) { if (!nm_setting_ip_config_add_dns(s_ip4, v)) PARSE_WARNING("duplicate DNS server %s", tag); } else { @@ -2606,9 +2607,8 @@ make_ip6_setting(shvarFile *ifcfg, shvarFile *network_ifcfg, gboolean routes_rea * Pick up just IPv6 addresses (IPv4 addresses are taken by make_ip4_setting()) */ for (i = 1; i < 10000; i++) { - int af; - NMIPAddr ip; - char tag[256]; + NMDnsServer dns; + char tag[256]; numbered_tag(tag, "DNS", i); nm_clear_g_free(&value); @@ -2616,7 +2616,7 @@ make_ip6_setting(shvarFile *ifcfg, shvarFile *network_ifcfg, gboolean routes_rea if (!v) break; - if (!nm_utils_dnsname_parse(AF_UNSPEC, v, &af, &ip, NULL)) { + if (!nm_dns_uri_parse(AF_UNSPEC, v, &dns)) { if (is_disabled) continue; g_set_error(error, @@ -2625,7 +2625,8 @@ make_ip6_setting(shvarFile *ifcfg, shvarFile *network_ifcfg, gboolean routes_rea "Invalid DNS server address '%s'", v); return NULL; - } else if (af == AF_INET6) { + } + if (dns.addr_family == AF_INET6) { if (is_disabled) { PARSE_WARNING("ignore DNS server addresses with method disabled/ignore"); break; diff --git a/src/libnm-client-impl/nm-ip-config.c b/src/libnm-client-impl/nm-ip-config.c index c054f2ccd6..ad5f08f814 100644 --- a/src/libnm-client-impl/nm-ip-config.c +++ b/src/libnm-client-impl/nm-ip-config.c @@ -166,25 +166,32 @@ _notify_update_prop_nameservers(NMClient *client, g_variant_iter_init(&iter, value); while (g_variant_iter_next(&iter, "a{sv}", &iter_v)) { - const char *key; - GVariant *val; + const char *key; + GVariant *val; + gs_free char *nameserver = NULL; while (g_variant_iter_next(iter_v, "{&sv}", &key, &val)) { - if (nm_streq(key, "address")) { + if (nm_streq(key, "address") && !nameserver) { gs_free char *val_str = NULL; if (!g_variant_is_of_type(val, G_VARIANT_TYPE_STRING)) goto next; if (!nm_inet_parse_str(AF_INET, g_variant_get_string(val, NULL), &val_str)) goto next; - if (!arr) - arr = g_ptr_array_new(); - g_ptr_array_add(arr, g_steal_pointer(&val_str)); - goto next; + nameserver = g_steal_pointer(&val_str); + } else if (nm_streq(key, "uri")) { + nameserver = g_variant_dup_string(val, NULL); } next: g_variant_unref(val); } + + if (nameserver) { + if (!arr) + arr = g_ptr_array_new(); + g_ptr_array_add(arr, g_steal_pointer(&nameserver)); + } + g_variant_iter_free(iter_v); } if (arr && arr->len > 0) diff --git a/src/libnm-core-impl/nm-keyfile.c b/src/libnm-core-impl/nm-keyfile.c index 3292142fdb..69b49fa0b7 100644 --- a/src/libnm-core-impl/nm-keyfile.c +++ b/src/libnm-core-impl/nm-keyfile.c @@ -1157,7 +1157,7 @@ ip_dns_parser(KeyfileReaderInfo *info, NMSetting *setting, const char *key) addr_family = NM_SETTING_IP_CONFIG_GET_ADDR_FAMILY(setting); for (i = 0, n = 0; i < length; i++) { - if (!nm_utils_dnsname_parse(addr_family, list[i], NULL, NULL, NULL)) { + if (!nm_dns_uri_parse(addr_family, list[i], NULL)) { if (!read_handle_warn(info, key, key, diff --git a/src/libnm-core-impl/nm-setting-ip-config.c b/src/libnm-core-impl/nm-setting-ip-config.c index 86fd1c953f..1ec97029a0 100644 --- a/src/libnm-core-impl/nm-setting-ip-config.c +++ b/src/libnm-core-impl/nm-setting-ip-config.c @@ -4095,7 +4095,7 @@ _ip_config_add_dns(NMSettingIPConfig *setting, const char *dns) priv = NM_SETTING_IP_CONFIG_GET_PRIVATE(setting); - s = nm_utils_dnsname_normalize(NM_SETTING_IP_CONFIG_GET_ADDR_FAMILY(setting), dns, &s_free); + s = nm_dns_uri_normalize(NM_SETTING_IP_CONFIG_GET_ADDR_FAMILY(setting), dns, &s_free); if (!s) s = dns; @@ -4186,7 +4186,7 @@ nm_setting_ip_config_remove_dns_by_value(NMSettingIPConfig *setting, const char gs_free char *s_free = NULL; const char *s; - s = nm_utils_dnsname_normalize(NM_SETTING_IP_CONFIG_GET_ADDR_FAMILY(setting), dns, &s_free); + s = nm_dns_uri_normalize(NM_SETTING_IP_CONFIG_GET_ADDR_FAMILY(setting), dns, &s_free); if (s && !nm_streq(dns, s)) idx = nm_strv_ptrarray_find_first(priv->dns, dns); } @@ -5615,11 +5615,7 @@ verify(NMSetting *setting, NMConnection *connection, GError **error) for (i = 0; i < priv->dns->len; i++) { const char *dns = priv->dns->pdata[i]; - if (!nm_utils_dnsname_parse(NM_SETTING_IP_CONFIG_GET_ADDR_FAMILY(setting), - dns, - NULL, - NULL, - NULL)) { + if (!nm_dns_uri_parse(NM_SETTING_IP_CONFIG_GET_ADDR_FAMILY(setting), dns, NULL)) { g_set_error(error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_INVALID_PROPERTY, @@ -6510,11 +6506,16 @@ nm_setting_ip_config_class_init(NMSettingIPConfigClass *klass) /** * NMSettingIPConfig:dns: * - * Array of IP addresses of DNS servers. + * Array of DNS servers. * - * For DoT (DNS over TLS), the SNI server name can be specified by appending - * "#example.com" to the IP address of the DNS server. This currently only has - * effect when using systemd-resolved. + * Each server can be specified either as a plain IP address (optionally followed + * by a "#" and the SNI server name for DNS over TLS) or with a URI syntax. + * + * When it is specified as an URI, the following forms are supported: + * dns+udp://ADDRESS[:PORT], dns+tls://ADDRESS[:PORT][#SERVERNAME] . + * + * When using the URI syntax, IPv6 addresses must be enclosed in square + * brackets ('[', ']'). **/ obj_properties[PROP_DNS] = g_param_spec_boxed(NM_SETTING_IP_CONFIG_DNS, diff --git a/src/libnm-core-impl/nm-utils.c b/src/libnm-core-impl/nm-utils.c index d5c683eef4..13ff0a5bef 100644 --- a/src/libnm-core-impl/nm-utils.c +++ b/src/libnm-core-impl/nm-utils.c @@ -1309,11 +1309,11 @@ nm_utils_dns_to_variant(int addr_family, const char *const *dns, gssize len) /* We can only represent the IP address on the legacy property "ipv[46].dns". * Expose what we can. */ - if (!nm_utils_dnsname_parse(addr_family, dns[i], NULL, &ip, NULL)) + if (!nm_dns_uri_parse_plain(addr_family, dns[i], NULL, &ip)) continue; if (IS_IPv4) - g_variant_builder_add(&builder, "u", ip); + g_variant_builder_add(&builder, "u", ip.addr4); else g_variant_builder_add(&builder, "@ay", nm_g_variant_new_ay_in6addr(&ip.addr6)); } diff --git a/src/libnmc-setting/settings-docs.h.in b/src/libnmc-setting/settings-docs.h.in index 25c4d0abfa..dd719afad6 100644 --- a/src/libnmc-setting/settings-docs.h.in +++ b/src/libnmc-setting/settings-docs.h.in @@ -196,7 +196,7 @@ #define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DHCP_SEND_RELEASE N_("Whether the DHCP client will send RELEASE message when bringing the connection down. The default value is \"default\" (-1). When the default value is specified, then the global value from NetworkManager configuration is looked up, if not set, it is considered as FALSE.") #define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DHCP_TIMEOUT N_("A timeout for a DHCP transaction in seconds. If zero (the default), a globally configured default is used. If still unspecified, a device specific timeout is used (usually 45 seconds). Set to 2147483647 (MAXINT32) for infinity.") #define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DHCP_VENDOR_CLASS_IDENTIFIER N_("The Vendor Class Identifier DHCP option (60). Special characters in the data string may be escaped using C-style escapes, nevertheless this property cannot contain nul bytes. If the per-profile value is unspecified (the default), a global connection default gets consulted. If still unspecified, the DHCP option is not sent to the server.") -#define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DNS N_("Array of IP addresses of DNS servers. For DoT (DNS over TLS), the SNI server name can be specified by appending \"#example.com\" to the IP address of the DNS server. This currently only has effect when using systemd-resolved.") +#define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DNS N_("Array of DNS servers. Each server can be specified either as a plain IP address (optionally followed by a \"#\" and the SNI server name for DNS over TLS) or with a URI syntax. When it is specified as an URI, the following forms are supported: dns+udp://ADDRESS[:PORT], dns+tls://ADDRESS[:PORT][SERVERNAME] . When using the URI syntax, IPv6 addresses must be enclosed in square brackets ('[', ']').") #define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DNS_OPTIONS N_("DNS options for /etc/resolv.conf as described in resolv.conf(5) manual. The currently supported options are \"attempts\", \"debug\", \"edns0\", \"ndots\", \"no-aaaa\", \"no-check-names\", \"no-reload\", \"no-tld-query\", \"rotate\", \"single-request\", \"single-request-reopen\", \"timeout\", \"trust-ad\", \"use-vc\". See the resolv.conf(5) manual. Note that there is a distinction between an unset (default) list and an empty list. In nmcli, to unset the list set the value to \"\". To set an empty list, set it to \" \". Currently, an unset list has the same meaning as an empty list. That might change in the future. The \"trust-ad\" setting is only honored if the profile contributes name servers to resolv.conf, and if all contributing profiles have \"trust-ad\" enabled. When using a caching DNS plugin (dnsmasq or systemd-resolved in NetworkManager.conf) then \"edns0\" and \"trust-ad\" are automatically added. The valid \"ipv4.dns-options\" and \"ipv6.dns-options\" get merged together.") #define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DNS_PRIORITY N_("DNS servers priority. The relative priority for DNS servers specified by this setting. A lower numerical value is better (higher priority). Negative values have the special effect of excluding other configurations with a greater numerical priority value; so in presence of at least one negative priority, only DNS servers from connections with the lowest priority value will be used. To avoid all DNS leaks, set the priority of the profile that should be used to the most negative value of all active connections profiles. Zero selects a globally configured default value. If the latter is missing or zero too, it defaults to 50 for VPNs (including WireGuard) and 100 for other connections. Note that the priority is to order DNS settings for multiple active connections. It does not disambiguate multiple DNS servers within the same connection profile. When multiple devices have configurations with the same priority, VPNs will be considered first, then devices with the best (lowest metric) default route and then all other devices. When using dns=default, servers with higher priority will be on top of resolv.conf. To prioritize a given server over another one within the same connection, just specify them in the desired order. Note that commonly the resolver tries name servers in /etc/resolv.conf in the order listed, proceeding with the next server in the list on failure. See for example the \"rotate\" option of the dns-options setting. If there are any negative DNS priorities, then only name servers from the devices with that lowest priority will be considered. When using a DNS resolver that supports Conditional Forwarding or Split DNS (with dns=dnsmasq or dns=systemd-resolved settings), each connection is used to query domains in its search list. The search domains determine which name servers to ask, and the DNS priority is used to prioritize name servers based on the domain. Queries for domains not present in any search list are routed through connections having the '~.' special wildcard domain, which is added automatically to connections with the default route (or can be added manually). When multiple connections specify the same domain, the one with the best priority (lowest numerical value) wins. If a sub domain is configured on another interface it will be accepted regardless the priority, unless parent domain on the other interface has a negative priority, which causes the sub domain to be shadowed. With Split DNS one can avoid undesired DNS leaks by properly configuring DNS priorities and the search domains, so that only name servers of the desired interface are configured.") #define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DNS_SEARCH N_("List of DNS search domains. Domains starting with a tilde ('~') are considered 'routing' domains and are used only to decide the interface over which a query must be forwarded; they are not used to complete unqualified host names. When using a DNS plugin that supports Conditional Forwarding or Split DNS, then the search domains specify which name servers to query. This makes the behavior different from running with plain /etc/resolv.conf. For more information see also the dns-priority setting. When set on a profile that also enabled DHCP, the DNS search list received automatically (option 119 for DHCPv4 and option 24 for DHCPv6) gets merged with the manual list. This can be prevented by setting \"ignore-auto-dns\". Note that if no DNS searches are configured, the fallback will be derived from the domain from DHCP (option 15).") @@ -231,7 +231,7 @@ #define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_DHCP_SEND_HOSTNAME_V2 N_("If TRUE, a hostname is sent to the DHCP server when acquiring a lease. Some DHCP servers use this hostname to update DNS databases, essentially providing a static hostname for the computer. If the dhcp-hostname property is NULL and this property is TRUE, the current persistent hostname of the computer is sent. The default value is default (-1). In this case the global value from NetworkManager configuration is looked up. If it's not set, the value from dhcp-send-hostname-deprecated, which defaults to TRUE, is used for backwards compatibility. In the future this will change and, in absence of a global default, it will always fallback to TRUE.") #define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_DHCP_SEND_RELEASE N_("Whether the DHCP client will send RELEASE message when bringing the connection down. The default value is \"default\" (-1). When the default value is specified, then the global value from NetworkManager configuration is looked up, if not set, it is considered as FALSE.") #define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_DHCP_TIMEOUT N_("A timeout for a DHCP transaction in seconds. If zero (the default), a globally configured default is used. If still unspecified, a device specific timeout is used (usually 45 seconds). Set to 2147483647 (MAXINT32) for infinity.") -#define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_DNS N_("Array of IP addresses of DNS servers. For DoT (DNS over TLS), the SNI server name can be specified by appending \"#example.com\" to the IP address of the DNS server. This currently only has effect when using systemd-resolved.") +#define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_DNS N_("Array of DNS servers. Each server can be specified either as a plain IP address (optionally followed by a \"#\" and the SNI server name for DNS over TLS) or with a URI syntax. When it is specified as an URI, the following forms are supported: dns+udp://ADDRESS[:PORT], dns+tls://ADDRESS[:PORT][SERVERNAME] . When using the URI syntax, IPv6 addresses must be enclosed in square brackets ('[', ']').") #define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_DNS_OPTIONS N_("DNS options for /etc/resolv.conf as described in resolv.conf(5) manual. The currently supported options are \"attempts\", \"debug\", \"edns0\", \"ndots\", \"no-aaaa\", \"no-check-names\", \"no-reload\", \"no-tld-query\", \"rotate\", \"single-request\", \"single-request-reopen\", \"timeout\", \"trust-ad\", \"use-vc\" and \"inet6\", \"ip6-bytestring\", \"ip6-dotint\", \"no-ip6-dotint\". See the resolv.conf(5) manual. Note that there is a distinction between an unset (default) list and an empty list. In nmcli, to unset the list set the value to \"\". To set an empty list, set it to \" \". Currently, an unset list has the same meaning as an empty list. That might change in the future. The \"trust-ad\" setting is only honored if the profile contributes name servers to resolv.conf, and if all contributing profiles have \"trust-ad\" enabled. When using a caching DNS plugin (dnsmasq or systemd-resolved in NetworkManager.conf) then \"edns0\" and \"trust-ad\" are automatically added. The valid \"ipv4.dns-options\" and \"ipv6.dns-options\" get merged together.") #define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_DNS_PRIORITY N_("DNS servers priority. The relative priority for DNS servers specified by this setting. A lower numerical value is better (higher priority). Negative values have the special effect of excluding other configurations with a greater numerical priority value; so in presence of at least one negative priority, only DNS servers from connections with the lowest priority value will be used. To avoid all DNS leaks, set the priority of the profile that should be used to the most negative value of all active connections profiles. Zero selects a globally configured default value. If the latter is missing or zero too, it defaults to 50 for VPNs (including WireGuard) and 100 for other connections. Note that the priority is to order DNS settings for multiple active connections. It does not disambiguate multiple DNS servers within the same connection profile. When multiple devices have configurations with the same priority, VPNs will be considered first, then devices with the best (lowest metric) default route and then all other devices. When using dns=default, servers with higher priority will be on top of resolv.conf. To prioritize a given server over another one within the same connection, just specify them in the desired order. Note that commonly the resolver tries name servers in /etc/resolv.conf in the order listed, proceeding with the next server in the list on failure. See for example the \"rotate\" option of the dns-options setting. If there are any negative DNS priorities, then only name servers from the devices with that lowest priority will be considered. When using a DNS resolver that supports Conditional Forwarding or Split DNS (with dns=dnsmasq or dns=systemd-resolved settings), each connection is used to query domains in its search list. The search domains determine which name servers to ask, and the DNS priority is used to prioritize name servers based on the domain. Queries for domains not present in any search list are routed through connections having the '~.' special wildcard domain, which is added automatically to connections with the default route (or can be added manually). When multiple connections specify the same domain, the one with the best priority (lowest numerical value) wins. If a sub domain is configured on another interface it will be accepted regardless the priority, unless parent domain on the other interface has a negative priority, which causes the sub domain to be shadowed. With Split DNS one can avoid undesired DNS leaks by properly configuring DNS priorities and the search domains, so that only name servers of the desired interface are configured.") #define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_DNS_SEARCH N_("List of DNS search domains. Domains starting with a tilde ('~') are considered 'routing' domains and are used only to decide the interface over which a query must be forwarded; they are not used to complete unqualified host names. When using a DNS plugin that supports Conditional Forwarding or Split DNS, then the search domains specify which name servers to query. This makes the behavior different from running with plain /etc/resolv.conf. For more information see also the dns-priority setting. When set on a profile that also enabled DHCP, the DNS search list received automatically (option 119 for DHCPv4 and option 24 for DHCPv6) gets merged with the manual list. This can be prevented by setting \"ignore-auto-dns\". Note that if no DNS searches are configured, the fallback will be derived from the domain from DHCP (option 15).") diff --git a/src/nmcli/gen-metadata-nm-settings-nmcli.xml.in b/src/nmcli/gen-metadata-nm-settings-nmcli.xml.in index 6004b110ac..9aa1751e7e 100644 --- a/src/nmcli/gen-metadata-nm-settings-nmcli.xml.in +++ b/src/nmcli/gen-metadata-nm-settings-nmcli.xml.in @@ -1325,7 +1325,7 @@ format="string" values="auto, link-local, manual, shared, disabled" />