X-Git-Url: http://git.harvie.cz/?p=svn%2FPrometheus-QoS%2F.git;a=blobdiff_plain;f=parsehosts.c;h=1e8dbe6773502e9b18f580570257cba552fe20df;hp=d17c61917c32ad0235da1f3b036b768e3b56e27b;hb=c2237b8a65286bff65d5bd81e48cb88fb7d2562e;hpb=f19d3cd0bca8ef24e8c78fb6ae24346dc3b7db36 diff --git a/parsehosts.c b/parsehosts.c index d17c619..1e8dbe6 100644 --- a/parsehosts.c +++ b/parsehosts.c @@ -15,6 +15,7 @@ extern int ip_count; extern int found_lmsid; extern int free_min; extern const int highest_priority; +extern char *ip6prefix; /* This must be object oriented! This looks almost like constructor ;-) */ void TheIP(char *ipaddr) @@ -38,13 +39,32 @@ void TheIP(char *ipaddr) ip->pktsup = \ ip->pktsdown = 0; ip->keyword = keywords; + ip->v6 = (strchr(ip->addr,':')!=NULL); push(ip,ips); + ip_count++; } +struct IP *lastIP6; + /* == This function strips extra characters after IPv4 address and stores it = */ -void parse_ip(char *str) +parse_ip(char *str) { - char *ptr, *ipaddr = NULL, *ipname = NULL, *lmsid = NULL; + char *ptr, *ipaddr, *ip6range = NULL, *ipname = NULL, *lmsid = NULL; + + if(ip6prefix) /* Try this only if IPv6 subsystem is active... */ + { + ptr = strstr(str, "::"); + if(ptr && ptr-str > 4) + { + ptr -= 4; + duplicate(ptr, ip6range); + ptr = strstr(ip6range, "::"); + if(ptr) + { + *(ptr+2) = 0; + } + } + } ptr = strchr(str, '{'); if(ptr) @@ -77,6 +97,28 @@ void parse_ip(char *str) } *ptr=0; + if(ip6range) + { + concatenate(ip6prefix,ip6range,ptr); + ip6range=ptr; + if_exists(ip, ips, eq(ip->addr,ip6range)); + else + { + TheIP(ip6range); + } + ip->name = ip6range; + ip->keyword = defaultkeyword; /* settings for default keyword */ + if(lmsid) + { + ip->lmsid = atoi(lmsid); + } + lastIP6 = ip; + } + else + { + lastIP6 = NULL; + } + if_exists(ip, ips, eq(ip->addr,ipaddr)); else { @@ -113,9 +155,13 @@ void parse_hosts(char *hosts) { substring += 8; /* "sharing-" */ parse_ip(str); - ip_count++; ip->sharing = substring; ip->keyword = defaultkeyword; /* settings for default keyword */ + if(lastIP6) + { + lastIP6->sharing = substring; + lastIP6 = NULL; + } while(*substring and *substring != '\n') { substring++; @@ -129,7 +175,11 @@ void parse_hosts(char *hosts) if_exists(keyword,keywords,(substring=strstr(str,keyword->key))) { parse_ip(str); - ip_count++; + if(lastIP6) + { + lastIP6->sharing = ip->name; + lastIP6 = NULL; + } ip->keyword = keyword; keyword->ip_count++; ip->prio = keyword->default_prio;