-/* Modified by: xChaos, 20121007 */\r
+/* Modified by: xChaos, 20131028 */\r
\r
#include "cll1-0.6.2.h"\r
#include "ipstruct.h"\r
#define FIRSTIPCLASS 2048\r
\r
/* globals declared in prometheus.c */\r
-extern struct IP *ips, *ip, *sharedip;\r
+extern struct IP *ips, *ip, *sharedip, *networks;\r
extern struct Group *groups, *group;\r
extern struct Keyword *keyword, *defaultkeyword, *keywords;\r
extern int class_count;\r
extern int found_lmsid;\r
extern int free_min;\r
extern const int highest_priority;\r
+extern char *ip6prefix;\r
+\r
+struct IP* find_network_for_ip(char *ipaddr_orig);\r
+/* implemented in networks.c */\r
\r
/* This must be object oriented! This looks almost like constructor ;-) */\r
-void TheIP(char *ipaddr)\r
+void TheIP(char *ipaddr, int is_network)\r
{\r
create(ip,IP);\r
ip->name = "";\r
ip->pktsup = \\r
ip->pktsdown = 0;\r
ip->keyword = keywords;\r
- push(ip,ips);\r
+ ip->v6 = (strchr(ip->addr,':')!=NULL);\r
+ ip->mask = ((ip->v6)?64:32);\r
+ if(is_network)\r
+ {\r
+ push(ip, networks);\r
+ }\r
+ else\r
+ {\r
+ push(ip, ips); \r
+ }\r
+ ip_count++;\r
}\r
\r
+struct IP *lastIP6;\r
+\r
/* == This function strips extra characters after IPv4 address and stores it = */\r
-void parse_ip(char *str)\r
+void parse_and_append_ip(char *str, struct IP *listhead)\r
{\r
- char *ptr, *ipaddr = NULL, *ipname = NULL, *lmsid = NULL;\r
+ char *ptr, *ipaddr, *ip6range = NULL, *ipname = NULL, *lmsid = NULL;\r
+\r
+ if(ip6prefix) /* Try this only if IPv6 subsystem is active... */\r
+ {\r
+ ptr = strstr(str, "::");\r
+ if(ptr && ptr-str > 4)\r
+ {\r
+ ptr -= 4; \r
+ duplicate(ptr, ip6range);\r
+ ptr = strstr(ip6range, "::");\r
+ if(ptr)\r
+ {\r
+ *(ptr+2) = 0;\r
+ }\r
+ }\r
+ }\r
\r
ptr = strchr(str, '{');\r
if(ptr)\r
}\r
*ptr=0;\r
\r
- if_exists(ip, ips, eq(ip->addr,ipaddr));\r
+ if(ip6range)\r
+ {\r
+ concatenate(ip6prefix,ip6range,ptr);\r
+ ip6range=ptr;\r
+ if_exists(ip, ips, eq(ip->addr,ip6range));\r
+ else\r
+ {\r
+ TheIP(ip6range, FALSE);\r
+ }\r
+ ip->name = ip6range;\r
+ ip->keyword = defaultkeyword; /* settings for default keyword */\r
+ if(lmsid)\r
+ {\r
+ ip->lmsid = atoi(lmsid);\r
+ }\r
+ lastIP6 = ip;\r
+ }\r
else\r
{\r
- TheIP(ipaddr);\r
+ lastIP6 = NULL;\r
+ }\r
+\r
+ if_exists(ip, listhead, eq(ip->addr,ipaddr));\r
+ else\r
+ {\r
+ TheIP(ipaddr, (listhead==networks));\r
}\r
ip->name = ipname;\r
if(lmsid)\r
int groupidx = FIRSTGROUPID;\r
char *str, *ptr;\r
char *substring;\r
+ struct IP *network;\r
\r
parse(hosts)\r
{\r
if(substring)\r
{ \r
substring += 8; /* "sharing-" */\r
- parse_ip(str);\r
- ip_count++;\r
+ parse_and_append_ip(str, ips);\r
ip->sharing = substring;\r
ip->keyword = defaultkeyword; /* settings for default keyword */\r
+ if(lastIP6)\r
+ {\r
+ lastIP6->sharing = substring;\r
+ lastIP6 = NULL;\r
+ }\r
while(*substring and *substring != '\n')\r
{\r
substring++;\r
}\r
else\r
{\r
- /*Do we have to create new QoS class for this IP ? */\r
-\r
- if_exists(keyword,keywords,(substring=strstr(str,keyword->key)))\r
+ substring = strstr(str, "#255.");\r
+ if(substring and not strstr(str, "#255.255.255.255")) /* do not ping /32 ranges */\r
{\r
- parse_ip(str);\r
- ip_count++;\r
- ip->keyword = keyword;\r
- keyword->ip_count++;\r
- ip->prio = keyword->default_prio;\r
- substring += strlen(keyword->key)+1;\r
- ptr = substring;\r
- while(*ptr and *ptr != '-')\r
+ /* netmask detected - save network*/\r
+ unsigned bit;\r
+ unsigned num, mask = 8;\r
+ substring += 5;\r
+ while(substring && *substring)\r
{\r
- ptr++;\r
- }\r
- if(*ptr == '-')\r
- {\r
- *ptr=0;\r
- ip->max = ip->desired = atoi(ptr+1);\r
- }\r
- ip->min = atoi(substring);\r
- if(ip->min <= 0)\r
- {\r
- printf(" %s: Illegal value of minimum bandwidth 0 kbps, using %d kb/s\n",\r
- str, free_min);\r
- ip->min = free_min;\r
- }\r
- if(ip->max <= ip->min)\r
- {\r
- ip->fixedprio = TRUE;\r
- ip->max = ip->min + ip->keyword->reserve_min;\r
- }\r
- else \r
- {\r
- ip->max -= ip->keyword->reserve_max;\r
- if(ip->max<ip->min)\r
+ ptr = substring;\r
+ substring = strchr(substring, '.');\r
+ if(substring)\r
{\r
- ip->max=ip->min;\r
+ *substring = 0;\r
+ substring += 1;\r
}\r
- }\r
- ip->mark = FIRSTIPCLASS+1+class_count++;\r
-\r
- if_exists(group,groups,(group->min == ip->min)) \r
- { \r
- group->count++; \r
- group->desired += ip->min;\r
- ip->group = group->id; \r
- }\r
- else\r
+ num = atoi(ptr);\r
+ for(bit = 1; bit <=128 ; bit<<=1)\r
+ {\r
+ if(bit & num)\r
+ {\r
+ mask++;\r
+ }\r
+ }\r
+ } \r
+ parse_and_append_ip(str, networks);\r
+ ip->mask = mask;\r
+ }\r
+ else\r
+ {\r
+ /*Do we have to create new QoS class for this IP ? */\r
+ if_exists(keyword,keywords,(substring=strstr(str,keyword->key)))\r
{\r
- create(group,Group);\r
- group->min = ip->min;\r
- group->id = groupidx++;\r
- ip->group = group->id;\r
-\r
- if(group->min < 8) group->min = 8;\r
- /* Warning - this is maybe because of primitive tc namespace, can be fixed */\r
- /* it is because class IDs are derived from min. bandwidth. - xCh */\r
- //if(group->min>MAX_GUARANTED_KBPS) group->min=MAX_GUARANTED_KBPS;\r
- \r
- group->count = 1;\r
- group->desired = ip->min; \r
- insert(group, groups, desc_order_by,min);\r
- }\r
- }//endif keyword-\r
+ parse_and_append_ip(str, ips);\r
+ if(lastIP6)\r
+ {\r
+ lastIP6->sharing = ip->name;\r
+ lastIP6 = NULL;\r
+ }\r
+ ip->keyword = keyword;\r
+ keyword->ip_count++;\r
+ ip->prio = keyword->default_prio;\r
+ substring += strlen(keyword->key)+1;\r
+ ptr = substring;\r
+ while(*ptr and *ptr != '-')\r
+ {\r
+ ptr++;\r
+ }\r
+ if(*ptr == '-')\r
+ {\r
+ *ptr=0;\r
+ ip->max = ip->desired = atoi(ptr+1);\r
+ }\r
+ ip->min = atoi(substring);\r
+ if(ip->min <= 0)\r
+ {\r
+ printf(" %s: Illegal value of minimum bandwidth 0 kbps, using %d kb/s\n",\r
+ str, free_min);\r
+ ip->min = free_min;\r
+ }\r
+ if(ip->max <= ip->min)\r
+ {\r
+ ip->fixedprio = TRUE;\r
+ ip->max = ip->min + ip->keyword->reserve_min;\r
+ }\r
+ else \r
+ {\r
+ ip->max -= ip->keyword->reserve_max;\r
+ if(ip->max<ip->min)\r
+ {\r
+ ip->max=ip->min;\r
+ }\r
+ }\r
+ ip->mark = FIRSTIPCLASS+1+class_count++;\r
+\r
+ network = find_network_for_ip(ip->addr);\r
+ if(network)\r
+ {\r
+ network->min += ip->min;\r
+ network->desired += ip->max;\r
+ if(ip->max > network->max)\r
+ {\r
+ network->max = ip->max;\r
+ }\r
+ }\r
+\r
+ if_exists(group,groups,(group->min == ip->min)) \r
+ { \r
+ group->count++; \r
+ group->desired += ip->min;\r
+ ip->group = group->id; \r
+ }\r
+ else\r
+ {\r
+ create(group,Group);\r
+ group->min = ip->min;\r
+ group->id = groupidx++;\r
+ ip->group = group->id;\r
+\r
+ if(group->min < 8) group->min = 8;\r
+ /* Warning - this is maybe because of primitive tc namespace, can be fixed */\r
+ /* it is because class IDs are derived from min. bandwidth. - xCh */\r
+ //if(group->min>MAX_GUARANTED_KBPS) group->min=MAX_GUARANTED_KBPS;\r
+ \r
+ group->count = 1;\r
+ group->desired = ip->min; \r
+ insert(group, groups, desc_order_by,min);\r
+ }\r
+ }//endif keyword-\r
+ }//endif netmask\r
}//endif sharing-\r
}\r
fail\r