Enable IP_BIND_ADDRESS_NO_PORT if supported

This commit is contained in:
Alex Xu (Hello71)
2022-05-21 15:21:25 -04:00
parent b733f9d6ac
commit b65ffa6f06
3 changed files with 30 additions and 0 deletions
+17
View File
@@ -2224,6 +2224,23 @@ connection_connect_sockaddr,(connection_t *conn,
tor_socket_strerror(errno));
}
#ifdef IP_BIND_ADDRESS_NO_PORT
static int try_ip_bind_address_no_port = 1;
if (bindaddr && try_ip_bind_address_no_port &&
setsockopt(s, SOL_IP, IP_BIND_ADDRESS_NO_PORT, &(int){1}, sizeof(int))) {
if (errno == EINVAL) {
log_notice(LD_NET, "Tor was built with support for "
"IP_BIND_ADDRESS_NO_PORT, but the current kernel "
"doesn't support it. This might cause Tor to run out "
"of ephemeral ports more quickly.");
try_ip_bind_address_no_port = 0;
} else {
log_warn(LD_NET, "Error setting IP_BIND_ADDRESS_NO_PORT on new "
"connection: %s", tor_socket_strerror(errno));
}
}
#endif
if (bindaddr && bind(s, bindaddr, bindaddr_len) < 0) {
*socket_error = tor_socket_errno(s);
if (ERRNO_IS_EADDRINUSE(*socket_error)) {