summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2022-07-23 02:00:32 +0200
committerYu Watanabe <watanabe.yu+github@gmail.com>2022-07-23 13:04:28 +0200
commit75255a8d43d82d0893a699aab6b57ca95fddb791 (patch)
treea6c69502de7e75642f4d356c4e5cc3a9f1610e91 /src
parentnetwork: introduce a tiny wrapper for manager_udev_process_link() (diff)
downloadsystemd-75255a8d43d82d0893a699aab6b57ca95fddb791.tar.xz
systemd-75255a8d43d82d0893a699aab6b57ca95fddb791.zip
network: unref sd-device object assigned to Link on remove uevent
Otherwise, outdated device information may be used in a short timespan.
Diffstat (limited to 'src')
-rw-r--r--src/network/networkd-link.c27
1 files changed, 14 insertions, 13 deletions
diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c
index 8b0ef8f076..838101a217 100644
--- a/src/network/networkd-link.c
+++ b/src/network/networkd-link.c
@@ -1495,16 +1495,24 @@ int manager_udev_process_link(Manager *m, sd_device *device, sd_device_action_t
assert(m);
assert(device);
- /* Ignore the "remove" uevent — let's remove a device only if rtnetlink says so. All other uevents
- * are "positive" events in some form, i.e. inform us about a changed or new network interface, that
- * still exists — and we are interested in that. */
- if (action == SD_DEVICE_REMOVE)
- return 0;
-
r = sd_device_get_ifindex(device, &ifindex);
if (r < 0)
return log_device_debug_errno(device, r, "Failed to get ifindex: %m");
+ r = link_get_by_index(m, ifindex, &link);
+ if (r < 0) {
+ /* This error is not critical, as the corresponding rtnl message may be received later. */
+ log_device_debug_errno(device, r, "Failed to get link from ifindex %i, ignoring: %m", ifindex);
+ return 0;
+ }
+
+ /* Let's unref the sd-device object assigned to the corresponding Link object, but keep the Link
+ * object here. It will be removed only when rtnetlink says so. */
+ if (action == SD_DEVICE_REMOVE) {
+ link->dev = sd_device_unref(link->dev);
+ return 0;
+ }
+
r = device_is_renaming(device);
if (r < 0)
return log_device_debug_errno(device, r, "Failed to determine if the device is renaming or not: %m");
@@ -1513,13 +1521,6 @@ int manager_udev_process_link(Manager *m, sd_device *device, sd_device_action_t
return 0;
}
- r = link_get_by_index(m, ifindex, &link);
- if (r < 0) {
- /* This error is not critical, as the corresponding rtnl message may be received later. */
- log_device_debug_errno(device, r, "Failed to get link from ifindex %i, ignoring: %m", ifindex);
- return 0;
- }
-
r = link_initialized(link, device);
if (r < 0)
link_enter_failed(link);