X-Git-Url: http://git.harvie.cz/?p=svn%2FPrometheus-QoS%2F.git;a=blobdiff_plain;f=prometheus.c;h=8aacb50830c759fecc469588393d4d4cf98b0761;hp=5a9492e3e7592cc4cf8fac51f5a98e674039016e;hb=HEAD;hpb=dba7666bdacf8846560e5414b6c9535434e98f8b diff --git a/prometheus.c b/prometheus.c index 5a9492e..8aacb50 100644 --- a/prometheus.c +++ b/prometheus.c @@ -2,12 +2,12 @@ /* Prometheus QoS - you can "steal fire" from your ISP */ /* "fair-per-IP" quality of service (QoS) utility */ /* requires Linux 2.4.x or 2.6.x with HTB support */ -/* Copyright(C) 2005-2019 Michael Polak, Arachne Aerospace */ +/* Copyright(C) 2005-2020 Michael Polak, Arachne Aerospace */ /* iptables-restore support Copyright(C) 2007-2008 ludva */ /* Credit: CZFree.Net,Martin Devera,Netdave,Aquarius,Gandalf */ /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ -/* Modified by: xChaos, 20190212 +/* Modified by: xChaos, 20231028 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.9.1"; +const char *version = "1.0.1"; /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ /* Versions: 0.9.0 is development release, 1.0 will be "stable" */ @@ -40,7 +40,7 @@ const char *version = "0.9.1"; /* Warning: unofficial Github mirror is not supported by author! */ /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ -const char *stats_html_signature = "Statistics generated by Prometheus QoS version %s
GPL+Copyright(C)2005-2019 Michael Polak, Arachne Labs
\n"; +const char *stats_html_signature = "Statistics generated by Prometheus QoS version %s
GPL+Copyright(C)2005-2020 Michael Polak, Arachne Labs
\n"; #define STRLEN 512 #undef DEBUG @@ -63,6 +63,7 @@ char *upstreamfile = "/etc/prometheus/upstream.interfaces"; /* list of interf char *downstreamfile = "/etc/prometheus/downstream.interfaces"; /* list of interfaces to manage */ char *qosfreefile = "/etc/prometheus/qosfree.interfaces"; /* list of interfaces to manage */ char *iptablesfile = "/var/spool/prometheus.iptables"; /* temporary file for iptables-restore*/ +char *iptablesdump = "/var/spool/prometheus.iptables-dump"; /* temporary file for iptables -L -v -x -n -t mangle */ 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 */ @@ -86,9 +87,8 @@ int filter_type = 1; /*1 mark, 2 classify*/ char *final_chain = "DROP"; /* REJECT would be better, but it is impossible in mangle */ char *mark = "MARK"; char *mark_iptables = "MARK --set-mark "; -int dry_run = FALSE; /* preview - use puts() instead of system() */ -int mix_new_hosts = FALSE; /* execute only commands not already in log of iptables */ -char *log_file_mode = "w"; /* overwrite command and iptables log files, except append in -x mode */ +int dry_run = FALSE; /* preview commands - use puts() instead of system() */ +int skip_stats = FALSE; /* skip generating statistics */ char *iptablespreamble = "*mangle\n:PREROUTING ACCEPT [0:0]\n:POSTROUTING ACCEPT [0:0]\n:INPUT ACCEPT [0:0]\n:OUTPUT ACCEPT [0:0]\n:FORWARD ACCEPT [0:0]"; char *ip6preamble = "-A FORWARD -p ipv6-icmp -j ACCEPT\n-A POSTROUTING -p ipv6-icmp -j ACCEPT\n-A FORWARD -s fe80::/10 -j ACCEPT\n-A FORWARD -d ff00::/8 -j ACCEPT\n-A POSTROUTING -s fe80::/10 -j ACCEPT\n-A POSTROUTING -d ff00::/8 -j ACCEPT"; FILE *iptables_file = NULL; @@ -103,8 +103,10 @@ char *medium = "1000Mbit"; /* 10Mbit/100Mbit ethernet */ char *ip6prefix = NULL; /* Prefix for global /48 IPv6 subnet */ char *qos_leaf = "sfq perturb 5"; /* leaf discipline */ char *qos_free_zone = NULL; /* QoS free zone */ +char *qos_free_dst_ipset = NULL; /* QoS free zone - dst match ipset name, must be prepared outside prometheus */ +char *qos_free_src_ipset = NULL; /* QoS free zone - src match ipset name, must be prepared outside prometheus */ /* int qos_proxy = TRUE; include proxy port to QoS */ -int found_lmsid = FALSE; /* show links to users in LMS information system */ +int found_code = FALSE; /* show links to users in LMS information system */ int include_upload = TRUE; /* upload+download=total traffic */ /* char *proxy_ip = "192.168.1.1/32"; our IP with proxy port */ /* int proxy_port = 3128; proxy port number */ @@ -117,7 +119,8 @@ int overlimit_max = 512; /* maximum allowed bandwidth for all undefined hos int qos_free_delay = 0; /* seconds to sleep before applying new QoS rules */ int digital_divide = 2; /* controls digital divide weirdness ratio, 1...3 */ int max_nesting = 5; /* /include/uapi/linux/pkt_sched.h: #define TC_HTB_MAXDEPTH 8 [... - 3 parent classes] */ -int htb_r2q = 256; /* should work for leaf values 512 kbps to 8 Mbps */ +//obsolete: int htb_r2q = 256; /* should work for leaf values 512 kbps to 8 Mbps */ +int htb_quantum = 1514; /* MTU + ethernet header */ int burst = 8; /* HTB burst (in kbits) */ int burst_main = 64; int burst_group = 32; @@ -128,12 +131,12 @@ int ip_count = 0; FILE *log_file = NULL; char *kwd = "via-prometheus"; /* /etc/hosts comment, eg. #qos-64-128 */ -const int highest_priority = 0; /* highest HTB priority (HTB built-in value is 0) */ -const int lowest_priority = 7; /* lowest HTB priority /include/uapi/linux/pkt_sched.h: #define TC_HTB_NUMPRIO 8 */ -const int idxtable_treshold1 = 24; /* this is no longer configurable */ -const int idxtable_treshold2 = 12; /* this is no longer configurable */ -const int idxtable_bitmask1 = 3; /* this is no longer configurable */ -const int idxtable_bitmask2 = 3; /* this is no longer configurable */ +const int highest_priority = 0; /* highest HTB priority (HTB built-in value is 0) */ +const int lowest_priority = 7; /* lowest HTB priority /include/uapi/linux/pkt_sched.h: #define TC_HTB_NUMPRIO 8 */ +const int idxtable_treshold1 = 24; /* this is no longer configurable */ +const int idxtable_treshold2 = 12; /* this is no longer configurable */ +const int idxtable_bitmask1 = 3; /* this is no longer configurable */ +const int idxtable_bitmask2 = 3; /* this is no longer configurable */ struct IP *ips = NULL, *networks = NULL, *ip, *sharedip; struct Group *groups = NULL, *group; @@ -142,7 +145,6 @@ struct Macro *macro, *macros = NULL; struct Index *idxs = NULL, *idx, *metaindex; struct Interface *interfaces = NULL, *interface; struct QosFreeInterface *qosfreeinterfaces = NULL, *qosfreeinterface; -struct Textfile *previous_commands = NULL, *previous_iptables = NULL, *previous_ip6tables = NULL, *previous_classmap = NULL, *textline; #define FREE_CLASS 3 #define OVERLIMIT_CLASS 4 @@ -290,6 +292,7 @@ void get_config(char *config_filename) option("ip6tables-save",ip6tablessave); option("ip6tables-restore",ip6tablesrestore); option("iptables-in-filename",iptablesfile); + option("iptables-dump-filename",iptablesdump); option("ip6tables-in-filename",ip6tablesfile); option("hosts",hosts); option("downstream-interfaces-list-filename",downstreamfile); @@ -316,6 +319,8 @@ void get_config(char *config_filename) option("lms-url",lms_url); ioption("use-jquery-popups",use_jquery_popups); option("qos-free-zone",qos_free_zone); + option("qos-free-dst-ipset",qos_free_dst_ipset); + option("qos-free-src-ipset",qos_free_src_ipset); ioption("qos-free-delay",qos_free_delay); /* ioption("qos-proxy-enable",qos_proxy); */ /* option("qos-proxy-ip",proxy_ip);*/ @@ -329,7 +334,7 @@ void get_config(char *config_filename) ioption("htb-burst-main",burst_main); ioption("htb-burst-group",burst_group); ioption("htb-nesting-limit",max_nesting); - ioption("htb-r2q",htb_r2q); + ioption("htb-quantum",htb_quantum); ioption("magic-include-upload",include_upload); ioption("magic-treshold",magic_treshold); option("filter-type", cnf); @@ -370,7 +375,7 @@ void get_config(char *config_filename) } -/* ========== This function executes, logs OR ALSO prints command ========== */ +/* ========== This function executes, logs or also prints command ========== */ void safe_run(char *cmd) { @@ -380,31 +385,9 @@ void safe_run(char *cmd) } else { - int skip_cmd = FALSE; - if(mix_new_hosts) - { - skip_cmd = FALSE; - for_each(textline, previous_commands) - { - if(eq(textline->str, cmd)) - { - skip_cmd = TRUE; - break; - } - } - } - - if(!skip_cmd) - { - if(mix_new_hosts) - { - printf("Executing command: %s\n", cmd); - } - else - system(cmd); - } + system(cmd); } - if(log_file && !mix_new_hosts)//!!debug + if(log_file) { fprintf(log_file,"%s\n",cmd); } @@ -412,41 +395,14 @@ void safe_run(char *cmd) void iptables_save_line(char *line, int ipv6) { - const char *cmd = NULL; - if(ipv6) { - if(mix_new_hosts) - for_each(textline, previous_ip6tables) - if(eq(textline->str, line)) - { - printf("Match: %s\n",line); - return; - } - - if(!mix_new_hosts) //!!debug - fprintf(ip6tables_file,"%s\n",line); - cmd = ip6tables; + fprintf(ip6tables_file,"%s\n",line); } else { - if(mix_new_hosts) - for_each(textline, previous_iptables) - if(eq(textline->str, line)) - { - printf("Match: %s\n",line); - return; - } - - if(!mix_new_hosts) //!!debug - fprintf(iptables_file,"%s\n",line); - cmd = iptables; + fprintf(iptables_file,"%s\n",line); } - if(mix_new_hosts) - { - - printf("Executing command: %s %s\n",cmd, line); - } } #define IPv4 FALSE @@ -520,7 +476,7 @@ program int just_preview = FALSE; /* preview - generate just stats */ int start_shaping = FALSE; /* apply FUP - requires classmap file */ int stop_shaping = FALSE; /* lift FUP - requires classmap file */ - int reduce_ceil = 0; /* allow only rate+(ceil-rate)/2, /4, etc. */ + int reduce_ceil = 0; /* allow only rate+(ceil-rate)/2, /4, etc. */ int just_logs = FALSE; /* just parse logs */ int run = FALSE; int total = 0; @@ -529,7 +485,7 @@ program printf("\n\ Prometheus QoS - \"fair-per-IP\" Quality of Service setup utility.\n\ -Version %s - Copyright (C)2005-2019 Michael Polak, Arachne Labs\n\ +Version %s - Copyright (C)2005-2017 Michael Polak, Arachne Labs\n\ iptables-restore & burst tunning & classify modification by Ludva\n\ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version); @@ -538,21 +494,21 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version); { argument("-c") { nextargument(config); } argument("-h") { nextargument(althosts);} - argument("-d") { run = TRUE; dry_run = TRUE; } - argument("-f") { run = TRUE; just_flush = TRUE; } - argument("-9") { run = TRUE; just_flush = 9; } - argument("-p") { run = TRUE; just_preview = TRUE; } - argument("-q") { run = TRUE; just_preview = TRUE; stop_shaping = TRUE; } - argument("-2") { run = TRUE; just_preview = TRUE; reduce_ceil = 2; } - argument("-4") { run = TRUE; just_preview = TRUE; reduce_ceil = 4; } - argument("-s") { run = TRUE; just_preview = TRUE; start_shaping = TRUE; } - argument("-x") { run = TRUE; mix_new_hosts = TRUE; log_file_mode = "a"; } - argument("-r") { run = TRUE; } - argument("-n") { run = TRUE; nodelay = TRUE; } - argument("-a") { run = TRUE; just_networks = TRUE; } - argument("-l") { just_logs = TRUE; } - argument("-m") { just_logs = TRUE; } - argument("-y") { just_logs = TRUE; } + argument("-d") { run=TRUE; dry_run=TRUE; } + argument("-f") { run=TRUE; just_flush=TRUE; } + argument("-9") { run=TRUE; just_flush=9; } + argument("-p") { run=TRUE; just_preview=TRUE; } + argument("-q") { run=TRUE; just_preview=TRUE; stop_shaping=TRUE; } + argument("-2") { run=TRUE; just_preview=TRUE; reduce_ceil=2; } + argument("-4") { run=TRUE; just_preview=TRUE; reduce_ceil=4; } + argument("-s") { run=TRUE; just_preview=TRUE; start_shaping=TRUE; } + argument("-r") { run=TRUE; } + argument("-n") { run=TRUE; nodelay=TRUE; } + argument("-b") { run=TRUE; nodelay=TRUE; skip_stats=TRUE; } + argument("-a") { run=TRUE; just_networks=TRUE; } + argument("-l") { just_logs=TRUE; } + argument("-m") { just_logs=TRUE; } + argument("-y") { just_logs=TRUE; } argument("-?") { help(); exit(0); } argument("--help") { help(); exit(0); } argument("-v") { exit(0); } @@ -591,7 +547,7 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version); interface->chain = "FORWARD"; interface->idxprefix = "forw"; push(interface, interfaces); - printf("Upstream interface %s: medium %s capacity %ld kbps\n", interface->name, medium, interface->speed); + printf("Upstream interface %s: medium %s capacity %Ld kbps\n", interface->name, medium, interface->speed); } } done; /* ugly macro end */ @@ -617,7 +573,7 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version); interface->chain = "POSTROUTING"; interface->idxprefix = "post"; push(interface, interfaces); - printf("Downstream interface %s: medium %s capacity %ld kbps\n", interface->name, medium, interface->speed); + printf("Downstream interface %s: medium %s capacity %Ld kbps\n", interface->name, medium, interface->speed); } } done; /* ugly macro end */ @@ -638,7 +594,7 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version); hosts = althosts; } - if(!mix_new_hosts && just_flush<9) + if(just_flush<9 && !skip_stats) { /*-----------------------------------------------------------------*/ puts("Parsing iptables verbose output ..."); @@ -682,39 +638,40 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version); } done; /* ugly macro end */ + + /*-----------------------------------------------------------------*/ printf("Parsing class defintion file %s ...\n", hosts); /*-----------------------------------------------------------------*/ parse_hosts(hosts); -/* - //this was pretty dumb idea anyway... - if(just_networks) - { - analyse_topology("/usr/sbin/traceroute -n -m 10 -w 2 %s.%d"); - exit(-1); - } -*/ - if(mix_new_hosts) +#ifdef MONITORINGTRHU_CTU +//special hack only to generate certain required CSV statistics for www.ctu.cz (regulation body) +//not required for everyday use, requires special syntax sugar in hosts file, see parsehosts.c + for_each(technology, technologies) { - char *eoln; - /*-----------------------------------------------------------------*/ - printf("Loading log of previously executed commands %s ...\n", cmdlog); - /*-----------------------------------------------------------------*/ - load(textline, previous_commands, cmdlog, Textfile, str); + char *filename; + FILE *f; + string(filename, strlen(log_dir) + strlen(technology->filename) + 5); + strcpy(filename, log_dir); + strcat(filename, technology->filename); + strcat(filename, ".csv"); /*-----------------------------------------------------------------*/ - printf("Loading log of iptables-restore commands %s ...\n", iptablesfile); + printf("Writing report file %s ...\n", filename); /*-----------------------------------------------------------------*/ - load(textline, previous_iptables, iptablesfile, Textfile, str); - /*-----------------------------------------------------------------*/ - printf("Loading log of ip6tables-restore commands %s ...\n", ip6tablesfile); - /*-----------------------------------------------------------------*/ - load(textline, previous_ip6tables, ip6tablesfile, Textfile, str); - /*-----------------------------------------------------------------*/ - printf("Loading map of IP addresses to tc classes %s ...\n", classmap); - /*-----------------------------------------------------------------*/ - load(textline, previous_classmap, classmap, Textfile, str); - } + f = fopen(filename, "w"); + if(f) + { + for_each(ip, ips) if(eq(technology->filename, ip->technology_str)) + { + fprintf(f,"%s,%s,%d\n", ip->code, ip->ruian_id_str, ip->max); + } + fclose(f); + } + else + perror(filename); + } +#endif /*-----------------------------------------------------------------*/ puts("Resolving shared connections ..."); @@ -728,7 +685,7 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version); sharedip->traffic_up += ip->upload; ip->traffic = 0; ip->mark = sharedip->mark; - ip->lmsid = sharedip->lmsid; + ip->code = sharedip->code; ip->pps_limit = sharedip->pps_limit; /* no other way to do this */ /* Ugly hack: append IPv4 addresses of sharedip to IPv6 uplinks */ @@ -756,7 +713,7 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version); } } - if(!mix_new_hosts && enable_credit && just_flush<9) + if(enable_credit && just_flush<9) { /*-----------------------------------------------------------------*/ printf("Parsing credit file %s ...\n", credit); @@ -778,36 +735,33 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version); if(!just_preview) { - if(!mix_new_hosts) - { - /*-----------------------------------------------------------------*/ - puts("Initializing iptables and tc classes ..."); - /*-----------------------------------------------------------------*/ + /*-----------------------------------------------------------------*/ + puts("Initializing iptables and tc classes ..."); + /*-----------------------------------------------------------------*/ - iptables_file = fopen(iptablesfile, "w"); - if(iptables_file == NULL) - { + iptables_file = fopen(iptablesfile, "w"); + if(iptables_file == NULL) + { perror(iptablesfile); exit(-1); - } - iptables_save_line(iptablespreamble, IPv4); + } + iptables_save_line(iptablespreamble, IPv4); - if(ip6prefix) + if(ip6prefix) + { + ip6tables_file = fopen(ip6tablesfile, "w"); + if(ip6tables_file == NULL) { - ip6tables_file = fopen(ip6tablesfile, "w"); - if(ip6tables_file == NULL) - { - perror(ip6tablesfile); - exit(-1); - } - iptables_save_line(iptablespreamble, IPv6); - iptables_save_line(ip6preamble, IPv6); + perror(ip6tablesfile); + exit(-1); } - - run_iptables_restore(); + iptables_save_line(iptablespreamble, IPv6); + iptables_save_line(ip6preamble, IPv6); } + + run_iptables_restore(); - log_file = fopen(cmdlog, log_file_mode); /* overwrite command and iptables log files, except append in -x mode */ + log_file = fopen(cmdlog, "w"); if(log_file == NULL) { perror(cmdlog); @@ -819,24 +773,48 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version); sprintf(str,"%s qdisc del dev %s root 2>/dev/null", tc, interface->name); safe_run(str); } + + iptables_file=fopen(iptablesfile,"w"); + iptables_save_line(iptablespreamble, IPv4); + if(ip6prefix) + { + ip6tables_file=fopen(ip6tablesfile,"w"); + iptables_save_line(iptablespreamble, IPv6); + iptables_save_line(ip6preamble, IPv6); + } - if(!mix_new_hosts) - { - iptables_file = fopen(iptablesfile, log_file_mode); /* overwrite command and iptables log files, except append in -x mode */ - iptables_save_line(iptablespreamble, IPv4); - if(ip6prefix) + /* this doesn't seem to be way to go... about 2/3 of all packets have ACK flag set + maybe with --length 40:100 it would make some sense, but not enought + for_each(interface, interfaces) + { + sprintf(str,"-A %s -m tcp -p tcp --tcp-flags ACK ACK -o %s -j ACCEPT", interface->chain, interface->name); + iptables_save_line(str, IPv4); + } + */ + + if(qos_free_zone && *qos_free_zone != '0') /* this is currently supported only for IPv4 */ + { + for_each(interface, interfaces) { - ip6tables_file = fopen(ip6tablesfile, log_file_mode); /* overwrite command and iptables log files, except append in -x mode */ - iptables_save_line(iptablespreamble, IPv6); - iptables_save_line(ip6preamble, IPv6); + sprintf(str,"-A %s -%c %s -o %s -j ACCEPT", interface->chain, (interface->is_upstream?'d':'s'), qos_free_zone, interface->name); + iptables_save_line(str, IPv4); } } - if(qos_free_zone && *qos_free_zone!='0') /* this is currently supported only for IPv4 */ + if(qos_free_dst_ipset && *qos_free_dst_ipset != '0') /* this is currently supported only for IPv4 */ { for_each(interface, interfaces) { - sprintf(str,"-A %s -%c %s -o %s -j ACCEPT", interface->chain, (interface->is_upstream?'d':'s'), qos_free_zone, interface->name); + sprintf(str,"-A %s -m set --match-set %s %s -o %s -j ACCEPT", interface->chain, qos_free_dst_ipset, (interface->is_upstream?"dst":"src"), interface->name); + iptables_save_line(str, IPv4); + } + } + + if(qos_free_src_ipset && *qos_free_src_ipset != '0') /* this is currently supported only for IPv4 */ + { + for_each(interface, interfaces) + { + sprintf(str,"-A %s -m set --match-set %s %s -o %s -j ACCEPT", interface->chain, qos_free_src_ipset, (interface->is_upstream?"src":"dst"), interface->name); iptables_save_line(str, IPv4); } } @@ -1002,7 +980,7 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version); exit(0); } - if(!mix_new_hosts && !just_preview) + if(!just_preview) { if(!dry_run && !nodelay && qos_free_delay) { @@ -1012,27 +990,24 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version); for_each(interface, interfaces) { - sprintf(str, "%s qdisc add dev %s root handle 1: htb r2q %d default 1", - tc, interface->name, htb_r2q); + sprintf(str, "%s qdisc add dev %s root handle 1: htb default 1", + tc, interface->name); safe_run(str); - sprintf(str, "%s class add dev %s parent 1: classid 1:2 htb rate %s ceil %s burst %dk prio %d", - tc, interface->name, medium, medium, burst_main, highest_priority); + sprintf(str, "%s class add dev %s parent 1: classid 1:2 htb rate %s ceil %s burst %dk prio %d quantum %d", + tc, interface->name, medium, medium, burst_main, highest_priority, htb_quantum); safe_run(str); - sprintf(str, "%s class add dev %s parent 1:2 classid 1:1 htb rate %Ldkbit ceil %Ldkbit burst %dk prio %d", - tc, interface->name, interface->speed, interface->speed, burst_main, highest_priority); + sprintf(str, "%s class add dev %s parent 1:2 classid 1:1 htb rate %Ldkbit ceil %Ldkbit burst %dk prio %d quantum %d", + tc, interface->name, interface->speed, interface->speed, burst_main, highest_priority, htb_quantum); safe_run(str); } } - if(mix_new_hosts) - { - /*-----------------------------------------------------------------*/ - puts("Locating heavy downloaders and generating root classes ..."); - /*-----------------------------------------------------------------*/ - sort(ip,ips,desc_order_by,traffic); - } + /*-----------------------------------------------------------------*/ + puts("Locating heavy downloaders and generating root classes ..."); + /*-----------------------------------------------------------------*/ + sort(ip,ips,desc_order_by,traffic); /*-----------------------------------------------------------------*/ for_each(interface, interfaces) @@ -1051,8 +1026,8 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version); { if(!just_preview) { - sprintf(str, "%s class add dev %s parent 1:%d classid 1:%d htb rate %Ldkbit ceil %Ldkbit burst %dk prio %d #down desired %d", - tc, interface->name, parent, group->id, rate, max, burst_group, highest_priority+1, group->desired); + sprintf(str, "%s class add dev %s parent 1:%d classid 1:%d htb rate %Ldkbit ceil %Ldkbit burst %dk prio %d quantum %d #down desired %d", + tc, interface->name, parent, group->id, rate, max, burst_group, highest_priority+1, htb_quantum, group->desired); safe_run(str); } @@ -1160,7 +1135,7 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version); agreg = (int)((float)(avg_mbps_down+1)/min_mbps+.5); ip->max /= agreg; ip->pps_limit /= agreg; - printf("Download aggregation 1:%d for %s (min: %lu Mbps avg: %ld Mbps)\n", agreg, ip->name, min_mbps, avg_mbps_down); + printf("Download aggregation 1:%d for %s (min: %d Mbps avg: %ld Mbps)\n", agreg, ip->name, min_mbps, avg_mbps_down); } else { @@ -1180,7 +1155,7 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version); unshape_this_ip = 0; agreg = (int)((float)(avg_mbps_up+1)/min_mbps+.5); ip->max /= agreg; - printf("Upload aggregation 1:%d for %s: (min: %lu Mbps avg: %ld Mbps)\n", agreg, ip->name, min_mbps, avg_mbps_up); + printf("Upload aggregation 1:%d for %s: (min: %d Mbps avg: %ld Mbps)\n", agreg, ip->name, min_mbps, avg_mbps_up); } else { @@ -1227,8 +1202,8 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version); { printf("[down %s: %dk-%dk wants %d]", interface->name, ip->min, ip->max, ip->desired); } - sprintf(str, "%s class change dev %s parent 1:%d classid 1:%d htb rate %dkbit ceil %dkbit burst %dk prio %d", - tc, interface->name, ip->group, ip->mark, ip->min, ip->max, burst, ip->prio); + sprintf(str, "%s class change dev %s parent 1:%d classid 1:%d htb rate %dkbit ceil %dkbit burst %dk prio %d quantum %d", + tc, interface->name, ip->group, ip->mark, ip->min, ip->max, burst, ip->prio, htb_quantum); safe_run(str); } else @@ -1239,10 +1214,10 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version); (int)((ip->desired/ip->keyword->asymetry_ratio)-ip->keyword->asymetry_fixed), (int)((ip->desired/ip->keyword->asymetry_ratio)-ip->keyword->asymetry_fixed)); } - sprintf(str,"%s class change dev %s parent 1:%d classid 1:%d htb rate %dkbit ceil %dkbit burst %dk prio %d", + sprintf(str,"%s class change dev %s parent 1:%d classid 1:%d htb rate %dkbit ceil %dkbit burst %dk prio %d quantum %d", tc, interface->name, ip->group, ip->mark, (int)((ip->min/ip->keyword->asymetry_ratio)-ip->keyword->asymetry_fixed), - (int)((ip->max/ip->keyword->asymetry_ratio)-ip->keyword->asymetry_fixed), burst, ip->prio); + (int)((ip->max/ip->keyword->asymetry_ratio)-ip->keyword->asymetry_fixed), burst, ip->prio, htb_quantum); safe_run(str); } } @@ -1267,7 +1242,7 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version); json_traffic=json_preview; } - if(!mix_new_hosts && !dry_run && !just_flush) + if(!dry_run && !just_flush && !skip_stats) { /*-----------------------------------------------------------------*/ printf("Writing json traffic overview %s ... ", json_traffic); @@ -1278,6 +1253,7 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version); printf("Writing statistics into HTML page %s ...\n", html); /*-----------------------------------------------------------------*/ write_htmlandlogs(html, d, total, just_preview); + printf("\n"); } if(just_preview) @@ -1298,8 +1274,8 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version); printf("Statistics preview generated (-%c switch) - now exiting ...\n", swchar); exit(0); - } - + } + i=0; #ifdef DEBUG printf("%-22s %-15s mark\n","name","ip"); @@ -1313,7 +1289,7 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version); } /*-----------------------------------------------------------------*/ - printf(" + generating iptables and tc classes ... "); + printf(" + generating iptables and tc classes ... \n"); /*-----------------------------------------------------------------*/ for_each(ip, ips) if(ip->mark > 0) @@ -1394,8 +1370,8 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version); printf("[down: %dk-%dk]", ip->min, ip->max); #endif - sprintf(str, "%s class add dev %s parent 1:%d classid 1:%d htb rate %dkbit ceil %dkbit burst %dk prio %d", - tc, interface->name, ip->group, ip->mark, ip->min, ip->max, burst, ip->prio); + sprintf(str, "%s class add dev %s parent 1:%d classid 1:%d htb rate %dkbit ceil %dkbit burst %dk prio %d quantum %d", + tc, interface->name, ip->group, ip->mark, ip->min, ip->max, burst, ip->prio, htb_quantum); safe_run(str); if(strcmpi(ip->keyword->leaf_discipline, "none")) @@ -1420,15 +1396,15 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version); } i++; } - /* classmap */ if(ip->min && f > 0) { fprintf(f, "%s %d\n", ip->addr, ip->mark); } + printf("."); } if(f > 0) { - puts("done."); + puts(" done."); fclose(f); } @@ -1467,8 +1443,8 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version); /*-----------------------------------------------------------------*/ puts("Generating free bandwith class ..."); /*-----------------------------------------------------------------*/ - sprintf(str, "%s class add dev %s parent 1:%d classid 1:%d htb rate %dkbit ceil %dkbit burst %dk prio %d", - tc, interface->name, parent, FREE_CLASS, free_min, free_max,burst, lowest_priority); + sprintf(str, "%s class add dev %s parent 1:%d classid 1:%d htb rate %dkbit ceil %dkbit burst %dk prio %d quantum %d", + tc, interface->name, parent, FREE_CLASS, free_min, free_max,burst, lowest_priority, htb_quantum); safe_run(str); /* tc SFQ */ if(strcmpi(qos_leaf, "none")) @@ -1480,18 +1456,18 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version); sprintf(str,"%s filter add dev %s parent 1:0 protocol ip handle %d fw flowid 1:%d", tc, interface->name, FREE_CLASS, FREE_CLASS); safe_run(str); } - /*-----------------------------------------------------------------*/ - puts("Generating bandwith class for overlimit packets..."); - /*-----------------------------------------------------------------*/ - sprintf(str, "%s class add dev %s parent 1:%d classid 1:%d htb rate %dkbit ceil %dkbit burst %dk prio %d", - tc, interface->name, parent, OVERLIMIT_CLASS, overlimit_min, overlimit_max, burst, lowest_priority); - safe_run(str); + if(*limit_pkts) /* non-empty string?*/ + { + /*-----------------------------------------------------------------*/ + puts("Generating bandwith class for overlimit packets..."); + /*-----------------------------------------------------------------*/ + sprintf(str, "%s class add dev %s parent 1:%d classid 1:%d htb rate %dkbit ceil %dkbit burst %dk prio %d quantum %d", + tc, interface->name, parent, OVERLIMIT_CLASS, overlimit_min, overlimit_max, burst, lowest_priority, htb_quantum); + safe_run(str); + } } printf("Total IP count: %d\n", i); - if(!mix_new_hosts) - { - run_iptables_restore(); - } + run_iptables_restore(); if(log_file) { fclose(log_file);