chiark / gitweb /
networkd: link - log when starting clients fail
[elogind.git] / src / network / networkd-link.c
index 392665a4d16d32923cb709563d8a6cb1d0df305b..9f632e4f1e797ea41cc7748209707c051ec3ee96 100644 (file)
@@ -151,13 +151,51 @@ static void link_enter_unmanaged(Link *link) {
         link_save(link);
 }
 
+static int link_stop_clients(Link *link) {
+        int r = 0, k;
+
+        assert(link);
+        assert(link->manager);
+        assert(link->manager->event);
+
+        if (!link->network)
+                return 0;
+
+        if (link->network->dhcp) {
+                assert(link->dhcp_client);
+
+                k = sd_dhcp_client_stop(link->dhcp_client);
+                if (k < 0) {
+                        log_warning_link(link, "Could not stop DHCPv4 client: %s", strerror(-r));
+                        r = k;
+                }
+        }
+
+        if (link->network->ipv4ll) {
+                assert(link->ipv4ll);
+
+                k = sd_ipv4ll_stop(link->ipv4ll);
+                if (k < 0) {
+                        log_warning_link(link, "Could not stop IPv4 link-local: %s", strerror(-r));
+                        r = k;
+                }
+        }
+
+        return r;
+}
+
 static void link_enter_failed(Link *link) {
         assert(link);
 
+        if (link->state == LINK_STATE_FAILED)
+                return;
+
         log_warning_link(link, "failed");
 
         link->state = LINK_STATE_FAILED;
 
+        link_stop_clients(link);
+
         link_save(link);
 }
 
@@ -1037,8 +1075,11 @@ static int link_acquire_conf(Link *link) {
                 log_debug_link(link, "acquiring IPv4 link-local address");
 
                 r = sd_ipv4ll_start(link->ipv4ll);
-                if (r < 0)
+                if (r < 0) {
+                        log_warning_link(link, "could not acquire IPv4 "
+                                         "link-local address");
                         return r;
+                }
         }
 
         if (link->network->dhcp) {
@@ -1047,8 +1088,11 @@ static int link_acquire_conf(Link *link) {
                 log_debug_link(link, "acquiring DHCPv4 lease");
 
                 r = sd_dhcp_client_start(link->dhcp_client);
-                if (r < 0)
+                if (r < 0) {
+                        log_warning_link(link, "could not acquire DHCPv4 "
+                                         "lease");
                         return r;
+                }
         }
 
         return 0;