From f64d54310ae39276c552b80183ae2320789bb4be Mon Sep 17 00:00:00 2001 From: xchaos Date: Wed, 16 Jan 2013 00:44:34 +0000 Subject: [PATCH] IPv6 support: step 1. prometheus.conf + hosts parsing git-svn-id: https://dev.arachne.cz/repos/prometheus/trunk@210 251d49ef-1d17-4917-a970-b30cf55b089b --- htmlandlogs.c | 19 ++++++++++++++++--- parsehosts.c | 35 ++++++++++++++++++++++++++++++++++- prometheus.c | 42 +++++++++++++++++++++++------------------- 3 files changed, 73 insertions(+), 23 deletions(-) diff --git a/htmlandlogs.c b/htmlandlogs.c index 98af96c..8bcfe71 100644 --- a/htmlandlogs.c +++ b/htmlandlogs.c @@ -191,11 +191,16 @@ void write_htmlandlogs(char *html, char *d, int total, int just_preview) { fprintf(f,"",i); popup_button=0; - for_each(sharedip, ips) if(eq(ip->name, sharedip->sharing)) + for_each(sharedip, ips) if(eq(ip->name, sharedip->sharing) && !strchr(sharedip->addr,':')) /* IPv4 only */ { fprintf(f,"
%s\n", log_url, sharedip->name, sharedip->name); popup_button++; } + for_each(sharedip, ips) if(eq(ip->name, sharedip->sharing) && !strchr(sharedip->addr,'.')) /* IPv6 only */ + { + fprintf(f,"
%s\n", log_url, sharedip->name, sharedip->addr); + popup_button++; + } fputs("
\n",f); if(popup_button) { @@ -229,7 +234,11 @@ void write_htmlandlogs(char *html, char *d, int total, int just_preview) if(use_jquery_popups) { fprintf(f,"",i); - for_each(sharedip, ips) if(eq(ip->name, sharedip->sharing)) + for_each(sharedip, ips) if(eq(ip->name, sharedip->sharing) && !strchr(sharedip->addr,':')) /* IPv4 only */ + { + fprintf(f,"
%Lu", sharedip->direct); + } + for_each(sharedip, ips) if(eq(ip->name, sharedip->sharing) && !strchr(sharedip->addr,'.')) /* IPv6 only */ { fprintf(f,"
%Lu", sharedip->direct); } @@ -247,7 +256,11 @@ void write_htmlandlogs(char *html, char *d, int total, int just_preview) if(use_jquery_popups) { fprintf(f,"",i); - for_each(sharedip,ips) if(eq(ip->name, sharedip->sharing)) + for_each(sharedip,ips) if(eq(ip->name, sharedip->sharing) && !strchr(sharedip->addr,':')) /* IPv4 only */ + { + fprintf(f,"
%Lu", sharedip->upload); + } + for_each(sharedip,ips) if(eq(ip->name, sharedip->sharing) && !strchr(sharedip->addr,'.')) /* IPv6 only */ { fprintf(f,"
%Lu", sharedip->upload); } diff --git a/parsehosts.c b/parsehosts.c index d17c619..528f376 100644 --- a/parsehosts.c +++ b/parsehosts.c @@ -15,6 +15,7 @@ extern int ip_count; extern int found_lmsid; extern int free_min; extern const int highest_priority; +extern char *ip6prefix; /* This must be object oriented! This looks almost like constructor ;-) */ void TheIP(char *ipaddr) @@ -44,7 +45,22 @@ void TheIP(char *ipaddr) /* == This function strips extra characters after IPv4 address and stores it = */ void parse_ip(char *str) { - char *ptr, *ipaddr = NULL, *ipname = NULL, *lmsid = NULL; + char *ptr, *ipaddr, *ip6range = NULL, *ipname = NULL, *lmsid = NULL; + + if(ip6prefix) /* Try this only if IPv6 subsystem is active...*/ + { + ptr = strstr(str, "::"); + if(ptr && ptr-str > 4) + { + ptr -= 4; + duplicate(ptr,ip6range); + ptr = strstr(ip6range, "::"); + if(ptr) + { + *(ptr+2) = 0; + } + } + } ptr = strchr(str, '{'); if(ptr) @@ -77,6 +93,23 @@ void parse_ip(char *str) } *ptr=0; + if(ip6range) + { + concatenate(ip6prefix,ip6range,ptr); + concatenate(ptr,"/64",ip6range); + if_exists(ip, ips, eq(ip->addr,ip6range)); + else + { + TheIP(ip6range); + } + ip->name = ptr; + ip->sharing = ipname; + if(lmsid) + { + ip->lmsid = atoi(lmsid); + } + } + if_exists(ip, ips, eq(ip->addr,ipaddr)); else { diff --git a/prometheus.c b/prometheus.c index b4de143..70bea1f 100644 --- a/prometheus.c +++ b/prometheus.c @@ -7,7 +7,7 @@ /* Credit: CZFree.Net,Martin Devera,Netdave,Aquarius,Gandalf */ /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ -/* Modified by: xChaos, 20130114 +/* Modified by: xChaos, 20130116 ludva, 20080415 Prometheus QoS is free software; you can redistribute it and/or @@ -29,7 +29,7 @@ #include "cll1-0.6.2.h" #include "ipstruct.h" -const char *version = "0.8.3-g"; +const char *version = "0.8.3-h"; /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ /* Versions: 0.8.3 is development release, 0.8.4 will be "stable" */ @@ -59,6 +59,7 @@ const char *ls = "/bin/ls"; /* this is not user configurable :-) * char *config = "/etc/prometheus/prometheus.conf"; /* main configuration file */ char *hosts = "/etc/prometheus/hosts"; /* per-IP bandwidth definition file */ char *iptablesfile = "/var/spool/prometheus.iptables"; /* temporary file for iptables-restore*/ +char *ip6tablesfile = "/var/spool/prometheus.ip6tables"; /* temporary file for ip6tables-restore*/ char *credit = "/var/lib/misc/prometheus.credit"; /* credit log file */ char *classmap = "/var/lib/misc/prometheus.classes"; /* credit log file */ char *html = "/var/www/traffic.html"; /* hall of fame - html version */ @@ -90,6 +91,7 @@ int hall_of_fame = TRUE; /* enable hall of fame */ char *lan = "eth0"; /* LAN interface */ char *lan_medium = "100Mbit"; /* 10Mbit/100Mbit ethernet */ char *wan = "eth1"; /* WAN/ISP interface */ +char *ip6prefix = NULL; /* Prefix for global /48 IPv6 subnet */ char *wan_medium = "100Mbit"; /* 10Mbit/100Mbit ethernet */ char *qos_leaf = "sfq perturb 5"; /* leaf discipline */ char *qos_free_zone = NULL; /* QoS free zone */ @@ -262,15 +264,17 @@ void get_config(char *config_filename) option("tc",tc); option("iptables",iptables); - option("iptables-save",iptablessave); /* new */ - option("iptables-restore",iptablesrestore); /* new */ + option("iptables-save",iptablessave); + option("iptables-restore",iptablesrestore); option("ip6tables",ip6tables); - option("ip6tables-save",ip6tablessave); /* new */ - option("ip6tables-restore",ip6tablesrestore); /* new */ - option("iptables-in-filename",iptablesfile); /* new */ + option("ip6tables-save",ip6tablessave); + option("ip6tables-restore",ip6tablesrestore); + option("iptables-in-filename",iptablesfile); + option("ip6tables-in-filename",ip6tablesfile); option("hosts",hosts); option("lan-interface",lan); option("wan-interface",wan); + option("ip6-prefix",ip6prefix); option("lan-medium",lan_medium); option("wan-medium",wan_medium); lloption("wan-download",line); @@ -558,17 +562,17 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version); puts("Initializing iptables and tc classes ..."); /*-----------------------------------------------------------------*/ - iptables_file=fopen(iptablesfile,"w"); + iptables_file = fopen(iptablesfile, "w"); if(iptables_file == NULL) { - puts("Cannot open iptablesfile!"); + perror(iptablesfile); exit(-1); } - log_file=fopen(cmdlog,"w"); + log_file = fopen(cmdlog, "w"); if(log_file == NULL) { - puts("Cannot open logfile!"); + perror(cmdlog); exit(-1); } @@ -612,7 +616,7 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version); save_line(str); } - if(ip_count>idxtable_treshold1 && !just_flush) + if(ip_count > idxtable_treshold1 && !just_flush) { int idxcount=0, bitmask=32-idxtable_bitmask1; /* default net mask: 255.255.255.240 */ char *subnet, *buf; @@ -623,7 +627,7 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version); save_line(":post_common - [0:0]"); save_line(":forw_common - [0:0]"); - for_each(ip,ips) if(ip->addr && *(ip->addr) && !eq(ip->addr,"0.0.0.0/0")) + for_each(ip,ips) if(ip->addr && *(ip->addr) && !eq(ip->addr,"0.0.0.0/0") && !strchr(ip->addr,':')) /* only IPv4 */ { buf=index_id(ip->addr,bitmask); if_exists(idx,idxs,eq(idx->id,buf)) @@ -644,14 +648,14 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version); } /* brutal perfomance optimalization */ - while(idxcount>idxtable_treshold2 && bitmask>2*idxtable_bitmask2) + while(idxcount > idxtable_treshold2 && bitmask > 2*idxtable_bitmask2) { - bitmask-=idxtable_bitmask2; - idxcount=0; + bitmask -= idxtable_bitmask2; + idxcount = 0; for_each(idx,idxs) if(idx->parent == NULL) { - buf=index_id(idx->addr,bitmask); + buf = index_id(idx->addr,bitmask); if_exists(metaindex,idxs,eq(metaindex->id,buf)) { metaindex->children++; @@ -671,7 +675,7 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version); } } - /* this should slightly optimize throughout ... */ + /* this should slightly optimize throughput ... */ sort(idx,idxs,desc_order_by,children); sort(idx,idxs,order_by,bitmask); @@ -960,7 +964,7 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version); puts("Generating iptables and tc classes ... "); /*-----------------------------------------------------------------*/ - for_each(ip, ips) if(ip->mark > 0) + for_each(ip, ips) if(ip->mark > 0 && !strchr(ip->addr,':')) /* works only for IPv4 so far */ { if(idxs) { -- 2.30.2