summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUlrich Ölmann <u.oelmann@pengutronix.de>2021-01-06 18:43:06 +0100
committerUlrich Ölmann <u.oelmann@pengutronix.de>2021-01-13 06:41:06 +0100
commitef4a91a7e8d8337a9d65177b09eb7580b25b8f5d (patch)
treeda8d956db0aa74f1072a9444ed9b699017221908
parentlink-config: amend log message for failed application of settings (diff)
downloadsystemd-ef4a91a7e8d8337a9d65177b09eb7580b25b8f5d.tar.xz
systemd-ef4a91a7e8d8337a9d65177b09eb7580b25b8f5d.zip
udev: introduce TxQueueLength= setting
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.
-rw-r--r--man/systemd.link.xml7
-rw-r--r--src/libsystemd/sd-netlink/netlink-util.c13
-rw-r--r--src/libsystemd/sd-netlink/netlink-util.h4
-rw-r--r--src/udev/net/link-config-gperf.gperf1
-rw-r--r--src/udev/net/link-config.c42
-rw-r--r--src/udev/net/link-config.h2
-rw-r--r--test/fuzz/fuzz-link-parser/directives.link1
7 files changed, 61 insertions, 9 deletions
diff --git a/man/systemd.link.xml b/man/systemd.link.xml
index e6b4b54668..8a57511889 100644
--- a/man/systemd.link.xml
+++ b/man/systemd.link.xml
@@ -410,6 +410,13 @@
</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>
<para>The maximum transmission unit in bytes to set for the
diff --git a/src/libsystemd/sd-netlink/netlink-util.c b/src/libsystemd/sd-netlink/netlink-util.c
index 56cde0ffb0..a0bc44e7fb 100644
--- a/src/libsystemd/sd-netlink/netlink-util.c
+++ b/src/libsystemd/sd-netlink/netlink-util.c
@@ -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)
diff --git a/src/libsystemd/sd-netlink/netlink-util.h b/src/libsystemd/sd-netlink/netlink-util.h
index 08b273b5e8..acf5b668a2 100644
--- a/src/libsystemd/sd-netlink/netlink-util.h
+++ b/src/libsystemd/sd-netlink/netlink-util.h
@@ -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);
diff --git a/src/udev/net/link-config-gperf.gperf b/src/udev/net/link-config-gperf.gperf
index 9d66cb284d..e6edc3e804 100644
--- a/src/udev/net/link-config-gperf.gperf
+++ b/src/udev/net/link-config-gperf.gperf
@@ -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)
diff --git a/src/udev/net/link-config.c b/src/udev/net/link-config.c
index 4f22836d13..dbd804ce76 100644
--- a/src/udev/net/link-config.c
+++ b/src/udev/net/link-config.c
@@ -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",
diff --git a/src/udev/net/link-config.h b/src/udev/net/link-config.h
index c563717448..059c48c8af 100644
--- a/src/udev/net/link-config.h
+++ b/src/udev/net/link-config.h
@@ -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);
diff --git a/test/fuzz/fuzz-link-parser/directives.link b/test/fuzz/fuzz-link-parser/directives.link
index f1067568fa..a94573bdd6 100644
--- a/test/fuzz/fuzz-link-parser/directives.link
+++ b/test/fuzz/fuzz-link-parser/directives.link
@@ -20,6 +20,7 @@ Name=
AlternativeNamesPolicy=
AlternativeName=
Alias=
+TxQueueLength=
MTUBytes=
BitsPerSecond=
Duplex=