]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Merge branch 'maint-0.4.7'
authorDavid Goulet <dgoulet@torproject.org>
Tue, 20 Dec 2022 14:09:47 +0000 (09:09 -0500)
committerDavid Goulet <dgoulet@torproject.org>
Tue, 20 Dec 2022 14:09:47 +0000 (09:09 -0500)
1  2 
src/core/mainloop/connection.c

index 4c9569ad5b843e3ae11031d4e198502218afd220,cf25213cb16644252ace39d4e9a7de84d4d7a6d6..d99498d6be4e9f9e98560ac827247ebc33780df0
@@@ -2233,6 -2222,20 +2233,30 @@@ connection_connect_sockaddr,(connection
               tor_socket_strerror(errno));
    }
  
 -  /*
 -   * We've got the socket open; give the OOS handler a chance to check
 -   * against configured maximum socket number, but tell it no exhaustion
 -   * failure.
 -   */
 -  connection_check_oos(get_n_open_sockets(), 0);
++#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
+   /* From ip(7): Inform the kernel to not reserve an ephemeral port when using
+    * bind(2) with a port number of 0. The port will later be automatically
+    * chosen at connect(2) time, in a way that allows sharing a source port as
+    * long as the 4-tuple is unique.
+    *
+    * This is needed for relays using OutboundBindAddresses because the port
+    * value in the bind address is set to 0. */
  #ifdef IP_BIND_ADDRESS_NO_PORT
    static int try_ip_bind_address_no_port = 1;
    if (bindaddr && try_ip_bind_address_no_port &&