[asterisk-dev] stun support in asterisk ? (and a related hack for rtp.c)

Philippe Sultan philippe.sultan at gmail.com
Wed Jul 11 07:28:05 CDT 2007


Hi Luigi,

STUN is used in Asterisk to communicate with GoogleTalk clients so you
might be interested in checking the corresponding pieces of code in
chan_gtalk.c.

Also, here is a bug related to NAT traversal + STUN handling in the
Gtalk channel : http://bugs.digium.com/view.php?id=8193
Basically, the problem here was that Asterisk was sending STUN
requests to the IP address advertised by the GoogleTalk client,  which
was a non routable IP address if the client was behind a NAT box. Of
course, the IP address being non routable, STUN requests never reached
the GoogleTalk client.

Asterisk was fixed to send STUN requests back to the source IP of the
received RTP stream (and therefore ignore the IP address advertized by
the GoogleTalk client), the same way you did it in your patch.

Hope this helps,

Philippe

On 7/11/07, Luigi Rizzo <rizzo at icir.org> wrote:
> Hi,
> i find myself more and more often behind a NAT box, with asterisk
> unable to receive the incoming RTP stream because it sends out
> the wrong IP/PORT in the sdp message.
>
> So i was wondering if there is any work in progress for an stun
> client (or other nat traversal trick, e.g. olle was suggesting ICE,
> whatever it is :) in asterisk.  I see there are bits of code in
> rtp.c but not clear on what they do.
>
> As a temporary workaround, I implemented a simple hack inspired by
> an idea from Olle at
>     http://www.voip-info.org/wiki/view/Asterisk+SIP+chan_sip2
> where the remote endpoint of the rtp is rewritten with the source
> address from incoming RTP packets. This way, if asterisk receives
> the audio stream, can reply back to the sender even if sdp had
> a bogus address.
>
> Of course this needs to be polished,
> possibly applied to RTCP, and enabled through an rtp.conf option ,
> but maybe it is of some interest for others as well ?
>
> Index: main/rtp.c
> ===================================================================
> --- main/rtp.c  (revision 72803)
> +++ main/rtp.c  (working copy)
> @@ -1237,6 +1237,17 @@
>         res = recvfrom(rtp->s, rtp->rawdata + AST_FRIENDLY_OFFSET, sizeof(rtp->rawdata) - AST_FRIENDLY_OFFSET,
>                                         0, (struct sockaddr *)&sin, &len);
>
> +       if (rtp->them.sin_addr.s_addr != sin.sin_addr.s_addr) {
> +               ast_log(LOG_WARNING, "RTP Read addr mismatch: got 0x%lx should be 0x%lx\n",
> +                       ntohl(sin.sin_addr.s_addr), ntohl(rtp->them.sin_addr.s_addr));
> +               rtp->them.sin_addr.s_addr = sin.sin_addr.s_addr;
> +       }
> +       if (rtp->them.sin_port != sin.sin_port) {
> +               ast_log(LOG_WARNING, "RTP Read port mismatch: got 0x%x should be 0x%x\n",
> +                       ntohs(sin.sin_port), ntohs(rtp->them.sin_port));
> +               rtp->them.sin_port = sin.sin_port;
> +       }
> +
>         rtpheader = (unsigned int *)(rtp->rawdata + AST_FRIENDLY_OFFSET);
>         if (res < 0) {
>                 if (errno == EBADF)
>
>
> cheers
> luigi
>
> _______________________________________________
> --Bandwidth and Colocation Provided by http://www.api-digital.com--
>
> asterisk-dev mailing list
> To UNSUBSCRIBE or update options visit:
>    http://lists.digium.com/mailman/listinfo/asterisk-dev
>


-- 
Philippe Sultan



More information about the asterisk-dev mailing list