+ 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 (type == CONNMAN_IPCONFIG_TYPE_IPV4) {
+ /*
+ * 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 (active_gateway->ipv4_gateway == NULL)
+ return;
+
+ 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);
+
+ } else if (type == CONNMAN_IPCONFIG_TYPE_IPV6) {
+
+ 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,
+ enum connman_ipconfig_type type)
+{
+ int status4 = 0, status6 = 0;
+ int 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 == TRUE && data->ipv4_gateway != NULL) {
+ if (data->ipv4_gateway->vpn == TRUE) {
+ 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 == TRUE && data->ipv6_gateway != NULL) {
+ if (data->ipv6_gateway->vpn == TRUE) {
+ 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 int disable_gateway(struct gateway_data *data,
+ enum connman_ipconfig_type type)
+{
+ gboolean active = FALSE;
+
+ if (type == CONNMAN_IPCONFIG_TYPE_IPV4) {
+ if (data->ipv4_gateway != NULL)
+ active = data->ipv4_gateway->active;
+ } else if (type == CONNMAN_IPCONFIG_TYPE_IPV6) {
+ if (data->ipv6_gateway != NULL)
+ active = data->ipv6_gateway->active;
+ } else
+ active = TRUE;
+
+ DBG("type %d active %d", type, active);
+
+ if (active == TRUE)
+ return del_routes(data, type);
+
+ return 0;
+}
+
+static struct gateway_data *add_gateway(struct connman_service *service,
+ int index, const char *gateway,
+ enum connman_ipconfig_type type)
+{
+ struct gateway_data *data, *old;
+ struct gateway_config *config;
+
+ if (gateway == NULL || strlen(gateway) == 0)