X-Git-Url: https://git.harvie.cz/?a=blobdiff_plain;f=parsehosts.c;h=ecb956a3a53edbf2bd1c3d2d7586d4324d9bc246;hb=8dcd2b4cab6d481b0875c702176505b6ef6b6d5d;hp=7e12a41b34d1280821ef1c916e417675fade4b4a;hpb=a25842fafee4469c8acbacd673fc4c905bcab3f9;p=svn%2FPrometheus-QoS%2F.git diff --git a/parsehosts.c b/parsehosts.c index 7e12a41..ecb956a 100644 --- a/parsehosts.c +++ b/parsehosts.c @@ -1,4 +1,4 @@ -/* Modified by: xChaos, 20131029 */ +/* Modified by: xChaos, 20131220 */ #include "cll1-0.6.2.h" #include "ipstruct.h" @@ -10,6 +10,7 @@ extern struct IP *ips, *ip, *sharedip, *networks; extern struct Group *groups, *group; extern struct Keyword *keyword, *defaultkeyword, *keywords; +extern struct Macro *macro, *macros; extern int class_count; extern int ip_count; extern int found_lmsid; @@ -151,17 +152,44 @@ void parse_hosts(char *hosts) char *str, *ptr; char *substring; struct IP *network; + int pktratio; parse(hosts) { - str=_; + str = _; if(*str < '0' or *str > '9') { /* any line starting with non-number is comment ...*/ continue; } - + + ptr = strchr(str,'\r'); /* fore unix-style end of line */ + if(ptr) + { + *ptr = 0; + } + + /* first, expand (rewrite) any predefined macros, if found*/ + for_each(macro, macros) + { + substring = strstr(str, macro->rewrite_from); + if(substring) + { + int l1, l3; + *substring = 0; + substring += strlen(macro->rewrite_from); + l1 = strlen(str); + l3 = strlen(substring); + string(ptr, l1 + strlen(macro->rewrite_to) + l3 + 1); + strcpy(ptr, str); + strcat(ptr, macro->rewrite_to); + strcat(ptr, substring); + str = ptr; + /* printf("REWRITE: %s -> %s\n",_,str); */ + } + } + /* Does this IP share QoS class with some other ? */ substring = strstr(str, "sharing-"); if(substring) @@ -259,12 +287,15 @@ void parse_hosts(char *hosts) } } - /* MTU is 1450 bytes = 11600 bits ~= 12 kbit, max is in kb/s - average pkt 1/2 MTU = 6 kbit*/ - ip->pps_limit = ip->max/6; - 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 */ + } } ip->mark = FIRSTIPCLASS+1+class_count++; @@ -305,4 +336,4 @@ void parse_hosts(char *hosts) // TheIP("0.0.0.0", TRUE); // ip->name = "TOTAL"; // ip->mask = 0; -} \ No newline at end of file +}