X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Fconnection.c;h=d40f4281e78ff6eb785ac64ac14f3fcef657e42e;hb=86cd761a6e375875ec904ea378ed61d4fc41e1b8;hp=daaea4210a0ee12d1392d5a54b34712bc64e0139;hpb=54167035198230e65aea2a4054d29ac67a7c8d60;p=framework%2Fconnectivity%2Fconnman.git diff --git a/src/connection.c b/src/connection.c index daaea42..d40f428 100644 --- a/src/connection.c +++ b/src/connection.c @@ -2,7 +2,7 @@ * * Connection Manager * - * Copyright (C) 2007-2010 Intel Corporation. All rights reserved. + * Copyright (C) 2007-2012 Intel Corporation. All rights reserved. * Copyright (C) 2011 BMW Car IT GmbH. All rights reserved. * * This program is free software; you can redistribute it and/or modify @@ -136,58 +136,103 @@ static struct gateway_data *find_phy_gateway(int index, const char *gateway) return NULL; } -static void set_vpn_routes(struct gateway_config *config, +static void set_vpn_routes(struct gateway_data *new_gateway, struct connman_service *service, const char *gateway, enum connman_ipconfig_type type, - const char *peer) + const char *peer, + struct gateway_data *active_gateway) { + struct gateway_config *config; struct gateway_data *data; struct connman_ipconfig *ipconfig; + char *dest; int index; + if (type == CONNMAN_IPCONFIG_TYPE_IPV4) { + ipconfig = __connman_service_get_ip4config(service); + config = new_gateway->ipv4_gateway; + } else if (type == CONNMAN_IPCONFIG_TYPE_IPV6) { + ipconfig = __connman_service_get_ip6config(service); + config = new_gateway->ipv6_gateway; + } else + return; + + if (config == NULL) + goto done; + config->vpn = TRUE; if (peer != NULL) config->vpn_ip = g_strdup(peer); else if (gateway != NULL) config->vpn_ip = g_strdup(gateway); + index = __connman_ipconfig_get_index(ipconfig); + data = find_phy_gateway(index, gateway); + + if (data == NULL) + goto done; + + /* + * data->service points now to original + * service that is serving the VPN link + */ if (type == CONNMAN_IPCONFIG_TYPE_IPV4) - ipconfig = __connman_service_get_ip4config(service); + ipconfig = __connman_service_get_ip4config(data->service); else if (type == CONNMAN_IPCONFIG_TYPE_IPV6) - ipconfig = __connman_service_get_ip6config(service); + ipconfig = __connman_service_get_ip6config(data->service); else return; - index = __connman_ipconfig_get_index(ipconfig); - data = find_phy_gateway(index, gateway); + if (ipconfig != NULL) { + const char *address; + + address = __connman_ipconfig_get_local(ipconfig); + config->vpn_phy_ip = g_strdup(address); + } + + config->vpn_phy_index = data->index; + + DBG("vpn %s phy %s index %d", config->vpn_ip, + config->vpn_phy_ip, config->vpn_phy_index); + +done: + if (active_gateway == NULL) + return; - if (data != NULL) { + if (type == CONNMAN_IPCONFIG_TYPE_IPV4) { /* - * data->service points now to original - * service that is serving the VPN link + * Special route to VPN server via gateway. This + * is needed so that we can access hosts behind + * the VPN. The route might already exist depending + * on network topology. */ - if (type == CONNMAN_IPCONFIG_TYPE_IPV4) - ipconfig = - __connman_service_get_ip4config(data->service); - else if (type == CONNMAN_IPCONFIG_TYPE_IPV6) - ipconfig = - __connman_service_get_ip6config(data->service); - else + if (active_gateway->ipv4_gateway == NULL) return; - if (ipconfig != NULL) { - const char *address; + if (g_strcmp0(active_gateway->ipv4_gateway->gateway, + "0.0.0.0") != 0) + dest = active_gateway->ipv4_gateway->gateway; + else + dest = NULL; - address = __connman_ipconfig_get_local(ipconfig); - config->vpn_phy_ip = g_strdup(address); - } + connman_inet_add_host_route(active_gateway->index, gateway, + dest); - config->vpn_phy_index = data->index; - } + } else if (type == CONNMAN_IPCONFIG_TYPE_IPV6) { - DBG("vpn %s phy %s index %d", config->vpn_ip, - config->vpn_phy_ip, config->vpn_phy_index); + if (active_gateway->ipv6_gateway == NULL) + return; + + if (g_strcmp0(active_gateway->ipv6_gateway->gateway, + "::") != 0) + dest = active_gateway->ipv6_gateway->gateway; + else + dest = NULL; + + connman_inet_add_ipv6_host_route(active_gateway->index, + gateway, dest); + } } static int del_routes(struct gateway_data *data, @@ -360,6 +405,8 @@ static void set_default_gateway(struct gateway_data *data, data->ipv4_gateway->vpn == TRUE) { connman_inet_set_gateway_address(data->index, data->ipv4_gateway->vpn_ip); + connman_inet_add_host_route(data->index, + data->ipv4_gateway->vpn_ip, NULL); data->ipv4_gateway->active = TRUE; DBG("set %p index %d vpn %s index %d phy %s", @@ -376,6 +423,8 @@ static void set_default_gateway(struct gateway_data *data, data->ipv6_gateway->vpn == TRUE) { connman_inet_set_ipv6_gateway_address(data->index, data->ipv6_gateway->vpn_ip); + connman_inet_add_ipv6_host_route(data->index, + data->ipv6_gateway->vpn_ip, NULL); data->ipv6_gateway->active = TRUE; DBG("set %p index %d vpn %s index %d phy %s", @@ -725,6 +774,54 @@ void __connman_connection_gateway_activate(struct connman_service *service, data->ipv6_gateway->active = TRUE; } +static void add_host_route(int family, int index, const char *gateway, + enum connman_service_type service_type) +{ + switch (family) { + case AF_INET: + if (g_strcmp0(gateway, "0.0.0.0") != 0) { + /* + * We must not set route to the phy dev gateway in + * VPN link. The packets to VPN link might be routed + * back to itself and not routed into phy link gateway. + */ + if (service_type != CONNMAN_SERVICE_TYPE_VPN) + connman_inet_add_host_route(index, gateway, + NULL); + } else { + /* + * Add host route to P-t-P link so that services can + * be moved around and we can have some link to P-t-P + * network (although those P-t-P links have limited + * usage if default route is not directed to them) + */ + char *dest; + if (connman_inet_get_dest_addr(index, &dest) == 0) { + connman_inet_add_host_route(index, dest, NULL); + g_free(dest); + } + } + break; + + case AF_INET6: + if (g_strcmp0(gateway, "::") != 0) { + if (service_type != CONNMAN_SERVICE_TYPE_VPN) + connman_inet_add_ipv6_host_route(index, + gateway, NULL); + } else { + /* P-t-P link, add route to destination */ + char *dest; + if (connman_inet_ipv6_get_dest_addr(index, + &dest) == 0) { + connman_inet_add_ipv6_host_route(index, dest, + NULL); + g_free(dest); + } + } + break; + } +} + int __connman_connection_gateway_add(struct connman_service *service, const char *gateway, enum connman_ipconfig_type type, @@ -734,6 +831,8 @@ int __connman_connection_gateway_add(struct connman_service *service, struct gateway_data *new_gateway = NULL; enum connman_ipconfig_type type4 = CONNMAN_IPCONFIG_TYPE_UNKNOWN, type6 = CONNMAN_IPCONFIG_TYPE_UNKNOWN; + enum connman_service_type service_type = + connman_service_get_type(service); int index; index = __connman_service_get_index(service); @@ -761,24 +860,9 @@ int __connman_connection_gateway_add(struct connman_service *service, DBG("active %p index %d new %p", active_gateway, active_gateway ? active_gateway->index : -1, new_gateway); - if (type == CONNMAN_IPCONFIG_TYPE_IPV6 && - new_gateway->ipv6_gateway != NULL && - g_strcmp0(new_gateway->ipv6_gateway->gateway, - "::") != 0) - connman_inet_add_ipv6_host_route(index, - new_gateway->ipv6_gateway->gateway, - NULL); - - if (type == CONNMAN_IPCONFIG_TYPE_IPV4 && - new_gateway->ipv4_gateway != NULL && - g_strcmp0(new_gateway->ipv4_gateway->gateway, - "0.0.0.0") != 0) - connman_inet_add_host_route(index, - new_gateway->ipv4_gateway->gateway, - NULL); - if (type == CONNMAN_IPCONFIG_TYPE_IPV4 && new_gateway->ipv4_gateway != NULL) { + add_host_route(AF_INET, index, gateway, service_type); __connman_service_nameserver_add_routes(service, new_gateway->ipv4_gateway->gateway); type4 = CONNMAN_IPCONFIG_TYPE_IPV4; @@ -786,21 +870,16 @@ int __connman_connection_gateway_add(struct connman_service *service, if (type == CONNMAN_IPCONFIG_TYPE_IPV6 && new_gateway->ipv6_gateway != NULL) { + add_host_route(AF_INET6, index, gateway, service_type); __connman_service_nameserver_add_routes(service, new_gateway->ipv6_gateway->gateway); type6 = CONNMAN_IPCONFIG_TYPE_IPV6; } - if (connman_service_get_type(service) == CONNMAN_SERVICE_TYPE_VPN) { - if (type == CONNMAN_IPCONFIG_TYPE_IPV4 && - new_gateway->ipv4_gateway != NULL) - set_vpn_routes(new_gateway->ipv4_gateway, - service, gateway, type, peer); + if (service_type == CONNMAN_SERVICE_TYPE_VPN) { - else if (type == CONNMAN_IPCONFIG_TYPE_IPV6 && - new_gateway->ipv6_gateway != NULL) - set_vpn_routes(new_gateway->ipv6_gateway, - service, gateway, type, peer); + set_vpn_routes(new_gateway, service, gateway, type, peer, + active_gateway); } else { if (type == CONNMAN_IPCONFIG_TYPE_IPV4 && @@ -820,14 +899,20 @@ int __connman_connection_gateway_add(struct connman_service *service, if (type == CONNMAN_IPCONFIG_TYPE_IPV4 && new_gateway->ipv4_gateway != NULL && new_gateway->ipv4_gateway->vpn == TRUE) { - connman_inet_clear_gateway_address(active_gateway->index, + if (__connman_service_is_split_routing(new_gateway->service) == + FALSE) + connman_inet_clear_gateway_address( + active_gateway->index, active_gateway->ipv4_gateway->gateway); } if (type == CONNMAN_IPCONFIG_TYPE_IPV6 && new_gateway->ipv6_gateway != NULL && new_gateway->ipv6_gateway->vpn == TRUE) { - connman_inet_clear_ipv6_gateway_address(active_gateway->index, + if (__connman_service_is_split_routing(new_gateway->service) == + FALSE) + connman_inet_clear_ipv6_gateway_address( + active_gateway->index, active_gateway->ipv6_gateway->gateway); } @@ -933,6 +1018,8 @@ gboolean __connman_connection_update_gateway(void) default_gateway = find_default_gateway(); + __connman_service_update_ordering(); + DBG("default %p", default_gateway); /* @@ -977,6 +1064,28 @@ gboolean __connman_connection_update_gateway(void) return updated; } +int __connman_connection_get_vpn_index(int phy_index) +{ + GHashTableIter iter; + gpointer value, key; + + g_hash_table_iter_init(&iter, gateway_hash); + + while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) { + struct gateway_data *data = value; + + if (data->ipv4_gateway != NULL && + data->ipv4_gateway->vpn_phy_index == phy_index) + return data->index; + + if (data->ipv6_gateway != NULL && + data->ipv6_gateway->vpn_phy_index == phy_index) + return data->index; + } + + return -1; +} + int __connman_connection_init(void) { int err;