IPv6 support: step 1. prometheus.conf + hosts parsing
[svn/Prometheus-QoS/.git] / prometheus.c
index b4de143..70bea1f 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.157072 seconds and 4 git commands to generate.