Discussion:
Trouble with speed/mode in .link files
(too old to reply)
Bruce A. Johnson
2018-01-02 18:32:50 UTC
Permalink
Raw Message
I've been trying for a few days to figure out how to set Ethernet speed
and mode using a .link file, and I can't figure out what I'm doing
wrong.  I've got a renamed interface ("eth2" -> "en01"), and ethtool
allows me to change it with no problem, but I get "Invalid argument"
messages from link_config, and the device ends up with the speed of the
connected switch and half-duplex.
# cat /etc/systemd/network/80-en01.link
[Match]
MACAddress=00:0d:b9:48:36:4a
[Link]
AutoNegotiation=no
Duplex=full
BitsPerSecond=10M
# udevadm test-builtin net_setup_link /sys/class/net/en01
calling: test-builtin
=== trie on-disk ===
tool version:          234
file size:         8715156 bytes
header size             80 bytes
strings            1900828 bytes
nodes              6814248 bytes
Found container virtualization none.
timestamp of '/etc/systemd/network' changed
timestamp of '/run/systemd/network' changed
ID_NET_DRIVER=igb
link_config: Cannot set device settings for en01 : Invalid argument
Could not set speed or duplex of en01 to 10 Mbps (full): Invalid argument
ID_NET_LINK_FILE=/etc/systemd/network/80-en01.link
I'm running systemd version 234, built from source using OpenEmbedded.
--
Bruce A. Johnson
Chantilly, Virginia
Bruce A. Johnson
2018-01-03 20:32:39 UTC
Permalink
Raw Message
My problem seems to be a bug in ethtool-util.c's set_slinksettings().
The base parameters were not being copied into the ethtool_link_settings
request, so they were all zero and ioctl didn't like that.  I've pasted
the patch below.  Please let me know if there is anything else I need to
do to get this to the right person.

Thanks!
--
Bruce A Johnson
Chantilly, Virginia

diff --git a/src/udev/net/ethtool-util.c b/src/udev/net/ethtool-util.c
index 201fc23..a16ea07 100644
--- a/src/udev/net/ethtool-util.c
+++ b/src/udev/net/ethtool-util.c
@@ -436,15 +436,16 @@ static int set_slinksettings(int *fd, struct ifreq *ifr, const struct ethtool_li
struct {
struct ethtool_link_settings req;
__u32 link_mode_data[3 * ETHTOOL_LINK_MODE_MASK_MAX_KERNEL_NU32];
- } ecmd = {
- .req.cmd = ETHTOOL_SLINKSETTINGS,
- };
+ } ecmd;
unsigned int offset;
int r;

if (u->base.cmd != ETHTOOL_GLINKSETTINGS || u->base.link_mode_masks_nwords <= 0)
return -EINVAL;

+ memset(&ecmd, sizeof(ecmd), 0);
+ memcpy(&ecmd.req, &u->base, sizeof(ecmd.req));
+ ecmd.req.cmd = ETHTOOL_SLINKSETTINGS;
offset = 0;
memcpy(&ecmd.link_mode_data[offset], u->link_modes.supported, 4 * ecmd.req.link_mode_masks_nwords);
Mantas Mikulėnas
2018-01-04 11:37:16 UTC
Permalink
Raw Message
On Wed, Jan 3, 2018 at 10:32 PM, Bruce A. Johnson <
Post by Bruce A. Johnson
My problem seems to be a bug in ethtool-util.c's set_slinksettings().
The base parameters were not being copied into the ethtool_link_settings
request, so they were all zero and ioctl didn't like that. I've pasted
the patch below. Please let me know if there is anything else I need to
do to get this to the right person.
It would be best if you could submit a pull request on GitHub:
https://github.com/systemd/systemd

Although patches via email are occassionally accepted, at minimum you
should send full commits using `git send-email` (or `git format-patch`).
--
Mantas Mikulėnas
Lennart Poettering
2018-01-04 12:19:36 UTC
Permalink
Raw Message
Post by Bruce A. Johnson
My problem seems to be a bug in ethtool-util.c's set_slinksettings().
The base parameters were not being copied into the ethtool_link_settings
request, so they were all zero and ioctl didn't like that.  I've pasted
the patch below.  Please let me know if there is anything else I need to
do to get this to the right person.
Could you submit this as PR on github please? This makes review much
easier! Thanks!
Post by Bruce A. Johnson
__u32 link_mode_data[3 * ETHTOOL_LINK_MODE_MASK_MAX_KERNEL_NU32];
- } ecmd = {
- .req.cmd = ETHTOOL_SLINKSETTINGS,
- };
+ } ecmd;
unsigned int offset;
int r;
if (u->base.cmd != ETHTOOL_GLINKSETTINGS || u->base.link_mode_masks_nwords <= 0)
return -EINVAL;
+ memset(&ecmd, sizeof(ecmd), 0);
+ memcpy(&ecmd.req, &u->base, sizeof(ecmd.req));
+ ecmd.req.cmd = ETHTOOL_SLINKSETTINGS;
We genereally pefer initialization at declaration time instead of
explicit memset(), as this tends to provide nicer code. Hence, please
keep at least the zero-initialization in the declaratin above.

Lennart
--
Lennart Poettering, Red Hat
Lennart Poettering
2018-01-24 10:29:48 UTC
Permalink
Raw Message
Post by Bruce A. Johnson
I've been trying for a few days to figure out how to set Ethernet speed
and mode using a .link file, and I can't figure out what I'm doing
wrong.  I've got a renamed interface ("eth2" -> "en01"), and ethtool
allows me to change it with no problem, but I get "Invalid argument"
messages from link_config, and the device ends up with the speed of the
connected switch and half-duplex.
# cat /etc/systemd/network/80-en01.link
[Match]
MACAddress=00:0d:b9:48:36:4a
[Link]
AutoNegotiation=no
Duplex=full
BitsPerSecond=10M
# udevadm test-builtin net_setup_link /sys/class/net/en01
calling: test-builtin
=== trie on-disk ===
tool version:          234
file size:         8715156 bytes
header size             80 bytes
strings            1900828 bytes
nodes              6814248 bytes
Found container virtualization none.
timestamp of '/etc/systemd/network' changed
timestamp of '/run/systemd/network' changed
ID_NET_DRIVER=igb
link_config: Cannot set device settings for en01 : Invalid argument
Could not set speed or duplex of en01 to 10 Mbps (full): Invalid argument
ID_NET_LINK_FILE=/etc/systemd/network/80-en01.link
I'm running systemd version 234, built from source using OpenEmbedded.
There were some fixes in the area recently, consider upgrading to
something newer, please.

Lennart
--
Lennart Poettering, Red Hat
Loading...