networkd: exit on idle

We will be woken up on rtnl or dbus activity, so let's just quit if some time has passed and that is the only thing that can happen.

Note that we will always stay around if we expect network activity (e.g. DHCP is enabled), as we are not restarted on that.
This commit is contained in:
Tom Gundersen
2015-02-05 12:04:19 +01:00
parent 3f171cabad
commit a97dcc12e4
7 changed files with 58 additions and 7 deletions
+5 -5
View File
@@ -35,7 +35,7 @@
#include "conf-parser.h"
#include "dhcp-lease-internal.h"
static bool link_dhcp6_enabled(Link *link) {
bool link_dhcp6_enabled(Link *link) {
if (link->flags & IFF_LOOPBACK)
return false;
@@ -45,7 +45,7 @@ static bool link_dhcp6_enabled(Link *link) {
return IN_SET(link->network->dhcp, ADDRESS_FAMILY_IPV6, ADDRESS_FAMILY_YES);
}
static bool link_dhcp4_enabled(Link *link) {
bool link_dhcp4_enabled(Link *link) {
if (link->flags & IFF_LOOPBACK)
return false;
@@ -55,7 +55,7 @@ static bool link_dhcp4_enabled(Link *link) {
return IN_SET(link->network->dhcp, ADDRESS_FAMILY_IPV4, ADDRESS_FAMILY_YES);
}
static bool link_dhcp4_server_enabled(Link *link) {
bool link_dhcp4_server_enabled(Link *link) {
if (link->flags & IFF_LOOPBACK)
return false;
@@ -65,7 +65,7 @@ static bool link_dhcp4_server_enabled(Link *link) {
return link->network->dhcp_server;
}
static bool link_ipv4ll_enabled(Link *link) {
bool link_ipv4ll_enabled(Link *link) {
if (link->flags & IFF_LOOPBACK)
return false;
@@ -75,7 +75,7 @@ static bool link_ipv4ll_enabled(Link *link) {
return link->network->ipv4ll;
}
static bool link_lldp_enabled(Link *link) {
bool link_lldp_enabled(Link *link) {
if (link->flags & IFF_LOOPBACK)
return false;
+6
View File
@@ -114,6 +114,12 @@ int ipv4ll_configure(Link *link);
int dhcp4_configure(Link *link);
int icmp6_configure(Link *link);
bool link_lldp_enabled(Link *link);
bool link_ipv4ll_enabled(Link *link);
bool link_dhcp4_server_enabled(Link *link);
bool link_dhcp4_enabled(Link *link);
bool link_dhcp6_enabled(Link *link);
const char* link_state_to_string(LinkState s) _const_;
LinkState link_state_from_string(const char *s) _pure_;
+42
View File
@@ -31,6 +31,8 @@
#include "libudev-private.h"
#include "udev-util.h"
#include "rtnl-util.h"
#include "bus-util.h"
#include "def.h"
#include "mkdir.h"
#include "virt.h"
@@ -497,6 +499,46 @@ void manager_free(Manager *m) {
free(m);
}
static bool manager_check_idle(void *userdata) {
Manager *m = userdata;
Link *link;
Iterator i;
assert(m);
HASHMAP_FOREACH(link, m->links, i) {
/* we are not woken on udev activity, so let's just wait for the
* pending udev event */
if (link->state == LINK_STATE_PENDING)
return false;
if (!link->network)
continue;
/* we are not woken on netork activity, so let's stay around */
if (link_lldp_enabled(link) ||
link_ipv4ll_enabled(link) ||
link_dhcp4_server_enabled(link) ||
link_dhcp4_enabled(link) ||
link_dhcp6_enabled(link))
return false;
}
return true;
}
int manager_run(Manager *m) {
assert(m);
return bus_event_loop_with_idle(
m->event,
m->bus,
"org.freedesktop.network1",
DEFAULT_EXIT_USEC,
manager_check_idle,
m);
}
int manager_load_config(Manager *m) {
int r;
+1 -1
View File
@@ -110,7 +110,7 @@ int main(int argc, char *argv[]) {
"READY=1\n"
"STATUS=Processing requests...");
r = sd_event_loop(m->event);
r = manager_run(m);
if (r < 0) {
log_error_errno(r, "Event loop failed: %m");
goto out;
+2
View File
@@ -239,6 +239,8 @@ extern const sd_bus_vtable manager_vtable[];
int manager_new(Manager **ret);
void manager_free(Manager *m);
int manager_run(Manager *m);
int manager_load_config(Manager *m);
bool manager_should_reload(Manager *m);