1 /* Modified by: xChaos, 20131208 */
3 #include "cll1-0.6.2.h"
8 /* globals declared in prometheus.c */
9 extern struct IP
*ips
, *ip
, *sharedip
;
11 /* extern char *proxy_ip; */
14 extern int include_upload
;
16 int traffic_detected
= 0;
17 extern char *iptablesdump
;
19 /* ===================== traffic analyser - uses iptables ================ */
21 void get_traffic_statistics(const char *whichiptables
, int ipv6
)
28 sprintf(cmd
, "%s -L -v -x -n -t mangle>%s", whichiptables
, iptablesdump
);
29 /*-----------------------------------------------------------------*/
30 printf("Running %s ...\n", cmd
);
31 /*-----------------------------------------------------------------*/
33 /*-----------------------------------------------------------------*/
34 printf("Processing %s ...\n", iptablesdump
);
35 /*-----------------------------------------------------------------*/
36 f
= fopen(iptablesdump
,"r");
42 int col
, accept
= 0, /*proxyflag = 0, */valid
= 1, setchainname
= 0, commonflag
= 0;
43 unsigned long long traffic
= 0;
44 unsigned long pkts
= 0;
45 char *ipaddr
= NULL
,*ptr
;
48 fgets(str
, STRLEN
, f
);
49 valid_columns(ptr
, str
, ' ', col
)
52 case 1: if(eq(ptr
,"Chain"))
56 else if(eq(ptr
,"pkts"))
62 sscanf(ptr
,"%lu",&pkts
);
65 case 2: if(setchainname
)
67 if(!strncmp(ptr
,"post_",5) || eq(ptr
,"POSTROUTING"))
73 if(!strncmp(ptr
,"forw_",5) || eq(ptr
,"FORWARD"))
78 if(eq(ptr
,"post_common") || eq(ptr
,"forw_common"))
85 sscanf(ptr
,"%Lu",&traffic
);
90 case 3: if((strncmp(ptr
,"post_",5) && strncmp(ptr
,"forw_",5)) || commonflag
)
92 accept
= eq(ptr
,mark
);
95 case 7: if(ipv6
&& !downloadflag
)
100 case 8: if(ipv6
&& downloadflag
)
108 if(strstr(proxy_ip,ptr))
122 case 9: if(!ipv6
&& downloadflag
)
129 if(accept
&& traffic
>0 && ipaddr
)
131 /* IPv6 subnet - /64 */
132 char *isipv6
= strstr(ipaddr
,"/64");
158 traffic_detected
= 1;
159 printf("%s %Lu MB (%ld pkts)\n", ipaddr
, traffic
, pkts
);
161 if_exists(ip
, ips
, eqi(ip
->addr
,ipaddr
));
164 TheIP(ipaddr
, FALSE
);
165 if(eq(ip
->addr
,"0.0.0.0/0"))
167 ip
->name
= "(unregistered)";
169 ip
->max
= ip
->desired
=free_max
;
186 ip
->traffic
+= traffic
;
187 ip
->traffic_down
+= traffic
;
189 ip
->direct
+= traffic
; /*-ip->proxy;*/
190 ip
->pktsdown
+= pkts
;
194 ip
->upload
+= traffic
;
195 ip
->traffic_up
+= traffic
;
199 ip
->traffic
+= traffic
;
203 if(ip
->upload
> ip
->traffic
)
205 ip
->traffic
= ip
->upload
;
This page took 0.396753 seconds and 4 git commands to generate.