summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2015-05-13 21:21:49 +0200
committerThomas Haller <thaller@redhat.com>2015-06-22 10:30:11 +0200
commitd9dac7ab4cd9c98fdf0fb856b587411ee2b598cf (patch)
tree3b7b46c90ea7616a1d8457c2310ec6e9391b79ad
parent29f13ecf66570d4f9240224998325ddf20bfc95b (diff)
downloadNetworkManager-d9dac7ab4cd9c98fdf0fb856b587411ee2b598cf.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 (cherry picked from commit 98e50e358bde29a78d7a9547a21736aa143cd04b)
-rw-r--r--src/devices/nm-device.c38
1 files changed, 34 insertions, 4 deletions
diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c
index c101185830..eba15a32d5 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;
@@ -3170,6 +3172,7 @@ 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) {
@@ -3227,13 +3230,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 ( !connection
- || !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)) {
@@ -3753,6 +3767,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 ();
@@ -3808,13 +3823,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 (absence 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 ( !connection
- || !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)) {
@@ -7632,8 +7658,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);
@@ -8573,7 +8601,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*