[PATCH] [1/4] Use libnl instead of iproute (nm_system_device_flush_ip4_routes)
- From: Benoit Boissinot <bboissin+networkmanager gmail com>
- To: networkmanager-list gnome org
- Subject: [PATCH] [1/4] Use libnl instead of iproute (nm_system_device_flush_ip4_routes)
- Date: Sun, 27 Apr 2008 18:59:21 +0200
move nm_system_device_flush_ip4_routes to a generic implementation
with libnl.
diff -r 119c572e331e src/NetworkManagerSystem.c
--- a/src/NetworkManagerSystem.c Fri Apr 25 22:36:49 2008 +0200
+++ b/src/NetworkManagerSystem.c Fri Apr 25 22:42:50 2008 +0200
@@ -559,3 +559,77 @@
rtnl_route_put (route);
}
+/*
+ * 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);
+}
+
diff -r 119c572e331e src/backends/NetworkManagerArch.c
--- a/src/backends/NetworkManagerArch.c Fri Apr 25 22:36:49 2008 +0200
+++ b/src/backends/NetworkManagerArch.c Fri Apr 25 22:42:50 2008 +0200
@@ -65,28 +65,6 @@
void nm_system_init (void)
{
nm_generic_init ();
-}
-
-/*
- * 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);
}
/*
diff -r 119c572e331e src/backends/NetworkManagerDebian.c
--- a/src/backends/NetworkManagerDebian.c Fri Apr 25 22:36:49 2008 +0200
+++ b/src/backends/NetworkManagerDebian.c Fri Apr 25 22:42:50 2008 +0200
@@ -62,28 +62,6 @@
* 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_flush_ip4_addresses
- *
- * Flush all network addresses associated with a network device
- *
- */
void nm_system_device_flush_ip4_addresses (NMDevice *dev)
{
nm_generic_device_flush_ip4_addresses (dev);
diff -r 119c572e331e src/backends/NetworkManagerFrugalware.c
--- a/src/backends/NetworkManagerFrugalware.c Fri Apr 25 22:36:49 2008 +0200
+++ b/src/backends/NetworkManagerFrugalware.c Fri Apr 25 22:42:50 2008 +0200
@@ -49,38 +49,6 @@
void nm_system_init (void)
{
}
-
-/*
- * 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_device_flush_ip4_addresses
diff -r 119c572e331e src/backends/NetworkManagerGeneric.c
--- a/src/backends/NetworkManagerGeneric.c Fri Apr 25 22:36:49 2008 +0200
+++ b/src/backends/NetworkManagerGeneric.c Fri Apr 25 22:42:50 2008 +0200
@@ -49,37 +49,6 @@
{
/* Kill any dhclients lying around */
nm_system_kill_all_dhcp_daemons ();
-}
-
-/*
- * 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);
}
/*
diff -r 119c572e331e src/backends/NetworkManagerGentoo.c
--- a/src/backends/NetworkManagerGentoo.c Fri Apr 25 22:36:49 2008 +0200
+++ b/src/backends/NetworkManagerGentoo.c Fri Apr 25 22:42:50 2008 +0200
@@ -52,28 +52,6 @@
void nm_system_init (void)
{
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);
}
/*
diff -r 119c572e331e src/backends/NetworkManagerMandriva.c
--- a/src/backends/NetworkManagerMandriva.c Fri Apr 25 22:36:49 2008 +0200
+++ b/src/backends/NetworkManagerMandriva.c Fri Apr 25 22:42:50 2008 +0200
@@ -52,29 +52,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_device_has_active_routes
diff -r 119c572e331e src/backends/NetworkManagerPaldo.c
--- a/src/backends/NetworkManagerPaldo.c Fri Apr 25 22:36:49 2008 +0200
+++ b/src/backends/NetworkManagerPaldo.c Fri Apr 25 22:42:50 2008 +0200
@@ -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_device_has_active_routes
*
diff -r 119c572e331e src/backends/NetworkManagerRedHat.c
--- a/src/backends/NetworkManagerRedHat.c Fri Apr 25 22:36:49 2008 +0200
+++ b/src/backends/NetworkManagerRedHat.c Fri Apr 25 22:42:50 2008 +0200
@@ -48,30 +48,6 @@
void nm_system_init (void)
{
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);
}
/*
diff -r 119c572e331e src/backends/NetworkManagerSlackware.c
--- a/src/backends/NetworkManagerSlackware.c Fri Apr 25 22:36:49 2008 +0200
+++ b/src/backends/NetworkManagerSlackware.c Fri Apr 25 22:42:50 2008 +0200
@@ -52,29 +52,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_device_flush_ip4_addresses
diff -r 119c572e331e src/backends/NetworkManagerSuSE.c
--- a/src/backends/NetworkManagerSuSE.c Fri Apr 25 22:36:49 2008 +0200
+++ b/src/backends/NetworkManagerSuSE.c Fri Apr 25 22:42:50 2008 +0200
@@ -57,30 +57,6 @@
void nm_system_init (void)
{
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);
}
/*
--
:wq
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]