-
Notifications
You must be signed in to change notification settings - Fork 220
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
merge in dnslib and fix setcap #103
Merged
Merged
Changes from 12 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
1d1bde2
add dnslib
majestrate 40678f9
add dnslib unit test coverage
majestrate 0f7053f
cut logging
majestrate c27b7c2
separate client/server in dns proxy
majestrate ebb42ca
fix previous commit
majestrate 1f10488
unit testing for ptr
majestrate e1ee2de
correctly encode response
majestrate f63045d
Merge remote-tracking branch 'origin/master' into dev
majestrate a303dbb
revert
majestrate a83e29c
revert
majestrate 45dad97
tick before expire
majestrate 1e339af
disable locking
majestrate 1c446d0
make it compile on os x
majestrate 512d32f
attempt to fix crash
majestrate File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#include <llarp/dns/name.hpp> | ||
#include <llarp/dns/rr.hpp> | ||
#include <llarp/dns/serialize.hpp> | ||
#include <llarp/dns/message.hpp> | ||
#include <llarp/dns/server.hpp> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
#ifndef LLARP_DNS_MESSAGE_HPP | ||
#define LLARP_DNS_MESSAGE_HPP | ||
#include <llarp/dns/serialize.hpp> | ||
#include <llarp/dns/rr.hpp> | ||
#include <llarp/dns/question.hpp> | ||
|
||
namespace llarp | ||
{ | ||
namespace dns | ||
{ | ||
using MsgID_t = uint16_t; | ||
using Fields_t = uint16_t; | ||
using Count_t = uint16_t; | ||
|
||
struct MessageHeader : public Serialize | ||
{ | ||
const static size_t Size = 12; | ||
|
||
MessageHeader() = default; | ||
|
||
MsgID_t id; | ||
Fields_t fields; | ||
Count_t qd_count; | ||
Count_t an_count; | ||
Count_t ns_count; | ||
Count_t ar_count; | ||
|
||
bool | ||
Encode(llarp_buffer_t* buf) const override; | ||
|
||
bool | ||
Decode(llarp_buffer_t* buf) override; | ||
|
||
bool | ||
operator==(const MessageHeader& other) const | ||
{ | ||
return id == other.id && fields == other.fields | ||
&& qd_count == other.qd_count && an_count == other.an_count | ||
&& ns_count == other.ns_count && ar_count == other.ar_count; | ||
} | ||
}; | ||
|
||
struct Message : public Serialize | ||
{ | ||
Message(const MessageHeader& hdr); | ||
|
||
Message(Message&& other); | ||
Message(const Message& other); | ||
|
||
void | ||
UpdateHeader(); | ||
|
||
void | ||
AddNXReply(); | ||
|
||
void | ||
AddINReply(llarp::huint32_t addr); | ||
|
||
void | ||
AddAReply(std::string name); | ||
|
||
bool | ||
Encode(llarp_buffer_t* buf) const override; | ||
|
||
bool | ||
Decode(llarp_buffer_t* buf) override; | ||
|
||
friend std::ostream& | ||
operator<<(std::ostream& out, const Message& msg) | ||
{ | ||
out << "[dns message id=" << std::hex << msg.hdr_id | ||
<< " fields=" << msg.hdr_fields << " questions=[ "; | ||
for(const auto& qd : msg.questions) | ||
out << qd << ", "; | ||
out << "] answers=[ "; | ||
for(const auto& an : msg.answers) | ||
out << an << ", "; | ||
out << "] nameserver=[ "; | ||
for(const auto& ns : msg.authorities) | ||
out << ns << ", "; | ||
out << "] additional=[ "; | ||
for(const auto& ar : msg.additional) | ||
out << ar << ", "; | ||
return out << "]"; | ||
} | ||
|
||
MsgID_t hdr_id; | ||
Fields_t hdr_fields; | ||
std::vector< Question > questions; | ||
std::vector< ResourceRecord > answers; | ||
std::vector< ResourceRecord > authorities; | ||
std::vector< ResourceRecord > additional; | ||
}; | ||
} // namespace dns | ||
} // namespace llarp | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#ifndef LLARP_DNS_NAME_HPP | ||
#define LLARP_DNS_NAME_HPP | ||
|
||
#include <string> | ||
#include <llarp/buffer.h> | ||
#include <llarp/net_int.hpp> | ||
|
||
namespace llarp | ||
{ | ||
namespace dns | ||
{ | ||
using Name_t = std::string; | ||
|
||
/// decode name from buffer | ||
bool | ||
DecodeName(llarp_buffer_t* buf, Name_t& name); | ||
|
||
/// encode name to buffer | ||
bool | ||
EncodeName(llarp_buffer_t* buf, const Name_t& name); | ||
|
||
bool | ||
DecodePTR(const Name_t& name, huint32_t& ip); | ||
|
||
} // namespace dns | ||
} // namespace llarp | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#ifndef LLARP_DNS_QUERY_HPP | ||
#define LLARP_DNS_QUERY_HPP | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#ifndef LLARP_DNS_QUESTION_HPP | ||
#define LLARP_DNS_QUESTION_HPP | ||
#include <llarp/dns/serialize.hpp> | ||
#include <llarp/dns/name.hpp> | ||
#include <llarp/net_int.hpp> | ||
|
||
namespace llarp | ||
{ | ||
namespace dns | ||
{ | ||
using QType_t = uint16_t; | ||
using QClass_t = uint16_t; | ||
|
||
struct Question : public Serialize | ||
{ | ||
Question() = default; | ||
Question(Question&& other); | ||
Question(const Question& other); | ||
bool | ||
Encode(llarp_buffer_t* buf) const override; | ||
|
||
bool | ||
Decode(llarp_buffer_t* buf) override; | ||
|
||
bool | ||
operator==(const Question& other) const | ||
{ | ||
return qname == other.qname && qtype == other.qtype | ||
&& qclass == other.qclass; | ||
} | ||
|
||
friend std::ostream& | ||
operator<<(std::ostream& out, const Question& q) | ||
{ | ||
return out << "qname=" << q.qname << " qtype=" << (int)q.qtype | ||
<< " qclass=" << (int)q.qclass; | ||
} | ||
|
||
Name_t qname; | ||
QType_t qtype; | ||
QClass_t qclass; | ||
}; | ||
} // namespace dns | ||
} // namespace llarp | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#ifndef LLARP_DNS_RR_HPP | ||
#define LLARP_DNS_RR_HPP | ||
#include <llarp/dns/name.hpp> | ||
#include <llarp/dns/serialize.hpp> | ||
#include <llarp/net_int.hpp> | ||
#include <vector> | ||
#include <memory> | ||
|
||
namespace llarp | ||
{ | ||
namespace dns | ||
{ | ||
using RRClass_t = uint16_t; | ||
using RRType_t = uint16_t; | ||
using RR_RData_t = std::vector< byte_t >; | ||
using RR_TTL_t = uint32_t; | ||
|
||
struct ResourceRecord : public Serialize | ||
{ | ||
ResourceRecord() = default; | ||
ResourceRecord(const ResourceRecord& other); | ||
ResourceRecord(ResourceRecord&& other); | ||
|
||
bool | ||
Encode(llarp_buffer_t* buf) const override; | ||
|
||
bool | ||
Decode(llarp_buffer_t* buf) override; | ||
|
||
friend std::ostream& | ||
operator<<(std::ostream& out, const ResourceRecord& rr) | ||
{ | ||
return out << "[RR name=" << rr.rr_name << " type=" << rr.rr_type | ||
<< " class=" << rr.rr_class << " ttl=" << rr.ttl | ||
<< " rdata=[" << rr.rData.size() << " bytes]"; | ||
} | ||
|
||
Name_t rr_name; | ||
RRType_t rr_type; | ||
RRClass_t rr_class; | ||
RR_TTL_t ttl; | ||
RR_RData_t rData; | ||
}; | ||
} // namespace dns | ||
} // namespace llarp | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#ifndef LLARP_DNS_SERIALIZE_HPP | ||
#define LLARP_DNS_SERIALIZE_HPP | ||
#include <llarp/buffer.h> | ||
#include <vector> | ||
|
||
namespace llarp | ||
{ | ||
namespace dns | ||
{ | ||
/// base type for serializable dns entities | ||
struct Serialize | ||
{ | ||
/// encode entity to buffer | ||
virtual bool | ||
Encode(llarp_buffer_t* buf) const = 0; | ||
|
||
/// decode entity from buffer | ||
virtual bool | ||
Decode(llarp_buffer_t* buf) = 0; | ||
}; | ||
|
||
bool | ||
EncodeRData(llarp_buffer_t* buf, const std::vector< byte_t >& rdata); | ||
|
||
bool | ||
DecodeRData(llarp_buffer_t* buf, std::vector< byte_t >& rdata); | ||
|
||
} // namespace dns | ||
} // namespace llarp | ||
|
||
#endif |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I needed to add a virtual destructor for Serialize to compile this PR on my OSX box:
After that, this PR seems to fix my issue in #104 ! Yeay!