Merge remote-tracking branch 'ryan/master'

pull/31/head
Jeff Becker 6 years ago
commit bf9512dfaf
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05

@ -399,6 +399,9 @@ set(TEST_SRC
test/encrypted_frame_unittest.cpp
test/hiddenservice_unittest.cpp
test/pq_unittest.cpp
test/test_dns_unit.cpp
test/test_dnsc_unit.cpp
test/test_dnsd_unit.cpp
)

@ -60,6 +60,8 @@ main(int argc, char *argv[])
multiThreaded = false;
}
//SetLogLevel(llarp::eLogDebug);
#ifdef _WIN32
if(startWinsock())
return -1;

@ -312,6 +312,7 @@ namespace llarp
// ask for next peer
if(txitr->second->AskNextPeer(from.node))
sendReply = false;
llarp::LogWarn("Target key ", txitr->second->target);
Inform(from, txitr->second->target, {}, sendReply, sendReply);
}

@ -1,13 +1,14 @@
#ifndef LLARP_DNS_H_
#define LLARP_DNS_H_
#include <llarp/ev.h> // for sockaadr
#include <sys/types.h> // for uint & ssize_t
//#include <llarp/ev.h> // for sockaadr
//#include <sys/types.h> // for uint & ssize_t
// all uint should have been removed in favor of uint_16t
/* non-cygnus does not have this type */
#ifdef _WIN32
#define uint UINT
#endif
//#ifdef _WIN32
//#define uint UINT
//#endif
#ifdef __cplusplus
extern "C"

@ -84,6 +84,12 @@ struct dns_packet
std::vector< std::unique_ptr< dns_msg_answer > > additional_rrs;
};
std::string
getDNSstring(const char *buffer);
void
code_domain(char *&buffer, const std::string &domain) throw();
extern "C"
{
uint16_t
@ -107,9 +113,6 @@ extern "C"
void
put32bits(char *&buffer, uint32_t value) throw();
void
code_domain(char *&buffer, const std::string &domain) throw();
void
llarp_handle_dns_recvfrom(struct llarp_udp_io *udp,
const struct sockaddr *addr, const void *buf,

@ -9,6 +9,20 @@
struct dnsc_answer_request;
#define DNC_BUF_SIZE 512
/// a question to be asked remotely (the actual bytes to send on the wire)
// header, question
struct dns_query
{
uint16_t length;
// char *url;
unsigned char request[DNC_BUF_SIZE];
// uint16_t reqType;
};
struct dns_query *
build_dns_packet(char *url, uint16_t id, uint16_t reqType);
/// hook function to handle an dns client request
// should we pass by llarp::Addr
// not as long as we're supporting raw

@ -6,6 +6,10 @@
#include <llarp/dns.hpp> // question and dnsc
#include <llarp/dnsc.hpp>
//
// Input structures/functions:
//
// fwd declaration
struct dnsd_context;
@ -19,10 +23,10 @@ struct dnsd_question_request
{
/// sock type
void *user;
// raw or llarp subsystem
// raw or llarp subsystem (is this used? does this matter?)
bool llarp;
/// request id
int id;
unsigned int id;
/// question being asked
dns_msg_question question;
// request source socket
@ -44,6 +48,47 @@ struct dnsd_query_hook_response
sockaddr *returnThis; // FIXME: llarp::Addr
};
/// builds and fires a request based based on llarp_udp_io udp event
/// called by the llarp_handle_dns_recvfrom generic (dnsd/dnsc) handler in dns
void
llarp_handle_dnsd_recvfrom(struct llarp_udp_io *udp,
const struct sockaddr *addr, const void *buf,
ssize_t sz);
//
// output structures/functions:
//
// we may want to pass dnsd_question_request to these,
// incase we need to send an error back up through the pipeline
/// NXDOMAIN not found
void
write404_dnss_response(const struct sockaddr *from,
dnsd_question_request *request);
/// for hook functions to use
void
writecname_dnss_response(std::string cname, const struct sockaddr *from,
dnsd_question_request *request);
// FIXME: llarp::Addr
/// send an A record found response
void
writesend_dnss_response(struct sockaddr *hostRes, const struct sockaddr *from,
dnsd_question_request *request);
// FIXME: llarp::Addr
/// send an PTR record found response
void
writesend_dnss_revresponse(std::string reverse, const struct sockaddr *from,
dnsd_question_request *request);
// FIXME: llarp::Addr
//
// setup/teardown functions/structure:
//
/// intercept query hook functor
typedef dnsd_query_hook_response *(*intercept_query_hook)(
std::string name, const struct sockaddr *from,
@ -65,23 +110,6 @@ struct dnsd_context
intercept_query_hook intercept;
};
/// udp event handler
void
llarp_handle_dnsd_recvfrom(struct llarp_udp_io *udp,
const struct sockaddr *addr, const void *buf,
ssize_t sz);
/// for hook functions to use
void
writecname_dnss_response(std::string cname, const struct sockaddr *from,
dnsd_question_request *request);
// FIXME: llarp::Addr
void
writesend_dnss_response(struct sockaddr *hostRes, const struct sockaddr *from,
dnsd_question_request *request);
// FIXME: llarp::Addr
/// initialize dns subsystem and bind socket
/// returns true on bind success otherwise returns false
bool

@ -23,7 +23,8 @@ namespace llarp
eLogDebug,
eLogInfo,
eLogWarn,
eLogError
eLogError,
eLogNone
};
struct Logger
@ -108,6 +109,8 @@ namespace llarp
int loglev = -1;
switch(lvl)
{
case eLogNone:
break;
case eLogDebug:
ss << "[DBG] ";
loglev = ANDROID_LOG_DEBUG;
@ -128,6 +131,8 @@ namespace llarp
#else
switch(lvl)
{
case eLogNone:
break;
case eLogDebug:
ss << (char)27 << "[0m";
ss << "[DBG] ";

@ -41,6 +41,8 @@ operator==(const in6_addr& a, const in6_addr& b);
struct privatesInUse
{
// true if used by real NICs on start
// false if not used, and means we could potentially use it if needed
bool ten; // 16m ips
bool oneSeven; // 1m ips
bool oneNine; // 65k ips
@ -469,6 +471,14 @@ namespace llarp
return (const sockaddr*)&_addr;
}
operator sockaddr*() const
{
if(af() == AF_INET)
return (sockaddr*)&_addr4;
else
return (sockaddr*)&_addr;
}
void
CopyInto(sockaddr* other) const
{
@ -593,12 +603,6 @@ namespace llarp
return nuint32_t{addr4()->s_addr};
}
sockaddr*
getSockAddr()
{
return (struct sockaddr*)&_addr4;
}
bool
sameAddr(const Addr& other) const
{

@ -334,7 +334,7 @@ namespace llarp
std::string host = bindaddr.substr(0, idx);
uint16_t port = std::stoi(bindaddr.substr(idx + 1));
addr = llarp::Addr(host, port);
saddr = addr.getSockAddr();
saddr = (sockaddr *)addr;
}
return llarp_tcp_serve(&m_acceptor, saddr);
}

@ -32,6 +32,35 @@ getDNSstring(const char *buffer)
return str;
}
void
code_domain(char *&buffer, const std::string &domain) throw()
{
std::string::size_type start(0);
std::string::size_type end; // indexes
// llarp::LogInfo("domain [", domain, "]");
while((end = domain.find('.', start)) != std::string::npos)
{
*buffer++ = end - start; // label length octet
for(std::string::size_type i = start; i < end; i++)
{
*buffer++ = domain[i]; // label octets
// llarp::LogInfo("Writing ", domain[i], " at ", i);
}
start = end + 1; // Skip '.'
}
// llarp::LogInfo("start ", start, " domain size ", domain.size());
*buffer++ = domain.size() - start; // last label length octet
for(size_t i = start; i < domain.size(); i++)
{
*buffer++ = domain[i]; // last label octets
// llarp::LogInfo("Writing ", domain[i], " at ", i);
}
*buffer++ = 0;
}
// lets just remove uint
#ifdef _WIN32
#define uint UINT
@ -71,9 +100,9 @@ extern "C"
hdr->rd = fields & 0x0100;
hdr->ra = (lFields >> 7) & 0x1;
// hdr->z = (lFields >> 6) & 0x1;
// hdr->ad = (lFields >> 5) & 0x1;
// hdr->cd = (lFields >> 4) & 0x1;
hdr->z = (lFields >> 6) & 0x1;
hdr->ad = (lFields >> 5) & 0x1;
hdr->cd = (lFields >> 4) & 0x1;
hdr->rcode = lFields & 0xf;
hdr->qdCount = get16bits(buffer);
@ -86,8 +115,11 @@ extern "C"
dns_msg_question *
decode_question(const char *buffer)
{
//char *start = (char *)buffer;
dns_msg_question *question = new dns_msg_question;
std::string m_qName = getDNSstring(buffer);
buffer += m_qName.length() + 2; // + length byte & ending terminator
//printf("Now0 at [%d]\n", buffer - start);
// buffer += m_qName.size() + 1;
/*
std::string m_qName = "";
@ -107,7 +139,9 @@ extern "C"
*/
question->name = m_qName;
question->type = get16bits(buffer);
//printf("Now1 at [%d]\n", buffer - start);
question->qClass = get16bits(buffer);
//printf("Now2 at [%d]\n", buffer - start);
return question;
}
@ -168,6 +202,12 @@ extern "C"
case 6: // type 6 = SOA
{
// 2 names, then 4x 32bit
// why risk any crashes
if (answer->rdLen < 24)
{
llarp::LogWarn("Weird SOA is less than 24 bytes: ", answer->rdLen);
}
/*
std::string mname = getDNSstring((char *)buffer);
std::string rname = getDNSstring((char *)buffer);
uint32_t serial = get32bits(buffer);
@ -182,6 +222,7 @@ extern "C"
llarp::LogDebug("retry : ", retry);
llarp::LogDebug("expire : ", expire);
llarp::LogDebug("minimum : ", minimum);
*/
}
break;
case 12:
@ -215,35 +256,6 @@ extern "C"
buffer += 4;
}
void
code_domain(char *&buffer, const std::string &domain) throw()
{
std::string::size_type start(0);
std::string::size_type end; // indexes
// llarp::LogInfo("domain [", domain, "]");
while((end = domain.find('.', start)) != std::string::npos)
{
*buffer++ = end - start; // label length octet
for(std::string::size_type i = start; i < end; i++)
{
*buffer++ = domain[i]; // label octets
// llarp::LogInfo("Writing ", domain[i], " at ", i);
}
start = end + 1; // Skip '.'
}
// llarp::LogInfo("start ", start, " domain size ", domain.size());
*buffer++ = domain.size() - start; // last label length octet
for(size_t i = start; i < domain.size(); i++)
{
*buffer++ = domain[i]; // last label octets
// llarp::LogInfo("Writing ", domain[i], " at ", i);
}
*buffer++ = 0;
}
void
llarp_handle_dns_recvfrom(struct llarp_udp_io *udp,
const struct sockaddr *addr, const void *buf,

@ -110,7 +110,7 @@ llarp_dotlokilookup_checkQuery(void *u, uint64_t orig, uint64_t left)
response->dontSendResponse = false;
// llarp::Addr test(*free_private->hostResult.getSockAddr());
// llarp::LogInfo("IP Test: ", test);
response->returnThis = free_private->hostResult.getSockAddr();
response->returnThis = free_private->hostResult;
llarp::LogInfo("Saving ", qr->request->question.name);
loki_tld_lookup_cache[qr->request->question.name] = response;
// we can't delete response now...

@ -16,9 +16,9 @@ dns_iptracker_init()
// disable all possibilities unless you setup a tunGateway
g_dns_iptracker.used_privates.ten = false;
g_dns_iptracker.used_privates.oneSeven = false;
g_dns_iptracker.used_privates.oneNine = false;
g_dns_iptracker.used_privates.ten = true;
g_dns_iptracker.used_privates.oneSeven = true;
g_dns_iptracker.used_privates.oneNine = true;
}
// not sure we want tunGatewayIP... we'll know when we get further
@ -59,17 +59,17 @@ dns_iptracker_setup(dns_iptracker *iptracker, llarp::Addr tunGatewayIp)
if(ip[0] == 10)
{
iptracker->used_ten_ips.push_back(std::move(range));
iptracker->used_privates.ten = true;
iptracker->used_privates.ten = false;
}
else if(ip[0] == 172)
{
iptracker->used_seven_ips.push_back(std::move(range));
iptracker->used_privates.oneSeven = true;
iptracker->used_privates.oneSeven = false;
}
else if(ip[0] == 192)
{
iptracker->used_nine_ips.push_back(std::move(range));
iptracker->used_privates.oneNine = true;
iptracker->used_privates.oneNine = false;
}
else
{
@ -158,9 +158,9 @@ dns_iptracker_get_free()
struct dns_pointer *
dns_iptracker_get_free(dns_iptracker *iptracker)
{
llarp::LogInfo("We used 10.x.x.x? ",
llarp::LogInfo("Was 10.x.x.x already in-use on start? ",
iptracker->used_privates.ten ? "Yes" : "No");
if(iptracker->used_privates.ten)
if(!iptracker->used_privates.ten)
{
struct dns_pointer *test =
dns_iptracker_check_range(iptracker->used_ten_ips, 10);
@ -169,9 +169,9 @@ dns_iptracker_get_free(dns_iptracker *iptracker)
return test;
}
}
llarp::LogInfo("We used 172.16.x.x? ",
llarp::LogInfo("Was 172.16.x.x already in-use on start? ",
iptracker->used_privates.oneSeven ? "Yes" : "No");
if(iptracker->used_privates.oneSeven)
if(!iptracker->used_privates.oneSeven)
{
struct dns_pointer *test =
dns_iptracker_check_range(iptracker->used_seven_ips, 172);
@ -180,9 +180,9 @@ dns_iptracker_get_free(dns_iptracker *iptracker)
return test;
}
}
llarp::LogInfo("We used 192.168.x.x? ",
llarp::LogInfo("Was 192.168.x.x already in-use on start? ",
iptracker->used_privates.oneNine ? "Yes" : "No");
if(iptracker->used_privates.oneNine)
if(!iptracker->used_privates.oneNine)
{
struct dns_pointer *test =
dns_iptracker_check_range(iptracker->used_nine_ips, 192);

@ -23,6 +23,8 @@
dns_tracker dns_udp_tracker;
/*
#define DNC_BUF_SIZE 512
/// a question to be asked remotely (the actual bytes to send on the wire)
// header, question
@ -33,6 +35,7 @@ struct dns_query
unsigned char request[DNC_BUF_SIZE];
// uint16_t reqType;
};
*/
/// build a DNS question packet
struct dns_query *

@ -268,9 +268,10 @@ handle_dnsc_result(dnsc_answer_request *client_request)
}
else
{
writesend_dnss_response(
client_request->found ? client_request->result.getSockAddr() : nullptr,
server_request->from, server_request);
struct sockaddr *useHostRes = nullptr;
if (client_request->found)
useHostRes = client_request->result;
writesend_dnss_response(useHostRes, server_request->from, server_request);
}
llarp_host_resolved(client_request);
}

@ -807,6 +807,7 @@ struct privatesInUse
llarp_getPrivateIfs()
{
struct privatesInUse result;
// mark all available for use
result.ten = false;
result.oneSeven = false;
result.oneNine = false;

@ -666,16 +666,12 @@ llarp_router::Run()
}
routerProfiling.Load(routerProfilesFile.c_str());
// zero out router contact
//sockaddr *dest = (sockaddr *)&this->ip4addr;
llarp::Addr publicAddr(this->addrInfo);
if(this->publicOverride)
{
if(publicAddr)
{
llarp::LogInfo("public address:port ", publicAddr);
}
llarp::LogDebug("public address:port ", publicAddr);
}
llarp::LogInfo("You have ", inboundLinks.size(), " inbound links");
@ -727,6 +723,7 @@ llarp_router::Run()
_rc.addrs.push_back(this->addrInfo);
}
}
// set public encryption key
_rc.enckey = llarp::seckey_topublic(encryption);
llarp::LogInfo("Your Encryption pubkey ", rc().enckey);
@ -1247,7 +1244,8 @@ namespace llarp
{
llarp::LogInfo("Setting public port ", val);
int p = atoi(val);
// Not needed to flip upside-down - this is done in llarp::Addr(const AddressInfo&)
// Not needed to flip upside-down - this is done in llarp::Addr(const
// AddressInfo&)
self->ip4addr.sin_port = p;
self->addrInfo.port = p;
self->publicOverride = true;

@ -0,0 +1,192 @@
#include <gtest/gtest.h>
#include <llarp.h> // for llarp_main_init
#include <llarp/logic.h> // for threadpool/llarp_logic
#include "llarp/net.hpp" // for llarp::Addr
#include "llarp/dns.hpp"
#include "llarp/dnsc.hpp"
struct DNSTest : public ::testing::Test
{
unsigned char buf[47] = {
0x00,0x01, // first short
0x01,0x00,0x00, // combined fields
0x01,0x00,0x01,0x00,0x00,0x00,0x00, // last 4 shorts
// question (is 18 bytes long)
0x04, // 4 letters
0x6C,0x6F,0x6B,0x69, // loki
0x07, // 7 letters
0x6E,0x65,0x74,0x77,0x6F,0x72,0x6B, // network
0x00, // end
0x00,0x01, // type (a 1/ptr 12)
0x00,0x01, // class (1 = internet)
// 30th byte
// Answer (is 16 bytes long)
0xc0, 0x0c, 0x00, 0x01, 0x00, 0x01, // name, type, class
0x00, 0x00, 0x08, 0x4b, // ttl 2123
0x00, 0x04, // rdLen
0x45, 0x10, 0xd1, 0x02, // an ip address
// extra
0x00 // null terminator (probably don't need this, just added it)
};
DNSTest()
{
}
void
SetUp()
{
llarp::SetLogLevel(llarp::eLogNone); // turn off logging to keep gtest output pretty
/*
const char *url = "loki.network";
struct dns_query *packet = build_dns_packet((char *)url, 1, 1); // id 1, type 1 (A)
unsigned int length = packet->length;
char *buffer = (char *)packet->request;
char hex_buffer[length * 5 + 1];
hex_buffer[length * 5] = 0;
for(unsigned int j = 0; j < length; j++)
sprintf(&hex_buffer[5 * j], "0x%02X,", ((const char *)buffer)[j]);
printf("Generated [%u] bytes: [%s]\n", length, hex_buffer);
*/
}
};
// test puts/gets
// test code_domain / getDNSstring
TEST_F(DNSTest, TestDecodeDNSstring)
{
char *buffer = (char *)this->buf;
buffer += 12; // skip header
std::string res = getDNSstring(buffer);
ASSERT_TRUE(res == "loki.network");
}
TEST_F(DNSTest, TestCodeDomain)
{
char buffer[16];
llarp::Zero(&buffer, 15);
char *write_buffer = buffer;
std::string url = "bob.com";
code_domain(write_buffer, url);
char hex_buffer[16 * 3 + 1];
hex_buffer[16 * 3] = 0;
for(unsigned int j = 0; j < 16; j++)
sprintf(&hex_buffer[3 * j], "%02X ", ((const char *)buffer)[j]);
//printf("first 16 [%s]", hex_buffer);
std::string expected_result = "03 62 6F 62 03 63 6F 6D 00 00 00 00 00 00 00 00 ";
ASSERT_TRUE(hex_buffer == expected_result);
}
// test decoders
TEST_F(DNSTest, TestDecodeHdr)
{
dns_msg_header *hdr = decode_hdr((char *)this->buf);
/*
printf("id[%d]", hdr->id);
printf("qr[%d]", hdr->qr);
printf("oc[%d]", hdr->opcode);
printf("aa[%d]", hdr->aa);
printf("tc[%d]", hdr->tc);
printf("rd[%d]", hdr->rd);
printf("ra[%d]", hdr->ra);
printf("z [%d]", hdr->z);
printf("ad[%d]", hdr->ad);
printf("cd[%d]", hdr->cd);
printf("rc[%d]", hdr->rcode);
printf("qd[%d]", hdr->qdCount);
printf("an[%d]", hdr->anCount);
printf("ns[%d]", hdr->nsCount);
printf("ar[%d]", hdr->arCount);
*/
ASSERT_TRUE(hdr->id == 1);
ASSERT_TRUE(hdr->qr == 0);
ASSERT_TRUE(hdr->opcode == 0);
ASSERT_TRUE(hdr->aa == 0);
ASSERT_TRUE(hdr->tc == 0);
ASSERT_TRUE(hdr->rd == 0);
ASSERT_TRUE(hdr->ra == 0);
ASSERT_TRUE(hdr->z == 0);
ASSERT_TRUE(hdr->ad == 0);
ASSERT_TRUE(hdr->cd == 0);
ASSERT_TRUE(hdr->rcode == 0);
ASSERT_TRUE(hdr->qdCount == 1);
ASSERT_TRUE(hdr->anCount == 1);
ASSERT_TRUE(hdr->nsCount == 0);
ASSERT_TRUE(hdr->arCount == 0);
}
TEST_F(DNSTest, TestDecodeQuestion)
{
char *buffer = (char *)this->buf;
buffer += 12; // skip header
dns_msg_question *question = decode_question(buffer);
//printf("name[%s]", question->name.c_str());
//printf("type[%d]", question->type);
//printf("qClass[%d]", question->qClass);
std::string url = "loki.network";
ASSERT_TRUE(question->name == url);
ASSERT_TRUE(question->type == 1);
ASSERT_TRUE(question->qClass == 1);
}
TEST_F(DNSTest, TestDecodeAnswer)
{
char *buffer = (char *)this->buf;
buffer += 12; // skip header
std::string url = "loki.network";
buffer += url.length() + 1 + 4;
buffer += 2; // FIXME: skip answer label
dns_msg_answer *answer = decode_answer(buffer);
/*
printf("type[%d]", answer->type);
printf("aClass[%d]", answer->aClass);
printf("ttl[%d]", answer->ttl);
printf("rdLen[%d]", answer->rdLen);
printf("[%zu].[%zu].[%zu].[%zu]", answer->rData[0], answer->rData[1], answer->rData[2], answer->rData[3]);
*/
ASSERT_TRUE(answer->type == 1);
ASSERT_TRUE(answer->aClass == 1);
ASSERT_TRUE(answer->ttl == 2123);
ASSERT_TRUE(answer->rdLen == 4);
ASSERT_TRUE(answer->rData[0] == 69);
ASSERT_TRUE(answer->rData[1] == 16);
ASSERT_TRUE(answer->rData[2] == 209);
ASSERT_TRUE(answer->rData[3] == 2);
}
/// UDP handling configuration
struct llarp_udp_io_mock
{
/// set after added
int fd;
void *user;
void *impl;
struct llarp_ev_loop *parent;
/// called every event loop tick after reads
void (*tick)(struct llarp_udp_io *);
// sockaddr * is the source
void (*recvfrom)(struct llarp_udp_io *, const struct sockaddr *, const void *,
ssize_t);
};
// will have to mock udp and intercept the sendto call...
// test llarp_handle_dns_recvfrom
TEST_F(DNSTest, handleDNSrecvFrom)
{
llarp_udp_io_mock udp;
sockaddr addr;
char buffer[16];
llarp::Zero(&buffer, 15);
ssize_t sz = 0;
// hdr->qr decides dnsc (1) or dnsd (0)
llarp_handle_dns_recvfrom((llarp_udp_io *)&udp, &addr, buffer, sz);
// llarp_handle_dnsc_recvfrom
// llarp_handle_dnsd_recvfrom
}

@ -0,0 +1,5 @@
#include <gtest/gtest.h>
#include <llarp.h> // for llarp_main_init
#include <llarp/logic.h> // for threadpool/llarp_logic
#include "llarp/net.hpp" // for llarp::Addr
#include "llarp/dnsc.hpp"

@ -0,0 +1,82 @@
#include <gtest/gtest.h>
#include <llarp.h> // for llarp_main_init
#include <llarp/logic.h> // for threadpool/llarp_logic
#include "llarp/net.hpp" // for llarp::Addr
#include "llarp/dnsd.hpp"
unsigned int g_length = 0;
std::string g_result = "";
ssize_t test_sendto_dns_hook(void *sock, const struct sockaddr *from,
const void *buffer, size_t length) {
char hex_buffer[length * 3 + 1];
hex_buffer[length * 3] = 0;
for(unsigned int j = 0; j < length; j++)
sprintf(&hex_buffer[3 * j], "%02X ", ((const char *)buffer)[j]);
//printf("Got [%zu] bytes: [%s]\n", length, hex_buffer);
g_result = hex_buffer;
g_length = length;
return length;
}
struct llarpDNSdTest : public ::testing::Test
{
dnsd_question_request test_request;
llarpDNSdTest()
{
}
void
SetUp()
{
test_request.id = 0;
test_request.llarp = true; // we don't care about raw atm
test_request.from = nullptr;
test_request.context = nullptr;
test_request.sendto_hook = &test_sendto_dns_hook;
test_request.question.name = "loki.network";
test_request.question.type = 1;
test_request.question.qClass = 1;
g_result = ""; // reset test global
g_length = 0;
llarp::SetLogLevel(llarp::eLogNone); // turn off logging to keep gtest output pretty
}
};
TEST_F(llarpDNSdTest, TestNxDomain)
{
write404_dnss_response(nullptr, &test_request);
ASSERT_TRUE(g_length == 55);
std::string expected_output = "00 00 FFF03 00 01 00 01 00 00 00 00 04 6C 6F 6B 69 07 6E 65 74 77 6F 72 6B 00 00 01 00 01 04 6C 6F 6B 69 07 6E 65 74 77 6F 72 6B 00 00 01 00 01 00 00 00 01 00 01 00 ";
ASSERT_TRUE(expected_output == g_result);
}
TEST_F(llarpDNSdTest, TestAResponse)
{
sockaddr hostRes;
llarp::Zero(&hostRes, sizeof(sockaddr));
writesend_dnss_response(&hostRes, nullptr, &test_request);
ASSERT_TRUE(g_length == 58);
std::string expected_output = "00 00 FFF00 00 01 00 01 00 00 00 00 04 6C 6F 6B 69 07 6E 65 74 77 6F 72 6B 00 00 01 00 01 04 6C 6F 6B 69 07 6E 65 74 77 6F 72 6B 00 00 01 00 01 00 00 00 01 00 04 00 00 00 00 ";
ASSERT_TRUE(expected_output == g_result);
}
TEST_F(llarpDNSdTest, TestPTRResponse)
{
writesend_dnss_revresponse("loki.network", nullptr,
&test_request);
ASSERT_TRUE(g_length == 68);
std::string expected_output = "00 00 FFF00 00 01 00 01 00 00 00 00 04 6C 6F 6B 69 07 6E 65 74 77 6F 72 6B 00 00 01 00 01 04 6C 6F 6B 69 07 6E 65 74 77 6F 72 6B 00 00 01 00 01 00 00 00 01 00 0E 04 6C 6F 6B 69 07 6E 65 74 77 6F 72 6B 00 ";
ASSERT_TRUE(expected_output == g_result);
}
TEST_F(llarpDNSdTest, TestCname)
{
writecname_dnss_response("test.cname", nullptr, &test_request);
ASSERT_TRUE(g_length == 122);
std::string expected_output = "00 00 FFF00 00 01 00 01 00 01 00 01 04 6C 6F 6B 69 07 6E 65 74 77 6F 72 6B 00 00 01 00 01 04 6C 6F 6B 69 07 6E 65 74 77 6F 72 6B 00 00 05 00 01 00 00 00 01 00 0C 04 74 65 73 74 05 63 6E 61 6D 65 00 04 74 65 73 74 05 63 6E 61 6D 65 00 00 02 00 01 00 00 00 01 00 0A 03 6E 73 31 04 6C 6F 6B 69 00 03 6E 73 31 04 6C 6F 6B 69 00 00 01 00 01 00 00 00 01 00 04 7F 00 00 01 ";
ASSERT_TRUE(expected_output == g_result);
}
Loading…
Cancel
Save