Index: main/tcptls.c =================================================================== --- main/tcptls.c (Revision 280623) +++ main/tcptls.c (Arbeitskopie) @@ -401,6 +401,12 @@ originate from the desired address */ if (desc->local_address.sin_family != 0) { setsockopt(desc->accept_fd, SOL_SOCKET, SO_REUSEADDR, &x, sizeof(x)); + if (setsockopt(desc->accept_fd, SOL_SOCKET, SO_REUSEADDR, &x, sizeof(x)) ) { + ast_log(LOG_ERROR, "Failed to set socket option SO_REUSEADDR: %s\n",strerror(errno)); + } + if (setsockopt(desc->accept_fd, SOL_SOCKET, SO_KEEPALIVE, &x, sizeof(x)) ) { + ast_log(LOG_ERROR, "Failed to set socket option SO_KEEPALIVE: %s\n",strerror(errno)); + } if (bind(desc->accept_fd, (struct sockaddr *) &desc->local_address, sizeof(desc->local_address))) { ast_log(LOG_ERROR, "Unable to bind %s to %s:%d: %s\n", desc->name, @@ -466,6 +472,12 @@ } setsockopt(desc->accept_fd, SOL_SOCKET, SO_REUSEADDR, &x, sizeof(x)); + if (setsockopt(desc->accept_fd, SOL_SOCKET, SO_REUSEADDR, &x, sizeof(x)) ) { + ast_log(LOG_ERROR, "Failed to set socket option SO_REUSEADDR: %s\n",strerror(errno)); + } + if (setsockopt(desc->accept_fd, SOL_SOCKET, SO_KEEPALIVE, &x, sizeof(x)) ) { + ast_log(LOG_ERROR, "Failed to set socket option SO_KEEPALIVE: %s\n",strerror(errno)); + } if (bind(desc->accept_fd, (struct sockaddr *) &desc->local_address, sizeof(desc->local_address))) { ast_log(LOG_ERROR, "Unable to bind %s to %s:%d: %s\n", desc->name, Index: channels/chan_sip.c =================================================================== --- channels/chan_sip.c (Revision 280623) +++ channels/chan_sip.c (Arbeitskopie) @@ -12324,6 +12324,32 @@ struct sockaddr_in oldsin, testsin; + /* check if we have already a tcp connection */ + if(peer->addr.sin_addr.s_addr && peer->socket.type != SIP_TRANSPORT_UDP){ + /* if the remote address is not me, close this tcp helper thread */ + if(peer->addr.sin_addr.s_addr != pvt->recv.sin_addr.s_addr || + peer->addr.sin_port != pvt->recv.sin_port + ) { + if (peer->socket.tcptls_session) { + struct sip_threadinfo *th; + + struct sip_threadinfo tmp = { + .tcptls_session = peer->socket.tcptls_session, + }; + + /* search for the tcp_helper_thread */ + th = ao2_t_find(threadt, &tmp, OBJ_POINTER, "ao2_find, getting sip_threadinfo in tcp helper thread"); + if(th){ + /* stopping the thread also closes socket an destroy it */ + pthread_t thread = th->threadid; + th->stop = 1; + pthread_kill(thread, SIGURG); + pthread_join(thread, NULL); + } + } + } + } /* end; search for older tcp connection */ + ast_copy_string(contact, get_header(req, "Contact"), sizeof(contact)); if (ast_strlen_zero(expires)) { /* No expires header, try look in Contact: */