X-Git-Url: http://git.harvie.cz/?p=svn%2FPrometheus-QoS%2F.git;a=blobdiff_plain;f=prometheus.c;h=8aacb50830c759fecc469588393d4d4cf98b0761;hp=9ddd593c3991661fde2cadeccb4454a2048d2eae;hb=HEAD;hpb=5450cb417ed9adc4abb072f449e2ea4e68d0551e diff --git a/prometheus.c b/prometheus.c index 9ddd593..8aacb50 100644 --- a/prometheus.c +++ b/prometheus.c @@ -7,7 +7,7 @@ /* Credit: CZFree.Net,Martin Devera,Netdave,Aquarius,Gandalf */ /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ -/* Modified by: xChaos, 20220327 +/* 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-b"; +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 */ @@ -188,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); @@ -504,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; } @@ -546,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 */ @@ -572,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 */ @@ -593,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 ..."); @@ -663,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); } @@ -684,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 */ @@ -782,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) @@ -1125,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 { @@ -1145,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 { @@ -1232,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); @@ -1279,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) @@ -1390,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); } @@ -1445,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 quantum %d", - tc, interface->name, parent, OVERLIMIT_CLASS, overlimit_min, overlimit_max, burst, lowest_priority, htb_quantum); - 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();