1
0
mirror of https://github.com/systemd/systemd.git synced 2024-11-04 13:51:24 +03:00

network: make RequiredForOnline= also take operational state

This will be used by systemd-networkd-wait-online.
This commit is contained in:
Yu Watanabe 2019-03-06 14:29:49 +09:00
parent f9974167e4
commit 4ac77d63e9
4 changed files with 50 additions and 1 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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;
}

View File

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