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.
This commit is contained in:
Ulrich Ölmann 2021-01-06 18:43:06 +01:00
parent 42e15a6f1a
commit ef4a91a7e8
7 changed files with 61 additions and 9 deletions

View file

@ -409,6 +409,13 @@
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>

View 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)

View 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);

View 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)

View 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",

View 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);

View file

@ -20,6 +20,7 @@ Name=
AlternativeNamesPolicy=
AlternativeName=
Alias=
TxQueueLength=
MTUBytes=
BitsPerSecond=
Duplex=