NetworkManager r3730 - in trunk/vpn-daemons/openvpn: . src



Author: dcbw
Date: Fri Jun  6 16:08:30 2008
New Revision: 3730
URL: http://svn.gnome.org/viewvc/NetworkManager?rev=3730&view=rev

Log:
2008-06-06  Dan Williams  <dcbw redhat com>

	Patch from Tambet Ingo  <tambet gmail com>

	* src/nm-openvpn-service-openvpn-helper.c
		- (main, get_routes): send routes too



Modified:
   trunk/vpn-daemons/openvpn/ChangeLog
   trunk/vpn-daemons/openvpn/src/nm-openvpn-service-openvpn-helper.c

Modified: trunk/vpn-daemons/openvpn/src/nm-openvpn-service-openvpn-helper.c
==============================================================================
--- trunk/vpn-daemons/openvpn/src/nm-openvpn-service-openvpn-helper.c	(original)
+++ trunk/vpn-daemons/openvpn/src/nm-openvpn-service-openvpn-helper.c	Fri Jun  6 16:08:30 2008
@@ -43,6 +43,10 @@
 #include "nm-openvpn-service.h"
 #include "nm-utils.h"
 
+/* These are here because nm-dbus-glib-types.h isn't exported */
+#define DBUS_TYPE_G_ARRAY_OF_UINT          (dbus_g_type_get_collection ("GArray", G_TYPE_UINT))
+#define DBUS_TYPE_G_ARRAY_OF_ARRAY_OF_UINT (dbus_g_type_get_collection ("GPtrArray", DBUS_TYPE_G_ARRAY_OF_UINT))
+
 static void
 helper_failed (DBusGConnection *connection, const char *reason)
 {
@@ -175,6 +179,66 @@
 	return value_array;
 }
 
+static GValue *
+get_routes (void)
+{
+	GValue *value = NULL;
+	GPtrArray *routes;
+	char *tmp;
+	int i;
+
+#define BUFLEN 256
+
+	routes = g_ptr_array_new ();
+
+	for (i = 1; i < 256; i++) {
+		GArray *array;
+		char buf[BUFLEN];
+		struct in_addr network;
+		struct in_addr netmask;
+		struct in_addr gateway = { 0, };
+
+		snprintf (buf, BUFLEN, "route_network_%d", i);
+		tmp = getenv (buf);
+		if (!tmp || strlen (tmp) < 1)
+			break;
+
+		if (inet_aton (tmp, &network) != 0) {
+			nm_warning ("Ignoring invalid static route address '%s'", tmp ? tmp : "NULL");
+			continue;
+		}
+
+		snprintf (buf, BUFLEN, "route_netmask_%d", i);
+		tmp = getenv (buf);
+		if (!tmp || inet_aton (tmp, &netmask) != 0) {
+			nm_warning ("Ignoring invalid static route netmask '%s'", tmp ? tmp : "NULL");
+			continue;
+		}
+
+		snprintf (buf, BUFLEN, "route_gateway_%d", i);
+		tmp = getenv (buf);
+		if (!tmp || inet_aton (tmp, &gateway) != 0) {
+			nm_warning ("Ignoring invalid static route gateway '%s'", tmp ? tmp : "NULL");
+			continue;
+		}
+
+		array = g_array_sized_new (FALSE, TRUE, sizeof (guint32), 3);
+		g_array_append_val (array, network.s_addr);
+		g_array_append_val (array, netmask.s_addr);
+		g_array_append_val (array, gateway.s_addr);
+		g_ptr_array_add (routes, array);
+	}
+
+	if (routes->len > 0) {
+		value = g_new0 (GValue, 1);
+		g_value_init (value, DBUS_TYPE_G_ARRAY_OF_ARRAY_OF_UINT);
+		g_value_take_boxed (value, routes);
+	} else
+		g_ptr_array_free (routes, TRUE);
+
+	return value;
+}
+
 int
 main (int argc, char *argv[])
 {
@@ -229,6 +293,10 @@
 	if (val)
 		g_hash_table_insert (config, NM_VPN_PLUGIN_IP4_CONFIG_NETMASK, val);
 
+	val = get_routes ();
+	if (val)
+		g_hash_table_insert (config, NM_VPN_PLUGIN_IP4_CONFIG_ROUTES, val);
+
     	/* DNS and WINS servers */
 	for (i = 1; i < 256; i++) {
 		char *env_name;



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