47b06bd5c28925d6495e7ddf20ca6065311a98e4
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_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;
49 ip
->keyword
= keywords
;
50 ip
->v6
= (strchr(ip
->addr
,':')!=NULL
);
51 ip
->mask
= ((ip
->v6
)?64:32);
63 struct IP
*lastIP6range
, *lastIP6uplink
;
65 /* == This function strips extra characters after IPv4 address and stores it = */
66 void parse_and_append_ip(char *str
, struct IP
*listhead
)
68 char *ptr
, *ipaddr
, *nextip6
, *ip6buf
;
69 char *ip6uplink
= NULL
, *ip6range
= NULL
, *ipname
= NULL
, *lmsid
= NULL
;
71 if(ip6prefix
) /* Try this only if IPv6 subsystem is active... */
73 ptr
= strstr(str
, "::");
74 while(ptr
&& ptr
-str
> 4)
76 nextip6
= strstr(ptr
+ 2, "::");
78 duplicate(ptr
, ip6buf
);
79 ptr
= strstr(ip6buf
, "::");
84 *(ptr
+3) = 0; /* ends with ::+ */
89 *(ptr
+2) = 0; /* ends with :: */
97 ptr
= strchr(str
, '{');
101 while(*ptr
and *ptr
!= '}')
109 while(*ptr
and *ptr
!=' ' and *ptr
!=9)
117 while(*ptr
and (*ptr
==' ' or *ptr
==9))
122 while(*ptr
and *ptr
!=' ' and *ptr
!=9)
130 concatenate(ip6prefix
,ip6range
,ptr
);
132 if_exists(ip
, ips
, eq(ip
->addr
,ip6range
)); /* check - allocated range must be unique */
135 TheIP(ip6range
, FALSE
);
138 ip
->keyword
= defaultkeyword
; /* settings for default keyword */
141 ip
->lmsid
= atoi(lmsid
);
150 /* it is ugly to copy+paste and search+replace, but... */
153 concatenate(ip6prefix
,ip6uplink
,ptr
);
155 TheIP(ip6uplink
, FALSE
); /* always new IP - more IPs in single uplink network */
156 ip
->name
= ip6uplink
;
157 ip
->keyword
= defaultkeyword
; /* settings for default keyword */
160 ip
->lmsid
= atoi(lmsid
);
166 lastIP6uplink
= NULL
;
169 if_exists(ip
, listhead
, eq(ip
->addr
,ipaddr
));
172 TheIP(ipaddr
, (listhead
==networks
));
177 ip
->lmsid
= atoi(lmsid
);
182 /* == This function parses hosts style main configuration file == */
183 void parse_hosts(char *hosts
)
185 int groupidx
= FIRSTGROUPID
;
195 if(*str
< '0' or *str
> '9')
197 /* any line starting with non-number is comment ...*/
201 ptr
= strchr(str
,'\r'); /* fore unix-style end of line */
207 /* first, expand (rewrite) any predefined macros, if found*/
208 for_each(macro
, macros
)
210 substring
= strstr(str
, macro
->rewrite_from
);
215 substring
+= strlen(macro
->rewrite_from
);
217 l3
= strlen(substring
);
218 string(ptr
, l1
+ strlen(macro
->rewrite_to
) + l3
+ 1);
220 strcat(ptr
, macro
->rewrite_to
);
221 strcat(ptr
, substring
);
223 /* printf("REWRITE: %s -> %s\n",_,str); */
227 /* Does this IP share QoS class with some other ? */
228 substring
= strstr(str
, "sharing-");
231 substring
+= 8; /* "sharing-" */
232 parse_and_append_ip(str
, ips
);
233 ip
->sharing
= substring
;
234 ip
->keyword
= defaultkeyword
; /* settings for default keyword */
237 lastIP6range
->sharing
= substring
;
242 lastIP6uplink
->sharing
= substring
;
243 lastIP6uplink
= NULL
;
245 while(*substring
and *substring
!= '\n')
253 substring
= strstr(str
, "#255.");
254 if(substring
and not strstr(str
, "#255.255.255.255")) /* do not ping /32 uplinks */
256 /* netmask detected - save network*/
258 unsigned num
, mask
= 8;
260 while(substring
&& *substring
)
263 substring
= strchr(substring
, '.');
270 for(bit
= 1; bit
<=128 ; bit
<<=1)
278 parse_and_append_ip(str
, networks
);
283 /*Do we have to create new QoS class for this IP ? */
284 if_exists(keyword
,keywords
,(substring
=strstr(str
,keyword
->key
)))
286 parse_and_append_ip(str
, ips
);
289 lastIP6range
->sharing
= ip
->name
;
294 lastIP6uplink
->sharing
= ip
->name
;
295 lastIP6uplink
= NULL
;
297 ip
->keyword
= keyword
;
299 ip
->prio
= keyword
->default_prio
;
300 substring
+= strlen(keyword
->key
)+1;
302 while(*ptr
and *ptr
!= '-')
309 ip
->max
= ip
->desired
= atoi(ptr
+1);
312 ip
->min
= atoi(substring
);
315 printf(" %s: Illegal value of minimum bandwidth 0 kbps, using %d kb/s\n",
320 if(ip
->max
<= ip
->min
)
322 ip
->fixedprio
= TRUE
;
323 ip
->max
= ip
->min
+ ip
->keyword
->reserve_min
;
327 ip
->max
-= ip
->keyword
->reserve_max
;
328 if(ip
->max
< ip
->min
)
334 /* avg MTU bytes * 8 >> 10 = in bits, max is in kb/s */
335 pktratio
= (ip
->keyword
->allowed_avgmtu
*8) >> 10;
338 ip
->pps_limit
= ip
->max
/pktratio
;
339 if(ip
->pps_limit
> 10000) /* this limit seems to be hardcoded in iptables */
341 ip
->pps_limit
= 0; /* do not apply packet limits */
345 ip
->mark
= FIRSTIPCLASS
+1+class_count
++;
346 update_network(ip
->addr
, ip
);
348 if_exists(group
,groups
,(group
->min
== ip
->min
))
351 group
->desired
+= ip
->min
;
352 ip
->group
= group
->id
;
357 group
->min
= ip
->min
;
358 group
->id
= groupidx
++;
359 ip
->group
= group
->id
;
361 if(group
->min
< 8) group
->min
= 8;
362 /* Warning - this is maybe because of primitive tc namespace, can be fixed */
363 /* it is because class IDs are derived from min. bandwidth. - xCh */
364 //if(group->min>MAX_GUARANTED_KBPS) group->min=MAX_GUARANTED_KBPS;
367 group
->desired
= ip
->min
;
368 insert(group
, groups
, desc_order_by
,min
);
379 done
; /* ugly macro end */
380 // TheIP("0.0.0.0", TRUE);
381 // ip->name = "TOTAL";
This page took 0.403278 seconds and 3 git commands to generate.