-/***
- This file is part of systemd.
-
- Copyright 2013 Tom Gundersen <teg@jklm.no>
-
- systemd is free software; you can redistribute it and/or modify it
- under the terms of the GNU Lesser General Public License as published by
- the Free Software Foundation; either version 2.1 of the License, or
- (at your option) any later version.
-
- systemd is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public License
- along with systemd; If not, see <http://www.gnu.org/licenses/>.
-***/
+/* SPDX-License-Identifier: LGPL-2.1+ */
#include <netinet/ether.h>
#include <linux/if.h>
#include "manager.h"
#include "netlink-util.h"
#include "network-internal.h"
+#include "strv.h"
#include "time-util.h"
#include "util.h"
if (m->interfaces && !strv_contains(m->interfaces, link->ifname))
return true;
+ if (!link->required_for_online)
+ return true;
+
/* ignore interfaces we explicitly are asked to ignore */
return strv_fnmatch(m->ignore, link->ifname, 0);
}
assert(mm);
r = sd_netlink_message_get_type(mm, &type);
- if (r < 0)
- goto fail;
+ if (r < 0) {
+ log_warning_errno(r, "rtnl: Could not get message type, ignoring: %m");
+ return 0;
+ }
r = sd_rtnl_message_link_get_ifindex(mm, &ifindex);
- if (r < 0)
- goto fail;
+ if (r < 0) {
+ log_warning_errno(r, "rtnl: Could not get ifindex from link, ignoring: %m");
+ return 0;
+ } else if (ifindex <= 0) {
+ log_warning("rtnl: received link message with invalid ifindex %d, ignoring", ifindex);
+ return 0;
+ }
r = sd_netlink_message_read_string(mm, IFLA_IFNAME, &ifname);
- if (r < 0)
- goto fail;
+ if (r < 0) {
+ log_warning_errno(r, "rtnl: Received link message without ifname, ignoring: %m");
+ return 0;
+ }
l = hashmap_get(m->links, INT_TO_PTR(ifindex));
r = link_new(m, &l, ifindex, ifname);
if (r < 0)
- goto fail;
+ return log_error_errno(r, "Failed to create link object: %m");
r = link_update_monitor(l);
if (r < 0)
- goto fail;
+ return log_error_errno(r, "Failed to initialize link object: %m");
}
r = link_update_rtnl(l, mm);
if (r < 0)
- goto fail;
+ return log_warning_errno(r, "Failed to process RTNL link message: %m");;
break;
}
return 0;
-
-fail:
- log_warning_errno(r, "Failed to process RTNL link message: %m");
- return 0;
}
static int on_rtnl_event(sd_netlink *rtnl, sd_netlink_message *mm, void *userdata) {
if (r < 0)
return r;
- r = sd_netlink_add_match(m->rtnl, RTM_NEWLINK, on_rtnl_event, m);
+ r = sd_netlink_add_match(m->rtnl, NULL, RTM_NEWLINK, on_rtnl_event, NULL, m, "wait-online-on-NEWLINK");
if (r < 0)
return r;
- r = sd_netlink_add_match(m->rtnl, RTM_DELLINK, on_rtnl_event, m);
+ r = sd_netlink_add_match(m->rtnl, NULL, RTM_DELLINK, on_rtnl_event, NULL, m, "wait-online-on-DELLINK");
if (r < 0)
return r;
if (r < 0)
return r;
- sd_event_add_signal(m->event, NULL, SIGTERM, NULL, NULL);
- sd_event_add_signal(m->event, NULL, SIGINT, NULL, NULL);
+ (void) sd_event_add_signal(m->event, NULL, SIGTERM, NULL, NULL);
+ (void) sd_event_add_signal(m->event, NULL, SIGINT, NULL, NULL);
if (timeout > 0) {
usec_t usec;
if (r < 0)
return r;
- *ret = m;
- m = NULL;
+ *ret = TAKE_PTR(m);
return 0;
}
void manager_free(Manager *m) {
- Link *l;
-
if (!m)
return;
- while ((l = hashmap_first(m->links)))
- link_free(l);
- hashmap_free(m->links);
+ hashmap_free_with_destructor(m->links, link_free);
hashmap_free(m->links_by_name);
sd_event_source_unref(m->network_monitor_event_source);