X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=include%2Fmodules%2Fdns.h;h=aa6092788e35a55e87e466875c7b7346e2af5836;hb=b4a174ee9c32d62ea6bf010e837e8c5b1c3d36a3;hp=65a1762b33c099f6b3408ba3140a0366d5f36842;hpb=1031f333332cf1b09db4fd632f141143ee637c34;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/include/modules/dns.h b/include/modules/dns.h index 65a1762b3..aa6092788 100644 --- a/include/modules/dns.h +++ b/include/modules/dns.h @@ -1,8 +1,9 @@ /* * InspIRCd -- Internet Relay Chat Daemon * - * Copyright (C) 2013 Adam - * Copyright (C) 2003-2013 Anope Team + * Copyright (C) 2017, 2019, 2021 Sadie Powell + * Copyright (C) 2014-2015 Attila Molnar + * Copyright (C) 2013, 2015-2016 Adam * * This file is part of InspIRCd. InspIRCd is free software: you can * redistribute it and/or modify it under the terms of the GNU General Public @@ -33,6 +34,8 @@ namespace DNS QUERY_CNAME = 5, /* Reverse DNS lookup */ QUERY_PTR = 12, + /* TXT */ + QUERY_TXT = 16, /* IPv6 AAAA lookup */ QUERY_AAAA = 28 }; @@ -54,9 +57,11 @@ namespace DNS enum Error { ERROR_NONE, + ERROR_DISABLED, ERROR_UNKNOWN, ERROR_UNLOADED, ERROR_TIMEDOUT, + ERROR_MALFORMED, ERROR_NOT_AN_ANSWER, ERROR_NONSTANDARD_QUERY, ERROR_FORMAT_ERROR, @@ -68,13 +73,9 @@ namespace DNS ERROR_INVALIDTYPE }; - const int PORT = 53; + typedef uint16_t RequestId; - /** - * The maximum value of a dns request id, - * 16 bits wide, 0xFFFF. - */ - const int MAX_REQUEST_ID = 0xFFFF; + const int PORT = 53; class Exception : public ModuleException { @@ -86,11 +87,11 @@ namespace DNS { std::string name; QueryType type; - unsigned short qclass; - Question() : type(QUERY_NONE), qclass(0) { } - Question(const std::string& n, QueryType t, unsigned short c = 1) : name(n), type(t), qclass(c) { } - inline bool operator==(const Question& other) const { return name == other.name && type == other.type && qclass == other.qclass; } + Question() : type(QUERY_NONE) { } + Question(const std::string& n, QueryType t) : name(n), type(t) { } + bool operator==(const Question& other) const { return ((name == other.name) && (type == other.type)); } + bool operator!=(const Question& other) const { return (!(*this == other)); } struct hash { @@ -107,19 +108,31 @@ namespace DNS std::string rdata; time_t created; - ResourceRecord(const std::string& n, QueryType t, unsigned short c = 1) : Question(n, t, c), ttl(0), created(ServerInstance->Time()) { } + ResourceRecord(const std::string& n, QueryType t) : Question(n, t), ttl(0), created(ServerInstance->Time()) { } ResourceRecord(const Question& question) : Question(question), ttl(0), created(ServerInstance->Time()) { } }; struct Query { - std::vector questions; + Question question; std::vector answers; Error error; bool cached; Query() : error(ERROR_NONE), cached(false) { } - Query(const Question& question) : error(ERROR_NONE), cached(false) { questions.push_back(question); } + Query(const Question& q) : question(q), error(ERROR_NONE), cached(false) { } + + const ResourceRecord* FindAnswerOfType(QueryType qtype) const + { + for (std::vector::const_iterator i = answers.begin(); i != answers.end(); ++i) + { + const DNS::ResourceRecord& rr = *i; + if (rr.type == qtype) + return &rr; + } + + return NULL; + } }; class ReplySocket; @@ -135,31 +148,32 @@ namespace DNS virtual void Process(Request* req) = 0; virtual void RemoveRequest(Request* req) = 0; virtual std::string GetErrorStr(Error) = 0; + virtual std::string GetTypeStr(QueryType) = 0; }; /** A DNS query. */ - class Request : public Timer, public Question + class Request : public Timer { protected: Manager* const manager; public: + Question question; /* Use result cache if available */ bool use_cache; /* Request id */ - unsigned short id; - /* Creator of this request */ + RequestId id; + /* Creator of this request */ Module* const creator; - Request(Manager* mgr, Module* mod, const std::string& addr, QueryType qt, bool usecache = true) - : Timer((ServerInstance->Config->dns_timeout ? ServerInstance->Config->dns_timeout : 5), ServerInstance->Time()) - , Question(addr, qt) + Request(Manager* mgr, Module* mod, const std::string& addr, QueryType qt, bool usecache = true, unsigned int timeout = 0) + : Timer(timeout ? timeout : ServerInstance->Config->ConfValue("dns")->getDuration("timeout", 5, 1)) , manager(mgr) + , question(addr, qt) , use_cache(usecache) , id(0) , creator(mod) { - ServerInstance->Timers->AddTimer(this); } virtual ~Request() @@ -168,26 +182,26 @@ namespace DNS } /** Called when this request succeeds - * @param r The query sent back from the nameserver + * @param req The query sent back from the nameserver */ virtual void OnLookupComplete(const Query* req) = 0; /** Called when this request fails or times out. - * @param r The query sent back from the nameserver, check the error code. + * @param req The query sent back from the nameserver, check the error code. */ virtual void OnError(const Query* req) { } /** Used to time out the query, calls OnError and asks the TimerManager * to delete this request */ - bool Tick(time_t now) + bool Tick(time_t now) CXX11_OVERRIDE { - Query rr(*this); + Query rr(this->question); rr.error = ERROR_TIMEDOUT; this->OnError(&rr); + delete this; return false; } }; } // namespace DNS -