From c7aa3617b84b41872f383d0e56514d0ffc8f8597 Mon Sep 17 00:00:00 2001 From: Ryan Tharp Date: Mon, 12 Nov 2018 17:19:01 -0800 Subject: [PATCH 1/3] fix PTR record reading when answer type doesn't make question type --- llarp/dns.cpp | 22 ++++++++++------------ llarp/dnsc.cpp | 31 ++++++++++++++++++------------- 2 files changed, 28 insertions(+), 25 deletions(-) diff --git a/llarp/dns.cpp b/llarp/dns.cpp index e551bb268..0d593213f 100644 --- a/llarp/dns.cpp +++ b/llarp/dns.cpp @@ -224,12 +224,6 @@ extern "C" decode_answer(const char *const buffer, uint32_t *pos) { dns_msg_answer *answer = new dns_msg_answer; - // skip for now until we can handle compressed labels - /* - std::string aName = getDNSstring((char *)buffer); - buffer += aName.size() + 1; - */ - /* llarp_buffer_t bob; bob.base = (unsigned char *)buffer; @@ -237,14 +231,10 @@ extern "C" llarp::DumpBuffer(bob); */ - // hexDump(buffer, 10); - const char *moveable = buffer; // llarp::LogDebug("Advancing to pos ", std::to_string(*pos)); moveable += (*pos); // advance to position - // hexDumpAt(buffer, (*pos) - 2, 12); - // hexDump(moveable, 12); if(*moveable == '\xc0') { // hexDump(moveable, 12); @@ -267,7 +257,14 @@ extern "C" else { // get DNSString? - llarp::LogWarn("Need to parse string"); + llarp::LogWarn("Need to parse string, implement me"); + /* + uint32_t readAt32 = *pos; + answer->name = getDNSstring(buffer, &readAt32); + llarp::LogInfo("Parsed string ", answer->name, " read ", std::to_string(readAt32)); + moveable += readAt32; (*pos) += readAt32; + */ + //moveable++; (*pos)++; } /* hexDump(moveable, 10); @@ -361,8 +358,9 @@ extern "C" llarp::LogInfo("revDNSname: ", revname); answer->rData = new uint8_t[answer->rdLen + 1]; memcpy(answer->rData, revname.c_str(), answer->rdLen); + //answer->rData = (uint8_t *)strdup(revname.c_str()); // safer? nope moveable += answer->rdLen; - (*pos) += answer->rdLen; // advance the length + //(*pos) += answer->rdLen; // advance the length } break; case 15: diff --git a/llarp/dnsc.cpp b/llarp/dnsc.cpp index c5ad99d15..2381218a1 100644 --- a/llarp/dnsc.cpp +++ b/llarp/dnsc.cpp @@ -217,17 +217,6 @@ generic_handle_dnsc_recvfrom(dnsc_answer_request *request, llarp::LogDebug("msg nsc ", msg->nsCount); llarp::LogDebug("msg arc ", msg->arCount); - // we may need to parse question first - - /* - dns_msg_question *question = decode_question((const char *)castBuf); - llarp::LogInfo("que name ", question->name); - castBuf += question->name.length() + 8; - - dns_msg_answer *answer = decode_answer((const char *)castBuf); - castBuf += answer->name.length() + 4 + 4 + 4 + answer->rdLen; - */ - // FIXME: only handling one atm uint32_t pos = 12; // just set after header dns_msg_question *question = nullptr; @@ -240,6 +229,7 @@ generic_handle_dnsc_recvfrom(dnsc_answer_request *request, // castBuf += question->name.length() + 1 + 4; // castBuf += 2; // skip answer label } + llarp::LogInfo("Question ", std::to_string(question->type), " ", question->name); // FIXME: only handling one atm std::vector< dns_msg_answer * > answers; @@ -303,8 +293,15 @@ generic_handle_dnsc_recvfrom(dnsc_answer_request *request, // pos = 0; // reset pos answer = decode_answer(castBufc, &pos); // answers.push_back(answer); - llarp::LogDebug("Read an authority"); + llarp::LogDebug("Read an authority for ", + request->question.name, " at ", std::to_string(pos)); // castBuf += answer->name.length() + 4 + 4 + 4 + answer->rdLen; + if(pos > sz) + { + llarp::LogWarn("Would read past end of dns packet. for ", + request->question.name); + break; + } } /* @@ -393,6 +390,14 @@ generic_handle_dnsc_recvfrom(dnsc_answer_request *request, int ip = 0; + // if no answer, just bail now + if (!answer) + { + request->found = false; + request->resolved(request); + return; + } + /* search for and print IPv4 addresses */ // if(dnsQuery->reqType == 0x01) llarp::LogDebug("request question type: ", @@ -447,7 +452,7 @@ generic_handle_dnsc_recvfrom(dnsc_answer_request *request, return; } } - else if(request->question.type == 12) + else if(answer->type == 12) { llarp::LogDebug("Resolving PTR"); request->found = true; From 87b1fb8b3199caaff9230c69e6ce4c15d99a22e6 Mon Sep 17 00:00:00 2001 From: Ryan Tharp Date: Mon, 12 Nov 2018 17:36:12 -0800 Subject: [PATCH 2/3] fix bad merge --- llarp/dns.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/llarp/dns.cpp b/llarp/dns.cpp index 316eaef9b..98c08ad2e 100644 --- a/llarp/dns.cpp +++ b/llarp/dns.cpp @@ -366,7 +366,8 @@ extern "C" { std::string revname = getDNSstring(buffer, pos); llarp::LogInfo("revDNSname: ", revname); - answer->rData = new uint8_t[answer->rdLen + 1]; + //answer->rData = new uint8_t[answer->rdLen + 1]; + answer->rData.resize(answer->rdLen); memcpy(answer->rData.data(), revname.c_str(), answer->rdLen); //answer->rData = (uint8_t *)strdup(revname.c_str()); // safer? nope moveable += answer->rdLen; From 2d190508c54a595299e43b0f1ce30d78b35b4cd4 Mon Sep 17 00:00:00 2001 From: Ryan Tharp Date: Mon, 12 Nov 2018 17:42:18 -0800 Subject: [PATCH 3/3] does not work on MacOS at all --- llarp/config.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/llarp/config.cpp b/llarp/config.cpp index dc1b5fec5..8169dd80f 100644 --- a/llarp/config.cpp +++ b/llarp/config.cpp @@ -162,7 +162,7 @@ llarp_generic_ensure_config(std::ofstream &f, std::string basepath) f << "upstream=" << DEFAULT_RESOLVER_EU << std::endl; f << "# opennic au resolver" << std::endl; f << "upstream=" << DEFAULT_RESOLVER_AU << std::endl; - f << "bind=127.3.2.1:53" << std::endl; + f << "bind=127.0.0.1:53" << std::endl; f << std::endl << std::endl; f << "# network database settings block " << std::endl;