diff --git a/man/NetworkManager.conf.xml b/man/NetworkManager.conf.xml index 3ef5d3dc5a..819c051e20 100644 --- a/man/NetworkManager.conf.xml +++ b/man/NetworkManager.conf.xml @@ -1150,6 +1150,44 @@ managed=1 + + keep-configuration + + + On startup, NetworkManager tries to not interfere with + interfaces that are already configured. It does so by + generating a in-memory connection based on the interface + current configuration. + + + If this generated connection matches one of the existing + persistent connections, the persistent connection gets + activated. If there is no match, the generated + connection gets activated as "external", which means + that the connection is considered as active, but + NetworkManager doesn't actually touch the interface. + + + It is possible to disable this behavior by setting + keep-configuration to + no. In this way, on startup + NetworkManager always tries to activate the most + suitable persistent connection (the one with highest + autoconnect-priority or, in case of a tie, the one + activated most recently). + + + Note that when NetworkManager gets restarted, it stores + the previous state in + /run/NetworkManager; in particular + it saves the UUID of the connection that was previously + active so that it can be activated again after the + restart. Therefore, + keep-configuration does not have + any effect on service restart. + + + wifi.scan-rand-mac-address diff --git a/src/core/nm-config.c b/src/core/nm-config.c index 94ec7f381b..981950ff70 100644 --- a/src/core/nm-config.c +++ b/src/core/nm-config.c @@ -878,6 +878,7 @@ static const ConfigGroup config_groups[] = { NM_CONFIG_KEYFILE_KEY_DEVICE_IGNORE_CARRIER, NM_CONFIG_KEYFILE_KEY_DEVICE_MANAGED, NM_CONFIG_KEYFILE_KEY_DEVICE_SRIOV_NUM_VFS, + NM_CONFIG_KEYFILE_KEY_DEVICE_KEEP_CONFIGURATION, NM_CONFIG_KEYFILE_KEY_DEVICE_WIFI_BACKEND, NM_CONFIG_KEYFILE_KEY_DEVICE_WIFI_SCAN_RAND_MAC_ADDRESS, NM_CONFIG_KEYFILE_KEY_DEVICE_WIFI_SCAN_GENERATE_MAC_ADDRESS_MASK, diff --git a/src/core/nm-manager.c b/src/core/nm-manager.c index 978cf09d0e..d859c1eaae 100644 --- a/src/core/nm-manager.c +++ b/src/core/nm-manager.c @@ -2632,28 +2632,41 @@ get_existing_connection(NMManager *self, NMDevice *device, gboolean *out_generat } } - /* The core of the API is nm_device_generate_connection() function, based on - * update_connection() virtual method and the @connection_type_supported - * class attribute. Devices that support assuming existing connections must - * have update_connection() implemented, otherwise - * nm_device_generate_connection() returns NULL. */ - connection = nm_device_generate_connection(device, master, &maybe_later, &gen_error); - if (!connection) { - if (maybe_later) { - /* The device can potentially assume connections, but at this - * time there are no addresses configured and we can't generate - * a connection. Allow the device to assume a connection indicated - * in the state file by UUID. */ - only_by_uuid = TRUE; - } else { - /* The device can't assume connections */ - nm_device_assume_state_reset(device); - _LOG2D(LOGD_DEVICE, - device, - "assume: cannot generate connection: %s", - gen_error->message); - return NULL; + if (nm_config_data_get_device_config_boolean(NM_CONFIG_GET_DATA, + NM_CONFIG_KEYFILE_KEY_DEVICE_KEEP_CONFIGURATION, + device, + TRUE, + TRUE)) { + /* The core of the API is nm_device_generate_connection() function, based on + * update_connection() virtual method and the @connection_type_supported + * class attribute. Devices that support assuming existing connections must + * have update_connection() implemented, otherwise + * nm_device_generate_connection() returns NULL. */ + connection = nm_device_generate_connection(device, master, &maybe_later, &gen_error); + if (!connection) { + if (maybe_later) { + /* The device can potentially assume connections, but at this + * time we can't generate a connection because no address is + * configured. Allow the device to assume a connection indicated + * in the state file by UUID. */ + only_by_uuid = TRUE; + } else { + nm_device_assume_state_reset(device); + _LOG2D(LOGD_DEVICE, + device, + "assume: cannot generate connection: %s", + gen_error->message); + return NULL; + } } + } else { + connection = NULL; + only_by_uuid = TRUE; + g_set_error(&gen_error, + NM_DEVICE_ERROR, + NM_DEVICE_ERROR_FAILED, + "device %s has 'keep-configuration=no'", + nm_device_get_iface(device)); } nm_device_assume_state_get(device, &assume_state_guess_assume, &assume_state_connection_uuid); diff --git a/src/libnm-base/nm-config-base.h b/src/libnm-base/nm-config-base.h index 7a23875a43..9ef5d7f846 100644 --- a/src/libnm-base/nm-config-base.h +++ b/src/libnm-base/nm-config-base.h @@ -62,6 +62,7 @@ #define NM_CONFIG_KEYFILE_KEY_DEVICE_MANAGED "managed" #define NM_CONFIG_KEYFILE_KEY_DEVICE_IGNORE_CARRIER "ignore-carrier" #define NM_CONFIG_KEYFILE_KEY_DEVICE_SRIOV_NUM_VFS "sriov-num-vfs" +#define NM_CONFIG_KEYFILE_KEY_DEVICE_KEEP_CONFIGURATION "keep-configuration" #define NM_CONFIG_KEYFILE_KEY_DEVICE_WIFI_BACKEND "wifi.backend" #define NM_CONFIG_KEYFILE_KEY_DEVICE_WIFI_SCAN_RAND_MAC_ADDRESS "wifi.scan-rand-mac-address" #define NM_CONFIG_KEYFILE_KEY_DEVICE_WIFI_SCAN_GENERATE_MAC_ADDRESS_MASK \