]> git.ipfire.org Git - thirdparty/pdns.git/blame - pdns/dnspbench.cc
implement stunningly cool spoofing protection, plus spoofer in dnspbench
[thirdparty/pdns.git] / pdns / dnspbench.cc
CommitLineData
06cf31b3
BH
1#include "logger.hh"
2Logger L("dnspbench");
3
bca6643b
BH
4#include "dnsparser.hh"
5#include "sstuff.hh"
6#include "misc.hh"
7#include "dnswriter.hh"
8#include "dnsrecords.hh"
06cf31b3 9
8a5602d4 10#include "statbag.hh"
06cf31b3 11#include <stdint.h>
43a2b29c 12#include <set>
43a2b29c 13
43a2b29c 14using namespace boost;
bca6643b 15
06cf31b3 16
8a5602d4 17StatBag S;
c154c8a4 18
06cf31b3
BH
19#include <bits/atomicity.h>
20// This code is ugly but does speedup the recursor tremendously on multi-processor systems, and even has a large effect (20, 30%) on uniprocessor
21namespace __gnu_cxx
22{
23 _Atomic_word
24 __attribute__ ((__unused__))
25 __exchange_and_add(volatile _Atomic_word* __mem, int __val)
26 {
27 register _Atomic_word __result=*__mem;
28 *__mem+=__val;
29 return __result;
30 }
31
32 void
33 __attribute__ ((__unused__))
34 __atomic_add(volatile _Atomic_word* __mem, int __val)
35 {
36 *__mem+=__val;
37 }
38}
39
40int xcount;
41
bca6643b 42int main(int argc, char** argv)
ea634573 43try
bca6643b 44{
06cf31b3 45 reportAllTypes();
06bd9ccf 46
06cf31b3 47 Socket s(InterNetwork, Datagram);
35ce8576
BH
48
49 IPEndpoint rem("127.0.0.1",1232), loc("213.156.2.1", 53);
50 s.bind(loc);
43a2b29c 51
06cf31b3 52 vector<uint8_t> vpacket;
35ce8576 53 string domain="ds9a.nl";
06cf31b3
BH
54 uint16_t type=1;
55
35ce8576 56 for(unsigned int n=0; n < 65536; ++n) {
06cf31b3 57 DNSPacketWriter pw(vpacket, domain, type);
06bd9ccf
BH
58
59 pw.getHeader()->rd=1;
35ce8576 60 pw.getHeader()->qr=1;
06bd9ccf 61 pw.getHeader()->id=n;
35ce8576
BH
62 ARecordContent arc("1.2.3.4");
63 pw.startRecord("ds9a.nl", 1, 9999, 1, DNSPacketWriter::ANSWER);
64 arc.toPacket(pw);
06cf31b3 65 pw.commit();
35ce8576 66
06bd9ccf
BH
67 string spacket((char*)(&*vpacket.begin()), vpacket.size());
68 s.sendTo(spacket, rem);
06cf31b3 69 }
43a2b29c 70
06bd9ccf 71 return 0;
35ce8576 72#if 0
c154c8a4 73
bca6643b 74 vector<uint8_t> packet;
8a5602d4 75
ea634573
BH
76 uint16_t type=DNSRecordContent::TypeToNumber(argv[2]);
77
78 DNSRecordContent* drc=DNSRecordContent::mastermake(type, 1, argv[3]);
79
80 cerr<<"In: "<<argv[1]<<" IN " <<argv[2]<<" "<< argv[3] << "\n";
81
82 string record=drc->serialize(argv[1]);
83
84 cerr<<"sizeof: "<<record.length()<<"\n";
85 cerr<<"hexdump: "<<makeHexDump(record)<<"\n";
86 // cerr<<"record: "<<record<<"\n";
87
c154c8a4 88 shared_ptr<DNSRecordContent> regen=DNSRecordContent::unserialize(argv[1], type, record);
ea634573 89 cerr<<"Out: "<<argv[1]<<" IN "<<argv[2]<<" "<<regen->getZoneRepresentation()<<endl;
35ce8576 90#endif
ea634573
BH
91}
92catch(exception& e)
93{
94 cerr<<"Fatal: "<<e.what()<<"\n";
bca6643b
BH
95}
96
97