NetworkManager static-routes support patch



Hi, 
i wrote patch for NetworkManager for support static-routes from DHCP
(033).

With regards

Blondak


diff -ru NetworkManager-0.6.5/src/dhcp-manager/nm-dhcp-manager.c NetworkManager-0.6.5-blondak/src/dhcp-manager/nm-dhcp-manager.c
--- NetworkManager-0.6.5/src/dhcp-manager/nm-dhcp-manager.c	2007-04-18 20:13:04.000000000 +0200
+++ NetworkManager-0.6.5-blondak/src/dhcp-manager/nm-dhcp-manager.c	2007-06-07 14:48:43.000000000 +0200
@@ -468,13 +468,17 @@
 	guint32 *		ip4_broadcast = NULL;
 	guint32 *		ip4_nameservers = NULL;
 	guint32 *		ip4_gateway = NULL;
+	guint32		num_ip4_static_routes = 0;
 	guint32		num_ip4_nameservers = 0;
 	guint32		num_ip4_nis_servers = 0;
 	char *		hostname = NULL;
 	char *		domain_names = NULL;
 	char *		nis_domain = NULL;
 	guint32 *		ip4_nis_servers = NULL;
+	guint32 *		ip4_static_routes = NULL;
+	char * test = NULL;
 	struct in_addr	temp_addr;
+	struct NMIP4Route *	temp_route;
 	nm_completion_args	args;
 
 	g_return_val_if_fail (manager != NULL, NULL);
@@ -520,6 +524,7 @@
 	get_ip4_string (manager, dev, "domain_name", &domain_names, TRUE);
 	get_ip4_string (manager, dev, "nis_domain", &nis_domain, TRUE);
 	get_ip4_uint32s (manager, dev, "nis_servers", &ip4_nis_servers, &num_ip4_nis_servers, TRUE);
+	get_ip4_uint32s (manager, dev, "static_routes", &ip4_static_routes, &num_ip4_static_routes, TRUE);
 
 	nm_info ("Retrieved the following IP4 configuration from the DHCP daemon:");
 
@@ -579,6 +584,16 @@
 		nm_info ("  nis server %s", inet_ntoa (temp_addr));
 	}
 
+	for (i = 0; i < num_ip4_static_routes / 2;i++)
+	{
+		temp_route = g_malloc0 (sizeof (NMIP4Route));
+		(*temp_route).host.s_addr = ip4_static_routes[(i*2)];
+		(*temp_route).gw.s_addr =  ip4_static_routes[((i*2)+1)];
+		(*temp_route).mask.s_addr = 0x0ffffffff;
+		nm_ip4_config_add_static_route (ip4_config, temp_route);
+		nm_info ("  static route %s gw %s", inet_ntoa((*temp_route).host), inet_ntoa((*temp_route).gw));
+	}
+
 	/*
 	 * Grab the MTU from the backend.  If DHCP servers can send recommended MTU's,
 	 * should set that here if the backend returns zero.
diff -ru NetworkManager-0.6.5/src/NetworkManagerSystem.c NetworkManager-0.6.5-blondak/src/NetworkManagerSystem.c
--- NetworkManager-0.6.5/src/NetworkManagerSystem.c	2007-04-18 20:13:06.000000000 +0200
+++ NetworkManager-0.6.5-blondak/src/NetworkManagerSystem.c	2007-06-07 13:42:41.000000000 +0200
@@ -294,6 +294,8 @@
 	struct nl_handle *	nlh = NULL;
 	struct rtnl_addr *	addr = NULL;
 	int				err;
+	int 			i,len;
+	struct NMIP4Route * 	static_route;
 
 	g_return_val_if_fail (dev != NULL, FALSE);
 
@@ -326,6 +328,14 @@
 	sleep (1);
 	nm_system_device_set_ip4_route (dev, nm_ip4_config_get_gateway (config), 0, 0, nm_ip4_config_get_mss (config));
 
+	len = nm_ip4_config_get_num_static_routes (config);
+	for (i =0; i < len; i++)
+	{
+		static_route = nm_ip4_config_get_static_route (config, i);
+		if (static_route != NULL)
+		    nm_system_device_set_ip4_route (dev, (*static_route).gw.s_addr, (*static_route).host.s_addr, (*static_route).mask.s_addr, nm_ip4_config_get_mss (config));
+	}
+
 	nm_named_manager_add_ip4_config (app_data->named_manager, config);
 
 	return TRUE;
diff -ru NetworkManager-0.6.5/src/nm-ip4-config.c NetworkManager-0.6.5-blondak/src/nm-ip4-config.c
--- NetworkManager-0.6.5/src/nm-ip4-config.c	2007-04-18 20:13:06.000000000 +0200
+++ NetworkManager-0.6.5-blondak/src/nm-ip4-config.c	2007-06-07 13:41:12.000000000 +0200
@@ -50,6 +50,7 @@
 	gchar *	hostname;
 	gchar *	nis_domain;
 	GSList *	nis_servers;
+	GSList * static_routes;
 
 	/* If this is a VPN/etc config that requires
 	 * another device (like Ethernet) to already have
@@ -99,6 +100,10 @@
 	for (i = 0; i < len; i++)
 		nm_ip4_config_add_nis_server (dst_config, nm_ip4_config_get_nis_server (src_config, i));
 
+	len = nm_ip4_config_get_num_static_routes (src_config);
+	for (i =0; i < len; i++)
+		nm_ip4_config_add_static_route (dst_config, nm_ip4_config_get_static_route (src_config, i));
+
 	return dst_config;
 }
 
@@ -264,6 +269,33 @@
 	return (g_slist_length (config->nis_servers));
 }
 
+void nm_ip4_config_add_static_route (NMIP4Config *config, NMIP4Route *static_route)
+{
+    g_return_if_fail ( config != NULL);
+    g_return_if_fail ( static_route != NULL);
+    
+    config->static_routes = g_slist_append (config->static_routes, static_route );
+}
+
+NMIP4Route * nm_ip4_config_get_static_route (NMIP4Config *config, guint32 i)
+{
+    NMIP4Route* static_route;
+    
+    g_return_val_if_fail (config != NULL, NULL);
+    g_return_val_if_fail (i < g_slist_length (config->static_routes), NULL);
+    
+    static_route = g_slist_nth_data (config->static_routes,i);
+    
+    return static_route;
+}
+
+guint32 nm_ip4_config_get_num_static_routes (NMIP4Config *config)
+{
+    g_return_val_if_fail (config != NULL, 0);
+    
+    return (g_slist_length (config->static_routes));
+}
+
 void nm_ip4_config_add_domain (NMIP4Config *config, const char *domain)
 {
 	g_return_if_fail (config != NULL);
diff -ru NetworkManager-0.6.5/src/nm-ip4-config.h NetworkManager-0.6.5-blondak/src/nm-ip4-config.h
--- NetworkManager-0.6.5/src/nm-ip4-config.h	2007-04-18 20:13:06.000000000 +0200
+++ NetworkManager-0.6.5-blondak/src/nm-ip4-config.h	2007-06-07 13:22:13.000000000 +0200
@@ -23,6 +23,14 @@
 #define NM_IP4_CONFIG_H
 
 #include <glib.h>
+#include <netinet/in.h>
+typedef struct NMIP4Route  NMIP4Route;
+struct NMIP4Route
+{
+    struct in_addr	host;
+    struct in_addr	mask;
+    struct in_addr	gw;
+};
 
 typedef struct NMIP4Config NMIP4Config;
 
@@ -58,6 +66,10 @@
 guint32		nm_ip4_config_get_nis_server		(NMIP4Config *config, guint i);
 guint32		nm_ip4_config_get_num_nis_servers	(NMIP4Config *config);
 
+void			nm_ip4_config_add_static_route		(NMIP4Config *config, NMIP4Route *route);
+NMIP4Route *	nm_ip4_config_get_static_route		(NMIP4Config *config, guint32 i);
+guint32		nm_ip4_config_get_num_static_routes	(NMIP4Config *config);
+
 void			nm_ip4_config_set_hostname		(NMIP4Config *config, const char *hostname);
 const char * 	nm_ip4_config_get_hostname		(NMIP4Config *config);
 

Attachment: signature.asc
Description: Toto je =?UTF-8?Q?digit=C3=A1ln=C4=9B?= =?ISO-8859-1?Q?_podepsan=E1?= =?UTF-8?Q?_=C4=8D=C3=A1st?= =?ISO-8859-1?Q?_zpr=E1vy?=



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