Version 0.8.3-f with -s start Shaping FUP limits
authorxchaos <xchaos@251d49ef-1d17-4917-a970-b30cf55b089b>
Mon, 11 Jun 2012 13:01:28 +0000 (13:01 +0000)
committerxchaos <xchaos@251d49ef-1d17-4917-a970-b30cf55b089b>
Mon, 11 Jun 2012 13:01:28 +0000 (13:01 +0000)
git-svn-id: https://dev.arachne.cz/repos/prometheus/trunk@190 251d49ef-1d17-4917-a970-b30cf55b089b

prometheus.c

index 6aaa3c78869793a9c3042eb18a6e5bc0e5fb8235..529315d91e32ed97c5cfea649299689f7768c34c 100644 (file)
@@ -2,7 +2,7 @@
  /*     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
  /*     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
 /*    iptables-restore support Copyright(C) 2007-2008 ludva     */\r
 /*  Credit: CZFree.Net,Martin Devera,Netdave,Aquarius,Gandalf  */\r
 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  */\r
@@ -33,7 +33,7 @@
 \r
 #include "cll1-0.6.2.h"\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
 /* 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
@@ -89,22 +89,21 @@ void help(void)
 {\r
  puts("Command line switches:\n\\r
 \n\\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
 }\r
 \r
 /* === Configuraration file values defaults - stored in global variables ==== */\r
@@ -476,7 +475,7 @@ void get_config(char *config_filename)
   perror(config_filename);\r
   puts("Warning - using built-in defaults instead ...");\r
  }\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
  printf("\n");\r
  \r
  /* leaf discipline for keywords */\r
@@ -699,7 +698,7 @@ void run_restore(void)
   {\r
    printf("%s\n",_);\r
   }\r
   {\r
    printf("%s\n",_);\r
   }\r
-  done;\r
+  done; /* ugly macro end */\r
  }\r
 \r
  sprintf(restor,"%s <%s",iptablesrestore, iptablesfile);\r
  }\r
 \r
  sprintf(restor,"%s <%s",iptablesrestore, iptablesfile);\r
@@ -880,7 +879,7 @@ void parse_ip_log(int argc, char **argv)
       accept_month = 1;\r
      }\r
     }\r
       accept_month = 1;\r
      }\r
     }\r
-    done;\r
+    done; /* ugly macro end */ \r
 \r
     if(accept_month)\r
     {\r
 \r
     if(accept_month)\r
     {\r
@@ -1082,16 +1081,17 @@ void append_log(struct IP *self) /*using global variables*/
 \r
 program\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
  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 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
  int run=FALSE;\r
  int total=0;\r
  \r
@@ -1100,12 +1100,11 @@ program
   \r
  printf("\n\\r
 Prometheus QoS - \"fair-per-IP\" Quality of Service setup utility.\n\\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
 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
  arguments\r
  {\r
   argument("-c") { nextargument(config); }\r
@@ -1114,6 +1113,7 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
   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("-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
   argument("-r") { run=TRUE; }\r
   argument("-n") { run=TRUE; nodelay=TRUE; }\r
   argument("-l") { just_logs=TRUE; }\r
@@ -1264,7 +1264,7 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
   perror(hosts);\r
   exit(-1);\r
  }\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
  /* cll1.h - let's allocate brand new character buffer...           */\r
@@ -1307,7 +1307,7 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
     }\r
    }\r
   }\r
     }\r
    }\r
   }\r
-  done;\r
+  done; /* ugly macro end */\r
  }\r
 \r
  if(!just_preview)\r
  }\r
 \r
  if(!just_preview)\r
@@ -1634,6 +1634,45 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
 \r
  if(just_preview)\r
  {\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
   f=fopen(preview,"w");\r
   ptr=preview; \r
  }\r
@@ -1791,18 +1830,6 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
    char *f1="", *f2="";\r
    i++;\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
 #ifdef DEBUG\r
    printf("%03d. %-22s %10Lu (%d/%d)\n",i ,ip->name, ip->traffic, ip->min, ip->max); \r
@@ -2053,7 +2080,12 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
 \r
  if(just_preview)\r
  {\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
   exit(0);\r
  }  \r
 \r
This page took 0.197781 seconds and 4 git commands to generate.