From: xchaos Date: Sat, 11 Mar 2023 17:20:27 +0000 (+0000) Subject: lmsid -> code X-Git-Url: https://git.harvie.cz/?a=commitdiff_plain;h=296d0585b23ee7c91267d0cb9238dce836106180;p=svn%2FPrometheus-QoS%2F.git lmsid -> code git-svn-id: https://dev.arachne.cz/repos/prometheus/trunk@280 251d49ef-1d17-4917-a970-b30cf55b089b --- diff --git a/htmlandlogs.c b/htmlandlogs.c index 798544d..431d044 100644 --- a/htmlandlogs.c +++ b/htmlandlogs.c @@ -18,7 +18,7 @@ extern int dry_run; extern int qos_proxy; extern char *title; extern char *log_url; -extern int found_lmsid; +extern int found_code; extern char *lms_url; extern char *log_dir; extern char *ip6prefix; @@ -42,9 +42,9 @@ void append_log(struct IP *self) /*using global variables*/ f = fopen(str, "a"); if(f > 0) { - fprintf(f, "%ld\t%s\t%Lu\t%Lu\t%Lu\t%Lu\t%d\t%d\t%d\t%d\t%s", + fprintf(f, "%ld\t%s\t%Lu\t%Lu\t%Lu\t%Lu\t%d\t%d\t%d\t%s\t%s", time(NULL), self->name, self->traffic, self->direct, self->proxy, - self->upload, self->min, self->max, self->desired, self->lmsid, d); /* d = date*/ + self->upload, self->min, self->max, self->desired, self->code, d); /* d = date*/ fclose(f); } else @@ -125,7 +125,7 @@ void write_htmlandlogs(char *html, char *d, int total, int just_preview) i=0; if(f > 0) { - unsigned long long total_traffic=0, total_direct=0, total_proxy=0, total_upload=0, tmp_sum = 0; + unsigned long long total_traffic = 1 /* prevent divide by zero */ , total_direct=0, total_proxy=0, total_upload=0, tmp_sum = 0; unsigned long long total_pktup = 0, total_pktdown = 0; int active_classes = 0; // int colspan = 14; @@ -133,7 +133,7 @@ void write_htmlandlogs(char *html, char *d, int total, int just_preview) int agreg_count = 0, limit_count = 0, prio_count = 0; int popup_button = 0; /* IPv6 vs. IPv4 stats */ - unsigned long long pkts4 =0, pkts6 = 0, bytes4 = 0, bytes6 = 0; + unsigned long long pkts4 = 1, pkts6 = 1 /*prevent divide by zero */, bytes4 = 0, bytes6 = 0; int count4 = 0, count6 = 0; int mpkts; double perc6; @@ -255,15 +255,15 @@ style=\"cursor: pointer;\">+%d]", fputs("\n",f); /* ----------------------------------------------- */ - if(found_lmsid) + if(found_code) { fputs("",f); - if(ip->lmsid > 0) + if(ip->code[0]) { - fprintf(f, "%04d\n", - lms_url, ip->lmsid, ip->lmsid); + fprintf(f, "%s\n", + lms_url, ip->code, ip->code); } - else if(ip->lmsid == 0) + else if(ip->code[0] == 0) { fputs("------",f); } diff --git a/ipstruct.h b/ipstruct.h index 3b80747..17635ff 100644 --- a/ipstruct.h +++ b/ipstruct.h @@ -15,7 +15,7 @@ struct IP int aggregated; int fixedprio; int group; - int lmsid; + char *code; int pps_limit; unsigned long long direct; unsigned long long proxy; diff --git a/json.c b/json.c index c04a568..f09f916 100644 --- a/json.c +++ b/json.c @@ -15,7 +15,7 @@ void write_json_traffic(char *json) for_each(ip, ips) { - if( ip->lmsid > 0 + if( ip->code[0] > 0 and (ip->traffic or ip->direct or ip->proxy or ip->upload)) { if(jsoncount) @@ -23,10 +23,10 @@ void write_json_traffic(char *json) fprintf(f, ",\n"); } fprintf(f, - " \"%s\":{ \"lms\": %d, \"ip\":\"%s\", \"total\":%Lu, \"down\":%Lu, \ + " \"%s\":{ \"code\": %s, \"ip\":\"%s\", \"total\":%Lu, \"down\":%Lu, \ \"proxy\":%Lu, \"up\":%Lu, \"min\":%d, \"max\":%d, \"limit\":%d, \ \"pktsup\":%Lu, \"pktsdown\":%Lu, \"realquota\":%Lu, \"credit\":%Lu, \"dailyquota\":%ld }", - ip->name, ip->lmsid, ip->addr, ip->traffic, ip->direct, ip->proxy, + ip->name, ip->code, ip->addr, ip->traffic, ip->direct, ip->proxy, ip->upload, ip->min, ip->desired, ip->max, ip->pktsup, ip->pktsdown, ip->realquota, ip->credit, (ip->min*ip->keyword->data_limit+(ip->keyword->fixed_limit<<20))); jsoncount++; diff --git a/parsehosts.c b/parsehosts.c index f356f16..cc2548f 100644 --- a/parsehosts.c +++ b/parsehosts.c @@ -13,7 +13,7 @@ extern struct Keyword *keyword, *defaultkeyword, *keywords; extern struct Macro *macro, *macros; extern int class_count; extern int ip_count; -extern int found_lmsid; +extern int found_code; extern int free_min; extern const int highest_priority; extern char *ip6prefix; @@ -29,7 +29,7 @@ void TheIP(char *ipaddr, int is_network) ip->addr = ipaddr; ip->sharing = NULL; ip->prio = highest_priority+1; - ip->lmsid = -1; + ip->code = "-----"; ip->fixedprio = \ ip->aggregated = \ ip->mark = \ @@ -74,7 +74,7 @@ struct IP *lastIP6range, *lastIP6uplink; void parse_and_append_ip(char *str, struct IP *listhead) { char *ptr, *ipaddr, *nextip6, *ip6buf; - char *ip6uplink = NULL, *ip6range = NULL, *ipname = NULL, *lmsid = NULL; + char *ip6uplink = NULL, *ip6range = NULL, *ipname = NULL, *code = NULL; if(ip6prefix) /* Try this only if IPv6 subsystem is active... */ { @@ -105,7 +105,7 @@ void parse_and_append_ip(char *str, struct IP *listhead) ptr = strchr(str, '{'); if(ptr) { - lmsid = ++ptr; + code = ++ptr; while(*ptr and *ptr != '}') { ptr++; @@ -144,9 +144,9 @@ void parse_and_append_ip(char *str, struct IP *listhead) } ip->name = ip6range; ip->keyword = defaultkeyword; /* settings for default keyword */ - if(lmsid) + if(code) { - ip->lmsid = atoi(lmsid); + ip->code = code; } lastIP6range = ip; } @@ -163,9 +163,9 @@ void parse_and_append_ip(char *str, struct IP *listhead) TheIP(ip6uplink, FALSE); /* always new IP - more IPs in single uplink network */ ip->name = ip6uplink; ip->keyword = defaultkeyword; /* settings for default keyword */ - if(lmsid) + if(code) { - ip->lmsid = atoi(lmsid); + ip->code = code; } lastIP6uplink = ip; } @@ -180,10 +180,10 @@ void parse_and_append_ip(char *str, struct IP *listhead) TheIP(ipaddr, (listhead==networks)); } ip->name = ipname; - if(lmsid) + if(code) { - ip->lmsid = atoi(lmsid); - found_lmsid = TRUE; + ip->code = code; + found_code = TRUE; } } @@ -375,14 +375,17 @@ void parse_hosts(char *hosts) } } - /* avg MTU bytes * 8 >> 10 = in bits, max is in kb/s */ - pktratio = (ip->keyword->allowed_avgmtu*8) >> 10; - if(pktratio > 0) + if(ip->keyword->allowed_avgmtu) { - ip->pps_limit = ip->max/pktratio; - if(ip->pps_limit > 10000) /* this limit seems to be hardcoded in iptables */ + /* avg MTU bytes * 8 >> 10 = in bits, max is in kb/s */ + pktratio = (ip->keyword->allowed_avgmtu*8) >> 10; + if(pktratio > 0) { - ip->pps_limit = 0; /* do not apply packet limits */ + ip->pps_limit = ip->max/pktratio; + if(ip->pps_limit > 10000) /* this limit seems to be hardcoded in iptables */ + { + ip->pps_limit = 0; /* do not apply packet limits */ + } } } diff --git a/prometheus.c b/prometheus.c index 9ddd593..d8069b8 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, 20220607 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.0-d"; /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ /* Versions: 0.9.0 is development release, 1.0 will be "stable" */ @@ -105,7 +105,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 */ @@ -663,7 +663,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 +684,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 +782,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) @@ -1279,7 +1288,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 +1399,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 +1455,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();