Ejemplo n.º 1
0
static int
nat_uac_test_f(struct sip_msg* msg, char* str1, char* str2)
{
	int tests;

	if (get_int_fparam(&tests, msg, (fparam_t*) str1) < 0)
		return -1;

	/* return true if any of the NAT-UAC tests holds */

	/* test if the source port is different from the port in Via */
	if ((tests & NAT_UAC_TEST_RPORT) &&
	    (msg->rcv.src_port != (msg->via1->port ? msg->via1->port : SIP_PORT))) {
		return 1;
	}
	/*
	 * test if source address of signaling is different from
	 * address advertised in Via
	 */
	if ((tests & NAT_UAC_TEST_RCVD) && received_test(msg))
		return 1;
	/*
	 * test for occurrences of RFC1918 addresses in Contact
	 * header field
	 */
	if ((tests & NAT_UAC_TEST_C_1918) && (contact_1918(msg) > 0))
		return 1;
	/*
	 * test for occurrences of RFC1918 addresses in SDP body
	 */
	if ((tests & NAT_UAC_TEST_S_1918) && sdp_1918(msg))
		return 1;
	/*
	 * test for occurrences of RFC1918 addresses top Via
	 */
	if ((tests & NAT_UAC_TEST_V_1918) && via_1918(msg))
		return 1;
	/*
	 * test if source port of signaling is different from
	 * port advertised in Contact
	 */
	if ((tests & NAT_UAC_TEST_C_PORT) && (contact_rport(msg) > 0))
		return 1;

	/* no test succeeded */
	return -1;

}
Ejemplo n.º 2
0
/* tests if address of signaling is different from address in 1st Via field */
static Bool
testSourceAddress(struct sip_msg* msg)
{
    Bool diffIP, diffPort;
    int via1Port;

    diffIP = received_test(msg);
    if (isSIPAsymmetric(getUserAgent(msg))) {
        // ignore port test for asymmetric clients (it's always different)
        diffPort = False;
    } else {
        via1Port = (msg->via1->port ? msg->via1->port : SIP_PORT);
        diffPort = (msg->rcv.src_port != via1Port);
    }

    return (diffIP || diffPort);
}
Ejemplo n.º 3
0
/** 
 * Tests if the message was received from behind a NAT.
 * - tests received, contact and via
 * @param msg - the SIP message
 */
int nat_uac_test(struct sip_msg * msg) {

	if(pcscf_nat_pingall)
		return 1;
		
	if((pcscf_nat_detection_type && NAT_UAC_TEST_RPORT) && 
		(msg->rcv.src_port != (msg-> via1->port ? msg->via1->port:SIP_PORT)))
		return 1;
	
	if((pcscf_nat_detection_type & NAT_UAC_TEST_RCVD) && received_test(msg))
		return 1;
	
//	if((pcscf_nat_detection_type & NAT_UAC_TEST_C_1918) && contact_1918(msg))
		//return 1;
	
//	if((pcscf_nat_detection_type & NAT_UAC_TEST_S_1918) && sdp_1918(msg))
//		return 1;
		
	if((pcscf_nat_detection_type & NAT_UAC_TEST_V_1918) && via_1918(msg))
		return 1;
	
	return 0;
}