[asterisk-bugs] [Asterisk 0011518]: Asterisk TRUNK version - problem with NAT, ignoring localnet, ..

noreply at bugs.digium.com noreply at bugs.digium.com
Tue Dec 11 15:55:46 CST 2007


The following issue has been ASSIGNED. 
====================================================================== 
http://bugs.digium.com/view.php?id=11518 
====================================================================== 
Reported By:                wilder
Assigned To:                qwell
====================================================================== 
Project:                    Asterisk
Issue ID:                   11518
Category:                   Channels/chan_sip/General
Reproducibility:            always
Severity:                   major
Priority:                   normal
Status:                     assigned
Asterisk Version:            SVN 
SVN Branch (only for SVN checkouts, not tarball releases):  trunk 
SVN Revision (number only!): 92201 
Disclaimer on File?:        N/A 
Request Review:              
====================================================================== 
Date Submitted:             12-11-2007 13:06 CST
Last Modified:              12-11-2007 15:55 CST
====================================================================== 
Summary:                    Asterisk TRUNK version - problem with NAT, ignoring
localnet, ..
Description: 
This bug affects only Asterisk TRUNK, SIP/TCP-TLS and related projects (the
latest stable Asterisk 1.4.15 and Asterisk 1.2.x are not affected).

The problem is appeared when my SIP client with the IP address from
"localnet"
subnet is connecting to my Asterisk server that is also in the "localnet"
subnet.
In this situation Asterisk ignores "localnet" parameter and remaps
internal IP addresses in the SIP frames with "externhost" which is
incorrect.
Asterisk 1.4.15 (and lower) does remapping only if the hosts are outside
of localnet subnet.

After hours of debugging/analysing I have revealed the bug in the
function
ast_sip_ouraddrfor (in chan_sip.c) - yes, this function has been
completely
rewritten since stable 1.4.15:

static void ast_sip_ouraddrfor(struct in_addr *them, struct sockaddr_in
*us)
{
        struct sockaddr_in theirs;
        /* Set want_remap to non-zero if we want to remap 'us' to an
externally
         * reachable IP address and port. This is done if:
         * 1. we have a localaddr list (containing 'internal' addresses
marked
         *    as 'deny', so ast_apply_ha() will return AST_SENSE_DENY on
them, 
         *    and AST_SENSE_ALLOW on 'external' ones);
         * 2. either stunaddr or externip is set, so we know what to use
as the
         *    externally visible address;
         * 3. the remote address, 'them', is external;
         * 4. the address returned by ast_ouraddrfor() is 'internal'
+(AST_SENSE_DENY
         *    when passed to ast_apply_ha() so it does need to be
remapped.
         *    This fourth condition is checked later.
         */
        int want_remap = localaddr &&
                (externip.sin_addr.s_addr || stunaddr.sin_addr.s_addr) &&
                ast_apply_ha(localaddr, &theirs) == AST_SENSE_ALLOW ;

        *us = internip;         /* starting guess for the internal address
*/
        /* now ask the system what would it use to talk to 'them' */
        ast_ouraddrfor(them, &us->sin_addr);
        theirs.sin_addr = *them;
..
..

as you can see, the variable want_remap is inicialized before setting
theirs.sin_addr variable which is wrong. I only changed the order of the
inicialization: and now it works correctly.
====================================================================== 

---------------------------------------------------------------------- 
 svnbot - 12-11-07 15:55  
---------------------------------------------------------------------- 
Repository: asterisk
Revision: 92421

U   trunk/channels/chan_sip.c

------------------------------------------------------------------------
r92421 | qwell | 2007-12-11 15:55:45 -0600 (Tue, 11 Dec 2007) | 4 lines

We need to set the address we want to match against before we actually do
the match..

Closes issue http://bugs.digium.com/view.php?id=11518.

------------------------------------------------------------------------

http://svn.digium.com/view/asterisk?view=rev&revision=92421 

Issue History 
Date Modified   Username       Field                    Change               
====================================================================== 
12-11-07 15:55  svnbot         Checkin                                      
12-11-07 15:55  svnbot         Note Added: 0075242                          
12-11-07 15:55  svnbot         Status                   new => assigned     
12-11-07 15:55  svnbot         Assigned To               => qwell           
======================================================================




More information about the asterisk-bugs mailing list