]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/network/networkd-sriov.c
tree-wide: use UINT64_MAX or friends
[thirdparty/systemd.git] / src / network / networkd-sriov.c
index 5ae751ed46f95efc3f6d40e17c081f2f287bd1b1..7a76b61c4aefec0384bb1b92500564b0717eb4df 100644 (file)
@@ -1,4 +1,4 @@
-/* SPDX-License-Identifier: LGPL-2.1+
+/* SPDX-License-Identifier: LGPL-2.1-or-later
  * Copyright © 2020 VMware, Inc. */
 
 #include "alloc-util.h"
@@ -17,7 +17,7 @@ static int sr_iov_new(SRIOV **ret) {
                 return -ENOMEM;
 
         *sr_iov = (SRIOV) {
-                  .vf = (uint32_t) -1,
+                  .vf = UINT32_MAX,
                   .vlan_proto = ETH_P_8021Q,
                   .vf_spoof_check_setting = -1,
                   .trust = -1,
@@ -58,11 +58,7 @@ static int sr_iov_new_static(Network *network, const char *filename, unsigned se
         sr_iov->network = network;
         sr_iov->section = TAKE_PTR(n);
 
-        r = ordered_hashmap_ensure_allocated(&network->sr_iov_by_section, &network_config_hash_ops);
-        if (r < 0)
-                return r;
-
-        r = ordered_hashmap_put(network->sr_iov_by_section, sr_iov->section, sr_iov);
+        r = ordered_hashmap_ensure_put(&network->sr_iov_by_section, &network_config_hash_ops, sr_iov->section, sr_iov);
         if (r < 0)
                 return r;
 
@@ -108,7 +104,7 @@ static int sr_iov_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) {
         return 1;
 }
 
-int sr_iov_configure(Link *link, SRIOV *sr_iov) {
+static int sr_iov_configure(Link *link, SRIOV *sr_iov) {
         _cleanup_(sd_netlink_message_unrefp) sd_netlink_message *req = NULL;
         int r;
 
@@ -226,13 +222,41 @@ int sr_iov_configure(Link *link, SRIOV *sr_iov) {
         return 0;
 }
 
-int sr_iov_section_verify(SRIOV *sr_iov) {
+int link_configure_sr_iov(Link *link) {
+        SRIOV *sr_iov;
+        int r;
+
+        assert(link);
+        assert(link->network);
+
+        if (link->sr_iov_messages != 0) {
+                log_link_debug(link, "SR-IOV is configuring.");
+                return 0;
+        }
+
+        link->sr_iov_configured = false;
+
+        ORDERED_HASHMAP_FOREACH(sr_iov, link->network->sr_iov_by_section) {
+                r = sr_iov_configure(link, sr_iov);
+                if (r < 0)
+                        return r;
+        }
+
+        if (link->sr_iov_messages == 0)
+                link->sr_iov_configured = true;
+        else
+                log_link_debug(link, "Configuring SR-IOV");
+
+        return 0;
+}
+
+static int sr_iov_section_verify(SRIOV *sr_iov) {
         assert(sr_iov);
 
         if (section_is_invalid(sr_iov->section))
                 return -EINVAL;
 
-        if (sr_iov->vf == (uint32_t) -1)
+        if (sr_iov->vf == UINT32_MAX)
                 return log_warning_errno(SYNTHETIC_ERRNO(EINVAL),
                                          "%s: [SRIOV] section without VirtualFunction= field configured. "
                                          "Ignoring [SRIOV] section from line %u.",
@@ -241,6 +265,16 @@ int sr_iov_section_verify(SRIOV *sr_iov) {
         return 0;
 }
 
+void network_drop_invalid_sr_iov(Network *network) {
+        SRIOV *sr_iov;
+
+        assert(network);
+
+        ORDERED_HASHMAP_FOREACH(sr_iov, network->sr_iov_by_section)
+                if (sr_iov_section_verify(sr_iov) < 0)
+                        sr_iov_free(sr_iov);
+}
+
 int config_parse_sr_iov_uint32(
                 const char *unit,
                 const char *filename,
@@ -269,7 +303,7 @@ int config_parse_sr_iov_uint32(
 
         if (isempty(rvalue)) {
                 if (streq(lvalue, "VirtualFunction"))
-                        sr_iov->vf = (uint32_t) -1;
+                        sr_iov->vf = UINT32_MAX;
                 else if (streq(lvalue, "VLANId"))
                         sr_iov->vlan = 0;
                 else if (streq(lvalue, "QualityOfService"))
@@ -283,20 +317,20 @@ int config_parse_sr_iov_uint32(
 
         r = safe_atou32(rvalue, &k);
         if (r < 0) {
-                log_syntax(unit, LOG_ERR, filename, line, r,
+                log_syntax(unit, LOG_WARNING, filename, line, r,
                            "Failed to parse SR-IOV '%s=', ignoring assignment: %s", lvalue, rvalue);
                 return 0;
         }
 
         if (streq(lvalue, "VLANId")) {
                 if (k == 0 || k > 4095) {
-                        log_syntax(unit, LOG_ERR, filename, line, 0, "Invalid SR-IOV VLANId: %d", k);
+                        log_syntax(unit, LOG_WARNING, filename, line, 0, "Invalid SR-IOV VLANId: %d", k);
                         return 0;
                 }
                 sr_iov->vlan = k;
         } else if (streq(lvalue, "VirtualFunction")) {
                 if (k >= INT_MAX) {
-                        log_syntax(unit, LOG_ERR, filename, line, 0, "Invalid SR-IOV virtual function: %d", k);
+                        log_syntax(unit, LOG_WARNING, filename, line, 0, "Invalid SR-IOV virtual function: %d", k);
                         return 0;
                 }
                 sr_iov->vf = k;
@@ -339,7 +373,7 @@ int config_parse_sr_iov_vlan_proto(
         else if (streq(rvalue, "802.1ad"))
                 sr_iov->vlan_proto = ETH_P_8021AD;
         else {
-                log_syntax(unit, LOG_ERR, filename, line, 0,
+                log_syntax(unit, LOG_WARNING, filename, line, 0,
                            "Invalid SR-IOV '%s=', ignoring assignment: %s", lvalue, rvalue);
                 return 0;
         }
@@ -390,7 +424,7 @@ int config_parse_sr_iov_link_state(
 
         r = parse_boolean(rvalue);
         if (r < 0) {
-                log_syntax(unit, LOG_ERR, filename, line, r,
+                log_syntax(unit, LOG_WARNING, filename, line, r,
                            "Failed to parse SR-IOV '%s=', ignoring assignment: %s", lvalue, rvalue);
                 return 0;
         }
@@ -441,7 +475,7 @@ int config_parse_sr_iov_boolean(
 
         r = parse_boolean(rvalue);
         if (r < 0) {
-                log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse '%s=', ignoring: %s", lvalue, rvalue);
+                log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse '%s=', ignoring: %s", lvalue, rvalue);
                 return 0;
         }
 
@@ -491,7 +525,7 @@ int config_parse_sr_iov_mac(
 
         r = ether_addr_from_string(rvalue, &sr_iov->mac);
         if (r < 0) {
-                log_syntax(unit, LOG_ERR, filename, line, 0,
+                log_syntax(unit, LOG_WARNING, filename, line, r,
                            "Failed to parse SR-IOV '%s=', ignoring assignment: %s", lvalue, rvalue);
                 return 0;
         }