1 /* Modified by: xChaos, 20131029 */
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_lmsid
;
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;
46 ip
->keyword
= keywords
;
47 ip
->v6
= (strchr(ip
->addr
,':')!=NULL
);
48 ip
->mask
= ((ip
->v6
)?64:32);
62 /* == This function strips extra characters after IPv4 address and stores it = */
63 void parse_and_append_ip(char *str
, struct IP
*listhead
)
65 char *ptr
, *ipaddr
, *ip6range
= NULL
, *ipname
= NULL
, *lmsid
= NULL
;
67 if(ip6prefix
) /* Try this only if IPv6 subsystem is active... */
69 ptr
= strstr(str
, "::");
70 if(ptr
&& ptr
-str
> 4)
73 duplicate(ptr
, ip6range
);
74 ptr
= strstr(ip6range
, "::");
82 ptr
= strchr(str
, '{');
86 while(*ptr
and *ptr
!= '}')
94 while(*ptr
and *ptr
!=' ' and *ptr
!=9)
102 while(*ptr
and (*ptr
==' ' or *ptr
==9))
107 while(*ptr
and *ptr
!=' ' and *ptr
!=9)
115 concatenate(ip6prefix
,ip6range
,ptr
);
117 if_exists(ip
, ips
, eq(ip
->addr
,ip6range
));
120 TheIP(ip6range
, FALSE
);
123 ip
->keyword
= defaultkeyword
; /* settings for default keyword */
126 ip
->lmsid
= atoi(lmsid
);
135 if_exists(ip
, listhead
, eq(ip
->addr
,ipaddr
));
138 TheIP(ipaddr
, (listhead
==networks
));
143 ip
->lmsid
= atoi(lmsid
);
148 /* == This function parses hosts style main configuration file == */
149 void parse_hosts(char *hosts
)
151 int groupidx
= FIRSTGROUPID
;
161 if(*str
< '0' or *str
> '9')
163 /* any line starting with non-number is comment ...*/
167 /* first, expand (rewrite) any predefined macros, if found*/
168 for_each(macro
, macros
)
170 substring
= strstr(str
, macro
->rewrite_from
);
175 substring
+= strlen(macro
->rewrite_from
);
177 l3
= strlen(substring
);
178 string(ptr
, l1
+ strlen(macro
->rewrite_to
) + l3
);
180 strcat(ptr
, macro
->rewrite_to
);
181 strcat(ptr
, substring
);
186 /* Does this IP share QoS class with some other ? */
187 substring
= strstr(str
, "sharing-");
190 substring
+= 8; /* "sharing-" */
191 parse_and_append_ip(str
, ips
);
192 ip
->sharing
= substring
;
193 ip
->keyword
= defaultkeyword
; /* settings for default keyword */
196 lastIP6
->sharing
= substring
;
199 while(*substring
and *substring
!= '\n')
207 substring
= strstr(str
, "#255.");
208 if(substring
and not strstr(str
, "#255.255.255.255")) /* do not ping /32 ranges */
210 /* netmask detected - save network*/
212 unsigned num
, mask
= 8;
214 while(substring
&& *substring
)
217 substring
= strchr(substring
, '.');
224 for(bit
= 1; bit
<=128 ; bit
<<=1)
232 parse_and_append_ip(str
, networks
);
237 /*Do we have to create new QoS class for this IP ? */
238 if_exists(keyword
,keywords
,(substring
=strstr(str
,keyword
->key
)))
240 parse_and_append_ip(str
, ips
);
243 lastIP6
->sharing
= ip
->name
;
246 ip
->keyword
= keyword
;
248 ip
->prio
= keyword
->default_prio
;
249 substring
+= strlen(keyword
->key
)+1;
251 while(*ptr
and *ptr
!= '-')
258 ip
->max
= ip
->desired
= atoi(ptr
+1);
261 ip
->min
= atoi(substring
);
264 printf(" %s: Illegal value of minimum bandwidth 0 kbps, using %d kb/s\n",
269 if(ip
->max
<= ip
->min
)
271 ip
->fixedprio
= TRUE
;
272 ip
->max
= ip
->min
+ ip
->keyword
->reserve_min
;
276 ip
->max
-= ip
->keyword
->reserve_max
;
277 if(ip
->max
< ip
->min
)
283 /* avg MTU bytes * 8 >> 10 = in bits, max is in kb/s */
284 pktratio
= (ip
->keyword
->allowed_avgmtu
*8) >> 10;
287 ip
->pps_limit
= ip
->max
/pktratio
;
288 if(ip
->pps_limit
> 10000) /* this limit seems to be hardcoded in iptables */
290 ip
->pps_limit
= 0; /* do not apply packet limits */
294 ip
->mark
= FIRSTIPCLASS
+1+class_count
++;
295 update_network(ip
->addr
, ip
);
297 if_exists(group
,groups
,(group
->min
== ip
->min
))
300 group
->desired
+= ip
->min
;
301 ip
->group
= group
->id
;
306 group
->min
= ip
->min
;
307 group
->id
= groupidx
++;
308 ip
->group
= group
->id
;
310 if(group
->min
< 8) group
->min
= 8;
311 /* Warning - this is maybe because of primitive tc namespace, can be fixed */
312 /* it is because class IDs are derived from min. bandwidth. - xCh */
313 //if(group->min>MAX_GUARANTED_KBPS) group->min=MAX_GUARANTED_KBPS;
316 group
->desired
= ip
->min
;
317 insert(group
, groups
, desc_order_by
,min
);
328 done
; /* ugly macro end */
329 // TheIP("0.0.0.0", TRUE);
330 // ip->name = "TOTAL";
This page took 0.349615 seconds and 4 git commands to generate.