int repl_prof_init(void) { int index; if (!repl_prof_dests_nr) return 0; if (repl_prof_utimer < 0) { LM_ERR("negative replicate timer for profiles %d\n", repl_prof_utimer); return -1; } if (repl_prof_timer_check < 0) { LM_ERR("negative replicate timer for profiles check %d\n", repl_prof_timer_check); return -1; } if (repl_prof_timer_expire < 0) { LM_ERR("negative replicate expire timer for profiles %d\n", repl_prof_timer_expire); return -1; } if (repl_prof_buffer_th < 0) { LM_ERR("negative replicate buffer threshold for profiles %d\n", repl_prof_buffer_th); return -1; } if (register_utimer("dialog-repl-profiles-utimer", repl_prof_utimer_f, NULL, repl_prof_utimer * 1000, TIMER_FLAG_DELAY_ON_DELAY) < 0) { LM_ERR("failed to register profiles utimer\n"); return -1; } if (register_timer("dialog-repl-profiles-timer", repl_prof_timer_f, NULL, repl_prof_timer_check, TIMER_FLAG_DELAY_ON_DELAY) < 0) { LM_ERR("failed to register profiles utimer\n"); return -1; } if (repl_prof_buffer_th > (BUF_SIZE * 0.9)) { LM_WARN("Buffer size too big %d - profiles information might get lost", repl_prof_buffer_th); return -1; } /* alocate the last_message counter in shared memory */ for (index = 0; index < repl_prof_dests_nr; index++) { repl_prof_dests[index].last_msg = shm_malloc(sizeof(time_t)); if (!repl_prof_dests[index].last_msg) { LM_ERR("OOM shm\n"); return -1; } } return 0; }
int repl_prof_init(void) { if (!profile_replicate_cluster && !accept_repl_profiles) return 0; if (repl_prof_timer_check < 0) { LM_ERR("negative replicate timer for profiles check %d\n", repl_prof_timer_check); return -1; } if (repl_prof_timer_expire < 0) { LM_ERR("negative replicate expire timer for profiles %d\n", repl_prof_timer_expire); return -1; } if (register_timer("dialog-repl-profiles-timer", repl_prof_timer_f, NULL, repl_prof_timer_check, TIMER_FLAG_DELAY_ON_DELAY) < 0) { LM_ERR("failed to register profiles utimer\n"); return -1; } if (!profile_replicate_cluster) return 0; if (repl_prof_utimer < 0) { LM_ERR("negative replicate timer for profiles %d\n", repl_prof_utimer); return -1; } if (repl_prof_buffer_th < 0) { LM_ERR("negative replicate buffer threshold for profiles %d\n", repl_prof_buffer_th); return -1; } if (register_utimer("dialog-repl-profiles-utimer", repl_prof_utimer_f, NULL, repl_prof_utimer * 1000, TIMER_FLAG_DELAY_ON_DELAY) < 0) { LM_ERR("failed to register profiles utimer\n"); return -1; } if (repl_prof_buffer_th > (BUF_SIZE * 0.9)) { LM_WARN("Buffer size too big %d - profiles information might get lost", repl_prof_buffer_th); return -1; } return 0; }
static int mod_init(void) { int heartbeats_timer_interval; cluster_info_t *cl; LM_INFO("Clusterer module - initializing\n"); db_table.len = strlen(db_table.s); id_col.len = strlen(id_col.s); cluster_id_col.len = strlen(cluster_id_col.s); node_id_col.len = strlen(node_id_col.s); url_col.len = strlen(url_col.s); state_col.len = strlen(state_col.s); no_ping_retries_col.len = strlen(no_ping_retries_col.s); priority_col.len = strlen(priority_col.s); sip_addr_col.len = strlen(sip_addr_col.s); flags_col.len = strlen(flags_col.s); description_col.len = strlen(description_col.s); /* only allow the DB URL to be skipped in "P2P discovery" mode */ init_db_url(clusterer_db_url, db_mode == 0); if (current_id < 1) { LM_CRIT("Invalid 'my_node_id' parameter\n"); return -1; } if (ping_interval <= 0) { LM_WARN("Invalid ping_interval parameter, using default value\n"); ping_interval = DEFAULT_PING_INTERVAL; } if (node_timeout < 0) { LM_WARN("Invalid node_timeout parameter, using default value\n"); node_timeout = DEFAULT_NODE_TIMEOUT; } if (ping_timeout <= 0) { LM_WARN("Invalid ping_timeout parameter, using default value\n"); ping_timeout = DEFAULT_PING_TIMEOUT; } /* create & init lock */ if ((cl_list_lock = lock_init_rw()) == NULL) { LM_CRIT("Failed to init lock\n"); return -1; } /* data pointer in shm */ if (cluster_list == NULL) { cluster_list = shm_malloc(sizeof *cluster_list); if (!cluster_list) { LM_CRIT("No more shm memory\n"); goto error; } *cluster_list = NULL; } else { /* sanity check of my_node_id if node_id also set in a my_node_info param */ for (cl = *cluster_list; cl; cl = cl->next) if (cl->current_node->node_id != current_id) { LM_ERR("Bad 'my_node_id' parameter, value: %d different than" " the node_id property in the 'my_node_info' parameter\n", current_id); goto error; } } if (db_mode) { /* bind to the mysql module */ if (db_bind_mod(&clusterer_db_url, &dr_dbf)) { LM_CRIT("Cannot bind to database module! " "Did you forget to load a database module ?\n"); goto error; } if (!DB_CAPABILITY(dr_dbf, DB_CAP_QUERY)) { LM_CRIT("Given SQL DB does not provide query types needed by this module!\n"); goto error; } /* init DB connection */ if ((db_hdl = dr_dbf.init(&clusterer_db_url)) == 0) { LM_ERR("cannot initialize database connection\n"); goto error; } if (load_db_info(&dr_dbf, db_hdl, &db_table, cluster_list) < 0) { LM_ERR("Failed to load info from DB\n"); goto error; } } /* register timer */ heartbeats_timer_interval = gcd(ping_interval*1000, ping_timeout); heartbeats_timer_interval = gcd(heartbeats_timer_interval, node_timeout*1000); if (heartbeats_timer_interval % 1000 == 0) { if (register_timer("clstr-heartbeats-timer", heartbeats_timer_handler, NULL, heartbeats_timer_interval/1000, TIMER_FLAG_DELAY_ON_DELAY) < 0) { LM_CRIT("Unable to register clusterer heartbeats timer\n"); goto error; } } else { if (register_utimer("clstr-heartbeats-utimer", heartbeats_utimer_handler, NULL, heartbeats_timer_interval*1000, TIMER_FLAG_DELAY_ON_DELAY) < 0) { LM_CRIT("Unable to register clusterer heartbeats timer\n"); goto error; } } if (bin_register_cb(&cl_internal_cap, bin_rcv_cl_packets, NULL) < 0) { LM_CRIT("Cannot register clusterer binary packet callback!\n"); goto error; } if (bin_register_cb(&cl_extra_cap, bin_rcv_cl_extra_packets, NULL) < 0) { LM_CRIT("Cannot register extra clusterer binary packet callback!\n"); goto error; } /* create generic message receiving events */ if (gen_rcv_evs_init() < 0) { LM_ERR("cannot create cluster message received event\n"); return -1; } return 0; error: lock_destroy_rw(cl_list_lock); cl_list_lock = NULL; if (cluster_list) { shm_free(cluster_list); cluster_list = 0; } return -1; }
/* initialize ratelimit module */ static int mod_init(void) { unsigned int n; LM_INFO("Ratelimit module - initializing ...\n"); if (rl_timer_interval < 0) { LM_ERR("invalid timer interval\n"); return -1; } if (rl_expire_time < 0) { LM_ERR("invalid expire time\n"); return -1; } if (rl_repl_timer_interval < 0) { LM_ERR("invalid replication time\n"); return -1; } if( rl_repl_cluster < 0 ) rl_repl_cluster = 0; if( accept_repl_pipes < 0 ) accept_repl_pipes = 0; if ( (rl_repl_cluster || accept_repl_pipes) && load_clusterer_api(&clusterer_api) != 0 ){ LM_DBG("failed to find clusterer API - is clusterer module loaded?\n"); return -1; } if (db_url.s) { db_url.len = strlen(db_url.s); db_prefix.len = strlen(db_prefix.s); LM_DBG("using CacheDB url: %s\n", db_url.s); } RL_SHM_MALLOC(rl_network_count, sizeof(int)); RL_SHM_MALLOC(rl_network_load, sizeof(int)); RL_SHM_MALLOC(rl_load_value, sizeof(double)); RL_SHM_MALLOC(pid_kp, sizeof(double)); RL_SHM_MALLOC(pid_ki, sizeof(double)); RL_SHM_MALLOC(pid_kd, sizeof(double)); RL_SHM_MALLOC(pid_setpoint, sizeof(double)); RL_SHM_MALLOC(drop_rate, sizeof(int)); RL_SHM_MALLOC(rl_feedback_limit, sizeof(int)); /* init ki value for feedback algo */ *pid_ki = -25.0; rl_lock = lock_alloc(); if (!rl_lock) { LM_ERR("cannot alloc lock\n"); return -1; } if (!lock_init(rl_lock)) { LM_ERR("failed to init lock\n"); return -1; } /* register timer to reset counters */ if (register_timer("rl-timer", rl_timer, NULL, rl_timer_interval, TIMER_FLAG_DELAY_ON_DELAY) < 0 ) { LM_ERR("could not register timer function\n"); return -1; } if(rl_repl_cluster) if (register_utimer("rl-utimer", rl_timer_repl, NULL, rl_repl_timer_interval * 1000, TIMER_FLAG_DELAY_ON_DELAY) < 0) { LM_ERR("failed to register utimer\n"); return -1; } /* if db_url is not used */ for( n=0 ; n < 8 * sizeof(unsigned int) ; n++) { if (rl_hash_size==(1<<n)) break; if (rl_hash_size<(1<<n)) { LM_WARN("hash_size is not a power " "of 2 as it should be -> rounding from %d to %d\n", rl_hash_size, 1<<(n-1)); rl_hash_size = 1<<(n-1); } } if (init_rl_table(rl_hash_size) < 0) { LM_ERR("cannot allocate the table\n"); return -1; } if (rl_repl_init() < 0) { LM_ERR("cannot init bin replication\n"); return -1; } return 0; }
static int mod_init(void) { unsigned int timer_sets,set; unsigned int roundto_init; LM_INFO("TM - initializing...\n"); /* checking if we have sufficient bitmap capacity for given maximum number of branches */ if (MAX_BRANCHES+1>31) { LM_CRIT("Too many max UACs for UAC branch_bm_t bitmap: %d\n", MAX_BRANCHES ); return -1; } fix_flag_name(minor_branch_flag_str, minor_branch_flag); minor_branch_flag = get_flag_id_by_name(FLAG_TYPE_BRANCH, minor_branch_flag_str); if (minor_branch_flag!=-1) { if (minor_branch_flag > (8*sizeof(int)-1)) { LM_CRIT("invalid minor branch flag\n"); return -1; } minor_branch_flag = 1<<minor_branch_flag; } else { minor_branch_flag = 0; } /* if statistics are disabled, prevent their registration to core */ if (tm_enable_stats==0) #ifdef STATIC_TM tm_exports.stats = 0; #else exports.stats = 0; #endif if (init_callid() < 0) { LM_CRIT("Error while initializing Call-ID generator\n"); return -1; } /* how many timer sets do we need to create? */ timer_sets = (timer_partitions<=1)?1:timer_partitions ; /* try first allocating all the structures needed for syncing */ if (lock_initialize( timer_sets )==-1) return -1; /* building the hash table*/ if (!init_hash_table( timer_sets )) { LM_ERR("initializing hash_table failed\n"); return -1; } /* init static hidden values */ init_t(); if (!tm_init_timers( timer_sets ) ) { LM_ERR("timer init failed\n"); return -1; } /* the ROUNDTO macro taken from the locking interface */ #ifdef ROUNDTO roundto_init = ROUNDTO; #else roundto_init = sizeof(void *); #endif while (roundto_init != 1) { tm_timer_shift++; roundto_init >>= 1; } LM_DBG("timer set shift is %d\n", tm_timer_shift); /* register the timer functions */ for ( set=0 ; set<timer_sets ; set++ ) { if (register_timer( "tm-timer", timer_routine, (void*)(long)set, 1, TIMER_FLAG_DELAY_ON_DELAY) < 0 ) { LM_ERR("failed to register timer for set %d\n",set); return -1; } if (register_utimer( "tm-utimer", utimer_routine, (void*)(long)set, 100*1000, TIMER_FLAG_DELAY_ON_DELAY)<0) { LM_ERR("failed to register utimer for set %d\n",set); return -1; } } if (uac_init()==-1) { LM_ERR("uac_init failed\n"); return -1; } if (init_tmcb_lists()!=1) { LM_CRIT("failed to init tmcb lists\n"); return -1; } tm_init_tags(); init_twrite_lines(); if (init_twrite_sock() < 0) { LM_ERR("failed to create socket\n"); return -1; } /* register post-script clean-up function */ if (register_script_cb( do_t_cleanup, POST_SCRIPT_CB|REQ_TYPE_CB, 0)<0 ) { LM_ERR("failed to register POST request callback\n"); return -1; } if (register_script_cb( script_init, PRE_SCRIPT_CB|REQ_TYPE_CB , 0)<0 ) { LM_ERR("failed to register PRE request callback\n"); return -1; } if(register_pv_context("request", tm_pv_context_request)< 0) { LM_ERR("Failed to register pv contexts\n"); return -1; } if(register_pv_context("reply", tm_pv_context_reply)< 0) { LM_ERR("Failed to register pv contexts\n"); return -1; } if ( parse_avp_spec( &uac_ctx_avp, &uac_ctx_avp_id)<0 ) { LM_ERR("failed to register AVP name <%s>\n",uac_ctx_avp.s); return -1; } if ( register_async_script_handlers( t_handle_async, t_resume_async )<0 ) { LM_ERR("failed to register async handler to core \n"); return -1; } return 0; }
static int mod_init(void) { LM_INFO("TM - initializing...\n"); /* checking if we have sufficient bitmap capacity for given maximum number of branches */ if (MAX_BRANCHES+1>31) { LM_CRIT("Too many max UACs for UAC branch_bm_t bitmap: %d\n", MAX_BRANCHES ); return -1; } if (minor_branch_flag!=-1) { if (minor_branch_flag > (8*sizeof(int)-1)) { LM_CRIT("invalid minor branch flag\n"); return -1; } minor_branch_flag = 1<<minor_branch_flag; } else { minor_branch_flag = 0; } /* if statistics are disabled, prevent their registration to core */ if (tm_enable_stats==0) #ifdef STATIC_TM tm_exports.stats = 0; #else exports.stats = 0; #endif if (init_callid() < 0) { LM_CRIT("Error while initializing Call-ID generator\n"); return -1; } /* building the hash table*/ if (!init_hash_table()) { LM_ERR("initializing hash_table failed\n"); return -1; } /* init static hidden values */ init_t(); if (!tm_init_timers()) { LM_ERR("timer init failed\n"); return -1; } /* register the timer functions */ if (register_timer( timer_routine , 0, 1 )<0) { LM_ERR("failed to register timer\n"); return -1; } if (register_utimer( utimer_routine , 0, 100*1000 )<0) { LM_ERR("failed to register utimer\n"); return -1; } if (uac_init()==-1) { LM_ERR("uac_init failed\n"); return -1; } if (init_tmcb_lists()!=1) { LM_CRIT("failed to init tmcb lists\n"); return -1; } tm_init_tags(); init_twrite_lines(); if (init_twrite_sock() < 0) { LM_ERR("failed to create socket\n"); return -1; } /* register post-script clean-up function */ if (register_script_cb( do_t_cleanup, POST_SCRIPT_CB|REQ_TYPE_CB, 0)<0 ) { LM_ERR("failed to register POST request callback\n"); return -1; } if (register_script_cb( script_init, PRE_SCRIPT_CB|REQ_TYPE_CB , 0)<0 ) { LM_ERR("failed to register PRE request callback\n"); return -1; } if ( init_avp_params( fr_timer_param, fr_inv_timer_param)<0 ){ LM_ERR("ERROR:tm:mod_init: failed to process timer AVPs\n"); return -1; } if(register_pv_context("request", tm_pv_context_request)< 0) { LM_ERR("Failed to register pv contexts\n"); return -1; } if(register_pv_context("reply", tm_pv_context_reply)< 0) { LM_ERR("Failed to register pv contexts\n"); return -1; } return 0; }