From 1ee28ba989d2017a5105c7af3f85e7a676de47f9 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 5 Aug 2015 10:15:20 +0200 Subject: [PATCH] device: only 'ignore-auto-routes' and 'ignore-auto-dns' for certain settings During merge_and_apply(), we merge several NMIPxConfig into a new @composite. For 'ignore-auto-routes' and 'ignore-auto-dns', we want to prevent certain routes/dns-settings to be merged. But it is wrong to reject settings from all partial configs. For example, especially ext_ipx_config and vpn_ipx_config contain routes that we still must merge and preserve. This was recently changed by 79630c11e502c3b0b958abc0b1b5d777a3db2a98 and previously by ab6548c62134518ba2871306397e7fb9c84260ca. But it was wrong for a long time already. Also note, that nm_ip4_config_merge() now also ignores NIS, WINS, and dns-options. https://bugzilla.gnome.org/show_bug.cgi?id=752546 Fixes: 79630c11e502c3b0b958abc0b1b5d777a3db2a98 (cherry picked from commit 43e6f6a1784f82a2e65d71fd4ab60415858ba823) --- src/devices/nm-device.c | 89 +++++++++++++++++++++++------------------ 1 file changed, 49 insertions(+), 40 deletions(-) diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index cd87a3c7f7..ad41b6147c 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -3238,6 +3238,8 @@ ip4_config_merge_and_apply (NMDevice *self, guint32 gateway; gboolean connection_has_default_route, connection_is_never_default; gboolean routes_full_sync; + gboolean ignore_auto_routes = FALSE; + gboolean ignore_auto_dns = FALSE; /* Merge all the configs into the composite config */ if (config) { @@ -3245,13 +3247,27 @@ ip4_config_merge_and_apply (NMDevice *self, priv->dev_ip4_config = g_object_ref (config); } + /* Apply ignore-auto-routes and ignore-auto-dns settings */ + connection = nm_device_get_connection (self); + if (connection) { + NMSettingIPConfig *s_ip4 = nm_connection_get_setting_ip4_config (connection); + + if (s_ip4) { + ignore_auto_routes = nm_setting_ip_config_get_ignore_auto_routes (s_ip4); + ignore_auto_dns = nm_setting_ip_config_get_ignore_auto_dns (s_ip4); + } + } + composite = nm_ip4_config_new (); if (commit) ensure_con_ip4_config (self); - if (priv->dev_ip4_config) - nm_ip4_config_merge (composite, priv->dev_ip4_config, NM_IP_CONFIG_MERGE_DEFAULT); + if (priv->dev_ip4_config) { + nm_ip4_config_merge (composite, priv->dev_ip4_config, + (ignore_auto_routes ? NM_IP_CONFIG_MERGE_NO_ROUTES : 0) + | (ignore_auto_dns ? NM_IP_CONFIG_MERGE_NO_DNS : 0)); + } if (priv->vpn4_config) nm_ip4_config_merge (composite, priv->vpn4_config, NM_IP_CONFIG_MERGE_DEFAULT); if (priv->ext_ip4_config) @@ -3260,23 +3276,10 @@ ip4_config_merge_and_apply (NMDevice *self, /* Merge WWAN config *last* to ensure modem-given settings overwrite * any external stuff set by pppd or other scripts. */ - if (priv->wwan_ip4_config) - nm_ip4_config_merge (composite, priv->wwan_ip4_config, NM_IP_CONFIG_MERGE_DEFAULT); - - /* Apply ignore-auto-routes and ignore-auto-dns settings */ - connection = nm_device_get_connection (self); - if (connection) { - NMSettingIPConfig *s_ip4 = nm_connection_get_setting_ip4_config (connection); - - if (s_ip4) { - if (nm_setting_ip_config_get_ignore_auto_routes (s_ip4)) - nm_ip4_config_reset_routes (composite); - if (nm_setting_ip_config_get_ignore_auto_dns (s_ip4)) { - nm_ip4_config_reset_nameservers (composite); - nm_ip4_config_reset_domains (composite); - nm_ip4_config_reset_searches (composite); - } - } + if (priv->wwan_ip4_config) { + nm_ip4_config_merge (composite, priv->wwan_ip4_config, + (ignore_auto_routes ? NM_IP_CONFIG_MERGE_NO_ROUTES : 0) + | (ignore_auto_dns ? NM_IP_CONFIG_MERGE_NO_DNS : 0)); } /* Merge user overrides into the composite config. For assumed connections, @@ -3865,6 +3868,19 @@ ip6_config_merge_and_apply (NMDevice *self, const struct in6_addr *gateway; gboolean connection_has_default_route, connection_is_never_default; gboolean routes_full_sync; + gboolean ignore_auto_routes = FALSE; + gboolean ignore_auto_dns = FALSE; + + /* Apply ignore-auto-routes and ignore-auto-dns settings */ + connection = nm_device_get_connection (self); + if (connection) { + NMSettingIPConfig *s_ip6 = nm_connection_get_setting_ip6_config (connection); + + if (s_ip6) { + ignore_auto_routes = nm_setting_ip_config_get_ignore_auto_routes (s_ip6); + ignore_auto_dns = nm_setting_ip_config_get_ignore_auto_dns (s_ip6); + } + } /* If no config was passed in, create a new one */ composite = nm_ip6_config_new (); @@ -3873,10 +3889,16 @@ ip6_config_merge_and_apply (NMDevice *self, ensure_con_ip6_config (self); /* Merge all the IP configs into the composite config */ - if (priv->ac_ip6_config) - nm_ip6_config_merge (composite, priv->ac_ip6_config, NM_IP_CONFIG_MERGE_DEFAULT); - if (priv->dhcp6_ip6_config) - nm_ip6_config_merge (composite, priv->dhcp6_ip6_config, NM_IP_CONFIG_MERGE_DEFAULT); + if (priv->ac_ip6_config) { + nm_ip6_config_merge (composite, priv->ac_ip6_config, + (ignore_auto_routes ? NM_IP_CONFIG_MERGE_NO_ROUTES : 0) + | (ignore_auto_dns ? NM_IP_CONFIG_MERGE_NO_DNS : 0)); + } + if (priv->dhcp6_ip6_config) { + nm_ip6_config_merge (composite, priv->dhcp6_ip6_config, + (ignore_auto_routes ? NM_IP_CONFIG_MERGE_NO_ROUTES : 0) + | (ignore_auto_dns ? NM_IP_CONFIG_MERGE_NO_DNS : 0)); + } if (priv->vpn6_config) nm_ip6_config_merge (composite, priv->vpn6_config, NM_IP_CONFIG_MERGE_DEFAULT); if (priv->ext_ip6_config) @@ -3885,23 +3907,10 @@ ip6_config_merge_and_apply (NMDevice *self, /* Merge WWAN config *last* to ensure modem-given settings overwrite * any external stuff set by pppd or other scripts. */ - if (priv->wwan_ip6_config) - nm_ip6_config_merge (composite, priv->wwan_ip6_config, NM_IP_CONFIG_MERGE_DEFAULT); - - /* Apply ignore-auto-routes and ignore-auto-dns settings */ - connection = nm_device_get_connection (self); - if (connection) { - NMSettingIPConfig *s_ip6 = nm_connection_get_setting_ip6_config (connection); - - if (s_ip6) { - if (nm_setting_ip_config_get_ignore_auto_routes (s_ip6)) - nm_ip6_config_reset_routes (composite); - if (nm_setting_ip_config_get_ignore_auto_dns (s_ip6)) { - nm_ip6_config_reset_nameservers (composite); - nm_ip6_config_reset_domains (composite); - nm_ip6_config_reset_searches (composite); - } - } + if (priv->wwan_ip6_config) { + nm_ip6_config_merge (composite, priv->wwan_ip6_config, + (ignore_auto_routes ? NM_IP_CONFIG_MERGE_NO_ROUTES : 0) + | (ignore_auto_dns ? NM_IP_CONFIG_MERGE_NO_DNS : 0)); } /* Merge user overrides into the composite config. For assumed connections,