libnm: refactor to_dbus_fcn() for "ipv6.dns" property
The goal is to get rid of gprop_to_dbus_fcn() uses. Note that there is a change in behavior. The "dns" GPtrArray in NMSettingIPConfig is never NULL (the default of the boxed property), thus the previous code always serialized the property, even the empty list. Now, empty dns properties are omitted from D-Bus.
This commit is contained in:
@@ -4101,6 +4101,12 @@ nm_setting_ip_config_clear_dns(NMSettingIPConfig *setting)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GPtrArray *
|
||||||
|
_nm_setting_ip_config_get_dns_array(NMSettingIPConfig *setting)
|
||||||
|
{
|
||||||
|
return NM_SETTING_IP_CONFIG_GET_PRIVATE(setting)->dns;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* nm_setting_ip_config_get_num_dns_searches:
|
* nm_setting_ip_config_get_num_dns_searches:
|
||||||
* @setting: the #NMSettingIPConfig
|
* @setting: the #NMSettingIPConfig
|
||||||
|
@@ -10,6 +10,7 @@
|
|||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
|
|
||||||
#include "nm-setting-private.h"
|
#include "nm-setting-private.h"
|
||||||
|
#include "nm-utils-private.h"
|
||||||
#include "nm-core-enum-types.h"
|
#include "nm-core-enum-types.h"
|
||||||
#include "libnm-core-intern/nm-core-internal.h"
|
#include "libnm-core-intern/nm-core-internal.h"
|
||||||
|
|
||||||
@@ -362,9 +363,21 @@ verify(NMSetting *setting, NMConnection *connection, GError **error)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static GVariant *
|
static GVariant *
|
||||||
ip6_dns_to_dbus(const GValue *prop_value)
|
ip6_dns_to_dbus(const NMSettInfoSetting * sett_info,
|
||||||
|
const NMSettInfoProperty * property_info,
|
||||||
|
NMConnection * connection,
|
||||||
|
NMSetting * setting,
|
||||||
|
NMConnectionSerializationFlags flags,
|
||||||
|
const NMConnectionSerializationOptions *options)
|
||||||
{
|
{
|
||||||
return nm_utils_ip6_dns_to_variant(g_value_get_boxed(prop_value));
|
GPtrArray *dns;
|
||||||
|
|
||||||
|
dns = _nm_setting_ip_config_get_dns_array(NM_SETTING_IP_CONFIG(setting));
|
||||||
|
|
||||||
|
if (nm_g_ptr_array_len(dns) == 0)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
return _nm_utils_ip6_dns_to_variant((const char *const *) dns->pdata, dns->len);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -1021,10 +1034,10 @@ nm_setting_ip6_config_class_init(NMSettingIP6ConfigClass *klass)
|
|||||||
_nm_properties_override_gobj(
|
_nm_properties_override_gobj(
|
||||||
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_GPROP(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,
|
||||||
.gprop_from_dbus_fcn = ip6_dns_from_dbus, ),
|
.to_dbus_fcn = ip6_dns_to_dbus,
|
||||||
.to_dbus_data.gprop_to_dbus_fcn = ip6_dns_to_dbus);
|
.gprop_from_dbus_fcn = ip6_dns_from_dbus, ));
|
||||||
|
|
||||||
/* ---dbus---
|
/* ---dbus---
|
||||||
* property: addresses
|
* property: addresses
|
||||||
|
@@ -65,4 +65,6 @@ GVariant *_nm_team_settings_property_to_dbus(const NMSettInfoSetting *
|
|||||||
|
|
||||||
void _nm_team_settings_property_from_dbus_link_watchers(GVariant *dbus_value, GValue *prop_value);
|
void _nm_team_settings_property_from_dbus_link_watchers(GVariant *dbus_value, GValue *prop_value);
|
||||||
|
|
||||||
|
GVariant *_nm_utils_ip6_dns_to_variant(const char *const *dns, gssize len);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@@ -1592,19 +1592,29 @@ nm_utils_ip4_get_default_prefix(guint32 ip)
|
|||||||
**/
|
**/
|
||||||
GVariant *
|
GVariant *
|
||||||
nm_utils_ip6_dns_to_variant(char **dns)
|
nm_utils_ip6_dns_to_variant(char **dns)
|
||||||
|
{
|
||||||
|
return _nm_utils_ip6_dns_to_variant(NM_CAST_STRV_CC(dns), -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
GVariant *
|
||||||
|
_nm_utils_ip6_dns_to_variant(const char *const *dns, gssize len)
|
||||||
{
|
{
|
||||||
GVariantBuilder builder;
|
GVariantBuilder builder;
|
||||||
gsize i;
|
gsize i;
|
||||||
|
gsize l;
|
||||||
|
|
||||||
|
if (len < 0)
|
||||||
|
l = NM_PTRARRAY_LEN(dns);
|
||||||
|
else
|
||||||
|
l = len;
|
||||||
|
|
||||||
g_variant_builder_init(&builder, G_VARIANT_TYPE("aay"));
|
g_variant_builder_init(&builder, G_VARIANT_TYPE("aay"));
|
||||||
if (dns) {
|
for (i = 0; i < l; i++) {
|
||||||
for (i = 0; dns[i]; i++) {
|
struct in6_addr ip;
|
||||||
struct in6_addr ip;
|
|
||||||
|
|
||||||
if (inet_pton(AF_INET6, dns[i], &ip) != 1)
|
if (inet_pton(AF_INET6, dns[i], &ip) != 1)
|
||||||
continue;
|
continue;
|
||||||
g_variant_builder_add(&builder, "@ay", nm_g_variant_new_ay_in6addr(&ip));
|
g_variant_builder_add(&builder, "@ay", nm_g_variant_new_ay_in6addr(&ip));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return g_variant_builder_end(&builder);
|
return g_variant_builder_end(&builder);
|
||||||
}
|
}
|
||||||
|
@@ -966,4 +966,6 @@ _nm_variant_attribute_spec_find_binary_search(const NMVariantAttributeSpec *cons
|
|||||||
|
|
||||||
gboolean _nm_ip_tunnel_mode_is_layer2(NMIPTunnelMode mode);
|
gboolean _nm_ip_tunnel_mode_is_layer2(NMIPTunnelMode mode);
|
||||||
|
|
||||||
|
GPtrArray *_nm_setting_ip_config_get_dns_array(NMSettingIPConfig *setting);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user