debug version
[svn/Prometheus-QoS/.git] / parsehosts.c
index ecb956a3a53edbf2bd1c3d2d7586d4324d9bc246..8c9eca159c6d1b3304f8e45342c1c04d2eeaced9 100644 (file)
@@ -11,7 +11,9 @@ extern struct IP *ips, *ip, *sharedip, *networks;
 extern struct Group *groups, *group;\r
 extern struct Keyword *keyword, *defaultkeyword, *keywords;\r
 extern struct Macro *macro, *macros;\r
+extern struct Textfile *previous_classmap, *textline;\r
 extern int class_count;\r
+extern int mix_new_hosts;\r
 extern int ip_count;\r
 extern int found_lmsid;\r
 extern int free_min;\r
@@ -25,27 +27,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
@@ -57,25 +62,37 @@ void TheIP(char *ipaddr, int is_network)
  ip_count++;\r
 }\r
 \r
-struct IP *lastIP6;\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, *ip6range = NULL, *ipname = NULL, *lmsid = NULL;\r
+ char *ptr, *ipaddr, *nextip6, *ip6buf; \r
+ char *ip6uplink = NULL, *ip6range = NULL, *ipname = NULL, *lmsid = NULL;\r
 \r
  if(ip6prefix) /* Try this only if IPv6 subsystem is active... */\r
  {\r
   ptr = strstr(str, "::");\r
-  if(ptr && ptr-str > 4)\r
+  while(ptr && ptr-str > 4)\r
   {\r
-   ptr -= 4;   \r
-   duplicate(ptr, ip6range);\r
-   ptr = strstr(ip6range, "::");\r
+   nextip6 = strstr(ptr + 2, "::");\r
+   ptr -= 4;\r
+   duplicate(ptr, ip6buf);\r
+   ptr = strstr(ip6buf, "::");\r
    if(ptr)\r
    {\r
-    *(ptr+2) = 0;\r
+    if(*(ptr+2) == '+')\r
+    {\r
+     *(ptr+3) = 0; /* ends with ::+ */\r
+     ip6uplink = ip6buf;\r
+    }\r
+    else\r
+    {\r
+     *(ptr+2) = 0; /* ends with :: */\r
+     ip6range = ip6buf;\r
+    }    \r
    }\r
+   ptr = nextip6;\r
   }\r
  }\r
 \r
@@ -103,7 +120,7 @@ void parse_and_append_ip(char *str, struct IP *listhead)
  {\r
   ptr++;\r
  }\r
- ipname=ptr; \r
+ ipname = ptr; \r
  while(*ptr and *ptr!=' ' and *ptr!=9)\r
  {\r
   ptr++;\r
@@ -114,7 +131,7 @@ void parse_and_append_ip(char *str, struct IP *listhead)
  {\r
   concatenate(ip6prefix,ip6range,ptr);\r
   ip6range=ptr;\r
-  if_exists(ip, ips, eq(ip->addr,ip6range));\r
+  if_exists(ip, ips, eq(ip->addr,ip6range)); /* check - allocated range must be unique */\r
   else\r
   {\r
    TheIP(ip6range, FALSE);\r
@@ -125,11 +142,30 @@ void parse_and_append_ip(char *str, struct IP *listhead)
   {\r
    ip->lmsid = atoi(lmsid);\r
   }\r
-  lastIP6 = ip;\r
+  lastIP6range = ip;\r
  }\r
  else\r
  {\r
-  lastIP6 = NULL;\r
+  lastIP6range = NULL;\r
+ }\r
+\r
+ /* it is ugly to copy+paste and search+replace, but... */\r
+ if(ip6uplink)\r
+ {\r
+  concatenate(ip6prefix,ip6uplink,ptr);\r
+  ip6uplink=ptr;\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
+  {\r
+   ip->lmsid = atoi(lmsid);\r
+  }\r
+  lastIP6uplink = ip;\r
+ }\r
+ else\r
+ {\r
+  lastIP6uplink = NULL;\r
  }\r
 \r
  if_exists(ip, listhead, eq(ip->addr,ipaddr));\r
@@ -198,10 +234,15 @@ void parse_hosts(char *hosts)
    parse_and_append_ip(str, ips);\r
    ip->sharing = substring;\r
    ip->keyword = defaultkeyword; /* settings for default keyword */\r
-   if(lastIP6)\r
+   if(lastIP6range)\r
+   {\r
+    lastIP6range->sharing = substring;\r
+    lastIP6range = NULL;\r
+   }\r
+   if(lastIP6uplink)\r
    {\r
-    lastIP6->sharing = substring;\r
-    lastIP6 = NULL;\r
+    lastIP6uplink->sharing = substring;\r
+    lastIP6uplink = NULL;\r
    }\r
    while(*substring and *substring != '\n')\r
    {\r
@@ -212,7 +253,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 ranges */\r
+   if(substring and not strstr(str, "#255.255.255.255")) /* do not ping /32 uplinks */\r
    {\r
     /* netmask detected - save network*/\r
     unsigned bit;\r
@@ -245,10 +286,15 @@ void parse_hosts(char *hosts)
     if_exists(keyword,keywords,(substring=strstr(str,keyword->key)))\r
     {\r
      parse_and_append_ip(str, ips);\r
-     if(lastIP6)\r
+     if(lastIP6range)\r
      {\r
-      lastIP6->sharing = ip->name;\r
-      lastIP6 = NULL;\r
+      lastIP6range->sharing = ip->name;\r
+      lastIP6range = NULL;\r
+     }\r
+     if(lastIP6uplink)\r
+     {\r
+      lastIP6uplink->sharing = ip->name;\r
+      lastIP6uplink = NULL;\r
      }\r
      ip->keyword = keyword;\r
      keyword->ip_count++;\r
@@ -298,7 +344,23 @@ void parse_hosts(char *hosts)
       }\r
      }\r
 \r
-     ip->mark = FIRSTIPCLASS+1+class_count++;     \r
+     if(mix_new_hosts)\r
+      for_each(textline, previous_classmap)\r
+      {\r
+       ptr = strchr(textline->str, ' ');\r
+       if(ptr)\r
+       {\r
+        if(!strncmp(ip->addr, textline->str, ptr-textline->str))\r
+        {\r
+         ip->mark = atoi(ptr+1);\r
+         printf("Match class: %s %d\n", ip->addr, ip->mark);\r
+        }\r
+       }      \r
+      }\r
+     \r
+     if(!mix_new_hosts || !ip->mark)\r
+      ip->mark = FIRSTIPCLASS+1+class_count++;\r
+          \r
      update_network(ip->addr, ip);\r
 \r
      if_exists(group,groups,(group->min == ip->min)) \r
This page took 0.249792 seconds and 4 git commands to generate.