should be completely fixed now
[svn/Prometheus-QoS/.git] / parsehosts.c
index db3bf2eb52f2003c647518487023cceb98d9d118..1e8dbe6773502e9b18f580570257cba552fe20df 100644 (file)
@@ -15,13 +15,14 @@ extern int ip_count;
 extern int found_lmsid;\r
 extern int free_min;\r
 extern const int highest_priority;\r
 extern int found_lmsid;\r
 extern int free_min;\r
 extern const int highest_priority;\r
+extern char *ip6prefix;\r
 \r
 /* This must be object oriented! This looks almost like constructor ;-) */\r
 \r
 /* This must be object oriented! This looks almost like constructor ;-) */\r
-void TheIP(void)\r
+void TheIP(char *ipaddr)\r
 {\r
  create(ip,IP);\r
  ip->name        = "";\r
 {\r
  create(ip,IP);\r
  ip->name        = "";\r
- ip->addr        = "";\r
+ ip->addr        = ipaddr;\r
  ip->sharing     = NULL;\r
  ip->prio        = highest_priority+1;\r
  ip->lmsid       = -1;\r
  ip->sharing     = NULL;\r
  ip->prio        = highest_priority+1;\r
  ip->lmsid       = -1;\r
@@ -38,13 +39,32 @@ void TheIP(void)
  ip->pktsup      = \\r
  ip->pktsdown    = 0;\r
  ip->keyword     = keywords;\r
  ip->pktsup      = \\r
  ip->pktsdown    = 0;\r
  ip->keyword     = keywords;\r
+ ip->v6          = (strchr(ip->addr,':')!=NULL);\r
  push(ip,ips);\r
  push(ip,ips);\r
+ ip_count++;\r
 }\r
 \r
 }\r
 \r
+struct IP *lastIP6;\r
+\r
 /* == This function strips extra characters after IPv4 address and stores it = */\r
 /* == This function strips extra characters after IPv4 address and stores it = */\r
-void parse_ip(char *str)\r
+parse_ip(char *str)\r
 {\r
 {\r
- char *ptr, *ipaddr = NULL, *ipname = NULL, *lmsid = NULL;\r
+ char *ptr, *ipaddr, *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
+  {\r
+   ptr -= 4;   \r
+   duplicate(ptr, ip6range);\r
+   ptr = strstr(ip6range, "::");\r
+   if(ptr)\r
+   {\r
+    *(ptr+2) = 0;\r
+   }\r
+  }\r
+ }\r
 \r
  ptr = strchr(str, '{');\r
  if(ptr)\r
 \r
  ptr = strchr(str, '{');\r
  if(ptr)\r
@@ -77,12 +97,33 @@ void parse_ip(char *str)
  }\r
  *ptr=0;\r
 \r
  }\r
  *ptr=0;\r
 \r
+ if(ip6range)\r
+ {\r
+  concatenate(ip6prefix,ip6range,ptr);\r
+  ip6range=ptr;\r
+  if_exists(ip, ips, eq(ip->addr,ip6range));\r
+  else\r
+  {\r
+   TheIP(ip6range);\r
+  }\r
+  ip->name = ip6range;\r
+  ip->keyword = defaultkeyword; /* settings for default keyword */\r
+  if(lmsid)\r
+  {\r
+   ip->lmsid = atoi(lmsid);\r
+  }\r
+  lastIP6 = ip;\r
+ }\r
+ else\r
+ {\r
+  lastIP6 = NULL;\r
+ }\r
+\r
  if_exists(ip, ips, eq(ip->addr,ipaddr));\r
  else\r
  {\r
  if_exists(ip, ips, eq(ip->addr,ipaddr));\r
  else\r
  {\r
-  TheIP();\r
+  TheIP(ipaddr);\r
  }\r
  }\r
- ip->addr = ipaddr;\r
  ip->name = ipname;\r
  if(lmsid)\r
  {\r
  ip->name = ipname;\r
  if(lmsid)\r
  {\r
@@ -114,9 +155,13 @@ void parse_hosts(char *hosts)
   { \r
    substring += 8; /* "sharing-" */\r
    parse_ip(str);\r
   { \r
    substring += 8; /* "sharing-" */\r
    parse_ip(str);\r
-   ip_count++;\r
    ip->sharing = substring;\r
    ip->keyword = defaultkeyword; /* settings for default keyword */\r
    ip->sharing = substring;\r
    ip->keyword = defaultkeyword; /* settings for default keyword */\r
+   if(lastIP6)\r
+   {\r
+    lastIP6->sharing = substring;\r
+    lastIP6 = NULL;\r
+   }\r
    while(*substring and *substring != '\n')\r
    {\r
     substring++;\r
    while(*substring and *substring != '\n')\r
    {\r
     substring++;\r
@@ -130,7 +175,11 @@ void parse_hosts(char *hosts)
    if_exists(keyword,keywords,(substring=strstr(str,keyword->key)))\r
    {\r
     parse_ip(str);\r
    if_exists(keyword,keywords,(substring=strstr(str,keyword->key)))\r
    {\r
     parse_ip(str);\r
-    ip_count++;\r
+    if(lastIP6)\r
+    {\r
+     lastIP6->sharing = ip->name;\r
+     lastIP6 = NULL;\r
+    }\r
     ip->keyword = keyword;\r
     keyword->ip_count++;\r
     ip->prio = keyword->default_prio;\r
     ip->keyword = keyword;\r
     keyword->ip_count++;\r
     ip->prio = keyword->default_prio;\r
This page took 0.122965 seconds and 4 git commands to generate.