[PATCH v5 16/42] vpnd: Add -r option which enables route handling in vpnd

Jukka Rissanen jukka.rissanen at linux.intel.com
Mon Nov 12 04:07:32 PST 2012


By default routes are handled by connman daemon.
---
 vpn/main.c         |  5 ++++-
 vpn/vpn-provider.c | 30 ++++++++++++++++++++++++------
 vpn/vpn.h          |  2 +-
 3 files changed, 29 insertions(+), 8 deletions(-)

diff --git a/vpn/main.c b/vpn/main.c
index 35daca7..dcf3a78 100644
--- a/vpn/main.c
+++ b/vpn/main.c
@@ -126,6 +126,7 @@ static gchar *option_plugin = NULL;
 static gchar *option_noplugin = NULL;
 static gboolean option_detach = TRUE;
 static gboolean option_version = FALSE;
+static gboolean option_routes = FALSE;
 
 static gboolean parse_debug(const char *key, const char *value,
 					gpointer user_data, GError **error)
@@ -149,6 +150,8 @@ static GOptionEntry options[] = {
 	{ "nodaemon", 'n', G_OPTION_FLAG_REVERSE,
 				G_OPTION_ARG_NONE, &option_detach,
 				"Don't fork daemon to background" },
+	{ "routes", 'r', 0, G_OPTION_ARG_NONE, &option_routes,
+				"Create/delete VPN routes" },
 	{ "version", 'v', 0, G_OPTION_ARG_NONE, &option_version,
 				"Show version information and exit" },
 	{ NULL },
@@ -223,7 +226,7 @@ int main(int argc, char *argv[])
 	__connman_log_init(argv[0], option_debug, option_detach, FALSE,
 			"Connection Manager VPN daemon", VERSION);
 	__connman_dbus_init(conn);
-	__vpn_provider_init();
+	__vpn_provider_init(option_routes);
 	__vpn_manager_init();
 	__vpn_ipconfig_init();
 	__vpn_rtnl_init();
diff --git a/vpn/vpn-provider.c b/vpn/vpn-provider.c
index 5dfd010..982b280 100644
--- a/vpn/vpn-provider.c
+++ b/vpn/vpn-provider.c
@@ -46,6 +46,7 @@ static DBusConnection *connection;
 static GHashTable *provider_hash;
 static GSList *driver_list;
 static int configuration_count;
+static gboolean handle_routes;
 
 struct vpn_route {
 	int family;
@@ -316,7 +317,8 @@ static void del_routes(struct vpn_provider *provider)
 	gpointer value, key;
 
 	g_hash_table_iter_init(&hash, provider->user_routes);
-	while (g_hash_table_iter_next(&hash, &key, &value) == TRUE) {
+	while (handle_routes == TRUE && g_hash_table_iter_next(&hash,
+						&key, &value) == TRUE) {
 		struct vpn_route *route = value;
 		if (route->family == AF_INET6) {
 			unsigned char prefixlen = atoi(route->netmask);
@@ -398,8 +400,9 @@ static DBusMessage *set_property(DBusConnection *conn, DBusMessage *msg,
 			provider->user_networks = networks;
 			set_user_networks(provider, provider->user_networks);
 
-			provider_schedule_changed(provider, USER_ROUTES_CHANGED);
-			provider_property_changed(provider, name);
+			if (handle_routes == FALSE)
+				provider_schedule_changed(provider,
+							USER_ROUTES_CHANGED);
 		}
 	} else
 		return __connman_error_invalid_property(msg);
@@ -421,7 +424,8 @@ static DBusMessage *clear_property(DBusConnection *conn, DBusMessage *msg,
 	if (g_str_equal(name, "UserRoutes") == TRUE) {
 		del_routes(provider);
 
-		provider_property_changed(provider, name);
+		if (handle_routes == FALSE)
+			provider_property_changed(provider, name);
 	} else {
 		return __connman_error_invalid_property(msg);
 	}
@@ -1241,6 +1245,9 @@ static void provider_append_routes(gpointer key, gpointer value,
 	struct vpn_provider *provider = user_data;
 	int index = provider->index;
 
+	if (handle_routes == FALSE)
+		return;
+
 	/*
 	 * If the VPN administrator/user has given a route to
 	 * VPN server, then we must discard that because the
@@ -1280,7 +1287,9 @@ static int set_connected(struct vpn_provider *provider,
 			ipconfig = provider->ipconfig_ipv4;
 
 		__vpn_ipconfig_address_add(ipconfig, provider->family);
-		__vpn_ipconfig_gateway_add(ipconfig, provider->family);
+
+		if (handle_routes == TRUE)
+			__vpn_ipconfig_gateway_add(ipconfig, provider->family);
 
 		provider_indicate_state(provider,
 					VPN_PROVIDER_STATE_READY);
@@ -2004,6 +2013,13 @@ int vpn_provider_append_route(struct vpn_provider *provider,
 		break;
 	}
 
+	if (handle_routes == FALSE) {
+		if (route->netmask != NULL && route->gateway != NULL &&
+							route->network != NULL)
+			provider_schedule_changed(provider,
+						SERVER_ROUTES_CHANGED);
+	}
+
 	return 0;
 }
 
@@ -2052,10 +2068,12 @@ void vpn_provider_driver_unregister(struct vpn_provider_driver *driver)
 	driver_list = g_slist_remove(driver_list, driver);
 }
 
-int __vpn_provider_init(void)
+int __vpn_provider_init(gboolean do_routes)
 {
 	DBG("");
 
+	handle_routes = do_routes;
+
 	connection = connman_dbus_get_connection();
 
 	provider_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
diff --git a/vpn/vpn.h b/vpn/vpn.h
index 10672e0..93894d1 100644
--- a/vpn/vpn.h
+++ b/vpn/vpn.h
@@ -84,7 +84,7 @@ int __vpn_provider_connect_path(const char *path);
 int __vpn_provider_disconnect(struct vpn_provider *provider);
 int __vpn_provider_remove(const char *path);
 void __vpn_provider_cleanup(void);
-int __vpn_provider_init(void);
+int __vpn_provider_init(gboolean handle_routes);
 
 #include "vpn-rtnl.h"
 
-- 
1.7.11.4




More information about the connman mailing list