From 2fafb4669a33f5c7700babdd55bfd2f0c26dde90 Mon Sep 17 00:00:00 2001 From: Jukka Rissanen Date: Wed, 14 Mar 2012 17:28:57 +0200 Subject: connection: Check all active gateways in update There can be multiple active gateways in the system at the same time so we must check them all when updating gateway info. --- src/connection.c | 51 ++++++++++++++++++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 17 deletions(-) (limited to 'src/connection.c') diff --git a/src/connection.c b/src/connection.c index 4e7b0ab6..c7159fed 100644 --- a/src/connection.c +++ b/src/connection.c @@ -809,42 +809,59 @@ void __connman_connection_gateway_remove(struct connman_service *service, gboolean __connman_connection_update_gateway(void) { - struct gateway_data *active_gateway, *default_gateway; + struct gateway_data *default_gateway; gboolean updated = FALSE; + GHashTableIter iter; + gpointer value, key; if (gateway_hash == NULL) return updated; - active_gateway = find_active_gateway(); - update_order(); default_gateway = find_default_gateway(); - DBG("active %p default %p", active_gateway, default_gateway); + DBG("default %p", default_gateway); - if (active_gateway && active_gateway != default_gateway) { - updated = TRUE; + /* + * There can be multiple active gateways so we need to + * check them all. + */ + g_hash_table_iter_init(&iter, gateway_hash); - if (active_gateway->ipv4_gateway) - unset_default_gateway(active_gateway, - CONNMAN_IPCONFIG_TYPE_IPV4); + while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) { + struct gateway_data *active_gateway = value; - if (active_gateway->ipv6_gateway) - unset_default_gateway(active_gateway, - CONNMAN_IPCONFIG_TYPE_IPV6); + if (active_gateway == default_gateway) + continue; + + if (active_gateway->ipv4_gateway != NULL && + active_gateway->ipv4_gateway->active == TRUE) { - if (default_gateway) { - if (default_gateway->ipv4_gateway) - set_default_gateway(default_gateway, + unset_default_gateway(active_gateway, CONNMAN_IPCONFIG_TYPE_IPV4); + updated = TRUE; + } + + if (active_gateway->ipv6_gateway != NULL && + active_gateway->ipv6_gateway->active == TRUE) { - if (default_gateway->ipv6_gateway) - set_default_gateway(default_gateway, + unset_default_gateway(active_gateway, CONNMAN_IPCONFIG_TYPE_IPV6); + updated = TRUE; } } + if (updated && default_gateway != NULL) { + if (default_gateway->ipv4_gateway) + set_default_gateway(default_gateway, + CONNMAN_IPCONFIG_TYPE_IPV4); + + if (default_gateway->ipv6_gateway) + set_default_gateway(default_gateway, + CONNMAN_IPCONFIG_TYPE_IPV6); + } + return updated; } -- cgit v1.2.3