summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2012-10-24 19:32:26 -0400
committerAdam <Adam@anope.org>2012-10-24 19:32:26 -0400
commit1057fa842144e84563ddd887beaeaebe8c4f8a47 (patch)
treec43d1706df45866d5c13fcfb8333d3ee62bbdfd0 /include
parentfca9ec085e74efa005dd981f2af2a6d6fd78ce89 (diff)
BIND's forward ability did not work as I expected
because it will not forward non recursive queries. So, added support for SOA, NS, and AXFR requests.
Diffstat (limited to 'include')
-rw-r--r--include/config.h6
-rw-r--r--include/dns.h89
-rw-r--r--include/sockets.h2
3 files changed, 79 insertions, 18 deletions
diff --git a/include/config.h b/include/config.h
index 5851247e8..d1e7210e0 100644
--- a/include/config.h
+++ b/include/config.h
@@ -503,6 +503,12 @@ class CoreExport ServerConfig
/* The IP/port DNS queries come in on */
Anope::string DNSIP;
int DNSPort;
+ /* DNS SOA admin */
+ Anope::string DNSSOAAdmin;
+ /* DNS SOA primary NS */
+ Anope::string DNSSOANS;
+ /* SOA Refresh time */
+ unsigned DNSSOARefresh;
/* Prefix of guest nicks when a user gets forced off of a nick */
Anope::string NSGuestNickPrefix;
diff --git a/include/dns.h b/include/dns.h
index bb57945f3..63882a075 100644
--- a/include/dns.h
+++ b/include/dns.h
@@ -27,12 +27,18 @@ enum QueryType
DNS_QUERY_NONE,
/* A simple A lookup */
DNS_QUERY_A = 1,
+ /* An authoritative name server */
+ DNS_QUERY_NS = 2,
/* A CNAME lookup */
DNS_QUERY_CNAME = 5,
+ /* Start of a zone of authority */
+ DNS_QUERY_SOA = 6,
/* Reverse DNS lookup */
DNS_QUERY_PTR = 12,
/* IPv6 AAAA lookup */
- DNS_QUERY_AAAA = 28
+ DNS_QUERY_AAAA = 28,
+ /* Zone transfer */
+ DNS_QUERY_AXFR = 252
};
/** Flags that can be AND'd into DNSPacket::flags to receive certain values
@@ -145,30 +151,85 @@ class DNSPacket : public DNSQuery
/* Flags on the packet */
unsigned short flags;
- DNSPacket(const sockaddrs &a);
+ DNSPacket(sockaddrs *a);
void Fill(const unsigned char *input, const unsigned short len);
unsigned short Pack(unsigned char *output, unsigned short output_size);
};
-/** DNS manager, manages all requests
+/** DNS manager
*/
-class CoreExport DNSManager : public Timer, public Socket
+class CoreExport DNSManager : public Timer
{
+ class ReplySocket : public virtual Socket
+ {
+ public:
+ virtual ~ReplySocket() { }
+ virtual void Reply(DNSPacket *p) = 0;
+ };
+
+ /* Listens for TCP requests */
+ class TCPSocket : public ListenSocket
+ {
+ /* A TCP client */
+ class Client : public ClientSocket, public Timer, public ReplySocket
+ {
+ TCPSocket *tcpsock;
+ DNSPacket *packet;
+ unsigned char packet_buffer[524];
+ int length;
+
+ public:
+ Client(TCPSocket *ls, int fd, const sockaddrs &addr);
+ ~Client();
+
+ /* Times out after a few seconds */
+ void Tick(time_t) anope_override { }
+ void Reply(DNSPacket *p) anope_override;
+ bool ProcessRead() anope_override;
+ bool ProcessWrite() anope_override;
+ };
+
+ public:
+ TCPSocket(const Anope::string &ip, int port);
+
+ ClientSocket *OnAccept(int fd, const sockaddrs &addr) anope_override;
+ };
+
+ /* Listens for UDP requests */
+ class UDPSocket : public ReplySocket
+ {
+ std::deque<DNSPacket *> packets;
+ public:
+
+ UDPSocket(const Anope::string &ip, int port);
+ ~UDPSocket();
+
+ void Reply(DNSPacket *p) anope_override;
+
+ std::deque<DNSPacket *>& GetPackets() { return packets; }
+
+ bool ProcessRead() anope_override;
+
+ bool ProcessWrite() anope_override;
+ };
+
typedef std::multimap<Anope::string, ResourceRecord, ci::less> cache_map;
cache_map cache;
- std::deque<DNSPacket *> packets;
+ uint32_t serial;
+ int last_year, last_day, last_num;
+
public:
+ TCPSocket *tcpsock;
+ UDPSocket *udpsock;
+
sockaddrs addrs;
std::map<unsigned short, DNSRequest *> requests;
DNSManager(const Anope::string &nameserver, const Anope::string &ip, int port);
-
~DNSManager();
- bool ProcessRead() anope_override;
-
- bool ProcessWrite() anope_override;
+ bool HandlePacket(ReplySocket *s, const unsigned char *const data, int len, sockaddrs *from);
/** Add a record to the dns cache
* @param r The record
@@ -189,14 +250,8 @@ class CoreExport DNSManager : public Timer, public Socket
*/
void Cleanup(Module *mod);
- /** Get the list of packets pending to be sent
- */
- std::deque<DNSPacket *>& GetPackets();
-
- /** Queues a packet for sending
- * @param p The packet
- */
- void SendPacket(DNSPacket *p);
+ void UpdateSerial();
+ uint32_t GetSerial() const;
/** Does a BLOCKING DNS query and returns the first IP.
* Only use this if you know what you are doing. Unless you specifically
diff --git a/include/sockets.h b/include/sockets.h
index 6b1fca441..ea59346db 100644
--- a/include/sockets.h
+++ b/include/sockets.h
@@ -358,7 +358,7 @@ class CoreExport BinarySocket : public virtual Socket
virtual bool Read(const char *buffer, size_t l);
};
-class CoreExport ListenSocket : public Socket
+class CoreExport ListenSocket : public virtual Socket
{
public:
/** Constructor