Skip to content

Commit

Permalink
Simplify DNS server implementation. (#1693)
Browse files Browse the repository at this point in the history
  • Loading branch information
Barenboim authored Feb 8, 2025
1 parent 0e0c1a3 commit cae71e4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
21 changes: 21 additions & 0 deletions src/factory/DnsTaskImpl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,31 @@ class WFDnsServerTask : public WFServerTask<DnsRequest, DnsResponse>
return this->WFServerTask::message_out();
}

virtual void handle(int state, int error);

protected:
enum TransportType type;
};

void WFDnsServerTask::handle(int state, int error)
{
if (state == WFT_STATE_TOREPLY)
{
DnsRequest *req = this->get_req();
DnsResponse *resp = this->get_resp();

resp->set_question_name(req->get_question_name());
resp->set_question_type(req->get_question_type());
resp->set_question_class(req->get_question_class());
resp->set_opcode(req->get_opcode());
resp->set_id(req->get_id());
resp->set_rd(req->get_rd());
resp->set_qr(1);
}

return WFServerTask::handle(state, error);
}

/**********Server Factory**********/

WFDnsTask *WFServerTaskFactory::create_dns_task(CommService *service,
Expand Down
11 changes: 1 addition & 10 deletions tutorial/tutorial-19-dns_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,14 @@ void process(WFDnsTask *task)
printf("name:%s type:%s class:%s\n",
name.c_str(), dns_type2str(qtype), dns_class2str(qclass));

resp->set_question_name(name);
resp->set_question_type(qtype);
resp->set_question_class(qclass);

resp->set_opcode(opcode);
resp->set_id(req->get_id()); // resp should set same id
resp->set_qr(1); // this is a response
resp->set_aa(1); // this is an authoritative answer
resp->set_rd(req->get_rd());

if (opcode != 0)
{
resp->set_rcode(DNS_RCODE_NOT_IMPLEMENTED);
return;
}

resp->set_rcode(DNS_RCODE_NO_ERROR);
resp->set_aa(1);

if (qtype == DNS_TYPE_A)
{
Expand Down

0 comments on commit cae71e4

Please sign in to comment.