]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
udev: introduce TxQueueLength= setting 18170/head
authorUlrich Ölmann <u.oelmann@pengutronix.de>
Wed, 6 Jan 2021 17:43:06 +0000 (18:43 +0100)
committerUlrich Ölmann <u.oelmann@pengutronix.de>
Wed, 13 Jan 2021 05:41:06 +0000 (06:41 +0100)
Enable udev to set the transmit queue length of a device via a new directive to
be used in link files. The kernel stores this parameter as an unsigned 32 bit
integer. As typical values currently range in the order of 10 to a few 10,000
packets reduce the domain of valid values for this directive to 0..4294967294
and take the excluded 4294967295 == UINT32_MAX to indicate that the directive
is unset.

man/systemd.link.xml
src/libsystemd/sd-netlink/netlink-util.c
src/libsystemd/sd-netlink/netlink-util.h
src/udev/net/link-config-gperf.gperf
src/udev/net/link-config.c
src/udev/net/link-config.h
test/fuzz/fuzz-link-parser/directives.link

index e6b4b546688e3650a2852cd31f9fe75ba12ded54..8a57511889b4b70965d4eb255daccff41e94bf31 100644 (file)
           be ignored.</para>
         </listitem>
       </varlistentry>
+      <varlistentry>
+        <term><varname>TxQueueLength=</varname></term>
+        <listitem>
+          <para>Specifies the transmit queue length of the device in number of packets. An unsigned integer
+          in the range 0..4294967294. When unset, the kernel's default will be used.</para>
+        </listitem>
+      </varlistentry>
       <varlistentry>
         <term><varname>MTUBytes=</varname></term>
         <listitem>
index 56cde0ffb05504cc34731be655a3fea4c7bcd384..a0bc44e7fbbf14503098d50dede031d5dc5d78e3 100644 (file)
@@ -57,16 +57,15 @@ int rtnl_set_link_name(sd_netlink **rtnl, int ifindex, const char *name) {
         return 0;
 }
 
-int rtnl_set_link_properties(sd_netlink **rtnl, int ifindex, const char *alias,
-                             const struct ether_addr *mac, uint32_t mtu,
-                             uint32_t gso_max_size, size_t gso_max_segments) {
+int rtnl_set_link_properties(sd_netlink **rtnl, int ifindex, const char *alias, const struct ether_addr *mac,
+                             uint32_t txqueuelen, uint32_t mtu, uint32_t gso_max_size, size_t gso_max_segments) {
         _cleanup_(sd_netlink_message_unrefp) sd_netlink_message *message = NULL;
         int r;
 
         assert(rtnl);
         assert(ifindex > 0);
 
-        if (!alias && !mac && mtu == 0 && gso_max_size == 0 && gso_max_segments == 0)
+        if (!alias && !mac && txqueuelen == UINT32_MAX && mtu == 0 && gso_max_size == 0 && gso_max_segments == 0)
                 return 0;
 
         if (!*rtnl) {
@@ -91,6 +90,12 @@ int rtnl_set_link_properties(sd_netlink **rtnl, int ifindex, const char *alias,
                         return r;
         }
 
+        if (txqueuelen < UINT32_MAX) {
+                r = sd_netlink_message_append_u32(message, IFLA_TXQLEN, txqueuelen);
+                if (r < 0)
+                        return r;
+        }
+
         if (mtu != 0) {
                 r = sd_netlink_message_append_u32(message, IFLA_MTU, mtu);
                 if (r < 0)
index 08b273b5e8a0008aab368c115bc4f679162abf5d..acf5b668a293fbcb83ecde6b7a4d66f7418d3ef7 100644 (file)
@@ -70,8 +70,8 @@ static inline bool rtnl_message_type_is_mdb(uint16_t type) {
 }
 
 int rtnl_set_link_name(sd_netlink **rtnl, int ifindex, const char *name);
-int rtnl_set_link_properties(sd_netlink **rtnl, int ifindex, const char *alias, const struct ether_addr *mac, uint32_t mtu,
-                             uint32_t gso_max_size, size_t gso_max_segments);
+int rtnl_set_link_properties(sd_netlink **rtnl, int ifindex, const char *alias, const struct ether_addr *mac,
+                             uint32_t txqueuelen, uint32_t mtu, uint32_t gso_max_size, size_t gso_max_segments);
 int rtnl_get_link_alternative_names(sd_netlink **rtnl, int ifindex, char ***ret);
 int rtnl_set_link_alternative_names(sd_netlink **rtnl, int ifindex, char * const *alternative_names);
 int rtnl_set_link_alternative_names_by_ifname(sd_netlink **rtnl, const char *ifname, char * const *alternative_names);
index 9d66cb284dc87b4ca5e26c107f1e1e0277699b42..e6edc3e804d55537247512d748426e1426029c89 100644 (file)
@@ -40,6 +40,7 @@ Link.Name,                             config_parse_ifname,                   0,
 Link.AlternativeName,                  config_parse_ifnames,                  IFNAME_VALID_ALTERNATIVE,      offsetof(link_config, alternative_names)
 Link.AlternativeNamesPolicy,           config_parse_alternative_names_policy, 0,                             offsetof(link_config, alternative_names_policy)
 Link.Alias,                            config_parse_ifalias,                  0,                             offsetof(link_config, alias)
+Link.TxQueueLength,                    config_parse_txqueuelen,               0,                             offsetof(link_config, txqueuelen)
 Link.MTUBytes,                         config_parse_mtu,                      AF_UNSPEC,                     offsetof(link_config, mtu)
 Link.BitsPerSecond,                    config_parse_si_uint64,                0,                             offsetof(link_config, speed)
 Link.Duplex,                           config_parse_duplex,                   0,                             offsetof(link_config, duplex)
index 4f22836d13f65a74bb29d51d6a8cb12ba5b1113d..dbd804ce7644bf439e2e93971a669441523442a3 100644 (file)
@@ -150,6 +150,7 @@ int link_load_one(link_config_ctx *ctx, const char *filename) {
                 .rx_flow_control = -1,
                 .tx_flow_control = -1,
                 .autoneg_flow_control = -1,
+                .txqueuelen = UINT32_MAX,
         };
 
         for (i = 0; i < ELEMENTSOF(link->features); i++)
@@ -426,10 +427,11 @@ static int link_config_apply_rtnl_settings(sd_netlink **rtnl, const link_config
         } else
                 mac = config->mac;
 
-        r = rtnl_set_link_properties(rtnl, ifindex, config->alias, mac, config->mtu, config->gso_max_size, config->gso_max_segments);
+        r = rtnl_set_link_properties(rtnl, ifindex, config->alias, mac, config->txqueuelen, config->mtu,
+                                     config->gso_max_size, config->gso_max_segments);
         if (r < 0)
-                log_device_warning_errno(device, r, "Could not set Alias=, MACAddress=, MTU=, GenericSegmentOffloadMaxBytes= "
-                                         "or GenericSegmentOffloadMaxSegments=, ignoring: %m");
+                log_device_warning_errno(device, r, "Could not set Alias=, MACAddress=, TxQueueLength=, MTU=, "
+                                        "GenericSegmentOffloadMaxBytes= or GenericSegmentOffloadMaxSegments=, ignoring: %m");
 
         return 0;
 }
@@ -702,6 +704,40 @@ int config_parse_ifalias(
         return 0;
 }
 
+int config_parse_txqueuelen(
+                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) {
+
+        uint32_t k, *v = data;
+        int r;
+
+        if (isempty(rvalue)) {
+                *v = UINT32_MAX;
+                return 0;
+        }
+
+        r = safe_atou32(rvalue, &k);
+        if (r < 0) {
+                log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse %s=, ignoring assignment: %s.", lvalue, rvalue);
+                return 0;
+        }
+        if (k == UINT32_MAX) {
+                log_syntax(unit, LOG_WARNING, filename, line, 0, "Invalid %s=, ignoring assignment: %s.", lvalue, rvalue);
+                return 0;
+        }
+
+        *v = k;
+        return 0;
+}
+
 static const char* const mac_address_policy_table[_MAC_ADDRESS_POLICY_MAX] = {
         [MAC_ADDRESS_POLICY_PERSISTENT] = "persistent",
         [MAC_ADDRESS_POLICY_RANDOM] = "random",
index c5637174487e87c4ecdc9bb10619f8f8f2e43a04..059c48c8af4b9b19ea51a27437d511bc189f5e66 100644 (file)
@@ -46,6 +46,7 @@ struct link_config {
         char *name;
         char **alternative_names;
         char *alias;
+        uint32_t txqueuelen;
         uint32_t mtu;
         uint32_t gso_max_segments;
         size_t gso_max_size;
@@ -90,6 +91,7 @@ MACAddressPolicy mac_address_policy_from_string(const char *p) _pure_;
 const struct ConfigPerfItem* link_config_gperf_lookup(const char *key, GPERF_LEN_TYPE length);
 
 CONFIG_PARSER_PROTOTYPE(config_parse_ifalias);
+CONFIG_PARSER_PROTOTYPE(config_parse_txqueuelen);
 CONFIG_PARSER_PROTOTYPE(config_parse_mac_address_policy);
 CONFIG_PARSER_PROTOTYPE(config_parse_name_policy);
 CONFIG_PARSER_PROTOTYPE(config_parse_alternative_names_policy);
index f1067568fae28481df0c4cfcfbeefdf393cf6402..a94573bdd651b534e799be9148343a0f53b287e9 100644 (file)
@@ -20,6 +20,7 @@ Name=
 AlternativeNamesPolicy=
 AlternativeName=
 Alias=
+TxQueueLength=
 MTUBytes=
 BitsPerSecond=
 Duplex=