2018-12-03 22:22:59 +00:00
|
|
|
#ifndef LLARP_DNS_MESSAGE_HPP
|
|
|
|
#define LLARP_DNS_MESSAGE_HPP
|
2019-01-10 19:41:51 +00:00
|
|
|
|
2018-12-12 00:58:08 +00:00
|
|
|
#include <dns/serialize.hpp>
|
|
|
|
#include <dns/rr.hpp>
|
|
|
|
#include <dns/question.hpp>
|
2018-12-03 22:22:59 +00:00
|
|
|
|
|
|
|
namespace llarp
|
|
|
|
{
|
|
|
|
namespace dns
|
|
|
|
{
|
2020-08-31 20:07:17 +00:00
|
|
|
struct SRVData;
|
|
|
|
|
2020-04-07 18:38:56 +00:00
|
|
|
using MsgID_t = uint16_t;
|
2018-12-03 22:22:59 +00:00
|
|
|
using Fields_t = uint16_t;
|
2020-04-07 18:38:56 +00:00
|
|
|
using Count_t = uint16_t;
|
2018-12-03 22:22:59 +00:00
|
|
|
|
|
|
|
struct MessageHeader : public Serialize
|
|
|
|
{
|
2020-09-17 19:18:08 +00:00
|
|
|
static constexpr size_t Size = 12;
|
2018-12-04 16:16:43 +00:00
|
|
|
|
|
|
|
MessageHeader() = default;
|
|
|
|
|
2018-12-03 22:22:59 +00:00
|
|
|
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;
|
2018-12-04 16:16:43 +00:00
|
|
|
|
|
|
|
bool
|
|
|
|
operator==(const MessageHeader& other) const
|
|
|
|
{
|
2020-04-07 18:38:56 +00:00
|
|
|
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;
|
2018-12-04 16:16:43 +00:00
|
|
|
}
|
2018-12-03 22:22:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct Message : public Serialize
|
|
|
|
{
|
2018-12-04 16:16:43 +00:00
|
|
|
Message(const MessageHeader& hdr);
|
|
|
|
|
|
|
|
Message(Message&& other);
|
|
|
|
Message(const Message& other);
|
|
|
|
|
|
|
|
void
|
2018-12-13 16:14:44 +00:00
|
|
|
AddNXReply(RR_TTL_t ttl = 1);
|
2018-12-03 22:22:59 +00:00
|
|
|
|
2019-04-05 16:39:43 +00:00
|
|
|
void
|
|
|
|
AddServFail(RR_TTL_t ttl = 30);
|
|
|
|
|
2018-12-07 21:52:19 +00:00
|
|
|
void
|
2018-12-13 16:14:44 +00:00
|
|
|
AddMXReply(std::string name, uint16_t priority, RR_TTL_t ttl = 1);
|
2018-12-07 21:52:19 +00:00
|
|
|
|
2018-12-13 00:03:19 +00:00
|
|
|
void
|
2018-12-13 16:14:44 +00:00
|
|
|
AddCNAMEReply(std::string name, RR_TTL_t ttl = 1);
|
2018-12-13 00:03:19 +00:00
|
|
|
|
2018-12-04 16:16:43 +00:00
|
|
|
void
|
2019-06-11 16:44:05 +00:00
|
|
|
AddINReply(llarp::huint128_t addr, bool isV6, RR_TTL_t ttl = 1);
|
2018-12-03 22:22:59 +00:00
|
|
|
|
2018-12-04 16:16:43 +00:00
|
|
|
void
|
2018-12-13 16:14:44 +00:00
|
|
|
AddAReply(std::string name, RR_TTL_t ttl = 1);
|
2018-12-03 22:22:59 +00:00
|
|
|
|
2020-08-31 20:07:17 +00:00
|
|
|
void
|
|
|
|
AddSRVReply(std::vector<SRVData> records, RR_TTL_t ttl = 1);
|
|
|
|
|
2020-03-09 20:03:44 +00:00
|
|
|
void
|
|
|
|
AddNSReply(std::string name, RR_TTL_t ttl = 1);
|
|
|
|
|
2020-10-12 16:18:46 +00:00
|
|
|
void
|
|
|
|
AddTXTReply(std::string value, RR_TTL_t ttl = 1);
|
|
|
|
|
2018-12-03 22:22:59 +00:00
|
|
|
bool
|
|
|
|
Encode(llarp_buffer_t* buf) const override;
|
|
|
|
|
|
|
|
bool
|
|
|
|
Decode(llarp_buffer_t* buf) override;
|
|
|
|
|
2019-02-24 23:46:37 +00:00
|
|
|
std::ostream&
|
|
|
|
print(std::ostream& stream, int level, int spaces) const;
|
2018-12-04 16:16:43 +00:00
|
|
|
|
|
|
|
MsgID_t hdr_id;
|
|
|
|
Fields_t hdr_fields;
|
2020-04-07 18:38:56 +00:00
|
|
|
std::vector<Question> questions;
|
|
|
|
std::vector<ResourceRecord> answers;
|
|
|
|
std::vector<ResourceRecord> authorities;
|
|
|
|
std::vector<ResourceRecord> additional;
|
2018-12-03 22:22:59 +00:00
|
|
|
};
|
2019-02-24 23:46:37 +00:00
|
|
|
|
|
|
|
inline std::ostream&
|
|
|
|
operator<<(std::ostream& out, const Message& msg)
|
|
|
|
{
|
|
|
|
msg.print(out, -1, -1);
|
|
|
|
return out;
|
|
|
|
}
|
2018-12-03 22:22:59 +00:00
|
|
|
} // namespace dns
|
|
|
|
} // namespace llarp
|
|
|
|
|
|
|
|
#endif
|