static void free_wispr_routes(struct connman_wispr_portal_context *wp_context) { while (wp_context->route_list) { struct wispr_route *route = wp_context->route_list->data; DBG("free route to %s if %d type %d", route->address, route->if_index, wp_context->type); switch (wp_context->type) { case CONNMAN_IPCONFIG_TYPE_IPV4: connman_inet_del_host_route(route->if_index, route->address); break; case CONNMAN_IPCONFIG_TYPE_IPV6: connman_inet_del_ipv6_host_route(route->if_index, route->address); break; case CONNMAN_IPCONFIG_TYPE_UNKNOWN: case CONNMAN_IPCONFIG_TYPE_ALL: break; } g_free(route->address); g_free(route); wp_context->route_list = g_slist_delete_link(wp_context->route_list, wp_context->route_list); } }
static int del_routes(struct gateway_data *data, enum connman_ipconfig_type type) { int status4 = 0, status6 = 0; bool do_ipv4 = false, do_ipv6 = false; if (type == CONNMAN_IPCONFIG_TYPE_IPV4) do_ipv4 = true; else if (type == CONNMAN_IPCONFIG_TYPE_IPV6) do_ipv6 = true; else do_ipv4 = do_ipv6 = true; if (do_ipv4 && data->ipv4_gateway) { if (data->ipv4_gateway->vpn) { status4 = connman_inet_clear_gateway_address( data->index, data->ipv4_gateway->vpn_ip); } else if (g_strcmp0(data->ipv4_gateway->gateway, "0.0.0.0") == 0) { status4 = connman_inet_clear_gateway_interface( data->index); } else { connman_inet_del_host_route(data->index, data->ipv4_gateway->gateway); status4 = connman_inet_clear_gateway_address( data->index, data->ipv4_gateway->gateway); } } if (do_ipv6 && data->ipv6_gateway) { if (data->ipv6_gateway->vpn) { status6 = connman_inet_clear_ipv6_gateway_address( data->index, data->ipv6_gateway->vpn_ip); } else if (g_strcmp0(data->ipv6_gateway->gateway, "::") == 0) { status6 = connman_inet_clear_ipv6_gateway_interface( data->index); } else { connman_inet_del_ipv6_host_route(data->index, data->ipv6_gateway->gateway); status6 = connman_inet_clear_ipv6_gateway_address( data->index, data->ipv6_gateway->gateway); } } return (status4 < 0 ? status4 : status6); }
static void del_routes(struct vpn_provider *provider) { GHashTableIter hash; gpointer value, key; g_hash_table_iter_init(&hash, provider->user_routes); 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); connman_inet_del_ipv6_network_route(provider->index, route->network, prefixlen); } else connman_inet_del_host_route(provider->index, route->network); } g_hash_table_remove_all(provider->user_routes); g_slist_free_full(provider->user_networks, free_route); provider->user_networks = NULL; }
void __connman_connection_gateway_remove(struct connman_service *service, enum connman_ipconfig_type type) { struct gateway_data *data = NULL; bool set_default4 = false, set_default6 = false; bool do_ipv4 = false, do_ipv6 = false; int err; DBG("service %p type %d", service, type); if (type == CONNMAN_IPCONFIG_TYPE_IPV4) do_ipv4 = true; else if (type == CONNMAN_IPCONFIG_TYPE_IPV6) do_ipv6 = true; else do_ipv4 = do_ipv6 = true; __connman_service_nameserver_del_routes(service, type); data = g_hash_table_lookup(gateway_hash, service); if (!data) return; if (do_ipv4 && data->ipv4_gateway) set_default4 = data->ipv4_gateway->vpn; if (do_ipv6 && data->ipv6_gateway) set_default6 = data->ipv6_gateway->vpn; DBG("ipv4 gateway %s ipv6 gateway %s vpn %d/%d", data->ipv4_gateway ? data->ipv4_gateway->gateway : "<null>", data->ipv6_gateway ? data->ipv6_gateway->gateway : "<null>", set_default4, set_default6); if (do_ipv4 && data->ipv4_gateway && data->ipv4_gateway->vpn && data->index >= 0) connman_inet_del_host_route(data->index, data->ipv4_gateway->gateway); if (do_ipv6 && data->ipv6_gateway && data->ipv6_gateway->vpn && data->index >= 0) connman_inet_del_ipv6_host_route(data->index, data->ipv6_gateway->gateway); err = disable_gateway(data, type); /* * We remove the service from the hash only if all the gateway * settings are to be removed. */ if (do_ipv4 == do_ipv6 || (data->ipv4_gateway && !data->ipv6_gateway && do_ipv4) || (data->ipv6_gateway && !data->ipv4_gateway && do_ipv6) ) { connman_service_unref(service); g_hash_table_remove(gateway_hash, service); } else DBG("Not yet removing gw ipv4 %p/%d ipv6 %p/%d", data->ipv4_gateway, do_ipv4, data->ipv6_gateway, do_ipv6); /* with vpn this will be called after the network was deleted, * we need to call set_default here because we will not recieve any * gateway delete notification. * We hit the same issue if remove_gateway() fails. */ if (set_default4 || set_default6 || err < 0) { data = find_default_gateway(); if (data) set_default_gateway(data, type); } }