--- /dev/null
+/* 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
/* Credit: CZFree.Net,Martin Devera,Netdave,Aquarius,Gandalf */\r
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */\r
\r
-/* Modified by: xChaos, 20120612\r
+/* Modified by: xChaos, 20121007\r
ludva, 20080415\r
\r
Prometheus QoS is free software; you can redistribute it and/or\r
GNU General Public License is located in file COPYING */\r
\r
#define STRLEN 512\r
-#define FIRSTGROUPID 1024\r
-#define FIRSTIPCLASS 2048\r
#undef DEBUG\r
\r
#include "cll1-0.6.2.h"\r
+#include "ipstruct.h"\r
\r
-const char *version = "0.8.3-f";\r
+const char *version = "0.8.3-g";\r
\r
/* Version numbers: 0.8.3 is development releases ("beta"), 0.8.4 will be "stable" */\r
/* Debian(RPM) package versions/patchlevels: 0.7.9-2, 0.8.0-1, 0.8.0-2, etc. */\r
void parse_ip_log(int argc, char **argv);\r
/* implementid in parselog.c */\r
\r
+void parse_hosts(char *hosts);\r
+/* implementid in parsehosts.c */\r
+\r
const char *tr_odd_even(void)\r
{\r
row_odd_even = 1 - row_odd_even;\r
int burst_group = 32;\r
int magic_treshold = 8; /* reduce ceil by X*magic_treshhold kbps (hard shaping) */\r
int keywordcount = 0;\r
+int class_count = 0;\r
+int ip_count = 0;\r
/* not yet implemented:\r
int fixed_packets = 0; maximum number of pps per IP address (not class!) \r
int packet_limit = 5; maximum number of pps to htn CEIL, not rate !!! \r
const int idxtable_bitmask1 = 3; /* this is no longer configurable */\r
const int idxtable_bitmask2 = 3; /* this is no longer configurable */\r
\r
-/* ==== This is C<<1 stuff - learn C<<1 first! https://dev.arachne.cz/svn/cll1h ==== */\r
+struct IP *ips = NULL, *ip, *sharedip;\r
+struct Group *groups = NULL, *group;\r
+struct Keyword *keyword, *defaultkeyword=NULL, *keywords=NULL;\r
\r
-struct IP\r
-{\r
- char *addr;\r
- char *name;\r
- char *sharing;\r
- int min;\r
- int desired;\r
- int max;\r
- int mark;\r
- int prio;\r
- int fixedprio;\r
- int group;\r
- int lmsid;\r
- unsigned long long direct;\r
- unsigned long long proxy;\r
- unsigned long long upload;\r
- unsigned long long traffic;\r
- unsigned long long credit;\r
- unsigned long pktsup;\r
- unsigned long pktsdown;\r
- struct Keyword *keyword;\r
- list(IP);\r
-} *ips=NULL, *ip, *sharedip;\r
-\r
-struct Group\r
-{\r
- int min;\r
- int count;\r
- int desired;\r
- int id;\r
- list(Group);\r
-} *groups=NULL, *group;\r
+/* ==== This is C<<1 stuff - learn C<<1 first! https://dev.arachne.cz/svn/cll1h ==== */\r
\r
struct Index\r
{\r
list(Index);\r
} *idxs=NULL, *idx, *metaindex;\r
\r
-struct Keyword\r
-{\r
- char *key;\r
- \r
- int asymetry_ratio; /* ratio for ADSL-like upload */\r
- int asymetry_fixed; /* fixed treshold for ADSL-like upload */\r
- int data_limit; /* hard shaping: apply magic_treshold if max*data_limit MB exceeded */\r
- int data_prio; /* soft shaping (qos): reduce HTB prio if max*data_prio MB exceeded */\r
- long fixed_limit; /* fixed data limit for setting lower HTB ceil */\r
- long fixed_prio; /* fixed data lmit for setting lower HTB prio */\r
- int reserve_min; /* bonus for nominal HTB rate bandwidth (in kbps) */\r
- int reserve_max; /* malus for nominal HTB ceil (in kbps) */\r
-// int divide_max; /* relative malus: new_ceil=rate+(old_ceil-rate)/divide_max */\r
-// int htb_ceil_bonus_divide; /* relative bonus: new_ceil=old_ceil+old_ceil/htb_ceil_bonus_divide */\r
- int default_prio; /* default HTB priority for this keyword */\r
- char *html_color;\r
- int ip_count;\r
- char *leaf_discipline;\r
- \r
- list(Keyword);\r
-} *keyword,*defaultkeyword=NULL,*keywords=NULL;\r
\r
/* Damned, this must be object oriented! This looks almost like constructor ;-) */\r
\r
free(restor);\r
}\r
\r
-/* == This function strips extra characters after IP address and stores it = */\r
-\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 && *ptr!='}')\r
- {\r
- ptr++;\r
- }\r
- *ptr=0;\r
- }\r
- \r
- ptr=str;\r
- while(*ptr && *ptr!=' ' && *ptr!=9)\r
- {\r
- ptr++;\r
- }\r
- \r
- *ptr=0;\r
- ipaddr=str;\r
- ptr++;\r
- while(*ptr && (*ptr==' ' || *ptr==9))\r
- {\r
- ptr++;\r
- }\r
- ipname=ptr; \r
- while(*ptr && *ptr!=' ' && *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=1;\r
- }\r
-}\r
-\r
char *parse_datafile_line(char *str)\r
{\r
char *ptr=strchr(str,' ');\r
}\r
}\r
\r
-\r
-\r
-\r
void append_log(struct IP *self) /*using global variables*/\r
{\r
char *d, *str;\r
}\r
}\r
\r
-\r
/*-----------------------------------------------------------------*/\r
/* Are you looking for int main(int argc, char **argv) ? :-)) */\r
/*-----------------------------------------------------------------*/\r
FILE *f=NULL; /* everything is just stream of bytes... */\r
char *str, *ptr, *d; /* LET A$=B$ :-) */\r
char *substring;\r
- int class_count=0,ip_count=0;\r
+\r
int parent=1;\r
int just_flush=FALSE; /* deactivates all previous actions */\r
int nodelay=FALSE;\r
/*-----------------------------------------------------------------*/\r
printf("Parsing class defintion file %s ...\n", hosts);\r
/*-----------------------------------------------------------------*/\r
- int groupidx = FIRSTGROUPID;\r
- parse(hosts)\r
- {\r
- str=_;\r
-\r
- if(*str<'0' || *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 && *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 && *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 = 1;\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
+ parse_hosts(hosts);\r
\r
/*-----------------------------------------------------------------*/\r
/* cll1.h - let's allocate brand new character buffer... */\r
ip->lmsid=sharedip->lmsid;\r
break;\r
}\r
- if(!sharedip)\r
+ if(not sharedip)\r
{\r
printf("Unresolved shared connection: %s %s sharing-%s\n",\r
ip->addr, ip->name, ip->sharing);\r