OpenSER And Mediaproxy

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:


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:


Created by: openser, Last modification: Tue 20 of Jun, 2006 (15:53 UTC)
Please update this page with new information, just login and click on the "Edit" or "Discussion" tab. Get a free login here: Register Thanks! - Find us on Google+