[Kamailio-Users-ES] Modificar Headers

sadzas sadzas at gmail.com
Mon Feb 23 20:53:51 CET 2009



Iñaki Baz Castillo wrote:
> 
>> Mi idea es que los telefonos puedas comunicarse entre si sin llegar a
>> Asterisk, pero si desean conferencias, voicemail, etc, la llamada se
>> efectue al asterisk.
> 
> Perfectamente viable. Hay ejemplos de ello en voip-info y en el wiki de 
> Kamailio.
> 
No puedo lograrlo con telefonos que esten detras de NAT, sucede que al
enviar un INVITE, este se le envia a la IP privada del tel y por supuesto no
llega.

Los telefonos en LAN funcionan bien, y los telefonos haciendo NAT se
registran bien en la BD, mostrando la IP publica y la privada. (en contact
la privada, y en received la publica).

Haciendo una captura con NGREP veo esto, lo cual es logico que esta enviando
el INVITE a la IP privada, no puedo lograr que lo envie a la publica.

IP Asterisk: 200.xx.xx.87
IP Kamailio: 200.xx.xx.53
Tel que llama: 192.168.10.152
Tel que hace NAT: 192.168.2.10

U 192.168.10.152:5060 -> 200.xx.xx.53:5060
INVITE sip:6001 at 200.xx.xx.53 SIP/2.0.
Via: SIP/2.0/UDP 192.168.10.152:5060;branch=z9hG4bK-7d0886bc.
From: "6005" <sip:6005 at 200.xx.xx.53>;tag=1b7f20bc3b144e87o0.
To: "6001" <sip:6001 at 200.xx.xx.53>.
Call-ID: 12ee10a0-722d7ff3 at 192.168.10.152.
CSeq: 102 INVITE.
Max-Forwards: 70.
Proxy-Authorization: Digest
username="6005",realm="asterisk",nonce="4883c065",uri="sip:6001 at 200.xx.xx.53",algorithm=MD5,response="a9
a75f94f05a8e04d2ec7d5ae7ac8def".
Contact: "6005" <sip:6005 at 192.168.10.152:5060>.

U 200.xx.xx.53:5060 -> 192.168.10.152:5060
SIP/2.0 100 Giving a try.
Via: SIP/2.0/UDP
192.168.10.152:5060;branch=z9hG4bK-7d0886bc;rport=5060;received=192.168.10.152.
From: "6005" <sip:6005 at 200.xx.xx.53>;tag=1b7f20bc3b144e87o0.
To: "6001" <sip:6001 at 200.xx.xx.53>.
Call-ID: 12ee10a0-722d7ff3 at 192.168.10.152.
CSeq: 102 INVITE.
Server: Kamailio (1.4.3-notls (i386/linux)).
Content-Length: 0.

U 200.xx.xx.53:5060 -> 200.xx.xx.87:5060
INVITE sip:6001 at 200.xx.xx.87:5060 SIP/2.0.
Record-Route: <sip:200.xx.xx.53;lr=on;ftag=1b7f20bc3b144e87o0>.
Via: SIP/2.0/UDP 200.xx.xx.53;branch=z9hG4bKb157.98e72b53.0.
Via: SIP/2.0/UDP 192.168.10.152:5060;rport=5060;branch=z9hG4bK-7d0886bc.
From: "6005" <sip:6005 at 200.xx.xx.53>;tag=1b7f20bc3b144e87o0.
To: "6001" <sip:6001 at 200.xx.xx.53>.
Call-ID: 12ee10a0-722d7ff3 at 192.168.10.152.
CSeq: 102 INVITE.
Max-Forwards: 69.
Proxy-Authorization: Digest
username="6005",realm="asterisk",nonce="4883c065",uri="sip:6001 at 200.xx.xx.53",

U 200.xx.xx.87:5060 -> 200.xx.xx.53:5060
SIP/2.0 100 Trying.
Via: SIP/2.0/UDP
200.xx.xx.53;branch=z9hG4bKb157.98e72b53.0;received=200.xx.xx.53.
Via: SIP/2.0/UDP 192.168.10.152:5060;rport=5060;branch=z9hG4bK-7d0886bc.
Record-Route: <sip:200.xx.xx.53;lr=on;ftag=1b7f20bc3b144e87o0>.
From: "6005" <sip:6005 at 200.xx.xx.53>;tag=1b7f20bc3b144e87o0.
To: "6001" <sip:6001 at 200.xx.xx.53>.
Call-ID: 12ee10a0-722d7ff3 at 192.168.10.152.
CSeq: 102 INVITE.
User-Agent: Asterisk PBX.
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY.
Supported: replaces.
Contact: <sip:6001 at 200.xx.xx.87>.
Content-Length: 0.

U 200.xx.xx.87:5060 -> 200.xx.xx.53:5060
INVITE sip:6001 at 192.168.2.10:5060 SIP/2.0.
Via: SIP/2.0/UDP 200.xx.xx.87:5060;branch=z9hG4bK0105fa70;rport.
From: "6005" <sip:6005 at 200.xx.xx.87>;tag=as5bbe9873.
To: <sip:6001 at 192.168.2.10:5060>.
Contact: <sip:6005 at 200.xx.xx.87>.
Call-ID: 445adc075a5d751f30d1a306737b80b7 at 200.xx.xx.87.
CSeq: 102 INVITE.

U 200.xx.xx.53:5060 -> 200.xx.xx.87:5060
SIP/2.0 100 Giving a try.
Via: SIP/2.0/UDP
200.xx.xx.87:5060;branch=z9hG4bK0105fa70;rport=5060;received=200.xx.xx.87.
From: "6005" <sip:6005 at 200.xx.xx.87>;tag=as5bbe9873.
To: <sip:6001 at 192.168.2.10:5060>.
Call-ID: 445adc075a5d751f30d1a306737b80b7 at 200.xx.xx.87.
CSeq: 102 INVITE.
Server: Kamailio (1.4.3-notls (i386/linux)).
Content-Length: 0.


U 200.xx.xx.53:5060 -> 192.168.2.10:5060
INVITE sip:6001 at 192.168.2.10:5060 SIP/2.0.
Record-Route: <sip:200.xx.xx.53;lr=on;ftag=as5bbe9873>.
Via: SIP/2.0/UDP 200.xx.xx.53;branch=z9hG4bK1604.43fd3526.0.
Via: SIP/2.0/UDP 200.xx.xx.87:5060;branch=z9hG4bK0105fa70;rport=5060.
From: "6005" <sip:6005 at 200.xx.xx.87>;tag=as5bbe9873.
To: <sip:6001 at 192.168.2.10:5060>.
Contact: <sip:6005 at 200.xx.xx.87>.


U 200.xx.xx.87:5060 -> 200.xx.xx.53:5060
SIP/2.0 180 Ringing.
Via: SIP/2.0/UDP
200.xx.xx.53;branch=z9hG4bKb157.98e72b53.0;received=200.xx.xx.53.
Via: SIP/2.0/UDP 192.168.10.152:5060;rport=5060;branch=z9hG4bK-7d0886bc.
Record-Route: <sip:200.xx.xx.53;lr=on;ftag=1b7f20bc3b144e87o0>.
From: "6005" <sip:6005 at 200.xx.xx.53>;tag=1b7f20bc3b144e87o0.
To: "6001" <sip:6001 at 200.xx.xx.53>;tag=as0a184172.

U 200.xx.xx.53:5060 -> 192.168.10.152:5060
SIP/2.0 180 Ringing.
Via: SIP/2.0/UDP 192.168.10.152:5060;rport=5060;branch=z9hG4bK-7d0886bc.
Record-Route: <sip:200.xx.xx.53;lr=on;ftag=1b7f20bc3b144e87o0>.
From: "6005" <sip:6005 at 200.xx.xx.53>;tag=1b7f20bc3b144e87o0.
To: "6001" <sip:6001 at 200.xx.xx.53>;tag=as0a184172.
Call-ID: 12ee10a0-722d7ff3 at 192.168.10.152.

U 200.xx.xx.53:5060 -> 192.168.2.10:5060
INVITE sip:6001 at 192.168.2.10:5060 SIP/2.0.
Record-Route: <sip:200.xx.xx.53;lr=on;ftag=as5bbe9873>.
Via: SIP/2.0/UDP 200.xx.xx.53;branch=z9hG4bK1604.43fd3526.0.
Via: SIP/2.0/UDP 200.xx.xx.87:5060;branch=z9hG4bK0105fa70;rport=5060.
From: "6005" <sip:6005 at 200.xx.xx.87>;tag=as5bbe9873.
To: <sip:6001 at 192.168.2.10:5060>.
Contact: <sip:6005 at 200.xx.xx.87>.
Call-ID: 445adc075a5d751f30d1a306737b80b7 at 200.xx.xx.87.


U 200.xx.xx.53:5060 -> 192.168.2.10:5060
INVITE sip:6001 at 192.168.2.10:5060 SIP/2.0.
Record-Route: <sip:200.xx.xx.53;lr=on;ftag=as5bbe9873>.
Via: SIP/2.0/UDP 200.xx.xx.53;branch=z9hG4bK1604.43fd3526.0.
Via: SIP/2.0/UDP 200.xx.xx.87:5060;branch=z9hG4bK0105fa70;rport=5060.
From: "6005" <sip:6005 at 200.xx.xx.87>;tag=as5bbe9873.
To: <sip:6001 at 192.168.2.10:5060>.
Contact: <sip:6005 at 200.xx.xx.87>.
Call-ID: 445adc075a5d751f30d1a306737b80b7 at 200.xx.xx.87.


U 200.xx.xx.53:5060 -> 192.168.2.10:5060
INVITE sip:6001 at 192.168.2.10:5060 SIP/2.0.
Record-Route: <sip:200.xx.xx.53;lr=on;ftag=as5bbe9873>.
Via: SIP/2.0/UDP 200.xx.xx.53;branch=z9hG4bK1604.43fd3526.0.
Via: SIP/2.0/UDP 200.xx.xx.87:5060;branch=z9hG4bK0105fa70;rport=5060.
From: "6005" <sip:6005 at 200.xx.xx.87>;tag=as5bbe9873.
To: <sip:6001 at 192.168.2.10:5060>.
Contact: <sip:6005 at 200.xx.xx.87>.
Call-ID: 445adc075a5d751f30d1a306737b80b7 at 200.xx.xx.87.

U 200.xx.xx.53:5060 -> 192.168.2.10:5060
INVITE sip:6001 at 192.168.2.10:5060 SIP/2.0.
Record-Route: <sip:200.xx.xx.53;lr=on;ftag=as5bbe9873>.
Via: SIP/2.0/UDP 200.xx.xx.53;branch=z9hG4bK1604.43fd3526.0.
Via: SIP/2.0/UDP 200.xx.xx.87:5060;branch=z9hG4bK0105fa70;rport=5060.
From: "6005" <sip:6005 at 200.xx.xx.87>;tag=as5bbe9873.
To: <sip:6001 at 192.168.2.10:5060>.
Contact: <sip:6005 at 200.xx.xx.87>.
Call-ID: 445adc075a5d751f30d1a306737b80b7 at 200.xx.xx.87.

La configuracion de mi CFG es:

route{

	if (!mf_process_maxfwd_header("10")) {
		sl_send_reply("483","Too Many Hops");
		exit;
	}
	
	route(2);

	if (has_totag()) {
		if (loose_route()) {
			if (is_method("BYE")) {
				setflag(1); # do accounting ...
				setflag(3); # ... even if the transaction fails
			}
			route(1);
		} else {
			
			if ( is_method("ACK") ) {
				if ( t_check_trans() ) {
					t_relay();
					exit;
				} else {
					exit;
				}
			}
			sl_send_reply("404","Not here");
		}
		exit;
	}

	#initial requests

	# CANCEL processing
	if (is_method("CANCEL"))
	{
		if (t_check_trans())
			t_relay();
		exit;
	}

	t_check_trans();

	# record routing
	if (!is_method("REGISTER|MESSAGE"))
		record_route();

	# account only INVITEs
	if (is_method("INVITE")) {

		if ($rU =~ "5[0-9]" && src_ip!=200.xx.xx.87){
                	route(3);
			exit;
		}
		setflag(1); # do accounting
	}
	if (!uri==myself) {
		append_hf("P-hint: outbound\r\n"); 
		route(1);
	}

	# requests for my domain

	if (is_method("PUBLISH"))
	{
		sl_send_reply("503", "Service Unavailable");
		exit;
	}
	
	if (is_method("REGISTER"))
	{
		if (isflagset(5)) {
			setbflag(6);
			save("location");
		};
		
		if (!save("location"))
			sl_reply_error();
		
		append_hf("P-hint: usrloc applied\r\n"); 

		exit;
	}

	if ($rU==NULL) {
		# request with no Username in RURI
		sl_send_reply("484","Address Incomplete");
		exit;
	}

	if (!lookup("location")) {
		switch ($retcode) {
			case -1:
			case -3:
				t_newtran();
				t_reply("404", "Not Found");
				exit;
			case -2:
				sl_send_reply("405", "Method Not Allowed");
				exit;
		}
	}

	# when routing via usrloc, log the missed calls also
	setflag(2);
	route(1);
}


route[1] {
	# for INVITEs enable some additional helper routes
	if (is_method("INVITE")) {
		t_on_branch("2");
		t_on_reply("2");
		t_on_failure("1");
	}

	if (!t_relay()) {
		sl_reply_error();
	};
	exit;
}

route[2]{
	force_rport();
	if (nat_uac_test("19")) {
		if (method=="REGISTER") {
			fix_nated_register();
		} else {
			fix_nated_contact();
		};
		setflag(5);
	};
}

route[3] {

	log(1, "Reenvia a Asterisk \n");
	rewritehostport("200.xx.xx.87:5060");
    route(1);
}

branch_route[2] {
	xlog("new branch at $ru\n");
}


onreply_route[2] {
	xlog("incoming reply\n");
	if ((isflagset(5) || isbflagset(6)) && status=~"(183)|(2[0-9][0-9])") {
		force_rtp_proxy();
	}
	search_append('Contact:.*sip:[^>[:cntrl:]]*', ';nat=yes');

	if (isbflagset(6)) {
		fix_nated_contact();
	}
	exit;
}


failure_route[1] {
	if (t_was_cancelled()) {
		exit;
	}

}

-- 
View this message in context: http://www.nabble.com/Modificar-Headers-tp21727191p22168773.html
Sent from the OpenSER Users - ES mailing list archive at Nabble.com.





More information about the Users-es mailing list