[Serusers] need help to route calls to PSTN

harry gaillac gaillacharry at yahoo.fr
Sun Jun 5 16:34:43 CEST 2005


Hello ser users,

I configure ser and asterisk on the same box (+nat).
I can send and receive calls from my domain or other
domains however i can't send uri to pstn :

ser listen on port 5060 / public ip
asterisk listen 5040 / private address 192.168.0.50

When I dial a number to pstn phone send
sip:1234 at mydomain:5060 but ser don't rewrite host port
according to ser.cfg .

What's wrong ? Why ?
# $Id: ser.cfg,v 1.27 2005/03/10 14:16:25 andrei Exp $
#
# simple quick-start config script
#

# ----------- global configuration parameters
------------------------

debug=3         # debug level (cmd line: -dddddddddd)
fork=yes
log_stderror=no	# (cmd line: -E)
#memlog=5 # memory debug log level
#log_facility=LOG_LOCAL0 # sets the facility used for
logging (see syslog(3))

/* Uncomment these lines to enter debugging mode 
#fork=no
#log_stderror=yes
*/

check_via=no	# (cmd. line: -v)
dns=no           # (cmd. line: -r)
rev_dns=no      # (cmd. line: -R)
port=5060
children=4
fifo="/tmp/ser_fifo"
user=root
group=ser
fifo_user=root # owner of the ser fifo
fifo_group=ser
fifo_mode=0660 # fifo's permissions
#disable_core=yes #disables core dumping
#open_fd_limit=1024 # sets the open file descriptors
limit
#mhomed=yes  # usefull for multihomed hosts, small
performance penalty
#disable_tcp=yes 
#tcp_accept_aliases=yes # accepts the tcp alias via
option (see NEWS)
listen=80.119.9.253
#

# ------------------ module loading
----------------------------------

loadmodule "/usr/lib/ser/modules/mysql.so"
loadmodule "/usr/lib/ser/modules/sl.so"
loadmodule "/usr/lib/ser/modules/tm.so"
loadmodule "/usr/lib/ser/modules/rr.so"
loadmodule "/usr/lib/ser/modules/maxfwd.so"
loadmodule "/usr/lib/ser/modules/usrloc.so"
loadmodule "/usr/lib/ser/modules/registrar.so"
loadmodule "/usr/lib/ser/modules/uri.so"
loadmodule "/usr/lib/ser/modules/nathelper.so"
loadmodule "/usr/lib/ser/modules/auth.so"
loadmodule "/usr/lib/ser/modules/auth_db.so"
loadmodule "/usr/lib/ser/modules/textops.so"
loadmodule "/usr/lib/ser/modules/permissions.so"
loadmodule "/usr/lib/ser/modules/group.so"
loadmodule "/usr/lib/ser/modules/domain.so"
loadmodule "/usr/lib/ser/modules/avpops.so"

# ----------------- setting module-specific parameters
---------------

#  -- usrloc params--
modparam("usrloc", "db_mode", 2)

#  -- autdb_params--
modparam("auth_db", "calculate_ha1", yes)
modparam("auth_db", "password_column", "password")

# -- rr params --
# add value to ;lr param to make some broken UAs happy
modparam("rr", "enable_full_lr", 1)

# -- nathelper params --
modparam("nathelper", "natping_interval", 30)
modparam("nathelper", "ping_nated_only", 1)

# -- registrar params --
modparam("registrar", "nat_flag", 6)

# -- tm params --
modparam("tm", "fr_inv_timer", 27)
modparam("tm", "fr_inv_timer_avp", "inv_timeout")

# --domain params --
modparam("domain", "db_mode", 1)   # Use caching

# -- permissions params --
modparam("permissions", "db_url",
"mysql://ser:heslo@localhost/ser")
modparam("permissions", "db_mode", 1)
modparam("permissions", "trusted_table", "trusted")
modparam("permissions", "default_deny_file",
"/etc/ser/permissions.deny")
modparam("permissions", "default_allow_file",
"/etc/ser/permissions.allow")

# -------------------------  request routing logic
-------------------


# main routing logic

route{

	# initial sanity checks -- messages with
	# max_forwards==0, or excessively long requests
	if (!mf_process_maxfwd_header("10")) {
		sl_send_reply("483","Too Many Hops");
		break;
	};
	if (msg:len >=  max_len ) {
		sl_send_reply("513", "Message too big");
		break;
	};
	
	# we record-route all messages -- to make sure that
	# subsequent messages will go through our proxy;
that's
	# particularly good if upstream and downstream
entities
	# use different transport protocol
	if (!method=="REGISTER") { 
		record_route();	
	};
	if (method=="ACK" || method=="BYE") {
		unforce_rtp_proxy();
	};

	# subsequent messages withing a dialog should take
the
	# path determined by record-routing
	if (loose_route()) {
		if (has_totag() && method=="INVITE" ||
method=="ACK") {
			if (nat_uac_test("19")) {
				setflag(6);
				force_rport();
				fix_nated_contact();
			};
			force_rtp_proxy("l");
		};	
		route(1);
		break;
	};

	# Requests to others domains
	if (!is_from_local()) {
		# mark routing logic in request
		append_hf("P-hint: outbound\r\n"); 
		route(1);
		break;
	};

	# if the request is for other domain use UsrLoc
	# (in case, it does not work, use the following
command
	# with proper names and addresses in it)
	if (is_from_local()) {

		if (method=="CANCEL") {
			route(3);
			break;
		} else if (method=="INVITE") {
			route(3);
			break;
		} else if (method=="REGISTER") {
			route(2);
			break;
		};

	};
}

route[1] { 
	###########################
	# Default Message Handler #
	###########################

	t_on_reply("1");

	# send it out now; use stateful forwarding as it
works reliably
	# even for UDP2TCP
	if (!t_relay()) {
		if (method=="INVITE" && isflagset(6)) {
			unforce_rtp_proxy();
		};

		sl_reply_error();
	};
}


route[2] {
	############################
	# Register Message Handler #
	############################

	if (!search("^Contact:") && nat_uac_test("19")) {
		setflag(6);
		fix_nated_register();
		force_rport();
	};

	if (!www_authorize("nxs.yi.org", "subscriber")) {
        	www_challenge("nxs.yi.org", "0");
		sl_send_reply("401", "Unauthorized");
                break;
	};

	if (!save("location")) {
		sl_reply_error();
		break;
	};
}

route[3] {
	#############################
	# CANCEL and INVITE handler #
	#############################

	if (nat_uac_test("19")) {
		setflag(6);
	};
	
        if (isflagset(6)) {
                force_rport();
                fix_nated_contact();
                force_rtp_proxy();
        };

	if (!is_from_local()) {
		route(1);
		break;
	};
	
	if (src_ip==192.168.0.50 && allow_trusted()) {
		route(4);
		route(1); 
	} else if (src_ip==192.168.0.50 && !allow_trusted())
{
			if (!proxy_authorize("","subscriber")) {
				proxy_challenge("","0");
				sl_send_reply("403", "Forbidden");
				break;
			};
		break;
	};

	if (uri=~"sip:^1013 at .*$" || uri=~"sip:^[0-9]{10}@.*$"
|| uri=~"sip:^06[0-9]{8}@.*$") {
		route(5); 
		route(1); 
		break;
	};

	# native SIP destinations are handled using our
USRLOC DB
	lookup("aliases");
	if (!lookup("location")) {
		sl_send_reply("404", "User Not Found");
		break;
	};
	route(1);
	break;
}

route[4] {
	##########################
	# Incoming PSTN Handler  #
	##########################
	if (uri=~"^[0-9]{10}@.*$") { 
		strip(8);
		break;
	};

}

route[5] {
        ##########################
        # Outgoing PSTN Handler  #
        ##########################

	if (uri=~"sip:^1013 at .*$") {
		if (!is_user_in("Request-URI", "local")) { 
			sl_send_reply("403", "Forbidden");
			break;
		};
	
	} else if (uri=~"sip:^[0-9]{2}@.*$") {
                if (!is_user_in("Request-URI",
"local")) {
                        sl_send_reply("403",
"Forbidden");
                        break;
		};

        } else if (uri=~"sip:^06[0-9]{8}@.*$") {
                if (!is_user_in("Request-URI", "cell
phone")) {
                        sl_send_reply("403",
"Forbidden");
                        break;
		};
	rewritehostport("192.168.50:5040");
	};		
}


onreply_route[1] {
	if (isflagset(6) && status=~"(180) | (183) |
2[0-9][0-9]") {
		force_rtp_proxy();
	};
	if (nat_uac_test("1")) {
		fix_nated_contact();
	};
}





	

	
		
_____________________________________________________________________________ 
Découvrez le nouveau Yahoo! Mail : 1 Go d'espace de stockage pour vos mails, photos et vidéos ! 
Créez votre Yahoo! Mail sur http://fr.mail.yahoo.com




More information about the sr-users mailing list