X-Git-Url: https://git.harvie.cz/?p=svn%2FPrometheus-QoS%2F.git;a=blobdiff_plain;f=prometheus.c;h=8a567a173671e6be1758b5f88d11a43facf48b52;hp=4461346cd47e73e0c60f3669091d1ab3f3e8964a;hb=5a8f2e77c57c7c7f2fcf1ef5933a0a771dd57777;hpb=5b902402b7b440ed3c1c93ed7f8eb8cf2c9fe31e diff --git a/prometheus.c b/prometheus.c index 4461346..8a567a1 100644 --- a/prometheus.c +++ b/prometheus.c @@ -1,14 +1,14 @@ -/* =============================================================== */ -/* == Prometheus QoS - you can "steal fire" from your ISP == */ -/* == "fair-per-IP" quality of service (QoS) utility == */ -/* == requires Linux 2.4.x or 2.6.x with HTB support == */ -/* == Copyright(C) 2005-2008 Michael Polak (xChaos) == */ -/* == iptables-restore support Copyright(C) 2007-2008 ludva == */ -/* == Credit: CZFree.Net,Martin Devera,Netdave,Aquarius,Gandalf == */ -/* =============================================================== */ - -/* Modified: xChaos, 20080205 - ludva, 20071227 + /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ + /* Prometheus QoS - you can "steal fire" from your ISP */ +/* "fair-per-IP" quality of service (QoS) utility */ +/* requires Linux 2.4.x or 2.6.x with HTB support */ +/* Copyright(C) 2005-2008 Michael Polak (xChaos) */ +/* iptables-restore support Copyright(C) 2007-2008 ludva */ +/* Credit: CZFree.Net,Martin Devera,Netdave,Aquarius,Gandalf */ +/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ + +/* Modified: xChaos, 20080422 + ludva, 20080415 Prometheus QoS is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as @@ -20,11 +20,11 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - You should have received a copy of the GNU General Public License - along with Prometheus Qos; if not, write to the Free Software + You should have received a copy of the GNU General Public License + along with Prometheus Qos; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - GNU General Public License is located in file COPYING */ + GNU General Public License is located in file COPYING */ #define STRLEN 256 #define FIRSTGROUPID 1024 @@ -33,9 +33,14 @@ #include "cll1-0.6.h" -const char *version="0.7.8.1"; /*0.7.9 will be last development, 0.8.0 first stable */ +const char *version="0.7.9-c"; -/* ======= All path names are defined hear (for RPM patch) ======= */ +/* Version numbers: 0.7.9 will be last development ("beta"), 0.8.0 first stable */ +/* Debian(RPM) package versions/patchlevels: 0.7.9-2, 0.8.0-1, 0.8.0-2, etc. */ +/* C source code development versions ("beta"): 0.7.9-a, 0.8.1-b, etc. */ +/* C source code release versions: 0.8.0, 0.8.2, 0.8.4, etc. */ + +/* ======= All path names are defined here (for RPM patch) ======= */ char *tc = "/sbin/tc"; /* requires tc with HTB support */ char *iptables = "/sbin/iptables"; /* requires iptables utility */ @@ -435,7 +440,7 @@ void get_config(char *config_filename) /* are supplied values meaningful ?*/ if(line<=0 || up<=0) { - puts("Illegal value of wan bandwidth: 0 kbps."); + puts("Illegal value of LAN or WAN bandwidth: 0 kbps."); reject_config_and_exit(config_filename); } } @@ -547,7 +552,6 @@ void get_traffic_statistics(void) } } - free(cmd); } @@ -628,35 +632,35 @@ char *parse_datafile_line(char *str) return NULL; } -struct IpLog -{ - char *name; - long traffic; - list(IpLog); -} *iplog,*iplogs; - -void parse_ip_log(int argc, char **argv) -{ - char *month,*year,*str,*name,*ptr,*ptr2; - long traffic,traffic_month,total=0; - int col,col2,y_ok,m_ok,accept_month,i=1,any_month=0; - char mstr[4],ystr[5]; - FILE *f; - - string(str,STRLEN); - +struct IpLog +{ + char *name; + long traffic; + long guaranted; + list(IpLog); +} *iplog,*iplogs; + +void parse_ip_log(int argc, char **argv) +{ + char *month, *year, *str, *name, *ptr, *ptr2; + long traffic, traffic_month, total=0, guaranted; + int col, col2, y_ok, m_ok, accept_month, i=1, any_month=0; + char mstr[4], ystr[5]; + FILE *f; + string(str,STRLEN); + if(argv[1][1]=='l') /* -l */ { - if(argc<4) - { - puts("Missing parameter(s)!\nUsage: prometheus -l Mmm YYYY (Mmm=Jan-Dec or Year, YYYY=year)"); - exit(-1); - } - else - { - month=argv[2]; - if(eq(month,"Year")) any_month=1; - year=argv[3]; + if(argc<4) + { + puts("Missing parameter(s)!\nUsage: prometheus -l Mmm YYYY (Mmm=Jan-Dec or Year, YYYY=year)"); + exit(-1); + } + else + { + month=argv[2]; + if(eq(month,"Year")) any_month=1; + year=argv[3]; } } else @@ -680,65 +684,82 @@ void parse_ip_log(int argc, char **argv) } } printf("Analysing traffic for %s %s ...\n",month,year); - - sprintf(str,"%s %s/*.log",ls,log_dir); - shell(str); - input(str,STRLEN) - { - ptr=strrchr(str,'\n'); - if(ptr) *ptr='\0'; - printf("Parsing %s ...",str); - accept_month=0; - traffic_month=0; - parse(str) - { - y_ok=m_ok=0; - valid_columns(ptr,_,'\t',col) switch(col) - { - case 2: name=ptr;break; - case 3: traffic=atol(ptr);break; - case 7: valid_columns(ptr2,ptr,' ',col2) switch(col2) - { - case 2: if(any_month || eq(ptr2,month)) m_ok=1; break; - case 5: if(eq(ptr2,year)) y_ok=1; break; - } - } - if(y_ok && m_ok) - { - traffic_month+=traffic; - accept_month=1; - } - } - done; - if(accept_month) - { - create(iplog,IpLog); - iplog->name=name; - iplog->traffic=traffic_month; - insert(iplog,iplogs,desc_order_by,traffic); - printf(" %ld MB\n",iplog->traffic); - } - else - puts(" no records."); - } - sprintf(str,"%s/%s-%s.html",html_log_dir,year,month); - printf("Writing %s ...",str); - f=fopen(str,"w"); - if(f) - { - fprintf(f,"\n ",month,year); - every(iplog,iplogs) - if(iplog->traffic) - { - fprintf(f,"\n",i++,iplog->name,iplog->traffic,iplog->traffic>>10); - total+=iplog->traffic>>10; - } - fprintf(f,"\n",total); - fputs("
Data transfers - %s %s
%d%s%ld MB%ld GB
Total:%ld GB
\n",f); - fclose(f); - puts(" done."); - } -} + + sprintf(str,"%s %s/*.log",ls,log_dir); + shell(str); + + input(str,STRLEN) + { + ptr=strrchr(str,'\n'); + if(ptr) *ptr='\0'; + printf("Parsing %s ...",str); + accept_month=0; + traffic_month=0; + guaranted = 0; + parse(str) + { + y_ok=m_ok=0; + valid_columns(ptr,_,'\t',col) switch(col) + { + case 2: name = ptr;break; + case 3: traffic = atol(ptr);break; + /* column number - was 7, now 10...*/ + case 7: + case 8: + case 9: + case 10: if (isalnum(*ptr)) /* alphanumeric string = date, just one*/ + { + valid_columns(ptr2,ptr,' ',col2) switch(col2) + { + case 2: if(any_month || eq(ptr2,month)) m_ok = 1; break; + case 5: if(eq(ptr2,year)) y_ok = 1; break; + } + } + else + { + if(col == 7) guaranted = atol(ptr); + } + } + + if(y_ok && m_ok) + { + traffic_month += traffic; + accept_month = 1; + } + } + done; + + if(accept_month) + { + create(iplog,IpLog); + iplog->name = name; + iplog->guaranted = guaranted; + iplog->traffic = traffic_month; + insert(iplog,iplogs,desc_order_by,traffic); + printf(" %ld MB\n",iplog->traffic); + } + else + puts(" no records."); + } + sprintf(str,"%s/%s-%s.html",html_log_dir,year,month); + printf("Writing %s ...",str); + f=fopen(str,"w"); + if(f) + { + fprintf(f,"\n ",month,year); + every(iplog,iplogs) + if(iplog->traffic) + { + fprintf(f,"\n", + i++, iplog->name, iplog->traffic, iplog->traffic>>10, iplog->guaranted); + total+=iplog->traffic>>10; + } + fprintf(f,"\n", total, line); + fputs("
Data transfers - %s %sMin.speed
%d%s%ld MB%ld GB%ld kbps
Total:%ld GB%Ld kbps
\n",f); + fclose(f); + puts(" done."); + } +} /*-----------------------------------------------------------------*/ @@ -755,7 +776,9 @@ program int parent=1; int just_flush=0; int nodelay=0; - int just_preview=0; /* preview - generate just stats */ + int just_preview=0; /* preview - generate just stats */ + int just_logs=0; /* just parse logs */ + char *chain_forward, *chain_postrouting; char *althosts=NULL; @@ -776,9 +799,9 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version); argument("-9") { just_flush=9; } argument("-p") { just_preview=1; } argument("-n") { nodelay=1; } - argument("-l") { parse_ip_log(argc,argv); exit(0); } - argument("-m") { parse_ip_log(argc,argv); exit(0); } - argument("-y") { parse_ip_log(argc,argv); exit(0); } + argument("-l") { just_logs=1; } + argument("-m") { just_logs=1; } + argument("-y") { just_logs=1; } argument("-?") { help(); exit(0); } argument("--help") { help(); exit(0); } argument("-v") { exit(0); } @@ -794,6 +817,12 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version); printf("Parsing configuration file %s ...\n", config); /*-----------------------------------------------------------------*/ get_config(config); + + if(just_logs) + { + parse_ip_log(argc,argv); + exit(0); + } if(althosts) hosts=althosts; @@ -852,8 +881,8 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version); ip->min=atoi(substring); if(ip->min<=0) { - puts("Illegal value of minimum bandwidth: 0 kbps."); - reject_config_and_exit(hosts); + printf(" %s: Illegal value of minimum bandwidth 0 kbps, using %d kbps\n",str,free_min); + ip->min=free_min; } if(ip->max<=ip->min) { @@ -1367,7 +1396,8 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version); iplog=fopen(str,"a"); if(iplog) { - fprintf(iplog,"%ld\t%s\t%Lu\t%Lu\t%Lu\t%Lu\t%s",time(NULL),ip->name,ip->traffic, ip->direct, ip->proxy, ip->upload,d); + fprintf(iplog,"%ld\t%s\t%Lu\t%Lu\t%Lu\t%Lu\t%d\t%d\t%d\t%s", + time(NULL),ip->name,ip->traffic,ip->direct,ip->proxy,ip->upload,ip->min,ip->max,ip->desired,d); /* d = date*/ fclose(iplog); } } @@ -1382,63 +1412,63 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version); fputs("\n\n",f); if(active_classes>10) - { - fputs("

\n",f); - fputs("\n",f); - fputs("\n",f); - - find(sum,sums,sum->l>=total/4) - { - fprintf(f,"\n"); - fprintf(f,"\n",sum->i,(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total); - } - - find(sum,sums,sum->i==10) - { - fprintf(f,"\n"); - fprintf(f,"\n",(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total); - } - - find(sum,sums,sum->l>=total/2) - { - fprintf(f,"\n"); - fprintf(f,"\n",sum->i,(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total); - } - - find(sum,sums,sum->l>=4*total/5) - { - fprintf(f,"\n"); - fprintf(f,"\n",sum->i,(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total); - } - - find (sum,sums,sum->i>=(active_classes+1)/5) - { - fprintf(f,"\n"); - fprintf(f,"\n",sum->i,(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total); - } - - find(sum,sums,sum->i>=(active_classes+1)/4) - { - fprintf(f,"\n"); - fprintf(f,"\n",sum->i,(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total); - } - - find(sum,sums,sum->i>=(active_classes+1)/2) - { - fprintf(f,"\n"); - fprintf(f,"\n",sum->i,(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total); - } - - find(sum,sums,sum->i>=4*(active_classes+1)/5) - { - fprintf(f,"\n"); - fprintf(f,"\n",sum->i,(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total); - } - - fprintf(f,"\n"); - fprintf(f,"\n",active_classes,total); - fputs("
Enterprise Research and Planning (ERP)
Analytic categoryActive ClassesData transfers
Top 25%% of traffic%d%d %%%Lu M%Ld %%
Top 10 downloaders10%d %%%Lu M%Ld %%
Top 50%% of traffic%d%d %%%Lu M%Ld %%
Top 80%% of traffic%d%d %%%Lu M%Ld %%
Top 20%% downloaders%d%d %%%Lu M%Ld %%
Top 25%% downloaders%d%d %%%Lu M%Ld %%
Top 50%% downloaders%d%d %%%Lu M%Ld %%
Top 80%% downloaders%d%d %%%Lu M%Ld %%
All users, all traffic%d100 %%%Lu M100 %%
\n",f); - } + { + fputs("

\n",f); + fputs("\n",f); + fputs("\n",f); + + find(sum,sums,sum->l>=total/4) + { + fprintf(f,"\n"); + fprintf(f,"\n",sum->i,(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total); + } + + find(sum,sums,sum->i==10) + { + fprintf(f,"\n"); + fprintf(f,"\n",(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total); + } + + find(sum,sums,sum->l>=total/2) + { + fprintf(f,"\n"); + fprintf(f,"\n",sum->i,(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total); + } + + find(sum,sums,sum->l>=4*total/5) + { + fprintf(f,"\n"); + fprintf(f,"\n",sum->i,(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total); + } + + find (sum,sums,sum->i>=(active_classes+1)/5) + { + fprintf(f,"\n"); + fprintf(f,"\n",sum->i,(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total); + } + + find(sum,sums,sum->i>=(active_classes+1)/4) + { + fprintf(f,"\n"); + fprintf(f,"\n",sum->i,(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total); + } + + find(sum,sums,sum->i>=(active_classes+1)/2) + { + fprintf(f,"\n"); + fprintf(f,"\n",sum->i,(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total); + } + + find(sum,sums,sum->i>=4*(active_classes+1)/5) + { + fprintf(f,"\n"); + fprintf(f,"\n",sum->i,(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total); + } + + fprintf(f,"\n"); + fprintf(f,"\n",active_classes,total); + fputs("
Enterprise Research and Planning (ERP)
Analytic categoryActive ClassesData transfers
Top 25%% of traffic%d%d %%%Lu M%Ld %%
Top 10 downloaders10%d %%%Lu M%Ld %%
Top 50%% of traffic%d%d %%%Lu M%Ld %%
Top 80%% of traffic%d%d %%%Lu M%Ld %%
Top 20%% downloaders%d%d %%%Lu M%Ld %%
Top 25%% downloaders%d%d %%%Lu M%Ld %%
Top 50%% downloaders%d%d %%%Lu M%Ld %%
Top 80%% downloaders%d%d %%%Lu M%Ld %%
All users, all traffic%d100 %%%Lu M100 %%
\n",f); + } fprintf(f,"Statistics generated by Prometheus QoS version %s
GPL+Copyright(C)2005-2008 Michael Polak, Arachne Labs
\n",version); fclose(f); } @@ -1566,18 +1596,18 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version); if(qos_proxy) { - sprintf(str,"-A %s -s %s -p tcp --sport %d -o %s -j MARK --set-mark 3",chain_postrouting,proxy_ip,proxy_port,lan); + sprintf(str,"-A %s -s %s -p tcp --sport %d -o %s -j %s%d",chain_postrouting,proxy_ip,proxy_port,lan,mark_iptables,3); save_line(str); sprintf(str,"-A %s -s %s -p tcp --sport %d -o %s -j ACCEPT",chain_postrouting,proxy_ip,proxy_port,lan); save_line(str); } - sprintf(str,"-A %s -o %s -j MARK --set-mark 3",chain_postrouting,lan); + sprintf(str,"-A %s -o %s -j %s%d",chain_postrouting,lan,mark_iptables,3); save_line(str); sprintf(str,"-A %s -o %s -j ACCEPT",chain_postrouting,lan); save_line(str); /* -------------------------------------------------------- mark upload */ - sprintf(str,"-A %s -o %s -j MARK --set-mark 3",chain_forward,wan); + sprintf(str,"-A %s -o %s -j %s%d",chain_forward,wan,mark_iptables,3); save_line(str); sprintf(str,"-A %s -o %s -j ACCEPT",chain_forward,wan); save_line(str);