macro definitions...
[svn/Prometheus-QoS/.git] / prometheus.c
index 1227592f5e566027f35ced5bf9272bc9c0234e6f..e091d6e095df8ada02c802803c5d84cdf1a67a2d 100644 (file)
@@ -7,7 +7,7 @@
 /* Credit: CZFree.Net,Martin Devera,Netdave,Aquarius,Gandalf  */\r
 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */\r
 \r
-/* Modified by: xChaos, 20131119\r
+/* Modified by: xChaos, 20131126\r
                  ludva, 20080415\r
  \r
    Prometheus QoS is free software; you can redistribute it and/or\r
@@ -29,7 +29,7 @@
 #include "cll1-0.6.2.h"\r
 #include "ipstruct.h"\r
 \r
-const char *version = "0.8.3-j";\r
+const char *version = "0.8.5-a";\r
 \r
 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */\r
 /* Versions: 0.8.3 is development release, 0.8.4 will be "stable"  */\r
@@ -58,6 +58,7 @@ const char               *ls = "/bin/ls"; /* this is not user configurable :-) *
 \r
 char          *config = "/etc/prometheus/prometheus.conf"; /* main configuration file */\r
 char           *hosts = "/etc/prometheus/hosts"; /* per-IP bandwidth definition file */\r
+char      *macrosfile = "/etc/prometheus/prometheus.macros"; /* rewrite rules for most common tariffs */\r
 char    *iptablesfile = "/var/spool/prometheus.iptables"; /* temporary file for iptables-restore*/\r
 char   *ip6tablesfile = "/var/spool/prometheus.ip6tables"; /* temporary file for ip6tables-restore*/\r
 char          *credit = "/var/lib/misc/prometheus.credit"; /* credit log file */\r
@@ -107,6 +108,8 @@ long long int     line = 1024; /* WAN/ISP download in kbps */
 long long int       up = 1024; /* WAN/ISP upload in kbps */\r
 int           free_min = 256; /* minimum guaranted bandwidth for all undefined hosts */\r
 int           free_max = 512; /* maximum allowed bandwidth for all undefined hosts */\r
+int      overlimit_min = 256; /* minimum guaranted bandwidth for all undefined hosts */\r
+int      overlimit_max = 512; /* maximum allowed bandwidth for all undefined hosts */\r
 int     qos_free_delay = 0; /* seconds to sleep before applying new QoS rules */\r
 int     digital_divide = 2; /* controls digital divide weirdness ratio, 1...3 */ \r
 int        max_nesting = 3; /* maximum nesting of HTB clases, built-in maximum seems to be 4 */\r
@@ -130,7 +133,8 @@ const int idxtable_bitmask2  = 3;        /* this is no longer configurable */
 \r
 struct IP *ips = NULL, *networks = NULL, *ip, *sharedip;\r
 struct Group *groups = NULL, *group;\r
-struct Keyword *keyword, *defaultkeyword=NULL, *keywords=NULL;\r
+struct Keyword *keyword, *defaultkeyword=NULL, *keywords = NULL;\r
+struct Macro *macro, *macros = NULL;\r
 \r
 #define FREE_CLASS      3\r
 #define OVERLIMIT_CLASS 4\r
@@ -220,24 +224,25 @@ void get_config(char *config_filename)
    printf("%s ",kwd);\r
 \r
    create(keyword,Keyword);\r
-   keyword->key=kwd;\r
-   keyword->asymetry_ratio=1;          /* ratio for ADSL-like upload */\r
-   keyword->asymetry_fixed=0;          /* fixed treshold for ADSL-like upload */\r
-   keyword->data_limit=8;              /* hard shaping: apply magic_treshold if max*data_limit MB exceeded */\r
-   keyword->data_prio=4;               /* soft shaping (qos): reduce HTB prio if max*data_prio MB exceeded */\r
-   keyword->fixed_limit=0;             /* fixed data limit for setting lower HTB ceil */\r
-   keyword->fixed_prio=0;              /* fixed data limit for setting lower HTB prio */\r
-   keyword->reserve_min=8;            /* bonus for nominal HTB rate bandwidth (in kbps) */\r
-   keyword->reserve_max=0;            /* malus for nominal HTB ceil (in kbps) */\r
-   keyword->default_prio=highest_priority+1;\r
-   keyword->html_color="000000";\r
-   keyword->ip_count=0;\r
-   keyword->leaf_discipline="";\r
-\r
-   push(keyword,keywords);\r
+   keyword->key = kwd;\r
+   keyword->asymetry_ratio = 1;          /* ratio for ADSL-like upload */\r
+   keyword->asymetry_fixed = 0;          /* fixed treshold for ADSL-like upload */\r
+   keyword->data_limit = 8;              /* hard shaping: apply magic_treshold if max*data_limit MB exceeded */\r
+   keyword->data_prio = 4;               /* soft shaping (qos): reduce HTB prio if max*data_prio MB exceeded */\r
+   keyword->fixed_limit = 0;             /* fixed data limit for setting lower HTB ceil */\r
+   keyword->fixed_prio = 0;              /* fixed data limit for setting lower HTB prio */\r
+   keyword->reserve_min = 8;            /* bonus for nominal HTB rate bandwidth (in kbps) */\r
+   keyword->reserve_max = 0;            /* malus for nominal HTB ceil (in kbps) */\r
+   keyword->default_prio = highest_priority+1;\r
+   keyword->html_color = "000000";\r
+   keyword->ip_count = 0;\r
+   keyword->leaf_discipline = "";\r
+   keyword->allowed_avgmtu = 0;\r
+\r
+   push(keyword, keywords);\r
    if(!defaultkeyword)\r
    {\r
-    defaultkeyword=keyword;\r
+    defaultkeyword = keyword;\r
    }\r
    keywordcount++;\r
    \r
@@ -253,17 +258,18 @@ void get_config(char *config_filename)
      {\r
       char *tmptr=_; /*  <---- l+1 ----> */\r
       _+=l+1;        /*  via-prometheus-asymetry-ratio, etc. */\r
-      ioption("asymetry-ratio",keyword->asymetry_ratio);\r
-      ioption("asymetry-treshold",keyword->asymetry_fixed);\r
-      ioption("magic-relative-limit",keyword->data_limit);\r
-      ioption("magic-relative-prio",keyword->data_prio);\r
-      loption("magic-fixed-limit",keyword->fixed_limit);\r
-      loption("magic-fixed-prio",keyword->fixed_prio);\r
-      ioption("htb-default-prio",keyword->default_prio);\r
-      ioption("htb-rate-bonus",keyword->reserve_min);\r
-      ioption("htb-ceil-malus",keyword->reserve_max);\r
-      option("leaf-discipline",keyword->leaf_discipline);\r
-      option("html-color",keyword->html_color);\r
+      ioption("asymetry-ratio", keyword->asymetry_ratio);\r
+      ioption("asymetry-treshold", keyword->asymetry_fixed);\r
+      ioption("magic-relative-limit", keyword->data_limit);\r
+      ioption("magic-relative-prio", keyword->data_prio);\r
+      loption("magic-fixed-limit", keyword->fixed_limit);\r
+      loption("magic-fixed-prio", keyword->fixed_prio);\r
+      ioption("htb-default-prio", keyword->default_prio);\r
+      ioption("htb-rate-bonus", keyword->reserve_min);\r
+      ioption("htb-ceil-malus", keyword->reserve_max);\r
+      option("leaf-discipline", keyword->leaf_discipline);\r
+      option("html-color", keyword->html_color);\r
+      ioption("allowed-avgmtu" ,keyword->allowed_avgmtu);\r
       _=tmptr;\r
       \r
       if(keyword->data_limit || keyword->fixed_limit || \r
@@ -316,6 +322,8 @@ void get_config(char *config_filename)
 /*  ioption("qos-proxy-port",proxy_port); */\r
   ioption("free-rate",free_min);\r
   ioption("free-ceil",free_max);\r
+  ioption("overlimit-rate",overlimit_min);\r
+  ioption("overlimit-ceil",overlimit_max);\r
   ioption("htb-burst",burst);\r
   ioption("htb-burst-main",burst_main);\r
   ioption("htb-burst-group",burst_group);\r
@@ -444,12 +452,20 @@ void run_iptables_restore(void)
 \r
 char *parse_datafile_line(char *str)\r
 {\r
- char *ptr=strchr(str,' ');\r
+ char *ptr = strchr(str,' ');\r
+ if(!ptr)\r
+ {\r
+  ptr = strchr(str,'\t');\r
+ }\r
 \r
  if(ptr)\r
  {\r
-  *ptr=0;\r
+  *ptr = 0;\r
   ptr++;\r
+  while(*ptr == ' ' || *ptr == '\t')\r
+  {\r
+   ptr++;\r
+  }\r
   return ptr;\r
  } \r
  else \r
@@ -603,7 +619,7 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
   /*-----------------------------------------------------------------*/\r
   parse(credit)\r
   {\r
-   ptr=parse_datafile_line(_);\r
+   ptr = parse_datafile_line(_);\r
    if(ptr)\r
    {\r
     if_exists(ip,ips,eq(ip->addr,_))\r
@@ -615,6 +631,26 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
   done; /* ugly macro end */\r
  }\r
 \r
+ if(enable_credit && just_flush<9)\r
+ {\r
+  /*-----------------------------------------------------------------*/\r
+  printf("Parsing macro definition file %s ...\n", macrosfile);\r
+  /*-----------------------------------------------------------------*/\r
+  parse(macrosfile)\r
+  {\r
+   ptr = parse_datafile_line(_);\r
+   if(ptr)\r
+   {\r
+    create(macro, Macro);\r
+    macro->rewrite_from = _;\r
+    macro->rewrite_to = ptr;\r
+    push(macro, macros);\r
+    printf("%s -> %s\n", macro->rewrite_from, macro->rewrite_to);\r
+   }\r
+  }\r
+  done; /* ugly macro end */\r
+ }\r
+\r
  if(!just_preview)\r
  {\r
   /*-----------------------------------------------------------------*/\r
@@ -1356,10 +1392,10 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
    puts("Generating bandwith class for overlimit packets...");\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, lan, parent, OVERLIMIT_CLASS, 1024, 4096, burst, lowest_priority);\r
+                tc, lan, parent, OVERLIMIT_CLASS, overlimit_min, overlimit_max, burst, lowest_priority);\r
    safe_run(str);\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, parent, OVERLIMIT_CLASS, 1024, 4096, burst, lowest_priority);\r
+                tc, wan, parent, OVERLIMIT_CLASS, overlimit_min, overlimit_max, burst, lowest_priority);\r
    safe_run(str);\r
  }\r
  printf("Total IP count: %d\n", i);\r
This page took 0.179393 seconds and 4 git commands to generate.