network: adjust default RequiredForOnline= and RequiredFamilyForOnline= setting

E.g. a bonding port does not support addressing, hence the default
should be 'enslaved'.

Follow-up for 3255bda698.

Closes #27724.
This commit is contained in:
Yu Watanabe 2024-02-02 15:23:43 +09:00
parent c89efaf9e5
commit a853cc99e6
4 changed files with 75 additions and 11 deletions

View file

@ -267,15 +267,8 @@
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
@ -290,6 +283,44 @@
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>

View 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;

View 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);

View 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));