]>
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
34 #include "s_newconf.h"
38 #define BAD_CONF_CLASS -1
40 #define BAD_CLIENT_CLASS -3
42 rb_dlink_list class_list
;
43 struct Class
*default_class
;
50 tmp
= rb_malloc(sizeof(struct Class
));
52 ConFreq(tmp
) = DEFAULT_CONNECTFREQUENCY
;
53 PingFreq(tmp
) = DEFAULT_PINGFREQUENCY
;
55 MaxSendq(tmp
) = DEFAULT_SENDQ
;
57 tmp
->ip_limits
= rb_new_patricia(PATRICIA_BITS
);
62 free_class(struct Class
*tmp
)
65 rb_destroy_patricia(tmp
->ip_limits
, NULL
);
67 rb_free(tmp
->class_name
);
75 * inputs - pointer to struct ConfItem
76 * output - ping frequency
80 get_conf_ping(struct ConfItem
*aconf
)
82 if((aconf
) && ClassPtr(aconf
))
83 return (ConfPingFreq(aconf
));
91 * inputs - pointer to client struct
92 * output - pointer to name of class
96 get_client_class(struct Client
*target_p
)
98 const char *retc
= "unknown";
100 if(target_p
== NULL
|| IsMe(target_p
))
103 if(IsServer(target_p
))
105 struct server_conf
*server_p
= target_p
->localClient
->att_sconf
;
106 return server_p
->class_name
;
110 struct ConfItem
*aconf
;
111 aconf
= target_p
->localClient
->att_conf
;
113 if((aconf
== NULL
) || (aconf
->className
== NULL
))
116 retc
= aconf
->className
;
125 * inputs - pointer to client struct
126 * output - ping frequency
127 * side effects - NONE
130 get_client_ping(struct Client
*target_p
)
134 if(IsServer(target_p
))
136 struct server_conf
*server_p
= target_p
->localClient
->att_sconf
;
137 ping
= PingFreq(server_p
->class);
141 struct ConfItem
*aconf
;
143 aconf
= target_p
->localClient
->att_conf
;
146 ping
= get_conf_ping(aconf
);
148 ping
= DEFAULT_PINGFREQUENCY
;
152 ping
= DEFAULT_PINGFREQUENCY
;
160 * inputs - pointer to class struct
161 * output - connection frequency
162 * side effects - NONE
165 get_con_freq(struct Class
*clptr
)
168 return (ConFreq(clptr
));
169 return (DEFAULT_CONNECTFREQUENCY
);
174 * input - class to add
176 * side effects - class is added to class_list if new, else old class
177 * is updated with new values.
180 add_class(struct Class
*classptr
)
182 struct Class
*tmpptr
;
184 tmpptr
= find_class(classptr
->class_name
);
186 if(tmpptr
== default_class
)
188 rb_dlinkAddAlloc(classptr
, &class_list
);
189 CurrUsers(classptr
) = 0;
193 MaxUsers(tmpptr
) = MaxUsers(classptr
);
194 MaxLocal(tmpptr
) = MaxLocal(classptr
);
195 MaxGlobal(tmpptr
) = MaxGlobal(classptr
);
196 MaxIdent(tmpptr
) = MaxIdent(classptr
);
197 PingFreq(tmpptr
) = PingFreq(classptr
);
198 MaxSendq(tmpptr
) = MaxSendq(classptr
);
199 ConFreq(tmpptr
) = ConFreq(classptr
);
200 CidrIpv4Bitlen(tmpptr
) = CidrIpv4Bitlen(classptr
);
201 CidrIpv6Bitlen(tmpptr
) = CidrIpv6Bitlen(classptr
);
202 CidrAmount(tmpptr
) = CidrAmount(classptr
);
204 free_class(classptr
);
212 * inputs - string name of class
213 * output - corresponding class pointer
214 * side effects - NONE
217 find_class(const char *classname
)
222 if(classname
== NULL
)
223 return default_class
;
225 RB_DLINK_FOREACH(ptr
, class_list
.head
)
229 if(!strcmp(ClassName(cltmp
), classname
))
233 return default_class
;
248 rb_dlink_node
*next_ptr
;
250 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, class_list
.head
)
254 if(MaxUsers(cltmp
) < 0)
256 rb_dlinkDestroy(ptr
, &class_list
);
257 if(CurrUsers(cltmp
) <= 0)
273 default_class
= make_class();
274 ClassName(default_class
) = rb_strdup("default");
280 * inputs - pointer to client to report to
282 * side effects - class report is done to this client
285 report_classes(struct Client
*source_p
)
290 RB_DLINK_FOREACH(ptr
, class_list
.head
)
294 sendto_one_numeric(source_p
, RPL_STATSYLINE
,
295 form_str(RPL_STATSYLINE
),
296 ClassName(cltmp
), PingFreq(cltmp
),
297 ConFreq(cltmp
), MaxUsers(cltmp
),
299 MaxLocal(cltmp
), MaxIdent(cltmp
),
300 MaxGlobal(cltmp
), MaxIdent(cltmp
),
304 /* also output the default class */
305 sendto_one_numeric(source_p
, RPL_STATSYLINE
, form_str(RPL_STATSYLINE
),
306 ClassName(default_class
), PingFreq(default_class
),
307 ConFreq(default_class
), MaxUsers(default_class
),
308 MaxSendq(default_class
),
309 MaxLocal(default_class
), MaxIdent(default_class
),
310 MaxGlobal(default_class
), MaxIdent(default_class
),
311 CurrUsers(default_class
));
317 * inputs - pointer to client
318 * output - sendq for this client as found from its class
319 * side effects - NONE
322 get_sendq(struct Client
*client_p
)
324 if(client_p
== NULL
|| IsMe(client_p
))
325 return DEFAULT_SENDQ
;
327 if(IsServer(client_p
))
329 struct server_conf
*server_p
;
330 server_p
= client_p
->localClient
->att_sconf
;
331 return MaxSendq(server_p
->class);
335 struct ConfItem
*aconf
= client_p
->localClient
->att_conf
;
337 if(aconf
!= NULL
&& aconf
->status
& CONF_CLIENT
)
338 return ConfMaxSendq(aconf
);
341 return DEFAULT_SENDQ
;