summaryrefslogtreecommitdiffstats
path: root/src/network/networkd-link.c
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2024-01-16 23:01:24 +0100
committerGitHub <noreply@github.com>2024-01-16 23:01:24 +0100
commit443afd6c191d071084bbafa06c2f01256e427649 (patch)
treed3e59c94664fad0389db9e2ce688c060f39ba91e /src/network/networkd-link.c
parentMerge pull request #30962 from poettering/varlink-json-sensitive-rework (diff)
parenttest-network: test the default required operational state for CAN devices (diff)
downloadsystemd-443afd6c191d071084bbafa06c2f01256e427649.tar.xz
systemd-443afd6c191d071084bbafa06c2f01256e427649.zip
Merge pull request #30967 from yuwata/network-can-required-operstate-for-online
network: several cleanups for required operstate for online, and change the default for CAN devices
Diffstat (limited to 'src/network/networkd-link.c')
-rw-r--r--src/network/networkd-link.c27
1 files changed, 23 insertions, 4 deletions
diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c
index a39477e78b..49ed8f59bb 100644
--- a/src/network/networkd-link.c
+++ b/src/network/networkd-link.c
@@ -71,6 +71,21 @@
#include "udev-util.h"
#include "vrf.h"
+void link_required_operstate_for_online(Link *link, LinkOperationalStateRange *ret) {
+ assert(link);
+ assert(ret);
+
+ if (link->network && operational_state_range_is_valid(&link->network->required_operstate_for_online))
+ *ret = link->network->required_operstate_for_online;
+ else if (link->iftype == ARPHRD_CAN)
+ *ret = (const LinkOperationalStateRange) {
+ .min = LINK_OPERSTATE_CARRIER,
+ .max = LINK_OPERSTATE_CARRIER,
+ };
+ else
+ *ret = LINK_OPERSTATE_RANGE_DEFAULT;
+}
+
bool link_ipv6_enabled(Link *link) {
assert(link);
@@ -1845,12 +1860,16 @@ void link_update_operstate(Link *link, bool also_update_master) {
else
operstate = LINK_OPERSTATE_ENSLAVED;
+ LinkOperationalStateRange req;
+ link_required_operstate_for_online(link, &req);
+
/* Only determine online state for managed links with RequiredForOnline=yes */
if (!link->network || !link->network->required_for_online)
online_state = _LINK_ONLINE_STATE_INVALID;
- else if (operstate < link->network->required_operstate_for_online.min ||
- operstate > link->network->required_operstate_for_online.max)
+
+ else if (!operational_state_is_in_range(operstate, &req))
online_state = LINK_ONLINE_STATE_OFFLINE;
+
else {
AddressFamily required_family = link->network->required_family_for_online;
bool needs_ipv4 = required_family & ADDRESS_FAMILY_IPV4;
@@ -1861,14 +1880,14 @@ void link_update_operstate(Link *link, bool also_update_master) {
* to offline in the blocks below. */
online_state = LINK_ONLINE_STATE_ONLINE;
- if (link->network->required_operstate_for_online.min >= LINK_OPERSTATE_DEGRADED) {
+ if (req.min >= LINK_OPERSTATE_DEGRADED) {
if (needs_ipv4 && ipv4_address_state < LINK_ADDRESS_STATE_DEGRADED)
online_state = LINK_ONLINE_STATE_OFFLINE;
if (needs_ipv6 && ipv6_address_state < LINK_ADDRESS_STATE_DEGRADED)
online_state = LINK_ONLINE_STATE_OFFLINE;
}
- if (link->network->required_operstate_for_online.min >= LINK_OPERSTATE_ROUTABLE) {
+ if (req.min >= LINK_OPERSTATE_ROUTABLE) {
if (needs_ipv4 && ipv4_address_state < LINK_ADDRESS_STATE_ROUTABLE)
online_state = LINK_ONLINE_STATE_OFFLINE;
if (needs_ipv6 && ipv6_address_state < LINK_ADDRESS_STATE_ROUTABLE)