X-Git-Url: http://git.harvie.cz/?p=svn%2FPrometheus-QoS%2F.git;a=blobdiff_plain;f=parsehosts.c;h=18418eddb6b9c587d6ec23925a71c6f8ed011c48;hp=9ae1d811f827bf9971e642a8015fffef70b256da;hb=bb5e73853e892f8bce70e03344a81b192c2b84ff;hpb=06733b885c35e5bf83505d064c55ccdda848ac01 diff --git a/parsehosts.c b/parsehosts.c index 9ae1d81..18418ed 100644 --- a/parsehosts.c +++ b/parsehosts.c @@ -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,10 +152,11 @@ 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') { @@ -162,6 +164,25 @@ void parse_hosts(char *hosts) continue; } + /* 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); + strcpy(ptr, str); + strcat(ptr, macro->rewrite_to); + strcat(ptr, substring); + str = ptr; + } + } + /* Does this IP share QoS class with some other ? */ substring = strstr(str, "sharing-"); if(substring) @@ -259,11 +280,15 @@ void parse_hosts(char *hosts) } } - /* MTU is 1450 bytes = 11600 bits ~= 12 kbit, max is in kb/s */ - ip->pps_limit = ip->max/12; - 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++;