network: introduce a tiny wrapper for manager_udev_process_link()
Preparation for later commits.
This commit is contained in:
@@ -1488,21 +1488,13 @@ static int link_check_initialized(Link *link) {
|
||||
return link_initialized(link, device);
|
||||
}
|
||||
|
||||
int manager_udev_process_link(sd_device_monitor *monitor, sd_device *device, void *userdata) {
|
||||
sd_device_action_t action;
|
||||
Manager *m = userdata;
|
||||
Link *link = NULL;
|
||||
int manager_udev_process_link(Manager *m, sd_device *device, sd_device_action_t action) {
|
||||
int r, ifindex;
|
||||
Link *link;
|
||||
|
||||
assert(m);
|
||||
assert(device);
|
||||
|
||||
r = sd_device_get_action(device, &action);
|
||||
if (r < 0) {
|
||||
log_device_debug_errno(device, r, "Failed to get udev action, ignoring device: %m");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* 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. */
|
||||
@@ -1510,25 +1502,20 @@ int manager_udev_process_link(sd_device_monitor *monitor, sd_device *device, voi
|
||||
return 0;
|
||||
|
||||
r = sd_device_get_ifindex(device, &ifindex);
|
||||
if (r < 0) {
|
||||
log_device_debug_errno(device, r, "Ignoring udev %s event for device without ifindex or with invalid ifindex: %m",
|
||||
device_action_to_string(action));
|
||||
return 0;
|
||||
}
|
||||
if (r < 0)
|
||||
return log_device_debug_errno(device, r, "Failed to get ifindex: %m");
|
||||
|
||||
r = device_is_renaming(device);
|
||||
if (r < 0) {
|
||||
log_device_debug_errno(device, r, "Failed to determine the device is renamed or not, ignoring '%s' uevent: %m",
|
||||
device_action_to_string(action));
|
||||
return 0;
|
||||
}
|
||||
if (r < 0)
|
||||
return log_device_debug_errno(device, r, "Failed to determine if the device is renaming or not: %m");
|
||||
if (r > 0) {
|
||||
log_device_debug(device, "Interface is under renaming, wait for the interface to be renamed.");
|
||||
log_device_debug(device, "Device is renaming, waiting for the interface to be renamed.");
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -235,7 +235,7 @@ LinkState link_state_from_string(const char *s) _pure_;
|
||||
int link_reconfigure(Link *link, bool force);
|
||||
int link_reconfigure_after_sleep(Link *link);
|
||||
|
||||
int manager_udev_process_link(sd_device_monitor *monitor, sd_device *device, void *userdata);
|
||||
int manager_udev_process_link(Manager *m, sd_device *device, sd_device_action_t action);
|
||||
int manager_rtnl_process_link(sd_netlink *rtnl, sd_netlink_message *message, Manager *m);
|
||||
|
||||
int link_flags_to_string_alloc(uint32_t flags, char **ret);
|
||||
|
||||
@@ -18,6 +18,8 @@
|
||||
#include "bus-util.h"
|
||||
#include "conf-parser.h"
|
||||
#include "def.h"
|
||||
#include "device-private.h"
|
||||
#include "device-util.h"
|
||||
#include "dns-domain.h"
|
||||
#include "fd-util.h"
|
||||
#include "fileio.h"
|
||||
@@ -168,6 +170,35 @@ static int manager_connect_bus(Manager *m) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int manager_process_uevent(sd_device_monitor *monitor, sd_device *device, void *userdata) {
|
||||
Manager *m = ASSERT_PTR(userdata);
|
||||
sd_device_action_t action;
|
||||
const char *s;
|
||||
int r;
|
||||
|
||||
assert(device);
|
||||
|
||||
r = sd_device_get_action(device, &action);
|
||||
if (r < 0)
|
||||
return log_device_warning_errno(device, r, "Failed to get udev action, ignoring: %m");
|
||||
|
||||
r = sd_device_get_subsystem(device, &s);
|
||||
if (r < 0)
|
||||
return log_device_warning_errno(device, r, "Failed to get subsystem, ignoring: %m");
|
||||
|
||||
if (streq(s, "net"))
|
||||
r = manager_udev_process_link(m, device, action);
|
||||
else {
|
||||
log_device_debug(device, "Received device with unexpected subsystem \"%s\", ignoring.", s);
|
||||
return 0;
|
||||
}
|
||||
if (r < 0)
|
||||
log_device_warning_errno(device, r, "Failed to process \"%s\" uevent, ignoring: %m",
|
||||
device_action_to_string(action));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int manager_connect_udev(Manager *m) {
|
||||
int r;
|
||||
|
||||
@@ -186,13 +217,13 @@ static int manager_connect_udev(Manager *m) {
|
||||
|
||||
r = sd_device_monitor_filter_add_match_subsystem_devtype(m->device_monitor, "net", NULL);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Could not add device monitor filter: %m");
|
||||
return log_error_errno(r, "Could not add device monitor filter for net subsystem: %m");
|
||||
|
||||
r = sd_device_monitor_attach_event(m->device_monitor, m->event);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to attach event to device monitor: %m");
|
||||
|
||||
r = sd_device_monitor_start(m->device_monitor, manager_udev_process_link, m);
|
||||
r = sd_device_monitor_start(m->device_monitor, manager_process_uevent, m);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to start device monitor: %m");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user