/* Prometheus QoS - you can "steal fire" from your ISP */\r
/* "fair-per-IP" quality of service (QoS) utility */\r
/* requires Linux 2.4.x or 2.6.x with HTB support */\r
-/* Copyright(C) 2005-2008 Michael Polak (xChaos) */\r
+/* Copyright(C) 2005-2012 Michael Polak, Arachne Labs */\r
/* iptables-restore support Copyright(C) 2007-2008 ludva */\r
/* Credit: CZFree.Net,Martin Devera,Netdave,Aquarius,Gandalf */\r
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */\r
\r
#include "cll1-0.6.2.h"\r
\r
-const char *version = "0.8.3-e";\r
+const char *version = "0.8.3-f";\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
{\r
puts("Command line switches:\n\\r
\n\\r
--?, --help this help screen\n\\r
--v, --version show Version number of this utility and exit\n\\r
--c filename force alternative /etc/prometheus.Conf filename\n\\r
--h filename force alternative /etc/Hosts filename (overrides hosts keyword)\n\\r
--f just Flush iptables and tc classes and exit (stop shaping)\n\\r
--9 emergency iptables flush (do not read data transfer statistics)\n\\r
--p just generate Preview of data transfer statistics and exit\n\\r
--d Dry run (preview tc and iptables commands on stdout)\n\\r
--r Run (reset all statistics and start shaping)\n\\r
--n run Now (start shaping without delay - overrides qos-free-delay keyword)\n\\r
--l Mmm YYYY generate HTML summary of traffic Logs (Mmm=Jan-Dec or Year, YYYY=year)\n\\r
--m generate HTML summary of traffic logs for yesterday's Month\n\\r
--y generate HTML summary of traffic logs for yesterday's Year\n");\r
-/* not yet implemented:\r
--s start shaping! (keep data transfer statistics - but apply shaping)\n\\r
-*/\r
+-d Dry run (preview tc and iptables commands on stdout)\n\\r
+-r Run (reset all statistics and start shaping - daily usage)\n\\r
+-p just generate Preview of data transfer statistics and exit (after -r)\n\\r
+-s start Shaping FUP limits (keeps data transfer stat like -p) (after -r)\n\\r
+-n run Now (like -r delay - overrides qos-free-delay keyword, after boot)\n\\r
+-f just Flush iptables and tc classes and exit (stop shaping, no QiS)\n\\r
+-9 emergency iptables flush (like -f, but dumps data transfer statistics)\n\\r
+\n\\r
+-c filename force alternative /etc/prometheus/prometheus.conf filename\n\\r
+-h filename force alternative /etc/hosts filename (overrides hosts keyword)\n\\r
+-l Mmm YYYY generate HTML summary of Logged traffic (Mmm=Jan-Dec) (and exit)\n\\r
+-m generate HTML summary of traffic for yesterday's Month (and exit)\n\\r
+-y generate HTML summary of traffic for yesterday's Year (and exit)\n\\r
+-? --help show this help scree (and exit)\n\\r
+-v --version show Version number of this utility (and exit)\n");\r
}\r
\r
/* === Configuraration file values defaults - stored in global variables ==== */\r
perror(config_filename);\r
puts("Warning - using built-in defaults instead ...");\r
}\r
- done;\r
+ done; /* ugly macro end */\r
printf("\n");\r
\r
/* leaf discipline for keywords */\r
{\r
printf("%s\n",_);\r
}\r
- done;\r
+ done; /* ugly macro end */\r
}\r
\r
sprintf(restor,"%s <%s",iptablesrestore, iptablesfile);\r
accept_month = 1;\r
}\r
}\r
- done;\r
+ done; /* ugly macro end */ \r
\r
if(accept_month)\r
{\r
\r
program\r
{\r
- int i=0;\r
- FILE *f=NULL;\r
- char *str, *ptr, *d;\r
+ int i=0; /* just plain old Fortran style integer :-) */\r
+ FILE *f=NULL; /* everything is just stream of bytes... */\r
+ char *str, *ptr, *d; /* LET A$=B$ :-) */\r
char *substring;\r
int class_count=0,ip_count=0;\r
int parent=1;\r
- int just_flush=FALSE;\r
+ int just_flush=FALSE; /* deactivates all previous actions */\r
int nodelay=FALSE;\r
- int just_preview=FALSE; /* preview - generate just stats */\r
- int just_logs=FALSE; /* just parse logs */\r
+ int just_preview=FALSE; /* preview - generate just stats */\r
+ int start_shaping=FALSE; /* apply FUP - requires classmap file */\r
+ int just_logs=FALSE; /* just parse logs */\r
int run=FALSE;\r
int total=0;\r
\r
\r
printf("\n\\r
Prometheus QoS - \"fair-per-IP\" Quality of Service setup utility.\n\\r
-Version %s - Copyright (C)2005-2012 Michael Polak (xChaos)\n\\r
+Version %s - Copyright (C)2005-2012 Michael Polak, Arachne Labs\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
- /*----- Boring... we have to check command line options first: ----*/\r
- \r
+ /*----- Boring... we have to check command line options first: ----*/ \r
arguments\r
{\r
argument("-c") { nextargument(config); }\r
argument("-f") { run=TRUE; just_flush=TRUE; }\r
argument("-9") { run=TRUE; just_flush=9; }\r
argument("-p") { run=TRUE; just_preview=TRUE; }\r
+ argument("-s") { run=TRUE; just_preview=TRUE; start_shaping=TRUE; }\r
argument("-r") { run=TRUE; }\r
argument("-n") { run=TRUE; nodelay=TRUE; }\r
argument("-l") { just_logs=TRUE; }\r
perror(hosts);\r
exit(-1);\r
}\r
- done;\r
+ done; /* ugly macro end */\r
\r
/*-----------------------------------------------------------------*/\r
/* cll1.h - let's allocate brand new character buffer... */\r
}\r
}\r
}\r
- done;\r
+ done; /* ugly macro end */\r
}\r
\r
if(!just_preview)\r
\r
if(just_preview)\r
{\r
+ if(start_shaping)\r
+ {\r
+ printf("Reading %s and applying Fair Use Policy rules ... \n", classmap);\r
+ parse(classmap)\r
+ {\r
+ ptr=strchr(_,' ');\r
+ if(ptr)\r
+ {\r
+ *ptr=0;\r
+ ptr++;\r
+ if_exists(ip,ips,eq(ip->addr,_))\r
+ {\r
+ ip->mark=atoi(ptr);\r
+ if(ip->max < ip->desired) /* apply FUP limit immediately.... */\r
+ {\r
+ printf("Applying limit for %-22s %-16s %04d ", ip->name, ip->addr, ip->mark); \r
+ printf("(down: %dk-%dk ", ip->min, ip->max); \r
+ sprintf(str, "%s class change dev %s parent 1:%d classid 1:%d htb rate %dkbit ceil %dkbit burst %dk prio %d", \r
+ tc, lan, ip->group, ip->mark,ip->min,ip->max, burst, ip->prio);\r
+ safe_run(str);\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
+ sprintf(str,"%s class change 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->min/ip->keyword->asymetry_ratio)-ip->keyword->asymetry_fixed),\r
+ (int)((ip->max/ip->keyword->asymetry_ratio)-ip->keyword->asymetry_fixed), burst, ip->prio);\r
+ safe_run(str);\r
+ }\r
+ }\r
+ }\r
+ }\r
+ fail\r
+ { \r
+ perror(classmap);\r
+ puts("Warning - classmap file not fund, just generating preview ...");\r
+ start_shaping=FALSE;\r
+ }\r
+ done; /* ugly macro end */\r
+ }\r
f=fopen(preview,"w");\r
ptr=preview; \r
}\r
char *f1="", *f2="";\r
i++;\r
\r
- if(ip->max < ip->desired)\r
- {\r
- f1="<span style=\"color:red\">";\r
- f2="</span>";\r
- limit_count++;\r
- }\r
- else if(ip->prio > highest_priority+1)\r
- {\r
- f1="<span style=\"color:brown\">";\r
- f2="</span>";\r
- prio_count++;\r
- }\r
\r
#ifdef DEBUG\r
printf("%03d. %-22s %10Lu (%d/%d)\n",i ,ip->name, ip->traffic, ip->min, ip->max); \r
\r
if(just_preview)\r
{\r
- puts("Statistics preview generated (-p switch) - now exiting ...");\r
+ char swchar='p';\r
+ if(start_shaping)\r
+ {\r
+ swchar='s';\r
+ }\r
+ printf("Statistics preview generated (-%c switch) - now exiting ...\n", swchar);\r
exit(0);\r
} \r
\r