Scale the DNS random scket pool on the value of dns-forward-max.

This commit is contained in:
Simon Kelley
2021-03-26 22:02:04 +00:00
parent 4a8c098840
commit ea28d0ef8a
5 changed files with 21 additions and 10 deletions

View File

@@ -399,6 +399,14 @@ int main (int argc, char **argv)
cache_init();
blockdata_init();
hash_questions_init();
/* Scale random socket pool by ftabsize, but
limit it based on available fds. */
daemon->numrrand = daemon->ftabsize/2;
if (daemon->numrrand > max_fd/3)
daemon->numrrand = max_fd/3;
/* safe_malloc returns zero'd memory */
daemon->randomsocks = safe_malloc(daemon->numrrand * sizeof(struct randfd));
}
#ifdef HAVE_INOTIFY
@@ -987,7 +995,7 @@ int main (int argc, char **argv)
a single file will be sent to may clients (the file only needs
one fd). */
max_fd -= 30; /* use other than TFTP */
max_fd -= 30 + daemon->numrrand; /* use other than TFTP */
if (max_fd < 0)
max_fd = 5;
@@ -1700,7 +1708,7 @@ static int set_dns_listeners(time_t now)
for (serverfdp = daemon->sfds; serverfdp; serverfdp = serverfdp->next)
poll_listen(serverfdp->fd, POLLIN);
for (i = 0; i < RANDOM_SOCKS; i++)
for (i = 0; i < daemon->numrrand; i++)
if (daemon->randomsocks[i].refcount != 0)
poll_listen(daemon->randomsocks[i].fd, POLLIN);
@@ -1752,7 +1760,7 @@ static void check_dns_listeners(time_t now)
if (poll_check(serverfdp->fd, POLLIN))
reply_query(serverfdp->fd, now);
for (i = 0; i < RANDOM_SOCKS; i++)
for (i = 0; i < daemon->numrrand; i++)
if (daemon->randomsocks[i].refcount != 0 &&
poll_check(daemon->randomsocks[i].fd, POLLIN))
reply_query(daemon->randomsocks[i].fd, now);