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 1646 by michael, Wed Nov 7 21:02:43 2012 UTC vs.
Revision 2213 by michael, Wed Jun 5 22:25:49 2013 UTC

# Line 26 | Line 26
26  
27   #include "stdinc.h"
28   #include "list.h"
29 #include "ircd_defs.h"
30 #include "balloc.h"
31 #include "conf.h"
32 #include "s_serv.h"
33 #include "resv.h"
34 #include "channel.h"
35 #include "client.h"
36 #include "event.h"
37 #include "hook.h"
38 #include "irc_string.h"
39 #include "s_bsd.h"
29   #include "ircd.h"
30 < #include "listener.h"
30 > #include "conf.h"
31   #include "hostmask.h"
32 < #include "modules.h"
44 < #include "numeric.h"
45 < #include "fdlist.h"
46 < #include "log.h"
47 < #include "send.h"
48 < #include "s_gline.h"
32 > #include "irc_string.h"
33   #include "memory.h"
50 #include "irc_res.h"
51 #include "userhost.h"
52 #include "s_user.h"
53 #include "channel_mode.h"
54 #include "parse.h"
55 #include "s_misc.h"
56 #include "conf_db.h"
34  
35  
36   struct ClassItem *class_default;
# Line 72 | Line 49 | class_make(void)
49   {
50    struct ClassItem *class = MyMalloc(sizeof(*class));
51  
52 +  class->active    = 1;
53 +  class->con_freq  = DEFAULT_CONNECTFREQUENCY;
54 +  class->ping_freq = DEFAULT_PINGFREQUENCY;
55 +  class->max_total = MAXIMUM_LINKS_DEFAULT;
56 +  class->max_sendq = DEFAULT_SENDQ;
57 +  class->max_recvq = DEFAULT_RECVQ;
58 +
59    dlinkAdd(class, &class->node, &class_list);
60  
61    return class;
# Line 92 | Line 76 | class_free(struct ClassItem *class)
76   void
77   class_init(void)
78   {
79 <  class_default = class_make();
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 <  class_default->name      = xstrdup("default");
98 <  class_default->active    = 1;
99 <  class_default->con_freq  = DEFAULT_CONNECTFREQUENCY;
100 <  class_default->ping_freq = DEFAULT_PINGFREQUENCY;
101 <  class_default->max_total = MAXIMUM_LINKS_DEFAULT;
102 <  class_default->max_sendq = DEFAULT_SENDQ;
103 <  class_default->max_recvq = DEFAULT_RECVQ;
97 >  return class_default;
98   }
99  
100   const char *
# Line 108 | Line 102 | get_client_class(const dlink_list *const
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);
110 <    assert(conf->type & (CONF_OPERATOR | CONF_CLIENT | CONF_SERVER));
110 >    assert(conf->type & (CONF_OPER | CONF_CLIENT | CONF_SERVER));
111  
112      return conf->class->name;
113    }
# Line 125 | 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(aconf->class);
128 <    assert(aconf->type & (CONF_OPERATOR | CONF_CLIENT | CONF_SERVER));
127 >    assert(conf->class);
128 >    assert(conf->type & (CONF_OPER | CONF_CLIENT | CONF_SERVER));
129  
130      return conf->class->ping_freq;
131    }
# Line 142 | 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);
146 <    assert(conf->type & (CONF_OPERATOR | CONF_CLIENT | CONF_SERVER));
146 >    assert(conf->type & (CONF_OPER | CONF_CLIENT | CONF_SERVER));
147  
148      return conf->class->max_sendq;
149    }
# Line 159 | 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);
164 <    assert(conf->type & (CONF_OPERATOR | CONF_CLIENT | CONF_SERVER));
164 >    assert(conf->type & (CONF_OPER | CONF_CLIENT | CONF_SERVER));
165  
166      return conf->class->max_recvq;
167    }
# Line 181 | 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 200 | Line 199 | class_mark_for_deletion(void)
199   {
200    dlink_node *ptr = NULL;
201  
202 <  DLINK_FOREACH(ptr, class_list.head)
203 <  {
205 <    struct ClassItem *class = ptr->data;
206 <
207 <    if (class != class_default)
208 <      class->active = 0;
209 <  }
202 >  DLINK_FOREACH_PREV(ptr, class_list.tail->prev)
203 >    ((struct ClassItem *)ptr->data)->active = 0;
204   }
205  
206   void
# Line 214 | 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 236 | Line 231 | class_delete_marked(void)
231   * side effects -
232   */
233   int
234 < cidr_limit_reached(int over_rule,
240 <                   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 253 | 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 +
261      cidr = MyMalloc(sizeof(struct CidrItem));
262      cidr->number_on_this_cidr = 1;
263      cidr->mask = *ip;
# Line 273 | Line 270 | cidr_limit_reached(int over_rule,
270      DLINK_FOREACH(ptr, class->list_ipv6.head)
271      {
272        cidr = ptr->data;
273 +
274        if (match_ipv6(ip, &cidr->mask, class->cidr_bitlen_ipv6))
275        {
276          if (!over_rule && (cidr->number_on_this_cidr >= class->number_per_cidr))
277            return -1;
278 +
279          cidr->number_on_this_cidr++;
280          return 0;
281        }
282      }
283 +
284      cidr = MyMalloc(sizeof(struct CidrItem));
285      cidr->number_on_this_cidr = 1;
286      cidr->mask = *ip;
# Line 317 | Line 317 | remove_from_cidr_check(struct irc_ssaddr
317      DLINK_FOREACH_SAFE(ptr, next_ptr, aclass->list_ipv4.head)
318      {
319        cidr = ptr->data;
320 +
321        if (match_ipv4(ip, &cidr->mask, aclass->cidr_bitlen_ipv4))
322        {
323 <        cidr->number_on_this_cidr--;
324 <        if (cidr->number_on_this_cidr == 0)
325 <        {
326 <          dlinkDelete(ptr, &aclass->list_ipv4);
327 <          MyFree(cidr);
328 <          return;
329 <        }
323 >        cidr->number_on_this_cidr--;
324 >
325 >        if (cidr->number_on_this_cidr == 0)
326 >        {
327 >          dlinkDelete(ptr, &aclass->list_ipv4);
328 >          MyFree(cidr);
329 >          return;
330 >        }
331        }
332      }
333    }
# Line 335 | Line 337 | remove_from_cidr_check(struct irc_ssaddr
337      DLINK_FOREACH_SAFE(ptr, next_ptr, aclass->list_ipv6.head)
338      {
339        cidr = ptr->data;
340 +
341        if (match_ipv6(ip, &cidr->mask, aclass->cidr_bitlen_ipv6))
342        {
343 <        cidr->number_on_this_cidr--;
344 <        if (cidr->number_on_this_cidr == 0)
345 <        {
346 <          dlinkDelete(ptr, &aclass->list_ipv6);
347 <          MyFree(cidr);
348 <          return;
349 <        }
343 >        cidr->number_on_this_cidr--;
344 >
345 >        if (cidr->number_on_this_cidr == 0)
346 >        {
347 >          dlinkDelete(ptr, &aclass->list_ipv6);
348 >          MyFree(cidr);
349 >          return;
350 >        }
351        }
352      }
353    }
354   #endif
355   }
356  
357 < static void
358 < rebuild_cidr_list(int aftype, struct ClassItem *oldcl, struct ClassItem *newcl,
355 <                  dlink_list *old_list, dlink_list *new_list, int changed)
357 > void
358 > rebuild_cidr_list(struct ClassItem *class)
359   {
360    dlink_node *ptr;
358  struct Client *client_p;
359  struct MaskItem *conf;
361  
362 <  if (!changed)
362 <  {
363 <    *new_list = *old_list;
364 <    old_list->head = old_list->tail = NULL;
365 <    old_list->length = 0;
366 <    return;
367 <  }
362 >  destroy_cidr_class(class);
363  
364    DLINK_FOREACH(ptr, local_client_list.head)
365    {
366 <    client_p = ptr->data;
367 <    if (client_p->localClient->aftype != aftype)
373 <      continue;
374 <    if (dlink_list_length(&client_p->localClient->confs) == 0)
375 <      continue;
376 <
377 <    conf = client_p->localClient->confs.tail->data;
378 <    if (conf->type == CONF_CLIENT)
379 <      if (conf->class == oldcl)
380 <        cidr_limit_reached(1, &client_p->localClient->ip, newcl);
381 <  }
382 < }
383 <
384 < /*
385 < * rebuild_cidr_class
386 < *
387 < * inputs       - pointer to old conf
388 < *              - pointer to new_class
389 < * output       - none
390 < * side effects - rebuilds the class link list of cidr blocks
391 < */
392 < void
393 < rebuild_cidr_class(struct ClassItem *old_class, struct ClassItem *new_class)
394 < {
395 <  if (old_class->number_per_cidr > 0 && new_class->number_per_cidr > 0)
396 <  {
397 <    if (old_class->cidr_bitlen_ipv4 > 0 && new_class->cidr_bitlen_ipv4 > 0)
398 <      rebuild_cidr_list(AF_INET, old_class, new_class,
399 <                        &old_class->list_ipv4, &new_class->list_ipv4,
400 <                        old_class->cidr_bitlen_ipv4 != new_class->cidr_bitlen_ipv4);
366 >    struct Client *client_p = ptr->data;
367 >    struct MaskItem *conf = client_p->localClient->confs.tail->data;
368  
369 < #ifdef IPV6
370 <    if (old_class->cidr_bitlen_ipv6 > 0 && new_class->cidr_bitlen_ipv6 > 0)
371 <      rebuild_cidr_list(AF_INET6, old_class, new_class,
405 <                        &old_class->list_ipv6, &new_class->list_ipv6,
406 <                        old_class->cidr_bitlen_ipv6 != new_class->cidr_bitlen_ipv6);
407 < #endif
369 >    if (conf && (conf->type == CONF_CLIENT))
370 >      if (conf->class == class)
371 >        cidr_limit_reached(1, &client_p->localClient->ip, class);
372    }
409
410  destroy_cidr_class(old_class);
373   }
374  
375   /*

Comparing ircd-hybrid/trunk/src/conf_class.c (property svn:eol-style):
Revision 1646 by michael, Wed Nov 7 21:02:43 2012 UTC vs.
Revision 2213 by michael, Wed Jun 5 22:25:49 2013 UTC

# Line 0 | Line 1
1 + native

Comparing ircd-hybrid/trunk/src/conf_class.c (property svn:executable):
Revision 1646 by michael, Wed Nov 7 21:02:43 2012 UTC vs.
Revision 2213 by michael, Wed Jun 5 22:25:49 2013 UTC

# Line 1 | Line 0
1 *

Comparing ircd-hybrid/trunk/src/conf_class.c (property svn:keywords):
Revision 1646 by michael, Wed Nov 7 21:02:43 2012 UTC vs.
Revision 2213 by michael, Wed Jun 5 22:25:49 2013 UTC

# Line 1 | Line 1
1 < Id
1 > Id Revision

Diff Legend

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