Static routes support patch for NetworkManager 0.7.0



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

With regards

Blondak


diff -bBru NetworkManager-0.7.0/src/dhcp-manager/nm-dhcp-manager.c NetworkManager-0.7.0-blondak/src/dhcp-manager/nm-dhcp-manager.c
--- NetworkManager-0.7.0/src/dhcp-manager/nm-dhcp-manager.c	2007-10-01 22:46:52.000000000 +0200
+++ NetworkManager-0.7.0-blondak/src/dhcp-manager/nm-dhcp-manager.c	2007-11-28 14:24:29.000000000 +0100
@@ -839,6 +839,7 @@
 	char *			nameservers = NULL;
 	char *			nis_domain = NULL;
 	char *			nis_servers = NULL;
+	char *			static_routes = NULL;
 	char *			ip = NULL;		//this is a general string that is used as a temporary place for ip(s)
 
 	g_return_val_if_fail (NM_IS_DHCP_MANAGER (manager), NULL);
@@ -909,7 +910,7 @@
 	domain_names = g_hash_table_lookup (device->options, "new_domain_name");
 	nis_domain = g_hash_table_lookup (device->options, "new_nis_domain");
 	nis_servers = g_hash_table_lookup (device->options, "new_nis_servers");
-
+	static_routes = g_hash_table_lookup (device->options, "new_static_routes");
 
 	if (nameservers) {
 		char **searches = g_strsplit (nameservers, " ", 0);
@@ -958,6 +959,22 @@
 		g_strfreev (searches);
 	}
 
+	if (static_routes){
+		char **searches = g_strsplit (static_routes, " ", 0);
+		char **s;
+		int ip4_address;
+		int ip4_route;
+
+		for (s = searches; *s; s=s+2) {
+			ip4_address = inet_addr (*s);
+			ip4_route = inet_addr (*(s+1));
+			nm_ip4_config_add_static_route (ip4_config, ip4_address, ip4_route);
+			nm_info ("  static route %s gw %s", *s, *(s+1));
+		}
+		g_strfreev (searches);
+//		nm_info ("  hostname '%s'", static_routes);
+	}
+
 	/*
 	 * FIXME:
 	 * Grab the MTU from the backend. If DHCP servers can send recommended
diff -bBru NetworkManager-0.7.0/src/NetworkManagerSystem.c NetworkManager-0.7.0-blondak/src/NetworkManagerSystem.c
--- NetworkManager-0.7.0/src/NetworkManagerSystem.c	2007-09-28 03:37:58.000000000 +0200
+++ NetworkManager-0.7.0-blondak/src/NetworkManagerSystem.c	2007-11-28 14:49:43.000000000 +0100
@@ -194,6 +193,8 @@
 	struct nl_handle *	nlh = NULL;
 	struct rtnl_addr *	addr = NULL;
 	int				err;
+	int		len,i;
+	guint32		saddr;
 
 	g_return_val_if_fail (dev != NULL, FALSE);
 
@@ -220,6 +221,12 @@
 	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++){
+		saddr = nm_ip4_config_get_static_route (config, i*2);
+    		nm_system_device_set_ip4_route (dev, nm_ip4_config_get_static_route(config,i*2+1), saddr, 0xffffffff, nm_ip4_config_get_mss (config));
+	}		
+
 	named_mgr = nm_named_manager_get ();
 	nm_named_manager_add_ip4_config (named_mgr, config);
 	g_object_unref (named_mgr);
diff -bBru NetworkManager-0.7.0/src/nm-ip4-config.c NetworkManager-0.7.0-blondak/src/nm-ip4-config.c
--- NetworkManager-0.7.0/src/nm-ip4-config.c	2007-09-12 03:12:13.000000000 +0200
+++ NetworkManager-0.7.0-blondak/src/nm-ip4-config.c	2007-11-28 14:37:30.000000000 +0100
@@ -55,6 +55,7 @@
 	gchar *	hostname;
 	gchar *	nis_domain;
 	GArray *nis_servers;
+	GArray *static_routes;
 
 	/* If this is a VPN/etc config that requires
 	 * another device (like Ethernet) to already have
@@ -75,6 +76,7 @@
 	PROP_DOMAINS,
 	PROP_NIS_DOMAIN,
 	PROP_NIS_SERVERS,
+	PROP_STATIC_ROUTES,
 
 	LAST_PROP
 };
@@ -105,6 +107,7 @@
 	NMIP4ConfigPrivate *priv;
 	int i;
 	int len;
+	guint32 addr;
 
 	g_return_val_if_fail (NM_IS_IP4_CONFIG (src_config), NULL);
 
@@ -131,6 +134,12 @@
 	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++){
+		addr = nm_ip4_config_get_static_route (src_config, i*2);
+		nm_ip4_config_add_static_route (dst_config, addr, nm_ip4_config_get_static_route (src_config, i*2+1));
+	}		
+
 	return dst_config;
 }
 
@@ -307,6 +316,28 @@
 	return NM_IP4_CONFIG_GET_PRIVATE (config)->nis_domain;
 }
 
+void nm_ip4_config_add_static_route (NMIP4Config *config, guint32 host, guint32 router) 
+{ 
+	g_return_if_fail (NM_IS_IP4_CONFIG (config)); 
+         
+        g_array_append_val (NM_IP4_CONFIG_GET_PRIVATE (config)->static_routes, host); 
+        g_array_append_val (NM_IP4_CONFIG_GET_PRIVATE (config)->static_routes, router); 
+} 
+                          
+guint32 nm_ip4_config_get_static_route (NMIP4Config *config, guint i) 
+{ 
+	g_return_val_if_fail (NM_IS_IP4_CONFIG (config), 0); 
+                                   
+        return g_array_index (NM_IP4_CONFIG_GET_PRIVATE (config)->static_routes, guint32, i); 
+} 
+                                            
+guint32 nm_ip4_config_get_num_static_routes (NMIP4Config *config) 
+{ 
+        g_return_val_if_fail (NM_IS_IP4_CONFIG (config), 0); 
+                                             
+	return NM_IP4_CONFIG_GET_PRIVATE (config)->static_routes->len / 2; 
+} 
+                                                             
 const char *nm_ip4_config_get_domain (NMIP4Config *config, guint i)
 {
 	g_return_val_if_fail (NM_IS_IP4_CONFIG (config), NULL);
@@ -440,6 +471,7 @@
 
 	priv->nameservers = g_array_new (FALSE, TRUE, sizeof (guint32));
 	priv->nis_servers = g_array_new (FALSE, TRUE, sizeof (guint32));
+	priv->static_routes = g_array_new (FALSE, TRUE, sizeof (guint32));
 	priv->domains = g_ptr_array_new ();
 }
 
@@ -453,6 +485,7 @@
 	g_array_free (priv->nameservers, TRUE);
 	g_ptr_array_free (priv->domains, TRUE);
 	g_array_free (priv->nis_servers, TRUE);
+	g_array_free (priv->static_routes, TRUE);
 }
 
 static void
@@ -489,6 +522,9 @@
 	case PROP_NIS_SERVERS:
 		g_value_set_boxed (value, priv->nis_servers);
 		break;
+	case PROP_STATIC_ROUTES:
+		g_value_set_boxed (value, priv->static_routes);		
+		break;
 	default:
 		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 		break;
@@ -571,6 +607,14 @@
 							 DBUS_TYPE_G_UINT_ARRAY,
 							 G_PARAM_READABLE));
 
+	g_object_class_install_property
+		(object_class, PROP_STATIC_ROUTES,
+		 g_param_spec_boxed (NM_IP4_CONFIG_STATIC_ROUTES,
+							 "Static routes",
+							 "Sattic routes",
+							 DBUS_TYPE_G_UINT_ARRAY,
+							 G_PARAM_READABLE));
+
 	dbus_g_object_type_install_info (G_TYPE_FROM_CLASS (config_class),
 									 &dbus_glib_nm_ip4_config_object_info);
 }
diff -bBru NetworkManager-0.7.0/src/nm-ip4-config.h NetworkManager-0.7.0-blondak/src/nm-ip4-config.h
--- NetworkManager-0.7.0/src/nm-ip4-config.h	2007-10-23 12:46:53.000000000 +0200
+++ NetworkManager-0.7.0-blondak/src/nm-ip4-config.h	2007-11-28 14:14:49.000000000 +0100
@@ -51,6 +51,7 @@
 #define NM_IP4_CONFIG_DOMAINS "domains"
 #define NM_IP4_CONFIG_NIS_DOMAIN "nis-domain"
 #define NM_IP4_CONFIG_NIS_SERVERS "nis-servers"
+#define NM_IP4_CONFIG_STATIC_ROUTES "static-routes"
 
 GType nm_ip4_config_get_type (void);
 
@@ -84,6 +85,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, guint32 addr, guint32 router);
+guint32		nm_ip4_config_get_static_route		(NMIP4Config *config, guint 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]