vpn: add device route to VPN gateway if parent has no gateway

We set a dedicated route to reach the VPN gateway only if the parent
device has a gateway. If the parent device doesn't have a gateway (for
example in case of GSM connections) and the VPN gets the default
route, the VPN gateway will be contacted through the VPN itself, which
obviously doesn't work.

Set up a device route if the parent device doesn't provide a gateway.

https://bugzilla.redhat.com/show_bug.cgi?id=1403660
(cherry picked from commit ae5adc9e21)
(cherry picked from commit 48db5806f3)
This commit is contained in:
Beniamino Galvani 2017-01-05 13:59:50 +01:00
parent 92f057ca1d
commit ff6ef0d696

View file

@ -660,12 +660,9 @@ add_ip4_vpn_gateway_route (NMIP4Config *config, NMDevice *parent_device, guint32
/* Set up a route to the VPN gateway's public IP address through the default
* network device if the VPN gateway is on a different subnet.
*/
parent_config = nm_device_get_ip4_config (parent_device);
g_return_if_fail (parent_config != NULL);
parent_gw = nm_ip4_config_get_gateway (parent_config);
if (!parent_gw)
return;
route_metric = nm_device_get_ip4_route_metric (parent_device);
@ -673,6 +670,9 @@ add_ip4_vpn_gateway_route (NMIP4Config *config, NMDevice *parent_device, guint32
route.network = vpn_gw;
route.plen = 32;
route.gateway = parent_gw;
/* Set up a device route if the parent device has no gateway */
if (!parent_gw)
route.ifindex = nm_device_get_ip_ifindex (parent_device);
/* If the VPN gateway is in the same subnet as one of the parent device's
* IP addresses, don't add the host route to it, but a route through the
@ -685,18 +685,20 @@ add_ip4_vpn_gateway_route (NMIP4Config *config, NMDevice *parent_device, guint32
route.metric = route_metric;
nm_ip4_config_add_route (config, &route);
/* Ensure there's a route to the parent device's gateway through the
* parent device, since if the VPN claims the default route and the VPN
* routes include a subnet that matches the parent device's subnet,
* the parent device's gateway would get routed through the VPN and fail.
*/
memset (&route, 0, sizeof (route));
route.network = parent_gw;
route.plen = 32;
route.source = NM_IP_CONFIG_SOURCE_VPN;
route.metric = route_metric;
if (parent_gw) {
/* Ensure there's a route to the parent device's gateway through the
* parent device, since if the VPN claims the default route and the VPN
* routes include a subnet that matches the parent device's subnet,
* the parent device's gateway would get routed through the VPN and fail.
*/
memset (&route, 0, sizeof (route));
route.network = parent_gw;
route.plen = 32;
route.source = NM_IP_CONFIG_SOURCE_VPN;
route.metric = route_metric;
nm_ip4_config_add_route (config, &route);
nm_ip4_config_add_route (config, &route);
}
}
static void