From: Michael Tremer Date: Sat, 10 Jun 2023 12:04:18 +0000 (+0000) Subject: links: Initialize udev device when links are created X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=4d7437ddbcb56da5d64ae9189bdb2c8c161e4a9b;p=network.git links: Initialize udev device when links are created Signed-off-by: Michael Tremer --- diff --git a/src/networkd/link.c b/src/networkd/link.c index b0d9e865..8ba5da59 100644 --- a/src/networkd/link.c +++ b/src/networkd/link.c @@ -245,6 +245,53 @@ static int nw_link_carrier_lost(nw_link* link) { return 0; // XXX TODO } +static int nw_link_initialize(nw_link* link) { + sd_device *device = NULL; + int r; + + // Fetch device + r = sd_device_new_from_ifindex(&device, link->ifindex); + if (r < 0) { + WARNING("Could not find device for link %d: %s\n", link->ifindex, strerror(-r)); + r = 0; + goto ERROR; + } + + // Check if device is initialized + r = sd_device_get_is_initialized(device); + switch (r) { + // Initialized - fallthrough + case 0: + break; + + case 1: + DEBUG("The device has not been initialized, yet\n"); + r = 0; + goto ERROR; + + default: + WARNING("Could not check whether device is initialized, ignoring: %s\n", + strerror(-r)); + goto ERROR; + } + + // XXX Check renaming?! + + if (link->device) + sd_device_unref(link->device); + + // Store the device + link->device = sd_device_ref(device); + + DEBUG("Link %d has been initialized\n", link->ifindex); + +ERROR: + if (device) + sd_device_unref(device); + + return r; +} + static int nw_link_update_ifname(nw_link* link, sd_netlink_message* message) { const char* ifname = NULL; int r; @@ -476,6 +523,11 @@ int nw_link_process(sd_netlink* rtnl, sd_netlink_message* message, void* data) { goto ERROR; } + // Initialize the link + r = nw_link_initialize(link); + if (r < 0) + goto ERROR; + // Add it to the list r = nw_links_add_link(links, link); if (r)