summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2015-05-13 21:21:49 +0200
committerThomas Haller <thaller@redhat.com>2015-05-27 12:19:12 +0200
commit2fde3b958b36e9bb82862adbcd2e69f99f6221e4 (patch)
tree58853cbdb3a8db71013f05b059e2d65a17a87183
parentfb2fe469167040d4bd6fcebeff8595311aa72145 (diff)
downloadNetworkManager-2fde3b958b36e9bb82862adbcd2e69f99f6221e4.tar.gz
default-route: for devices with 'never-default' enforce the default-route only once
Since da708059dabb2854d11eed1a403398327b31535b, we would pickup the default-route as configured externally, except at those moments when NM re-applys the IP configuration of the interface, such as during a DHCP lease. That allows the user to add/remove the default-route externally (iproute). But still, at random times (DHCP lease), we will revert those external changes. Extend this, that if the connection is explicitly configured as 'never-default=yes', that it tells NM not to interfere with externally added default-routes on this device. That means, NM will only remove any preexisting default-routes when configuring the device a first time. On any later attempts, NM will assume whatever is configured there. That makes sense because the user indicated not wanting NM to manage a default-route on that device, so if something externally added a default-route, assume that is what the user wants. This only affects non-assumed connections, with 'never-default=yes'. https://bugzilla.redhat.com/show_bug.cgi?id=1205405
-rw-r--r--src/devices/nm-device.c37
1 files changed, 35 insertions, 2 deletions
diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c
index 0a17637e68..826427b346 100644
--- a/src/devices/nm-device.c
+++ b/src/devices/nm-device.c
@@ -257,9 +257,11 @@ typedef struct {
struct {
gboolean v4_has;
gboolean v4_is_assumed;
+ gboolean v4_configure_first_time;
NMPlatformIP4Route v4;
gboolean v6_has;
gboolean v6_is_assumed;
+ gboolean v6_configure_first_time;
NMPlatformIP6Route v6;
} default_route;
@@ -3065,6 +3067,8 @@ ip4_config_merge_and_apply (NMDevice *self,
gboolean has_direct_route;
const guint32 default_route_metric = nm_device_get_ip4_route_metric (self);
guint32 gateway;
+ gboolean connection_has_default_route, connection_is_never_default;
+
/* Merge all the configs into the composite config */
if (config) {
@@ -3122,12 +3126,24 @@ ip4_config_merge_and_apply (NMDevice *self,
if (nm_device_uses_assumed_connection (self))
goto END_ADD_DEFAULT_ROUTE;
+ connection_has_default_route
+ = nm_default_route_manager_ip4_connection_has_default_route (nm_default_route_manager_get (),
+ connection, &connection_is_never_default);
+
+ if ( !priv->default_route.v4_configure_first_time
+ && connection_is_never_default) {
+ /* If the connection is explicitly configured as never-default, we enforce the (absense of the)
+ * default-route only once. That allows the user to configure a connection as never-default,
+ * but he can add default routes externally (via a dispatcher script) and NM will not interfere. */
+ goto END_ADD_DEFAULT_ROUTE;
+ }
/* we are about to commit (for a non-assumed connection). Enforce whatever we have
* configured. */
+ priv->default_route.v4_configure_first_time = FALSE;
priv->default_route.v4_is_assumed = FALSE;
- if (!nm_default_route_manager_ip4_connection_has_default_route (nm_default_route_manager_get (), connection, NULL))
+ if (!connection_has_default_route)
goto END_ADD_DEFAULT_ROUTE;
if (!nm_ip4_config_get_num_addresses (composite)) {
@@ -3647,6 +3663,7 @@ ip6_config_merge_and_apply (NMDevice *self,
NMIP6Config *composite;
gboolean has_direct_route;
const struct in6_addr *gateway;
+ gboolean connection_has_default_route, connection_is_never_default;
/* If no config was passed in, create a new one */
composite = nm_ip6_config_new (nm_device_get_ip_ifindex (self));
@@ -3703,12 +3720,24 @@ ip6_config_merge_and_apply (NMDevice *self,
if (nm_device_uses_assumed_connection (self))
goto END_ADD_DEFAULT_ROUTE;
+ connection_has_default_route
+ = nm_default_route_manager_ip6_connection_has_default_route (nm_default_route_manager_get (),
+ connection, &connection_is_never_default);
+
+ if ( !priv->default_route.v6_configure_first_time
+ && connection_is_never_default) {
+ /* If the connection is explicitly configured as never-default, we enforce the (absense of the)
+ * default-route only once. That allows the user to configure a connection as never-default,
+ * but he can add default routes externally (via a dispatcher script) and NM will not interfere. */
+ goto END_ADD_DEFAULT_ROUTE;
+ }
/* we are about to commit (for a non-assumed connection). Enforce whatever we have
* configured. */
+ priv->default_route.v6_configure_first_time = FALSE;
priv->default_route.v6_is_assumed = FALSE;
- if (!nm_default_route_manager_ip6_connection_has_default_route (nm_default_route_manager_get (), connection, NULL))
+ if (!connection_has_default_route)
goto END_ADD_DEFAULT_ROUTE;
if (!nm_ip6_config_get_num_addresses (composite)) {
@@ -7539,8 +7568,10 @@ _cleanup_generic_post (NMDevice *self, gboolean deconfigure)
priv->default_route.v4_has = FALSE;
priv->default_route.v4_is_assumed = TRUE;
+ priv->default_route.v4_configure_first_time = TRUE;
priv->default_route.v6_has = FALSE;
priv->default_route.v6_is_assumed = TRUE;
+ priv->default_route.v6_configure_first_time = TRUE;
nm_default_route_manager_ip4_update_default_route (nm_default_route_manager_get (), self);
nm_default_route_manager_ip6_update_default_route (nm_default_route_manager_get (), self);
@@ -8490,7 +8521,9 @@ nm_device_init (NMDevice *self)
priv->ip6_saved_properties = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, g_free);
priv->default_route.v4_is_assumed = TRUE;
+ priv->default_route.v4_configure_first_time = TRUE;
priv->default_route.v6_is_assumed = TRUE;
+ priv->default_route.v6_configure_first_time = TRUE;
}
static GObject*