]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
networkd: rework when LLDP reception is enabled
authorLennart Poettering <lennart@poettering.net>
Sat, 20 Feb 2016 21:35:02 +0000 (22:35 +0100)
committerLennart Poettering <lennart@poettering.net>
Sun, 21 Feb 2016 19:40:57 +0000 (20:40 +0100)
Being on the link-layer LLDP is nothing we should turn on only when there's a
link beat. Instead, turn it on, whenever the iface is UP regardless if there's
a link beat or not. This closes the race between a link beat being available
and us subscribing to LLDP as a result.

src/network/networkd-link.c

index 32437d21959d82787c3954b32b8151162b3c286e..aa8adf1eae18c8712b086eea0f4171954d8b10b0 100644 (file)
@@ -531,12 +531,6 @@ static int link_stop_clients(Link *link) {
                         r = log_link_warning_errno(link, k, "Could not stop IPv6 Router Discovery: %m");
         }
 
-        if (link->lldp) {
-                k = sd_lldp_stop(link->lldp);
-                if (k < 0)
-                        r = log_link_warning_errno(link, k, "Could not stop LLDP: %m");
-        }
-
         return r;
 }
 
@@ -1374,16 +1368,6 @@ static int link_acquire_conf(Link *link) {
                         return log_link_warning_errno(link, r, "Could not acquire DHCPv4 lease: %m");
         }
 
-        if (link_lldp_enabled(link)) {
-                assert(link->lldp);
-
-                log_link_debug(link, "Starting LLDP");
-
-                r = sd_lldp_start(link->lldp);
-                if (r < 0)
-                        return log_link_warning_errno(link, r, "Could not start LLDP: %m");
-        }
-
         return 0;
 }
 
@@ -2093,6 +2077,27 @@ static int link_drop_foreign_config(Link *link) {
         return 0;
 }
 
+static int link_update_lldp(Link *link) {
+        int r;
+
+        assert(link);
+
+        if (!link->lldp)
+                return 0;
+
+        if (link->flags & IFF_UP) {
+                r = sd_lldp_start(link->lldp);
+                if (r > 0)
+                        log_link_debug(link, "Started LLDP.");
+        } else {
+                r = sd_lldp_stop(link->lldp);
+                if (r > 0)
+                        log_link_debug(link, "Stopped LLDP.");
+        }
+
+        return r;
+}
+
 static int link_configure(Link *link) {
         int r;
 
@@ -2190,6 +2195,10 @@ static int link_configure(Link *link) {
                 r = sd_lldp_set_callback(link->lldp, lldp_handler, link);
                 if (r < 0)
                         return r;
+
+                r = link_update_lldp(link);
+                if (r < 0)
+                        return r;
         }
 
         if (link_has_carrier(link)) {
@@ -2736,6 +2745,10 @@ int link_update(Link *link, sd_netlink_message *m) {
         if (r < 0)
                 return r;
 
+        r = link_update_lldp(link);
+        if (r < 0)
+                return r;
+
         carrier_gained = !had_carrier && link_has_carrier(link);
         carrier_lost = had_carrier && !link_has_carrier(link);