[Serusers] Strange problem - SIP-->PSTN - 40 sec calls duration

Andrei Pelinescu-Onciul andrei at iptel.org
Tue Nov 8 14:29:28 CET 2005


On Nov 07, 2005 at 15:20, deviator <deviator at inbox.ru> wrote:
> Thank you for your reply!
> 
> But i'm still misundestand what to do, sorry i'm a beginner :(


In general ACKs and CANCELs must be treated like the INVITE when request
uri's are rewritten.
This means that if you rewrite the uri in the INVITE in the PSTN case,
you must do the same for ACKs and CANCELs (but don't challenge/auth. them!).

What happens in your case is you send an INVITE like
91234 at ser_ip which gets rewritten to 9123 at pstn_ip by ser and forwarded
to the pstn gw. When the pstn replies it sets the Contact to the ser ip
 (91234 at ser_ip). Now when your UA sends the ACK is sends it to the
 Contact in the 200 Ok, so it will send and ACK to 91234 at ser_ip. However
 in your ser cfg the ACK is handled differently and the uri won't get
 rewritten to 91234 at pstn_ip. The ACK will be forwarded untouched
 instead, which results in a loop (it will be forwarded to ser_ip).

You will have the same problem for CANCELs (you won't be able to cancel
a call to the pstn).


Andrei

> 
> 	if (uri==myself) {
> 		append_hf("P-hint: Local Destination\r\n");
> 		if (method=="ACK") {
> 			setflag(1);
> 			route(9);
> 			break;
> 
> ..........
> route[9] {
> 	if (method=="ACK") {
> 		t_relay();
> 		return;
> 	};
> 
> 	lookup("aliases");
> 	if (uri!=myself) {
> 		route(1);
> 		break;
> 	};
> 	lookup("location");
> 	route(1);
> }
> 
> is it right ???
> 
> in syslog i see LOOP DETECTED and warning: sl_send_reply:i won't send a reply for ack
> 
> the whole route block
> route {
> 
> 	# ------------------------------------------------------------------------
> 	# Sanity Check Section
> 	# ------------------------------------------------------------------------
> 	if (!mf_process_maxfwd_header("10")) {
> 		log(1, "LOOP DETECTED");
> 		sl_send_reply("483", "Nah, too many hops");
> 		break;
> 	};
> 
> 	if (msg:len > max_len) {
> 		log(1, "MESSAGE OVERFLOW");
> 		sl_send_reply("513", "Fucking shit, &#9552;essage too large");
> 		break;
> 	};
> 
> 	# ------------------------------------------------------------------------
> 	# Record Route Section
> 	# ------------------------------------------------------------------------
> 	if (method=="INVITE" && client_nat_test("3")) {
> 		setflag(7);
> 		record_route_preset("212.212.212.212:5060;nat=yes");
> 	} else if (method!="REGISTER") {
> 		record_route_preset("212.212.212.212:5060");
> 	};
> 
> 	# ------------------------------------------------------------------------
> 	# Media Proxy Tear Down
> 	# ------------------------------------------------------------------------
> 	if (method=="BYE" || method=="CANCEL") {
> 		setflag(1);
> 		end_media_session();
> 	};
> 
> 	# ------------------------------------------------------------------------
> 	# Message Handler Logic
> 	# ------------------------------------------------------------------------
> 	if (loose_route()) {
> 		append_hf("P-hint: Loose Routed\r\n");
> 		if (has_totag() && (method=="INVITE" || method=="ACK")) {
> 			if (isflagset(7) || search("^Route:.*;nat=yes")) {
> 				setflag(6);
> 				use_media_proxy();
> 			};
> 		};
> 		route(1);
> 		break;
> 	};
> 
> 	if (uri!=myself) {
> 		append_hf("P-hint: External Destination\r\n");
> 		route(1);
> 		break;
> 	};
> 
> 	if (uri==myself) {
> 		append_hf("P-hint: Local Destination\r\n");
> 		if (method=="ACK") {
> 			setflag(1);
> 			route(9);
> 			break;
> 		} else if (method=="CANCEL") {
> 			route(5);
> 			break;
> 		} else if (method=="INVITE") {
> 			setflag(1);
> 			route(5);
> 			break;
> 		} else if (method=="REFER") {
> 			route(5);
> 			break;
> 		} else if (method=="REGISTER") {
> 			setflag(1);
> 			route(3);
> 			break;
> 		} else if (method=="OPTIONS") {
> 			options_reply();
> 			break;
> 		};
> 
> 		lookup("aliases");
> 		if (uri!=myself) {
> 			append_hf("P-hint: Alias External Destination\r\n");
> 			route(1);
> 			break;
> 		};
> 
> 		if (!lookup("location")) {
> 			sl_send_reply("404", "User Not Found");
> 			break;
> 		};
> 	};
> 
> 	append_hf("P-hint: USRLOC Applied\r\n");
> 	route(1);
> }
> 
> route[1] {
>         # ------------------------------------------------------------------------
> 	# Default Message Handler
>         # ------------------------------------------------------------------------
> 	remove_hf("Proxy-Authorization");
> 	t_on_reply("1");
> 	if (!t_relay()) {
> 		if (method=="INVITE" || method=="ACK") {
> 			end_media_session();
> 		};
> 		sl_reply_error();
> 	};
> }
> 
> route[2] {
> 	# ------------------------------------------------------------------------
> 	# Call Forwarding Reply Route Handler
> 	# ------------------------------------------------------------------------
> 
> 	if (!lookup("location")) {
> 		rewritehost("213.213.213.213"); # PSTN GW IP ADDRESSS GOES HERE
> 	} else {
> 		route(8);
> 		route(1);
> 	};
> }
> 
> route[3] {
> 	# ------------------------------------------------------------------------
> 	# REGISTER Message Handler
> 	# ------------------------------------------------------------------------
> 
> 	# ------------------------------------------------------------------------
> 	# NAT Test Section
> 	# ------------------------------------------------------------------------
> 	if (!search("^Contact:\ +\*") && client_nat_test("7")) {
> 		setflag(6);
> 		fix_nated_register();
> 		force_rport();
> 	};
> 
> 		if (!www_authorize("", "subscriber")) {
> 			www_challenge("", "1");
> 			break;
> 		};
> 
> 		consume_credentials();
> 
> 		add_rcv_param();
> 		append_time();
> 
> 		if (!save("location")) {
> 			sl_reply_error();
> 			break;
> 		};
> 	
> }
> 
> route[5] {
> 	# ------------------------------------------------------------------------
> 	# NAT Test
> 	# ------------------------------------------------------------------------
> 	if (client_nat_test("3")) {
> 		setflag(7);
> 		force_rport();
> 		fix_nated_contact();
> 	};
> 
> 	# ------------------------------------------------------------------------
> 	# Aliases Section
> 	# ------------------------------------------------------------------------
> 	lookup("aliases");
> 	if (uri!=myself) {
> 		append_hf("P-hint: Alias External Destination\r\n");
> 		route(1);
> 		break;
> 	};
> 
> 	# ------------------------------------------------------------------------
> 	# Load ACL Section
> 	# ------------------------------------------------------------------------
> 	if ((method=="INVITE") && (uri=~"^sip:9[0-9]*@")) {
> 
> 		if (!allow_trusted()) {
> 
> 			if (!proxy_authorize("", "subscriber")) {
> 				proxy_challenge("", "1");
> 				break;
> 			};
> 
> 			if (is_from_local() || is_uri_host_local()) {
> 
> 				if (is_user_in("credentials", "int")) {
> 					setflag(29);
> 				};
> 
> 			};
> 
> 			consume_credentials();
> 
> 		};
> 
> 		# ----------------------------------------------------------------
> 		# 9 International Call Test
> 		# ----------------------------------------------------------------
> 		if (uri=~"^sip:9[0-9]*@") {
> 			if (isflagset(29)) {
>        				route(7);
> 			} else {
> 				acc_db_request("403 - Int Disabled", "acc");
> 				sl_send_reply("403", "Service Unavailable");
> 			};
> 			break;
> 		};
> 	};
> 
> 	# ------------------------------------------------------------------------
> 	# Call Routing Section
> 	# ------------------------------------------------------------------------
> 	if (!lookup("location")) {
> 		if (method=="CANCEL") {
> 			route(1);
> 			break;
> 		};
> 
> 	};
> 
> 	# ------------------------------------------------------------------------
> 	# CANCEL message branch
> 	# ------------------------------------------------------------------------
> 	if (method=="CANCEL") {
> 		route(1);
> 		break;
> 	};
> 
> 	# ------------------------------------------------------------------------
> 	# NAT Test
> 	# ------------------------------------------------------------------------
> 	if (isflagset(6) && !isflagset(7)) {
> 		force_rport();
> 		fix_nated_contact();
> 	};
> 
> 	# ------------------------------------------------------------------------
> 	# Final Call Routing Decision
> 	# ------------------------------------------------------------------------
> 		route(8);
> 		t_on_failure("1");
> 
> 	route(1);
> }
> 
> 
> route[7] {
> 
> 	# ------------------------------------------------------------------------
> 	# PSTN Handler
> 	# ------------------------------------------------------------------------
> 
> 	rewritehost("195.135.204.85");	# PSTN GW IP ADDRESSS GOES HERE
> 
> 	if (method!="CANCEL") {
> 
> 		if (!proxy_authorize("", "subscriber")) {
> 			proxy_challenge("", "1");
> 			break;
> 		};
> 
> 		consume_credentials();
> 		route(8);
> 	};
> 
> 	t_on_failure("1");
> 	route(1);
> }
> 
> route[8] {
> 
> 	# ------------------------------------------------------------------------
> 	# RTP Proxy Enabler
> 	# ------------------------------------------------------------------------
> 
> 	if (isflagset(6) || isflagset(7)) {
> 		use_media_proxy();
> 	};
> }
> 
> route[9] {
> 
> 	# ------------------------------------------------------------------------
> 	# ACK Handler
> 	# ------------------------------------------------------------------------
> 	if (method=="ACK") {
> 		t_relay();
> 		return;
> 	};
> 
> 	# ------------------------------------------------------------------------
> 	# Aliases Section
> 	# ------------------------------------------------------------------------
> 	lookup("aliases");
> 	if (uri!=myself) {
> 		route(1);
> 		break;
> 	};
> 
> 	lookup("location");
> 
> 	route(1);
> }
> 
> onreply_route[1] {
> 
>         # Not all 2xx messages have a content body so here we
>         # make sure our Content-Length > 0 to avoid a parse error
> 
> 
> 	if (isflagset(6) || isflagset(7) || search("212.212.212.212")) {
> 
> 		if (status=~"(180)|(183)|2[0-9][0-9]") {
> 
> 			if (!search("^Content-Length:\ +0")) {
> 				append_hf("P-hint: NATed Reply\r\n");
> 				use_media_proxy();	
> 			};
> 		};
> 	};
> 
> 	if (client_nat_test("1")) {
> 		fix_nated_contact();
> 	};
> } 
> 
> failure_route[1] {
> 
> 	if (t_check_status("487")) {
> 		break;
> 	};
> 
> 	if (t_check_status("5[0-9]{2}")) {
> 		if (t_check_status("500")) {
> 			acc_db_request("500 - PSTN GW Says Internal Server Error", "acc");
> 		} else if (t_check_status("501")) {
> 			acc_db_request("501 - PSTN GW Says Not Implemented", "acc");
> 		} else if (t_check_status("502")) {
> 			acc_db_request("502 - PSTN GW Says Bad Gateway", "acc");
> 		} else if (t_check_status("503")) {
> 			acc_db_request("503 - PSTN GW Says Service Unavailable", "acc");
>                 } else if (t_check_status("504")) {
>                         acc_db_request("504 - PSTN GW Says Server Time Out", "acc");
> 		};
> 	};
> 
> 	if (isflagset(27) && t_check_status("408")) {
> 
> 		# forward no answer is flag 27
> 		if (avp_pushto("$ruri", "s:fwdnoanswer")) {
> 			append_hf("P-hint: Forward No Answer\r\n");
> 			avp_delete("s:fwdnoanswer");
> 			resetflag(27);
> 			route(2);
> 			break;
> 		};
> 	};
> 
> 	end_media_session();
> 	};
> }
> 
> help me please, my head is burning :(
> 
> -----Original Message-----
> From: Andrei Pelinescu-Onciul <andrei at iptel.org>
> To: deviator <deviator at inbox.ru>
> Date: Thu, 3 Nov 2005 14:45:21 +0100
> Subject: Re: [Serusers] Strange problem - SIP-->PSTN - 40 sec calls duration
> 
> > 
> > On Nov 03, 2005 at 09:50, deviator <deviator at inbox.ru> wrote:
> > > Thanks for reply!
> > > 
> > > This is part of my openser.cfg
> > [...]
> > > 	if (uri==myself) {
> > > 		append_hf("P-hint: Local Destination\r\n");
> > > 		if (method=="ACK") {
> > > 			setflag(1);
> > > 			route(9);
> >             ^^^^^^^^ - you haven't sent route[9], check it to see if you
> >             drop the ACKs in there (you should treat them almost the
> >             same as the invites)
> > > 			break;
> > > 		} else if (method=="CANCEL") {
> > > 			route(5);
> > > 			break;
> > > 		} else if (method=="INVITE") {
> > > 			setflag(1);
> > > 			route(5);
> > > 			break;
> > 
> > [...]
> > > 
> > > I dont think that my UA is broken, same results have all my ipphones and softphones :(
> > 
> > The ACK was not dropped because the UA was broken, but nevertheless you
> >  the UA didn't properly handle record-routing.
> > 
> > 
> > Andrei
> > 




More information about the sr-users mailing list