X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Fconnection.c;h=d40f4281e78ff6eb785ac64ac14f3fcef657e42e;hb=230905c20905f2bc5ccf4b8fab75c1b5df2ac31d;hp=f4abd5745d0dcc3ce658a5340334b65b5bc7accc;hpb=8b3a3c9bf51d3dd8a2605f1995da341b7caee185;p=framework%2Fconnectivity%2Fconnman.git diff --git a/src/connection.c b/src/connection.c index f4abd57..d40f428 100644 --- a/src/connection.c +++ b/src/connection.c @@ -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); + } - if (data != NULL) { + 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 (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; + + connman_inet_add_host_route(active_gateway->index, gateway, + dest); - address = __connman_ipconfig_get_local(ipconfig); - config->vpn_phy_ip = g_strdup(address); - } + } else if (type == CONNMAN_IPCONFIG_TYPE_IPV6) { - config->vpn_phy_index = data->index; - } + if (active_gateway->ipv6_gateway == NULL) + return; - DBG("vpn %s phy %s index %d", config->vpn_ip, - config->vpn_phy_ip, config->vpn_phy_index); + 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, @@ -833,30 +878,8 @@ int __connman_connection_gateway_add(struct connman_service *service, if (service_type == CONNMAN_SERVICE_TYPE_VPN) { - if (type == CONNMAN_IPCONFIG_TYPE_IPV4) { - if (new_gateway->ipv4_gateway != NULL) - set_vpn_routes(new_gateway->ipv4_gateway, - service, gateway, type, peer); - - /* - * 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. - */ - connman_inet_add_host_route(active_gateway->index, - gateway, - active_gateway->ipv4_gateway->gateway); - - } else if (type == CONNMAN_IPCONFIG_TYPE_IPV6) { - if (new_gateway->ipv6_gateway != NULL) - set_vpn_routes(new_gateway->ipv6_gateway, - service, gateway, type, peer); - - connman_inet_add_ipv6_host_route(active_gateway->index, - gateway, - active_gateway->ipv6_gateway->gateway); - } + set_vpn_routes(new_gateway, service, gateway, type, peer, + active_gateway); } else { if (type == CONNMAN_IPCONFIG_TYPE_IPV4 &&