summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2016-05-27 17:58:14 +0200
committerThomas Haller <thaller@redhat.com>2016-05-27 18:04:05 +0200
commit9ab1682b5e30122fdbc93c0ff7ac09064c743423 (patch)
treea455744b4798805b9e17e9f75b3db268181722a1
parent0c80e38f640c3d838806b537864c1702583cd9e4 (diff)
parent3f8a60def635afb613a88602ffd4d4f88f622e92 (diff)
downloadNetworkManager-9ab1682b5e30122fdbc93c0ff7ac09064c743423.tar.gz
core: merge branch 'th/vpn-connection-dns-fix'
nm-libreswan VPN has no own IP interface. Thus we got an assertion failure in nm_dns_manager_add_ip_config(). Fix that, by using the IP interface of the parent device.
-rw-r--r--src/nm-default-route-manager.c16
-rw-r--r--src/nm-policy.c2
-rw-r--r--src/vpn-manager/nm-vpn-connection.c80
-rw-r--r--src/vpn-manager/nm-vpn-connection.h4
4 files changed, 71 insertions, 31 deletions
diff --git a/src/nm-default-route-manager.c b/src/nm-default-route-manager.c
index a637c6cb88..2fd2c7db47 100644
--- a/src/nm-default-route-manager.c
+++ b/src/nm-default-route-manager.c
@@ -727,16 +727,8 @@ _ipx_update_default_route (const VTableIP *vtable, NMDefaultRouteManager *self,
if (device)
ip_ifindex = nm_device_get_ip_ifindex (device);
- else {
- ip_ifindex = nm_vpn_connection_get_ip_ifindex (vpn);
-
- if (ip_ifindex <= 0) {
- NMDevice *parent = nm_active_connection_get_device (NM_ACTIVE_CONNECTION (vpn));
-
- if (parent)
- ip_ifindex = nm_device_get_ip_ifindex (parent);
- }
- }
+ else
+ ip_ifindex = nm_vpn_connection_get_ip_ifindex (vpn, TRUE);
entries = vtable->get_entries (priv);
entry = _entry_find_by_source (entries, source, &entry_idx);
@@ -818,7 +810,7 @@ _ipx_update_default_route (const VTableIP *vtable, NMDefaultRouteManager *self,
}
}
}
- if (nm_vpn_connection_get_ip_ifindex (vpn) > 0)
+ if (nm_vpn_connection_get_ip_ifindex (vpn, FALSE) > 0)
synced = TRUE;
else {
/* a VPN connection without tunnel device cannot have a non-synced, missing default route.
@@ -1149,7 +1141,7 @@ _ipx_get_best_config (const VTableIP *vtable,
if (out_ac)
*out_ac = NM_ACTIVE_CONNECTION (vpn);
if (out_ip_iface)
- *out_ip_iface = nm_vpn_connection_get_ip_iface (vpn);
+ *out_ip_iface = nm_vpn_connection_get_ip_iface (vpn, TRUE);
} else {
NMDevice *device = entry->source.device;
NMActRequest *req;
diff --git a/src/nm-policy.c b/src/nm-policy.c
index 0d39723344..8f23ce81e3 100644
--- a/src/nm-policy.c
+++ b/src/nm-policy.c
@@ -1441,7 +1441,7 @@ vpn_connection_activated (NMPolicy *self, NMVpnConnection *vpn)
nm_dns_manager_begin_updates (priv->dns_manager, __func__);
- ip_iface = nm_vpn_connection_get_ip_iface (vpn);
+ ip_iface = nm_vpn_connection_get_ip_iface (vpn, TRUE);
/* Add the VPN connection's IP configs from DNS */
diff --git a/src/vpn-manager/nm-vpn-connection.c b/src/vpn-manager/nm-vpn-connection.c
index 410256027f..b2aa8f6bc6 100644
--- a/src/vpn-manager/nm-vpn-connection.c
+++ b/src/vpn-manager/nm-vpn-connection.c
@@ -195,14 +195,14 @@ __LOG_create_prefix (char *buf, NMVpnConnection *self)
"%s%s" /*con-uuid*/
"%s%s%s%s" /*con-id*/
",%d" /*ifindex*/
- "%s%s%s%s" /*iface*/
+ "%s%s%s" /*iface*/
"]",
_NMLOG_PREFIX_NAME,
self,
con ? "," : "--", con ? (nm_connection_get_uuid (con) ?: "??") : "",
con ? "," : "", NM_PRINT_FMT_QUOTED (id, "\"", id, "\"", con ? "??" : ""),
priv->ip_ifindex,
- priv->ip_iface ? ":" : "", NM_PRINT_FMT_QUOTED (priv->ip_iface, "(", priv->ip_iface, ")", "")
+ NM_PRINT_FMT_QUOTED (priv->ip_iface, ":(", priv->ip_iface, ")", "")
);
return buf;
@@ -912,7 +912,7 @@ print_vpn_config (NMVpnConnection *self)
nm_utils_inet6_ntop (priv->ip6_external_gw, NULL));
}
- _LOGI ("Data: Tunnel Device: %s", priv->ip_iface ? priv->ip_iface : "(none)");
+ _LOGI ("Data: Tunnel Device: %s%s%s", NM_PRINT_FMT_QUOTE_STRING (priv->ip_iface));
if (priv->ip4_config) {
_LOGI ("Data: IPv4 configuration:");
@@ -1221,6 +1221,8 @@ process_generic_config (NMVpnConnection *self, GVariant *dict)
}
g_clear_pointer (&priv->ip_iface, g_free);
+ priv->ip_ifindex = 0;
+
if (g_variant_lookup (dict, NM_VPN_PLUGIN_CONFIG_TUNDEV, "&s", &str)) {
/* Backwards compat with NM-openswan */
if (g_strcmp0 (str, "_none_") != 0)
@@ -1231,7 +1233,13 @@ process_generic_config (NMVpnConnection *self, GVariant *dict)
/* Grab the interface index for address/routing operations */
priv->ip_ifindex = nm_platform_link_get_ifindex (NM_PLATFORM_GET, priv->ip_iface);
if (priv->ip_ifindex <= 0) {
+ nm_platform_process_events (NM_PLATFORM_GET);
+ priv->ip_ifindex = nm_platform_link_get_ifindex (NM_PLATFORM_GET, priv->ip_iface);
+ }
+ if (priv->ip_ifindex <= 0) {
_LOGE ("failed to look up VPN interface index for \"%s\"", priv->ip_iface);
+ g_clear_pointer (&priv->ip_iface, g_free);
+ priv->ip_ifindex = 0;
nm_vpn_connection_config_maybe_complete (self, FALSE);
return FALSE;
}
@@ -1332,7 +1340,6 @@ nm_vpn_connection_ip4_config_get (NMVpnConnection *self, GVariant *dict)
const char *str;
GVariant *v;
gboolean b;
- int ifindex;
g_return_if_fail (dict && g_variant_is_of_type (dict, G_VARIANT_TYPE_VARDICT));
@@ -1360,13 +1367,7 @@ nm_vpn_connection_ip4_config_get (NMVpnConnection *self, GVariant *dict)
priv->has_ip6 = FALSE;
}
- if (priv->ip_ifindex > 0) {
- ifindex = priv->ip_ifindex;
- } else {
- NMDevice *parent_dev = nm_active_connection_get_device (NM_ACTIVE_CONNECTION (self));
- ifindex = nm_device_get_ip_ifindex (parent_dev);
- }
- config = nm_ip4_config_new (ifindex);
+ config = nm_ip4_config_new (nm_vpn_connection_get_ip_ifindex (self, TRUE));
nm_ip4_config_set_dns_priority (config, NM_DNS_PRIORITY_DEFAULT_VPN);
memset (&address, 0, sizeof (address));
@@ -2150,20 +2151,67 @@ nm_vpn_connection_get_ip6_config (NMVpnConnection *self)
return NM_VPN_CONNECTION_GET_PRIVATE (self)->ip6_config;
}
+static int
+_get_ip_iface_for_device (NMVpnConnection *self, const char **out_iface)
+{
+ NMDevice *parent_dev;
+ int ifindex;
+ const char *iface;
+
+ nm_assert (NM_IS_VPN_CONNECTION (self));
+
+ /* the ifindex and the ifname in this case should come together.
+ * They either must be both set, or none. */
+
+ parent_dev = nm_active_connection_get_device (NM_ACTIVE_CONNECTION (self));
+ if (!parent_dev)
+ goto none;
+ ifindex = nm_device_get_ip_ifindex (parent_dev);
+ if (ifindex <= 0)
+ goto none;
+ iface = nm_device_get_ip_iface (parent_dev);
+ if (!iface)
+ goto none;
+
+ NM_SET_OUT (out_iface, iface);
+ return ifindex;
+none:
+ NM_SET_OUT (out_iface, NULL);
+ return 0;
+}
+
const char *
-nm_vpn_connection_get_ip_iface (NMVpnConnection *self)
+nm_vpn_connection_get_ip_iface (NMVpnConnection *self, gboolean fallback_device)
{
+ NMVpnConnectionPrivate *priv;
+ const char *iface;
+
g_return_val_if_fail (NM_IS_VPN_CONNECTION (self), NULL);
- return NM_VPN_CONNECTION_GET_PRIVATE (self)->ip_iface;
+ priv = NM_VPN_CONNECTION_GET_PRIVATE (self);
+
+ if (priv->ip_iface || !fallback_device)
+ return priv->ip_iface;
+
+ _get_ip_iface_for_device (self, &iface);
+ return iface;
}
int
-nm_vpn_connection_get_ip_ifindex (NMVpnConnection *self)
+nm_vpn_connection_get_ip_ifindex (NMVpnConnection *self, gboolean fallback_device)
{
- g_return_val_if_fail (NM_IS_VPN_CONNECTION (self), -1);
+ NMVpnConnectionPrivate *priv;
+
+ g_return_val_if_fail (NM_IS_VPN_CONNECTION (self), 0);
+
+ priv = NM_VPN_CONNECTION_GET_PRIVATE (self);
+
+ if (priv->ip_ifindex > 0)
+ return priv->ip_ifindex;
+ if (!fallback_device)
+ return 0;
- return NM_VPN_CONNECTION_GET_PRIVATE (self)->ip_ifindex;
+ return _get_ip_iface_for_device (self, NULL);
}
guint32
diff --git a/src/vpn-manager/nm-vpn-connection.h b/src/vpn-manager/nm-vpn-connection.h
index 19b0eb3feb..6837432926 100644
--- a/src/vpn-manager/nm-vpn-connection.h
+++ b/src/vpn-manager/nm-vpn-connection.h
@@ -91,8 +91,8 @@ void nm_vpn_connection_disconnect (NMVpnConnection *self,
NMIP4Config * nm_vpn_connection_get_ip4_config (NMVpnConnection *self);
NMIP6Config * nm_vpn_connection_get_ip6_config (NMVpnConnection *self);
-const char * nm_vpn_connection_get_ip_iface (NMVpnConnection *self);
-int nm_vpn_connection_get_ip_ifindex (NMVpnConnection *self);
+const char * nm_vpn_connection_get_ip_iface (NMVpnConnection *self, gboolean fallback_device);
+int nm_vpn_connection_get_ip_ifindex (NMVpnConnection *self, gboolean fallback_device);
guint32 nm_vpn_connection_get_ip4_internal_gateway (NMVpnConnection *self);
struct in6_addr * nm_vpn_connection_get_ip6_internal_gateway (NMVpnConnection *self);