macro definitions...
[svn/Prometheus-QoS/.git] / parsehosts.c
index 04fce9ffca9714d2fbfbc474f49d91211477d154..18418eddb6b9c587d6ec23925a71c6f8ed011c48 100644 (file)
@@ -1,4 +1,4 @@
-/* Modified by: xChaos, 20131028 */\r
+/* Modified by: xChaos, 20131029 */\r
 \r
 #include "cll1-0.6.2.h"\r
 #include "ipstruct.h"\r
@@ -10,6 +10,7 @@
 extern struct IP *ips, *ip, *sharedip, *networks;\r
 extern struct Group *groups, *group;\r
 extern struct Keyword *keyword, *defaultkeyword, *keywords;\r
+extern struct Macro *macro, *macros;\r
 extern int class_count;\r
 extern int ip_count;\r
 extern int found_lmsid;\r
@@ -17,7 +18,7 @@ extern int free_min;
 extern const int highest_priority;\r
 extern char *ip6prefix;\r
 \r
-struct IP* find_network_for_ip(char *ipaddr_orig);\r
+void update_network(char *look_for, struct IP* ip);\r
 /* implemented in networks.c */\r
 \r
 /* This must be object oriented! This looks almost like constructor ;-) */\r
@@ -40,6 +41,7 @@ void TheIP(char *ipaddr, int is_network)
  ip->direct      = \\r
  ip->traffic     = \\r
  ip->pktsup      = \\r
+ ip->pps_limit   = \\r
  ip->pktsdown    = 0;\r
  ip->keyword     = keywords;\r
  ip->v6          = (strchr(ip->addr,':')!=NULL);\r
@@ -150,10 +152,11 @@ void parse_hosts(char *hosts)
  char *str, *ptr;\r
  char *substring;\r
  struct IP *network;\r
+ int pktratio;\r
 \r
  parse(hosts)\r
  {\r
-  str=_;\r
+  str = _;\r
 \r
   if(*str < '0' or *str > '9')\r
   {\r
@@ -161,6 +164,25 @@ void parse_hosts(char *hosts)
    continue;\r
   }\r
   \r
+  /* first, expand (rewrite) any predefined macros, if found*/\r
+  for_each(macro, macros)\r
+  {\r
+   substring = strstr(str, macro->rewrite_from);\r
+   if(substring);\r
+   {\r
+    int l1, l3;\r
+    *substring = 0;\r
+    substring += strlen(macro->rewrite_from);\r
+    l1 = strlen(str);\r
+    l3 = strlen(substring);\r
+    string(ptr, l1 + strlen(macro->rewrite_to) + l3);\r
+    strcpy(ptr, str);\r
+    strcat(ptr, macro->rewrite_to);\r
+    strcat(ptr, substring);\r
+    str = ptr;\r
+   }\r
+  }\r
+\r
   /* Does this IP share QoS class with some other ? */\r
   substring = strstr(str, "sharing-");\r
   if(substring)\r
@@ -235,6 +257,7 @@ void parse_hosts(char *hosts)
       *ptr=0;\r
       ip->max = ip->desired = atoi(ptr+1);\r
      }\r
+\r
      ip->min = atoi(substring);\r
      if(ip->min <= 0)\r
      {\r
@@ -242,6 +265,7 @@ void parse_hosts(char *hosts)
              str, free_min);\r
       ip->min = free_min;\r
      }\r
+\r
      if(ip->max <= ip->min)\r
      {\r
       ip->fixedprio = TRUE;\r
@@ -250,24 +274,26 @@ void parse_hosts(char *hosts)
      else \r
      {\r
       ip->max -= ip->keyword->reserve_max;\r
-      if(ip->max<ip->min)\r
+      if(ip->max < ip->min)\r
       {\r
-       ip->max=ip->min;\r
+       ip->max = ip->min;\r
       }\r
      }\r
-     ip->mark = FIRSTIPCLASS+1+class_count++;\r
 \r
-     network = find_network_for_ip(ip->addr);\r
-     if(network)\r
+     /* avg MTU bytes * 8 >> 10 = in bits, max is in kb/s  */\r
+     pktratio = (ip->keyword->allowed_avgmtu*8) >> 10;\r
+     if(pktratio > 0)\r
      {\r
-      network->min += ip->min;\r
-      network->desired += ip->max;\r
-      if(ip->max > network->max)\r
+      ip->pps_limit = ip->max/pktratio;\r
+      if(ip->pps_limit > 10000) /* this limit seems to be hardcoded in iptables */\r
       {\r
-       network->max = ip->max;\r
+       ip->pps_limit = 0; /* do not apply packet limits */\r
       }\r
      }\r
 \r
+     ip->mark = FIRSTIPCLASS+1+class_count++;     \r
+     update_network(ip->addr, ip);\r
+\r
      if_exists(group,groups,(group->min == ip->min)) \r
      { \r
       group->count++;      \r
@@ -300,4 +326,7 @@ void parse_hosts(char *hosts)
   exit(-1);\r
  }\r
  done; /* ugly macro end */\r
+// TheIP("0.0.0.0", TRUE);\r
+// ip->name = "TOTAL";\r
+// ip->mask = 0;\r
 }
\ No newline at end of file
This page took 0.129783 seconds and 4 git commands to generate.