]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network: make RequiredForOnline= also take operational state
authorYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 6 Mar 2019 05:29:49 +0000 (14:29 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 13 Mar 2019 05:29:03 +0000 (14:29 +0900)
This will be used by systemd-networkd-wait-online.

src/network/networkd-link.c
src/network/networkd-network-gperf.gperf
src/network/networkd-network.c
src/network/networkd-network.h

index 9a4ba7a93a5cc17559cb7ffc3d461128c573ff2c..bc8c180665fc9f25d0eb61bb004060c47c346427 100644 (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)
index 51123d12ef0cacd1751b55cd7f3e6d15db6beb90..73a7fcdf086bbf5a21e34323926ec23ac3160a00 100644 (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)
index 5f12df907afe9afcc8127c89fa2f49b44fac116f..fe26720103af3186bdc9918cbba113114c3c8373 100644 (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;
+}
index 2f7b6133fd506a3ebdda3b0d6f8cbeb7b2adbb02..2561bba1bc0ecd2d962dbba9528df6928d285ae0 100644 (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);