jbaublitz / neli

Rust type safe netlink library
BSD 3-Clause "New" or "Revised" License
180 stars 35 forks source link

Access ethtool interface using neli #222

Closed cueo closed 1 year ago

cueo commented 1 year ago

Is this a question about neli specifically? If so, please describe. I wish to use neli to access ethtool interface (specifically ethtool -S <ifname> command). I am wondering if neli in its current state can be used to do that.

I have written a sample program which attempts to use neli to interface and send and receive an ethtool command (specifically, the ETHTOOL_MSG_STATS_GET command). Here’s a small project which I pushed to GitHub: ethtool.

However, I keep running into the error: "Error response received from netlink: No such file or directory (os error 2)” or "Operation not supported".

I’d appreciate any help whatsoever. Here's the code in question. I’m fairly certain the way I'm constructing the attributes in not the right way to do so.

Finally, thanks a lot for creating this library. It was an amazing source of learning for me (both about netlink and Rust).

jbaublitz commented 1 year ago

Hi @cueo, after digging into this a bit, I'm almost 100% confident that this is a user error largely because the code I'm seeing doesn't match the documentation that I'm reading. For example, nowhere do I see a nested netlink attribute in your code which is specifically called out in the documentation you linked. I'm not myself familiar with ethtool's protocol, but I'd recommend reading up on nested attributes because you simply have added attributes to the generic netlink message. Likely you need some sort of container attribute with values that I'm not sure of and then inside that container attribute, you need to add a nested attribute with a struct of the format specified in the documentation. Another error that I just wanted to call out since I saw it is the value of ETHTOOL_GENL_NAME. On my system, that macro evaluates to a string, not to a u8. Hope this helps point you in the right direction!