]>
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"
37 #define BAD_CONF_CLASS -1
39 #define BAD_CLIENT_CLASS -3
41 rb_dlink_list class_list
;
42 struct Class
*default_class
;
49 tmp
= rb_malloc(sizeof(struct Class
));
51 ConFreq(tmp
) = DEFAULT_CONNECTFREQUENCY
;
52 PingFreq(tmp
) = DEFAULT_PINGFREQUENCY
;
54 MaxSendq(tmp
) = DEFAULT_SENDQ
;
56 tmp
->ip_limits
= rb_new_patricia(PATRICIA_BITS
);
61 free_class(struct Class
*tmp
)
64 rb_destroy_patricia(tmp
->ip_limits
, NULL
);
66 rb_free(tmp
->class_name
);
74 * inputs - pointer to struct ConfItem
75 * output - ping frequency
79 get_conf_ping(struct ConfItem
*aconf
)
81 if((aconf
) && ClassPtr(aconf
))
82 return (ConfPingFreq(aconf
));
90 * inputs - pointer to client struct
91 * output - pointer to name of class
95 get_client_class(struct Client
*target_p
)
97 const char *retc
= "unknown";
99 if(target_p
== NULL
|| IsMe(target_p
))
102 if(IsServer(target_p
))
104 struct server_conf
*server_p
= target_p
->localClient
->att_sconf
;
105 return server_p
->class_name
;
109 struct ConfItem
*aconf
;
110 aconf
= target_p
->localClient
->att_conf
;
112 if((aconf
== NULL
) || (aconf
->className
== NULL
))
115 retc
= aconf
->className
;
124 * inputs - pointer to client struct
125 * output - ping frequency
126 * side effects - NONE
129 get_client_ping(struct Client
*target_p
)
133 if(IsServer(target_p
))
135 struct server_conf
*server_p
= target_p
->localClient
->att_sconf
;
136 ping
= PingFreq(server_p
->class);
140 struct ConfItem
*aconf
;
142 aconf
= target_p
->localClient
->att_conf
;
145 ping
= get_conf_ping(aconf
);
147 ping
= DEFAULT_PINGFREQUENCY
;
151 ping
= DEFAULT_PINGFREQUENCY
;
159 * inputs - pointer to class struct
160 * output - connection frequency
161 * side effects - NONE
164 get_con_freq(struct Class
*clptr
)
167 return (ConFreq(clptr
));
168 return (DEFAULT_CONNECTFREQUENCY
);
173 * input - class to add
175 * side effects - class is added to class_list if new, else old class
176 * is updated with new values.
179 add_class(struct Class
*classptr
)
181 struct Class
*tmpptr
;
183 tmpptr
= find_class(classptr
->class_name
);
185 if(tmpptr
== default_class
)
187 rb_dlinkAddAlloc(classptr
, &class_list
);
188 CurrUsers(classptr
) = 0;
192 MaxUsers(tmpptr
) = MaxUsers(classptr
);
193 MaxLocal(tmpptr
) = MaxLocal(classptr
);
194 MaxGlobal(tmpptr
) = MaxGlobal(classptr
);
195 MaxIdent(tmpptr
) = MaxIdent(classptr
);
196 PingFreq(tmpptr
) = PingFreq(classptr
);
197 MaxSendq(tmpptr
) = MaxSendq(classptr
);
198 ConFreq(tmpptr
) = ConFreq(classptr
);
199 CidrIpv4Bitlen(tmpptr
) = CidrIpv4Bitlen(classptr
);
200 CidrIpv6Bitlen(tmpptr
) = CidrIpv6Bitlen(classptr
);
201 CidrAmount(tmpptr
) = CidrAmount(classptr
);
203 free_class(classptr
);
211 * inputs - string name of class
212 * output - corresponding class pointer
213 * side effects - NONE
216 find_class(const char *classname
)
221 if(classname
== NULL
)
222 return default_class
;
224 RB_DLINK_FOREACH(ptr
, class_list
.head
)
228 if(!strcmp(ClassName(cltmp
), classname
))
232 return default_class
;
247 rb_dlink_node
*next_ptr
;
249 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, class_list
.head
)
253 if(MaxUsers(cltmp
) < 0)
255 rb_dlinkDestroy(ptr
, &class_list
);
256 if(CurrUsers(cltmp
) <= 0)
272 default_class
= make_class();
273 ClassName(default_class
) = rb_strdup("default");
279 * inputs - pointer to client to report to
281 * side effects - class report is done to this client
284 report_classes(struct Client
*source_p
)
289 RB_DLINK_FOREACH(ptr
, class_list
.head
)
293 sendto_one_numeric(source_p
, RPL_STATSYLINE
,
294 form_str(RPL_STATSYLINE
),
295 ClassName(cltmp
), PingFreq(cltmp
),
296 ConFreq(cltmp
), MaxUsers(cltmp
),
298 MaxLocal(cltmp
), MaxIdent(cltmp
),
299 MaxGlobal(cltmp
), MaxIdent(cltmp
),
303 /* also output the default class */
304 sendto_one_numeric(source_p
, RPL_STATSYLINE
, form_str(RPL_STATSYLINE
),
305 ClassName(default_class
), PingFreq(default_class
),
306 ConFreq(default_class
), MaxUsers(default_class
),
307 MaxSendq(default_class
),
308 MaxLocal(default_class
), MaxIdent(default_class
),
309 MaxGlobal(default_class
), MaxIdent(default_class
),
310 CurrUsers(default_class
));
316 * inputs - pointer to client
317 * output - sendq for this client as found from its class
318 * side effects - NONE
321 get_sendq(struct Client
*client_p
)
323 if(client_p
== NULL
|| IsMe(client_p
))
324 return DEFAULT_SENDQ
;
326 if(IsServer(client_p
))
328 struct server_conf
*server_p
;
329 server_p
= client_p
->localClient
->att_sconf
;
330 return MaxSendq(server_p
->class);
334 struct ConfItem
*aconf
= client_p
->localClient
->att_conf
;
336 if(aconf
!= NULL
&& aconf
->status
& CONF_CLIENT
)
337 return ConfMaxSendq(aconf
);
340 return DEFAULT_SENDQ
;