X-Git-Url: http://git.harvie.cz/?p=svn%2FPrometheus-QoS%2F.git;a=blobdiff_plain;f=prometheus.c;h=4cc02a02543b8c2c23c1070fcb09a3b6807362da;hp=1c917386c82e7d68cb1d747f7fc6733f73bd59e8;hb=HEAD;hpb=47b5fd64878b8e1206cbdc7fc2ec65308b0d9e89 diff --git a/prometheus.c b/prometheus.c index 1c91738..8aacb50 100644 --- a/prometheus.c +++ b/prometheus.c @@ -7,7 +7,7 @@ /* Credit: CZFree.Net,Martin Devera,Netdave,Aquarius,Gandalf */ /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ -/* Modified by: xChaos, 20200107 +/* 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 = "1.0.0-a"; +const char *version = "1.0.1"; /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ /* Versions: 0.9.0 is development release, 1.0 will be "stable" */ @@ -87,7 +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 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; @@ -105,7 +106,7 @@ 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 */ @@ -118,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; @@ -187,7 +189,6 @@ const char *tr_odd_even(void) } } - /* ====== iptables indexes are used to reduce complexity to log8(N) ===== */ char *index_id(char *ip, int bitmask); @@ -333,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); @@ -374,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) { @@ -503,6 +504,7 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version); 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; } @@ -545,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 */ @@ -571,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 */ @@ -592,7 +594,7 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version); hosts = althosts; } - if(just_flush<9) + if(just_flush<9 && !skip_stats) { /*-----------------------------------------------------------------*/ puts("Parsing iptables verbose output ..."); @@ -651,7 +653,7 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version); char *filename; FILE *f; string(filename, strlen(log_dir) + strlen(technology->filename) + 5); - strcpy(filename, html_log_dir); + strcpy(filename, log_dir); strcat(filename, technology->filename); strcat(filename, ".csv"); /*-----------------------------------------------------------------*/ @@ -662,7 +664,7 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version); { for_each(ip, ips) if(eq(technology->filename, ip->technology_str)) { - fprintf(f,"%d,%s,%d\n", ip->lmsid, ip->ruian_id_str, ip->max); + fprintf(f,"%s,%s,%d\n", ip->code, ip->ruian_id_str, ip->max); } fclose(f); } @@ -683,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 */ @@ -781,6 +783,15 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version); iptables_save_line(ip6preamble, IPv6); } + /* 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) @@ -979,16 +990,16 @@ 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); } } @@ -1015,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); } @@ -1124,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 { @@ -1144,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 { @@ -1191,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 @@ -1203,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); } } @@ -1231,7 +1242,7 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version); json_traffic=json_preview; } - if(!dry_run && !just_flush) + if(!dry_run && !just_flush && !skip_stats) { /*-----------------------------------------------------------------*/ printf("Writing json traffic overview %s ... ", json_traffic); @@ -1278,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) @@ -1359,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")) @@ -1389,10 +1400,11 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version); { fprintf(f, "%s %d\n", ip->addr, ip->mark); } + printf("."); } if(f > 0) { - puts("done."); + puts(" done."); fclose(f); } @@ -1431,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")) @@ -1444,12 +1456,15 @@ 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); run_iptables_restore();