NetworkManager static-routes support patch

2007-06-07 Thread Blonďák
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.0 +0200
+++ NetworkManager-0.6.5-blondak/src/dhcp-manager/nm-dhcp-manager.c	2007-06-07 14:48:43.0 +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 = 0x0;
+		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.0 +0200
+++ NetworkManager-0.6.5-blondak/src/NetworkManagerSystem.c	2007-06-07 13:42:41.0 +0200
@@ -294,6 +294,8 @@
 	struct nl_handle *	nlh = NULL;
 	struct rtnl_addr *	addr = NULL;
 	interr;
+	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.0 +0200
+++ NetworkManager-0.6.5-blondak/src/nm-ip4-config.c	2007-06-07 13:41:12.0 +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 

Re: NetworkManager static-routes support patch

2007-06-07 Thread Dan Williams
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 0x?

- 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

___
NetworkManager-list mailing list
NetworkManager-list@gnome.org
http://mail.gnome.org/mailman/listinfo/networkmanager-list


Re: NetworkManager static-routes support patch

2007-06-07 Thread Dan Williams
On Thu, 2007-06-07 at 13:13 -0400, Derek Atkins wrote:
 Quoting Dan Williams [EMAIL PROTECTED]:
 
  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 0x?
 
 -host routes do. -net routes do not.

So would the patch need to do additional checking for the routes
returned by the DHCP server to determine whether the last bit is 0 or
something?  If so, what netmask would be used instead?

Dan

 
 -derek
 

___
NetworkManager-list mailing list
NetworkManager-list@gnome.org
http://mail.gnome.org/mailman/listinfo/networkmanager-list


Re: NetworkManager static-routes support patch

2007-06-07 Thread Derek Atkins
Quoting Dan Williams [EMAIL PROTECTED]:

  - do static routes -always- have a netmask of 0x?

 -host routes do. -net routes do not.

 So would the patch need to do additional checking for the routes
 returned by the DHCP server to determine whether the last bit is 0 or
 something?  If so, what netmask would be used instead?

I'm afraid I didn't look at the patch, but how does a static route
have anything to do with DHCP?  (Maybe I'd understand if I looked
at the patch)..  Generally when I think of static routes I think
I know how to get to host X or net Y/Z -- so if it's a static
host route I only need to know the host address, and if it's a static
network route I need the network and netmask.  These numbers would
need to be part of the static route configuration.

 Dan

-derek

-- 
   Derek Atkins, SB '93 MIT EE, SM '95 MIT Media Laboratory
   Member, MIT Student Information Processing Board  (SIPB)
   URL: http://web.mit.edu/warlord/PP-ASEL-IA N1NWH
   [EMAIL PROTECTED]PGP key available

___
NetworkManager-list mailing list
NetworkManager-list@gnome.org
http://mail.gnome.org/mailman/listinfo/networkmanager-list


Re: NetworkManager static-routes support patch

2007-06-07 Thread Dan Williams
On Thu, 2007-06-07 at 13:23 -0400, Derek Atkins wrote:
 Quoting Dan Williams [EMAIL PROTECTED]:
 
   - do static routes -always- have a netmask of 0x?
 
  -host routes do. -net routes do not.
 
  So would the patch need to do additional checking for the routes
  returned by the DHCP server to determine whether the last bit is 0 or
  something?  If so, what netmask would be used instead?
 
 I'm afraid I didn't look at the patch, but how does a static route
 have anything to do with DHCP?  (Maybe I'd understand if I looked

The DHCP server can push static routes out the client just like it can
push DNS servers or YP servers, I think.

Dan

 at the patch)..  Generally when I think of static routes I think
 I know how to get to host X or net Y/Z -- so if it's a static
 host route I only need to know the host address, and if it's a static
 network route I need the network and netmask.  These numbers would
 need to be part of the static route configuration.
 
  Dan
 
 -derek
 

___
NetworkManager-list mailing list
NetworkManager-list@gnome.org
http://mail.gnome.org/mailman/listinfo/networkmanager-list