Ejemplo n.º 1
0
/* FOR DEBUG PURPOSES */
void list_hash(dpl_id_t * hash, rw_lock_t * ref_lock)
{
	dpl_id_p crt_idp;
	dpl_node_p rulep;
	int i;

	if(!hash)
		return;

	/* lock the data for reading */
	lock_start_read( ref_lock );

	for(crt_idp = hash; crt_idp; crt_idp = crt_idp->next) {
		LM_DBG("DPID: %i, pointer %p\n", crt_idp->dp_id, crt_idp);

		for (i = 0; i <= DP_INDEX_HASH_SIZE; i++) {
			LM_DBG("BUCKET %d rules:\n", i);

			for(rulep = crt_idp->rule_hash[i].first_rule; rulep;
				rulep = rulep->next) {

				list_rule(rulep);
			}
		}
	}

	/* we are done reading -> unref the data */
	lock_stop_read( ref_lock );
}
Ejemplo n.º 2
0
/* get provider pointer from emergency service provider table
*  get 3 types of provider, depend on its attribution:
*   0 - source provider
*   1 - VPC provider
*   2 - vsp provider
*/
struct service_provider* get_provider(struct sip_msg *msg, int attr, rw_lock_t *ref_lock ) {

    int vsp_addr_len;
    char *vsp_addr;

    lock_start_read(ref_lock);

    struct service_provider* provider = *db_service_provider;
    while (provider != NULL) {

        LM_DBG("***attr:%d\n ", provider->attribution);

        if (provider->attribution == attr ){
            if (provider->attribution == 2){
                // search ip source
                vsp_addr = ip_addr2a(&msg->rcv.src_ip);
                vsp_addr_len = strlen(vsp_addr);      

                if ( (provider->nodeIP.len == vsp_addr_len) && (strncmp(vsp_addr, provider->nodeIP.s, vsp_addr_len) == 0)) {
                    LM_DBG(" FOUND IP SOURCE\n ");
                    lock_stop_read(ref_lock);
                    return provider;       
                }

            }else{
                lock_stop_read(ref_lock);
                return provider;
            }
        }
        provider = provider->next;
    }
    lock_stop_read(ref_lock);

    return NULL;    
}
Ejemplo n.º 3
0
int lb_update_from_replication( unsigned int group, str *uri,
														unsigned int flags)
{
	struct lb_dst *dst;

	lock_start_read( ref_lock );

	for( dst=(*curr_data)->dsts; dst; dst=dst->next ) {
		if ( (dst->group == group) &&
		(strncmp(dst->uri.s, uri->s, dst->uri.len) == 0)) {
			if ((dst->flags&LB_DST_STAT_MASK) != flags) {
				/* import the status flags */
				dst->flags = ((~LB_DST_STAT_MASK)&dst->flags)|
					(LB_DST_STAT_MASK&flags);
				/* raise event of status change */
				lb_raise_event(dst);
				lock_stop_read( ref_lock );
				return 0;
			}
		}
	}

	lock_stop_read( ref_lock );

	return -1;
}
Ejemplo n.º 4
0
/*FOR DEBUG PURPOSE*/
void list_hash(int h_index)
{
	dpl_id_p crt_idp;
	dpl_index_p indexp;
	dpl_node_p rulep;

	/* lock the data for reading */
	lock_start_read( ref_lock );

	if(!rules_hash[h_index])
		goto done;

	for(crt_idp=rules_hash[h_index]; crt_idp!=NULL; crt_idp = crt_idp->next){
		LM_DBG("DPID: %i, pointer %p\n", crt_idp->dp_id, crt_idp);
		for(indexp=crt_idp->first_index; indexp!=NULL;indexp= indexp->next){
			LM_DBG("INDEX LEN: %i\n", indexp->len);
			for(rulep = indexp->first_rule; rulep!= NULL;rulep = rulep->next){
				list_rule(rulep);
			}
		}
	}

done:
	/* we are done reading -> unref the data */
	lock_stop_read( ref_lock );
}
Ejemplo n.º 5
0
/* retreives esgwrifrom the list db_esrn_esgwri
* using  srid(selectiveRoutingID), resn(routingESN) and npa. 
*/
int emergency_routing(char *srid, int resn, int npa, char** esgwri, rw_lock_t *ref_lock ) {

    lock_start_read(ref_lock);

    struct esrn_routing* esrn_domain = *db_esrn_esgwri;
    LM_DBG("SRID = %s \n", srid);
    while (esrn_domain != NULL) {
        LM_DBG("CMP SRID= %.*s \n", esrn_domain->srid.len, esrn_domain->srid.s);
        LM_DBG("CMP RESN= %d \n", esrn_domain->resn);
        LM_DBG("CMP NPA = %d \n", esrn_domain->npa);                
        if (strncmp(esrn_domain->srid.s, srid, esrn_domain->srid.len) == 0) {
            if ((esrn_domain->resn == resn)&&(esrn_domain->npa == npa)) {
                char* temp = pkg_malloc(sizeof (char) * esrn_domain->esgwri.len + 1);
                if (!temp) {
                    LM_ERR("no more memory\n");
                    lock_stop_read(ref_lock);
                    return -1;
                }
                memcpy(temp, esrn_domain->esgwri.s, esrn_domain->esgwri.len);
                temp[esrn_domain->esgwri.len] = 0;
                *esgwri = temp;

                lock_stop_read(ref_lock);

                return 1;
            }
        }
        esrn_domain = esrn_domain->next;
    }
    lock_stop_read(ref_lock);

    return -1;
}
Ejemplo n.º 6
0
clusterer_node_t* get_clusterer_nodes(int cluster_id)
{
	clusterer_node_t *ret_nodes = NULL;
	node_info_t *node;
	cluster_info_t *cl;

	lock_start_read(cl_list_lock);

	cl = get_cluster_by_id(cluster_id);
	if (!cl) {
		LM_ERR("cluster id: %d not found!\n", cluster_id);
		lock_stop_read(cl_list_lock);
		return NULL;
	}
	for (node = cl->node_list; node; node = node->next)
		if (get_next_hop(node) > 0)
			if (add_clusterer_node(&ret_nodes, node) < 0) {
				lock_stop_read(cl_list_lock);
				LM_ERR("Unable to add node: %d to the returned list of reachable nodes\n",
					node->node_id);
				free_clusterer_nodes(ret_nodes);
				return NULL;
			}

	lock_stop_read(cl_list_lock);

	return ret_nodes;
}
Ejemplo n.º 7
0
/* lists all domains */
static struct mi_root * tls_list(struct mi_root *cmd_tree, void *param)
{
	struct mi_node *root = NULL;
	struct mi_root *rpl_tree = NULL;

	rpl_tree = init_mi_tree(200, MI_OK_S, MI_OK_LEN);
	if (rpl_tree == NULL) {
		return NULL;
	}

	if (dom_lock)
		lock_start_read(dom_lock);

	root = &rpl_tree->node;

	if (list_domain(root, tls_client_domains) < 0)
		goto error;

	if (list_domain(root, tls_server_domains) < 0)
		goto error;

	if (dom_lock)
		lock_stop_read(dom_lock);

	return rpl_tree;
error:
	if (dom_lock)
		lock_stop_read(dom_lock);
	if (rpl_tree) free_mi_tree(rpl_tree);
	return NULL;
}
Ejemplo n.º 8
0
void set_dst_state_from_rplcode( int id, int code)
{
	struct lb_dst *dst;

	lock_start_read( ref_lock );

	for( dst=(*curr_data)->dsts ; dst && dst->id!=id ; dst=dst->next);
	if (dst==NULL) {
		lock_stop_read( ref_lock );
		return;
	}

	if ((code == 200) || check_options_rplcode(code)) {
		/* re-enable to DST  (if allowed) */
		if ( dst->flags&LB_DST_STAT_NOEN_FLAG ) {
			lock_stop_read( ref_lock );
			return;
		}
		dst->flags &= ~LB_DST_STAT_DSBL_FLAG;
		lock_stop_read( ref_lock );
		return;
	}

	if (code>=400) {
		dst->flags |= LB_DST_STAT_DSBL_FLAG;
	}

	lock_stop_read( ref_lock );
}
Ejemplo n.º 9
0
static void lb_prob_handler(unsigned int ticks, void* param)
{
	lock_start_read( ref_lock );

	/* do probing */
	lb_do_probing(*curr_data);

	lock_stop_read( ref_lock );
}
Ejemplo n.º 10
0
static struct mi_root* mi_lb_resize(struct mi_root *cmd, void *param)
{
	struct mi_root *rpl_tree;
	struct lb_dst *dst;
	struct mi_node *node;
	unsigned int  id, size;
	str *name;
	int n;

	for( n=0,node = cmd->node.kids; n<3 && node ; n++,node=node->next );
	if (n!=3 || node!=0)
		return init_mi_tree( 400, MI_MISSING_PARM_S, MI_MISSING_PARM_LEN);

	node = cmd->node.kids;

	/* id (param 1) */
	if (str2int( &node->value, &id) < 0)
		goto bad_syntax;

	/* resource (param 2) */
	node = node->next;
	name = &node->value;

	/* id (param 3) */
	node = node->next;
	if (str2int( &node->value, &size) < 0)
		goto bad_syntax;

	lock_start_read( ref_lock );

	/* get destination */
	for( dst=(*curr_data)->dsts ; dst && dst->id!=id ; dst=dst->next);
	if (dst==NULL) {
		rpl_tree = init_mi_tree( 404, MI_SSTR("Destination ID not found"));
	} else {
		/* get resource */
		for( n=0 ; n<dst->rmap_no ; n++)
			if (dst->rmap[n].resource->name.len == name->len &&
			memcmp( dst->rmap[n].resource->name.s, name->s, name->len)==0)
				break;
		if (n==dst->rmap_no) {
			rpl_tree = init_mi_tree( 404,
				MI_SSTR("Destination has no such resource"));
		} else {
			dst->rmap[n].max_load = size;
			rpl_tree = init_mi_tree( 200, MI_SSTR(MI_OK_S));
		}
	}

	lock_stop_read( ref_lock );

	return rpl_tree;
bad_syntax:
	return init_mi_tree( 400, MI_SSTR(MI_BAD_PARM_S));

}
Ejemplo n.º 11
0
/*! \brief
 * Timer handler
 */
static void timer(unsigned int ticks, void* param)
{
	if (sync_lock)
		lock_start_read(sync_lock);
	if (synchronize_all_udomains() != 0) {
		LM_ERR("synchronizing cache failed\n");
	}
	if (sync_lock)
		lock_stop_read(sync_lock);
}
Ejemplo n.º 12
0
static int w_load_balance(struct sip_msg *req, char *grp, char *rl, char *al)
{
	int ret;
	int grp_no;
	struct lb_grp_param *lbgp = (struct lb_grp_param *)grp;
	pv_value_t val;
	struct lb_res_str_list *lb_rl;
	struct lb_res_parse *lbp;
	pv_elem_t *model;
	str dest;

	if (lbgp->grp_pv) {
		if (pv_get_spec_value( req, (pv_spec_p)lbgp->grp_pv, &val)!=0) {
			LM_ERR("failed to get PV value\n");
			return -1;
		}
		if ( (val.flags&PV_VAL_INT)==0 ) {
			LM_ERR("PV vals is not integer\n");
			return -1;
		}
		grp_no = val.ri;
	} else {
		grp_no = lbgp->grp_no;
	}

	lbp = (struct lb_res_parse *)rl;
	if (lbp->type & RES_ELEM) {
		model = (pv_elem_p)lbp->param;
		if (pv_printf_s(req, model, &dest) || dest.len <= 0) {
			LM_ERR("cannot create resource string\n");
			return -1;
		}
		lb_rl = parse_resources_list(dest.s, 0);
		if (!lb_rl) {
			LM_ERR("cannot create resource list\n");
			return -1;
		}
	} else
		lb_rl = (struct lb_res_str_list *)lbp->param;

	lock_start_read( ref_lock );

	/* do lb */
	ret = do_load_balance(req, grp_no, lb_rl,
			(unsigned int)(long)al, *curr_data);

	lock_stop_read( ref_lock );

	if (lbp->type & RES_ELEM)
		pkg_free(lb_rl);

	if (ret<0)
		return ret;
	return 1;
}
Ejemplo n.º 13
0
/*
 * find client domain
 * return 0 if virtual domain not found
 */
struct tls_domain *tls_find_client_domain(struct ip_addr *ip, unsigned short port)
{
	struct tls_domain *dom;
	struct usr_avp *avp;
	int_str val;

	avp = NULL;

	if (tls_client_domain_avp > 0)
		avp = search_first_avp(0, tls_client_domain_avp, &val, 0);
	else
		LM_DBG("name based TLS client domain matching is disabled\n");

	if (dom_lock)
		lock_start_read(dom_lock);

	if (!avp) {
		LM_DBG("no TLS client domain AVP set, looking "
			"to match TLS client domain by scoket\n");
		dom = tls_find_client_domain_addr(ip, port);
		if (dom) {
			LM_DBG("found TLS client domain [%s:%d] based on socket\n",
				ip_addr2a(&dom->addr), dom->port);
		}
	} else {
		LM_DBG("TLS client domain AVP found = '%.*s'\n",
			val.s.len, ZSW(val.s.s));
		dom = tls_find_client_domain_name(val.s);
		if (dom) {
			LM_DBG("found TLS client domain '%.*s' by name\n",
				val.s.len, ZSW(val.s.s));
		} else {
			LM_DBG("TLS client domain not found by name, "
				"trying socket based TLS client domain matching\n");
			dom = tls_find_client_domain_addr(ip, port);
			if (dom) {
				LM_DBG("found TLS client domain [%s:%d] based on socket\n",
					ip_addr2a(&dom->addr), dom->port);
			}
		}
	}

	if (dom && dom->type & TLS_DOMAIN_DB) {
		lock_get(dom->lock);
		dom->refs++;
		lock_release(dom->lock);
	}

	if (dom_lock)
		lock_stop_read(dom_lock);

	return dom;
}
Ejemplo n.º 14
0
static int w_lb_is_dst2(struct sip_msg *msg, char *ip, char *port)
{
	int ret;

	lock_start_read( ref_lock );

	ret = lb_is_dst(*curr_data, msg, (pv_spec_t*)ip, (gparam_t*)port, -1, 0);

	lock_stop_read( ref_lock );

	if (ret<0)
		return ret;
	return 1;
}
Ejemplo n.º 15
0
static struct mi_root * clusterer_list_cap(struct mi_root *cmd_tree, void *param)
{
	cluster_info_t *cl;
	struct local_cap *cap;
	struct mi_root *rpl_tree = NULL;
	struct mi_node *node = NULL;
	struct mi_node *node_s = NULL;
	struct mi_attr* attr;
	str val;
	static str str_ok = str_init("Ok");
	static str str_not_synced = str_init("not synced");

	rpl_tree = init_mi_tree(200, MI_OK_S, MI_OK_LEN);
	if (!rpl_tree)
		return NULL;
	rpl_tree->node.flags |= MI_IS_ARRAY;

	lock_start_read(cl_list_lock);

	for (cl = *cluster_list; cl; cl = cl->next) {
		val.s = int2str(cl->cluster_id, &val.len);
		node = add_mi_node_child(&rpl_tree->node, MI_DUP_VALUE|MI_IS_ARRAY,
			MI_SSTR("Cluster"), val.s, val.len);
		if (!node) goto error;

		for (cap = cl->capabilities; cap; cap = cap->next) {
			val.s = cap->reg.name.s;
			val.len = cap->reg.name.len;
			node_s = add_mi_node_child(node, MI_DUP_VALUE|MI_IS_ARRAY,
			   MI_SSTR("Capability"), val.s, val.len);
			if (!node_s) goto error;

			lock_get(cl->lock);
			val.s = int2str((cap->flags & CAP_STATE_OK) ? 1 : 0, &val.len);
			lock_release(cl->lock);
			attr = add_mi_attr(node_s, MI_DUP_VALUE, MI_SSTR("State"),
				(cap->flags & CAP_STATE_OK) ? str_ok.s : str_not_synced.s,
				(cap->flags & CAP_STATE_OK) ? str_ok.len : str_not_synced.len);
			if (!attr) goto error;
	   }
	}

	lock_stop_read(cl_list_lock);
	return rpl_tree;

error:
	lock_stop_read(cl_list_lock);
	if (rpl_tree) free_mi_tree(rpl_tree);
	return NULL;
}
Ejemplo n.º 16
0
static int w_lb_disable_dst(struct sip_msg *req)
{
	int ret;

	lock_start_read(ref_lock);

	/* do lb */
	ret = do_lb_disable_dst(req, *curr_data, lb_prob_verbose);

	lock_stop_read(ref_lock);

	if( ret < 0 )
		return ret;
	return 1;
}
Ejemplo n.º 17
0
static int w_lb_reset(struct sip_msg *req)
{
	int ret;

	lock_start_read(ref_lock);

	/* do lb */
	ret = do_lb_reset(req, *curr_data);

	lock_stop_read(ref_lock);

	if( ret < 0 )
		return ret;
	return 1;
}
Ejemplo n.º 18
0
static int send_to(int cluster_id, int proto)
{
	table_entry_value_t *value;
	str send_buffer;
	unsigned long ctime = time(0);
	int ok = -1;

	if (proto == PROTO_BIN)
		bin_get_buffer(&send_buffer);

	lock_start_read(ref_lock);

	value = clusterer_find_nodes(cluster_id, proto);
	for (; value; value = value->next) {
		ok = 0;
		if (value->state == 1) {
			if (value->prev_no_tries != -1 &&
				value->no_tries > 0 &&
				value->prev_no_tries == value->no_tries) {
				value->no_tries = 0;
			}
			value->prev_no_tries = value->no_tries;
		}

		if (value->state == 2) {
			if ((ctime - value->last_attempt) >= value->duration) {
				value->last_attempt = ctime;
				value->state = 1;
				value->no_tries = 0;
			}
		}

		if (value->state == 1) {
			if (proto == PROTO_BIN) {
				if (msg_send(NULL, PROTO_BIN, &value->addr, 0,
				             send_buffer.s, send_buffer.len, 0) != 0) {
					LM_ERR("cannot send message\n");
					temp_disable_machine(value);
				}
			}
		}
	}

	lock_stop_read(ref_lock);

	return ok;
}
Ejemplo n.º 19
0
void receive_lb_binary_packet(bin_packet_t *packet)
{
	LM_DBG("received a binary packet [%d]!\n", packet->type);

	if(get_bin_pkg_version(packet) != BIN_VERSION) {
		LM_ERR("incompatible bin protocol version\n");
		return;
	}

	if (packet->type == REPL_LB_STATUS_UPDATE) {
		lock_start_read(ref_lock);
		replicate_lb_status_update(packet, *curr_data);
		lock_stop_read(ref_lock);
	} else {
		LM_ERR("invalid load_balancer binary packet type: %d\n", packet->type);
	}
}
Ejemplo n.º 20
0
static void lb_update_max_loads(unsigned int ticks, void *param)
{
	struct lb_dst *dst;
	int ri, old, psz;

	LM_DBG("updating max loads...\n");

	lock_start_write(ref_lock);
	for (dst = (*curr_data)->dsts; dst; dst = dst->next) {
		if (!dst->fs_sock)
			continue;

		lock_start_read(dst->fs_sock->stats_lk);
		for (ri = 0; ri < dst->rmap_no; ri++) {
			if (dst->rmap[ri].fs_enabled) {
				psz = lb_dlg_binds.get_profile_size(
				            dst->rmap[ri].resource->profile, &dst->profile_id);
				old = dst->rmap[ri].max_load;

				/*
				 * The normal case. OpenSIPS sees, at _most_, the same number
				 * of sessions as FreeSWITCH does. Any differences must be
				 * subtracted from the remote "max sessions" value
				 */
				if (psz < dst->fs_sock->stats.max_sess) {
					dst->rmap[ri].max_load =
					(dst->fs_sock->stats.id_cpu / (float)100) *
						(dst->fs_sock->stats.max_sess -
						 (dst->fs_sock->stats.sess - psz));
				} else {
					dst->rmap[ri].max_load =
					(dst->fs_sock->stats.id_cpu / (float)100) *
						dst->fs_sock->stats.max_sess;
				}
				LM_DBG("load update on FS (%p) %s:%d: "
				       "%d -> %d (%d %d %.3f), prof=%d\n",
				       dst->fs_sock, dst->fs_sock->host.s, dst->fs_sock->port,
				       old, dst->rmap[ri].max_load, dst->fs_sock->stats.sess,
				       dst->fs_sock->stats.max_sess,
				       dst->fs_sock->stats.id_cpu, psz);
			}
		}
		lock_stop_read(dst->fs_sock->stats_lk);
	}
	lock_stop_write(ref_lock);
}
Ejemplo n.º 21
0
int cl_get_my_index(int cluster_id, str *capability, int *nr_nodes)
{
	int i, j, tmp;
	int sorted[MAX_NO_NODES];
	node_info_t *node;
	cluster_info_t *cl;
	struct remote_cap *cap;

	lock_start_read(cl_list_lock);

	cl = get_cluster_by_id(cluster_id);
	if (!cl) {
		LM_ERR("cluster id: %d not found!\n", cluster_id);
		lock_stop_read(cl_list_lock);
		return -1;
	}

	*nr_nodes = 0;
	for (node = cl->node_list; node; node = node->next)
		if (get_next_hop(node) > 0) {
			lock_get(node->lock);
			for (cap = node->capabilities; cap; cap = cap->next)
				if (!str_strcmp(capability, &cap->name))
					break;

			if (cap && cap->flags & CAP_STATE_OK)
				sorted[(*nr_nodes)++] = node->node_id;
			lock_release(node->lock);
		}

	lock_stop_read(cl_list_lock);

	/* sort array of reachable node ids */
	for (i = 1; i < *nr_nodes; i++) {
		tmp = sorted[i];
		for (j = i - 1; j >= 0 && sorted[j] > tmp; j = j - 1)
			sorted[j+1] = sorted[j];
		sorted[j+1] = tmp;
	}

	for (i = 0; i < *nr_nodes && sorted[i] < current_id; i++) ;

	(*nr_nodes)++;
	return i;
}
Ejemplo n.º 22
0
static clusterer_node_t* get_nodes(int cluster_id, int proto)
{
	clusterer_node_t* tmp;
	clusterer_node_t* nodes = NULL;
	table_entry_value_t* head;
	unsigned long ctime = time(0);

	lock_start_read(ref_lock);

	head = clusterer_find_nodes(cluster_id, proto);
	for (; head; head = head->next) {
		if (head->state == 1) {
			if (head->prev_no_tries != -1 &&
				head->no_tries > 0 &&
				head->prev_no_tries == head->no_tries) {
				head->no_tries = 0;
			}
			head->prev_no_tries = head->no_tries;
		}

		if (head->state == 2) {
			if ((ctime - head->last_attempt) >= head->duration) {
				head->last_attempt = ctime;
				head->state = 1;
				head->no_tries = 0;
			}
		}
		if (head->state == 1 && add_node(&nodes, head, proto) < 0) {
			goto error;
		}
	}

	lock_stop_read(ref_lock);
	return nodes;

error:
	lock_stop_read(ref_lock);
	while (nodes) {
		tmp = nodes;
		nodes = nodes->next;
		free_node(tmp);
	}
	return NULL;
}
Ejemplo n.º 23
0
void set_dst_state_from_rplcode( int id, int code)
{
	struct lb_dst *dst;
	int old_flags;

	lock_start_read( ref_lock );

	for( dst=(*curr_data)->dsts ; dst && dst->id!=id ; dst=dst->next);
	if (dst==NULL) {
		lock_stop_read( ref_lock );
		return;
	}

	if ((code == 200) || check_options_rplcode(code)) {
		/* re-enable to DST  (if allowed) */
		if ( dst->flags&LB_DST_STAT_NOEN_FLAG ) {
			lock_stop_read( ref_lock );
			return;
		}
		old_flags = dst->flags;
		dst->flags &= ~LB_DST_STAT_DSBL_FLAG;
		if (dst->flags != old_flags) {
			lb_status_changed(dst);
			if (lb_prob_verbose)
				LM_INFO("re-enable destination %d <%.*s> after %d reply "
					"on probe\n", dst->id, dst->uri.len, dst->uri.s, code);
		}
		lock_stop_read( ref_lock );
		return;
	}

	if (code>=400) {
		old_flags = dst->flags;
		dst->flags |= LB_DST_STAT_DSBL_FLAG;
		if (dst->flags != old_flags) {
			lb_status_changed(dst);
			if (lb_prob_verbose)
				LM_INFO("disable destination %d <%.*s> after %d reply "
					"on probe\n", dst->id, dst->uri.len, dst->uri.s, code);
		}
	}

	lock_stop_read( ref_lock );
}
Ejemplo n.º 24
0
int clusterer_check(int cluster_id, union sockaddr_union* su, int machine_id, int proto)
{
	int rc = 0;
	table_entry_value_t *head;

	lock_start_read(ref_lock);

	head = clusterer_find_nodes(cluster_id, proto);
	for (; head; head = head->next) {
		if (su_ip_cmp(su, &head->addr) && head->machine_id == machine_id) {
			rc = 1;
			break;
		}
	}

	lock_stop_read(ref_lock);

	return rc;
}
Ejemplo n.º 25
0
clusterer_node_t *api_get_next_hop(int cluster_id, int node_id)
{
	clusterer_node_t *ret = NULL;
	node_info_t *dest_node;
	cluster_info_t *cluster;
	int rc;

	lock_start_read(cl_list_lock);

	cluster = get_cluster_by_id(cluster_id);
	if (!cluster) {
		LM_DBG("Cluster id: %d not found!\n", cluster_id);
		return NULL;
	}
	dest_node = get_node_by_id(cluster, node_id);
	if (!dest_node) {
		LM_DBG("Node id: %d no found!\n", node_id);
		return NULL;
	}

	rc = get_next_hop(dest_node);
	if (rc < 0)
		return NULL;
	else if (rc == 0) {
		LM_DBG("No other path to node: %d\n", node_id);
		return NULL;
	}

	lock_get(dest_node->lock);

	if (add_clusterer_node(&ret, dest_node->next_hop) < 0) {
		LM_ERR("Failed to allocate next hop\n");
		return NULL;
	}

	lock_release(dest_node->lock);

	lock_stop_read(cl_list_lock);

	return ret;
}
Ejemplo n.º 26
0
static int w_lb_is_dst4(struct sip_msg *msg,char *ip,char *port,char *grp,
															char *active)
{
	int ret, group;

	if (fixup_get_ivalue(msg, (gparam_p)grp, &group) != 0) {
		LM_ERR("Invalid lb group pseudo variable!\n");
		return -1;
	}

	lock_start_read( ref_lock );

	ret = lb_is_dst(*curr_data, msg, (pv_spec_t*)ip, (gparam_t*)port,
	                group, active ? (int)*(unsigned int *)active : 0);

	lock_stop_read( ref_lock );

	if (ret<0)
		return ret;
	return 1;
}
Ejemplo n.º 27
0
int cl_get_my_sip_addr(int cluster_id, str *out_addr)
{
	cluster_info_t *cl;
	int rc;

	if (!cl_list_lock) {
		LM_ERR("cluster shutdown\n");
		memset(out_addr, 0, sizeof *out_addr);
		return -1;
	}
	lock_start_read(cl_list_lock);

	cl = get_cluster_by_id(cluster_id);
	if (!cl) {
		LM_ERR("unknown cluster id: %d\n", cluster_id);
		lock_stop_read(cl_list_lock);
		memset(out_addr, 0, sizeof *out_addr);
		return -1;
	}

	lock_get(cl->current_node->lock);
	if (ZSTR(cl->current_node->sip_addr)) {
		memset(out_addr, 0, sizeof *out_addr);
		rc = 0;
	} else {
		if (pkg_str_dup(out_addr, &cl->current_node->sip_addr) != 0) {
			LM_ERR("oom\n");
			memset(out_addr, 0, sizeof *out_addr);
			rc = -1;
		} else {
			rc = 0;
		}
	}

	lock_release(cl->current_node->lock);
	lock_stop_read(cl_list_lock);
	return rc;
}
Ejemplo n.º 28
0
struct mi_root *mi_list_sharing_tags(struct mi_root *cmd_tree, void *param)
{
    struct mi_root *rpl_tree= NULL;
    struct mi_node *node, *rpl = NULL;
    struct mi_attr *attr;
    struct dlg_sharing_tag *tag;
    str val;

    if (!dialog_repl_cluster)
		return init_mi_tree(400, MI_SSTR("Dialog replication disabled"));

    rpl_tree = init_mi_tree(200, MI_SSTR(MI_OK));
    if (rpl_tree==0)
        return NULL;
    rpl = &rpl_tree->node;
    rpl->flags |= MI_IS_ARRAY;

    lock_start_read(shtags_lock);
    for (tag = *shtags_list; tag; tag = tag->next) {
        node = add_mi_node_child(rpl, MI_DUP_VALUE,
            MI_SSTR("Tag"), tag->name.s, tag->name.len);
        if (!node) goto error;

        val.s = int2str(tag->state, &val.len);
        attr = add_mi_attr(node, MI_DUP_VALUE,
            MI_SSTR("State"), val.s, val.len);
        if (!attr) goto error;
    }
    lock_stop_read(shtags_lock);

    return rpl_tree;

error:
    lock_stop_read(shtags_lock);
    if (rpl_tree) free_mi_tree(rpl_tree);
    return NULL;
}
Ejemplo n.º 29
0
/*
 * find server domain with given ip and port
 * return default domain if virtual domain not found
 */
struct tls_domain *
tls_find_server_domain(struct ip_addr *ip, unsigned short port)
{
	struct tls_domain *p;

	if (dom_lock)
		lock_start_read(dom_lock);

	p = *tls_server_domains;
	while (p) {
		if ((p->port == port) && ip_addr_cmp(&p->addr, ip)) {
			LM_DBG("virtual TLS server domain found\n");
			if (p->type & TLS_DOMAIN_DB) {
				lock_get(p->lock);
				p->refs++;
				lock_release(p->lock);
				if (dom_lock)
					lock_stop_read(dom_lock);
			}
			return p;
		}
		p = p->next;
	}

	lock_get((*tls_default_server_domain)->lock);
	(*tls_default_server_domain)->refs++;
	lock_release((*tls_default_server_domain)->lock);

	if (dom_lock)
		lock_stop_read(dom_lock);

	LM_DBG("virtual TLS server domain not found, "
		"Using default TLS server domain settings\n");

	return *tls_default_server_domain;
}
Ejemplo n.º 30
0
/*! \brief
 * Module destroy function
 */
static void destroy(void)
{
	/* we need to sync DB in order to flush the cache */
	if (ul_dbh) {
		ul_unlock_locks();
		if (sync_lock)
			lock_start_read(sync_lock);
		if (synchronize_all_udomains() != 0) {
			LM_ERR("flushing cache failed\n");
		}
		if (sync_lock) {
			lock_stop_read(sync_lock);
			lock_destroy_rw(sync_lock);
			sync_lock = 0;
		}
		ul_dbf.close(ul_dbh);
	}

	free_all_udomains();
	ul_destroy_locks();

	/* free callbacks list */
	destroy_ulcb_list();
}