safchain / ethtool

A simple ethtool "like" library for GO
Apache License 2.0
116 stars 69 forks source link

Add Names for supported capabilities of interfaces #47

Closed gutjuri closed 1 year ago

gutjuri commented 2 years ago

Currently, one can acquire a bitmask of supported modes of operation by using the GetCmdMapped function:

e, err := ethtool.NewEthtool()
if err != nil {
    panic(err.Error())
}
defer e.Close()
cmdGet, err := e.CmdGetMapped(*name)
if err != nil {
    panic(err.Error())
}
fmt.Printf("cmd get: %+d\n", cmdGet["Supported"])

Unfortunately, there is no information on what the individual bits mean.

In this PR, I added the names of some supported capabilities (which I got from here: https://github.com/lyonel/lshw/blob/fdab06ac0b190ea0aa02cd468f904ed69ce0d9f1/src/core/network.cc#L113). This enables users of this library to seamlessly check, which capacities the interface in question supports.

closes #46

ventifus commented 2 years ago

Hi gutjuri,

These bit flags are actually in go already, in the golang.org/x/sys/unix package. Here's how we use those constants in node_exporter:

https://github.com/prometheus/node_exporter/blob/e3a18fdd37447992c213f42d61fdaed997fe9351/collector/ethtool_linux.go#L277

gutjuri commented 2 years ago

Thanks for this info. I wasn't aware of that, I guess this makes this PR redundant

gutjuri commented 1 year ago

@safchain Would you like to merge this PR into your project? Otherwise I'd close this PR. Or are more changes required?