summaryrefslogtreecommitdiffstats
path: root/collectors/cgroups.plugin
diff options
context:
space:
mode:
authorIlya Mashchenko <ilya@netdata.cloud>2022-05-02 16:37:09 +0300
committerGitHub <noreply@github.com>2022-05-02 16:37:09 +0300
commitdb9b85a9cb9eac7b55a4145207ccc407e4064f4c (patch)
treea17c465acfe2265cb601c67a6906e57710dc16a0 /collectors/cgroups.plugin
parentcba0dca1f69f5ea8fc4d35cb35463a71349f654d (diff)
fix(cgroups.plugin): do not add network devices if cgroup proc is in the host net ns (#12788)
Diffstat (limited to 'collectors/cgroups.plugin')
-rw-r--r--collectors/cgroups.plugin/cgroup-network.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/collectors/cgroups.plugin/cgroup-network.c b/collectors/cgroups.plugin/cgroup-network.c
index bd7822609c..ec3d814c64 100644
--- a/collectors/cgroups.plugin/cgroup-network.c
+++ b/collectors/cgroups.plugin/cgroup-network.c
@@ -27,6 +27,14 @@ struct iface {
struct iface *next;
};
+unsigned int calc_num_ifaces(struct iface *root) {
+ unsigned int num = 0;
+ for (struct iface *h = root; h; h = h->next) {
+ num++;
+ }
+ return num;
+}
+
unsigned int read_iface_iflink(const char *prefix, const char *iface) {
if(!prefix) prefix = "";
@@ -447,6 +455,25 @@ void detect_veth_interfaces(pid_t pid) {
goto cleanup;
}
+ unsigned int host_dev_num = calc_num_ifaces(host);
+ unsigned int cgroup_dev_num = calc_num_ifaces(cgroup);
+ // host ifaces == guest ifaces => we are still in the host namespace
+ // and we can't really identify which ifaces belong to the cgroup (e.g. Proxmox VM).
+ if (host_dev_num == cgroup_dev_num) {
+ unsigned int m = 0;
+ for (h = host; h; h = h->next) {
+ for (c = cgroup; c; c = c->next) {
+ if (h->ifindex == c->ifindex && h->iflink == c->iflink) {
+ m++;
+ break;
+ }
+ }
+ }
+ if (host_dev_num == m) {
+ goto cleanup;
+ }
+ }
+
for(h = host; h ; h = h->next) {
if(iface_is_eligible(h)) {
for (c = cgroup; c; c = c->next) {