X-Git-Url: https://git.harvie.cz/?p=svn%2FPrometheus-QoS%2F.git;a=blobdiff_plain;f=parsehosts.c;h=f356f165b76b9d21fcc36b3382e0aaf7d0eac947;hp=8c9eca159c6d1b3304f8e45342c1c04d2eeaced9;hb=HEAD;hpb=dba7666bdacf8846560e5414b6c9535434e98f8b diff --git a/parsehosts.c b/parsehosts.c index 8c9eca1..cc2548f 100644 --- a/parsehosts.c +++ b/parsehosts.c @@ -11,11 +11,9 @@ extern struct IP *ips, *ip, *sharedip, *networks; extern struct Group *groups, *group; extern struct Keyword *keyword, *defaultkeyword, *keywords; extern struct Macro *macro, *macros; -extern struct Textfile *previous_classmap, *textline; extern int class_count; -extern int mix_new_hosts; extern int ip_count; -extern int found_lmsid; +extern int found_code; extern int free_min; extern const int highest_priority; extern char *ip6prefix; @@ -31,7 +29,7 @@ void TheIP(char *ipaddr, int is_network) ip->addr = ipaddr; ip->sharing = NULL; ip->prio = highest_priority+1; - ip->lmsid = -1; + ip->code = "-----"; ip->fixedprio = \ ip->aggregated = \ ip->mark = \ @@ -59,16 +57,24 @@ void TheIP(char *ipaddr, int is_network) { push(ip, ips); } +#ifdef MONITORINGTRHU_CTU + ip->technology_str = NULL; + ip->ruian_id_str = NULL; +#endif + ip_count++; } +#ifdef MONITORINGTRHU_CTU +struct Technology *technologies = NULL, *technology = NULL; +#endif struct IP *lastIP6range, *lastIP6uplink; /* == This function strips extra characters after IPv4 address and stores it = */ void parse_and_append_ip(char *str, struct IP *listhead) { char *ptr, *ipaddr, *nextip6, *ip6buf; - char *ip6uplink = NULL, *ip6range = NULL, *ipname = NULL, *lmsid = NULL; + char *ip6uplink = NULL, *ip6range = NULL, *ipname = NULL, *code = NULL; if(ip6prefix) /* Try this only if IPv6 subsystem is active... */ { @@ -99,7 +105,7 @@ void parse_and_append_ip(char *str, struct IP *listhead) ptr = strchr(str, '{'); if(ptr) { - lmsid = ++ptr; + code = ++ptr; while(*ptr and *ptr != '}') { ptr++; @@ -138,9 +144,9 @@ void parse_and_append_ip(char *str, struct IP *listhead) } ip->name = ip6range; ip->keyword = defaultkeyword; /* settings for default keyword */ - if(lmsid) + if(code) { - ip->lmsid = atoi(lmsid); + ip->code = code; } lastIP6range = ip; } @@ -157,9 +163,9 @@ void parse_and_append_ip(char *str, struct IP *listhead) TheIP(ip6uplink, FALSE); /* always new IP - more IPs in single uplink network */ ip->name = ip6uplink; ip->keyword = defaultkeyword; /* settings for default keyword */ - if(lmsid) + if(code) { - ip->lmsid = atoi(lmsid); + ip->code = code; } lastIP6uplink = ip; } @@ -174,10 +180,10 @@ void parse_and_append_ip(char *str, struct IP *listhead) TheIP(ipaddr, (listhead==networks)); } ip->name = ipname; - if(lmsid) + if(code) { - ip->lmsid = atoi(lmsid); - found_lmsid = TRUE; + ip->code = code; + found_code = TRUE; } } @@ -253,7 +259,7 @@ void parse_hosts(char *hosts) else { substring = strstr(str, "#255."); - if(substring and not strstr(str, "#255.255.255.255")) /* do not ping /32 uplinks */ + if(substring and not strstr(str, "#255.255.255.255")) /* ignore /32 subnets */ { /* netmask detected - save network*/ unsigned bit; @@ -282,9 +288,45 @@ void parse_hosts(char *hosts) } else { + /* Main branch - most IP addresses go here */ /*Do we have to create new QoS class for this IP ? */ if_exists(keyword,keywords,(substring=strstr(str,keyword->key))) { +#ifdef MONITORINGTRHU_CTU +//special hack only to generate certain required CSV statistics for www.ctu.cz (regulation body) + char *found_at = strchr(str, '@'); + char *ruian_id_str = NULL; + technology = NULL; + if(found_at) + { + int len; + char *found_ruian_end = strchr(found_at, ' '); + char *found_tech_str = found_at; + while(found_tech_str-- > str && *found_tech_str != ' ' && *found_tech_str != '#'); + if(found_tech_str > str) + { + len = found_at - found_tech_str - 1; + for_each(technology, technologies) + if(strlen(technology->filename)==len && !strncmp(technology->filename, found_tech_str + 1, len)) + break; + if(!technology) + { + create(technology,Technology); + string(technology->filename, len + 1); + strncpy(technology->filename, found_tech_str + 1, len); + technology->filename[len] = 0; + push(technology, technologies); + } + if(found_ruian_end) + { + len = found_ruian_end - found_at - 1; + string(ruian_id_str, len + 1); + strncpy(ruian_id_str, found_at + 1, len); + ruian_id_str[len] = 0; + } + } + } +#endif parse_and_append_ip(str, ips); if(lastIP6range) { @@ -333,36 +375,32 @@ void parse_hosts(char *hosts) } } - /* avg MTU bytes * 8 >> 10 = in bits, max is in kb/s */ - pktratio = (ip->keyword->allowed_avgmtu*8) >> 10; - if(pktratio > 0) + if(ip->keyword->allowed_avgmtu) { - ip->pps_limit = ip->max/pktratio; - 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 */ + } } } - if(mix_new_hosts) - for_each(textline, previous_classmap) - { - ptr = strchr(textline->str, ' '); - if(ptr) - { - if(!strncmp(ip->addr, textline->str, ptr-textline->str)) - { - ip->mark = atoi(ptr+1); - printf("Match class: %s %d\n", ip->addr, ip->mark); - } - } - } - - if(!mix_new_hosts || !ip->mark) - ip->mark = FIRSTIPCLASS+1+class_count++; - + ip->mark = FIRSTIPCLASS+1+class_count++; update_network(ip->addr, ip); +#ifdef MONITORINGTRHU_CTU + if(technology) + { + ip->technology_str = technology->filename; + ip->ruian_id_str = ruian_id_str; + /* debug printf("[%s,%d,%s,%d]\n", ip->technology_str,ip->lmsid, ip->ruian_id_str, ip->max); */ + } +#endif + if_exists(group,groups,(group->min == ip->min)) { group->count++; @@ -385,7 +423,7 @@ void parse_hosts(char *hosts) group->desired = ip->min; insert(group, groups, desc_order_by,min); } - }//endif keyword- + }//endif keyword- }//endif netmask }//endif sharing- } @@ -398,4 +436,4 @@ void parse_hosts(char *hosts) // TheIP("0.0.0.0", TRUE); // ip->name = "TOTAL"; // ip->mask = 0; -} +} \ No newline at end of file