Direct RTP same LAN, via Asterisk remote LANs

Hello everyone,
I was looking all over the web for a solution to this and found nothing so far.

I have 1 remote location named A with 5 nat’ed IP Phones and no local asterisk and another remote location named B with 7 nat’ed IP Phones, no local asterisk machine. All 12 IP Phones are registered to an Asterisk server running at a 3rd location C with public IP address, no firewall and enough BW to handle many calls.

A’s IP Phones are numbered 9001 to 9005.
B’s IP Phones are numbered 8001 to 8007.

I want all RTP traffic from extensions in the same location to travel directly between SIP endpoints rather than going to asterisk (remote bridging from asterisk’s view) and all RTP traffic between locations A and B to go thru asterisk (local bridging from asterisk’s view).

Asterisk version is: 1.8.10.1

-I have set up my Dial command for every extension as follows :
exten => 9001,1,Dial(SIP/${EXTEN},30,C) , so no t, T, w, W options

-I have configured all sip peers as follows:

[9001]
type=friend
host=dynamic
nat=yes
directmedia=no
;directrtpsetup=yes

I have made some test calls with directmedia=yes (or no directmedia parameter), and calls between extensions in the same location are OK, RTP goes peer to peer. However, calls between A and B locations fails, as asterisk sends a re invite with the private IP address of the SIP remote peers.
If I set directmedia=no, all RTP traffic goes thru the asterisk (locally bridged) regarless of whether the SIP endpoint are on the same LAN or not.

Since asterisk can determine whether the SIP peers are behind the same NAT by checking the source IP address and contact address, how should I make my configuration?

kind regards, Pablo.

Feature requests should be submitted to the developer mailing list.

However, I think the fundamental problem here is with the phones or the remote NAT routers. Asterisk should not be seeing private addresses in the SDP.

I’ve been looking all afternoon for an answer to this question but have run into a dead end as well. My scenario is exactly the same, I only want Asterisk to use reINVITE/directmedia when the external IP of the SIP endpoints are the same (meaning they are behind the same NAT device) and then bridge everything through itself if the external IP’s are different.

A work around I thought of would be to keep a database on the server with locations assigned to each endpoint (or external IP) and then query the database in the dialplan before dialing the endpoint. If the end points are in a different location then add w to the dial options to make asterisk bridge the call, otherwise let directmedia work as per normal. Ideally you could use the endpoints IP address in SIP PEERS but I’m not sure how you would get that into the dialplan without using realtime and ODBC.

Is there anyone that knows Asterisk a little more deeply than myself that can see a solution?

Asterisk doesn’t know, for certain, that the addresses really are behind the same NAT, and if the device is NAT aware, won’t have any idea as to what the local addresses are.

The right way is either a VPN or it might be posisble to have a PABX in each site.

I can completely understand why Asterisk is designed this way, what I’m after is a way to override this if possible.

The use case I’m trying to solve is a basic provider scenario where all of the SIP endpoints are behind customer owned NAT (which is why VPN is not an option). Being able to route interoffice calls over the local network would save a heap of bandwidth since Asterisk no longer has to relay two streams of audio over a WAN link. It would certainly be a lot more efficient than deploying a small PBX per office in terms of equiptment cost, maintainence etc.

I’ll have a look at the Asterisk source but it’s probably out of my league to code this. If I could manage it using the dial plan I’d be a very happy man :smiley:

Thanks again for the explanation