2 * This file is part of PowerDNS or dnsdist.
3 * Copyright -- PowerDNS.COM B.V. and its contributors
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.
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.
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.
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.
24 #include <sys/socket.h>
25 #include <netinet/in.h>
26 #include <arpa/inet.h>
27 #include "dnspacket.hh"
31 #include "namespaces.hh"
37 This is a thread that just throws packets around. Should handle ~1000 packets/second.
39 Consists of a thread receiving packets back from the backend and retransmitting them to the original client.
41 Furthermore, it provides a member function that reports the packet to the connection tracker and actually sends it out.
43 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
44 to make sure outside parties can't spoof us.
46 To fix: how to remove the stale entries that will surely accumulate
52 DNSProxy(const string& remote); //!< creates socket
53 ~DNSProxy(); //<! dtor for DNSProxy
54 void go(); //!< launches the actual thread
55 bool completePacket(std::unique_ptr<DNSPacket>& reply, const DNSName& target, const DNSName& aname, uint8_t scopeMask);
57 void mainloop(); //!< this is the main loop that receives reply packets and sends them out again
62 boost::optional<ComboAddress> anyLocal;
64 std::unique_ptr<DNSPacket> complete;
66 uint8_t anameScopeMask;
73 using map_t = map<int, ConntrackEntry>;
76 ComboAddress d_remote;
77 AtomicCounter* d_resanswers;
78 AtomicCounter* d_udpanswers;
79 AtomicCounter* d_resquestions;
80 LockGuarded<map_t> d_conntrack;
84 static int getID_locked(map_t&);