From 95310a5dec092fb84121d193af8f65df1edea094 Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Mon, 9 May 2016 16:30:41 +0200 Subject: [PATCH] core: use default value for ipvx.dns-priority Fall back to system default value for ipvx.dns-priority when it's zero in the setting. For VPNs the default value is 50; for other connections is 100, but it depends also on the content of [connection*] sections in NetworkManager.conf. (cherry picked from commit 77ded12da46457848e86561b0e9460f03302e6e8) --- src/devices/nm-device.c | 31 +++++++++++++++++++++++++++++ src/dns-manager/nm-dns-manager.h | 5 +++++ src/vpn-manager/nm-vpn-connection.c | 3 +++ 3 files changed, 39 insertions(+) diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index d28487f095..20a44889f4 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -524,6 +524,34 @@ NM_UTILS_LOOKUP_STR_DEFINE_STATIC (_reason_to_string, NMDeviceStateReason, /***********************************************************/ +static void +init_ip4_config_dns_priority (NMDevice *self, NMIP4Config *config) +{ + gs_free char *value = NULL; + gint priority; + + value = nm_config_data_get_connection_default (NM_CONFIG_GET_DATA, + "ipv4.dns-priority", + self); + priority = _nm_utils_ascii_str_to_int64 (value, 10, G_MININT, G_MAXINT, 0); + nm_ip4_config_set_dns_priority (config, priority ?: NM_DNS_PRIORITY_DEFAULT_NORMAL); +} + +static void +init_ip6_config_dns_priority (NMDevice *self, NMIP6Config *config) +{ + gs_free char *value = NULL; + gint priority; + + value = nm_config_data_get_connection_default (NM_CONFIG_GET_DATA, + "ipv6.dns-priority", + self); + priority = _nm_utils_ascii_str_to_int64 (value, 10, G_MININT, G_MAXINT, 0); + nm_ip6_config_set_dns_priority (config, priority ?: NM_DNS_PRIORITY_DEFAULT_NORMAL); +} + +/***********************************************************/ + gboolean nm_device_ipv6_sysctl_set (NMDevice *self, const char *property, const char *value) { @@ -4368,6 +4396,7 @@ ip4_config_merge_and_apply (NMDevice *self, } composite = nm_ip4_config_new (nm_device_get_ip_ifindex (self)); + init_ip4_config_dns_priority (self, composite); if (commit) ensure_con_ip4_config (self); @@ -5094,9 +5123,11 @@ ip6_config_merge_and_apply (NMDevice *self, /* If no config was passed in, create a new one */ composite = nm_ip6_config_new (nm_device_get_ip_ifindex (self)); + init_ip6_config_dns_priority (self, composite); if (commit) ensure_con_ip6_config (self); + g_assert (composite); /* Merge all the IP configs into the composite config */ diff --git a/src/dns-manager/nm-dns-manager.h b/src/dns-manager/nm-dns-manager.h index 72dc4e3cb4..a82fdfc036 100644 --- a/src/dns-manager/nm-dns-manager.h +++ b/src/dns-manager/nm-dns-manager.h @@ -36,6 +36,11 @@ typedef enum { NM_DNS_IP_CONFIG_TYPE_VPN } NMDnsIPConfigType; +enum { + NM_DNS_PRIORITY_DEFAULT_NORMAL = 100, + NM_DNS_PRIORITY_DEFAULT_VPN = 50, +}; + typedef struct { gpointer config; NMDnsIPConfigType type; diff --git a/src/vpn-manager/nm-vpn-connection.c b/src/vpn-manager/nm-vpn-connection.c index 31b94752af..683e6c923e 100644 --- a/src/vpn-manager/nm-vpn-connection.c +++ b/src/vpn-manager/nm-vpn-connection.c @@ -44,6 +44,7 @@ #include "nm-config.h" #include "nm-vpn-plugin-info.h" #include "nm-vpn-manager.h" +#include "nm-dns-manager.h" #include "nmdbus-vpn-connection.h" @@ -1364,6 +1365,7 @@ nm_vpn_connection_ip4_config_get (NMVpnConnection *self, GVariant *dict) ifindex = nm_device_get_ip_ifindex (parent_dev); } config = nm_ip4_config_new (ifindex); + nm_ip4_config_set_dns_priority (config, NM_DNS_PRIORITY_DEFAULT_VPN); memset (&address, 0, sizeof (address)); address.plen = 24; @@ -1497,6 +1499,7 @@ nm_vpn_connection_ip6_config_get (NMVpnConnection *self, GVariant *dict) } config = nm_ip6_config_new (priv->ip_ifindex); + nm_ip6_config_set_dns_priority (config, NM_DNS_PRIORITY_DEFAULT_VPN); memset (&address, 0, sizeof (address)); address.plen = 128;