Skip to content

Commit

Permalink
ares_socket: set IP_BIND_ADDRESS_NO_PORT on ares_set_local_ip* tcp so…
Browse files Browse the repository at this point in the history
…ckets

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.
  • Loading branch information
crrodriguez committed Sep 24, 2024
1 parent 9e64b10 commit d1da617
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/lib/ares_socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit d1da617

Please sign in to comment.