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

Comparing ircd-hybrid/branches/8.2.x/src/ircd.c (file contents):
Revision 3906 by michael, Fri Jun 6 23:52:50 2014 UTC vs.
Revision 4398 by michael, Mon Aug 4 19:35:22 2014 UTC

# Line 53 | Line 53
53   #include "memory.h"
54   #include "mempool.h"
55   #include "ircd_getopt.h"
56 #include "supported.h"
56   #include "watch.h"
57   #include "conf_db.h"
58   #include "conf_class.h"
59 + #include "ipcache.h"
60  
61  
62   #ifdef HAVE_LIBGEOIP
63   GeoIP *geoip_ctx;
64   #endif
65  
66 /* /quote set variables */
67 struct SetOptions GlobalSetOptions;
68 struct Counter Count;
69 struct ServerState_t server_state;
66   struct ServerStatistics ServerStats;
67   struct timeval SystemTime;
68   struct Client me;             /* That's me */
# Line 89 | Line 85 | unsigned int splitchecking;
85   unsigned int split_users;
86   unsigned int split_servers;
87  
88 < /* Do klines the same way hybrid-6 did them, i.e. at the
89 < * top of the next io_loop instead of in the same loop as
90 < * the klines are being applied.
91 < *
92 < * This should fix strange CPU starvation as very indirectly reported.
93 < * (Why do you people not email bug reports? WHY? WHY?)
94 < *
95 < * - Dianora
96 < */
88 > static struct event event_cleanup_glines =
89 > {
90 >  .name = "cleanup_glines",
91 >  .handler = cleanup_glines,
92 >  .when = CLEANUP_GLINES_TIME
93 > };
94 >
95 > static struct event event_cleanup_tklines =
96 > {
97 >  .name = "cleanup_tklines",
98 >  .handler = cleanup_tklines,
99 >  .when = CLEANUP_TKLINES_TIME
100 > };
101 >
102 > static struct event event_try_connections =
103 > {
104 >  .name = "try_connections",
105 >  .handler = try_connections,
106 >  .when = STARTUP_CONNECTIONS_TIME
107 > };
108 >
109 > static struct event event_comm_checktimeouts =
110 > {
111 >  .name = "comm_checktimeouts",
112 >  .handler = comm_checktimeouts,
113 >  .when = 1
114 > };
115 >
116 > static struct event event_save_all_databases =
117 > {
118 >  .name = "save_all_databases",
119 >  .handler = save_all_databases,
120 >  .when = DATABASE_UPDATE_TIMEOUT
121 > };
122  
123 < int rehashed_klines = 0;
123 > struct event event_write_links_file =
124 > {
125 >  .name = "write_links_file",
126 >  .handler = write_links_file,
127 > };
128  
129  
130   /*
# Line 111 | Line 136 | print_startup(int pid)
136    printf("ircd: version %s(%s)\n", ircd_version, serno);
137    printf("ircd: pid %d\n", pid);
138    printf("ircd: running in %s mode from %s\n", !server_state.foreground ? "background"
139 <         : "foreground", ConfigFileEntry.dpath);
139 >         : "foreground", ConfigGeneral.dpath);
140   }
141  
142   static void
# Line 137 | Line 162 | static int printVersion = 0;
162  
163   static struct lgetopt myopts[] =
164   {
165 <  {"configfile", &ConfigFileEntry.configfile,
165 >  {"configfile", &ConfigGeneral.configfile,
166     STRING, "File to use for ircd.conf"},
167 <  {"glinefile",  &ConfigFileEntry.glinefile,
167 >  {"glinefile",  &ConfigGeneral.glinefile,
168     STRING, "File to use for gline database"},
169 <  {"klinefile",  &ConfigFileEntry.klinefile,
169 >  {"klinefile",  &ConfigGeneral.klinefile,
170     STRING, "File to use for kline database"},
171 <  {"dlinefile",  &ConfigFileEntry.dlinefile,
171 >  {"dlinefile",  &ConfigGeneral.dlinefile,
172     STRING, "File to use for dline database"},
173 <  {"xlinefile",  &ConfigFileEntry.xlinefile,
173 >  {"xlinefile",  &ConfigGeneral.xlinefile,
174     STRING, "File to use for xline database"},
175 <  {"resvfile",  &ConfigFileEntry.resvfile,
175 >  {"resvfile",  &ConfigGeneral.resvfile,
176     STRING, "File to use for resv database"},
177    {"logfile",    &logFileName,
178     STRING, "File to use for ircd.log"},
# Line 196 | Line 221 | io_loop(void)
221   {
222    while (1)
223    {
199    /*
200     * Maybe we want a flags word?
201     * ie. if (REHASHED_KLINES(global_flags))
202     * SET_REHASHED_KLINES(global_flags)
203     * CLEAR_REHASHED_KLINES(global_flags)
204     *
205     * - Dianora
206     */
207    if (rehashed_klines)
208    {
209      check_conf_klines();
210      rehashed_klines = 0;
211    }
212
224      if (listing_client_list.head)
225      {
226        dlink_node *ptr = NULL, *ptr_next = NULL;
# Line 217 | Line 228 | io_loop(void)
228          safe_list_channels(ptr->data, 0);
229      }
230  
231 <    /* Run pending events, then get the number of seconds to the next
232 <     * event
222 <     */
223 <    while (eventNextTime() <= CurrentTime)
224 <      eventRun();
231 >    /* Run pending events */
232 >    event_run();
233  
234      comm_select();
235      exit_aborted_clients();
# Line 253 | Line 261 | io_loop(void)
261   static void
262   initialize_global_set_options(void)
263   {
256  memset(&GlobalSetOptions, 0, sizeof(GlobalSetOptions));
257
264    GlobalSetOptions.autoconn  = 1;
265    GlobalSetOptions.spam_time = MIN_JOIN_LEAVE_TIME;
266    GlobalSetOptions.spam_num  = MAX_JOIN_LEAVE_COUNT;
267  
268 <  if (ConfigFileEntry.default_floodcount)
269 <    GlobalSetOptions.floodcount = ConfigFileEntry.default_floodcount;
268 >  if (ConfigGeneral.default_floodcount)
269 >    GlobalSetOptions.floodcount = ConfigGeneral.default_floodcount;
270    else
271      GlobalSetOptions.floodcount = 10;
272  
# Line 279 | Line 285 | initialize_global_set_options(void)
285    }
286  
287    GlobalSetOptions.ident_timeout = IDENT_TIMEOUT;
282  /* End of global set options */
288   }
289  
290   /* initialize_server_capabs()
# Line 418 | Line 423 | ssl_init(void)
423    SSL_load_error_strings();
424    SSLeay_add_ssl_algorithms();
425  
426 <  if ((ServerInfo.server_ctx = SSL_CTX_new(SSLv23_server_method())) == NULL)
426 >  if ((ConfigServerInfo.server_ctx = SSL_CTX_new(SSLv23_server_method())) == NULL)
427    {
428 <    const char *s;
428 >    const char *s = ERR_lib_error_string(ERR_get_error());
429  
430 <    fprintf(stderr, "ERROR: Could not initialize the SSL Server context -- %s\n",
426 <            s = ERR_lib_error_string(ERR_get_error()));
430 >    fprintf(stderr, "ERROR: Could not initialize the SSL Server context -- %s\n", s);
431      ilog(LOG_TYPE_IRCD, "ERROR: Could not initialize the SSL Server context -- %s\n", s);
432    }
433  
434 <  SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_NO_TLSv1);
435 <  SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_TLS_ROLLBACK_BUG|SSL_OP_ALL);
436 <  SSL_CTX_set_verify(ServerInfo.server_ctx, SSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE,
434 >  SSL_CTX_set_options(ConfigServerInfo.server_ctx, SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3);
435 >  SSL_CTX_set_options(ConfigServerInfo.server_ctx, SSL_OP_SINGLE_DH_USE);
436 >  SSL_CTX_set_verify(ConfigServerInfo.server_ctx, SSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE,
437                       always_accept_verify_cb);
438 <  SSL_CTX_set_session_id_context(ServerInfo.server_ctx, session_id, sizeof(session_id) - 1);
438 >  SSL_CTX_set_session_id_context(ConfigServerInfo.server_ctx, session_id, sizeof(session_id) - 1);
439  
440 <  if ((ServerInfo.client_ctx = SSL_CTX_new(SSLv23_client_method())) == NULL)
440 > #if OPENSSL_VERSION_NUMBER >= 0x1000005FL && !defined(OPENSSL_NO_ECDH)
441    {
442 <    const char *s;
442 >    EC_KEY *key = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1);
443  
444 <    fprintf(stderr, "ERROR: Could not initialize the SSL Client context -- %s\n",
445 <            s = ERR_lib_error_string(ERR_get_error()));
444 >    if (key)
445 >    {
446 >      SSL_CTX_set_tmp_ecdh(ConfigServerInfo.server_ctx, key);
447 >      EC_KEY_free(key);
448 >    }
449 >  }
450 >
451 >  SSL_CTX_set_options(ConfigServerInfo.server_ctx, SSL_OP_SINGLE_ECDH_USE);
452 > #endif
453 >
454 >  if ((ConfigServerInfo.client_ctx = SSL_CTX_new(SSLv23_client_method())) == NULL)
455 >  {
456 >    const char *s = ERR_lib_error_string(ERR_get_error());
457 >
458 >    fprintf(stderr, "ERROR: Could not initialize the SSL Client context -- %s\n", s);
459      ilog(LOG_TYPE_IRCD, "ERROR: Could not initialize the SSL Client context -- %s\n", s);
460    }
461  
462 <  SSL_CTX_set_options(ServerInfo.client_ctx, SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_NO_TLSv1);
463 <  SSL_CTX_set_options(ServerInfo.client_ctx, SSL_OP_TLS_ROLLBACK_BUG|SSL_OP_ALL);
464 <  SSL_CTX_set_verify(ServerInfo.client_ctx, SSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE,
462 >  SSL_CTX_set_options(ConfigServerInfo.client_ctx, SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3);
463 >  SSL_CTX_set_options(ConfigServerInfo.client_ctx, SSL_OP_SINGLE_DH_USE);
464 >  SSL_CTX_set_verify(ConfigServerInfo.client_ctx, SSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE,
465                       always_accept_verify_cb);
466   #endif /* HAVE_LIBCRYPTO */
467   }
# Line 471 | Line 488 | main(int argc, char *argv[])
488    me.localClient = &meLocalUser;
489    dlinkAdd(&me, &me.node, &global_client_list);  /* Pointer to beginning
490                                                     of Client list */
491 <  ConfigFileEntry.dpath      = DPATH;
492 <  ConfigFileEntry.spath      = SPATH;
493 <  ConfigFileEntry.mpath      = MPATH;
494 <  ConfigFileEntry.configfile = CPATH;    /* Server configuration file */
495 <  ConfigFileEntry.klinefile  = KPATH;    /* Server kline file         */
496 <  ConfigFileEntry.glinefile  = GPATH;    /* Server gline file         */
497 <  ConfigFileEntry.xlinefile  = XPATH;    /* Server xline file         */
498 <  ConfigFileEntry.dlinefile  = DLPATH;   /* dline file                */
499 <  ConfigFileEntry.resvfile   = RESVPATH; /* resv file                 */
491 >  ConfigLog.use_logging = 1;
492 >  ConfigGeneral.dpath      = DPATH;
493 >  ConfigGeneral.spath      = SPATH;
494 >  ConfigGeneral.mpath      = MPATH;
495 >  ConfigGeneral.configfile = CPATH;    /* Server configuration file */
496 >  ConfigGeneral.klinefile  = KPATH;    /* Server kline file         */
497 >  ConfigGeneral.glinefile  = GPATH;    /* Server gline file         */
498 >  ConfigGeneral.xlinefile  = XPATH;    /* Server xline file         */
499 >  ConfigGeneral.dlinefile  = DLPATH;   /* dline file                */
500 >  ConfigGeneral.resvfile   = RESVPATH; /* resv file                 */
501  
502    myargv = argv;
503    umask(077);                /* better safe than sorry --SRB */
# Line 492 | Line 510 | main(int argc, char *argv[])
510      exit(EXIT_SUCCESS);
511    }
512  
513 <  if (chdir(ConfigFileEntry.dpath))
513 >  if (chdir(ConfigGeneral.dpath))
514    {
515      perror("chdir");
516      exit(EXIT_FAILURE);
# Line 510 | Line 528 | main(int argc, char *argv[])
528  
529    setup_signals();
530  
513  /* Init the event subsystem */
514  eventInit();
515
531    /* We need this to initialise the fd array before anything else */
532    fdlist_init();
533    log_set_file(LOG_TYPE_IRCD, 0, logFileName);
# Line 527 | Line 542 | main(int argc, char *argv[])
542    init_isupport();
543    dbuf_init();
544    hash_init();
545 <  init_ip_hash_table();      /* client host ip hash table */
545 >  ipcache_init();
546    init_host_hash();          /* Host-hashtable. */
547    client_init();
548    class_init();
# Line 547 | Line 562 | main(int argc, char *argv[])
562    geoip_ctx = GeoIP_new(GEOIP_MEMORY_CACHE);
563   #endif
564  
565 <  if (EmptyString(ServerInfo.sid))
565 >  if (EmptyString(ConfigServerInfo.sid))
566    {
567      ilog(LOG_TYPE_IRCD, "ERROR: No server id specified in serverinfo block.");
568      exit(EXIT_FAILURE);
569    }
570  
571 <  strlcpy(me.id, ServerInfo.sid, sizeof(me.id));
571 >  strlcpy(me.id, ConfigServerInfo.sid, sizeof(me.id));
572  
573 <  if (EmptyString(ServerInfo.name))
573 >  if (EmptyString(ConfigServerInfo.name))
574    {
575      ilog(LOG_TYPE_IRCD, "ERROR: No server name specified in serverinfo block.");
576      exit(EXIT_FAILURE);
577    }
578  
579 <  strlcpy(me.name, ServerInfo.name, sizeof(me.name));
579 >  strlcpy(me.name, ConfigServerInfo.name, sizeof(me.name));
580  
581    /* serverinfo{} description must exist.  If not, error out.*/
582 <  if (EmptyString(ServerInfo.description))
582 >  if (EmptyString(ConfigServerInfo.description))
583    {
584      ilog(LOG_TYPE_IRCD, "ERROR: No server description specified in serverinfo block.");
585      exit(EXIT_FAILURE);
586    }
587  
588 <  strlcpy(me.info, ServerInfo.description, sizeof(me.info));
588 >  strlcpy(me.info, ConfigServerInfo.description, sizeof(me.info));
589  
590    me.from                   = &me;
591    me.servptr                = &me;
# Line 584 | Line 599 | main(int argc, char *argv[])
599    hash_add_id(&me);
600    hash_add_client(&me);
601  
602 <  /* add ourselves to global_serv_list */
588 <  dlinkAdd(&me, make_dlink_node(), &global_serv_list);
602 >  dlinkAdd(&me, make_dlink_node(), &global_server_list);
603  
604    load_kline_database();
605    load_dline_database();
# Line 604 | Line 618 | main(int argc, char *argv[])
618    load_core_modules(1);
619  
620    /* Go back to DPATH after checking to see if we can chdir to MODPATH */
621 <  if (chdir(ConfigFileEntry.dpath))
621 >  if (chdir(ConfigGeneral.dpath))
622    {
623      perror("chdir");
624      exit(EXIT_FAILURE);
# Line 620 | Line 634 | main(int argc, char *argv[])
634  
635    ilog(LOG_TYPE_IRCD, "Server Ready");
636  
637 <  eventAddIsh("cleanup_glines", cleanup_glines, NULL, CLEANUP_GLINES_TIME);
638 <  eventAddIsh("cleanup_tklines", cleanup_tklines, NULL, CLEANUP_TKLINES_TIME);
637 >  event_addish(&event_cleanup_glines, NULL);
638 >  event_addish(&event_cleanup_tklines, NULL);
639  
640    /* We want try_connections to be called as soon as possible now! -- adrian */
641    /* No, 'cause after a restart it would cause all sorts of nick collides */
642 <  eventAddIsh("try_connections", try_connections, NULL, STARTUP_CONNECTIONS_TIME);
642 >  event_addish(&event_try_connections, NULL);
643  
644    /* Setup the timeout check. I'll shift it later :)  -- adrian */
645 <  eventAddIsh("comm_checktimeouts", comm_checktimeouts, NULL, 1);
645 >  event_add(&event_comm_checktimeouts, NULL);
646  
647 <  eventAddIsh("save_all_databases", save_all_databases, NULL, DATABASE_UPDATE_TIMEOUT);
647 >  event_addish(&event_save_all_databases, NULL);
648  
649    if (ConfigServerHide.links_delay > 0)
650 <    eventAddIsh("write_links_file", write_links_file, NULL, ConfigServerHide.links_delay);
650 >  {
651 >    event_write_links_file.when = ConfigServerHide.links_delay;
652 >    event_addish(&event_write_links_file, NULL);
653 >  }
654    else
655      ConfigServerHide.links_disabled = 1;
656  
657    if (splitmode)
658 <    eventAddIsh("check_splitmode", check_splitmode, NULL, 60);
658 >    event_addish(&splitmode_event, NULL);
659  
660    io_loop();
661    return 0;

Diff Legend

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