mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-12-06 19:41:15 +01:00
Enable IP_BIND_ADDRESS_NO_PORT if supported
This commit is contained in:
@@ -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)) {
|
||||
|
||||
Reference in New Issue
Block a user