mirror of
https://github.com/systemd/systemd
synced 2024-09-06 16:56:43 +00:00
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:
parent
3f171cabad
commit
a97dcc12e4
|
@ -30,6 +30,7 @@
|
|||
#include "socket-util.h"
|
||||
#include "mkdir.h"
|
||||
#include "import-util.h"
|
||||
#include "def.h"
|
||||
|
||||
typedef struct Transfer Transfer;
|
||||
typedef struct Manager Manager;
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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_;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ Wants=network.target
|
|||
|
||||
[Service]
|
||||
Type=notify
|
||||
Restart=always
|
||||
Restart=on-failure
|
||||
RestartSec=0
|
||||
ExecStart=@rootlibexecdir@/systemd-networkd
|
||||
CapabilityBoundingSet=CAP_NET_ADMIN CAP_NET_BIND_SERVICE CAP_NET_BROADCAST CAP_NET_RAW CAP_SETUID CAP_SETGID CAP_SETPCAP CAP_CHOWN CAP_DAC_OVERRIDE CAP_FOWNER
|
||||
|
|
Loading…
Reference in a new issue