]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network: adjust default RequiredForOnline= and RequiredFamilyForOnline= setting 31176/head
authorYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 2 Feb 2024 06:23:43 +0000 (15:23 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 2 Feb 2024 06:38:30 +0000 (15:38 +0900)
E.g. a bonding port does not support addressing, hence the default
should be 'enslaved'.

Follow-up for 3255bda698d2a02ab2f2825a1e652ac6f0871a89.

Closes #27724.

man/systemd.network.xml
src/network/networkd-link.c
src/network/networkd-link.h
src/network/networkd-state-file.c

index 9bad97b07b8b5df00236003a1bdb12cc58c4c723..dfae8119e7385c7e84c3e1ccf2d4ad7421251e7c 100644 (file)
           when determining whether the system is online (including when running
           <command>systemd-networkd-wait-online</command>). When <literal>no</literal>, the network is
           ignored when determining the online state. When a minimum operational state and an optional
-          maximum operational state are set, <literal>yes</literal> is implied, and this controls the
-          minimum and maximum operational state required for the network interface to be considered
-          online.</para>
-
-          <para>When <literal>yes</literal> is specified for a CAN device,
-          <command>systemd-networkd-wait-online</command> deems that the interface is online when its
-          operational state becomes <literal>carrier</literal>. For an interface with other type, e.g.
-          <literal>ether</literal>, the interface is deened online when its online state is
-          <literal>degraded</literal> or <literal>routable</literal>.</para>
+          maximum operational state are set, <command>systemd-networkd-wait-online</command> deems that the
+          interface is online when the operational state is in the specified range.</para>
 
           <para>Defaults to <literal>yes</literal> when <varname>ActivationPolicy=</varname> is not
           set, or set to <literal>up</literal>, <literal>always-up</literal>, or
           skipped automatically by <command>systemd-networkd-wait-online</command> if
           <literal>RequiredForOnline=no</literal>.</para>
 
+          <para>The boolean value <literal>yes</literal> is translated as follows;
+          <variablelist>
+            <varlistentry>
+              <term><option>CAN devices</option></term>
+              <listitem>
+                <para><literal>carrier</literal>,</para>
+                <xi:include href="version-info.xml" xpointer="v256"/>
+              </listitem>
+            </varlistentry>
+            <varlistentry>
+              <term><option>Master devices, e.g. bond or bridge</option></term>
+              <listitem>
+                <para><literal>degraded-carrier</literal> with <varname>RequiredFamilyForOnline=any</varname>,</para>
+                <xi:include href="version-info.xml" xpointer="v256"/>
+              </listitem>
+            </varlistentry>
+            <varlistentry>
+              <term><option>Bonding port interfaces</option></term>
+              <listitem>
+                <para><literal>enslaved</literal>,</para>
+                <xi:include href="version-info.xml" xpointer="v256"/>
+              </listitem>
+            </varlistentry>
+            <varlistentry>
+              <term><option>Other interfaces</option></term>
+              <listitem>
+                <para><literal>degraded</literal>.</para>
+                <xi:include href="version-info.xml" xpointer="v236"/>
+              </listitem>
+            </varlistentry>
+          </variablelist>
+          </para>
+
+          <para>This setting can be overridden by the command line option for
+          <command>systemd-networkd-wait-online</command>. See
+          <citerefentry><refentrytitle>systemd-networkd-wait-online.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>
+          for more details.</para>
+
           <xi:include href="version-info.xml" xpointer="v236"/>
         </listitem>
       </varlistentry>
index 194d31eafe89dea0e5540f0444d8bd2323a9f9fe..621f8592061d6c2f5ab4f82e5d1b7dddfb9e67df 100644 (file)
@@ -76,16 +76,48 @@ void link_required_operstate_for_online(Link *link, LinkOperationalStateRange *r
         assert(ret);
 
         if (link->network && operational_state_range_is_valid(&link->network->required_operstate_for_online))
+                /* If explicitly specified, use it as is. */
                 *ret = link->network->required_operstate_for_online;
         else if (link->iftype == ARPHRD_CAN)
+                /* CAN devices do not support addressing, hence defaults to 'carrier'. */
                 *ret = (const LinkOperationalStateRange) {
                         .min = LINK_OPERSTATE_CARRIER,
                         .max = LINK_OPERSTATE_CARRIER,
                 };
+        else if (link->network && link->network->bond)
+                /* Bonding slaves do not support addressing. */
+                *ret = (const LinkOperationalStateRange) {
+                        .min = LINK_OPERSTATE_ENSLAVED,
+                        .max = LINK_OPERSTATE_ENSLAVED,
+                };
+        else if (STRPTR_IN_SET(link->kind, "batadv", "bond", "bridge", "vrf"))
+                /* Some of slave interfaces may be offline. */
+                *ret = (const LinkOperationalStateRange) {
+                        .min = LINK_OPERSTATE_DEGRADED_CARRIER,
+                        .max = LINK_OPERSTATE_ROUTABLE,
+                };
         else
                 *ret = LINK_OPERSTATE_RANGE_DEFAULT;
 }
 
+AddressFamily link_required_family_for_online(Link *link) {
+        assert(link);
+
+        if (link->network && link->network->required_family_for_online >= 0)
+                return link->network->required_family_for_online;
+
+        if (link->network && operational_state_range_is_valid(&link->network->required_operstate_for_online))
+                /* If RequiredForOnline= is explicitly specified, defaults to no. */
+                return ADDRESS_FAMILY_NO;
+
+        if (STRPTR_IN_SET(link->kind, "batadv", "bond", "bridge", "vrf"))
+                /* As the minimum required operstate for master interfaces is 'degraded-carrier',
+                 * we should request an address assigned to the link for backward compatibility. */
+                return ADDRESS_FAMILY_YES;
+
+        return ADDRESS_FAMILY_NO;
+}
+
 bool link_ipv6_enabled(Link *link) {
         assert(link);
 
@@ -1877,7 +1909,7 @@ void link_update_operstate(Link *link, bool also_update_master) {
                 online_state = LINK_ONLINE_STATE_OFFLINE;
 
         else {
-                AddressFamily required_family = link->network->required_family_for_online;
+                AddressFamily required_family = link_required_family_for_online(link);
                 bool needs_ipv4 = required_family & ADDRESS_FAMILY_IPV4;
                 bool needs_ipv6 = required_family & ADDRESS_FAMILY_IPV6;
 
index 985670fcd2fb9243bd39af9392ad63df87e2e16a..d81b45bd643e5319d5fc4c35524912a659b11dc1 100644 (file)
@@ -260,3 +260,4 @@ int link_flags_to_string_alloc(uint32_t flags, char **ret);
 const char *kernel_operstate_to_string(int t) _const_;
 
 void link_required_operstate_for_online(Link *link, LinkOperationalStateRange *ret);
+AddressFamily link_required_family_for_online(Link *link);
index 5b2e8a2de4fd30b97476a91017b50f91a63a79fe..859a28aa59f5641e14d1bcefe33bc8ef9603a498 100644 (file)
@@ -637,7 +637,7 @@ static int link_save(Link *link) {
                         link_operstate_to_string(st.min), link_operstate_to_string(st.max));
 
                 fprintf(f, "REQUIRED_FAMILY_FOR_ONLINE=%s\n",
-                        link_required_address_family_to_string(link->network->required_family_for_online));
+                        link_required_address_family_to_string(link_required_family_for_online(link)));
 
                 fprintf(f, "ACTIVATION_POLICY=%s\n",
                         activation_policy_to_string(link->network->activation_policy));