mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-05-05 21:38:06 +02:00
policy: merge IPv4 and IPv6 implementation of update_ip_dns()
(cherry picked from commit 157932f7dd)
This commit is contained in:
parent
dbe2f20aba
commit
dd4e8ef9dc
3 changed files with 52 additions and 101 deletions
|
|
@ -1305,7 +1305,7 @@ forget_data (NMDnsManager *self, NMDnsIPConfigData *data)
|
||||||
g_signal_handlers_disconnect_by_func (data->config, ip_config_dns_priority_changed, self);
|
g_signal_handlers_disconnect_by_func (data->config, ip_config_dns_priority_changed, self);
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
gboolean
|
||||||
nm_dns_manager_add_ip_config (NMDnsManager *self,
|
nm_dns_manager_add_ip_config (NMDnsManager *self,
|
||||||
const char *iface,
|
const char *iface,
|
||||||
gpointer config,
|
gpointer config,
|
||||||
|
|
@ -1320,6 +1320,7 @@ nm_dns_manager_add_ip_config (NMDnsManager *self,
|
||||||
g_return_val_if_fail (NM_IS_DNS_MANAGER (self), FALSE);
|
g_return_val_if_fail (NM_IS_DNS_MANAGER (self), FALSE);
|
||||||
g_return_val_if_fail (config, FALSE);
|
g_return_val_if_fail (config, FALSE);
|
||||||
g_return_val_if_fail (iface && iface[0], FALSE);
|
g_return_val_if_fail (iface && iface[0], FALSE);
|
||||||
|
nm_assert (NM_IP4_CONFIG (config) || NM_IS_IP6_CONFIG (config));
|
||||||
|
|
||||||
priv = NM_DNS_MANAGER_GET_PRIVATE (self);
|
priv = NM_DNS_MANAGER_GET_PRIVATE (self);
|
||||||
|
|
||||||
|
|
@ -1368,24 +1369,6 @@ nm_dns_manager_add_ip_config (NMDnsManager *self,
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
nm_dns_manager_add_ip4_config (NMDnsManager *self,
|
|
||||||
const char *iface,
|
|
||||||
NMIP4Config *config,
|
|
||||||
NMDnsIPConfigType cfg_type)
|
|
||||||
{
|
|
||||||
return nm_dns_manager_add_ip_config (self, iface, config, cfg_type);
|
|
||||||
}
|
|
||||||
|
|
||||||
gboolean
|
|
||||||
nm_dns_manager_add_ip6_config (NMDnsManager *self,
|
|
||||||
const char *iface,
|
|
||||||
NMIP6Config *config,
|
|
||||||
NMDnsIPConfigType cfg_type)
|
|
||||||
{
|
|
||||||
return nm_dns_manager_add_ip_config (self, iface, config, cfg_type);
|
|
||||||
}
|
|
||||||
|
|
||||||
static gboolean
|
|
||||||
nm_dns_manager_remove_ip_config (NMDnsManager *self, gpointer config)
|
nm_dns_manager_remove_ip_config (NMDnsManager *self, gpointer config)
|
||||||
{
|
{
|
||||||
NMDnsManagerPrivate *priv;
|
NMDnsManagerPrivate *priv;
|
||||||
|
|
@ -1395,6 +1378,7 @@ nm_dns_manager_remove_ip_config (NMDnsManager *self, gpointer config)
|
||||||
|
|
||||||
g_return_val_if_fail (NM_IS_DNS_MANAGER (self), FALSE);
|
g_return_val_if_fail (NM_IS_DNS_MANAGER (self), FALSE);
|
||||||
g_return_val_if_fail (config, FALSE);
|
g_return_val_if_fail (config, FALSE);
|
||||||
|
nm_assert (NM_IP4_CONFIG (config) || NM_IS_IP6_CONFIG (config));
|
||||||
|
|
||||||
priv = NM_DNS_MANAGER_GET_PRIVATE (self);
|
priv = NM_DNS_MANAGER_GET_PRIVATE (self);
|
||||||
|
|
||||||
|
|
@ -1416,18 +1400,6 @@ nm_dns_manager_remove_ip_config (NMDnsManager *self, gpointer config)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
|
||||||
nm_dns_manager_remove_ip4_config (NMDnsManager *self, NMIP4Config *config)
|
|
||||||
{
|
|
||||||
return nm_dns_manager_remove_ip_config (self, config);
|
|
||||||
}
|
|
||||||
|
|
||||||
gboolean
|
|
||||||
nm_dns_manager_remove_ip6_config (NMDnsManager *self, NMIP6Config *config)
|
|
||||||
{
|
|
||||||
return nm_dns_manager_remove_ip_config (self, config);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
nm_dns_manager_set_initial_hostname (NMDnsManager *self,
|
nm_dns_manager_set_initial_hostname (NMDnsManager *self,
|
||||||
const char *hostname)
|
const char *hostname)
|
||||||
|
|
|
||||||
|
|
@ -72,19 +72,12 @@ NMDnsManager * nm_dns_manager_get (void);
|
||||||
void nm_dns_manager_begin_updates (NMDnsManager *self, const char *func);
|
void nm_dns_manager_begin_updates (NMDnsManager *self, const char *func);
|
||||||
void nm_dns_manager_end_updates (NMDnsManager *self, const char *func);
|
void nm_dns_manager_end_updates (NMDnsManager *self, const char *func);
|
||||||
|
|
||||||
gboolean nm_dns_manager_add_ip4_config (NMDnsManager *self,
|
gboolean nm_dns_manager_add_ip_config (NMDnsManager *self,
|
||||||
const char *iface,
|
const char *iface,
|
||||||
NMIP4Config *config,
|
gpointer config,
|
||||||
NMDnsIPConfigType cfg_type);
|
NMDnsIPConfigType cfg_type);
|
||||||
|
|
||||||
gboolean nm_dns_manager_remove_ip4_config (NMDnsManager *self, NMIP4Config *config);
|
gboolean nm_dns_manager_remove_ip_config (NMDnsManager *self, gpointer config);
|
||||||
|
|
||||||
gboolean nm_dns_manager_add_ip6_config (NMDnsManager *self,
|
|
||||||
const char *iface,
|
|
||||||
NMIP6Config *config,
|
|
||||||
NMDnsIPConfigType cfg_type);
|
|
||||||
|
|
||||||
gboolean nm_dns_manager_remove_ip6_config (NMDnsManager *self, NMIP6Config *config);
|
|
||||||
|
|
||||||
void nm_dns_manager_set_initial_hostname (NMDnsManager *self,
|
void nm_dns_manager_set_initial_hostname (NMDnsManager *self,
|
||||||
const char *hostname);
|
const char *hostname);
|
||||||
|
|
|
||||||
102
src/nm-policy.c
102
src/nm-policy.c
|
|
@ -918,26 +918,6 @@ get_best_ip_config (NMPolicy *self,
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
update_ip4_dns (NMPolicy *self, NMDnsManager *dns_mgr)
|
|
||||||
{
|
|
||||||
NMIP4Config *ip4_config;
|
|
||||||
const char *ip_iface = NULL;
|
|
||||||
NMVpnConnection *vpn = NULL;
|
|
||||||
NMDnsIPConfigType dns_type = NM_DNS_IP_CONFIG_TYPE_BEST_DEVICE;
|
|
||||||
|
|
||||||
ip4_config = get_best_ip_config (self, AF_INET, &ip_iface, NULL, NULL, &vpn);
|
|
||||||
if (ip4_config) {
|
|
||||||
if (vpn)
|
|
||||||
dns_type = NM_DNS_IP_CONFIG_TYPE_VPN;
|
|
||||||
|
|
||||||
/* Tell the DNS manager this config is preferred by re-adding it with
|
|
||||||
* a different IP config type.
|
|
||||||
*/
|
|
||||||
nm_dns_manager_add_ip4_config (dns_mgr, ip_iface, ip4_config, dns_type);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
update_ip4_routing (NMPolicy *self, gboolean force_update)
|
update_ip4_routing (NMPolicy *self, gboolean force_update)
|
||||||
{
|
{
|
||||||
|
|
@ -1008,28 +988,6 @@ update_ip6_dns_delegation (NMPolicy *self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
update_ip6_dns (NMPolicy *self, NMDnsManager *dns_mgr)
|
|
||||||
{
|
|
||||||
NMIP6Config *ip6_config;
|
|
||||||
const char *ip_iface = NULL;
|
|
||||||
NMVpnConnection *vpn = NULL;
|
|
||||||
NMDnsIPConfigType dns_type = NM_DNS_IP_CONFIG_TYPE_BEST_DEVICE;
|
|
||||||
|
|
||||||
ip6_config = get_best_ip_config (self, AF_INET6, &ip_iface, NULL, NULL, &vpn);
|
|
||||||
if (ip6_config) {
|
|
||||||
if (vpn)
|
|
||||||
dns_type = NM_DNS_IP_CONFIG_TYPE_VPN;
|
|
||||||
|
|
||||||
/* Tell the DNS manager this config is preferred by re-adding it with
|
|
||||||
* a different IP config type.
|
|
||||||
*/
|
|
||||||
nm_dns_manager_add_ip6_config (dns_mgr, ip_iface, ip6_config, dns_type);
|
|
||||||
}
|
|
||||||
|
|
||||||
update_ip6_dns_delegation (self);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
update_ip6_prefix_delegation (NMPolicy *self)
|
update_ip6_prefix_delegation (NMPolicy *self)
|
||||||
{
|
{
|
||||||
|
|
@ -1103,6 +1061,34 @@ update_ip6_routing (NMPolicy *self, gboolean force_update)
|
||||||
_notify (self, PROP_DEFAULT_IP6_DEVICE);
|
_notify (self, PROP_DEFAULT_IP6_DEVICE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
update_ip_dns (NMPolicy *self, int addr_family)
|
||||||
|
{
|
||||||
|
gpointer ip_config;
|
||||||
|
const char *ip_iface = NULL;
|
||||||
|
NMVpnConnection *vpn = NULL;
|
||||||
|
NMDnsIPConfigType dns_type = NM_DNS_IP_CONFIG_TYPE_BEST_DEVICE;
|
||||||
|
|
||||||
|
nm_assert_addr_family (addr_family);
|
||||||
|
|
||||||
|
ip_config = get_best_ip_config (self, addr_family, &ip_iface, NULL, NULL, &vpn);
|
||||||
|
if (ip_config) {
|
||||||
|
if (vpn)
|
||||||
|
dns_type = NM_DNS_IP_CONFIG_TYPE_VPN;
|
||||||
|
|
||||||
|
/* Tell the DNS manager this config is preferred by re-adding it with
|
||||||
|
* a different IP config type.
|
||||||
|
*/
|
||||||
|
nm_dns_manager_add_ip_config (NM_POLICY_GET_PRIVATE (self)->dns_manager,
|
||||||
|
ip_iface,
|
||||||
|
ip_config,
|
||||||
|
dns_type);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (addr_family == AF_INET6)
|
||||||
|
update_ip6_dns_delegation (self);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
update_routing_and_dns (NMPolicy *self, gboolean force_update)
|
update_routing_and_dns (NMPolicy *self, gboolean force_update)
|
||||||
{
|
{
|
||||||
|
|
@ -1110,8 +1096,8 @@ update_routing_and_dns (NMPolicy *self, gboolean force_update)
|
||||||
|
|
||||||
nm_dns_manager_begin_updates (priv->dns_manager, __func__);
|
nm_dns_manager_begin_updates (priv->dns_manager, __func__);
|
||||||
|
|
||||||
update_ip4_dns (self, priv->dns_manager);
|
update_ip_dns (self, AF_INET);
|
||||||
update_ip6_dns (self, priv->dns_manager);
|
update_ip_dns (self, AF_INET6);
|
||||||
|
|
||||||
update_ip4_routing (self, force_update);
|
update_ip4_routing (self, force_update);
|
||||||
update_ip6_routing (self, force_update);
|
update_ip6_routing (self, force_update);
|
||||||
|
|
@ -1800,10 +1786,10 @@ device_state_changed (NMDevice *device,
|
||||||
|
|
||||||
ip4_config = nm_device_get_ip4_config (device);
|
ip4_config = nm_device_get_ip4_config (device);
|
||||||
if (ip4_config)
|
if (ip4_config)
|
||||||
nm_dns_manager_add_ip4_config (priv->dns_manager, ip_iface, ip4_config, NM_DNS_IP_CONFIG_TYPE_DEFAULT);
|
nm_dns_manager_add_ip_config (priv->dns_manager, ip_iface, ip4_config, NM_DNS_IP_CONFIG_TYPE_DEFAULT);
|
||||||
ip6_config = nm_device_get_ip6_config (device);
|
ip6_config = nm_device_get_ip6_config (device);
|
||||||
if (ip6_config)
|
if (ip6_config)
|
||||||
nm_dns_manager_add_ip6_config (priv->dns_manager, ip_iface, ip6_config, NM_DNS_IP_CONFIG_TYPE_DEFAULT);
|
nm_dns_manager_add_ip_config (priv->dns_manager, ip_iface, ip6_config, NM_DNS_IP_CONFIG_TYPE_DEFAULT);
|
||||||
|
|
||||||
update_routing_and_dns (self, FALSE);
|
update_routing_and_dns (self, FALSE);
|
||||||
|
|
||||||
|
|
@ -1903,17 +1889,17 @@ device_ip4_config_changed (NMDevice *device,
|
||||||
if (nm_device_get_state (device) == NM_DEVICE_STATE_ACTIVATED) {
|
if (nm_device_get_state (device) == NM_DEVICE_STATE_ACTIVATED) {
|
||||||
if (old_config != new_config) {
|
if (old_config != new_config) {
|
||||||
if (old_config)
|
if (old_config)
|
||||||
nm_dns_manager_remove_ip4_config (priv->dns_manager, old_config);
|
nm_dns_manager_remove_ip_config (priv->dns_manager, old_config);
|
||||||
if (new_config)
|
if (new_config)
|
||||||
nm_dns_manager_add_ip4_config (priv->dns_manager, ip_iface, new_config, NM_DNS_IP_CONFIG_TYPE_DEFAULT);
|
nm_dns_manager_add_ip_config (priv->dns_manager, ip_iface, new_config, NM_DNS_IP_CONFIG_TYPE_DEFAULT);
|
||||||
}
|
}
|
||||||
update_ip4_dns (self, priv->dns_manager);
|
update_ip_dns (self, AF_INET);
|
||||||
update_ip4_routing (self, TRUE);
|
update_ip4_routing (self, TRUE);
|
||||||
update_system_hostname (self, "ip4 conf");
|
update_system_hostname (self, "ip4 conf");
|
||||||
} else {
|
} else {
|
||||||
/* Old configs get removed immediately */
|
/* Old configs get removed immediately */
|
||||||
if (old_config)
|
if (old_config)
|
||||||
nm_dns_manager_remove_ip4_config (priv->dns_manager, old_config);
|
nm_dns_manager_remove_ip_config (priv->dns_manager, old_config);
|
||||||
}
|
}
|
||||||
|
|
||||||
nm_dns_manager_end_updates (priv->dns_manager, __func__);
|
nm_dns_manager_end_updates (priv->dns_manager, __func__);
|
||||||
|
|
@ -1939,17 +1925,17 @@ device_ip6_config_changed (NMDevice *device,
|
||||||
if (nm_device_get_state (device) == NM_DEVICE_STATE_ACTIVATED) {
|
if (nm_device_get_state (device) == NM_DEVICE_STATE_ACTIVATED) {
|
||||||
if (old_config != new_config) {
|
if (old_config != new_config) {
|
||||||
if (old_config)
|
if (old_config)
|
||||||
nm_dns_manager_remove_ip6_config (priv->dns_manager, old_config);
|
nm_dns_manager_remove_ip_config (priv->dns_manager, old_config);
|
||||||
if (new_config)
|
if (new_config)
|
||||||
nm_dns_manager_add_ip6_config (priv->dns_manager, ip_iface, new_config, NM_DNS_IP_CONFIG_TYPE_DEFAULT);
|
nm_dns_manager_add_ip_config (priv->dns_manager, ip_iface, new_config, NM_DNS_IP_CONFIG_TYPE_DEFAULT);
|
||||||
}
|
}
|
||||||
update_ip6_dns (self, priv->dns_manager);
|
update_ip_dns (self, AF_INET6);
|
||||||
update_ip6_routing (self, TRUE);
|
update_ip6_routing (self, TRUE);
|
||||||
update_system_hostname (self, "ip6 conf");
|
update_system_hostname (self, "ip6 conf");
|
||||||
} else {
|
} else {
|
||||||
/* Old configs get removed immediately */
|
/* Old configs get removed immediately */
|
||||||
if (old_config)
|
if (old_config)
|
||||||
nm_dns_manager_remove_ip6_config (priv->dns_manager, old_config);
|
nm_dns_manager_remove_ip_config (priv->dns_manager, old_config);
|
||||||
}
|
}
|
||||||
|
|
||||||
nm_dns_manager_end_updates (priv->dns_manager, __func__);
|
nm_dns_manager_end_updates (priv->dns_manager, __func__);
|
||||||
|
|
@ -2055,11 +2041,11 @@ vpn_connection_activated (NMPolicy *self, NMVpnConnection *vpn)
|
||||||
|
|
||||||
ip4_config = nm_vpn_connection_get_ip4_config (vpn);
|
ip4_config = nm_vpn_connection_get_ip4_config (vpn);
|
||||||
if (ip4_config)
|
if (ip4_config)
|
||||||
nm_dns_manager_add_ip4_config (priv->dns_manager, ip_iface, ip4_config, NM_DNS_IP_CONFIG_TYPE_VPN);
|
nm_dns_manager_add_ip_config (priv->dns_manager, ip_iface, ip4_config, NM_DNS_IP_CONFIG_TYPE_VPN);
|
||||||
|
|
||||||
ip6_config = nm_vpn_connection_get_ip6_config (vpn);
|
ip6_config = nm_vpn_connection_get_ip6_config (vpn);
|
||||||
if (ip6_config)
|
if (ip6_config)
|
||||||
nm_dns_manager_add_ip6_config (priv->dns_manager, ip_iface, ip6_config, NM_DNS_IP_CONFIG_TYPE_VPN);
|
nm_dns_manager_add_ip_config (priv->dns_manager, ip_iface, ip6_config, NM_DNS_IP_CONFIG_TYPE_VPN);
|
||||||
|
|
||||||
update_routing_and_dns (self, TRUE);
|
update_routing_and_dns (self, TRUE);
|
||||||
|
|
||||||
|
|
@ -2078,13 +2064,13 @@ vpn_connection_deactivated (NMPolicy *self, NMVpnConnection *vpn)
|
||||||
ip4_config = nm_vpn_connection_get_ip4_config (vpn);
|
ip4_config = nm_vpn_connection_get_ip4_config (vpn);
|
||||||
if (ip4_config) {
|
if (ip4_config) {
|
||||||
/* Remove the VPN connection's IP4 config from DNS */
|
/* Remove the VPN connection's IP4 config from DNS */
|
||||||
nm_dns_manager_remove_ip4_config (priv->dns_manager, ip4_config);
|
nm_dns_manager_remove_ip_config (priv->dns_manager, ip4_config);
|
||||||
}
|
}
|
||||||
|
|
||||||
ip6_config = nm_vpn_connection_get_ip6_config (vpn);
|
ip6_config = nm_vpn_connection_get_ip6_config (vpn);
|
||||||
if (ip6_config) {
|
if (ip6_config) {
|
||||||
/* Remove the VPN connection's IP6 config from DNS */
|
/* Remove the VPN connection's IP6 config from DNS */
|
||||||
nm_dns_manager_remove_ip6_config (priv->dns_manager, ip6_config);
|
nm_dns_manager_remove_ip_config (priv->dns_manager, ip6_config);
|
||||||
}
|
}
|
||||||
|
|
||||||
update_routing_and_dns (self, TRUE);
|
update_routing_and_dns (self, TRUE);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue