Commit 55811722 authored by Thomas Haller's avatar Thomas Haller

device: merge branch 'th/device-ignore-auto-bgo752546'

https://bugzilla.gnome.org/show_bug.cgi?id=752546
parents 54d10f0e 43e6f6a1
......@@ -3427,6 +3427,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) {
......@@ -3434,44 +3436,45 @@ 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 (nm_device_get_ip_ifindex (self));
if (commit)
ensure_con_ip4_config (self);
if (priv->dev_ip4_config)
nm_ip4_config_merge (composite, priv->dev_ip4_config);
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_ip4_config_merge (composite, priv->vpn4_config, NM_IP_CONFIG_MERGE_DEFAULT);
if (priv->ext_ip4_config)
nm_ip4_config_merge (composite, priv->ext_ip4_config);
nm_ip4_config_merge (composite, priv->ext_ip4_config, NM_IP_CONFIG_MERGE_DEFAULT);
/* 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);
/* 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,
* con_ip4_config is empty. */
if (priv->con_ip4_config)
nm_ip4_config_merge (composite, priv->con_ip4_config);
nm_ip4_config_merge (composite, priv->con_ip4_config, NM_IP_CONFIG_MERGE_DEFAULT);
/* Add the default route.
......@@ -4039,6 +4042,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 (nm_device_get_ip_ifindex (self));
......@@ -4048,41 +4064,34 @@ ip6_config_merge_and_apply (NMDevice *self,
g_assert (composite);
/* Merge all the IP configs into the composite config */
if (priv->ac_ip6_config)
nm_ip6_config_merge (composite, priv->ac_ip6_config);
if (priv->dhcp6_ip6_config)
nm_ip6_config_merge (composite, priv->dhcp6_ip6_config);
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_ip6_config_merge (composite, priv->vpn6_config, NM_IP_CONFIG_MERGE_DEFAULT);
if (priv->ext_ip6_config)
nm_ip6_config_merge (composite, priv->ext_ip6_config);
nm_ip6_config_merge (composite, priv->ext_ip6_config, NM_IP_CONFIG_MERGE_DEFAULT);
/* 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);
/* 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,
* con_ip6_config is empty. */
if (priv->con_ip6_config)
nm_ip6_config_merge (composite, priv->con_ip6_config);
nm_ip6_config_merge (composite, priv->con_ip6_config, NM_IP_CONFIG_MERGE_DEFAULT);
/* Add the default route.
*
......
......@@ -101,7 +101,7 @@ dhcp4_state_changed (NMDhcpClient *client,
if (last_config)
nm_ip4_config_subtract (existing, last_config);
nm_ip4_config_merge (existing, ip4_config);
nm_ip4_config_merge (existing, ip4_config, NM_IP_CONFIG_MERGE_DEFAULT);
if (!nm_ip4_config_commit (existing, ifindex, TRUE, global_opt.priority_v4))
nm_log_warn (LOGD_DHCP4, "(%s): failed to apply DHCPv4 config", global_opt.ifname);
......@@ -238,7 +238,7 @@ rdisc_config_changed (NMRDisc *rdisc, NMRDiscConfigMap changed, gpointer user_da
if (last_config)
nm_ip6_config_subtract (existing, last_config);
nm_ip6_config_merge (existing, ip6_config);
nm_ip6_config_merge (existing, ip6_config, NM_IP_CONFIG_MERGE_DEFAULT);
if (!nm_ip6_config_commit (existing, ifindex, TRUE))
nm_log_warn (LOGD_IP6, "(%s): failed to apply IPv6 config", global_opt.ifname);
......
......@@ -35,6 +35,7 @@
#include "nm-core-internal.h"
#include "nm-route-manager.h"
#include "nm-core-internal.h"
#include "nm-macros-internal.h"
G_DEFINE_TYPE (NMIP4Config, nm_ip4_config, NM_TYPE_EXPORTED_OBJECT)
......@@ -562,7 +563,7 @@ nm_ip4_config_create_setting (const NMIP4Config *config)
/******************************************************************/
void
nm_ip4_config_merge (NMIP4Config *dst, const NMIP4Config *src)
nm_ip4_config_merge (NMIP4Config *dst, const NMIP4Config *src, NMIPConfigMergeFlags merge_flags)
{
NMIP4ConfigPrivate *dst_priv, *src_priv;
guint32 i;
......@@ -580,16 +581,20 @@ nm_ip4_config_merge (NMIP4Config *dst, const NMIP4Config *src)
nm_ip4_config_add_address (dst, nm_ip4_config_get_address (src, i));
/* nameservers */
for (i = 0; i < nm_ip4_config_get_num_nameservers (src); i++)
nm_ip4_config_add_nameserver (dst, nm_ip4_config_get_nameserver (src, i));
if (!NM_FLAGS_HAS (merge_flags, NM_IP_CONFIG_MERGE_NO_DNS)) {
for (i = 0; i < nm_ip4_config_get_num_nameservers (src); i++)
nm_ip4_config_add_nameserver (dst, nm_ip4_config_get_nameserver (src, i));
}
/* default gateway */
if (nm_ip4_config_has_gateway (src))
nm_ip4_config_set_gateway (dst, nm_ip4_config_get_gateway (src));
/* routes */
for (i = 0; i < nm_ip4_config_get_num_routes (src); i++)
nm_ip4_config_add_route (dst, nm_ip4_config_get_route (src, i));
if (!NM_FLAGS_HAS (merge_flags, NM_IP_CONFIG_MERGE_NO_ROUTES)) {
for (i = 0; i < nm_ip4_config_get_num_routes (src); i++)
nm_ip4_config_add_route (dst, nm_ip4_config_get_route (src, i));
}
if (dst_priv->route_metric == -1)
dst_priv->route_metric = src_priv->route_metric;
......@@ -597,16 +602,22 @@ nm_ip4_config_merge (NMIP4Config *dst, const NMIP4Config *src)
dst_priv->route_metric = MIN (dst_priv->route_metric, src_priv->route_metric);
/* domains */
for (i = 0; i < nm_ip4_config_get_num_domains (src); i++)
nm_ip4_config_add_domain (dst, nm_ip4_config_get_domain (src, i));
if (!NM_FLAGS_HAS (merge_flags, NM_IP_CONFIG_MERGE_NO_DNS)) {
for (i = 0; i < nm_ip4_config_get_num_domains (src); i++)
nm_ip4_config_add_domain (dst, nm_ip4_config_get_domain (src, i));
}
/* dns searches */
for (i = 0; i < nm_ip4_config_get_num_searches (src); i++)
nm_ip4_config_add_search (dst, nm_ip4_config_get_search (src, i));
if (!NM_FLAGS_HAS (merge_flags, NM_IP_CONFIG_MERGE_NO_DNS)) {
for (i = 0; i < nm_ip4_config_get_num_searches (src); i++)
nm_ip4_config_add_search (dst, nm_ip4_config_get_search (src, i));
}
/* dns options */
for (i = 0; i < nm_ip4_config_get_num_dns_options (src); i++)
nm_ip4_config_add_dns_option (dst, nm_ip4_config_get_dns_option (src, i));
if (!NM_FLAGS_HAS (merge_flags, NM_IP_CONFIG_MERGE_NO_DNS)) {
for (i = 0; i < nm_ip4_config_get_num_dns_options (src); i++)
nm_ip4_config_add_dns_option (dst, nm_ip4_config_get_dns_option (src, i));
}
/* MSS */
if (nm_ip4_config_get_mss (src))
......@@ -618,15 +629,19 @@ nm_ip4_config_merge (NMIP4Config *dst, const NMIP4Config *src)
nm_ip4_config_get_mtu_source (src));
/* NIS */
for (i = 0; i < nm_ip4_config_get_num_nis_servers (src); i++)
nm_ip4_config_add_nis_server (dst, nm_ip4_config_get_nis_server (src, i));
if (!NM_FLAGS_HAS (merge_flags, NM_IP_CONFIG_MERGE_NO_DNS)) {
for (i = 0; i < nm_ip4_config_get_num_nis_servers (src); i++)
nm_ip4_config_add_nis_server (dst, nm_ip4_config_get_nis_server (src, i));
if (nm_ip4_config_get_nis_domain (src))
nm_ip4_config_set_nis_domain (dst, nm_ip4_config_get_nis_domain (src));
if (nm_ip4_config_get_nis_domain (src))
nm_ip4_config_set_nis_domain (dst, nm_ip4_config_get_nis_domain (src));
}
/* WINS */
for (i = 0; i < nm_ip4_config_get_num_wins (src); i++)
nm_ip4_config_add_wins (dst, nm_ip4_config_get_wins (src, i));
if (!NM_FLAGS_HAS (merge_flags, NM_IP_CONFIG_MERGE_NO_DNS)) {
for (i = 0; i < nm_ip4_config_get_num_wins (src); i++)
nm_ip4_config_add_wins (dst, nm_ip4_config_get_wins (src, i));
}
/* metered flag */
nm_ip4_config_set_metered (dst, nm_ip4_config_get_metered (dst) ||
......
......@@ -70,7 +70,7 @@ void nm_ip4_config_merge_setting (NMIP4Config *config, NMSettingIPConfig *settin
NMSetting *nm_ip4_config_create_setting (const NMIP4Config *config);
/* Utility functions */
void nm_ip4_config_merge (NMIP4Config *dst, const NMIP4Config *src);
void nm_ip4_config_merge (NMIP4Config *dst, const NMIP4Config *src, NMIPConfigMergeFlags merge_flags);
void nm_ip4_config_subtract (NMIP4Config *dst, const NMIP4Config *src);
void nm_ip4_config_intersect (NMIP4Config *dst, const NMIP4Config *src);
gboolean nm_ip4_config_replace (NMIP4Config *dst, const NMIP4Config *src, gboolean *relevant_changes);
......
......@@ -34,6 +34,7 @@
#include "nm-route-manager.h"
#include "nm-core-internal.h"
#include "NetworkManagerUtils.h"
#include "nm-macros-internal.h"
G_DEFINE_TYPE (NMIP6Config, nm_ip6_config, NM_TYPE_EXPORTED_OBJECT)
......@@ -640,7 +641,7 @@ nm_ip6_config_create_setting (const NMIP6Config *config)
/******************************************************************/
void
nm_ip6_config_merge (NMIP6Config *dst, const NMIP6Config *src)
nm_ip6_config_merge (NMIP6Config *dst, const NMIP6Config *src, NMIPConfigMergeFlags merge_flags)
{
NMIP6ConfigPrivate *dst_priv, *src_priv;
guint32 i;
......@@ -666,8 +667,10 @@ nm_ip6_config_merge (NMIP6Config *dst, const NMIP6Config *src)
nm_ip6_config_set_gateway (dst, nm_ip6_config_get_gateway (src));
/* routes */
for (i = 0; i < nm_ip6_config_get_num_routes (src); i++)
nm_ip6_config_add_route (dst, nm_ip6_config_get_route (src, i));
if (!NM_FLAGS_HAS (merge_flags, NM_IP_CONFIG_MERGE_NO_ROUTES)) {
for (i = 0; i < nm_ip6_config_get_num_routes (src); i++)
nm_ip6_config_add_route (dst, nm_ip6_config_get_route (src, i));
}
if (dst_priv->route_metric == -1)
dst_priv->route_metric = src_priv->route_metric;
......@@ -675,16 +678,22 @@ nm_ip6_config_merge (NMIP6Config *dst, const NMIP6Config *src)
dst_priv->route_metric = MIN (dst_priv->route_metric, src_priv->route_metric);
/* domains */
for (i = 0; i < nm_ip6_config_get_num_domains (src); i++)
nm_ip6_config_add_domain (dst, nm_ip6_config_get_domain (src, i));
if (!NM_FLAGS_HAS (merge_flags, NM_IP_CONFIG_MERGE_NO_DNS)) {
for (i = 0; i < nm_ip6_config_get_num_domains (src); i++)
nm_ip6_config_add_domain (dst, nm_ip6_config_get_domain (src, i));
}
/* dns searches */
for (i = 0; i < nm_ip6_config_get_num_searches (src); i++)
nm_ip6_config_add_search (dst, nm_ip6_config_get_search (src, i));
if (!NM_FLAGS_HAS (merge_flags, NM_IP_CONFIG_MERGE_NO_DNS)) {
for (i = 0; i < nm_ip6_config_get_num_searches (src); i++)
nm_ip6_config_add_search (dst, nm_ip6_config_get_search (src, i));
}
/* dns options */
for (i = 0; i < nm_ip6_config_get_num_dns_options (src); i++)
nm_ip6_config_add_dns_option (dst, nm_ip6_config_get_dns_option (src, i));
if (!NM_FLAGS_HAS (merge_flags, NM_IP_CONFIG_MERGE_NO_DNS)) {
for (i = 0; i < nm_ip6_config_get_num_dns_options (src); i++)
nm_ip6_config_add_dns_option (dst, nm_ip6_config_get_dns_option (src, i));
}
if (nm_ip6_config_get_mss (src))
nm_ip6_config_set_mss (dst, nm_ip6_config_get_mss (src));
......
......@@ -71,7 +71,7 @@ void nm_ip6_config_merge_setting (NMIP6Config *config, NMSettingIPConfig *settin
NMSetting *nm_ip6_config_create_setting (const NMIP6Config *config);
/* Utility functions */
void nm_ip6_config_merge (NMIP6Config *dst, const NMIP6Config *src);
void nm_ip6_config_merge (NMIP6Config *dst, const NMIP6Config *src, NMIPConfigMergeFlags merge_flags);
void nm_ip6_config_subtract (NMIP6Config *dst, const NMIP6Config *src);
void nm_ip6_config_intersect (NMIP6Config *dst, const NMIP6Config *src);
gboolean nm_ip6_config_replace (NMIP6Config *dst, const NMIP6Config *src, gboolean *relevant_changes);
......
......@@ -132,6 +132,12 @@ typedef enum {
NMP_OBJECT_TYPE_MAX = __NMP_OBJECT_TYPE_LAST - 1,
} NMPObjectType;
typedef enum {
NM_IP_CONFIG_MERGE_DEFAULT = 0,
NM_IP_CONFIG_MERGE_NO_ROUTES = (1LL << 0),
NM_IP_CONFIG_MERGE_NO_DNS = (1LL << 1),
} NMIPConfigMergeFlags;
/* settings */
typedef struct _NMAgentManager NMAgentManager;
typedef struct _NMSecretAgent NMSecretAgent;
......
......@@ -318,12 +318,12 @@ test_merge_subtract_mss_mtu (void)
nm_ip4_config_set_mss (cfg3, expected_mss3);
nm_ip4_config_set_mtu (cfg3, expected_mtu3, NM_IP_CONFIG_SOURCE_UNKNOWN);
nm_ip4_config_merge (cfg1, cfg2);
nm_ip4_config_merge (cfg1, cfg2, NM_IP_CONFIG_MERGE_DEFAULT);
/* ensure MSS and MTU are in cfg1 */
g_assert_cmpuint (nm_ip4_config_get_mss (cfg1), ==, expected_mss2);
g_assert_cmpuint (nm_ip4_config_get_mtu (cfg1), ==, expected_mtu2);
nm_ip4_config_merge (cfg1, cfg3);
nm_ip4_config_merge (cfg1, cfg3, NM_IP_CONFIG_MERGE_DEFAULT);
/* ensure again the MSS and MTU in cfg1 got overriden */
g_assert_cmpuint (nm_ip4_config_get_mss (cfg1), ==, expected_mss3);
g_assert_cmpuint (nm_ip4_config_get_mtu (cfg1), ==, expected_mtu3);
......
......@@ -919,12 +919,12 @@ apply_parent_device_config (NMVpnConnection *connection)
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_ip4_config_merge (vpn4_parent_config, priv->ip4_config, NM_IP_CONFIG_MERGE_DEFAULT);
nm_ip4_config_set_gateway (vpn4_parent_config, 0);
}
if (priv->ip6_config) {
vpn6_parent_config = nm_ip6_config_new (ifindex);
nm_ip6_config_merge (vpn6_parent_config, priv->ip6_config);
nm_ip6_config_merge (vpn6_parent_config, priv->ip6_config, NM_IP_CONFIG_MERGE_DEFAULT);
nm_ip6_config_set_gateway (vpn6_parent_config, NULL);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment