]>
jfr.im git - solanum.git/blob - ircd/class.c
2 * ircd-ratbox: A slightly useful ircd.
3 * class.c: Controls connection classes.
5 * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center
6 * Copyright (C) 1996-2002 Hybrid Development Team
7 * Copyright (C) 2002-2005 ircd-ratbox development team
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
24 * $Id: class.c 254 2005-09-21 23:35:12Z nenolod $
36 #include "s_newconf.h"
40 #define BAD_CONF_CLASS -1
42 #define BAD_CLIENT_CLASS -3
44 rb_dlink_list class_list
;
45 struct Class
*default_class
;
52 tmp
= rb_malloc(sizeof(struct Class
));
54 ConFreq(tmp
) = DEFAULT_CONNECTFREQUENCY
;
55 PingFreq(tmp
) = DEFAULT_PINGFREQUENCY
;
57 MaxSendq(tmp
) = DEFAULT_SENDQ
;
58 MaxSendqHard(tmp
) = DEFAULT_SENDQ
* 4;
60 tmp
->ip_limits
= rb_new_patricia(PATRICIA_BITS
);
65 free_class(struct Class
*tmp
)
68 rb_destroy_patricia(tmp
->ip_limits
, NULL
);
70 rb_free(tmp
->class_name
);
78 * inputs - pointer to struct ConfItem
79 * output - ping frequency
83 get_conf_ping(struct ConfItem
*aconf
)
85 if((aconf
) && ClassPtr(aconf
))
86 return (ConfPingFreq(aconf
));
94 * inputs - pointer to client struct
95 * output - pointer to name of class
99 get_client_class(struct Client
*target_p
)
101 const char *retc
= "unknown";
103 if(target_p
== NULL
|| IsMe(target_p
))
106 if(IsServer(target_p
))
108 struct server_conf
*server_p
= target_p
->localClient
->att_sconf
;
109 return server_p
->class_name
;
113 struct ConfItem
*aconf
;
114 aconf
= target_p
->localClient
->att_conf
;
116 if((aconf
== NULL
) || (aconf
->className
== NULL
))
119 retc
= aconf
->className
;
128 * inputs - pointer to client struct
129 * output - ping frequency
130 * side effects - NONE
133 get_client_ping(struct Client
*target_p
)
137 if(IsServer(target_p
))
139 struct server_conf
*server_p
= target_p
->localClient
->att_sconf
;
140 ping
= PingFreq(server_p
->class);
144 struct ConfItem
*aconf
;
146 aconf
= target_p
->localClient
->att_conf
;
149 ping
= get_conf_ping(aconf
);
151 ping
= DEFAULT_PINGFREQUENCY
;
155 ping
= DEFAULT_PINGFREQUENCY
;
163 * inputs - pointer to class struct
164 * output - connection frequency
165 * side effects - NONE
168 get_con_freq(struct Class
*clptr
)
171 return (ConFreq(clptr
));
172 return (DEFAULT_CONNECTFREQUENCY
);
177 * input - class to add
179 * side effects - class is added to class_list if new, else old class
180 * is updated with new values.
183 add_class(struct Class
*classptr
)
185 struct Class
*tmpptr
;
187 tmpptr
= find_class(classptr
->class_name
);
189 if(tmpptr
== default_class
)
191 rb_dlinkAddAlloc(classptr
, &class_list
);
192 CurrUsers(classptr
) = 0;
196 MaxUsers(tmpptr
) = MaxUsers(classptr
);
197 MaxLocal(tmpptr
) = MaxLocal(classptr
);
198 MaxGlobal(tmpptr
) = MaxGlobal(classptr
);
199 MaxIdent(tmpptr
) = MaxIdent(classptr
);
200 PingFreq(tmpptr
) = PingFreq(classptr
);
201 MaxSendq(tmpptr
) = MaxSendq(classptr
);
202 MaxSendqHard(tmpptr
) = MaxSendq(classptr
) * 4;
203 ConFreq(tmpptr
) = ConFreq(classptr
);
204 CidrIpv4Bitlen(tmpptr
) = CidrIpv4Bitlen(classptr
);
205 CidrIpv6Bitlen(tmpptr
) = CidrIpv6Bitlen(classptr
);
206 CidrAmount(tmpptr
) = CidrAmount(classptr
);
208 free_class(classptr
);
216 * inputs - string name of class
217 * output - corresponding class pointer
218 * side effects - NONE
221 find_class(const char *classname
)
226 if(classname
== NULL
)
227 return default_class
;
229 RB_DLINK_FOREACH(ptr
, class_list
.head
)
233 if(!strcmp(ClassName(cltmp
), classname
))
237 return default_class
;
252 rb_dlink_node
*next_ptr
;
254 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, class_list
.head
)
258 if(MaxUsers(cltmp
) < 0)
260 rb_dlinkDestroy(ptr
, &class_list
);
261 if(CurrUsers(cltmp
) <= 0)
277 default_class
= make_class();
278 ClassName(default_class
) = rb_strdup("default");
284 * inputs - pointer to client to report to
286 * side effects - class report is done to this client
289 report_classes(struct Client
*source_p
)
294 RB_DLINK_FOREACH(ptr
, class_list
.head
)
298 sendto_one_numeric(source_p
, RPL_STATSYLINE
,
299 form_str(RPL_STATSYLINE
),
300 ClassName(cltmp
), PingFreq(cltmp
),
301 ConFreq(cltmp
), MaxUsers(cltmp
),
303 MaxLocal(cltmp
), MaxIdent(cltmp
),
304 MaxGlobal(cltmp
), MaxIdent(cltmp
),
308 /* also output the default class */
309 sendto_one_numeric(source_p
, RPL_STATSYLINE
, form_str(RPL_STATSYLINE
),
310 ClassName(default_class
), PingFreq(default_class
),
311 ConFreq(default_class
), MaxUsers(default_class
),
312 MaxSendq(default_class
),
313 MaxLocal(default_class
), MaxIdent(default_class
),
314 MaxGlobal(default_class
), MaxIdent(default_class
),
315 CurrUsers(default_class
));
321 * inputs - pointer to client
322 * output - sendq for this client as found from its class
323 * side effects - NONE
326 get_sendq(struct Client
*client_p
)
328 if(client_p
== NULL
|| IsMe(client_p
))
329 return DEFAULT_SENDQ
;
331 if(IsServer(client_p
))
333 struct server_conf
*server_p
;
334 server_p
= client_p
->localClient
->att_sconf
;
335 return MaxSendq(server_p
->class);
339 struct ConfItem
*aconf
= client_p
->localClient
->att_conf
;
341 if(aconf
!= NULL
&& aconf
->status
& CONF_CLIENT
)
342 return ConfMaxSendq(aconf
);
345 return DEFAULT_SENDQ
;
351 * inputs - pointer to client
352 * output - hard sendq limit for this client as found from its class
353 * side effects - NONE
356 get_sendq_hard(struct Client
*client_p
)
358 if(client_p
== NULL
|| IsMe(client_p
))
359 return DEFAULT_SENDQ
;
361 if(IsServer(client_p
))
363 struct server_conf
*server_p
;
364 server_p
= client_p
->localClient
->att_sconf
;
365 return MaxSendqHard(server_p
->class);
369 struct ConfItem
*aconf
= client_p
->localClient
->att_conf
;
371 if(aconf
!= NULL
&& aconf
->status
& CONF_CLIENT
)
372 return ConfMaxSendqHard(aconf
);
375 return DEFAULT_SENDQ
;