After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 699649 - platform: incorrect use of kernel ethtool API
platform: incorrect use of kernel ethtool API
Status: RESOLVED FIXED
Product: NetworkManager
Classification: Platform
Component: general
unspecified
Other Linux
: Normal major
: ---
Assigned To: NetworkManager maintainer(s)
NetworkManager maintainer(s)
Depends on:
Blocks: nm-0.9.10
 
 
Reported: 2013-05-03 23:24 UTC by Pavel Simerda
Modified: 2013-05-09 09:19 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
platform: fix use of ethtool (3.21 KB, patch)
2013-05-06 16:59 UTC, Dan Winship
none Details | Review

Description Pavel Simerda 2013-05-03 23:24:56 UTC
I recieved a bug report for my commit in NetworkManager from the kernel folks via e-mail. I must admit I didn't know how to use the ethtool API, found no good documentation and had to seek help for that.

Therefore I'm posting the bug report here as I think I will need help once again.

Cheers,

Pavel

2013/5/2 Bjørn Mork <bjorn@mork.no>:
> Ben Hutchings <bhutchings@solarflare.com> writes:
>> On Thu, 2013-05-02 at 05:17 -0400, David Miller wrote:
>>> From: Bjørn Mork <bjorn@mork.no>
>>> Date: Thu, 02 May 2013 11:06:42 +0200
>>>
>>> > Adding the new netdev features will make it go from 1 to 2:
>>>
>>> We already had more than 31 feature bits before Patrick's
>>> changes, and I'm pretty sure this was the case when we added
>>> that ethtool API.
>>
>> It wasn't, but this should be OK.  Userland is supposed to query the
>> number of features using ETHTOOL_GSSET_INFO and then work out the number
>> of words/blocks using FEATURE_BITS_TO_BLOCKS().
>
>
> Looking at
> http://cgit.freedesktop.org/NetworkManager/NetworkManager/tree/src/platform/nm-linux-platform.c#n1025
> there seems to be a couple of bugs in this area. This is certainly
> abusing the exported API, but it does mean that NM breaks if you ever
> move NETIF_F_VLAN_CHALLENGED (like the 802.1ad patch did):
>
> ----
> #define NETIF_F_VLAN_CHALLENGED (1 << 10)
>
> static gboolean
> link_supports_vlans (NMPlatform *platform, int ifindex)
> {
>         auto_nl_object struct rtnl_link *rtnllink = link_get (platform, ifindex);
>         const char *name = nm_platform_link_get_name (ifindex);
>         struct {
>                 struct ethtool_gfeatures features;
>                 struct ethtool_get_features_block features_block;
>         } edata = { .features = { .cmd = ETHTOOL_GFEATURES, .size = 1 } };
>
>         /* Only ARPHRD_ETHER links can possibly support VLANs. */
>         if (!rtnllink || rtnl_link_get_arptype (rtnllink) != ARPHRD_ETHER)
>                 return FALSE;
>
>         if (!name || !ethtool_get (name, &edata))
>                 return FALSE;
>
>         return !(edata.features.features[0].active & NETIF_F_VLAN_CHALLENGED);
> }
> ----
>
>
> Not that I see how this particular bug matters unless you need VLAN
> support in NM.  But there could be similar issues around.  I guess
> avoiding unnecessary renumbering of the NETIF_F bits can save us some
> trouble.  Although you can certainly argue that those bits never were
> intended to be part of the API, and that using them like this is a user
> application bug.

This is certainly a bug in NM, and a fresh one: commit
b636ea86b1c0a28b77eda311c84d3b2417cad22e from 2013-04-10 14:40:58
(GMT). Userspace is expected to use ETHTOOL_GSTRINGS for
ETH_SS_FEATURES and find a corresponding bit position by feature name
("vlan-challenged" in this case).

Cc: commit's author.

Best Regards,
Michał Mirosław
Comment 1 Dan Winship 2013-05-04 14:42:56 UTC
> Userspace is expected to use ETHTOOL_GSTRINGS for
> ETH_SS_FEATURES and find a corresponding bit position by feature name
> ("vlan-challenged" in this case).

We should probably make a helper function for this; I need to do basically the same thing in NMDeviceVeth (fetch ETH_SS_STATS and use it to figure out which element of ETHTOOL_GSTATS contains the ifindex of the veth's peer).
Comment 2 Pavel Simerda 2013-05-06 14:14:03 UTC
(In reply to comment #1)
> We should probably make a helper function for this; I need to do basically the
> same thing in NMDeviceVeth (fetch ETH_SS_STATS and use it to figure out which
> element of ETHTOOL_GSTATS contains the ifindex of the veth's peer).

Feel free to amend nm-platform to provide the necessary features.
Comment 3 Dan Winship 2013-05-06 16:59:04 UTC
Created attachment 243404 [details] [review]
platform: fix use of ethtool

The bits in the result of ETHTOOL_GFEATURES are not in any defined
order; you need to use ETHTOOL_GSTRINGS to get the names associated
with each bit to find what each one does. Fix
NMPlatformLinux:link_supports_vlans() to do this.
Comment 4 Pavel Simerda 2013-05-06 18:22:33 UTC
We should also try to suppress valgrind's warnings on ethtool calls.
Comment 5 Dan Williams 2013-05-07 19:48:01 UTC
Patch looks OK to me; but geez is that a horrible interface...
Comment 6 Dan Winship 2013-05-07 20:48:21 UTC
(In reply to comment #4)
> We should also try to suppress valgrind's warnings on ethtool calls.

fixed by using g_malloc0() and auto_g_free rather than g_alloca().
Comment 7 Pavel Simerda 2013-05-09 09:19:07 UTC
Thanks!