summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2019-02-09 11:46:47 +0100
committerThomas Haller <thaller@redhat.com>2019-02-14 08:00:29 +0100
commit6f35efe6fe380a1f0c18638217e747ae836a7505 (patch)
tree851329de9691ec5c701c26ea3ad278bdd523f087
parent55ce9d9de920cf7dd347df8a839829114596160d (diff)
downloadNetworkManager-6f35efe6fe380a1f0c18638217e747ae836a7505.tar.gz
policy: treat WireGuard devices as VPN for DNS
WireGuard devices are (will be) regular NMDevice implementations, but NMDnsManager should treat them like VPN. For that, reuse the device's type and nm_device_get_route_metric_default().
-rw-r--r--src/devices/nm-device.c9
-rw-r--r--src/nm-core-utils.h4
-rw-r--r--src/nm-policy.c39
-rw-r--r--src/vpn/nm-vpn-connection.h2
4 files changed, 41 insertions, 13 deletions
diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c
index 8b68469cd9..bcb56baeea 100644
--- a/src/devices/nm-device.c
+++ b/src/devices/nm-device.c
@@ -2042,9 +2042,14 @@ nm_device_get_route_metric_default (NMDeviceType device_type)
*/
switch (device_type) {
- /* 50 is also used for VPN plugins (NM_VPN_ROUTE_METRIC_DEFAULT) */
+
+ /* 50 is also used for VPN plugins (NM_VPN_ROUTE_METRIC_DEFAULT).
+ *
+ * Note that returning 50 from this function means that this device-type is
+ * in some aspects a VPN. */
case NM_DEVICE_TYPE_WIREGUARD:
- return 50;
+ return NM_VPN_ROUTE_METRIC_DEFAULT;
+
case NM_DEVICE_TYPE_ETHERNET:
case NM_DEVICE_TYPE_VETH:
return 100;
diff --git a/src/nm-core-utils.h b/src/nm-core-utils.h
index a93854a465..1b0d39ed69 100644
--- a/src/nm-core-utils.h
+++ b/src/nm-core-utils.h
@@ -485,4 +485,8 @@ const char *nm_activation_type_to_string (NMActivationType activation_type);
const char *nm_utils_parse_dns_domain (const char *domain, gboolean *is_routing);
+/*****************************************************************************/
+
+#define NM_VPN_ROUTE_METRIC_DEFAULT 50
+
#endif /* __NM_CORE_UTILS_H__ */
diff --git a/src/nm-policy.c b/src/nm-policy.c
index cb0688f43b..540f406514 100644
--- a/src/nm-policy.c
+++ b/src/nm-policy.c
@@ -149,6 +149,25 @@ static NMDevice *get_default_device (NMPolicy *self, int addr_family);
/*****************************************************************************/
+static void
+_dns_manager_set_ip_config (NMDnsManager *dns_manager,
+ NMIPConfig *ip_config,
+ NMDnsIPConfigType ip_config_type,
+ NMDevice *device)
+{
+ if ( NM_IN_SET (ip_config_type, NM_DNS_IP_CONFIG_TYPE_DEFAULT,
+ NM_DNS_IP_CONFIG_TYPE_BEST_DEVICE)
+ && device
+ && nm_device_get_route_metric_default (nm_device_get_device_type (device)) == NM_VPN_ROUTE_METRIC_DEFAULT) {
+ /* some device types are inherently VPN. */
+ ip_config_type = NM_DNS_IP_CONFIG_TYPE_VPN;
+ }
+
+ nm_dns_manager_set_ip_config (dns_manager, ip_config, ip_config_type);
+}
+
+/*****************************************************************************/
+
typedef struct {
NMPlatformIP6Address prefix;
NMDevice *device; /* The requesting ("uplink") device */
@@ -1090,19 +1109,21 @@ update_ip_dns (NMPolicy *self, int addr_family)
gpointer ip_config;
const char *ip_iface = NULL;
NMVpnConnection *vpn = NULL;
+ NMDevice *device = NULL;
nm_assert_addr_family (addr_family);
- ip_config = get_best_ip_config (self, addr_family, &ip_iface, NULL, NULL, &vpn);
+ ip_config = get_best_ip_config (self, addr_family, &ip_iface, NULL, &device, &vpn);
if (ip_config) {
/* Tell the DNS manager this config is preferred by re-adding it with
* a different IP config type.
*/
- nm_dns_manager_set_ip_config (NM_POLICY_GET_PRIVATE (self)->dns_manager,
- ip_config,
- vpn
- ? NM_DNS_IP_CONFIG_TYPE_VPN
- : NM_DNS_IP_CONFIG_TYPE_BEST_DEVICE);
+ _dns_manager_set_ip_config (NM_POLICY_GET_PRIVATE (self)->dns_manager,
+ ip_config,
+ vpn
+ ? NM_DNS_IP_CONFIG_TYPE_VPN
+ : NM_DNS_IP_CONFIG_TYPE_BEST_DEVICE,
+ device);
}
if (addr_family == AF_INET6)
@@ -1849,10 +1870,10 @@ device_state_changed (NMDevice *device,
ip4_config = nm_device_get_ip4_config (device);
if (ip4_config)
- nm_dns_manager_set_ip_config (priv->dns_manager, NM_IP_CONFIG_CAST (ip4_config), NM_DNS_IP_CONFIG_TYPE_DEFAULT);
+ _dns_manager_set_ip_config (priv->dns_manager, NM_IP_CONFIG_CAST (ip4_config), NM_DNS_IP_CONFIG_TYPE_DEFAULT, device);
ip6_config = nm_device_get_ip6_config (device);
if (ip6_config)
- nm_dns_manager_set_ip_config (priv->dns_manager, NM_IP_CONFIG_CAST (ip6_config), NM_DNS_IP_CONFIG_TYPE_DEFAULT);
+ _dns_manager_set_ip_config (priv->dns_manager, NM_IP_CONFIG_CAST (ip6_config), NM_DNS_IP_CONFIG_TYPE_DEFAULT, device);
update_routing_and_dns (self, FALSE);
@@ -1979,7 +2000,7 @@ device_ip_config_changed (NMDevice *device,
if (nm_device_get_state (device) == NM_DEVICE_STATE_ACTIVATED) {
if (old_config != new_config) {
if (new_config)
- nm_dns_manager_set_ip_config (priv->dns_manager, new_config, NM_DNS_IP_CONFIG_TYPE_DEFAULT);
+ _dns_manager_set_ip_config (priv->dns_manager, new_config, NM_DNS_IP_CONFIG_TYPE_DEFAULT, device);
if (old_config)
nm_dns_manager_set_ip_config (priv->dns_manager, old_config, NM_DNS_IP_CONFIG_TYPE_REMOVED);
}
diff --git a/src/vpn/nm-vpn-connection.h b/src/vpn/nm-vpn-connection.h
index 5482fb0d8b..e70590b248 100644
--- a/src/vpn/nm-vpn-connection.h
+++ b/src/vpn/nm-vpn-connection.h
@@ -28,8 +28,6 @@
#include "nm-active-connection.h"
#include "nm-vpn-plugin-info.h"
-#define NM_VPN_ROUTE_METRIC_DEFAULT 50
-
#define NM_TYPE_VPN_CONNECTION (nm_vpn_connection_get_type ())
#define NM_VPN_CONNECTION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_VPN_CONNECTION, NMVpnConnection))
#define NM_VPN_CONNECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_VPN_CONNECTION, NMVpnConnectionClass))