Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Network statistics unavailable for interfaces after switching network namespace on Linux #1053

Open
rvql opened this issue Aug 31, 2023 · 1 comment

Comments

@rvql
Copy link

rvql commented Aug 31, 2023

Describe the bug
I'm using sysinfo 0.26 on CentOS 7.

Sysinfo is reading /sys/class/net for interface list, but setting network namespace will not refresh sysfs, making it impossible for sysinfo to read statistics for interfaces in the new namespace.

To Reproduce

The code:

use sysinfo::{System, SystemExt, NetworksExt};

fn main() {
    let mut system = System::new();
    system.refresh_networks_list();
    system.networks().iter().for_each(|(s, _)| println!("{}", s));
}

Compile this code as netns and run it under CentOS 7:

[root@mars-1 ~]# ip netns add test
[root@mars-1 ~]# nsenter --net=/var/run/netns/test ip a
1: lo: <LOOPBACK> mtu 65536 qdisc noop state DOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: tunl0@NONE: <NOARP> mtu 1480 qdisc noop state DOWN group default qlen 1000
    link/ipip 0.0.0.0 brd 0.0.0.0
[root@mars-1 ~]# nsenter --net=/var/run/netns/test ./netns
cali90f3eb8a8da
calif27411bfc29
cali31894e8eb51
cali05f070dffe3
calia118c7520e3
lo
cali577f4fcaaf9
tunl0
... (more)

A possible fix is to use netlink to retrieve interface statistics.

@GuillaumeGomez
Copy link
Owner

Thanks for the bug report! I'll need to check how netlink works, might take some time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants