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 int class_count
;
15 extern int found_lmsid
;
17 extern const int highest_priority
;
18 extern char *ip6prefix
;
20 void update_network(char *look_for
, struct IP
* ip
);
21 /* implemented in networks.c */
23 /* This must be object oriented! This looks almost like constructor ;-) */
24 void TheIP(char *ipaddr
, int is_network
)
30 ip
->prio
= highest_priority
+1;
45 ip
->keyword
= keywords
;
46 ip
->v6
= (strchr(ip
->addr
,':')!=NULL
);
47 ip
->mask
= ((ip
->v6
)?64:32);
61 /* == This function strips extra characters after IPv4 address and stores it = */
62 void parse_and_append_ip(char *str
, struct IP
*listhead
)
64 char *ptr
, *ipaddr
, *ip6range
= NULL
, *ipname
= NULL
, *lmsid
= NULL
;
66 if(ip6prefix
) /* Try this only if IPv6 subsystem is active... */
68 ptr
= strstr(str
, "::");
69 if(ptr
&& ptr
-str
> 4)
72 duplicate(ptr
, ip6range
);
73 ptr
= strstr(ip6range
, "::");
81 ptr
= strchr(str
, '{');
85 while(*ptr
and *ptr
!= '}')
93 while(*ptr
and *ptr
!=' ' and *ptr
!=9)
101 while(*ptr
and (*ptr
==' ' or *ptr
==9))
106 while(*ptr
and *ptr
!=' ' and *ptr
!=9)
114 concatenate(ip6prefix
,ip6range
,ptr
);
116 if_exists(ip
, ips
, eq(ip
->addr
,ip6range
));
119 TheIP(ip6range
, FALSE
);
122 ip
->keyword
= defaultkeyword
; /* settings for default keyword */
125 ip
->lmsid
= atoi(lmsid
);
134 if_exists(ip
, listhead
, eq(ip
->addr
,ipaddr
));
137 TheIP(ipaddr
, (listhead
==networks
));
142 ip
->lmsid
= atoi(lmsid
);
147 /* == This function parses hosts style main configuration file == */
148 void parse_hosts(char *hosts
)
150 int groupidx
= FIRSTGROUPID
;
159 if(*str
< '0' or *str
> '9')
161 /* any line starting with non-number is comment ...*/
165 /* Does this IP share QoS class with some other ? */
166 substring
= strstr(str
, "sharing-");
169 substring
+= 8; /* "sharing-" */
170 parse_and_append_ip(str
, ips
);
171 ip
->sharing
= substring
;
172 ip
->keyword
= defaultkeyword
; /* settings for default keyword */
175 lastIP6
->sharing
= substring
;
178 while(*substring
and *substring
!= '\n')
186 substring
= strstr(str
, "#255.");
187 if(substring
and not strstr(str
, "#255.255.255.255")) /* do not ping /32 ranges */
189 /* netmask detected - save network*/
191 unsigned num
, mask
= 8;
193 while(substring
&& *substring
)
196 substring
= strchr(substring
, '.');
203 for(bit
= 1; bit
<=128 ; bit
<<=1)
211 parse_and_append_ip(str
, networks
);
216 /*Do we have to create new QoS class for this IP ? */
217 if_exists(keyword
,keywords
,(substring
=strstr(str
,keyword
->key
)))
219 parse_and_append_ip(str
, ips
);
222 lastIP6
->sharing
= ip
->name
;
225 ip
->keyword
= keyword
;
227 ip
->prio
= keyword
->default_prio
;
228 substring
+= strlen(keyword
->key
)+1;
230 while(*ptr
and *ptr
!= '-')
237 ip
->max
= ip
->desired
= atoi(ptr
+1);
240 ip
->min
= atoi(substring
);
243 printf(" %s: Illegal value of minimum bandwidth 0 kbps, using %d kb/s\n",
248 if(ip
->max
<= ip
->min
)
250 ip
->fixedprio
= TRUE
;
251 ip
->max
= ip
->min
+ ip
->keyword
->reserve_min
;
255 ip
->max
-= ip
->keyword
->reserve_max
;
256 if(ip
->max
< ip
->min
)
262 /* MTU is 1450 bytes = 11600 bits ~= 12 kbit, max is in kb/s
263 average pkt 1/2 MTU = 6 kbit*/
264 ip
->pps_limit
= ip
->max
/6;
265 if(ip
->pps_limit
> 10000) /* this limit seems to be hardcoded in iptables */
267 ip
->pps_limit
= 0; /* do not apply packet limits */
270 ip
->mark
= FIRSTIPCLASS
+1+class_count
++;
271 update_network(ip
->addr
, ip
);
273 if_exists(group
,groups
,(group
->min
== ip
->min
))
276 group
->desired
+= ip
->min
;
277 ip
->group
= group
->id
;
282 group
->min
= ip
->min
;
283 group
->id
= groupidx
++;
284 ip
->group
= group
->id
;
286 if(group
->min
< 8) group
->min
= 8;
287 /* Warning - this is maybe because of primitive tc namespace, can be fixed */
288 /* it is because class IDs are derived from min. bandwidth. - xCh */
289 //if(group->min>MAX_GUARANTED_KBPS) group->min=MAX_GUARANTED_KBPS;
292 group
->desired
= ip
->min
;
293 insert(group
, groups
, desc_order_by
,min
);
304 done
; /* ugly macro end */
305 // TheIP("0.0.0.0", TRUE);
306 // ip->name = "TOTAL";
This page took 0.429325 seconds and 4 git commands to generate.