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-7.2/src/s_serv.c (file contents), Revision 337 by michael, Mon Dec 26 19:20:47 2005 UTC vs.
ircd-hybrid-7.3/src/s_serv.c (file contents), Revision 1029 by michael, Sun Nov 8 13:10:50 2009 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"
# Line 43 | Line 43
43   #include "ircd_defs.h"
44   #include "s_bsd.h"
45   #include "irc_getnameinfo.h"
46 #include "list.h"
46   #include "numeric.h"
47   #include "packet.h"
48   #include "irc_res.h"
49   #include "s_conf.h"
50   #include "s_serv.h"
51   #include "s_log.h"
53 #include "s_stats.h"
52   #include "s_user.h"
53   #include "send.h"
54   #include "memory.h"
# Line 58 | Line 56
56  
57   #define MIN_CONN_FREQ 300
58  
61 struct Client *uplink  = NULL;
62
63
59   static dlink_list cap_list = { NULL, NULL, 0 };
65 static unsigned long freeMask;
60   static void server_burst(struct Client *);
61   static int fork_server(struct Client *);
62   static void burst_all(struct Client *);
69 static void cjoin_all(struct Client *);
63   static void send_tb(struct Client *client_p, struct Channel *chptr);
64  
65   static CNCB serv_connect_callback;
66  
67   static void start_io(struct Client *);
68   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 *);
69  
70   static SlinkRplHnd slink_error;
71   static SlinkRplHnd slink_zipstats;
# Line 135 | Line 126 | slink_zipstats(unsigned int rpl, unsigne
126                 struct Client *server_p)
127   {
128    struct ZipStats zipstats;
129 <  unsigned long in = 0, in_wire = 0, out = 0, out_wire = 0;
129 >  uint64_t in = 0, in_wire = 0, out = 0, out_wire = 0;
130    int i = 0;
131  
132    assert(rpl == SLINKRPL_ZIPSTATS);
# Line 195 | Line 186 | slink_zipstats(unsigned int rpl, unsigne
186    else
187      zipstats.out_ratio = 0;
188  
189 <  memcpy(&server_p->localClient->zipstats, &zipstats, sizeof (struct ZipStats));
189 >  memcpy(&server_p->localClient->zipstats, &zipstats, sizeof(struct ZipStats));
190   }
191  
192   void
193   collect_zipstats(void *unused)
194   {
195 <  dlink_node *ptr;
205 <  struct Client *target_p;
195 >  dlink_node *ptr = NULL;
196  
197    DLINK_FOREACH(ptr, serv_list.head)
198    {
199 <    target_p = ptr->data;
199 >    struct Client *target_p = ptr->data;
200  
201      if (IsCapable(target_p, CAP_ZIP))
202      {
# Line 257 | Line 247 | my_name_for_link(struct ConfItem *conf)
247  
248    aconf = (struct AccessItem *)map_to_conf(conf);
249    if (aconf->fakename != NULL)
250 <    return(aconf->fakename);
250 >    return aconf->fakename;
251    else
252 <    return(me.name);
252 >    return me.name;
253   }
254  
255   /*
# Line 458 | Line 448 | hunt_server(struct Client *client_p, str
448      if (!match(target_p->name, parv[server]))
449        parv[server] = target_p->name;
450  
461    /* Deal with lazylinks */
462    client_burst_if_needed(target_p, source_p);
463
451      /* This is a little kludgy but should work... */
452      if (IsClient(source_p) &&
453          ((MyConnect(target_p) && IsCapable(target_p, CAP_TS6)) ||
# Line 504 | Line 491 | try_connections(void *unused)
491    DLINK_FOREACH(ptr, server_items.head)
492    {
493      conf = ptr->data;
494 <    aconf = (struct AccessItem *)map_to_conf(conf);
494 >    aconf = map_to_conf(conf);
495  
496      /* Also when already connecting! (update holdtimes) --SRB
497       */
498 <    if (!(aconf->status & CONF_SERVER) || aconf->port <= 0 ||
498 >    if (!(aconf->status & CONF_SERVER) || !aconf->port ||
499          !(IsConfAllowAutoConn(aconf)))
500        continue;
501  
502 <    cltmp = (struct ClassItem *)map_to_conf(aconf->class_ptr);
502 >    cltmp = map_to_conf(aconf->class_ptr);
503  
504      /* Skip this entry if the use of it is still on hold until
505       * future. Otherwise handle this entry (and set it on hold
# Line 596 | Line 583 | check_server(const char *name, struct Cl
583    DLINK_FOREACH(ptr, server_items.head)
584    {
585      conf = ptr->data;
586 <    aconf = (struct AccessItem *)map_to_conf(conf);
586 >    aconf = map_to_conf(conf);
587  
588      if (!match(name, conf->name))
589        continue;
# Line 666 | Line 653 | check_server(const char *name, struct Cl
653      attach_conf(client_p, conf);
654    }
655  
656 <  server_aconf = (struct AccessItem *)map_to_conf(server_conf);
656 >  server_aconf = map_to_conf(server_conf);
657  
671  if (!IsConfLazyLink(server_aconf))
672    ClearCap(client_p, CAP_LL);
658   #ifdef HAVE_LIBZ /* otherwise, clear it unconditionally */
659    if (!IsConfCompressed(server_aconf))
660   #endif
# Line 726 | Line 711 | check_server(const char *name, struct Cl
711   void
712   add_capability(const char *capab_name, int cap_flag, int add_to_default)
713   {
714 <  struct Capability *cap;
714 >  struct Capability *cap = MyMalloc(sizeof(*cap));
715  
731  cap = (struct Capability *)MyMalloc(sizeof(*cap));
716    DupString(cap->name, capab_name);
717    cap->cap = cap_flag;
718    dlinkAdd(cap, &cap->node, &cap_list);
719 +
720    if (add_to_default)
721      default_server_capabs |= cap_flag;
722   }
# Line 766 | Line 751 | delete_capability(const char *capab_name
751      }
752    }
753  
754 <  return(0);
754 >  return 0;
755   }
756  
757   /*
# Line 779 | Line 764 | delete_capability(const char *capab_name
764   int
765   find_capability(const char *capab)
766   {
767 <  dlink_node *ptr;
783 <  struct Capability *cap;
767 >  const dlink_node *ptr = NULL;
768  
769    DLINK_FOREACH(ptr, cap_list.head)
770    {
771 <    cap = ptr->data;
771 >    const struct Capability *cap = ptr->data;
772  
773 <    if (cap->cap != 0)
774 <    {
791 <      if (irccmp(cap->name, capab) == 0)
792 <        return(cap->cap);
793 <    }
773 >    if (cap->cap && !irccmp(cap->name, capab))
774 >      return cap->cap;
775    }
776 <  return(0);
776 >
777 >  return 0;
778   }
779  
780   /* send_capabilities()
# Line 864 | Line 846 | send_capabilities(struct Client *client_
846   /* sendnick_TS()
847   *
848   * inputs       - client (server) to send nick towards
849 < *              - client to send nick for
849 > *          - client to send nick for
850   * output       - NONE
851   * side effects - NICK message is sent towards given client_p
852   */
# Line 889 | Line 871 | sendnick_TS(struct Client *client_p, str
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 :%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))?target_p->sockhost:"0"),
878 <           target_p->id, target_p->info);
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, target_p->info);
879    else
880      sendto_one(client_p, "NICK %s %d %lu %s %s %s %s :%s",
881                 target_p->name, target_p->hopcount + 1,
882                 (unsigned long) target_p->tsinfo,
883                 ubuf, target_p->username, target_p->host,
884                 target_p->servptr->name, target_p->info);
885 +
886    if (IsConfAwayBurst((struct AccessItem *)map_to_conf(client_p->serv->sconf)))
887      if (!EmptyString(target_p->away))
888        sendto_one(client_p, ":%s AWAY :%s", target_p->name,
# Line 907 | Line 890 | sendnick_TS(struct Client *client_p, str
890  
891   }
892  
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
893   /*
894   * show_capabilities - show current server capabilities
895   *
# Line 977 | Line 936 | struct Server *
936   make_server(struct Client *client_p)
937   {
938    if (client_p->serv == NULL)
980  {
939      client_p->serv = MyMalloc(sizeof(struct Server));
982    client_p->serv->dep_servers = 1;
983  }
940  
941    return client_p->serv;
942   }
# Line 1033 | Line 989 | server_estab(struct Client *client_p)
989    {
990      if (client_p != serv_list.head->data || serv_list.head->next)
991      {
992 <      ServerStats->is_ref++;
992 >      ++ServerStats.is_ref;
993        sendto_one(client_p, "ERROR :I'm a leaf not a hub");
994        exit_client(client_p, &me, "I'm a leaf");
995        return;
# Line 1060 | Line 1016 | server_estab(struct Client *client_p)
1016  
1017      /* Pass my info to the new server
1018       *
1063     * If trying to negotiate LazyLinks, pass on CAP_LL
1019       * If this is a HUB, pass on CAP_HUB
1020       * Pass on ZIP if supported
1021       * Pass on TB if supported.
# Line 1068 | Line 1023 | server_estab(struct Client *client_p)
1023       */
1024  
1025      send_capabilities(client_p, aconf, (ServerInfo.hub ? CAP_HUB : 0)
1071      | (IsConfLazyLink(aconf) ? CAP_LL : 0)
1026        | (IsConfCompressed(aconf) ? CAP_ZIP : 0)
1027        | (IsConfTopicBurst(aconf) ? CAP_TBURST|CAP_TB : 0), 0);
1028  
# Line 1143 | Line 1097 | server_estab(struct Client *client_p)
1097    set_chcap_usage_counts(client_p);
1098  
1099    /* Some day, all these lists will be consolidated *sigh* */
1100 <  dlinkAdd(client_p, &client_p->lnode, &me.serv->servers);
1100 >  dlinkAdd(client_p, &client_p->lnode, &me.serv->server_list);
1101  
1102    m = dlinkFind(&unknown_list, client_p);
1103    assert(NULL != m);
# Line 1262 | Line 1216 | server_estab(struct Client *client_p)
1216                   IsHidden(target_p) ? "(H) " : "", target_p->info);
1217    }
1218  
1265  if ((ServerInfo.hub == 0) && MyConnect(client_p))
1266    uplink = client_p;
1267
1219    server_burst(client_p);
1220   }
1221  
# Line 1462 | Line 1413 | server_burst(struct Client *client_p)
1413    ** -orabidoo
1414    */
1415  
1416 <  /* 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 <  }
1416 >  burst_all(client_p);
1417  
1418    /* EOB stuff is now in burst_all */
1419    /* Always send a PING after connect burst is done */
# Line 1585 | Line 1519 | send_tb(struct Client *client_p, struct
1519    }
1520   }
1521  
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
1522   /* burst_members()
1523   *
1524   * inputs       - pointer to server to send members to
# Line 1755 | Line 1548 | burst_members(struct Client *client_p, s
1548    }
1549   }
1550  
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;
1776
1777    if ((target_p->lazyLinkClientExists & client_p->localClient->serverMask) == 0)
1778    {
1779      if (target_p->from != client_p)
1780      {
1781        add_lazylinkclient(client_p,target_p);
1782        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);
1822    }
1823  }
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 ... */
1861 }
1862
1551   /* New server connection code
1552   * Based upon the stuff floating about in s_bsd.c
1553   *   -- adrian
# Line 1906 | Line 1594 | serv_connect(struct AccessItem *aconf, s
1594         buf);
1595  
1596    /* Still processing a DNS lookup? -> exit */
1597 <  if (aconf->dns_query != NULL)
1597 >  if (aconf->dns_pending)
1598    {
1599 <    sendto_realops_flags(UMODE_ALL, L_OPER,
1600 <                         "Error connecting to %s: Error during DNS lookup", conf->name);
1599 >    sendto_realops_flags(UMODE_ALL, L_ALL,
1600 >                         "Error connecting to %s: DNS lookup for connect{} in progress.",
1601 >                         conf->name);
1602 >    return (0);
1603 >  }
1604 >
1605 >  if (aconf->dns_failed)
1606 >  {
1607 >    sendto_realops_flags(UMODE_ALL, L_ALL,
1608 >                         "Error connecting to %s: DNS lookup for connect{} failed.",
1609 >                         conf->name);
1610      return (0);
1611    }
1612  
# Line 2159 | Line 1856 | serv_connect_callback(fde_t *fd, int sta
1856  
1857    /* Pass my info to the new server
1858     *
2162   * If trying to negotiate LazyLinks, pass on CAP_LL
1859     * If this is a HUB, pass on CAP_HUB
1860     * Pass on ZIP if supported
1861     * Pass on TB if supported.
1862     * - Dianora
1863     */
1864    send_capabilities(client_p, aconf, (ServerInfo.hub ? CAP_HUB : 0)
2169                    | (IsConfLazyLink(aconf) ? CAP_LL : 0)
1865                      | (IsConfCompressed(aconf) ? CAP_ZIP : 0)
1866                      | (IsConfTopicBurst(aconf) ? CAP_TBURST|CAP_TB : 0), 0);
1867  
# Line 2277 | Line 1972 | cryptlink_init(struct Client *client_p,
1972    }
1973  
1974    send_capabilities(client_p, aconf, (ServerInfo.hub ? CAP_HUB : 0)
2280                    | (IsConfLazyLink(aconf) ? CAP_LL : 0)
1975                      | (IsConfCompressed(aconf) ? CAP_ZIP : 0)
1976                      | (IsConfTopicBurst(aconf) ? CAP_TBURST|CAP_TB : 0), CAP_ENC_MASK);
1977  

Diff Legend

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