if (streq_ptr(udev_device_get_action(device), "remove")) {
uint64_t ifindex;
- log_debug("Link removed: %s", udev_device_get_sysname(device));
+ log_debug("%s: link removed", udev_device_get_sysname(device));
ifindex = udev_device_get_ifindex(device);
link = hashmap_get(m->links, &ifindex);
link_free(link);
} else {
- log_debug("New link: %s", udev_device_get_sysname(device));
-
- r = link_add(m, device);
+ r = link_add(m, device, &link);
if (r < 0) {
- log_error("Could not handle link %s: %s",
- udev_device_get_sysname(device),
- strerror(-r));
- }
+ if (r == -EEXIST)
+ log_debug("%s: link already exists, ignoring",
+ link->ifname);
+ else
+ log_error("%s: could not handle link: %s",
+ udev_device_get_sysname(device),
+ strerror(-r));
+ } else
+ log_debug("%s: link (with ifindex %" PRIu64") added",
+ link->ifname, link->ifindex);
}
return 0;
if (r < 0)
return r;
+ r = udev_enumerate_add_match_is_initialized(e);
+ if (r < 0)
+ return r;
+
r = udev_enumerate_scan_devices(e);
if (r < 0)
return r;
if (!d)
return -ENOMEM;
- if (!udev_device_get_is_initialized(d))
- continue;
-
k = manager_process_link(m, d);
if (k < 0)
r = k;
static int manager_rtnl_process_link(sd_rtnl *rtnl, sd_rtnl_message *message, void *userdata) {
Manager *m = userdata;
Link *link;
+ uint64_t ifindex_64;
int r, ifindex;
r = sd_rtnl_message_link_get_ifindex(message, &ifindex);
- if (r < 0)
+ if (r < 0) {
+ log_debug("received RTM_NEWLINK message without valid ifindex");
return 0;
+ }
- link = hashmap_get(m->links, &ifindex);
- if (!link)
+ ifindex_64 = ifindex;
+ link = hashmap_get(m->links, &ifindex_64);
+ if (!link) {
+ log_debug("received RTM_NEWLINK message for untracked ifindex %d", ifindex);
return 0;
+ }
- r = link_update(link, message);
- if (r < 0)
- return 0;
+ /* only track the status of links we want to manage */
+ if (link->network) {
+ r = link_update(link, message);
+ if (r < 0)
+ return 0;
+ } else
+ log_debug("%s: received RTM_NEWLINK message for unmanaged link", link->ifname);
return 1;
}