| 1 | #ifndef PDNS_SYNCRES_HH |
|---|
| 2 | #define PDNS_SYNCRES_HH |
|---|
| 3 | #include <string> |
|---|
| 4 | #include "dns.hh" |
|---|
| 5 | #include "qtype.hh" |
|---|
| 6 | #include <vector> |
|---|
| 7 | #include <set> |
|---|
| 8 | #include <map> |
|---|
| 9 | #include "misc.hh" |
|---|
| 10 | #include "lwres.hh" |
|---|
| 11 | |
|---|
| 12 | /* external functions, opaque to us */ |
|---|
| 13 | void replaceCache(const string &qname, const QType &qt, const set<DNSResourceRecord>& content); |
|---|
| 14 | int getCache(const string &qname, const QType& qt, set<DNSResourceRecord>* res=0); |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | class SyncRes |
|---|
| 18 | { |
|---|
| 19 | public: |
|---|
| 20 | SyncRes() : d_outqueries(0), d_cacheonly(false), d_nocache(false){} |
|---|
| 21 | int beginResolve(const string &qname, const QType &qtype, vector<DNSResourceRecord>&ret); |
|---|
| 22 | void setId(int id) |
|---|
| 23 | { |
|---|
| 24 | d_prefix="["+itoa(id)+"] "; |
|---|
| 25 | } |
|---|
| 26 | static void setLog(bool log) |
|---|
| 27 | { |
|---|
| 28 | s_log=log; |
|---|
| 29 | } |
|---|
| 30 | void setCacheOnly(bool state=true) |
|---|
| 31 | { |
|---|
| 32 | d_cacheonly=state; |
|---|
| 33 | } |
|---|
| 34 | void setNoCache(bool state=true) |
|---|
| 35 | { |
|---|
| 36 | d_nocache=state; |
|---|
| 37 | } |
|---|
| 38 | static unsigned int s_queries; |
|---|
| 39 | static unsigned int s_outqueries; |
|---|
| 40 | unsigned int d_outqueries; |
|---|
| 41 | |
|---|
| 42 | private: |
|---|
| 43 | struct GetBestNSAnswer; |
|---|
| 44 | int doResolveAt(set<string> nameservers, string auth, const string &qname, const QType &qtype, vector<DNSResourceRecord>&ret, |
|---|
| 45 | int depth, set<GetBestNSAnswer>&beenthere); |
|---|
| 46 | int doResolve(const string &qname, const QType &qtype, vector<DNSResourceRecord>&ret, int depth, set<GetBestNSAnswer>& beenthere); |
|---|
| 47 | bool doCNAMECacheCheck(const string &qname, const QType &qtype, vector<DNSResourceRecord>&ret, int depth, int &res); |
|---|
| 48 | bool doCacheCheck(const string &qname, const QType &qtype, vector<DNSResourceRecord>&ret, int depth, int &res); |
|---|
| 49 | void getBestNSFromCache(const string &qname, set<DNSResourceRecord>&bestns, int depth, set<GetBestNSAnswer>& beenthere); |
|---|
| 50 | void addCruft(const string &qname, vector<DNSResourceRecord>& ret); |
|---|
| 51 | string getBestNSNamesFromCache(const string &qname,set<string>& nsset, int depth, set<GetBestNSAnswer>&beenthere); |
|---|
| 52 | void addAuthorityRecords(const string& qname, vector<DNSResourceRecord>& ret, int depth); |
|---|
| 53 | |
|---|
| 54 | vector<string> shuffle(set<string> &nameservers); |
|---|
| 55 | bool moreSpecificThan(const string& a, const string &b); |
|---|
| 56 | string getA(const string &qname, int depth, set<GetBestNSAnswer>& beenthere); |
|---|
| 57 | |
|---|
| 58 | private: |
|---|
| 59 | string d_prefix; |
|---|
| 60 | static bool s_log; |
|---|
| 61 | bool d_cacheonly; |
|---|
| 62 | bool d_nocache; |
|---|
| 63 | LWRes d_lwr; |
|---|
| 64 | static map<string,string> s_negcache; |
|---|
| 65 | struct GetBestNSAnswer |
|---|
| 66 | { |
|---|
| 67 | string qname; |
|---|
| 68 | set<DNSResourceRecord> bestns; |
|---|
| 69 | bool operator<(const GetBestNSAnswer &b) const |
|---|
| 70 | { |
|---|
| 71 | if(qname<b.qname) |
|---|
| 72 | return true; |
|---|
| 73 | if(qname==b.qname) |
|---|
| 74 | return bestns<b.bestns; |
|---|
| 75 | return false; |
|---|
| 76 | } |
|---|
| 77 | }; |
|---|
| 78 | |
|---|
| 79 | }; |
|---|
| 80 | #endif |
|---|