[PATCH] [resend] [2/3] Use libnl instead of iproute/AF_PACKET (nm_system_device_replace_default_ipv4_route)



(resend)
(depends on the cleanup of the frugalware backend)

Remove nm_system_device_replace_default_ip4_route from all
backends, implement it with libnl.

diff -r 44a2c48934ef src/NetworkManagerPolicy.c
--- a/src/NetworkManagerPolicy.c	Wed Apr 16 00:35:47 2008 -0400
+++ b/src/NetworkManagerPolicy.c	Wed Apr 23 20:54:30 2008 +0200
@@ -83,12 +83,12 @@
 	   a serial device with ppp interface, so route all the traffic to it. */
 	ip_iface = nm_device_get_ip_iface (new);
 	if (strcmp (ip_iface, nm_device_get_iface (new))) {
-		nm_system_device_replace_default_route (ip_iface, 0, 0);
+		nm_system_device_replace_default_ip4_route (ip_iface, 0, 0);
 	} else {
 		NMIP4Config *config;
 
 		config = nm_device_get_ip4_config (new);
-		nm_system_device_replace_default_route (ip_iface, nm_ip4_config_get_gateway (config),
+		nm_system_device_replace_default_ip4_route (ip_iface, nm_ip4_config_get_gateway (config),
 		                                        nm_ip4_config_get_mss (config));
 	}
 }
diff -r 44a2c48934ef src/NetworkManagerSystem.c
--- a/src/NetworkManagerSystem.c	Wed Apr 16 00:35:47 2008 -0400
+++ b/src/NetworkManagerSystem.c	Wed Apr 23 20:54:30 2008 +0200
@@ -347,7 +347,7 @@
 	nm_system_device_flush_ip4_routes_with_iface (iface);
 
 	if (g_slist_length (routes) == 0) {
-		nm_system_device_replace_default_route (iface, 0, 0);
+		nm_system_device_replace_default_ip4_route (iface, 0, 0);
 	} else {
 		GSList *iter;
 
@@ -500,3 +500,46 @@
 	rtnl_route_put (route);
 }
 
+/*
+ * nm_system_replace_default_ip4_route
+ *
+ * Replace default IPv4 route with one via the current device
+ *
+ */
+void
+nm_system_device_replace_default_ip4_route (const char *iface, guint32 gw, guint32 mss)
+{
+	struct rtnl_route * route;
+	struct nl_handle  * nlh;
+	struct nl_addr    * gw_addr;
+	int iface_idx;
+
+	nlh = nm_netlink_get_default_handle ();
+	g_return_if_fail (nlh != NULL);
+
+	route = rtnl_route_alloc();
+	g_return_if_fail (route != NULL);
+
+	rtnl_route_set_scope (route, RT_SCOPE_UNIVERSE);
+
+	iface_idx = nm_netlink_iface_to_index (iface);
+	if (iface_idx < 0)
+		goto out;
+	rtnl_route_set_oif (route, iface_idx);
+
+	if (gw > 0) {
+		if (!(gw_addr = nl_addr_build (AF_INET, &gw, sizeof (gw))))
+			goto out;
+		rtnl_route_set_gateway (route, gw_addr);
+		nl_addr_put (gw_addr);
+	}
+
+	if (mss > 0)
+		if (rtnl_route_set_metric (route, RTAX_ADVMSS, mss) < 0)
+			goto out;
+
+	rtnl_route_add (nlh, route, NLM_F_REPLACE);
+out:
+	rtnl_route_put (route);
+}
+
diff -r 44a2c48934ef src/NetworkManagerSystem.h
--- a/src/NetworkManagerSystem.h	Wed Apr 16 00:35:47 2008 -0400
+++ b/src/NetworkManagerSystem.h	Wed Apr 23 20:54:30 2008 +0200
@@ -38,7 +38,7 @@
 void			nm_system_device_flush_ip4_routes				(NMDevice *dev);
 void			nm_system_device_flush_ip4_routes_with_iface	(const char *iface);
 
-void			nm_system_device_replace_default_route      (const char *iface,
+void			nm_system_device_replace_default_ip4_route   (const char *iface,
                                                              guint32 gw,
                                                              guint32 mss);
 
diff -r 44a2c48934ef src/backends/NetworkManagerArch.c
--- a/src/backends/NetworkManagerArch.c	Wed Apr 16 00:35:47 2008 -0400
+++ b/src/backends/NetworkManagerArch.c	Wed Apr 23 20:54:30 2008 +0200
@@ -65,20 +65,6 @@
 void nm_system_init (void)
 {
 	nm_generic_init ();
-}
-
-/*
- * nm_system_device_replace_default_route
- *
- * Add default route to the given device
- *
- */
-void
-nm_system_device_replace_default_route (const char *iface,
-                                        guint32 gw,
-                                        guint32 mss)
-{
-	nm_generic_device_replace_default_route (iface, gw, mss);
 }
 
 /*
diff -r 44a2c48934ef src/backends/NetworkManagerDebian.c
--- a/src/backends/NetworkManagerDebian.c	Wed Apr 16 00:35:47 2008 -0400
+++ b/src/backends/NetworkManagerDebian.c	Wed Apr 23 20:54:30 2008 +0200
@@ -57,20 +57,6 @@
 }
 
 /*
- * nm_system_device_replace_default_route
- *
- * Add default route to the given device
- *
- */
-void
-nm_system_device_replace_default_route (const char *iface,
-                                        guint32 gw,
-                                        guint32 mss)
-{
-	nm_generic_device_replace_default_route (iface, gw, mss);
-}
-
-/*
  * nm_system_device_flush_ip4_addresses
  *
  * Flush all network addresses associated with a network device
diff -r 44a2c48934ef src/backends/NetworkManagerFrugalware.c
--- a/src/backends/NetworkManagerFrugalware.c	Wed Apr 16 00:35:47 2008 -0400
+++ b/src/backends/NetworkManagerFrugalware.c	Wed Apr 23 20:54:30 2008 +0200
@@ -162,21 +162,6 @@
 }
 
 /*
- * nm_system_device_replace_default_route
- *
- * Add default route to the given device
- *
- */
-void
-nm_system_device_replace_default_route (const char *iface,
-                                        guint32 gw,
-                                        guint32 mss)
-{
-	nm_generic_device_replace_default_route (iface, gw, mss);
-}
-
- 
-/*
  * nm_system_flush_loopback_routes
  *
  * Flush all routes associated with the loopback device, because it
diff -r 44a2c48934ef src/backends/NetworkManagerGeneric.c
--- a/src/backends/NetworkManagerGeneric.c	Wed Apr 16 00:35:47 2008 -0400
+++ b/src/backends/NetworkManagerGeneric.c	Wed Apr 23 20:54:30 2008 +0200
@@ -49,39 +49,6 @@
 {
 	/* Kill any dhclients lying around */
 	nm_system_kill_all_dhcp_daemons ();
-}
-
-/*
- * nm_generic_replace_default_route
- *
- * Replace default route with one via the current device
- *
- */
-void
-nm_generic_device_replace_default_route (const char *iface, guint32 gw, guint32 mss)
-{
-	char *buf, *addr_str = NULL, *mss_str = NULL;
-
-	g_return_if_fail (iface != NULL);
-
-	if (gw > 0) {
-		struct in_addr addr = { .s_addr = gw };
-		char buf2[INET_ADDRSTRLEN + 1];
-
-		memset (buf2, 0, sizeof (buf2));
-		inet_ntop (AF_INET, &addr, buf2, INET_ADDRSTRLEN);	
-		addr_str = g_strdup_printf ("via %s", buf2);
-	}
-
-	if (mss > 0)
-		mss_str = g_strdup_printf ("advmss %d", mss);
-
-	buf = g_strdup_printf (IP_BINARY_PATH" route replace default %s %s dev %s",
-	                       addr_str ? addr_str : "",
-	                       mss_str ? mss_str : "",
-	                       iface);
-	nm_spawn_process (buf);
-	g_free (buf);
 }
 
 /*
diff -r 44a2c48934ef src/backends/NetworkManagerGeneric.h
--- a/src/backends/NetworkManagerGeneric.h	Wed Apr 16 00:35:47 2008 -0400
+++ b/src/backends/NetworkManagerGeneric.h	Wed Apr 23 20:54:30 2008 +0200
@@ -39,8 +39,6 @@
 void			nm_generic_device_flush_ip4_routes				(NMDevice *dev);
 void			nm_generic_device_flush_ip4_routes_with_iface	(const char *iface);
 
-void            nm_generic_device_replace_default_route (const char *iface, guint32 gw, guint32 mss);
-
 void			nm_generic_device_flush_ip4_addresses			(NMDevice *dev);
 void			nm_generic_device_flush_ip4_addresses_with_iface	(const char *iface);
 
diff -r 44a2c48934ef src/backends/NetworkManagerGentoo.c
--- a/src/backends/NetworkManagerGentoo.c	Wed Apr 16 00:35:47 2008 -0400
+++ b/src/backends/NetworkManagerGentoo.c	Wed Apr 23 20:54:30 2008 +0200
@@ -220,20 +220,6 @@
 }
 
 /*
- * nm_system_device_replace_default_route
- *
- * Add default route to the given device
- *
- */
-void
-nm_system_device_replace_default_route (const char *iface,
-                                        guint32 gw,
-                                        guint32 mss)
-{
-	nm_generic_device_replace_default_route (iface, gw, mss);
-}
- 
-/*
  * nm_system_activate_nis
  *
  * set up the nis domain and write a yp.conf
diff -r 44a2c48934ef src/backends/NetworkManagerMandriva.c
--- a/src/backends/NetworkManagerMandriva.c	Wed Apr 16 00:35:47 2008 -0400
+++ b/src/backends/NetworkManagerMandriva.c	Wed Apr 23 20:54:30 2008 +0200
@@ -74,21 +74,6 @@
 void nm_system_device_flush_ip4_routes_with_iface (const char *iface)
 {
 	nm_generic_device_flush_ip4_routes_with_iface (iface);
-}
-
-
-/*
- * nm_system_device_replace_default_route
- *
- * Add default route to the given device
- *
- */
-void
-nm_system_device_replace_default_route (const char *iface,
-		guint32 gw,
-		guint32 mss)
-{
-	nm_generic_device_replace_default_route (iface, gw, mss);
 }
 
 /*
diff -r 44a2c48934ef src/backends/NetworkManagerPaldo.c
--- a/src/backends/NetworkManagerPaldo.c	Wed Apr 16 00:35:47 2008 -0400
+++ b/src/backends/NetworkManagerPaldo.c	Wed Apr 23 20:54:30 2008 +0200
@@ -77,21 +77,6 @@
 	nm_generic_device_flush_ip4_routes_with_iface (iface);
 }
 
-
-/*
- * nm_system_device_replace_default_route
- *
- * Add default route to the given device
- *
- */
-void
-nm_system_device_replace_default_route (const char *iface,
-                                        guint32 gw,
-                                        guint32 mss)
-{
-	nm_generic_device_replace_default_route (iface, gw, mss);
-}
-
 /*
  * nm_system_device_has_active_routes
  *
diff -r 44a2c48934ef src/backends/NetworkManagerRedHat.c
--- a/src/backends/NetworkManagerRedHat.c	Wed Apr 16 00:35:47 2008 -0400
+++ b/src/backends/NetworkManagerRedHat.c	Wed Apr 23 20:54:30 2008 +0200
@@ -72,21 +72,6 @@
 void nm_system_device_flush_ip4_routes_with_iface (const char *iface)
 {
 	nm_generic_device_flush_ip4_routes_with_iface (iface);
-}
-
-
-/*
- * nm_system_device_replace_default_route
- *
- * Add default route to the given device
- *
- */
-void
-nm_system_device_replace_default_route (const char *iface,
-                                        guint32 gw,
-                                        guint32 mss)
-{
-	nm_generic_device_replace_default_route (iface, gw, mss);
 }
 
 /*
diff -r 44a2c48934ef src/backends/NetworkManagerSlackware.c
--- a/src/backends/NetworkManagerSlackware.c	Wed Apr 16 00:35:47 2008 -0400
+++ b/src/backends/NetworkManagerSlackware.c	Wed Apr 23 20:54:30 2008 +0200
@@ -158,22 +158,6 @@
 {
 }
 
-
-/*
- * nm_system_device_replace_default_route
- *
- * Add default route to the given device
- *
- */
-void
-nm_system_device_replace_default_route (const char *iface,
-                                        guint32 gw,
-                                        guint32 mss)
-{
-	nm_generic_device_replace_default_route (iface, gw, mss);
-}
- 
- 
 /*
  * nm_system_flush_loopback_routes
  *
diff -r 44a2c48934ef src/backends/NetworkManagerSuSE.c
--- a/src/backends/NetworkManagerSuSE.c	Wed Apr 16 00:35:47 2008 -0400
+++ b/src/backends/NetworkManagerSuSE.c	Wed Apr 23 20:54:30 2008 +0200
@@ -81,21 +81,6 @@
 void nm_system_device_flush_ip4_routes_with_iface (const char *iface)
 {
 	nm_generic_device_flush_ip4_routes_with_iface (iface);
-}
-
-
-/*
- * nm_system_device_replace_default_route
- *
- * Add default route to the given device
- *
- */
-void
-nm_system_device_replace_default_route (const char *iface,
-                                        guint32 gw,
-                                        guint32 mss)
-{
-	nm_generic_device_replace_default_route (iface, gw, mss);
 }
 
 /*
-- 
:wq


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