Merge pull request #8391 from hardliner66/fix_econ

Allow econ to succeed, even if ipv6 econ fails to bind to socket
This commit is contained in:
heinrich5991 2024-05-21 19:20:14 +00:00 committed by GitHub
commit 7c4d3a5978
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1846,7 +1846,7 @@ NETSOCKET net_tcp_create(NETADDR bindaddr)
NETSOCKET sock = (NETSOCKET_INTERNAL *)malloc(sizeof(*sock)); NETSOCKET sock = (NETSOCKET_INTERNAL *)malloc(sizeof(*sock));
*sock = invalid_socket; *sock = invalid_socket;
NETADDR tmpbindaddr = bindaddr; NETADDR tmpbindaddr = bindaddr;
int socket = -1; int socket4 = -1;
if(bindaddr.type & NETTYPE_IPV4) if(bindaddr.type & NETTYPE_IPV4)
{ {
@ -1855,14 +1855,15 @@ NETSOCKET net_tcp_create(NETADDR bindaddr)
/* bind, we should check for error */ /* bind, we should check for error */
tmpbindaddr.type = NETTYPE_IPV4; tmpbindaddr.type = NETTYPE_IPV4;
netaddr_to_sockaddr_in(&tmpbindaddr, &addr); netaddr_to_sockaddr_in(&tmpbindaddr, &addr);
socket = priv_net_create_socket(AF_INET, SOCK_STREAM, (struct sockaddr *)&addr, sizeof(addr)); socket4 = priv_net_create_socket(AF_INET, SOCK_STREAM, (struct sockaddr *)&addr, sizeof(addr));
if(socket >= 0) if(socket4 >= 0)
{ {
sock->type |= NETTYPE_IPV4; sock->type |= NETTYPE_IPV4;
sock->ipv4sock = socket; sock->ipv4sock = socket4;
} }
} }
int socket6 = -1;
if(bindaddr.type & NETTYPE_IPV6) if(bindaddr.type & NETTYPE_IPV6)
{ {
struct sockaddr_in6 addr; struct sockaddr_in6 addr;
@ -1870,15 +1871,15 @@ NETSOCKET net_tcp_create(NETADDR bindaddr)
/* bind, we should check for error */ /* bind, we should check for error */
tmpbindaddr.type = NETTYPE_IPV6; tmpbindaddr.type = NETTYPE_IPV6;
netaddr_to_sockaddr_in6(&tmpbindaddr, &addr); netaddr_to_sockaddr_in6(&tmpbindaddr, &addr);
socket = priv_net_create_socket(AF_INET6, SOCK_STREAM, (struct sockaddr *)&addr, sizeof(addr)); socket6 = priv_net_create_socket(AF_INET6, SOCK_STREAM, (struct sockaddr *)&addr, sizeof(addr));
if(socket >= 0) if(socket6 >= 0)
{ {
sock->type |= NETTYPE_IPV6; sock->type |= NETTYPE_IPV6;
sock->ipv6sock = socket; sock->ipv6sock = socket6;
} }
} }
if(socket < 0) if(socket4 < 0 && socket6 < 0)
{ {
free(sock); free(sock);
sock = nullptr; sock = nullptr;