Upgrade 3CX to v18 and get it hosted free!

OpenSER And Mediaproxy

Author image

This is a basic configuration file for OpenSER to handle NAT traversal using MediaProxy. It was found on the net and reported as working. It is lot of space for improvements, so people using OpenSER and MediaProxy are welcome to contribute.


#  
# sample config file to be used with MediaProxy
#


# --- global parameters
#
listen=udp:sip.example.com:5060
fifo="/tmp/openser_fifo
alias="example.com"
alias="voip.example.com"

# --- load modules
mpath="/usr/local/lib/openser/modules/"
loadmodule "sl.so"
loadmodule "tm.so"
loadmodule "rr.so"
loadmodule "maxfwd.so"
loadmodule "usrloc.so"
loadmodule "registrar.so"
loadmodule "textops.so"
loadmodule "domain.so"
loadmodule "mediaproxy.so"
loadmodule "xlog.so"


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

# mediaproxy
modparam("mediaproxy", "mediaproxy_socket", "/var/run/proxydispatcher.sock")
modparam("mediaproxy", "natping_interval", 60)
modparam("registrar", "nat_flag", 2)

# request routing logic
route 
{
	# sanity checks
	if (!mf_process_maxfwd_header("10")) 
	{
		sl_send_reply("483","Too Many Hops");
		exit;
	}
	if (msg:len >= max_len) 
	{
		sl_send_reply("513", "Message too big");
		exit;
	}

	# apply loose (normal) routing rules
	if(!is_method("REGISTER"))
		if(loose_route())
			route(1);

	# NAT test
	if (client_nat_test("3") && !is_present_hf("Route")) 
	{
		setflag(2); # flag for NAT
		force_rport();
		fix_contact();
		append_hf("P-hint: NAT\r\n"); 
	}

	# outbound routing if not for me
	if (uri != myself) 
	{
		route(1);
		exit;
	}

	# Registration
	if (is_method("REGISTER")) 
	{
		save("location"); # no-auth registration
		exit;
	}

	if (is_method("INVITE"))
	{
		# enable Record-Route
		record_route();

		# Is this to one of our numbers
		if (lookup("location")) 
		{
			append_hf("P-hint: userloc applied\r\n");
		} else {
			sl_send_reply("404","Not found");
		}
	}
	route(1);
}


route[1] 
{
	if (isflagset(2))
	{
		if (is_method("INVITE"))
		{
			t_on_reply("1");
			t_on_failure("1");
			use_media_proxy();
		} else if (is_method("BYE|CANCEL")) {
			end_media_session();
		}
	}

	# send it out now; use stateful forwarding as it works reliably
	# even for UDP2TCP
	if (!t_relay()) 
	{
		sl_reply_error();
	}
	exit;
}

onreply_route[1]
{
	if (status =~ "(183)|(2[0-9][0-9])")
	{
		if (client_nat_test("1"))
		{
			fix_contact();
		}
		use_media_proxy();
	}
}

failure_route[1]
{
	end_media_session();
}

See also:


Article Reviews

Write a Review

Your email address will not be published. Required fields are marked *

Required Field. Minimum 5 characters.

Required Field. Minimum 5 characters, maximum 50.

Required field.There is an error with this field.

Required Field.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

There are no reviews for this article. Be the first one to write a review.

Related Posts:

Get 3CX - Absolutely Free!
Link up your team and customers Phone System Live Chat Video Conferencing

Hosted or Self-managed. Up to 10 users free forever. No credit card. Try risk free.

3CX
A 3CX Account with that email already exists. You will be redirected to the Customer Portal to sign in or reset your password if you've forgotten it.