mirror of
https://github.com/systemd/systemd.git
synced 2024-12-22 17:35:35 +03:00
Add a "RequiredForOnline=" Link attribute for .network files (#7347)
RequiredForOnline= denotes a link/network that does/does not require being up for systemd-networkd-wait-online to consider the system online; this makes it possible to ignore devices without modifying parameters to wait-online.
This commit is contained in:
parent
9d4f242a53
commit
c1a3890410
@ -252,6 +252,21 @@
|
||||
controlled by other applications.</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
<varlistentry>
|
||||
<term><varname>RequiredForOnline=</varname></term>
|
||||
<listitem>
|
||||
<para>A boolean. When <literal>yes</literal>, the network is deemed
|
||||
required when determining whether the system is online when running
|
||||
<literal>systemd-networkd-wait-online</literal>.
|
||||
When <literal>no</literal>, the network is ignored when checking for
|
||||
online state. Defaults to <literal>yes</literal>.</para>
|
||||
<para>The network will be brought up normally in all cases, but in
|
||||
the event that there is no address being assigned by DHCP or the
|
||||
cable is not plugged in, the link will simply remain offline and be
|
||||
skipped automatically by <literal>systemd-networkd-wait-online</literal>
|
||||
if <literal>RequiredForOnline=true</literal>.</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
</variablelist>
|
||||
</refsect1>
|
||||
|
||||
|
@ -172,6 +172,21 @@ _public_ int sd_network_link_get_operational_state(int ifindex, char **state) {
|
||||
return network_link_get_string(ifindex, "OPER_STATE", state);
|
||||
}
|
||||
|
||||
_public_ int sd_network_link_get_required_for_online(int ifindex) {
|
||||
_cleanup_free_ char *s = NULL;
|
||||
int r;
|
||||
|
||||
r = network_link_get_string(ifindex, "REQUIRED_FOR_ONLINE", &s);
|
||||
if (r < 0) {
|
||||
/* Handle -ENODATA as RequiredForOnline=yes, for compatibility */
|
||||
if (r == -ENODATA)
|
||||
return true;
|
||||
return r;
|
||||
}
|
||||
|
||||
return parse_boolean(s);
|
||||
}
|
||||
|
||||
_public_ int sd_network_link_get_llmnr(int ifindex, char **llmnr) {
|
||||
return network_link_get_string(ifindex, "LLMNR", llmnr);
|
||||
}
|
||||
|
@ -3411,6 +3411,9 @@ int link_save(Link *link) {
|
||||
char **dhcp_domains = NULL;
|
||||
unsigned j;
|
||||
|
||||
fprintf(f, "REQUIRED_FOR_ONLINE=%s\n",
|
||||
yes_no(link->network->required_for_online));
|
||||
|
||||
if (link->dhcp6_client) {
|
||||
r = sd_dhcp6_client_get_lease(link->dhcp6_client, &dhcp6_lease);
|
||||
if (r < 0 && r != -ENOMSG)
|
||||
|
@ -33,6 +33,7 @@ Link.MACAddress, config_parse_hwaddr,
|
||||
Link.MTUBytes, config_parse_iec_size, 0, offsetof(Network, mtu)
|
||||
Link.ARP, config_parse_tristate, 0, offsetof(Network, arp)
|
||||
Link.Unmanaged, config_parse_bool, 0, offsetof(Network, unmanaged)
|
||||
Link.RequiredForOnline, config_parse_bool, 0, offsetof(Network, required_for_online)
|
||||
Network.Description, config_parse_string, 0, offsetof(Network, description)
|
||||
Network.Bridge, config_parse_netdev, 0, offsetof(Network, bridge)
|
||||
Network.Bond, config_parse_netdev, 0, offsetof(Network, bond)
|
||||
|
@ -205,6 +205,7 @@ static int network_load_one(Manager *manager, const char *filename) {
|
||||
|
||||
*d = '\0';
|
||||
|
||||
network->required_for_online = true;
|
||||
network->dhcp = ADDRESS_FAMILY_NO;
|
||||
network->dhcp_use_ntp = true;
|
||||
network->dhcp_use_dns = true;
|
||||
|
@ -215,6 +215,8 @@ struct Network {
|
||||
uint32_t iaid;
|
||||
DUID duid;
|
||||
|
||||
bool required_for_online; /* Is this network required to be considered online? */
|
||||
|
||||
LLDPMode lldp_mode; /* LLDP reception */
|
||||
LLDPEmit lldp_emit; /* LLDP transmission */
|
||||
|
||||
|
@ -121,6 +121,8 @@ int link_update_rtnl(Link *l, sd_netlink_message *m) {
|
||||
int link_update_monitor(Link *l) {
|
||||
assert(l);
|
||||
|
||||
l->required_for_online = sd_network_link_get_required_for_online(l->ifindex) != 0;
|
||||
|
||||
l->operational_state = mfree(l->operational_state);
|
||||
|
||||
sd_network_link_get_operational_state(l->ifindex, &l->operational_state);
|
||||
|
@ -33,6 +33,7 @@ struct Link {
|
||||
char *ifname;
|
||||
unsigned flags;
|
||||
|
||||
bool required_for_online;
|
||||
char *operational_state;
|
||||
char *state;
|
||||
};
|
||||
@ -41,6 +42,5 @@ int link_new(Manager *m, Link **ret, int ifindex, const char *ifname);
|
||||
Link *link_free(Link *l);
|
||||
int link_update_rtnl(Link *l, sd_netlink_message *m);
|
||||
int link_update_monitor(Link *l);
|
||||
bool link_relevant(Link *l);
|
||||
|
||||
DEFINE_TRIVIAL_CLEANUP_FUNC(Link*, link_free);
|
||||
|
@ -42,6 +42,9 @@ bool manager_ignore_link(Manager *m, Link *link) {
|
||||
if (m->interfaces && !strv_contains(m->interfaces, link->ifname))
|
||||
return true;
|
||||
|
||||
if (!link->required_for_online)
|
||||
return true;
|
||||
|
||||
/* ignore interfaces we explicitly are asked to ignore */
|
||||
return strv_fnmatch(m->ignore, link->ifname, 0);
|
||||
}
|
||||
|
@ -95,6 +95,14 @@ int sd_network_link_get_setup_state(int ifindex, char **state);
|
||||
*/
|
||||
int sd_network_link_get_operational_state(int ifindex, char **state);
|
||||
|
||||
/* Indicates whether the network is relevant to being online.
|
||||
* Possible return codes:
|
||||
* 0: the connection is not required
|
||||
* 1: the connection is required to consider the system online
|
||||
* <0: networkd is not aware of the link
|
||||
*/
|
||||
int sd_network_link_get_required_for_online(int ifindex);
|
||||
|
||||
/* Get path to .network file applied to link */
|
||||
int sd_network_link_get_network_file(int ifindex, char **filename);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user