chiark / gitweb /
networkd: exit on idle
authorTom Gundersen <teg@jklm.no>
Wed, 4 Feb 2015 14:00:20 +0000 (15:00 +0100)
committerTom Gundersen <teg@jklm.no>
Thu, 5 Feb 2015 11:04:19 +0000 (12:04 +0100)
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.

src/import/importd.c
src/network/networkd-link.c
src/network/networkd-link.h
src/network/networkd-manager.c
src/network/networkd.c
src/network/networkd.h
units/systemd-networkd.service.in

index 4715785..1222bf3 100644 (file)
@@ -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;
index 1442230..eff1ce9 100644 (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;
 
index b237120..ce83f24 100644 (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_;
 
index 40328a3..02ab9f9 100644 (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;
 
index 0aaef8b..571f523 100644 (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;
index 9f3a5ea..e6d84f1 100644 (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);
 
index fab278e..5a91b8e 100644 (file)
@@ -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