1 /* Modified by: xChaos, 20130115 */
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 /* ===================== traffic analyser - uses iptables ================ */
18 void get_traffic_statistics(const char *whichiptables
, int ipv6
)
23 textfile(Pipe
,str
) *line
,*lines
=NULL
;
27 sprintf(cmd
,"%s -L -v -x -n -t mangle", whichiptables
);
39 int col
, accept
= 0, proxyflag
= 0, valid
= 1, setchainname
= 0, commonflag
= 0;
40 unsigned long long traffic
= 0;
41 unsigned long pkts
= 0;
42 char *ipaddr
= NULL
,*ptr
;
44 valid_columns(ptr
, line
->str
, ' ', col
)
47 case 1: if(eq(ptr
,"Chain"))
51 else if(eq(ptr
,"pkts"))
57 sscanf(ptr
,"%lu",&pkts
);
60 case 2: if(setchainname
)
62 if(!strncmp(ptr
,"post_",5) || eq(ptr
,"POSTROUTING"))
68 if(!strncmp(ptr
,"forw_",5) || eq(ptr
,"FORWARD"))
73 if(eq(ptr
,"post_common") || eq(ptr
,"forw_common"))
80 sscanf(ptr
,"%Lu",&traffic
);
85 case 3: if((strncmp(ptr
,"post_",5) && strncmp(ptr
,"forw_",5)) || commonflag
)
87 accept
= eq(ptr
,mark
);
90 case 7: if(ipv6
&& !downloadflag
)
95 case 8: if(ipv6
&& downloadflag
)
103 if(strstr(proxy_ip
,ptr
))
114 case 9: if(!ipv6
&& downloadflag
)
121 if(accept
&& traffic
>0 && ipaddr
)
123 /* IPv6 subnet - /64 */
124 char *isipv6
= strstr(ipaddr
,"/64");
139 else if(!downloadflag
)
148 printf("%s %Lu MB (%ld pkts)\n", ipaddr
, traffic
, pkts
);
150 if_exists(ip
, ips
, eqi(ip
->addr
,ipaddr
));
154 if(eq(ip
->addr
,"0.0.0.0/0"))
156 ip
->name
= "(unregistered)";
158 ip
->max
= ip
->desired
=free_max
;
174 ip
->traffic
+= traffic
;
176 ip
->direct
= ip
->traffic
-ip
->upload
-ip
->proxy
;
181 ip
->upload
= traffic
;
185 ip
->traffic
+= traffic
;
189 if(traffic
> ip
->traffic
)
191 ip
->traffic
= traffic
;
This page took 0.57806 seconds and 4 git commands to generate.