X-Git-Url: http://git.harvie.cz/?p=svn%2FPrometheus-QoS%2F.git;a=blobdiff_plain;f=parsehosts.c;h=18418eddb6b9c587d6ec23925a71c6f8ed011c48;hp=bcf222e86cb8991e029841ba75bec82dd23908d0;hb=bb5e73853e892f8bce70e03344a81b192c2b84ff;hpb=2b460b72764116f1846fbb5f51299e4cc8074b9a diff --git a/parsehosts.c b/parsehosts.c index bcf222e..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; @@ -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,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') { @@ -161,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) @@ -235,6 +257,7 @@ void parse_hosts(char *hosts) *ptr=0; ip->max = ip->desired = atoi(ptr+1); } + ip->min = atoi(substring); if(ip->min <= 0) { @@ -242,6 +265,7 @@ void parse_hosts(char *hosts) str, free_min); ip->min = free_min; } + if(ip->max <= ip->min) { ip->fixedprio = TRUE; @@ -250,13 +274,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; + } + } + + /* 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->max=ip->min; + ip->pps_limit = 0; /* do not apply packet limits */ } } - ip->mark = FIRSTIPCLASS+1+class_count++; + ip->mark = FIRSTIPCLASS+1+class_count++; update_network(ip->addr, ip); if_exists(group,groups,(group->min == ip->min)) @@ -291,4 +326,7 @@ void parse_hosts(char *hosts) exit(-1); } done; /* ugly macro end */ +// TheIP("0.0.0.0", TRUE); +// ip->name = "TOTAL"; +// ip->mask = 0; } \ No newline at end of file