[asterisk-dev] NAT traversal always disabled when Asterisk INVITEs peer

Yoann Aubineau yoann.aubineau at wengo.fr
Fri Sep 15 04:28:39 MST 2006


Hi list,

I think I found a nasty bug about NAT traversal. Or I'm definitely
stupid, which is another potential option ;)

When nat=yes is set in sip.conf, it seems that ast_rtp_setnat function
is called accordingly for calls coming INTO Asterisk, but this function
is *not* called ever for calls going OUTSIDE of Asterisk.

Here is the use case:


(( LAN ))    NAT GW                  (( INTERNET ))
            ----+----
                |
+--------+      |                    +------------+
|  peer  |======|====================|  Asterisk  |
+--------+      |                    +------------+
                |
                | -1-
                | --> INVITE from peer to Asterisk
                | <-- RTP sent to peer's *public* IP
		| [OK]
                |
                | -2-
                | <-- INVITE from Asterisk to peer
                | <-- RTP sent to peer's *private* IP, 
                |     thus not routed to the gateway
                | [ERROR!]
                |

The peer has a local IP and is connected to the Internet through a
NAT-enabled gateway. The Asterisk box has a public IP. Nothing but very
common case :)

-1-
When the peer initiate a call to the Asterisk box, everything works
fine: the RTP stream from Asterisk is sent to the peer's public IP.

-2-
When Asterisk initiate a call to the peer (through a SIP proxy onto
which the peer has previously registered), it then sends the RTP stream
to peer's local IP instead of it's public one. Which result in Asterisk
"hearing" the peer, but the pear not "hearing" Asterisk.

I temporarily kinda solved the problem in rtp.c by always enabling NAT
traversal feature (ie. sending RTP frames back to whoever sent to us)
whatever the value of rtp->nat. It now works ok, but it's not a viable
solution for the long term.

I haven't find anything in the bug tracking system nor in the svn
sources. I tried very hard to come with a patch for that problem but
without success. Someone points me to the piece of code involved in that
case ?

Ah, and some useful information:
I use Asterisk 1.2.8 and http://www.pbxfreeware.org/app_changrab.c for
the origination, which in turn calls ast_pbx_outgoing_exten.

1. Is this an actual bug with Asterisk?
2. If yes, has it been already fixed?
3. If not, how could I fix it for you?

Thanks for your help.
Yoann Aubineau



More information about the asterisk-dev mailing list