--- src/dhcp-manager/nm-dhcp-manager.c	2008-11-30 16:36:19.000000000 +0100
+++ src/dhcp-manager/nm-dhcp-manager.c	2008-11-30 18:52:00.000000000 +0100
@@ -777,21 +777,122 @@
 		nm_info ("  prefix %d (%s)", nm_ip4_address_get_prefix (addr), str);
 	}
 
-	str = g_hash_table_lookup (device->options, "new_routers");
-	if (str) {
-		char **routers = g_strsplit (str, " ", 0);
-		char **s;
+	/* Classless static routes over-ride any static routes and routers
+	 * provided. We should also check for MS classless static routes as
+	 * they implemented the draft RFC using their own code :/ */
+	str = g_hash_table_lookup (device->options, "new_classless_static_routes");
+	if (!str)
+		str = g_hash_table_lookup (device->options, "new_ms_classless_static_routes");
+	if (str) {
+		char **routes = g_strsplit (str, " ", 0);
+		routes = g_strsplit (str, " ", 0);
+		if ((g_strv_length (routes) %2) == 0) {
+			char **r;
 
-		for (s = routers; *s; s++) {
-			/* FIXME: how to handle multiple routers? */
-			if (inet_pton (AF_INET, *s, &tmp_addr) > 0) {
-				nm_ip4_address_set_gateway (addr, tmp_addr.s_addr);
-				nm_info ("  gateway %s", *s);
-				break;
-			} else
-				nm_warning ("Ignoring invalid gateway '%s'", *s);
+			for (r = routes; *r; r += 2) {
+				char *slash;
+				NMIP4Route *route;
+				int rt_cidr = 32;
+				struct in_addr rt_addr;
+				struct in_addr rt_route;
+
+				slash = strchr(*r, '/');
+				if (slash) {
+					*slash = '\0';
+					errno = 0;
+					rt_cidr = strtol (slash + 1, NULL, 10);
+					if ((errno == EINVAL) || (errno == ERANGE)) {
+						nm_warning ("DHCP provided invalid classless static route cidr: '%s'", slash + 1);
+						continue;
+					}
+				}
+				if (inet_pton (AF_INET, *r, &rt_addr) <= 0) {
+					nm_warning ("DHCP provided invalid classless static route address: '%s'", *r);
+					continue;
+				}
+				if (inet_pton (AF_INET, *(r + 1), &rt_route) <= 0) {
+					nm_warning ("DHCP provided invalid classless static route gateway: '%s'", *(r + 1));
+					continue;
+				}
+
+				if (rt_cidr == 0 && rt_addr.s_addr == 0) {
+					/* FIXME: how to handle multiple routers? */
+					if (!nm_ip4_address_get_gateway(addr)) {
+						nm_ip4_address_set_gateway (addr, rt_route.s_addr); 
+						nm_info ("  gateway %s", *(r + 1));
+					}
+				} else {
+					route = nm_ip4_route_new ();
+					nm_ip4_route_set_dest (route, (guint32) rt_addr.s_addr);
+					nm_ip4_route_set_prefix (route, rt_cidr);
+					nm_ip4_route_set_next_hop (route, (guint32) rt_route.s_addr);
+
+
+					nm_ip4_config_take_route (ip4_config, route);
+					nm_info ("  classless static route %s/%d gw %s", *r, rt_cidr, *(r + 1));
+				}
+			}
+		} else {
+			nm_info ("  classless tatic routes provided, but invalid");
+ 		}
+		g_strfreev (routes);
+	} else {
+		str = g_hash_table_lookup (device->options, "new_static_routes");
+		if (str) {
+			char **searches = g_strsplit (str, " ", 0);
+
+			nm_info ("in rout");
+			if ((g_strv_length (searches) % 2) == 0) {
+				char **s;
+
+				for (s = searches; *s; s += 2) {
+					NMIP4Route *route;
+					struct in_addr rt_addr;
+					struct in_addr rt_route;
+
+					if (inet_pton (AF_INET, *s, &rt_addr) <= 0) {
+						nm_warning ("DHCP provided invalid static route address: '%s'", *s);
+						continue;
+					}
+					if (inet_pton (AF_INET, *(s + 1), &rt_route) <= 0) {
+						nm_warning ("DHCP provided invalid static route gateway: '%s'", *(s + 1));
+						continue;
+					}
+
+					// FIXME: ensure the IP addresse and route are sane
+
+					route = nm_ip4_route_new ();
+					nm_ip4_route_set_dest (route, (guint32) rt_addr.s_addr);
+					nm_ip4_route_set_prefix (route, 32); /* 255.255.255.255 */
+					nm_ip4_route_set_next_hop (route, (guint32) rt_route.s_addr);
+
+					nm_ip4_config_take_route (ip4_config, route);
+					nm_info ("  static route %s gw %s", *s, *(s + 1));
+				}
+			} else {
+				nm_info ("  static routes provided, but invalid");
+			}
+			g_strfreev (searches);
+		}
+
+		str = g_hash_table_lookup (device->options, "new_routers");
+		if (str) {
+			char **routers = g_strsplit (str, " ", 0);
+			char **s;
+
+			for (s = routers; *s; s++) {
+				/* FIXME: how to handle multiple routers? */
+				if (inet_pton (AF_INET, *s, &tmp_addr) > 0) {
+					nm_ip4_address_set_gateway (addr, tmp_addr.s_addr); 
+					nm_info ("  gateway %s", *s);
+					break;
+				} else {
+					nm_info ("foo");
+					nm_warning ("Ignoring invalid gateway '%s'", *s);
+				}
+			}
+			g_strfreev (routers);
 		}
-		g_strfreev (routers);
 	}
 
 	nm_ip4_config_take_address (ip4_config, addr);
@@ -840,43 +941,6 @@
 		g_strfreev (searches);
 	}
 
-	str = g_hash_table_lookup (device->options, "new_static_routes");
-	if (str) {
-		char **searches = g_strsplit (str, " ", 0);
-
-		if ((g_strv_length (searches) % 2) == 0) {
-			char **s;
-
-			for (s = searches; *s; s += 2) {
-				NMIP4Route *route;
-				struct in_addr rt_addr;
-				struct in_addr rt_route;
-
-				if (inet_pton (AF_INET, *s, &rt_addr) <= 0) {
-					nm_warning ("DHCP provided invalid static route address: '%s'", *s);
-					continue;
-				}
-				if (inet_pton (AF_INET, *(s + 1), &rt_route) <= 0) {
-					nm_warning ("DHCP provided invalid static route gateway: '%s'", *(s + 1));
-					continue;
-				}
-
-				// FIXME: ensure the IP addresse and route are sane
-
-				route = nm_ip4_route_new ();
-				nm_ip4_route_set_dest (route, (guint32) rt_addr.s_addr);
-				nm_ip4_route_set_prefix (route, 32); /* 255.255.255.255 */
-				nm_ip4_route_set_next_hop (route, (guint32) rt_route.s_addr);
-
-				nm_ip4_config_take_route (ip4_config, route);
-				nm_info ("  static route %s gw %s", *s, *(s + 1));
-			}
-		} else {
-			nm_info ("  static routes provided, but invalid");
-		}
-		g_strfreev (searches);
-	}
-
 	str = g_hash_table_lookup (device->options, "new_interface_mtu");
 	if (str) {
 		int int_mtu;
