networkd-wait-online-manager.c revision 5d8689d749ffc50ade3d5c8598c1d3d11f5240f2
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright 2013 Tom Gundersen <teg@jklm.no>
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/>.
***/
#include <fnmatch.h>
#include "rtnl-util.h"
#include "network-util.h"
#include "network-internal.h"
#include "networkd-wait-online-link.h"
#include "networkd-wait-online.h"
#include "util.h"
char **ignore;
assert(m);
return true;
return true;
return false;
}
bool manager_all_configured(Manager *m) {
Iterator i;
Link *l;
char **ifname;
bool one_ready = false;
/* wait for all the links given on the command line to appear */
if (!l) {
return false;
}
}
/* 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 (manager_ignore_link(m, l)) {
continue;
}
if (!l->state) {
log_debug("link %s has not yet been processed by udev",
l->ifname);
return false;
}
log_debug("link %s is being processed by networkd",
l->ifname);
return false;
}
if (l->operational_state &&
/* we wait for at least one link to be ready,
regardless of who manages it */
one_ready = true;
}
return one_ready;
}
Link *l;
const char *ifname;
int ifindex, r;
assert(m);
if (r < 0)
goto fail;
if (r < 0)
goto fail;
if (r < 0)
goto fail;
switch (type) {
case RTM_NEWLINK:
if (!l) {
if (r < 0)
goto fail;
r = link_update_monitor(l);
if (r < 0)
goto fail;
}
r = link_update_rtnl(l, mm);
if (r < 0)
goto fail;
break;
case RTM_DELLINK:
if (l) {
link_free(l);
}
break;
}
return 0;
fail:
log_warning_errno(r, "Failed to process RTNL link message: %m");
return 0;
}
int r;
if (r < 0)
return r;
if (manager_all_configured(m))
sd_event_exit(m->event, 0);
return 1;
}
static int manager_rtnl_listen(Manager *m) {
sd_rtnl_message *i;
int r;
assert(m);
/* First, subscribe to interfaces coming and going */
if (r < 0)
return r;
if (r < 0)
return r;
if (r < 0)
return r;
if (r < 0)
return r;
/* Then, enumerate all links */
if (r < 0)
return r;
r = sd_rtnl_message_request_dump(req, true);
if (r < 0)
return r;
if (r < 0)
return r;
for (i = reply; i; i = sd_rtnl_message_next(i)) {
r = manager_process_link(m->rtnl, i, m);
if (r < 0)
return r;
}
return r;
}
Iterator i;
Link *l;
int r;
assert(m);
HASHMAP_FOREACH(l, m->links, i) {
r = link_update_monitor(l);
if (r < 0)
}
if (manager_all_configured(m))
sd_event_exit(m->event, 0);
return 0;
}
static int manager_network_monitor_listen(Manager *m) {
assert(m);
if (r < 0)
return r;
if (fd < 0)
return fd;
if (events < 0)
return events;
if (r < 0)
return r;
return 0;
}
int r;
if (!m)
return -ENOMEM;
m->interfaces = interfaces;
r = sd_event_default(&m->event);
if (r < 0)
return r;
sd_event_set_watchdog(m->event, true);
r = manager_network_monitor_listen(m);
if (r < 0)
return r;
r = manager_rtnl_listen(m);
if (r < 0)
return r;
*ret = m;
m = NULL;
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);
sd_rtnl_unref(m->rtnl);
sd_event_unref(m->event);
free(m);
return;
}