[systemd-commits] src/network

Tom Gundersen tomegun at kemper.freedesktop.org
Sat Apr 12 04:00:07 PDT 2014


 src/network/networkd-link.c |   31 +++++++++++++++++++++++--------
 1 file changed, 23 insertions(+), 8 deletions(-)

New commits:
commit 7cc832b91e8f5883b505c42f9f403e03dfc83c89
Author: Tom Gundersen <teg at jklm.no>
Date:   Sat Apr 12 12:27:22 2014 +0200

    networkd: link - require both RUNNING and LOWER_UP before using link
    
    Usually RUNNING implies LOWER_UP, but for drivers that don't support oper state, RUNNING can
    also mean that the state is unknown. In that case we should just trust LOWER_UP directly.

diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c
index 45276ba..7f81538 100644
--- a/src/network/networkd-link.c
+++ b/src/network/networkd-link.c
@@ -1032,6 +1032,7 @@ static int link_acquire_conf(Link *link) {
 
 static int link_update_flags(Link *link, unsigned flags) {
         unsigned flags_added, flags_removed, generic_flags;
+        bool carrier_gained, carrier_lost;
         int r;
 
         assert(link);
@@ -1047,6 +1048,18 @@ static int link_update_flags(Link *link, unsigned flags) {
         flags_removed = (link->flags ^ flags) & link->flags;
         generic_flags = ~(IFF_UP | IFF_LOWER_UP | IFF_RUNNING);
 
+        /* consider link to have carrier when both RUNNING and LOWER_UP, as RUNNING
+           may mean that the oper state is unknown, in which case we should fall back to
+           simply trust LOWER_UP, even thought that is less reliable
+         */
+        carrier_gained = ((flags_added & IFF_LOWER_UP) && (flags & IFF_RUNNING)) ||
+                         ((flags_added & IFF_RUNNING) && (flags & IFF_LOWER_UP));
+        carrier_lost = ((link->flags & (IFF_RUNNING | IFF_LOWER_UP)) ==
+                        (IFF_RUNNING | IFF_LOWER_UP)) &&
+                       (flags_removed & (IFF_LOWER_UP | IFF_RUNNING));
+
+        link->flags = flags;
+
         if (flags_added & generic_flags)
                 log_debug_link(link, "link flags gained: %#.8x",
                                flags_added & generic_flags);
@@ -1061,13 +1074,17 @@ static int link_update_flags(Link *link, unsigned flags) {
                 log_info_link(link, "link is down");
 
         if (flags_added & IFF_LOWER_UP)
-                log_info_link(link, "carrier on");
+                log_info_link(link, "link is lower up");
         else if (flags_removed & IFF_LOWER_UP)
-                log_info_link(link, "carrier off");
+                log_info_link(link, "link is lower down");
 
+        if (flags_added & IFF_RUNNING)
+                log_info_link(link, "link is running");
+        else if (flags_removed & IFF_RUNNING)
+                log_info_link(link, "link is not running");
 
-        if (flags_added & IFF_RUNNING) {
-                log_info_link(link, "running");
+        if (carrier_gained) {
+                log_info_link(link, "gained carrier");
 
                 if (link->network->dhcp || link->network->ipv4ll) {
                         r = link_acquire_conf(link);
@@ -1077,8 +1094,8 @@ static int link_update_flags(Link *link, unsigned flags) {
                                 return r;
                         }
                 }
-        } else if (flags_removed & IFF_RUNNING) {
-                log_info_link(link, "not running");
+        } else if (carrier_lost) {
+                log_info_link(link, "lost carrier");
 
                 if (link->network->dhcp) {
                         r = sd_dhcp_client_stop(link->dhcp_client);
@@ -1099,8 +1116,6 @@ static int link_update_flags(Link *link, unsigned flags) {
                 }
         }
 
-        link->flags = flags;
-
         return 0;
 }
 



More information about the systemd-commits mailing list