move nm_system_device_flush_ip4_addresses to a generic implementation
with libnl.

diff -r 04bd8ecd5c5b src/NetworkManagerSystem.c
--- a/src/NetworkManagerSystem.c        Fri Apr 25 22:42:50 2008 +0200
+++ b/src/NetworkManagerSystem.c        Fri Apr 25 22:43:18 2008 +0200
@@ -188,6 +188,7 @@
        const char *iface;
        struct nl_handle *nlh;
        struct rtnl_addr *match;
+       int iface_idx;
 } AddrCheckData;
 
 static void
@@ -198,13 +199,13 @@
        int err;
 
        /* Delete addresses on this interface which don't match the one we
-        * are about to add to it.
+        * are about to add to it (if a match is provided).
         */
-       if (nl_object_identical ((struct nl_object *) data->match, (struct 
nl_object *) addr))
+       if (data->match && nl_object_identical ((struct nl_object *) 
data->match, (struct nl_object *) addr))
                return;
-       if (rtnl_addr_get_ifindex (addr) != rtnl_addr_get_ifindex (data->match))
+       if (rtnl_addr_get_ifindex (addr) != data->iface_idx)
                return;
-       if (rtnl_addr_get_family (addr) != rtnl_addr_get_family (data->match))
+       if (rtnl_addr_get_family (addr) != AF_INET)
                return;
 
        err = rtnl_addr_delete (data->nlh, addr, 0);
@@ -260,6 +261,7 @@
        check_data.iface = iface;
        check_data.nlh = nlh;
        check_data.match = addr;
+       check_data.iface_idx = nm_netlink_iface_to_index (iface);
 
        /* Remove all addresses except the one we're about to add */
        nl_cache_foreach (addr_cache, check_one_address, &check_data);
@@ -633,3 +635,54 @@
        nl_cache_free (route_cache);
 }
 
+/*
+ * nm_system_device_flush_ip4_addresses
+ *
+ * Flush all network addresses associated with a network device
+ *
+ */
+void nm_system_device_flush_ip4_addresses (NMDevice *dev)
+{
+       g_return_if_fail (dev != NULL);
+
+       nm_system_device_flush_ip4_addresses_with_iface (nm_device_get_iface 
(dev));
+}
+
+
+/*
+ * nm_system_device_flush_ip4_addresses_with_iface
+ *
+ * Flush all network addresses associated with a network device
+ *
+ */
+void nm_system_device_flush_ip4_addresses_with_iface (const char *iface)
+{
+       struct nl_handle *nlh = NULL;
+       struct nl_cache *addr_cache = NULL;
+       int iface_idx;
+       AddrCheckData 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.match = NULL;
+       check_data.iface_idx = nm_netlink_iface_to_index (iface);
+
+       addr_cache = rtnl_addr_alloc_cache (nlh);
+       if (!addr_cache)
+               return;
+       nl_cache_mngt_provide (addr_cache);
+
+       /* Remove all IP addresses for a device */
+       nl_cache_foreach (addr_cache, check_one_address, &check_data);
+
+       nl_cache_free (addr_cache);
+}
+
diff -r 04bd8ecd5c5b src/backends/NetworkManagerArch.c
--- a/src/backends/NetworkManagerArch.c Fri Apr 25 22:42:50 2008 +0200
+++ b/src/backends/NetworkManagerArch.c Fri Apr 25 22:43:18 2008 +0200
@@ -65,29 +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_addresses (NMDevice *dev)
-{
-       nm_generic_device_flush_ip4_addresses (dev);
-}
-
-
-/*
- * nm_system_device_flush_ip4_addresses_with_iface
- *
- * Flush all network addresses associated with a network device
- *
- */
-void nm_system_device_flush_ip4_addresses_with_iface (const char *iface)
-{
-       nm_generic_device_flush_ip4_addresses_with_iface (iface);
 }
 
 /*
diff -r 04bd8ecd5c5b src/backends/NetworkManagerDebian.c
--- a/src/backends/NetworkManagerDebian.c       Fri Apr 25 22:42:50 2008 +0200
+++ b/src/backends/NetworkManagerDebian.c       Fri Apr 25 22:43:18 2008 +0200
@@ -57,29 +57,6 @@
 }
 
 /*
- * 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);
-}
-
-
-/*
- * nm_system_device_flush_ip4_addresses_with_iface
- *
- * Flush all network addresses associated with a network device
- *
- */
-void nm_system_device_flush_ip4_addresses_with_iface (const char *iface)
-{
-       nm_generic_device_flush_ip4_addresses_with_iface (iface);
-}
-
-/*
  * nm_system_enable_loopback
  *
  * Bring up the loopback interface
diff -r 04bd8ecd5c5b src/backends/NetworkManagerFrugalware.c
--- a/src/backends/NetworkManagerFrugalware.c   Fri Apr 25 22:42:50 2008 +0200
+++ b/src/backends/NetworkManagerFrugalware.c   Fri Apr 25 22:43:18 2008 +0200
@@ -48,37 +48,6 @@
  */
 void nm_system_init (void)
 {
-}
-
-/*
- * nm_system_device_flush_ip4_addresses
- *
- * Flush all network addresses associated with a network device
- *
- */
-void nm_system_device_flush_ip4_addresses (NMDevice *dev)
-{
-       g_return_if_fail (dev != NULL);
-
-       nm_system_device_flush_ip4_addresses_with_iface (nm_device_get_iface 
(dev));
-}
-
-/*
- * nm_system_device_flush_ip4_addresses_with_iface
- *
- * Flush all network addresses associated with a network device
- *
- */
-void nm_system_device_flush_ip4_addresses_with_iface (const char *iface)
-{
-       char    *buf;
-
-       g_return_if_fail (iface != NULL);
-
-       /* Remove all IP addresses for a device */
-       buf = g_strdup_printf ("/usr/sbin/ip -4 addr flush dev %s", iface);
-       nm_spawn_process (buf);
-       g_free (buf);
 }
 
 /*
diff -r 04bd8ecd5c5b src/backends/NetworkManagerGeneric.c
--- a/src/backends/NetworkManagerGeneric.c      Fri Apr 25 22:42:50 2008 +0200
+++ b/src/backends/NetworkManagerGeneric.c      Fri Apr 25 22:43:18 2008 +0200
@@ -49,38 +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_addresses (NMDevice *dev)
-{
-       g_return_if_fail (dev != NULL);
-
-       nm_system_device_flush_ip4_addresses_with_iface (nm_device_get_iface 
(dev));
-}
-
-
-/*
- * nm_generic_device_flush_ip4_addresses_with_iface
- *
- * Flush all network addresses associated with a network device
- *
- */
-void nm_generic_device_flush_ip4_addresses_with_iface (const char *iface)
-{
-       char    *buf;
-
-       g_return_if_fail (iface != NULL);
-
-       /* Remove all IP addresses for a device */
-       buf = g_strdup_printf (IP_BINARY_PATH" -4 addr flush dev %s", iface);
-       nm_spawn_process (buf);
-       g_free (buf);
 }
 
 /*
diff -r 04bd8ecd5c5b src/backends/NetworkManagerGentoo.c
--- a/src/backends/NetworkManagerGentoo.c       Fri Apr 25 22:42:50 2008 +0200
+++ b/src/backends/NetworkManagerGentoo.c       Fri Apr 25 22:43:18 2008 +0200
@@ -65,29 +65,6 @@
 {
         /* TODO */
        return (FALSE);
-}
-
-
-/*
- * 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);
-}
-
-/*
- * nm_system_device_flush_ip4_addresses_with_iface
- *
- * Flush all network addresses associated with a network device
- *
- */
-void nm_system_device_flush_ip4_addresses_with_iface (const char *iface)
-{
-       nm_generic_device_flush_ip4_addresses_with_iface (iface);
 }
 
 #if 0
diff -r 04bd8ecd5c5b src/backends/NetworkManagerMandriva.c
--- a/src/backends/NetworkManagerMandriva.c     Fri Apr 25 22:42:50 2008 +0200
+++ b/src/backends/NetworkManagerMandriva.c     Fri Apr 25 22:43:18 2008 +0200
@@ -64,31 +64,6 @@
 {
        return (FALSE);
 }
-
-
-/*
- * 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);
-}
-
-
-/*
- * nm_system_device_flush_ip4_addresses_with_iface
- *
- * Flush all network addresses associated with a network device
- *
- */
-void nm_system_device_flush_ip4_addresses_with_iface (const char *iface)
-{
-       nm_generic_device_flush_ip4_addresses_with_iface (iface);
-}
-
 
 #if 0
        /* Alert other computers of our new address */
diff -r 04bd8ecd5c5b src/backends/NetworkManagerPaldo.c
--- a/src/backends/NetworkManagerPaldo.c        Fri Apr 25 22:42:50 2008 +0200
+++ b/src/backends/NetworkManagerPaldo.c        Fri Apr 25 22:43:18 2008 +0200
@@ -65,31 +65,6 @@
        return (FALSE);
 }
 
-
-/*
- * 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);
-}
-
-
-/*
- * nm_system_device_flush_ip4_addresses_with_iface
- *
- * Flush all network addresses associated with a network device
- *
- */
-void nm_system_device_flush_ip4_addresses_with_iface (const char *iface)
-{
-       nm_generic_device_flush_ip4_addresses_with_iface (iface);
-}
-
-
 /*
  * nm_system_enable_loopback
  *
diff -r 04bd8ecd5c5b src/backends/NetworkManagerRedHat.c
--- a/src/backends/NetworkManagerRedHat.c       Fri Apr 25 22:42:50 2008 +0200
+++ b/src/backends/NetworkManagerRedHat.c       Fri Apr 25 22:43:18 2008 +0200
@@ -62,31 +62,6 @@
        return (FALSE);
 }
 
-
-/*
- * 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);
-}
-
-
-/*
- * nm_system_device_flush_ip4_addresses_with_iface
- *
- * Flush all network addresses associated with a network device
- *
- */
-void nm_system_device_flush_ip4_addresses_with_iface (const char *iface)
-{
-       nm_generic_device_flush_ip4_addresses_with_iface (iface);
-}
-
-
 #if 0
        /* Alert other computers of our new address */
        temp_addr.s_addr = addr;
diff -r 04bd8ecd5c5b src/backends/NetworkManagerSlackware.c
--- a/src/backends/NetworkManagerSlackware.c    Fri Apr 25 22:42:50 2008 +0200
+++ b/src/backends/NetworkManagerSlackware.c    Fri Apr 25 22:43:18 2008 +0200
@@ -51,28 +51,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_addresses (NMDevice *dev)
-{
-       nm_generic_device_flush_ip4_addresses (dev);
-}
-
-/*
- * nm_system_device_flush_ip4_addresses_with_iface
- *
- * Flush all network addresses associated with a network device
- *
- */
-void nm_system_device_flush_ip4_addresses_with_iface (const char *iface)
-{
-       nm_generic_device_flush_ip4_addresses_with_iface (iface);
 }
 
 /*
diff -r 04bd8ecd5c5b src/backends/NetworkManagerSuSE.c
--- a/src/backends/NetworkManagerSuSE.c Fri Apr 25 22:42:50 2008 +0200
+++ b/src/backends/NetworkManagerSuSE.c Fri Apr 25 22:43:18 2008 +0200
@@ -70,31 +70,6 @@
 {
        return FALSE;
 }
-
-
-/*
- * 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);
-}
-
-
-/*
- * nm_system_device_flush_ip4_addresses_with_iface
- *
- * Flush all network addresses associated with a network device
- *
- */
-void nm_system_device_flush_ip4_addresses_with_iface (const char *iface)
-{
-       nm_generic_device_flush_ip4_addresses_with_iface (iface);
-}
-
 
 /*
  * nm_system_enable_loopback
-- 
:wq
_______________________________________________
NetworkManager-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/networkmanager-list

Reply via email to