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;
44 ip
->keyword
= keywords
;
45 ip
->v6
= (strchr(ip
->addr
,':')!=NULL
);
46 ip
->mask
= ((ip
->v6
)?64:32);
60 /* == This function strips extra characters after IPv4 address and stores it = */
61 void parse_and_append_ip(char *str
, struct IP
*listhead
)
63 char *ptr
, *ipaddr
, *ip6range
= NULL
, *ipname
= NULL
, *lmsid
= NULL
;
65 if(ip6prefix
) /* Try this only if IPv6 subsystem is active... */
67 ptr
= strstr(str
, "::");
68 if(ptr
&& ptr
-str
> 4)
71 duplicate(ptr
, ip6range
);
72 ptr
= strstr(ip6range
, "::");
80 ptr
= strchr(str
, '{');
84 while(*ptr
and *ptr
!= '}')
92 while(*ptr
and *ptr
!=' ' and *ptr
!=9)
100 while(*ptr
and (*ptr
==' ' or *ptr
==9))
105 while(*ptr
and *ptr
!=' ' and *ptr
!=9)
113 concatenate(ip6prefix
,ip6range
,ptr
);
115 if_exists(ip
, ips
, eq(ip
->addr
,ip6range
));
118 TheIP(ip6range
, FALSE
);
121 ip
->keyword
= defaultkeyword
; /* settings for default keyword */
124 ip
->lmsid
= atoi(lmsid
);
133 if_exists(ip
, listhead
, eq(ip
->addr
,ipaddr
));
136 TheIP(ipaddr
, (listhead
==networks
));
141 ip
->lmsid
= atoi(lmsid
);
146 /* == This function parses hosts style main configuration file == */
147 void parse_hosts(char *hosts
)
149 int groupidx
= FIRSTGROUPID
;
158 if(*str
< '0' or *str
> '9')
160 /* any line starting with non-number is comment ...*/
164 /* Does this IP share QoS class with some other ? */
165 substring
= strstr(str
, "sharing-");
168 substring
+= 8; /* "sharing-" */
169 parse_and_append_ip(str
, ips
);
170 ip
->sharing
= substring
;
171 ip
->keyword
= defaultkeyword
; /* settings for default keyword */
174 lastIP6
->sharing
= substring
;
177 while(*substring
and *substring
!= '\n')
185 substring
= strstr(str
, "#255.");
186 if(substring
and not strstr(str
, "#255.255.255.255")) /* do not ping /32 ranges */
188 /* netmask detected - save network*/
190 unsigned num
, mask
= 8;
192 while(substring
&& *substring
)
195 substring
= strchr(substring
, '.');
202 for(bit
= 1; bit
<=128 ; bit
<<=1)
210 parse_and_append_ip(str
, networks
);
215 /*Do we have to create new QoS class for this IP ? */
216 if_exists(keyword
,keywords
,(substring
=strstr(str
,keyword
->key
)))
218 parse_and_append_ip(str
, ips
);
221 lastIP6
->sharing
= ip
->name
;
224 ip
->keyword
= keyword
;
226 ip
->prio
= keyword
->default_prio
;
227 substring
+= strlen(keyword
->key
)+1;
229 while(*ptr
and *ptr
!= '-')
236 ip
->max
= ip
->desired
= atoi(ptr
+1);
238 ip
->min
= atoi(substring
);
241 printf(" %s: Illegal value of minimum bandwidth 0 kbps, using %d kb/s\n",
245 if(ip
->max
<= ip
->min
)
247 ip
->fixedprio
= TRUE
;
248 ip
->max
= ip
->min
+ ip
->keyword
->reserve_min
;
252 ip
->max
-= ip
->keyword
->reserve_max
;
258 ip
->mark
= FIRSTIPCLASS
+1+class_count
++;
260 update_network(ip
->addr
, ip
);
262 if_exists(group
,groups
,(group
->min
== ip
->min
))
265 group
->desired
+= ip
->min
;
266 ip
->group
= group
->id
;
271 group
->min
= ip
->min
;
272 group
->id
= groupidx
++;
273 ip
->group
= group
->id
;
275 if(group
->min
< 8) group
->min
= 8;
276 /* Warning - this is maybe because of primitive tc namespace, can be fixed */
277 /* it is because class IDs are derived from min. bandwidth. - xCh */
278 //if(group->min>MAX_GUARANTED_KBPS) group->min=MAX_GUARANTED_KBPS;
281 group
->desired
= ip
->min
;
282 insert(group
, groups
, desc_order_by
,min
);
293 done
; /* ugly macro end */
This page took 0.44273 seconds and 5 git commands to generate.