X-Git-Url: http://git.harvie.cz/?p=svn%2FPrometheus-QoS%2F.git;a=blobdiff_plain;f=prometheus.c;h=3793a2ae79bb9240109d3a41d5c708ab5dbc622c;hp=cd7dc2cca1951c7aa47bf2b78df08057eee8e704;hb=493e1ccd36ad4f318fd9abb6bad398f7e055a4b8;hpb=312ac2c13172fb101cb0d9b6bc3052a14352287c diff --git a/prometheus.c b/prometheus.c index cd7dc2c..3793a2a 100644 --- a/prometheus.c +++ b/prometheus.c @@ -7,8 +7,8 @@ /* Credit: CZFree.Net,Martin Devera,Netdave,Aquarius,Gandalf */ /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ -/* Modified: xChaos, 20080407 - ludva, 20071227 +/* Modified by: xChaos, 20080728 + 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,27 +33,34 @@ #include "cll1-0.6.h" -const char *version="0.7.9.1"; /*0.7.9 will be last development, 0.8.0 first stable */ +const char *version = "0.8.1-a"; -/* ======= All path names are defined hear (for RPM patch) ======= */ +/* Version numbers: 0.7.9 is development releases ("beta"), 0.8.0 will be "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. */ -char *tc = "/sbin/tc"; /* requires tc with HTB support */ -char *iptables = "/sbin/iptables"; /* requires iptables utility */ -char *iptablessave = "/sbin/iptables-save"; /* not yet required */ +const char *stats_html_signature = "Statistics generated by Prometheus QoS version %s
GPL+Copyright(C)2005-2008 Michael Polak, Arachne Labs
\n"; + +/* ======= 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 */ +char *iptablessave = "/sbin/iptables-save"; /* not yet required */ char *iptablesrestore = "/sbin/iptables-restore"; /* requires iptables-restore */ -char *ls = "/bin/ls"; /* this is not user configurable :-) */ +char *ls = "/bin/ls"; /* this is not user configurable :-) */ -char *config = "/etc/prometheus/prometheus.conf"; /* main configuration file */ -char *hosts = "/etc/prometheus/hosts"; /* per-IP bandwidth definition file */ +char *config = "/etc/prometheus/prometheus.conf"; /* main configuration file */ +char *hosts = "/etc/prometheus/hosts"; /* per-IP bandwidth definition file */ -char *iptablesfile = "/var/spool/prometheus.iptables"; /* temporary file for iptables-restore*/ -char *credit = "/var/lib/misc/prometheus.credit"; /* credit log file */ -char *html = "/var/www/traffic.html"; /* hall of fame filename */ -char *preview = "/var/www/preview.html"; /* hall of fame preview */ -char *cmdlog = "/var/log/prometheuslog"; /* command log filename */ -char *log_dir = "/var/www/logs/"; /* log directory pathname, ended with slash */ -char *log_url = "logs/"; /* log directory relative URI prefix (partial URL) */ -char *html_log_dir = "/var/www/logs/html/"; +char *iptablesfile = "/var/spool/prometheus.iptables"; /* temporary file for iptables-restore*/ +char *credit = "/var/lib/misc/prometheus.credit"; /* credit log file */ +char *html = "/var/www/traffic.html"; /* hall of fame filename */ +char *preview = "/var/www/preview.html"; /* hall of fame preview */ +char *cmdlog = "/var/log/prometheuslog"; /* command log filename */ +char *log_dir = "/var/www/logs/"; /* log directory pathname, ended with slash */ +char *log_url = "logs/"; /* log directory relative URI prefix (partial URL) */ +char *html_log_dir = "/var/www/logs/html/"; /* ======= Help screen is hopefuly self-documenting part of code :-) ======= */ @@ -78,51 +85,48 @@ void help(void) -r just reload configuration (...and keep data transfer statistics)\n\ */ } - /* === Configuraration file values defaults - stored in global variables ==== */ -int filter_type=1; /*1 mark, 2 classify*/ -char *mark="MARK"; -char *mark_iptables="MARK --set-mark "; -int dry_run=0; /* preview - use puts() instead of system() */ -char *iptablespreamble="*mangle\n:PREROUTING ACCEPT [0:0]\n:POSTROUTING ACCEPT [0:0]\n:INPUT ACCEPT [0:0]\n:OUTPUT ACCEPT [0:0]\n:FORWARD ACCEPT [0:0]"; -FILE *iptables_file=NULL; -int enable_credit=1; /* enable credit file */ -int use_credit=0; /* use credit file (if enabled)*/ -char *title="Hall of Fame - Greatest Suckers"; /* hall of fame title */ -int hall_of_fame=1; /* enable hall of fame */ -char *lan="eth0"; /* LAN interface */ -char *lan_medium="100Mbit"; /* 10Mbit/100Mbit ethernet */ -char *wan="eth1"; /* WAN/ISP interface */ -char *wan_medium="100Mbit"; /* 10Mbit/100Mbit ethernet */ -char *qos_leaf="sfq perturb 5"; /* leaf discipline */ -char *qos_free_zone=NULL; /* QoS free zone */ -int qos_proxy=1; /* include proxy port to QoS */ -int include_upload=1; /* upload+download=total traffic */ -char *proxy_ip="192.168.1.1/32"; /* our IP with proxy port */ -int proxy_port=3128; /* proxy port number */ -long long int line=1024; /* WAN/ISP download in kbps */ -long long int up=1024; /* WAN/ISP upload in kbps */ -int free_min=32; /* minimum guaranted bandwidth for all undefined hosts */ -int free_max=64; /* maximum allowed bandwidth for all undefined hosts */ -int qos_free_delay=0; /* seconds to sleep before applying new QoS rules */ -int digital_divide=2; /* controls digital divide weirdness ratio, 1...3 */ -int max_nesting=3; /* maximum nesting of HTB clases, built-in maximum seems to be 4 */ -int htb_r2q=1; -int burst=8; /* HTB burst (in kbits) */ -int burst_main=64; -int burst_group=32; -int magic_priorities=8; /* number of priority levels (soft shaping) */ -int magic_treshold=8; /* reduce ceil by X*magic_treshhold kbps (hard shaping) */ -int keywordcount=0; - +int filter_type = 1; /*1 mark, 2 classify*/ +char *mark = "MARK"; +char *mark_iptables = "MARK --set-mark "; +int dry_run = 0; /* preview - use puts() instead of system() */ +char *iptablespreamble = "*mangle\n:PREROUTING ACCEPT [0:0]\n:POSTROUTING ACCEPT [0:0]\n:INPUT ACCEPT [0:0]\n:OUTPUT ACCEPT [0:0]\n:FORWARD ACCEPT [0:0]"; +FILE *iptables_file = NULL; +int enable_credit = 1; /* enable credit file */ +int use_credit = 0; /* use credit file (if enabled)*/ +char *title = "Hall of Fame - Greatest Suckers"; /* hall of fame title */ +int hall_of_fame = 1; /* enable hall of fame */ +char *lan = "eth0"; /* LAN interface */ +char *lan_medium = "100Mbit"; /* 10Mbit/100Mbit ethernet */ +char *wan = "eth1"; /* WAN/ISP interface */ +char *wan_medium = "100Mbit"; /* 10Mbit/100Mbit ethernet */ +char *qos_leaf = "sfq perturb 5"; /* leaf discipline */ +char *qos_free_zone = NULL; /* QoS free zone */ +int qos_proxy = 1; /* include proxy port to QoS */ +int include_upload = 1; /* upload+download=total traffic */ +char *proxy_ip = "192.168.1.1/32"; /* our IP with proxy port */ +int proxy_port = 3128; /* proxy port number */ +long long int line = 1024; /* WAN/ISP download in kbps */ +long long int up = 1024; /* WAN/ISP upload in kbps */ +int free_min = 32; /* minimum guaranted bandwidth for all undefined hosts */ +int free_max = 64; /* maximum allowed bandwidth for all undefined hosts */ +int qos_free_delay = 0; /* seconds to sleep before applying new QoS rules */ +int digital_divide = 2; /* controls digital divide weirdness ratio, 1...3 */ +int max_nesting = 3; /* maximum nesting of HTB clases, built-in maximum seems to be 4 */ +int htb_r2q = 1; +int burst = 8; /* HTB burst (in kbits) */ +int burst_main = 64; +int burst_group = 32; +int magic_priorities = 8; /* number of priority levels (soft shaping) */ +int magic_treshold = 8; /* reduce ceil by X*magic_treshhold kbps (hard shaping) */ +int keywordcount = 0; /* not yet implemented: - int fixed_packets=0; maximum number of pps per IP address (not class!) - int packet_limit=5; maximum number of pps to htn CEIL, not rate !!! +int fixed_packets = 0; maximum number of pps per IP address (not class!) +int packet_limit = 5; maximum number of pps to htn CEIL, not rate !!! */ -FILE *log_file=NULL; - -char *kwd="via-prometheus"; /* /etc/hosts comment, eg. #qos-64-128 */ +FILE *log_file = NULL; +char *kwd = "via-prometheus"; /* /etc/hosts comment, eg. #qos-64-128 */ const int idxtable_treshold1=24; /* this is no longer configurable */ const int idxtable_treshold2=12; /* this is no longer configurable */ @@ -435,7 +439,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 +551,6 @@ void get_traffic_statistics(void) } } - free(cmd); } @@ -628,35 +631,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,69 +683,90 @@ 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."); - } -} + + /* sorry... next release of C<<1 header file will include for_path_files(name,path) { } macro */ + sprintf(str,"%s %s/",ls,log_dir); + shell(str); + input(str,STRLEN) + { + if(strstr(str,".log")) + { + 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 (isalpha(*ptr)) /* character, not numeric 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("
%s %sData transfersMin.speed
%d%s%ld MB%ld GB%ld kbps
Total:%ld GB%Ld kbps
\n", f); + fprintf(f, stats_html_signature, version); + fclose(f); + puts(" done."); + } +} /*-----------------------------------------------------------------*/ -/* Are you looking for int main (int argc, char **argv) ? :-)) */ +/* Are you looking for int main(int argc, char **argv) ? :-)) */ /*-----------------------------------------------------------------*/ program @@ -755,14 +779,16 @@ 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; printf("\n\ Prometheus QoS - \"fair-per-IP\" Quality of Service setup utility.\n\ Version %s - Copyright (C)2005-2008 Michael Polak (xChaos)\n\ -iptables-restore & burst tunning & classify modification 0.7d by Ludva\n\ +iptables-restore & burst tunning & classify modification by Ludva\n\ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version); /*----- Boring... we have to check command line options first: ----*/ @@ -776,9 +802,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 +820,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; @@ -1367,8 +1399,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%d\t%s", - time(NULL),ip->name,ip->traffic,ip->direct,ip->proxy,ip->upload,ip->min,d); /* d = date*/ + 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); } } @@ -1383,64 +1415,64 @@ 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); - } - fprintf(f,"Statistics generated by Prometheus QoS version %s
GPL+Copyright(C)2005-2008 Michael Polak, Arachne Labs
\n",version); + { + 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, stats_html_signature, version); fclose(f); } @@ -1516,14 +1548,15 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version); sprintf(str,"%s class add dev %s parent 1:%d classid 1:%d htb rate %dkbit ceil %dkbit burst %dk prio %d", tc, lan, ip->group, ip->mark,ip->min,ip->max, burst, ip->prio); safe_run(str); - if (strcmpi(ip->keyword->leaf_discipline, "none")){ - sprintf(str,"%s qdisc add dev %s parent 1:%d handle %d %s", tc, lan, ip->mark, ip->mark, ip->keyword->leaf_discipline); /*qos_leaf*/ - safe_run(str); - } - - if (filter_type == 1){ - sprintf(str,"%s filter add dev %s parent 1:0 protocol ip handle %d fw flowid 1:%d", tc, lan, ip->mark, ip->mark); - safe_run(str); + if (strcmpi(ip->keyword->leaf_discipline, "none")) + { + sprintf(str,"%s qdisc add dev %s parent 1:%d handle %d %s", tc, lan, ip->mark, ip->mark, ip->keyword->leaf_discipline); /*qos_leaf*/ + safe_run(str); + } + if (filter_type == 1) + { + sprintf(str,"%s filter add dev %s parent 1:0 protocol ip handle %d fw flowid 1:%d", tc, lan, ip->mark, ip->mark); + safe_run(str); } /* -------------------------------------------------------- upload class */ @@ -1536,14 +1569,15 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version); (int)((ip->max/ip->keyword->asymetry_ratio)-ip->keyword->asymetry_fixed), burst, ip->prio); safe_run(str); - if (strcmpi(ip->keyword->leaf_discipline, "none")){ - sprintf(str,"%s qdisc add dev %s parent 1:%d handle %d %s",tc, wan, ip->mark, ip->mark, ip->keyword->leaf_discipline); /*qos_leaf*/ - safe_run(str); - } - - if (filter_type == 1){ - sprintf(str,"%s filter add dev %s parent 1:0 protocol ip handle %d fw flowid 1:%d",tc, wan, ip->mark, ip->mark); - safe_run(str); + if (strcmpi(ip->keyword->leaf_discipline, "none")) + { + sprintf(str,"%s qdisc add dev %s parent 1:%d handle %d %s",tc, wan, ip->mark, ip->mark, ip->keyword->leaf_discipline); /*qos_leaf*/ + safe_run(str); + } + if (filter_type == 1) + { + sprintf(str,"%s filter add dev %s parent 1:0 protocol ip handle %d fw flowid 1:%d",tc, wan, ip->mark, ip->mark); + safe_run(str); } } else @@ -1551,72 +1585,76 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version); i++; } - if(idxs) { - chain_forward="forw_common"; - chain_postrouting="post_common"; + chain_forward = "forw_common"; + chain_postrouting = "post_common"; } else { - chain_forward="FORWARD"; - chain_postrouting="POSTROUTING"; + chain_forward = "FORWARD"; + chain_postrouting = "POSTROUTING"; } - - /* -------------------------------------------------------- mark download */ - - if(qos_proxy) + /* -------------------------------- classify or reject free download */ { - sprintf(str,"-A %s -s %s -p tcp --sport %d -o %s -j MARK --set-mark 3",chain_postrouting,proxy_ip,proxy_port,lan); - 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); + char *final_chain = "DROP"; /* REJECT would be better, but it is impossible in mangle */ + if(free_min) final_chain = "ACCEPT"; + if(qos_proxy) + { + if(free_min) + { + 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 %s",chain_postrouting,proxy_ip,proxy_port,lan,final_chain); + save_line(str); + } + if(free_min) + { + 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 %s",chain_postrouting,lan,final_chain); + save_line(str); + /* ------------------------------- classify or reject free upload */ + if(free_min) + { + 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 %s",chain_forward,wan,final_chain); + save_line(str); } - sprintf(str,"-A %s -o %s -j MARK --set-mark 3",chain_postrouting,lan); - 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); - save_line(str); - sprintf(str,"-A %s -o %s -j ACCEPT",chain_forward,wan); - save_line(str); - - printf("Total IP count: %d\n", i); - - /*-----------------------------------------------------------------*/ - puts("Generating free bandwith classes ..."); - /*-----------------------------------------------------------------*/ - /* ---------------------------------------- tc - free bandwith shared class */ - sprintf(str,"%s class add dev %s parent 1:%d classid 1:3 htb rate %dkbit ceil %dkbit burst %dk prio 2",tc,lan,parent,free_min,free_max,burst); - safe_run(str); - - sprintf(str,"%s class add dev %s parent 1:%d classid 1:3 htb rate %dkbit ceil %dkbit burst %dk prio 2",tc,wan,parent,free_min,free_max,burst); - safe_run(str); + if(free_min) /* allocate free bandwith if it is not zero... */ + { + /*-----------------------------------------------------------------*/ + puts("Generating free bandwith classes ..."); + /*-----------------------------------------------------------------*/ + sprintf(str,"%s class add dev %s parent 1:%d classid 1:3 htb rate %dkbit ceil %dkbit burst %dk prio 2",tc,lan,parent,free_min,free_max,burst); + safe_run(str); + sprintf(str,"%s class add dev %s parent 1:%d classid 1:3 htb rate %dkbit ceil %dkbit burst %dk prio 2",tc,wan,parent,free_min,free_max,burst); + safe_run(str); + /* tc SFQ */ + if (strcmpi(qos_leaf, "none")) + { + sprintf(str,"%s qdisc add dev %s parent 1:3 handle 3 %s",tc,lan,qos_leaf); + safe_run(str); + + sprintf(str,"%s qdisc add dev %s parent 1:3 handle 3 %s",tc,wan,qos_leaf); + safe_run(str); + } + /* tc handle 1 fw flowid */ + sprintf(str,"%s filter add dev %s parent 1:0 protocol ip handle 3 fw flowid 1:3",tc,lan); + safe_run(str); - /* tc SFQ */ - if (strcmpi(qos_leaf, "none")){ - sprintf(str,"%s qdisc add dev %s parent 1:3 handle 3 %s",tc,lan,qos_leaf); - safe_run(str); - - sprintf(str,"%s qdisc add dev %s parent 1:3 handle 3 %s",tc,wan,qos_leaf); - safe_run(str); + sprintf(str,"%s filter add dev %s parent 1:0 protocol ip handle 3 fw flowid 1:3",tc,wan); + safe_run(str); } - - /* tc handle 1 fw flowid */ - sprintf(str,"%s filter add dev %s parent 1:0 protocol ip handle 3 fw flowid 1:3",tc,lan); - safe_run(str); - - sprintf(str,"%s filter add dev %s parent 1:0 protocol ip handle 3 fw flowid 1:3",tc,wan); - safe_run(str); - - run_restore(); - + printf("Total IP count: %d\n", i); + run_restore(); if (log_file) fclose(log_file); return 0; - /* that's all folks, thank you for reading it all the way up to this point ;-) */ /* bad luck C<<1 is not yet finished, I promise no sprintf() next time... */ }