From: Yu Watanabe Date: Wed, 6 Mar 2019 05:29:49 +0000 (+0900) Subject: network: make RequiredForOnline= also take operational state X-Git-Tag: v242-rc1~151^2~5 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=4ac77d63e999d59697c758f8304e55f19c160ecb;p=thirdparty%2Fsystemd.git network: make RequiredForOnline= also take operational state This will be used by systemd-networkd-wait-online. --- diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c index 9a4ba7a93a5..bc8c180665f 100644 --- a/src/network/networkd-link.c +++ b/src/network/networkd-link.c @@ -4003,6 +4003,9 @@ int link_save(Link *link) { fprintf(f, "REQUIRED_FOR_ONLINE=%s\n", yes_no(link->network->required_for_online)); + fprintf(f, "REQUIRED_OPER_STATE_FOR_ONLINE=%s\n", + strempty(link_operstate_to_string(link->network->required_operstate_for_online))); + if (link->dhcp6_client) { r = sd_dhcp6_client_get_lease(link->dhcp6_client, &dhcp6_lease); if (r < 0 && r != -ENOMSG) diff --git a/src/network/networkd-network-gperf.gperf b/src/network/networkd-network-gperf.gperf index 51123d12ef0..73a7fcdf086 100644 --- a/src/network/networkd-network-gperf.gperf +++ b/src/network/networkd-network-gperf.gperf @@ -36,7 +36,7 @@ Link.ARP, config_parse_tristate, Link.Multicast, config_parse_tristate, 0, offsetof(Network, multicast) Link.AllMulticast, config_parse_tristate, 0, offsetof(Network, allmulticast) Link.Unmanaged, config_parse_bool, 0, offsetof(Network, unmanaged) -Link.RequiredForOnline, config_parse_bool, 0, offsetof(Network, required_for_online) +Link.RequiredForOnline, config_parse_required_for_online, 0, 0 Network.Description, config_parse_string, 0, offsetof(Network, description) Network.Bridge, config_parse_ifname, 0, offsetof(Network, bridge_name) Network.Bond, config_parse_ifname, 0, offsetof(Network, bond_name) diff --git a/src/network/networkd-network.c b/src/network/networkd-network.c index 5f12df907af..fe26720103a 100644 --- a/src/network/networkd-network.c +++ b/src/network/networkd-network.c @@ -366,6 +366,7 @@ int network_load_one(Manager *manager, const char *filename) { .name = TAKE_PTR(name), .required_for_online = true, + .required_operstate_for_online = LINK_OPERSTATE_DEGRADED, .dhcp = ADDRESS_FAMILY_NO, .dhcp_use_ntp = true, .dhcp_use_dns = true, @@ -1671,3 +1672,46 @@ int config_parse_iaid(const char *unit, return 0; } + +int config_parse_required_for_online( + const char *unit, + const char *filename, + unsigned line, + const char *section, + unsigned section_line, + const char *lvalue, + int ltype, + const char *rvalue, + void *data, + void *userdata) { + + Network *network = data; + LinkOperationalState s; + bool required = true; + int r; + + if (isempty(rvalue)) { + network->required_for_online = true; + network->required_operstate_for_online = LINK_OPERSTATE_DEGRADED; + return 0; + } + + s = link_operstate_from_string(rvalue); + if (s < 0) { + r = parse_boolean(rvalue); + if (r < 0) { + log_syntax(unit, LOG_ERR, filename, line, r, + "Failed to parse %s= setting, ignoring assignment: %s", + lvalue, rvalue); + return 0; + } + + required = r; + s = LINK_OPERSTATE_DEGRADED; + } + + network->required_for_online = required; + network->required_operstate_for_online = s; + + return 0; +} diff --git a/src/network/networkd-network.h b/src/network/networkd-network.h index 2f7b6133fd5..2561bba1bc0 100644 --- a/src/network/networkd-network.h +++ b/src/network/networkd-network.h @@ -241,6 +241,7 @@ struct Network { bool iaid_set; bool required_for_online; /* Is this network required to be considered online? */ + LinkOperationalState required_operstate_for_online; LLDPMode lldp_mode; /* LLDP reception */ LLDPEmit lldp_emit; /* LLDP transmission */ @@ -324,6 +325,7 @@ CONFIG_PARSER_PROTOTYPE(config_parse_section_route_table); CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_user_class); CONFIG_PARSER_PROTOTYPE(config_parse_ntp); CONFIG_PARSER_PROTOTYPE(config_parse_iaid); +CONFIG_PARSER_PROTOTYPE(config_parse_required_for_online); /* Legacy IPv4LL support */ CONFIG_PARSER_PROTOTYPE(config_parse_ipv4ll);