little-dude / netlink

netlink libraries for rust
Other
332 stars 89 forks source link

Netlink taskstats #272

Closed mhupfer closed 1 year ago

mhupfer commented 2 years ago

Netlink task statistics support

mhupfer commented 2 years ago

This is a somewhat surprising answer since the taskstats are received via a NETLINK_GENERIC protocol ...

cathay4t commented 1 year ago

The ethtool, nl80211, wireguard, netfilter, taskstats are all NETLINK_GENERIC based. They all register a generic netlink family at runtime (genl_register_family()). In stead of bloating netlink-packet-generic, please create a new crate task-stats. You may take ethtool or mptcp-pm as example.

I also have a blog https://blog.grisge.info/posts/ethtool_netlink_intro/ explaining how generic netlink should be parsed.

You can simply implement the trait GenlFamily, something like:

impl GenlFamily for TaskStats {
    fn family_name() -> &'static str {
        "TASKSTATS"
    }

    fn version(&self) -> u8 {
        1
    }

    fn command(&self) -> u8 {
        self.cmd.into()
    }
}
cathay4t commented 1 year ago

The kernel has #define TASKSTATS_GENL_NAME "TASKSTATS". But your code is using lower case taskstats as family name.

mhupfer commented 1 year ago

I will close this PR and create a new one which hopefully satisfies your requirements.