From f40df55af2f50789ca4a8b89a213f7323b1932f2 Mon Sep 17 00:00:00 2001 From: Daniel-Constantin Mierla Date: Wed, 11 Sep 2019 12:42:58 +0200 Subject: [PATCH] core: tcp - set default local socket for tls when lookup fails - GH #2028 --- src/core/tcp_main.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/core/tcp_main.c b/src/core/tcp_main.c index 668103e676d..e86fc872a86 100644 --- a/src/core/tcp_main.c +++ b/src/core/tcp_main.c @@ -1373,18 +1373,31 @@ inline static int tcp_do_connect( union sockaddr_union* server, su2ip_addr(&ip, &my_name); find_socket: #ifdef USE_TLS - if (unlikely(type==PROTO_TLS)) + if (unlikely(type==PROTO_TLS)) { *res_si=find_si(&ip, 0, PROTO_TLS); - else -#endif + } else { *res_si=find_si(&ip, 0, PROTO_TCP); - + } +#else + *res_si=find_si(&ip, 0, PROTO_TCP); +#endif + if (unlikely(*res_si==0)){ LM_WARN("%s: could not find corresponding" " listening socket for %s, using default...\n", su2a(server, sizeof(*server)), ip_addr2a(&ip)); +#ifdef USE_TLS + if (unlikely(type==PROTO_TLS)) { + if (server->s.sa_family==AF_INET) *res_si=sendipv4_tls; + else *res_si=sendipv6_tls; + } else { + if (server->s.sa_family==AF_INET) *res_si=sendipv4_tcp; + else *res_si=sendipv6_tcp; + } +#else if (server->s.sa_family==AF_INET) *res_si=sendipv4_tcp; else *res_si=sendipv6_tcp; +#endif } *res_local_addr=*from; return s;