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 struct Textfile
*previous_classmap
, *textline
;
15 extern int class_count
;
16 extern int mix_new_hosts
;
18 extern int found_lmsid
;
20 extern const int highest_priority
;
21 extern char *ip6prefix
;
23 void update_network(char *look_for
, struct IP
* ip
);
24 /* implemented in networks.c */
26 /* This must be object oriented! This looks almost like constructor ;-) */
27 void TheIP(char *ipaddr
, int is_network
)
33 ip
->prio
= highest_priority
+1;
51 ip
->keyword
= keywords
;
52 ip
->v6
= (strchr(ip
->addr
,':')!=NULL
);
53 ip
->mask
= ((ip
->v6
)?64:32);
65 struct IP
*lastIP6range
, *lastIP6uplink
;
67 /* == This function strips extra characters after IPv4 address and stores it = */
68 void parse_and_append_ip(char *str
, struct IP
*listhead
)
70 char *ptr
, *ipaddr
, *nextip6
, *ip6buf
;
71 char *ip6uplink
= NULL
, *ip6range
= NULL
, *ipname
= NULL
, *lmsid
= NULL
;
73 if(ip6prefix
) /* Try this only if IPv6 subsystem is active... */
75 ptr
= strstr(str
, "::");
76 while(ptr
&& ptr
-str
> 4)
78 nextip6
= strstr(ptr
+ 2, "::");
80 duplicate(ptr
, ip6buf
);
81 ptr
= strstr(ip6buf
, "::");
86 *(ptr
+3) = 0; /* ends with ::+ */
91 *(ptr
+2) = 0; /* ends with :: */
99 ptr
= strchr(str
, '{');
103 while(*ptr
and *ptr
!= '}')
111 while(*ptr
and *ptr
!=' ' and *ptr
!=9)
119 while(*ptr
and (*ptr
==' ' or *ptr
==9))
124 while(*ptr
and *ptr
!=' ' and *ptr
!=9)
132 concatenate(ip6prefix
,ip6range
,ptr
);
134 if_exists(ip
, ips
, eq(ip
->addr
,ip6range
)); /* check - allocated range must be unique */
137 TheIP(ip6range
, FALSE
);
140 ip
->keyword
= defaultkeyword
; /* settings for default keyword */
143 ip
->lmsid
= atoi(lmsid
);
152 /* it is ugly to copy+paste and search+replace, but... */
155 concatenate(ip6prefix
,ip6uplink
,ptr
);
157 TheIP(ip6uplink
, FALSE
); /* always new IP - more IPs in single uplink network */
158 ip
->name
= ip6uplink
;
159 ip
->keyword
= defaultkeyword
; /* settings for default keyword */
162 ip
->lmsid
= atoi(lmsid
);
168 lastIP6uplink
= NULL
;
171 if_exists(ip
, listhead
, eq(ip
->addr
,ipaddr
));
174 TheIP(ipaddr
, (listhead
==networks
));
179 ip
->lmsid
= atoi(lmsid
);
184 /* == This function parses hosts style main configuration file == */
185 void parse_hosts(char *hosts
)
187 int groupidx
= FIRSTGROUPID
;
197 if(*str
< '0' or *str
> '9')
199 /* any line starting with non-number is comment ...*/
203 ptr
= strchr(str
,'\r'); /* fore unix-style end of line */
209 /* first, expand (rewrite) any predefined macros, if found*/
210 for_each(macro
, macros
)
212 substring
= strstr(str
, macro
->rewrite_from
);
217 substring
+= strlen(macro
->rewrite_from
);
219 l3
= strlen(substring
);
220 string(ptr
, l1
+ strlen(macro
->rewrite_to
) + l3
+ 1);
222 strcat(ptr
, macro
->rewrite_to
);
223 strcat(ptr
, substring
);
225 /* printf("REWRITE: %s -> %s\n",_,str); */
229 /* Does this IP share QoS class with some other ? */
230 substring
= strstr(str
, "sharing-");
233 substring
+= 8; /* "sharing-" */
234 parse_and_append_ip(str
, ips
);
235 ip
->sharing
= substring
;
236 ip
->keyword
= defaultkeyword
; /* settings for default keyword */
239 lastIP6range
->sharing
= substring
;
244 lastIP6uplink
->sharing
= substring
;
245 lastIP6uplink
= NULL
;
247 while(*substring
and *substring
!= '\n')
255 substring
= strstr(str
, "#255.");
256 if(substring
and not strstr(str
, "#255.255.255.255")) /* do not ping /32 uplinks */
258 /* netmask detected - save network*/
260 unsigned num
, mask
= 8;
262 while(substring
&& *substring
)
265 substring
= strchr(substring
, '.');
272 for(bit
= 1; bit
<=128 ; bit
<<=1)
280 parse_and_append_ip(str
, networks
);
285 /*Do we have to create new QoS class for this IP ? */
286 if_exists(keyword
,keywords
,(substring
=strstr(str
,keyword
->key
)))
288 parse_and_append_ip(str
, ips
);
291 lastIP6range
->sharing
= ip
->name
;
296 lastIP6uplink
->sharing
= ip
->name
;
297 lastIP6uplink
= NULL
;
299 ip
->keyword
= keyword
;
301 ip
->prio
= keyword
->default_prio
;
302 substring
+= strlen(keyword
->key
)+1;
304 while(*ptr
and *ptr
!= '-')
311 ip
->max
= ip
->desired
= atoi(ptr
+1);
314 ip
->min
= atoi(substring
);
317 printf(" %s: Illegal value of minimum bandwidth 0 kbps, using %d kb/s\n",
322 if(ip
->max
<= ip
->min
)
324 ip
->fixedprio
= TRUE
;
325 ip
->max
= ip
->min
+ ip
->keyword
->reserve_min
;
329 ip
->max
-= ip
->keyword
->reserve_max
;
330 if(ip
->max
< ip
->min
)
336 /* avg MTU bytes * 8 >> 10 = in bits, max is in kb/s */
337 pktratio
= (ip
->keyword
->allowed_avgmtu
*8) >> 10;
340 ip
->pps_limit
= ip
->max
/pktratio
;
341 if(ip
->pps_limit
> 10000) /* this limit seems to be hardcoded in iptables */
343 ip
->pps_limit
= 0; /* do not apply packet limits */
348 for_each(textline
, previous_classmap
)
350 ptr
= strchr(textline
->str
, ' ');
353 if(!strncmp(ip
->addr
, textline
->str
, ptr
-textline
->str
))
355 ip
->mark
= atoi(ptr
+1);
356 printf("Match class: %s %d\n", ip
->addr
, ip
->mark
);
361 if(!mix_new_hosts
|| !ip
->mark
)
362 ip
->mark
= FIRSTIPCLASS
+1+class_count
++;
364 update_network(ip
->addr
, ip
);
366 if_exists(group
,groups
,(group
->min
== ip
->min
))
369 group
->desired
+= ip
->min
;
370 ip
->group
= group
->id
;
375 group
->min
= ip
->min
;
376 group
->id
= groupidx
++;
377 ip
->group
= group
->id
;
379 if(group
->min
< 8) group
->min
= 8;
380 /* Warning - this is maybe because of primitive tc namespace, can be fixed */
381 /* it is because class IDs are derived from min. bandwidth. - xCh */
382 //if(group->min>MAX_GUARANTED_KBPS) group->min=MAX_GUARANTED_KBPS;
385 group
->desired
= ip
->min
;
386 insert(group
, groups
, desc_order_by
,min
);
397 done
; /* ugly macro end */
398 // TheIP("0.0.0.0", TRUE);
399 // ip->name = "TOTAL";
This page took 0.411112 seconds and 4 git commands to generate.