IPv6 support: step 1. prometheus.conf + hosts parsing
authorxchaos <xchaos@251d49ef-1d17-4917-a970-b30cf55b089b>
Wed, 16 Jan 2013 00:44:34 +0000 (00:44 +0000)
committerxchaos <xchaos@251d49ef-1d17-4917-a970-b30cf55b089b>
Wed, 16 Jan 2013 00:44:34 +0000 (00:44 +0000)
git-svn-id: https://dev.arachne.cz/repos/prometheus/trunk@210 251d49ef-1d17-4917-a970-b30cf55b089b

htmlandlogs.c
parsehosts.c
prometheus.c

index 98af96c4a3fb22b34208d9e0bd8b5c3c9450beb8..8bcfe71f2e36832e0633eae6ac79e895ab543a02 100644 (file)
@@ -191,11 +191,16 @@ void write_htmlandlogs(char *html, char *d, int total, int just_preview)
    {\r
      fprintf(f,"<span id=\"sharing_%d\" style=\"display:none\">",i);\r
      popup_button=0;\r
-     for_each(sharedip, ips) if(eq(ip->name, sharedip->sharing))\r
+     for_each(sharedip, ips) if(eq(ip->name, sharedip->sharing) && !strchr(sharedip->addr,':')) /* IPv4 only */\r
      {\r
       fprintf(f,"<br /><a class=\"blue\" target=\"_blank\" href=\"%s%s.log\">%s</a>\n", log_url, sharedip->name, sharedip->name);\r
       popup_button++;\r
      }\r
+     for_each(sharedip, ips) if(eq(ip->name, sharedip->sharing) && !strchr(sharedip->addr,'.')) /* IPv6 only */\r
+     {\r
+      fprintf(f,"<br /><a class=\"blue\" target=\"_blank\" href=\"%s%s.log\">%s</a>\n", log_url, sharedip->name, sharedip->addr);\r
+      popup_button++;\r
+     }\r
      fputs("</span>\n",f);\r
      if(popup_button)\r
      {\r
@@ -229,7 +234,11 @@ void write_htmlandlogs(char *html, char *d, int total, int just_preview)
    if(use_jquery_popups)\r
    {\r
      fprintf(f,"<span id=\"download_%d\" style=\"display:none\">",i);\r
-     for_each(sharedip, ips) if(eq(ip->name, sharedip->sharing))\r
+     for_each(sharedip, ips) if(eq(ip->name, sharedip->sharing) && !strchr(sharedip->addr,':')) /* IPv4 only */\r
+     {\r
+      fprintf(f,"<br />%Lu", sharedip->direct);\r
+     }\r
+     for_each(sharedip, ips) if(eq(ip->name, sharedip->sharing) && !strchr(sharedip->addr,'.')) /* IPv6 only */\r
      {\r
       fprintf(f,"<br />%Lu", sharedip->direct);\r
      }\r
@@ -247,7 +256,11 @@ void write_htmlandlogs(char *html, char *d, int total, int just_preview)
    if(use_jquery_popups)\r
    {\r
      fprintf(f,"<span id=\"upload_%d\" style=\"display:none\">",i);\r
-     for_each(sharedip,ips) if(eq(ip->name, sharedip->sharing))\r
+     for_each(sharedip,ips) if(eq(ip->name, sharedip->sharing) && !strchr(sharedip->addr,':')) /* IPv4 only */\r
+     {\r
+      fprintf(f,"<br />%Lu", sharedip->upload);\r
+     }\r
+     for_each(sharedip,ips) if(eq(ip->name, sharedip->sharing) && !strchr(sharedip->addr,'.')) /* IPv6 only */\r
      {\r
       fprintf(f,"<br />%Lu", sharedip->upload);\r
      }\r
index d17c61917c32ad0235da1f3b036b768e3b56e27b..528f376ce38fa5333bb6305d3d15c5db47021451 100644 (file)
@@ -15,6 +15,7 @@ extern int ip_count;
 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
 void TheIP(char *ipaddr)\r
@@ -44,7 +45,22 @@ void TheIP(char *ipaddr)
 /* == This function strips extra characters after IPv4 address and stores it = */\r
 void parse_ip(char *str)\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
@@ -77,6 +93,23 @@ void parse_ip(char *str)
  }\r
  *ptr=0;\r
 \r
+ if(ip6range)\r
+ {\r
+  concatenate(ip6prefix,ip6range,ptr);\r
+  concatenate(ptr,"/64",ip6range);\r
+  if_exists(ip, ips, eq(ip->addr,ip6range));\r
+  else\r
+  {\r
+   TheIP(ip6range);\r
+  }\r
+  ip->name = ptr;\r
+  ip->sharing = ipname;\r
+  if(lmsid)\r
+  {\r
+   ip->lmsid = atoi(lmsid);\r
+  }\r
+ }\r
+\r
  if_exists(ip, ips, eq(ip->addr,ipaddr));\r
  else\r
  {\r
index b4de143676ff19ec7a58c47c800ec895de2951ef..70bea1f2355559c9dca504dde27523d95bc36558 100644 (file)
@@ -7,7 +7,7 @@
 /* Credit: CZFree.Net,Martin Devera,Netdave,Aquarius,Gandalf  */\r
 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */\r
 \r
-/* Modified by: xChaos, 20130114\r
+/* Modified by: xChaos, 20130116\r
                  ludva, 20080415\r
  \r
    Prometheus QoS is free software; you can redistribute it and/or\r
@@ -29,7 +29,7 @@
 #include "cll1-0.6.2.h"\r
 #include "ipstruct.h"\r
 \r
-const char *version = "0.8.3-g";\r
+const char *version = "0.8.3-h";\r
 \r
 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */\r
 /* Versions: 0.8.3 is development release, 0.8.4 will be "stable"  */\r
@@ -59,6 +59,7 @@ const char               *ls = "/bin/ls"; /* this is not user configurable :-) *
 char          *config = "/etc/prometheus/prometheus.conf"; /* main configuration file */\r
 char           *hosts = "/etc/prometheus/hosts"; /* per-IP bandwidth definition file */\r
 char    *iptablesfile = "/var/spool/prometheus.iptables"; /* temporary file for iptables-restore*/\r
+char   *ip6tablesfile = "/var/spool/prometheus.ip6tables"; /* temporary file for ip6tables-restore*/\r
 char          *credit = "/var/lib/misc/prometheus.credit"; /* credit log file */\r
 char        *classmap = "/var/lib/misc/prometheus.classes"; /* credit log file */\r
 char            *html = "/var/www/traffic.html"; /* hall of fame - html version */\r
@@ -90,6 +91,7 @@ int       hall_of_fame = TRUE; /* enable hall of fame */
 char              *lan = "eth0"; /* LAN interface */\r
 char       *lan_medium = "100Mbit"; /* 10Mbit/100Mbit ethernet */\r
 char              *wan = "eth1"; /* WAN/ISP interface */\r
+char        *ip6prefix = NULL; /* Prefix for global /48 IPv6 subnet */\r
 char       *wan_medium = "100Mbit"; /* 10Mbit/100Mbit ethernet */\r
 char         *qos_leaf = "sfq perturb 5"; /* leaf discipline */\r
 char    *qos_free_zone = NULL; /* QoS free zone */\r
@@ -262,15 +264,17 @@ void get_config(char *config_filename)
 \r
   option("tc",tc);\r
   option("iptables",iptables);\r
-  option("iptables-save",iptablessave); /* new */\r
-  option("iptables-restore",iptablesrestore); /* new */\r
+  option("iptables-save",iptablessave);\r
+  option("iptables-restore",iptablesrestore);\r
   option("ip6tables",ip6tables);\r
-  option("ip6tables-save",ip6tablessave); /* new */\r
-  option("ip6tables-restore",ip6tablesrestore); /* new */\r
-  option("iptables-in-filename",iptablesfile); /* new */\r
+  option("ip6tables-save",ip6tablessave);\r
+  option("ip6tables-restore",ip6tablesrestore);\r
+  option("iptables-in-filename",iptablesfile);\r
+  option("ip6tables-in-filename",ip6tablesfile);\r
   option("hosts",hosts);\r
   option("lan-interface",lan);\r
   option("wan-interface",wan);\r
+  option("ip6-prefix",ip6prefix);\r
   option("lan-medium",lan_medium);\r
   option("wan-medium",wan_medium);\r
   lloption("wan-download",line);\r
@@ -558,17 +562,17 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
   puts("Initializing iptables and tc classes ...");\r
   /*-----------------------------------------------------------------*/\r
   \r
-  iptables_file=fopen(iptablesfile,"w");\r
+  iptables_file = fopen(iptablesfile, "w");\r
   if(iptables_file == NULL)\r
   {\r
-    puts("Cannot open iptablesfile!");\r
+    perror(iptablesfile);\r
     exit(-1);\r
   }\r
   \r
-  log_file=fopen(cmdlog,"w");\r
+  log_file = fopen(cmdlog, "w");\r
   if(log_file == NULL) \r
   {\r
-    puts("Cannot open logfile!");\r
+    perror(cmdlog);\r
     exit(-1);\r
   }\r
   \r
@@ -612,7 +616,7 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
    save_line(str);\r
   }\r
   \r
-  if(ip_count>idxtable_treshold1 && !just_flush)\r
+  if(ip_count > idxtable_treshold1 && !just_flush)\r
   {\r
    int idxcount=0, bitmask=32-idxtable_bitmask1; /* default net mask: 255.255.255.240 */\r
    char *subnet, *buf;\r
@@ -623,7 +627,7 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
    save_line(":post_common - [0:0]");\r
    save_line(":forw_common - [0:0]");\r
 \r
-   for_each(ip,ips) if(ip->addr && *(ip->addr) && !eq(ip->addr,"0.0.0.0/0"))\r
+   for_each(ip,ips) if(ip->addr && *(ip->addr) && !eq(ip->addr,"0.0.0.0/0") && !strchr(ip->addr,':')) /* only IPv4 */\r
    {\r
     buf=index_id(ip->addr,bitmask);\r
     if_exists(idx,idxs,eq(idx->id,buf))\r
@@ -644,14 +648,14 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
    }\r
 \r
    /* brutal perfomance optimalization */\r
-   while(idxcount>idxtable_treshold2 && bitmask>2*idxtable_bitmask2)\r
+   while(idxcount > idxtable_treshold2 && bitmask > 2*idxtable_bitmask2)\r
    {\r
-    bitmask-=idxtable_bitmask2;\r
-    idxcount=0;\r
+    bitmask -= idxtable_bitmask2;\r
+    idxcount = 0;\r
 \r
     for_each(idx,idxs) if(idx->parent == NULL)\r
     {\r
-     buf=index_id(idx->addr,bitmask);\r
+     buf = index_id(idx->addr,bitmask);\r
      if_exists(metaindex,idxs,eq(metaindex->id,buf))\r
      {\r
       metaindex->children++;\r
@@ -671,7 +675,7 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
     }\r
    }\r
 \r
-   /* this should slightly optimize throughout ... */\r
+   /* this should slightly optimize throughput ... */\r
    sort(idx,idxs,desc_order_by,children);\r
    sort(idx,idxs,order_by,bitmask);\r
 \r
@@ -960,7 +964,7 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
  puts("Generating iptables and tc classes ... ");\r
  /*-----------------------------------------------------------------*/\r
 \r
- for_each(ip, ips) if(ip->mark > 0)\r
+ for_each(ip, ips) if(ip->mark > 0 && !strchr(ip->addr,':')) /* works only for IPv4 so far */\r
  {\r
   if(idxs)\r
   {\r
This page took 0.22918 seconds and 4 git commands to generate.