We have problem having VPN work on a networks dont have gateway
server like some 3G card. To have VPN work we need to add the VPN
server ip as a host in the active network.
---
 src/connection.c |   26 ++++++++++++++++++++------
 1 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/src/connection.c b/src/connection.c
index 8ca1f7a..509a441 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -42,6 +42,7 @@ struct gateway_data {
        gboolean vpn;
        char *vpn_ip;
        int vpn_phy_index;
+       char *vpn_phy_ipv4_gateway;
 };
 
 static GHashTable *gateway_hash = NULL;
@@ -110,6 +111,7 @@ static struct gateway_data *add_gateway(struct 
connman_service *service,
        data->ipv6_gateway = g_strdup(ipv6_gateway);
        data->active = FALSE;
        data->vpn_ip = NULL;
+       data->vpn_phy_ipv4_gateway = NULL;
        data->vpn = FALSE;
        data->vpn_phy_index = -1;
        data->service = service;
@@ -141,8 +143,14 @@ static void set_default_gateway(struct gateway_data *data)
        DBG("gateway %s", data->ipv4_gateway);
 
        if (data->vpn == TRUE) {
+
                connman_inet_set_gateway_address(data->index,
                                                        data->vpn_ip);
+
+               connman_inet_add_host_route(data->vpn_phy_index,
+                                               data->vpn_ip,
+                                               data->vpn_phy_ipv4_gateway);
+
                data->active = TRUE;
 
                __connman_service_indicate_default(data->service);
@@ -204,6 +212,7 @@ static void remove_gateway(gpointer user_data)
        g_free(data->ipv4_gateway);
        g_free(data->ipv6_gateway);
        g_free(data->vpn_ip);
+       g_free(data->vpn_phy_ipv4_gateway);
        g_free(data);
 }
 
@@ -316,8 +325,17 @@ int __connman_connection_gateway_add(struct 
connman_service *service,
                else
                        new_gateway->vpn_ip = g_strdup(ipv6_gateway);
 
-               if (active_gateway)
+               if (active_gateway) {
+                       if (active_gateway->ipv4_gateway != NULL &&
+                                       g_strcmp0(active_gateway->ipv4_gateway,
+                                                               "0.0.0.0") != 0)
+                               new_gateway->vpn_phy_ipv4_gateway = g_strdup(
+                                               active_gateway->ipv4_gateway);
+                       else
+                               new_gateway->vpn_phy_ipv4_gateway = NULL;
+
                        new_gateway->vpn_phy_index = active_gateway->index;
+               }
        } else {
                new_gateway->vpn = FALSE;
        }
@@ -327,13 +345,9 @@ int __connman_connection_gateway_add(struct 
connman_service *service,
                return 0;
        }
 
-       if (new_gateway->vpn == TRUE) {
-               connman_inet_add_host_route(active_gateway->index,
-                                               new_gateway->ipv4_gateway,
-                                               active_gateway->ipv4_gateway);
+       if (new_gateway->vpn == TRUE)
                connman_inet_clear_gateway_address(active_gateway->index,
                                                active_gateway->ipv4_gateway);
-       }
 
        return 0;
 }
-- 
1.7.3.4

_______________________________________________
connman mailing list
[email protected]
http://lists.connman.net/listinfo/connman

Reply via email to