X-Git-Url: http://git.harvie.cz/?a=blobdiff_plain;f=parseiptables.c;h=cfd1add8018f5c711974c435df0b078e45bb11a0;hb=7d05bfc0742ea64ad5b1b5511a0c89a8da0badcc;hp=e73632497340e0c5566d888f8f9ed8e3312f5ca1;hpb=f19d3cd0bca8ef24e8c78fb6ae24346dc3b7db36;p=svn%2FPrometheus-QoS%2F.git diff --git a/parseiptables.c b/parseiptables.c index e736324..cfd1add 100644 --- a/parseiptables.c +++ b/parseiptables.c @@ -1,4 +1,4 @@ -/* Modified by: xChaos, 20130115 */ +/* Modified by: xChaos, 20131029 */ #include "cll1-0.6.2.h" #include "ipstruct.h" @@ -15,7 +15,7 @@ extern int include_upload; /* ===================== traffic analyser - uses iptables ================ */ -void get_traffic_statistics(const char *whichiptables) +void get_traffic_statistics(const char *whichiptables, int ipv6) { char *str,*cmd; int downloadflag=0; @@ -41,7 +41,7 @@ void get_traffic_statistics(const char *whichiptables) unsigned long pkts = 0; char *ipaddr = NULL,*ptr; - valid_columns(ptr, line->str, ' ', col) + valid_columns(ptr, line->str, ' ', col) if(valid) switch(col) { case 1: if(eq(ptr,"Chain")) @@ -86,39 +86,71 @@ void get_traffic_statistics(const char *whichiptables) { accept = eq(ptr,mark); } - /*if(filter_type==1) accept=eq(ptr,"MARK"); else accept=eq(ptr,"CLASSIFY");*/ break; - case 8: if(downloadflag) - { - if(strstr(proxy_ip,ptr)) + case 7: if(ipv6 && !downloadflag) + { + ipaddr = ptr; + } + break; + case 8: if(ipv6 && downloadflag) + { + ipaddr = ptr; + } + else if(!ipv6) + { + if(downloadflag) + { + if(strstr(proxy_ip,ptr)) + { + proxyflag = 1; + } + } + else { - proxyflag = 1; + ipaddr = ptr; } } - else + break; + case 9: if(!ipv6 && downloadflag) { ipaddr = ptr; } break; - case 9: if(downloadflag)ipaddr = ptr;break; } if(accept && traffic>0 && ipaddr) { + /* IPv6 subnet - /64 */ + char *isipv6 = strstr(ipaddr,"/64"); + if(ipv6 && isipv6) + { + *isipv6=0; + printf("(IPv6) "); + } + else + { + printf("(IPv4) "); + } + if(proxyflag) { printf("(proxy) "); } else if(!downloadflag) { - printf("(upload) "); + printf("(up) "); } - printf("IP %s: %Lu MB (%ld pkts)\n", ipaddr, traffic, pkts); + else + { + printf("(down) "); + } + + printf("%s %Lu MB (%ld pkts)\n", ipaddr, traffic, pkts); - if_exists(ip,ips,eq(ip->addr,ipaddr)); + if_exists(ip, ips, eqi(ip->addr,ipaddr)); else { - TheIP(ipaddr); + TheIP(ipaddr, FALSE); if(eq(ip->addr,"0.0.0.0/0")) { ip->name = "(unregistered)"; @@ -141,22 +173,22 @@ void get_traffic_statistics(const char *whichiptables) { ip->traffic += traffic; } - ip->direct = ip->traffic-ip->upload-ip->proxy; - ip->pktsdown = pkts; + ip->direct += ip->traffic-ip->upload-ip->proxy; + ip->pktsdown += pkts; } else { - ip->upload = traffic; - ip->pktsup = pkts; + ip->upload += traffic; + ip->pktsup += pkts; if(include_upload) { ip->traffic += traffic; } else { - if(traffic > ip->traffic) + if(ip->upload > ip->traffic) { - ip->traffic = traffic; + ip->traffic = ip->upload; } } }