Skip to content

Commit

Permalink
Support TXT record splitting
Browse files Browse the repository at this point in the history
  • Loading branch information
cmouse committed Apr 15, 2018
1 parent ec773d4 commit 8f8ae55
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
2 changes: 2 additions & 0 deletions tdns/contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ void loadZones(DNSNode& zones)
newzone->add({"ent", "was", "here"})->addRRs(TXTGen::make("plenum"));
newzone->add({"some.embedded.dots"})->addRRs(TXTGen::make("what do the dots look like?"));

newzone->add({"split"})->addRRs(TXTGen::make("hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello"));
newzone->add({"split"})->addRRs(TXTGen::make({{"this is the first part"},{"this is the second part"}}));

const char zero[]="name-does-not-stop-here\x0-it-goes-on";
std::string zstring(zero, sizeof(zero)-1);
Expand Down
11 changes: 8 additions & 3 deletions tdns/record-types.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,14 @@ void MXGen::toMessage(DNSMessageWriter& dmw)

void TXTGen::toMessage(DNSMessageWriter& dmw)
{
// XXX should autosplit
dmw.putUInt8(d_txt.length());
dmw.putBlob(d_txt);
for(auto segment: d_txts) {
while(segment.length() > 0) {
const auto fragment = segment.substr(0, 254);
dmw.putUInt8(fragment.length());
dmw.putBlob(fragment);
segment.erase(0, fragment.length());
}
}
}

void ClockTXTGen::toMessage(DNSMessageWriter& dmw)
Expand Down
12 changes: 10 additions & 2 deletions tdns/record-types.hh
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,22 @@ struct MXGen : RRGen

struct TXTGen : RRGen
{
TXTGen(const std::string& txt) : d_txt(txt) {}
TXTGen(const std::vector<std::string>& txts) : d_txts(txts) {}
TXTGen(const std::string& txt) : d_txts({txt}) {}

static std::unique_ptr<RRGen> make(const std::vector<std::string>& txts)
{
return std::make_unique<TXTGen>(txts);
}

static std::unique_ptr<RRGen> make(const std::string& txt)
{
return std::make_unique<TXTGen>(txt);
}

void toMessage(DNSMessageWriter& dpw) override;
DNSType getType() const override { return DNSType::TXT; }
std::string d_txt;
std::vector<std::string> d_txts;
};

struct ClockTXTGen : RRGen
Expand Down

0 comments on commit 8f8ae55

Please sign in to comment.