move check for cname into the right place, fix up logging output, move edns parsing to right place
This commit is contained in:
@ -66,7 +66,11 @@ DNSNode* DNSNode::add(dnsname name)
|
|||||||
{
|
{
|
||||||
cout<<"Add called for '"<<name<<"'"<<endl;
|
cout<<"Add called for '"<<name<<"'"<<endl;
|
||||||
if(name.size() == 1) {
|
if(name.size() == 1) {
|
||||||
cout<<" Last label, possibly addding, already present="<<children.count(name.front())<<endl;
|
cout<<" Last label, done with add. ";
|
||||||
|
if(children.count(name.front()))
|
||||||
|
cout<<"Label was present already"<<endl;
|
||||||
|
else
|
||||||
|
cout<<"Added label as new child"<<endl;
|
||||||
return &children[name.front()];
|
return &children[name.front()];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,6 +25,23 @@ void DNSMessageReader::getQuestion(dnsname& name, DNSType& type)
|
|||||||
payload.getUInt16(); // skip the class
|
payload.getUInt16(); // skip the class
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool DNSMessageReader::getEDNS(uint16_t* newsize, bool* doBit)
|
||||||
|
{
|
||||||
|
if(dh.arcount) {
|
||||||
|
if(payload.getUInt8() == 0 && payload.getUInt16() == (uint16_t)DNSType::OPT) {
|
||||||
|
*newsize=payload.getUInt16();
|
||||||
|
payload.getUInt16(); // extended RCODE, EDNS version
|
||||||
|
auto flags = payload.getUInt8();
|
||||||
|
*doBit = flags & 0x80;
|
||||||
|
payload.getUInt8(); payload.getUInt16(); // ignore rest
|
||||||
|
cout<<" There was an EDNS section, size supported: "<<newsize<<endl;
|
||||||
|
return true;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void DNSMessageWriter::putRR(DNSSection section, const dnsname& name, DNSType type, uint32_t ttl, const std::unique_ptr<RRGen>& content)
|
void DNSMessageWriter::putRR(DNSSection section, const dnsname& name, DNSType type, uint32_t ttl, const std::unique_ptr<RRGen>& content)
|
||||||
{
|
{
|
||||||
auto cursize = payloadpos;
|
auto cursize = payloadpos;
|
||||||
|
@ -11,7 +11,7 @@ struct DNSMessageReader
|
|||||||
|
|
||||||
dnsname getName();
|
dnsname getName();
|
||||||
void getQuestion(dnsname& name, DNSType& type);
|
void getQuestion(dnsname& name, DNSType& type);
|
||||||
|
bool getEDNS(uint16_t* newsize, bool* doBit);
|
||||||
std::string serialize() const;
|
std::string serialize() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
57
tdns/tdns.cc
57
tdns/tdns.cc
@ -52,20 +52,10 @@ bool processQuestion(const DNSNode& zones, DNSMessageReader& dm, const ComboAddr
|
|||||||
cout<<"Received a query from "<<remote.toStringWithPort()<<" for "<<name<<" and type "<<type<<endl;
|
cout<<"Received a query from "<<remote.toStringWithPort()<<" for "<<name<<" and type "<<type<<endl;
|
||||||
uint16_t newsize=0;
|
uint16_t newsize=0;
|
||||||
bool doBit=false;
|
bool doBit=false;
|
||||||
if(dm.dh.arcount) {
|
haveEDNS = dm.getEDNS(&newsize, &doBit);
|
||||||
if(dm.payload.getUInt8() == 0 && dm.payload.getUInt16() == (uint16_t)DNSType::OPT) {
|
if(haveEDNS && newsize > sizeof(dnsheader))
|
||||||
haveEDNS=true;
|
|
||||||
newsize=dm.payload.getUInt16();
|
|
||||||
dm.payload.getUInt16(); // extended RCODE, EDNS version
|
|
||||||
auto flags = dm.payload.getUInt8();
|
|
||||||
doBit = flags & 0x80;
|
|
||||||
dm.payload.getUInt8(); dm.payload.getUInt16(); // ignore rest
|
|
||||||
cout<<" There was an EDNS section, size supported: "<<newsize<<endl;
|
|
||||||
if(newsize > sizeof(dnsheader))
|
|
||||||
response.payload.resize(newsize - sizeof(dnsheader));
|
response.payload.resize(newsize - sizeof(dnsheader));
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
response.dh = dm.dh;
|
response.dh = dm.dh;
|
||||||
response.dh.ad = response.dh.ra = response.dh.aa = 0;
|
response.dh.ad = response.dh.ra = response.dh.aa = 0;
|
||||||
@ -131,28 +121,8 @@ bool processQuestion(const DNSNode& zones, DNSMessageReader& dm, const ComboAddr
|
|||||||
|
|
||||||
auto iter = node->rrsets.cbegin();
|
auto iter = node->rrsets.cbegin();
|
||||||
vector<dnsname> additional;
|
vector<dnsname> additional;
|
||||||
if(type == DNSType::ANY) {
|
if(iter = node->rrsets.find(DNSType::CNAME), iter != node->rrsets.end()) {
|
||||||
for(const auto& t : node->rrsets) {
|
cout<<"We have a CNAME!"<<endl;
|
||||||
const auto& rrset = t.second;
|
|
||||||
for(const auto& rr : rrset.contents) {
|
|
||||||
response.putRR(DNSSection::Answer, lastnode+zone, t.first, rrset.ttl, rr);
|
|
||||||
if(t.first == DNSType::MX)
|
|
||||||
additional.push_back(dynamic_cast<MXGen*>(rr.get())->d_name);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if(iter = node->rrsets.find(type), iter != node->rrsets.end()) {
|
|
||||||
const auto& rrset = iter->second;
|
|
||||||
for(const auto& rr : rrset.contents) {
|
|
||||||
response.putRR(DNSSection::Answer, lastnode+zone, type, rrset.ttl, rr);
|
|
||||||
if(type == DNSType::MX)
|
|
||||||
additional.push_back(dynamic_cast<MXGen*>(rr.get())->d_name);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
else if(iter = node->rrsets.find(DNSType::CNAME), iter != node->rrsets.end()) {
|
|
||||||
cout<<"We do have a CNAME!"<<endl;
|
|
||||||
const auto& rrset = iter->second;
|
const auto& rrset = iter->second;
|
||||||
dnsname target;
|
dnsname target;
|
||||||
for(const auto& rr : rrset.contents) {
|
for(const auto& rr : rrset.contents) {
|
||||||
@ -172,6 +142,25 @@ bool processQuestion(const DNSNode& zones, DNSMessageReader& dm, const ComboAddr
|
|||||||
else
|
else
|
||||||
cout<<" CNAME points to record "<<target<<" in other zone, good luck"<<endl;
|
cout<<" CNAME points to record "<<target<<" in other zone, good luck"<<endl;
|
||||||
}
|
}
|
||||||
|
else if(type == DNSType::ANY) {
|
||||||
|
for(const auto& t : node->rrsets) {
|
||||||
|
const auto& rrset = t.second;
|
||||||
|
for(const auto& rr : rrset.contents) {
|
||||||
|
response.putRR(DNSSection::Answer, lastnode+zone, t.first, rrset.ttl, rr);
|
||||||
|
if(t.first == DNSType::MX)
|
||||||
|
additional.push_back(dynamic_cast<MXGen*>(rr.get())->d_name);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(iter = node->rrsets.find(type), iter != node->rrsets.end() || type==DNSType::ANY) {
|
||||||
|
const auto& rrset = iter->second;
|
||||||
|
for(const auto& rr : rrset.contents) {
|
||||||
|
response.putRR(DNSSection::Answer, lastnode+zone, type, rrset.ttl, rr);
|
||||||
|
if(type == DNSType::MX)
|
||||||
|
additional.push_back(dynamic_cast<MXGen*>(rr.get())->d_name);
|
||||||
|
}
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
cout<<"Node exists, qtype doesn't, NOERROR situation, inserting SOA"<<endl;
|
cout<<"Node exists, qtype doesn't, NOERROR situation, inserting SOA"<<endl;
|
||||||
const auto& rrset = fnd->zone->rrsets[DNSType::SOA];
|
const auto& rrset = fnd->zone->rrsets[DNSType::SOA];
|
||||||
|
Reference in New Issue
Block a user