]> git.ipfire.org Git - thirdparty/pdns.git/blob - pdns/tcpreceiver.hh
auth: Add TCP management options described in section 10 of rfc7766
[thirdparty/pdns.git] / pdns / tcpreceiver.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 #ifndef PDNS_TCPRECEIVER_HH
23 #define PDNS_TCPRECEIVER_HH
24
25 #include "dns.hh"
26 #include "iputils.hh"
27 #include "dnsbackend.hh"
28 #include "packethandler.hh"
29 #include <vector>
30 #include <mutex>
31 #include <poll.h>
32 #include <sys/select.h>
33 #include <sys/socket.h>
34 #include <netinet/in.h>
35 #include <arpa/inet.h>
36 #include <sys/stat.h>
37 #include <unistd.h>
38 #include <netdb.h>
39 #include <sys/uio.h>
40 #include <sys/select.h>
41
42 #include "namespaces.hh"
43
44 class TCPNameserver
45 {
46 public:
47 TCPNameserver();
48 ~TCPNameserver();
49 void go();
50 private:
51
52 static void sendPacket(std::shared_ptr<DNSPacket> p, int outsock);
53 static int readLength(int fd, ComboAddress *remote);
54 static void getQuestion(int fd, char *mesg, int pktlen, const ComboAddress& remote, unsigned int totalTime);
55 static int doAXFR(const DNSName &target, std::shared_ptr<DNSPacket> q, int outsock);
56 static int doIXFR(std::shared_ptr<DNSPacket> q, int outsock);
57 static bool canDoAXFR(std::shared_ptr<DNSPacket> q);
58 static void *doConnection(void *data);
59 static void *launcher(void *data);
60 static void decrementClientCount(const ComboAddress& remote);
61 void thread(void);
62 static pthread_mutex_t s_plock;
63 static std::mutex s_clientsCountMutex;
64 static std::map<ComboAddress,size_t,ComboAddress::addressOnlyLessThan> s_clientsCount;
65 static PacketHandler *s_P;
66 pthread_t d_tid;
67 static Semaphore *d_connectionroom_sem;
68 static NetmaskGroup d_ng;
69 static size_t d_maxTransactionsPerConn;
70 static size_t d_maxConnectionsPerClient;
71 static unsigned int d_idleTimeout;
72 static unsigned int d_maxConnectionDuration;
73
74 vector<int>d_sockets;
75 vector<struct pollfd> d_prfds;
76 };
77
78 #endif /* PDNS_TCPRECEIVER_HH */