[PATCH 1/1] Fix for 2 default gateways.

mabbasconnman at gmail.com mabbasconnman at gmail.com
Fri Apr 16 16:47:20 PDT 2010


From: Mohamed Abbas <mohamed.abbas at intel.com>

This patch fixes the issue of more than one defaut gateway showing up.
VPN gateway needs extra work to clean and set the gateway since it needs
a physical interface to set the host/gateway correctly.
---
 src/connection.c |   24 ++++++++++++++----------
 1 files changed, 14 insertions(+), 10 deletions(-)

diff --git a/src/connection.c b/src/connection.c
index 6dfb6d9..d0d59d7 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -38,6 +38,7 @@ struct gateway_data {
 	/* VPN extra data */
 	gboolean vpn;
 	char *vpn_ip;
+	int vpn_phy_index;
 };
 
 static GSList *gateway_list = NULL;
@@ -67,13 +68,15 @@ static int del_routes(struct gateway_data *data)
 {
 	const char *address;
 
-	connman_inet_del_host_route(data->index, data->gateway);
-
-	if (data->vpn)
+	if (data->vpn) {
+		if (data->vpn_phy_index >= 0)
+			connman_inet_del_host_route(data->vpn_phy_index,
+							data->gateway);
 		address = data->vpn_ip;
-	else
+	} else {
+		connman_inet_del_host_route(data->index, data->gateway);
 		address = data->gateway;
-
+	}
 	return connman_inet_clear_gateway_address(data->index, address);
 }
 
@@ -107,6 +110,7 @@ static struct gateway_data *add_gateway(int index, const char *gateway)
 	data->element = NULL;
 	data->vpn_ip = NULL;
 	data->vpn = FALSE;
+	data->vpn_phy_index = -1;
 
 	__connman_element_foreach(NULL, CONNMAN_ELEMENT_TYPE_CONNECTION,
 							find_element, data);
@@ -142,6 +146,7 @@ static void set_default_gateway(struct gateway_data *data)
 
 	if (data->vpn == TRUE) {
 		connman_inet_set_gateway_address(data->index, data->vpn_ip);
+		data->active = TRUE;
 		/* vpn gateway going away no changes in services */
 		return;
 	}
@@ -278,6 +283,8 @@ static int connection_probe(struct connman_element *element)
 		new_gateway->vpn_ip = g_strdup(vpn_ip);
 		/* make sure vpn gateway are at higher priority */
 		new_gateway->order = 10;
+		if (active_gateway)
+			new_gateway->vpn_phy_index = active_gateway->index;
 	} else
 		new_gateway->vpn = FALSE;
 
@@ -290,9 +297,6 @@ static int connection_probe(struct connman_element *element)
 		connman_inet_add_host_route_vpn(active_gateway->index,
 						active_gateway->gateway,
 						new_gateway->gateway);
-
-		connman_inet_set_gateway_address(new_gateway->index,
-							new_gateway->gateway);
 	}
 
 	if (new_gateway->order >= active_gateway->order) {
@@ -332,8 +336,8 @@ static void connection_remove(struct connman_element *element)
 
 	set_default = data->vpn;
 
-	if (data->vpn == TRUE)
-		connman_inet_del_host_route(data->index, data->gateway);
+	if (data->vpn == TRUE && data->vpn_phy_index >= 0)
+		connman_inet_del_host_route(data->vpn_phy_index, data->gateway);
 
 	remove_gateway(data);
 
-- 
1.6.1.3




More information about the connman mailing list