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

Comparing ircd-hybrid/branches/8.2.x/src/server.c (file contents):
Revision 5459 by michael, Tue Feb 3 22:24:23 2015 UTC vs.
Revision 6528 by michael, Fri Sep 11 16:33:52 2015 UTC

# Line 48 | Line 48
48   #include "channel.h"
49   #include "parse.h"
50  
51 #define MIN_CONN_FREQ 300
51  
52   dlink_list flatten_links;
53 < static dlink_list cap_list;
53 > static dlink_list server_capabilities_list;
54   static void serv_connect_callback(fde_t *, int, void *);
55  
56  
# Line 177 | Line 176 | hunt_server(struct Client *source_p, con
176  
177    if (!target_p && has_wildcards(parv[server]))
178    {
179 <    DLINK_FOREACH(node, global_client_list.head)
179 >    DLINK_FOREACH(node, global_server_list.head)
180      {
181        struct Client *tmp = node->data;
182  
183 <      assert(IsMe(tmp) || IsServer(tmp) || IsClient(tmp));
183 >      assert(IsMe(tmp) || IsServer(tmp));
184        if (!match(parv[server], tmp->name))
185        {
186          if (tmp->from == source_p->from && !MyConnect(tmp))
# Line 191 | Line 190 | hunt_server(struct Client *source_p, con
190          break;
191        }
192      }
193 +
194 +    if (!target_p)
195 +    {
196 +      DLINK_FOREACH(node, global_client_list.head)
197 +      {
198 +        struct Client *tmp = node->data;
199 +
200 +        assert(IsMe(tmp) || IsServer(tmp) || IsClient(tmp));
201 +        if (!match(parv[server], tmp->name))
202 +        {
203 +          if (tmp->from == source_p->from && !MyConnect(tmp))
204 +            continue;
205 +
206 +          target_p = node->data;
207 +          break;
208 +        }
209 +      }
210 +    }
211    }
212  
213    if (target_p)
# Line 224 | Line 241 | void
241   try_connections(void *unused)
242   {
243    dlink_node *node = NULL;
227  int confrq = 0;
244  
245    /* TODO: change this to set active flag to 0 when added to event! --Habeeb */
246    if (GlobalSetOptions.autoconn == 0)
# Line 253 | Line 269 | try_connections(void *unused)
269  
270      assert(conf->class);
271  
272 <    confrq = conf->class->con_freq;
257 <    if (confrq < MIN_CONN_FREQ)
258 <      confrq = MIN_CONN_FREQ;
259 <
260 <    conf->until = CurrentTime + confrq;
272 >    conf->until = CurrentTime + conf->class->con_freq;
273  
274      /*
275       * Found a CONNECT config with port specified, scan clients
# Line 268 | Line 280 | try_connections(void *unused)
280  
281      if (conf->class->ref_count < conf->class->max_total)
282      {
283 <      /* Go to the end of the list, if not already last */
283 >      /* Move this entry to the end of the list, if not already last */
284        if (node->next)
285        {
286          dlinkDelete(node, &server_items);
# Line 288 | Line 300 | try_connections(void *unused)
300         *   -- adrian
301         */
302        if (ConfigServerHide.hide_server_ips)
303 <        sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
303 >        sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
304                               "Connection to %s activated.",
305                               conf->name);
306        else
307 <        sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
307 >        sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
308                               "Connection to %s[%s] activated.",
309                               conf->name, conf->host);
310  
# Line 331 | Line 343 | check_server(const char *name, struct Cl
343  
344    assert(client_p);
345  
346 <  /* loop through looking for all possible connect items that might work */
346 >  /* Loop through looking for all possible connect items that might work */
347    DLINK_FOREACH(node, server_items.head)
348    {
349      conf = node->data;
# Line 364 | Line 376 | check_server(const char *name, struct Cl
376  
377    attach_conf(client_p, server_conf);
378  
379 <
368 <  if (server_conf)
379 >  switch (server_conf->aftype)
380    {
381 <    struct sockaddr_in *v4;
371 <    struct sockaddr_in6 *v6;
372 <
373 <    switch (server_conf->aftype)
381 >    case AF_INET6:
382      {
383 <      case AF_INET6:
376 <        v6 = (struct sockaddr_in6 *)&server_conf->addr;
383 >      const struct sockaddr_in6 *v6 = (struct sockaddr_in6 *)&server_conf->addr;
384  
385 <        if (IN6_IS_ADDR_UNSPECIFIED(&v6->sin6_addr))
386 <          memcpy(&server_conf->addr, &client_p->connection->ip, sizeof(struct irc_ssaddr));
387 <        break;
388 <      case AF_INET:
389 <        v4 = (struct sockaddr_in *)&server_conf->addr;
385 >      if (IN6_IS_ADDR_UNSPECIFIED(&v6->sin6_addr))
386 >        memcpy(&server_conf->addr, &client_p->connection->ip, sizeof(struct irc_ssaddr));
387 >      break;
388 >    }
389 >    case AF_INET:
390 >    {
391 >      const struct sockaddr_in *v4 = (struct sockaddr_in *)&server_conf->addr;
392  
393 <        if (v4->sin_addr.s_addr == INADDR_NONE)
394 <          memcpy(&server_conf->addr, &client_p->connection->ip, sizeof(struct irc_ssaddr));
395 <        break;
393 >      if (v4->sin_addr.s_addr == INADDR_NONE)
394 >        memcpy(&server_conf->addr, &client_p->connection->ip, sizeof(struct irc_ssaddr));
395 >      break;
396      }
397    }
398  
# Line 400 | Line 409 | check_server(const char *name, struct Cl
409   *                modules to dynamically add or subtract their capability.
410   */
411   void
412 < add_capability(const char *capab_name, int cap_flag, int add_to_default)
412 > add_capability(const char *name, unsigned int flag)
413   {
414    struct Capability *cap = MyCalloc(sizeof(*cap));
415  
416 <  cap->name = xstrdup(capab_name);
417 <  cap->cap = cap_flag;
418 <  dlinkAdd(cap, &cap->node, &cap_list);
410 <
411 <  if (add_to_default)
412 <    default_server_capabs |= cap_flag;
416 >  cap->name = xstrdup(name);
417 >  cap->cap = flag;
418 >  dlinkAdd(cap, &cap->node, &server_capabilities_list);
419   }
420  
421   /* delete_capability()
# Line 418 | Line 424 | add_capability(const char *capab_name, i
424   * output       - NONE
425   * side effects - delete given capability from ones known.
426   */
427 < int
428 < delete_capability(const char *capab_name)
427 > void
428 > delete_capability(const char *name)
429   {
430    dlink_node *node = NULL, *node_next = NULL;
431  
432 <  DLINK_FOREACH_SAFE(node, node_next, cap_list.head)
432 >  DLINK_FOREACH_SAFE(node, node_next, server_capabilities_list.head)
433    {
434      struct Capability *cap = node->data;
435  
436 <    if (cap->cap)
436 >    if (!irccmp(cap->name, name))
437      {
438 <      if (!irccmp(cap->name, capab_name))
439 <      {
440 <        default_server_capabs &= ~(cap->cap);
435 <        dlinkDelete(node, &cap_list);
436 <        MyFree(cap->name);
437 <        MyFree(cap);
438 <      }
438 >      dlinkDelete(node, &server_capabilities_list);
439 >      MyFree(cap->name);
440 >      MyFree(cap);
441      }
442    }
441
442  return 0;
443   }
444  
445   /*
# Line 450 | Line 450 | delete_capability(const char *capab_name
450   * side effects - none
451   */
452   unsigned int
453 < find_capability(const char *capab)
453 > find_capability(const char *name)
454   {
455    const dlink_node *node = NULL;
456  
457 <  DLINK_FOREACH(node, cap_list.head)
457 >  DLINK_FOREACH(node, server_capabilities_list.head)
458    {
459      const struct Capability *cap = node->data;
460  
461 <    if (cap->cap && !irccmp(cap->name, capab))
461 >    if (!irccmp(cap->name, name))
462        return cap->cap;
463    }
464  
# Line 474 | Line 474 | find_capability(const char *capab)
474   *
475   */
476   void
477 < send_capabilities(struct Client *client_p, int cap_can_send)
477 > send_capabilities(struct Client *client_p)
478   {
479    char buf[IRCD_BUFSIZE] = "";
480    const dlink_node *node = NULL;
481  
482 <  DLINK_FOREACH(node, cap_list.head)
482 >  DLINK_FOREACH(node, server_capabilities_list.head)
483    {
484      const struct Capability *cap = node->data;
485  
486 <    if (cap->cap & (cap_can_send|default_server_capabs))
487 <    {
488 <      strlcat(buf, cap->name, sizeof(buf));
489 <      if (node->next)
490 <        strlcat(buf, " ", sizeof(buf));
491 <    }
486 >    strlcat(buf, cap->name, sizeof(buf));
487 >
488 >    if (node->next)
489 >      strlcat(buf, " ", sizeof(buf));
490    }
491  
492    sendto_one(client_p, "CAPAB :%s", buf);
# Line 509 | Line 507 | show_capabilities(const struct Client *t
507  
508    strlcpy(msgbuf, "TS", sizeof(msgbuf));
509  
510 <  DLINK_FOREACH(node, cap_list.head)
510 >  DLINK_FOREACH(node, server_capabilities_list.head)
511    {
512      const struct Capability *cap = node->data;
513  
# Line 580 | Line 578 | serv_connect(struct MaskItem *conf, stru
578    /* Still processing a DNS lookup? -> exit */
579    if (conf->dns_pending)
580    {
581 <    sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
581 >    sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
582                           "Error connecting to %s: DNS lookup for connect{} in progress.",
583                           conf->name);
584      return 0;
# Line 588 | Line 586 | serv_connect(struct MaskItem *conf, stru
586  
587    if (conf->dns_failed)
588    {
589 <    sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
589 >    sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
590                           "Error connecting to %s: DNS lookup for connect{} failed.",
591                           conf->name);
592      return 0;
# Line 599 | Line 597 | serv_connect(struct MaskItem *conf, stru
597     */
598    if ((client_p = hash_find_server(conf->name)))
599    {
600 <    sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
600 >    sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE,
601                           "Server %s already present from %s",
602                           conf->name, get_client_name(client_p, SHOW_IP));
603 <    sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE,
603 >    sendto_realops_flags(UMODE_SERVNOTICE, L_OPER, SEND_NOTICE,
604                           "Server %s already present from %s",
605                           conf->name, get_client_name(client_p, MASK_IP));
606      if (by && IsClient(by) && !MyClient(by))
# Line 640 | Line 638 | serv_connect(struct MaskItem *conf, stru
638     */
639    if (!attach_connect_block(client_p, conf->name, conf->host))
640    {
641 <    sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
641 >    sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
642                           "Host %s is not enabled for connecting: no connect {} block",
643                           conf->name);
644      if (by && IsClient(by) && !MyClient(by))
# Line 757 | Line 755 | finish_ssl_server_handshake(struct Clien
755                          client_p->name, CONF_SERVER);
756    if (conf == NULL)
757    {
758 <    sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
759 <                         "Lost connect{} block for %s", get_client_name(client_p, HIDE_IP));
760 <    sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE,
758 >    sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE,
759 >                         "Lost connect{} block for %s", get_client_name(client_p, SHOW_IP));
760 >    sendto_realops_flags(UMODE_SERVNOTICE, L_OPER, SEND_NOTICE,
761                           "Lost connect{} block for %s", get_client_name(client_p, MASK_IP));
762  
763      exit_client(client_p, "Lost connect{} block");
# Line 768 | Line 766 | finish_ssl_server_handshake(struct Clien
766  
767    sendto_one(client_p, "PASS %s TS %d %s", conf->spasswd, TS_CURRENT, me.id);
768  
769 <  send_capabilities(client_p, 0);
769 >  send_capabilities(client_p);
770  
771    sendto_one(client_p, "SERVER %s 1 :%s%s",
772               me.name, ConfigServerHide.hidden ? "(H) " : "",
773               me.info);
774  
775 <  /* If we've been marked dead because a send failed, just exit
775 >  /*
776 >   * If we've been marked dead because a send failed, just exit
777     * here now and save everyone the trouble of us ever existing.
778     */
779    if (IsDead(client_p))
780    {
781 <      sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
782 <                           "%s[%s] went dead during handshake",
783 <                           client_p->name,
784 <                           client_p->host);
785 <      sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE,
787 <                           "%s went dead during handshake", client_p->name);
788 <      return;
781 >    sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE,
782 >                         "%s went dead during handshake", get_client_name(client_p, SHOW_IP));
783 >    sendto_realops_flags(UMODE_SERVNOTICE, L_OPER, SEND_NOTICE,
784 >                         "%s went dead during handshake", get_client_name(client_p, MASK_IP));
785 >    return;
786    }
787  
788    /* don't move to serv_list yet -- we haven't sent a burst! */
# Line 821 | Line 818 | ssl_server_handshake(fde_t *fd, void *da
818        default:
819        {
820          const char *sslerr = ERR_error_string(ERR_get_error(), NULL);
821 <        sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
821 >        sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
822                               "Error connecting to %s: %s", client_p->name,
823                               sslerr ? sslerr : "unknown SSL error");
824          exit_client(client_p, "Error during SSL handshake");
# Line 860 | Line 857 | ssl_server_handshake(fde_t *fd, void *da
857   }
858  
859   static void
860 < ssl_connect_init(struct Client *client_p, struct MaskItem *conf, fde_t *fd)
860 > ssl_connect_init(struct Client *client_p, const struct MaskItem *conf, fde_t *fd)
861   {
862    if ((client_p->connection->fd.ssl = SSL_new(ConfigServerInfo.client_ctx)) == NULL)
863    {
# Line 891 | Line 888 | ssl_connect_init(struct Client *client_p
888   static void
889   serv_connect_callback(fde_t *fd, int status, void *data)
890   {
891 <  struct Client *client_p = data;
892 <  struct MaskItem *conf = NULL;
891 >  struct Client *const client_p = data;
892 >  const struct MaskItem *conf = NULL;
893  
894    /* First, make sure it's a real client! */
895    assert(client_p);
# Line 905 | Line 902 | serv_connect_callback(fde_t *fd, int sta
902    /* Check the status */
903    if (status != COMM_OK)
904    {
905 <    /* We have an error, so report it and quit
906 <     * Admins get to see any IP, mere opers don't *sigh*
905 >    /* We have an error, so report it and quit */
906 >    sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE,
907 >                         "Error connecting to %s: %s",
908 >                         get_client_name(client_p, SHOW_IP), comm_errstr(status));
909 >    sendto_realops_flags(UMODE_SERVNOTICE, L_OPER, SEND_NOTICE,
910 >                         "Error connecting to %s: %s",
911 >                         get_client_name(client_p, MASK_IP), comm_errstr(status));
912 >
913 >    /*
914 >     * If a fd goes bad, call dead_link() the socket is no
915 >     * longer valid for reading or writing.
916       */
917 <     if (ConfigServerHide.hide_server_ips)
918 <       sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
913 <                            "Error connecting to %s: %s",
914 <                            client_p->name, comm_errstr(status));
915 <     else
916 <       sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
917 <                            "Error connecting to %s[%s]: %s", client_p->name,
918 <                            client_p->host, comm_errstr(status));
919 <
920 <     sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE,
921 <                          "Error connecting to %s: %s",
922 <                          client_p->name, comm_errstr(status));
923 <
924 <     /* If a fd goes bad, call dead_link() the socket is no
925 <      * longer valid for reading or writing.
926 <      */
927 <     dead_link_on_write(client_p, 0);
928 <     return;
917 >    dead_link_on_write(client_p, 0);
918 >    return;
919    }
920  
921    /* COMM_OK, so continue the connection procedure */
# Line 934 | Line 924 | serv_connect_callback(fde_t *fd, int sta
924                          client_p->name, CONF_SERVER);
925    if (conf == NULL)
926    {
927 <    sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
928 <                         "Lost connect{} block for %s", get_client_name(client_p, HIDE_IP));
929 <    sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE,
927 >    sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE,
928 >                         "Lost connect{} block for %s", get_client_name(client_p, SHOW_IP));
929 >    sendto_realops_flags(UMODE_SERVNOTICE, L_OPER, SEND_NOTICE,
930                           "Lost connect{} block for %s", get_client_name(client_p, MASK_IP));
931  
932      exit_client(client_p, "Lost connect{} block");
# Line 956 | Line 946 | serv_connect_callback(fde_t *fd, int sta
946  
947    sendto_one(client_p, "PASS %s TS %d %s", conf->spasswd, TS_CURRENT, me.id);
948  
949 <  send_capabilities(client_p, 0);
949 >  send_capabilities(client_p);
950  
951    sendto_one(client_p, "SERVER %s 1 :%s%s", me.name,
952               ConfigServerHide.hidden ? "(H) " : "", me.info);
953  
954 <  /* If we've been marked dead because a send failed, just exit
954 >  /*
955 >   * If we've been marked dead because a send failed, just exit
956     * here now and save everyone the trouble of us ever existing.
957     */
958    if (IsDead(client_p))
959    {
960 <      sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
961 <                           "%s[%s] went dead during handshake",
962 <                           client_p->name,
963 <                           client_p->host);
964 <      sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE,
974 <                           "%s went dead during handshake", client_p->name);
975 <      return;
960 >    sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE,
961 >                         "%s went dead during handshake", get_client_name(client_p, SHOW_IP));
962 >    sendto_realops_flags(UMODE_SERVNOTICE, L_OPER, SEND_NOTICE,
963 >                         "%s went dead during handshake", get_client_name(client_p, MASK_IP));
964 >    return;
965    }
966  
967    /* don't move to serv_list yet -- we haven't sent a burst! */

Diff Legend

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