]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
Add a "RequiredForOnline=" Link attribute for .network files (#7347)
authorMathieu Trudel-Lapierre <mathieu.tl@gmail.com>
Thu, 30 Nov 2017 17:03:50 +0000 (12:03 -0500)
committerLennart Poettering <lennart@poettering.net>
Thu, 30 Nov 2017 17:03:50 +0000 (18:03 +0100)
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.

man/systemd.network.xml
src/libsystemd/sd-network/sd-network.c
src/network/networkd-link.c
src/network/networkd-network-gperf.gperf
src/network/networkd-network.c
src/network/networkd-network.h
src/network/wait-online/link.c
src/network/wait-online/link.h
src/network/wait-online/manager.c
src/systemd/sd-network.h

index 57f27e6f37afaca6d566e3e3e532b8922e65d5ce..5a5ecb0b168f4277a8435a033bbc1e53f77948c8 100644 (file)
           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>
 
index e0f38b62aa305f91cbea95a341197995df3c8e49..f6460b9f7c062f6d5cad6bef52db67e4d2ceb157 100644 (file)
@@ -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);
 }
index 473bd420d4fa81f8b897df3323e6719450daae74..67cdea0b9f9f53d423a8ff6fddd0f332f5156e74 100644 (file)
@@ -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)
index 62c47d6eae0cf1fd678acf25dd14dacb628dd8b9..46eaa8140047ab8d7add393490899c7f50cfbf5e 100644 (file)
@@ -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)
index 679d7ed36c3b7ca9138dd3b944e27c8ed801c09a..8e37a0a229f2da2c124f622bcb6db9a141f9293f 100644 (file)
@@ -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;
index 4265ba634e225ce3af2e8d172af501653ec04ef9..49c62654b6b72a1ffabf2ec379c02924ccf9eae2 100644 (file)
@@ -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 */
 
index dfe18bd9601cfb92babbc3005f1baee2bf293c1d..f0cb70ab4cbb20c11c04b725b058024f478051fc 100644 (file)
@@ -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);
index bf8b453c28980d2afbf1b74ed25c62c08b3b57cd..ab623ff4de768bfed7bfb9cb34ccf53108b7a772 100644 (file)
@@ -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);
index f7a3ec849546c8491d0d06a3a6ba38d7e382a259..05f030dbe78d45f76ac9084e520fc6e82494dd95 100644 (file)
@@ -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);
 }
index 7f5a6bd3fa1b1bfbfb336f7c1531ef4af4678746..2d48946d2a0221e647a4a3f7c810fc1f4088ef0f 100644 (file)
@@ -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);