Re: NetworkManager static-routes support patch



Hi, 
i have finally 100% working patch (include info in log) ;)

Dan Williams píše v Po 11. 06. 2007 v 21:57 -0400:
> On Fri, 2007-06-08 at 09:36 +0200, Blonďák wrote:
> > Hi,
> > after small fix it works, here is working version, but i have small
> > question.
> > Don't you have idea why this doesn't work?
> > 
> > nm_info ("  static route %s gw %s", inet_ntoa(temp_route.host),
> > inet_ntoa(temp_route.gw));
> > 
> > it output host IP address twice instead of host and gw ip address, code
> > bellow works without problem.
> > 
> > nm_info ("  static route %s", inet_ntoa(temp_route.host));
> > nm_info ("            gw %s", inet_ntoa(temp_route.gw));
> 
> Probably because inet_ntoa() uses a static buffer, and compiler
> instruction ordering may not guarantee what gets called when within the
> same statement, because neither of those really have side-effects.  Just
> a guess.
> 
> You should probably use inet_ntop() instead here, with two different
> static buffers, one for the host and one for the gw.  Something like the
> following would probably do it better:
> 
> -------------------------------
> 
> #define BUFSIZE 50
> char buf1[BUFSIZE];
> char buf2[BUFSIZE];
> char * ret;
> struct in_addr addr;
> 
> addr.s_addr = temp_route.host;
> ret = inet_ntop (AF_INET, &addr, &buf1, BUFSIZE);
> if (!ret)
>     goto error;
> 
> addr.s_addr = temp_route.gw;
> ret = inet_ntop (AF_INET, &addr, &buf2, BUFSIZE);
> if (!ret)
>     goto error;
> 
> nm_info ("  static route %s gw %s", buf1, buf2);
> 
> ------------------------------
> 
> Dan
> 
> > 
> > with regards
> > 
> > Blondak
> > 
> > Dan Williams píše v Čt 07. 06. 2007 v 16:29 -0400:
> > > On Thu, 2007-06-07 at 22:17 +0200, Blonďák wrote:
> > > > I update the patch code using your comments, but i am not able test it
> > > > right now, i will test it tomorrow.
> > > 
> > > Looks better, thanks.  Let me know if the test works and then I'll be
> > > happy to apply it.
> > > 
> > > Thanks,
> > > Dan
> > > 
> > > > Blondak
> > > > 
> > > > 
> > > > Dan Williams píše v Čt 07. 06. 2007 v 13:01 -0400:
> > > > > On Thu, 2007-06-07 at 15:12 +0200, Blonďák wrote:
> > > > > > Hi, 
> > > > > > i wrote patch for NetworkManager for support static-routes from DHCP
> > > > > > (033).
> > > > > 
> > > > > Nice!  A few comments...
> > > > > 
> > > > > - instead of doing "(*temp_route).host", just use "temp_route->host".
> > > > > That shows up in a few places.
> > > > > 
> > > > > - do static routes -always- have a netmask of 0xffffffff?
> > > > > 
> > > > > - I'd prefer to have the nm_ip4_config_add_static_route() function
> > > > > _copy_ the NMIP4Route structure and append it to the list.  The
> > > > > NMIP4Config should also free any NMIP4Route structures that it has
> > > > > references to when it is destroyed.  Once you've done this don't forget
> > > > > to free the malloc-ed NMIP4Route structure too.  Also please check for a
> > > > > NULL return value after the malloc and print out a warning and break out
> > > > > of the for() loop.  Should also check for NULL return from the g_malloc0
> > > > > when you add that to nm_ip4_config_add_static_route and return.
> > > > > 
> > > > > - There are some spaces after the ( in nm_ip4_config_add_static_route():
> > > > > +    g_return_if_fail ( config != NULL);
> > > > > 
> > > > > Thanks!
> > > > > Dan
> > > > > 
> > > > > > With regards
> > > > > > 
> > > > > > Blondak
> > > > > > 
> > > > > > 
> > > > > > _______________________________________________
> > > > > > NetworkManager-list mailing list
> > > > > > NetworkManager-list gnome org
> > > > > > http://mail.gnome.org/mailman/listinfo/networkmanager-list
> > > > > 
> > > 
> 
diff -bBru 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-12 15:53:15.000000000 +0200
@@ -468,13 +468,18 @@
 	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;
 	struct in_addr	temp_addr;
+	struct NMIP4Route 	temp_route;
+	char 	temp_char_host[INET_ADDRSTRLEN];
+	char	temp_char_gw[INET_ADDRSTRLEN];
 	nm_completion_args	args;
 
 	g_return_val_if_fail (manager != NULL, NULL);
@@ -520,6 +525,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 +585,19 @@
 		nm_info ("  nis server %s", inet_ntoa (temp_addr));
 	}
 
+	for (i = 0; i < num_ip4_static_routes / 2;i++)
+	{
+		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);
+		if ( inet_ntop(AF_INET, &temp_route.host, &temp_char_host,INET_ADDRSTRLEN) && inet_ntop(AF_INET, &temp_route.gw  , &temp_char_gw  ,INET_ADDRSTRLEN))
+		    nm_info ("  static route %s gw %s", temp_char_host, temp_char_gw);
+		else
+		    nm_warning ("  Cannot convert addresses for display");
+		    
+	}
+
 	/*
 	 * Grab the MTU from the backend.  If DHCP servers can send recommended MTU's,
 	 * should set that here if the backend returns zero.
diff -bBru 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 21:59:06.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 -bBru 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-08 09:10:36.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;
 }
 
@@ -122,6 +127,8 @@
 		g_slist_foreach (config->domains, (GFunc) g_free, NULL);
 		g_slist_free (config->domains);
 		g_slist_free (config->nis_servers);
+		g_slist_foreach (config->static_routes, (GFunc) g_free, NULL);
+		g_slist_free (config->static_routes);
 
 		memset (config, 0, sizeof (NMIP4Config));
 		g_free (config);
@@ -264,6 +271,36 @@
 	return (g_slist_length (config->nis_servers));
 }
 
+void nm_ip4_config_add_static_route (NMIP4Config *config, NMIP4Route route)
+{
+    struct NMIP4Route* static_route = g_memdup(&route, sizeof (NMIP4Route));
+    g_return_if_fail ( config != NULL);
+    g_return_if_fail ( static_route != NULL);
+    if ( (static_route->host.s_addr == 0) || (static_route->mask.s_addr != 0x0ffffffff) || (static_route->gw.s_addr == 0) )
+	return;
+    
+    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 -bBru 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 21:50:46.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]