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

Simplify DNS resolver when resolving both v4 and v6. #1698

Merged
merged 1 commit into from
Feb 14, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 19 additions & 33 deletions src/nameservice/WFDnsResolver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,8 @@ using thread_dns_callback_t = std::function<void (ThreadDnsTask *)>;

struct DnsContext
{
int state;
int error;
int eai_error;
unsigned short port;
int eai_error;
struct addrinfo *ai;
};

Expand Down Expand Up @@ -662,10 +660,9 @@ void WFResolverTask::dns_partial_callback(void *net_dns_task)
WFGlobal::get_dns_respool()->post(NULL);

struct DnsContext *ctx = (struct DnsContext *)dns_task->user_data;

ctx->ai = NULL;
ctx->state = dns_task->get_state();
ctx->error = dns_task->get_error();
if (ctx->state == WFT_STATE_SUCCESS)
if (dns_task->get_state() == WFT_STATE_SUCCESS)
{
protocol::DnsResponse *resp = dns_task->get_resp();
ctx->eai_error = protocol::DnsUtil::getaddrinfo(resp, ctx->port,
Expand All @@ -678,46 +675,35 @@ void WFResolverTask::dns_partial_callback(void *net_dns_task)
void WFResolverTask::dns_parallel_callback(const void *parallel)
{
const ParallelWork *pwork = (const ParallelWork *)parallel;
struct DnsContext *c4 = (struct DnsContext *)(pwork->get_context());
struct DnsContext *c4 = (struct DnsContext *)pwork->get_context();
struct DnsContext *c6 = c4 + 1;
DnsOutput out;

if (c4->state != WFT_STATE_SUCCESS && c6->state != WFT_STATE_SUCCESS)
{
this->state = WFT_STATE_DNS_ERROR;
this->error = EAI_AGAIN;
}
else if (c4->eai_error != 0 && c6->eai_error != 0)
if (c4->eai_error == 0 || c6->eai_error == 0)
{
int eai_error = c4->eai_error;
struct addrinfo *ai = NULL;
struct addrinfo **pai = &ai;
DnsOutput out;

if (c6->eai_error == EAI_AGAIN)
eai_error = EAI_AGAIN;
*pai = c4->ai;
while (*pai)
pai = &(*pai)->ai_next;

DnsRoutine::create(&out, eai_error, NULL);
*pai = c6->ai;
DnsRoutine::create(&out, 0, ai);
dns_callback_internal(&out, dns_ttl_default_, dns_ttl_min_);
}
else
{
struct addrinfo *ai = NULL;
struct addrinfo **pai = &ai;

if (c4->ai != NULL)
{
*pai = c4->ai;
while (*pai)
pai = &(*pai)->ai_next;
}
int eai_error = c4->eai_error;

if (c6->ai != NULL)
*pai = c6->ai;
if (c6->eai_error == EAI_AGAIN)
eai_error = EAI_AGAIN;

DnsRoutine::create(&out, 0, ai);
dns_callback_internal(&out, dns_ttl_default_, dns_ttl_min_);
this->state = WFT_STATE_DNS_ERROR;
this->error = eai_error;
}

delete[] c4;

delete []c4;
task_callback();
}

Expand Down