vpn,dns: merge branch 'bg/vpn-dns-rh1348901'

This commit is contained in:
Beniamino Galvani 2016-06-28 16:39:17 +02:00
commit 88637dee66
3 changed files with 73 additions and 15 deletions

View file

@ -51,6 +51,14 @@ _nm_auto_unset_gvalue_impl (GValue *v)
}
#define nm_auto_unset_gvalue nm_auto(_nm_auto_unset_gvalue_impl)
static inline void
_nm_auto_free_gstring_impl (GString **str)
{
if (*str)
g_string_free (*str, TRUE);
}
#define nm_auto_free_gstring nm_auto(_nm_auto_free_gstring_impl)
/********************************************************/
/* http://stackoverflow.com/a/11172679 */

View file

@ -940,6 +940,44 @@ merge_global_dns_config (NMResolvConfData *rc, NMGlobalDnsConfig *global_conf)
return TRUE;
}
static const char *
get_nameserver_list (void *config, GString **str)
{
NMIP4Config *ip4;
NMIP6Config *ip6;
guint num, i;
nm_assert (str);
if (*str)
g_string_truncate (*str, 0);
else
*str = g_string_sized_new (64);
if (NM_IS_IP4_CONFIG (config)) {
ip4 = (NMIP4Config *) config;
num = nm_ip4_config_get_num_nameservers (ip4);
for (i = 0; i < num; i++) {
g_string_append (*str,
nm_utils_inet4_ntop (nm_ip4_config_get_nameserver (ip4, i),
NULL));
g_string_append_c (*str, ' ');
}
} else if (NM_IS_IP6_CONFIG (config)) {
ip6 = (NMIP6Config *) config;
num = nm_ip6_config_get_num_nameservers (ip6);
for (i = 0; i < num; i++) {
g_string_append (*str,
nm_utils_inet6_ntop (nm_ip6_config_get_nameserver (ip6, i),
NULL));
g_string_append_c (*str, ' ');
}
} else
g_return_val_if_reached (NULL);
return (*str)->str;
}
static gboolean
update_dns (NMDnsManager *self,
gboolean no_caching,
@ -959,6 +997,7 @@ update_dns (NMDnsManager *self,
NMConfigData *data;
NMGlobalDnsConfig *global_config;
gs_free NMDnsIPConfigData **plugin_confs = NULL;
nm_auto_free_gstring GString *tmp_gstring = NULL;
g_return_val_if_fail (!error || !*error, FALSE);
@ -1015,12 +1054,13 @@ update_dns (NMDnsManager *self,
prev_prio = prio;
_LOGT ("config: %8d %-7s v%c %-16s %s",
_LOGT ("config: %8d %-7s v%c %-16s %s: %s",
prio,
_config_type_to_string (current->type),
v4 ? '4' : '6',
v4 ? '4' : '6',
current->iface,
skip ? "<SKIP>" : "");
skip ? "<SKIP>" : "",
get_nameserver_list (current->config, &tmp_gstring));
if (!skip) {
merge_one_ip_config_data (self, &rc, current);

View file

@ -1025,12 +1025,11 @@ apply_parent_device_config (NMVpnConnection *self)
ifindex = nm_device_get_ip_ifindex (parent_dev);
if (priv->ip4_config) {
vpn4_parent_config = nm_ip4_config_new (ifindex);
nm_ip4_config_merge (vpn4_parent_config, priv->ip4_config, NM_IP_CONFIG_MERGE_DEFAULT);
nm_ip4_config_unset_gateway (vpn4_parent_config);
nm_ip4_config_merge (vpn4_parent_config, priv->ip4_config, NM_IP_CONFIG_MERGE_NO_DNS);
}
if (priv->ip6_config) {
vpn6_parent_config = nm_ip6_config_new (ifindex);
nm_ip6_config_merge (vpn6_parent_config, priv->ip6_config, NM_IP_CONFIG_MERGE_DEFAULT);
nm_ip6_config_merge (vpn6_parent_config, priv->ip6_config, NM_IP_CONFIG_MERGE_NO_DNS);
nm_ip6_config_set_gateway (vpn6_parent_config, NULL);
}
}
@ -1082,7 +1081,8 @@ nm_vpn_connection_apply_config (NMVpnConnection *self)
nm_default_route_manager_ip6_update_default_route (priv->default_route_manager, self);
_LOGI ("VPN connection: (IP Config Get) complete");
_set_vpn_state (self, STATE_PRE_UP, NM_VPN_CONNECTION_STATE_REASON_NONE, FALSE);
if (priv->vpn_state < STATE_PRE_UP)
_set_vpn_state (self, STATE_PRE_UP, NM_VPN_CONNECTION_STATE_REASON_NONE, FALSE);
return TRUE;
}
@ -1469,10 +1469,15 @@ nm_vpn_connection_ip4_config_get (NMVpnConnection *self, GVariant *dict)
nm_connection_get_setting_ip4_config (_get_applied_connection (self)),
route_metric);
nm_exported_object_clear_and_unexport (&priv->ip4_config);
priv->ip4_config = config;
nm_exported_object_export (NM_EXPORTED_OBJECT (config));
g_object_notify (G_OBJECT (self), NM_ACTIVE_CONNECTION_IP4_CONFIG);
if (priv->ip4_config) {
nm_ip4_config_replace (priv->ip4_config, config, NULL);
g_object_unref (config);
} else {
priv->ip4_config = config;
nm_exported_object_export (NM_EXPORTED_OBJECT (config));
g_object_notify (G_OBJECT (self), NM_ACTIVE_CONNECTION_IP4_CONFIG);
}
nm_vpn_connection_config_maybe_complete (self, TRUE);
}
@ -1606,10 +1611,15 @@ next:
nm_connection_get_setting_ip6_config (_get_applied_connection (self)),
route_metric);
nm_exported_object_clear_and_unexport (&priv->ip6_config);
priv->ip6_config = config;
nm_exported_object_export (NM_EXPORTED_OBJECT (config));
g_object_notify (G_OBJECT (self), NM_ACTIVE_CONNECTION_IP6_CONFIG);
if (priv->ip6_config) {
nm_ip6_config_replace (priv->ip6_config, config, NULL);
g_object_unref (config);
} else {
priv->ip6_config = config;
nm_exported_object_export (NM_EXPORTED_OBJECT (config));
g_object_notify (G_OBJECT (self), NM_ACTIVE_CONNECTION_IP6_CONFIG);
}
nm_vpn_connection_config_maybe_complete (self, TRUE);
}