fix(cgroups.plugin): do not add network devices if cgroup proc is in the host net ns (#12788)
Ilya Mashchenko committed
May 2, 2022 at 16:37 UTC
db9b85a9cb9eac7b55a4145207ccc407e4064f4c
1 file changed
+27
collectors/cgroups.plugin/cgroup-network.c
+27
@@ -27,6 +27,14 @@ struct iface {
27
struct iface *next;
28
};
29
30
+unsigned int calc_num_ifaces(struct iface *root) {
31
+ unsigned int num = 0;
32
+ for (struct iface *h = root; h; h = h->next) {
33
+ num++;
34
+ }
35
+ return num;
36
+}
37
+
38
unsigned int read_iface_iflink(const char *prefix, const char *iface) {
39
if(!prefix) prefix = "";
40
@@ -447,6 +455,25 @@ void detect_veth_interfaces(pid_t pid) {
455
goto cleanup;
456
}
457
458
+ unsigned int host_dev_num = calc_num_ifaces(host);
459
+ unsigned int cgroup_dev_num = calc_num_ifaces(cgroup);
460
+ // host ifaces == guest ifaces => we are still in the host namespace
461
+ // and we can't really identify which ifaces belong to the cgroup (e.g. Proxmox VM).
462
+ if (host_dev_num == cgroup_dev_num) {
463
+ unsigned int m = 0;
464
+ for (h = host; h; h = h->next) {
465
+ for (c = cgroup; c; c = c->next) {
466
+ if (h->ifindex == c->ifindex && h->iflink == c->iflink) {
467
+ m++;
468
+ break;
469
+ }
470
+ }
471
+ }
472
+ if (host_dev_num == m) {
473
+ goto cleanup;
474
+ }
475
+ }
476
+
477
for(h = host; h ; h = h->next) {
478
if(iface_is_eligible(h)) {
479
for (c = cgroup; c; c = c->next) {