libnm: add "dns-data" replacement for "ipv[46].dns" properties on D-Bus

On D-Bus, the properties "ipv[46].dns" are of type "au" and "aay",
respectively.

Btw, in particular "au" is bad, because we put there a big-endian
number. There is no D-Bus type to represent big endian numbers, so "u"
is bad because it can cause endianess problem when trying to remote
the D-Bus communication to another host (without explicitly
understanding which "u" properties need to swap for endinness).

Anyway. The plain addresses are not enough. We soon will also support
the DNS-over-TLS server name, or maybe a DoT port number. The previous
property was not extensible, so deprecate it and replace it by
"dns-data".

This one is just a list of strings. That is unlike "address-data" or
"route-data", which do a similar thing but are "a{sv}" dictionaries.
Here a string is supposed to be sufficient also for the future. Also,
because in nmcli and keyfile will will simply have a string format for
representing the extra data, not a structure (unlike for routes or
addresses).
This commit is contained in:
Thomas Haller
2022-10-21 14:50:32 +02:00
parent 3297b079b2
commit 63eaf168d1
3 changed files with 85 additions and 21 deletions

View File

@@ -5829,6 +5829,35 @@ _nm_setting_property_from_dbus_fcn_direct_ip_config_gateway(
error); error);
} }
static GVariant *
dns_data_to_dbus(_NM_SETT_INFO_PROP_TO_DBUS_FCN_ARGS _nm_nil)
{
GPtrArray *arr;
if (!_nm_connection_serialize_non_secret(flags))
return NULL;
arr = _nm_setting_ip_config_get_dns_array(NM_SETTING_IP_CONFIG(setting));
if (nm_g_ptr_array_len(arr) == 0)
return NULL;
return g_variant_new_strv((const char *const *) arr->pdata, arr->len);
}
static gboolean
dns_data_from_dbus(_NM_SETT_INFO_PROP_FROM_DBUS_FCN_ARGS _nm_nil)
{
gs_free const char **strv = NULL;
if (_nm_setting_use_legacy_property(setting, connection_dict, "dns", "dns-data")) {
*out_is_modified = FALSE;
return TRUE;
}
strv = g_variant_get_strv(value, NULL);
g_object_set(setting, NM_SETTING_IP_CONFIG_DNS, strv, NULL);
return TRUE;
}
GArray * GArray *
_nm_sett_info_property_override_create_array_ip_config(int addr_family) _nm_sett_info_property_override_create_array_ip_config(int addr_family)
{ {
@@ -5915,6 +5944,21 @@ _nm_sett_info_property_override_create_array_ip_config(int addr_family)
.direct_offset = .direct_offset =
NM_STRUCT_OFFSET_ENSURE_TYPE(bool, NMSettingIPConfigPrivate, ignore_auto_dns)); NM_STRUCT_OFFSET_ENSURE_TYPE(bool, NMSettingIPConfigPrivate, ignore_auto_dns));
/* ---dbus---
* property: dns-data
* format: array of strings
* description: Array of DNS name servers. This replaces the deprecated
* "dns" property. Each name server can also contain a DoT server name.
* ---end---
*/
_nm_properties_override_dbus(
properties_override,
"dns-data",
NM_SETT_INFO_PROPERT_TYPE_DBUS(NM_G_VARIANT_TYPE("as"),
.to_dbus_fcn = dns_data_to_dbus,
.compare_fcn = _nm_setting_property_compare_fcn_ignore,
.from_dbus_fcn = dns_data_from_dbus, ));
_nm_properties_override_gobj( _nm_properties_override_gobj(
properties_override, properties_override,
obj_properties[PROP_DNS_PRIORITY], obj_properties[PROP_DNS_PRIORITY],
@@ -6156,11 +6200,13 @@ nm_setting_ip_config_class_init(NMSettingIPConfigClass *klass)
* *
* Array of IP addresses of DNS servers. * Array of IP addresses of DNS servers.
**/ **/
obj_properties[PROP_DNS] = g_param_spec_boxed(NM_SETTING_IP_CONFIG_DNS, obj_properties[PROP_DNS] =
"", g_param_spec_boxed(NM_SETTING_IP_CONFIG_DNS,
"", "",
G_TYPE_STRV, "",
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); G_TYPE_STRV,
/* On D-Bus, "dns" is deprecated for "dns-data". */
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
/** /**
* NMSettingIPConfig:dns-search: * NMSettingIPConfig:dns-search:

View File

@@ -395,10 +395,19 @@ ip4_dns_to_dbus(_NM_SETT_INFO_PROP_TO_DBUS_FCN_ARGS _nm_nil)
return _nm_utils_ip4_dns_to_variant((const char *const *) dns->pdata, dns->len); return _nm_utils_ip4_dns_to_variant((const char *const *) dns->pdata, dns->len);
} }
static void static gboolean
ip4_dns_from_dbus(_NM_SETT_INFO_PROP_FROM_DBUS_GPROP_FCN_ARGS _nm_nil) ip4_dns_from_dbus(_NM_SETT_INFO_PROP_FROM_DBUS_FCN_ARGS _nm_nil)
{ {
g_value_take_boxed(to, nm_utils_ip4_dns_from_variant(from)); gs_strfreev char **strv = NULL;
if (!_nm_setting_use_legacy_property(setting, connection_dict, "dns", "dns-data")) {
*out_is_modified = FALSE;
return TRUE;
}
strv = nm_utils_ip4_dns_from_variant(value);
g_object_set(setting, NM_SETTING_IP_CONFIG_DNS, strv, NULL);
return TRUE;
} }
static GVariant * static GVariant *
@@ -964,11 +973,11 @@ nm_setting_ip4_config_class_init(NMSettingIP4ConfigClass *klass)
properties_override, properties_override,
g_object_class_find_property(G_OBJECT_CLASS(setting_class), NM_SETTING_IP_CONFIG_DNS), g_object_class_find_property(G_OBJECT_CLASS(setting_class), NM_SETTING_IP_CONFIG_DNS),
NM_SETT_INFO_PROPERT_TYPE_DBUS(NM_G_VARIANT_TYPE("au"), NM_SETT_INFO_PROPERT_TYPE_DBUS(NM_G_VARIANT_TYPE("au"),
.compare_fcn = _nm_setting_property_compare_fcn_default, .compare_fcn = _nm_setting_property_compare_fcn_default,
.to_dbus_fcn = ip4_dns_to_dbus, .to_dbus_fcn = ip4_dns_to_dbus,
.typdata_from_dbus.gprop_fcn = ip4_dns_from_dbus, .from_dbus_fcn = ip4_dns_from_dbus, ),
.from_dbus_fcn = _nm_setting_property_from_dbus_fcn_gprop, .to_dbus_only_in_manager_process = TRUE,
.from_dbus_is_full = TRUE), ); .dbus_deprecated = TRUE, );
/* ---dbus--- /* ---dbus---
* property: addresses * property: addresses

View File

@@ -396,10 +396,19 @@ ip6_dns_to_dbus(_NM_SETT_INFO_PROP_TO_DBUS_FCN_ARGS _nm_nil)
return _nm_utils_ip6_dns_to_variant((const char *const *) dns->pdata, dns->len); return _nm_utils_ip6_dns_to_variant((const char *const *) dns->pdata, dns->len);
} }
static void static gboolean
ip6_dns_from_dbus(_NM_SETT_INFO_PROP_FROM_DBUS_GPROP_FCN_ARGS _nm_nil) ip6_dns_from_dbus(_NM_SETT_INFO_PROP_FROM_DBUS_FCN_ARGS _nm_nil)
{ {
g_value_take_boxed(to, nm_utils_ip6_dns_from_variant(from)); gs_strfreev char **strv = NULL;
if (!_nm_setting_use_legacy_property(setting, connection_dict, "dns", "dns-data")) {
*out_is_modified = FALSE;
return TRUE;
}
strv = nm_utils_ip6_dns_from_variant(value);
g_object_set(setting, NM_SETTING_IP_CONFIG_DNS, strv, NULL);
return TRUE;
} }
static GVariant * static GVariant *
@@ -973,11 +982,11 @@ nm_setting_ip6_config_class_init(NMSettingIP6ConfigClass *klass)
properties_override, properties_override,
g_object_class_find_property(G_OBJECT_CLASS(setting_class), NM_SETTING_IP_CONFIG_DNS), g_object_class_find_property(G_OBJECT_CLASS(setting_class), NM_SETTING_IP_CONFIG_DNS),
NM_SETT_INFO_PROPERT_TYPE_DBUS(NM_G_VARIANT_TYPE("aay"), NM_SETT_INFO_PROPERT_TYPE_DBUS(NM_G_VARIANT_TYPE("aay"),
.compare_fcn = _nm_setting_property_compare_fcn_default, .compare_fcn = _nm_setting_property_compare_fcn_default,
.to_dbus_fcn = ip6_dns_to_dbus, .to_dbus_fcn = ip6_dns_to_dbus,
.typdata_from_dbus.gprop_fcn = ip6_dns_from_dbus, .from_dbus_fcn = ip6_dns_from_dbus, ),
.from_dbus_fcn = _nm_setting_property_from_dbus_fcn_gprop, .to_dbus_only_in_manager_process = TRUE,
.from_dbus_is_full = TRUE)); .dbus_deprecated = TRUE);
/* ---dbus--- /* ---dbus---
* property: addresses * property: addresses