default-route: for devices with 'never-default' enforce the default-route only once

Since da708059da, 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 98e50e358b)
This commit is contained in:
Thomas Haller 2015-05-13 21:21:49 +02:00
parent 29f13ecf66
commit d9dac7ab4c

View file

@ -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*