Skip to content

Commit f0f5d69

Browse files
committed
generator: use keep-configuration for NM
Network Manager will create external connection profiles for existing interfaces. There are cases where it will happen, in particular with virtual interfaces, during "netplan apply" even for interfaces that have profiles. "keep-configuration" forces NM to use the most appropriate profile for existing interfaces.
1 parent e0e8711 commit f0f5d69

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/generate.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,9 +304,20 @@ int main(int argc, char** argv)
304304

305305
/* Disable /usr/lib/NetworkManager/conf.d/10-globally-managed-devices.conf
306306
* (which restricts NM to wifi and wwan) if "renderer: NetworkManager" is used anywhere */
307-
if (netplan_state_get_backend(np_state) == NETPLAN_BACKEND_NM || any_nm)
307+
if (netplan_state_get_backend(np_state) == NETPLAN_BACKEND_NM || any_nm) {
308308
_netplan_g_string_free_to_file(g_string_new(NULL), rootdir, "/run/NetworkManager/conf.d/10-globally-managed-devices.conf", NULL);
309309

310+
/*
311+
* Always try to match existing interfaces with connections.
312+
* Because "netplan apply" is too aggressive with Network Manager connections it might
313+
* create in-memory profiles for existing virtual interfaces.
314+
* keep-configuration forces NM to use existing connection profiles for these interfaces avoiding
315+
* this problem.
316+
*/
317+
_netplan_g_string_free_to_file(g_string_new("[device]\nkeep-configuration=no\n"), rootdir,
318+
"/run/NetworkManager/conf.d/10-keep-configuration.conf", NULL);
319+
}
320+
310321
gboolean enable_wait_online = FALSE;
311322
if (any_networkd)
312323
enable_wait_online = _netplan_networkd_write_wait_online(np_state, rootdir);

src/nm.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,8 +1185,11 @@ _netplan_nm_cleanup(const char* rootdir)
11851185
"/run/NetworkManager/conf.d/netplan.conf", NULL);
11861186
g_autofree char* global_manage_path = g_strjoin(NULL, rootdir != NULL ? rootdir : "",
11871187
"/run/NetworkManager/conf.d/10-globally-managed-devices.conf", NULL);
1188+
g_autofree char* keep_configuration_path = g_strjoin(NULL, rootdir != NULL ? rootdir : "",
1189+
"/run/NetworkManager/conf.d/10-keep-configuration.conf", NULL);
11881190
unlink(confpath);
11891191
unlink(global_manage_path);
1192+
unlink(keep_configuration_path);
11901193
_netplan_unlink_glob(rootdir, "/run/NetworkManager/system-connections/netplan-*");
11911194
return TRUE;
11921195
}

0 commit comments

Comments
 (0)