Merge ~alfonsosanchezbeato/snappy-hwe-snaps/+git/network-manager:fix-route-end-dhcp-lease into ~snappy-hwe-team/snappy-hwe-snaps/+git/network-manager:network-manager/xenial/1.2.2

Proposed by Alfonso Sanchez-Beato
Status: Merged
Approved by: Tony Espy
Approved revision: 06511d90695866218578feeff8740298b1034480
Merged at revision: 06511d90695866218578feeff8740298b1034480
Proposed branch: ~alfonsosanchezbeato/snappy-hwe-snaps/+git/network-manager:fix-route-end-dhcp-lease
Merge into: ~snappy-hwe-team/snappy-hwe-snaps/+git/network-manager:network-manager/xenial/1.2.2
Diff against target: 123 lines (+21/-20)
1 file modified
src/devices/nm-device.c (+21/-20)
Reviewer Review Type Date Requested Status
System Enablement Bot continuous-integration Needs Fixing
Tony Espy Approve
Review via email: mp+361207@code.launchpad.net

Commit message

Make sure default routes survive across expiring of DHCP leases. Commits taken from upstream. Related to LP: #1800712.

Description of the change

Make sure default routes survive across expiring of DHCP leases. Commits taken from upstream. Related to LP: #1800712.

To post a comment you must log in.
Revision history for this message
Tony Espy (awe) wrote :

The bug you reference says:

FTR, this MP would also help here, although the initially proposed fix for the configuration snap should be enough.

It doesn't sound to me like this is *really* needed? Also the RH bug associated with the first commit isn't viewable w/out a login. ;(-

What version of NM did you cherry pick these fixes from?

Would also mind explaining the actual scenario in some more detail?

It sounds like NM is assuming an existing connection from networkd? And that when this happens, and DHCP leases associated with the connection expire, when a DHCP lease is re-acquired the default route wasn't being restored?

Finally, why is networkd involved here at all? Don't we ship a netplan file which makes NM the default renderer?

review: Needs Information
Revision history for this message
Alfonso Sanchez-Beato (alfonsosanchezbeato) wrote :

Actually, both changes (the MP in the bug and this one) solve the issue, the first one by making sure the IP does not survive after networkd does not manage the interface anymore, this one by making sure NM handles well that situation. This MP is for more general cases, so it is good that we land it, it is a bug fix anyway.

The fixes come from branch 1.2 of NM upstream.

The scenario is basically as you describe. Bottom line is that NM finds an IP already existing in the interface, but when it uses DHCP (which it does always when starting) the lease gives a different IP. In that situation, some times the default route is not restored. This is a race which happens maybe 50% of the times. This is what this MP fixes.

We do ship a netplan file that sets NM as the rendered, but on *first boot* networkd takes eth0 until a systemd service that sets the new netplan file does the change of netplan files.

Revision history for this message
Tony Espy (awe) wrote :

Thanks for the explanation!

review: Approve
Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :
review: Needs Fixing (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c
2index 8472ff8..e8da548 100644
3--- a/src/devices/nm-device.c
4+++ b/src/devices/nm-device.c
5@@ -4287,6 +4287,7 @@ ip4_config_merge_and_apply (NMDevice *self,
6 gboolean routes_full_sync;
7 gboolean ignore_auto_routes = FALSE;
8 gboolean ignore_auto_dns = FALSE;
9+ gboolean auto_method = FALSE;
10
11 /* Merge all the configs into the composite config */
12 if (config) {
13@@ -4302,6 +4303,10 @@ ip4_config_merge_and_apply (NMDevice *self,
14 if (s_ip4) {
15 ignore_auto_routes = nm_setting_ip_config_get_ignore_auto_routes (s_ip4);
16 ignore_auto_dns = nm_setting_ip_config_get_ignore_auto_dns (s_ip4);
17+
18+ if (nm_streq0 (nm_setting_ip_config_get_method (s_ip4),
19+ NM_SETTING_IP4_CONFIG_METHOD_AUTO))
20+ auto_method = TRUE;
21 }
22 }
23
24@@ -4357,10 +4362,12 @@ ip4_config_merge_and_apply (NMDevice *self,
25 goto END_ADD_DEFAULT_ROUTE;
26 }
27
28- if (nm_device_uses_generated_assumed_connection (self)) {
29- /* a generate-assumed-connection always detects the default route from platform */
30+ /* a generated-assumed connection detects the default route from the platform,
31+ * but if the IP method is automatic we need to update the default route to
32+ * maintain connectivity.
33+ */
34+ if (nm_device_uses_generated_assumed_connection (self) && !auto_method)
35 goto END_ADD_DEFAULT_ROUTE;
36- }
37
38 /* At this point, we treat assumed and non-assumed connections alike.
39 * For assumed connections we do that because we still manage RA and DHCP
40@@ -5009,6 +5016,7 @@ ip6_config_merge_and_apply (NMDevice *self,
41 gboolean routes_full_sync;
42 gboolean ignore_auto_routes = FALSE;
43 gboolean ignore_auto_dns = FALSE;
44+ gboolean auto_method = FALSE;
45
46 /* Apply ignore-auto-routes and ignore-auto-dns settings */
47 connection = nm_device_get_applied_connection (self);
48@@ -5018,6 +5026,11 @@ ip6_config_merge_and_apply (NMDevice *self,
49 if (s_ip6) {
50 ignore_auto_routes = nm_setting_ip_config_get_ignore_auto_routes (s_ip6);
51 ignore_auto_dns = nm_setting_ip_config_get_ignore_auto_dns (s_ip6);
52+
53+ if (NM_IN_STRSET (nm_setting_ip_config_get_method (s_ip6),
54+ NM_SETTING_IP6_CONFIG_METHOD_AUTO,
55+ NM_SETTING_IP6_CONFIG_METHOD_DHCP))
56+ auto_method = TRUE;
57 }
58 }
59
60@@ -5081,10 +5094,12 @@ ip6_config_merge_and_apply (NMDevice *self,
61 goto END_ADD_DEFAULT_ROUTE;
62 }
63
64- if (nm_device_uses_generated_assumed_connection (self)) {
65- /* a generate-assumed-connection always detects the default route from platform */
66+ /* a generated-assumed connection detects the default route from the platform,
67+ * but if the IP method is automatic we need to update the default route to
68+ * maintain connectivity.
69+ */
70+ if (nm_device_uses_generated_assumed_connection (self) && !auto_method)
71 goto END_ADD_DEFAULT_ROUTE;
72- }
73
74 /* At this point, we treat assumed and non-assumed connections alike.
75 * For assumed connections we do that because we still manage RA and DHCP
76@@ -7963,23 +7978,16 @@ nm_device_set_ip4_config (NMDevice *self,
77 nm_exported_object_clear_and_unexport (&old_config);
78
79 if (nm_device_uses_generated_assumed_connection (self)) {
80- NMConnection *connection = nm_device_get_applied_connection (self);
81 NMConnection *settings_connection = NM_CONNECTION (nm_device_get_settings_connection (self));
82 NMSetting *s_ip4;
83
84- g_object_freeze_notify (G_OBJECT (connection));
85 g_object_freeze_notify (G_OBJECT (settings_connection));
86
87 nm_connection_remove_setting (settings_connection, NM_TYPE_SETTING_IP4_CONFIG);
88 s_ip4 = nm_ip4_config_create_setting (priv->ip4_config);
89 nm_connection_add_setting (settings_connection, s_ip4);
90
91- nm_connection_remove_setting (connection, NM_TYPE_SETTING_IP4_CONFIG);
92- s_ip4 = nm_ip4_config_create_setting (priv->ip4_config);
93- nm_connection_add_setting (connection, s_ip4);
94-
95 g_object_thaw_notify (G_OBJECT (settings_connection));
96- g_object_thaw_notify (G_OBJECT (connection));
97 }
98
99 nm_device_queue_recheck_assume (self);
100@@ -8128,23 +8136,16 @@ nm_device_set_ip6_config (NMDevice *self,
101 nm_exported_object_clear_and_unexport (&old_config);
102
103 if (nm_device_uses_generated_assumed_connection (self)) {
104- NMConnection *connection = nm_device_get_applied_connection (self);
105 NMConnection *settings_connection = NM_CONNECTION (nm_device_get_settings_connection (self));
106 NMSetting *s_ip6;
107
108- g_object_freeze_notify (G_OBJECT (connection));
109 g_object_freeze_notify (G_OBJECT (settings_connection));
110
111 nm_connection_remove_setting (settings_connection, NM_TYPE_SETTING_IP6_CONFIG);
112 s_ip6 = nm_ip6_config_create_setting (priv->ip6_config);
113 nm_connection_add_setting (settings_connection, s_ip6);
114
115- nm_connection_remove_setting (connection, NM_TYPE_SETTING_IP6_CONFIG);
116- s_ip6 = nm_ip6_config_create_setting (priv->ip6_config);
117- nm_connection_add_setting (connection, s_ip6);
118-
119 g_object_thaw_notify (G_OBJECT (settings_connection));
120- g_object_thaw_notify (G_OBJECT (connection));
121 }
122
123 nm_device_queue_recheck_assume (self);

Subscribers

People subscribed via source and target branches