ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/conf_class.c
(Generate patch)

Comparing ircd-hybrid/trunk/src/conf_class.c (file contents):
Revision 1666 by michael, Sun Nov 18 17:03:18 2012 UTC vs.
Revision 4565 by michael, Sun Aug 24 10:27:40 2014 UTC

# Line 1 | Line 1
1   /*
2 < *  ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
2 > *  ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3   *
4 < *  Copyright (C) 2002 by the past and present ircd coders, and others.
4 > *  Copyright (c) 1997-2014 ircd-hybrid development team
5   *
6   *  This program is free software; you can redistribute it and/or modify
7   *  it under the terms of the GNU General Public License as published by
# Line 15 | Line 15
15   *
16   *  You should have received a copy of the GNU General Public License
17   *  along with this program; if not, write to the Free Software
18 < *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
18 > *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19   *  USA
20   */
21  
22 < /*! \file
22 > /*! \file conf_class.c
23   * \brief Configuration managment for class{} blocks
24   * \version $Id$
25   */
# Line 35 | Line 35
35  
36   struct ClassItem *class_default;
37  
38 < static dlink_list class_list = { NULL, NULL, 0 };
38 > static dlink_list class_list;
39  
40  
41   const dlink_list *
# Line 47 | Line 47 | class_get_list(void)
47   struct ClassItem *
48   class_make(void)
49   {
50 <  struct ClassItem *class = MyMalloc(sizeof(*class));
50 >  struct ClassItem *class = MyCalloc(sizeof(*class));
51  
52    class->active    = 1;
53    class->con_freq  = DEFAULT_CONNECTFREQUENCY;
# Line 64 | Line 64 | class_make(void)
64   void
65   class_free(struct ClassItem *class)
66   {
67 <  assert(class);
67 >  assert(class != class_default);
68    assert(class->active    == 0);
69    assert(class->ref_count == 0);
70  
# Line 79 | Line 79 | class_init(void)
79    (class_default = class_make())->name = xstrdup("default");
80   }
81  
82 + struct ClassItem *
83 + get_class_ptr(const dlink_list *const list)
84 + {
85 +  const dlink_node *ptr = NULL;
86 +
87 +  if ((ptr = list->head))
88 +  {
89 +    const struct MaskItem *conf = ptr->data;
90 +
91 +    assert(conf->class);
92 +    assert(conf->type & (CONF_OPER | CONF_CLIENT | CONF_SERVER));
93 +
94 +    return conf->class;
95 +  }
96 +
97 +  return class_default;
98 + }
99 +
100   const char *
101   get_client_class(const dlink_list *const list)
102   {
103    const dlink_node *ptr = NULL;
104  
105 <  if ((ptr = list->head)) {
105 >  if ((ptr = list->head))
106 >  {
107      const struct MaskItem *conf = ptr->data;
108  
109      assert(conf->class);
# Line 101 | Line 120 | get_client_ping(const dlink_list *const
120   {
121    const dlink_node *ptr = NULL;
122  
123 <  if ((ptr = list->head)) {
123 >  if ((ptr = list->head))
124 >  {
125      const struct MaskItem *conf = ptr->data;
126  
127      assert(conf->class);
# Line 118 | Line 138 | get_sendq(const dlink_list *const list)
138   {
139    const dlink_node *ptr = NULL;
140  
141 <  if ((ptr = list->head)) {
141 >  if ((ptr = list->head))
142 >  {
143      const struct MaskItem *conf = ptr->data;
144  
145      assert(conf->class);
# Line 135 | Line 156 | get_recvq(const dlink_list *const list)
156   {
157    const dlink_node *ptr = NULL;
158  
159 <  if ((ptr = list->head)) {
159 >  if ((ptr = list->head))
160 >  {
161      const struct MaskItem *conf = ptr->data;
162  
163      assert(conf->class);
# Line 157 | Line 179 | class_find(const char *name, int active)
179   {
180    dlink_node *ptr = NULL;
181  
182 <  DLINK_FOREACH(ptr, class_list.head) {
182 >  DLINK_FOREACH(ptr, class_list.head)
183 >  {
184      struct ClassItem *class = ptr->data;
185  
186      if (!irccmp(class->name, name))
# Line 185 | Line 208 | class_delete_marked(void)
208   {
209    dlink_node *ptr = NULL, *ptr_next = NULL;
210  
211 <  DLINK_FOREACH_SAFE(ptr, ptr_next, class_list.head) {
211 >  DLINK_FOREACH_SAFE(ptr, ptr_next, class_list.head)
212 >  {
213      struct ClassItem *class = ptr->data;
214  
215      if (!class->active && !class->ref_count)
# Line 207 | Line 231 | class_delete_marked(void)
231   * side effects -
232   */
233   int
234 < cidr_limit_reached(int over_rule,
211 <                   struct irc_ssaddr *ip, struct ClassItem *class)
234 > cidr_limit_reached(int over_rule, struct irc_ssaddr *ip, struct ClassItem *class)
235   {
236    dlink_node *ptr = NULL;
237    struct CidrItem *cidr = NULL;
# Line 224 | Line 247 | cidr_limit_reached(int over_rule,
247      DLINK_FOREACH(ptr, class->list_ipv4.head)
248      {
249        cidr = ptr->data;
250 +
251        if (match_ipv4(ip, &cidr->mask, class->cidr_bitlen_ipv4))
252        {
253          if (!over_rule && (cidr->number_on_this_cidr >= class->number_per_cidr))
254            return -1;
255 +
256          cidr->number_on_this_cidr++;
257          return 0;
258        }
259      }
260 <    cidr = MyMalloc(sizeof(struct CidrItem));
260 >
261 >    cidr = MyCalloc(sizeof(struct CidrItem));
262      cidr->number_on_this_cidr = 1;
263      cidr->mask = *ip;
264      mask_addr(&cidr->mask, class->cidr_bitlen_ipv4);
265      dlinkAdd(cidr, &cidr->node, &class->list_ipv4);
266    }
241 #ifdef IPV6
267    else if (class->cidr_bitlen_ipv6 > 0)
268    {
269      DLINK_FOREACH(ptr, class->list_ipv6.head)
270      {
271        cidr = ptr->data;
272 +
273        if (match_ipv6(ip, &cidr->mask, class->cidr_bitlen_ipv6))
274        {
275          if (!over_rule && (cidr->number_on_this_cidr >= class->number_per_cidr))
276            return -1;
277 +
278          cidr->number_on_this_cidr++;
279          return 0;
280        }
281      }
282 <    cidr = MyMalloc(sizeof(struct CidrItem));
282 >
283 >    cidr = MyCalloc(sizeof(struct CidrItem));
284      cidr->number_on_this_cidr = 1;
285      cidr->mask = *ip;
286      mask_addr(&cidr->mask, class->cidr_bitlen_ipv6);
287      dlinkAdd(cidr, &cidr->node, &class->list_ipv6);
288    }
289 < #endif
289 >
290    return 0;
291   }
292  
# Line 288 | Line 316 | remove_from_cidr_check(struct irc_ssaddr
316      DLINK_FOREACH_SAFE(ptr, next_ptr, aclass->list_ipv4.head)
317      {
318        cidr = ptr->data;
319 +
320        if (match_ipv4(ip, &cidr->mask, aclass->cidr_bitlen_ipv4))
321        {
322 <        cidr->number_on_this_cidr--;
323 <        if (cidr->number_on_this_cidr == 0)
324 <        {
325 <          dlinkDelete(ptr, &aclass->list_ipv4);
326 <          MyFree(cidr);
327 <          return;
328 <        }
322 >        cidr->number_on_this_cidr--;
323 >
324 >        if (cidr->number_on_this_cidr == 0)
325 >        {
326 >          dlinkDelete(ptr, &aclass->list_ipv4);
327 >          MyFree(cidr);
328 >          return;
329 >        }
330        }
331      }
332    }
303 #ifdef IPV6
333    else if (aclass->cidr_bitlen_ipv6 > 0)
334    {
335      DLINK_FOREACH_SAFE(ptr, next_ptr, aclass->list_ipv6.head)
336      {
337        cidr = ptr->data;
338 +
339        if (match_ipv6(ip, &cidr->mask, aclass->cidr_bitlen_ipv6))
340        {
341 <        cidr->number_on_this_cidr--;
342 <        if (cidr->number_on_this_cidr == 0)
343 <        {
344 <          dlinkDelete(ptr, &aclass->list_ipv6);
345 <          MyFree(cidr);
346 <          return;
347 <        }
341 >        cidr->number_on_this_cidr--;
342 >
343 >        if (cidr->number_on_this_cidr == 0)
344 >        {
345 >          dlinkDelete(ptr, &aclass->list_ipv6);
346 >          MyFree(cidr);
347 >          return;
348 >        }
349        }
350      }
351    }
321 #endif
352   }
353  
354   void
355   rebuild_cidr_list(struct ClassItem *class)
356   {
357 <  dlink_node *ptr;
357 >  dlink_node *ptr = NULL;
358  
359    destroy_cidr_class(class);
360  
# Line 349 | Line 379 | rebuild_cidr_list(struct ClassItem *clas
379   static void
380   destroy_cidr_list(dlink_list *list)
381   {
382 <  dlink_node *ptr = NULL, *next_ptr = NULL;
382 >  dlink_node *ptr = NULL, *ptr_next = NULL;
383  
384 <  DLINK_FOREACH_SAFE(ptr, next_ptr, list->head)
384 >  DLINK_FOREACH_SAFE(ptr, ptr_next, list->head)
385    {
386      dlinkDelete(ptr, list);
387      MyFree(ptr->data);

Diff Legend

Removed lines
+ Added lines
< Changed lines (old)
> Changed lines (new)