From 3255bda698d2a02ab2f2825a1e652ac6f0871a89 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Wed, 17 Jan 2024 01:35:34 +0900 Subject: [PATCH] network: make 'carrier' as the default required operational state for CAN device As CAN devices do not support IP address, hence the state never goes to higher than 'carrier'. Prompted by https://github.com/linux-can/can-utils/issues/68#issuecomment-1327987724. --- man/systemd.network.xml | 11 +++++++++-- src/network/networkd-link.c | 5 +++++ src/network/networkd-network.c | 4 ++-- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/man/systemd.network.xml b/man/systemd.network.xml index 76f9f4d042..35c897af39 100644 --- a/man/systemd.network.xml +++ b/man/systemd.network.xml @@ -259,8 +259,9 @@ RequiredForOnline= - Takes a boolean or a minimum operational state and an optional maximum operational - state. Please see + Takes a boolean, a minimum operational state (e.g., carrier), or a range + of operational state separated with a colon (e.g., degraded:routable). + Please see networkctl1 for possible operational states. When yes, the network is deemed required when determining whether the system is online (including when running @@ -270,6 +271,12 @@ minimum and maximum operational state required for the network interface to be considered online. + When yes is specified for a CAN device, + systemd-networkd-wait-online deems that the interface is online when its + operational state becomes carrier. For an interface with other type, e.g. + ether, the interface is deened online when its online state is + degraded or routable. + Defaults to yes when ActivationPolicy= is not set, or set to up, always-up, or bound. Defaults to no when diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c index d553a716fa..57ea9ecb75 100644 --- a/src/network/networkd-link.c +++ b/src/network/networkd-link.c @@ -77,6 +77,11 @@ void link_required_operstate_for_online(Link *link, LinkOperationalStateRange *r 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; } diff --git a/src/network/networkd-network.c b/src/network/networkd-network.c index 845a8130bd..08c7da5699 100644 --- a/src/network/networkd-network.c +++ b/src/network/networkd-network.c @@ -372,7 +372,7 @@ int network_load_one(Manager *manager, OrderedHashmap **networks, const char *fi .n_ref = 1, .required_for_online = -1, - .required_operstate_for_online = LINK_OPERSTATE_RANGE_DEFAULT, + .required_operstate_for_online = LINK_OPERSTATE_RANGE_INVALID, .activation_policy = _ACTIVATION_POLICY_INVALID, .group = -1, .arp = -1, @@ -1221,7 +1221,7 @@ int config_parse_required_for_online( if (isempty(rvalue)) { network->required_for_online = -1; - network->required_operstate_for_online = LINK_OPERSTATE_RANGE_DEFAULT; + network->required_operstate_for_online = LINK_OPERSTATE_RANGE_INVALID; return 0; }