Changeset 308
- Timestamp:
- 02/12/05 20:42:44 (8 years ago)
- Location:
- trunk/pdns/pdns
- Files:
-
- 4 modified
-
dnsparser.cc (modified) (4 diffs)
-
dnsparser.hh (modified) (5 diffs)
-
dnsrecords.cc (modified) (9 diffs)
-
sdig.cc (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/pdns/pdns/dnsparser.cc
r303 r308 7 7 { 8 8 public: 9 UnknownRecordContent(const struct dnsrecordheader& ah, PacketReader& pr)10 : d_ ah(ah)9 UnknownRecordContent(const DNSRecord& dr, PacketReader& pr) 10 : d_dr(dr) 11 11 { 12 pr.copyRecord(d_record, ah.d_clen); 13 } 14 15 string getType() const 16 { 17 return "#"+lexical_cast<string>(d_ah.d_type); 18 } 19 20 12 pr.copyRecord(d_record, dr.d_clen); 13 } 21 14 22 15 string getZoneRepresentation() const 23 16 { 24 17 ostringstream str; 25 if(d_ ah.d_class==1)18 if(d_dr.d_class==1) 26 19 str<<"IN"; 27 20 else 28 str<<"CLASS"<<d_ ah.d_class;21 str<<"CLASS"<<d_dr.d_class; 29 22 30 23 str<<"\t"; 31 24 32 str<<"TYPE"<<d_ ah.d_type<<"\t";25 str<<"TYPE"<<d_dr.d_type<<"\t"; 33 26 34 27 str<<"\\# "<<d_record.size()<<" "; … … 44 37 45 38 private: 46 struct dnsrecordheader d_ah;39 const DNSRecord& d_dr; 47 40 vector<u_int8_t> d_record; 48 41 }; … … 50 43 51 44 52 DNSRecordContent* DNSRecordContent::mastermake(const struct dnsrecordheader& ah,45 DNSRecordContent* DNSRecordContent::mastermake(const DNSRecord &dr, 53 46 PacketReader& pr) 54 47 { 55 typemap_t::const_iterator i=typemap.find(make_pair( ah.d_class, ah.d_type));48 typemap_t::const_iterator i=typemap.find(make_pair(dr.d_class, dr.d_type)); 56 49 if(i==typemap.end()) { 57 return new UnknownRecordContent( ah, pr);58 } 59 return i->second( ah, pr);50 return new UnknownRecordContent(dr, pr); 51 } 52 return i->second(dr, pr); 60 53 } 61 54 62 55 63 56 DNSRecordContent::typemap_t DNSRecordContent::typemap __attribute__((init_priority(1000))); 57 DNSRecordContent::namemap_t DNSRecordContent::namemap __attribute__((init_priority(1000))); 64 58 65 59 void MOADNSParser::init(const char *packet, unsigned int len) … … 112 106 113 107 dr.d_label=label; 114 dr.d_ ah=ah;108 dr.d_clen=ah.d_clen; 115 109 d_answers.push_back(make_pair(dr, pr.d_pos)); 116 110 117 dr.d_content=boost::shared_ptr<DNSRecordContent>(DNSRecordContent::mastermake( ah, pr));111 dr.d_content=boost::shared_ptr<DNSRecordContent>(DNSRecordContent::mastermake(dr, pr)); 118 112 if(dr.d_content) { 119 113 // cout<<dr.d_label<<"\t"<<dr.d_content->getZoneRepresentation(); -
trunk/pdns/pdns/dnsparser.hh
r303 r308 12 12 #include <arpa/nameser.h> 13 13 #include <boost/shared_ptr.hpp> 14 #include <boost/lexical_cast.hpp> 14 15 15 16 namespace { … … 31 32 32 33 class MOADNSParser; 34 35 33 36 34 37 class PacketReader … … 55 58 }; 56 59 60 class DNSRecord; 61 57 62 class DNSRecordContent 58 63 { 59 64 public: 60 static DNSRecordContent* mastermake(const struct dnsrecordheader& ah, PacketReader& pr);65 static DNSRecordContent* mastermake(const DNSRecord &dr, PacketReader& pr); 61 66 virtual std::string getZoneRepresentation() const = 0; 62 virtual std::string getType() const=0;63 67 virtual ~DNSRecordContent() {} 64 68 65 69 std::string label; 66 70 struct dnsrecordheader header; 71 72 typedef DNSRecordContent* makerfunc_t(const struct DNSRecord& dr, PacketReader& pr); 73 static void regist(uint16_t cl, uint16_t ty, makerfunc_t* f, const char* name) 74 { 75 typemap[make_pair(cl,ty)]=f; 76 namemap[make_pair(cl,ty)]=name; 77 } 78 79 static uint16_t TypeToNumber(const string& name) 80 { 81 for(namemap_t::const_iterator i=namemap.begin(); i!=namemap.end();++i) 82 if(i->second==name) 83 return i->first.second; 84 85 throw runtime_error("Unknown DNS type '"+name+"'"); 86 87 } 88 89 static const string NumberToType(uint16_t num) 90 { 91 if(!namemap.count(make_pair(1,num))) 92 throw runtime_error("Unknown DNS type with numerical id "+lexical_cast<string>(num)); 93 return namemap[make_pair(1,num)]; 94 } 95 96 67 97 protected: 68 typedef DNSRecordContent* makerfunc_t(const struct dnsrecordheader& ah, PacketReader& pr); 98 69 99 typedef std::map<std::pair<u_int16_t, u_int16_t>, makerfunc_t* > typemap_t; 70 100 static typemap_t typemap; 101 typedef std::map<std::pair<u_int16_t, u_int16_t>, string > namemap_t; 102 static namemap_t namemap; 71 103 }; 72 104 … … 77 109 u_int16_t d_class; 78 110 u_int32_t d_ttl; 111 u_int16_t d_clen; 79 112 enum {Answer, Nameserver, Additional} d_place; 80 113 boost::shared_ptr<DNSRecordContent> d_content; 81 struct dnsrecordheader d_ah;82 114 }; 115 83 116 84 117 class MOADNSParser … … 97 130 string d_qname; 98 131 u_int16_t d_qclass, d_qtype; 132 uint8_t d_rcode; 99 133 100 134 typedef vector<pair<DNSRecord, uint16_t > > answers_t; -
trunk/pdns/pdns/dnsrecords.cc
r303 r308 4 4 using namespace boost; 5 5 6 7 6 class ARecordContent : public DNSRecordContent 8 7 { … … 10 9 static void report(void) 11 10 { 12 typemap[make_pair(1,1)]=&make;13 }14 15 static DNSRecordContent* make(const struct dnsrecordheader& ah, PacketReader& pr)16 { 17 if( ah.d_clen!=4)11 regist(1,1,&make,"A"); 12 } 13 14 static DNSRecordContent* make(const DNSRecord& dr, PacketReader& pr) 15 { 16 if(dr.d_clen!=4) 18 17 throw MOADNSException("Wrong size for A record"); 19 18 … … 28 27 } 29 28 30 string getType() const31 {32 return "A";33 }34 29 35 30 string getZoneRepresentation() const … … 57 52 } 58 53 59 string getType() const 60 { 61 return "AAAA"; 62 } 63 64 65 static DNSRecordContent* make(const struct dnsrecordheader& ah, PacketReader& pr) 66 { 67 if(ah.d_clen!=16) 54 static DNSRecordContent* make(const DNSRecord &dr, PacketReader& pr) 55 { 56 if(dr.d_clen!=16) 68 57 throw MOADNSException("Wrong size for AAAA record"); 69 58 … … 111 100 public: 112 101 113 OneLabelRecordContent(const struct dnsrecordheader& ah, const string& nsname) : d_type(ah.d_type), d_nsname(nsname) {} 114 115 static void report(void) 116 { 117 typemap[make_pair(1,ns_t_ns)]=&make; 118 typemap[make_pair(1,ns_t_cname)]=&make; 119 typemap[make_pair(1,ns_t_ptr)]=&make; 120 } 121 122 static DNSRecordContent* make(const struct dnsrecordheader& ah, PacketReader &pr) 123 { 124 return new OneLabelRecordContent(ah, pr.getLabel()); 125 } 126 127 string getType() const 128 { 129 if(d_type==ns_t_ns) 130 return "NS"; 131 else if(d_type==ns_t_cname) 132 return "CNAME"; 133 if(d_type==ns_t_ptr) 134 return "PTR"; 102 OneLabelRecordContent(const DNSRecord &dr, const string& nsname) : d_type(dr.d_type), d_nsname(nsname) {} 103 104 static void report(void) 105 { 106 regist(1, ns_t_ns, &make, "NS"); 107 regist(1, ns_t_cname, &make, "CNAME"); 108 regist(1, ns_t_ptr, &make, "PTR"); 109 } 110 111 static DNSRecordContent* make(const DNSRecord &dr, PacketReader &pr) 112 { 113 return new OneLabelRecordContent(dr, pr.getLabel()); 135 114 } 136 115 … … 166 145 static void report(void) 167 146 { 168 typemap[make_pair(1,6)]=&make; 169 } 170 171 string getType() const 172 { 173 return "SOA"; 174 } 175 176 177 static DNSRecordContent* make(const struct dnsrecordheader& ah, PacketReader& pr) 147 regist(1,ns_t_soa,&make,"SOA"); 148 } 149 150 static DNSRecordContent* make(const DNSRecord &dr, PacketReader& pr) 178 151 { 179 152 u_int16_t nowpos(pr.d_pos); … … 181 154 string rname=pr.getLabel(); 182 155 183 u_int16_t left= ah.d_clen - (pr.d_pos-nowpos);156 u_int16_t left=dr.d_clen - (pr.d_pos-nowpos); 184 157 185 158 if(left!=sizeof(struct soatimes)) … … 224 197 } 225 198 226 string getType() const 227 { 228 return "MX"; 229 } 230 231 232 static void report(void) 233 { 234 typemap[make_pair(1,ns_t_mx)]=&make; 235 } 236 237 static DNSRecordContent* make(const struct dnsrecordheader& ah, PacketReader& pr) 199 static void report(void) 200 { 201 regist(1,ns_t_mx,&make,"MX"); 202 } 203 204 static DNSRecordContent* make(const DNSRecord &dr, PacketReader& pr) 238 205 { 239 206 u_int16_t preference=pr.get16BitInt(); … … 265 232 SOARecordContent::report(); 266 233 MXRecordContent::report(); 234 MXRecordContent::regist(1,255,0,"ANY"); 267 235 } 268 236 } reporter __attribute__((init_priority(65535))); -
trunk/pdns/pdns/sdig.cc
r303 r308 51 51 try 52 52 { 53 DNSPacketGenerator dpg(argv[3], atoi(argv[4]));53 DNSPacketGenerator dpg(argv[3], DNSRecordContent::TypeToNumber(argv[4])); 54 54 55 55 Socket sock(InterNetwork, Datagram); 56 IPEndpoint dest(argv[1] , atoi(argv[2]));56 IPEndpoint dest(argv[1] + (*argv[1]=='@'), atoi(argv[2])); 57 57 sock.sendTo(dpg.getPacket(), dest); 58 58 … … 61 61 62 62 MOADNSParser mdp(reply); 63 cout<<"Reply to question for qname='"<<mdp.d_qname<<"', qtype="<<mdp.d_qtype<<endl; 64 63 cout<<"Reply to question for qname='"<<mdp.d_qname<<"', qtype="<<DNSRecordContent::NumberToType(mdp.d_qtype)<<endl; 64 cout<<"Rcode: "<<mdp.d_header.rcode<<", RA: "<<mdp.d_header.ra<<", RD: "<<mdp.d_header.rd; 65 cout<<", TC: "<<mdp.d_header.tc<<", AA: "<<mdp.d_header.aa<<", opcode: "<<mdp.d_header.opcode<<endl; 65 66 for(MOADNSParser::answers_t::const_iterator i=mdp.d_answers.begin(); i!=mdp.d_answers.end(); ++i) { 66 67 shared_ptr<PacketReader> pr=mdp.getPacketReader(i->second); 67 DNSRecordContent* drc=DNSRecordContent::mastermake(i->first .d_ah, *pr);68 cout<<i->first.d_place<<"\t"<<i->first.d_label<<"\tIN\t"<< drc->getType()<<"\t"<<i->first.d_ttl<<"\t"<<drc->getZoneRepresentation()<<endl;68 DNSRecordContent* drc=DNSRecordContent::mastermake(i->first, *pr); 69 cout<<i->first.d_place<<"\t"<<i->first.d_label<<"\tIN\t"<<DNSRecordContent::NumberToType(i->first.d_type)<<"\t"<<i->first.d_ttl<<"\t"<<drc->getZoneRepresentation()<<endl; 69 70 } 70 71