X-Git-Url: http://git.harvie.cz/?p=svn%2FPrometheus-QoS%2F.git;a=blobdiff_plain;f=parsehosts.c;h=18418eddb6b9c587d6ec23925a71c6f8ed011c48;hp=04fce9ffca9714d2fbfbc474f49d91211477d154;hb=bb5e73853e892f8bce70e03344a81b192c2b84ff;hpb=af37be1dccdd5c9b86113a6e02ed794da3102ec4 diff --git a/parsehosts.c b/parsehosts.c index 04fce9f..18418ed 100644 --- a/parsehosts.c +++ b/parsehosts.c @@ -1,4 +1,4 @@ -/* Modified by: xChaos, 20131028 */ +/* Modified by: xChaos, 20131029 */ #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; @@ -17,7 +18,7 @@ extern int free_min; extern const int highest_priority; extern char *ip6prefix; -struct IP* find_network_for_ip(char *ipaddr_orig); +void update_network(char *look_for, struct IP* ip); /* implemented in networks.c */ /* This must be object oriented! This looks almost like constructor ;-) */ @@ -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,24 +274,26 @@ 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++; - network = find_network_for_ip(ip->addr); - if(network) + /* avg MTU bytes * 8 >> 10 = in bits, max is in kb/s */ + pktratio = (ip->keyword->allowed_avgmtu*8) >> 10; + if(pktratio > 0) { - network->min += ip->min; - network->desired += ip->max; - if(ip->max > network->max) + ip->pps_limit = ip->max/pktratio; + if(ip->pps_limit > 10000) /* this limit seems to be hardcoded in iptables */ { - network->max = ip->max; + 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)) { group->count++; @@ -300,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