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

Comparing ircd-hybrid/trunk/src/s_serv.c (file contents):
Revision 1618 by michael, Tue Oct 30 21:04:38 2012 UTC vs.
Revision 1632 by michael, Sun Nov 4 15:37:10 2012 UTC

# Line 271 | Line 271 | hunt_server(struct Client *client_p, str
271   void
272   try_connections(void *unused)
273   {
274 <  dlink_node *ptr;
275 <  struct ConfItem *conf;
276 <  struct AccessItem *aconf;
277 <  struct ClassItem *cltmp;
274 >  dlink_node *ptr = NULL;
275 >  struct MaskItem *conf;
276    int confrq;
277  
278    /* TODO: change this to set active flag to 0 when added to event! --Habeeb */
# Line 284 | Line 282 | try_connections(void *unused)
282    DLINK_FOREACH(ptr, server_items.head)
283    {
284      conf = ptr->data;
285 <    aconf = map_to_conf(conf);
285 >
286 >    assert(conf->status & CONF_SERVER);
287  
288      /* Also when already connecting! (update holdtimes) --SRB
289       */
290 <    if (!(aconf->status & CONF_SERVER) || !aconf->port ||
292 <        !(IsConfAllowAutoConn(aconf)))
290 >    if (!conf->port ||!IsConfAllowAutoConn(conf))
291        continue;
292  
295    cltmp = map_to_conf(aconf->class_ptr);
293  
294      /* Skip this entry if the use of it is still on hold until
295       * future. Otherwise handle this entry (and set it on hold
# Line 300 | Line 297 | try_connections(void *unused)
297       * made one successfull connection... [this algorithm is
298       * a bit fuzzy... -- msa >;) ]
299       */
300 <    if (aconf->hold > CurrentTime)
300 >    if (conf->hold > CurrentTime)
301        continue;
302  
303 <    if (cltmp == NULL)
303 >    if (conf->class == NULL)
304        confrq = DEFAULT_CONNECTFREQUENCY;
305      else
306      {
307 <      confrq = cltmp->con_freq;
307 >      confrq = conf->class->con_freq;
308        if (confrq < MIN_CONN_FREQ)
309          confrq = MIN_CONN_FREQ;
310      }
311  
312 <    aconf->hold = CurrentTime + confrq;
312 >    conf->hold = CurrentTime + confrq;
313  
314      /* Found a CONNECT config with port specified, scan clients
315       * and see if this server is already connected?
# Line 320 | Line 317 | try_connections(void *unused)
317      if (hash_find_server(conf->name) != NULL)
318        continue;
319  
320 <    if (cltmp->curr_user_count < cltmp->max_total)
320 >    if (conf->class->ref_count < conf->class->max_total)
321      {
322        /* Go to the end of the list, if not already last */
323        if (ptr->next != NULL)
# Line 347 | Line 344 | try_connections(void *unused)
344        else
345          sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
346                               "Connection to %s[%s] activated.",
347 <                             conf->name, aconf->host);
347 >                             conf->name, conf->host);
348  
349 <      serv_connect(aconf, NULL);
349 >      serv_connect(conf, NULL);
350        /* We connect only one at time... */
351        return;
352      }
# Line 381 | Line 378 | int
378   check_server(const char *name, struct Client *client_p)
379   {
380    dlink_node *ptr;
381 <  struct ConfItem *conf           = NULL;
382 <  struct ConfItem *server_conf    = NULL;
386 <  struct AccessItem *server_aconf = NULL;
387 <  struct AccessItem *aconf        = NULL;
381 >  struct MaskItem *conf        = NULL;
382 >  struct MaskItem *server_conf = NULL;
383    int error = -1;
384  
385    assert(client_p != NULL);
# Line 393 | Line 388 | check_server(const char *name, struct Cl
388    DLINK_FOREACH(ptr, server_items.head)
389    {
390      conf = ptr->data;
396    aconf = map_to_conf(conf);
391  
392      if (!match(name, conf->name))
393        continue;
# Line 402 | Line 396 | check_server(const char *name, struct Cl
396  
397      /* XXX: Fix me for IPv6                    */
398      /* XXX sockhost is the IPv4 ip as a string */
399 <    if (match(aconf->host, client_p->host) ||
400 <        match(aconf->host, client_p->sockhost))
399 >    if (match(conf->host, client_p->host) ||
400 >        match(conf->host, client_p->sockhost))
401      {
402        error = -2;
403  
404 <      if (!match_conf_password(client_p->localClient->passwd, aconf))
404 >      if (!match_conf_password(client_p->localClient->passwd, conf))
405          return -2;
406  
407        server_conf = conf;
# Line 419 | Line 413 | check_server(const char *name, struct Cl
413  
414    attach_conf(client_p, server_conf);
415  
422  server_aconf = map_to_conf(server_conf);
416  
417 <  if (aconf != NULL)
417 >  if (server_conf != NULL)
418    {
419      struct sockaddr_in *v4;
420   #ifdef IPV6
421      struct sockaddr_in6 *v6;
422   #endif
423 <    switch (aconf->aftype)
423 >    switch (server_conf->aftype)
424      {
425   #ifdef IPV6
426        case AF_INET6:
427 <        v6 = (struct sockaddr_in6 *)&aconf->addr;
427 >        v6 = (struct sockaddr_in6 *)&server_conf->addr;
428  
429          if (IN6_IS_ADDR_UNSPECIFIED(&v6->sin6_addr))
430 <          memcpy(&aconf->addr, &client_p->localClient->ip, sizeof(struct irc_ssaddr));
430 >          memcpy(&server_conf->addr, &client_p->localClient->ip, sizeof(struct irc_ssaddr));
431          break;
432   #endif
433        case AF_INET:
434 <        v4 = (struct sockaddr_in *)&aconf->addr;
434 >        v4 = (struct sockaddr_in *)&server_conf->addr;
435  
436          if (v4->sin_addr.s_addr == INADDR_NONE)
437 <          memcpy(&aconf->addr, &client_p->localClient->ip, sizeof(struct irc_ssaddr));
437 >          memcpy(&server_conf->addr, &client_p->localClient->ip, sizeof(struct irc_ssaddr));
438          break;
439      }
440    }
# Line 530 | Line 523 | find_capability(const char *capab)
523   /* send_capabilities()
524   *
525   * inputs       - Client pointer to send to
533 *              - Pointer to AccessItem (for crypt)
526   *              - int flag of capabilities that this server can send
527   * output       - NONE
528   * side effects - send the CAPAB line to a server  -orabidoo
529   *
530   */
531   void
532 < send_capabilities(struct Client *client_p, struct AccessItem *aconf,
541 <                  int cap_can_send)
532 > send_capabilities(struct Client *client_p, int cap_can_send)
533   {
534    struct Capability *cap=NULL;
535    char msgbuf[IRCD_BUFSIZE];
# Line 683 | Line 674 | void
674   server_estab(struct Client *client_p)
675   {
676    struct Client *target_p;
677 <  struct ConfItem *conf;
687 <  struct AccessItem *aconf=NULL;
677 >  struct MaskItem *conf = NULL;
678    char *host;
679    const char *inpath;
680    static char inpath_ip[HOSTLEN * 2 + USERLEN + 6];
# Line 700 | Line 690 | server_estab(struct Client *client_p)
690    inpath = get_client_name(client_p, MASK_IP); /* "refresh" inpath with host */
691    host   = client_p->name;
692  
693 <  if ((conf = find_conf_name(&client_p->localClient->confs, host, SERVER_TYPE))
693 >  if ((conf = find_conf_name(&client_p->localClient->confs, host, CONF_SERVER))
694        == NULL)
695    {
696      /* This shouldn't happen, better tell the ops... -A1kmm */
# Line 731 | Line 721 | server_estab(struct Client *client_p)
721      }
722    }
723  
734  aconf = map_to_conf(conf);
735
724    if (IsUnknown(client_p))
725    {
726      /* jdc -- 1.  Use EmptyString(), not [0] index reference.
727 <     *        2.  Check aconf->spasswd, not aconf->passwd.
727 >     *        2.  Check conf->spasswd, not conf->passwd.
728       */
729 <    if (!EmptyString(aconf->spasswd))
729 >    if (!EmptyString(conf->spasswd))
730        sendto_one(client_p, "PASS %s TS %d %s",
731 <                 aconf->spasswd, TS_CURRENT, me.id);
731 >                 conf->spasswd, TS_CURRENT, me.id);
732  
733 <    /* Pass my info to the new server
746 <     *
747 <     * Pass on ZIP if supported
748 <     * Pass on TB if supported.
749 <     * - Dianora
750 <     */
751 <
752 <    send_capabilities(client_p, aconf, 0);
733 >    send_capabilities(client_p, 0);
734  
735      sendto_one(client_p, "SERVER %s 1 :%s%s",
736                 me.name, ConfigServerHide.hidden ? "(H) " : "", me.info);
# Line 763 | Line 744 | server_estab(struct Client *client_p)
744      hash_add_id(client_p);
745  
746    /* XXX Does this ever happen? I don't think so -db */
747 <  detach_conf(client_p, OPER_TYPE);
747 >  detach_conf(client_p, CONF_OPER);
748  
749    /* *WARNING*
750    **    In the following code in place of plain server's
# Line 805 | Line 786 | server_estab(struct Client *client_p)
786    /* fixing eob timings.. -gnp */
787    client_p->localClient->firsttime = CurrentTime;
788  
789 <  if (find_matching_name_conf(SERVICE_TYPE, client_p->name, NULL, NULL, 0))
789 >  if (find_matching_name_conf(CONF_SERVICE, client_p->name, NULL, NULL, 0))
790      AddFlag(client_p, FLAGS_SERVICE);
791  
792    /* Show the real host/IP to admins */
# Line 1078 | Line 1059 | burst_members(struct Client *client_p, s
1059   * it suceeded or not, and 0 if it fails in here somewhere.
1060   */
1061   int
1062 < serv_connect(struct AccessItem *aconf, struct Client *by)
1062 > serv_connect(struct MaskItem *conf, struct Client *by)
1063   {
1083  struct ConfItem *conf;
1064    struct Client *client_p;
1065    char buf[HOSTIPLEN + 1];
1066  
1067    /* conversion structs */
1068    struct sockaddr_in *v4;
1069 <  /* Make sure aconf is useful */
1070 <  assert(aconf != NULL);
1069 >  /* Make sure conf is useful */
1070 >  assert(conf != NULL);
1071  
1092  /* XXX should be passing struct ConfItem in the first place */
1093  conf = unmap_conf_item(aconf);
1072  
1073 <  /* log */
1096 <  getnameinfo((struct sockaddr *)&aconf->addr, aconf->addr.ss_len,
1073 >  getnameinfo((struct sockaddr *)&conf->addr, conf->addr.ss_len,
1074                buf, sizeof(buf), NULL, 0, NI_NUMERICHOST);
1075 <  ilog(LOG_TYPE_IRCD, "Connect to %s[%s] @%s", conf->name, aconf->host,
1075 >  ilog(LOG_TYPE_IRCD, "Connect to %s[%s] @%s", conf->name, conf->host,
1076         buf);
1077  
1078    /* Still processing a DNS lookup? -> exit */
1079 <  if (aconf->dns_pending)
1079 >  if (conf->dns_pending)
1080    {
1081      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1082                           "Error connecting to %s: DNS lookup for connect{} in progress.",
# Line 1107 | Line 1084 | serv_connect(struct AccessItem *aconf, s
1084      return (0);
1085    }
1086  
1087 <  if (aconf->dns_failed)
1087 >  if (conf->dns_failed)
1088    {
1089      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1090                           "Error connecting to %s: DNS lookup for connect{} failed.",
# Line 1116 | Line 1093 | serv_connect(struct AccessItem *aconf, s
1093    }
1094  
1095    /* Make sure this server isn't already connected
1096 <   * Note: aconf should ALWAYS be a valid C: line
1096 >   * Note: conf should ALWAYS be a valid C: line
1097     */
1098    if ((client_p = hash_find_server(conf->name)) != NULL)
1099    {
# Line 1138 | Line 1115 | serv_connect(struct AccessItem *aconf, s
1115  
1116    /* Copy in the server, hostname, fd */
1117    strlcpy(client_p->name, conf->name, sizeof(client_p->name));
1118 <  strlcpy(client_p->host, aconf->host, sizeof(client_p->host));
1118 >  strlcpy(client_p->host, conf->host, sizeof(client_p->host));
1119  
1120    /* We already converted the ip once, so lets use it - stu */
1121    strlcpy(client_p->sockhost, buf, sizeof(client_p->sockhost));
1122  
1123    /* create a socket for the server connection */
1124 <  if (comm_open(&client_p->localClient->fd, aconf->addr.ss.ss_family,
1124 >  if (comm_open(&client_p->localClient->fd, conf->addr.ss.ss_family,
1125                  SOCK_STREAM, 0, NULL) < 0)
1126    {
1127      /* Eek, failure to create the socket */
# Line 1161 | Line 1138 | serv_connect(struct AccessItem *aconf, s
1138    /* Attach config entries to client here rather than in
1139     * serv_connect_callback(). This to avoid null pointer references.
1140     */
1141 <  if (!attach_connect_block(client_p, conf->name, aconf->host))
1141 >  if (!attach_connect_block(client_p, conf->name, conf->host))
1142    {
1143      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1144                           "Host %s is not enabled for connecting: no connect{} block",
# Line 1190 | Line 1167 | serv_connect(struct AccessItem *aconf, s
1167    SetConnecting(client_p);
1168    dlinkAdd(client_p, &client_p->node, &global_client_list);
1169    /* from def_fam */
1170 <  client_p->localClient->aftype = aconf->aftype;
1170 >  client_p->localClient->aftype = conf->aftype;
1171  
1172    /* Now, initiate the connection */
1173    /* XXX assume that a non 0 type means a specific bind address
1174     * for this connect.
1175     */
1176 <  switch (aconf->aftype)
1176 >  switch (conf->aftype)
1177    {
1178      case AF_INET:
1179 <      v4 = (struct sockaddr_in*)&aconf->bind;
1179 >      v4 = (struct sockaddr_in*)&conf->bind;
1180        if (v4->sin_addr.s_addr != 0)
1181        {
1182          struct irc_ssaddr ipn;
1183          memset(&ipn, 0, sizeof(struct irc_ssaddr));
1184          ipn.ss.ss_family = AF_INET;
1185          ipn.ss_port = 0;
1186 <        memcpy(&ipn, &aconf->bind, sizeof(struct irc_ssaddr));
1187 <        comm_connect_tcp(&client_p->localClient->fd, aconf->host, aconf->port,
1186 >        memcpy(&ipn, &conf->bind, sizeof(struct irc_ssaddr));
1187 >        comm_connect_tcp(&client_p->localClient->fd, conf->host, conf->port,
1188                           (struct sockaddr *)&ipn, ipn.ss_len,
1189 <                         serv_connect_callback, client_p, aconf->aftype,
1189 >                         serv_connect_callback, client_p, conf->aftype,
1190                           CONNECTTIMEOUT);
1191        }
1192        else if (ServerInfo.specific_ipv4_vhost)
# Line 1219 | Line 1196 | serv_connect(struct AccessItem *aconf, s
1196          ipn.ss.ss_family = AF_INET;
1197          ipn.ss_port = 0;
1198          memcpy(&ipn, &ServerInfo.ip, sizeof(struct irc_ssaddr));
1199 <        comm_connect_tcp(&client_p->localClient->fd, aconf->host, aconf->port,
1199 >        comm_connect_tcp(&client_p->localClient->fd, conf->host, conf->port,
1200                           (struct sockaddr *)&ipn, ipn.ss_len,
1201 <                         serv_connect_callback, client_p, aconf->aftype,
1201 >                         serv_connect_callback, client_p, conf->aftype,
1202                           CONNECTTIMEOUT);
1203        }
1204        else
1205 <        comm_connect_tcp(&client_p->localClient->fd, aconf->host, aconf->port,
1206 <                         NULL, 0, serv_connect_callback, client_p, aconf->aftype,
1205 >        comm_connect_tcp(&client_p->localClient->fd, conf->host, conf->port,
1206 >                         NULL, 0, serv_connect_callback, client_p, conf->aftype,
1207                           CONNECTTIMEOUT);
1208        break;
1209   #ifdef IPV6
# Line 1237 | Line 1214 | serv_connect(struct AccessItem *aconf, s
1214          struct sockaddr_in6 *v6conf;
1215  
1216          memset(&ipn, 0, sizeof(struct irc_ssaddr));
1217 <        v6conf = (struct sockaddr_in6 *)&aconf->bind;
1217 >        v6conf = (struct sockaddr_in6 *)&conf->bind;
1218          v6 = (struct sockaddr_in6 *)&ipn;
1219  
1220          if (memcmp(&v6conf->sin6_addr, &v6->sin6_addr,
1221                     sizeof(struct in6_addr)) != 0)
1222          {
1223 <          memcpy(&ipn, &aconf->bind, sizeof(struct irc_ssaddr));
1223 >          memcpy(&ipn, &conf->bind, sizeof(struct irc_ssaddr));
1224            ipn.ss.ss_family = AF_INET6;
1225            ipn.ss_port = 0;
1226            comm_connect_tcp(&client_p->localClient->fd,
1227 <                           aconf->host, aconf->port,
1227 >                           conf->host, conf->port,
1228                             (struct sockaddr *)&ipn, ipn.ss_len,
1229                             serv_connect_callback, client_p,
1230 <                           aconf->aftype, CONNECTTIMEOUT);
1230 >                           conf->aftype, CONNECTTIMEOUT);
1231          }
1232          else if (ServerInfo.specific_ipv6_vhost)
1233          {
# Line 1258 | Line 1235 | serv_connect(struct AccessItem *aconf, s
1235            ipn.ss.ss_family = AF_INET6;
1236            ipn.ss_port = 0;
1237            comm_connect_tcp(&client_p->localClient->fd,
1238 <                           aconf->host, aconf->port,
1238 >                           conf->host, conf->port,
1239                             (struct sockaddr *)&ipn, ipn.ss_len,
1240                             serv_connect_callback, client_p,
1241 <                           aconf->aftype, CONNECTTIMEOUT);
1241 >                           conf->aftype, CONNECTTIMEOUT);
1242          }
1243          else
1244            comm_connect_tcp(&client_p->localClient->fd,
1245 <                           aconf->host, aconf->port,
1245 >                           conf->host, conf->port,
1246                             NULL, 0, serv_connect_callback, client_p,
1247 <                           aconf->aftype, CONNECTTIMEOUT);
1247 >                           conf->aftype, CONNECTTIMEOUT);
1248        }
1249   #endif
1250    }
# Line 1278 | Line 1255 | serv_connect(struct AccessItem *aconf, s
1255   static void
1256   finish_ssl_server_handshake(struct Client *client_p)
1257   {
1258 <  struct ConfItem *conf=NULL;
1282 <  struct AccessItem *aconf=NULL;
1258 >  struct MaskItem *conf = NULL;
1259  
1260    conf = find_conf_name(&client_p->localClient->confs,
1261 <                        client_p->name, SERVER_TYPE);
1261 >                        client_p->name, CONF_SERVER);
1262    if (conf == NULL)
1263    {
1264      sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
# Line 1294 | Line 1270 | finish_ssl_server_handshake(struct Clien
1270      return;
1271    }
1272  
1297  aconf = map_to_conf(conf);
1298
1273    /* jdc -- Check and send spasswd, not passwd. */
1274 <  if (!EmptyString(aconf->spasswd))
1274 >  if (!EmptyString(conf->spasswd))
1275      sendto_one(client_p, "PASS %s TS %d %s",
1276 <               aconf->spasswd, TS_CURRENT, me.id);
1276 >               conf->spasswd, TS_CURRENT, me.id);
1277  
1278 <  send_capabilities(client_p, aconf, 0);
1278 >  send_capabilities(client_p, 0);
1279  
1280    sendto_one(client_p, "SERVER %s 1 :%s%s",
1281               me.name, ConfigServerHide.hidden ? "(H) " : "",
# Line 1362 | Line 1336 | ssl_server_handshake(fde_t *fd, struct C
1336   }
1337  
1338   static void
1339 < ssl_connect_init(struct Client *client_p, struct AccessItem *aconf, fde_t *fd)
1339 > ssl_connect_init(struct Client *client_p, struct MaskItem *conf, fde_t *fd)
1340   {
1341    if ((client_p->localClient->fd.ssl = SSL_new(ServerInfo.client_ctx)) == NULL)
1342    {
# Line 1375 | Line 1349 | ssl_connect_init(struct Client *client_p
1349  
1350    SSL_set_fd(fd->ssl, fd->fd);
1351  
1352 <  if (!EmptyString(aconf->cipher_list))
1353 <    SSL_set_cipher_list(client_p->localClient->fd.ssl, aconf->cipher_list);
1352 >  if (!EmptyString(conf->cipher_list))
1353 >    SSL_set_cipher_list(client_p->localClient->fd.ssl, conf->cipher_list);
1354  
1355    ssl_server_handshake(NULL, client_p);
1356   }
# Line 1394 | Line 1368 | static void
1368   serv_connect_callback(fde_t *fd, int status, void *data)
1369   {
1370    struct Client *client_p = data;
1371 <  struct ConfItem *conf=NULL;
1398 <  struct AccessItem *aconf=NULL;
1371 >  struct MaskItem *conf = NULL;
1372  
1373    /* First, make sure its a real client! */
1374    assert(client_p != NULL);
# Line 1433 | Line 1406 | serv_connect_callback(fde_t *fd, int sta
1406    /* COMM_OK, so continue the connection procedure */
1407    /* Get the C/N lines */
1408    conf = find_conf_name(&client_p->localClient->confs,
1409 <                        client_p->name, SERVER_TYPE);
1409 >                        client_p->name, CONF_SERVER);
1410    if (conf == NULL)
1411    {
1412      sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
# Line 1445 | Line 1418 | serv_connect_callback(fde_t *fd, int sta
1418      return;
1419    }
1420  
1448  aconf = map_to_conf(conf);
1421    /* Next, send the initial handshake */
1422    SetHandshake(client_p);
1423  
1424   #ifdef HAVE_LIBCRYPTO
1425 <  if (IsConfSSL(aconf))
1425 >  if (IsConfSSL(conf))
1426    {
1427 <    ssl_connect_init(client_p, aconf, fd);
1427 >    ssl_connect_init(client_p, conf, fd);
1428      return;
1429    }
1430   #endif
1431  
1432    /* jdc -- Check and send spasswd, not passwd. */
1433 <  if (!EmptyString(aconf->spasswd))
1433 >  if (!EmptyString(conf->spasswd))
1434      sendto_one(client_p, "PASS %s TS %d %s",
1435 <               aconf->spasswd, TS_CURRENT, me.id);
1435 >               conf->spasswd, TS_CURRENT, me.id);
1436  
1437 <  send_capabilities(client_p, aconf, 0);
1437 >  send_capabilities(client_p, 0);
1438  
1439    sendto_one(client_p, "SERVER %s 1 :%s%s",
1440               me.name, ConfigServerHide.hidden ? "(H) " : "",

Diff Legend

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