+/* Modified by: xChaos, 20121007 */\r
+\r
+#include "cll1-0.6.2.h"\r
+#include "ipstruct.h"\r
+\r
+#define FIRSTGROUPID 1024\r
+#define FIRSTIPCLASS 2048\r
+\r
+/* globals declared in prometheus.c */\r
+extern struct IP *ips, *ip, *sharedip;\r
+extern struct Group *groups, *group;\r
+extern struct Keyword *keyword, *defaultkeyword, *keywords;\r
+extern int class_count;\r
+extern int ip_count;\r
+extern int found_lmsid;\r
+extern int free_min;\r
+\r
+/* function implemented in prometheus.c */\r
+void TheIP(void);\r
+\r
+/* == This function strips extra characters after IPv4 address and stores it = */\r
+void parse_ip(char *str)\r
+{\r
+ char *ptr, *ipaddr = NULL, *ipname = NULL, *lmsid = NULL;\r
+\r
+ ptr = strchr(str, '{');\r
+ if(ptr)\r
+ {\r
+ lmsid = ++ptr;\r
+ while(*ptr and *ptr != '}')\r
+ {\r
+ ptr++;\r
+ }\r
+ *ptr = 0;\r
+ }\r
+ \r
+ ptr = str;\r
+ while(*ptr and *ptr!=' ' and *ptr!=9)\r
+ {\r
+ ptr++;\r
+ }\r
+ \r
+ *ptr = 0;\r
+ ipaddr = str;\r
+ ptr++;\r
+ while(*ptr and (*ptr==' ' or *ptr==9))\r
+ {\r
+ ptr++;\r
+ }\r
+ ipname=ptr; \r
+ while(*ptr and *ptr!=' ' and *ptr!=9)\r
+ {\r
+ ptr++;\r
+ }\r
+ *ptr=0;\r
+\r
+ if_exists(ip, ips, eq(ip->addr,ipaddr));\r
+ else\r
+ {\r
+ TheIP();\r
+ }\r
+ ip->addr = ipaddr;\r
+ ip->name = ipname;\r
+ if(lmsid)\r
+ {\r
+ ip->lmsid = atoi(lmsid);\r
+ found_lmsid = TRUE;\r
+ }\r
+}\r
+\r
+/* == This function parses hosts style main configuration file == */\r
+void parse_hosts(char *hosts)\r
+{\r
+ int groupidx = FIRSTGROUPID;\r
+ char *str, *ptr;\r
+ char *substring;\r
+\r
+ parse(hosts)\r
+ {\r
+ str=_;\r
+\r
+ if(*str < '0' or *str > '9')\r
+ {\r
+ /* any line starting with non-number is comment ...*/\r
+ continue;\r
+ }\r
+ \r
+ /* Does this IP share QoS class with some other ? */\r
+ substring = strstr(str, "sharing-");\r
+ if(substring)\r
+ { \r
+ substring += 8; /* "sharing-" */\r
+ parse_ip(str);\r
+ ip_count++;\r
+ ip->sharing = substring;\r
+ ip->keyword = defaultkeyword; /* settings for default keyword */\r
+ while(*substring and *substring != '\n')\r
+ {\r
+ substring++;\r
+ }\r
+ *substring = 0; \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
+ {\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
+ {\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
+ 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 sharing-\r
+ }\r
+ fail\r
+ {\r
+ perror(hosts);\r
+ exit(-1);\r
+ }\r
+ done; /* ugly macro end */\r
+}
\ No newline at end of file