diff --git a/include/llarp/dns/message.hpp b/include/llarp/dns/message.hpp index 94d7ced93..2047fe0eb 100644 --- a/include/llarp/dns/message.hpp +++ b/include/llarp/dns/message.hpp @@ -53,6 +53,9 @@ namespace llarp void AddNXReply(); + void + AddMXReply(std::string name, uint16_t priority); + void AddINReply(llarp::huint32_t addr); diff --git a/llarp/dns/message.cpp b/llarp/dns/message.cpp index f10bb3e3c..e3df5c518 100644 --- a/llarp/dns/message.cpp +++ b/llarp/dns/message.cpp @@ -189,6 +189,31 @@ namespace llarp } } + void + Message::AddMXReply(std::string name, uint16_t priority) + { + if(questions.size()) + { + hdr_fields |= (1 << 15); + const auto& question = questions[0]; + answers.emplace_back(); + auto& rec = answers.back(); + rec.rr_name = question.qname; + rec.rr_type = question.qtype; + rec.rr_class = 15; + rec.ttl = 1; + byte_t tmp[512] = {0}; + auto buf = llarp::StackBuffer< decltype(tmp) >(tmp); + llarp_buffer_put_uint16(&buf, priority); + if(EncodeName(&buf, name)) + { + buf.sz = buf.cur - buf.base; + rec.rData.resize(buf.sz); + memcpy(rec.rData.data(), buf.base, buf.sz); + } + } + } + void Message::AddNXReply() { diff --git a/llarp/handlers/tun.cpp b/llarp/handlers/tun.cpp index 37de0b007..cbc0bc8ad 100644 --- a/llarp/handlers/tun.cpp +++ b/llarp/handlers/tun.cpp @@ -184,7 +184,16 @@ namespace llarp return false; } std::string qname = msg.questions[0].qname; - if(msg.questions[0].qtype == 1) + if(msg.questions[0].qtype == 15) + { + // mx record + llarp::service::Address addr; + if(addr.FromString(qname, ".loki")) + msg.AddMXReply(qname, 1); + else + msg.AddNXReply(); + } + else if(msg.questions[0].qtype == 1) { // forward dns llarp::service::Address addr; @@ -198,10 +207,11 @@ namespace llarp } else return EnsurePathToService( - addr, - std::bind(&TunEndpoint::SendDNSReply, this, std::placeholders::_1, - std::placeholders::_2, msg, reply), - 2000); + addr, + std::bind(&TunEndpoint::SendDNSReply, this, + std::placeholders::_1, std::placeholders::_2, msg, + reply), + 2000); } else if(addr.FromString(qname, ".snode")) {