added IPv6 support for single /128 addresses of routers (based on IPv4 address)
authorxchaos <xchaos@251d49ef-1d17-4917-a970-b30cf55b089b>
Thu, 14 Aug 2014 17:52:50 +0000 (17:52 +0000)
committerxchaos <xchaos@251d49ef-1d17-4917-a970-b30cf55b089b>
Thu, 14 Aug 2014 17:52:50 +0000 (17:52 +0000)
git-svn-id: https://dev.arachne.cz/repos/prometheus/trunk@246 251d49ef-1d17-4917-a970-b30cf55b089b

cll1-0.6.2.h
htmlandlogs.c
ipstruct.h
parsehosts.c
prometheus.c

index d3456ce3d07ddc1b5c911210719d367da2f697b5..6edbd8353427d25e9d41196ace6dfcb75bd59a6d 100644 (file)
 #define option(STR,SETVAR) if(_){char *_K,*_V,*_O,*_Q; duplicate(_,_Q); _O=_Q; tr(_O,'\t',' '); prefix(_K,_O,' '); if(eq(STR,_K)) {skipspaces(_O); prefix(_V,_O,'#'); cutspaces(_V); SETVAR=_V; _=NULL;} else free(_Q);}
 #define ioption(STR,SETVAR) if(_){char *_K,*_V,*_O,*_Q; duplicate(_,_Q); _O=_Q; tr(_O,'\t',' '); prefix(_K,_O,' '); if(eq(STR,_K)) {skipspaces(_O); prefix(_V,_O,'#'); cutspaces(_V); SETVAR=atoi(_V); _=NULL;} free(_Q);}
 #define loption(STR,SETVAR) if(_){char *_K,*_V,*_O,*_Q; duplicate(_,_Q); _O=_Q; tr(_O,'\t',' '); prefix(_K,_O,' '); if(eq(STR,_K)) {skipspaces(_O); prefix(_V,_O,'#');  cutspaces(_V); SETVAR=atol(_V); _=NULL;} free(_Q);}
+#define foption(STR,SETVAR) if(_){char *_K,*_V,*_O,*_Q; duplicate(_,_Q); _O=_Q; tr(_O,'\t',' '); prefix(_K,_O,' '); if(eq(STR,_K)) {skipspaces(_O); prefix(_V,_O,'#');  cutspaces(_V); SETVAR=atof(_V); _=NULL;} free(_Q);}
 #define lloption(STR,SETVAR) if(_){char *_K,*_V,*_O,*_Q; duplicate(_,_Q); _O=_Q; tr(_O,'\t',' '); prefix(_K,_O,' '); if(eq(STR,_K)) {skipspaces(_O); prefix(_V,_O,'#');  cutspaces(_V); SETVAR=atoll(_V); _=NULL;} free(_Q);}
 
 /* Dynamic list advanced I/O, updated 2003-05-30 by xCh. */
index 39a4286abd51192fbcfda7e3542588be5d66627d..3820ae462297c5a5059e84c07fabd8c7e3632ff7 100644 (file)
@@ -232,8 +232,8 @@ $(\'#pktsup_\'+n).show();\
 \r
      for_each(sharedip, ips) if(eq(ip->name, sharedip->sharing) && sharedip->v6) /* IPv6 only */\r
      {\r
-      fprintf(f, "<br /><a class=\"blue\" target=\"_blank\" href=\"%s%s.log\">%s/64</a>\n", \r
-                 log_url, sharedip->addr, sharedip->addr);\r
+      fprintf(f, "<br /><a class=\"blue\" target=\"_blank\" href=\"%s%s.log\">%s/%d</a>\n", \r
+                 log_url, sharedip->addr, sharedip->addr, sharedip->mask);\r
       popup_button++;\r
      }\r
 \r
index 797fb7bb72bca3bcd2f0f64157c1ffc08d9f1c11..6f0e5694dc2aab8b15174b4c7ad8b59992964a45 100644 (file)
@@ -42,7 +42,7 @@ struct Keyword
 {\r
  char *key;\r
  \r
int asymetry_ratio;        /* ratio for ADSL-like upload */\r
float asymetry_ratio;      /* ratio for ADSL-like upload */\r
  int asymetry_fixed;        /* fixed treshold for ADSL-like upload */\r
  int data_limit;            /* hard shaping: apply magic_treshold if max*data_limit MB exceeded */\r
  int data_prio;             /* soft shaping (qos): reduce HTB prio if max*data_prio MB exceeded */\r
index ecb956a3a53edbf2bd1c3d2d7586d4324d9bc246..27d378e9a9fa81b8e8f4d0c4ddc054327ed438fe 100644 (file)
@@ -57,25 +57,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 +115,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
@@ -125,11 +137,34 @@ 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
+  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
+  if_exists(ip, ips, eq(ip->addr,ip6uplink));\r
+  else\r
+  {\r
+   TheIP(ip6uplink, FALSE);\r
+  }\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
-  lastIP6 = NULL;\r
+  lastIP6uplink = NULL;\r
  }\r
 \r
  if_exists(ip, listhead, eq(ip->addr,ipaddr));\r
@@ -198,10 +233,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 +252,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 +285,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
+      lastIP6range->sharing = ip->name;\r
+      lastIP6range = NULL;\r
+     }\r
+     if(lastIP6uplink)\r
      {\r
-      lastIP6->sharing = ip->name;\r
-      lastIP6 = NULL;\r
+      lastIP6uplink->sharing = ip->name;\r
+      lastIP6uplink = NULL;\r
      }\r
      ip->keyword = keyword;\r
      keyword->ip_count++;\r
index 49fa5e2396153c7aa73f6def8b201caff95a005a..03b75543d8964c125fc87c03b48995d74505b162 100644 (file)
@@ -258,7 +258,7 @@ void get_config(char *config_filename)
      {\r
       char *tmptr=_; /*  <---- l+1 ----> */\r
       _+=l+1;        /*  via-prometheus-asymetry-ratio, etc. */\r
-      ioption("asymetry-ratio", keyword->asymetry_ratio);\r
+      foption("asymetry-ratio", keyword->asymetry_ratio);\r
       ioption("asymetry-treshold", keyword->asymetry_fixed);\r
       ioption("magic-relative-limit", keyword->data_limit);\r
       ioption("magic-relative-prio", keyword->data_prio);\r
@@ -503,7 +503,7 @@ program
   \r
  printf("\n\\r
 Prometheus QoS - \"fair-per-IP\" Quality of Service setup utility.\n\\r
-Version %s - Copyright (C)2005-2013 Michael Polak, Arachne Labs\n\\r
+Version %s - Copyright (C)2005-2014 Michael Polak, Arachne Labs\n\\r
 iptables-restore & burst tunning & classify modification by Ludva\n\\r
 Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);\r
 \r
@@ -620,6 +620,23 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
    ip->mark = sharedip->mark; \r
    ip->lmsid = sharedip->lmsid;\r
    ip->pps_limit = sharedip->pps_limit; /* no other way to do this */\r
+\r
+   /* Ugly hack: append IPv4 addresses of sharedip to IPv6 uplinks */\r
+   ptr = strchr(ip->addr, '+');\r
+   if(ptr && ptr-ip->addr > 1 && !sharedip->v6)\r
+   {\r
+    *(--ptr) = 0;\r
+    concatenate(ip->addr, sharedip->addr, ptr);\r
+    ip->name = ip->addr = ptr;\r
+    ptr = strchr(ip->addr, '.');\r
+    while(ptr && *ptr)\r
+    {\r
+     *ptr = ':';\r
+     ptr = strchr(ptr, '.');\r
+    }\r
+    ip->mask += 64;\r
+   }\r
+\r
    break;\r
   }\r
   if(not sharedip)\r
@@ -1183,7 +1200,7 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
 \r
   /* -------------------------------------------------------- mark download */  \r
   sprintf(str, "-A %s -d %s/%d -o %s -j %s%d",\r
-               chain_postrouting, ip->addr, 32*(1+ip->v6),\r
+               chain_postrouting, ip->addr, ip->mask,\r
                lan, mark_iptables, ip->mark);\r
   iptables_save_line(str, ip->v6);\r
 \r
@@ -1192,40 +1209,40 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
   {\r
    sprintf(str, "-A %s -s %s -p tcp --sport %d -d %s/%d -o %s -j %s%d",\r
                 chain_postrouting, proxy_ip, proxy_port, ip->addr,\r
-                32*(1+ip->v6), lan, mark_iptables, ip->mark);\r
+                ip->mask, lan, mark_iptables, ip->mark);\r
    iptables_save_line(str, ip->v6);\r
   }\r
 */\r
   sprintf(str, "-A %s -d %s/%d -o %s %s-j ACCEPT",\r
-               chain_postrouting, ip->addr, 32*(1+ip->v6), lan, limit_pkts);\r
+               chain_postrouting, ip->addr, ip->mask, lan, limit_pkts);\r
   iptables_save_line(str, ip->v6);\r
 \r
   /* classify overlimit packets to separate overlimit class */\r
   sprintf(str, "-A %s -d %s/%d -o %s -j %s%d",\r
-               chain_postrouting, ip->addr, 32*(1+ip->v6),\r
+               chain_postrouting, ip->addr, ip->mask,\r
                lan, mark_iptables, OVERLIMIT_CLASS);\r
   iptables_save_line(str, ip->v6);\r
 \r
   sprintf(str, "-A %s -d %s/%d -o %s -j ACCEPT",\r
-               chain_postrouting, ip->addr, 32*(1+ip->v6), lan);\r
+               chain_postrouting, ip->addr, ip->mask, lan);\r
   iptables_save_line(str, ip->v6);\r
 \r
   /* -------------------------------------------------------- mark upload */\r
   sprintf(str, "-A %s -s %s/%d -o %s -j %s%d", \r
-               chain_forward, ip->addr, 32*(1+ip->v6), wan, mark_iptables, ip->mark);\r
+               chain_forward, ip->addr, ip->mask, wan, mark_iptables, ip->mark);\r
   iptables_save_line(str, ip->v6);\r
 \r
   sprintf(str, "-A %s -s %s/%d -o %s %s-j ACCEPT",\r
-               chain_forward, ip->addr, 32*(1+ip->v6), wan, limit_pkts);\r
+               chain_forward, ip->addr, ip->mask, wan, limit_pkts);\r
   iptables_save_line(str, ip->v6);\r
 \r
   /* classify overlimit packets to separate overlimit class */\r
   sprintf(str, "-A %s -s %s/%d -o %s -j %s%d", \r
-               chain_forward, ip->addr, 32*(1+ip->v6), wan, mark_iptables, OVERLIMIT_CLASS);\r
+               chain_forward, ip->addr, ip->mask, wan, mark_iptables, OVERLIMIT_CLASS);\r
   iptables_save_line(str, ip->v6);\r
 \r
   sprintf(str, "-A %s -s %s/%d -o %s -j ACCEPT",\r
-               chain_forward, ip->addr, 32*(1+ip->v6), wan);\r
+               chain_forward, ip->addr, ip->mask, wan);\r
   iptables_save_line(str, ip->v6);\r
 \r
   if(ip->min)\r
This page took 0.292434 seconds and 4 git commands to generate.