-b Boot mode
[svn/Prometheus-QoS/.git] / parsehosts.c
index 47b06bd5c28925d6495e7ddf20ca6065311a98e4..cc2548f909dc040f04b82002bc5c2f38cb9abb09 100644 (file)
@@ -13,7 +13,7 @@ extern struct Keyword *keyword, *defaultkeyword, *keywords;
 extern struct Macro *macro, *macros;\r
 extern int class_count;\r
 extern int ip_count;\r
 extern struct Macro *macro, *macros;\r
 extern int class_count;\r
 extern int ip_count;\r
-extern int found_lmsid;\r
+extern int found_code;\r
 extern int free_min;\r
 extern const int highest_priority;\r
 extern char *ip6prefix;\r
 extern int free_min;\r
 extern const int highest_priority;\r
 extern char *ip6prefix;\r
@@ -29,7 +29,7 @@ void TheIP(char *ipaddr, int is_network)
  ip->addr         = ipaddr;\r
  ip->sharing      = NULL;\r
  ip->prio         = highest_priority+1;\r
  ip->addr         = ipaddr;\r
  ip->sharing      = NULL;\r
  ip->prio         = highest_priority+1;\r
- ip->lmsid        = -1;\r
+ ip->code         = "-----";\r
  ip->fixedprio    = \\r
  ip->aggregated   = \\r
  ip->mark         = \\r
  ip->fixedprio    = \\r
  ip->aggregated   = \\r
  ip->mark         = \\r
@@ -57,16 +57,24 @@ void TheIP(char *ipaddr, int is_network)
  {\r
   push(ip, ips); \r
  }\r
  {\r
   push(ip, ips); \r
  }\r
+#ifdef MONITORINGTRHU_CTU\r
+ ip->technology_str = NULL;\r
+ ip->ruian_id_str   = NULL;\r
+#endif\r
+\r
  ip_count++;\r
 }\r
 \r
  ip_count++;\r
 }\r
 \r
+#ifdef MONITORINGTRHU_CTU\r
+struct Technology *technologies = NULL, *technology = NULL;\r
+#endif\r
 struct IP *lastIP6range, *lastIP6uplink;\r
 \r
 /* == This function strips extra characters after IPv4 address and stores it = */\r
 void parse_and_append_ip(char *str, struct IP *listhead)\r
 {\r
  char *ptr, *ipaddr, *nextip6, *ip6buf; \r
 struct IP *lastIP6range, *lastIP6uplink;\r
 \r
 /* == This function strips extra characters after IPv4 address and stores it = */\r
 void parse_and_append_ip(char *str, struct IP *listhead)\r
 {\r
  char *ptr, *ipaddr, *nextip6, *ip6buf; \r
- char *ip6uplink = NULL, *ip6range = NULL, *ipname = NULL, *lmsid = NULL;\r
+ char *ip6uplink = NULL, *ip6range = NULL, *ipname = NULL, *code = NULL;\r
 \r
  if(ip6prefix) /* Try this only if IPv6 subsystem is active... */\r
  {\r
 \r
  if(ip6prefix) /* Try this only if IPv6 subsystem is active... */\r
  {\r
@@ -97,7 +105,7 @@ void parse_and_append_ip(char *str, struct IP *listhead)
  ptr = strchr(str, '{');\r
  if(ptr)\r
  {\r
  ptr = strchr(str, '{');\r
  if(ptr)\r
  {\r
-  lmsid = ++ptr;\r
+  code = ++ptr;\r
   while(*ptr and *ptr != '}')\r
   {\r
    ptr++;\r
   while(*ptr and *ptr != '}')\r
   {\r
    ptr++;\r
@@ -136,9 +144,9 @@ void parse_and_append_ip(char *str, struct IP *listhead)
   }\r
   ip->name = ip6range;\r
   ip->keyword = defaultkeyword; /* settings for default keyword */\r
   }\r
   ip->name = ip6range;\r
   ip->keyword = defaultkeyword; /* settings for default keyword */\r
-  if(lmsid)\r
+  if(code)\r
   {\r
   {\r
-   ip->lmsid = atoi(lmsid);\r
+   ip->code = code;\r
   }\r
   lastIP6range = ip;\r
  }\r
   }\r
   lastIP6range = ip;\r
  }\r
@@ -155,9 +163,9 @@ void parse_and_append_ip(char *str, struct IP *listhead)
   TheIP(ip6uplink, FALSE); /* always new IP - more IPs in single uplink network */\r
   ip->name = ip6uplink;\r
   ip->keyword = defaultkeyword; /* settings for default keyword */\r
   TheIP(ip6uplink, FALSE); /* always new IP - more IPs in single uplink network */\r
   ip->name = ip6uplink;\r
   ip->keyword = defaultkeyword; /* settings for default keyword */\r
-  if(lmsid)\r
+  if(code)\r
   {\r
   {\r
-   ip->lmsid = atoi(lmsid);\r
+   ip->code = code;\r
   }\r
   lastIP6uplink = ip;\r
  }\r
   }\r
   lastIP6uplink = ip;\r
  }\r
@@ -172,10 +180,10 @@ void parse_and_append_ip(char *str, struct IP *listhead)
   TheIP(ipaddr, (listhead==networks));\r
  }\r
  ip->name = ipname;\r
   TheIP(ipaddr, (listhead==networks));\r
  }\r
  ip->name = ipname;\r
- if(lmsid)\r
+ if(code)\r
  {\r
  {\r
-  ip->lmsid = atoi(lmsid);\r
-  found_lmsid = TRUE;\r
+  ip->code = code;\r
+  found_code = TRUE;\r
  }\r
 }\r
 \r
  }\r
 }\r
 \r
@@ -251,7 +259,7 @@ void parse_hosts(char *hosts)
   else\r
   {\r
    substring = strstr(str, "#255.");\r
   else\r
   {\r
    substring = strstr(str, "#255.");\r
-   if(substring and not strstr(str, "#255.255.255.255")) /* do not ping /32 uplinks */\r
+   if(substring and not strstr(str, "#255.255.255.255")) /* ignore /32 subnets */\r
    {\r
     /* netmask detected - save network*/\r
     unsigned bit;\r
    {\r
     /* netmask detected - save network*/\r
     unsigned bit;\r
@@ -280,9 +288,45 @@ void parse_hosts(char *hosts)
    }\r
    else\r
    {\r
    }\r
    else\r
    {\r
+    /* Main branch - most IP addresses go here */\r
     /*Do we have to create new QoS class for this IP ? */\r
     if_exists(keyword,keywords,(substring=strstr(str,keyword->key)))\r
     {\r
     /*Do we have to create new QoS class for this IP ? */\r
     if_exists(keyword,keywords,(substring=strstr(str,keyword->key)))\r
     {\r
+#ifdef MONITORINGTRHU_CTU\r
+//special hack only to generate certain required CSV statistics for www.ctu.cz (regulation body)\r
+     char *found_at = strchr(str, '@');\r
+     char *ruian_id_str = NULL;\r
+     technology = NULL;\r
+     if(found_at)\r
+     {\r
+      int len;\r
+      char *found_ruian_end = strchr(found_at, ' ');\r
+      char *found_tech_str = found_at;\r
+      while(found_tech_str-- > str && *found_tech_str != ' ' && *found_tech_str != '#');\r
+      if(found_tech_str > str)\r
+      {\r
+       len = found_at - found_tech_str - 1;\r
+       for_each(technology, technologies)\r
+        if(strlen(technology->filename)==len && !strncmp(technology->filename, found_tech_str + 1, len))\r
+         break;\r
+       if(!technology)\r
+       {\r
+        create(technology,Technology);\r
+        string(technology->filename, len + 1);\r
+        strncpy(technology->filename, found_tech_str + 1, len);\r
+        technology->filename[len] = 0;\r
+        push(technology, technologies);\r
+       }\r
+       if(found_ruian_end)\r
+       {\r
+        len = found_ruian_end - found_at - 1;\r
+        string(ruian_id_str, len + 1);\r
+        strncpy(ruian_id_str, found_at + 1, len);\r
+        ruian_id_str[len] = 0;\r
+       }\r
+      }\r
+     }\r
+#endif\r
      parse_and_append_ip(str, ips);\r
      if(lastIP6range)\r
      {\r
      parse_and_append_ip(str, ips);\r
      if(lastIP6range)\r
      {\r
@@ -331,20 +375,32 @@ void parse_hosts(char *hosts)
       }\r
      }\r
 \r
       }\r
      }\r
 \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
+     if(ip->keyword->allowed_avgmtu)\r
      {\r
      {\r
-      ip->pps_limit = ip->max/pktratio;\r
-      if(ip->pps_limit > 10000) /* this limit seems to be hardcoded in iptables */\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
       {\r
-       ip->pps_limit = 0; /* do not apply packet limits */\r
+       ip->pps_limit = ip->max/pktratio;\r
+       if(ip->pps_limit > 10000) /* this limit seems to be hardcoded in iptables */\r
+       {\r
+        ip->pps_limit = 0; /* do not apply packet limits */\r
+       }\r
       }\r
      }\r
 \r
      ip->mark = FIRSTIPCLASS+1+class_count++;     \r
      update_network(ip->addr, ip);\r
 \r
       }\r
      }\r
 \r
      ip->mark = FIRSTIPCLASS+1+class_count++;     \r
      update_network(ip->addr, ip);\r
 \r
+#ifdef MONITORINGTRHU_CTU\r
+     if(technology)\r
+     {\r
+      ip->technology_str = technology->filename;\r
+      ip->ruian_id_str = ruian_id_str;\r
+      /* debug printf("[%s,%d,%s,%d]\n", ip->technology_str,ip->lmsid, ip->ruian_id_str, ip->max); */\r
+     }\r
+#endif\r
+\r
      if_exists(group,groups,(group->min == ip->min)) \r
      { \r
       group->count++;      \r
      if_exists(group,groups,(group->min == ip->min)) \r
      { \r
       group->count++;      \r
@@ -367,7 +423,7 @@ void parse_hosts(char *hosts)
       group->desired = ip->min;   \r
       insert(group, groups, desc_order_by,min);\r
      }\r
       group->desired = ip->min;   \r
       insert(group, groups, desc_order_by,min);\r
      }\r
-    }//endif keyword-\r
+    }//endif keyword-   \r
    }//endif netmask\r
   }//endif sharing-\r
  }\r
    }//endif netmask\r
   }//endif sharing-\r
  }\r
@@ -380,4 +436,4 @@ void parse_hosts(char *hosts)
 // TheIP("0.0.0.0", TRUE);\r
 // ip->name = "TOTAL";\r
 // ip->mask = 0;\r
 // TheIP("0.0.0.0", TRUE);\r
 // ip->name = "TOTAL";\r
 // ip->mask = 0;\r
-}\r
+}
\ No newline at end of file
This page took 0.167294 seconds and 4 git commands to generate.