@cryptotaxi247 / netdata-1 / commits / b710d4f88

prevent adding unused interfaces and IFB devices - they can still be enabled via config

Costa Tsaousis (ktsaou) committed Dec 20, 2015 at 05:48 UTC b710d4f881cf1f2e4eb95a7837eaf0d9054060b6
1 file changed +18 -4
src/proc_net_dev.c
+18 -4
@@ -3,6 +3,7 @@
3 #endif
4 #include <stdio.h>
5 #include <stdlib.h>
6 +#include <string.h>
7
8 #include "common.h"
9 #include "appconfig.h"
@@ -12,7 +13,7 @@
13
14 int do_proc_net_dev(int update_every, unsigned long long dt) {
15 static procfile *ff = NULL;
15 - static int enable_new_interfaces = -1;
16 + static int enable_new_interfaces = -1, enable_ifb_interfaces = -1;
17 static int do_bandwidth = -1, do_packets = -1, do_errors = -1, do_drops = -1, do_fifo = -1, do_compressed = -1, do_events = -1;
18
19 if(dt) {};
@@ -28,6 +29,7 @@ int do_proc_net_dev(int update_every, unsigned long long dt) {
29 if(!ff) return 0; // we return 0, so that we will retry to open it next time
30
31 if(enable_new_interfaces == -1) enable_new_interfaces = config_get_boolean("plugin:proc:/proc/net/dev", "enable new interfaces detected at runtime", 1);
32 + if(enable_ifb_interfaces == -1) enable_ifb_interfaces = config_get_boolean("plugin:proc:/proc/net/dev", "enable ifb interfaces", 0);
33
34 if(do_bandwidth == -1) do_bandwidth = config_get_boolean("plugin:proc:/proc/net/dev", "bandwidth for all interfaces", 1);
35 if(do_packets == -1) do_packets = config_get_boolean("plugin:proc:/proc/net/dev", "packets for all interfaces", 1);
@@ -68,10 +70,22 @@ int do_proc_net_dev(int update_every, unsigned long long dt) {
70 tcarrier = strtoull(procfile_lineword(ff, l, 15), NULL, 10);
71 tcompressed = strtoull(procfile_lineword(ff, l, 16), NULL, 10);
72
73 + int default_enable = enable_new_interfaces;
74 +
75 + // prevent unused interfaces from creating charts
76 + if(!rbytes && !tbytes)
77 + default_enable = 0;
78 + else {
79 + int len = strlen(iface);
80 + if(len >= 4 && strcmp(&iface[len-4], "-ifb") == 0)
81 + default_enable = enable_ifb_interfaces;
82 + }
83 +
84 + // check if the user wants it
85 {
72 - char var_name[4096 + 1];
73 - snprintf(var_name, 4096, "interface %s", iface);
74 - if(!config_get_boolean("plugin:proc:/proc/net/dev", var_name, enable_new_interfaces)) continue;
86 + char var_name[512 + 1];
87 + snprintf(var_name, 512, "interface %s", iface);
88 + if(!config_get_boolean("plugin:proc:/proc/net/dev", var_name, default_enable)) continue;
89 }
90
91 RRDSET *st;