vector<uint8_t> packet;
boost::trim(line);
auto p = splitField(line, ' ');
- DNSPacketWriter pw(packet, p.first, DNSRecordContent::TypeToNumber(p.second));
+ DNSPacketWriter pw(packet, DNSName(p.first), DNSRecordContent::TypeToNumber(p.second));
packets.push_back(packet);
}
cout<<"Generated "<<packets.size()<<" queries"<<endl;
{
BenchQuery(const std::string& qname_, uint16_t qtype_) : qname(qname_), qtype(qtype_), udpUsec(0), tcpUsec(0), answerSecond(0) {}
BenchQuery(){}
- std::string qname;
+ DNSName qname;
uint16_t qtype;
uint32_t udpUsec, tcpUsec;
time_t answerSecond;
throw runtime_error("Failed to connect PowerDNS socket to address "+pdns.toString()+": "+stringerror());
vector<uint8_t> outpacket;
- DNSPacketWriter pw(outpacket, argv[2], QType::SOA, 1, Opcode::Notify);
+ DNSPacketWriter pw(outpacket, DNSName(argv[2]), QType::SOA, 1, Opcode::Notify);
pw.getHeader()->id = random();
}
vector<uint8_t> packet;
- string qname=argv[3];
+ DNSName qname(argv[3]);
DNSPacketWriter pw(packet, qname, DNSRecordContent::TypeToNumber(argv[4]));
if(recurse)
delete[] creply;
MOADNSParser mdp(reply);
- cout<<"Reply to question for qname='"<<mdp.d_qname.toString()<<"', qtype="<<DNSRecordContent::NumberToType(mdp.d_qtype)<<endl;
+ cout<<"Reply to question for qname='"<<mdp.d_qname<<"', qtype="<<DNSRecordContent::NumberToType(mdp.d_qtype)<<endl;
cout<<"Rcode: "<<mdp.d_header.rcode<<", RD: "<<mdp.d_header.rd<<", QR: "<<mdp.d_header.qr;
cout<<", TC: "<<mdp.d_header.tc<<", AA: "<<mdp.d_header.aa<<", opcode: "<<mdp.d_header.opcode<<endl;
if(i->first.d_type == QType::CNAME)
{
- namesseen.insert(stripDot(i->first.d_content->getZoneRepresentation()));
+ namesseen.insert(DNSName(i->first.d_content->getZoneRepresentation()));
}
cout<<i->first.d_place-1<<"\t"<<i->first.d_label.toString()<<"\tIN\t"<<DNSRecordContent::NumberToType(i->first.d_type);
cout<<"== nsec3 prove/deny report follows =="<<endl;
set<DNSName> proven;
set<DNSName> denied;
- namesseen.insert(stripDot(qname));
+ namesseen.insert(qname);
for(const auto &n: namesseen)
{
DNSName shorter(n);
for(const auto &n: namestocheck)
{
proveOrDeny(nsec3s, n, nsec3salt, nsec3iters, proven, denied);
- proveOrDeny(nsec3s, "*."+n, nsec3salt, nsec3iters, proven, denied);
+ proveOrDeny(nsec3s, DNSName("*")+n, nsec3salt, nsec3iters, proven, denied);
}
- if(names.count(qname+"."))
+ if(names.count(qname))
{
cout<<"== qname found in names, investigating NSEC3s in case it's a wildcard"<<endl;
// exit(EXIT_SUCCESS);
int size(); //!< number of entries in the cache
void cleanup(); //!< force the cache to preen itself from expired packets
int purge();
- int purge(const string &match);
+ int purge(const std::string& match); // could be $ terminated. Is not a dnsname!
map<char,int> getCounts();
private:
bool gss=false;
bool tsig=false;
TSIGHashEnum tsig_algo;
- string tsig_key;
+ DNSName tsig_key;
string tsig_secret;
string tsigprevious;
string remote_principal;
cerr<<"Invalid syntax for tsig"<<endl;
exit(EXIT_FAILURE);
}
- if (!getTSIGHashEnum(parts[2], tsig_algo)) {
+ if (!getTSIGHashEnum(DNSName(parts[2]), tsig_algo)) {
cerr<<"Cannot understand TSIG algorithm '"<<parts[1]<<"'"<<endl;
exit(EXIT_FAILURE);
}
- tsig_key = parts[1];
- if (tsig_key.size()==0) {
+ tsig_key = DNSName(parts[1]);
+ if (tsig_key == DNSName()) {
cerr<<"Key name must be set for tsig"<<endl;
exit(EXIT_FAILURE);
}
exit(EXIT_FAILURE);
}
- tsig_key = gssctx.getLabel();
+ tsig_key = DNSName(gssctx.getLabel());
#endif
}
- DNSPacketWriter pw(packet, argv[3], 252);
+ DNSPacketWriter pw(packet, DNSName(argv[3]), 252);
pw.getHeader()->id = dns_random(0xffff);
DNSName shorter(i->first.d_label);
do {
labels.insert(shorter);
- if (pdns_iequals(shorter, argv[3]))
+ if (shorter == DNSName(argv[3]))
break;
}while(shorter.chopOff());
DNSName label /* FIXME400 rename */=record.first;
if (isNSEC3 && unhash)
{
- auto i = hashes.find(label.makeRelative(argv[3]).toStringNoDot());
+ auto i = hashes.find(label.makeRelative(DNSName(argv[3])).toStringNoDot());
if (i != hashes.end())
label=i->second;
}
vector<uint8_t> packet;
- DNSPacketWriter pw(packet, argv[3], DNSRecordContent::TypeToNumber(argv[4]));
+ DNSPacketWriter pw(packet, DNSName(argv[3]), DNSRecordContent::TypeToNumber(argv[4]));
if(dnssec || getenv("SDIGBUFSIZE"))
{
BOOST_CHECK_EQUAL(domains.size(), 11);
#define checkzone(i, dname, fname, ztype, nmasters) { \
- BOOST_CHECK(domains[i].name == #dname); \
+ BOOST_CHECK(domains[i].name == DNSName(#dname)); \
BOOST_CHECK_EQUAL(domains[i].filename, fname); \
BOOST_CHECK_EQUAL(domains[i].type, #ztype); \
BOOST_CHECK_EQUAL(domains[i].masters.size(), nmasters); \
for(int n=0; n < 100; ++n) {
auto q = new Question();
q->d_dt.set();
- q->qdomain=std::to_string(n);
+ q->qdomain=DNSName(std::to_string(n));
d->question(q, report2);
}
BOOST_AUTO_TEST_CASE(test_QuestionHash) {
vector<unsigned char> packet;
reportBasicTypes();
- DNSPacketWriter dpw1(packet, "www.ds9a.nl.", QType::AAAA);
+ DNSPacketWriter dpw1(packet, DNSName("www.ds9a.nl."), QType::AAAA);
auto hash1=hashQuestion((char*)&packet[0], packet.size(), 0);
- DNSPacketWriter dpw2(packet, "wWw.Ds9A.nL.", QType::AAAA);
+ DNSPacketWriter dpw2(packet, DNSName("wWw.Ds9A.nL."), QType::AAAA);
auto hash2=hashQuestion((char*)&packet[0], packet.size(), 0);
BOOST_CHECK_EQUAL(hash1, hash2);
for(unsigned int n=0; n < 100000; ++n) {
packet.clear();
- DNSPacketWriter dpw1(packet, std::to_string(n)+"."+std::to_string(n*2)+".", QType::AAAA);
+ DNSPacketWriter dpw1(packet, DNSName(std::to_string(n)+"."+std::to_string(n*2)+"."), QType::AAAA);
counts[hashQuestion((char*)&packet[0], packet.size(), 0) % counts.size()]++;
}
BOOST_AUTO_TEST_CASE(test_packetParse) {
vector<unsigned char> packet;
reportBasicTypes();
- DNSPacketWriter dpw(packet, "www.ds9a.nl.", QType::AAAA);
+ DNSPacketWriter dpw(packet, DNSName("www.ds9a.nl."), QType::AAAA);
uint16_t qtype, qclass;
DNSName dn((char*)&packet[0], packet.size(), 12, false, &qtype, &qclass);
BOOST_CHECK(qtype == QType::AAAA);
BOOST_CHECK_EQUAL(qclass, 1);
- dpw.startRecord("ds9a.nl.", DNSRecordContent::TypeToNumber("NS"));
+ dpw.startRecord(DNSName("ds9a.nl."), DNSRecordContent::TypeToNumber("NS"));
NSRecordContent nrc("ns1.powerdns.com");
nrc.toPacket(dpw);
BOOST_CHECK(lower.canonCompare(higher));
- vector<DNSName> vec({"bert.com.", "alpha.nl.", "articles.xxx.",
+ vector<DNSName> vec;
+ for(const std::string& a : {"bert.com.", "alpha.nl.", "articles.xxx.",
"Aleph1.powerdns.com.", "ZOMG.powerdns.com.", "aaa.XXX.", "yyy.XXX.",
- "test.powerdns.com."});
+ "test.powerdns.com."}) {
+ vec.push_back(DNSName(a));
+ }
sort(vec.begin(), vec.end(), CanonDNSNameCompare());
// for(const auto& v : vec)
// cerr<<'"'<<v.toString()<<'"'<<endl;
- vector<DNSName> right({"bert.com.", "Aleph1.powerdns.com.",
+ vector<DNSName> right;
+ for(const auto& a: {"bert.com.", "Aleph1.powerdns.com.",
"test.powerdns.com.",
"ZOMG.powerdns.com.",
"alpha.nl.",
"aaa.XXX.",
"articles.xxx.",
- "yyy.XXX."});
+ "yyy.XXX."})
+ right.push_back(DNSName(a));
BOOST_CHECK(vec==right);
}
default:
REC_CHECK_EQUAL(rec->getZoneRepresentation(), val.get<2>());
}
- recData = rec->serialize("rec.test");
+ recData = rec->serialize(DNSName("rec.test"));
} else {
- std::shared_ptr<DNSRecordContent> rec3 = DNSRecordContent::unserialize("rec.test",q.getCode(),(val.get<3>()));
+ std::shared_ptr<DNSRecordContent> rec3 = DNSRecordContent::unserialize(DNSName("rec.test"),q.getCode(),(val.get<3>()));
// TSIG special, only works the other way
- recData = rec3->serialize("rec.test");
+ recData = rec3->serialize(DNSName("rec.test"));
}
- std::shared_ptr<DNSRecordContent> rec2 = DNSRecordContent::unserialize("rec.test",q.getCode(),recData);
+ std::shared_ptr<DNSRecordContent> rec2 = DNSRecordContent::unserialize(DNSName("rec.test"),q.getCode(),recData);
BOOST_CHECK_MESSAGE(rec2 != NULL, "unserialize(rec.test, " << q.getCode() << ", recData) returned NULL");
if (rec2 == NULL) continue;
// now verify the zone representation (here it can be different!)
BOOST_TEST_MESSAGE("Checking bad value for record type " << q.getName() << " test #" << n);
vector<uint8_t> packet;
- DNSPacketWriter pw(packet, "unit.test", q.getCode());
+ DNSPacketWriter pw(packet, DNSName("unit.test"), q.getCode());
if (val.get<2>()) {
bool success=true;
- BOOST_WARN_EXCEPTION( { boost::scoped_ptr<DNSRecordContent> drc(DNSRecordContent::mastermake(q.getCode(), 1, val.get<1>())); pw.startRecord("unit.test", q.getCode()); drc->toPacket(pw); success=false; }, std::runtime_error, test_dnsrecords_cc_predicate );
+ BOOST_WARN_EXCEPTION( { boost::scoped_ptr<DNSRecordContent> drc(DNSRecordContent::mastermake(q.getCode(), 1, val.get<1>())); pw.startRecord(DNSName("unit.test"), q.getCode()); drc->toPacket(pw); success=false; }, std::runtime_error, test_dnsrecords_cc_predicate );
if (success==false) REC_FAIL_XSUCCESS2(q.getName() << " test #" << n << " has unexpectedly passed"); // a bad record was detected when it was supposed not to be detected
} else {
- BOOST_CHECK_EXCEPTION( { boost::scoped_ptr<DNSRecordContent> drc(DNSRecordContent::mastermake(q.getCode(), 1, val.get<1>())); pw.startRecord("unit.test", q.getCode()); drc->toPacket(pw); }, std::runtime_error, test_dnsrecords_cc_predicate );
+ BOOST_CHECK_EXCEPTION( { boost::scoped_ptr<DNSRecordContent> drc(DNSRecordContent::mastermake(q.getCode(), 1, val.get<1>())); pw.startRecord(DNSName("unit.test"), q.getCode()); drc->toPacket(pw); }, std::runtime_error, test_dnsrecords_cc_predicate );
}
};
}
vector<uint8_t> pak;
vector<pair<uint16_t,string > > opts;
- DNSPacketWriter pw(pak, "www.powerdns.com", QType::A);
- pw.startRecord("www.powerdns.com", QType::A, 16, 1, DNSPacketWriter::ANSWER);
+ DNSPacketWriter pw(pak, DNSName("www.powerdns.com"), QType::A);
+ pw.startRecord(DNSName("www.powerdns.com"), QType::A, 16, 1, DNSPacketWriter::ANSWER);
pw.xfrIP(htonl(0x7f000001));
opts.push_back(pair<uint16_t,string>(3, "powerdns"));
pw.addOpt(1280, 0, 0, opts);
BOOST_CHECK_EQUAL(PC.size(), 0);
- PC.insert("hello", QType(QType::A), PacketCache::QUERYCACHE, "something", 3600, 1);
+ PC.insert(DNSName("hello"), QType(QType::A), PacketCache::QUERYCACHE, "something", 3600, 1);
BOOST_CHECK_EQUAL(PC.size(), 1);
PC.purge();
BOOST_CHECK_EQUAL(PC.size(), 0);
int counter=0;
try {
for(counter = 0; counter < 100000; ++counter) {
- PC.insert("hello "+boost::lexical_cast<string>(counter), QType(QType::A), PacketCache::QUERYCACHE, "something", 3600, 1);
+ PC.insert(DNSName("hello ")+DNSName(boost::lexical_cast<string>(counter)), QType(QType::A), PacketCache::QUERYCACHE, "something", 3600, 1);
}
BOOST_CHECK_EQUAL(PC.size(), counter);
int delcounter=0;
for(delcounter=0; delcounter < counter/100; ++delcounter) {
- PC.purge("hello "+boost::lexical_cast<string>(delcounter));
+ PC.purge((DNSName("hello ")+DNSName(boost::lexical_cast<string>(delcounter))).toString());
}
BOOST_CHECK_EQUAL(PC.size(), counter-delcounter);
string entry;
int expected=counter-delcounter;
for(; delcounter < counter; ++delcounter) {
- if(PC.getEntry("hello "+boost::lexical_cast<string>(delcounter), QType(QType::A), PacketCache::QUERYCACHE, entry, 1)) {
+ if(PC.getEntry(DNSName("hello ")+DNSName(boost::lexical_cast<string>(delcounter)), QType(QType::A), PacketCache::QUERYCACHE, entry, 1)) {
matches++;
}
}
{
unsigned int offset=(unsigned int)(unsigned long)a;
for(unsigned int counter=0; counter < 100000; ++counter)
- g_PC->insert("hello "+boost::lexical_cast<string>(counter+offset), QType(QType::A), PacketCache::QUERYCACHE, "something", 3600, 1);
+ g_PC->insert(DNSName("hello ")+DNSName(boost::lexical_cast<string>(counter+offset)), QType(QType::A), PacketCache::QUERYCACHE, "something", 3600, 1);
return 0;
}
catch(PDNSException& e) {
unsigned int offset=(unsigned int)(unsigned long)a;
string entry;
for(unsigned int counter=0; counter < 100000; ++counter)
- if(!g_PC->getEntry("hello "+boost::lexical_cast<string>(counter+offset), QType(QType::A), PacketCache::QUERYCACHE, entry, 1)) {
+ if(!g_PC->getEntry(DNSName("hello ")+DNSName(boost::lexical_cast<string>(counter+offset)), QType(QType::A), PacketCache::QUERYCACHE, entry, 1)) {
g_missing++;
}
return 0;
PacketCache PC;
for(unsigned int counter = 0; counter < 1000000; ++counter) {
- PC.insert("hello "+boost::lexical_cast<string>(counter), QType(QType::A), PacketCache::QUERYCACHE, "something", 1, 1);
+ PC.insert(DNSName("hello ")+DNSName(boost::lexical_cast<string>(counter)), QType(QType::A), PacketCache::QUERYCACHE, "something", 1, 1);
}
sleep(1);
vector<uint8_t> pak;
vector<pair<uint16_t,string > > opts;
- DNSPacketWriter pw(pak, "www.powerdns.com", QType::A);
+ DNSPacketWriter pw(pak, DNSName("www.powerdns.com"), QType::A);
DNSPacket q, r, r2;
q.parse((char*)&pak[0], pak.size());
pak.clear();
- DNSPacketWriter pw2(pak, "www.powerdns.com", QType::A);
- pw2.startRecord("www.powerdns.com", QType::A, 16, 1, DNSPacketWriter::ANSWER);
+ DNSPacketWriter pw2(pak, DNSName("www.powerdns.com"), QType::A);
+ pw2.startRecord(DNSName("www.powerdns.com"), QType::A, 16, 1, DNSPacketWriter::ANSWER);
pw2.xfrIP(htonl(0x7f000001));
pw2.commit();
if(!p)
p = ".";
pathbuf << p << "/../regression-tests/zones/unit.test";
- ZoneParserTNG zp(pathbuf.str(), "unit.test");
+ ZoneParserTNG zp(pathbuf.str(), DNSName("unit.test"));
DNSResourceRecord rr;
ifstream ifs(pathbuf.str());
else
qname=boost::lexical_cast<string>(n)+"."+argv[3];
- DNSPacketWriter pw(packet, qname, DNSRecordContent::TypeToNumber(argv[4]));
+ DNSPacketWriter pw(packet, DNSName(qname), DNSRecordContent::TypeToNumber(argv[4]));
pw.getHeader()->rd=1;
vector<uint8_t> packet;
- DNSPacketWriter pw(packet, argv[3], DNSRecordContent::TypeToNumber(argv[4]));
+ DNSPacketWriter pw(packet, DNSName(argv[3]), DNSRecordContent::TypeToNumber(argv[4]));
pw.getHeader()->id=htons(0x4831);
DNSName keyname("pdns-b-aa");
TSIGRecordContent trc;
- trc.d_algoName="hmac-md5.sig-alg.reg.int";
+ trc.d_algoName=DNSName("hmac-md5.sig-alg.reg.int");
trc.d_time=time(0);
trc.d_fudge=300;
trc.d_origID=ntohs(pw.getHeader()->id);