wait-online: make manager_link_is_online() return 0 when in unmanaged state
authorYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 26 Jan 2022 07:48:08 +0000 (16:48 +0900)
committerLuca Boccassi <luca.boccassi@gmail.com>
Fri, 11 Mar 2022 12:48:49 +0000 (12:48 +0000)
Previously, even if a link is in unmanaged state, the function may
returns positive value. So, even if all managed links are in the configured
sate but do not satisfy the online criteria, e.g., IPv4 address state,
then wait-online finishes with positive value.

This makes the function always return 0 for unmanaged state. So, at
least one managed link must satisfies the online criteria.

This also adds more comments and debugging logs.

Fixes #22246.

(cherry picked from commit cd7fcda54333dc95116a434cffc591f21edddbb2)
(cherry picked from commit 056fcd4e318aa664bd36950bf6c2dae4647c96c7)

src/network/wait-online/manager.c

index d8cf2338b0bfd842106027f13e32d40db7222be0..5d65d92f2e8392117607a3054d50b26037a1c8df 100644 (file)
@@ -45,13 +45,29 @@ static int manager_link_is_online(Manager *m, Link *l, LinkOperationalStateRange
          *       0: operstate is not enough
          *       1: online */
 
-        if (!l->state)
+        if (!l->state || streq(l->state, "pending"))
+                /* If no state string exists, networkd (and possibly also udevd) has not detected the
+                 * interface yet, that mean we cannot determine whether the interface is managed or
+                 * not. Hence, return negative value.
+                 * If the link is in pending state, then udevd has not processed the link, and networkd
+                 * has not tried to find .network file for the link. Hence, return negative value. */
                 return log_link_debug_errno(l, SYNTHETIC_ERRNO(EAGAIN),
-                                            "link has not yet been processed by udev");
+                                            "link has not yet been processed by udev: setup state is %s.",
+                                            strna(l->state));
+
+        if (streq(l->state, "unmanaged")) {
+                /* If the link is in unmanaged state, then ignore the interface unless the interface is
+                 * specified in '--interface/-i' option. */
+                if (!hashmap_contains(m->command_line_interfaces_by_name, l->ifname)) {
+                        log_link_debug(l, "link is not managed by networkd (yet?).");
+                        return 0;
+                }
 
-        if (STR_IN_SET(l->state, "configuring", "pending"))
+        } else if (!streq(l->state, "configured"))
+                /* If the link is in non-configured state, return negative value here. */
                 return log_link_debug_errno(l, SYNTHETIC_ERRNO(EAGAIN),
-                                            "link is being processed by networkd");
+                                            "link is being processed by networkd: setup state is %s.",
+                                            l->state);
 
         if (s.min < 0)
                 s.min = m->required_operstate.min >= 0 ? m->required_operstate.min
@@ -96,6 +112,7 @@ static int manager_link_is_online(Manager *m, Link *l, LinkOperationalStateRange
                 }
         }
 
+        log_link_debug(l, "link is confiured by networkd and online.");
         return 1;
 }