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

Comparing ircd-hybrid/trunk/src/client.c (file contents):
Revision 4140 by michael, Wed Jul 2 14:44:45 2014 UTC vs.
Revision 4400 by michael, Tue Aug 5 17:42:56 2014 UTC

# Line 49 | Line 49
49   #include "watch.h"
50   #include "rng_mt.h"
51   #include "parse.h"
52 + #include "ipcache.h"
53  
53 dlink_list listing_client_list = { NULL, NULL, 0 };
54 /* Pointer to beginning of Client list */
55 dlink_list global_client_list = {NULL, NULL, 0};
56 /* unknown/client pointer lists */
57 dlink_list unknown_list = {NULL, NULL, 0};
58 dlink_list local_client_list = {NULL, NULL, 0};
59 dlink_list serv_list = {NULL, NULL, 0};
60 dlink_list global_serv_list = {NULL, NULL, 0};
61 dlink_list oper_list = {NULL, NULL, 0};
54  
55 < static void check_pings(void *);
56 <
57 < static mp_pool_t *client_pool  = NULL;
58 < static mp_pool_t *lclient_pool = NULL;
59 <
60 < static dlink_list dead_list  = { NULL, NULL, 0};
61 < static dlink_list abort_list = { NULL, NULL, 0};
55 > dlink_list listing_client_list;
56 > dlink_list unknown_list;
57 > dlink_list local_client_list;
58 > dlink_list local_server_list;
59 > dlink_list global_client_list;
60 > dlink_list global_server_list;
61 > dlink_list oper_list;
62  
63 + static mp_pool_t *client_pool, *lclient_pool;
64 + static dlink_list dead_list, abort_list;
65   static dlink_node *eac_next;  /* next aborted client to exit */
66  
73 static void check_pings_list(dlink_list *);
74 static void check_unknowns_list(void);
75
76
77 /* client_init()
78 *
79 * inputs       - NONE
80 * output       - NONE
81 * side effects - initialize client free memory
82 */
83 void
84 client_init(void)
85 {
86  static struct event event_ping =
87  {
88    .name = "check_pings",
89    .handler = check_pings,
90    .when = 5
91  };
92
93  client_pool = mp_pool_new(sizeof(struct Client), MP_CHUNK_SIZE_CLIENT);
94  lclient_pool = mp_pool_new(sizeof(struct LocalUser), MP_CHUNK_SIZE_LCLIENT);
95  event_add(&event_ping, NULL);
96 }
67  
68   /*
69   * make_client - create a new Client struct and set it to initial state.
# Line 191 | Line 161 | free_client(struct Client *client_p)
161    mp_pool_release(client_p);
162   }
163  
194 /*
195 * check_pings - go through the local client list and check activity
196 * kill off stuff that should die
197 *
198 * inputs       - NOT USED (from event)
199 * output       - next time_t when check_pings() should be called again
200 * side effects -
201 *
202 *
203 * A PING can be sent to clients as necessary.
204 *
205 * Client/Server ping outs are handled.
206 */
207
208 /*
209 * Addon from adrian. We used to call this after nextping seconds,
210 * however I've changed it to run once a second. This is only for
211 * PING timeouts, not K/etc-line checks (thanks dianora!). Having it
212 * run once a second makes life a lot easier - when a new client connects
213 * and they need a ping in 4 seconds, if nextping was set to 20 seconds
214 * we end up waiting 20 seconds. This is stupid. :-)
215 * I will optimise (hah!) check_pings() once I've finished working on
216 * tidying up other network IO evilnesses.
217 *     -- adrian
218 */
219
220 static void
221 check_pings(void *notused)
222 {
223  check_pings_list(&local_client_list);
224  check_pings_list(&serv_list);
225  check_unknowns_list();
226 }
227
164   /* check_pings_list()
165   *
166   * inputs       - pointer to list to check
# Line 234 | Line 170 | check_pings(void *notused)
170   static void
171   check_pings_list(dlink_list *list)
172   {
173 <  char scratch[IRCD_BUFSIZE];
173 >  char buf[IRCD_BUFSIZE] = "";
174    int ping = 0;      /* ping time value from client */
175 <  dlink_node *ptr = NULL, *next_ptr = NULL;
175 >  dlink_node *ptr = NULL, *ptr_next = NULL;
176  
177 <  DLINK_FOREACH_SAFE(ptr, next_ptr, list->head)
177 >  DLINK_FOREACH_SAFE(ptr, ptr_next, list->head)
178    {
179      struct Client *client_p = ptr->data;
180  
245    /*
246    ** Note: No need to notify opers here. It's
247    ** already done when "FLAGS_DEADSOCKET" is set.
248    */
181      if (IsDead(client_p))
182 <    {
251 <      /* Ignore it, its been exited already */
252 <      continue;
253 <    }
182 >      continue;  /* Ignore it, its been exited already */
183  
184      if (!IsRegistered(client_p))
185        ping = CONNECTTIMEOUT;
# Line 262 | Line 191 | check_pings_list(dlink_list *list)
191        if (!IsPingSent(client_p))
192        {
193          /*
194 <         * if we havent PINGed the connection and we havent
194 >         * If we haven't PINGed the connection and we haven't
195           * heard from it in a while, PING it to make sure
196           * it is still alive.
197           */
# Line 290 | Line 219 | check_pings_list(dlink_list *list)
219                   get_client_name(client_p, HIDE_IP));
220            }
221  
222 <          snprintf(scratch, sizeof(scratch), "Ping timeout: %d seconds",
222 >          snprintf(buf, sizeof(buf), "Ping timeout: %d seconds",
223                     (int)(CurrentTime - client_p->localClient->lasttime));
224 <          exit_client(client_p, scratch);
224 >          exit_client(client_p, buf);
225          }
226        }
227      }
# Line 323 | Line 252 | check_unknowns_list(void)
252    }
253   }
254  
255 + /*
256 + * check_pings - go through the local client list and check activity
257 + * kill off stuff that should die
258 + *
259 + * inputs       - NOT USED (from event)
260 + * output       - next time_t when check_pings() should be called again
261 + * side effects -
262 + *
263 + *
264 + * A PING can be sent to clients as necessary.
265 + *
266 + * Client/Server ping outs are handled.
267 + */
268 +
269 + /*
270 + * Addon from adrian. We used to call this after nextping seconds,
271 + * however I've changed it to run once a second. This is only for
272 + * PING timeouts, not K/etc-line checks (thanks dianora!). Having it
273 + * run once a second makes life a lot easier - when a new client connects
274 + * and they need a ping in 4 seconds, if nextping was set to 20 seconds
275 + * we end up waiting 20 seconds. This is stupid. :-)
276 + * I will optimise (hah!) check_pings() once I've finished working on
277 + * tidying up other network IO evilnesses.
278 + *     -- adrian
279 + */
280 +
281 + static void
282 + check_pings(void *notused)
283 + {
284 +  check_pings_list(&local_client_list);
285 +  check_pings_list(&local_server_list);
286 +  check_unknowns_list();
287 + }
288 +
289   /* check_conf_klines()
290   *
291   * inputs       - NONE
# Line 352 | Line 315 | check_conf_klines(void)
315        continue; /* and go examine next fd/client_p */
316      }
317  
318 <    if (ConfigFileEntry.glines)
318 >    if (ConfigGeneral.glines)
319      {
320        if ((conf = find_conf_by_address(client_p->host, &client_p->localClient->ip,
321                                         CONF_GLINE, client_p->localClient->aftype,
# Line 529 | Line 492 | find_chasing(struct Client *source_p, co
492      return NULL;
493  
494    if ((who = whowas_get_history(name,
495 <                         (time_t)ConfigFileEntry.kill_chase_time_limit))
495 >                         (time_t)ConfigGeneral.kill_chase_time_limit))
496                           == NULL)
497    {
498      sendto_one_numeric(source_p, &me, ERR_NOSUCHNICK, name);
# Line 548 | Line 511 | find_chasing(struct Client *source_p, co
511   *        But, this can be used to any client structure.
512   *
513   * NOTE 1:
514 < *        Watch out the allocation of "nbuf", if either source_p->name
514 > *        Watch out the allocation of "buf", if either source_p->name
515   *        or source_p->sockhost gets changed into pointers instead of
516   *        directly allocated within the structure...
517   *
518   * NOTE 2:
519   *        Function return either a pointer to the structure (source_p) or
520 < *        to internal buffer (nbuf). *NEVER* use the returned pointer
520 > *        to internal buffer (buf). *NEVER* use the returned pointer
521   *        to modify what it points!!!
522   */
523   const char *
524   get_client_name(const struct Client *client_p, enum addr_mask_type type)
525   {
526 <  static char nbuf[HOSTLEN * 2 + USERLEN + 5];
526 >  static char buf[HOSTLEN * 2 + USERLEN + 5];
527  
528    assert(client_p);
529  
# Line 575 | Line 538 | get_client_name(const struct Client *cli
538        type = MASK_IP;
539    }
540  
541 <  if (ConfigFileEntry.hide_spoof_ips)
541 >  if (ConfigGeneral.hide_spoof_ips)
542      if (IsIPSpoof(client_p) && type == SHOW_IP)
543        type = MASK_IP;
544  
# Line 583 | Line 546 | get_client_name(const struct Client *cli
546    switch (type)
547    {
548      case SHOW_IP:
549 <      snprintf(nbuf, sizeof(nbuf), "%s[%s@%s]",
549 >      snprintf(buf, sizeof(buf), "%s[%s@%s]",
550                 client_p->name,
551                 client_p->username, client_p->sockhost);
552        break;
553      case MASK_IP:
554        if (client_p->localClient->aftype == AF_INET)
555 <        snprintf(nbuf, sizeof(nbuf), "%s[%s@255.255.255.255]",
555 >        snprintf(buf, sizeof(buf), "%s[%s@255.255.255.255]",
556                   client_p->name, client_p->username);
557        else
558 <        snprintf(nbuf, sizeof(nbuf), "%s[%s@ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff]",
558 >        snprintf(buf, sizeof(buf), "%s[%s@ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff]",
559                   client_p->name, client_p->username);
560        break;
561      default:
562 <      snprintf(nbuf, sizeof(nbuf), "%s[%s@%s]",
562 >      snprintf(buf, sizeof(buf), "%s[%s@%s]",
563                 client_p->name,
564                 client_p->username, client_p->host);
565    }
566  
567 <  return nbuf;
567 >  return buf;
568   }
569  
570   void
# Line 624 | Line 587 | free_exited_clients(void)
587   * The only messages generated are QUITs on channels.
588   */
589   static void
590 < exit_one_client(struct Client *source_p, const char *quitmsg)
590 > exit_one_client(struct Client *source_p, const char *comment)
591   {
592    dlink_node *ptr = NULL, *ptr_next = NULL;
593  
594    assert(!IsMe(source_p));
595 +  assert(source_p != &me);
596  
597    if (IsClient(source_p))
598    {
599      dlinkDelete(&source_p->lnode, &source_p->servptr->serv->client_list);
600 +    dlinkDelete(&source_p->node, &global_client_list);
601  
602      /*
603       * If a person is on a channel, send a QUIT notice
# Line 642 | Line 607 | exit_one_client(struct Client *source_p,
607       */
608      sendto_common_channels_local(source_p, 0, 0, ":%s!%s@%s QUIT :%s",
609                                   source_p->name, source_p->username,
610 <                                 source_p->host, quitmsg);
610 >                                 source_p->host, comment);
611      DLINK_FOREACH_SAFE(ptr, ptr_next, source_p->channel.head)
612        remove_user_from_channel(ptr->data);
613  
# Line 663 | Line 628 | exit_one_client(struct Client *source_p,
628    else if (IsServer(source_p))
629    {
630      dlinkDelete(&source_p->lnode, &source_p->servptr->serv->server_list);
631 +    dlinkDelete(&source_p->node, &global_client_list);
632  
633 <    if ((ptr = dlinkFindDelete(&global_serv_list, source_p)))
633 >    if ((ptr = dlinkFindDelete(&global_server_list, source_p)))
634        free_dlink_node(ptr);
635    }
636  
# Line 677 | Line 643 | exit_one_client(struct Client *source_p,
643    if (IsUserHostIp(source_p))
644      delete_user_host(source_p->username, source_p->host, !MyConnect(source_p));
645  
680  assert(source_p->node.next);
681  dlinkDelete(&source_p->node, &global_client_list);
682
646    update_client_exit_stats(source_p);
647  
648    /* Check to see if the client isn't already on the dead list */
# Line 697 | Line 660 | exit_one_client(struct Client *source_p,
660   * actually removing things off llists.   tweaked from +CSr31  -orabidoo
661   */
662   static void
663 < recurse_remove_clients(struct Client *source_p, const char *quitmsg)
663 > recurse_remove_clients(struct Client *source_p, const char *comment)
664   {
665    dlink_node *ptr = NULL, *ptr_next = NULL;
666  
667    DLINK_FOREACH_SAFE(ptr, ptr_next, source_p->serv->client_list.head)
668 <    exit_one_client(ptr->data, quitmsg);
668 >    exit_one_client(ptr->data, comment);
669  
670    DLINK_FOREACH_SAFE(ptr, ptr_next, source_p->serv->server_list.head)
671    {
672 <    recurse_remove_clients(ptr->data, quitmsg);
673 <    exit_one_client(ptr->data, quitmsg);
672 >    recurse_remove_clients(ptr->data, comment);
673 >    exit_one_client(ptr->data, comment);
674    }
675   }
676  
# Line 733 | Line 696 | exit_client(struct Client *source_p, con
696   {
697    dlink_node *m = NULL;
698  
699 +  assert(!IsMe(source_p));
700 +  assert(source_p != &me);
701 +
702    if (MyConnect(source_p))
703    {
704      /* DO NOT REMOVE. exit_client can be called twice after a failed
# Line 743 | Line 709 | exit_client(struct Client *source_p, con
709  
710      SetClosing(source_p);
711  
712 <    if (IsIpHash(source_p))
713 <      remove_one_ip(&source_p->localClient->ip);
712 >    if (HasFlag(source_p, FLAGS_IPHASH))
713 >    {
714 >      DelFlag(source_p, FLAGS_IPHASH);
715 >      ipcache_remove_address(&source_p->localClient->ip);
716 >    }
717  
718      delete_auth(&source_p->localClient->auth);
719  
# Line 781 | Line 750 | exit_client(struct Client *source_p, con
750        sendto_realops_flags(UMODE_CCONN, L_ALL, SEND_NOTICE,
751                             "Client exiting: %s (%s@%s) [%s] [%s]",
752                             source_p->name, source_p->username, source_p->host, comment,
753 <                           ConfigFileEntry.hide_spoof_ips && IsIPSpoof(source_p) ?
753 >                           ConfigGeneral.hide_spoof_ips && IsIPSpoof(source_p) ?
754                             "255.255.255.255" : source_p->sockhost);
755        ilog(LOG_TYPE_USER, "%s (%3u:%02u:%02u): %s!%s@%s %llu/%llu",
756             myctime(source_p->localClient->firsttime), (unsigned int)(on_for / 3600),
# Line 795 | Line 764 | exit_client(struct Client *source_p, con
764        assert(Count.myserver > 0);
765        --Count.myserver;
766  
767 <      assert(dlinkFind(&serv_list, source_p));
768 <      dlinkDelete(&source_p->localClient->lclient_node, &serv_list);
767 >      assert(dlinkFind(&local_server_list, source_p));
768 >      dlinkDelete(&source_p->localClient->lclient_node, &local_server_list);
769      }
770  
771      if (!IsDead(source_p))
# Line 840 | Line 809 | exit_client(struct Client *source_p, con
809        snprintf(splitstr, sizeof(splitstr), "%s %s",
810                 source_p->servptr->name, source_p->name);
811  
812 <    /* Send SQUIT for source_p in every direction. source_p is already off of serv_list here */
812 >    /* Send SQUIT for source_p in every direction. source_p is already off of local_server_list here */
813      if (!HasFlag(source_p, FLAGS_SQUIT))
814        sendto_server(NULL, NOCAPS, NOCAPS, "SQUIT %s :%s", source_p->id, comment);
815  
# Line 867 | Line 836 | exit_client(struct Client *source_p, con
836    /* The client *better* be off all of the lists */
837    assert(dlinkFind(&unknown_list, source_p) == NULL);
838    assert(dlinkFind(&local_client_list, source_p) == NULL);
839 <  assert(dlinkFind(&serv_list, source_p) == NULL);
839 >  assert(dlinkFind(&local_server_list, source_p) == NULL);
840    assert(dlinkFind(&oper_list, source_p) == NULL);
841  
842    exit_one_client(source_p, comment);
# Line 1111 | Line 1080 | idle_time_get(const struct Client *sourc
1080  
1081    return idle;
1082   }
1083 +
1084 + /* client_init()
1085 + *
1086 + * inputs       - NONE
1087 + * output       - NONE
1088 + * side effects - initialize client free memory
1089 + */
1090 + void
1091 + client_init(void)
1092 + {
1093 +  static struct event event_ping =
1094 +  {
1095 +    .name = "check_pings",
1096 +    .handler = check_pings,
1097 +    .when = 5
1098 +  };
1099 +
1100 +  client_pool = mp_pool_new(sizeof(struct Client), MP_CHUNK_SIZE_CLIENT);
1101 +  lclient_pool = mp_pool_new(sizeof(struct LocalUser), MP_CHUNK_SIZE_LCLIENT);
1102 +  event_add(&event_ping, NULL);
1103 + }

Diff Legend

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