]> git.ipfire.org Git - thirdparty/pdns.git/blob - pdns/dnsproxy.hh
Make the constructors taking a pthread_rwlock_t * private.
[thirdparty/pdns.git] / pdns / dnsproxy.hh
1 /*
2 * This file is part of PowerDNS or dnsdist.
3 * Copyright -- PowerDNS.COM B.V. and its contributors
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * In addition, for the avoidance of any doubt, permission is granted to
10 * link this program with OpenSSL and to (re)distribute the binaries
11 * produced as the result of such linking.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 */
22 #pragma once
23 #include <map>
24 #include <mutex>
25 #include <sys/socket.h>
26 #include <netinet/in.h>
27 #include <arpa/inet.h>
28 #include "dnspacket.hh"
29 #include "lock.hh"
30 #include "iputils.hh"
31
32 #include "namespaces.hh"
33
34 /**
35
36 how will this work.
37
38 This is a thread that just throws packets around. Should handle ~1000 packets/second.
39
40 Consists of a thread receiving packets back from the backend and retransmitting them to the original client.
41
42 Furthermore, it provides a member function that reports the packet to the connection tracker and actually sends it out.
43
44 The sending happens from a source port that is determined by the constructor, but IS random. Furthermore, the ID is XOR-ed with a random value
45 to make sure outside parties can't spoof us.
46
47 To fix: how to remove the stale entries that will surely accumulate
48 */
49
50 class DNSProxy
51 {
52 public:
53 DNSProxy(const string &ip); //!< creates socket
54 ~DNSProxy(); //<! dtor for DNSProxy
55 void go(); //!< launches the actual thread
56 bool completePacket(std::unique_ptr<DNSPacket>& r, const DNSName& target,const DNSName& aname, const uint8_t scopeMask);
57
58 void mainloop(); //!< this is the main loop that receives reply packets and sends them out again
59 bool recurseFor(DNSPacket* p);
60 private:
61 struct ConntrackEntry
62 {
63 time_t created;
64 boost::optional<ComboAddress> anyLocal;
65 DNSName qname;
66 std::unique_ptr<DNSPacket> complete;
67 DNSName aname;
68 uint8_t anameScopeMask;
69 ComboAddress remote;
70 uint16_t id;
71 uint16_t qtype;
72 int outsock;
73 };
74
75 typedef map<int,ConntrackEntry> map_t;
76
77 // Data
78 ComboAddress d_remote;
79 AtomicCounter* d_resanswers;
80 AtomicCounter* d_udpanswers;
81 AtomicCounter* d_resquestions;
82 std::mutex d_lock;
83 map_t d_conntrack;
84 int d_sock;
85 int getID_locked();
86 uint16_t d_xor;
87 };