[systemd-commits] 4 commits - src/network TODO

Tom Gundersen tomegun at kemper.freedesktop.org
Thu Sep 4 05:29:51 PDT 2014


 TODO                        |    3 
 src/network/networkd-link.c |  244 ++++++++++++++++++++++----------------------
 src/network/networkd-link.h |    2 
 3 files changed, 128 insertions(+), 121 deletions(-)

New commits:
commit a821cbb00c3f6e33d99e9e38ec1538a16dd90ce3
Author: Tom Gundersen <teg at jklm.no>
Date:   Thu Sep 4 14:16:56 2014 +0200

    networkd: link - clarify log message when receiving address for unknown link

diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c
index f726e2b..bcd2e6d 100644
--- a/src/network/networkd-link.c
+++ b/src/network/networkd-link.c
@@ -1336,7 +1336,7 @@ int link_rtnl_process_address(sd_rtnl *rtnl, sd_rtnl_message *message,
         } else {
                 r = link_get(m, ifindex, &link);
                 if (r < 0 || !link) {
-                        log_warning("rtnl: received address for a nonexistent link, ignoring");
+                        log_warning("rtnl: received address for a nonexistent link (%d), ignoring", ifindex);
                         return 0;
                 }
         }

commit bd2efe9219a3791b47c2c5c2ef0fe2579ffd547d
Author: Tom Gundersen <teg at jklm.no>
Date:   Thu Sep 4 13:40:24 2014 +0200

    networkd: link - do not manage loopback links
    
    Fixes https://bugs.freedesktop.org/show_bug.cgi?id=83134.

diff --git a/TODO b/TODO
index f0f2bcb..380fd49 100644
--- a/TODO
+++ b/TODO
@@ -78,9 +78,6 @@ Features:
   - ipv4ll with multiple interfaces doesn't work when both dhcp and
     ipv4ll is used. for some reasons the kernel will currently pick an
     ipv4ll source address to reach non-ipv4ll gateways.
-  - dhcp and ipv4ll should probably be skipped for "lo" devices, even
-    if the user has a catchall .network file installed, that might
-    theoretically match it.
   - the DHCP lease data (such as NTP/DNS) is still made available when
     a carrier is lost on a link. It should be removed instantly.
   - .network setting that allows overriding of the hostname to send to the dhcp server
diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c
index 1b7b189..f726e2b 100644
--- a/src/network/networkd-link.c
+++ b/src/network/networkd-link.c
@@ -1250,6 +1250,12 @@ static int link_initialized_and_synced(sd_rtnl *rtnl, sd_rtnl_message *m,
         } else if (r < 0)
                 return r;
 
+        if (link->flags & IFF_LOOPBACK) {
+                log_debug_link(link, "matching network ignored for loopback link");
+                link_enter_unmanaged(link);
+                return 1;
+        }
+
         r = network_apply(link->manager, network, link);
         if (r < 0)
                 return r;

commit 51d18171529dcdad1366e422e42d538434af0ff6
Author: Tom Gundersen <teg at jklm.no>
Date:   Thu Sep 4 14:10:43 2014 +0200

    networkd: link - save link flags when the link is added
    
    Don't wait for the link to be fully synchronised.

diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c
index 57e7194..1b7b189 100644
--- a/src/network/networkd-link.c
+++ b/src/network/networkd-link.c
@@ -35,6 +35,85 @@
 
 #include "dhcp-lease-internal.h"
 
+#define FLAG_STRING(string, flag, old, new) \
+        (((old ^ new) & flag) \
+                ? ((old & flag) ? (" -" string) : (" +" string)) \
+                : "")
+
+static int link_update_flags(Link *link, sd_rtnl_message *m) {
+        unsigned flags, unknown_flags_added, unknown_flags_removed, unknown_flags;
+        uint8_t operstate;
+        int r;
+
+        assert(link);
+
+        r = sd_rtnl_message_link_get_flags(m, &flags);
+        if (r < 0) {
+                log_warning_link(link, "Could not get link flags");
+                return r;
+        }
+
+        r = sd_rtnl_message_read_u8(m, IFLA_OPERSTATE, &operstate);
+        if (r < 0)
+                /* if we got a message without operstate, take it to mean
+                   the state was unchanged */
+                operstate = link->kernel_operstate;
+
+        if ((link->flags == flags) && (link->kernel_operstate == operstate))
+                return 0;
+
+        if (link->flags != flags) {
+                log_debug_link(link, "flags change:%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
+                               FLAG_STRING("LOOPBACK", IFF_LOOPBACK, link->flags, flags),
+                               FLAG_STRING("MASTER", IFF_MASTER, link->flags, flags),
+                               FLAG_STRING("SLAVE", IFF_SLAVE, link->flags, flags),
+                               FLAG_STRING("UP", IFF_UP, link->flags, flags),
+                               FLAG_STRING("DORMANT", IFF_DORMANT, link->flags, flags),
+                               FLAG_STRING("LOWER_UP", IFF_LOWER_UP, link->flags, flags),
+                               FLAG_STRING("RUNNING", IFF_RUNNING, link->flags, flags),
+                               FLAG_STRING("MULTICAST", IFF_MULTICAST, link->flags, flags),
+                               FLAG_STRING("BROADCAST", IFF_BROADCAST, link->flags, flags),
+                               FLAG_STRING("POINTOPOINT", IFF_POINTOPOINT, link->flags, flags),
+                               FLAG_STRING("PROMISC", IFF_PROMISC, link->flags, flags),
+                               FLAG_STRING("ALLMULTI", IFF_ALLMULTI, link->flags, flags),
+                               FLAG_STRING("PORTSEL", IFF_PORTSEL, link->flags, flags),
+                               FLAG_STRING("AUTOMEDIA", IFF_AUTOMEDIA, link->flags, flags),
+                               FLAG_STRING("DYNAMIC", IFF_DYNAMIC, link->flags, flags),
+                               FLAG_STRING("NOARP", IFF_NOARP, link->flags, flags),
+                               FLAG_STRING("NOTRAILERS", IFF_NOTRAILERS, link->flags, flags),
+                               FLAG_STRING("DEBUG", IFF_DEBUG, link->flags, flags),
+                               FLAG_STRING("ECHO", IFF_ECHO, link->flags, flags));
+
+                unknown_flags = ~(IFF_LOOPBACK | IFF_MASTER | IFF_SLAVE | IFF_UP |
+                                  IFF_DORMANT | IFF_LOWER_UP | IFF_RUNNING |
+                                  IFF_MULTICAST | IFF_BROADCAST | IFF_POINTOPOINT |
+                                  IFF_PROMISC | IFF_ALLMULTI | IFF_PORTSEL |
+                                  IFF_AUTOMEDIA | IFF_DYNAMIC | IFF_NOARP |
+                                  IFF_NOTRAILERS | IFF_DEBUG | IFF_ECHO);
+                unknown_flags_added = ((link->flags ^ flags) & flags & unknown_flags);
+                unknown_flags_removed = ((link->flags ^ flags) & link->flags & unknown_flags);
+
+                /* link flags are currently at most 18 bits, let's align to
+                 * printing 20 */
+                if (unknown_flags_added)
+                        log_debug_link(link,
+                                       "unknown link flags gained: %#.5x (ignoring)",
+                                       unknown_flags_added);
+
+                if (unknown_flags_removed)
+                        log_debug_link(link,
+                                       "unknown link flags lost: %#.5x (ignoring)",
+                                       unknown_flags_removed);
+        }
+
+        link->flags = flags;
+        link->kernel_operstate = operstate;
+
+        link_save(link);
+
+        return 0;
+}
+
 static int link_new(Manager *manager, sd_rtnl_message *message, Link **ret) {
         _cleanup_link_unref_ Link *link = NULL;
         uint16_t type;
@@ -95,6 +174,10 @@ static int link_new(Manager *manager, sd_rtnl_message *message, Link **ret) {
         if (r < 0)
                 return r;
 
+        r = link_update_flags(link, message);
+        if (r < 0)
+                return r;
+
         *ret = link;
         link = NULL;
 
@@ -877,85 +960,6 @@ bool link_has_carrier(Link *link) {
         return false;
 }
 
-#define FLAG_STRING(string, flag, old, new) \
-        (((old ^ new) & flag) \
-                ? ((old & flag) ? (" -" string) : (" +" string)) \
-                : "")
-
-static int link_update_flags(Link *link, sd_rtnl_message *m) {
-        unsigned flags, unknown_flags_added, unknown_flags_removed, unknown_flags;
-        uint8_t operstate;
-        int r;
-
-        assert(link);
-
-        r = sd_rtnl_message_link_get_flags(m, &flags);
-        if (r < 0) {
-                log_warning_link(link, "Could not get link flags");
-                return r;
-        }
-
-        r = sd_rtnl_message_read_u8(m, IFLA_OPERSTATE, &operstate);
-        if (r < 0)
-                /* if we got a message without operstate, take it to mean
-                   the state was unchanged */
-                operstate = link->kernel_operstate;
-
-        if ((link->flags == flags) && (link->kernel_operstate == operstate))
-                return 0;
-
-        if (link->flags != flags) {
-                log_debug_link(link, "flags change:%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
-                               FLAG_STRING("LOOPBACK", IFF_LOOPBACK, link->flags, flags),
-                               FLAG_STRING("MASTER", IFF_MASTER, link->flags, flags),
-                               FLAG_STRING("SLAVE", IFF_SLAVE, link->flags, flags),
-                               FLAG_STRING("UP", IFF_UP, link->flags, flags),
-                               FLAG_STRING("DORMANT", IFF_DORMANT, link->flags, flags),
-                               FLAG_STRING("LOWER_UP", IFF_LOWER_UP, link->flags, flags),
-                               FLAG_STRING("RUNNING", IFF_RUNNING, link->flags, flags),
-                               FLAG_STRING("MULTICAST", IFF_MULTICAST, link->flags, flags),
-                               FLAG_STRING("BROADCAST", IFF_BROADCAST, link->flags, flags),
-                               FLAG_STRING("POINTOPOINT", IFF_POINTOPOINT, link->flags, flags),
-                               FLAG_STRING("PROMISC", IFF_PROMISC, link->flags, flags),
-                               FLAG_STRING("ALLMULTI", IFF_ALLMULTI, link->flags, flags),
-                               FLAG_STRING("PORTSEL", IFF_PORTSEL, link->flags, flags),
-                               FLAG_STRING("AUTOMEDIA", IFF_AUTOMEDIA, link->flags, flags),
-                               FLAG_STRING("DYNAMIC", IFF_DYNAMIC, link->flags, flags),
-                               FLAG_STRING("NOARP", IFF_NOARP, link->flags, flags),
-                               FLAG_STRING("NOTRAILERS", IFF_NOTRAILERS, link->flags, flags),
-                               FLAG_STRING("DEBUG", IFF_DEBUG, link->flags, flags),
-                               FLAG_STRING("ECHO", IFF_ECHO, link->flags, flags));
-
-                unknown_flags = ~(IFF_LOOPBACK | IFF_MASTER | IFF_SLAVE | IFF_UP |
-                                  IFF_DORMANT | IFF_LOWER_UP | IFF_RUNNING |
-                                  IFF_MULTICAST | IFF_BROADCAST | IFF_POINTOPOINT |
-                                  IFF_PROMISC | IFF_ALLMULTI | IFF_PORTSEL |
-                                  IFF_AUTOMEDIA | IFF_DYNAMIC | IFF_NOARP |
-                                  IFF_NOTRAILERS | IFF_DEBUG | IFF_ECHO);
-                unknown_flags_added = ((link->flags ^ flags) & flags & unknown_flags);
-                unknown_flags_removed = ((link->flags ^ flags) & link->flags & unknown_flags);
-
-                /* link flags are currently at most 18 bits, let's align to
-                 * printing 20 */
-                if (unknown_flags_added)
-                        log_debug_link(link,
-                                       "unknown link flags gained: %#.5x (ignoring)",
-                                       unknown_flags_added);
-
-                if (unknown_flags_removed)
-                        log_debug_link(link,
-                                       "unknown link flags lost: %#.5x (ignoring)",
-                                       unknown_flags_removed);
-        }
-
-        link->flags = flags;
-        link->kernel_operstate = operstate;
-
-        link_save(link);
-
-        return 0;
-}
-
 static int link_up_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userdata) {
         _cleanup_link_unref_ Link *link = userdata;
         int r;

commit a61bb41c29c370a7e64285525ec35baac8944149
Author: Tom Gundersen <teg at jklm.no>
Date:   Thu Sep 4 14:05:54 2014 +0200

    networkd: move carrier gained/lost handling from link_update_flags() to link_update()
    
    This allows us also to simplify link_has_carrier() a bit.

diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c
index dff3270..57e7194 100644
--- a/src/network/networkd-link.c
+++ b/src/network/networkd-link.c
@@ -863,15 +863,15 @@ static int link_acquire_conf(Link *link) {
         return 0;
 }
 
-bool link_has_carrier(unsigned flags, uint8_t operstate) {
+bool link_has_carrier(Link *link) {
         /* see Documentation/networking/operstates.txt in the kernel sources */
 
-        if (operstate == IF_OPER_UP)
+        if (link->kernel_operstate == IF_OPER_UP)
                 return true;
 
-        if (operstate == IF_OPER_UNKNOWN)
+        if (link->kernel_operstate == IF_OPER_UNKNOWN)
                 /* operstate may not be implemented, so fall back to flags */
-                if ((flags & IFF_LOWER_UP) && !(flags & IFF_DORMANT))
+                if ((link->flags & IFF_LOWER_UP) && !(link->flags & IFF_DORMANT))
                         return true;
 
         return false;
@@ -885,7 +885,6 @@ bool link_has_carrier(unsigned flags, uint8_t operstate) {
 static int link_update_flags(Link *link, sd_rtnl_message *m) {
         unsigned flags, unknown_flags_added, unknown_flags_removed, unknown_flags;
         uint8_t operstate;
-        bool carrier_gained = false, carrier_lost = false;
         int r;
 
         assert(link);
@@ -949,40 +948,11 @@ static int link_update_flags(Link *link, sd_rtnl_message *m) {
                                        unknown_flags_removed);
         }
 
-        carrier_gained = !link_has_carrier(link->flags, link->kernel_operstate) &&
-                       link_has_carrier(flags, operstate);
-        carrier_lost = link_has_carrier(link->flags, link->kernel_operstate) &&
-                         !link_has_carrier(flags, operstate);
-
         link->flags = flags;
         link->kernel_operstate = operstate;
 
         link_save(link);
 
-        if (link->state == LINK_STATE_FAILED ||
-            link->state == LINK_STATE_UNMANAGED)
-                return 0;
-
-        if (carrier_gained) {
-                log_info_link(link, "gained carrier");
-
-                if (link->network) {
-                        r = link_acquire_conf(link);
-                        if (r < 0) {
-                                link_enter_failed(link);
-                                return r;
-                        }
-                }
-        } else if (carrier_lost) {
-                log_info_link(link, "lost carrier");
-
-                r = link_stop_clients(link);
-                if (r < 0) {
-                        link_enter_failed(link);
-                        return r;
-                }
-        }
-
         return 0;
 }
 
@@ -1244,7 +1214,7 @@ static int link_configure(Link *link) {
                         return r;
         }
 
-        if (link_has_carrier(link->flags, link->kernel_operstate)) {
+        if (link_has_carrier(link)) {
                 r = link_acquire_conf(link);
                 if (r < 0)
                         return r;
@@ -1554,6 +1524,7 @@ int link_update(Link *link, sd_rtnl_message *m) {
         struct ether_addr mac;
         const char *ifname;
         uint32_t mtu;
+        bool had_carrier, carrier_gained, carrier_lost;
         int r;
 
         assert(link);
@@ -1650,7 +1621,36 @@ int link_update(Link *link, sd_rtnl_message *m) {
                 }
         }
 
-        return link_update_flags(link, m);
+        had_carrier = link_has_carrier(link);
+
+        r = link_update_flags(link, m);
+        if (r < 0)
+                return r;
+
+        carrier_gained = !had_carrier && link_has_carrier(link);
+        carrier_lost = had_carrier && !link_has_carrier(link);
+
+        if (carrier_gained) {
+                log_info_link(link, "gained carrier");
+
+                if (link->network) {
+                        r = link_acquire_conf(link);
+                        if (r < 0) {
+                                link_enter_failed(link);
+                                return r;
+                        }
+                }
+        } else if (carrier_lost) {
+                log_info_link(link, "lost carrier");
+
+                r = link_stop_clients(link);
+                if (r < 0) {
+                        link_enter_failed(link);
+                        return r;
+                }
+        }
+
+        return 0;
 }
 
 static void link_update_operstate(Link *link) {
@@ -1659,7 +1659,7 @@ static void link_update_operstate(Link *link) {
 
         if (link->kernel_operstate == IF_OPER_DORMANT)
                 link->operstate = LINK_OPERSTATE_DORMANT;
-        else if (link_has_carrier(link->flags, link->kernel_operstate)) {
+        else if (link_has_carrier(link)) {
                 Address *address;
                 uint8_t scope = RT_SCOPE_NOWHERE;
 
diff --git a/src/network/networkd-link.h b/src/network/networkd-link.h
index 0f73ec7..7acf404 100644
--- a/src/network/networkd-link.h
+++ b/src/network/networkd-link.h
@@ -113,7 +113,7 @@ int link_rtnl_process_address(sd_rtnl *rtnl, sd_rtnl_message *message, void *use
 
 int link_save(Link *link);
 
-bool link_has_carrier(unsigned flags, uint8_t operstate);
+bool link_has_carrier(Link *link);
 
 int link_set_mtu(Link *link, uint32_t mtu);
 int link_set_hostname(Link *link, const char *hostname);



More information about the systemd-commits mailing list