ares_socket: set IP_BIND_ADDRESS_NO_PORT on ares_set_local_ip* tcp sockets (#887)

If you bind to a local address, you now only have approx 32k possible
source ports to initiate connections.
In modern days that can quickly run out.
setting IP_BIND_ADDRESS_NO_PORT let's the kernel choose a port at
connect time, increasing the limit of combinations to around a million.

Authored-By: Cristian Rodríguez (@crrodriguez)
pull/891/head
Cristian Rodríguez 5 months ago committed by GitHub
parent 9e64b10f5e
commit 3c4084c30c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 7
      src/lib/ares_socket.c

@ -574,7 +574,12 @@ ares_status_t ares_socket_configure(ares_channel_t *channel, int family,
sizeof(channel->local_ip6));
bindlen = sizeof(local.sa6);
}
#ifdef IP_BIND_ADDRESS_NO_PORT
if (is_tcp && bindlen) {
int opt = 1;
(void) setsockopt(fd, SOL_IP, IP_BIND_ADDRESS_NO_PORT, &opt, sizeof(opt));
}
#endif
if (bindlen && bind(fd, &local.sa, bindlen) < 0) {
return ARES_ECONNREFUSED;
}

Loading…
Cancel
Save