#include <netinet/ether.h>
#include <linux/if.h>
+#include <fnmatch.h>
-#include "rtnl-util.h"
-
-#include "network-util.h"
+#include "alloc-util.h"
+#include "netlink-util.h"
#include "network-internal.h"
#include "networkd-wait-online-link.h"
#include "networkd-wait-online.h"
-
+#include "time-util.h"
#include "util.h"
+bool manager_ignore_link(Manager *m, Link *link) {
+ char **ignore;
+
+ assert(m);
+ assert(link);
+
+ /* always ignore the loopback interface */
+ if (link->flags & IFF_LOOPBACK)
+ return true;
+
+ /* if interfaces are given on the command line, ignore all others */
+ if (m->interfaces && !strv_contains(m->interfaces, link->ifname))
+ return true;
+
+ /* ignore interfaces we explicitly are asked to ignore */
+ STRV_FOREACH(ignore, m->ignore)
+ if (fnmatch(*ignore, link->ifname, 0) == 0)
+ return true;
+
+ return false;
+}
+
bool manager_all_configured(Manager *m) {
Iterator i;
Link *l;
/* wait for all links networkd manages to be in admin state 'configured'
and at least one link to gain a carrier */
HASHMAP_FOREACH(l, m->links, i) {
- if (!link_relevant(l)) {
- log_info("ignore irrelevant link: %s", l->ifname);
+ if (manager_ignore_link(m, l)) {
+ log_info("ignoring: %s", l->ifname);
continue;
}
return false;
}
- if (streq(l->state, "configuring")) {
+ if (STR_IN_SET(l->state, "configuring", "pending")) {
log_debug("link %s is being processed by networkd",
l->ifname);
return false;
return one_ready;
}
-static int manager_process_link(sd_rtnl *rtnl, sd_rtnl_message *mm, void *userdata) {
+static int manager_process_link(sd_netlink *rtnl, sd_netlink_message *mm, void *userdata) {
Manager *m = userdata;
uint16_t type;
Link *l;
assert(m);
assert(mm);
- r = sd_rtnl_message_get_type(mm, &type);
+ r = sd_netlink_message_get_type(mm, &type);
if (r < 0)
goto fail;
if (r < 0)
goto fail;
- r = sd_rtnl_message_read_string(mm, IFLA_IFNAME, &ifname);
+ r = sd_netlink_message_read_string(mm, IFLA_IFNAME, &ifname);
if (r < 0)
goto fail;
return 0;
fail:
- log_warning_errno(-r, "Failed to process RTNL link message: %m");
+ log_warning_errno(r, "Failed to process RTNL link message: %m");
return 0;
}
-static int on_rtnl_event(sd_rtnl *rtnl, sd_rtnl_message *mm, void *userdata) {
+static int on_rtnl_event(sd_netlink *rtnl, sd_netlink_message *mm, void *userdata) {
Manager *m = userdata;
int r;
}
static int manager_rtnl_listen(Manager *m) {
- _cleanup_rtnl_message_unref_ sd_rtnl_message *req = NULL, *reply = NULL;
- sd_rtnl_message *i;
+ _cleanup_netlink_message_unref_ sd_netlink_message *req = NULL, *reply = NULL;
+ sd_netlink_message *i;
int r;
assert(m);
- /* First, subscibe to interfaces coming and going */
- r = sd_rtnl_open(&m->rtnl, 3, RTNLGRP_LINK, RTNLGRP_IPV4_IFADDR, RTNLGRP_IPV6_IFADDR);
+ /* First, subscribe to interfaces coming and going */
+ r = sd_netlink_open(&m->rtnl);
if (r < 0)
return r;
- r = sd_rtnl_attach_event(m->rtnl, m->event, 0);
+ r = sd_netlink_attach_event(m->rtnl, m->event, 0);
if (r < 0)
return r;
- r = sd_rtnl_add_match(m->rtnl, RTM_NEWLINK, on_rtnl_event, m);
+ r = sd_netlink_add_match(m->rtnl, RTM_NEWLINK, on_rtnl_event, m);
if (r < 0)
return r;
- r = sd_rtnl_add_match(m->rtnl, RTM_DELLINK, on_rtnl_event, m);
+ r = sd_netlink_add_match(m->rtnl, RTM_DELLINK, on_rtnl_event, m);
if (r < 0)
return r;
if (r < 0)
return r;
- r = sd_rtnl_message_request_dump(req, true);
+ r = sd_netlink_message_request_dump(req, true);
if (r < 0)
return r;
- r = sd_rtnl_call(m->rtnl, req, 0, &reply);
+ r = sd_netlink_call(m->rtnl, req, 0, &reply);
if (r < 0)
return r;
- for (i = reply; i; i = sd_rtnl_message_next(i)) {
+ for (i = reply; i; i = sd_netlink_message_next(i)) {
r = manager_process_link(m->rtnl, i, m);
if (r < 0)
return r;
HASHMAP_FOREACH(l, m->links, i) {
r = link_update_monitor(l);
if (r < 0)
- log_warning_errno(-r, "Failed to update monitor information for %i: %m", l->ifindex);
+ log_warning_errno(r, "Failed to update monitor information for %i: %m", l->ifindex);
}
if (manager_all_configured(m))
return 0;
}
-int manager_new(Manager **ret, char **interfaces) {
+int manager_new(Manager **ret, char **interfaces, char **ignore, usec_t timeout) {
_cleanup_(manager_freep) Manager *m = NULL;
int r;
return -ENOMEM;
m->interfaces = interfaces;
+ m->ignore = ignore;
r = sd_event_default(&m->event);
if (r < 0)
sd_event_add_signal(m->event, NULL, SIGTERM, NULL, NULL);
sd_event_add_signal(m->event, NULL, SIGINT, NULL, NULL);
+ if (timeout > 0) {
+ usec_t usec;
+
+ usec = now(clock_boottime_or_monotonic()) + timeout;
+
+ r = sd_event_add_time(m->event, NULL, clock_boottime_or_monotonic(), usec, 0, NULL, INT_TO_PTR(-ETIMEDOUT));
+ if (r < 0)
+ return r;
+ }
+
sd_event_set_watchdog(m->event, true);
r = manager_network_monitor_listen(m);
sd_network_monitor_unref(m->network_monitor);
sd_event_source_unref(m->rtnl_event_source);
- sd_rtnl_unref(m->rtnl);
+ sd_netlink_unref(m->rtnl);
sd_event_unref(m->event);
free(m);