]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
channels/chan_sip.c: use binding IP address for outgoing TCP SIP connections
authorThierry Magnien <thierry.magnien@gmail.com>
Wed, 26 Apr 2017 12:58:44 +0000 (14:58 +0200)
committerThierry Magnien <thierry.magnien@gmail.com>
Tue, 2 May 2017 10:57:54 +0000 (05:57 -0500)
For outgoing TCP connections, Asterisk uses the first IP address of the
interface instead of the IP address we asked him to bind to.

ASTERISK-26922 #close
Reported-by: Ksenia
Change-Id: I43c71ca89211dbf1838e5bcdb9be8d06d98e54eb

channels/chan_sip.c

index ea77aff14c5a310dff94bf0550df2aeb46e22f94..2c5d3c31409be565bf758d39166d791eabdf7249 100644 (file)
@@ -29224,6 +29224,17 @@ static int sip_prepare_socket(struct sip_pvt *p)
                }
        }
 
+       /* If a bind address has been specified, use it */
+       if ((s->type == AST_TRANSPORT_TLS) && !ast_sockaddr_isnull(&sip_tls_desc.local_address)) {
+               ca->local_address = sip_tls_desc.local_address;
+       }
+       else if ((s->type == AST_TRANSPORT_TCP) && !ast_sockaddr_isnull(&sip_tcp_desc.local_address)) {
+               ca->local_address = sip_tcp_desc.local_address;
+       }
+       /* Reset tcp source port to zero to let system pick a random one */
+       if (!ast_sockaddr_isnull(&ca->local_address)) {
+               ast_sockaddr_set_port(&ca->local_address, 0);
+       }
        /* Create a client connection for address, this does not start the connection, just sets it up. */
        if (!(s->tcptls_session = ast_tcptls_client_create(ca))) {
                goto create_tcptls_session_fail;