/* Credit: CZFree.Net,Martin Devera,Netdave,Aquarius,Gandalf */\r
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */\r
\r
-/* Modified by: xChaos, 20111130\r
+/* Modified by: xChaos, 20120511\r
ludva, 20080415\r
\r
Prometheus QoS is free software; you can redistribute it and/or\r
\r
#include "cll1-0.6.2.h"\r
\r
-const char *version = "0.8.3-b";\r
+const char *version = "0.8.3-c";\r
\r
/* Version numbers: 0.8.3 is development releases ("beta"), 0.8.4 will be "stable" */\r
/* Debian(RPM) package versions/patchlevels: 0.7.9-2, 0.8.0-1, 0.8.0-2, etc. */\r
/* C source code development versions ("beta"): 0.7.9-a, 0.8.1-b, etc. */\r
/* C source code release versions: 0.8.0, 0.8.2, 0.8.4, etc. */\r
\r
-const char *stats_html_signature = "<small>Statistics generated by Prometheus QoS version %s<br>GPL+Copyright(C)2005-2011 Michael Polak, <a href=\"http://www.arachne.cz/\">Arachne Labs</a></small>\n";\r
+const char *stats_html_signature = "<small>Statistics generated by Prometheus QoS version %s<br>GPL+Copyright(C)2005-2012 Michael Polak, <a href=\"http://www.arachne.cz/\">Arachne Labs</a></small>\n";\r
\r
/* ======= All path names are defined here (for RPM patch) ======= */\r
\r
char *very_ugly_ipv4_code(char *inip,int bitmask,int format_as_chainname)\r
{\r
/* warning: this function was debugged only for bitmask values 20,24,28 !!!*/\r
- int dot=0,n;\r
+ int dot=0, n;\r
char *ip,*outip,*outptr,*fmt;\r
\r
duplicate(inip,ip);\r
}\r
else\r
{\r
- char *cutdot=strchr(ip+1,'.'); /*for bitmask<24*/\r
- if(cutdot)*cutdot='\0';\r
+ char *cutdot=strchr(ip+1,'.'); /*for bitmask<24*/ \r
+ if(cutdot)\r
+ {\r
+ *cutdot = '\0';\r
+ }\r
+ \r
if(format_as_chainname)\r
- fmt="_%d_%d";\r
+ {\r
+ fmt = "_%d_%d";\r
+ }\r
else\r
- fmt=".%d";\r
+ {\r
+ fmt = ".%d";\r
+ }\r
+ \r
if(bitmask%8)\r
- n=atoi(ip+1)-atoi(ip+1)%(1<<(8-bitmask%8));\r
+ {\r
+ n = atoi(ip+1)-atoi(ip+1)%(1<<(8-bitmask%8));\r
+ }\r
else\r
- n=0;\r
+ {\r
+ n = 0;\r
+ }\r
\r
/*debug printf("%d/%d => [_%d_%d]\n",atoi(ip+1),bitmask,n,bitmask); */\r
sprintf(outptr,fmt,n,bitmask);\r
- if(!format_as_chainname) while(bitmask<24)\r
+ if(!format_as_chainname)\r
{\r
- strcat(outip,".0");\r
- bitmask+=8;\r
+ while(bitmask<24)\r
+ {\r
+ strcat(outip,".0");\r
+ bitmask+=8;\r
+ }\r
}\r
/* debug printf("[%s]\n",outip); */\r
return outip;\r
ioption("htb-r2q",htb_r2q);\r
ioption("magic-include-upload",include_upload);\r
ioption("magic-treshold",magic_treshold); \r
- option("filter-type", cnf);\r
- \r
+ option("filter-type", cnf); \r
/* not yet implemented:\r
ioption("magic-fixed-packets",fixed_packets);\r
ioption("magic-relative-packets",packet_limit);\r
/*leaf discipline for keywords*/\r
for_each(keyword,keywords)\r
{\r
- if (!strcmpi(keyword->leaf_discipline, ""))\r
+ if(!strcmpi(keyword->leaf_discipline, ""))\r
{\r
keyword->leaf_discipline = qos_leaf;\r
}\r
}\r
\r
- if (strcmpi(cnf, "mark"))\r
+ if(strcmpi(cnf, "mark"))\r
{\r
filter_type = 2;\r
mark = "CLASSIFY";\r
if(valid) switch(col)\r
{ \r
case 1: if(eq(ptr,"Chain"))\r
+ {\r
setchainname=1;\r
+ }\r
else if(eq(ptr,"pkts")) \r
+ {\r
valid=0;\r
+ }\r
else\r
+ {\r
sscanf(ptr,"%lu",&pkts); \r
+ }\r
break;\r
case 2: if(setchainname)\r
{\r
if(!strncmp(ptr,"post_",5) || eq(ptr,"POSTROUTING"))\r
- downloadflag=1; \r
+ {\r
+ downloadflag = 1; \r
+ }\r
else \r
- if(!strncmp(ptr,"forw_",5) || eq(ptr,"FORWARD"))\r
- downloadflag=0;\r
- \r
+ {\r
+ if(!strncmp(ptr,"forw_",5) || eq(ptr,"FORWARD"))\r
+ {\r
+ downloadflag = 0;\r
+ }\r
+ } \r
if(eq(ptr,"post_common") || eq(ptr,"forw_common"))\r
- commonflag=1;\r
+ {\r
+ commonflag = 1;\r
+ }\r
}\r
else\r
- sscanf(ptr,"%Lu",&traffic); traffic+=(1<<19); traffic>>=20;\r
+ {\r
+ sscanf(ptr,"%Lu",&traffic); \r
+ traffic += (1<<19);\r
+ traffic >>= 20;\r
+ }\r
break;\r
case 3: if((strncmp(ptr,"post_",5) && strncmp(ptr,"forw_",5)) || commonflag)\r
+ {\r
accept=eq(ptr,mark);\r
- /*if (filter_type==1) accept=eq(ptr,"MARK"); else accept=eq(ptr,"CLASSIFY");*/\r
+ }\r
+ /*if(filter_type==1) accept=eq(ptr,"MARK"); else accept=eq(ptr,"CLASSIFY");*/\r
break;\r
case 8: if(downloadflag)\r
{ \r
- if(strstr(proxy_ip,ptr))proxyflag=1; \r
+ if(strstr(proxy_ip,ptr))\r
+ {\r
+ proxyflag=1; \r
+ }\r
}\r
else\r
+ {\r
ipaddr=ptr; \r
- break;\r
+ }\r
+ break;\r
case 9: if(downloadflag)ipaddr=ptr;break;\r
}\r
\r
case 8:\r
case 9:\r
case 10:\r
- case 11: if (isalpha(*ptr)) /* character, not numeric string = date, just one*/\r
+ case 11: if(isalpha(*ptr)) /* character, not numeric string = date, just one*/\r
{\r
valid_columns(ptr2,ptr,' ',col2) switch(col2)\r
{\r
\r
printf("\n\\r
Prometheus QoS - \"fair-per-IP\" Quality of Service setup utility.\n\\r
-Version %s - Copyright (C)2005-2011 Michael Polak (xChaos)\n\\r
+Version %s - Copyright (C)2005-2012 Michael Polak (xChaos)\n\\r
iptables-restore & burst tunning & classify modification by Ludva\n\\r
Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);\r
\r
if(*ptr=='-')\r
{\r
*ptr=0;\r
- ip->max=ip->desired=atoi(ptr+1);\r
+ ip->max = ip->desired=atoi(ptr+1);\r
}\r
- ip->min=atoi(substring);\r
- if(ip->min<=0)\r
+ ip->min = atoi(substring);\r
+ if(ip->min <= 0)\r
{\r
- printf(" %s: Illegal value of minimum bandwidth 0 kbps, using %d kbps\n",str,free_min);\r
- ip->min=free_min;\r
+ printf(" %s: Illegal value of minimum bandwidth 0 kbps, using %d kbps\n",\r
+ str, free_min);\r
+ ip->min = free_min;\r
}\r
- if(ip->max<=ip->min)\r
+ if(ip->max <= ip->min)\r
{\r
- ip->fixedprio=1;\r
- ip->max=ip->min+ip->keyword->reserve_min;\r
+ ip->fixedprio = 1;\r
+ ip->max = ip->min+ip->keyword->reserve_min;\r
}\r
else \r
{\r
- ip->max-=ip->keyword->reserve_max;\r
+ ip->max -= ip->keyword->reserve_max;\r
if(ip->max<ip->min)\r
{\r
ip->max=ip->min;\r
if_exists(group,groups,group->min==ip->min) \r
{ \r
group->count++; \r
- group->desired+=ip->min;\r
+ group->desired += ip->min;\r
ip->group = group->id; \r
}\r
else\r
{\r
create(group,Group);\r
- group->min=ip->min;\r
+ group->min = ip->min;\r
group->id = groupidx++;\r
ip->group = group->id;\r
\r
}\r
if(!sharedip)\r
{\r
- printf("Unresolved shared connection: %s %s sharing-%s\n",ip->addr,ip->name,ip->sharing);\r
+ printf("Unresolved shared connection: %s %s sharing-%s\n",\r
+ ip->addr, ip->name, ip->sharing);\r
}\r
}\r
\r
/*-----------------------------------------------------------------*/\r
\r
iptables_file=fopen(iptablesfile,"w");\r
- if (iptables_file == NULL)\r
+ if(iptables_file == NULL)\r
{\r
puts("Cannot open iptablesfile!");\r
exit(-1);\r
}\r
\r
log_file=fopen(cmdlog,"w");\r
- if (log_file == NULL) \r
+ if(log_file == NULL) \r
{\r
puts("Cannot open logfile!");\r
exit(-1);\r
save_line(":post_common - [0:0]");\r
save_line(":forw_common - [0:0]");\r
\r
- for_each(ip,ips) if (ip->addr && *(ip->addr) && !eq(ip->addr,"0.0.0.0/0"))\r
+ for_each(ip,ips) if(ip->addr && *(ip->addr) && !eq(ip->addr,"0.0.0.0/0"))\r
{\r
buf=hash_id(ip->addr,bitmask);\r
if_exists(idx,idxs,eq(idx->id,buf))\r
for_each(idx,idxs)\r
{\r
subnet=subnet_id(idx->addr,idx->bitmask);\r
- printf("%d: %s/%d\n",++i,subnet,idx->bitmask);\r
+ printf("%d: %s/%d\n",\r
+ ++i, subnet, idx->bitmask);\r
\r
sprintf(str,":post_%s - [0:0]", idx->id);\r
save_line(str);\r
if(just_flush)\r
{\r
fclose(iptables_file);\r
- if (log_file) fclose(log_file);\r
+ if(log_file) fclose(log_file);\r
puts("Just flushed iptables and tc classes - now exiting ...");\r
exit(0);\r
}\r
f=fopen("/var/run/prometheus.previous","w");\r
if(f)\r
{\r
- for_each(ip,ips) if(ip->traffic || ip->direct || ip->proxy || ip->upload)\r
+ for_each(ip,ips)\r
{\r
- fprintf(f,"%s %Lu %Lu %Lu %Lu\n",\r
- ip->addr, ip->traffic, ip->direct, ip->proxy, ip->upload);\r
+ if(ip->traffic || ip->direct || ip->proxy || ip->upload)\r
+ {\r
+ fprintf(f,"%s %Lu %Lu %Lu %Lu\n",\r
+ ip->addr, ip->traffic, ip->direct, ip->proxy, ip->upload);\r
+ }\r
}\r
fclose(f);\r
}\r
/*-----------------------------------------------------------------*/\r
\r
i=0;\r
+#ifdef DEBUG\r
printf("%-22s %-15s mark\n","name","ip");\r
+#endif\r
\r
for_each(ip,ips) if(ip->mark>0)\r
{ \r
chain_postrouting="POSTROUTING";\r
}\r
\r
+#ifdef DEBUG\r
printf("%-22s %-16s %04d ", ip->name, ip->addr, ip->mark); \r
+#endif\r
\r
/* -------------------------------------------------------- mark download */\r
\r
if(ip->min)\r
{\r
/* -------------------------------------------------------- download class */\r
+#ifdef DEBUG\r
printf("(down: %dk-%dk ", ip->min, ip->max); \r
+#endif\r
\r
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);\r
safe_run(str);\r
\r
- if (strcmpi(ip->keyword->leaf_discipline, "none"))\r
+ if(strcmpi(ip->keyword->leaf_discipline, "none"))\r
{\r
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*/\r
safe_run(str);\r
} \r
- if (filter_type == 1)\r
+ if(filter_type == 1)\r
{\r
sprintf(str,"%s filter add dev %s parent 1:0 protocol ip handle %d fw flowid 1:%d", tc, lan, ip->mark, ip->mark);\r
safe_run(str);\r
}\r
\r
/* -------------------------------------------------------- upload class */\r
+#ifdef DEBUG\r
printf("up: %dk-%dk)\n", (int)((ip->min/ip->keyword->asymetry_ratio)-ip->keyword->asymetry_fixed), \r
(int)((ip->max/ip->keyword->asymetry_ratio)-ip->keyword->asymetry_fixed));\r
+#endif\r
\r
sprintf(str,"%s class add dev %s parent 1:%d classid 1:%d htb rate %dkbit ceil %dkbit burst %dk prio %d",\r
tc, wan, ip->group, ip->mark,\r
(int)((ip->max/ip->keyword->asymetry_ratio)-ip->keyword->asymetry_fixed), burst, ip->prio);\r
safe_run(str);\r
\r
- if (strcmpi(ip->keyword->leaf_discipline, "none"))\r
+ if(strcmpi(ip->keyword->leaf_discipline, "none"))\r
{\r
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*/\r
safe_run(str);\r
} \r
- if (filter_type == 1)\r
+ if(filter_type == 1)\r
{\r
sprintf(str,"%s filter add dev %s parent 1:0 protocol ip handle %d fw flowid 1:%d",tc, wan, ip->mark, ip->mark);\r
safe_run(str);\r
}\r
}\r
else\r
+ {\r
+#ifdef DEBUG\r
printf("(sharing %s)\n", ip->sharing);\r
+#endif\r
+ }\r
i++;\r
}\r
\r
tc,wan,parent,free_min,free_max,burst,lowest_priority);\r
safe_run(str);\r
/* tc SFQ */\r
- if (strcmpi(qos_leaf, "none"))\r
+ if(strcmpi(qos_leaf, "none"))\r
{\r
sprintf(str,"%s qdisc add dev %s parent 1:3 handle 3 %s",tc,lan,qos_leaf);\r
safe_run(str);\r
}\r
printf("Total IP count: %d\n", i);\r
run_restore(); \r
- if (log_file) fclose(log_file);\r
+ if(log_file)\r
+ {\r
+ fclose(log_file);\r
+ }\r
return 0;\r
/* that's all folks, thank you for reading it all the way up to this point ;-) */\r
/* bad luck C<<1 is not yet finished, I promise no sprintf() next time... */\r