version 1.0.0.-a - significat iptables parsing speed improvement
[svn/Prometheus-QoS/.git] / parsehosts.c
index 1e0c65ceceaf5a6517f94074367b88d1e93d6b36..146e897b8fde295714b575f7a30166ff98038649 100644 (file)
@@ -25,27 +25,30 @@ void update_network(char *look_for, struct IP* ip);
 void TheIP(char *ipaddr, int is_network)\r
 {\r
  create(ip,IP);\r
- ip->name        = "";\r
- ip->addr        = ipaddr;\r
- ip->sharing     = NULL;\r
- ip->prio        = highest_priority+1;\r
- ip->lmsid       = -1;\r
- ip->fixedprio   = \\r
- ip->mark        = \\r
- ip->min         = \\r
- ip->max         = \\r
- ip->desired     = \\r
- ip->credit      = \\r
- ip->upload      = \\r
- ip->proxy       = \\r
- 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
- ip->mask        = ((ip->v6)?64:32);\r
+ ip->name         = "";\r
+ ip->addr         = ipaddr;\r
+ ip->sharing      = NULL;\r
+ ip->prio         = highest_priority+1;\r
+ ip->lmsid        = -1;\r
+ ip->fixedprio    = \\r
+ ip->aggregated   = \\r
+ ip->mark         = \\r
+ ip->min          = \\r
+ ip->max          = \\r
+ ip->desired      = \\r
+ ip->credit       = \\r
+ ip->upload       = \\r
+ ip->proxy        = \\r
+ ip->direct       = \\r
+ ip->traffic      = \\r
+ ip->traffic_down = \\r
+ ip->traffic_up   = \\r
+ ip->pktsup       = \\r
+ ip->pps_limit    = \\r
+ ip->pktsdown     = 0;\r
+ ip->keyword      = keywords;\r
+ ip->v6           = (strchr(ip->addr,':')!=NULL);\r
+ ip->mask         = ((ip->v6)?64:32);\r
  if(is_network)\r
  {\r
   push(ip, networks);\r
@@ -54,9 +57,17 @@ void TheIP(char *ipaddr, int is_network)
  {\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
+#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
@@ -248,7 +259,7 @@ void parse_hosts(char *hosts)
   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
@@ -277,9 +288,45 @@ void parse_hosts(char *hosts)
    }\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
+#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(!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
@@ -342,6 +389,15 @@ void parse_hosts(char *hosts)
      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
@@ -364,7 +420,7 @@ void parse_hosts(char *hosts)
       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
@@ -377,4 +433,4 @@ void parse_hosts(char *hosts)
 // 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.117229 seconds and 4 git commands to generate.