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

Comparing:
ircd-hybrid-7.2/src/s_serv.c (file contents), Revision 337 by michael, Mon Dec 26 19:20:47 2005 UTC vs.
ircd-hybrid-8/src/s_serv.c (file contents), Revision 1294 by michael, Wed Feb 22 20:48:30 2012 UTC

# Line 27 | Line 27
27   #include <openssl/rsa.h>
28   #include "rsa.h"
29   #endif
30 < #include "tools.h"
30 > #include "list.h"
31   #include "channel.h"
32   #include "channel_mode.h"
33   #include "client.h"
34 #include "common.h"
34   #include "dbuf.h"
35   #include "event.h"
36   #include "fdlist.h"
37   #include "hash.h"
38   #include "irc_string.h"
40 #include "inet_misc.h"
39   #include "sprintf_irc.h"
40   #include "ircd.h"
41   #include "ircd_defs.h"
42   #include "s_bsd.h"
45 #include "irc_getnameinfo.h"
46 #include "list.h"
43   #include "numeric.h"
44   #include "packet.h"
45   #include "irc_res.h"
46   #include "s_conf.h"
47   #include "s_serv.h"
48   #include "s_log.h"
53 #include "s_stats.h"
49   #include "s_user.h"
50   #include "send.h"
51   #include "memory.h"
52   #include "channel.h" /* chcap_usage_counts stuff...*/
53 + #include "parse.h"
54  
55   #define MIN_CONN_FREQ 300
56  
61 struct Client *uplink  = NULL;
62
63
57   static dlink_list cap_list = { NULL, NULL, 0 };
65 static unsigned long freeMask;
58   static void server_burst(struct Client *);
59   static int fork_server(struct Client *);
60   static void burst_all(struct Client *);
69 static void cjoin_all(struct Client *);
61   static void send_tb(struct Client *client_p, struct Channel *chptr);
62  
63   static CNCB serv_connect_callback;
64  
65   static void start_io(struct Client *);
66   static void burst_members(struct Client *, struct Channel *);
76 static void burst_ll_members(struct Client *, struct Channel *);
77 static void add_lazylinkchannel(struct Client *, struct Channel *);
67  
68   static SlinkRplHnd slink_error;
69   static SlinkRplHnd slink_zipstats;
# Line 135 | Line 124 | slink_zipstats(unsigned int rpl, unsigne
124                 struct Client *server_p)
125   {
126    struct ZipStats zipstats;
127 <  unsigned long in = 0, in_wire = 0, out = 0, out_wire = 0;
127 >  uint64_t in = 0, in_wire = 0, out = 0, out_wire = 0;
128    int i = 0;
129  
130    assert(rpl == SLINKRPL_ZIPSTATS);
# Line 195 | Line 184 | slink_zipstats(unsigned int rpl, unsigne
184    else
185      zipstats.out_ratio = 0;
186  
187 <  memcpy(&server_p->localClient->zipstats, &zipstats, sizeof (struct ZipStats));
187 >  memcpy(&server_p->localClient->zipstats, &zipstats, sizeof(struct ZipStats));
188   }
189  
190   void
191   collect_zipstats(void *unused)
192   {
193 <  dlink_node *ptr;
205 <  struct Client *target_p;
193 >  dlink_node *ptr = NULL;
194  
195    DLINK_FOREACH(ptr, serv_list.head)
196    {
197 <    target_p = ptr->data;
197 >    struct Client *target_p = ptr->data;
198  
199      if (IsCapable(target_p, CAP_ZIP))
200      {
# Line 246 | Line 234 | check_cipher(struct Client *client_p, st
234   }
235   #endif /* HAVE_LIBCRYPTO */
236  
249 /* my_name_for_link()
250 * return wildcard name of my server name
251 * according to given config entry --Jto
252 */
253 const char *
254 my_name_for_link(struct ConfItem *conf)
255 {
256  struct AccessItem *aconf;
257
258  aconf = (struct AccessItem *)map_to_conf(conf);
259  if (aconf->fakename != NULL)
260    return(aconf->fakename);
261  else
262    return(me.name);
263 }
264
237   /*
238   * write_links_file
239   *
# Line 395 | Line 367 | hunt_server(struct Client *client_p, str
367     * non-matching lookups.
368     */
369    if (MyClient(source_p))
370 <    target_p = find_client(parv[server]);
370 >    target_p = hash_find_client(parv[server]);
371    else
372      target_p = find_person(client_p, parv[server]);
373  
# Line 403 | Line 375 | hunt_server(struct Client *client_p, str
375      if (target_p->from == source_p->from && !MyConnect(target_p))
376        target_p = NULL;
377  
378 <  if (target_p == NULL && (target_p = find_server(parv[server])))
378 >  if (target_p == NULL && (target_p = hash_find_server(parv[server])))
379      if (target_p->from == source_p->from && !MyConnect(target_p))
380        target_p = NULL;
381  
# Line 417 | Line 389 | hunt_server(struct Client *client_p, str
389    {
390      if (!wilds)
391      {
392 <      if (!(target_p = find_server(parv[server])))
392 >      if (!(target_p = hash_find_server(parv[server])))
393        {
394          sendto_one(source_p, form_str(ERR_NOSUCHSERVER),
395 <                   me.name, parv[0], parv[server]);
395 >                   me.name, source_p->name, parv[server]);
396          return(HUNTED_NOSUCH);
397        }
398      }
# Line 448 | Line 420 | hunt_server(struct Client *client_p, str
420      if(!IsRegistered(target_p))
421      {
422        sendto_one(source_p, form_str(ERR_NOSUCHSERVER),
423 <                 me.name, parv[0], parv[server]);
423 >                 me.name, source_p->name, parv[server]);
424        return HUNTED_NOSUCH;
425      }
426  
# Line 458 | Line 430 | hunt_server(struct Client *client_p, str
430      if (!match(target_p->name, parv[server]))
431        parv[server] = target_p->name;
432  
461    /* Deal with lazylinks */
462    client_burst_if_needed(target_p, source_p);
463
433      /* This is a little kludgy but should work... */
434      if (IsClient(source_p) &&
435          ((MyConnect(target_p) && IsCapable(target_p, CAP_TS6)) ||
# Line 474 | Line 443 | hunt_server(struct Client *client_p, str
443    }
444  
445    sendto_one(source_p, form_str(ERR_NOSUCHSERVER),
446 <             me.name, parv[0], parv[server]);
446 >             me.name, source_p->name, parv[server]);
447    return(HUNTED_NOSUCH);
448   }
449  
# Line 504 | Line 473 | try_connections(void *unused)
473    DLINK_FOREACH(ptr, server_items.head)
474    {
475      conf = ptr->data;
476 <    aconf = (struct AccessItem *)map_to_conf(conf);
476 >    aconf = map_to_conf(conf);
477  
478      /* Also when already connecting! (update holdtimes) --SRB
479       */
480 <    if (!(aconf->status & CONF_SERVER) || aconf->port <= 0 ||
480 >    if (!(aconf->status & CONF_SERVER) || !aconf->port ||
481          !(IsConfAllowAutoConn(aconf)))
482        continue;
483  
484 <    cltmp = (struct ClassItem *)map_to_conf(aconf->class_ptr);
484 >    cltmp = map_to_conf(aconf->class_ptr);
485  
486      /* Skip this entry if the use of it is still on hold until
487       * future. Otherwise handle this entry (and set it on hold
# Line 537 | Line 506 | try_connections(void *unused)
506      /* Found a CONNECT config with port specified, scan clients
507       * and see if this server is already connected?
508       */
509 <    if (find_server(conf->name) != NULL)
509 >    if (hash_find_server(conf->name) != NULL)
510        continue;
511  
512      if (CurrUserCount(cltmp) < MaxTotal(cltmp))
# Line 575 | Line 544 | try_connections(void *unused)
544   }
545  
546   int
547 + valid_servname(const char *name)
548 + {
549 +  unsigned int length = 0;
550 +  unsigned int dots   = 0;
551 +  const char *p = name;
552 +
553 +  for (; *p; ++p)
554 +  {
555 +    if (!IsServChar(*p))
556 +      return 0;
557 +
558 +    ++length;
559 +
560 +    if (*p == '.')
561 +      ++dots;
562 +  }
563 +
564 +  return dots != 0 && length <= HOSTLEN;
565 + }
566 +
567 + int
568   check_server(const char *name, struct Client *client_p, int cryptlink)
569   {
570    dlink_node *ptr;
# Line 596 | Line 586 | check_server(const char *name, struct Cl
586    DLINK_FOREACH(ptr, server_items.head)
587    {
588      conf = ptr->data;
589 <    aconf = (struct AccessItem *)map_to_conf(conf);
589 >    aconf = map_to_conf(conf);
590  
591      if (!match(name, conf->name))
592        continue;
# Line 666 | Line 656 | check_server(const char *name, struct Cl
656      attach_conf(client_p, conf);
657    }
658  
659 <  server_aconf = (struct AccessItem *)map_to_conf(server_conf);
659 >  server_aconf = map_to_conf(server_conf);
660  
671  if (!IsConfLazyLink(server_aconf))
672    ClearCap(client_p, CAP_LL);
661   #ifdef HAVE_LIBZ /* otherwise, clear it unconditionally */
662    if (!IsConfCompressed(server_aconf))
663   #endif
# Line 682 | Line 670 | check_server(const char *name, struct Cl
670      ClearCap(client_p, CAP_TBURST);
671    }
672  
685  /* Don't unset CAP_HUB here even if the server isn't a hub,
686   * it only indicates if the server thinks it's lazylinks are
687   * leafs or not.. if you unset it, bad things will happen
688   */
673    if (aconf != NULL)
674    {
675      struct sockaddr_in *v4;
# Line 726 | Line 710 | check_server(const char *name, struct Cl
710   void
711   add_capability(const char *capab_name, int cap_flag, int add_to_default)
712   {
713 <  struct Capability *cap;
713 >  struct Capability *cap = MyMalloc(sizeof(*cap));
714  
731  cap = (struct Capability *)MyMalloc(sizeof(*cap));
715    DupString(cap->name, capab_name);
716    cap->cap = cap_flag;
717    dlinkAdd(cap, &cap->node, &cap_list);
718 +
719    if (add_to_default)
720      default_server_capabs |= cap_flag;
721   }
# Line 766 | Line 750 | delete_capability(const char *capab_name
750      }
751    }
752  
753 <  return(0);
753 >  return 0;
754   }
755  
756   /*
# Line 779 | Line 763 | delete_capability(const char *capab_name
763   int
764   find_capability(const char *capab)
765   {
766 <  dlink_node *ptr;
783 <  struct Capability *cap;
766 >  const dlink_node *ptr = NULL;
767  
768    DLINK_FOREACH(ptr, cap_list.head)
769    {
770 <    cap = ptr->data;
770 >    const struct Capability *cap = ptr->data;
771  
772 <    if (cap->cap != 0)
773 <    {
791 <      if (irccmp(cap->name, capab) == 0)
792 <        return(cap->cap);
793 <    }
772 >    if (cap->cap && !irccmp(cap->name, capab))
773 >      return cap->cap;
774    }
775 <  return(0);
775 >
776 >  return 0;
777   }
778  
779   /* send_capabilities()
# Line 864 | Line 845 | send_capabilities(struct Client *client_
845   /* sendnick_TS()
846   *
847   * inputs       - client (server) to send nick towards
848 < *              - client to send nick for
848 > *          - client to send nick for
849   * output       - NONE
850   * side effects - NICK message is sent towards given client_p
851   */
# Line 876 | Line 857 | sendnick_TS(struct Client *client_p, str
857    if (!IsClient(target_p))
858      return;
859  
860 <  send_umode(NULL, target_p, 0, IsOperHiddenAdmin(target_p) ?
880 <    SEND_UMODES & ~UMODE_ADMIN : SEND_UMODES, ubuf);
860 >  send_umode(NULL, target_p, 0, SEND_UMODES, ubuf);
861  
862    if (ubuf[0] == '\0')
863    {
# Line 886 | Line 866 | sendnick_TS(struct Client *client_p, str
866    }
867  
868    /* XXX Both of these need to have a :me.name or :mySID!?!?! */
869 <  if (HasID(target_p) && IsCapable(client_p, CAP_TS6))
870 <    sendto_one(client_p, ":%s UID %s %d %lu %s %s %s %s %s :%s",
871 <               target_p->servptr->id,
872 <               target_p->name, target_p->hopcount + 1,
873 <               (unsigned long) target_p->tsinfo,
874 <               ubuf, target_p->username, target_p->host,
875 <           ((MyClient(target_p)&&!IsIPSpoof(target_p))?target_p->sockhost:"0"),
876 <           target_p->id, target_p->info);
869 >  if (IsCapable(client_p, CAP_SVS))
870 >  {
871 >    if (HasID(target_p) && IsCapable(client_p, CAP_TS6))
872 >      sendto_one(client_p, ":%s UID %s %d %lu %s %s %s %s %s %lu :%s",
873 >                 target_p->servptr->id,
874 >                 target_p->name, target_p->hopcount + 1,
875 >                 (unsigned long) target_p->tsinfo,
876 >                 ubuf, target_p->username, target_p->host,
877 >                 (MyClient(target_p) && IsIPSpoof(target_p)) ?
878 >                 "0" : target_p->sockhost, target_p->id,
879 >                 (unsigned long)target_p->servicestamp, target_p->info);
880 >    else
881 >      sendto_one(client_p, "NICK %s %d %lu %s %s %s %s %lu :%s",
882 >                 target_p->name, target_p->hopcount + 1,
883 >                 (unsigned long) target_p->tsinfo,
884 >                 ubuf, target_p->username, target_p->host,
885 >                 target_p->servptr->name, (unsigned long)target_p->servicestamp,
886 >                 target_p->info);
887 >  }
888    else
889 <    sendto_one(client_p, "NICK %s %d %lu %s %s %s %s :%s",
890 <               target_p->name, target_p->hopcount + 1,
891 <               (unsigned long) target_p->tsinfo,
892 <               ubuf, target_p->username, target_p->host,
893 <               target_p->servptr->name, target_p->info);
889 >  {
890 >    if (HasID(target_p) && IsCapable(client_p, CAP_TS6))
891 >      sendto_one(client_p, ":%s UID %s %d %lu %s %s %s %s %s :%s",
892 >                 target_p->servptr->id,
893 >                 target_p->name, target_p->hopcount + 1,
894 >                 (unsigned long) target_p->tsinfo,
895 >                 ubuf, target_p->username, target_p->host,
896 >                 (MyClient(target_p) && IsIPSpoof(target_p)) ?
897 >                 "0" : target_p->sockhost, target_p->id, target_p->info);
898 >    else
899 >      sendto_one(client_p, "NICK %s %d %lu %s %s %s %s :%s",
900 >                 target_p->name, target_p->hopcount + 1,
901 >                 (unsigned long) target_p->tsinfo,
902 >                 ubuf, target_p->username, target_p->host,
903 >                 target_p->servptr->name, target_p->info);
904 >  }
905 >
906    if (IsConfAwayBurst((struct AccessItem *)map_to_conf(client_p->serv->sconf)))
907      if (!EmptyString(target_p->away))
908        sendto_one(client_p, ":%s AWAY :%s", target_p->name,
# Line 907 | Line 910 | sendnick_TS(struct Client *client_p, str
910  
911   }
912  
910 /* client_burst_if_needed()
911 *
912 * inputs       - pointer to server
913 *              - pointer to client to add
914 * output       - NONE
915 * side effects - If this client is not known by this lazyleaf, send it
916 */
917 void
918 client_burst_if_needed(struct Client *client_p, struct Client *target_p)
919 {
920  if (!ServerInfo.hub)
921    return;
922  if (!MyConnect(client_p))
923    return;
924  if (!IsCapable(client_p,CAP_LL))
925    return;
926
927  if ((target_p->lazyLinkClientExists & client_p->localClient->serverMask) == 0)
928  {
929    sendnick_TS(client_p, target_p);
930    add_lazylinkclient(client_p,target_p);
931  }
932 }
933
913   /*
914   * show_capabilities - show current server capabilities
915   *
# Line 977 | Line 956 | struct Server *
956   make_server(struct Client *client_p)
957   {
958    if (client_p->serv == NULL)
980  {
959      client_p->serv = MyMalloc(sizeof(struct Server));
982    client_p->serv->dep_servers = 1;
983  }
960  
961    return client_p->serv;
962   }
# Line 1000 | Line 976 | server_estab(struct Client *client_p)
976    char *host;
977    const char *inpath;
978    static char inpath_ip[HOSTLEN * 2 + USERLEN + 6];
1003  dlink_node *m;
979    dlink_node *ptr;
980  
981    assert(client_p != NULL);
# Line 1033 | Line 1008 | server_estab(struct Client *client_p)
1008    {
1009      if (client_p != serv_list.head->data || serv_list.head->next)
1010      {
1011 <      ServerStats->is_ref++;
1011 >      ++ServerStats.is_ref;
1012        sendto_one(client_p, "ERROR :I'm a leaf not a hub");
1013        exit_client(client_p, &me, "I'm a leaf");
1014        return;
1015      }
1016    }
1017  
1018 <  aconf = (struct AccessItem *)map_to_conf(conf);
1018 >  aconf = map_to_conf(conf);
1019  
1020    if (IsUnknown(client_p) && !IsConfCryptLink(aconf))
1021    {
# Line 1048 | Line 1023 | server_estab(struct Client *client_p)
1023       *        2.  Check aconf->spasswd, not aconf->passwd.
1024       */
1025      if (!EmptyString(aconf->spasswd))
1026 <    {
1027 <      /* only send ts6 format PASS if we have ts6 enabled */
1053 <    if (me.id[0] != '\0')               /* Send TS 6 form only if id */
1054 <        sendto_one(client_p, "PASS %s TS %d %s",
1055 <                   aconf->spasswd, TS_CURRENT, me.id);
1056 <      else
1057 <        sendto_one(client_p, "PASS %s TS 5",
1058 <                   aconf->spasswd);
1059 <    }
1026 >      sendto_one(client_p, "PASS %s TS %d %s",
1027 >                 aconf->spasswd, TS_CURRENT, me.id);
1028  
1029      /* Pass my info to the new server
1030       *
1063     * If trying to negotiate LazyLinks, pass on CAP_LL
1064     * If this is a HUB, pass on CAP_HUB
1031       * Pass on ZIP if supported
1032       * Pass on TB if supported.
1033       * - Dianora
1034       */
1035  
1036 <    send_capabilities(client_p, aconf, (ServerInfo.hub ? CAP_HUB : 0)
1037 <      | (IsConfLazyLink(aconf) ? CAP_LL : 0)
1072 <      | (IsConfCompressed(aconf) ? CAP_ZIP : 0)
1036 >    send_capabilities(client_p, aconf,
1037 >      (IsConfCompressed(aconf) ? CAP_ZIP : 0)
1038        | (IsConfTopicBurst(aconf) ? CAP_TBURST|CAP_TB : 0), 0);
1039  
1040      /* SERVER is the last command sent before switching to ziplinks.
# Line 1083 | Line 1048 | server_estab(struct Client *client_p)
1048       * Nagle is already disabled at this point --adx
1049       */
1050      sendto_one(client_p, "SERVER %s 1 :%s%s",
1051 <               my_name_for_link(conf),
1087 <               ConfigServerHide.hidden ? "(H) " : "",
1088 <               (me.info[0]) ? (me.info) : "IRCers United");
1051 >               me.name, ConfigServerHide.hidden ? "(H) " : "", me.info);
1052      send_queued_write(client_p);
1053    }
1054  
# Line 1109 | Line 1072 | server_estab(struct Client *client_p)
1072      SetServlink(client_p);
1073    }
1074  
1075 <  /* only send ts6 format SVINFO if we have ts6 enabled */
1113 <  sendto_one(client_p, "SVINFO %d %d 0 :%lu",
1114 <             (me.id[0] ? TS_CURRENT : 5), TS_MIN,
1075 >  sendto_one(client_p, "SVINFO %d %d 0 :%lu", TS_CURRENT, TS_MIN,
1076               (unsigned long)CurrentTime);
1077  
1078    /* assumption here is if they passed the correct TS version, they also passed an SID */
# Line 1143 | Line 1104 | server_estab(struct Client *client_p)
1104    set_chcap_usage_counts(client_p);
1105  
1106    /* Some day, all these lists will be consolidated *sigh* */
1107 <  dlinkAdd(client_p, &client_p->lnode, &me.serv->servers);
1107 >  dlinkAdd(client_p, &client_p->lnode, &me.serv->server_list);
1108  
1109 <  m = dlinkFind(&unknown_list, client_p);
1149 <  assert(NULL != m);
1109 >  assert(dlinkFind(&unknown_list, client_p));
1110  
1111 <  dlinkDelete(m, &unknown_list);
1112 <  dlinkAdd(client_p, m, &serv_list);
1111 >  dlink_move_node(&client_p->localClient->lclient_node,
1112 >                  &unknown_list, &serv_list);
1113  
1114    Count.myserver++;
1115  
# Line 1160 | Line 1120 | server_estab(struct Client *client_p)
1120    make_server(client_p);
1121  
1122    /* fixing eob timings.. -gnp */
1123 <  client_p->firsttime = CurrentTime;
1123 >  client_p->localClient->firsttime = CurrentTime;
1124 >
1125 >
1126 >  if (find_matching_name_conf(SERVICE_TYPE, client_p->name, NULL, NULL, 0))
1127 >    AddFlag(client_p, FLAGS_SERVICE);
1128  
1129    /* Show the real host/IP to admins */
1130    sendto_realops_flags(UMODE_ALL, L_ADMIN,
# Line 1170 | Line 1134 | server_estab(struct Client *client_p)
1134    sendto_realops_flags(UMODE_ALL, L_OPER,
1135                         "Link with %s established: (%s) link",
1136                         inpath,show_capabilities(client_p));
1137 <  ilog(L_NOTICE, "Link with %s established: (%s) link",
1137 >  ilog(LOG_TYPE_IRCD, "Link with %s established: (%s) link",
1138         inpath_ip, show_capabilities(client_p));
1139  
1140    client_p->serv->sconf = conf;
# Line 1197 | Line 1161 | server_estab(struct Client *client_p)
1161      if (target_p == client_p)
1162        continue;
1163  
1200    if ((conf = target_p->serv->sconf) &&
1201         match(my_name_for_link(conf), client_p->name))
1202      continue;
1203
1164      if (IsCapable(target_p, CAP_TS6) && HasID(client_p))
1165        sendto_one(target_p, ":%s SID %s 2 %s :%s%s",
1166                   me.id, client_p->name, client_p->id,
# Line 1231 | Line 1191 | server_estab(struct Client *client_p)
1191    **    is destroyed...)
1192    */
1193  
1234  conf = client_p->serv->sconf;
1235
1194    DLINK_FOREACH_PREV(ptr, global_serv_list.tail)
1195    {
1196      target_p = ptr->data;
1197  
1198      /* target_p->from == target_p for target_p == client_p */
1199 <    if (target_p->from == client_p)
1242 <      continue;
1243 <
1244 <    if (match(my_name_for_link(conf), target_p->name))
1199 >    if (IsMe(target_p) || target_p->from == client_p)
1200        continue;
1201  
1202      if (IsCapable(client_p, CAP_TS6))
# Line 1262 | Line 1217 | server_estab(struct Client *client_p)
1217                   IsHidden(target_p) ? "(H) " : "", target_p->info);
1218    }
1219  
1265  if ((ServerInfo.hub == 0) && MyConnect(client_p))
1266    uplink = client_p;
1267
1220    server_burst(client_p);
1221   }
1222  
# Line 1462 | Line 1414 | server_burst(struct Client *client_p)
1414    ** -orabidoo
1415    */
1416  
1417 <  /* On a "lazy link" hubs send nothing.
1466 <   * Leafs always have to send nicks plus channels
1467 <   */
1468 <  if (IsCapable(client_p, CAP_LL))
1469 <  {
1470 <    if (!ServerInfo.hub)
1471 <    {
1472 <      /* burst all our info */
1473 <      burst_all(client_p);
1474 <
1475 <      /* Now, ask for channel info on all our current channels */
1476 <      cjoin_all(client_p);
1477 <    }
1478 <  }
1479 <  else
1480 <  {
1481 <    burst_all(client_p);
1482 <  }
1417 >  burst_all(client_p);
1418  
1419    /* EOB stuff is now in burst_all */
1420    /* Always send a PING after connect burst is done */
# Line 1518 | Line 1453 | burst_all(struct Client *client_p)
1453    {
1454      struct Client *target_p = ptr->data;
1455  
1456 <    if (!IsBursted(target_p) && target_p->from != client_p)
1456 >    if (!HasFlag(target_p, FLAGS_BURSTED) && target_p->from != client_p)
1457        sendnick_TS(client_p, target_p);
1458      
1459 <    ClearBursted(target_p);
1459 >    DelFlag(target_p, FLAGS_BURSTED);
1460    }
1461  
1462    /* We send the time we started the burst, and let the remote host determine an EOB time,
# Line 1563 | Line 1498 | send_tb(struct Client *client_p, struct
1498        sendto_one(client_p, ":%s TBURST %lu %s %lu %s :%s",
1499                   me.name, (unsigned long)chptr->channelts, chptr->chname,
1500                   (unsigned long)chptr->topic_time,
1501 <                 chptr->topic_info ? chptr->topic_info : "",
1502 <                 chptr->topic ? chptr->topic : "");
1501 >                 chptr->topic_info,
1502 >                 chptr->topic);
1503      else if (IsCapable(client_p, CAP_TB))
1504      {
1505        if (ConfigChannel.burst_topicwho)
# Line 1572 | Line 1507 | send_tb(struct Client *client_p, struct
1507          sendto_one(client_p, ":%s TB %s %lu %s :%s",
1508                     me.name, chptr->chname,
1509                     (unsigned long)chptr->topic_time,
1510 <                   chptr->topic_info, chptr->topic ? chptr->topic : "");
1510 >                   chptr->topic_info, chptr->topic);
1511        }
1512        else
1513        {
1514          sendto_one(client_p, ":%s TB %s %lu :%s",
1515                     me.name, chptr->chname,
1516                     (unsigned long)chptr->topic_time,
1517 <                   chptr->topic ? chptr->topic : "");
1517 >                   chptr->topic);
1518        }
1519      }
1520    }
1521   }
1522  
1588 /* cjoin_all()
1589 *
1590 * inputs       - server to ask for channel info from
1591 * output       - NONE
1592 * side effects - CJOINS for all the leafs known channels is sent
1593 */
1594 static void
1595 cjoin_all(struct Client *client_p)
1596 {
1597  const dlink_node *gptr = NULL;
1598
1599  DLINK_FOREACH(gptr, global_channel_list.head)
1600  {
1601    const struct Channel *chptr = gptr->data;
1602    sendto_one(client_p, ":%s CBURST %s",
1603               me.name, chptr->chname);
1604  }
1605 }
1606
1607 /* burst_channel()
1608 *
1609 * inputs       - pointer to server to send sjoins to
1610 *              - channel pointer
1611 * output       - none
1612 * side effects - All sjoins for channel(s) given by chptr are sent
1613 *                for all channel members. ONLY called by hub on
1614 *                behalf of a lazylink so client_p is always guarunteed
1615 *                to be a LL leaf.
1616 */
1617 void
1618 burst_channel(struct Client *client_p, struct Channel *chptr)
1619 {
1620  burst_ll_members(client_p, chptr);
1621
1622  send_channel_modes(client_p, chptr);
1623  add_lazylinkchannel(client_p,chptr);
1624
1625  if (chptr->topic != NULL && chptr->topic_info != NULL)
1626  {
1627    sendto_one(client_p, ":%s TOPIC %s %s %lu :%s",
1628               me.name, chptr->chname, chptr->topic_info,
1629               (unsigned long)chptr->topic_time, chptr->topic);
1630  }
1631 }
1632
1633 /* add_lazlinkchannel()
1634 *
1635 * inputs       - pointer to directly connected leaf server
1636 *                being introduced to this hub
1637 *              - pointer to channel structure being introduced
1638 * output       - NONE
1639 * side effects - The channel pointed to by chptr is now known
1640 *                to be on lazyleaf server given by local_server_p.
1641 *                mark that in the bit map and add to the list
1642 *                of channels to examine after this newly introduced
1643 *                server is squit off.
1644 */
1645 static void
1646 add_lazylinkchannel(struct Client *local_server_p, struct Channel *chptr)
1647 {
1648  assert(MyConnect(local_server_p));
1649
1650  chptr->lazyLinkChannelExists |= local_server_p->localClient->serverMask;
1651  dlinkAdd(chptr, make_dlink_node(), &lazylink_channels);
1652 }
1653
1654 /* add_lazylinkclient()
1655 *
1656 * inputs       - pointer to directly connected leaf server
1657 *                being introduced to this hub
1658 *              - pointer to client being introduced
1659 * output       - NONE
1660 * side effects - The client pointed to by client_p is now known
1661 *                to be on lazyleaf server given by local_server_p.
1662 *                mark that in the bit map and add to the list
1663 *                of clients to examine after this newly introduced
1664 *                server is squit off.
1665 */
1666 void
1667 add_lazylinkclient(struct Client *local_server_p, struct Client *client_p)
1668 {
1669  assert(MyConnect(local_server_p));
1670  client_p->lazyLinkClientExists |= local_server_p->localClient->serverMask;
1671 }
1672
1673 /* remove_lazylink_flags()
1674 *
1675 * inputs       - pointer to server quitting
1676 * output       - NONE
1677 * side effects - All the channels on the lazylink channel list are examined
1678 *                If they hold a bit corresponding to the servermask
1679 *                attached to client_p, clear that bit. If this bitmask
1680 *                goes to 0, then the channel is no longer known to
1681 *                be on any lazylink server, and can be removed from the
1682 *                link list.
1683 *
1684 *                Similar is done for lazylink clients
1685 *
1686 *                This function must be run by the HUB on any exiting
1687 *                lazylink leaf server, while the pointer is still valid.
1688 *                Hence must be run from client.c in exit_one_client()
1689 *
1690 *                The old code scanned all channels, this code only
1691 *                scans channels/clients on the lazylink_channels
1692 *                lazylink_clients lists.
1693 */
1694 void
1695 remove_lazylink_flags(unsigned long mask)
1696 {
1697  dlink_node *ptr;
1698  dlink_node *next_ptr;
1699  struct Channel *chptr;
1700  struct Client *target_p;
1701  unsigned long clear_mask;
1702
1703  if (!mask) /* On 0 mask, don't do anything */
1704   return;
1705
1706  clear_mask = ~mask;
1707  freeMask |= mask;
1708
1709  DLINK_FOREACH_SAFE(ptr, next_ptr, lazylink_channels.head)
1710  {
1711    chptr = ptr->data;
1712
1713    chptr->lazyLinkChannelExists &= clear_mask;
1714
1715    if (chptr->lazyLinkChannelExists == 0)
1716    {
1717      dlinkDelete(ptr, &lazylink_channels);
1718      free_dlink_node(ptr);
1719    }
1720  }
1721
1722  DLINK_FOREACH(ptr, global_client_list.head)
1723  {
1724    target_p = ptr->data;
1725    target_p->lazyLinkClientExists &= clear_mask;
1726  }
1727 }
1728
1523   /* burst_members()
1524   *
1525   * inputs       - pointer to server to send members to
# Line 1745 | Line 1539 | burst_members(struct Client *client_p, s
1539      ms       = ptr->data;
1540      target_p = ms->client_p;
1541  
1542 <    if (!IsBursted(target_p))
1542 >    if (!HasFlag(target_p, FLAGS_BURSTED))
1543      {
1544 <      SetBursted(target_p);
1751 <
1752 <      if (target_p->from != client_p)
1753 <        sendnick_TS(client_p, target_p);
1754 <    }
1755 <  }
1756 < }
1757 <
1758 < /* burst_ll_members()
1759 < *
1760 < * inputs       - pointer to server to send members to
1761 < *              - dlink_list pointer to membership list to send
1762 < * output       - NONE
1763 < * side effects - This version also has to check the bitmap for lazylink
1764 < */
1765 < static void
1766 < burst_ll_members(struct Client *client_p, struct Channel *chptr)
1767 < {
1768 <  struct Client *target_p;
1769 <  struct Membership *ms;
1770 <  dlink_node *ptr;
1771 <
1772 <  DLINK_FOREACH(ptr, chptr->members.head)
1773 <  {
1774 <    ms       = ptr->data;
1775 <    target_p = ms->client_p;
1544 >      AddFlag(target_p, FLAGS_BURSTED);
1545  
1777    if ((target_p->lazyLinkClientExists & client_p->localClient->serverMask) == 0)
1778    {
1546        if (target_p->from != client_p)
1780      {
1781        add_lazylinkclient(client_p,target_p);
1547          sendnick_TS(client_p, target_p);
1783      }
1784    }
1785  }
1786 }
1787
1788 /* set_autoconn()
1789 *
1790 * inputs       - struct Client pointer to oper requesting change
1791 * output       - none
1792 * side effects - set autoconnect mode
1793 */
1794 void
1795 set_autoconn(struct Client *source_p, const char *name, int newval)
1796 {
1797  struct ConfItem *conf;
1798  struct AccessItem *aconf;
1799
1800  if (name != NULL)
1801  {
1802    conf = find_exact_name_conf(SERVER_TYPE, name, NULL, NULL);
1803    if (conf != NULL)
1804    {
1805      aconf = (struct AccessItem *)map_to_conf(conf);
1806      if (newval)
1807        SetConfAllowAutoConn(aconf);
1808      else
1809        ClearConfAllowAutoConn(aconf);
1810
1811      sendto_realops_flags(UMODE_ALL, L_ALL,
1812                           "%s has changed AUTOCONN for %s to %i",
1813                           source_p->name, name, newval);
1814      sendto_one(source_p,
1815                 ":%s NOTICE %s :AUTOCONN for %s is now set to %i",
1816                 me.name, source_p->name, name, newval);
1817    }
1818    else
1819    {
1820      sendto_one(source_p, ":%s NOTICE %s :Can't find %s",
1821                 me.name, source_p->name, name);
1548      }
1549    }
1824  else
1825  {
1826    sendto_one(source_p, ":%s NOTICE %s :Please specify a server name!",
1827               me.name, source_p->name);
1828  }
1829 }
1830
1831 void
1832 initServerMask(void)
1833 {
1834  freeMask = 0xFFFFFFFFUL;
1835 }
1836
1837 /* nextFreeMask()
1838 *
1839 * inputs       - NONE
1840 * output       - unsigned long next unused mask for use in LL
1841 * side effects -
1842 */
1843 unsigned long
1844 nextFreeMask(void)
1845 {
1846  int i;
1847  unsigned long mask = 1;
1848
1849  for (i = 0; i < 32; i++)
1850  {
1851    if (mask & freeMask)
1852    {
1853      freeMask &= ~mask;
1854      return(mask);
1855    }
1856
1857    mask <<= 1;
1858  }
1859
1860  return(0L); /* watch this special case ... */
1550   }
1551  
1552   /* New server connection code
# Line 1900 | Line 1589 | serv_connect(struct AccessItem *aconf, s
1589    conf = unmap_conf_item(aconf);
1590  
1591    /* log */
1592 <  irc_getnameinfo((struct sockaddr*)&aconf->ipnum, aconf->ipnum.ss_len,
1593 <                  buf, HOSTIPLEN, NULL, 0, NI_NUMERICHOST);
1594 <  ilog(L_NOTICE, "Connect to %s[%s] @%s", aconf->user, aconf->host,
1592 >  getnameinfo((struct sockaddr *)&aconf->ipnum, aconf->ipnum.ss_len,
1593 >              buf, sizeof(buf), NULL, 0, NI_NUMERICHOST);
1594 >  ilog(LOG_TYPE_IRCD, "Connect to %s[%s] @%s", aconf->user, aconf->host,
1595         buf);
1596  
1597    /* Still processing a DNS lookup? -> exit */
1598 <  if (aconf->dns_query != NULL)
1598 >  if (aconf->dns_pending)
1599    {
1600 <    sendto_realops_flags(UMODE_ALL, L_OPER,
1601 <                         "Error connecting to %s: Error during DNS lookup", conf->name);
1600 >    sendto_realops_flags(UMODE_ALL, L_ALL,
1601 >                         "Error connecting to %s: DNS lookup for connect{} in progress.",
1602 >                         conf->name);
1603 >    return (0);
1604 >  }
1605 >
1606 >  if (aconf->dns_failed)
1607 >  {
1608 >    sendto_realops_flags(UMODE_ALL, L_ALL,
1609 >                         "Error connecting to %s: DNS lookup for connect{} failed.",
1610 >                         conf->name);
1611      return (0);
1612    }
1613  
1614    /* Make sure this server isn't already connected
1615     * Note: aconf should ALWAYS be a valid C: line
1616     */
1617 <  if ((client_p = find_server(conf->name)) != NULL)
1617 >  if ((client_p = hash_find_server(conf->name)) != NULL)
1618    {
1619      sendto_realops_flags(UMODE_ALL, L_ADMIN,
1620                           "Server %s already present from %s",
# Line 1939 | Line 1637 | serv_connect(struct AccessItem *aconf, s
1637    strlcpy(client_p->host, aconf->host, sizeof(client_p->host));
1638  
1639    /* We already converted the ip once, so lets use it - stu */
1640 <  strlcpy(client_p->sockhost, buf, HOSTIPLEN);
1640 >  strlcpy(client_p->sockhost, buf, sizeof(client_p->sockhost));
1641  
1642    /* create a socket for the server connection */
1643    if (comm_open(&client_p->localClient->fd, aconf->ipnum.ss.ss_family,
# Line 2149 | Line 1847 | serv_connect_callback(fde_t *fd, int sta
1847   #endif
1848  
1849    /* jdc -- Check and send spasswd, not passwd. */
1850 <  if (!EmptyString(aconf->spasswd) && (me.id[0] != '\0'))
1850 >  if (!EmptyString(aconf->spasswd))
1851        /* Send TS 6 form only if id */
1852      sendto_one(client_p, "PASS %s TS %d %s",
1853                 aconf->spasswd, TS_CURRENT, me.id);
2156  else
2157    sendto_one(client_p, "PASS %s TS 5",
2158               aconf->spasswd);
1854  
1855    /* Pass my info to the new server
1856     *
2162   * If trying to negotiate LazyLinks, pass on CAP_LL
2163   * If this is a HUB, pass on CAP_HUB
1857     * Pass on ZIP if supported
1858     * Pass on TB if supported.
1859     * - Dianora
1860     */
1861 <  send_capabilities(client_p, aconf, (ServerInfo.hub ? CAP_HUB : 0)
1862 <                    | (IsConfLazyLink(aconf) ? CAP_LL : 0)
2170 <                    | (IsConfCompressed(aconf) ? CAP_ZIP : 0)
1861 >  send_capabilities(client_p, aconf,
1862 >                    (IsConfCompressed(aconf) ? CAP_ZIP : 0)
1863                      | (IsConfTopicBurst(aconf) ? CAP_TBURST|CAP_TB : 0), 0);
1864  
1865    sendto_one(client_p, "SERVER %s 1 :%s%s",
1866 <             my_name_for_link(conf),
2175 <             ConfigServerHide.hidden ? "(H) " : "",
1866 >             me.name, ConfigServerHide.hidden ? "(H) " : "",
1867               me.info);
1868  
1869    /* If we've been marked dead because a send failed, just exit
# Line 2205 | Line 1896 | find_servconn_in_progress(const char *na
1896      cptr = ptr->data;
1897  
1898      if (cptr && cptr->name[0])
1899 <      if (match(cptr->name, name) || match(name, cptr->name))
1899 >      if (match(name, cptr->name))
1900          return cptr;
1901    }
1902    
# Line 2276 | Line 1967 | cryptlink_init(struct Client *client_p,
1967      return;
1968    }
1969  
1970 <  send_capabilities(client_p, aconf, (ServerInfo.hub ? CAP_HUB : 0)
1971 <                    | (IsConfLazyLink(aconf) ? CAP_LL : 0)
2281 <                    | (IsConfCompressed(aconf) ? CAP_ZIP : 0)
1970 >  send_capabilities(client_p, aconf,
1971 >                    (IsConfCompressed(aconf) ? CAP_ZIP : 0)
1972                      | (IsConfTopicBurst(aconf) ? CAP_TBURST|CAP_TB : 0), CAP_ENC_MASK);
1973  
1974 <  if (me.id[0])
2285 <    sendto_one(client_p, "PASS . TS %d %s", TS_CURRENT, me.id);
2286 <
1974 >  sendto_one(client_p, "PASS . TS %d %s", TS_CURRENT, me.id);
1975    sendto_one(client_p, "CRYPTLINK SERV %s %s :%s%s",
1976 <             my_name_for_link(conf), key_to_send,
1976 >             me.name, key_to_send,
1977               ConfigServerHide.hidden ? "(H) " : "", me.info);
1978  
1979    SetHandshake(client_p);
# Line 2310 | Line 1998 | cryptlink_error(struct Client *client_p,
1998                         get_client_name(client_p, SHOW_IP), type, reason);
1999    sendto_realops_flags(UMODE_ALL, L_OPER,  "%s: CRYPTLINK %s error - %s",
2000                         get_client_name(client_p, MASK_IP), type, reason);
2001 <  ilog(L_ERROR, "%s: CRYPTLINK %s error - %s",
2001 >  ilog(LOG_TYPE_IRCD, "%s: CRYPTLINK %s error - %s",
2002         get_client_name(client_p, SHOW_IP), type, reason);
2003  
2004    /* If client_reason isn't NULL, then exit the client with the message

Diff Legend

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