NetworkManager r3698 - in trunk: . src src/backends



Author: dcbw
Date: Wed May 28 21:49:34 2008
New Revision: 3698
URL: http://svn.gnome.org/viewvc/NetworkManager?rev=3698&view=rev

Log:
2008-05-28  Dan Williams  <dcbw redhat com>

	Patch from Benoit Boissinot <bboissin+networkmanager gmail com>

	* src/NetworkManagerSystem.c
		- (nm_system_device_flush_ip4_routes_with_iface): implement with libnl
		- (nm_system_vpn_device_set_from_ip4_config): don't flush routes here,
			was causing -EINVAL errors since the libnl code actually does flush
			the routes on VPN interfaces now

	* src/backends/NetworkManagerArch.c
	  src/backends/NetworkManagerDebian.c
	  src/backends/NetworkManagerFrugalware.c
	  src/backends/NetworkManagerGeneric.c
	  src/backends/NetworkManagerGentoo.c
	  src/backends/NetworkManagerMandriva.c
	  src/backends/NetworkManagerPaldo.c
	  src/backends/NetworkManagerRedHat.c
	  src/backends/NetworkManagerSlackware.c
	  src/backends/NetworkManagerSuSE.c
		- (nm_system_device_flush_ip4_routes,
		   nm_system_device_flush_ip4_routes_with_iface): remove



Modified:
   trunk/ChangeLog
   trunk/src/NetworkManagerSystem.c
   trunk/src/backends/NetworkManagerArch.c
   trunk/src/backends/NetworkManagerDebian.c
   trunk/src/backends/NetworkManagerFrugalware.c
   trunk/src/backends/NetworkManagerGeneric.c
   trunk/src/backends/NetworkManagerGentoo.c
   trunk/src/backends/NetworkManagerMandriva.c
   trunk/src/backends/NetworkManagerPaldo.c
   trunk/src/backends/NetworkManagerRedHat.c
   trunk/src/backends/NetworkManagerSlackware.c
   trunk/src/backends/NetworkManagerSuSE.c

Modified: trunk/src/NetworkManagerSystem.c
==============================================================================
--- trunk/src/NetworkManagerSystem.c	(original)
+++ trunk/src/NetworkManagerSystem.c	Wed May 28 21:49:34 2008
@@ -367,10 +367,6 @@
 	if (nm_ip4_config_get_mtu (config))
 		nm_system_device_set_mtu (iface, nm_ip4_config_get_mtu (config));
 
-	sleep (1);
-
-	nm_system_device_flush_ip4_routes_with_iface (iface);
-
 	if (g_slist_length (routes) == 0) {
 		nm_system_device_replace_default_ip4_route (iface, 0, 0);
 	} else {
@@ -705,3 +701,77 @@
 	nl_cache_free (addr_cache);
 }
 
+/*
+ * nm_system_device_flush_ip4_routes
+ *
+ * Flush all network addresses associated with a network device
+ *
+ */
+void nm_system_device_flush_ip4_routes (NMDevice *dev)
+{
+	g_return_if_fail (dev != NULL);
+
+	nm_system_device_flush_ip4_routes_with_iface (nm_device_get_iface (dev));
+}
+
+typedef struct {
+	const char *iface;
+	struct nl_handle *nlh;
+	int iface_idx;
+} RouteCheckData;
+
+static void
+check_one_route (struct nl_object *object, void *user_data)
+{
+	RouteCheckData *data = (RouteCheckData *) user_data;
+	struct rtnl_route *route = (struct rtnl_route *) object;
+	int err;
+
+	/* Delete all IPv4 routes from this interface */
+	if (rtnl_route_get_oif (route) != data->iface_idx)
+		return;
+	if (rtnl_route_get_family (route) != AF_INET)
+		return;
+
+	err = rtnl_route_del (data->nlh, route, 0);
+	if (err < 0) {
+		nm_warning ("(%s) error %d returned from rtnl_route_del(): %s",
+		            data->iface, err, nl_geterror());
+	}
+}
+
+/*
+ * nm_system_device_flush_ip4_routes_with_iface
+ *
+ * Flush all routes associated with a network device
+ *
+ */
+void nm_system_device_flush_ip4_routes_with_iface (const char *iface)
+{
+	struct nl_handle *nlh = NULL;
+	struct nl_cache *route_cache = NULL;
+	int iface_idx;
+	RouteCheckData check_data;
+
+	g_return_if_fail (iface != NULL);
+	iface_idx = nm_netlink_iface_to_index (iface);
+	g_return_if_fail (iface_idx >= 0);
+
+	nlh = nm_netlink_get_default_handle ();
+	g_return_if_fail (nlh != NULL);
+
+	memset (&check_data, 0, sizeof (check_data));
+	check_data.iface = iface;
+	check_data.nlh = nlh;
+	check_data.iface_idx = iface_idx;
+
+	route_cache = rtnl_route_alloc_cache (nlh);
+	g_return_if_fail (route_cache != NULL);
+	nl_cache_mngt_provide (route_cache);
+
+	/* Remove routing table entries */
+	nl_cache_foreach (route_cache, check_one_route, &check_data);
+
+	nl_cache_free (route_cache);
+}
+

Modified: trunk/src/backends/NetworkManagerArch.c
==============================================================================
--- trunk/src/backends/NetworkManagerArch.c	(original)
+++ trunk/src/backends/NetworkManagerArch.c	Wed May 28 21:49:34 2008
@@ -68,139 +68,6 @@
 }
 
 /*
- * nm_system_device_flush_ip4_addresses
- *
- * Flush all network addresses associated with a network device
- *
- */
-void nm_system_device_flush_ip4_routes (NMDevice *dev)
-{
-	nm_generic_device_flush_ip4_routes (dev);
-}
-
-/*
- * nm_system_device_flush_ip4_routes_with_iface
- *
- * Flush all routes associated with a network device
- *
- */
-void nm_system_device_flush_ip4_routes_with_iface (const char *iface)
-{
-	nm_generic_device_flush_ip4_routes_with_iface (iface);
-}
-
-/*
- * nm_system_device_setup_static_ip4_config
- *
- * Set up the device with a particular IPv4 address/netmask/gateway.
- *
- * Returns:	TRUE	on success
- *			FALSE on error
- *
- */
-#if 0
-gboolean nm_system_device_setup_static_ip4_config (NMDevice *dev)
-{
-#define IPBITS (sizeof (guint32) * 8)
-	struct in_addr  temp_addr;
-	struct in_addr  temp_addr2;
-	char            *s_tmp;
-	char            *s_tmp2;
-	int             i;
-	guint32         addr;
-	guint32         netmask;
-	guint32         prefix = IPBITS;	 /* initialize with # bits in ipv4 address */
-	guint32         broadcast;
-	char            *buf;
-	int             err;
-	const char            *iface;
-
-	g_return_val_if_fail (dev != NULL, FALSE);
-	g_return_val_if_fail (!nm_device_config_get_use_dhcp (dev), FALSE);
-
-	addr = nm_device_config_get_ip4_address (dev);
-	netmask = nm_device_config_get_ip4_netmask (dev);
-	iface = nm_device_get_iface (dev);
-	broadcast = nm_device_config_get_ip4_broadcast (dev);
-
-	/* get the prefix from the netmask */
-	for (i = 0; i < IPBITS; i++)
-	{
-		if (!(ntohl (netmask) & ((2 << i) - 1)))
-			prefix--;
-	}
-
-	/* Calculate the broadcast address if the user didn't specify one */
-	if (!broadcast)
-		broadcast = ((addr & (int)netmask) | ~(int)netmask);
-
-	/* 
-	 * Try and work out if someone else has our IP
-	 * using RFC 2131 Duplicate Address Detection
-	 */
-	temp_addr.s_addr = addr;
-	buf = g_strdup_printf ("%s -q -D -c 1 -I %s %s",ARPING, 
-					   iface, inet_ntoa (temp_addr));
-	if ((err = nm_spawn_process (buf)))
-	{
-		nm_warning ("Error: Duplicate address '%s' detected for " 
-				  "device '%s' \n", iface, inet_ntoa (temp_addr));
-		goto error;
-	}
-	g_free (buf);
-
-	/* set our IP address */
-	temp_addr.s_addr = addr;
-	temp_addr2.s_addr = broadcast;
-	s_tmp = g_strdup (inet_ntoa (temp_addr));
-	s_tmp2 = g_strdup (inet_ntoa (temp_addr2));
-	buf = g_strdup_printf ("/sbin/ip addr add %s/%d brd %s dev %s label %s",
-					   s_tmp, prefix, s_tmp2, iface, iface);
-	g_free (s_tmp);
-	g_free (s_tmp2);
-	if ((err = nm_spawn_process (buf)))
-	{
-		nm_warning ("Error: could not set network configuration for "
-				  "device '%s' using command:\n      '%s'",
-				  iface, buf);
-		goto error;
-	}
-	g_free (buf);
-
-	/* Alert other computers of our new address */
-	temp_addr.s_addr = addr;
-	buf = g_strdup_printf ("%s -q -A -c 1 -I %s %s", ARPING,iface,
-					   inet_ntoa (temp_addr));
-	nm_spawn_process (buf);
-	g_free (buf);
-	g_usleep (G_USEC_PER_SEC * 2);
-	buf = g_strdup_printf ("%s -q -U -c 1 -I %s %s", ARPING, iface,
-					   inet_ntoa (temp_addr));
-	nm_spawn_process (buf);
-	g_free (buf);
-
-	/* set the default route to be this device's gateway */
-	temp_addr.s_addr = nm_device_config_get_ip4_gateway (dev);
-	buf = g_strdup_printf ("/sbin/ip route replace default via %s dev %s",
-					   inet_ntoa (temp_addr), iface);
-	if ((err = nm_spawn_process (buf)))
-	{
-		nm_warning ("Error: could not set default route using "
-				  "command:\n    '%s'", buf);
-		goto error;
-	}
-	g_free (buf);
-	return(TRUE);
-
-	error:
-	g_free (buf);
-	nm_system_device_flush_ip4_addresses (dev);
-	nm_system_device_flush_ip4_routes (dev);
-	return(FALSE);
-}
-#endif
-
-/*
  * nm_system_enable_loopback
  *
  * Bring up the loopback interface

Modified: trunk/src/backends/NetworkManagerDebian.c
==============================================================================
--- trunk/src/backends/NetworkManagerDebian.c	(original)
+++ trunk/src/backends/NetworkManagerDebian.c	Wed May 28 21:49:34 2008
@@ -57,28 +57,6 @@
 }
 
 /*
- * nm_system_device_flush_ip4_addresses
- *
- * Flush all network addresses associated with a network device
- *
- */
-void nm_system_device_flush_ip4_routes (NMDevice *dev)
-{
-	nm_generic_device_flush_ip4_routes (dev);
-}
-
-/*
- * nm_system_device_flush_ip4_routes_with_iface
- *
- * Flush all routes associated with a network device
- *
- */
-void nm_system_device_flush_ip4_routes_with_iface (const char *iface)
-{
-	nm_generic_device_flush_ip4_routes_with_iface (iface);
-}
-
-/*
  * nm_system_enable_loopback
  *
  * Bring up the loopback interface

Modified: trunk/src/backends/NetworkManagerFrugalware.c
==============================================================================
--- trunk/src/backends/NetworkManagerFrugalware.c	(original)
+++ trunk/src/backends/NetworkManagerFrugalware.c	Wed May 28 21:49:34 2008
@@ -51,37 +51,6 @@
 }
 
 /*
- * nm_system_device_flush_ip4_routes
- *
- * Flush all routes associated with a network device
- *
- */
-void nm_system_device_flush_ip4_routes (NMDevice *dev)
-{
-	g_return_if_fail (dev != NULL);
-
-	nm_system_device_flush_ip4_routes_with_iface (nm_device_get_iface (dev));
-}
-
-/*
- * nm_system_device_flush_ip4_routes_with_iface
- *
- * Flush all routes associated with a network device
- *
- */
-void nm_system_device_flush_ip4_routes_with_iface (const char *iface)
-{
-	char	*buf;
-
-	g_return_if_fail (iface != NULL);
-
-	/* Remove routing table entries */
-	buf = g_strdup_printf ("/usr/sbin/ip -4 route flush dev %s", iface);
-	nm_spawn_process (buf);
-	g_free (buf);
-}
-
-/*
  * nm_system_enable_loopback
  *
  * Bring up the loopback interface

Modified: trunk/src/backends/NetworkManagerGeneric.c
==============================================================================
--- trunk/src/backends/NetworkManagerGeneric.c	(original)
+++ trunk/src/backends/NetworkManagerGeneric.c	Wed May 28 21:49:34 2008
@@ -59,37 +59,6 @@
 }
 
 /*
- * nm_generic_device_flush_ip4_addresses
- *
- * Flush all network addresses associated with a network device
- *
- */
-void nm_generic_device_flush_ip4_routes (NMDevice *dev)
-{
-	g_return_if_fail (dev != NULL);
-
-	nm_system_device_flush_ip4_routes_with_iface (nm_device_get_iface (dev));
-}
-
-/*
- * nm_generic_device_flush_ip4_routes_with_iface
- *
- * Flush all routes associated with a network device
- *
- */
-void nm_generic_device_flush_ip4_routes_with_iface (const char *iface)
-{
-	char	*buf;
-
-	g_return_if_fail (iface != NULL);
-
-	/* Remove routing table entries */
-	buf = g_strdup_printf (IP_BINARY_PATH" -4 route flush dev %s", iface);
-	nm_spawn_process (buf);
-	g_free (buf);
-}
-
-/*
  * nm_generic_enable_loopback
  *
  * Bring up the loopback interface

Modified: trunk/src/backends/NetworkManagerGentoo.c
==============================================================================
--- trunk/src/backends/NetworkManagerGentoo.c	(original)
+++ trunk/src/backends/NetworkManagerGentoo.c	Wed May 28 21:49:34 2008
@@ -55,28 +55,6 @@
 }
 
 /*
- * nm_system_device_flush_ip4_routes
- *
- * Flush all routes associated with a network device
- *
- */
-void nm_system_device_flush_ip4_routes (NMDevice *dev)
-{
-	nm_generic_device_flush_ip4_routes (dev);
-}
-
-/*
- * nm_system_device_flush_ip4_routes_with_iface
- *
- * Flush all routes associated with a network device
- *
- */
-void nm_system_device_flush_ip4_routes_with_iface (const char *iface)
-{
-	nm_generic_device_flush_ip4_routes_with_iface (iface);
-}
-
-/*
  * nm_system_enable_loopback
  *
  * Bring up the loopback interface

Modified: trunk/src/backends/NetworkManagerMandriva.c
==============================================================================
--- trunk/src/backends/NetworkManagerMandriva.c	(original)
+++ trunk/src/backends/NetworkManagerMandriva.c	Wed May 28 21:49:34 2008
@@ -54,29 +54,6 @@
 
 
 /*
- * nm_system_device_flush_ip4_routes
- *
- * Flush all routes associated with a network device
- *
- */
-void nm_system_device_flush_ip4_routes (NMDevice *dev)
-{
-	nm_generic_device_flush_ip4_routes (dev);
-}
-
-
-/*
- * nm_system_device_flush_ip4_routes_with_iface
- *
- * Flush all routes associated with a network device
- *
- */
-void nm_system_device_flush_ip4_routes_with_iface (const char *iface)
-{
-	nm_generic_device_flush_ip4_routes_with_iface (iface);
-}
-
-/*
  * nm_system_enable_loopback
  *
  * Bring up the loopback interface

Modified: trunk/src/backends/NetworkManagerPaldo.c
==============================================================================
--- trunk/src/backends/NetworkManagerPaldo.c	(original)
+++ trunk/src/backends/NetworkManagerPaldo.c	Wed May 28 21:49:34 2008
@@ -53,30 +53,6 @@
 	nm_generic_init ();
 }
 
-
-/*
- * nm_system_device_flush_ip4_routes
- *
- * Flush all routes associated with a network device
- *
- */
-void nm_system_device_flush_ip4_routes (NMDevice *dev)
-{
-	nm_generic_device_flush_ip4_routes (dev);
-}
-
-
-/*
- * nm_system_device_flush_ip4_routes_with_iface
- *
- * Flush all routes associated with a network device
- *
- */
-void nm_system_device_flush_ip4_routes_with_iface (const char *iface)
-{
-	nm_generic_device_flush_ip4_routes_with_iface (iface);
-}
-
 /*
  * nm_system_enable_loopback
  *

Modified: trunk/src/backends/NetworkManagerRedHat.c
==============================================================================
--- trunk/src/backends/NetworkManagerRedHat.c	(original)
+++ trunk/src/backends/NetworkManagerRedHat.c	Wed May 28 21:49:34 2008
@@ -50,30 +50,6 @@
 	nm_generic_init ();
 }
 
-
-/*
- * nm_system_device_flush_ip4_routes
- *
- * Flush all routes associated with a network device
- *
- */
-void nm_system_device_flush_ip4_routes (NMDevice *dev)
-{
-	nm_generic_device_flush_ip4_routes (dev);
-}
-
-
-/*
- * nm_system_device_flush_ip4_routes_with_iface
- *
- * Flush all routes associated with a network device
- *
- */
-void nm_system_device_flush_ip4_routes_with_iface (const char *iface)
-{
-	nm_generic_device_flush_ip4_routes_with_iface (iface);
-}
-
 /*
  * nm_system_enable_loopback
  *

Modified: trunk/src/backends/NetworkManagerSlackware.c
==============================================================================
--- trunk/src/backends/NetworkManagerSlackware.c	(original)
+++ trunk/src/backends/NetworkManagerSlackware.c	Wed May 28 21:49:34 2008
@@ -54,28 +54,6 @@
 }
 
 /*
- * nm_system_device_flush_ip4_routes
- *
- * Flush all routes associated with a network device
- *
- */
-void nm_system_device_flush_ip4_routes (NMDevice *dev)
-{
-	nm_generic_device_flush_ip4_routes (dev);
-}
-
-/*
- * nm_system_device_flush_ip4_routes_with_iface
- *
- * Flush all routes associated with a network device
- *
- */
-void nm_system_device_flush_ip4_routes_with_iface (const char *iface)
-{
-	nm_generic_device_flush_ip4_routes_with_iface (iface);
-}
-
-/*
  * nm_system_enable_loopback
  *
  * Bring up the loopback interface

Modified: trunk/src/backends/NetworkManagerSuSE.c
==============================================================================
--- trunk/src/backends/NetworkManagerSuSE.c	(original)
+++ trunk/src/backends/NetworkManagerSuSE.c	Wed May 28 21:49:34 2008
@@ -59,30 +59,6 @@
 	nm_generic_init ();
 }
 
-
-/*
- * nm_system_device_flush_ip4_routes
- *
- * Flush all routes associated with a network device
- *
- */
-void nm_system_device_flush_ip4_routes (NMDevice *dev)
-{
-	nm_generic_device_flush_ip4_routes (dev);
-}
-
-
-/*
- * nm_system_device_flush_ip4_routes_with_iface
- *
- * Flush all routes associated with a network device
- *
- */
-void nm_system_device_flush_ip4_routes_with_iface (const char *iface)
-{
-	nm_generic_device_flush_ip4_routes_with_iface (iface);
-}
-
 /*
  * nm_system_enable_loopback
  *



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