]>
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
33 #include "s_newconf.h"
39 rb_dlink_list class_list
;
40 struct Class
*default_class
;
47 tmp
= rb_malloc(sizeof(struct Class
));
49 ConFreq(tmp
) = DEFAULT_CONNECTFREQUENCY
;
50 PingFreq(tmp
) = DEFAULT_PINGFREQUENCY
;
52 MaxSendq(tmp
) = DEFAULT_SENDQ
;
54 tmp
->ip_limits
= rb_new_patricia(PATRICIA_BITS
);
59 free_class(struct Class
*tmp
)
62 rb_destroy_patricia(tmp
->ip_limits
, NULL
);
64 rb_free(tmp
->class_name
);
72 * inputs - pointer to struct ConfItem
73 * output - ping frequency
77 get_conf_ping(struct ConfItem
*aconf
)
79 if((aconf
) && ClassPtr(aconf
))
80 return (ConfPingFreq(aconf
));
88 * inputs - pointer to client struct
89 * output - pointer to name of class
93 get_client_class(struct Client
*target_p
)
95 const char *retc
= "unknown";
97 if(target_p
== NULL
|| IsMe(target_p
))
100 if(IsServer(target_p
))
102 struct server_conf
*server_p
= target_p
->localClient
->att_sconf
;
103 return server_p
->class_name
;
107 struct ConfItem
*aconf
;
108 aconf
= target_p
->localClient
->att_conf
;
110 if((aconf
== NULL
) || (aconf
->className
== NULL
))
113 retc
= aconf
->className
;
122 * inputs - pointer to client struct
123 * output - ping frequency
124 * side effects - NONE
127 get_client_ping(struct Client
*target_p
)
131 if(IsServer(target_p
))
133 struct server_conf
*server_p
= target_p
->localClient
->att_sconf
;
134 ping
= PingFreq(server_p
->class);
138 struct ConfItem
*aconf
;
140 aconf
= target_p
->localClient
->att_conf
;
143 ping
= get_conf_ping(aconf
);
145 ping
= DEFAULT_PINGFREQUENCY
;
149 ping
= DEFAULT_PINGFREQUENCY
;
157 * inputs - pointer to class struct
158 * output - connection frequency
159 * side effects - NONE
162 get_con_freq(struct Class
*clptr
)
165 return (ConFreq(clptr
));
166 return (DEFAULT_CONNECTFREQUENCY
);
171 * input - class to add
173 * side effects - class is added to class_list if new, else old class
174 * is updated with new values.
177 add_class(struct Class
*classptr
)
179 struct Class
*tmpptr
;
181 tmpptr
= find_class(classptr
->class_name
);
183 if(tmpptr
== default_class
)
185 rb_dlinkAddAlloc(classptr
, &class_list
);
186 CurrUsers(classptr
) = 0;
190 MaxUsers(tmpptr
) = MaxUsers(classptr
);
191 MaxLocal(tmpptr
) = MaxLocal(classptr
);
192 MaxGlobal(tmpptr
) = MaxGlobal(classptr
);
193 MaxIdent(tmpptr
) = MaxIdent(classptr
);
194 PingFreq(tmpptr
) = PingFreq(classptr
);
195 MaxSendq(tmpptr
) = MaxSendq(classptr
);
196 ConFreq(tmpptr
) = ConFreq(classptr
);
197 CidrIpv4Bitlen(tmpptr
) = CidrIpv4Bitlen(classptr
);
198 CidrIpv6Bitlen(tmpptr
) = CidrIpv6Bitlen(classptr
);
199 CidrAmount(tmpptr
) = CidrAmount(classptr
);
201 free_class(classptr
);
209 * inputs - string name of class
210 * output - corresponding class pointer
211 * side effects - NONE
214 find_class(const char *classname
)
219 if(classname
== NULL
)
220 return default_class
;
222 RB_DLINK_FOREACH(ptr
, class_list
.head
)
226 if(!strcmp(ClassName(cltmp
), classname
))
230 return default_class
;
245 rb_dlink_node
*next_ptr
;
247 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, class_list
.head
)
251 if(MaxUsers(cltmp
) < 0)
253 rb_dlinkDestroy(ptr
, &class_list
);
254 if(CurrUsers(cltmp
) <= 0)
270 default_class
= make_class();
271 ClassName(default_class
) = rb_strdup("default");
277 * inputs - pointer to client to report to
279 * side effects - class report is done to this client
282 report_classes(struct Client
*source_p
)
287 RB_DLINK_FOREACH(ptr
, class_list
.head
)
291 sendto_one_numeric(source_p
, RPL_STATSYLINE
,
292 form_str(RPL_STATSYLINE
),
293 ClassName(cltmp
), PingFreq(cltmp
),
294 ConFreq(cltmp
), MaxUsers(cltmp
),
296 MaxLocal(cltmp
), MaxIdent(cltmp
),
297 MaxGlobal(cltmp
), MaxIdent(cltmp
),
301 /* also output the default class */
302 sendto_one_numeric(source_p
, RPL_STATSYLINE
, form_str(RPL_STATSYLINE
),
303 ClassName(default_class
), PingFreq(default_class
),
304 ConFreq(default_class
), MaxUsers(default_class
),
305 MaxSendq(default_class
),
306 MaxLocal(default_class
), MaxIdent(default_class
),
307 MaxGlobal(default_class
), MaxIdent(default_class
),
308 CurrUsers(default_class
));
314 * inputs - pointer to client
315 * output - sendq for this client as found from its class
316 * side effects - NONE
319 get_sendq(struct Client
*client_p
)
321 if(client_p
== NULL
|| IsMe(client_p
))
322 return DEFAULT_SENDQ
;
324 if(IsServer(client_p
))
326 struct server_conf
*server_p
;
327 server_p
= client_p
->localClient
->att_sconf
;
328 return MaxSendq(server_p
->class);
332 struct ConfItem
*aconf
= client_p
->localClient
->att_conf
;
334 if(aconf
!= NULL
&& aconf
->status
& CONF_CLIENT
)
335 return ConfMaxSendq(aconf
);
338 return DEFAULT_SENDQ
;