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.
26 #include <sys/socket.h>
27 #include <netinet/in.h>
28 #include <arpa/inet.h>
29 #include "dnspacket.hh"
33 #include "namespaces.hh"
39 This is a thread that just throws packets around. Should handle ~1000 packets/second.
41 Consists of a thread receiving packets back from the backend and retransmitting them to the original client.
43 Furthermore, it provides a member function that reports the packet to the connection tracker and actually sends it out.
45 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
46 to make sure outside parties can't spoof us.
48 To fix: how to remove the stale entries that will surely accumulate
54 DNSProxy(const string &ip); //!< creates socket
55 ~DNSProxy(); //<! dtor for DNSProxy
56 void go(); //!< launches the actual thread
57 bool completePacket(DNSPacket *r, const DNSName& target,const DNSName& aname, const uint8_t scopeMask);
59 void mainloop(); //!< this is the main loop that receives reply packets and sends them out again
60 static void *launchhelper(void *p)
62 static_cast<DNSProxy *>(p)->mainloop();
65 bool recurseFor(DNSPacket* p);
70 boost::optional<ComboAddress> anyLocal;
74 uint8_t anameScopeMask;
81 typedef map<int,ConntrackEntry> map_t;
84 ComboAddress d_remote;
85 AtomicCounter* d_resanswers;
86 AtomicCounter* d_udpanswers;
87 AtomicCounter* d_resquestions;
88 pthread_mutex_t d_lock;