chiark / gitweb /
networkd: link - make check for whether addresses/routes are being configured implicit
[elogind.git] / src / network / networkd-link.c
index d13a47bb2ebc705dc9fd0009b1bd015309c2ea93..f73b06916ab27e35b45a73ee36b4ccfd926d09dd 100644 (file)
@@ -23,7 +23,7 @@
 #include <linux/if.h>
 #include <unistd.h>
 
-#include "networkd.h"
+#include "networkd-link.h"
 #include "networkd-netdev.h"
 #include "libudev-private.h"
 #include "udev-util.h"
@@ -33,7 +33,6 @@
 #include "network-internal.h"
 #include "conf-parser.h"
 
-#include "network-util.h"
 #include "dhcp-lease-internal.h"
 
 static int link_new(Manager *manager, sd_rtnl_message *message, Link **ret) {
@@ -453,13 +452,6 @@ static int link_enter_set_routes(Link *link) {
 
         link->state = LINK_STATE_SETTING_ROUTES;
 
-        if (!link->network->static_routes &&
-            !link->dhcp_lease &&
-            !ipv4ll_is_bound(link->ipv4ll))
-                return link_enter_configured(link);
-
-        log_debug_link(link, "setting routes");
-
         LIST_FOREACH(routes, rt, link->network->static_routes) {
                 r = route_configure(rt, link, &route_handler);
                 if (r < 0) {
@@ -563,7 +555,8 @@ static int link_enter_set_routes(Link *link) {
 
         if (link->route_messages == 0) {
                 link_enter_configured(link);
-        }
+        } else
+                log_debug_link(link, "setting routes");
 
         return 0;
 }
@@ -665,13 +658,6 @@ static int link_enter_set_addresses(Link *link) {
 
         link->state = LINK_STATE_SETTING_ADDRESSES;
 
-        if (!link->network->static_addresses &&
-            !link->dhcp_lease &&
-            !ipv4ll_is_bound(link->ipv4ll))
-                return link_enter_set_routes(link);
-
-        log_debug_link(link, "setting addresses");
-
         LIST_FOREACH(addresses, ad, link->network->static_addresses) {
                 r = address_configure(ad, link, &address_handler);
                 if (r < 0) {
@@ -779,6 +765,11 @@ static int link_enter_set_addresses(Link *link) {
                 link->addr_messages ++;
         }
 
+        if (link->addr_messages == 0) {
+                link_enter_set_routes(link);
+        } else
+                log_debug_link(link, "setting addresses");
+
         return 0;
 }
 
@@ -2333,7 +2324,7 @@ int link_save(Link *link) {
 
         r = fopen_temporary(link->state_file, &f, &temp_path);
         if (r < 0)
-                goto finish;
+                return r;
 
         fchmod(fileno(f), 0644);
 
@@ -2394,7 +2385,7 @@ int link_save(Link *link) {
 
                 r = dhcp_lease_save(link->dhcp_lease, link->lease_file);
                 if (r < 0)
-                        goto finish;
+                        goto fail;
 
                 fprintf(f,
                         "DHCP_LEASE=%s\n",
@@ -2402,18 +2393,21 @@ int link_save(Link *link) {
         } else
                 unlink(link->lease_file);
 
-        fflush(f);
+        r = fflush_and_check(f);
+        if (r < 0)
+                goto fail;
 
-        if (ferror(f) || rename(temp_path, link->state_file) < 0) {
+        if (rename(temp_path, link->state_file) < 0) {
                 r = -errno;
-                unlink(link->state_file);
-                unlink(temp_path);
+                goto fail;
         }
 
-finish:
-        if (r < 0)
-                log_error_link(link, "Failed to save link data to %s: %s", link->state_file, strerror(-r));
+        return 0;
 
+fail:
+        log_error_link(link, "Failed to save link data to %s: %s", link->state_file, strerror(-r));
+        unlink(link->state_file);
+        unlink(temp_path);
         return r;
 }