NetworkManager r4378 - in branches/NETWORKMANAGER_0_7: . libnm-util src system-settings/plugins/ifcfg-rh



Author: dcbw
Date: Tue Dec  9 20:01:49 2008
New Revision: 4378
URL: http://svn.gnome.org/viewvc/NetworkManager?rev=4378&view=rev

Log:
2008-12-09  Dan Williams  <dcbw redhat com>

	* libnm-util/libnm-util.ver
	  libnm-util/nm-setting-ip4-config.c
	  libnm-util/nm-setting-ip4-config.h
		- Add 'never-default' property, which when true indicates that a
			connection should never be the default connection

	* src/nm-ip4-config.c
	  src/nm-ip4-config.h
		- (nm_ip4_config_get_never_default, nm_ip4_config_set_never_default):
			Add never-default helpers

	* src/NetworkManagerUtils.c
		- (nm_utils_merge_ip4_config): update never-default when merging the
			IP4 setting to the IP4 config

	* src/NetworkManagerSystem.c
		- (nm_system_apply_ip4_config): if the connection is never-default,
			don't add routes without a gateway

	* src/NetworkManagerPolicy.c
		- (get_best_device): don't let never-default connections be the best
		- (update_routing_and_dns): handle never-default for VPN connections

	* system-settings/plugins/ifcfg-rh/reader.c
		- (make_ip4_setting): handle never-default by checking GATEWAYDEV



Modified:
   branches/NETWORKMANAGER_0_7/ChangeLog
   branches/NETWORKMANAGER_0_7/libnm-util/libnm-util.ver
   branches/NETWORKMANAGER_0_7/libnm-util/nm-setting-ip4-config.c
   branches/NETWORKMANAGER_0_7/libnm-util/nm-setting-ip4-config.h
   branches/NETWORKMANAGER_0_7/src/NetworkManagerPolicy.c
   branches/NETWORKMANAGER_0_7/src/NetworkManagerSystem.c
   branches/NETWORKMANAGER_0_7/src/NetworkManagerUtils.c
   branches/NETWORKMANAGER_0_7/src/nm-ip4-config.c
   branches/NETWORKMANAGER_0_7/src/nm-ip4-config.h
   branches/NETWORKMANAGER_0_7/system-settings/plugins/ifcfg-rh/reader.c

Modified: branches/NETWORKMANAGER_0_7/libnm-util/libnm-util.ver
==============================================================================
--- branches/NETWORKMANAGER_0_7/libnm-util/libnm-util.ver	(original)
+++ branches/NETWORKMANAGER_0_7/libnm-util/libnm-util.ver	Tue Dec  9 20:01:49 2008
@@ -132,6 +132,7 @@
 	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_ip4_config_get_never_default;
 	nm_setting_need_secrets;
 	nm_setting_ppp_error_get_type;
 	nm_setting_ppp_error_quark;

Modified: branches/NETWORKMANAGER_0_7/libnm-util/nm-setting-ip4-config.c
==============================================================================
--- branches/NETWORKMANAGER_0_7/libnm-util/nm-setting-ip4-config.c	(original)
+++ branches/NETWORKMANAGER_0_7/libnm-util/nm-setting-ip4-config.c	Tue Dec  9 20:01:49 2008
@@ -81,6 +81,7 @@
 	gboolean ignore_auto_dns;
 	char *dhcp_client_id;
 	char *dhcp_hostname;
+	gboolean never_default;
 } NMSettingIP4ConfigPrivate;
 
 enum {
@@ -94,6 +95,7 @@
 	PROP_IGNORE_AUTO_DNS,
 	PROP_DHCP_CLIENT_ID,
 	PROP_DHCP_HOSTNAME,
+	PROP_NEVER_DEFAULT,
 
 	LAST_PROP
 };
@@ -418,6 +420,14 @@
 	return NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting)->dhcp_hostname;
 }
 
+gboolean
+nm_setting_ip4_config_get_never_default (NMSettingIP4Config *setting)
+{
+	g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), FALSE);
+
+	return NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting)->never_default;
+}
+
 static gboolean
 verify (NMSetting *setting, GSList *all_settings, GError **error)
 {
@@ -611,6 +621,9 @@
 		g_free (priv->dhcp_hostname);
 		priv->dhcp_hostname = g_value_dup_string (value);
 		break;
+	case PROP_NEVER_DEFAULT:
+		priv->never_default = g_value_get_boolean (value);
+		break;
 	default:
 		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 		break;
@@ -652,6 +665,9 @@
 	case PROP_DHCP_HOSTNAME:
 		g_value_set_string (value, nm_setting_ip4_config_get_dhcp_hostname (setting));
 		break;
+	case PROP_NEVER_DEFAULT:
+		g_value_set_boolean (value, priv->never_default);
+		break;
 	default:
 		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 		break;
@@ -744,6 +760,14 @@
 						   "DHCP Hostname",
 						   NULL,
 						   G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE));
+
+	g_object_class_install_property
+		(object_class, PROP_NEVER_DEFAULT,
+		 g_param_spec_boolean (NM_SETTING_IP4_CONFIG_NEVER_DEFAULT,
+						   "Never default",
+						   "Never make this connection the default IPv4 connection",
+						   FALSE,
+						   G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE));
 }
 
 

Modified: branches/NETWORKMANAGER_0_7/libnm-util/nm-setting-ip4-config.h
==============================================================================
--- branches/NETWORKMANAGER_0_7/libnm-util/nm-setting-ip4-config.h	(original)
+++ branches/NETWORKMANAGER_0_7/libnm-util/nm-setting-ip4-config.h	Tue Dec  9 20:01:49 2008
@@ -62,6 +62,7 @@
 #define NM_SETTING_IP4_CONFIG_IGNORE_AUTO_DNS    "ignore-auto-dns"
 #define NM_SETTING_IP4_CONFIG_DHCP_CLIENT_ID     "dhcp-client-id"
 #define NM_SETTING_IP4_CONFIG_DHCP_HOSTNAME      "dhcp-hostname"
+#define NM_SETTING_IP4_CONFIG_NEVER_DEFAULT      "never-default"
 
 #define NM_SETTING_IP4_CONFIG_METHOD_AUTO       "auto"
 #define NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL "link-local"
@@ -158,6 +159,8 @@
 const char *  nm_setting_ip4_config_get_dhcp_client_id     (NMSettingIP4Config *setting);
 const char *  nm_setting_ip4_config_get_dhcp_hostname      (NMSettingIP4Config *setting);
 
+gboolean      nm_setting_ip4_config_get_never_default      (NMSettingIP4Config *setting);
+
 G_END_DECLS
 
 #endif /* NM_SETTING_IP4_CONFIG_H */

Modified: branches/NETWORKMANAGER_0_7/src/NetworkManagerPolicy.c
==============================================================================
--- branches/NETWORKMANAGER_0_7/src/NetworkManagerPolicy.c	(original)
+++ branches/NETWORKMANAGER_0_7/src/NetworkManagerPolicy.c	Tue Dec  9 20:01:49 2008
@@ -238,6 +238,10 @@
 		if (!can_default && !NM_IS_HSO_GSM_DEVICE (dev))
 			continue;
 
+		/* 'never-default' devices can't ever be the default */
+		if (s_ip4 && nm_setting_ip4_config_get_never_default (s_ip4))
+			continue;
+
 		prio = nm_device_get_priority (dev);
 		if (prio > 0 && prio < best_prio) {
 			best = dev;
@@ -487,7 +491,6 @@
 	NMIP4Config *ip4_config = NULL;
 	NMIP4Address *addr;
 	const char *ip_iface = NULL;
-	NMVPNConnection *vpn = NULL;
 	NMConnection *connection = NULL;
 	NMSettingConnection *s_con = NULL;
 	const char *connection_id;
@@ -502,55 +505,43 @@
 	vpns = nm_vpn_manager_get_active_connections (policy->vpn_manager);
 	for (iter = vpns; iter; iter = g_slist_next (iter)) {
 		NMVPNConnection *candidate = NM_VPN_CONNECTION (iter->data);
+		NMConnection *vpn_connection;
+		NMSettingIP4Config *s_ip4;
+		gboolean can_default = TRUE;
+		NMVPNConnectionState vpn_state;
+
+		/* If it's marked 'never-default', don't make it default */
+		vpn_connection = nm_vpn_connection_get_connection (candidate);
+		g_assert (vpn_connection);
+		s_ip4 = (NMSettingIP4Config *) nm_connection_get_setting (vpn_connection, NM_TYPE_SETTING_IP4_CONFIG);
+		if (s_ip4 && nm_setting_ip4_config_get_never_default (s_ip4))
+			can_default = FALSE;
 
-		if (!vpn && (nm_vpn_connection_get_vpn_state (candidate) == NM_VPN_CONNECTION_STATE_ACTIVATED))
-			vpn = g_object_ref (candidate);
-		g_object_unref (candidate);
-	}
-	g_slist_free (vpns);
-
-	/* VPNs are the default route only if they don't have custom non-host (ie, /32)
-	 * routes.  Custom non-host routes are redundant when the VPN is the default
-	 * route because any traffic meant for the custom route would be routed over
-	 * the VPN anyway.
-	 */
-	if (vpn) {
-		gboolean have_non_host_routes = FALSE;
-		int i;
-
-		ip4_config = nm_vpn_connection_get_ip4_config (vpn);
-		for (i = 0; i < nm_ip4_config_get_num_routes (ip4_config); i++) {
-			NMIP4Route *route = nm_ip4_config_get_route (ip4_config, i);
-
-			if (nm_ip4_route_get_prefix (route) != 32) {
-				have_non_host_routes = TRUE;
-				break;
-			}
-		}
-
-
-		if (!have_non_host_routes) {
+		vpn_state = nm_vpn_connection_get_vpn_state (candidate);
+		if (can_default && (vpn_state == NM_VPN_CONNECTION_STATE_ACTIVATED)) {
 			NMIP4Config *parent_ip4;
 			NMDevice *parent;
 
-			ip_iface = nm_vpn_connection_get_ip_iface (vpn);
-			connection = nm_vpn_connection_get_connection (vpn);
+			ip_iface = nm_vpn_connection_get_ip_iface (candidate);
+			connection = nm_vpn_connection_get_connection (candidate);
+			ip4_config = nm_vpn_connection_get_ip4_config (candidate);
 			addr = nm_ip4_config_get_address (ip4_config, 0);
 
-			parent = nm_vpn_connection_get_parent_device (vpn);
+			parent = nm_vpn_connection_get_parent_device (candidate);
 			parent_ip4 = nm_device_get_ip4_config (parent);
 
 			nm_system_replace_default_ip4_route_vpn (ip_iface,
 			                                         nm_ip4_address_get_gateway (addr),
-			                                         nm_vpn_connection_get_ip4_internal_gateway (vpn),
+			                                         nm_vpn_connection_get_ip4_internal_gateway (candidate),
 			                                         nm_ip4_config_get_mss (ip4_config),
 			                                         nm_device_get_ip_iface (parent),
 			                                         nm_ip4_config_get_mss (parent_ip4));
 
 			dns_type = NM_NAMED_IP_CONFIG_TYPE_VPN;
 		}
-		g_object_unref (vpn);
+		g_object_unref (candidate);
 	}
+	g_slist_free (vpns);
 
 	/* The best device gets the default route if a VPN connection didn't */
 	if (!ip_iface || !ip4_config) {

Modified: branches/NETWORKMANAGER_0_7/src/NetworkManagerSystem.c
==============================================================================
--- branches/NETWORKMANAGER_0_7/src/NetworkManagerSystem.c	(original)
+++ branches/NETWORKMANAGER_0_7/src/NetworkManagerSystem.c	Tue Dec  9 20:01:49 2008
@@ -358,6 +358,13 @@
 			                             nm_ip4_route_get_prefix (route)))
 				continue;
 
+			/* Don't add the route if it doesn't have a gateway and the connection
+			 * is never supposed to be the default connection.
+			 */
+			if (   nm_ip4_config_get_never_default (config)
+			    && nm_ip4_route_get_dest (route) == 0)
+				continue;
+
 			tmp = nm_system_device_set_ip4_route (iface,
 			                                      nm_ip4_route_get_dest (route),
 			                                      nm_ip4_route_get_prefix (route),

Modified: branches/NETWORKMANAGER_0_7/src/NetworkManagerUtils.c
==============================================================================
--- branches/NETWORKMANAGER_0_7/src/NetworkManagerUtils.c	(original)
+++ branches/NETWORKMANAGER_0_7/src/NetworkManagerUtils.c	Tue Dec  9 20:01:49 2008
@@ -359,6 +359,9 @@
 		if (j == num)
 			nm_ip4_config_add_route (ip4_config, setting_route);
 	}
+
+	if (nm_setting_ip4_config_get_never_default (setting))
+		nm_ip4_config_set_never_default (ip4_config, TRUE);
 }
 
 static void

Modified: branches/NETWORKMANAGER_0_7/src/nm-ip4-config.c
==============================================================================
--- branches/NETWORKMANAGER_0_7/src/nm-ip4-config.c	(original)
+++ branches/NETWORKMANAGER_0_7/src/nm-ip4-config.c	Tue Dec  9 20:01:49 2008
@@ -55,6 +55,8 @@
 	GPtrArray *searches;
 
 	GSList *routes;
+
+	gboolean never_default;
 } NMIP4ConfigPrivate;
 
 
@@ -364,6 +366,22 @@
 	NM_IP4_CONFIG_GET_PRIVATE (config)->mss = mss;
 }
 
+gboolean
+nm_ip4_config_get_never_default (NMIP4Config *config)
+{
+	g_return_val_if_fail (NM_IS_IP4_CONFIG (config), FALSE);
+
+	return NM_IP4_CONFIG_GET_PRIVATE (config)->never_default;
+}
+
+void
+nm_ip4_config_set_never_default (NMIP4Config *config, gboolean never_default)
+{
+	g_return_if_fail (NM_IS_IP4_CONFIG (config));
+
+	NM_IP4_CONFIG_GET_PRIVATE (config)->never_default = never_default;
+}
+
 /* libnl convenience/conversion functions */
 
 static int ip4_addr_to_rtnl_local (guint32 ip4_address, struct rtnl_addr *addr)

Modified: branches/NETWORKMANAGER_0_7/src/nm-ip4-config.h
==============================================================================
--- branches/NETWORKMANAGER_0_7/src/nm-ip4-config.h	(original)
+++ branches/NETWORKMANAGER_0_7/src/nm-ip4-config.h	Tue Dec  9 20:01:49 2008
@@ -89,6 +89,9 @@
 guint32       nm_ip4_config_get_mss             (NMIP4Config *config);
 void          nm_ip4_config_set_mss             (NMIP4Config *config, guint32 mss);
 
+gboolean      nm_ip4_config_get_never_default   (NMIP4Config *config);
+void          nm_ip4_config_set_never_default   (NMIP4Config *config, gboolean never_default);
+
 /* Flags for nm_ip4_config_to_rtnl_addr() */
 #define NM_RTNL_ADDR_NONE		0x0000
 #define NM_RTNL_ADDR_ADDR		0x0001

Modified: branches/NETWORKMANAGER_0_7/system-settings/plugins/ifcfg-rh/reader.c
==============================================================================
--- branches/NETWORKMANAGER_0_7/system-settings/plugins/ifcfg-rh/reader.c	(original)
+++ branches/NETWORKMANAGER_0_7/system-settings/plugins/ifcfg-rh/reader.c	Tue Dec  9 20:01:49 2008
@@ -180,6 +180,27 @@
 	NMIP4Address *addr = NULL;
 	char *method = NM_SETTING_IP4_CONFIG_METHOD_MANUAL;
 	guint32 netmask = 0, tmp = 0;
+	shvarFile *network_ifcfg;
+	gboolean never_default = FALSE;
+
+	network_ifcfg = svNewFile (SYSCONFDIR "/sysconfig/network");
+	if (network_ifcfg) {
+		char *gatewaydev;
+
+		/* Get the connection ifcfg device name and the global gateway device */
+		value = svGetValue (ifcfg, "DEVICE");
+		gatewaydev = svGetValue (network_ifcfg, "GATEWAYDEV");
+
+		/* If there was a global gateway device specified, then only connections
+		 * for that device can be the default connection.
+		 */
+		if (gatewaydev && value && strcmp (value, gatewaydev))
+			never_default = TRUE;
+
+		g_free (gatewaydev);
+		g_free (value);
+		svCloseFile (network_ifcfg);
+	}
 
 	value = svGetValue (ifcfg, "BOOTPROTO");
 	if (value && (!g_ascii_strcasecmp (value, "bootp") || !g_ascii_strcasecmp (value, "dhcp")))
@@ -188,7 +209,10 @@
 	if (value && !g_ascii_strcasecmp (value, "autoip")) {
 		g_free (value);
 		s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new ();
-		g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL, NULL);
+		g_object_set (s_ip4,
+		              NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL,
+		              NM_SETTING_IP4_CONFIG_NEVER_DEFAULT, never_default,
+		              NULL);
 		return NM_SETTING (s_ip4);
 	}
 
@@ -210,12 +234,10 @@
 
 		/* If no gateway in the ifcfg, try /etc/sysconfig/network instead */
 		if (!nm_ip4_address_get_gateway (addr)) {
-			shvarFile *network;
-
-			network = svNewFile ("/etc/sysconfig/network");
-			if (network) {
-				get_one_ip4_addr (network, "GATEWAY", &tmp, error);
-				svCloseFile (network);
+			network_ifcfg = svNewFile (SYSCONFDIR "/sysconfig/network");
+			if (network_ifcfg) {
+				get_one_ip4_addr (network_ifcfg, "GATEWAY", &tmp, error);
+				svCloseFile (network_ifcfg);
 				if (*error)
 					goto error;
 				nm_ip4_address_set_gateway (addr, tmp);
@@ -261,6 +283,7 @@
 	g_object_set (s_ip4,
 	              NM_SETTING_IP4_CONFIG_METHOD, method,
 	              NM_SETTING_IP4_CONFIG_IGNORE_AUTO_DNS, !svTrueValue (ifcfg, "PEERDNS", 1),
+	              NM_SETTING_IP4_CONFIG_NEVER_DEFAULT, never_default,
 	              NULL);
 
 	/* DHCP hostname for 'send host-name' option */



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