NetworkManager r4233 - in trunk: . callouts libnm-glib libnm-util src src/dhcp-manager src/dnsmasq-manager src/ppp-manager src/vpn-manager system-settings/plugins/ifcfg-fedora system-settings/plugins/ifcfg-suse system-settings/plugins/ifupdown test vpn-daemons/vpnc/properties



Author: dcbw
Date: Wed Oct 29 14:35:25 2008
New Revision: 4233
URL: http://svn.gnome.org/viewvc/NetworkManager?rev=4233&view=rev

Log:
2008-10-29  Dan Williams  <dcbw redhat com>

	* libnm-util/libnm-util.ver
	  libnm-util/nm-setting-ip4-config.c
	  libnm-util/nm-setting-ip4-config.h
		- Make properties private and add accessor functions

	* callouts/nm-dispatcher-action.c
	  libnm-glib/libnm-glib-test.c
	  libnm-util/nm-utils.c
	  src/NetworkManagerPolicy.c
	  src/NetworkManagerSystem.c
	  src/NetworkManagerUtils.c
	  src/dhcp-manager/nm-dhcp-dhclient.c
	  src/dhcp-manager/nm-dhcp-manager.c
	  src/dnsmasq-manager/nm-dnsmasq-manager.c
	  src/nm-device-wifi.c
	  src/nm-device.c
	  src/nm-hso-gsm-device.c
	  src/nm-ip4-config.c
	  src/nm-ip4-config.h
	  src/ppp-manager/nm-ppp-manager.c
	  src/vpn-manager/nm-vpn-connection.c
	  system-settings/plugins/ifcfg-fedora/reader.c
	  system-settings/plugins/ifcfg-suse/parser.c
	  system-settings/plugins/ifcfg-suse/plugin.c
	  system-settings/plugins/ifupdown/parser.c
	  test/nm-tool.c
	  vpn-daemons/vpnc/properties/nm-vpnc.c
		- Use IP4 accessor functions



Modified:
   trunk/ChangeLog
   trunk/callouts/nm-dispatcher-action.c
   trunk/libnm-glib/libnm-glib-test.c
   trunk/libnm-glib/nm-ip4-config.c
   trunk/libnm-util/libnm-util.ver
   trunk/libnm-util/nm-setting-ip4-config.c
   trunk/libnm-util/nm-setting-ip4-config.h
   trunk/libnm-util/nm-utils.c
   trunk/src/NetworkManagerPolicy.c
   trunk/src/NetworkManagerSystem.c
   trunk/src/NetworkManagerUtils.c
   trunk/src/dhcp-manager/nm-dhcp-dhclient.c
   trunk/src/dhcp-manager/nm-dhcp-manager.c
   trunk/src/dnsmasq-manager/nm-dnsmasq-manager.c
   trunk/src/nm-device-wifi.c
   trunk/src/nm-device.c
   trunk/src/nm-hso-gsm-device.c
   trunk/src/nm-ip4-config.c
   trunk/src/nm-ip4-config.h
   trunk/src/ppp-manager/nm-ppp-manager.c
   trunk/src/vpn-manager/nm-vpn-connection.c
   trunk/system-settings/plugins/ifcfg-fedora/reader.c
   trunk/system-settings/plugins/ifcfg-suse/parser.c
   trunk/system-settings/plugins/ifcfg-suse/plugin.c
   trunk/system-settings/plugins/ifupdown/parser.c
   trunk/test/nm-tool.c
   trunk/vpn-daemons/vpnc/properties/nm-vpnc.c

Modified: trunk/callouts/nm-dispatcher-action.c
==============================================================================
--- trunk/callouts/nm-dispatcher-action.c	(original)
+++ trunk/callouts/nm-dispatcher-action.c	Wed Oct 29 14:35:25 2008
@@ -273,22 +273,23 @@
 
 	/* IP4 config stuff */
 	for (iter = addresses, num = 0; iter; iter = g_slist_next (iter)) {
-		NMSettingIP4Address *addr = (NMSettingIP4Address *) iter->data;
+		NMIP4Address *addr = (NMIP4Address *) iter->data;
 		char str_addr[INET_ADDRSTRLEN + 1];
 		char str_gw[INET_ADDRSTRLEN + 1];
 		struct in_addr tmp_addr;
+		guint32 prefix = nm_ip4_address_get_prefix (addr);
 
 		memset (str_addr, 0, sizeof (str_addr));
-		tmp_addr.s_addr = addr->address;
+		tmp_addr.s_addr = nm_ip4_address_get_address (addr);
 		if (!inet_ntop (AF_INET, &tmp_addr, str_addr, sizeof (str_addr)))
 			continue;
 
 		memset (str_gw, 0, sizeof (str_gw));
-		tmp_addr.s_addr = addr->gateway;
+		tmp_addr.s_addr = nm_ip4_address_get_gateway (addr);
 		inet_ntop (AF_INET, &tmp_addr, str_gw, sizeof (str_gw));
 
 		tmp = g_string_sized_new (25 + strlen (str_addr) + strlen (str_gw));
-		g_string_append_printf (tmp, "IP4_ADDRESS_%d=%s/%d %s", num++, str_addr, addr->prefix, str_gw);
+		g_string_append_printf (tmp, "IP4_ADDRESS_%d=%s/%d %s", num++, str_addr, prefix, str_gw);
 		envp[envp_idx++] = tmp->str;
 		g_string_free (tmp, FALSE);
 	}
@@ -328,22 +329,24 @@
 	}
 
 	for (iter = routes, num = 0; iter; iter = g_slist_next (iter)) {
-		NMSettingIP4Route *route = (NMSettingIP4Route *) iter->data;
+		NMIP4Route *route = (NMIP4Route *) iter->data;
 		char str_addr[INET_ADDRSTRLEN + 1];
 		char str_nh[INET_ADDRSTRLEN + 1];
 		struct in_addr tmp_addr;
+		guint32 prefix = nm_ip4_route_get_prefix (route);
+		guint32 metric = nm_ip4_route_get_metric (route);
 
 		memset (str_addr, 0, sizeof (str_addr));
-		tmp_addr.s_addr = route->address;
+		tmp_addr.s_addr = nm_ip4_route_get_dest (route);
 		if (!inet_ntop (AF_INET, &tmp_addr, str_addr, sizeof (str_addr)))
 			continue;
 
 		memset (str_nh, 0, sizeof (str_nh));
-		tmp_addr.s_addr = route->next_hop;
+		tmp_addr.s_addr = nm_ip4_route_get_next_hop (route);
 		inet_ntop (AF_INET, &tmp_addr, str_nh, sizeof (str_nh));
 
 		tmp = g_string_sized_new (30 + strlen (str_addr) + strlen (str_nh));
-		g_string_append_printf (tmp, "IP4_ROUTE_%d=%s/%d %s %d", num++, str_addr, route->prefix, str_nh, route->metric);
+		g_string_append_printf (tmp, "IP4_ROUTE_%d=%s/%d %s %d", num++, str_addr, prefix, str_nh, metric);
 		envp[envp_idx++] = tmp->str;
 		g_string_free (tmp, FALSE);
 	}

Modified: trunk/libnm-glib/libnm-glib-test.c
==============================================================================
--- trunk/libnm-glib/libnm-glib-test.c	(original)
+++ trunk/libnm-glib/libnm-glib-test.c	Wed Oct 29 14:35:25 2008
@@ -73,17 +73,19 @@
 	int i;
 
 	for (iter = (GSList *) nm_ip4_config_get_addresses (cfg); iter; iter = g_slist_next (iter)) {
-		NMSettingIP4Address *addr = iter->data;
+		NMIP4Address *addr = iter->data;
+		guint32 u;
 
-		tmp = ip4_address_as_string (addr->address);
+		tmp = ip4_address_as_string (nm_ip4_address_get_address (addr));
 		g_print ("IP4 address: %s\n", tmp);
 		g_free (tmp);
 
-		tmp = ip4_address_as_string (nm_utils_ip4_prefix_to_netmask (addr->prefix));
-		g_print ("IP4 prefix: %d (%s)\n", addr->prefix, tmp);
+		u = nm_ip4_address_get_prefix (addr);
+		tmp = ip4_address_as_string (nm_utils_ip4_prefix_to_netmask (u));
+		g_print ("IP4 prefix: %d (%s)\n", u, tmp);
 		g_free (tmp);
 
-		tmp = ip4_address_as_string (addr->gateway);
+		tmp = ip4_address_as_string (nm_ip4_address_get_gateway (addr));
 		g_print ("IP4 gateway: %s\n\n", tmp);
 		g_free (tmp);
 	}

Modified: trunk/libnm-glib/nm-ip4-config.c
==============================================================================
--- trunk/libnm-glib/nm-ip4-config.c	(original)
+++ trunk/libnm-glib/nm-ip4-config.c	Wed Oct 29 14:35:25 2008
@@ -1,5 +1,6 @@
 #include <string.h>
 
+#include <nm-setting-ip4-config.h>
 #include "nm-ip4-config.h"
 #include "NetworkManager.h"
 #include "nm-types-private.h"
@@ -41,7 +42,7 @@
 {
 	NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (object);
 
-	g_slist_foreach (priv->addresses, (GFunc) g_free, NULL);
+	g_slist_foreach (priv->addresses, (GFunc) nm_ip4_address_unref, NULL);
 	g_slist_free (priv->addresses);
 	priv->addresses = NULL;
 

Modified: trunk/libnm-util/libnm-util.ver
==============================================================================
--- trunk/libnm-util/libnm-util.ver	(original)
+++ trunk/libnm-util/libnm-util.ver	Wed Oct 29 14:35:25 2008
@@ -77,6 +77,31 @@
 	nm_setting_ip4_config_error_quark;
 	nm_setting_ip4_config_get_type;
 	nm_setting_ip4_config_new;
+	nm_setting_ip4_config_get_method;
+	nm_setting_ip4_config_get_num_dns;
+	nm_setting_ip4_config_get_dns;
+	nm_setting_ip4_config_add_dns;
+	nm_setting_ip4_config_remove_dns;
+	nm_setting_ip4_config_clear_dns;
+	nm_setting_ip4_config_get_num_dns_searches;
+	nm_setting_ip4_config_get_dns_search;
+	nm_setting_ip4_config_add_dns_search;
+	nm_setting_ip4_config_remove_dns_search;
+	nm_setting_ip4_config_clear_dns_searches;
+	nm_setting_ip4_config_get_num_addresses;
+	nm_setting_ip4_config_get_address;
+	nm_setting_ip4_config_add_address;
+	nm_setting_ip4_config_remove_address;
+	nm_setting_ip4_config_clear_addresses;
+	nm_setting_ip4_config_get_num_routes;
+	nm_setting_ip4_config_get_route;
+	nm_setting_ip4_config_add_route;
+	nm_setting_ip4_config_remove_route;
+	nm_setting_ip4_config_clear_routes;
+	nm_setting_ip4_config_get_ignore_auto_routes;
+	nm_setting_ip4_config_get_ignore_auto_dns;
+	nm_setting_ip4_config_get_dhcp_client_id;
+	nm_setting_ip4_config_get_dhcp_hostname;
 	nm_setting_ip6_config_error_get_type;
 	nm_setting_ip6_config_error_quark;
 	nm_setting_ip6_config_get_type;
@@ -197,6 +222,28 @@
 	nm_utils_string_slist_validate;
 	nm_utils_uuid_generate;
 	nm_utils_uuid_generate_from_string;
+	nm_ip4_address_new;
+	nm_ip4_address_dup;
+	nm_ip4_address_ref;
+	nm_ip4_address_unref;
+	nm_ip4_address_get_address;
+	nm_ip4_address_set_address;
+	nm_ip4_address_get_prefix;
+	nm_ip4_address_set_prefix;
+	nm_ip4_address_get_gateway;
+	nm_ip4_address_set_gateway;
+	nm_ip4_route_new;
+	nm_ip4_route_dup;
+	nm_ip4_route_ref;
+	nm_ip4_route_unref;
+	nm_ip4_route_get_dest;
+	nm_ip4_route_set_dest;
+	nm_ip4_route_get_prefix;
+	nm_ip4_route_set_prefix;
+	nm_ip4_route_get_next_hop;
+	nm_ip4_route_set_next_hop;
+	nm_ip4_route_get_metric;
+	nm_ip4_route_set_metric;
 local:
 	*;
 };

Modified: trunk/libnm-util/nm-setting-ip4-config.c
==============================================================================
--- trunk/libnm-util/nm-setting-ip4-config.c	(original)
+++ trunk/libnm-util/nm-setting-ip4-config.c	Wed Oct 29 14:35:25 2008
@@ -69,6 +69,20 @@
 
 G_DEFINE_TYPE (NMSettingIP4Config, nm_setting_ip4_config, NM_TYPE_SETTING)
 
+#define NM_SETTING_IP4_CONFIG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_IP4_CONFIG, NMSettingIP4ConfigPrivate))
+
+typedef struct {
+	char *method;
+	GArray *dns;        /* array of guint32; elements in network byte order */
+	GSList *dns_search; /* list of strings */
+	GSList *addresses;  /* array of NMIP4Address */
+	GSList *routes;     /* array of NMIP4Route */
+	gboolean ignore_auto_routes;
+	gboolean ignore_auto_dns;
+	char *dhcp_client_id;
+	char *dhcp_hostname;
+} NMSettingIP4ConfigPrivate;
+
 enum {
 	PROP_0,
 	PROP_METHOD,
@@ -90,14 +104,328 @@
 	return (NMSetting *) g_object_new (NM_TYPE_SETTING_IP4_CONFIG, NULL);
 }
 
+const char *
+nm_setting_ip4_config_get_method (NMSettingIP4Config *setting)
+{
+	g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), NULL);
+
+	return NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting)->method;
+}
+
+guint32
+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;
+}
+
+guint32
+nm_setting_ip4_config_get_dns (NMSettingIP4Config *setting, guint32 i)
+{
+	NMSettingIP4ConfigPrivate *priv;
+
+	g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), 0);
+
+	priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting);
+	g_return_val_if_fail (i <= priv->dns->len, 0);
+
+	return g_array_index (priv->dns, guint32, i);
+}
+
+gboolean
+nm_setting_ip4_config_add_dns (NMSettingIP4Config *setting, guint32 dns)
+{
+	NMSettingIP4ConfigPrivate *priv;
+	int i;
+
+	g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), 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))
+			return FALSE;
+	}
+
+	g_array_append_val (priv->dns, dns);
+	return TRUE;
+}
+
+void
+nm_setting_ip4_config_remove_dns (NMSettingIP4Config *setting, guint32 i)
+{
+	NMSettingIP4ConfigPrivate *priv;
+
+	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);
+
+	g_array_remove_index (priv->dns, i);
+}
+
+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);
+}
+
+guint32
+nm_setting_ip4_config_get_num_dns_searches (NMSettingIP4Config *setting)
+{
+	g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), 0);
+
+	return g_slist_length (NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting)->dns_search);
+}
+
+const char *
+nm_setting_ip4_config_get_dns_search (NMSettingIP4Config *setting, guint32 i)
+{
+	NMSettingIP4ConfigPrivate *priv;
+
+	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);
+
+	return (const char *) g_slist_nth_data (priv->dns_search, i);
+}
+
+gboolean
+nm_setting_ip4_config_add_dns_search (NMSettingIP4Config *setting,
+                                      const char *dns_search)
+{
+	NMSettingIP4ConfigPrivate *priv;
+	GSList *iter;
+
+	g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), FALSE);
+	g_return_val_if_fail (dns_search != NULL, FALSE);
+	g_return_val_if_fail (dns_search[0] != '\0', FALSE);
+
+	priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting);
+	for (iter = priv->dns_search; iter; iter = g_slist_next (iter)) {
+		if (!strcmp (dns_search, (char *) iter->data))
+			return FALSE;
+	}
+
+	priv->dns_search = g_slist_append (priv->dns_search, g_strdup (dns_search));
+	return TRUE;
+}
+
+void
+nm_setting_ip4_config_remove_dns_search (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);
+	elt = g_slist_nth (priv->dns_search, i);
+	g_return_if_fail (elt != NULL);
+
+	g_free (elt->data);
+	priv->dns_search = g_slist_delete_link (priv->dns_search, elt);
+}
+
+void
+nm_setting_ip4_config_clear_dns_searches (NMSettingIP4Config *setting)
+{
+	g_return_if_fail (NM_IS_SETTING_IP4_CONFIG (setting));
+
+	nm_utils_slist_free (NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting)->dns_search, g_free);
+	NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting)->dns_search = NULL;
+}
+
+guint32
+nm_setting_ip4_config_get_num_addresses (NMSettingIP4Config *setting)
+{
+	g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), 0);
+
+	return g_slist_length (NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting)->addresses);
+}
+
+NMIP4Address *
+nm_setting_ip4_config_get_address (NMSettingIP4Config *setting, guint32 i)
+{
+	NMSettingIP4ConfigPrivate *priv;
+
+	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);
+
+	return (NMIP4Address *) g_slist_nth_data (priv->addresses, i);
+}
+
+gboolean
+nm_setting_ip4_config_add_address (NMSettingIP4Config *setting,
+                                   NMIP4Address *address)
+{
+	NMSettingIP4ConfigPrivate *priv;
+	NMIP4Address *copy;
+	GSList *iter;
+
+	g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), FALSE);
+	g_return_val_if_fail (address != NULL, FALSE);
+
+	priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting);
+	for (iter = priv->addresses; iter; iter = g_slist_next (iter)) {
+		if (nm_ip4_address_compare ((NMIP4Address *) iter->data, address))
+			return FALSE;
+	}
+
+	copy = nm_ip4_address_dup (address);
+	g_return_val_if_fail (copy != NULL, FALSE);
+
+	priv->addresses = g_slist_append (priv->addresses, copy);
+	return TRUE;
+}
+
+void
+nm_setting_ip4_config_remove_address (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);
+	elt = g_slist_nth (priv->addresses, i);
+	g_return_if_fail (elt != NULL);
+
+	nm_ip4_address_unref ((NMIP4Address *) elt->data);
+	priv->addresses = g_slist_delete_link (priv->addresses, elt);
+}
+
+void
+nm_setting_ip4_config_clear_addresses (NMSettingIP4Config *setting)
+{
+	NMSettingIP4ConfigPrivate *priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting);
+
+	g_return_if_fail (NM_IS_SETTING_IP4_CONFIG (setting));
+
+	nm_utils_slist_free (priv->addresses, (GDestroyNotify) nm_ip4_address_unref);
+	priv->addresses = NULL;
+}
+
+guint32
+nm_setting_ip4_config_get_num_routes (NMSettingIP4Config *setting)
+{
+	g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), 0);
+
+	return g_slist_length (NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting)->routes);
+}
+
+NMIP4Route *
+nm_setting_ip4_config_get_route (NMSettingIP4Config *setting, guint32 i)
+{
+	NMSettingIP4ConfigPrivate *priv;
+
+	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);
+
+	return (NMIP4Route *) g_slist_nth_data (priv->routes, i);
+}
+
+gboolean
+nm_setting_ip4_config_add_route (NMSettingIP4Config *setting,
+                                 NMIP4Route *route)
+{
+	NMSettingIP4ConfigPrivate *priv;
+	NMIP4Route *copy;
+	GSList *iter;
+
+	g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), FALSE);
+	g_return_val_if_fail (route != NULL, FALSE);
+
+	priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting);
+	for (iter = priv->routes; iter; iter = g_slist_next (iter)) {
+		if (nm_ip4_route_compare ((NMIP4Route *) iter->data, route))
+			return FALSE;
+	}
+
+	copy = nm_ip4_route_dup (route);
+	g_return_val_if_fail (copy != NULL, FALSE);
+
+	priv->routes = g_slist_append (priv->routes, copy);
+	return TRUE;
+}
+
+void
+nm_setting_ip4_config_remove_route (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);
+	elt = g_slist_nth (priv->routes, i);
+	g_return_if_fail (elt != NULL);
+
+	nm_ip4_route_unref ((NMIP4Route *) elt->data);
+	priv->routes = g_slist_delete_link (priv->routes, elt);
+}
+
+void
+nm_setting_ip4_config_clear_routes (NMSettingIP4Config *setting)
+{
+	NMSettingIP4ConfigPrivate *priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting);
+
+	g_return_if_fail (NM_IS_SETTING_IP4_CONFIG (setting));
+
+	nm_utils_slist_free (priv->routes, (GDestroyNotify) nm_ip4_route_unref);
+	priv->routes = NULL;
+}
+
+gboolean
+nm_setting_ip4_config_get_ignore_auto_routes (NMSettingIP4Config *setting)
+{
+	g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), FALSE);
+
+	return NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting)->ignore_auto_routes;
+}
+
+gboolean
+nm_setting_ip4_config_get_ignore_auto_dns (NMSettingIP4Config *setting)
+{
+	g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), FALSE);
+
+	return NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting)->ignore_auto_dns;
+}
+
+const char *
+nm_setting_ip4_config_get_dhcp_client_id (NMSettingIP4Config *setting)
+{
+	g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), FALSE);
+
+	return NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting)->dhcp_client_id;
+}
+
+const char *
+nm_setting_ip4_config_get_dhcp_hostname (NMSettingIP4Config *setting)
+{
+	g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), FALSE);
+
+	return NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting)->dhcp_hostname;
+}
+
 static gboolean
 verify (NMSetting *setting, GSList *all_settings, GError **error)
 {
-	NMSettingIP4Config *self = NM_SETTING_IP4_CONFIG (setting);
+	NMSettingIP4ConfigPrivate *priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting);
 	GSList *iter;
 	int i;
 
-	if (!self->method) {
+	if (!priv->method) {
 		g_set_error (error,
 		             NM_SETTING_IP4_CONFIG_ERROR,
 		             NM_SETTING_IP4_CONFIG_ERROR_MISSING_PROPERTY,
@@ -105,17 +433,17 @@
 		return FALSE;
 	}
 
-	if (!strcmp (self->method, NM_SETTING_IP4_CONFIG_METHOD_MANUAL)) {
-		if (!self->addresses) {
+	if (!strcmp (priv->method, NM_SETTING_IP4_CONFIG_METHOD_MANUAL)) {
+		if (!priv->addresses) {
 			g_set_error (error,
 			             NM_SETTING_IP4_CONFIG_ERROR,
 			             NM_SETTING_IP4_CONFIG_ERROR_MISSING_PROPERTY,
 			             NM_SETTING_IP4_CONFIG_ADDRESSES);
 			return FALSE;
 		}
-	} else if (   !strcmp (self->method, NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL)
-	           || !strcmp (self->method, NM_SETTING_IP4_CONFIG_METHOD_SHARED)) {
-		if (self->dns && self->dns->len) {
+	} else if (   !strcmp (priv->method, NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL)
+	           || !strcmp (priv->method, NM_SETTING_IP4_CONFIG_METHOD_SHARED)) {
+		if (priv->dns && priv->dns->len) {
 			g_set_error (error,
 			             NM_SETTING_IP4_CONFIG_ERROR,
 			             NM_SETTING_IP4_CONFIG_ERROR_NOT_ALLOWED_FOR_METHOD,
@@ -123,7 +451,7 @@
 			return FALSE;
 		}
 
-		if (g_slist_length (self->dns_search)) {
+		if (g_slist_length (priv->dns_search)) {
 			g_set_error (error,
 			             NM_SETTING_IP4_CONFIG_ERROR,
 			             NM_SETTING_IP4_CONFIG_ERROR_NOT_ALLOWED_FOR_METHOD,
@@ -131,14 +459,14 @@
 			return FALSE;
 		}
 
-		if (g_slist_length (self->addresses)) {
+		if (g_slist_length (priv->addresses)) {
 			g_set_error (error,
 			             NM_SETTING_IP4_CONFIG_ERROR,
 			             NM_SETTING_IP4_CONFIG_ERROR_NOT_ALLOWED_FOR_METHOD,
 			             NM_SETTING_IP4_CONFIG_ADDRESSES);
 			return FALSE;
 		}
-	} else if (!strcmp (self->method, NM_SETTING_IP4_CONFIG_METHOD_AUTO)) {
+	} else if (!strcmp (priv->method, NM_SETTING_IP4_CONFIG_METHOD_AUTO)) {
 		/* nothing to do */
 	} else {
 		g_set_error (error,
@@ -148,7 +476,7 @@
 		return FALSE;
 	}
 
-	if (self->dhcp_client_id && !strlen (self->dhcp_client_id)) {
+	if (priv->dhcp_client_id && !strlen (priv->dhcp_client_id)) {
 		g_set_error (error,
 		             NM_SETTING_IP4_CONFIG_ERROR,
 		             NM_SETTING_IP4_CONFIG_ERROR_INVALID_PROPERTY,
@@ -156,7 +484,7 @@
 		return FALSE;
 	}
 
-	if (self->dhcp_hostname && !strlen (self->dhcp_hostname)) {
+	if (priv->dhcp_hostname && !strlen (priv->dhcp_hostname)) {
 		g_set_error (error,
 		             NM_SETTING_IP4_CONFIG_ERROR,
 		             NM_SETTING_IP4_CONFIG_ERROR_INVALID_PROPERTY,
@@ -165,10 +493,11 @@
 	}
 
 	/* Validate addresses */
-	for (iter = self->addresses, i = 0; iter; iter = g_slist_next (iter), i++) {
-		NMSettingIP4Address *addr = (NMSettingIP4Address *) iter->data;
+	for (iter = priv->addresses, i = 0; iter; iter = g_slist_next (iter), i++) {
+		NMIP4Address *addr = (NMIP4Address *) iter->data;
+		guint32 prefix = nm_ip4_address_get_prefix (addr);
 
-		if (!addr->address) {
+		if (!nm_ip4_address_get_address (addr)) {
 			g_set_error (error,
 			             NM_SETTING_IP4_CONFIG_ERROR,
 			             NM_SETTING_IP4_CONFIG_ERROR_INVALID_PROPERTY,
@@ -176,7 +505,7 @@
 			return FALSE;
 		}
 
-		if (!addr->prefix || addr->prefix > 32) {
+		if (!prefix || prefix > 32) {
 			g_set_error (error,
 			             NM_SETTING_IP4_CONFIG_ERROR,
 			             NM_SETTING_IP4_CONFIG_ERROR_INVALID_PROPERTY,
@@ -186,10 +515,11 @@
 	}
 
 	/* Validate routes */
-	for (iter = self->routes, i = 0; iter; iter = g_slist_next (iter), i++) {
-		NMSettingIP4Route *route = (NMSettingIP4Route *) iter->data;
+	for (iter = priv->routes, i = 0; iter; iter = g_slist_next (iter), i++) {
+		NMIP4Route *route = (NMIP4Route *) iter->data;
+		guint32 prefix = nm_ip4_route_get_prefix (route);
 
-		if (!route->address) {
+		if (!nm_ip4_route_get_dest (route)) {
 			g_set_error (error,
 			             NM_SETTING_IP4_CONFIG_ERROR,
 			             NM_SETTING_IP4_CONFIG_ERROR_INVALID_PROPERTY,
@@ -197,7 +527,7 @@
 			return FALSE;
 		}
 
-		if (!route->prefix || route->prefix > 32) {
+		if (!prefix || prefix > 32) {
 			g_set_error (error,
 			             NM_SETTING_IP4_CONFIG_ERROR,
 			             NM_SETTING_IP4_CONFIG_ERROR_INVALID_PROPERTY,
@@ -213,22 +543,26 @@
 static void
 nm_setting_ip4_config_init (NMSettingIP4Config *setting)
 {
+	NMSettingIP4ConfigPrivate *priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting);
+
 	g_object_set (setting, NM_SETTING_NAME, NM_SETTING_IP4_CONFIG_SETTING_NAME, NULL);
+
+	priv->dns = g_array_sized_new (FALSE, TRUE, sizeof (guint32), 3);
 }
 
 static void
 finalize (GObject *object)
 {
 	NMSettingIP4Config *self = NM_SETTING_IP4_CONFIG (object);
+	NMSettingIP4ConfigPrivate *priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (self);
 
-	g_free (self->method);
+	g_free (priv->method);
 
-	if (self->dns)
-		g_array_free (self->dns, TRUE);
+	g_array_free (priv->dns, TRUE);
 
-	nm_utils_slist_free (self->dns_search, g_free);
-	nm_utils_slist_free (self->addresses, g_free);
-	nm_utils_slist_free (self->routes, g_free);
+	nm_utils_slist_free (priv->dns_search, g_free);
+	nm_utils_slist_free (priv->addresses, (GDestroyNotify) nm_ip4_address_unref);
+	nm_utils_slist_free (priv->routes, (GDestroyNotify) nm_ip4_route_unref);
 
 	G_OBJECT_CLASS (nm_setting_ip4_config_parent_class)->finalize (object);
 }
@@ -238,42 +572,44 @@
 		    const GValue *value, GParamSpec *pspec)
 {
 	NMSettingIP4Config *setting = NM_SETTING_IP4_CONFIG (object);
+	NMSettingIP4ConfigPrivate *priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting);
 
 	switch (prop_id) {
 	case PROP_METHOD:
-		g_free (setting->method);
-		setting->method = g_value_dup_string (value);
+		g_free (priv->method);
+		priv->method = g_value_dup_string (value);
 		break;
 	case PROP_DNS:
-		if (setting->dns)
-			g_array_free (setting->dns, TRUE);
-		setting->dns = g_value_dup_boxed (value);
+		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);			
 		break;
 	case PROP_DNS_SEARCH:
-		nm_utils_slist_free (setting->dns_search, g_free);
-		setting->dns_search = g_value_dup_boxed (value);
+		nm_utils_slist_free (priv->dns_search, g_free);
+		priv->dns_search = g_value_dup_boxed (value);
 		break;
 	case PROP_ADDRESSES:
-		nm_utils_slist_free (setting->addresses, g_free);
-		setting->addresses = nm_utils_ip4_addresses_from_gvalue (value);
+		nm_utils_slist_free (priv->addresses, (GDestroyNotify) nm_ip4_address_unref);
+		priv->addresses = nm_utils_ip4_addresses_from_gvalue (value);
 		break;
 	case PROP_ROUTES:
-		nm_utils_slist_free (setting->routes, g_free);
-		setting->routes = nm_utils_ip4_routes_from_gvalue (value);
+		nm_utils_slist_free (priv->routes, (GDestroyNotify) nm_ip4_route_unref);
+		priv->routes = nm_utils_ip4_routes_from_gvalue (value);
 		break;
 	case PROP_IGNORE_AUTO_ROUTES:
-		setting->ignore_auto_routes = g_value_get_boolean (value);
+		priv->ignore_auto_routes = g_value_get_boolean (value);
 		break;
 	case PROP_IGNORE_AUTO_DNS:
-		setting->ignore_auto_dns = g_value_get_boolean (value);
+		priv->ignore_auto_dns = g_value_get_boolean (value);
 		break;
 	case PROP_DHCP_CLIENT_ID:
-		g_free (setting->dhcp_client_id);
-		setting->dhcp_client_id = g_value_dup_string (value);
+		g_free (priv->dhcp_client_id);
+		priv->dhcp_client_id = g_value_dup_string (value);
 		break;
 	case PROP_DHCP_HOSTNAME:
-		g_free (setting->dhcp_hostname);
-		setting->dhcp_hostname = g_value_dup_string (value);
+		g_free (priv->dhcp_hostname);
+		priv->dhcp_hostname = g_value_dup_string (value);
 		break;
 	default:
 		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -286,34 +622,35 @@
 		    GValue *value, GParamSpec *pspec)
 {
 	NMSettingIP4Config *setting = NM_SETTING_IP4_CONFIG (object);
+	NMSettingIP4ConfigPrivate *priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting);
 
 	switch (prop_id) {
 	case PROP_METHOD:
-		g_value_set_string (value, setting->method);
+		g_value_set_string (value, nm_setting_ip4_config_get_method (setting));
 		break;
 	case PROP_DNS:
-		g_value_set_boxed (value, setting->dns);
+		g_value_set_boxed (value, priv->dns);
 		break;
 	case PROP_DNS_SEARCH:
-		g_value_set_boxed (value, setting->dns_search);
+		g_value_set_boxed (value, priv->dns_search);
 		break;
 	case PROP_ADDRESSES:
-		nm_utils_ip4_addresses_to_gvalue (setting->addresses, value);
+		nm_utils_ip4_addresses_to_gvalue (priv->addresses, value);
 		break;
 	case PROP_ROUTES:
-		nm_utils_ip4_routes_to_gvalue (setting->routes, value);
+		nm_utils_ip4_routes_to_gvalue (priv->routes, value);
 		break;
 	case PROP_IGNORE_AUTO_ROUTES:
-		g_value_set_boolean (value, setting->ignore_auto_routes);
+		g_value_set_boolean (value, nm_setting_ip4_config_get_ignore_auto_routes (setting));
 		break;
 	case PROP_IGNORE_AUTO_DNS:
-		g_value_set_boolean (value, setting->ignore_auto_dns);
+		g_value_set_boolean (value, nm_setting_ip4_config_get_ignore_auto_dns (setting));
 		break;
 	case PROP_DHCP_CLIENT_ID:
-		g_value_set_string (value, setting->dhcp_client_id);
+		g_value_set_string (value, nm_setting_ip4_config_get_dhcp_client_id (setting));
 		break;
 	case PROP_DHCP_HOSTNAME:
-		g_value_set_string (value, setting->dhcp_hostname);
+		g_value_set_string (value, nm_setting_ip4_config_get_dhcp_hostname (setting));
 		break;
 	default:
 		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -327,6 +664,8 @@
 	GObjectClass *object_class = G_OBJECT_CLASS (setting_class);
 	NMSettingClass *parent_class = NM_SETTING_CLASS (setting_class);
 
+	g_type_class_add_private (setting_class, sizeof (NMSettingIP4ConfigPrivate));
+
 	/* virtual methods */
 	object_class->set_property = set_property;
 	object_class->get_property = get_property;
@@ -362,7 +701,7 @@
 		(object_class, PROP_ADDRESSES,
 		 _nm_param_spec_specialized (NM_SETTING_IP4_CONFIG_ADDRESSES,
 							   "Addresses",
-							   "List of NMSettingIP4Addresses",
+							   "List of NMIP4Addresses",
 							   DBUS_TYPE_G_ARRAY_OF_ARRAY_OF_UINT,
 							   G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE));
 
@@ -370,7 +709,7 @@
 		(object_class, PROP_ROUTES,
 		 _nm_param_spec_specialized (NM_SETTING_IP4_CONFIG_ROUTES,
 							   "Routes",
-							   "List of NMSettingIP4Routes",
+							   "List of NMIP4Routes",
 							   DBUS_TYPE_G_ARRAY_OF_ARRAY_OF_UINT,
 							   G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE));
 
@@ -407,3 +746,277 @@
 						   G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE));
 }
 
+
+struct NMIP4Address {
+	guint32 refcount;
+	guint32 address;   /* network byte order */
+	guint32 prefix;
+	guint32 gateway;   /* network byte order */
+};
+
+NMIP4Address *
+nm_ip4_address_new (void)
+{
+	NMIP4Address *address;
+
+	address = g_malloc0 (sizeof (NMIP4Address));
+	address->refcount = 1;
+	return address;
+}
+
+NMIP4Address *
+nm_ip4_address_dup (NMIP4Address *source)
+{
+	NMIP4Address *address;
+
+	g_return_val_if_fail (source != NULL, NULL);
+	g_return_val_if_fail (source->refcount > 0, NULL);
+
+	address = nm_ip4_address_new ();
+	address->address = source->address;
+	address->prefix = source->prefix;
+	address->gateway = source->gateway;
+
+	return address;
+}
+
+void
+nm_ip4_address_ref (NMIP4Address *address)
+{
+	g_return_if_fail (address != NULL);
+	g_return_if_fail (address->refcount > 0);
+
+	address->refcount++;
+}
+
+void
+nm_ip4_address_unref (NMIP4Address *address)
+{
+	g_return_if_fail (address != NULL);
+	g_return_if_fail (address->refcount > 0);
+
+	address->refcount--;
+	if (address->refcount == 0) {
+		memset (address, 0, sizeof (NMIP4Address));
+		g_free (address);
+	}
+}
+
+gboolean
+nm_ip4_address_compare (NMIP4Address *address, NMIP4Address *other)
+{
+	g_return_val_if_fail (address != NULL, FALSE);
+	g_return_val_if_fail (address->refcount > 0, FALSE);
+
+	g_return_val_if_fail (other != NULL, FALSE);
+	g_return_val_if_fail (other->refcount > 0, FALSE);
+
+	if (   address->address != other->address
+	    || address->prefix != other->prefix
+	    || address->gateway != other->gateway)
+		return FALSE;
+	return TRUE;
+}
+
+guint32
+nm_ip4_address_get_address (NMIP4Address *address)
+{
+	g_return_val_if_fail (address != NULL, 0);
+	g_return_val_if_fail (address->refcount > 0, 0);
+
+	return address->address;
+}
+
+void
+nm_ip4_address_set_address (NMIP4Address *address, guint32 addr)
+{
+	g_return_if_fail (address != NULL);
+	g_return_if_fail (address->refcount > 0);
+
+	address->address = addr;
+}
+
+guint32
+nm_ip4_address_get_prefix (NMIP4Address *address)
+{
+	g_return_val_if_fail (address != NULL, 0);
+	g_return_val_if_fail (address->refcount > 0, 0);
+
+	return address->prefix;
+}
+
+void
+nm_ip4_address_set_prefix (NMIP4Address *address, guint32 prefix)
+{
+	g_return_if_fail (address != NULL);
+	g_return_if_fail (address->refcount > 0);
+
+	address->prefix = prefix;
+}
+
+guint32
+nm_ip4_address_get_gateway (NMIP4Address *address)
+{
+	g_return_val_if_fail (address != NULL, 0);
+	g_return_val_if_fail (address->refcount > 0, 0);
+
+	return address->gateway;
+}
+
+void
+nm_ip4_address_set_gateway (NMIP4Address *address, guint32 gateway)
+{
+	g_return_if_fail (address != NULL);
+	g_return_if_fail (address->refcount > 0);
+
+	address->gateway = gateway;
+}
+
+
+struct NMIP4Route {
+	guint32 refcount;
+
+	guint32 dest;   /* network byte order */
+	guint32 prefix;
+	guint32 next_hop;   /* network byte order */
+	guint32 metric;    /* lower metric == more preferred */
+};
+
+NMIP4Route *
+nm_ip4_route_new (void)
+{
+	NMIP4Route *route;
+
+	route = g_malloc0 (sizeof (NMIP4Route));
+	route->refcount = 1;
+	return route;
+}
+
+NMIP4Route *
+nm_ip4_route_dup (NMIP4Route *source)
+{
+	NMIP4Route *route;
+
+	g_return_val_if_fail (source != NULL, NULL);
+	g_return_val_if_fail (source->refcount > 0, NULL);
+
+	route = nm_ip4_route_new ();
+	route->dest = source->dest;
+	route->prefix = source->prefix;
+	route->next_hop = source->next_hop;
+	route->metric = source->metric;
+
+	return route;
+}
+
+void
+nm_ip4_route_ref (NMIP4Route *route)
+{
+	g_return_if_fail (route != NULL);
+	g_return_if_fail (route->refcount > 0);
+
+	route->refcount++;
+}
+
+void
+nm_ip4_route_unref (NMIP4Route *route)
+{
+	g_return_if_fail (route != NULL);
+	g_return_if_fail (route->refcount > 0);
+
+	route->refcount--;
+	if (route->refcount == 0) {
+		memset (route, 0, sizeof (NMIP4Route));
+		g_free (route);
+	}
+}
+
+gboolean
+nm_ip4_route_compare (NMIP4Route *route, NMIP4Route *other)
+{
+	g_return_val_if_fail (route != NULL, FALSE);
+	g_return_val_if_fail (route->refcount > 0, FALSE);
+
+	g_return_val_if_fail (other != NULL, FALSE);
+	g_return_val_if_fail (other->refcount > 0, FALSE);
+
+	if (   route->dest != other->dest
+	    || route->prefix != other->prefix
+	    || route->next_hop != other->next_hop
+	    || route->metric != other->metric)
+		return FALSE;
+	return TRUE;
+}
+
+guint32
+nm_ip4_route_get_dest (NMIP4Route *route)
+{
+	g_return_val_if_fail (route != NULL, 0);
+	g_return_val_if_fail (route->refcount > 0, 0);
+
+	return route->dest;
+}
+
+void
+nm_ip4_route_set_dest (NMIP4Route *route, guint32 dest)
+{
+	g_return_if_fail (route != NULL);
+	g_return_if_fail (route->refcount > 0);
+
+	route->dest = dest;
+}
+
+guint32
+nm_ip4_route_get_prefix (NMIP4Route *route)
+{
+	g_return_val_if_fail (route != NULL, 0);
+	g_return_val_if_fail (route->refcount > 0, 0);
+
+	return route->prefix;
+}
+
+void
+nm_ip4_route_set_prefix (NMIP4Route *route, guint32 prefix)
+{
+	g_return_if_fail (route != NULL);
+	g_return_if_fail (route->refcount > 0);
+
+	route->prefix = prefix;
+}
+
+guint32
+nm_ip4_route_get_next_hop (NMIP4Route *route)
+{
+	g_return_val_if_fail (route != NULL, 0);
+	g_return_val_if_fail (route->refcount > 0, 0);
+
+	return route->next_hop;
+}
+
+void
+nm_ip4_route_set_next_hop (NMIP4Route *route, guint32 next_hop)
+{
+	g_return_if_fail (route != NULL);
+	g_return_if_fail (route->refcount > 0);
+
+	route->next_hop = next_hop;
+}
+
+guint32
+nm_ip4_route_get_metric (NMIP4Route *route)
+{
+	g_return_val_if_fail (route != NULL, 0);
+	g_return_val_if_fail (route->refcount > 0, 0);
+
+	return route->metric;
+}
+
+void
+nm_ip4_route_set_metric (NMIP4Route *route, guint32 metric)
+{
+	g_return_if_fail (route != NULL);
+	g_return_if_fail (route->refcount > 0);
+
+	route->metric = metric;
+}
+

Modified: trunk/libnm-util/nm-setting-ip4-config.h
==============================================================================
--- trunk/libnm-util/nm-setting-ip4-config.h	(original)
+++ trunk/libnm-util/nm-setting-ip4-config.h	Wed Oct 29 14:35:25 2008
@@ -68,31 +68,56 @@
 #define NM_SETTING_IP4_CONFIG_METHOD_MANUAL     "manual"
 #define NM_SETTING_IP4_CONFIG_METHOD_SHARED     "shared"
 
-typedef struct {
-	guint32 address;   /* network byte order */
-	guint32 prefix;
-	guint32 gateway;   /* network byte order */
-} NMSettingIP4Address;
 
-typedef struct {
-	guint32 address;   /* network byte order */
-	guint32 prefix;
-	guint32 next_hop;   /* network byte order */
-	guint32 metric;    /* lower metric == more preferred */
-} NMSettingIP4Route;
+typedef struct NMIP4Address NMIP4Address;
+
+NMIP4Address * nm_ip4_address_new         (void);
+NMIP4Address * nm_ip4_address_dup         (NMIP4Address *source);
+void           nm_ip4_address_ref         (NMIP4Address *address);
+void           nm_ip4_address_unref       (NMIP4Address *address);
+/* Return TRUE if addresses are identical */
+gboolean       nm_ip4_address_compare     (NMIP4Address *address, NMIP4Address *other);
+
+guint32        nm_ip4_address_get_address (NMIP4Address *address);
+void           nm_ip4_address_set_address (NMIP4Address *address,
+                                           guint32 addr);  /* network byte order */
+
+guint32        nm_ip4_address_get_prefix  (NMIP4Address *address);
+void           nm_ip4_address_set_prefix  (NMIP4Address *address,
+                                           guint32 prefix);
+
+guint32        nm_ip4_address_get_gateway (NMIP4Address *address);
+void           nm_ip4_address_set_gateway (NMIP4Address *address,
+                                           guint32 gateway);  /* network byte order */
+
+typedef struct NMIP4Route NMIP4Route;
+
+NMIP4Route * nm_ip4_route_new          (void);
+NMIP4Route * nm_ip4_route_dup          (NMIP4Route *route);
+void         nm_ip4_route_ref          (NMIP4Route *route);
+void         nm_ip4_route_unref        (NMIP4Route *route);
+/* Return TRUE if routes are identical */
+gboolean     nm_ip4_route_compare      (NMIP4Route *route, NMIP4Route *other);
+
+guint32      nm_ip4_route_get_dest     (NMIP4Route *route);
+void         nm_ip4_route_set_dest     (NMIP4Route *route,
+                                        guint32 dest);  /* network byte order */
+
+guint32      nm_ip4_route_get_prefix   (NMIP4Route *route);
+void         nm_ip4_route_set_prefix   (NMIP4Route *route,
+                                        guint32 prefix);
+
+guint32      nm_ip4_route_get_next_hop (NMIP4Route *route);
+void         nm_ip4_route_set_next_hop (NMIP4Route *route,
+                                        guint32 next_hop);  /* network byte order */
+
+guint32      nm_ip4_route_get_metric   (NMIP4Route *route);
+void         nm_ip4_route_set_metric   (NMIP4Route *route,
+                                        guint32 metric);
+
 
 typedef struct {
 	NMSetting parent;
-
-	char *method;
-	GArray *dns;        /* array of guint32; elements in network byte order */
-	GSList *dns_search; /* list of strings */
-	GSList *addresses;  /* array of NMSettingIP4Address */
-	GSList *routes;     /* array of NMSettingIP4Route */
-	gboolean ignore_auto_routes;
-	gboolean ignore_auto_dns;
-	char *dhcp_client_id;
-	char *dhcp_hostname;
 } NMSettingIP4Config;
 
 typedef struct {
@@ -101,7 +126,37 @@
 
 GType nm_setting_ip4_config_get_type (void);
 
-NMSetting *nm_setting_ip4_config_new (void);
+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);
+void          nm_setting_ip4_config_remove_dns             (NMSettingIP4Config *setting, guint32 i);
+void          nm_setting_ip4_config_clear_dns              (NMSettingIP4Config *setting);
+
+guint32       nm_setting_ip4_config_get_num_dns_searches   (NMSettingIP4Config *setting);
+const char *  nm_setting_ip4_config_get_dns_search         (NMSettingIP4Config *setting, guint32 i);
+gboolean      nm_setting_ip4_config_add_dns_search         (NMSettingIP4Config *setting, const char *dns_search);
+void          nm_setting_ip4_config_remove_dns_search      (NMSettingIP4Config *setting, guint32 i);
+void          nm_setting_ip4_config_clear_dns_searches     (NMSettingIP4Config *setting);
+
+guint32       nm_setting_ip4_config_get_num_addresses      (NMSettingIP4Config *setting);
+NMIP4Address *nm_setting_ip4_config_get_address            (NMSettingIP4Config *setting, guint32 i);
+gboolean      nm_setting_ip4_config_add_address            (NMSettingIP4Config *setting, NMIP4Address *address);
+void          nm_setting_ip4_config_remove_address         (NMSettingIP4Config *setting, guint32 i);
+void          nm_setting_ip4_config_clear_addresses        (NMSettingIP4Config *setting);
+
+guint32       nm_setting_ip4_config_get_num_routes         (NMSettingIP4Config *setting);
+NMIP4Route *  nm_setting_ip4_config_get_route              (NMSettingIP4Config *setting, guint32 i);
+gboolean      nm_setting_ip4_config_add_route              (NMSettingIP4Config *setting, NMIP4Route *route);
+void          nm_setting_ip4_config_remove_route           (NMSettingIP4Config *setting, guint32 i);
+void          nm_setting_ip4_config_clear_routes           (NMSettingIP4Config *setting);
+
+gboolean      nm_setting_ip4_config_get_ignore_auto_routes (NMSettingIP4Config *setting);
+gboolean      nm_setting_ip4_config_get_ignore_auto_dns    (NMSettingIP4Config *setting);
+const char *  nm_setting_ip4_config_get_dhcp_client_id     (NMSettingIP4Config *setting);
+const char *  nm_setting_ip4_config_get_dhcp_hostname      (NMSettingIP4Config *setting);
 
 G_END_DECLS
 

Modified: trunk/libnm-util/nm-utils.c
==============================================================================
--- trunk/libnm-util/nm-utils.c	(original)
+++ trunk/libnm-util/nm-utils.c	Wed Oct 29 14:35:25 2008
@@ -852,17 +852,17 @@
 	addresses = (GPtrArray *) g_value_get_boxed (value);
 	for (i = 0; addresses && (i < addresses->len); i++) {
 		GArray *array = (GArray *) g_ptr_array_index (addresses, i);
-		NMSettingIP4Address *addr;
+		NMIP4Address *addr;
 
 		if (array->len != 3) {
 			nm_warning ("Ignoring invalid IP4 address");
 			continue;
 		}
 		
-		addr = g_malloc0 (sizeof (NMSettingIP4Address));
-		addr->address = g_array_index (array, guint32, 0);
-		addr->prefix = g_array_index (array, guint32, 1);
-		addr->gateway = g_array_index (array, guint32, 2);
+		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));
 		list = g_slist_prepend (list, addr);
 	}
 
@@ -878,14 +878,21 @@
 	addresses = g_ptr_array_new ();
 
 	for (iter = list; iter; iter = iter->next) {
-		NMSettingIP4Address *addr = (NMSettingIP4Address *) iter->data;
+		NMIP4Address *addr = (NMIP4Address *) iter->data;
 		GArray *array;
+		guint32 tmp;
 
 		array = g_array_sized_new (FALSE, TRUE, sizeof (guint32), 3);
 
-		g_array_append_val (array, addr->address);
-		g_array_append_val (array, addr->prefix);
-		g_array_append_val (array, addr->gateway);
+		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 (addresses, array);
 	}
 
@@ -902,18 +909,18 @@
 	routes = (GPtrArray *) g_value_get_boxed (value);
 	for (i = 0; routes && (i < routes->len); i++) {
 		GArray *array = (GArray *) g_ptr_array_index (routes, i);
-		NMSettingIP4Route *route;
+		NMIP4Route *route;
 
 		if (array->len != 4) {
 			nm_warning ("Ignoring invalid IP4 route");
 			continue;
 		}
 		
-		route = g_malloc0 (sizeof (NMSettingIP4Route));
-		route->address = g_array_index (array, guint32, 0);
-		route->prefix = g_array_index (array, guint32, 1);
-		route->next_hop = g_array_index (array, guint32, 2);
-		route->metric = g_array_index (array, guint32, 3);
+		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));
 		list = g_slist_prepend (list, route);
 	}
 
@@ -929,15 +936,24 @@
 	routes = g_ptr_array_new ();
 
 	for (iter = list; iter; iter = iter->next) {
-		NMSettingIP4Route *route = (NMSettingIP4Route *) iter->data;
+		NMIP4Route *route = (NMIP4Route *) iter->data;
 		GArray *array;
+		guint32 tmp;
 
 		array = g_array_sized_new (FALSE, TRUE, sizeof (guint32), 3);
 
-		g_array_append_val (array, route->address);
-		g_array_append_val (array, route->prefix);
-		g_array_append_val (array, route->next_hop);
-		g_array_append_val (array, route->metric);
+		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 (routes, array);
 	}
 

Modified: trunk/src/NetworkManagerPolicy.c
==============================================================================
--- trunk/src/NetworkManagerPolicy.c	(original)
+++ trunk/src/NetworkManagerPolicy.c	Wed Oct 29 14:35:25 2008
@@ -202,7 +202,8 @@
 		int prio;
 		guint i;
 		gboolean can_default = FALSE;
-		
+		const char *method = NULL;
+
 		if (nm_device_get_state (dev) != NM_DEVICE_STATE_ACTIVATED)
 			continue;
 
@@ -217,15 +218,18 @@
 
 		/* Never set the default route through an IPv4LL-addressed device */
 		s_ip4 = (NMSettingIP4Config *) nm_connection_get_setting (connection, NM_TYPE_SETTING_IP4_CONFIG);
-		if (s_ip4 && !strcmp (s_ip4->method, NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL))
+		if (s_ip4)
+			method = nm_setting_ip4_config_get_method (s_ip4);
+
+		if (s_ip4 && !strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL))
 			continue;
 
 		/* Make sure at least one of this device's IP addresses has a gateway */
 		for (i = 0; i < nm_ip4_config_get_num_addresses (ip4_config); i++) {
-			const NMSettingIP4Address *addr;
+			NMIP4Address *addr;
 
 			addr = nm_ip4_config_get_address (ip4_config, i);
-			if (addr->gateway) {
+			if (nm_ip4_address_get_gateway (addr)) {
 				can_default = TRUE;
 				break;
 			}
@@ -401,7 +405,7 @@
 	NMActRequest *best_req = NULL;
 	NMDHCP4Config *dhcp4_config;
 	NMIP4Config *ip4_config;
-	const NMSettingIP4Address *addr;
+	NMIP4Address *addr;
 
 	g_return_if_fail (policy != NULL);
 
@@ -464,7 +468,7 @@
 	g_assert (addr); /* checked for > 1 address above */
 
 	/* Start the hostname lookup thread */
-	policy->lookup = lookup_thread_new (addr->address, lookup_callback, policy);
+	policy->lookup = lookup_thread_new (nm_ip4_address_get_address (addr), lookup_callback, policy);
 	if (!policy->lookup) {
 		/* Fall back to 'localhost.localdomain' */
 		set_system_hostname (NULL, "error starting hostname thread");
@@ -480,7 +484,7 @@
 	NMNamedManager *named_mgr;
 	GSList *devices = NULL, *iter, *vpns;
 	NMIP4Config *ip4_config = NULL;
-	const NMSettingIP4Address *addr;
+	NMIP4Address *addr;
 	const char *ip_iface = NULL;
 	NMVPNConnection *vpn = NULL;
 	NMConnection *connection = NULL;
@@ -515,9 +519,9 @@
 
 		ip4_config = nm_vpn_connection_get_ip4_config (vpn);
 		for (i = 0; i < nm_ip4_config_get_num_routes (ip4_config); i++) {
-			const NMSettingIP4Route *route = nm_ip4_config_get_route (ip4_config, i);
+			NMIP4Route *route = nm_ip4_config_get_route (ip4_config, i);
 
-			if (route->prefix != 32) {
+			if (nm_ip4_route_get_prefix (route) != 32) {
 				have_non_host_routes = TRUE;
 				break;
 			}
@@ -536,7 +540,7 @@
 			parent_ip4 = nm_device_get_ip4_config (parent);
 
 			nm_system_replace_default_ip4_route_vpn (ip_iface,
-			                                         addr->gateway,
+			                                         nm_ip4_address_get_gateway (addr),
 			                                         nm_vpn_connection_get_ip4_internal_gateway (vpn),
 			                                         nm_ip4_config_get_mss (ip4_config),
 			                                         nm_device_get_ip_iface (parent),
@@ -555,7 +559,7 @@
 		g_assert (ip4_config);
 		addr = nm_ip4_config_get_address (ip4_config, 0);
 
-		nm_system_replace_default_ip4_route (ip_iface, addr->gateway, nm_ip4_config_get_mss (ip4_config));
+		nm_system_replace_default_ip4_route (ip_iface, nm_ip4_address_get_gateway (addr), nm_ip4_config_get_mss (ip4_config));
 
 		dns_type = NM_NAMED_IP_CONFIG_TYPE_BEST_DEVICE;
 	}

Modified: trunk/src/NetworkManagerSystem.c
==============================================================================
--- trunk/src/NetworkManagerSystem.c	(original)
+++ trunk/src/NetworkManagerSystem.c	Wed Oct 29 14:35:25 2008
@@ -73,12 +73,13 @@
 
 	num = nm_ip4_config_get_num_addresses (config);
 	for (i = 0; i < num; i++) {
-		const NMSettingIP4Address *addr;
-
-		addr = nm_ip4_config_get_address (config, i);
-		if (addr->prefix <= dest_prefix) {
-			guint32 masked_addr = ntohl(addr->address) >> (32 - addr->prefix);
-			guint32 masked_dest = ntohl(dest) >> (32 - addr->prefix);
+		NMIP4Address *addr = nm_ip4_config_get_address (config, i);
+		guint32 prefix = nm_ip4_address_get_prefix (addr);
+		guint32 address = nm_ip4_address_get_address (addr);
+
+		if (prefix <= dest_prefix) {
+			guint32 masked_addr = ntohl(address) >> (32 - prefix);
+			guint32 masked_dest = ntohl(dest) >> (32 - prefix);
 
 			if (masked_addr == masked_dest)
 				return TRUE;
@@ -239,14 +240,14 @@
 	nl_cache_foreach (addr_cache, check_one_address, &check_data);
 
 	for (i = 0; i < nm_ip4_config_get_num_addresses (config); i++) {
-		const NMSettingIP4Address *addr;
+		NMIP4Address *addr;
 		struct rtnl_addr *nl_addr = NULL;
 
 		addr = nm_ip4_config_get_address (config, i);
 		g_assert (addr);
 
 		flags = NM_RTNL_ADDR_DEFAULT;
-		if (addr->gateway && !did_gw) {
+		if (nm_ip4_address_get_gateway (addr) && !did_gw) {
 			if (nm_ip4_config_get_ptp_address (config))
 				flags |= NM_RTNL_ADDR_PTP_ADDR;
 			did_gw = TRUE;
@@ -276,7 +277,7 @@
 {
 	NMIP4Config *parent_config;
 	guint32 parent_gw = 0, parent_prefix = 0, vpn_gw = 0, i;
-	const NMSettingIP4Address *tmp;
+	NMIP4Address *tmp;
 
 	g_return_if_fail (NM_IS_DEVICE (parent_device));
 
@@ -289,17 +290,17 @@
 
 	for (i = 0; i < nm_ip4_config_get_num_addresses (parent_config); i++) {
 		tmp = nm_ip4_config_get_address (parent_config, i);
-		if (tmp->gateway) {
-			parent_gw = tmp->gateway;
-			parent_prefix = tmp->prefix;
+		if (nm_ip4_address_get_gateway (tmp)) {
+			parent_gw = nm_ip4_address_get_gateway (tmp);
+			parent_prefix = nm_ip4_address_get_prefix (tmp);
 			break;
 		}
 	}
 
 	for (i = 0; i < nm_ip4_config_get_num_addresses (config); i++) {
 		tmp = nm_ip4_config_get_address (config, i);
-		if (tmp->gateway) {
-			vpn_gw = tmp->gateway;
+		if (nm_ip4_address_get_gateway (tmp)) {
+			vpn_gw = nm_ip4_address_get_gateway (tmp);
 			break;
 		}
 	}
@@ -347,19 +348,21 @@
 	sleep (1);
 
 	for (i = 0; i < nm_ip4_config_get_num_routes (config); i++) {
-		const NMSettingIP4Route *route = nm_ip4_config_get_route (config, i);
+		NMIP4Route *route = nm_ip4_config_get_route (config, i);
 
 		/* Don't add the route if it's more specific than one of the subnets
 		 * the device already has an IP address on.
 		 */
-		if (ip4_dest_in_same_subnet (config, route->address, route->prefix))
+		if (ip4_dest_in_same_subnet (config,
+		                             nm_ip4_route_get_dest (route),
+		                             nm_ip4_route_get_prefix (route)))
 			continue;
 
 		nm_system_device_set_ip4_route (iface,
-		                                route->address,
-		                                route->prefix,
-		                                route->next_hop,
-		                                route->metric,
+		                                nm_ip4_route_get_dest (route),
+		                                nm_ip4_route_get_prefix (route),
+		                                nm_ip4_route_get_next_hop (route),
+		                                nm_ip4_route_get_metric (route),
 		                                nm_ip4_config_get_mss (config));
 	}
 
@@ -836,10 +839,12 @@
 	dst_addr = nl_addr_get_binary_addr (dst);
 	num = nm_ip4_config_get_num_addresses (info->config);
 	for (i = 0; i < num; i++) {
-		const NMSettingIP4Address *addr = nm_ip4_config_get_address (info->config, i);
+		NMIP4Address *addr = nm_ip4_config_get_address (info->config, i);
+		guint32 prefix = nm_ip4_address_get_prefix (addr);
+		guint32 address = nm_ip4_address_get_address (addr);
 
-		if (addr->prefix == nl_addr_get_prefixlen (dst) &&
-		    (addr->address & nm_utils_ip4_prefix_to_netmask (addr->prefix)) == dst_addr->s_addr) {
+		if (prefix == nl_addr_get_prefixlen (dst) &&
+		    (address & nm_utils_ip4_prefix_to_netmask (prefix)) == dst_addr->s_addr) {
 
 			/* Ref the route so it sticks around after the cache is cleared */
 			rtnl_route_get (route);

Modified: trunk/src/NetworkManagerUtils.c
==============================================================================
--- trunk/src/NetworkManagerUtils.c	(original)
+++ trunk/src/NetworkManagerUtils.c	Wed Oct 29 14:35:25 2008
@@ -273,100 +273,92 @@
 void
 nm_utils_merge_ip4_config (NMIP4Config *ip4_config, NMSettingIP4Config *setting)
 {
-	GSList *iter;
+	int i, j;
 
 	if (!setting)
 		return; /* Defaults are just fine */
 
-	if (setting->ignore_auto_dns) {
+	if (nm_setting_ip4_config_get_ignore_auto_dns (setting)) {
 		nm_ip4_config_reset_nameservers (ip4_config);
 		nm_ip4_config_reset_searches (ip4_config);
 	}
 
-	if (setting->ignore_auto_routes)
+	if (nm_setting_ip4_config_get_ignore_auto_routes (setting))
 		nm_ip4_config_reset_routes (ip4_config);
 
-	if (setting->dns) {
-		int i, j;
+	for (i = 0; i < nm_setting_ip4_config_get_num_dns (setting); i++) {
+		guint32 ns;
+		gboolean found = FALSE;
 
-		for (i = 0; i < setting->dns->len; i++) {
-			guint32 ns;
-			gboolean found = FALSE;
-
-			/* Avoid dupes */
-			ns = g_array_index (setting->dns, guint32, i);
-			for (j = 0; j < nm_ip4_config_get_num_nameservers (ip4_config); j++) {
-				if (nm_ip4_config_get_nameserver (ip4_config, j) == ns) {
-					found = TRUE;
-					break;
-				}
+		/* Avoid dupes */
+		ns = nm_setting_ip4_config_get_dns (setting, i);
+		for (j = 0; j < nm_ip4_config_get_num_nameservers (ip4_config); j++) {
+			if (nm_ip4_config_get_nameserver (ip4_config, j) == ns) {
+				found = TRUE;
+				break;
 			}
-
-			if (!found)
-				nm_ip4_config_add_nameserver (ip4_config, ns);
 		}
+
+		if (!found)
+			nm_ip4_config_add_nameserver (ip4_config, ns);
 	}
 
 	/* DNS search domains */
-	for (iter = setting->dns_search; iter; iter = iter->next) {
-		int i;
+	for (i = 0; i < nm_setting_ip4_config_get_num_dns_searches (setting); i++) {
+		const char *search = nm_setting_ip4_config_get_dns_search (setting, i);
 		gboolean found = FALSE;
 
 		/* Avoid dupes */
-		for (i = 0; i < nm_ip4_config_get_num_searches (ip4_config); i++) {
-			const char *search = nm_ip4_config_get_search (ip4_config, i);
-
-			if (!strcmp (search, (char *) iter->data)) {
+		for (j = 0; j < nm_ip4_config_get_num_searches (ip4_config); j++) {
+			if (!strcmp (search, nm_ip4_config_get_search (ip4_config, j))) {
 				found = TRUE;
 				break;
 			}
 		}
 
 		if (!found)
-			nm_ip4_config_add_search (ip4_config, (char *) iter->data);
+			nm_ip4_config_add_search (ip4_config, search);
 	}
 
 	/* IPv4 addresses */
-	for (iter = setting->addresses; iter; iter = g_slist_next (iter)) {
-		NMSettingIP4Address *setting_addr = (NMSettingIP4Address *) iter->data;
-		guint32 i, num;
+	for (i = 0; i < nm_setting_ip4_config_get_num_addresses (setting); i++) {
+		NMIP4Address *setting_addr = nm_setting_ip4_config_get_address (setting, i);
+		guint32 num;
 
 		num = nm_ip4_config_get_num_addresses (ip4_config);
-		for (i = 0; i < num; i++) {
-			const NMSettingIP4Address *cfg_addr;
+		for (j = 0; j < num; j++) {
+			NMIP4Address *cfg_addr = nm_ip4_config_get_address (ip4_config, j);
 
-			cfg_addr = nm_ip4_config_get_address (ip4_config, i);
 			/* Dupe, override with user-specified address */
-			if (cfg_addr->address == setting_addr->address) {
-				nm_ip4_config_replace_address (ip4_config, i, setting_addr);
+			if (nm_ip4_address_get_address (cfg_addr) == nm_ip4_address_get_address (setting_addr)) {
+				nm_ip4_config_replace_address (ip4_config, j, setting_addr);
 				break;
 			}
 		}
 
-		if (i == num)
+		if (j == num)
 			nm_ip4_config_add_address (ip4_config, setting_addr);
 	}
 
 	/* IPv4 routes */
-	for (iter = setting->routes; iter; iter = g_slist_next (iter)) {
-		NMSettingIP4Route *setting_route = (NMSettingIP4Route *) iter->data;
-		guint32 i, num;
+	for (i = 0; i < nm_setting_ip4_config_get_num_routes (setting); i++) {
+		NMIP4Route *setting_route = nm_setting_ip4_config_get_route (setting, i);
+		guint32 num;
 
 		num = nm_ip4_config_get_num_routes (ip4_config);
-		for (i = 0; i < num; i++) {
-			const NMSettingIP4Route *cfg_route;
+		for (j = 0; j < num; j++) {
+			NMIP4Route *cfg_route = nm_ip4_config_get_route (ip4_config, j);
 
-			cfg_route = nm_ip4_config_get_route (ip4_config, i);
 			/* Dupe, override with user-specified route */
-			if (   (cfg_route->address == setting_route->address)
-			    && (cfg_route->prefix == setting_route->prefix)
-			    && (cfg_route->next_hop == setting_route->next_hop)) {
-				nm_ip4_config_replace_route (ip4_config, i, setting_route);
+			if (   (nm_ip4_route_get_dest (cfg_route) == nm_ip4_route_get_dest (setting_route))
+			    && (nm_ip4_route_get_prefix (cfg_route) == nm_ip4_route_get_prefix (setting_route))
+			    && (nm_ip4_route_get_next_hop (cfg_route) == nm_ip4_route_get_next_hop (setting_route))) {
+				nm_ip4_config_replace_route (ip4_config, j, setting_route);
 				break;
 			}
 		}
 
-		if (i == num)
+		if (j == num)
 			nm_ip4_config_add_route (ip4_config, setting_route);
 	}
 }

Modified: trunk/src/dhcp-manager/nm-dhcp-dhclient.c
==============================================================================
--- trunk/src/dhcp-manager/nm-dhcp-dhclient.c	(original)
+++ trunk/src/dhcp-manager/nm-dhcp-dhclient.c	Wed Oct 29 14:35:25 2008
@@ -102,12 +102,12 @@
 				continue;
 
 			if (   s_ip4
-			    && s_ip4->dhcp_client_id
+			    && nm_setting_ip4_config_get_dhcp_client_id (s_ip4)
 			    && !strncmp (*line, DHCP_CLIENT_ID_TAG, strlen (DHCP_CLIENT_ID_TAG)))
 				ignore = TRUE;
 
 			if (   s_ip4
-			    && s_ip4->dhcp_client_id
+			    && nm_setting_ip4_config_get_dhcp_hostname (s_ip4)
 			    && !strncmp (*line, DHCP_HOSTNAME_TAG, strlen (DHCP_HOSTNAME_TAG)))
 				ignore = TRUE;
 
@@ -123,11 +123,17 @@
 		g_string_append_c (new_contents, '\n');
 
 	/* Add NM options from connection */
-	if (s_ip4 && s_ip4->dhcp_client_id)
-		g_string_append_printf (new_contents, DHCP_CLIENT_ID_FORMAT "\n", s_ip4->dhcp_client_id);
+	if (s_ip4) {
+		const char *tmp;
 
-	if (s_ip4 && s_ip4->dhcp_hostname)
-		g_string_append_printf (new_contents, DHCP_HOSTNAME_FORMAT "\n", s_ip4->dhcp_hostname);
+		tmp = nm_setting_ip4_config_get_dhcp_client_id (s_ip4);
+		if (tmp)
+			g_string_append_printf (new_contents, DHCP_CLIENT_ID_FORMAT "\n", tmp);
+
+		tmp = nm_setting_ip4_config_get_dhcp_hostname (s_ip4);
+		if (tmp)
+			g_string_append_printf (new_contents, DHCP_HOSTNAME_FORMAT "\n", tmp);
+	}
 
 	if (g_file_set_contents (device->conf_file, new_contents->str, -1, error))
 		success = TRUE;

Modified: trunk/src/dhcp-manager/nm-dhcp-manager.c
==============================================================================
--- trunk/src/dhcp-manager/nm-dhcp-manager.c	(original)
+++ trunk/src/dhcp-manager/nm-dhcp-manager.c	Wed Oct 29 14:35:25 2008
@@ -734,7 +734,7 @@
 	NMDHCPDevice *device;
 	NMIP4Config *ip4_config = NULL;
 	struct in_addr tmp_addr;
-	NMSettingIP4Address *addr = NULL;
+	NMIP4Address *addr = NULL;
 	char *str = NULL;
 
 	g_return_val_if_fail (NM_IS_DHCP_MANAGER (manager), NULL);
@@ -759,7 +759,7 @@
 		return NULL;
 	}
 
-	addr = g_malloc0 (sizeof (NMSettingIP4Address));
+	addr = nm_ip4_address_new ();
 	if (!addr) {
 		nm_warning ("%s: couldn't allocate memory for an IP4 Address!", device->iface);
 		goto error;
@@ -767,15 +767,15 @@
 
 	str = g_hash_table_lookup (device->options, "new_ip_address");
 	if (str && (inet_pton (AF_INET, str, &tmp_addr) > 0)) {
-		addr->address = tmp_addr.s_addr;
+		nm_ip4_address_set_address (addr, tmp_addr.s_addr);
 		nm_info ("  address %s", str);
 	} else
 		goto error;
 
 	str = g_hash_table_lookup (device->options, "new_subnet_mask");
 	if (str && (inet_pton (AF_INET, str, &tmp_addr) > 0)) {
-		addr->prefix = nm_utils_ip4_netmask_to_prefix (tmp_addr.s_addr);
-		nm_info ("  prefix %d (%s)", addr->prefix, str);
+		nm_ip4_address_set_prefix (addr, nm_utils_ip4_netmask_to_prefix (tmp_addr.s_addr));
+		nm_info ("  prefix %d (%s)", nm_ip4_address_get_prefix (addr), str);
 	}
 
 	str = g_hash_table_lookup (device->options, "new_routers");
@@ -786,7 +786,7 @@
 		for (s = routers; *s; s++) {
 			/* FIXME: how to handle multiple routers? */
 			if (inet_pton (AF_INET, *s, &tmp_addr) > 0) {
-				addr->gateway = tmp_addr.s_addr;
+				nm_ip4_address_set_gateway (addr, tmp_addr.s_addr);
 				nm_info ("  gateway %s", *s);
 				break;
 			} else
@@ -849,7 +849,7 @@
 			char **s;
 
 			for (s = searches; *s; s += 2) {
-				NMSettingIP4Route *route;
+				NMIP4Route *route;
 				struct in_addr rt_addr;
 				struct in_addr rt_route;
 
@@ -864,10 +864,10 @@
 
 				// FIXME: ensure the IP addresse and route are sane
 
-				route = g_malloc0 (sizeof (NMSettingIP4Route));
-				route->address = (guint32) rt_addr.s_addr;
-				route->prefix = 32; /* 255.255.255.255 */
-				route->next_hop = (guint32) rt_route.s_addr;
+				route = nm_ip4_route_new ();
+				nm_ip4_route_set_dest (route, (guint32) rt_addr.s_addr);
+				nm_ip4_route_set_prefix (route, 32); /* 255.255.255.255 */
+				nm_ip4_route_set_next_hop (route, (guint32) rt_route.s_addr);
 
 				nm_ip4_config_take_route (ip4_config, route);
 				nm_info ("  static route %s gw %s", *s, *(s + 1));

Modified: trunk/src/dnsmasq-manager/nm-dnsmasq-manager.c
==============================================================================
--- trunk/src/dnsmasq-manager/nm-dnsmasq-manager.c	(original)
+++ trunk/src/dnsmasq-manager/nm-dnsmasq-manager.c	Wed Oct 29 14:35:25 2008
@@ -230,7 +230,7 @@
 	const char *dm_binary;
 	NMCmdLine *cmd;
 	GString *s;
-	const NMSettingIP4Address *tmp;
+	NMIP4Address *tmp;
 	struct in_addr addr;
 	char buf[INET_ADDRSTRLEN + 1];
 	char localaddr[INET_ADDRSTRLEN + 1];
@@ -256,7 +256,7 @@
 	nm_cmd_line_add_string (cmd, "--except-interface=lo");
 
 	s = g_string_new ("--listen-address=");
-	addr.s_addr = tmp->address;
+	addr.s_addr = nm_ip4_address_get_address (tmp);
 	if (!inet_ntop (AF_INET, &addr, &localaddr[0], INET_ADDRSTRLEN)) {
 		nm_warning ("%s: error converting IP4 address 0x%X",
 		            __func__, ntohl (addr.s_addr));
@@ -269,7 +269,7 @@
 	s = g_string_new ("--dhcp-range=");
 
 	/* Add start of address range */
-	addr.s_addr = tmp->address + ntohl (9);
+	addr.s_addr = nm_ip4_address_get_address (tmp) + htonl (9);
 	if (!inet_ntop (AF_INET, &addr, &buf[0], INET_ADDRSTRLEN)) {
 		nm_warning ("%s: error converting IP4 address 0x%X",
 		            __func__, ntohl (addr.s_addr));
@@ -280,7 +280,7 @@
 	g_string_append_c (s, ',');
 
 	/* Add end of address range */
-	addr.s_addr = tmp->address + ntohl (99);
+	addr.s_addr = nm_ip4_address_get_address (tmp) + htonl (99);
 	if (!inet_ntop (AF_INET, &addr, &buf[0], INET_ADDRSTRLEN)) {
 		nm_warning ("%s: error converting IP4 address 0x%X",
 		            __func__, ntohl (addr.s_addr));

Modified: trunk/src/nm-device-wifi.c
==============================================================================
--- trunk/src/nm-device-wifi.c	(original)
+++ trunk/src/nm-device-wifi.c	Wed Oct 29 14:35:25 2008
@@ -1058,6 +1058,7 @@
 		NMSettingWireless *s_wireless;
 		const GByteArray *mac;
 		NMSettingIP4Config *s_ip4;
+		const char *method = NULL;
 
 		s_con = (NMSettingConnection *) nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION);
 		if (s_con == NULL)
@@ -1077,7 +1078,10 @@
 
 		/* Use the connection if it's a shared connection */
 		s_ip4 = (NMSettingIP4Config *) nm_connection_get_setting (connection, NM_TYPE_SETTING_IP4_CONFIG);
-		if (s_ip4 && !strcmp (s_ip4->method, NM_SETTING_IP4_CONFIG_METHOD_SHARED))
+		if (s_ip4)
+			method = nm_setting_ip4_config_get_method (s_ip4);
+
+		if (s_ip4 && !strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_SHARED))
 			return connection;
 
 		for (ap_iter = priv->ap_list; ap_iter; ap_iter = g_slist_next (ap_iter)) {
@@ -1659,10 +1663,14 @@
 		NMConnection *connection;
 		NMSettingIP4Config *s_ip4;
 		NMSettingIP6Config *s_ip6;
+		const char *ip4_method = NULL;
 
 		connection = nm_act_request_get_connection (req);
 		s_ip4 = (NMSettingIP4Config *) nm_connection_get_setting (connection, NM_TYPE_SETTING_IP4_CONFIG);
-		if (s_ip4 && !strcmp (s_ip4->method, NM_SETTING_IP4_CONFIG_METHOD_SHARED))
+		if (s_ip4)
+			ip4_method = nm_setting_ip4_config_get_method (s_ip4);
+
+		if (s_ip4 && !strcmp (ip4_method, NM_SETTING_IP4_CONFIG_METHOD_SHARED))
 			return FALSE;
 
 		s_ip6 = (NMSettingIP6Config *) nm_connection_get_setting (connection, NM_TYPE_SETTING_IP6_CONFIG);

Modified: trunk/src/nm-device.c
==============================================================================
--- trunk/src/nm-device.c	(original)
+++ trunk/src/nm-device.c	Wed Oct 29 14:35:25 2008
@@ -593,7 +593,7 @@
 {
 	NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
 	NMIP4Config *config = NULL;
-	NMSettingIP4Address *addr;
+	NMIP4Address *addr;
 
 	g_return_val_if_fail (priv->aipd_addr > 0, NULL);
 
@@ -603,9 +603,9 @@
 		return NULL;
 	}
 
-	addr = g_malloc0 (sizeof (NMSettingIP4Address));
-	addr->address = (guint32) priv->aipd_addr;
-	addr->prefix = 16;
+	addr = nm_ip4_address_new ();
+	nm_ip4_address_set_address (addr, (guint32) priv->aipd_addr);
+	nm_ip4_address_set_prefix (addr, 16);
 	nm_ip4_config_take_address (config, addr);
 
 	return config;	
@@ -655,7 +655,7 @@
 	NMConnection *connection = NULL;
 	NMSettingIP4Config *s_ip4 = NULL;
 	NMDeviceState state;
-	const char *iface;
+	const char *iface, *method = NULL;
 
 	g_return_if_fail (event != NULL);
 
@@ -669,7 +669,10 @@
 
 	/* Ignore if the connection isn't an AutoIP connection */
 	s_ip4 = (NMSettingIP4Config *) nm_connection_get_setting (connection, NM_TYPE_SETTING_IP4_CONFIG);
-	if (!s_ip4 || !s_ip4->method || strcmp (s_ip4->method, NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL))
+	if (s_ip4)
+		method = nm_setting_ip4_config_get_method (s_ip4);
+
+	if (!s_ip4 || !method || strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL))
 		return;
 
 	iface = nm_device_get_iface (self);
@@ -837,7 +840,7 @@
 	NMSettingIP4Config *s_ip4;
 	NMActRequest *req;
 	NMActStageReturn ret = NM_ACT_STAGE_RETURN_SUCCESS;
-	const char *ip_iface;
+	const char *ip_iface, *method = NULL;
 
 	g_return_val_if_fail (reason != NULL, NM_ACT_STAGE_RETURN_FAILURE);
 
@@ -849,7 +852,10 @@
 	                                                          NM_TYPE_SETTING_IP4_CONFIG);
 
 	/* If we did not receive IP4 configuration information, default to DHCP */
-	if (!s_ip4 || !strcmp (s_ip4->method, NM_SETTING_IP4_CONFIG_METHOD_AUTO)) {
+	if (s_ip4)
+		method = nm_setting_ip4_config_get_method (s_ip4);
+
+	if (!s_ip4 || !method || !strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_AUTO)) {
 		NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
 		gboolean success;
 
@@ -871,7 +877,7 @@
 			*reason = NM_DEVICE_STATE_REASON_DHCP_START_FAILED;
 			ret = NM_ACT_STAGE_RETURN_FAILURE;
 		}
-	} else if (s_ip4 && !strcmp (s_ip4->method, NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL)) {
+	} else if (s_ip4 && !strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL)) {
 		GError *error = NULL;
 		const char *iface = nm_device_get_iface (self);
 
@@ -985,7 +991,7 @@
 nm_device_new_ip4_shared_config (NMDevice *self, NMDeviceStateReason *reason)
 {
 	NMIP4Config *config = NULL;
-	NMSettingIP4Address *addr;
+	NMIP4Address *addr;
 	guint32 tmp_addr;
 
 	g_return_val_if_fail (self != NULL, NULL);
@@ -1000,14 +1006,14 @@
 	}
 
 	config = nm_ip4_config_new ();
-	addr = g_malloc0 (sizeof (NMSettingIP4Address));
-	addr->address = tmp_addr;
-	addr->prefix = 24; /* 255.255.255.0 */
+	addr = nm_ip4_address_new ();
+	nm_ip4_address_set_address (addr, tmp_addr);
+	nm_ip4_address_set_prefix (addr, 24);
 	nm_ip4_config_take_address (config, addr);
 
 	/* Remove the address lock when the object gets disposed */
 	g_object_set_data_full (G_OBJECT (config), "shared-ip",
-	                        GUINT_TO_POINTER (addr->address), release_shared_ip);
+	                        GUINT_TO_POINTER (tmp_addr), release_shared_ip);
 
 	return config;
 }
@@ -1046,18 +1052,22 @@
 		} else
 			*reason = NM_DEVICE_STATE_REASON_DHCP_ERROR;
 	} else {
+		const char *method;
+
 		g_assert (s_ip4);
-		g_assert (s_ip4->method);
 
-		if (!strcmp (s_ip4->method, NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL)) {
+		method = nm_setting_ip4_config_get_method (s_ip4);
+		g_assert (method);
+
+		if (!strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL)) {
 			*config = aipd_get_ip4_config (self, reason);
-		} else if (!strcmp (s_ip4->method, NM_SETTING_IP4_CONFIG_METHOD_MANUAL)) {
+		} else if (!strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_MANUAL)) {
 			*config = nm_ip4_config_new ();
 			if (*config)
 				nm_utils_merge_ip4_config (*config, s_ip4);
 			else
 				*reason = NM_DEVICE_STATE_REASON_IP_CONFIG_UNAVAILABLE;
-		} else if (!strcmp (s_ip4->method, NM_SETTING_IP4_CONFIG_METHOD_SHARED)) {
+		} else if (!strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_SHARED)) {
 			*config = nm_device_new_ip4_shared_config (self, reason);
 			if (*config)
 				priv->dnsmasq_manager = nm_dnsmasq_manager_new (ip_iface);
@@ -1302,7 +1312,7 @@
 	char str_mask[INET_ADDRSTRLEN + 1];
 	guint32 netmask, network;
 	NMIP4Config *ip4_config;
-	const NMSettingIP4Address *ip4_addr;
+	NMIP4Address *ip4_addr;
 	const char *ip_iface;
 
 	ip_iface = nm_device_get_ip_iface (self);
@@ -1312,14 +1322,14 @@
 		return FALSE;
 
 	ip4_addr = nm_ip4_config_get_address (ip4_config, 0);
-	if (!ip4_addr || !ip4_addr->address)
+	if (!ip4_addr || !nm_ip4_address_get_address (ip4_addr))
 		return FALSE;
 
-	netmask = nm_utils_ip4_prefix_to_netmask (ip4_addr->prefix);
+	netmask = nm_utils_ip4_prefix_to_netmask (nm_ip4_address_get_prefix (ip4_addr));
 	if (!inet_ntop (AF_INET, &netmask, str_mask, sizeof (str_mask)))
 		return FALSE;
 
-	network = ip4_addr->address & netmask;
+	network = nm_ip4_address_get_address (ip4_addr) & netmask;
 	if (!inet_ntop (AF_INET, &network, str_addr, sizeof (str_addr)))
 		return FALSE;
 
@@ -1368,7 +1378,7 @@
 	NMDevice *self = NM_DEVICE (user_data);
 	NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
 	NMIP4Config *ip4_config = NULL;
-	const char *iface;
+	const char *iface, *method = NULL;
 	NMConnection *connection;
 	NMSettingIP4Config *s_ip4;
 	NMDeviceStateReason reason = NM_DEVICE_STATE_REASON_NONE;
@@ -1392,7 +1402,10 @@
 
 	connection = nm_act_request_get_connection (nm_device_get_act_request (self));
 	s_ip4 = (NMSettingIP4Config *) nm_connection_get_setting (connection, NM_TYPE_SETTING_IP4_CONFIG);
-	if (s_ip4 && !strcmp (s_ip4->method, "shared")) {
+	if (s_ip4)
+		method = nm_setting_ip4_config_get_method (s_ip4);
+
+	if (s_ip4 && !strcmp (method, "shared")) {
 		if (!start_sharing (self)) {
 			nm_warning ("Activation (%s) Stage 5 of 5 (IP Configure Commit) start sharing failed.", iface);
 			nm_device_state_changed (self, NM_DEVICE_STATE_FAILED, NM_DEVICE_STATE_REASON_SHARED_START_FAILED);

Modified: trunk/src/nm-hso-gsm-device.c
==============================================================================
--- trunk/src/nm-hso-gsm-device.c	(original)
+++ trunk/src/nm-hso-gsm-device.c	Wed Oct 29 14:35:25 2008
@@ -269,8 +269,7 @@
 	NMActRequest *req;
 	char **items, **iter;
 	guint cid, i;
-	NMSettingIP4Address addr = { 0, 32, 0 };
-	guint32 dns1 = 0, dns2 = 0;
+	guint32 dns1 = 0, dns2 = 0, ip4_address = 0;
 
 	if (   (reply_index < 0)
 	    || !response
@@ -297,8 +296,8 @@
 				goto out;
 			}
 		} else if (i == 1) { /* IP address */
-			if (inet_pton (AF_INET, *iter, &(addr.address)) <= 0)
-				addr.address = 0;
+			if (inet_pton (AF_INET, *iter, &ip4_address) <= 0)
+				ip4_address = 0;
 		} else if (i == 3) { /* DNS 1 */
 			if (inet_pton (AF_INET, *iter, &dns1) <= 0)
 				dns1 = 0;
@@ -311,10 +310,16 @@
 out:
 	g_strfreev (items);
 
-	if (addr.address) {
+	if (ip4_address) {
+		NMIP4Address *addr;
+
 		priv->pending_ip4_config = nm_ip4_config_new ();
 
-		nm_ip4_config_add_address (priv->pending_ip4_config, &addr);
+		addr = nm_ip4_address_new ();
+		nm_ip4_address_set_address (addr, ip4_address);
+		nm_ip4_address_set_prefix (addr, 32);
+
+		nm_ip4_config_take_address (priv->pending_ip4_config, addr);
 
 		if (dns1)
 			nm_ip4_config_add_nameserver (priv->pending_ip4_config, dns1);

Modified: trunk/src/nm-ip4-config.c
==============================================================================
--- trunk/src/nm-ip4-config.c	(original)
+++ trunk/src/nm-ip4-config.c	Wed Oct 29 14:35:25 2008
@@ -108,8 +108,7 @@
 }
 
 void
-nm_ip4_config_take_address (NMIP4Config *config,
-                            NMSettingIP4Address *address)
+nm_ip4_config_take_address (NMIP4Config *config, NMIP4Address *address)
 {
 	NMIP4ConfigPrivate *priv;
 
@@ -122,27 +121,23 @@
 
 void
 nm_ip4_config_add_address (NMIP4Config *config,
-                           NMSettingIP4Address *address)
+                           NMIP4Address *address)
 {
 	NMIP4ConfigPrivate *priv;
-	NMSettingIP4Address *copy;
 
 	g_return_if_fail (NM_IS_IP4_CONFIG (config));
 	g_return_if_fail (address != NULL);
 
 	priv = NM_IP4_CONFIG_GET_PRIVATE (config);
-	copy = g_malloc0 (sizeof (NMSettingIP4Address));
-	memcpy (copy, address, sizeof (NMSettingIP4Address));
-	priv->addresses = g_slist_append (priv->addresses, copy);
+	priv->addresses = g_slist_append (priv->addresses, nm_ip4_address_dup (address));
 }
 
 void
 nm_ip4_config_replace_address (NMIP4Config *config,
                                guint i,
-                               NMSettingIP4Address *new_address)
+                               NMIP4Address *new_address)
 {
 	NMIP4ConfigPrivate *priv;
-	NMSettingIP4Address *copy;
 	GSList *old;
 
 	g_return_if_fail (NM_IS_IP4_CONFIG (config));
@@ -150,18 +145,16 @@
 	priv = NM_IP4_CONFIG_GET_PRIVATE (config);
 	old = g_slist_nth (priv->addresses, i);
 	g_return_if_fail (old != NULL);
-	g_free (old->data);
+	nm_ip4_address_unref ((NMIP4Address *) old->data);
 
-	copy = g_malloc0 (sizeof (NMSettingIP4Address));
-	memcpy (copy, new_address, sizeof (NMSettingIP4Address));
-	old->data = copy;
+	old->data = nm_ip4_address_dup (new_address);
 }
 
-const NMSettingIP4Address *nm_ip4_config_get_address (NMIP4Config *config, guint i)
+NMIP4Address *nm_ip4_config_get_address (NMIP4Config *config, guint i)
 {
 	g_return_val_if_fail (NM_IS_IP4_CONFIG (config), NULL);
 
-	return (const NMSettingIP4Address *) g_slist_nth_data (NM_IP4_CONFIG_GET_PRIVATE (config)->addresses, i);
+	return (NMIP4Address *) g_slist_nth_data (NM_IP4_CONFIG_GET_PRIVATE (config)->addresses, i);
 }
 
 guint32 nm_ip4_config_get_num_addresses (NMIP4Config *config)
@@ -219,8 +212,7 @@
 }
 
 void
-nm_ip4_config_take_route (NMIP4Config *config,
-						   NMSettingIP4Route *route)
+nm_ip4_config_take_route (NMIP4Config *config, NMIP4Route *route)
 {
 	NMIP4ConfigPrivate *priv;
 
@@ -232,28 +224,23 @@
 }
 
 void
-nm_ip4_config_add_route (NMIP4Config *config,
-						  NMSettingIP4Route *route)
+nm_ip4_config_add_route (NMIP4Config *config, NMIP4Route *route)
 {
 	NMIP4ConfigPrivate *priv;
-	NMSettingIP4Route *copy;
 
 	g_return_if_fail (NM_IS_IP4_CONFIG (config));
 	g_return_if_fail (route != NULL);
 
 	priv = NM_IP4_CONFIG_GET_PRIVATE (config);
-	copy = g_malloc0 (sizeof (NMSettingIP4Route));
-	memcpy (copy, route, sizeof (NMSettingIP4Route));
-	priv->routes = g_slist_append (priv->routes, copy);
+	priv->routes = g_slist_append (priv->routes, nm_ip4_route_dup (route));
 }
 
 void
 nm_ip4_config_replace_route (NMIP4Config *config,
 							 guint i,
-							 NMSettingIP4Route *new_route)
+							 NMIP4Route *new_route)
 {
 	NMIP4ConfigPrivate *priv;
-	NMSettingIP4Route *copy;
 	GSList *old;
 
 	g_return_if_fail (NM_IS_IP4_CONFIG (config));
@@ -261,19 +248,17 @@
 	priv = NM_IP4_CONFIG_GET_PRIVATE (config);
 	old = g_slist_nth (priv->routes, i);
 	g_return_if_fail (old != NULL);
-	g_free (old->data);
+	nm_ip4_route_unref ((NMIP4Route *) old->data);
 
-	copy = g_malloc0 (sizeof (NMSettingIP4Route));
-	memcpy (copy, new_route, sizeof (NMSettingIP4Route));
-	old->data = copy;
+	old->data = nm_ip4_route_dup (new_route);
 }
 
-const NMSettingIP4Route *
+NMIP4Route *
 nm_ip4_config_get_route (NMIP4Config *config, guint i)
 {
 	g_return_val_if_fail (NM_IS_IP4_CONFIG (config), NULL);
 
-	return (const NMSettingIP4Route *) g_slist_nth_data (NM_IP4_CONFIG_GET_PRIVATE (config)->routes, i);
+	return (NMIP4Route *) g_slist_nth_data (NM_IP4_CONFIG_GET_PRIVATE (config)->routes, i);
 }
 
 guint32 nm_ip4_config_get_num_routes (NMIP4Config *config)
@@ -431,7 +416,7 @@
 nm_ip4_config_to_rtnl_addr (NMIP4Config *config, guint32 i, guint32 flags)
 {
 	NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config);
-	const NMSettingIP4Address *config_addr;
+	NMIP4Address *config_addr;
 	struct rtnl_addr *addr;
 	gboolean success = TRUE;
 
@@ -444,19 +429,19 @@
 		return NULL;
 
 	if (flags & NM_RTNL_ADDR_ADDR)
-		success = (ip4_addr_to_rtnl_local (config_addr->address, addr) >= 0);
+		success = (ip4_addr_to_rtnl_local (nm_ip4_address_get_address (config_addr), addr) >= 0);
 
 	if (flags & NM_RTNL_ADDR_PTP_ADDR)
 		success = (ip4_addr_to_rtnl_peer (priv->ptp_address, addr) >= 0);
 
 	if (flags & NM_RTNL_ADDR_PREFIX)
-		rtnl_addr_set_prefixlen (addr, config_addr->prefix);
+		rtnl_addr_set_prefixlen (addr, nm_ip4_address_get_prefix (config_addr));
 
 	if (flags & NM_RTNL_ADDR_BROADCAST) {
 		guint32 hostmask, network, bcast, netmask;
 
-		netmask = nm_utils_ip4_prefix_to_netmask (config_addr->prefix);
-		network = ntohl (config_addr->address) & ntohl (netmask);
+		netmask = nm_utils_ip4_prefix_to_netmask (nm_ip4_address_get_prefix (config_addr));
+		network = ntohl (nm_ip4_address_get_address (config_addr)) & ntohl (netmask);
 		hostmask = ~ntohl (netmask);
 		bcast = htonl (network | hostmask);
 
@@ -486,11 +471,11 @@
 {
 	NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (object);
 
-	nm_utils_slist_free (priv->addresses, g_free);
+	nm_utils_slist_free (priv->addresses, (GDestroyNotify) nm_ip4_address_unref);
+	nm_utils_slist_free (priv->routes, (GDestroyNotify) nm_ip4_route_unref);
 	g_array_free (priv->nameservers, TRUE);
 	g_ptr_array_free (priv->domains, TRUE);
 	g_ptr_array_free (priv->searches, TRUE);
-	nm_utils_slist_free (priv->routes, g_free);
 }
 
 static void

Modified: trunk/src/nm-ip4-config.h
==============================================================================
--- trunk/src/nm-ip4-config.h	(original)
+++ trunk/src/nm-ip4-config.h	Wed Oct 29 14:35:25 2008
@@ -52,45 +52,45 @@
 GType nm_ip4_config_get_type (void);
 
 
-NMIP4Config * nm_ip4_config_new (void);
-void nm_ip4_config_export (NMIP4Config *config);
-const char *nm_ip4_config_get_dbus_path (NMIP4Config *config);
-
-void					nm_ip4_config_take_address		(NMIP4Config *config, NMSettingIP4Address *address);
-void					nm_ip4_config_add_address		(NMIP4Config *config, NMSettingIP4Address *address);
-void					nm_ip4_config_replace_address		(NMIP4Config *config, guint32 i, NMSettingIP4Address *new_address);
-const NMSettingIP4Address *	nm_ip4_config_get_address		(NMIP4Config *config, guint32 i);
-guint32					nm_ip4_config_get_num_addresses	(NMIP4Config *config);
-
-guint32		nm_ip4_config_get_ptp_address		(NMIP4Config *config);
-void			nm_ip4_config_set_ptp_address		(NMIP4Config *config, guint32 ptp_addr);
-
-void			nm_ip4_config_add_nameserver		(NMIP4Config *config, guint32 nameserver);
-guint32		nm_ip4_config_get_nameserver		(NMIP4Config *config, guint i);
-guint32		nm_ip4_config_get_num_nameservers	(NMIP4Config *config);
-void			nm_ip4_config_reset_nameservers		(NMIP4Config *config);
-
-void			nm_ip4_config_take_route		(NMIP4Config *config, NMSettingIP4Route *route);
-void			nm_ip4_config_add_route			(NMIP4Config *config, NMSettingIP4Route *route);
-void			nm_ip4_config_replace_route		(NMIP4Config *config, guint32 i, NMSettingIP4Route *new_route);
-const NMSettingIP4Route *	nm_ip4_config_get_route		(NMIP4Config *config, guint32 i);
-guint32		nm_ip4_config_get_num_routes		(NMIP4Config *config);
-void            nm_ip4_config_reset_routes		(NMIP4Config *config);
-
-void			nm_ip4_config_add_domain			(NMIP4Config *config, const char *domain);
-const char *	nm_ip4_config_get_domain			(NMIP4Config *config, guint i);
-guint32		nm_ip4_config_get_num_domains		(NMIP4Config *config);
-
-void			nm_ip4_config_add_search			(NMIP4Config *config, const char *search);
-const char *	nm_ip4_config_get_search			(NMIP4Config *config, guint i);
-guint32		nm_ip4_config_get_num_searches		(NMIP4Config *config);
-void			nm_ip4_config_reset_searches		(NMIP4Config *config);
+NMIP4Config * nm_ip4_config_new                 (void);
+void          nm_ip4_config_export              (NMIP4Config *config);
+const char *  nm_ip4_config_get_dbus_path       (NMIP4Config *config);
+
+void          nm_ip4_config_take_address        (NMIP4Config *config, NMIP4Address *address);
+void          nm_ip4_config_add_address         (NMIP4Config *config, NMIP4Address *address);
+void          nm_ip4_config_replace_address     (NMIP4Config *config, guint32 i, NMIP4Address *new_address);
+NMIP4Address *nm_ip4_config_get_address         (NMIP4Config *config, guint32 i);
+guint32       nm_ip4_config_get_num_addresses   (NMIP4Config *config);
+
+guint32       nm_ip4_config_get_ptp_address     (NMIP4Config *config);
+void          nm_ip4_config_set_ptp_address     (NMIP4Config *config, guint32 ptp_addr);
+
+void          nm_ip4_config_add_nameserver      (NMIP4Config *config, guint32 nameserver);
+guint32       nm_ip4_config_get_nameserver      (NMIP4Config *config, guint i);
+guint32       nm_ip4_config_get_num_nameservers (NMIP4Config *config);
+void          nm_ip4_config_reset_nameservers   (NMIP4Config *config);
+
+void          nm_ip4_config_take_route          (NMIP4Config *config, NMIP4Route *route);
+void          nm_ip4_config_add_route           (NMIP4Config *config, NMIP4Route *route);
+void          nm_ip4_config_replace_route       (NMIP4Config *config, guint32 i, NMIP4Route *new_route);
+NMIP4Route *  nm_ip4_config_get_route           (NMIP4Config *config, guint32 i);
+guint32       nm_ip4_config_get_num_routes      (NMIP4Config *config);
+void          nm_ip4_config_reset_routes        (NMIP4Config *config);
+
+void          nm_ip4_config_add_domain          (NMIP4Config *config, const char *domain);
+const char *  nm_ip4_config_get_domain          (NMIP4Config *config, guint i);
+guint32       nm_ip4_config_get_num_domains     (NMIP4Config *config);
+
+void          nm_ip4_config_add_search          (NMIP4Config *config, const char *search);
+const char *  nm_ip4_config_get_search          (NMIP4Config *config, guint i);
+guint32       nm_ip4_config_get_num_searches    (NMIP4Config *config);
+void          nm_ip4_config_reset_searches      (NMIP4Config *config);
 
-guint32		nm_ip4_config_get_mtu			(NMIP4Config *config);
-void			nm_ip4_config_set_mtu			(NMIP4Config *config, guint32 mtu);
+guint32       nm_ip4_config_get_mtu             (NMIP4Config *config);
+void          nm_ip4_config_set_mtu             (NMIP4Config *config, guint32 mtu);
 
-guint32		nm_ip4_config_get_mss			(NMIP4Config *config);
-void			nm_ip4_config_set_mss			(NMIP4Config *config, guint32 mss);
+guint32       nm_ip4_config_get_mss             (NMIP4Config *config);
+void          nm_ip4_config_set_mss             (NMIP4Config *config, guint32 mss);
 
 /* Flags for nm_ip4_config_to_rtnl_addr() */
 #define NM_RTNL_ADDR_NONE		0x0000

Modified: trunk/src/ppp-manager/nm-ppp-manager.c
==============================================================================
--- trunk/src/ppp-manager/nm-ppp-manager.c	(original)
+++ trunk/src/ppp-manager/nm-ppp-manager.c	Wed Oct 29 14:35:25 2008
@@ -1,4 +1,4 @@
-/* -*- Mode: C; tab-width: 5; indent-tabs-mode: t; c-basic-offset: 5 -*- */
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
 
 #include <sys/types.h>
 #include <sys/wait.h>
@@ -446,7 +446,7 @@
 	NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE (manager);
 	NMConnection *connection;
 	NMIP4Config *config;
-	NMSettingIP4Address *addr;
+	NMIP4Address *addr;
 	GValue *val;
 	int i;
 
@@ -455,28 +455,28 @@
 	remove_timeout_handler (manager);
 
 	config = nm_ip4_config_new ();
-	addr = g_malloc0 (sizeof (NMSettingIP4Address));
-	addr->prefix = 32;
+	addr = nm_ip4_address_new ();
+	nm_ip4_address_set_prefix (addr, 32);
 
 	val = (GValue *) g_hash_table_lookup (config_hash, NM_PPP_IP4_CONFIG_GATEWAY);
 	if (val) {
-		addr->gateway = g_value_get_uint (val);
+		nm_ip4_address_set_gateway (addr, g_value_get_uint (val));
 		nm_ip4_config_set_ptp_address (config, g_value_get_uint (val));
 	}
 
 	val = (GValue *) g_hash_table_lookup (config_hash, NM_PPP_IP4_CONFIG_ADDRESS);
 	if (val)
-		addr->address = g_value_get_uint (val);
+		nm_ip4_address_set_address (addr, g_value_get_uint (val));
 
 	val = (GValue *) g_hash_table_lookup (config_hash, NM_PPP_IP4_CONFIG_PREFIX);
 	if (val)
-		addr->prefix = g_value_get_uint (val);
+		nm_ip4_address_set_prefix (addr, g_value_get_uint (val));
 
-	if (addr->address && addr->prefix) {
+	if (nm_ip4_address_get_address (addr) && nm_ip4_address_get_prefix (addr)) {
 		nm_ip4_config_take_address (config, addr);
 	} else {
 		nm_warning ("%s: invalid IPv4 address received!", __func__);
-		g_free (addr);
+		nm_ip4_address_unref (addr);
 		goto out;
 	}
 

Modified: trunk/src/vpn-manager/nm-vpn-connection.c
==============================================================================
--- trunk/src/vpn-manager/nm-vpn-connection.c	(original)
+++ trunk/src/vpn-manager/nm-vpn-connection.c	Wed Oct 29 14:35:25 2008
@@ -314,34 +314,33 @@
                   const char *tundev,
                   const char *banner)
 {
-	const NMSettingIP4Address *addr;
-	char *         dns_domain = NULL;
-	guint32        num;
-	guint32        i;
+	NMIP4Address *addr;
+	char *dns_domain = NULL;
+	guint32 num, i;
 
 	g_return_if_fail (config != NULL);
 
 	addr = nm_ip4_config_get_address (config, 0);
 
-	nm_info ("VPN Gateway: %s", ip_address_to_string (addr->gateway));
+	nm_info ("VPN Gateway: %s", ip_address_to_string (nm_ip4_address_get_gateway (addr)));
 	if (internal_gw)
 		nm_info ("Internal Gateway: %s", ip_address_to_string (internal_gw));
 	nm_info ("Tunnel Device: %s", tundev);
-	nm_info ("Internal IP4 Address: %s", ip_address_to_string (addr->address));
-	nm_info ("Internal IP4 Prefix: %d", addr->prefix);
+	nm_info ("Internal IP4 Address: %s", ip_address_to_string (nm_ip4_address_get_address (addr)));
+	nm_info ("Internal IP4 Prefix: %d", nm_ip4_address_get_prefix (addr));
 	nm_info ("Internal IP4 Point-to-Point Address: %s",
 		    ip_address_to_string (nm_ip4_config_get_ptp_address (config)));
 	nm_info ("Maximum Segment Size (MSS): %d", nm_ip4_config_get_mss (config));
 
 	num = nm_ip4_config_get_num_routes (config);
 	for (i = 0; i < num; i++) {
-		const NMSettingIP4Route *route;
+		NMIP4Route *route;
 
 		route = nm_ip4_config_get_route (config, i);
 		nm_info ("Static Route: %s/%d   Next Hop: %s",
-			    ip_address_to_string (route->address),
-			    route->prefix,
-			    ip_address_to_string (route->next_hop));
+			    ip_address_to_string (nm_ip4_route_get_dest (route)),
+			    nm_ip4_route_get_prefix (route),
+			    ip_address_to_string (nm_ip4_route_get_next_hop (route)));
 	}
 
 	num = nm_ip4_config_get_num_nameservers (config);
@@ -365,7 +364,7 @@
 	NMVPNConnection *connection = NM_VPN_CONNECTION (user_data);
 	NMVPNConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE (connection);
 	NMSettingIP4Config *s_ip4;
-	NMSettingIP4Address *addr;
+	NMIP4Address *addr;
 	NMIP4Config *config;
 	GValue *val;
 	int i;
@@ -378,9 +377,6 @@
 
 	config = nm_ip4_config_new ();
 
-	addr = g_malloc0 (sizeof (NMSettingIP4Address));
-	addr->prefix = 24; /* default to class C */
-
 	val = (GValue *) g_hash_table_lookup (config_hash, NM_VPN_PLUGIN_IP4_CONFIG_TUNDEV);
 	if (val)
 		priv->tundev = g_strdup (g_value_get_string (val));
@@ -389,6 +385,9 @@
 		goto error;
 	}
 
+	addr = nm_ip4_address_new ();
+	nm_ip4_address_set_prefix (addr, 24); /* default to class C */
+
 	/* Internal address of the VPN subnet's gateway */
 	val = (GValue *) g_hash_table_lookup (config_hash, NM_VPN_PLUGIN_IP4_CONFIG_INT_GATEWAY);
 	if (val)
@@ -397,11 +396,11 @@
 	/* External world-visible address of the VPN server */
 	val = (GValue *) g_hash_table_lookup (config_hash, NM_VPN_PLUGIN_IP4_CONFIG_EXT_GATEWAY);
 	if (val)
-		addr->gateway = g_value_get_uint (val);
+		nm_ip4_address_set_gateway (addr, g_value_get_uint (val));
 
 	val = (GValue *) g_hash_table_lookup (config_hash, NM_VPN_PLUGIN_IP4_CONFIG_ADDRESS);
 	if (val)
-		addr->address = g_value_get_uint (val);
+		nm_ip4_address_set_address (addr, g_value_get_uint (val));
 
 	val = (GValue *) g_hash_table_lookup (config_hash, NM_VPN_PLUGIN_IP4_CONFIG_PTP);
 	if (val)
@@ -409,13 +408,13 @@
 
 	val = (GValue *) g_hash_table_lookup (config_hash, NM_VPN_PLUGIN_IP4_CONFIG_PREFIX);
 	if (val)
-		addr->prefix = g_value_get_uint (val);
+		nm_ip4_address_set_prefix (addr, g_value_get_uint (val));
 
-	if (addr->address && addr->prefix) {
+	if (nm_ip4_address_get_address (addr) && nm_ip4_address_get_prefix (addr)) {
 		nm_ip4_config_take_address (config, addr);
 	} else {
 		nm_warning ("%s: invalid IP4 config received!", __func__);
-		g_free (addr);
+		nm_ip4_address_unref (addr);
 		goto error;
 	}
 
@@ -461,7 +460,7 @@
 
 		routes = nm_utils_ip4_routes_from_gvalue (val);
 		for (iter = routes; iter; iter = iter->next)
-			nm_ip4_config_take_route (config, (NMSettingIP4Route *) iter->data);
+			nm_ip4_config_take_route (config, (NMIP4Route *) iter->data);
 
 		g_slist_free (routes);
 	}

Modified: trunk/system-settings/plugins/ifcfg-fedora/reader.c
==============================================================================
--- trunk/system-settings/plugins/ifcfg-fedora/reader.c	(original)
+++ trunk/system-settings/plugins/ifcfg-fedora/reader.c	Wed Oct 29 14:35:25 2008
@@ -165,8 +165,10 @@
 		get_one_ip4_addr (ifcfg, tag, &dns, error); \
 		if (*error) \
 			goto error; \
-		if (dns) \
-			g_array_append_val (s_ip4->dns, dns); \
+		if (dns) { \
+			if (!nm_setting_ip4_config_add_dns (s_ip4, dns)) \
+				PLUGIN_PRINT (IFCFG_PLUGIN_NAME, "    warning: duplicate DNS server %s", tag); \
+		} \
 	}
 		
 
@@ -175,9 +177,9 @@
 {
 	NMSettingIP4Config *s_ip4 = NULL;
 	char *value = NULL;
-	NMSettingIP4Address tmp = { 0, 0, 0 };
+	NMIP4Address *addr = NULL;
 	char *method = NM_SETTING_IP4_CONFIG_METHOD_MANUAL;
-	guint32 netmask = 0;
+	guint32 netmask = 0, tmp = 0;
 
 	value = svGetValue (ifcfg, "BOOTPROTO");
 	if (value && (!g_ascii_strcasecmp (value, "bootp") || !g_ascii_strcasecmp (value, "dhcp")))
@@ -186,7 +188,7 @@
 	if (value && !g_ascii_strcasecmp (value, "autoip")) {
 		g_free (value);
 		s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new ();
-		s_ip4->method = g_strdup (NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL);
+		g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL, NULL);
 		return NM_SETTING (s_ip4);
 	}
 
@@ -194,24 +196,29 @@
 
 	/* Handle manual settings */
 	if (!strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_MANUAL)) {
-		get_one_ip4_addr (ifcfg, "IPADDR", &tmp.address, error);
+		addr = nm_ip4_address_new ();
+
+		get_one_ip4_addr (ifcfg, "IPADDR", &tmp, error);
 		if (*error)
 			goto error;
+		nm_ip4_address_set_address (addr, tmp);
 
-		get_one_ip4_addr (ifcfg, "GATEWAY", &tmp.gateway, error);
+		get_one_ip4_addr (ifcfg, "GATEWAY", &tmp, error);
 		if (*error)
 			goto error;
+		nm_ip4_address_set_gateway (addr, tmp);
 
 		/* If no gateway in the ifcfg, try /etc/sysconfig/network instead */
-		if (!tmp.gateway) {
+		if (!nm_ip4_address_get_gateway (addr)) {
 			shvarFile *network;
 
 			network = svNewFile ("/etc/sysconfig/network");
 			if (network) {
-				get_one_ip4_addr (network, "GATEWAY", &tmp.gateway, error);
+				get_one_ip4_addr (network, "GATEWAY", &tmp, error);
 				svCloseFile (network);
 				if (*error)
 					goto error;
+				nm_ip4_address_set_gateway (addr, tmp);
 			}
 		}
 
@@ -227,57 +234,52 @@
 				g_free (value);
 				goto error;
 			}
-			tmp.prefix = (guint32) prefix;
+			nm_ip4_address_set_prefix (addr, (guint32) prefix);
 			g_free (value);
 		}
 
 		/* Fall back to NETMASK if no PREFIX was specified */
-		if (!tmp.prefix) {
+		if (!nm_ip4_address_get_prefix (addr)) {
 			get_one_ip4_addr (ifcfg, "NETMASK", &netmask, error);
 			if (*error)
 				goto error;
-			tmp.prefix = nm_utils_ip4_netmask_to_prefix (netmask);
+			nm_ip4_address_set_prefix (addr, nm_utils_ip4_netmask_to_prefix (netmask));
 		}
 
 		/* Validate the prefix */
-		if (!tmp.prefix || tmp.prefix > 32) {
+		if (  !nm_ip4_address_get_prefix (addr)
+		    || nm_ip4_address_get_prefix (addr) > 32) {
 			g_set_error (error, ifcfg_plugin_error_quark (), 0,
-			             "Invalid IP4 prefix '%d'", tmp.prefix);
+			             "Invalid IP4 prefix '%d'",
+			             nm_ip4_address_get_prefix (addr));
 			goto error;
 		}
 	}
 
 	/* Yay, let's make an IP4 config */
 	s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new ();
-	s_ip4->method = g_strdup (method);
-	s_ip4->ignore_auto_dns = !svTrueValue (ifcfg, "PEERDNS", 1);
+	g_object_set (s_ip4,
+	              NM_SETTING_IP4_CONFIG_METHOD, method,
+	              NM_SETTING_IP4_CONFIG_IGNORE_AUTO_DNS, !svTrueValue (ifcfg, "PEERDNS", 1),
+	              NULL);
 
 	/* DHCP hostname for 'send host-name' option */
 	if (!strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_AUTO)) {
 		value = svGetValue (ifcfg, "DHCP_HOSTNAME");
 		if (value && strlen (value))
-			s_ip4->dhcp_hostname = g_strdup (value);
+			g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_DHCP_HOSTNAME, value, NULL);
 		g_free (value);
 	}
 
-	if (tmp.address && tmp.prefix) {
-		NMSettingIP4Address *addr;
-		addr = g_new0 (NMSettingIP4Address, 1);
-		memcpy (addr, &tmp, sizeof (NMSettingIP4Address));
-		s_ip4->addresses = g_slist_append (s_ip4->addresses, addr);
+	if (nm_ip4_address_get_address (addr) && nm_ip4_address_get_prefix (addr)) {
+		if (!nm_setting_ip4_config_add_address (s_ip4, addr))
+			PLUGIN_PRINT (IFCFG_PLUGIN_NAME, "    warning: duplicate IP4 address");
 	}
 
-	s_ip4->dns = g_array_sized_new (FALSE, TRUE, sizeof (guint32), 3);
-
 	GET_ONE_DNS("DNS1");
 	GET_ONE_DNS("DNS2");
 	GET_ONE_DNS("DNS3");
 
-	if (s_ip4->dns && !s_ip4->dns->len) {
-		g_array_free (s_ip4->dns, TRUE);
-		s_ip4->dns = NULL;
-	}
-
 	/* DNS searches */
 	value = svGetValue (ifcfg, "DOMAIN");
 	if (value) {
@@ -286,15 +288,19 @@
 		searches = g_strsplit (value, " ", 0);
 		if (searches) {
 			char **item;
-			for (item = searches; *item; item++)
-				s_ip4->dns_search = g_slist_append (s_ip4->dns_search, *item);
-			g_free (searches);
+			for (item = searches; *item; item++) {
+				if (strlen (*item)) {
+					if (!nm_setting_ip4_config_add_dns_search (s_ip4, *item))
+						PLUGIN_PRINT (IFCFG_PLUGIN_NAME, "    warning: duplicate DNS domain '%s'", *item);
+				}
+			}
+			g_strfreev (searches);
 		}
 		g_free (value);
 	}
 
 	/* Legacy value NM used for a while but is incorrect (rh #459370) */
-	if (!g_slist_length (s_ip4->dns_search)) {
+	if (!nm_setting_ip4_config_get_num_dns_searches (s_ip4)) {
 		value = svGetValue (ifcfg, "SEARCH");
 		if (value) {
 			char **searches = NULL;
@@ -302,17 +308,26 @@
 			searches = g_strsplit (value, " ", 0);
 			if (searches) {
 				char **item;
-				for (item = searches; *item; item++)
-					s_ip4->dns_search = g_slist_append (s_ip4->dns_search, *item);
-				g_free (searches);
+				for (item = searches; *item; item++) {
+					if (strlen (*item)) {
+						if (!nm_setting_ip4_config_add_dns_search (s_ip4, *item))
+							PLUGIN_PRINT (IFCFG_PLUGIN_NAME, "    warning: duplicate DNS search '%s'", *item);
+					}
+				}
+				g_strfreev (searches);
 			}
 			g_free (value);
 		}
 	}
 
+	if (addr)
+		nm_ip4_address_unref (addr);
+
 	return NM_SETTING (s_ip4);
 
 error:
+	if (addr)
+		nm_ip4_address_unref (addr);
 	if (s_ip4)
 		g_object_unref (s_ip4);
 	return NULL;

Modified: trunk/system-settings/plugins/ifcfg-suse/parser.c
==============================================================================
--- trunk/system-settings/plugins/ifcfg-suse/parser.c	(original)
+++ trunk/system-settings/plugins/ifcfg-suse/parser.c	Wed Oct 29 14:35:25 2008
@@ -111,24 +111,26 @@
 {
 	NMSettingIP4Config *s_ip4;
 	char *str;
-	NMSettingIP4Address tmp = { 0, 0, 0 };
+	NMIP4Address *addr;
 
 	s_ip4 = NM_SETTING_IP4_CONFIG (nm_setting_ip4_config_new ());
 
 	str = svGetValue (ifcfg, "BOOTPROTO");
 	if (str) {
 		if (!g_ascii_strcasecmp (str, "bootp") || !g_ascii_strcasecmp (str, "dhcp"))
-			s_ip4->method = g_strdup (NM_SETTING_IP4_CONFIG_METHOD_AUTO);
+			g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL);
 		else if (!g_ascii_strcasecmp (str, "static"))
-			s_ip4->method = g_strdup (NM_SETTING_IP4_CONFIG_METHOD_MANUAL);
+			g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL, NULL);
 		else if (!g_ascii_strcasecmp (str, "autoip"))
-			s_ip4->method = g_strdup (NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL);
+			g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL, NULL);
 
 		g_free (str);
 	}
 
-	if (!s_ip4->method)
-		s_ip4->method = g_strdup (NM_SETTING_IP4_CONFIG_METHOD_AUTO);
+	if (!nm_setting_ip4_config_get_method (s_ip4))
+		g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL);
+
+	addr = nm_ip4_address_new ();
 
 	str = svGetValue (ifcfg, "IPADDR");
 	if (str) {
@@ -138,10 +140,10 @@
 		pieces = g_strsplit (str, "/", 2);
 
 		if (inet_pton (AF_INET, pieces[0], &ip4_addr) > 0) {
-			tmp.address = ip4_addr.s_addr;
+			nm_ip4_address_set_address (addr, ip4_addr.s_addr);
 
 			if (g_strv_length (pieces) == 2)
-				tmp.prefix = atoi (pieces[1]);
+				nm_ip4_address_set_prefix (addr, atoi (pieces[1]));
 		} else
 			g_warning ("Ignoring invalid IP4 address '%s'", str);
 
@@ -149,43 +151,43 @@
 		g_free (str);
 	}
 
-	if (tmp.address && tmp.prefix == 0) {
+	if (nm_ip4_address_get_address (addr) && nm_ip4_address_get_prefix (addr) == 0) {
 		str = svGetValue (ifcfg, "PREFIXLEN");
 		if (str) {
-			tmp.prefix = atoi (str);
+			nm_ip4_address_set_prefix (addr, atoi (str));
 			g_free (str);
 		}
 	}
 
-	if (tmp.address && tmp.prefix == 0) {
+	if (nm_ip4_address_get_address (addr) && nm_ip4_address_get_prefix (addr) == 0) {
 		str = svGetValue (ifcfg, "NETMASK");
 		if (str) {
 			struct in_addr mask_addr;
 
 			if (inet_pton (AF_INET, str, &mask_addr) > 0)
-				tmp.prefix = nm_utils_ip4_netmask_to_prefix (mask_addr.s_addr);
+				nm_ip4_address_set_prefix (addr, nm_utils_ip4_netmask_to_prefix (mask_addr.s_addr));
 			else {
-				g_warning ("Ignoring invalid IP4 addres: invalid netmask: '%s'", str);
-				tmp.address = 0;
-				tmp.prefix = 0;
+				g_warning ("Ignoring invalid IP4 address: invalid netmask: '%s'", str);
+				nm_ip4_address_set_address (addr, 0);
+				nm_ip4_address_set_prefix (addr, 0);
 			}
 			g_free (str);
 		}
 	}
 
-	if (!tmp.prefix || tmp.prefix > 32) {
-		g_warning ("Ignoring invalid IP4 addres: invalid prefix: '%d'", tmp.prefix);
-		tmp.address = 0;
-		tmp.prefix = 0;
+	if (!nm_ip4_address_get_prefix (addr) || nm_ip4_address_get_prefix (addr) > 32) {
+		g_warning ("Ignoring invalid IP4 address: invalid prefix: '%d'", nm_ip4_address_get_prefix (addr));
+		nm_ip4_address_set_address (addr, 0);
+		nm_ip4_address_set_prefix (addr, 0);
 	}
 
-	if (tmp.address) {
-		NMSettingIP4Address *addr;
-		addr = g_new0 (NMSettingIP4Address, 1);
-		memcpy (addr, &tmp, sizeof (NMSettingIP4Address));
-		s_ip4->addresses = g_slist_append (s_ip4->addresses, addr);
+	if (nm_ip4_address_get_address (addr)) {
+		if (!nm_setting_ip4_config_add_address (s_ip4, addr))
+			g_warning ("Ignoring duplicate IP4 address");
 	}
 
+	nm_ip4_address_unref (addr);
+
 	return NM_SETTING (s_ip4);
 }
 

Modified: trunk/system-settings/plugins/ifcfg-suse/plugin.c
==============================================================================
--- trunk/system-settings/plugins/ifcfg-suse/plugin.c	(original)
+++ trunk/system-settings/plugins/ifcfg-suse/plugin.c	Wed Oct 29 14:35:25 2008
@@ -94,14 +94,14 @@
 	if (!ip4_config)
 		return;
 
-	if (ip4_config->addresses) {
+	if (nm_setting_ip4_config_get_num_addresses (ip4_config)) {
 		/* suse only has one address per device */
-		NMSettingIP4Address *ip4_address = (NMSettingIP4Address *) ip4_config->addresses->data;
+		NMIP4Address *ip4_address = nm_setting_ip4_config_get_address (ip4_config, 0);
 		SCPluginIfcfgPrivate *priv = SC_PLUGIN_IFCFG_GET_PRIVATE (user_data);
 		GHashTable *settings;
 
-		if (ip4_address->gateway != priv->default_gw) {
-			ip4_address->gateway = priv->default_gw;
+		if (nm_ip4_address_get_gateway (ip4_address) != priv->default_gw) {
+			nm_ip4_address_set_gateway (ip4_address, priv->default_gw);
 			settings = nm_connection_to_hash (connection);
 			nm_exported_connection_signal_updated (exported, settings);
 			g_hash_table_destroy (settings);

Modified: trunk/system-settings/plugins/ifupdown/parser.c
==============================================================================
--- trunk/system-settings/plugins/ifupdown/parser.c	(original)
+++ trunk/system-settings/plugins/ifupdown/parser.c	Wed Oct 29 14:35:25 2008
@@ -460,9 +460,7 @@
 				   NULL);
 	} else {
  		struct in_addr tmp_ip4_addr;
-		NMSettingIP4Address *ip4config = g_new0(NMSettingIP4Address, 1);
-		GSList *ip4_addresses = NULL;
-		GArray *nameserver = g_array_new (TRUE, TRUE, sizeof(guint32));
+		NMIP4Address *ip4_addr = nm_ip4_address_new ();
 
 		const char *address_v = ifparser_getkey(block, "address");
 		const char *netmask_v = ifparser_getkey(block, "netmask");
@@ -482,7 +480,7 @@
 			address_v = g_strdup ("0.0.0.0");
 
 		if (inet_pton (AF_INET, address_v, &tmp_ip4_addr))
-			ip4config->address = tmp_ip4_addr.s_addr;
+			nm_ip4_address_set_address (ip4_addr, tmp_ip4_addr.s_addr);
 		else
 			g_set_error (&error, eni_plugin_error_quark (), 0,
 					   "Invalid %s IP4 address '%s'", "address", address_v);
@@ -490,7 +488,7 @@
 			netmask_v = g_strdup( "255.255.255.255");
 
 		if (inet_pton (AF_INET, netmask_v, &tmp_ip4_addr))
-			ip4config->prefix = nm_utils_ip4_netmask_to_prefix(tmp_ip4_addr.s_addr);
+			nm_ip4_address_set_prefix (ip4_addr, nm_utils_ip4_netmask_to_prefix(tmp_ip4_addr.s_addr));
 		else
 			g_set_error (&error, eni_plugin_error_quark (), 0,
 					   "Invalid %s IP4 address '%s'", "netmask", netmask_v);
@@ -499,32 +497,33 @@
 			gateway_v = g_strdup (address_v);
 
 		if (inet_pton (AF_INET, gateway_v, &tmp_ip4_addr))
-			ip4config->gateway = tmp_ip4_addr.s_addr;
+			nm_ip4_address_set_gateway (ip4_addr, tmp_ip4_addr.s_addr);
 		else
 			g_set_error (&error, eni_plugin_error_quark (), 0,
 					   "Invalid %s IP4 address '%s'", "gateway", gateway_v);
 
-		ip4_addresses = g_slist_append(ip4_addresses, ip4config);
-
-		PLUGIN_PRINT("SCPlugin-Ifupdown", "addresses count: %d", g_slist_length(ip4_addresses));
+		if (nm_setting_ip4_config_add_address (ip4_setting, ip4_addr)) {
+			PLUGIN_PRINT("SCPlugin-Ifupdown", "addresses count: %d",
+			             nm_setting_ip4_config_get_num_addresses (ip4_setting));
+		} else {
+			PLUGIN_PRINT("SCPlugin-Ifupdown", "ignoring duplicate IP4 address");
+		}
 
 		while(nameservers_list_i) {
 			gchar *dns = nameservers_list_i->data;
 			nameservers_list_i = nameservers_list_i -> next;
 			if(!dns)
 				continue;
-			if (inet_pton (AF_INET, dns, &tmp_ip4_addr))
-				g_array_append_vals(nameserver, &tmp_ip4_addr.s_addr, 1);
-			else
+			if (inet_pton (AF_INET, dns, &tmp_ip4_addr)) {
+				if (!nm_setting_ip4_config_add_dns (ip4_setting, tmp_ip4_addr.s_addr))
+					PLUGIN_PRINT("SCPlugin-Ifupdown", "ignoring duplicate DNS server '%s'", dns);
+			} else
 				g_set_error (&error, eni_plugin_error_quark (), 0,
 						   "Invalid %s IP4 address nameserver '%s'", "nameserver", dns);
 		}
-		if (!nameserver->len)
+		if (!nm_setting_ip4_config_get_num_dns (ip4_setting))
 			PLUGIN_PRINT("SCPlugin-Ifupdown", "No dns-nameserver configured in /etc/network/interfaces");
 
-		ip4_setting->addresses = ip4_addresses;
-		ip4_setting->dns = nameserver;
-
 		g_object_set(ip4_setting,
 				   NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL,
 				   NULL);

Modified: trunk/test/nm-tool.c
==============================================================================
--- trunk/test/nm-tool.c	(original)
+++ trunk/test/nm-tool.c	Wed Oct 29 14:35:25 2008
@@ -338,20 +338,21 @@
 		printf ("\n  IPv4 Settings:\n");
 
 		for (iter = (GSList *) nm_ip4_config_get_addresses (cfg); iter; iter = g_slist_next (iter)) {
-			NMSettingIP4Address *addr = iter->data;
+			NMIP4Address *addr = (NMIP4Address *) iter->data;
+			guint32 prefix = nm_ip4_address_get_prefix (addr);
 			char *tmp2;
 
-			tmp = ip4_address_as_string (addr->address);
+			tmp = ip4_address_as_string (nm_ip4_address_get_address (addr));
 			print_string ("  Address", tmp);
 			g_free (tmp);
 
-			tmp2 = ip4_address_as_string (nm_utils_ip4_prefix_to_netmask (addr->prefix));
-			tmp = g_strdup_printf ("%d (%s)", addr->prefix, tmp2);
+			tmp2 = ip4_address_as_string (nm_utils_ip4_prefix_to_netmask (prefix));
+			tmp = g_strdup_printf ("%d (%s)", prefix, tmp2);
 			g_free (tmp2);
 			print_string ("  Prefix", tmp);
 			g_free (tmp);
 
-			tmp = ip4_address_as_string (addr->gateway);
+			tmp = ip4_address_as_string (nm_ip4_address_get_gateway (addr));
 			print_string ("  Gateway", tmp);
 			g_free (tmp);
 			printf ("\n");

Modified: trunk/vpn-daemons/vpnc/properties/nm-vpnc.c
==============================================================================
--- trunk/vpn-daemons/vpnc/properties/nm-vpnc.c	(original)
+++ trunk/vpn-daemons/vpnc/properties/nm-vpnc.c	Wed Oct 29 14:35:25 2008
@@ -629,10 +629,9 @@
 	iface_class->save_secrets = save_secrets;
 }
 
-static GSList *
-get_routes (const char *routelist)
+static void
+add_routes (NMSettingIP4Config *s_ip4, const char *routelist)
 {
-	GSList *routes = NULL;
 	char **substrs;
 	unsigned int i;
 
@@ -659,13 +658,12 @@
 		/* don't pass the prefix to inet_pton() */
 		*p = '\0';
 		if (inet_pton (AF_INET, str_route, &tmp) > 0) {
-			NMSettingIP4Route *route;
+			NMIP4Route *route = nm_ip4_route_new ();
 
-			route = g_new0 (NMSettingIP4Route, 1);
-			route->address = tmp.s_addr;
-			route->prefix = (guint32) prefix;
+			nm_ip4_route_set_dest (route, tmp.s_addr);
+			nm_ip4_route_set_prefix (route, (guint32) prefix);
 
-			routes = g_slist_append (routes, route);
+			nm_setting_ip4_config_add_route (s_ip4, route);
 		} else
 			g_warning ("Ignoring invalid route '%s'", str_route);
 
@@ -674,7 +672,6 @@
 	}
 
 	g_strfreev (substrs);
-	return routes;
 }
 
 static NMConnection *
@@ -774,7 +771,7 @@
 
 		s_ip4 = NM_SETTING_IP4_CONFIG (nm_setting_ip4_config_new ());
 		nm_connection_add_setting (connection, NM_SETTING (s_ip4));
-		s_ip4->routes = get_routes (buf);
+		add_routes (s_ip4, buf);
 	}
 
 	if ((buf = pcf_file_lookup_value (pcf, "main", "TunnelingMode"))) {
@@ -870,20 +867,20 @@
 		peertimeout = value;
 
 	routes = g_string_new ("");
-	if (s_ip4 && s_ip4->routes) {
-		GSList *iter;
+	if (s_ip4 && nm_setting_ip4_config_get_num_routes (s_ip4)) {
+		int i;
 
-		for (iter = s_ip4->routes; iter; iter = g_slist_next (iter)) {
-			NMSettingIP4Route *route = (NMSettingIP4Route *) iter->data;
+		for (i = 0; i < nm_setting_ip4_config_get_num_routes (s_ip4); i++) {
+			NMIP4Route *route = nm_setting_ip4_config_get_route (s_ip4, i);
 			char str_addr[INET_ADDRSTRLEN + 1];
 			struct in_addr num_addr;
 
 			if (routes->len)
 				g_string_append_c (routes, ' ');
 
-			num_addr.s_addr = route->address;
+			num_addr.s_addr = nm_ip4_route_get_dest (route);
 			if (inet_ntop (AF_INET, &num_addr, &str_addr[0], INET_ADDRSTRLEN + 1))
-				g_string_append_printf (routes, "%s/%d", str_addr, route->prefix);
+				g_string_append_printf (routes, "%s/%d", str_addr, nm_ip4_route_get_prefix (route));
 		}
 	}
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]