Skip to content

Commit

Permalink
Enable TCP (method without raw socket) by default
Browse files Browse the repository at this point in the history
  • Loading branch information
blechschmidt committed Feb 9, 2023
1 parent 53203d3 commit de6a074
Showing 1 changed file with 33 additions and 3 deletions.
36 changes: 33 additions & 3 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,17 @@
#include <unistd.h>
#include <pwd.h>
#include <grp.h>
#include <sys/ioctl.h>
#include <stddef.h>
#ifdef HAVE_SYSINFO
#include <sys/sysinfo.h>
#endif
#include <limits.h>
#include <stdarg.h>

#ifdef IS_LINUX
#include <sys/resource.h>
#endif

static char json_buffer[5 * 0xFFFF];
static uint8_t packet_buffer[0x20000];

Expand Down Expand Up @@ -2184,10 +2187,36 @@ void make_query_sockets_nonblocking()
}
}

void set_open_file_limit_max()
{
#ifdef IS_LINUX
// With TCP, we create a socket for each lookup. Therefore, increase the limit of open files to the maximum.
if(context.cmd_args.tcp_enabled && !context.cmd_args.tcp_raw)
{
struct rlimit limit;
if (getrlimit(RLIMIT_NOFILE, &limit) != 0)
{
log_msg(LOG_ERROR, "Failed to get open file limit: %s\n", strerror(errno));
clean_exit(EXIT_FAILURE);
}

limit.rlim_cur = limit.rlim_max;

if (setrlimit(RLIMIT_NOFILE, &limit) != 0)
{
log_msg(LOG_ERROR, "Failed to set open file limit: %s\n", strerror(errno));
clean_exit(EXIT_FAILURE);
}
}
#endif
}

void run()
{
static char multiproc_outfile_name[8192];

set_open_file_limit_max();

if(!urandom_init())
{
log_msg(LOG_ERROR, "Failed to open /dev/urandom: %s\n", strerror(errno));
Expand Down Expand Up @@ -2471,6 +2500,7 @@ void parse_cmd(int argc, char **argv)
context.cmd_args.retry_codes[DNS_RCODE_NOERROR] = false;
context.cmd_args.num_processes = 1;
context.cmd_args.socket_count = 1;
context.cmd_args.tcp_enabled = true;
#ifndef HAVE_EPOLL
context.cmd_args.busypoll = true;
#endif
Expand All @@ -2483,9 +2513,9 @@ void parse_cmd(int argc, char **argv)
clean_exit(EXIT_SUCCESS);
}
#ifdef IS_LINUX
else if (strcmp(argv[i], "--tcp-enabled") == 0)
else if (strcmp(argv[i], "--tcp-disabled") == 0)
{
context.cmd_args.tcp_enabled = true;
context.cmd_args.tcp_enabled = false;
}
else if (strcmp(argv[i], "--tcp-only") == 0)
{
Expand Down

0 comments on commit de6a074

Please sign in to comment.