Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support attempts and timeout options from resolv.conf #632

Merged
merged 1 commit into from Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/lib/ares_sysconfig_files.c
Expand Up @@ -339,16 +339,29 @@ static ares_status_t set_options(ares_sysconfig_t *sysconfig, const char *str)
sysconfig->ndots = strtoul(val, NULL, 10);
}

// Outdated option.
val = try_option(p, q, "retrans:");
if (val) {
sysconfig->timeout_ms = strtoul(val, NULL, 10);
}

val = try_option(p, q, "timeout:");
if (val) {
sysconfig->timeout_ms = strtoul(val, NULL, 10) * 1000;
}

// Outdated option.
val = try_option(p, q, "retry:");
if (val) {
sysconfig->tries = strtoul(val, NULL, 10);
}

val = try_option(p, q, "attempts:");
if (val) {
fprintf(stderr, "ATTEMPTS: %d", (int)strtoul(val, NULL, 10));
sysconfig->tries = strtoul(val, NULL, 10);
}

val = try_option(p, q, "rotate");
if (val) {
sysconfig->rotate = ARES_TRUE;
Expand Down
19 changes: 19 additions & 0 deletions test/ares-test-init.cc
Expand Up @@ -275,6 +275,25 @@ TEST_F(LibraryTest, EnvInit) {
ares_destroy(channel);
}

TEST_F(LibraryTest, EnvInitModernOptions) {
ares_channel_t *channel = nullptr;
EnvValue v1("LOCALDOMAIN", "this.is.local");
EnvValue v2("RES_OPTIONS", "options debug retrans:2 ndots:3 attempts:4 timeout:5 rotate");
EXPECT_EQ(ARES_SUCCESS, ares_init(&channel));

channel->optmask |= ARES_OPT_TRIES;
channel->optmask |= ARES_OPT_TIMEOUTMS;

struct ares_options opts;
memset(&opts, 0, sizeof(opts));
int optmask = 0;
EXPECT_EQ(ARES_SUCCESS, ares_save_options(channel, &opts, &optmask));
EXPECT_EQ(5000, opts.timeout);
EXPECT_EQ(4, opts.tries);

ares_destroy(channel);
}

TEST_F(LibraryTest, EnvInitAllocFail) {
ares_channel_t *channel;
EnvValue v1("LOCALDOMAIN", "this.is.local");
Expand Down