X-Git-Url: https://git.harvie.cz/?a=blobdiff_plain;f=parsehosts.c;h=ecb956a3a53edbf2bd1c3d2d7586d4324d9bc246;hb=8dcd2b4cab6d481b0875c702176505b6ef6b6d5d;hp=ac9b39fd47c374f23c965bb159f3223c2648258c;hpb=9694a8ec9258e894c4001b076a6c7f6c0e5a46f4;p=svn%2FPrometheus-QoS%2F.git diff --git a/parsehosts.c b/parsehosts.c index ac9b39f..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; @@ -40,6 +41,7 @@ void TheIP(char *ipaddr, int is_network) ip->direct = \ ip->traffic = \ ip->pktsup = \ + ip->pps_limit = \ ip->pktsdown = 0; ip->keyword = keywords; ip->v6 = (strchr(ip->addr,':')!=NULL); @@ -150,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) @@ -252,13 +281,24 @@ void parse_hosts(char *hosts) else { ip->max -= ip->keyword->reserve_max; - if(ip->maxmin) + if(ip->max < ip->min) { - ip->max=ip->min; + ip->max = ip->min; } } - ip->mark = FIRSTIPCLASS+1+class_count++; + /* 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 = 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++; update_network(ip->addr, ip); if_exists(group,groups,(group->min == ip->min)) @@ -296,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 +}