1 /* Modified by: xChaos, 20131220 */
3 #include "cll1-0.6.2.h"
6 #define FIRSTGROUPID 1024
7 #define FIRSTIPCLASS 2048
9 /* globals declared in prometheus.c */
10 extern struct IP
*ips
, *ip
, *sharedip
, *networks
;
11 extern struct Group
*groups
, *group
;
12 extern struct Keyword
*keyword
, *defaultkeyword
, *keywords
;
13 extern struct Macro
*macro
, *macros
;
14 extern int class_count
;
16 extern int found_code
;
18 extern const int highest_priority
;
19 extern char *ip6prefix
;
21 void update_network(char *look_for
, struct IP
* ip
);
22 /* implemented in networks.c */
24 /* This must be object oriented! This looks almost like constructor ;-) */
25 void TheIP(char *ipaddr
, int is_network
)
31 ip
->prio
= highest_priority
+1;
49 ip
->keyword
= keywords
;
50 ip
->v6
= (strchr(ip
->addr
,':')!=NULL
);
51 ip
->mask
= ((ip
->v6
)?64:32);
60 #ifdef MONITORINGTRHU_CTU
61 ip
->technology_str
= NULL
;
62 ip
->ruian_id_str
= NULL
;
68 #ifdef MONITORINGTRHU_CTU
69 struct Technology
*technologies
= NULL
, *technology
= NULL
;
71 struct IP
*lastIP6range
, *lastIP6uplink
;
73 /* == This function strips extra characters after IPv4 address and stores it = */
74 void parse_and_append_ip(char *str
, struct IP
*listhead
)
76 char *ptr
, *ipaddr
, *nextip6
, *ip6buf
;
77 char *ip6uplink
= NULL
, *ip6range
= NULL
, *ipname
= NULL
, *code
= NULL
;
79 if(ip6prefix
) /* Try this only if IPv6 subsystem is active... */
81 ptr
= strstr(str
, "::");
82 while(ptr
&& ptr
-str
> 4)
84 nextip6
= strstr(ptr
+ 2, "::");
86 duplicate(ptr
, ip6buf
);
87 ptr
= strstr(ip6buf
, "::");
92 *(ptr
+3) = 0; /* ends with ::+ */
97 *(ptr
+2) = 0; /* ends with :: */
105 ptr
= strchr(str
, '{');
109 while(*ptr
and *ptr
!= '}')
117 while(*ptr
and *ptr
!=' ' and *ptr
!=9)
125 while(*ptr
and (*ptr
==' ' or *ptr
==9))
130 while(*ptr
and *ptr
!=' ' and *ptr
!=9)
138 concatenate(ip6prefix
,ip6range
,ptr
);
140 if_exists(ip
, ips
, eq(ip
->addr
,ip6range
)); /* check - allocated range must be unique */
143 TheIP(ip6range
, FALSE
);
146 ip
->keyword
= defaultkeyword
; /* settings for default keyword */
158 /* it is ugly to copy+paste and search+replace, but... */
161 concatenate(ip6prefix
,ip6uplink
,ptr
);
163 TheIP(ip6uplink
, FALSE
); /* always new IP - more IPs in single uplink network */
164 ip
->name
= ip6uplink
;
165 ip
->keyword
= defaultkeyword
; /* settings for default keyword */
174 lastIP6uplink
= NULL
;
177 if_exists(ip
, listhead
, eq(ip
->addr
,ipaddr
));
180 TheIP(ipaddr
, (listhead
==networks
));
190 /* == This function parses hosts style main configuration file == */
191 void parse_hosts(char *hosts
)
193 int groupidx
= FIRSTGROUPID
;
203 if(*str
< '0' or *str
> '9')
205 /* any line starting with non-number is comment ...*/
209 ptr
= strchr(str
,'\r'); /* fore unix-style end of line */
215 /* first, expand (rewrite) any predefined macros, if found*/
216 for_each(macro
, macros
)
218 substring
= strstr(str
, macro
->rewrite_from
);
223 substring
+= strlen(macro
->rewrite_from
);
225 l3
= strlen(substring
);
226 string(ptr
, l1
+ strlen(macro
->rewrite_to
) + l3
+ 1);
228 strcat(ptr
, macro
->rewrite_to
);
229 strcat(ptr
, substring
);
231 /* printf("REWRITE: %s -> %s\n",_,str); */
235 /* Does this IP share QoS class with some other ? */
236 substring
= strstr(str
, "sharing-");
239 substring
+= 8; /* "sharing-" */
240 parse_and_append_ip(str
, ips
);
241 ip
->sharing
= substring
;
242 ip
->keyword
= defaultkeyword
; /* settings for default keyword */
245 lastIP6range
->sharing
= substring
;
250 lastIP6uplink
->sharing
= substring
;
251 lastIP6uplink
= NULL
;
253 while(*substring
and *substring
!= '\n')
261 substring
= strstr(str
, "#255.");
262 if(substring
and not strstr(str
, "#255.255.255.255")) /* ignore /32 subnets */
264 /* netmask detected - save network*/
266 unsigned num
, mask
= 8;
268 while(substring
&& *substring
)
271 substring
= strchr(substring
, '.');
278 for(bit
= 1; bit
<=128 ; bit
<<=1)
286 parse_and_append_ip(str
, networks
);
291 /* Main branch - most IP addresses go here */
292 /*Do we have to create new QoS class for this IP ? */
293 if_exists(keyword
,keywords
,(substring
=strstr(str
,keyword
->key
)))
295 #ifdef MONITORINGTRHU_CTU
296 //special hack only to generate certain required CSV statistics for www.ctu.cz (regulation body)
297 char *found_at
= strchr(str
, '@');
298 char *ruian_id_str
= NULL
;
303 char *found_ruian_end
= strchr(found_at
, ' ');
304 char *found_tech_str
= found_at
;
305 while(found_tech_str
-- > str
&& *found_tech_str
!= ' ' && *found_tech_str
!= '#');
306 if(found_tech_str
> str
)
308 len
= found_at
- found_tech_str
- 1;
309 for_each(technology
, technologies
)
310 if(strlen(technology
->filename
)==len
&& !strncmp(technology
->filename
, found_tech_str
+ 1, len
))
314 create(technology
,Technology
);
315 string(technology
->filename
, len
+ 1);
316 strncpy(technology
->filename
, found_tech_str
+ 1, len
);
317 technology
->filename
[len
] = 0;
318 push(technology
, technologies
);
322 len
= found_ruian_end
- found_at
- 1;
323 string(ruian_id_str
, len
+ 1);
324 strncpy(ruian_id_str
, found_at
+ 1, len
);
325 ruian_id_str
[len
] = 0;
330 parse_and_append_ip(str
, ips
);
333 lastIP6range
->sharing
= ip
->name
;
338 lastIP6uplink
->sharing
= ip
->name
;
339 lastIP6uplink
= NULL
;
341 ip
->keyword
= keyword
;
343 ip
->prio
= keyword
->default_prio
;
344 substring
+= strlen(keyword
->key
)+1;
346 while(*ptr
and *ptr
!= '-')
353 ip
->max
= ip
->desired
= atoi(ptr
+1);
356 ip
->min
= atoi(substring
);
359 printf(" %s: Illegal value of minimum bandwidth 0 kbps, using %d kb/s\n",
364 if(ip
->max
<= ip
->min
)
366 ip
->fixedprio
= TRUE
;
367 ip
->max
= ip
->min
+ ip
->keyword
->reserve_min
;
371 ip
->max
-= ip
->keyword
->reserve_max
;
372 if(ip
->max
< ip
->min
)
378 if(ip
->keyword
->allowed_avgmtu
)
380 /* avg MTU bytes * 8 >> 10 = in bits, max is in kb/s */
381 pktratio
= (ip
->keyword
->allowed_avgmtu
*8) >> 10;
384 ip
->pps_limit
= ip
->max
/pktratio
;
385 if(ip
->pps_limit
> 10000) /* this limit seems to be hardcoded in iptables */
387 ip
->pps_limit
= 0; /* do not apply packet limits */
392 ip
->mark
= FIRSTIPCLASS
+1+class_count
++;
393 update_network(ip
->addr
, ip
);
395 #ifdef MONITORINGTRHU_CTU
398 ip
->technology_str
= technology
->filename
;
399 ip
->ruian_id_str
= ruian_id_str
;
400 /* debug printf("[%s,%d,%s,%d]\n", ip->technology_str,ip->lmsid, ip->ruian_id_str, ip->max); */
404 if_exists(group
,groups
,(group
->min
== ip
->min
))
407 group
->desired
+= ip
->min
;
408 ip
->group
= group
->id
;
413 group
->min
= ip
->min
;
414 group
->id
= groupidx
++;
415 ip
->group
= group
->id
;
417 if(group
->min
< 8) group
->min
= 8;
418 /* Warning - this is maybe because of primitive tc namespace, can be fixed */
419 /* it is because class IDs are derived from min. bandwidth. - xCh */
420 //if(group->min>MAX_GUARANTED_KBPS) group->min=MAX_GUARANTED_KBPS;
423 group
->desired
= ip
->min
;
424 insert(group
, groups
, desc_order_by
,min
);
435 done
; /* ugly macro end */
436 // TheIP("0.0.0.0", TRUE);
437 // ip->name = "TOTAL";
This page took 0.491617 seconds and 4 git commands to generate.