/* * init_client * * inputs - NONE * output - NONE * side effects - initialize client free memory */ void init_client(void) { remote_client_count = 0; local_client_count = 0; /* * start off the check ping event .. -- adrian * Every 30 seconds is plenty -- db */ client_heap = BlockHeapCreate(sizeof(struct Client), CLIENT_HEAP_SIZE); lclient_heap = BlockHeapCreate(sizeof(struct LocalUser), LCLIENT_HEAP_SIZE); eventAddIsh("check_pings", check_pings, NULL, 30); eventAddIsh("free_exited_clients", &free_exited_clients, NULL, 4); eventAddIsh("client_heap_gc", client_heap_gc, NULL, 30); }
static void peerRefreshDNS(void *data) { peer *p = NULL; if (eventFind(peerRefreshDNS, NULL)) eventDelete(peerRefreshDNS, NULL); if (!data && 0 == stat5minClientRequests()) { /* no recent client traffic, wait a bit */ eventAddIsh("peerRefreshDNS", peerRefreshDNS, NULL, 180.0, 1); return; } for (p = Config.peers; p; p = p->next) { ipcache_nbgethostbyname(p->host, peerDNSConfigure, p); } /* Reconfigure the peers every hour */ eventAddIsh("peerRefreshDNS", peerRefreshDNS, NULL, 3600.0, 1); }
void init_log(const char *filename) { open_log(filename); #ifdef USE_SYSLOG openlog(PACKAGE, LOG_PID | LOG_NDELAY, LOG_FACILITY); #endif #ifndef SYSLOG_USERS eventAddIsh("user_log_resync", user_log_resync, NULL, 60); #endif }
static void netdbSaveState(void *foo) { Logfile *lf; netdbEntry *n; net_db_name *x; struct timeval start = current_time; int count = 0; if (strcmp(Config.netdbFilename, "none") == 0) return; /* * This was nicer when we were using stdio, but thanks to * Solaris bugs, its a bad idea. fopen can fail if more than * 256 FDs are open. */ /* * unlink() is here because there is currently no way to make * logfileOpen() use O_TRUNC. */ unlink(Config.netdbFilename); lf = logfileOpen(Config.netdbFilename, 4096, 0); if (NULL == lf) { debug(50, 1) ("netdbSaveState: %s: %s\n", Config.netdbFilename, xstrerror()); return; } hash_first(addr_table); while ((n = (netdbEntry *) hash_next(addr_table))) { if (n->pings_recv == 0) continue; logfilePrintf(lf, "%s %d %d %10.5f %10.5f %d %d", n->network, n->pings_sent, n->pings_recv, n->hops, n->rtt, (int) n->next_ping_time, (int) n->last_use_time); for (x = n->hosts; x; x = x->next) logfilePrintf(lf, " %s", hashKeyStr(&x->hash)); logfilePrintf(lf, "\n"); count++; #undef RBUF_SZ } logfileClose(lf); getCurrentTime(); debug(38, 1) ("NETDB state saved; %d entries, %d msec\n", count, tvSubMsec(start, current_time)); eventAddIsh("netdbSaveState", netdbSaveState, NULL, 3600.0, 1); }
/* void init_resolver(void) * Input: None * Output: None * Side effects: Reads the ADNS configuration and sets up the ADNS server * polling and query timeouts. */ void init_resolver(void) { int r; r = adns_init(&dns_state, adns_if_noautosys, 0); if(dns_state == NULL) { ilog(L_CRIT, "Error opening /etc/resolv.conf: %s; r = %d", strerror(errno), r); exit(76); } eventAddIsh("timeout_adns", timeout_adns, NULL, 2); dns_select(); }
void netdbInit(void) { #if USE_ICMP int n; if (addr_table) return; n = hashPrime(Config.Netdb.high / 4); addr_table = hash_create((HASHCMP *) strcmp, n, hash_string); n = hashPrime(3 * Config.Netdb.high / 4); host_table = hash_create((HASHCMP *) strcmp, n, hash_string); eventAddIsh("netdbSaveState", netdbSaveState, NULL, 3600.0, 1); netdbReloadState(); cachemgrRegister("netdb", "Network Measurement Database", netdbDump, 0, 1); #endif }
static void peerDNSConfigure(const ipcache_addrs * ia, void *data) { peer *p = data; struct sockaddr_in *ap; int j; if (p->n_addresses == 0) { debug(15, 1) ("Configuring %s %s %s/%d/%d\n", p->name, neighborTypeStr(p), p->name, p->http_port, p->icp.port); if (p->type == PEER_MULTICAST) debug(15, 1) (" Multicast TTL = %d\n", p->mcast.ttl); } p->n_addresses = 0; if (ia == NULL) { debug(0, 0) ("WARNING: DNS lookup of '%s' failed!\n", p->host); return; } if ((int) ia->count < 1) { debug(0, 0) ("WARNING: No IP address found for '%s'!\n", p->host); return; } for (j = 0; j < (int) ia->count && j < PEER_MAX_ADDRESSES; j++) { p->addresses[j] = ia->in_addrs[j]; debug(15, 2) ("--> IP address #%d: %s\n", j, inet_ntoa(p->addresses[j])); p->n_addresses++; } if (!p->tcp_up) peerProbeConnect((peer *) p); ap = &p->in_addr; memset(ap, '\0', sizeof(struct sockaddr_in)); ap->sin_family = AF_INET; ap->sin_addr = p->addresses[0]; ap->sin_port = htons(p->icp.port); if (p->type == PEER_MULTICAST) peerCountMcastPeersSchedule(p, 10); if (p->type != PEER_MULTICAST) if (!p->options.no_netdb_exchange) eventAddIsh("netdbExchangeStart", netdbExchangeStart, p, 30.0, 1); }
void linebuf_init(void) { linebuf_heap = BlockHeapCreate(sizeof(buf_line_t), LINEBUF_HEAP_SIZE); eventAddIsh("linebuf_garbage_collect", linebuf_garbage_collect, NULL, 30); }
int main(int argc, char *argv[]) { /* Check to see if the user is running us as root, which is a nono */ if(geteuid() == 0) { fprintf(stderr, "Don't run ircd as root!!!\n"); return -1; } /* * save server boot time right away, so getrusage works correctly */ set_time(); /* * Setup corefile size immediately after boot -kre */ setup_corefile(); /* * set initialVMTop before we allocate any memory */ initialVMTop = get_vm_top(); ServerRunning = 0; /* It ain't random, but it ought to be a little harder to guess */ srand(SystemTime.tv_sec ^ (SystemTime.tv_usec | (getpid() << 20))); memset(&me, 0, sizeof(me)); memset(&meLocalUser, 0, sizeof(meLocalUser)); me.localClient = &meLocalUser; /* Make sure all lists are zeroed */ memset(&unknown_list, 0, sizeof(unknown_list)); memset(&lclient_list, 0, sizeof(lclient_list)); memset(&serv_list, 0, sizeof(serv_list)); memset(&global_serv_list, 0, sizeof(global_serv_list)); memset(&oper_list, 0, sizeof(oper_list)); dlinkAddTail(&me, &me.node, &global_client_list); memset((void *) &Count, 0, sizeof(Count)); memset((void *) &ServerInfo, 0, sizeof(ServerInfo)); memset((void *) &AdminInfo, 0, sizeof(AdminInfo)); /* Initialise the channel capability usage counts... */ init_chcap_usage_counts(); ConfigFileEntry.dpath = DPATH; ConfigFileEntry.configfile = CPATH; /* Server configuration file */ ConfigFileEntry.klinefile = KPATH; /* Server kline file */ ConfigFileEntry.dlinefile = DLPATH; /* dline file */ ConfigFileEntry.xlinefile = XPATH; ConfigFileEntry.resvfile = RESVPATH; ConfigFileEntry.connect_timeout = 30; /* Default to 30 */ myargv = argv; umask(077); /* better safe than sorry --SRB */ parseargs(&argc, &argv, myopts); if(printVersion) { printf("ircd: version %s\n", ircd_version); exit(EXIT_SUCCESS); } if(chdir(ConfigFileEntry.dpath)) { fprintf(stderr, "Unable to chdir to %s: %s\n", ConfigFileEntry.dpath, strerror(errno)); exit(EXIT_FAILURE); } setup_signals(); #ifdef __CYGWIN__ server_state_foreground = 1; #endif if (testing_conf) server_state_foreground = 1; /* We need this to initialise the fd array before anything else */ fdlist_init(); if(!server_state_foreground) { comm_close_all(); } /* Check if there is pidfile and daemon already running */ if(!testing_conf) { check_pidfile(pidFileName); if(!server_state_foreground) make_daemon(); else print_startup(getpid()); } init_netio(); /* This needs to be setup early ! -- adrian */ /* Init the event subsystem */ eventInit(); init_sys(); init_main_logfile(); initBlockHeap(); init_dlink_nodes(); init_patricia(); newconf_init(); init_s_conf(); init_s_newconf(); linebuf_init(); /* set up some linebuf stuff to control paging */ init_hash(); clear_scache_hash_table(); /* server cache name table */ init_host_hash(); clear_hash_parse(); init_client(); initUser(); init_channels(); initclass(); initwhowas(); init_stats(); init_hook(); init_reject(); init_cache(); init_monitor(); load_all_modules(1); #ifndef STATIC_MODULES load_core_modules(1); #endif init_auth(); /* Initialise the auth code */ init_resolver(); /* Needs to be setup before the io loop */ if (testing_conf) fprintf(stderr, "\nBeginning config test\n"); read_conf_files(YES); /* cold start init conf files */ rehash_bans(0); #ifndef STATIC_MODULES mod_add_path(MODULE_DIR); mod_add_path(MODULE_DIR "/autoload"); #endif initialize_server_capabs(); /* Set up default_server_capabs */ initialize_global_set_options(); if(ServerInfo.name == NULL) { fprintf(stderr, "ERROR: No server name specified in serverinfo block.\n"); ilog(L_MAIN, "No server name specified in serverinfo block."); exit(EXIT_FAILURE); } strlcpy(me.name, ServerInfo.name, sizeof(me.name)); if(ServerInfo.sid[0] == '\0') { fprintf(stderr, "ERROR: No server sid specified in serverinfo block.\n"); ilog(L_MAIN, "No server sid specified in serverinfo block."); exit(EXIT_FAILURE); } strcpy(me.id, ServerInfo.sid); init_uid(); /* serverinfo{} description must exist. If not, error out. */ if(ServerInfo.description == NULL) { fprintf(stderr, "ERROR: No server description specified in serverinfo block.\n"); ilog(L_MAIN, "ERROR: No server description specified in serverinfo block."); exit(EXIT_FAILURE); } strlcpy(me.info, ServerInfo.description, sizeof(me.info)); if (testing_conf) { fprintf(stderr, "\nConfig testing complete.\n"); fflush(stderr); exit(EXIT_SUCCESS); } me.from = &me; me.servptr = &me; SetMe(&me); make_server(&me); me.serv->up = me.name; startup_time = CurrentTime; add_to_client_hash(me.name, &me); add_to_id_hash(me.id, &me); dlinkAddAlloc(&me, &global_serv_list); check_class(); write_pidfile(pidFileName); load_help(); open_logfiles(); ilog(L_MAIN, "Server Ready"); eventAddIsh("cleanup_glines", cleanup_glines, NULL, CLEANUP_GLINES_TIME); /* We want try_connections to be called as soon as possible now! -- adrian */ /* No, 'cause after a restart it would cause all sorts of nick collides */ /* um. by waiting even longer, that just means we have even *more* * nick collisions. what a stupid idea. set an event for the IO loop --fl */ eventAddIsh("try_connections", try_connections, NULL, STARTUP_CONNECTIONS_TIME); eventAddOnce("try_connections_startup", try_connections, NULL, 0); eventAddIsh("collect_zipstats", collect_zipstats, NULL, ZIPSTATS_TIME); /* Setup the timeout check. I'll shift it later :) -- adrian */ eventAddIsh("comm_checktimeouts", comm_checktimeouts, NULL, 1); if(ConfigServerHide.links_delay > 0) eventAddIsh("cache_links", cache_links, NULL, ConfigServerHide.links_delay); else ConfigServerHide.links_disabled = 1; if(splitmode) eventAdd("check_splitmode", check_splitmode, NULL, 2); ServerRunning = 1; io_loop(); return 0; }
int main (int argc, char *argv[]) { /* Check to see if the user is running * us as root, which is a nono */ if (geteuid () == 0) { fprintf (stderr, "Don't run ircd as root!!!\n"); return (-1); } /* save server boot time right away, so getrusage works correctly */ set_time (); /* Setup corefile size immediately after boot -kre */ setup_corefile (); /* set initialVMTop before we allocate any memory */ initialVMTop = get_vm_top (); ServerRunning = 0; /* It ain't random, but it ought to be a little harder to guess */ srand (SystemTime.tv_sec ^ (SystemTime.tv_usec | (getpid () << 20))); memset (&me, 0, sizeof (me)); memset (&meLocalUser, 0, sizeof (meLocalUser)); me.localClient = &meLocalUser; dlinkAdd (&me, &me.node, &global_client_list); /* Pointer to beginning of Client list */ memset (&ServerInfo, 0, sizeof (ServerInfo)); /* Initialise the channel capability usage counts... */ init_chcap_usage_counts (); ConfigFileEntry.dpath = DPATH; ConfigFileEntry.configfile = CPATH; /* Server configuration file */ ConfigFileEntry.klinefile = KPATH; /* Server kline file */ ConfigFileEntry.xlinefile = XPATH; /* Server xline file */ ConfigFileEntry.dlinefile = DLPATH; /* dline file */ ConfigFileEntry.cresvfile = CRESVPATH; /* channel resv file */ ConfigFileEntry.nresvfile = NRESVPATH; /* nick resv file */ myargv = argv; umask (077); /* better safe than sorry --SRB */ parseargs (&argc, &argv, myopts); build_version (); if (printVersion) { printf ("ircd: version %s\n", ircd_version); exit (EXIT_SUCCESS); } if (chdir (ConfigFileEntry.dpath)) { perror ("chdir"); exit (EXIT_FAILURE); } if (!server_state.foreground) make_daemon (); else print_startup (getpid ()); #ifdef HAVE_LIBCRYPTO dh_init(); fprintf(stderr, "SSL: Initialize\n"); SSL_load_error_strings(); SSLeay_add_ssl_algorithms(); ServerInfo.ctx = SSL_CTX_new(SSLv23_server_method()); if (!ServerInfo.ctx) { ERR_print_errors_fp(stderr); return 0; } fprintf(stderr, "SSL: Client based SSL connections are enabled.\n"); #endif setup_signals (); /* We need this to initialise the fd array before anything else */ fdlist_init (); if (!server_state.foreground) close_all_connections (); /* this needs to be before init_netio()! */ else check_can_use_v6 (); /* Done in close_all_connections normally */ init_log (logFileName); init_netio (); /* This needs to be setup early ! -- adrian */ /* Check if there is pidfile and daemon already running */ check_pidfile (pidFileName); /* Init the event subsystem */ eventInit (); init_sys (); #ifndef NOBALLOC initBlockHeap (); #endif init_dlink_nodes (); init_slink_nodes (); initialize_message_files (); dbuf_init (); init_hash (); init_ip_hash_table (); /* client host ip hash table */ init_host_hash (); /* Host-hashtable. */ clear_hash_parse (); init_client (); init_user (); init_channels (); init_class (); init_whowas (); init_stats (); init_hooks (); read_conf_files (1); /* cold start init conf files */ initServerMask (); init_uid (); init_auth (); /* Initialise the auth code */ init_resolver (); /* Needs to be setup before the io loop */ init_reject (); /* Set up the reject code. */ init_umodes (); /* Set up the usermode system. */ initialize_foundation_signals(); /* register things that modules need */ #ifdef HAVE_LIBCRYPTO bio_spare_fd = save_spare_fd ("SSL private key validation"); #endif /* HAVE_LIBCRYPTO */ initialize_server_capabs (); /* Set up default_server_capabs */ initialize_global_set_options (); if (ServerInfo.name == NULL) { fprintf (stderr, "ERROR: No server name specified in serverinfo block.\n"); ilog (L_CRIT, "No server name specified in serverinfo block."); exit (EXIT_FAILURE); } strlcpy (me.name, ServerInfo.name, sizeof (me.name)); /* serverinfo{} description must exist. If not, error out. */ if (ServerInfo.description == NULL) { fprintf (stderr, "ERROR: No server description specified in serverinfo block.\n"); ilog (L_CRIT, "ERROR: No server description specified in serverinfo block."); exit (EXIT_FAILURE); } strlcpy (me.info, ServerInfo.description, sizeof (me.info)); me.from = &me; me.servptr = &me; SetMe (&me); make_server (&me); strlcpy (me.serv->up, me.name, sizeof (me.serv->up)); me.lasttime = me.since = me.firsttime = CurrentTime; hash_add_client (&me); /* add ourselves to global_serv_list */ dlinkAdd (&me, make_dlink_node (), &global_serv_list); check_class (); #ifndef STATIC_MODULES if (chdir (MODPATH)) { ilog (L_CRIT, "Could not load core modules. Terminating!"); exit (EXIT_FAILURE); } mod_set_base (); load_all_modules (1); load_core_modules (1); /* Go back to DPATH after checking to see if we can chdir to MODPATH */ chdir (ConfigFileEntry.dpath); #else load_all_modules (1); #endif write_pidfile (pidFileName); ilog (L_NOTICE, "Server Ready"); eventAddIsh ("cleanup_tklines", cleanup_tklines, NULL, CLEANUP_TKLINES_TIME); /* We want try_connections to be called as soon as possible now! -- adrian */ /* No, 'cause after a restart it would cause all sorts of nick collides */ eventAddIsh ("try_connections", try_connections, NULL, STARTUP_CONNECTIONS_TIME); eventAddIsh ("collect_zipstats", collect_zipstats, NULL, ZIPSTATS_TIME); /* Setup the timeout check. I'll shift it later :) -- adrian */ eventAddIsh ("comm_checktimeouts", comm_checktimeouts, NULL, 1); if (splitmode) eventAddIsh ("check_splitmode", check_splitmode, NULL, 60); ServerRunning = 1; io_loop (); return (0); }