Beispiel #1
0
/*
 * Checks if address/port is found in cached address or
 * subnet table in any group. If yes, returns that group. If not returns -1.
 * Port value 0 in cached address and group table matches any port.
 */
int allow_address_group(struct sip_msg* _msg, char* _addr, char* _port)
{
	int group = -1;

	unsigned int port;
	str ips;
	ip_addr_t *ipa;

	if (_addr==NULL
			|| (fixup_get_svalue(_msg, (gparam_p)_addr, &ips) < 0)) {
		LM_ERR("cannot get value of address pvar\n");
		return -1;
	}
	if (_port==NULL
			|| (fixup_get_ivalue(_msg, (gparam_p)_port, (int*)&port) < 0)) {
		LM_ERR("cannot get value of port pvar\n");
		return -1;
	}

	ipa=strtoipX(&ips);

	if ( ipa ) {
		LM_DBG("looking for <%.*s, %u> in address table\n",
				ips.len, ips.s, port);
		if(addr_hash_table) {
			group = find_group_in_addr_hash_table(*addr_hash_table,
					ipa, port);
			LM_DBG("Found address in group <%d>\n", group);

			if (group != -1) return group;
		}
		if(subnet_table) {
			LM_DBG("looking for <%.*s, %u> in subnet table\n",
					ips.len, ips.s, port);
			group = find_group_in_subnet_table(*subnet_table,
					ipa, port);
			LM_DBG("Found a match of subnet in group <%d>\n", group);
		}
	} else {
		LM_DBG("looking for <%.*s, %u> in domain_name table\n",
				ips.len, ips.s, port);
		if(domain_list_table) {
			group = find_group_in_domain_name_table(*domain_list_table,
					&ips, port);
			LM_DBG("Found a match of domain_name in group <%d>\n", group);
		}
	}

	LM_DBG("Found <%d>\n", group);
	return group;
}
Beispiel #2
0
/*
 * Checks if source address/port is found in cached address or
 * subnet table in any group. If yes, returns that group. If not returns -1.
 * Port value 0 in cached address and group table matches any port.
 */
int allow_source_address_group(struct sip_msg* _msg, char* _str1, char* _str2) 
{
	int group;

	LM_DBG("looking for <%x, %u> in address table\n",
			_msg->rcv.src_ip.u.addr32[0], _msg->rcv.src_port);
	group = find_group_in_addr_hash_table(*addr_hash_table,
			&_msg->rcv.src_ip,
			_msg->rcv.src_port);
	LM_DBG("Found <%d>\n", group);

	if (group != -1) return group;

	LM_DBG("looking for <%x, %u> in subnet table\n",
			_msg->rcv.src_ip.u.addr32[0], _msg->rcv.src_port);
	group = find_group_in_subnet_table(*subnet_table,
			&_msg->rcv.src_ip,
			_msg->rcv.src_port);
	LM_DBG("Found <%d>\n", group);
	return group;

}
Beispiel #3
0
int get_source_group(struct sip_msg* msg, char *arg) {
	int group = -1;
	struct in_addr in;
	struct ip_addr *ip;
	str str_ip, partition;
	pv_value_t pvt;
	struct part_pvar *ppv;
	struct pm_part_struct *ps;

	ppv  = (struct part_pvar *)arg;

	if (ppv->part) {
		if (fixup_get_svalue(msg, ppv->part, &partition)) {
			    LM_ERR("cannot get partition value\n");
				return -1;
		}

		str_trim_spaces_lr(partition);
		ps = get_part_struct(&partition);

		if (ps == NULL) {
			LM_ERR("no such partition (%.*s)\n", partition.len, partition.s);
			return -1;
		}

	} else {
		ps = get_part_struct(&def_part);
		if (ps == NULL) {
			LM_ERR("no default partition\n");
			return -1;
		}
	}

	LM_DBG("Looking for <%x, %u> in address table\n",
			msg->rcv.src_ip.u.addr32[0], msg->rcv.src_port);

	in.s_addr = msg->rcv.src_ip.u.addr32[0];
	str_ip.s = inet_ntoa(in);
	str_ip.len = str_ip.s ? strlen(str_ip.s) : 0;

	ip = str2ip(&str_ip);

	group = find_group_in_hash_table(*ps->hash_table,
				ip,
				msg->rcv.src_port);
	group=0;

	LM_DBG("Found <%d>\n", group);

	if (group == -1) {

		LM_DBG("Looking for <%x, %u> in subnet table\n",
			msg->rcv.src_ip.u.addr32[0], msg->rcv.src_port);

/* TODO FIX INPUT PARAMS*/
	group = find_group_in_subnet_table(*ps->subnet_table,
			ip,
			msg->rcv.src_port);
		group = 0;

		LM_DBG("Found <%d>\n", group);
	}

	pvt.flags = PV_VAL_INT|PV_TYPE_INT;
	pvt.rs.s = NULL;
	pvt.rs.len = 0;
	pvt.ri = group;

	if (pv_set_value(msg, ppv->sp, (int)EQ_T, &pvt) < 0) {
		LM_ERR("setting of pvar failed\n");
		return -1;
	}

	return 1;
}