summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Winship <danw@gnome.org>2014-06-24 12:46:03 -0400
committerDan Winship <danw@gnome.org>2014-09-03 16:24:42 -0400
commite78500e20b355d8976f29e5d17550265e6b3a8fd (patch)
treea05d56c9089b05f5d6e042f54383b6e58be56483
parent8f548f66a6dcb2cfbf41ff02ae2638d342e6dfcc (diff)
downloadNetworkManager-e78500e20b355d8976f29e5d17550265e6b3a8fd.tar.gz
libnm-core: improve NMSettingIP4Config / NMSettingIP6Config property types
Make the :addresses and :routes properties be GPtrArrays of NMIP4Address, etc, rather than just reflecting the D-Bus data. Make the :dns properties be arrays of strings rather than arrays of binary IP addresses (and update the corresponding APIs as well).
-rw-r--r--clients/cli/settings.c181
-rw-r--r--clients/tui/nm-editor-bindings.c319
-rw-r--r--clients/tui/nmt-route-table.c96
-rw-r--r--libnm-core/nm-core-internal.h7
-rw-r--r--libnm-core/nm-setting-ip4-config.c176
-rw-r--r--libnm-core/nm-setting-ip4-config.h6
-rw-r--r--libnm-core/nm-setting-ip6-config.c155
-rw-r--r--libnm-core/nm-setting-ip6-config.h6
-rw-r--r--libnm-core/nm-utils-private.h26
-rw-r--r--libnm-core/nm-utils.c514
-rw-r--r--libnm-core/nm-value-transforms.c321
-rw-r--r--libnm-core/tests/test-general.c106
-rw-r--r--src/nm-ip4-config.c10
-rw-r--r--src/nm-ip6-config.c10
-rw-r--r--src/settings/plugins/ibft/reader.c8
-rw-r--r--src/settings/plugins/ibft/tests/test-ibft.c4
-rw-r--r--src/settings/plugins/ifcfg-rh/reader.c36
-rw-r--r--src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c112
-rw-r--r--src/settings/plugins/ifcfg-rh/writer.c18
-rw-r--r--src/settings/plugins/ifnet/connection_parser.c19
-rw-r--r--src/settings/plugins/ifnet/net_utils.c7
-rw-r--r--src/settings/plugins/ifupdown/parser.c4
-rw-r--r--src/settings/plugins/ifupdown/tests/test-ifupdown.c36
-rw-r--r--src/settings/plugins/keyfile/reader.c143
-rw-r--r--src/settings/plugins/keyfile/tests/test-keyfile.c52
-rw-r--r--src/settings/plugins/keyfile/writer.c141
26 files changed, 1274 insertions, 1239 deletions
diff --git a/clients/cli/settings.c b/clients/cli/settings.c
index 678b786545..1b325a7cbd 100644
--- a/clients/cli/settings.c
+++ b/clients/cli/settings.c
@@ -789,9 +789,6 @@ vpn_data_item (const char *key, const char *value, gpointer user_data)
GValue val = G_VALUE_INIT; \
g_value_init (&val, G_TYPE_STRING); \
g_object_get_property (G_OBJECT (setting), property_name, &val); \
- /* Getters return allocated values, and returning the string \
- * the GValue copied from the object without unsetting the \
- * GValue fulfills that requirement. */ \
s = g_value_dup_string (&val); \
g_value_unset (&val); \
return s; \
@@ -1200,8 +1197,82 @@ DEFINE_GETTER (nmc_property_ib_get_parent, NM_SETTING_INFINIBAND_PARENT)
DEFINE_GETTER (nmc_property_ipv4_get_method, NM_SETTING_IP4_CONFIG_METHOD)
DEFINE_GETTER (nmc_property_ipv4_get_dns, NM_SETTING_IP4_CONFIG_DNS)
DEFINE_GETTER (nmc_property_ipv4_get_dns_search, NM_SETTING_IP4_CONFIG_DNS_SEARCH)
-DEFINE_GETTER (nmc_property_ipv4_get_addresses, NM_SETTING_IP4_CONFIG_ADDRESSES)
-DEFINE_GETTER (nmc_property_ipv4_get_routes, NM_SETTING_IP4_CONFIG_ROUTES)
+
+static char *
+nmc_property_ipv4_get_addresses (NMSetting *setting)
+{
+ NMSettingIP4Config *s_ip4 = NM_SETTING_IP4_CONFIG (setting);
+ GString *printable;
+ guint32 num_addresses, i;
+ NMIP4Address *addr;
+ char buf[INET_ADDRSTRLEN];
+
+ printable = g_string_new (NULL);
+
+ num_addresses = nm_setting_ip4_config_get_num_addresses (s_ip4);
+ for (i = 0; i < num_addresses; i++) {
+ addr = nm_setting_ip4_config_get_address (s_ip4, i);
+
+ if (printable->len > 0)
+ g_string_append (printable, "; ");
+
+ g_string_append (printable, "{ ");
+
+ nm_utils_inet4_ntop (nm_ip4_address_get_address (addr), buf);
+ g_string_append_printf (printable, "ip = %s", buf);
+
+ g_string_append_printf (printable, "/%u", nm_ip4_address_get_prefix (addr));
+
+ if (nm_ip4_address_get_gateway (addr)) {
+ nm_utils_inet4_ntop (nm_ip4_address_get_gateway (addr), buf);
+ g_string_append_printf (printable, ", gw = %s", buf);
+ }
+
+ g_string_append (printable, " }");
+ }
+
+ return g_string_free (printable, FALSE);
+}
+
+static char *
+nmc_property_ipv4_get_routes (NMSetting *setting)
+{
+ NMSettingIP4Config *s_ip4 = NM_SETTING_IP4_CONFIG (setting);
+ GString *printable;
+ guint32 num_routes, i;
+ NMIP4Route *route;
+ char buf[INET_ADDRSTRLEN];
+
+ printable = g_string_new (NULL);
+
+ num_routes = nm_setting_ip4_config_get_num_routes (s_ip4);
+ for (i = 0; i < num_routes; i++) {
+ route = nm_setting_ip4_config_get_route (s_ip4, i);
+
+ if (printable->len > 0)
+ g_string_append (printable, "; ");
+
+ g_string_append (printable, "{ ");
+
+ nm_utils_inet4_ntop (nm_ip4_route_get_dest (route), buf);
+ g_string_append_printf (printable, "ip = %s", buf);
+
+ g_string_append_printf (printable, "/%u", nm_ip4_route_get_prefix (route));
+
+ if (nm_ip4_route_get_next_hop (route)) {
+ nm_utils_inet4_ntop (nm_ip4_route_get_next_hop (route), buf);
+ g_string_append_printf (printable, ", nh = %s", buf);
+ }
+
+ if (nm_ip4_route_get_metric (route))
+ g_string_append_printf (printable, ", mt = %u", nm_ip4_route_get_metric (route));
+
+ g_string_append (printable, " }");
+ }
+
+ return g_string_free (printable, FALSE);
+}
+
DEFINE_GETTER (nmc_property_ipv4_get_ignore_auto_routes, NM_SETTING_IP4_CONFIG_IGNORE_AUTO_ROUTES)
DEFINE_GETTER (nmc_property_ipv4_get_ignore_auto_dns, NM_SETTING_IP4_CONFIG_IGNORE_AUTO_DNS)
DEFINE_GETTER (nmc_property_ipv4_get_dhcp_client_id, NM_SETTING_IP4_CONFIG_DHCP_CLIENT_ID)
@@ -1214,8 +1285,82 @@ DEFINE_GETTER (nmc_property_ipv4_get_may_fail, NM_SETTING_IP4_CONFIG_MAY_FAIL)
DEFINE_GETTER (nmc_property_ipv6_get_method, NM_SETTING_IP6_CONFIG_METHOD)
DEFINE_GETTER (nmc_property_ipv6_get_dns, NM_SETTING_IP6_CONFIG_DNS)
DEFINE_GETTER (nmc_property_ipv6_get_dns_search, NM_SETTING_IP6_CONFIG_DNS_SEARCH)
-DEFINE_GETTER (nmc_property_ipv6_get_addresses, NM_SETTING_IP6_CONFIG_ADDRESSES)
-DEFINE_GETTER (nmc_property_ipv6_get_routes, NM_SETTING_IP6_CONFIG_ROUTES)
+
+static char *
+nmc_property_ipv6_get_addresses (NMSetting *setting)
+{
+ NMSettingIP6Config *s_ip6 = NM_SETTING_IP6_CONFIG (setting);
+ GString *printable;
+ guint32 num_addresses, i;
+ NMIP6Address *addr;
+ char buf[INET6_ADDRSTRLEN];
+
+ printable = g_string_new (NULL);
+
+ num_addresses = nm_setting_ip6_config_get_num_addresses (s_ip6);
+ for (i = 0; i < num_addresses; i++) {
+ addr = nm_setting_ip6_config_get_address (s_ip6, i);
+
+ if (printable->len > 0)
+ g_string_append (printable, "; ");
+
+ g_string_append (printable, "{ ");
+
+ nm_utils_inet6_ntop (nm_ip6_address_get_address (addr), buf);
+ g_string_append_printf (printable, "ip = %s", buf);
+
+ g_string_append_printf (printable, "/%u", nm_ip6_address_get_prefix (addr));
+
+ if (nm_ip6_address_get_gateway (addr)) {
+ nm_utils_inet6_ntop (nm_ip6_address_get_gateway (addr), buf);
+ g_string_append_printf (printable, ", gw = %s", buf);
+ }
+
+ g_string_append (printable, " }");
+ }
+
+ return g_string_free (printable, FALSE);
+}
+
+static char *
+nmc_property_ipv6_get_routes (NMSetting *setting)
+{
+ NMSettingIP6Config *s_ip6 = NM_SETTING_IP6_CONFIG (setting);
+ GString *printable;
+ guint32 num_routes, i;
+ NMIP6Route *route;
+ char buf[INET6_ADDRSTRLEN];
+
+ printable = g_string_new (NULL);
+
+ num_routes = nm_setting_ip6_config_get_num_routes (s_ip6);
+ for (i = 0; i < num_routes; i++) {
+ route = nm_setting_ip6_config_get_route (s_ip6, i);
+
+ if (printable->len > 0)
+ g_string_append (printable, "; ");
+
+ g_string_append (printable, "{ ");
+
+ nm_utils_inet6_ntop (nm_ip6_route_get_dest (route), buf);
+ g_string_append_printf (printable, "ip = %s", buf);
+
+ g_string_append_printf (printable, "/%u", nm_ip6_route_get_prefix (route));
+
+ if (nm_ip6_route_get_next_hop (route)) {
+ nm_utils_inet6_ntop (nm_ip6_route_get_next_hop (route), buf);
+ g_string_append_printf (printable, ", nh = %s", buf);
+ }
+
+ if (nm_ip6_route_get_metric (route))
+ g_string_append_printf (printable, ", mt = %u", nm_ip6_route_get_metric (route));
+
+ g_string_append (printable, " }");
+ }
+
+ return g_string_free (printable, FALSE);
+}
+
DEFINE_GETTER (nmc_property_ipv6_get_ignore_auto_routes, NM_SETTING_IP6_CONFIG_IGNORE_AUTO_ROUTES)
DEFINE_GETTER (nmc_property_ipv6_get_ignore_auto_dns, NM_SETTING_IP6_CONFIG_IGNORE_AUTO_DNS)
DEFINE_GETTER (nmc_property_ipv6_get_never_default, NM_SETTING_IP6_CONFIG_NEVER_DEFAULT)
@@ -2885,19 +3030,20 @@ DEFINE_ALLOWED_VAL_FUNC (nmc_property_ipv4_allowed_method, ipv4_valid_methods)
static gboolean
nmc_property_ipv4_set_dns (NMSetting *setting, const char *prop, const char *val, GError **error)
{
- char **strv = NULL, **iter;
+ char **strv = NULL, **iter, *addr;
guint32 ip4_addr;
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
strv = nmc_strsplit_set (val, " \t,", 0);
for (iter = strv; iter && *iter; iter++) {
- if (inet_pton (AF_INET, g_strstrip (*iter), &ip4_addr) < 1) {
- g_set_error (error, 1, 0, _("invalid IPv4 address '%s'"), *iter);
+ addr = g_strstrip (*iter);
+ if (inet_pton (AF_INET, addr, &ip4_addr) < 1) {
+ g_set_error (error, 1, 0, _("invalid IPv4 address '%s'"), addr);
g_strfreev (strv);
return FALSE;
}
- nm_setting_ip4_config_add_dns (NM_SETTING_IP4_CONFIG (setting), ip4_addr);
+ nm_setting_ip4_config_add_dns (NM_SETTING_IP4_CONFIG (setting), addr);
}
g_strfreev (strv);
return TRUE;
@@ -2916,7 +3062,7 @@ _validate_and_remove_ipv4_dns (NMSettingIP4Config *setting,
return FALSE;
}
- ret = nm_setting_ip4_config_remove_dns_by_value (setting, ip4_addr);
+ ret = nm_setting_ip4_config_remove_dns_by_value (setting, dns);
if (!ret)
g_set_error (error, 1, 0, _("the property doesn't contain DNS server '%s'"), dns);
return ret;
@@ -3230,19 +3376,20 @@ DEFINE_ALLOWED_VAL_FUNC (nmc_property_ipv6_allowed_method, ipv6_valid_methods)
static gboolean
nmc_property_ipv6_set_dns (NMSetting *setting, const char *prop, const char *val, GError **error)
{
- char **strv = NULL, **iter;
+ char **strv = NULL, **iter, *addr;
struct in6_addr ip6_addr;
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
strv = nmc_strsplit_set (val, " \t,", 0);
for (iter = strv; iter && *iter; iter++) {
- if (inet_pton (AF_INET6, g_strstrip (*iter), &ip6_addr) < 1) {
- g_set_error (error, 1, 0, _("invalid IPv6 address '%s'"), *iter);
+ addr = g_strstrip (*iter);
+ if (inet_pton (AF_INET6, addr, &ip6_addr) < 1) {
+ g_set_error (error, 1, 0, _("invalid IPv6 address '%s'"), addr);
g_strfreev (strv);
return FALSE;
}
- nm_setting_ip6_config_add_dns (NM_SETTING_IP6_CONFIG (setting), &ip6_addr);
+ nm_setting_ip6_config_add_dns (NM_SETTING_IP6_CONFIG (setting), addr);
}
g_strfreev (strv);
return TRUE;
@@ -3261,7 +3408,7 @@ _validate_and_remove_ipv6_dns (NMSettingIP6Config *setting,
return FALSE;
}
- ret = nm_setting_ip6_config_remove_dns_by_value (setting, &ip6_addr);
+ ret = nm_setting_ip6_config_remove_dns_by_value (setting, dns);
if (!ret)
g_set_error (error, 1, 0, _("the property doesn't contain DNS server '%s'"), dns);
return ret;
diff --git a/clients/tui/nm-editor-bindings.c b/clients/tui/nm-editor-bindings.c
index 0325c0a8b8..e3b210dec6 100644
--- a/clients/tui/nm-editor-bindings.c
+++ b/clients/tui/nm-editor-bindings.c
@@ -119,7 +119,7 @@ ip4_addresses_with_prefix_to_strv (GBinding *binding,
gpointer user_data)
{
GPtrArray *addrs;
- GArray *addr;
+ NMIP4Address *addr;
guint32 addrbytes, prefix;
char buf[INET_ADDRSTRLEN], **strings;
int i;
@@ -129,8 +129,8 @@ ip4_addresses_with_prefix_to_strv (GBinding *binding,
for (i = 0; i < addrs->len; i++) {
addr = addrs->pdata[i];
- addrbytes = g_array_index (addr, guint32, 0);
- prefix = g_array_index (addr, guint32, 1);
+ addrbytes = nm_ip4_address_get_address (addr);
+ prefix = nm_ip4_address_get_prefix (addr);
if (addrbytes) {
strings[i] = g_strdup_printf ("%s/%d",
@@ -152,8 +152,8 @@ ip4_addresses_with_prefix_from_strv (GBinding *binding,
{
char **strings;
GPtrArray *addrs;
- GArray *addr;
- guint32 *addrvals;
+ NMIP4Address *addr;
+ guint32 addrbytes, prefix;
int i;
strings = g_value_get_boxed (source_value);
@@ -164,24 +164,19 @@ ip4_addresses_with_prefix_from_strv (GBinding *binding,
for (i = 0; strings[i]; i++) {
if (i >= addrs->len) {
- guint32 val;
-
- addr = g_array_sized_new (FALSE, FALSE, sizeof (guint32), 3);
- val = 0;
- g_array_append_val (addr, val);
- val = 32;
- g_array_append_val (addr, val);
- val = 0;
- g_array_append_val (addr, val);
+ addr = nm_ip4_address_new ();
+ nm_ip4_address_set_prefix (addr, 32);
g_ptr_array_add (addrs, addr);
} else
addr = addrs->pdata[i];
- addrvals = (guint32 *)addr->data;
- if (!ip_string_parse (strings[i], AF_INET, &addrvals[0], &addrvals[1])) {
+ if (!ip_string_parse (strings[i], AF_INET, &addrbytes, &prefix)) {
g_ptr_array_unref (addrs);
return FALSE;
}
+
+ nm_ip4_address_set_address (addr, addrbytes);
+ nm_ip4_address_set_prefix (addr, prefix);
}
g_ptr_array_set_size (addrs, i);
@@ -199,16 +194,14 @@ ip4_addresses_with_prefix_from_strv (GBinding *binding,
* (eg, "strings")
* @flags: %GBindingFlags
*
- * Binds the %DBUS_TYPE_G_ARRAY_OF_ARRAY_OF_UINT property
- * @source_property on @source to the %G_TYPE_STRV property
- * @target_property on @target.
+ * Binds the #GPtrArray-of-#NMIP4Address property @source_property on @source to
+ * the %G_TYPE_STRV property @target_property on @target.
*
- * Each address/prefix/gateway triplet in @source_property will be
- * converted to a string of the form "ip.ad.dr.ess/prefix" in
- * @target_property (and vice versa if %G_BINDING_BIDIRECTIONAL) is
- * specified. The "gateway" fields in @source_property are ignored
- * when converting to strings, and unmodified when converting from
- * strings.
+ * Each #NMIP4Address in @source_property will be converted to a string of the
+ * form "ip.ad.dr.ess/prefix" in @target_property (and vice versa if
+ * %G_BINDING_BIDIRECTIONAL) is specified. The "gateway" fields in
+ * @source_property are ignored when converting to strings, and unmodified when
+ * converting from strings.
*/
void
nm_editor_bind_ip4_addresses_with_prefix_to_strv (gpointer source,
@@ -226,55 +219,23 @@ nm_editor_bind_ip4_addresses_with_prefix_to_strv (gpointer source,
}
static gboolean
-ip4_addresses_to_strv (GBinding *binding,
- const GValue *source_value,
- GValue *target_value,
- gpointer user_data)
-{
- GArray *addrs;
- guint32 addrbytes;
- char buf[INET_ADDRSTRLEN], **strings;
- int i;
-
- addrs = g_value_get_boxed (source_value);
- strings = g_new0 (char *, addrs->len + 1);
-
- for (i = 0; i < addrs->len; i++) {
- addrbytes = g_array_index (addrs, guint32, i);
- if (addrbytes)
- inet_ntop (AF_INET, &addrbytes, buf, sizeof (buf));
- else
- buf[0] = '\0';
- strings[i] = g_strdup (buf);
- }
-
- g_value_take_boxed (target_value, strings);
- return TRUE;
-}
-
-static gboolean
-ip4_addresses_from_strv (GBinding *binding,
- const GValue *source_value,
- GValue *target_value,
- gpointer user_data)
+ip4_addresses_check_and_copy (GBinding *binding,
+ const GValue *source_value,
+ GValue *target_value,
+ gpointer user_data)
{
char **strings;
- GArray *addrs;
guint32 addr;
int i;
strings = g_value_get_boxed (source_value);
- addrs = g_array_new (FALSE, FALSE, sizeof (guint32));
for (i = 0; strings[i]; i++) {
- if (!ip_string_parse (strings[i], AF_INET, &addr, NULL)) {
- g_array_unref (addrs);
+ if (!ip_string_parse (strings[i], AF_INET, &addr, NULL))
return FALSE;
- }
- g_array_append_val (addrs, addr);
}
- g_value_take_boxed (target_value, addrs);
+ g_value_set_boxed (target_value, strings);
return TRUE;
}
@@ -288,12 +249,9 @@ ip4_addresses_from_strv (GBinding *binding,
* (eg, "strings")
* @flags: %GBindingFlags
*
- * Binds the %DBUS_TYPE_G_UINT_ARRAY property @source_property on
- * @source to the %G_TYPE_STRV property @target_property on @target.
- *
- * Each address in @source_property will be converted to a string of
- * the form "ip.ad.dr.ess" in @target_property (and vice versa if
- * %G_BINDING_BIDIRECTIONAL) is specified.
+ * Binds the %G_TYPE_STRV property @source_property on @source to the
+ * %G_TYPE_STRV property @target_property on @target, verifying that
+ * each string is a valid IPv4 address when copying.
*/
void
nm_editor_bind_ip4_addresses_to_strv (gpointer source,
@@ -305,8 +263,8 @@ nm_editor_bind_ip4_addresses_to_strv (gpointer source,
g_object_bind_property_full (source, source_property,
target, target_property,
flags,
- ip4_addresses_to_strv,
- ip4_addresses_from_strv,
+ ip4_addresses_check_and_copy,
+ ip4_addresses_check_and_copy,
NULL, NULL);
}
@@ -317,7 +275,7 @@ ip4_gateway_to_string (GBinding *binding,
gpointer user_data)
{
GPtrArray *addrs;
- GArray *addr;
+ NMIP4Address *addr;
guint32 gateway = 0;
const char *str;
char buf[INET_ADDRSTRLEN];
@@ -326,7 +284,7 @@ ip4_gateway_to_string (GBinding *binding,
addrs = g_value_get_boxed (source_value);
for (i = 0; i < addrs->len; i++) {
addr = addrs->pdata[i];
- gateway = g_array_index (addr, guint32, 2);
+ gateway = nm_ip4_address_get_gateway (addr);
if (gateway)
break;
}
@@ -347,8 +305,8 @@ ip4_gateway_from_string (GBinding *binding,
{
const char *text;
GPtrArray *addrs;
- GArray *addr;
- guint32 addrbytes, *addrvals;
+ NMIP4Address *addr;
+ guint32 addrbytes;
int i;
text = g_value_get_string (source_value);
@@ -364,17 +322,15 @@ ip4_gateway_from_string (GBinding *binding,
return FALSE;
}
addr = addrs->pdata[0];
- addrvals = (guint32 *)addr->data;
- if (addrbytes == addrvals[2]) {
+ if (addrbytes == nm_ip4_address_get_gateway (addr)) {
g_ptr_array_unref (addrs);
return FALSE;
}
- addrvals[2] = addrbytes;
+ nm_ip4_address_set_gateway (addr, addrbytes);
for (i = 1; i < addrs->len; i++) {
addr = addrs->pdata[i];
- addrvals = (guint32 *)addr->data;
- addrvals[2] = 0;
+ nm_ip4_address_set_gateway (addr, 0);
}
g_value_take_boxed (target_value, addrs);
@@ -391,13 +347,12 @@ ip4_gateway_from_string (GBinding *binding,
* (eg, "text")
* @flags: %GBindingFlags
*
- * Binds the %DBUS_TYPE_G_ARRAY_OF_ARRAY_OF_UINT property
- * @source_property on @source to the %G_TYPE_STRING property
- * @target_property on @target.
+ * Binds the #GPtrArray-of-#NMIP4Route property @source_property on @source to
+ * the %G_TYPE_STRING property @target_property on @target.
*
- * Specifically, this binds the "gateway" field of the first address
- * in @source_property; all other addresses in @source_property are
- * ignored, and its "address" and "prefix" fields are unmodified.
+ * Specifically, this binds the "gateway" field of the first address in
+ * @source_property; all other addresses in @source_property are ignored, and
+ * its "address" and "prefix" fields are unmodified.
*/
void
nm_editor_bind_ip4_gateway_to_string (gpointer source,
@@ -572,13 +527,13 @@ ip4_route_transform_from_metric_string (GBinding *binding,
* @metric_target_property: the property on @metric_target
* @flags: %GBindingFlags
*
- * Binds the #NMIP4Route-valued property @source_property on @source
- * to the three indicated string-valued target properties (and vice
- * versa if %G_BINDING_BIDIRECTIONAL is specified).
+ * Binds the #NMIP4Route-valued property @source_property on @source to the
+ * three indicated string-valued target properties (and vice versa if
+ * %G_BINDING_BIDIRECTIONAL is specified).
*
* @dest_target_property should be an "address/prefix" string, as with
- * nm_editor_bind_ip4_addresses_with_prefix_to_strv(). @next_hop_target
- * is a plain IP address, and @metric_target is a number.
+ * nm_editor_bind_ip4_addresses_with_prefix_to_strv(). @next_hop_target_property
+ * is a plain IP address, and @metric_target_property is a number.
*/
void
nm_editor_bind_ip4_route_to_strings (gpointer source,
@@ -612,8 +567,7 @@ nm_editor_bind_ip4_route_to_strings (gpointer source,
}
#define IP6_ADDRESS_SET(addr) ( addr \
- && addr->len == sizeof (struct in6_addr) \
- && memcmp (addr->data, &in6addr_any, addr->len) != 0)
+ && memcmp (addr, &in6addr_any, sizeof (struct in6_addr)) != 0)
static gboolean
ip6_addresses_with_prefix_to_strv (GBinding *binding,
@@ -622,9 +576,8 @@ ip6_addresses_with_prefix_to_strv (GBinding *binding,
gpointer user_data)
{
GPtrArray *addrs;
- GValueArray *addr;
- GValue *val;
- GByteArray *addrbytes;
+ NMIP6Address *addr;
+ const struct in6_addr *addrbytes;
guint prefix;
char **strings, buf[INET6_ADDRSTRLEN];
int i;
@@ -634,14 +587,12 @@ ip6_addresses_with_prefix_to_strv (GBinding *binding,
for (i = 0; i < addrs->len; i++) {
addr = addrs->pdata[i];
- val = g_value_array_get_nth (addr, 0);
- addrbytes = g_value_get_boxed (val);
- val = g_value_array_get_nth (addr, 1);
- prefix = g_value_get_uint (val);
+ addrbytes = nm_ip6_address_get_address (addr);
+ prefix = nm_ip6_address_get_prefix (addr);
if (IP6_ADDRESS_SET (addrbytes)) {
strings[i] = g_strdup_printf ("%s/%d",
- inet_ntop (AF_INET6, addrbytes->data, buf, sizeof (buf)),
+ inet_ntop (AF_INET6, addrbytes, buf, sizeof (buf)),
prefix);
} else
strings[i] = g_strdup ("");
@@ -659,10 +610,9 @@ ip6_addresses_with_prefix_from_strv (GBinding *binding,
{
char **strings;
GPtrArray *addrs;
- GValueArray *addr;
+ NMIP6Address *addr;
+ struct in6_addr addrbytes;
guint32 prefix;
- GValue val = G_VALUE_INIT, *valp;
- GByteArray *ba;
int i;
strings = g_value_get_boxed (source_value);
@@ -674,42 +624,19 @@ ip6_addresses_with_prefix_from_strv (GBinding *binding,
for (i = 0; strings[i]; i++) {
if (i >= addrs->len) {
- addr = g_value_array_new (3);
-
- g_value_init (&val, DBUS_TYPE_G_UCHAR_ARRAY);
- ba = g_byte_array_sized_new (sizeof (struct in6_addr));
- g_byte_array_append (ba, (guint8 *) &in6addr_any, sizeof (struct in6_addr));
- g_value_take_boxed (&val, ba);
- g_value_array_append (addr, &val);
- g_value_unset (&val);
-
- g_value_init (&val, G_TYPE_UINT);
- g_value_set_uint (&val, 128);
- g_value_array_append (addr, &val);
- g_value_unset (&val);
-
- g_value_init (&val, DBUS_TYPE_G_UCHAR_ARRAY);
- ba = g_byte_array_sized_new (sizeof (struct in6_addr));
- g_byte_array_append (ba, (guint8 *) &in6addr_any, sizeof (struct in6_addr));
- g_value_take_boxed (&val, ba);
- g_value_array_append (addr, &val);
- g_value_unset (&val);
-
+ addr = nm_ip6_address_new ();
+ nm_ip6_address_set_prefix (addr, 128);
g_ptr_array_add (addrs, addr);
} else
addr = addrs->pdata[i];
- valp = g_value_array_get_nth (addr, 0);
- ba = g_value_get_boxed (valp);
- g_assert (ba->len == sizeof (struct in6_addr));
-
- if (!ip_string_parse (strings[i], AF_INET6, ba->data, &prefix)) {
+ if (!ip_string_parse (strings[i], AF_INET6, &addrbytes, &prefix)) {
g_ptr_array_unref (addrs);
return FALSE;
}
- valp = g_value_array_get_nth (addr, 1);
- g_value_set_uint (valp, prefix);
+ nm_ip6_address_set_address (addr, &addrbytes);
+ nm_ip6_address_set_prefix (addr, prefix);
}
g_ptr_array_set_size (addrs, i);
@@ -727,16 +654,14 @@ ip6_addresses_with_prefix_from_strv (GBinding *binding,
* (eg, "strings")
* @flags: %GBindingFlags
*
- * Binds the %DBUS_TYPE_G_ARRAY_OF_IP6_ADDRESS property
- * @source_property on @source to the %G_TYPE_STRV property
- * @target_property on @target.
+ * Binds the #GPtrArray-of-#NMIP6Address property @source_property on @source to
+ * the %G_TYPE_STRV property @target_property on @target.
*
- * Each address/prefix/gateway triplet in @source_property will be
- * converted to a string of the form "ip::ad:dr:ess/prefix" in
- * @target_property (and vice versa if %G_BINDING_BIDIRECTIONAL) is
- * specified. The "gateway" fields in @source_property are ignored
- * when converting to strings, and unmodified when converting from
- * strings.
+ * Each #NMIP6Address in triplet in @source_property will be converted to a
+ * string of the form "ip::ad:dr:ess/prefix" in @target_property (and vice versa
+ * if %G_BINDING_BIDIRECTIONAL) is specified. The "gateway" fields in
+ * @source_property are ignored when converting to strings, and unmodified when
+ * converting from strings.
*/
void
nm_editor_bind_ip6_addresses_with_prefix_to_strv (gpointer source,
@@ -754,61 +679,23 @@ nm_editor_bind_ip6_addresses_with_prefix_to_strv (gpointer source,
}
static gboolean
-ip6_addresses_to_strv (GBinding *binding,
- const GValue *source_value,
- GValue *target_value,
- gpointer user_data)
-{
- GPtrArray *addrs;
- GByteArray *addrbytes;
- char buf[INET6_ADDRSTRLEN], **strings;
- int i;
-
- addrs = g_value_get_boxed (source_value);
- strings = g_new0 (char *, addrs->len + 1);
-
- for (i = 0; i < addrs->len; i++) {
- addrbytes = addrs->pdata[i];
- if (IP6_ADDRESS_SET (addrbytes))
- inet_ntop (AF_INET6, addrbytes->data, buf, sizeof (buf));
- else
- buf[0] = '\0';
- strings[i] = g_strdup (buf);
- }
-
- g_value_take_boxed (target_value, strings);
- return TRUE;
-}
-
-static gboolean
-ip6_addresses_from_strv (GBinding *binding,
- const GValue *source_value,
- GValue *target_value,
- gpointer user_data)
+ip6_addresses_check_and_copy (GBinding *binding,
+ const GValue *source_value,
+ GValue *target_value,
+ gpointer user_data)
{
char **strings;
- GPtrArray *addrs;
- GByteArray *addr;
- struct in6_addr addrbytes;
+ struct in6_addr addr;
int i;
strings = g_value_get_boxed (source_value);
- addrs = g_ptr_array_new ();
for (i = 0; strings[i]; i++) {
- if (!ip_string_parse (strings[i], AF_INET6, &addrbytes, NULL)) {
- while (i--)
- g_byte_array_unref (addrs->pdata[i]);
- g_ptr_array_unref (addrs);
+ if (!ip_string_parse (strings[i], AF_INET6, &addr, NULL))
return FALSE;
- }
-
- addr = g_byte_array_sized_new (sizeof (addrbytes));
- g_byte_array_append (addr, (guint8 *)&addrbytes, sizeof (addrbytes));
- g_ptr_array_add (addrs, addr);
}
- g_value_take_boxed (target_value, addrs);
+ g_value_set_boxed (target_value, strings);
return TRUE;
}
@@ -822,13 +709,9 @@ ip6_addresses_from_strv (GBinding *binding,
* (eg, "strings")
* @flags: %GBindingFlags
*
- * Binds the %DBUS_TYPE_G_ARRAY_OF_ARRAY_OF_UCHAR property
- * @source_property on @source to the %G_TYPE_STRV property
- * @target_property on @target.
- *
- * Each address in @source_property will be converted to a string of
- * the form "ip::ad:dr:ess" in @target_property (and vice versa if
- * %G_BINDING_BIDIRECTIONAL) is specified.
+ * Binds the %G_TYPE_STRV property @source_property on @source to the
+ * %G_TYPE_STRV property @target_property on @target, verifying that
+ * each string is a valid IPv6 address when copying.
*/
void
nm_editor_bind_ip6_addresses_to_strv (gpointer source,
@@ -840,8 +723,8 @@ nm_editor_bind_ip6_addresses_to_strv (gpointer source,
g_object_bind_property_full (source, source_property,
target, target_property,
flags,
- ip6_addresses_to_strv,
- ip6_addresses_from_strv,
+ ip6_addresses_check_and_copy,
+ ip6_addresses_check_and_copy,
NULL, NULL);
}
@@ -852,9 +735,8 @@ ip6_gateway_to_string (GBinding *binding,
gpointer user_data)
{
GPtrArray *addrs;
- GValueArray *addr;
- GValue *val;
- GByteArray *gateway;
+ NMIP6Address *addr;
+ const struct in6_addr *gateway;
char buf[INET6_ADDRSTRLEN];
const char *str;
@@ -863,11 +745,10 @@ ip6_gateway_to_string (GBinding *binding,
return FALSE;
addr = addrs->pdata[0];
- val = g_value_array_get_nth (addr, 2);
- gateway = g_value_get_boxed (val);
+ gateway = nm_ip6_address_get_gateway (addr);
if (IP6_ADDRESS_SET (gateway))
- str = inet_ntop (AF_INET6, gateway->data, buf, sizeof (buf));
+ str = inet_ntop (AF_INET6, gateway, buf, sizeof (buf));
else
str = "";
g_value_set_string (target_value, str);
@@ -882,10 +763,8 @@ ip6_gateway_from_string (GBinding *binding,
{
GPtrArray *addrs;
const char *text;
- GValueArray *addr;
+ NMIP6Address *addr;
struct in6_addr gateway;
- GValue *val;
- GByteArray *ba;
int i;
text = g_value_get_string (source_value);
@@ -902,20 +781,11 @@ ip6_gateway_from_string (GBinding *binding,
}
addr = addrs->pdata[0];
-
- ba = g_byte_array_sized_new (sizeof (gateway));
- g_byte_array_append (ba, (guint8 *) &gateway, sizeof (gateway));
-
- val = g_value_array_get_nth (addr, 2);
- g_value_take_boxed (val, ba);
+ nm_ip6_address_set_gateway (addr, &gateway);
for (i = 1; i < addrs->len; i++) {
addr = addrs->pdata[i];
- val = g_value_array_get_nth (addr, 2);
- ba = g_value_get_boxed (val);
-
- if (ba)
- memset (ba->data, 0, ba->len);
+ nm_ip6_address_set_gateway (addr, &in6addr_any);
}
g_value_take_boxed (target_value, addrs);
@@ -932,13 +802,12 @@ ip6_gateway_from_string (GBinding *binding,
* (eg, "text")
* @flags: %GBindingFlags
*
- * Binds the %DBUS_TYPE_G_ARRAY_OF_IP6_ADDRESS property
- * @source_property on @source to the %G_TYPE_STRING property
- * @target_property on @target.
+ * Binds the #GPtrArray-of-#NMIP6Address property @source_property on @source to
+ * the %G_TYPE_STRING property @target_property on @target.
*
- * Specifically, this binds the "gateway" field of the first address
- * in @source_property; all other addresses in @source_property are
- * ignored, and its "address" and "prefix" fields are unmodified.
+ * Specifically, this binds the "gateway" field of the first address in
+ * @source_property; all other addresses in @source_property are ignored, and
+ * its "address" and "prefix" fields are unmodified.
*/
void
nm_editor_bind_ip6_gateway_to_string (gpointer source,
@@ -955,8 +824,6 @@ nm_editor_bind_ip6_gateway_to_string (gpointer source,
NULL, NULL);
}
-#define IN6_ADDR_SET(bytes) (memcmp (bytes, &in6addr_any, sizeof (struct in6_addr)) != 0)
-
static gboolean
ip6_route_transform_to_dest_string (GBinding *binding,
const GValue *source_value,
@@ -973,7 +840,7 @@ ip6_route_transform_to_dest_string (GBinding *binding,
else
addrbytes = &in6addr_any;
- if (IN6_ADDR_SET (addrbytes)) {
+ if (IP6_ADDRESS_SET (addrbytes)) {
string = g_strdup_printf ("%s/%d",
inet_ntop (AF_INET6, addrbytes, buf, sizeof (buf)),
(int) nm_ip6_route_get_prefix (route));
@@ -999,7 +866,7 @@ ip6_route_transform_to_next_hop_string (GBinding *binding,
else
addrbytes = &in6addr_any;
- if (IN6_ADDR_SET (addrbytes))
+ if (IP6_ADDRESS_SET (addrbytes))
inet_ntop (AF_INET6, addrbytes, buf, sizeof (buf));
else
buf[0] = '\0';
@@ -1017,7 +884,7 @@ ip6_route_transform_to_metric_string (GBinding *binding,
char *string;
route = g_value_get_boxed (source_value);
- if (route && IN6_ADDR_SET (nm_ip6_route_get_dest (route))) {
+ if (route && IP6_ADDRESS_SET (nm_ip6_route_get_dest (route))) {
string = g_strdup_printf ("%lu", (gulong) nm_ip6_route_get_metric (route));
g_value_take_string (target_value, string);
} else
diff --git a/clients/tui/nmt-route-table.c b/clients/tui/nmt-route-table.c
index 83765da04d..f8b5e89725 100644
--- a/clients/tui/nmt-route-table.c
+++ b/clients/tui/nmt-route-table.c
@@ -47,7 +47,7 @@ typedef struct {
int ip_entry_width;
int metric_entry_width;
- GSList *routes;
+ GPtrArray *routes;
NmtNewtWidget *list;
} NmtRouteTablePrivate;
@@ -87,7 +87,7 @@ route_list_transform_to_route (GBinding *binding,
int n = GPOINTER_TO_INT (user_data);
gpointer route;
- route = g_slist_nth_data (priv->routes, n);
+ route = priv->routes->pdata[n];
if (route)
g_value_set_boxed (target_value, route);
return route != NULL;
@@ -102,31 +102,25 @@ route_list_transform_from_route (GBinding *binding,
NmtRouteTable *table = NMT_ROUTE_TABLE (g_binding_get_source (binding));
NmtRouteTablePrivate *priv = NMT_ROUTE_TABLE_GET_PRIVATE (table);
int n = GPOINTER_TO_INT (user_data);
- GSList *routes, *nth;
+ GPtrArray *routes;
+ gpointer route;
- nth = g_slist_nth (priv->routes, n);
- if (!nth)
+ if (n >= priv->routes->len)
return FALSE;
+ route = priv->routes->pdata[n];
routes = priv->routes;
priv->routes = NULL;
- if (nth->data) {
+ if (route) {
if (priv->family == AF_INET)
- nm_ip4_route_unref (nth->data);
+ nm_ip4_route_unref (route);
else if (priv->family == AF_INET6)
- nm_ip6_route_unref (nth->data);
- }
- nth->data = g_value_dup_boxed (source_value);
-
- if (priv->family == AF_INET) {
- nm_utils_ip4_routes_to_gvalue (routes, target_value);
- g_slist_free_full (routes, (GDestroyNotify) nm_ip4_route_unref);
- } else if (priv->family == AF_INET6) {
- nm_utils_ip6_routes_to_gvalue (routes, target_value);
- g_slist_free_full (routes, (GDestroyNotify) nm_ip6_route_unref);
+ nm_ip6_route_unref (route);
}
+ routes->pdata[n] = g_value_dup_boxed (source_value);
+ g_value_take_boxed (target_value, routes);
return TRUE;
}
@@ -171,16 +165,16 @@ add_route (NmtWidgetList *list,
route = nm_ip4_route_new ();
nm_ip4_route_set_prefix (route, 32);
- priv->routes = g_slist_append (priv->routes, route);
- nmt_widget_list_set_length (list, g_slist_length (priv->routes));
+ g_ptr_array_add (priv->routes, route);
+ nmt_widget_list_set_length (list, priv->routes->len);
g_object_notify (table, "ip4-routes");
} else {
NMIP6Route *route;
route = nm_ip6_route_new ();
nm_ip6_route_set_prefix (route, 128);
- priv->routes = g_slist_append (priv->routes, route);
- nmt_widget_list_set_length (list, g_slist_length (priv->routes));
+ g_ptr_array_add (priv->routes, route);
+ nmt_widget_list_set_length (list, priv->routes->len);
g_object_notify (table, "ip6-routes");
}
}
@@ -191,16 +185,14 @@ remove_route (NmtWidgetList *list,
gpointer table)
{
NmtRouteTablePrivate *priv = NMT_ROUTE_TABLE_GET_PRIVATE (table);
- GSList *nth;
gpointer route;
- nth = g_slist_nth (priv->routes, num);
- if (!nth)
+ if (num >= priv->routes->len)
return;
- route = nth->data;
- priv->routes = g_slist_delete_link (priv->routes, nth);
- nmt_widget_list_set_length (list, g_slist_length (priv->routes));
+ route = priv->routes->pdata[num];
+ g_ptr_array_remove_index (priv->routes, num);
+ nmt_widget_list_set_length (list, priv->routes->len);
if (priv->family == AF_INET) {
nm_ip4_route_unref (route);
@@ -271,10 +263,7 @@ nmt_route_table_finalize (GObject *object)
{
NmtRouteTablePrivate *priv = NMT_ROUTE_TABLE_GET_PRIVATE (object);
- if (priv->family == AF_INET)
- g_slist_free_full (priv->routes, (GDestroyNotify) nm_ip4_route_unref);
- else if (priv->family == AF_INET6)
- g_slist_free_full (priv->routes, (GDestroyNotify) nm_ip6_route_unref);
+ g_ptr_array_unref (priv->routes);
G_OBJECT_CLASS (nmt_route_table_parent_class)->finalize (object);
}
@@ -286,24 +275,36 @@ nmt_route_table_set_property (GObject *object,
GParamSpec *pspec)
{
NmtRouteTablePrivate *priv = NMT_ROUTE_TABLE_GET_PRIVATE (object);
+ GPtrArray *array;
+ int i;
switch (prop_id) {
case PROP_FAMILY:
priv->family = g_value_get_int (value);
+ if (priv->family == AF_INET)
+ priv->routes = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_ip4_route_unref);
+ else
+ priv->routes = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_ip6_route_unref);
break;
case PROP_IP4_ROUTES:
g_return_if_fail (priv->family == AF_INET);
- g_slist_free_full (priv->routes, (GDestroyNotify) nm_ip4_route_unref);
- priv->routes = nm_utils_ip4_routes_from_gvalue (value);
- nmt_widget_list_set_length (NMT_WIDGET_LIST (priv->list),
- g_slist_length (priv->routes));
+ array = g_value_get_boxed (value);
+ g_ptr_array_set_size (priv->routes, 0);
+ for (i = 0; i < array->len; i++) {
+ nm_ip4_route_ref (array->pdata[i]);
+ g_ptr_array_add (priv->routes, array->pdata[i]);
+ }
+ nmt_widget_list_set_length (NMT_WIDGET_LIST (priv->list), priv->routes->len);
break;
case PROP_IP6_ROUTES:
g_return_if_fail (priv->family == AF_INET6);
- g_slist_free_full (priv->routes, (GDestroyNotify) nm_ip6_route_unref);
- priv->routes = nm_utils_ip6_routes_from_gvalue (value);
- nmt_widget_list_set_length (NMT_WIDGET_LIST (priv->list),
- g_slist_length (priv->routes));
+ array = g_value_get_boxed (value);
+ g_ptr_array_set_size (priv->routes, 0);
+ for (i = 0; i < array->len; i++) {
+ nm_ip6_route_ref (array->pdata[i]);
+ g_ptr_array_add (priv->routes, array->pdata[i]);
+ }
+ nmt_widget_list_set_length (NMT_WIDGET_LIST (priv->list), priv->routes->len);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -325,11 +326,11 @@ nmt_route_table_get_property (GObject *object,
break;
case PROP_IP4_ROUTES:
g_return_if_fail (priv->family == AF_INET);
- nm_utils_ip4_routes_to_gvalue (priv->routes, value);
+ g_value_set_boxed (value, priv->routes);
break;
case PROP_IP6_ROUTES:
g_return_if_fail (priv->family == AF_INET6);
- nm_utils_ip6_routes_to_gvalue (priv->routes, value);
+ g_value_set_boxed (value, priv->routes);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -337,11 +338,6 @@ nmt_route_table_get_property (GObject *object,
}
}
-#define DBUS_TYPE_G_ARRAY_OF_UINT (dbus_g_type_get_collection ("GArray", G_TYPE_UINT))
-#define DBUS_TYPE_G_ARRAY_OF_ARRAY_OF_UINT (dbus_g_type_get_collection ("GPtrArray", DBUS_TYPE_G_ARRAY_OF_UINT))
-#define DBUS_TYPE_G_IP6_ROUTE (dbus_g_type_get_struct ("GValueArray", DBUS_TYPE_G_UCHAR_ARRAY, G_TYPE_UINT, DBUS_TYPE_G_UCHAR_ARRAY, G_TYPE_UINT, G_TYPE_INVALID))
-#define DBUS_TYPE_G_ARRAY_OF_IP6_ROUTE (dbus_g_type_get_collection ("GPtrArray", DBUS_TYPE_G_IP6_ROUTE))
-
static void
nmt_route_table_class_init (NmtRouteTableClass *table_class)
{
@@ -373,11 +369,13 @@ nmt_route_table_class_init (NmtRouteTableClass *table_class)
* #NMSettingIP4Config:routes.
*
* Only valid if #NmtRouteTable:family is %AF_INET
+ *
+ * Element-type: NMIP4Route
*/
g_object_class_install_property
(object_class, PROP_IP4_ROUTES,
g_param_spec_boxed ("ip4-routes", "", "",
- DBUS_TYPE_G_ARRAY_OF_ARRAY_OF_UINT,
+ G_TYPE_PTR_ARRAY,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
/**
@@ -387,11 +385,13 @@ nmt_route_table_class_init (NmtRouteTableClass *table_class)
* #NMSettingIP6Config:routes.
*
* Only valid if #NmtRouteTable:family is %AF_INET6
+ *
+ * Element-type: NMIP6Route
*/
g_object_class_install_property
(object_class, PROP_IP6_ROUTES,
g_param_spec_boxed ("ip6-routes", "", "",
- DBUS_TYPE_G_ARRAY_OF_IP6_ROUTE,
+ G_TYPE_PTR_ARRAY,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
}
diff --git a/libnm-core/nm-core-internal.h b/libnm-core/nm-core-internal.h
index b02bb69850..d5e85e1475 100644
--- a/libnm-core/nm-core-internal.h
+++ b/libnm-core/nm-core-internal.h
@@ -65,5 +65,12 @@ GSList * _nm_utils_hash_values_to_slist (GHashTable *hash);
GHashTable *_nm_utils_copy_strdict (GHashTable *strdict);
+typedef gpointer (*NMUtilsCopyFunc) (gpointer);
+
+GPtrArray *_nm_utils_copy_slist_to_array (const GSList *list,
+ NMUtilsCopyFunc copy_func,
+ GDestroyNotify unref_func);
+GSList *_nm_utils_copy_array_to_slist (const GPtrArray *array,
+ NMUtilsCopyFunc copy_func);
#endif
diff --git a/libnm-core/nm-setting-ip4-config.c b/libnm-core/nm-setting-ip4-config.c
index 1228778cbc..ef31832dc2 100644
--- a/libnm-core/nm-setting-ip4-config.c
+++ b/libnm-core/nm-setting-ip4-config.c
@@ -68,7 +68,7 @@ NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_IP4_CONFIG)
typedef struct {
char *method;
- GArray *dns; /* array of guint32; elements in network byte order */
+ GSList *dns; /* list of IP address strings */
GSList *dns_search; /* list of strings */
GSList *addresses; /* array of NMIP4Address */
GSList *address_labels; /* list of strings */
@@ -139,7 +139,7 @@ nm_setting_ip4_config_get_num_dns (NMSettingIP4Config *setting)
{
g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), 0);
- return NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting)->dns->len;
+ return g_slist_length (NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting)->dns);
}
/**
@@ -147,26 +147,36 @@ nm_setting_ip4_config_get_num_dns (NMSettingIP4Config *setting)
* @setting: the #NMSettingIP4Config
* @i: index number of the DNS server to return
*
- * Returns: the IPv4 address (network byte order) of the DNS server at index
- * @i
+ * Returns: the IPv4 address of the DNS server at index @i
**/
-guint32
+const char *
nm_setting_ip4_config_get_dns (NMSettingIP4Config *setting, guint32 i)
{
NMSettingIP4ConfigPrivate *priv;
- g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), 0);
+ g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), NULL);
priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting);
- g_return_val_if_fail (i <= priv->dns->len, 0);
+ g_return_val_if_fail (i < g_slist_length (priv->dns), NULL);
+
+ return (const char *) g_slist_nth_data (priv->dns, i);
+}
+
+static const char *
+canonicalize_ip (const char *ip)
+{
+ in_addr_t addr;
+ int ret;
- return g_array_index (priv->dns, guint32, i);
+ ret = inet_pton (AF_INET, ip, &addr);
+ g_return_val_if_fail (ret == 1, NULL);
+ return nm_utils_inet4_ntop (addr, NULL);
}
/**
* nm_setting_ip4_config_add_dns:
* @setting: the #NMSettingIP4Config
- * @dns: the IPv4 address (network byte order) of the DNS server to add
+ * @dns: the IPv4 address of the DNS server to add
*
* Adds a new DNS server to the setting.
*
@@ -174,20 +184,27 @@ nm_setting_ip4_config_get_dns (NMSettingIP4Config *setting, guint32 i)
* known
**/
gboolean
-nm_setting_ip4_config_add_dns (NMSettingIP4Config *setting, guint32 dns)
+nm_setting_ip4_config_add_dns (NMSettingIP4Config *setting, const char *dns)
{
NMSettingIP4ConfigPrivate *priv;
- int i;
+ const char *dns_canonical;
+ GSList *iter;
g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), FALSE);
+ g_return_val_if_fail (dns != NULL, FALSE);
+ g_return_val_if_fail (dns[0] != '\0', FALSE);
priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting);
- for (i = 0; i < priv->dns->len; i++) {
- if (dns == g_array_index (priv->dns, guint32, i))
+
+ dns_canonical = canonicalize_ip (dns);
+ g_return_val_if_fail (dns_canonical != NULL, FALSE);
+
+ for (iter = priv->dns; iter; iter = g_slist_next (iter)) {
+ if (!strcmp (dns_canonical, (char *) iter->data))
return FALSE;
}
- g_array_append_val (priv->dns, dns);
+ priv->dns = g_slist_append (priv->dns, g_strdup (dns_canonical));
g_object_notify (G_OBJECT (setting), NM_SETTING_IP4_CONFIG_DNS);
return TRUE;
}
@@ -203,13 +220,16 @@ void
nm_setting_ip4_config_remove_dns (NMSettingIP4Config *setting, guint32 i)
{
NMSettingIP4ConfigPrivate *priv;
+ GSList *elt;
g_return_if_fail (NM_IS_SETTING_IP4_CONFIG (setting));
priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting);
- g_return_if_fail (i <= priv->dns->len);
+ elt = g_slist_nth (priv->dns, i);
+ g_return_if_fail (elt != NULL);
- g_array_remove_index (priv->dns, i);
+ g_free (elt->data);
+ priv->dns = g_slist_delete_link (priv->dns, elt);
g_object_notify (G_OBJECT (setting), NM_SETTING_IP4_CONFIG_DNS);
}
@@ -221,20 +241,26 @@ nm_setting_ip4_config_remove_dns (NMSettingIP4Config *setting, guint32 i)
* Removes the DNS server @dns.
*
* Returns: %TRUE if the DNS server was found and removed; %FALSE if it was not.
- * domain was already known
**/
gboolean
-nm_setting_ip4_config_remove_dns_by_value (NMSettingIP4Config *setting, guint32 dns)
+nm_setting_ip4_config_remove_dns_by_value (NMSettingIP4Config *setting, const char *dns)
{
NMSettingIP4ConfigPrivate *priv;
- int i;
+ const char *dns_canonical;
+ GSList *iter;
g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), FALSE);
+ g_return_val_if_fail (dns != NULL, FALSE);
+ g_return_val_if_fail (dns[0] != '\0', FALSE);
priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting);
- for (i = 0; i < priv->dns->len; i++) {
- if (dns == g_array_index (priv->dns, guint32, i)) {
- g_array_remove_index (priv->dns, i);
+
+ dns_canonical = canonicalize_ip (dns);
+ g_return_val_if_fail (dns_canonical != NULL, FALSE);
+
+ for (iter = priv->dns; iter; iter = g_slist_next (iter)) {
+ if (!strcmp (dns_canonical, (char *) iter->data)) {
+ priv->dns = g_slist_delete_link (priv->dns, iter);
g_object_notify (G_OBJECT (setting), NM_SETTING_IP4_CONFIG_DNS);
return TRUE;
}
@@ -251,12 +277,10 @@ nm_setting_ip4_config_remove_dns_by_value (NMSettingIP4Config *setting, guint32
void
nm_setting_ip4_config_clear_dns (NMSettingIP4Config *setting)
{
- NMSettingIP4ConfigPrivate *priv;
-
g_return_if_fail (NM_IS_SETTING_IP4_CONFIG (setting));
- priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting);
- g_array_remove_range (priv->dns, 0, priv->dns->len);
+ g_slist_free_full (NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting)->dns, g_free);
+ NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting)->dns = NULL;
g_object_notify (G_OBJECT (setting), NM_SETTING_IP4_CONFIG_DNS);
}
@@ -289,7 +313,7 @@ nm_setting_ip4_config_get_dns_search (NMSettingIP4Config *setting, guint32 i)
g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), NULL);
priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting);
- g_return_val_if_fail (i <= g_slist_length (priv->dns_search), NULL);
+ g_return_val_if_fail (i < g_slist_length (priv->dns_search), NULL);
return (const char *) g_slist_nth_data (priv->dns_search, i);
}
@@ -426,7 +450,7 @@ nm_setting_ip4_config_get_address (NMSettingIP4Config *setting, guint32 i)
g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), NULL);
priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting);
- g_return_val_if_fail (i <= g_slist_length (priv->addresses), NULL);
+ g_return_val_if_fail (i < g_slist_length (priv->addresses), NULL);
return (NMIP4Address *) g_slist_nth_data (priv->addresses, i);
}
@@ -439,7 +463,7 @@ _nm_setting_ip4_config_get_address_label (NMSettingIP4Config *setting, guint32 i
g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), NULL);
priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting);
- g_return_val_if_fail (i <= g_slist_length (priv->address_labels), NULL);
+ g_return_val_if_fail (i < g_slist_length (priv->address_labels), NULL);
return (const char *) g_slist_nth_data (priv->address_labels, i);
}
@@ -597,7 +621,7 @@ nm_setting_ip4_config_get_route (NMSettingIP4Config *setting, guint32 i)
g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), NULL);
priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting);
- g_return_val_if_fail (i <= g_slist_length (priv->routes), NULL);
+ g_return_val_if_fail (i < g_slist_length (priv->routes), NULL);
return (NMIP4Route *) g_slist_nth_data (priv->routes, i);
}
@@ -890,7 +914,7 @@ verify (NMSetting *setting, GSList *all_settings, GError **error)
} else if ( !strcmp (priv->method, NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL)
|| !strcmp (priv->method, NM_SETTING_IP4_CONFIG_METHOD_SHARED)
|| !strcmp (priv->method, NM_SETTING_IP4_CONFIG_METHOD_DISABLED)) {
- if (priv->dns && priv->dns->len) {
+ if (priv->dns) {
g_set_error (error,
NM_SETTING_IP4_CONFIG_ERROR,
NM_SETTING_IP4_CONFIG_ERROR_NOT_ALLOWED_FOR_METHOD,
@@ -900,7 +924,7 @@ verify (NMSetting *setting, GSList *all_settings, GError **error)
return FALSE;
}
- if (g_slist_length (priv->dns_search)) {
+ if (priv->dns_search) {
g_set_error (error,
NM_SETTING_IP4_CONFIG_ERROR,
NM_SETTING_IP4_CONFIG_ERROR_NOT_ALLOWED_FOR_METHOD,
@@ -912,7 +936,7 @@ verify (NMSetting *setting, GSList *all_settings, GError **error)
/* Shared allows IP addresses; link-local and disabled do not */
if (strcmp (priv->method, NM_SETTING_IP4_CONFIG_METHOD_SHARED) != 0) {
- if (g_slist_length (priv->addresses)) {
+ if (priv->addresses) {
g_set_error (error,
NM_SETTING_IP4_CONFIG_ERROR,
NM_SETTING_IP4_CONFIG_ERROR_NOT_ALLOWED_FOR_METHOD,
@@ -1027,6 +1051,22 @@ verify (NMSetting *setting, GSList *all_settings, GError **error)
}
}
+ /* Validate DNS */
+ for (iter = priv->dns, i = 0; iter; iter = g_slist_next (iter), i++) {
+ const char *dns = (const char *) iter->data;
+ in_addr_t addr;
+
+ if (inet_pton (AF_INET, dns, &addr) != 1) {
+ g_set_error (error,
+ NM_SETTING_IP4_CONFIG_ERROR,
+ NM_SETTING_IP4_CONFIG_ERROR_INVALID_PROPERTY,
+ _("%d. DNS server address is invalid"),
+ i+1);
+ g_prefix_error (error, "%s.%s: ", NM_SETTING_IP4_CONFIG_SETTING_NAME, NM_SETTING_IP4_CONFIG_DNS);
+ return FALSE;
+ }
+ }
+
return TRUE;
}
@@ -1034,10 +1074,6 @@ verify (NMSetting *setting, GSList *all_settings, GError **error)
static void
nm_setting_ip4_config_init (NMSettingIP4Config *setting)
{
- NMSettingIP4ConfigPrivate *priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting);
-
-
- priv->dns = g_array_sized_new (FALSE, TRUE, sizeof (guint32), 3);
}
static void
@@ -1050,8 +1086,7 @@ finalize (GObject *object)
g_free (priv->dhcp_hostname);
g_free (priv->dhcp_client_id);
- g_array_free (priv->dns, TRUE);
-
+ g_slist_free_full (priv->dns, g_free);
g_slist_free_full (priv->dns_search, g_free);
g_slist_free_full (priv->addresses, (GDestroyNotify) nm_ip4_address_unref);
g_slist_free_full (priv->address_labels, g_free);
@@ -1074,10 +1109,8 @@ set_property (GObject *object, guint prop_id,
priv->method = g_value_dup_string (value);
break;
case PROP_DNS:
- g_array_free (priv->dns, TRUE);
- priv->dns = g_value_dup_boxed (value);
- if (!priv->dns)
- priv->dns = g_array_sized_new (FALSE, TRUE, sizeof (guint32), 3);
+ g_slist_free_full (priv->dns, g_free);
+ priv->dns = _nm_utils_strv_to_slist (g_value_get_boxed (value));
break;
case PROP_DNS_SEARCH:
g_slist_free_full (priv->dns_search, g_free);
@@ -1085,7 +1118,8 @@ set_property (GObject *object, guint prop_id,
break;
case PROP_ADDRESSES:
g_slist_free_full (priv->addresses, (GDestroyNotify) nm_ip4_address_unref);
- priv->addresses = nm_utils_ip4_addresses_from_gvalue (value);
+ priv->addresses = _nm_utils_copy_array_to_slist (g_value_get_boxed (value),
+ (NMUtilsCopyFunc) nm_ip4_address_dup);
if (g_slist_length (priv->addresses) != g_slist_length (priv->address_labels)) {
g_slist_free_full (priv->address_labels, g_free);
@@ -1100,7 +1134,8 @@ set_property (GObject *object, guint prop_id,
break;
case PROP_ROUTES:
g_slist_free_full (priv->routes, (GDestroyNotify) nm_ip4_route_unref);
- priv->routes = nm_utils_ip4_routes_from_gvalue (value);
+ priv->routes = _nm_utils_copy_array_to_slist (g_value_get_boxed (value),
+ (NMUtilsCopyFunc) nm_ip4_route_dup);
break;
case PROP_IGNORE_AUTO_ROUTES:
priv->ignore_auto_routes = g_value_get_boolean (value);
@@ -1143,19 +1178,19 @@ get_property (GObject *object, guint prop_id,
g_value_set_string (value, nm_setting_ip4_config_get_method (setting));
break;
case PROP_DNS:
- g_value_set_boxed (value, priv->dns);
+ g_value_take_boxed (value, _nm_utils_slist_to_strv (priv->dns));
break;
case PROP_DNS_SEARCH:
g_value_take_boxed (value, _nm_utils_slist_to_strv (priv->dns_search));
break;
case PROP_ADDRESSES:
- nm_utils_ip4_addresses_to_gvalue (priv->addresses, value);
+ g_value_take_boxed (value, _nm_utils_copy_slist_to_array (priv->addresses, (NMUtilsCopyFunc) nm_ip4_address_dup, (GDestroyNotify) nm_ip4_address_unref));
break;
case PROP_ADDRESS_LABELS:
g_value_take_boxed (value, _nm_utils_slist_to_strv (priv->address_labels));
break;
case PROP_ROUTES:
- nm_utils_ip4_routes_to_gvalue (priv->routes, value);
+ g_value_take_boxed (value, _nm_utils_copy_slist_to_array (priv->routes, (NMUtilsCopyFunc) nm_ip4_route_dup, (GDestroyNotify) nm_ip4_route_unref));
break;
case PROP_IGNORE_AUTO_ROUTES:
g_value_set_boolean (value, nm_setting_ip4_config_get_ignore_auto_routes (setting));
@@ -1196,7 +1231,7 @@ nm_setting_ip4_config_class_init (NMSettingIP4ConfigClass *setting_class)
object_class->set_property = set_property;
object_class->get_property = get_property;
object_class->finalize = finalize;
- parent_class->verify = verify;
+ parent_class->verify = verify;
/* Properties */
/**
@@ -1226,7 +1261,7 @@ nm_setting_ip4_config_class_init (NMSettingIP4ConfigClass *setting_class)
/**
* NMSettingIP4Config:dns:
*
- * List of DNS servers (network byte order). For the "auto" method, these
+ * Array of IPv4 addresses of DNS servers. For the 'auto' method, these
* DNS servers are appended to those (if any) returned by automatic
* configuration. DNS servers cannot be used with the "shared",
* "link-local", or "disabled" methods as there is no upstream network. In
@@ -1236,9 +1271,13 @@ nm_setting_ip4_config_class_init (NMSettingIP4ConfigClass *setting_class)
g_object_class_install_property
(object_class, PROP_DNS,
g_param_spec_boxed (NM_SETTING_IP4_CONFIG_DNS, "", "",
- DBUS_TYPE_G_UINT_ARRAY,
+ G_TYPE_STRV,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
+ _nm_setting_class_transform_property (parent_class, NM_SETTING_IP4_CONFIG_DNS,
+ DBUS_TYPE_G_UINT_ARRAY,
+ _nm_utils_ip4_dns_to_dbus,
+ _nm_utils_ip4_dns_from_dbus);
/**
* NMSettingIP4Config:dns-search:
@@ -1259,22 +1298,25 @@ nm_setting_ip4_config_class_init (NMSettingIP4ConfigClass *setting_class)
/**
* NMSettingIP4Config:addresses:
*
- * Array of IPv4 address structures. Each IPv4 address structure is
- * composed of 3 32-bit values; the first being the IPv4 address (network
- * byte order), the second the prefix (1 - 32), and last the IPv4 gateway
- * (network byte order). The gateway may be left as 0 if no gateway exists
- * for that subnet. For the "auto" method, given IP addresses are appended
+ * Array of IPv4 addresses. The gateway may be left as 0 if no gateway exists
+ * for that subnet. For the 'auto' method, given IP addresses are appended
* to those returned by automatic configuration. Addresses cannot be used
* with the "shared", "link-local", or "disabled" methods as addressing is
* either automatic or disabled with these methods.
+ *
+ * Element-Type: NMIP4Address
**/
g_object_class_install_property
(object_class, PROP_ADDRESSES,
g_param_spec_boxed (NM_SETTING_IP4_CONFIG_ADDRESSES, "", "",
- DBUS_TYPE_G_ARRAY_OF_ARRAY_OF_UINT,
+ G_TYPE_PTR_ARRAY,
G_PARAM_READWRITE |
NM_SETTING_PARAM_INFERRABLE |
G_PARAM_STATIC_STRINGS));
+ _nm_setting_class_transform_property (parent_class, NM_SETTING_IP4_CONFIG_ADDRESSES,
+ DBUS_TYPE_G_ARRAY_OF_ARRAY_OF_UINT,
+ _nm_utils_ip4_addresses_to_dbus,
+ _nm_utils_ip4_addresses_from_dbus);
/**
* NMSettingIP4Config:address-labels:
@@ -1292,22 +1334,24 @@ nm_setting_ip4_config_class_init (NMSettingIP4ConfigClass *setting_class)
/**
* NMSettingIP4Config:routes:
*
- * Array of IPv4 route structures. Each IPv4 route structure is composed of
- * 4 32-bit values; the first being the destination IPv4 network or address
- * (network byte order), the second the destination network or address
- * prefix (1 - 32), the third being the next-hop (network byte order) if
- * any, and the fourth being the route metric. For the "auto" method, given
- * IP routes are appended to those returned by automatic configuration.
- * Routes cannot be used with the "shared", "link-local", or "disabled"
- * methods because there is no upstream network.
+ * Array of IPv4 routes. For the 'auto' method, given IP routes are appended
+ * to those returned by automatic configuration. Routes cannot be used with
+ * the 'shared', 'link-local', or 'disabled' methods because there is no
+ * upstream network.
+ *
+ * Element-Type: NMIP4Route
**/
g_object_class_install_property
(object_class, PROP_ROUTES,
g_param_spec_boxed (NM_SETTING_IP4_CONFIG_ROUTES, "", "",
- DBUS_TYPE_G_ARRAY_OF_ARRAY_OF_UINT,
+ G_TYPE_PTR_ARRAY,
G_PARAM_READWRITE |
NM_SETTING_PARAM_INFERRABLE |
G_PARAM_STATIC_STRINGS));
+ _nm_setting_class_transform_property (parent_class, NM_SETTING_IP4_CONFIG_ROUTES,
+ DBUS_TYPE_G_ARRAY_OF_ARRAY_OF_UINT,
+ _nm_utils_ip4_routes_to_dbus,
+ _nm_utils_ip4_routes_from_dbus);
/**
* NMSettingIP4Config:ignore-auto-routes:
diff --git a/libnm-core/nm-setting-ip4-config.h b/libnm-core/nm-setting-ip4-config.h
index 1caa563ddb..4891571131 100644
--- a/libnm-core/nm-setting-ip4-config.h
+++ b/libnm-core/nm-setting-ip4-config.h
@@ -184,10 +184,10 @@ NMSetting * nm_setting_ip4_config_new (void);
const char * nm_setting_ip4_config_get_method (NMSettingIP4Config *setting);
guint32 nm_setting_ip4_config_get_num_dns (NMSettingIP4Config *setting);
-guint32 nm_setting_ip4_config_get_dns (NMSettingIP4Config *setting, guint32 i);
-gboolean nm_setting_ip4_config_add_dns (NMSettingIP4Config *setting, guint32 dns);
+const char * nm_setting_ip4_config_get_dns (NMSettingIP4Config *setting, guint32 i);
+gboolean nm_setting_ip4_config_add_dns (NMSettingIP4Config *setting, const char *dns);
void nm_setting_ip4_config_remove_dns (NMSettingIP4Config *setting, guint32 i);
-gboolean nm_setting_ip4_config_remove_dns_by_value (NMSettingIP4Config *setting, guint32 dns);
+gboolean nm_setting_ip4_config_remove_dns_by_value (NMSettingIP4Config *setting, const char *dns);
void nm_setting_ip4_config_clear_dns (NMSettingIP4Config *setting);
guint32 nm_setting_ip4_config_get_num_dns_searches (NMSettingIP4Config *setting);
diff --git a/libnm-core/nm-setting-ip6-config.c b/libnm-core/nm-setting-ip6-config.c
index a17e3620c3..6c085404d0 100644
--- a/libnm-core/nm-setting-ip6-config.c
+++ b/libnm-core/nm-setting-ip6-config.c
@@ -161,18 +161,28 @@ nm_setting_ip6_config_get_num_dns (NMSettingIP6Config *setting)
*
* Returns: (transfer none): the IPv6 address of the DNS server at index @i
**/
-const struct in6_addr *
+const char *
nm_setting_ip6_config_get_dns (NMSettingIP6Config *setting, guint32 i)
{
NMSettingIP6ConfigPrivate *priv;
-
g_return_val_if_fail (NM_IS_SETTING_IP6_CONFIG (setting), NULL);
priv = NM_SETTING_IP6_CONFIG_GET_PRIVATE (setting);
- g_return_val_if_fail (i <= g_slist_length (priv->dns), NULL);
+ g_return_val_if_fail (i < g_slist_length (priv->dns), NULL);
+
+ return (const char *) g_slist_nth_data (priv->dns, i);
+}
+
+static const char *
+canonicalize_ip (const char *ip)
+{
+ struct in6_addr addr;
+ int ret;
- return (const struct in6_addr *) g_slist_nth_data (priv->dns, i);
+ ret = inet_pton (AF_INET6, ip, &addr);
+ g_return_val_if_fail (ret == 1, NULL);
+ return nm_utils_inet6_ntop (&addr, NULL);
}
/**
@@ -186,25 +196,28 @@ nm_setting_ip6_config_get_dns (NMSettingIP6Config *setting, guint32 i)
* known
**/
gboolean
-nm_setting_ip6_config_add_dns (NMSettingIP6Config *setting, const struct in6_addr *addr)
+nm_setting_ip6_config_add_dns (NMSettingIP6Config *setting, const char *dns)
{
NMSettingIP6ConfigPrivate *priv;
- struct in6_addr *copy;
+ const char *dns_canonical;
GSList *iter;
g_return_val_if_fail (NM_IS_SETTING_IP6_CONFIG (setting), FALSE);
+ g_return_val_if_fail (dns != NULL, FALSE);
+ g_return_val_if_fail (dns[0] != '\0', FALSE);
priv = NM_SETTING_IP6_CONFIG_GET_PRIVATE (setting);
+
+ dns_canonical = canonicalize_ip (dns);
+ g_return_val_if_fail (dns_canonical != NULL, FALSE);
+
for (iter = priv->dns; iter; iter = g_slist_next (iter)) {
- if (!memcmp (addr, (struct in6_addr *) iter->data, sizeof (struct in6_addr)))
+ if (!strcmp (dns_canonical, (char *) iter->data))
return FALSE;
}
- copy = g_malloc0 (sizeof (struct in6_addr));
- memcpy (copy, addr, sizeof (struct in6_addr));
- priv->dns = g_slist_append (priv->dns, copy);
+ priv->dns = g_slist_append (priv->dns, g_strdup (dns_canonical));
g_object_notify (G_OBJECT (setting), NM_SETTING_IP6_CONFIG_DNS);
-
return TRUE;
}
@@ -243,16 +256,23 @@ nm_setting_ip6_config_remove_dns (NMSettingIP6Config *setting, guint32 i)
**/
gboolean
nm_setting_ip6_config_remove_dns_by_value (NMSettingIP6Config *setting,
- const struct in6_addr *addr)
+ const char *dns)
{
NMSettingIP6ConfigPrivate *priv;
+ const char *dns_canonical;
GSList *iter;
g_return_val_if_fail (NM_IS_SETTING_IP6_CONFIG (setting), FALSE);
+ g_return_val_if_fail (dns != NULL, FALSE);
+ g_return_val_if_fail (dns[0] != '\0', FALSE);
priv = NM_SETTING_IP6_CONFIG_GET_PRIVATE (setting);
+
+ dns_canonical = canonicalize_ip (dns);
+ g_return_val_if_fail (dns_canonical != NULL, FALSE);
+
for (iter = priv->dns; iter; iter = g_slist_next (iter)) {
- if (!memcmp (addr, (struct in6_addr *) iter->data, sizeof (struct in6_addr))) {
+ if (!strcmp (dns_canonical, (char *) iter->data)) {
priv->dns = g_slist_delete_link (priv->dns, iter);
g_object_notify (G_OBJECT (setting), NM_SETTING_IP6_CONFIG_DNS);
return TRUE;
@@ -306,7 +326,7 @@ nm_setting_ip6_config_get_dns_search (NMSettingIP6Config *setting, guint32 i)
g_return_val_if_fail (NM_IS_SETTING_IP6_CONFIG (setting), NULL);
priv = NM_SETTING_IP6_CONFIG_GET_PRIVATE (setting);
- g_return_val_if_fail (i <= g_slist_length (priv->dns_search), NULL);
+ g_return_val_if_fail (i < g_slist_length (priv->dns_search), NULL);
return (const char *) g_slist_nth_data (priv->dns_search, i);
}
@@ -443,7 +463,7 @@ nm_setting_ip6_config_get_address (NMSettingIP6Config *setting, guint32 i)
g_return_val_if_fail (NM_IS_SETTING_IP6_CONFIG (setting), NULL);
priv = NM_SETTING_IP6_CONFIG_GET_PRIVATE (setting);
- g_return_val_if_fail (i <= g_slist_length (priv->addresses), NULL);
+ g_return_val_if_fail (i < g_slist_length (priv->addresses), NULL);
return (NMIP6Address *) g_slist_nth_data (priv->addresses, i);
}
@@ -583,7 +603,7 @@ nm_setting_ip6_config_get_route (NMSettingIP6Config *setting, guint32 i)
g_return_val_if_fail (NM_IS_SETTING_IP6_CONFIG (setting), NULL);
priv = NM_SETTING_IP6_CONFIG_GET_PRIVATE (setting);
- g_return_val_if_fail (i <= g_slist_length (priv->routes), NULL);
+ g_return_val_if_fail (i < g_slist_length (priv->routes), NULL);
return (NMIP6Route *) g_slist_nth_data (priv->routes, i);
}
@@ -787,6 +807,8 @@ static gboolean
verify (NMSetting *setting, GSList *all_settings, GError **error)
{
NMSettingIP6ConfigPrivate *priv = NM_SETTING_IP6_CONFIG_GET_PRIVATE (setting);
+ GSList *iter;
+ int i;
if (!priv->method) {
g_set_error_literal (error,
@@ -810,7 +832,7 @@ verify (NMSetting *setting, GSList *all_settings, GError **error)
} else if ( !strcmp (priv->method, NM_SETTING_IP6_CONFIG_METHOD_IGNORE)
|| !strcmp (priv->method, NM_SETTING_IP6_CONFIG_METHOD_LINK_LOCAL)
|| !strcmp (priv->method, NM_SETTING_IP6_CONFIG_METHOD_SHARED)) {
- if (g_slist_length (priv->dns)) {
+ if (priv->dns) {
g_set_error (error,
NM_SETTING_IP6_CONFIG_ERROR,
NM_SETTING_IP6_CONFIG_ERROR_NOT_ALLOWED_FOR_METHOD,
@@ -821,7 +843,7 @@ verify (NMSetting *setting, GSList *all_settings, GError **error)
return FALSE;
}
- if (g_slist_length (priv->dns_search)) {
+ if (priv->dns_search) {
g_set_error (error,
NM_SETTING_IP6_CONFIG_ERROR,
NM_SETTING_IP6_CONFIG_ERROR_NOT_ALLOWED_FOR_METHOD,
@@ -831,7 +853,7 @@ verify (NMSetting *setting, GSList *all_settings, GError **error)
return FALSE;
}
- if (g_slist_length (priv->addresses)) {
+ if (priv->addresses) {
g_set_error (error,
NM_SETTING_IP6_CONFIG_ERROR,
NM_SETTING_IP6_CONFIG_ERROR_NOT_ALLOWED_FOR_METHOD,
@@ -861,6 +883,21 @@ verify (NMSetting *setting, GSList *all_settings, GError **error)
return FALSE;
}
+ for (iter = priv->dns, i = 0; iter; iter = g_slist_next (iter), i++) {
+ const char *dns = (const char *) iter->data;
+ struct in6_addr addr;
+
+ if (inet_pton (AF_INET6, dns, &addr) != 1) {
+ g_set_error (error,
+ NM_SETTING_IP6_CONFIG_ERROR,
+ NM_SETTING_IP6_CONFIG_ERROR_INVALID_PROPERTY,
+ _("%d. DNS server address is invalid"),
+ i+1);
+ g_prefix_error (error, "%s.%s: ", NM_SETTING_IP6_CONFIG_SETTING_NAME, NM_SETTING_IP6_CONFIG_DNS);
+ return FALSE;
+ }
+ }
+
return TRUE;
}
@@ -899,19 +936,21 @@ set_property (GObject *object, guint prop_id,
break;
case PROP_DNS:
g_slist_free_full (priv->dns, g_free);
- priv->dns = nm_utils_ip6_dns_from_gvalue (value);
+ priv->dns = _nm_utils_strv_to_slist (g_value_get_boxed (value));
break;
case PROP_DNS_SEARCH:
g_slist_free_full (priv->dns_search, g_free);
priv->dns_search = _nm_utils_strv_to_slist (g_value_get_boxed (value));
break;
case PROP_ADDRESSES:
- g_slist_free_full (priv->addresses, g_free);
- priv->addresses = nm_utils_ip6_addresses_from_gvalue (value);
+ g_slist_free_full (priv->routes, (GDestroyNotify) nm_ip6_address_unref);
+ priv->addresses = _nm_utils_copy_array_to_slist (g_value_get_boxed (value),
+ (NMUtilsCopyFunc) nm_ip6_address_dup);
break;
case PROP_ROUTES:
- g_slist_free_full (priv->routes, g_free);
- priv->routes = nm_utils_ip6_routes_from_gvalue (value);
+ g_slist_free_full (priv->routes, (GDestroyNotify) nm_ip6_route_unref);
+ priv->routes = _nm_utils_copy_array_to_slist (g_value_get_boxed (value),
+ (NMUtilsCopyFunc) nm_ip6_route_dup);
break;
case PROP_IGNORE_AUTO_ROUTES:
priv->ignore_auto_routes = g_value_get_boolean (value);
@@ -949,16 +988,16 @@ get_property (GObject *object, guint prop_id,
g_value_set_string (value, priv->method);
break;
case PROP_DNS:
- nm_utils_ip6_dns_to_gvalue (priv->dns, value);
+ g_value_take_boxed (value, _nm_utils_slist_to_strv (priv->dns));
break;
case PROP_DNS_SEARCH:
g_value_take_boxed (value, _nm_utils_slist_to_strv (priv->dns_search));
break;
case PROP_ADDRESSES:
- nm_utils_ip6_addresses_to_gvalue (priv->addresses, value);
+ g_value_take_boxed (value, _nm_utils_copy_slist_to_array (priv->addresses, (NMUtilsCopyFunc) nm_ip6_address_dup, (GDestroyNotify) nm_ip6_address_unref));
break;
case PROP_ROUTES:
- nm_utils_ip6_routes_to_gvalue (priv->routes, value);
+ g_value_take_boxed (value, _nm_utils_copy_slist_to_array (priv->routes, (NMUtilsCopyFunc) nm_ip6_route_dup, (GDestroyNotify) nm_ip6_route_unref));
break;
case PROP_IGNORE_AUTO_ROUTES:
g_value_set_boolean (value, priv->ignore_auto_routes);
@@ -996,7 +1035,7 @@ nm_setting_ip6_config_class_init (NMSettingIP6ConfigClass *setting_class)
object_class->set_property = set_property;
object_class->get_property = get_property;
object_class->finalize = finalize;
- parent_class->verify = verify;
+ parent_class->verify = verify;
/* Properties */
/**
@@ -1037,20 +1076,23 @@ nm_setting_ip6_config_class_init (NMSettingIP6ConfigClass *setting_class)
/**
* NMSettingIP6Config:dns:
*
- * Array of DNS servers, where each member of the array is a byte array
- * containing the IPv6 address of the DNS server (in network byte order).
- * For the "auto" method, these DNS servers are appended to those (if any)
- * returned by automatic configuration. DNS servers cannot be used with the
- * "shared" or "link-local" methods as there is no usptream network. In all
- * other methods, these DNS servers are used as the only DNS servers for
- * this connection.
+ * Array of IPv6 addresses of DNS servers. For the "auto" method, these DNS
+ * servers are appended to those (if any) returned by automatic
+ * configuration. DNS servers cannot be used with the "shared" or
+ * "link-local" methods as there is no usptream network. In all other
+ * methods, these DNS servers are used as the only DNS servers for this
+ * connection.
**/
g_object_class_install_property
(object_class, PROP_DNS,
g_param_spec_boxed (NM_SETTING_IP6_CONFIG_DNS, "", "",
- DBUS_TYPE_G_ARRAY_OF_ARRAY_OF_UCHAR,
+ G_TYPE_STRV,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
+ _nm_setting_class_transform_property (parent_class, NM_SETTING_IP6_CONFIG_DNS,
+ DBUS_TYPE_G_ARRAY_OF_ARRAY_OF_UCHAR,
+ _nm_utils_ip6_dns_to_dbus,
+ _nm_utils_ip6_dns_from_dbus);
/**
* NMSettingIP6Config:dns-search:
@@ -1071,44 +1113,45 @@ nm_setting_ip6_config_class_init (NMSettingIP6ConfigClass *setting_class)
/**
* NMSettingIP6Config:addresses:
*
- * Array of IPv6 address structures. Each IPv6 address structure is
- * composed of 3 members, the first being a byte array containing the IPv6
- * address (network byte order), the second a 32-bit integer containing the
- * IPv6 address prefix, and the third a byte array containing the IPv6
- * address (network byte order) of the gateway associated with this address,
- * if any. If no gateway is given, the third element should be given as all
- * zeros. For the "auto" method, given IP addresses are appended to those
- * returned by automatic configuration. Addresses cannot be used with the
- * "shared" or "link-local" methods as the interface is automatically
- * assigned an address with these methods.
+ * Array of IPv6 addresses. For the 'auto' method, given IP addresses are
+ * appended to those returned by automatic configuration. Addresses cannot
+ * be used with the 'shared' or 'link-local' methods as the interface is
+ * automatically assigned an address with these methods.
+ *
+ * Element-Type: NMIP6Address
**/
g_object_class_install_property
(object_class, PROP_ADDRESSES,
g_param_spec_boxed (NM_SETTING_IP6_CONFIG_ADDRESSES, "", "",
- DBUS_TYPE_G_ARRAY_OF_IP6_ADDRESS,
+ G_TYPE_PTR_ARRAY,
G_PARAM_READWRITE |
NM_SETTING_PARAM_INFERRABLE |
G_PARAM_STATIC_STRINGS));
+ _nm_setting_class_transform_property (parent_class, NM_SETTING_IP6_CONFIG_ADDRESSES,
+ DBUS_TYPE_G_ARRAY_OF_IP6_ADDRESS,
+ _nm_utils_ip6_addresses_to_dbus,
+ _nm_utils_ip6_addresses_from_dbus);
/**
* NMSettingIP6Config:routes:
*
- * Array of IPv6 route structures. Each IPv6 route structure is composed of
- * 4 members; the first being the destination IPv6 network or address
- * (network byte order) as a byte array, the second the destination network
- * or address IPv6 prefix, the third being the next-hop IPv6 address
- * (network byte order) if any, and the fourth being the route metric. For
- * the "auto" method, given IP routes are appended to those returned by
- * automatic configuration. Routes cannot be used with the "shared" or
- * "link-local" methods because there is no upstream network.
+ * Array of IPv6 routes. For the 'auto' method, given IP routes are appended
+ * to those returned by automatic configuration. Routes cannot be used with
+ * the 'shared' or 'link-local' methods because there is no upstream network.
+ *
+ * Element-Type: NMIP6Route
**/
g_object_class_install_property
(object_class, PROP_ROUTES,
g_param_spec_boxed (NM_SETTING_IP6_CONFIG_ROUTES, "", "",
- DBUS_TYPE_G_ARRAY_OF_IP6_ROUTE,
+ G_TYPE_PTR_ARRAY,
G_PARAM_READWRITE |
NM_SETTING_PARAM_INFERRABLE |
G_PARAM_STATIC_STRINGS));
+ _nm_setting_class_transform_property (parent_class, NM_SETTING_IP6_CONFIG_ROUTES,
+ DBUS_TYPE_G_ARRAY_OF_IP6_ROUTE,
+ _nm_utils_ip6_routes_to_dbus,
+ _nm_utils_ip6_routes_from_dbus);
/**
* NMSettingIP6Config:ignore-auto-routes:
diff --git a/libnm-core/nm-setting-ip6-config.h b/libnm-core/nm-setting-ip6-config.h
index 2dc9c8dde2..349cc36a48 100644
--- a/libnm-core/nm-setting-ip6-config.h
+++ b/libnm-core/nm-setting-ip6-config.h
@@ -214,10 +214,10 @@ NMSetting * nm_setting_ip6_config_new (void);
const char * nm_setting_ip6_config_get_method (NMSettingIP6Config *setting);
guint32 nm_setting_ip6_config_get_num_dns (NMSettingIP6Config *setting);
-const struct in6_addr *nm_setting_ip6_config_get_dns (NMSettingIP6Config *setting, guint32 i);
-gboolean nm_setting_ip6_config_add_dns (NMSettingIP6Config *setting, const struct in6_addr *dns);
+const char * nm_setting_ip6_config_get_dns (NMSettingIP6Config *setting, guint32 i);
+gboolean nm_setting_ip6_config_add_dns (NMSettingIP6Config *setting, const char *dns);
void nm_setting_ip6_config_remove_dns (NMSettingIP6Config *setting, guint32 i);
-gboolean nm_setting_ip6_config_remove_dns_by_value (NMSettingIP6Config *setting, const struct in6_addr *dns);
+gboolean nm_setting_ip6_config_remove_dns_by_value (NMSettingIP6Config *setting, const char *dns);
void nm_setting_ip6_config_clear_dns (NMSettingIP6Config *setting);
guint32 nm_setting_ip6_config_get_num_dns_searches (NMSettingIP6Config *setting);
diff --git a/libnm-core/nm-utils-private.h b/libnm-core/nm-utils-private.h
index 9154a40598..8e3f958b3c 100644
--- a/libnm-core/nm-utils-private.h
+++ b/libnm-core/nm-utils-private.h
@@ -44,6 +44,32 @@ void _nm_utils_strdict_to_dbus (const GValue *prop_value,
void _nm_utils_strdict_from_dbus (const GValue *dbus_value,
GValue *prop_value);
+void _nm_utils_ip4_dns_to_dbus (const GValue *prop_value,
+ GValue *dbus_value);
+void _nm_utils_ip4_dns_from_dbus (const GValue *dbus_value,
+ GValue *prop_value);
+void _nm_utils_ip4_addresses_to_dbus (const GValue *prop_value,
+ GValue *dbus_value);
+void _nm_utils_ip4_addresses_from_dbus (const GValue *dbus_value,
+ GValue *prop_value);
+void _nm_utils_ip4_routes_to_dbus (const GValue *prop_value,
+ GValue *dbus_value);
+void _nm_utils_ip4_routes_from_dbus (const GValue *dbus_value,
+ GValue *prop_value);
+
+void _nm_utils_ip6_dns_to_dbus (const GValue *prop_value,
+ GValue *dbus_value);
+void _nm_utils_ip6_dns_from_dbus (const GValue *dbus_value,
+ GValue *prop_value);
+void _nm_utils_ip6_addresses_to_dbus (const GValue *prop_value,
+ GValue *dbus_value);
+void _nm_utils_ip6_addresses_from_dbus (const GValue *dbus_value,
+ GValue *prop_value);
+void _nm_utils_ip6_routes_to_dbus (const GValue *prop_value,
+ GValue *dbus_value);
+void _nm_utils_ip6_routes_from_dbus (const GValue *dbus_value,
+ GValue *prop_value);
+
GSList * _nm_utils_strv_to_slist (char **strv);
char ** _nm_utils_slist_to_strv (GSList *slist);
diff --git a/libnm-core/nm-utils.c b/libnm-core/nm-utils.c
index 444a5d71e8..d4f1dff456 100644
--- a/libnm-core/nm-utils.c
+++ b/libnm-core/nm-utils.c
@@ -594,6 +594,36 @@ _nm_utils_copy_strdict (GHashTable *strdict)
return copy;
}
+GPtrArray *
+_nm_utils_copy_slist_to_array (const GSList *list,
+ NMUtilsCopyFunc copy_func,
+ GDestroyNotify unref_func)
+{
+ const GSList *iter;
+ GPtrArray *array;
+
+ array = g_ptr_array_new_with_free_func (unref_func);
+ for (iter = list; iter; iter = iter->next)
+ g_ptr_array_add (array, copy_func (iter->data));
+ return array;
+}
+
+GSList *
+_nm_utils_copy_array_to_slist (const GPtrArray *array,
+ NMUtilsCopyFunc copy_func)
+{
+ GSList *slist = NULL;
+ gpointer item;
+ int i;
+
+ for (i = 0; i < array->len; i++) {
+ item = array->pdata[i];
+ slist = g_slist_prepend (slist, copy_func (item));
+ }
+
+ return g_slist_reverse (slist);
+}
+
GSList *
_nm_utils_strv_to_slist (char **strv)
{
@@ -956,6 +986,191 @@ nm_utils_wpa_psk_valid (const char *psk)
return TRUE;
}
+void
+_nm_utils_ip4_dns_to_dbus (const GValue *prop_value,
+ GValue *dbus_value)
+{
+ char **dns;
+ int i;
+ GArray *array;
+
+ dns = g_value_get_boxed (prop_value);
+ array = g_array_new (FALSE, FALSE, sizeof (guint32));
+
+ if (dns) {
+ for (i = 0; dns[i]; i++) {
+ guint32 ip = 0;
+
+ inet_pton (AF_INET, dns[i], &ip);
+ g_array_append_val (array, ip);
+ }
+ }
+
+ g_value_take_boxed (dbus_value, array);
+}
+
+void
+_nm_utils_ip4_dns_from_dbus (const GValue *dbus_value,
+ GValue *prop_value)
+{
+ GArray *array;
+ GPtrArray *dns;
+ int i;
+
+ array = g_value_get_boxed (dbus_value);
+ dns = g_ptr_array_new ();
+
+ if (array) {
+ for (i = 0; i < array->len; i++) {
+ guint32 ip = g_array_index (array, guint32, i);
+ const char *str;
+
+ str = nm_utils_inet4_ntop (ip, NULL);
+ g_ptr_array_add (dns, g_strdup (str));
+ }
+ }
+
+ g_ptr_array_add (dns, NULL);
+ g_value_take_boxed (prop_value, g_ptr_array_free (dns, FALSE));
+}
+
+void
+_nm_utils_ip4_addresses_to_dbus (const GValue *prop_value,
+ GValue *dbus_value)
+{
+ GPtrArray *addresses, *dbus_addresses;
+ int i;
+
+ addresses = g_value_get_boxed (prop_value);
+ dbus_addresses = g_ptr_array_new ();
+
+ if (addresses) {
+ for (i = 0; i < addresses->len; i++) {
+ NMIP4Address *addr = addresses->pdata[i];
+ GArray *array;
+ guint32 tmp;
+
+ array = g_array_sized_new (FALSE, TRUE, sizeof (guint32), 3);
+
+ tmp = nm_ip4_address_get_address (addr);
+ g_array_append_val (array, tmp);
+
+ tmp = nm_ip4_address_get_prefix (addr);
+ g_array_append_val (array, tmp);
+
+ tmp = nm_ip4_address_get_gateway (addr);
+ g_array_append_val (array, tmp);
+
+ g_ptr_array_add (dbus_addresses, array);
+ }
+ }
+
+ g_value_take_boxed (dbus_value, dbus_addresses);
+}
+
+void
+_nm_utils_ip4_addresses_from_dbus (const GValue *dbus_value,
+ GValue *prop_value)
+{
+ GPtrArray *dbus_addresses;
+ GPtrArray *addresses;
+ int i;
+
+ dbus_addresses = g_value_get_boxed (dbus_value);
+ addresses = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_ip4_address_unref);
+
+ if (dbus_addresses) {
+ for (i = 0; i < dbus_addresses->len; i++) {
+ GArray *array = dbus_addresses->pdata[i];
+ NMIP4Address *addr;
+
+ if (array->len < 3) {
+ g_warning ("Ignoring invalid IP4 address");
+ continue;
+ }
+
+ addr = nm_ip4_address_new ();
+ nm_ip4_address_set_address (addr, g_array_index (array, guint32, 0));
+ nm_ip4_address_set_prefix (addr, g_array_index (array, guint32, 1));
+ nm_ip4_address_set_gateway (addr, g_array_index (array, guint32, 2));
+
+ g_ptr_array_add (addresses, addr);
+ }
+ }
+
+ g_value_take_boxed (prop_value, addresses);
+}
+
+void
+_nm_utils_ip4_routes_to_dbus (const GValue *prop_value,
+ GValue *dbus_value)
+{
+ GPtrArray *routes, *dbus_routes;
+ int i;
+
+ routes = g_value_get_boxed (prop_value);
+ dbus_routes = g_ptr_array_new ();
+
+ if (routes) {
+ for (i = 0; i < routes->len; i++) {
+ NMIP4Route *route = routes->pdata[i];
+ GArray *array;
+ guint32 tmp;
+
+ array = g_array_sized_new (FALSE, TRUE, sizeof (guint32), 4);
+
+ tmp = nm_ip4_route_get_dest (route);
+ g_array_append_val (array, tmp);
+
+ tmp = nm_ip4_route_get_prefix (route);
+ g_array_append_val (array, tmp);
+
+ tmp = nm_ip4_route_get_next_hop (route);
+ g_array_append_val (array, tmp);
+
+ tmp = nm_ip4_route_get_metric (route);
+ g_array_append_val (array, tmp);
+
+ g_ptr_array_add (dbus_routes, array);
+ }
+ }
+
+ g_value_take_boxed (dbus_value, dbus_routes);
+}
+
+void
+_nm_utils_ip4_routes_from_dbus (const GValue *dbus_value,
+ GValue *prop_value)
+{
+ GPtrArray *dbus_routes, *routes;
+ int i;
+
+ dbus_routes = g_value_get_boxed (dbus_value);
+ routes = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_ip4_route_unref);
+
+ if (dbus_routes) {
+ for (i = 0; i < dbus_routes->len; i++) {
+ GArray *array = dbus_routes->pdata[i];
+ NMIP4Route *route;
+
+ if (array->len < 4) {
+ g_warning ("Ignoring invalid IP4 route");
+ continue;
+ }
+
+ route = nm_ip4_route_new ();
+ nm_ip4_route_set_dest (route, g_array_index (array, guint32, 0));
+ nm_ip4_route_set_prefix (route, g_array_index (array, guint32, 1));
+ nm_ip4_route_set_next_hop (route, g_array_index (array, guint32, 2));
+ nm_ip4_route_set_metric (route, g_array_index (array, guint32, 3));
+
+ g_ptr_array_add (routes, route);
+ }
+ }
+
+ g_value_take_boxed (prop_value, routes);
+}
+
/**
* nm_utils_ip4_addresses_from_gvalue:
* @value: #GValue containing a #GPtrArray of #GArrays of #guint32s
@@ -1195,6 +1410,289 @@ nm_utils_ip4_get_default_prefix (guint32 ip)
return 24; /* Class C - 255.255.255.0 */
}
+void
+_nm_utils_ip6_dns_to_dbus (const GValue *prop_value,
+ GValue *dbus_value)
+{
+ char **dns;
+ GPtrArray *dbus_dns;
+ int i;
+
+ dns = g_value_get_boxed (prop_value);
+ dbus_dns = g_ptr_array_new ();
+
+ if (dns) {
+ for (i = 0; dns[i]; i++) {
+ GByteArray *bytearray;
+
+ bytearray = g_byte_array_new ();
+ g_byte_array_set_size (bytearray, 16);
+ inet_pton (AF_INET6, dns[i], bytearray->data);
+ g_ptr_array_add (dbus_dns, bytearray);
+ }
+ }
+
+ g_value_take_boxed (dbus_value, dbus_dns);
+}
+
+void
+_nm_utils_ip6_dns_from_dbus (const GValue *dbus_value,
+ GValue *prop_value)
+{
+ GPtrArray *dbus_dns, *dns;
+ int i;
+
+ dbus_dns = g_value_get_boxed (dbus_value);
+ dns = g_ptr_array_new ();
+
+ if (dbus_dns) {
+ for (i = 0; i < dbus_dns->len; i++) {
+ GByteArray *bytearray = dbus_dns->pdata[i];
+ const char *str;
+
+ if (bytearray->len != 16) {
+ g_warning ("%s: ignoring invalid IP6 address of length %d",
+ __func__, bytearray->len);
+ continue;
+ }
+
+ str = nm_utils_inet6_ntop ((struct in6_addr *) bytearray->data, NULL);
+ g_ptr_array_add (dns, g_strdup (str));
+ }
+ }
+
+ g_ptr_array_add (dns, NULL);
+ g_value_take_boxed (prop_value, g_ptr_array_free (dns, FALSE));
+}
+
+void
+_nm_utils_ip6_addresses_to_dbus (const GValue *prop_value,
+ GValue *dbus_value)
+{
+ GPtrArray *addresses, *dbus_addresses;
+ int i;
+
+ addresses = g_value_get_boxed (prop_value);
+ dbus_addresses = g_ptr_array_new ();
+
+ if (addresses) {
+ for (i = 0; i < addresses->len; i++) {
+ NMIP6Address *addr = addresses->pdata[i];
+ GValueArray *array;
+ GValue element = G_VALUE_INIT;
+ GByteArray *ba;
+
+ array = g_value_array_new (3);
+
+ /* IP address */
+ g_value_init (&element, DBUS_TYPE_G_UCHAR_ARRAY);
+ ba = g_byte_array_new ();
+ g_byte_array_append (ba, (guint8 *) nm_ip6_address_get_address (addr), 16);
+ g_value_take_boxed (&element, ba);
+ g_value_array_append (array, &element);
+ g_value_unset (&element);
+
+ /* Prefix */
+ g_value_init (&element, G_TYPE_UINT);
+ g_value_set_uint (&element, nm_ip6_address_get_prefix (addr));
+ g_value_array_append (array, &element);
+ g_value_unset (&element);
+
+ /* Gateway */
+ g_value_init (&element, DBUS_TYPE_G_UCHAR_ARRAY);
+ ba = g_byte_array_new ();
+ g_byte_array_append (ba, (guint8 *) nm_ip6_address_get_gateway (addr), 16);
+ g_value_take_boxed (&element, ba);
+ g_value_array_append (array, &element);
+ g_value_unset (&element);
+
+ g_ptr_array_add (dbus_addresses, array);
+ }
+ }
+
+ g_value_take_boxed (dbus_value, dbus_addresses);
+}
+
+void
+_nm_utils_ip6_addresses_from_dbus (const GValue *dbus_value,
+ GValue *prop_value)
+{
+ GPtrArray *addresses, *dbus_addresses;
+ int i;
+
+ dbus_addresses = g_value_get_boxed (dbus_value);
+ addresses = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_ip6_address_unref);
+
+ if (dbus_addresses) {
+ for (i = 0; i < dbus_addresses->len; i++) {
+ GValueArray *elements = dbus_addresses->pdata[i];
+ GValue *tmp;
+ GByteArray *ba_addr;
+ GByteArray *ba_gw = NULL;
+ NMIP6Address *addr;
+ guint32 prefix;
+
+ if (elements->n_values < 2 || elements->n_values > 3) {
+ g_warning ("%s: ignoring invalid IP6 address structure", __func__);
+ continue;
+ }
+
+ /* Third element (gateway) is optional */
+ if ( !_nm_utils_gvalue_array_validate (elements, 2, DBUS_TYPE_G_UCHAR_ARRAY, G_TYPE_UINT)
+ && !_nm_utils_gvalue_array_validate (elements, 3, DBUS_TYPE_G_UCHAR_ARRAY, G_TYPE_UINT, DBUS_TYPE_G_UCHAR_ARRAY)) {
+ g_warning ("%s: ignoring invalid IP6 address structure", __func__);
+ continue;
+ }
+
+ tmp = g_value_array_get_nth (elements, 0);
+ ba_addr = g_value_get_boxed (tmp);
+ if (ba_addr->len != 16) {
+ g_warning ("%s: ignoring invalid IP6 address of length %d",
+ __func__, ba_addr->len);
+ continue;
+ }
+
+ tmp = g_value_array_get_nth (elements, 1);
+ prefix = g_value_get_uint (tmp);
+ if (prefix > 128) {
+ g_warning ("%s: ignoring invalid IP6 prefix %d",
+ __func__, prefix);
+ continue;
+ }
+
+ if (elements->n_values == 3) {
+ tmp = g_value_array_get_nth (elements, 2);
+ ba_gw = g_value_get_boxed (tmp);
+ if (ba_gw->len != 16) {
+ g_warning ("%s: ignoring invalid IP6 gateway address of length %d",
+ __func__, ba_gw->len);
+ continue;
+ }
+ }
+
+ addr = nm_ip6_address_new ();
+ nm_ip6_address_set_prefix (addr, prefix);
+ nm_ip6_address_set_address (addr, (const struct in6_addr *) ba_addr->data);
+ if (ba_gw)
+ nm_ip6_address_set_gateway (addr, (const struct in6_addr *) ba_gw->data);
+
+ g_ptr_array_add (addresses, addr);
+ }
+ }
+
+ g_value_take_boxed (prop_value, addresses);
+}
+
+void
+_nm_utils_ip6_routes_to_dbus (const GValue *prop_value,
+ GValue *dbus_value)
+{
+ GPtrArray *routes, *dbus_routes;
+ int i;
+
+ routes = g_value_get_boxed (prop_value);
+ dbus_routes = g_ptr_array_new ();
+
+ if (routes) {
+ for (i = 0; i < routes->len; i++) {
+ NMIP6Route *route = routes->pdata[i];
+ GValueArray *array;
+ const struct in6_addr *addr;
+ GByteArray *ba;
+ GValue element = G_VALUE_INIT;
+
+ array = g_value_array_new (4);
+
+ g_value_init (&element, DBUS_TYPE_G_UCHAR_ARRAY);
+ addr = nm_ip6_route_get_dest (route);
+ ba = g_byte_array_new ();
+ g_byte_array_append (ba, (guchar *)addr, sizeof (*addr));
+ g_value_take_boxed (&element, ba);
+ g_value_array_append (array, &element);
+ g_value_unset (&element);
+
+ g_value_init (&element, G_TYPE_UINT);
+ g_value_set_uint (&element, nm_ip6_route_get_prefix (route));
+ g_value_array_append (array, &element);
+ g_value_unset (&element);
+
+ g_value_init (&element, DBUS_TYPE_G_UCHAR_ARRAY);
+ addr = nm_ip6_route_get_next_hop (route);
+ ba = g_byte_array_new ();
+ g_byte_array_append (ba, (guchar *)addr, sizeof (*addr));
+ g_value_take_boxed (&element, ba);
+ g_value_array_append (array, &element);
+ g_value_unset (&element);
+
+ g_value_init (&element, G_TYPE_UINT);
+ g_value_set_uint (&element, nm_ip6_route_get_metric (route));
+ g_value_array_append (array, &element);
+ g_value_unset (&element);
+
+ g_ptr_array_add (dbus_routes, array);
+ }
+ }
+
+ g_value_take_boxed (dbus_value, dbus_routes);
+}
+
+void
+_nm_utils_ip6_routes_from_dbus (const GValue *dbus_value,
+ GValue *prop_value)
+{
+ GPtrArray *routes, *dbus_routes;
+ int i;
+
+ dbus_routes = g_value_get_boxed (dbus_value);
+ routes = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_ip6_route_unref);
+
+ if (dbus_routes) {
+ for (i = 0; i < dbus_routes->len; i++) {
+ GValueArray *route_values = dbus_routes->pdata[i];
+ GByteArray *dest, *next_hop;
+ guint prefix, metric;
+ NMIP6Route *route;
+
+ if (!_nm_utils_gvalue_array_validate (route_values, 4,
+ DBUS_TYPE_G_UCHAR_ARRAY,
+ G_TYPE_UINT,
+ DBUS_TYPE_G_UCHAR_ARRAY,
+ G_TYPE_UINT)) {
+ g_warning ("Ignoring invalid IP6 route");
+ continue;
+ }
+
+ dest = g_value_get_boxed (g_value_array_get_nth (route_values, 0));
+ if (dest->len != 16) {
+ g_warning ("%s: ignoring invalid IP6 dest address of length %d",
+ __func__, dest->len);
+ continue;
+ }
+
+ prefix = g_value_get_uint (g_value_array_get_nth (route_values, 1));
+
+ next_hop = g_value_get_boxed (g_value_array_get_nth (route_values, 2));
+ if (next_hop->len != 16) {
+ g_warning ("%s: ignoring invalid IP6 next_hop address of length %d",
+ __func__, next_hop->len);
+ continue;
+ }
+
+ metric = g_value_get_uint (g_value_array_get_nth (route_values, 3));
+
+ route = nm_ip6_route_new ();
+ nm_ip6_route_set_dest (route, (struct in6_addr *)dest->data);
+ nm_ip6_route_set_prefix (route, prefix);
+ nm_ip6_route_set_next_hop (route, (struct in6_addr *)next_hop->data);
+ nm_ip6_route_set_metric (route, metric);
+
+ g_ptr_array_add (routes, route);
+ }
+ }
+
+ g_value_take_boxed (prop_value, routes);
+}
+
/**
* nm_utils_ip6_addresses_from_gvalue:
* @value: gvalue containing a GPtrArray of GValueArrays of (GArray of guchars) and #guint32
@@ -1463,7 +1961,7 @@ nm_utils_ip6_routes_to_gvalue (GSList *list, GValue *value)
* @value: a #GValue
*
* Converts a #GValue containing a #GPtrArray of IP6 DNS, represented as
- * #GByteArrays into a #GSList of <literal><type>struct in6_addr</type></literal>s.
+ * #GByteArrays into a #GSList of IP address strings.
*
* Returns: a #GSList of IP6 addresses.
*/
@@ -1477,7 +1975,7 @@ nm_utils_ip6_dns_from_gvalue (const GValue *value)
dns = (GPtrArray *) g_value_get_boxed (value);
for (i = 0; dns && (i < dns->len); i++) {
GByteArray *bytearray = (GByteArray *) g_ptr_array_index (dns, i);
- struct in6_addr *addr;
+ const char *str;
if (bytearray->len != 16) {
g_warning ("%s: ignoring invalid IP6 address of length %d",
@@ -1485,9 +1983,8 @@ nm_utils_ip6_dns_from_gvalue (const GValue *value)
continue;
}
- addr = g_malloc0 (sizeof (struct in6_addr));
- memcpy (addr->s6_addr, bytearray->data, bytearray->len);
- list = g_slist_prepend (list, addr);
+ str = nm_utils_inet6_ntop ((struct in6_addr *) bytearray->data, NULL);
+ list = g_slist_prepend (list, g_strdup (str));
}
return g_slist_reverse (list);
@@ -1515,11 +2012,12 @@ nm_utils_ip6_dns_to_gvalue (GSList *list, GValue *value)
dns = g_ptr_array_new ();
for (iter = list; iter; iter = iter->next) {
- struct in6_addr *addr = (struct in6_addr *) iter->data;
+ const char *str = iter->data;
GByteArray *bytearray;
- bytearray = g_byte_array_sized_new (16);
- g_byte_array_append (bytearray, (guint8 *) addr->s6_addr, 16);
+ bytearray = g_byte_array_new ();
+ g_byte_array_set_size (bytearray, 16);
+ inet_pton (AF_INET6, str, bytearray->data);
g_ptr_array_add (dns, bytearray);
}
diff --git a/libnm-core/nm-value-transforms.c b/libnm-core/nm-value-transforms.c
index de73d9b44e..d19ad58afc 100644
--- a/libnm-core/nm-value-transforms.c
+++ b/libnm-core/nm-value-transforms.c
@@ -64,87 +64,6 @@ _nm_utils_convert_op_array_to_string (const GValue *src_value, GValue *dest_valu
}
static void
-_nm_utils_convert_uint_array_to_string (const GValue *src_value, GValue *dest_value)
-{
- GArray *array;
- GString *printable;
- guint i = 0;
-
- g_return_if_fail (g_type_is_a (G_VALUE_TYPE (src_value), DBUS_TYPE_G_UINT_ARRAY));
-
- array = (GArray *) g_value_get_boxed (src_value);
-
- printable = g_string_new (NULL);
- while (array && (i < array->len)) {
- guint32 addr;
-
- if (i > 0)
- g_string_append (printable, ", ");
-
- addr = g_array_index (array, guint32, i++);
- g_string_append (printable, nm_utils_inet4_ntop (addr, NULL));
- }
-
- g_value_take_string (dest_value, g_string_free (printable, FALSE));
-}
-
-static void
-_nm_utils_convert_ip4_addr_route_struct_array_to_string (const GValue *src_value, GValue *dest_value)
-{
- GPtrArray *ptr_array;
- GString *printable;
- guint i = 0;
- char buf[INET_ADDRSTRLEN];
-
- g_return_if_fail (g_type_is_a (G_VALUE_TYPE (src_value), DBUS_TYPE_G_ARRAY_OF_ARRAY_OF_UINT));
-
- ptr_array = (GPtrArray *) g_value_get_boxed (src_value);
-
- printable = g_string_new (NULL);
- while (ptr_array && (i < ptr_array->len)) {
- GArray *array;
- gboolean is_addr; /* array contains address x route */
-
- if (i > 0)
- g_string_append (printable, "; ");
-
- g_string_append (printable, "{ ");
- array = (GArray *) g_ptr_array_index (ptr_array, i++);
- if (array->len < 2) {
- g_string_append (printable, "invalid");
- continue;
- }
- is_addr = (array->len < 4);
-
- nm_utils_inet4_ntop (g_array_index (array, guint32, 0), buf);
- if (is_addr)
- g_string_append_printf (printable, "ip = %s", buf);
- else
- g_string_append_printf (printable, "dst = %s", buf);
-
- g_string_append_printf (printable, "/%u",
- g_array_index (array, guint32, 1));
-
- if (array->len > 2) {
- nm_utils_inet4_ntop (g_array_index (array, guint32, 2), buf);
- if (is_addr)
- g_string_append_printf (printable, ", gw = %s", buf);
- else
- g_string_append_printf (printable, ", nh = %s", buf);
- }
-
- if (array->len > 3) {
- g_string_append_printf (printable, ", mt = %u",
- g_array_index (array, guint32, 3));
- }
-
- g_string_append (printable, " }");
- }
-
- g_value_take_string (dest_value, g_string_free (printable, FALSE));
-}
-
-static void
convert_one_gvalue_hash_entry (gpointer key, gpointer value, gpointer user_data)
{
GString *printable = (GString *) user_data;
@@ -200,228 +119,6 @@ _nm_utils_convert_byte_array_to_string (const GValue *src_value, GValue *dest_va
g_value_take_string (dest_value, g_string_free (printable, FALSE));
}
-static void
-_nm_utils_convert_ip6_dns_array_to_string (const GValue *src_value, GValue *dest_value)
-{
- GPtrArray *ptr_array;
- GString *printable;
- guint i = 0;
-
- g_return_if_fail (g_type_is_a (G_VALUE_TYPE (src_value), DBUS_TYPE_G_ARRAY_OF_ARRAY_OF_UCHAR));
-
- ptr_array = (GPtrArray *) g_value_get_boxed (src_value);
-
- printable = g_string_new (NULL);
- while (ptr_array && (i < ptr_array->len)) {
- GByteArray *bytearray;
- struct in6_addr *addr;
-
- if (i > 0)
- g_string_append (printable, ", ");
-
- bytearray = (GByteArray *) g_ptr_array_index (ptr_array, i++);
- if (bytearray->len != 16) {
- g_string_append (printable, "invalid");
- continue;
- }
- addr = (struct in6_addr *) bytearray->data;
- g_string_append (printable, nm_utils_inet6_ntop (addr, NULL));
- }
-
- g_value_take_string (dest_value, g_string_free (printable, FALSE));
-}
-
-static void
-_nm_utils_convert_ip6_addr_struct_array_to_string (const GValue *src_value, GValue *dest_value)
-{
- GPtrArray *ptr_array;
- GString *printable;
- guint i = 0;
-
- g_return_if_fail (g_type_is_a (G_VALUE_TYPE (src_value), DBUS_TYPE_G_ARRAY_OF_IP6_ADDRESS));
-
- ptr_array = (GPtrArray *) g_value_get_boxed (src_value);
-
- printable = g_string_new (NULL);
- while (ptr_array && (i < ptr_array->len)) {
- GValueArray *elements;
- GValue *tmp;
- GByteArray *ba_addr;
- struct in6_addr *addr;
- guint32 prefix;
-
- if (i > 0)
- g_string_append (printable, "; ");
-
- g_string_append (printable, "{ ");
- elements = (GValueArray *) g_ptr_array_index (ptr_array, i++);
- if (!_nm_utils_gvalue_array_validate (elements, 3,
- DBUS_TYPE_G_UCHAR_ARRAY,
- G_TYPE_UINT,
- DBUS_TYPE_G_UCHAR_ARRAY)) {
- g_string_append (printable, "invalid }");
- continue;
- }
-
- /* IPv6 address */
- tmp = g_value_array_get_nth (elements, 0);
- ba_addr = g_value_get_boxed (tmp);
- if (ba_addr->len != 16) {
- g_string_append (printable, "invalid }");
- continue;
- }
- addr = (struct in6_addr *) ba_addr->data;
- g_string_append_printf (printable, "ip = %s", nm_utils_inet6_ntop (addr, NULL));
-
- /* Prefix */
- tmp = g_value_array_get_nth (elements, 1);
- prefix = g_value_get_uint (tmp);
- if (prefix > 128) {
- g_string_append (printable, "/invalid }");
- continue;
- }
- g_string_append_printf (printable, "/%u", prefix);
- g_string_append (printable, ", ");
-
- /* IPv6 Gateway */
- tmp = g_value_array_get_nth (elements, 2);
- ba_addr = g_value_get_boxed (tmp);
- if (ba_addr->len != 16) {
- g_string_append (printable, "invalid }");
- continue;
- }
- addr = (struct in6_addr *) ba_addr->data;
- g_string_append_printf (printable, "gw = %s", nm_utils_inet6_ntop (addr, NULL));
- g_string_append (printable, " }");
- }
-
- g_value_take_string (dest_value, g_string_free (printable, FALSE));
-}
-
-static void
-_nm_utils_convert_ip6_route_struct_array_to_string (const GValue *src_value, GValue *dest_value)
-{
- GPtrArray *ptr_array;
- GString *printable;
- guint i = 0;
-
- g_return_if_fail (g_type_is_a (G_VALUE_TYPE (src_value), DBUS_TYPE_G_ARRAY_OF_IP6_ROUTE));
-
- ptr_array = (GPtrArray *) g_value_get_boxed (src_value);
-
- printable = g_string_new (NULL);
- while (ptr_array && (i < ptr_array->len)) {
- GValueArray *elements;
- GValue *tmp;
- GByteArray *ba_addr;
- struct in6_addr *addr;
- guint32 prefix, metric;
-
- if (i > 0)
- g_string_append (printable, "; ");
-
- g_string_append (printable, "{ ");
- elements = (GValueArray *) g_ptr_array_index (ptr_array, i++);
- if (!_nm_utils_gvalue_array_validate (elements, 4,
- DBUS_TYPE_G_UCHAR_ARRAY,
- G_TYPE_UINT,
- DBUS_TYPE_G_UCHAR_ARRAY,
- G_TYPE_UINT)) {
- g_string_append (printable, "invalid");
- continue;
- }
-
- /* Destination address */
- tmp = g_value_array_get_nth (elements, 0);
- ba_addr = g_value_get_boxed (tmp);
- if (ba_addr->len != 16) {
- g_string_append (printable, "invalid");
- continue;
- }
- addr = (struct in6_addr *) ba_addr->data;
- g_string_append_printf (printable, "dst = %s", nm_utils_inet6_ntop (addr, NULL));
-
- /* Prefix */
- tmp = g_value_array_get_nth (elements, 1);
- prefix = g_value_get_uint (tmp);
- if (prefix > 128) {
- g_string_append (printable, "/invalid");
- continue;
- }
- g_string_append_printf (printable, "/%u", prefix);
- g_string_append (printable, ", ");
-
- /* Next hop addresses */
- tmp = g_value_array_get_nth (elements, 2);
- ba_addr = g_value_get_boxed (tmp);
- if (ba_addr->len != 16) {
- g_string_append (printable, "invalid");
- continue;
- }
- addr = (struct in6_addr *) ba_addr->data;
- g_string_append_printf (printable, "nh = %s", nm_utils_inet6_ntop (addr, NULL));
- g_string_append (printable, ", ");
-
- /* Metric */
- tmp = g_value_array_get_nth (elements, 3);
- metric = g_value_get_uint (tmp);
- g_string_append_printf (printable, "mt = %u", metric);
-
- g_string_append (printable, " }");
- }
-
- g_value_take_string (dest_value, g_string_free (printable, FALSE));
-}
-
-#define OLD_DBUS_TYPE_G_IP6_ADDRESS (dbus_g_type_get_struct ("GValueArray", DBUS_TYPE_G_UCHAR_ARRAY, G_TYPE_UINT, G_TYPE_INVALID))
-#define OLD_DBUS_TYPE_G_ARRAY_OF_IP6_ADDRESS (dbus_g_type_get_collection ("GPtrArray", OLD_DBUS_TYPE_G_IP6_ADDRESS))
-
-static void
-_nm_utils_convert_old_ip6_addr_array (const GValue *src_value, GValue *dst_value)
-{
- GPtrArray *src_outer_array;
- GPtrArray *dst_outer_array;
- guint i;
-
- g_return_if_fail (g_type_is_a (G_VALUE_TYPE (src_value), OLD_DBUS_TYPE_G_ARRAY_OF_IP6_ADDRESS));
-
- src_outer_array = (GPtrArray *) g_value_get_boxed (src_value);
- dst_outer_array = g_ptr_array_new ();
-
- for (i = 0; src_outer_array && (i < src_outer_array->len); i++) {
- GValueArray *src_addr_array;
- GValueArray *dst_addr_array;
- GValue element = G_VALUE_INIT;
- GValue *src_addr, *src_prefix;
- GByteArray *ba;
-
- src_addr_array = (GValueArray *) g_ptr_array_index (src_outer_array, i);
- if (!_nm_utils_gvalue_array_validate (src_addr_array, 2, DBUS_TYPE_G_UCHAR_ARRAY, G_TYPE_UINT)) {
- g_warning ("%s: invalid old IPv6 address type", __func__);
- return;
- }
-
- dst_addr_array = g_value_array_new (3);
-
- src_addr = g_value_array_get_nth (src_addr_array, 0);
- g_value_array_append (dst_addr_array, src_addr);
- src_prefix = g_value_array_get_nth (src_addr_array, 1);
- g_value_array_append (dst_addr_array, src_prefix);
-
- /* Blank Gateway */
- g_value_init (&element, DBUS_TYPE_G_UCHAR_ARRAY);
- ba = g_byte_array_new ();
- g_byte_array_append (ba, (guint8 *) "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", 16);
- g_value_take_boxed (&element, ba);
- g_value_array_append (dst_addr_array, &element);
- g_value_unset (&element);
-
- g_ptr_array_add (dst_outer_array, dst_addr_array);
- }
-
- g_value_take_boxed (dst_value, dst_outer_array);
-}
-
void
_nm_value_transforms_register (void)
{
@@ -434,30 +131,12 @@ _nm_value_transforms_register (void)
g_value_register_transform_func (DBUS_TYPE_G_ARRAY_OF_OBJECT_PATH,
G_TYPE_STRING,
_nm_utils_convert_op_array_to_string);
- g_value_register_transform_func (DBUS_TYPE_G_UINT_ARRAY,
- G_TYPE_STRING,
- _nm_utils_convert_uint_array_to_string);
- g_value_register_transform_func (DBUS_TYPE_G_ARRAY_OF_ARRAY_OF_UINT,
- G_TYPE_STRING,
- _nm_utils_convert_ip4_addr_route_struct_array_to_string);
g_value_register_transform_func (DBUS_TYPE_G_MAP_OF_VARIANT,
G_TYPE_STRING,
_nm_utils_convert_gvalue_hash_to_string);
g_value_register_transform_func (DBUS_TYPE_G_UCHAR_ARRAY,
G_TYPE_STRING,
_nm_utils_convert_byte_array_to_string);
- g_value_register_transform_func (DBUS_TYPE_G_ARRAY_OF_ARRAY_OF_UCHAR,
- G_TYPE_STRING,
- _nm_utils_convert_ip6_dns_array_to_string);
- g_value_register_transform_func (DBUS_TYPE_G_ARRAY_OF_IP6_ADDRESS,
- G_TYPE_STRING,
- _nm_utils_convert_ip6_addr_struct_array_to_string);
- g_value_register_transform_func (DBUS_TYPE_G_ARRAY_OF_IP6_ROUTE,
- G_TYPE_STRING,
- _nm_utils_convert_ip6_route_struct_array_to_string);
- g_value_register_transform_func (OLD_DBUS_TYPE_G_ARRAY_OF_IP6_ADDRESS,
- DBUS_TYPE_G_ARRAY_OF_IP6_ADDRESS,
- _nm_utils_convert_old_ip6_addr_array);
registered = TRUE;
}
}
diff --git a/libnm-core/tests/test-general.c b/libnm-core/tests/test-general.c
index a5f8ee6f97..e08b98b0b6 100644
--- a/libnm-core/tests/test-general.c
+++ b/libnm-core/tests/test-general.c
@@ -388,7 +388,7 @@ test_setting_ip4_config_labels (void)
g_object_set (G_OBJECT (s_ip4),
NM_SETTING_IP4_CONFIG_ADDRESSES, addrs,
NULL);
- g_boxed_free (DBUS_TYPE_G_ARRAY_OF_ARRAY_OF_UINT, addrs);
+ g_ptr_array_unref (addrs);
nm_setting_verify (NM_SETTING (s_ip4), NULL, &error);
g_assert_no_error (error);
g_assert_cmpint (nm_setting_ip4_config_get_num_addresses (s_ip4), ==, 2);
@@ -457,99 +457,6 @@ test_setting_ip4_config_labels (void)
g_object_unref (s_ip4);
}
-#define OLD_DBUS_TYPE_G_IP6_ADDRESS (dbus_g_type_get_struct ("GValueArray", DBUS_TYPE_G_UCHAR_ARRAY, G_TYPE_UINT, G_TYPE_INVALID))
-#define OLD_DBUS_TYPE_G_ARRAY_OF_IP6_ADDRESS (dbus_g_type_get_collection ("GPtrArray", OLD_DBUS_TYPE_G_IP6_ADDRESS))
-
-/* Test that setting the IPv6 setting's 'addresses' property using the old
- * IPv6 address format still works, i.e. that the GValue transformation function
- * from old->new is working correctly.
- */
-static void
-test_setting_ip6_config_old_address_array (void)
-{
- NMSettingIP6Config *s_ip6;
- GPtrArray *addresses, *read_addresses;
- GValueArray *array, *read_array;
- GValue element = G_VALUE_INIT, written_value = G_VALUE_INIT, read_value = G_VALUE_INIT;
- GByteArray *ba;
- const guint8 addr[16] = { 0x88, 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11,
- 0x11, 0x22, 0x33, 0x44, 0x66, 0x77, 0x88, 0x99 };
- const guint8 gw[16] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- guint32 prefix = 56;
- GValue *read_addr, *read_prefix, *read_gw;
-
- s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new ();
- ASSERT (s_ip6 != NULL,
- "ip6-old-addr", "error creating IP6 setting");
-
- g_value_init (&written_value, OLD_DBUS_TYPE_G_ARRAY_OF_IP6_ADDRESS);
-
- addresses = g_ptr_array_new ();
- array = g_value_array_new (3);
-
- /* IP address */
- g_value_init (&element, DBUS_TYPE_G_UCHAR_ARRAY);
- ba = g_byte_array_new ();
- g_byte_array_append (ba, &addr[0], sizeof (addr));
- g_value_take_boxed (&element, ba);
- g_value_array_append (array, &element);
- g_value_unset (&element);
-
- /* Prefix */
- g_value_init (&element, G_TYPE_UINT);
- g_value_set_uint (&element, prefix);
- g_value_array_append (array, &element);
- g_value_unset (&element);
-
- g_ptr_array_add (addresses, array);
- g_value_set_boxed (&written_value, addresses);
-
- /* Set the address array on the object */
- g_object_set_property (G_OBJECT (s_ip6), NM_SETTING_IP6_CONFIG_ADDRESSES, &written_value);
-
- /* Get it back so we can compare it */
- g_value_init (&read_value, DBUS_TYPE_G_ARRAY_OF_IP6_ADDRESS);
- g_object_get_property (G_OBJECT (s_ip6), NM_SETTING_IP6_CONFIG_ADDRESSES, &read_value);
-
- ASSERT (G_VALUE_HOLDS (&read_value, DBUS_TYPE_G_ARRAY_OF_IP6_ADDRESS),
- "ip6-old-addr", "wrong addresses property value type '%s'",
- G_VALUE_TYPE_NAME (&read_value));
-
- read_addresses = (GPtrArray *) g_value_get_boxed (&read_value);
- ASSERT (read_addresses != NULL,
- "ip6-old-addr", "missing addresses on readback");
- ASSERT (read_addresses->len == 1,
- "ip6-old-addr", "expected one address on readback");
-
- read_array = (GValueArray *) g_ptr_array_index (read_addresses, 0);
-
- read_addr = g_value_array_get_nth (read_array, 0);
- ba = g_value_get_boxed (read_addr);
- ASSERT (ba->len == sizeof (addr),
- "ip6-old-addr", "unexpected address item length %d", ba->len);
- ASSERT (memcmp (ba->data, &addr[0], sizeof (addr)) == 0,
- "ip6-old-addr", "unexpected failure comparing addresses");
-
- read_prefix = g_value_array_get_nth (read_array, 1);
- ASSERT (g_value_get_uint (read_prefix) == prefix,
- "ip6-old-addr", "unexpected failure comparing prefix");
-
- /* Ensure the gateway is all zeros, which is how the 2-item to 3-item
- * conversion happens.
- */
- read_gw = g_value_array_get_nth (read_array, 2);
- ba = g_value_get_boxed (read_gw);
- ASSERT (ba->len == sizeof (gw),
- "ip6-old-addr", "unexpected gateway item length %d", ba->len);
- ASSERT (memcmp (ba->data, &gw[0], sizeof (gw)) == 0,
- "ip6-old-addr", "unexpected failure comparing gateways");
-
- g_value_unset (&written_value);
- g_value_unset (&read_value);
- g_object_unref (s_ip6);
-}
-
static void
test_setting_gsm_apn_spaces (void)
{
@@ -2372,14 +2279,14 @@ test_setting_ip4_changed_signal (void)
s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new ();
nm_connection_add_setting (connection, NM_SETTING (s_ip4));
- ASSERT_CHANGED (nm_setting_ip4_config_add_dns (s_ip4, 0x1122));
+ ASSERT_CHANGED (nm_setting_ip4_config_add_dns (s_ip4, "11.22.0.0"));
ASSERT_CHANGED (nm_setting_ip4_config_remove_dns (s_ip4, 0));
- g_test_expect_message ("libnm", G_LOG_LEVEL_CRITICAL, "*i <= priv->dns->len*");
+ g_test_expect_message ("libnm", G_LOG_LEVEL_CRITICAL, "*elt != NULL*");
ASSERT_UNCHANGED (nm_setting_ip4_config_remove_dns (s_ip4, 1));
g_test_assert_expected_messages ();
- nm_setting_ip4_config_add_dns (s_ip4, 0x3344);
+ nm_setting_ip4_config_add_dns (s_ip4, "33.44.0.0");
ASSERT_CHANGED (nm_setting_ip4_config_clear_dns (s_ip4));
ASSERT_CHANGED (nm_setting_ip4_config_add_dns_search (s_ip4, "foobar.com"));
@@ -2443,14 +2350,14 @@ test_setting_ip6_changed_signal (void)
s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new ();
nm_connection_add_setting (connection, NM_SETTING (s_ip6));
- ASSERT_CHANGED (nm_setting_ip6_config_add_dns (s_ip6, &t));
+ ASSERT_CHANGED (nm_setting_ip6_config_add_dns (s_ip6, "1:2:3::4:5:6"));
ASSERT_CHANGED (nm_setting_ip6_config_remove_dns (s_ip6, 0));
g_test_expect_message ("libnm", G_LOG_LEVEL_CRITICAL, "*elt != NULL*");
ASSERT_UNCHANGED (nm_setting_ip6_config_remove_dns (s_ip6, 1));
g_test_assert_expected_messages ();
- nm_setting_ip6_config_add_dns (s_ip6, &t);
+ nm_setting_ip6_config_add_dns (s_ip6, "1:2:3::4:5:6");
ASSERT_CHANGED (nm_setting_ip6_config_clear_dns (s_ip6));
ASSERT_CHANGED (nm_setting_ip6_config_add_dns_search (s_ip6, "foobar.com"));
@@ -3251,7 +3158,6 @@ int main (int argc, char **argv)
g_test_add_func ("/core/general/test_setting_vpn_update_secrets", test_setting_vpn_update_secrets);
g_test_add_func ("/core/general/test_setting_vpn_modify_during_foreach", test_setting_vpn_modify_during_foreach);
g_test_add_func ("/core/general/test_setting_ip4_config_labels", test_setting_ip4_config_labels);
- g_test_add_func ("/core/general/test_setting_ip6_config_old_address_array", test_setting_ip6_config_old_address_array);
g_test_add_func ("/core/general/test_setting_gsm_apn_spaces", test_setting_gsm_apn_spaces);
g_test_add_func ("/core/general/test_setting_gsm_apn_bad_chars", test_setting_gsm_apn_bad_chars);
g_test_add_func ("/core/general/test_setting_gsm_apn_underscore", test_setting_gsm_apn_underscore);
diff --git a/src/nm-ip4-config.c b/src/nm-ip4-config.c
index beb4b92815..aab50aeb8d 100644
--- a/src/nm-ip4-config.c
+++ b/src/nm-ip4-config.c
@@ -367,8 +367,12 @@ nm_ip4_config_merge_setting (NMIP4Config *config, NMSettingIP4Config *setting, i
nm_ip4_config_reset_domains (config);
nm_ip4_config_reset_searches (config);
}
- for (i = 0; i < nnameservers; i++)
- nm_ip4_config_add_nameserver (config, nm_setting_ip4_config_get_dns (setting, i));
+ for (i = 0; i < nnameservers; i++) {
+ guint32 ip;
+
+ if (inet_pton (AF_INET, nm_setting_ip4_config_get_dns (setting, i), &ip) == 1)
+ nm_ip4_config_add_nameserver (config, ip);
+ }
for (i = 0; i < nsearches; i++)
nm_ip4_config_add_search (config, nm_setting_ip4_config_get_dns_search (setting, i));
@@ -460,7 +464,7 @@ nm_ip4_config_create_setting (const NMIP4Config *config)
for (i = 0; i < nnameservers; i++) {
guint32 nameserver = nm_ip4_config_get_nameserver (config, i);
- nm_setting_ip4_config_add_dns (s_ip4, nameserver);
+ nm_setting_ip4_config_add_dns (s_ip4, nm_utils_inet4_ntop (nameserver, NULL));
}
for (i = 0; i < nsearches; i++) {
const char *search = nm_ip4_config_get_search (config, i);
diff --git a/src/nm-ip6-config.c b/src/nm-ip6-config.c
index 0d4307f288..9d2b61f2c5 100644
--- a/src/nm-ip6-config.c
+++ b/src/nm-ip6-config.c
@@ -470,8 +470,12 @@ nm_ip6_config_merge_setting (NMIP6Config *config, NMSettingIP6Config *setting, i
nm_ip6_config_reset_domains (config);
nm_ip6_config_reset_searches (config);
}
- for (i = 0; i < nnameservers; i++)
- nm_ip6_config_add_nameserver (config, nm_setting_ip6_config_get_dns (setting, i));
+ for (i = 0; i < nnameservers; i++) {
+ struct in6_addr ip;
+
+ if (inet_pton (AF_INET6, nm_setting_ip6_config_get_dns (setting, i), &ip) == 1)
+ nm_ip6_config_add_nameserver (config, &ip);
+ }
for (i = 0; i < nsearches; i++)
nm_ip6_config_add_search (config, nm_setting_ip6_config_get_dns_search (setting, i));
@@ -571,7 +575,7 @@ nm_ip6_config_create_setting (const NMIP6Config *config)
for (i = 0; i < nnameservers; i++) {
const struct in6_addr *nameserver = nm_ip6_config_get_nameserver (config, i);
- nm_setting_ip6_config_add_dns (s_ip6, nameserver);
+ nm_setting_ip6_config_add_dns (s_ip6, nm_utils_inet6_ntop (nameserver, NULL));
}
for (i = 0; i < nsearches; i++) {
const char *search = nm_ip6_config_get_search (config, i);
diff --git a/src/settings/plugins/ibft/reader.c b/src/settings/plugins/ibft/reader.c
index d5db7c70b4..57fdb34536 100644
--- a/src/settings/plugins/ibft/reader.c
+++ b/src/settings/plugins/ibft/reader.c
@@ -367,10 +367,10 @@ ip4_setting_add_from_block (const GPtrArray *block,
nm_setting_ip4_config_add_address (s_ip4, addr);
nm_ip4_address_unref (addr);
- if (dns1)
- nm_setting_ip4_config_add_dns (s_ip4, dns1);
- if (dns2)
- nm_setting_ip4_config_add_dns (s_ip4, dns2);
+ if (s_dns1)
+ nm_setting_ip4_config_add_dns (s_ip4, s_dns1);
+ if (s_dns2)
+ nm_setting_ip4_config_add_dns (s_ip4, s_dns2);
success:
nm_connection_add_setting (connection, NM_SETTING (s_ip4));
diff --git a/src/settings/plugins/ibft/tests/test-ibft.c b/src/settings/plugins/ibft/tests/test-ibft.c
index 1fe2be27c0..8252dda769 100644
--- a/src/settings/plugins/ibft/tests/test-ibft.c
+++ b/src/settings/plugins/ibft/tests/test-ibft.c
@@ -160,8 +160,8 @@ test_read_ibft_static (void)
g_assert_cmpstr (nm_setting_ip4_config_get_method (s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_MANUAL);
g_assert_cmpint (nm_setting_ip4_config_get_num_dns (s_ip4), ==, 2);
- nmtst_assert_ip4_address_equals (nm_setting_ip4_config_get_dns (s_ip4, 0), "10.16.255.2");
- nmtst_assert_ip4_address_equals (nm_setting_ip4_config_get_dns (s_ip4, 1), "10.16.255.3");
+ g_assert_cmpstr (nm_setting_ip4_config_get_dns (s_ip4, 0), ==, "10.16.255.2");
+ g_assert_cmpstr (nm_setting_ip4_config_get_dns (s_ip4, 1), ==, "10.16.255.3");
g_assert_cmpint (nm_setting_ip4_config_get_num_addresses (s_ip4), ==, 1);
ip4_addr = nm_setting_ip4_config_get_address (s_ip4, 0);
diff --git a/src/settings/plugins/ifcfg-rh/reader.c b/src/settings/plugins/ifcfg-rh/reader.c
index bba4d1da04..48e757a706 100644
--- a/src/settings/plugins/ifcfg-rh/reader.c
+++ b/src/settings/plugins/ifcfg-rh/reader.c
@@ -1106,25 +1106,26 @@ make_ip4_setting (shvarFile *ifcfg,
struct in6_addr ip6_dns;
tag = g_strdup_printf ("DNS%u", i);
- if (!read_ip4_address (ifcfg, tag, &dns, error)) {
- gboolean valid = TRUE;
+ value = svGetValue (ifcfg, tag, FALSE);
+ if (value) {
+ if (!read_ip4_address (ifcfg, tag, &dns, error)) {
+ gboolean valid = TRUE;
- /* Ignore IPv6 addresses */
- dns = 0;
- value = svGetValue (ifcfg, tag, FALSE);
- if (value)
+ /* Ignore IPv6 addresses */
valid = parse_ip6_address (value, &ip6_dns, NULL);
- g_free (value);
-
- if (!valid) {
- g_free (tag);
- goto done;
+ if (!valid) {
+ g_free (tag);
+ goto done;
+ }
+ g_clear_error (error);
+ dns = 0;
}
- g_clear_error (error);
+
+ if (dns && !nm_setting_ip4_config_add_dns (s_ip4, value))
+ PARSE_WARNING ("duplicate DNS server %s", tag);
+ g_free (value);
}
- if (dns && !nm_setting_ip4_config_add_dns (s_ip4, dns))
- PARSE_WARNING ("duplicate DNS server %s", tag);
g_free (tag);
}
@@ -1223,10 +1224,11 @@ read_aliases (NMSettingIP4Config *s_ip4, const char *filename, const char *netwo
g_return_if_fail (s_ip4 != NULL);
g_return_if_fail (filename != NULL);
- base_addr = nm_setting_ip4_config_get_address (s_ip4, 0);
- if (!base_addr)
+ if (nm_setting_ip4_config_get_num_addresses (s_ip4) == 0)
return;
+ base_addr = nm_setting_ip4_config_get_address (s_ip4, 0);
+
dirname = g_path_get_dirname (filename);
g_return_if_fail (dirname != NULL);
base = g_path_get_basename (filename);
@@ -1497,7 +1499,7 @@ make_ip6_setting (shvarFile *ifcfg,
ip6_dns = in6addr_any;
if (parse_ip6_address (value, &ip6_dns, NULL)) {
- if (!IN6_IS_ADDR_UNSPECIFIED (&ip6_dns) && !nm_setting_ip6_config_add_dns (s_ip6, &ip6_dns))
+ if (!IN6_IS_ADDR_UNSPECIFIED (&ip6_dns) && !nm_setting_ip6_config_add_dns (s_ip6, value))
PARSE_WARNING ("duplicate DNS server %s", tag);
} else {
/* Maybe an IPv4 address? If so ignore it */
diff --git a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c
index 570d0c26fc..f4379739e6 100644
--- a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c
+++ b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c
@@ -396,14 +396,9 @@ test_read_wired_static (const char *file,
GError *error = NULL;
const char *mac;
char expected_mac_address[ETH_ALEN] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0xee };
- const char *expected_dns1 = "4.2.2.1";
- const char *expected_dns2 = "4.2.2.2";
- guint32 addr;
struct in6_addr addr6;
const char *expected6_address1 = "dead:beaf::1";
const char *expected6_address2 = "dead:beaf::2";
- const char *expected6_dns1 = "1:2:3:4::a";
- const char *expected6_dns2 = "1:2:3:4::b";
NMIP4Address *ip4_addr;
NMIP6Address *ip6_addr;
gboolean success;
@@ -442,10 +437,8 @@ test_read_wired_static (const char *file,
/* DNS Addresses */
g_assert_cmpint (nm_setting_ip4_config_get_num_dns (s_ip4), ==, 2);
- g_assert_cmpint (inet_pton (AF_INET, expected_dns1, &addr), >, 0);
- g_assert_cmpint (nm_setting_ip4_config_get_dns (s_ip4, 0), ==, addr);
- g_assert_cmpint (inet_pton (AF_INET, expected_dns2, &addr), >, 0);
- g_assert_cmpint (nm_setting_ip4_config_get_dns (s_ip4, 1), ==, addr);
+ g_assert_cmpstr (nm_setting_ip4_config_get_dns (s_ip4, 0), ==, "4.2.2.1");
+ g_assert_cmpstr (nm_setting_ip4_config_get_dns (s_ip4, 1), ==, "4.2.2.2");
/* IP addresses */
g_assert_cmpint (nm_setting_ip4_config_get_num_addresses (s_ip4), ==, 1);
@@ -464,10 +457,8 @@ test_read_wired_static (const char *file,
/* DNS Addresses */
g_assert_cmpint (nm_setting_ip6_config_get_num_dns (s_ip6), ==, 2);
- g_assert_cmpint (inet_pton (AF_INET6, expected6_dns1, &addr6), >, 0);
- g_assert (IN6_ARE_ADDR_EQUAL (nm_setting_ip6_config_get_dns (s_ip6, 0), &addr6));
- g_assert_cmpint (inet_pton (AF_INET6, expected6_dns2, &addr6), >, 0);
- g_assert (IN6_ARE_ADDR_EQUAL (nm_setting_ip6_config_get_dns (s_ip6, 1), &addr6));
+ g_assert_cmpstr (nm_setting_ip6_config_get_dns (s_ip6, 0), ==, "1:2:3:4::a");
+ g_assert_cmpstr (nm_setting_ip6_config_get_dns (s_ip6, 1), ==, "1:2:3:4::b");
/* IP addresses */
g_assert_cmpint (nm_setting_ip6_config_get_num_addresses (s_ip6), ==, 2);
@@ -553,9 +544,6 @@ test_read_wired_dhcp (void)
char expected_mac_address[ETH_ALEN] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0xee };
const char *tmp;
const char *expected_id = "System test-wired-dhcp";
- const char *expected_dns1 = "4.2.2.1";
- const char *expected_dns2 = "4.2.2.2";
- guint32 addr;
const char *expected_dhcp_hostname = "foobar";
connection = connection_from_file (TEST_IFCFG_WIRED_DHCP,
@@ -673,23 +661,13 @@ test_read_wired_dhcp (void)
NM_SETTING_IP4_CONFIG_SETTING_NAME,
NM_SETTING_IP4_CONFIG_DNS);
- ASSERT (inet_pton (AF_INET, expected_dns1, &addr) > 0,
- "wired-dhcp-verify-ip4", "failed to verify %s: couldn't convert DNS IP address #1",
- TEST_IFCFG_WIRED_DHCP,
- NM_SETTING_IP4_CONFIG_SETTING_NAME,
- NM_SETTING_IP4_CONFIG_DNS);
- ASSERT (nm_setting_ip4_config_get_dns (s_ip4, 0) == addr,
+ ASSERT (strcmp (nm_setting_ip4_config_get_dns (s_ip4, 0), "4.2.2.1") == 0,
"wired-dhcp-verify-ip4", "failed to verify %s: unexpected %s / %s key value #1",
TEST_IFCFG_WIRED_DHCP,
NM_SETTING_IP4_CONFIG_SETTING_NAME,
NM_SETTING_IP4_CONFIG_DNS);
- ASSERT (inet_pton (AF_INET, expected_dns2, &addr) > 0,
- "wired-dhcp-verify-ip4", "failed to verify %s: couldn't convert DNS IP address #2",
- TEST_IFCFG_WIRED_DHCP,
- NM_SETTING_IP4_CONFIG_SETTING_NAME,
- NM_SETTING_IP4_CONFIG_DNS);
- ASSERT (nm_setting_ip4_config_get_dns (s_ip4, 1) == addr,
+ ASSERT (strcmp (nm_setting_ip4_config_get_dns (s_ip4, 1), "4.2.2.2") == 0,
"wired-dhcp-verify-ip4", "failed to verify %s: unexpected %s / %s key value #2",
TEST_IFCFG_WIRED_DHCP,
NM_SETTING_IP4_CONFIG_SETTING_NAME,
@@ -732,10 +710,8 @@ test_read_wired_dhcp_plus_ip (void)
/* DNS Addresses */
g_assert_cmpint (nm_setting_ip4_config_get_num_dns (s_ip4), ==, 2);
- g_assert_cmpint (inet_pton (AF_INET, "4.2.2.1", &addr4), >, 0);
- g_assert_cmpint (nm_setting_ip4_config_get_dns (s_ip4, 0), ==, addr4);
- g_assert_cmpint (inet_pton (AF_INET, "4.2.2.2", &addr4), >, 0);
- g_assert_cmpint (nm_setting_ip4_config_get_dns (s_ip4, 1), ==, addr4);
+ g_assert_cmpstr (nm_setting_ip4_config_get_dns (s_ip4, 0), ==, "4.2.2.1");
+ g_assert_cmpstr (nm_setting_ip4_config_get_dns (s_ip4, 1), ==, "4.2.2.2");
/* IP addresses */
g_assert_cmpint (nm_setting_ip4_config_get_num_addresses (s_ip4), ==, 2);
@@ -761,10 +737,8 @@ test_read_wired_dhcp_plus_ip (void)
/* DNS Addresses */
g_assert_cmpint (nm_setting_ip6_config_get_num_dns (s_ip6), ==, 2);
- g_assert_cmpint (inet_pton (AF_INET6, "1:2:3:4::a", &addr6), >, 0);
- g_assert (IN6_ARE_ADDR_EQUAL (nm_setting_ip6_config_get_dns (s_ip6, 0), &addr6));
- g_assert_cmpint (inet_pton (AF_INET6, "1:2:3:4::b", &addr6), >, 0);
- g_assert (IN6_ARE_ADDR_EQUAL (nm_setting_ip6_config_get_dns (s_ip6, 1), &addr6));
+ g_assert_cmpstr (nm_setting_ip6_config_get_dns (s_ip6, 0), ==, "1:2:3:4::a");
+ g_assert_cmpstr (nm_setting_ip6_config_get_dns (s_ip6, 1), ==, "1:2:3:4::b");
/* IP addresses */
g_assert_cmpint (nm_setting_ip6_config_get_num_addresses (s_ip6), ==, 3);
@@ -1533,8 +1507,6 @@ test_read_wired_ipv6_manual (void)
guint32 expected_prefix1 = 56;
guint32 expected_prefix2 = 64;
guint32 expected_prefix3 = 96;
- const char *expected_dns1 = "1:2:3:4::a";
- const char *expected_dns2 = "1:2:3:4::b";
NMIP6Address *ip6_addr;
NMIP6Route *ip6_route;
struct in6_addr addr;
@@ -1762,19 +1734,13 @@ test_read_wired_ipv6_manual (void)
NM_SETTING_IP6_CONFIG_SETTING_NAME,
NM_SETTING_IP6_CONFIG_DNS);
- ASSERT (inet_pton (AF_INET6, expected_dns1, &addr) > 0,
- "wired-ipv6-manual-verify-ip6", "failed to verify %s: couldn't convert DNS IP address #1",
- TEST_IFCFG_WIRED_IPV6_MANUAL);
- ASSERT (IN6_ARE_ADDR_EQUAL (nm_setting_ip6_config_get_dns (s_ip6, 0), &addr),
+ ASSERT (strcmp (nm_setting_ip6_config_get_dns (s_ip6, 0), "1:2:3:4::a") == 0,
"wired-ipv6-manual-verify-ip6", "failed to verify %s: unexpected %s / %s key value #1",
TEST_IFCFG_WIRED_IPV6_MANUAL,
NM_SETTING_IP6_CONFIG_SETTING_NAME,
NM_SETTING_IP6_CONFIG_DNS);
- ASSERT (inet_pton (AF_INET6, expected_dns2, &addr) > 0,
- "wired-ipv6-manual-verify-ip6", "failed to verify %s: couldn't convert DNS IP address #2",
- TEST_IFCFG_WIRED_IPV6_MANUAL);
- ASSERT (IN6_ARE_ADDR_EQUAL (nm_setting_ip6_config_get_dns (s_ip6, 1), &addr),
+ ASSERT (strcmp (nm_setting_ip6_config_get_dns (s_ip6, 1), "1:2:3:4::b") == 0,
"wired-ipv6-manual-verify-ip6", "failed to verify %s: unexpected %s / %s key value #2",
TEST_IFCFG_WIRED_IPV6_MANUAL,
NM_SETTING_IP6_CONFIG_SETTING_NAME,
@@ -1814,7 +1780,6 @@ test_read_wired_ipv6_only (void)
const char *expected_id = "System test-wired-ipv6-only";
const char *expected_address1 = "1001:abba::1234";
guint32 expected_prefix1 = 56;
- const char *expected_dns1 = "1:2:3:4::a";
NMIP6Address *ip6_addr;
struct in6_addr addr;
const char *method;
@@ -1928,10 +1893,7 @@ test_read_wired_ipv6_only (void)
NM_SETTING_IP6_CONFIG_SETTING_NAME,
NM_SETTING_IP6_CONFIG_DNS);
- ASSERT (inet_pton (AF_INET6, expected_dns1, &addr) > 0,
- "wired-ipv6-only-verify-ip6", "failed to verify %s: couldn't convert DNS IP address #1",
- TEST_IFCFG_WIRED_IPV6_MANUAL);
- ASSERT (IN6_ARE_ADDR_EQUAL (nm_setting_ip6_config_get_dns (s_ip6, 0), &addr),
+ ASSERT (strcmp (nm_setting_ip6_config_get_dns (s_ip6, 0), "1:2:3:4::a") == 0,
"wired-ipv6-only-verify-ip6", "failed to verify %s: unexpected %s / %s key value #1",
TEST_IFCFG_WIRED_IPV6_MANUAL,
NM_SETTING_IP6_CONFIG_SETTING_NAME,
@@ -3559,9 +3521,6 @@ test_read_wifi_wep_adhoc (void)
const char *expected_ssid = "blahblah";
const char *expected_mode = "adhoc";
const char *expected_wep_key0 = "0123456789abcdef0123456789";
- guint32 addr;
- const char *expected_dns1 = "4.2.2.1";
- const char *expected_dns2 = "4.2.2.2";
connection = connection_from_file (TEST_IFCFG_WIFI_WEP_ADHOC,
NULL,
@@ -3761,23 +3720,13 @@ test_read_wifi_wep_adhoc (void)
NM_SETTING_IP4_CONFIG_SETTING_NAME,
NM_SETTING_IP4_CONFIG_DNS);
- ASSERT (inet_pton (AF_INET, expected_dns1, &addr) > 0,
- "wifi-wep-adhoc-verify-ip4", "failed to verify %s: couldn't convert DNS IP address #1",
- TEST_IFCFG_WIFI_WEP_ADHOC,
- NM_SETTING_IP4_CONFIG_SETTING_NAME,
- NM_SETTING_IP4_CONFIG_DNS);
- ASSERT (nm_setting_ip4_config_get_dns (s_ip4, 0) == addr,
+ ASSERT (strcmp (nm_setting_ip4_config_get_dns (s_ip4, 0), "4.2.2.1") == 0,
"wifi-wep-adhoc-verify-ip4", "failed to verify %s: unexpected %s / %s key value #1",
TEST_IFCFG_WIFI_WEP_ADHOC,
NM_SETTING_IP4_CONFIG_SETTING_NAME,
NM_SETTING_IP4_CONFIG_DNS);
- ASSERT (inet_pton (AF_INET, expected_dns2, &addr) > 0,
- "wifi-wep-adhoc-verify-ip4", "failed to verify %s: couldn't convert DNS IP address #2",
- TEST_IFCFG_WIFI_WEP_ADHOC,
- NM_SETTING_IP4_CONFIG_SETTING_NAME,
- NM_SETTING_IP4_CONFIG_DNS);
- ASSERT (nm_setting_ip4_config_get_dns (s_ip4, 1) == addr,
+ ASSERT (strcmp (nm_setting_ip4_config_get_dns (s_ip4, 1), "4.2.2.2") == 0,
"wifi-wep-adhoc-verify-ip4", "failed to verify %s: unexpected %s / %s key value #2",
TEST_IFCFG_WIFI_WEP_ADHOC,
NM_SETTING_IP4_CONFIG_SETTING_NAME,
@@ -6335,8 +6284,8 @@ test_write_wired_static (void)
const guint32 ip1 = htonl (0x01010103);
const guint32 ip2 = htonl (0x01010105);
const guint32 gw = htonl (0x01010101);
- const guint32 dns1 = htonl (0x04020201);
- const guint32 dns2 = htonl (0x04020202);
+ const char *dns1 = "4.2.2.1";
+ const char *dns2 = "4.2.2.2";
const guint32 prefix = 24;
const char *dns_search1 = "foobar.com";
const char *dns_search2 = "lab.foobar.com";
@@ -6344,7 +6293,8 @@ test_write_wired_static (void)
const char *dns_search4 = "lab6.foobar.com";
struct in6_addr ip6, ip6_1, ip6_2;
struct in6_addr route1_dest, route2_dest, route1_nexthop, route2_nexthop;
- struct in6_addr dns6_1, dns6_2;
+ const char *dns6_1 = "fade:0102:0103::face";
+ const char *dns6_2 = "cafe:ffff:eeee:dddd:cccc:bbbb:aaaa:feed";
const guint32 route1_prefix = 64, route2_prefix = 128;
const guint32 route1_metric = 99, route2_metric = 1;
NMIP4Address *addr;
@@ -6366,8 +6316,6 @@ test_write_wired_static (void)
inet_pton (AF_INET6, "2222:aaaa:bbbb:cccc:dddd:eeee:5555:6666", &route1_nexthop);
inet_pton (AF_INET6, "::", &route2_dest);
inet_pton (AF_INET6, "2222:aaaa::9999", &route2_nexthop);
- inet_pton (AF_INET6, "fade:0102:0103::face", &dns6_1);
- inet_pton (AF_INET6, "cafe:ffff:eeee:dddd:cccc:bbbb:aaaa:feed", &dns6_2);
connection = nm_simple_connection_new ();
@@ -6468,8 +6416,8 @@ test_write_wired_static (void)
nm_ip6_route_unref (route6);
/* DNS servers */
- nm_setting_ip6_config_add_dns (s_ip6, &dns6_1);
- nm_setting_ip6_config_add_dns (s_ip6, &dns6_2);
+ nm_setting_ip6_config_add_dns (s_ip6, dns6_1);
+ nm_setting_ip6_config_add_dns (s_ip6, dns6_2);
/* DNS domains */
nm_setting_ip6_config_add_dns_search (s_ip6, dns_search3);
@@ -6770,7 +6718,7 @@ test_write_wired_static_ip6_only (void)
static const char *mac = "31:33:33:37:be:cd";
char *uuid;
struct in6_addr ip6;
- struct in6_addr dns6;
+ const char *dns6 = "fade:0102:0103::face";
NMIP6Address *addr6;
gboolean success;
GError *error = NULL;
@@ -6782,7 +6730,6 @@ test_write_wired_static_ip6_only (void)
gboolean ignore_error = FALSE;
inet_pton (AF_INET6, "1003:1234:abcd::1", &ip6);
- inet_pton (AF_INET6, "fade:0102:0103::face", &dns6);
connection = nm_simple_connection_new ();
@@ -6829,7 +6776,7 @@ test_write_wired_static_ip6_only (void)
nm_ip6_address_unref (addr6);
/* DNS server */
- nm_setting_ip6_config_add_dns (s_ip6, &dns6);
+ nm_setting_ip6_config_add_dns (s_ip6, dns6);
ASSERT (nm_connection_verify (connection, &error) == TRUE,
"wired-static-ip6-only-write", "failed to verify connection: %s",
@@ -6903,7 +6850,7 @@ test_write_wired_static_ip6_only_gw (gconstpointer user_data)
static const char *mac = "31:33:33:37:be:cd";
char *uuid;
struct in6_addr ip6;
- struct in6_addr dns6;
+ const char *dns6 = "fade:0102:0103::face";
NMIP6Address *addr6;
gboolean success;
GError *error = NULL;
@@ -6923,7 +6870,6 @@ test_write_wired_static_ip6_only_gw (gconstpointer user_data)
}
inet_pton (AF_INET6, "1003:1234:abcd::1", &ip6);
- inet_pton (AF_INET6, "fade:0102:0103::face", &dns6);
if (gateway6)
inet_ntop (AF_INET6, gateway6, s_gateway6, sizeof (s_gateway6));
@@ -6976,7 +6922,7 @@ test_write_wired_static_ip6_only_gw (gconstpointer user_data)
nm_ip6_address_unref (addr6);
/* DNS server */
- nm_setting_ip6_config_add_dns (s_ip6, &dns6);
+ nm_setting_ip6_config_add_dns (s_ip6, dns6);
g_assert (nm_connection_verify (connection, &error));
@@ -7202,8 +7148,8 @@ test_write_wired_static_routes (void)
const guint32 ip1 = htonl (0x01010103);
const guint32 ip2 = htonl (0x01010105);
const guint32 gw = htonl (0x01010101);
- const guint32 dns1 = htonl (0x04020201);
- const guint32 dns2 = htonl (0x04020202);
+ const char *dns1 = "4.2.2.1";
+ const char *dns2 = "4.2.2.2";
const guint32 route_dst1 = htonl (0x01020300);
const guint32 route_dst2= htonl (0x03020100);
const guint32 route_gw1 = htonl (0xdeadbeef);
@@ -8487,7 +8433,7 @@ test_write_wifi_wep_adhoc (void)
NMIP4Address *addr;
const guint32 ip1 = htonl (0x01010103);
const guint32 gw = htonl (0x01010101);
- const guint32 dns1 = htonl (0x04020201);
+ const char *dns1 = "4.2.2.1";
const guint32 prefix = 24;
connection = nm_simple_connection_new ();
@@ -9486,7 +9432,7 @@ test_write_wifi_wpa_psk_adhoc (void)
NMIP4Address *addr;
const guint32 ip1 = htonl (0x01010103);
const guint32 gw = htonl (0x01010101);
- const guint32 dns1 = htonl (0x04020201);
+ const char *dns1 = "4.2.2.1";
const guint32 prefix = 24;
connection = nm_simple_connection_new ();
diff --git a/src/settings/plugins/ifcfg-rh/writer.c b/src/settings/plugins/ifcfg-rh/writer.c
index 1b037e2a7b..94944d27b5 100644
--- a/src/settings/plugins/ifcfg-rh/writer.c
+++ b/src/settings/plugins/ifcfg-rh/writer.c
@@ -1955,19 +1955,15 @@ write_ip4_setting (NMConnection *connection, shvarFile *ifcfg, GError **error)
num = nm_setting_ip4_config_get_num_dns (s_ip4);
for (i = 0; i < 254; i++) {
- char buf[INET_ADDRSTRLEN + 1];
- guint32 ip;
+ const char *dns;
addr_key = g_strdup_printf ("DNS%d", i + 1);
if (i >= num)
svSetValue (ifcfg, addr_key, NULL, FALSE);
else {
- ip = nm_setting_ip4_config_get_dns (s_ip4, i);
-
- memset (buf, 0, sizeof (buf));
- inet_ntop (AF_INET, (const void *) &ip, &buf[0], sizeof (buf));
- svSetValue (ifcfg, addr_key, &buf[0], FALSE);
+ dns = nm_setting_ip4_config_get_dns (s_ip4, i);
+ svSetValue (ifcfg, addr_key, dns, FALSE);
}
g_free (addr_key);
}
@@ -2278,6 +2274,7 @@ write_ip6_setting (NMConnection *connection, shvarFile *ifcfg, GError **error)
char ipv6_defaultgw[INET6_ADDRSTRLEN];
NMIP6Address *addr;
const struct in6_addr *ip;
+ const char *dns;
GString *ip_str1, *ip_str2, *ip_ptr;
char *route6_path;
@@ -2372,11 +2369,8 @@ write_ip6_setting (NMConnection *connection, shvarFile *ifcfg, GError **error)
if (i >= num)
svSetValue (ifcfg, addr_key, NULL, FALSE);
else {
- ip = nm_setting_ip6_config_get_dns (s_ip6, i);
-
- memset (buf, 0, sizeof (buf));
- inet_ntop (AF_INET6, (const void *) ip, buf, sizeof (buf));
- svSetValue (ifcfg, addr_key, buf, FALSE);
+ dns = nm_setting_ip6_config_get_dns (s_ip6, i);
+ svSetValue (ifcfg, addr_key, dns, FALSE);
}
g_free (addr_key);
}
diff --git a/src/settings/plugins/ifnet/connection_parser.c b/src/settings/plugins/ifnet/connection_parser.c
index adfafdaa02..3594dce2c3 100644
--- a/src/settings/plugins/ifnet/connection_parser.c
+++ b/src/settings/plugins/ifnet/connection_parser.c
@@ -2438,15 +2438,10 @@ write_ip4_setting (NMConnection *connection, const char *conn_name, GError **err
if (num > 0) {
dns = g_string_new (NULL);
for (i = 0; i < num; i++) {
- char buf[INET_ADDRSTRLEN + 1];
- guint32 ip;
+ const char *ip;
ip = nm_setting_ip4_config_get_dns (s_ip4, i);
-
- memset (buf, 0, sizeof (buf));
- inet_ntop (AF_INET, (const void *) &ip, &buf[0],
- sizeof (buf));
- g_string_append_printf (dns, " %s", buf);
+ g_string_append_printf (dns, " %s", ip);
}
ifnet_set_data (conn_name, "dns_servers", dns->str);
g_string_free (dns, TRUE);
@@ -2652,17 +2647,15 @@ write_ip6_setting (NMConnection *connection, const char *conn_name, GError **err
const char *dns_servers = ifnet_get_data (conn_name, "dns_servers");
gchar *tmp;
GString *dns_string = g_string_new (NULL);
+ const char *dns;
if (!dns_servers)
dns_servers = "";
for (i = 0; i < num; i++) {
- ip = nm_setting_ip6_config_get_dns (s_ip6, i);
+ dns = nm_setting_ip6_config_get_dns (s_ip6, i);
- memset (buf, 0, sizeof (buf));
- inet_ntop (AF_INET6, (const void *) ip, buf,
- sizeof (buf));
- if (!strstr (dns_servers, buf))
- g_string_append_printf (dns_string, "%s ", buf);
+ if (!strstr (dns_servers, dns))
+ g_string_append_printf (dns_string, "%s ", dns);
}
tmp = g_strdup_printf ("%s %s", dns_servers, dns_string->str);
ifnet_set_data (conn_name, "dns_servers", tmp);
diff --git a/src/settings/plugins/ifnet/net_utils.c b/src/settings/plugins/ifnet/net_utils.c
index 86ab8537da..1f7ca56f17 100644
--- a/src/settings/plugins/ifnet/net_utils.c
+++ b/src/settings/plugins/ifnet/net_utils.c
@@ -682,7 +682,6 @@ set_ip4_dns_servers (NMSettingIP4Config *s_ip4, const char *conn_name)
gchar **server_list, *stripped;
guint length, i;
guint32 tmp_ip4_addr;
- guint32 new_dns;
dns_servers = ifnet_get_data (conn_name, "dns_servers");
if (!dns_servers)
@@ -705,8 +704,7 @@ set_ip4_dns_servers (NMSettingIP4Config *s_ip4, const char *conn_name)
nm_log_warn (LOGD_SETTINGS, "ignored dns: %s\n", server_list[i]);
continue;
}
- new_dns = tmp_ip4_addr;
- if (new_dns && !nm_setting_ip4_config_add_dns (s_ip4, new_dns))
+ if (!nm_setting_ip4_config_add_dns (s_ip4, server_list[i]))
nm_log_warn (LOGD_SETTINGS, "warning: duplicate DNS server %s", server_list[i]);
}
g_strfreev (server_list);
@@ -742,8 +740,7 @@ set_ip6_dns_servers (NMSettingIP6Config *s_ip6, const char *conn_name)
nm_log_warn (LOGD_SETTINGS, "ignored dns: %s\n", server_list[i]);
continue;
}
- if (!IN6_IS_ADDR_UNSPECIFIED (&tmp_ip6_addr)
- && !nm_setting_ip6_config_add_dns (s_ip6, &tmp_ip6_addr))
+ if (!nm_setting_ip6_config_add_dns (s_ip6, server_list[i]))
nm_log_warn (LOGD_SETTINGS, "warning: duplicate DNS server %s", server_list[i]);
}
g_strfreev (server_list);
diff --git a/src/settings/plugins/ifupdown/parser.c b/src/settings/plugins/ifupdown/parser.c
index b3fe546cb9..097fe7b64e 100644
--- a/src/settings/plugins/ifupdown/parser.c
+++ b/src/settings/plugins/ifupdown/parser.c
@@ -447,7 +447,7 @@ ifupdown_ip4_add_dns (NMSettingIP4Config *s_ip4, const char *dns)
continue;
}
- if (!nm_setting_ip4_config_add_dns (s_ip4, addr))
+ if (!nm_setting_ip4_config_add_dns (s_ip4, *iter))
nm_log_warn (LOGD_SETTINGS, " duplicate DNS domain '%s'", *iter);
}
g_strfreev (list);
@@ -582,7 +582,7 @@ ifupdown_ip6_add_dns (NMSettingIP6Config *s_ip6, const char *dns)
continue;
}
- if (!nm_setting_ip6_config_add_dns (s_ip6, &addr))
+ if (!nm_setting_ip6_config_add_dns (s_ip6, *iter))
nm_log_warn (LOGD_SETTINGS, " duplicate DNS domain '%s'", *iter);
}
g_strfreev (list);
diff --git a/src/settings/plugins/ifupdown/tests/test-ifupdown.c b/src/settings/plugins/ifupdown/tests/test-ifupdown.c
index 07102c803a..10c07f1ca9 100644
--- a/src/settings/plugins/ifupdown/tests/test-ifupdown.c
+++ b/src/settings/plugins/ifupdown/tests/test-ifupdown.c
@@ -467,8 +467,6 @@ test17_read_static_ipv4 (const char *path)
const char* tmp;
const char *expected_address = "10.0.0.3";
const char *expected_id = "Ifupdown (eth0)";
- const char *expected_dns1 = "10.0.0.1";
- const char *expected_dns2 = "10.0.0.2";
const char *expected_search1 = "example.com";
const char *expected_search2 = "foo.example.com";
guint32 expected_prefix = 8;
@@ -569,25 +567,13 @@ test17_read_static_ipv4 (const char *path)
NM_SETTING_IP4_CONFIG_SETTING_NAME,
NM_SETTING_IP4_CONFIG_DNS);
- ASSERT (inet_pton (AF_INET, expected_dns1, &addr) > 0,
- TEST17_NAME, "failed to verify %s: couldn't convert DNS IP address #1",
- file,
- NM_SETTING_IP4_CONFIG_SETTING_NAME,
- NM_SETTING_IP4_CONFIG_DNS);
-
- ASSERT (nm_setting_ip4_config_get_dns (s_ip4, 0) == addr,
+ ASSERT (!strcmp (nm_setting_ip4_config_get_dns (s_ip4, 0), "10.0.0.1"),
TEST17_NAME, "failed to verify %s: unexpected %s / %s key value #1",
file,
NM_SETTING_IP4_CONFIG_SETTING_NAME,
NM_SETTING_IP4_CONFIG_DNS);
- ASSERT (inet_pton (AF_INET, expected_dns2, &addr) > 0,
- TEST17_NAME, "failed to verify %s: couldn't convert DNS IP address #2",
- file,
- NM_SETTING_IP4_CONFIG_SETTING_NAME,
- NM_SETTING_IP4_CONFIG_DNS);
-
- ASSERT (nm_setting_ip4_config_get_dns (s_ip4, 1) == addr,
+ ASSERT (!strcmp (nm_setting_ip4_config_get_dns (s_ip4, 1), "10.0.0.2"),
TEST17_NAME, "failed to verify %s: unexpected %s / %s key value #2",
file,
NM_SETTING_IP4_CONFIG_SETTING_NAME,
@@ -646,8 +632,6 @@ test18_read_static_ipv6 (const char *path)
const char* tmp;
const char *expected_address = "fc00::1";
const char *expected_id = "Ifupdown (myip6tunnel)";
- const char *expected_dns1 = "fc00::2";
- const char *expected_dns2 = "fc00::3";
const char *expected_search1 = "example.com";
const char *expected_search2 = "foo.example.com";
guint32 expected_prefix = 64;
@@ -768,26 +752,14 @@ test18_read_static_ipv6 (const char *path)
NM_SETTING_IP6_CONFIG_SETTING_NAME,
NM_SETTING_IP6_CONFIG_DNS);
- ASSERT (inet_pton (AF_INET6, expected_dns1, &addr) > 0,
- TEST18_NAME,
- "failed to verify %s: couldn't convert DNS IP address #1",
- file);
-
- ASSERT (IN6_ARE_ADDR_EQUAL (nm_setting_ip6_config_get_dns (s_ip6, 0),
- &addr),
+ ASSERT (!strcmp (nm_setting_ip6_config_get_dns (s_ip6, 0), "fc00::2"),
TEST18_NAME,
"failed to verify %s: unexpected %s / %s #1",
file,
NM_SETTING_IP6_CONFIG_SETTING_NAME,
NM_SETTING_IP6_CONFIG_DNS);
- ASSERT (inet_pton (AF_INET6, expected_dns2, &addr) > 0,
- TEST18_NAME,
- "failed to verify %s: couldn't convert DNS IP address #2",
- file);
-
- ASSERT (IN6_ARE_ADDR_EQUAL (nm_setting_ip6_config_get_dns (s_ip6, 1),
- &addr),
+ ASSERT (!strcmp (nm_setting_ip6_config_get_dns (s_ip6, 1), "fc00::3"),
TEST18_NAME, "failed to verify %s: unexpected %s / %s #2",
file,
NM_SETTING_IP6_CONFIG_SETTING_NAME,
diff --git a/src/settings/plugins/keyfile/reader.c b/src/settings/plugins/keyfile/reader.c
index 25192e6079..b77ae13084 100644
--- a/src/settings/plugins/keyfile/reader.c
+++ b/src/settings/plugins/keyfile/reader.c
@@ -118,7 +118,7 @@ get_one_int (const char *str, guint32 max_val, const char *key_name, guint32 *ou
static gpointer
build_ip4_address_or_route (const char *key_name, const char *address_str, guint32 plen, const char *gateway_str, const char *metric_str, gboolean route)
{
- GArray *result;
+ gpointer result;
guint32 addr;
guint32 address = 0;
guint32 gateway = 0;
@@ -153,12 +153,18 @@ build_ip4_address_or_route (const char *key_name, const char *address_str, guint
return NULL;
}
- result = g_array_sized_new (FALSE, TRUE, sizeof (guint32), 3 + !!route);
- g_array_append_val (result, address);
- g_array_append_val (result, plen);
- g_array_append_val (result, gateway);
- if (route)
- g_array_append_val (result, metric);
+ if (route) {
+ result = nm_ip4_route_new ();
+ nm_ip4_route_set_dest (result, address);
+ nm_ip4_route_set_prefix (result, plen);
+ nm_ip4_route_set_next_hop (result, gateway);
+ nm_ip4_route_set_metric (result, metric);
+ } else {
+ result = nm_ip4_address_new ();
+ nm_ip4_address_set_address (result, address);
+ nm_ip4_address_set_prefix (result, plen);
+ nm_ip4_address_set_gateway (result, gateway);
+ }
return result;
}
@@ -166,36 +172,31 @@ build_ip4_address_or_route (const char *key_name, const char *address_str, guint
static gpointer
build_ip6_address_or_route (const char *key_name, const char *address_str, guint32 plen, const char *gateway_str, const char *metric_str, gboolean route)
{
- GValueArray *result;
+ gpointer result;
struct in6_addr addr;
- GByteArray *address;
- GByteArray *gateway;
guint32 metric = 0;
- GValue value = G_VALUE_INIT;
int err;
g_return_val_if_fail (address_str, NULL);
- result = g_value_array_new (3);
+ if (route)
+ result = nm_ip6_route_new ();
+ else
+ result = nm_ip6_address_new ();
- /* add address */
+ /* add address and prefix length */
err = inet_pton (AF_INET6, address_str, &addr);
if (err <= 0) {
nm_log_warn (LOGD_SETTINGS, "%s: ignoring invalid IPv6 address '%s'", __func__, address_str);
goto error_out;
}
- address = g_byte_array_new ();
- g_byte_array_append (address, (guint8 *) addr.s6_addr, 16);
- g_value_init (&value, DBUS_TYPE_G_UCHAR_ARRAY);
- g_value_take_boxed (&value, address);
- g_value_array_append (result, &value);
- g_value_unset (&value);
-
- /* add prefix length */
- g_value_init (&value, G_TYPE_UINT);
- g_value_set_uint (&value, plen);
- g_value_array_append (result, &value);
- g_value_unset (&value);
+ if (route) {
+ nm_ip6_route_set_dest (result, &addr);
+ nm_ip6_route_set_prefix (result, plen);
+ } else {
+ nm_ip6_address_set_address (result, &addr);
+ nm_ip6_address_set_prefix (result, plen);
+ }
/* add gateway */
if (gateway_str && gateway_str[0]) {
@@ -219,31 +220,25 @@ build_ip6_address_or_route (const char *key_name, const char *address_str, guint
} else
addr = in6addr_any;
- /* parse metric, default to 0 */
- if (metric_str) {
- if (!get_one_int (metric_str, G_MAXUINT32, key_name, &metric))
- goto error_out;
- }
-
- gateway = g_byte_array_new ();
- g_byte_array_append (gateway, (guint8 *) addr.s6_addr, 16);
- g_value_init (&value, DBUS_TYPE_G_UCHAR_ARRAY);
- g_value_take_boxed (&value, gateway);
- g_value_array_append (result, &value);
- g_value_unset (&value);
-
- /* add metric (for routing) */
if (route) {
- g_value_init (&value, G_TYPE_UINT);
- g_value_set_uint (&value, metric);
- g_value_array_append (result, &value);
- g_value_unset (&value);
- }
+ nm_ip6_route_set_next_hop (result, &addr);
+
+ /* parse metric, default to 0 */
+ if (metric_str) {
+ if (!get_one_int (metric_str, G_MAXUINT32, key_name, &metric))
+ goto error_out;
+ }
+ nm_ip6_route_set_metric (result, metric);
+ } else
+ nm_ip6_address_set_gateway (result, &addr);
return result;
error_out:
- g_value_array_free (result);
+ if (route)
+ nm_ip6_route_unref (result);
+ else
+ nm_ip4_route_unref (result);
return NULL;
}
@@ -331,15 +326,13 @@ read_field (char **current, char **error, const char *characters, const char *de
* changed. The default for IPv4 is now 24, which is the closest
* IPv4 equivalent. These defaults may just as well be changed to
* match the iproute2 defaults (32 for IPv4 and 128 for IPv6).
- *
- * The returned result is GArray for IPv4 and GValueArray for IPv6.
*/
static gpointer
read_one_ip_address_or_route (GKeyFile *file,
- const char *setting_name,
- const char *key_name,
- gboolean ipv6,
- gboolean route)
+ const char *setting_name,
+ const char *key_name,
+ gboolean ipv6,
+ gboolean route)
{
guint32 plen;
gpointer result;
@@ -425,12 +418,21 @@ ip_address_or_route_parser (NMSetting *setting, const char *key, GKeyFile *keyfi
static const char *key_names_addresses[] = { "address", "addresses", NULL };
const char **key_names = routes ? key_names_routes : key_names_addresses;
GPtrArray *list;
+ GDestroyNotify free_func;
int i;
- G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
- list = g_ptr_array_new_with_free_func (
- ipv6 ? (GDestroyNotify) g_value_array_free : (GDestroyNotify) g_array_unref);
- G_GNUC_END_IGNORE_DEPRECATIONS;
+ if (ipv6) {
+ if (routes)
+ free_func = (GDestroyNotify) nm_ip6_route_unref;
+ else
+ free_func = (GDestroyNotify) nm_ip6_address_unref;
+ } else {
+ if (routes)
+ free_func = (GDestroyNotify) nm_ip4_route_unref;
+ else
+ free_func = (GDestroyNotify) nm_ip4_address_unref;
+ }
+ list = g_ptr_array_new_with_free_func (free_func);
for (i = -1; i < 1000; i++) {
const char **key_basename;
@@ -464,7 +466,7 @@ static void
ip4_dns_parser (NMSetting *setting, const char *key, GKeyFile *keyfile, const char *keyfile_path)
{
const char *setting_name = nm_setting_get_name (setting);
- GArray *array = NULL;
+ GPtrArray *array;
gsize length;
char **list, **iter;
int ret;
@@ -473,7 +475,7 @@ ip4_dns_parser (NMSetting *setting, const char *key, GKeyFile *keyfile, const ch
if (!list || !g_strv_length (list))
return;
- array = g_array_sized_new (FALSE, FALSE, sizeof (guint32), length);
+ array = g_ptr_array_sized_new (length + 1);
for (iter = list; *iter; iter++) {
guint32 addr;
@@ -483,14 +485,13 @@ ip4_dns_parser (NMSetting *setting, const char *key, GKeyFile *keyfile, const ch
continue;
}
- g_array_append_val (array, addr);
+ g_ptr_array_add (array, *iter);
}
- g_strfreev (list);
+ g_ptr_array_add (array, NULL);
- if (array) {
- g_object_set (setting, key, array, NULL);
- g_array_unref (array);
- }
+ g_object_set (setting, key, array->pdata, NULL);
+ g_ptr_array_unref (array);
+ g_strfreev (list);
}
static void
@@ -506,10 +507,9 @@ ip6_dns_parser (NMSetting *setting, const char *key, GKeyFile *keyfile, const ch
if (!list || !g_strv_length (list))
return;
- array = g_ptr_array_new_with_free_func ((GDestroyNotify) g_byte_array_unref);
+ array = g_ptr_array_sized_new (length + 1);
for (iter = list; *iter; iter++) {
- GByteArray *byte_array;
struct in6_addr addr;
ret = inet_pton (AF_INET6, *iter, &addr);
@@ -517,17 +517,14 @@ ip6_dns_parser (NMSetting *setting, const char *key, GKeyFile *keyfile, const ch
nm_log_warn (LOGD_SETTINGS, "%s: ignoring invalid DNS server IPv6 address '%s'", __func__, *iter);
continue;
}
- byte_array = g_byte_array_new ();
- g_byte_array_append (byte_array, (guint8 *) addr.s6_addr, 16);
- g_ptr_array_add (array, byte_array);
+ g_ptr_array_add (array, *iter);
}
- g_strfreev (list);
+ g_ptr_array_add (array, NULL);
- if (array) {
- g_object_set (setting, key, array, NULL);
- g_ptr_array_unref (array);
- }
+ g_object_set (setting, key, array->pdata, NULL);
+ g_ptr_array_unref (array);
+ g_strfreev (list);
}
static void
diff --git a/src/settings/plugins/keyfile/tests/test-keyfile.c b/src/settings/plugins/keyfile/tests/test-keyfile.c
index cba3e67bb2..bb22556ff8 100644
--- a/src/settings/plugins/keyfile/tests/test-keyfile.c
+++ b/src/settings/plugins/keyfile/tests/test-keyfile.c
@@ -146,12 +146,6 @@ test_read_valid_wired_connection (void)
const char *expected_uuid = "4e80a56d-c99f-4aad-a6dd-b449bc398c57";
const guint64 expected_timestamp = 6654332;
guint64 timestamp;
- const char *expected_dns1 = "4.2.2.1";
- const char *expected_dns2 = "4.2.2.2";
- guint32 addr;
- struct in6_addr addr6;
- const char *expected6_dns1 = "1111:dddd::aaaa";
- const char *expected6_dns2 = "1::cafe";
const char *expected6_dnssearch1 = "super-domain.com";
const char *expected6_dnssearch2 = "redhat.com";
const char *expected6_dnssearch3 = "gnu.org";
@@ -291,23 +285,13 @@ test_read_valid_wired_connection (void)
NM_SETTING_IP4_CONFIG_SETTING_NAME,
NM_SETTING_IP4_CONFIG_DNS);
- ASSERT (inet_pton (AF_INET, expected_dns1, &addr) > 0,
- "connection-verify-wired", "failed to verify %s: couldn't convert DNS IP address #1",
- TEST_WIRED_FILE,
- NM_SETTING_IP4_CONFIG_SETTING_NAME,
- NM_SETTING_IP4_CONFIG_DNS);
- ASSERT (nm_setting_ip4_config_get_dns (s_ip4, 0) == addr,
+ ASSERT (strcmp (nm_setting_ip4_config_get_dns (s_ip4, 0), "4.2.2.1") == 0,
"connection-verify-wired", "failed to verify %s: unexpected %s / %s key value #1",
TEST_WIRED_FILE,
NM_SETTING_IP4_CONFIG_SETTING_NAME,
NM_SETTING_IP4_CONFIG_DNS);
- ASSERT (inet_pton (AF_INET, expected_dns2, &addr) > 0,
- "connection-verify-wired", "failed to verify %s: couldn't convert DNS IP address #2",
- TEST_WIRED_FILE,
- NM_SETTING_IP4_CONFIG_SETTING_NAME,
- NM_SETTING_IP4_CONFIG_DNS);
- ASSERT (nm_setting_ip4_config_get_dns (s_ip4, 1) == addr,
+ ASSERT (strcmp (nm_setting_ip4_config_get_dns (s_ip4, 1), "4.2.2.2") == 0,
"connection-verify-wired", "failed to verify %s: unexpected %s / %s key value #2",
TEST_WIRED_FILE,
NM_SETTING_IP4_CONFIG_SETTING_NAME,
@@ -360,23 +344,13 @@ test_read_valid_wired_connection (void)
NM_SETTING_IP6_CONFIG_SETTING_NAME,
NM_SETTING_IP6_CONFIG_DNS);
- ASSERT (inet_pton (AF_INET6, expected6_dns1, &addr6) > 0,
- "connection-verify-wired", "failed to verify %s: couldn't convert DNS IP6 address #1",
- TEST_WIRED_FILE,
- NM_SETTING_IP6_CONFIG_SETTING_NAME,
- NM_SETTING_IP6_CONFIG_DNS);
- ASSERT (IN6_ARE_ADDR_EQUAL (nm_setting_ip6_config_get_dns (s_ip6, 0), &addr6),
+ ASSERT (strcmp (nm_setting_ip6_config_get_dns (s_ip6, 0), "1111:dddd::aaaa") == 0,
"connection-verify-wired", "failed to verify %s: unexpected %s / %s key value #1",
TEST_WIRED_FILE,
NM_SETTING_IP6_CONFIG_SETTING_NAME,
NM_SETTING_IP6_CONFIG_DNS);
- ASSERT (inet_pton (AF_INET6, expected6_dns2, &addr6) > 0,
- "connection-verify-wired", "failed to verify %s: couldn't convert DNS IP address #2",
- TEST_WIRED_FILE,
- NM_SETTING_IP6_CONFIG_SETTING_NAME,
- NM_SETTING_IP6_CONFIG_DNS);
- ASSERT (IN6_ARE_ADDR_EQUAL (nm_setting_ip6_config_get_dns (s_ip6, 1), &addr6),
+ ASSERT (strcmp (nm_setting_ip6_config_get_dns (s_ip6, 1), "1::cafe") == 0,
"connection-verify-wired", "failed to verify %s: unexpected %s / %s key value #2",
TEST_WIRED_FILE,
NM_SETTING_IP6_CONFIG_SETTING_NAME,
@@ -541,8 +515,6 @@ test_write_wired_connection (void)
GError *error = NULL;
pid_t owner_grp;
uid_t owner_uid;
- guint32 addr;
- struct in6_addr addr6;
const char *dns1 = "4.2.2.1";
const char *dns2 = "4.2.2.2";
const char *address1 = "192.168.0.5";
@@ -618,10 +590,8 @@ test_write_wired_connection (void)
add_one_ip4_route (s_ip4, route4, route4_nh, 6, 4);
/* DNS servers */
- inet_pton (AF_INET, dns1, &addr);
- nm_setting_ip4_config_add_dns (s_ip4, addr);
- inet_pton (AF_INET, dns2, &addr);
- nm_setting_ip4_config_add_dns (s_ip4, addr);
+ nm_setting_ip4_config_add_dns (s_ip4, dns1);
+ nm_setting_ip4_config_add_dns (s_ip4, dns2);
/* IP6 setting */
@@ -643,10 +613,8 @@ test_write_wired_connection (void)
add_one_ip6_route (s_ip6, route6_4, route6_4_nh, 62, 0);
/* DNS servers */
- inet_pton (AF_INET6, dns6_1, &addr6);
- nm_setting_ip6_config_add_dns (s_ip6, &addr6);
- inet_pton (AF_INET6, dns6_2, &addr6);
- nm_setting_ip6_config_add_dns (s_ip6, &addr6);
+ nm_setting_ip6_config_add_dns (s_ip6, dns6_1);
+ nm_setting_ip6_config_add_dns (s_ip6, dns6_2);
/* DNS searches */
nm_setting_ip6_config_add_dns_search (s_ip6, "wallaceandgromit.com");
@@ -801,7 +769,6 @@ test_write_ip6_wired_connection (void)
GError *error = NULL;
pid_t owner_grp;
uid_t owner_uid;
- struct in6_addr addr6;
const char *dns = "1::cafe";
const char *address = "abcd::beef";
const char *gw = "dcba::beef";
@@ -849,8 +816,7 @@ test_write_ip6_wired_connection (void)
add_one_ip6_address (s_ip6, address, 64, gw);
/* DNS servers */
- inet_pton (AF_INET6, dns, &addr6);
- nm_setting_ip6_config_add_dns (s_ip6, &addr6);
+ nm_setting_ip6_config_add_dns (s_ip6, dns);
/* DNS searches */
nm_setting_ip6_config_add_dns_search (s_ip6, "wallaceandgromit.com");
diff --git a/src/settings/plugins/keyfile/writer.c b/src/settings/plugins/keyfile/writer.c
index 4278397ee1..e2eb56601c 100644
--- a/src/settings/plugins/keyfile/writer.c
+++ b/src/settings/plugins/keyfile/writer.c
@@ -104,29 +104,13 @@ ip4_dns_writer (GKeyFile *file,
const char *key,
const GValue *value)
{
- GArray *array;
char **list;
- int i, num = 0;
-
- g_return_if_fail (G_VALUE_HOLDS (value, DBUS_TYPE_G_UINT_ARRAY));
-
- array = (GArray *) g_value_get_boxed (value);
- if (!array || !array->len)
- return;
-
- list = g_new0 (char *, array->len + 1);
- for (i = 0; i < array->len; i++) {
- char *buf = g_new (char, INET_ADDRSTRLEN);
- guint32 addr;
-
- addr = g_array_index (array, guint32, i);
- nm_utils_inet4_ntop (addr, buf);
- list[num++] = buf;
+ list = g_value_get_boxed (value);
+ if (list && list[0]) {
+ nm_keyfile_plugin_kf_set_string_list (file, nm_setting_get_name (setting), key,
+ (const char **) list, g_strv_length (list));
}
-
- nm_keyfile_plugin_kf_set_string_list (file, nm_setting_get_name (setting), key, (const char **) list, num);
- g_strfreev (list);
}
static void
@@ -148,12 +132,21 @@ write_ip4_values (GKeyFile *file,
output = g_string_sized_new (2*INET_ADDRSTRLEN + 10);
for (i = 0; i < array->len; i++) {
- GArray *tuple = g_ptr_array_index (array, i);
+ if (is_route) {
+ NMIP4Route *route = array->pdata[i];
- addr = g_array_index (tuple, guint32, 0);
- plen = g_array_index (tuple, guint32, 1);
- gw = g_array_index (tuple, guint32, 2);
- metric = is_route ? g_array_index (tuple, guint32, 3) : 0;
+ addr = nm_ip4_route_get_dest (route);
+ plen = nm_ip4_route_get_prefix (route);
+ gw = nm_ip4_route_get_next_hop (route);
+ metric = nm_ip4_route_get_metric (route);
+ } else {
+ NMIP4Address *address = array->pdata[i];
+
+ addr = nm_ip4_address_get_address (address);
+ plen = nm_ip4_address_get_prefix (address);
+ gw = nm_ip4_address_get_gateway (address);
+ metric = 0;
+ }
g_string_set_size (output, 0);
g_string_append_printf (output, "%s/%u",
@@ -187,8 +180,6 @@ ip4_addr_writer (GKeyFile *file,
GPtrArray *array;
const char *setting_name = nm_setting_get_name (setting);
- g_return_if_fail (G_VALUE_HOLDS (value, DBUS_TYPE_G_ARRAY_OF_ARRAY_OF_UINT));
-
array = (GPtrArray *) g_value_get_boxed (value);
if (array && array->len)
write_ip4_values (file, setting_name, array, FALSE);
@@ -216,8 +207,6 @@ ip4_route_writer (GKeyFile *file,
GPtrArray *array;
const char *setting_name = nm_setting_get_name (setting);
- g_return_if_fail (G_VALUE_HOLDS (value, DBUS_TYPE_G_ARRAY_OF_ARRAY_OF_UINT));
-
array = (GPtrArray *) g_value_get_boxed (value);
if (array && array->len)
write_ip4_values (file, setting_name, array, TRUE);
@@ -231,79 +220,38 @@ ip6_dns_writer (GKeyFile *file,
const char *key,
const GValue *value)
{
- GPtrArray *array;
- GByteArray *byte_array;
char **list;
- int i, num = 0;
-
- g_return_if_fail (G_VALUE_HOLDS (value, DBUS_TYPE_G_ARRAY_OF_ARRAY_OF_UCHAR));
- array = (GPtrArray *) g_value_get_boxed (value);
- if (!array || !array->len)
- return;
-
- list = g_new0 (char *, array->len + 1);
-
- for (i = 0; i < array->len; i++) {
- char *buf = g_new (char, INET6_ADDRSTRLEN);
-
- byte_array = g_ptr_array_index (array, i);
- nm_utils_inet6_ntop ((const struct in6_addr *) byte_array->data, buf);
- list[num++] = buf;
+ list = g_value_get_boxed (value);
+ if (list && list[0]) {
+ nm_keyfile_plugin_kf_set_string_list (file, nm_setting_get_name (setting), key,
+ (const char **) list, g_strv_length (list));
}
-
- nm_keyfile_plugin_kf_set_string_list (file, nm_setting_get_name (setting), key, (const char **) list, num);
- g_strfreev (list);
-}
-
-static void
-ip6_array_to_addr (GValueArray *values,
- guint32 idx,
- char *buf,
- struct in6_addr *out_addr)
-{
- GByteArray *byte_array;
- GValue *addr_val;
- const struct in6_addr *addr;
-
- addr_val = g_value_array_get_nth (values, idx);
- byte_array = g_value_get_boxed (addr_val);
- addr = (const struct in6_addr *) byte_array->data;
-
- nm_utils_inet6_ntop (addr, buf);
-
- if (out_addr)
- *out_addr = *addr;
}
static char *
-ip6_array_to_addr_prefix (GValueArray *values, gboolean force_write_gateway)
+ip6_values_to_addr_prefix (const struct in6_addr *addr, guint prefix, const struct in6_addr *gw,
+ gboolean force_write_gateway)
{
- GValue *prefix_val;
- char *ret = NULL;
GString *ip6_str;
char buf[INET6_ADDRSTRLEN];
- struct in6_addr addr;
/* address */
- ip6_array_to_addr (values, 0, buf, NULL);
+ nm_utils_inet6_ntop (addr, buf);
/* Enough space for the address, '/', and the prefix */
ip6_str = g_string_sized_new ((INET6_ADDRSTRLEN * 2) + 5);
/* prefix */
g_string_append (ip6_str, buf);
- prefix_val = g_value_array_get_nth (values, 1);
- g_string_append_printf (ip6_str, "/%u", g_value_get_uint (prefix_val));
+ g_string_append_printf (ip6_str, "/%u", prefix);
- ip6_array_to_addr (values, 2, buf, &addr);
- if (force_write_gateway || !IN6_IS_ADDR_UNSPECIFIED (&addr))
+ /* gateway */
+ nm_utils_inet6_ntop (gw, buf);
+ if (force_write_gateway || !IN6_IS_ADDR_UNSPECIFIED (gw))
g_string_append_printf (ip6_str, ",%s", buf);
- ret = ip6_str->str;
- g_string_free (ip6_str, FALSE);
-
- return ret;
+ return g_string_free (ip6_str, FALSE);
}
static void
@@ -318,24 +266,19 @@ ip6_addr_writer (GKeyFile *file,
const char *setting_name = nm_setting_get_name (setting);
int i, j;
- g_return_if_fail (G_VALUE_HOLDS (value, DBUS_TYPE_G_ARRAY_OF_IP6_ADDRESS));
-
array = (GPtrArray *) g_value_get_boxed (value);
if (!array || !array->len)
return;
for (i = 0, j = 1; i < array->len; i++) {
- GValueArray *values = g_ptr_array_index (array, i);
+ NMIP6Address *addr = array->pdata[i];
char *key_name, *ip6_addr;
- if (values->n_values != 3) {
- nm_log_warn (LOGD_SETTINGS, "%s: error writing IP6 address %d (address array "
- "length %d is not 3)", __func__, i, values->n_values);
- continue;
- }
-
- /* we allow omitting the gateway if it's :: */
- ip6_addr = ip6_array_to_addr_prefix (values, FALSE);
+ ip6_addr = ip6_values_to_addr_prefix (nm_ip6_address_get_address (addr),
+ nm_ip6_address_get_prefix (addr),
+ nm_ip6_address_get_gateway (addr),
+ /* we allow omitting the gateway if it's :: */
+ FALSE);
/* Write it out */
key_name = g_strdup_printf ("address%d", j++);
nm_keyfile_plugin_kf_set_string (file, setting_name, key_name, ip6_addr);
@@ -357,14 +300,12 @@ ip6_route_writer (GKeyFile *file,
GString *output;
int i, j;
- g_return_if_fail (G_VALUE_HOLDS (value, DBUS_TYPE_G_ARRAY_OF_IP6_ROUTE));
-
array = (GPtrArray *) g_value_get_boxed (value);
if (!array || !array->len)
return;
for (i = 0, j = 1; i < array->len; i++) {
- GValueArray *values = g_ptr_array_index (array, i);
+ NMIP6Route *route = array->pdata[i];
char *key_name;
char *addr_str;
guint metric;
@@ -372,8 +313,7 @@ ip6_route_writer (GKeyFile *file,
output = g_string_new ("");
/* Metric */
- value = g_value_array_get_nth (values, 3);
- metric = g_value_get_uint (value);
+ metric = nm_ip6_route_get_metric (route);
/* Address, prefix and next hop
* We allow omitting the gateway ::, if we also omit the metric
@@ -385,7 +325,10 @@ ip6_route_writer (GKeyFile *file,
* But if possible, we omit them both (",::,0") or only the metric
* (",0").
**/
- addr_str = ip6_array_to_addr_prefix (values, metric != 0);
+ addr_str = ip6_values_to_addr_prefix (nm_ip6_route_get_dest (route),
+ nm_ip6_route_get_prefix (route),
+ nm_ip6_route_get_next_hop (route),
+ metric != 0);
g_string_append (output, addr_str);
g_free (addr_str);